ribbonconnections.h \
ribbonconversations.h \
ribbonserver.h \
- ribbonsocket.h
+ ribbonsocket.h \
+ ribbonutil.h
SOURCES += ribbonmanager.cpp \
ribbonaccount.cpp \
ribbonconversations.cpp \
ribbonserver.cpp \
ribbonsocket.cpp \
+ ribbonutil.cpp \
main.cpp
#include "ribbonconversations.h"
#include "ribbonmanager.h"
+#include "ribbonutil.h"
#include <QDebug>
#include <QDateTime>
}
qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << sender << purple_conversation_get_name(conv) << message;
}
+
+void RibbonConversations::send_im(QString protocol, QString account, QString buddy, QString message)
+{
+ qDebug() << "sending im from" << protocol << account << "to" << buddy << ":" << message;
+ PurpleAccount* p_acct = purple_accounts_find(account.toUtf8(), protocol.toUtf8());
+ PurpleBuddy* p_buddy = purple_find_buddy(p_acct, buddy.toUtf8());
+ // TODO: call the purple functions to send an IM
+ Q_UNUSED(p_buddy);
+}
+
+void RibbonConversations::handleExternalEvent(QString method, QVariantMap context)
+{
+ if (method == "send_im") {
+ // TODO: check args, extract args from context, call send_im
+ if (hasStringMember(context, "proto") && hasStringMember(context, "account")
+ && hasStringMember(context, "buddy") && hasStringMember(context, "message")) {
+ send_im(context["protocol"].toString(), context["account"].toString(),
+ context["buddy"].toString(), context["message"].toString());
+ } else {
+ qWarning() << "Invalid args to send_im:" << context;
+ }
+ }
+}
void init();
void received_im_msg(PurpleAccount *account, char *sender, char *message,
PurpleConversation *conv, PurpleMessageFlags flags);
+ void handleExternalEvent(QString method, QVariantMap context);
signals:
void event(QString source, QString signal, QVariantMap context);
private:
RibbonManager* _manager;
+ void send_im(QString protocol, QString account, QString buddy, QString message);
};
#endif /* RIBBONCONVERSATIONS_H */
qDebug() << "TODO: do something with" << destination << "." << method << "(" << context << ")";
if (destination == "accounts") {
_accounts->handleExternalEvent(method, context);
+ } else if (destination == "conversations") {
+ _conversations->handleExternalEvent(method, context);
}
}
#include "ribbonserver.h"
#include "ribbonsocket.h"
+#include "ribbonutil.h"
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
#include <QJsonObject>
#include <QDebug>
-// Helper functions for sanitizing external events
-static bool hasStringMember(QVariantMap m, QString memberName)
-{
- return m.contains(memberName) && m[memberName].type() == QVariant::String;
-}
-
-static bool hasMapMember(QVariantMap m, QString memberName)
-{
- return m.contains(memberName) && m[memberName].type() == QVariant::Map;
-}
-
RibbonServer::RibbonServer(QObject* parent) :
QObject(parent)
{
--- /dev/null
+#include "ribbonutil.h"
+
+bool hasStringMember(QVariantMap m, QString memberName)
+{
+ return m.contains(memberName) && m[memberName].type() == QVariant::String;
+}
+
+bool hasMapMember(QVariantMap m, QString memberName)
+{
+ return m.contains(memberName) && m[memberName].type() == QVariant::Map;
+}
+
--- /dev/null
+#ifndef RIBBONUTIL_H
+#define RIBBONUTIL_H
+
+#include <QString>
+#include <QVariantMap>
+
+// Helper functions for validating parameters
+bool hasStringMember(QVariantMap m, QString memberName);
+bool hasMapMember(QVariantMap m, QString memberName);
+
+
+#endif // RIBBONUTIL_H