From 8e8e4771387b6c3b58470670409c880d46129702 Mon Sep 17 00:00:00 2001 From: Drew Fisher Date: Fri, 25 Apr 2014 23:39:52 -0700 Subject: [PATCH] ribbon: extract blist into separate class --- ribbon/ribbon.pro | 2 ++ ribbon/ribbonblist.cpp | 27 +++++++++++++++++++++++++++ ribbon/ribbonblist.h | 25 +++++++++++++++++++++++++ ribbon/ribbonmanager.cpp | 14 +++++--------- ribbon/ribbonmanager.h | 3 +++ 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 ribbon/ribbonblist.cpp create mode 100644 ribbon/ribbonblist.h diff --git a/ribbon/ribbon.pro b/ribbon/ribbon.pro index 2e19c40..8f5cd7a 100644 --- a/ribbon/ribbon.pro +++ b/ribbon/ribbon.pro @@ -19,6 +19,7 @@ QMAKE_CXXFLAGS += -Werror -W HEADERS += ribbonmanager.h \ ribbonaccount.h \ ribbonaccounts.h \ + ribbonblist.h \ ribbonconversations.h \ ribbonserver.h \ ribbonsocket.h @@ -26,6 +27,7 @@ HEADERS += ribbonmanager.h \ SOURCES += ribbonmanager.cpp \ ribbonaccount.cpp \ ribbonaccounts.cpp \ + ribbonblist.cpp \ ribbonconversations.cpp \ ribbonserver.cpp \ ribbonsocket.cpp \ diff --git a/ribbon/ribbonblist.cpp b/ribbon/ribbonblist.cpp new file mode 100644 index 0000000..6f45df1 --- /dev/null +++ b/ribbon/ribbonblist.cpp @@ -0,0 +1,27 @@ +#include "ribbonblist.h" +#include "ribbonmanager.h" + +#include + +RibbonBlist::RibbonBlist(RibbonManager* parent) : QObject((QObject*)parent) +{ + _manager = parent; +} + +RibbonBlist::~RibbonBlist() +{ +} + +static void buddy_signed_on(PurpleBuddy* buddy, void* data) +{ + Q_UNUSED(data); + qDebug() << purple_buddy_get_contact_alias(buddy) << "signed on"; +} + +void RibbonBlist::init() +{ + static int handle; + void *blist_handle = purple_blist_get_handle(); + purple_signal_connect(blist_handle, "buddy-signed-on", &handle, + PURPLE_CALLBACK(buddy_signed_on), NULL); +} diff --git a/ribbon/ribbonblist.h b/ribbon/ribbonblist.h new file mode 100644 index 0000000..87bcfe0 --- /dev/null +++ b/ribbon/ribbonblist.h @@ -0,0 +1,25 @@ +#ifndef RIBBONBLIST_H +#define RIBBONBLIST_H + +#include +#include +#include + +class RibbonManager; + +class RibbonBlist : public QObject { + Q_OBJECT +public: + RibbonBlist(RibbonManager* parent = 0); + ~RibbonBlist(); + + void init(); +signals: + void event(QString source, QString signal, QVariantMap context); + +private: + RibbonManager* _manager; + +}; + +#endif // RIBBONBLIST_H diff --git a/ribbon/ribbonmanager.cpp b/ribbon/ribbonmanager.cpp index 074afd5..7a56a3b 100644 --- a/ribbon/ribbonmanager.cpp +++ b/ribbon/ribbonmanager.cpp @@ -1,5 +1,6 @@ #include "ribbonmanager.h" #include "ribbonaccounts.h" +#include "ribbonblist.h" #include "ribbonconversations.h" #include @@ -210,28 +211,22 @@ static void signed_on(PurpleConnection *gc, void* data) printf("Account connected: \"%s\" (%s)\n", purple_account_get_username(account), purple_account_get_protocol_id(account)); } -static void buddy_signed_on(PurpleBuddy* buddy, void* data) -{ - Q_UNUSED(data); - qDebug() << purple_buddy_get_contact_alias(buddy) << "signed on"; -} - static void connect_to_signals(void) { static int handle; - void *blist_handle = purple_blist_get_handle(); void *connections_handle = purple_connections_get_handle(); purple_signal_connect(connections_handle, "signed-on", &handle, PURPLE_CALLBACK(signed_on), NULL); - purple_signal_connect(blist_handle, "buddy-signed-on", &handle, - PURPLE_CALLBACK(buddy_signed_on), NULL); } RibbonManager::RibbonManager(QObject* parent) : QObject(parent) { _accounts = new RibbonAccounts(this); + _blist = new RibbonBlist(this); _conversations = new RibbonConversations(this); + QObject::connect(_blist, 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))); } @@ -270,6 +265,7 @@ void RibbonManager::init(void) connect_to_signals(); // TODO: add more children init() calls when refactoring + _blist->init(); _conversations->init(); } diff --git a/ribbon/ribbonmanager.h b/ribbon/ribbonmanager.h index 58e460b..171dfef 100644 --- a/ribbon/ribbonmanager.h +++ b/ribbon/ribbonmanager.h @@ -7,6 +7,7 @@ // Forward declarations class RibbonAccounts; +class RibbonBlist; class RibbonConversations; #define UI_ID "ribbon" @@ -20,6 +21,7 @@ public: // Called to configure libpurple and connect to purple signals void init(void); RibbonAccounts* accounts() { return _accounts; } + RibbonBlist* blist() { return _blist; } RibbonConversations* conversations() { return _conversations; } // Exposes purple_get_version() @@ -33,6 +35,7 @@ signals: private: RibbonAccounts* _accounts; + RibbonBlist* _blist; RibbonConversations* _conversations; Q_DISABLE_COPY(RibbonManager) }; -- 2.39.5