ribbonaccount.h \
ribbonaccounts.h \
ribbonblist.h \
+ ribbonconnections.h \
ribbonconversations.h \
ribbonserver.h \
ribbonsocket.h
ribbonaccount.cpp \
ribbonaccounts.cpp \
ribbonblist.cpp \
+ ribbonconnections.cpp \
ribbonconversations.cpp \
ribbonserver.cpp \
ribbonsocket.cpp \
{
}
+QVariantMap RibbonAccounts::context(PurpleAccount* acct)
+{
+ QVariantMap m;
+ m["proto"] = purple_account_get_protocol_id(acct);
+ m["account"] = purple_account_get_username(acct);
+ return m;
+}
+
void RibbonAccounts::handleExternalEvent(QString method, QVariantMap params)
{
qDebug() << "called" << method << "on" << params;
public:
RibbonAccounts(RibbonManager* parent = 0);
~RibbonAccounts();
+ static QVariantMap context(PurpleAccount* acct);
public slots:
void handleExternalEvent(QString method, QVariantMap params);
signals:
void RibbonBlist::init()
{
+ /* Create and load the buddylist */
+ purple_set_blist(purple_blist_new());
+ purple_blist_load();
+
+ // Register signal callbacks
static int handle;
void *blist_handle = purple_blist_get_handle();
purple_signal_connect(blist_handle, "buddy-signed-on", &handle,
--- /dev/null
+#include "ribbonconnections.h"
+#include "ribbonmanager.h"
+#include "ribbonaccounts.h"
+
+#include <QDebug>
+
+static void connect_progress(PurpleConnection *gc, const char* text, size_t step, size_t step_count)
+{
+ PurpleAccount* account = purple_connection_get_account(gc);
+ RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
+ qDebug() << QString("Connection progress (%1:%2):").arg(account->protocol_id, account->username).toUtf8().constData() << text << step << "of" << step_count;
+ // TODO: add enough unique information from account to ctx to handle the message
+ QVariantMap ctx = RibbonAccounts::context(account);
+ ctx["step"] = QVariant((qulonglong)step);
+ ctx["step_count"] = QVariant((qulonglong)step_count);
+ ctx["text"] = QVariant(QString::fromUtf8(text));
+ r->event(QString("connection"), QString("connect_progress"), ctx);
+}
+
+static void connection_notice(PurpleConnection *gc, const char* text)
+{
+ qDebug() << "Connection notice:" << text;
+ PurpleAccount* account = purple_connection_get_account(gc);
+ RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
+ QVariantMap ctx = RibbonAccounts::context(account);
+ ctx["message"] = QVariant(QString::fromUtf8(text));
+ r->event(QString("connection"), QString("connect_notice"), ctx);
+}
+
+static void connection_disconnected(PurpleConnection *gc, const char* text)
+{
+ qDebug() << "Connection disconnected:" << text;
+ PurpleAccount* account = purple_connection_get_account(gc);
+ RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
+ QVariantMap ctx = RibbonAccounts::context(account);
+ ctx["message"] = QVariant(QString::fromUtf8(text));
+ r->event(QString("connection"), QString("connection_disconnected"), ctx);
+}
+
+static void network_connected(void)
+{
+ qWarning() << "Network connection established";
+}
+
+static void network_disconnected(void)
+{
+ qWarning() << "This machine has been disconnected from the internet";
+}
+
+static void report_disconnect_reason(PurpleConnection *gc, PurpleConnectionError reason, const char *text)
+{
+ PurpleAccount *account = purple_connection_get_account(gc);
+ //qDebug() << QString("Connection disconnected: \'%1\' (%2)\n >Error: %3\n >Reason: %4\n").arg(purple_account_get_username(account), purple_account_get_protocol_id(account), qint32(reason), text);
+ RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
+ QVariantMap ctx = RibbonAccounts::context(account);
+ ctx["reason_code"] = QVariant(qint32(reason));
+ ctx["reason_text"] = QVariant(QString::fromUtf8(text));
+ r->event(QString("connection"), QString("disconnect_reason"), ctx);
+}
+
+static PurpleConnectionUiOps connection_uiops =
+{
+ connect_progress, /* connect_progress */
+ NULL, /* connected */
+ NULL, /* disconnected */
+ connection_notice, /* notice */
+ connection_disconnected, /* report_disconnect */
+ network_connected, /* network_connected */
+ network_disconnected, /* network_disconnected */
+ report_disconnect_reason, /* report_disconnect_reason */
+ NULL,
+ NULL,
+ NULL
+};
+
+// TODO: note that the void* data can be set at purple_signal_connect time, and
+// set it to the class instance to allow for convenient upcalls
+// Then, actually do upcalls and emit the appropriate signals.
+static void signed_on(PurpleConnection *gc, void* data)
+{
+ Q_UNUSED(data);
+ PurpleAccount *account = purple_connection_get_account(gc);
+ printf("Account connected: \"%s\" (%s)\n", purple_account_get_username(account), purple_account_get_protocol_id(account));
+}
+
+RibbonConnections::RibbonConnections(RibbonManager* parent) : QObject((QObject*)parent)
+{
+ _manager = parent;
+}
+
+RibbonConnections::~RibbonConnections()
+{
+}
+
+void RibbonConnections::init(void)
+{
+ purple_connections_set_ui_ops(&connection_uiops);
+ static int handle;
+ void *connections_handle = purple_connections_get_handle();
+
+ purple_signal_connect(connections_handle, "signed-on", &handle,
+ PURPLE_CALLBACK(signed_on), this);
+}
--- /dev/null
+#ifndef RIBBONCONNECTIONS_H
+#define RIBBONCONNECTIONS_H
+
+#include <QObject>
+#include <QVariantMap>
+#include <libpurple/purple.h>
+
+class RibbonManager;
+
+class RibbonConnections : public QObject {
+ Q_OBJECT
+public:
+ RibbonConnections(RibbonManager* parent = 0);
+ ~RibbonConnections();
+ void init(void);
+
+signals:
+ void event(QString source, QString signal, QVariantMap context);
+private:
+ RibbonManager* _manager;
+};
+
+#endif // RIBBONCONNECTIONS_H
#include "ribbonmanager.h"
#include "ribbonaccounts.h"
#include "ribbonblist.h"
+#include "ribbonconnections.h"
#include "ribbonconversations.h"
#include <QDebug>
// NULL
//};
-static QVariantMap ctx_from_account(PurpleAccount* account)
-{
- QVariantMap ctx;
- ctx["protocol"] = QVariant(purple_account_get_protocol_id(account));
- ctx["username"] = QVariant(purple_account_get_username(account));
- return ctx;
-}
-
-static void connect_progress(PurpleConnection *gc, const char* text, size_t step, size_t step_count)
-{
- PurpleAccount* account = purple_connection_get_account(gc);
- RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
- qDebug() << QString("Connection progress (%1:%2):").arg(account->protocol_id, account->username).toUtf8().constData() << text << step << "of" << step_count;
- // TODO: add enough unique information from account to ctx to handle the message
- QVariantMap ctx = ctx_from_account(account);
- ctx["step"] = QVariant((qulonglong)step);
- ctx["step_count"] = QVariant((qulonglong)step_count);
- ctx["text"] = QVariant(QString::fromUtf8(text));
- r->event(QString("connection"), QString("connect_progress"), ctx);
-}
-
-static void connection_notice(PurpleConnection *gc, const char* text)
-{
- qDebug() << "Connection notice:" << text;
- PurpleAccount* account = purple_connection_get_account(gc);
- RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
- QVariantMap ctx = ctx_from_account(account);
- ctx["message"] = QVariant(QString::fromUtf8(text));
- r->event(QString("connection"), QString("connect_notice"), ctx);
-}
-
-static void connection_disconnected(PurpleConnection *gc, const char* text)
-{
- qDebug() << "Connection disconnected:" << text;
- PurpleAccount* account = purple_connection_get_account(gc);
- RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
- QVariantMap ctx = ctx_from_account(account);
- ctx["message"] = QVariant(QString::fromUtf8(text));
- r->event(QString("connection"), QString("connection_disconnected"), ctx);
-}
-
-static void network_connected(void)
-{
- qWarning() << "Network connection established";
-}
-
-static void network_disconnected(void)
-{
- qWarning() << "This machine has been disconnected from the internet";
-}
-
-static void report_disconnect_reason(PurpleConnection *gc, PurpleConnectionError reason, const char *text)
-{
- PurpleAccount *account = purple_connection_get_account(gc);
- //qDebug() << QString("Connection disconnected: \'%1\' (%2)\n >Error: %3\n >Reason: %4\n").arg(purple_account_get_username(account), purple_account_get_protocol_id(account), qint32(reason), text);
- RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
- QVariantMap ctx = ctx_from_account(account);
- ctx["reason_code"] = QVariant(qint32(reason));
- ctx["reason_text"] = QVariant(QString::fromUtf8(text));
- r->event(QString("connection"), QString("disconnect_reason"), ctx);
-}
-
-static PurpleConnectionUiOps connection_uiops =
-{
- connect_progress, /* connect_progress */
- NULL, /* connected */
- NULL, /* disconnected */
- connection_notice, /* notice */
- connection_disconnected, /* report_disconnect */
- network_connected, /* network_connected */
- network_disconnected, /* network_disconnected */
- report_disconnect_reason, /* report_disconnect_reason */
- NULL,
- NULL,
- NULL
-};
-
static void ribbon_core_init(void) {
printf("core_init called\n");
- printf("setting connection callbacks\n");
- purple_connections_set_ui_ops(&connection_uiops);
}
static PurpleCoreUiOps ribbon_core_callbacks = {
NULL
};
-// TODO: note that the void* data can be set at purple_signal_connect time, and
-// set it to the class instance to allow for convenient upcalls
-// Then, actually do upcalls and emit the appropriate signals.
-static void signed_on(PurpleConnection *gc, void* data)
-{
- Q_UNUSED(data);
- PurpleAccount *account = purple_connection_get_account(gc);
- printf("Account connected: \"%s\" (%s)\n", purple_account_get_username(account), purple_account_get_protocol_id(account));
-}
-
-static void connect_to_signals(void)
-{
- static int handle;
- void *connections_handle = purple_connections_get_handle();
-
- purple_signal_connect(connections_handle, "signed-on", &handle,
- PURPLE_CALLBACK(signed_on), NULL);
-}
RibbonManager::RibbonManager(QObject* parent) : QObject(parent)
{
_accounts = new RibbonAccounts(this);
_blist = new RibbonBlist(this);
+ _connections = new RibbonConnections(this);
_conversations = new RibbonConversations(this);
QObject::connect(_blist, SIGNAL(event(QString,QString,QVariantMap)),
this, SIGNAL(event(QString,QString,QVariantMap)));
+ QObject::connect(_connections, SIGNAL(event(QString,QString,QVariantMap)),
+ this, SIGNAL(event(QString,QString,QVariantMap)));
QObject::connect(_conversations, SIGNAL(event(QString,QString,QVariantMap)),
this, SIGNAL(event(QString,QString,QVariantMap)));
}
abort();
}
- /* Create and load the buddylist */
- purple_set_blist(purple_blist_new());
- purple_blist_load();
-
- /* Hopefully this is an okay time for this? */
- connect_to_signals();
-
+ // set up connections first, since it has to use the callback structure
+ // whereas other things can just connect to glib signals
// TODO: add more children init() calls when refactoring
+ _connections->init();
_blist->init();
_conversations->init();
}
// Forward declarations
class RibbonAccounts;
class RibbonBlist;
+class RibbonConnections;
class RibbonConversations;
#define UI_ID "ribbon"
RibbonAccounts* accounts() { return _accounts; }
RibbonBlist* blist() { return _blist; }
RibbonConversations* conversations() { return _conversations; }
+ RibbonConnections* connections() { return _connections; }
// Exposes purple_get_version()
const char* get_version(void);
private:
RibbonAccounts* _accounts;
RibbonBlist* _blist;
+ RibbonConnections* _connections;
RibbonConversations* _conversations;
Q_DISABLE_COPY(RibbonManager)
};