HEADERS += ribbonmanager.h \
ribbonaccount.h \
ribbonaccounts.h \
+ ribbonconversations.h \
ribbonserver.h \
ribbonsocket.h
SOURCES += ribbonmanager.cpp \
ribbonaccount.cpp \
ribbonaccounts.cpp \
+ ribbonconversations.cpp \
ribbonserver.cpp \
ribbonsocket.cpp \
main.cpp
createAccount(params["protocol"].toByteArray(),
params["username"].toByteArray(),
params["password"].toByteArray());
+ } else if (method == "destroy_account") {
+ destroyAccount(RibbonAccount::fromString(params["account_id"].toString()));
}
}
r_acct.username = username;
accounts[r_acct] = account;
}
+
+void RibbonAccounts::destroyAccount(RibbonAccount r_acct)
+{
+ if (accounts.contains(r_acct)) {
+ qDebug() << "Deleting" << r_acct.toString();
+ PurpleAccount* account = accounts.take(r_acct);
+ purple_account_destroy(account);
+ }
+}
~RibbonAccounts();
public slots:
void handleExternalEvent(QString method, QVariantMap params);
+signals:
+ void event(QString source, QString signal, QVariantMap context);
private:
RibbonManager* _manager;
QMap<RibbonAccount, PurpleAccount*> accounts;
void createAccount(QByteArray protocol, QByteArray username, QByteArray password);
+ void destroyAccount(RibbonAccount r_acct);
};
#endif /* RIBBONACCOUNTS_H */
--- /dev/null
+#include "ribbonconversations.h"
+#include "ribbonmanager.h"
+
+#include <QDebug>
+#include <QDateTime>
+
+static void static_received_im_msg(PurpleAccount *account, char *sender, char *message,
+ PurpleConversation *conv, PurpleMessageFlags flags, void* data)
+{
+ Q_UNUSED(data);
+ RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
+ r->conversations()->received_im_msg(account, sender, message, conv, flags);
+}
+
+RibbonConversations::RibbonConversations(RibbonManager* parent) : QObject((QObject*)parent)
+{
+ _manager = parent;
+}
+
+RibbonConversations::~RibbonConversations()
+{
+}
+
+void RibbonConversations::init()
+{
+ static int handle;
+ void *conversations_handle = purple_conversations_get_handle();
+ purple_signal_connect(conversations_handle, "received-im-msg", &handle,
+ PURPLE_CALLBACK(static_received_im_msg), NULL);
+}
+
+void RibbonConversations::received_im_msg(PurpleAccount *account,
+ char *sender, char *message, PurpleConversation *conv,
+ PurpleMessageFlags flags) {
+ Q_UNUSED(flags);
+ if (conv==NULL) {
+ conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sender);
+ }
+ qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << sender << purple_conversation_get_name(conv) << message;
+}
--- /dev/null
+#ifndef RIBBONCONVERSATIONS_H
+#define RIBBONCONVERSATIONS_H
+
+#include <QObject>
+#include <QString>
+#include <QVariantMap>
+#include <libpurple/purple.h>
+
+class RibbonManager;
+
+class RibbonConversations : public QObject {
+ Q_OBJECT
+public:
+ RibbonConversations(RibbonManager* parent = 0);
+ ~RibbonConversations();
+ void init();
+ void received_im_msg(PurpleAccount *account, char *sender, char *message,
+ PurpleConversation *conv, PurpleMessageFlags flags);
+signals:
+ void event(QString source, QString signal, QVariantMap context);
+private:
+ RibbonManager* _manager;
+};
+
+#endif /* RIBBONCONVERSATIONS_H */
#include "ribbonmanager.h"
#include "ribbonaccounts.h"
+#include "ribbonconversations.h"
#include <QDebug>
#include <QFile>
printf("Account connected: \"%s\" (%s)\n", purple_account_get_username(account), purple_account_get_protocol_id(account));
}
-static void received_im_msg(PurpleAccount *account, char *sender, char *message,
- PurpleConversation *conv, PurpleMessageFlags flags, void* data)
-{
- Q_UNUSED(data);
- RibbonManager* r = static_cast<RibbonManager*>(account->ui_data);
- r->received_im_msg(account, sender, message, conv, flags);
-}
-
static void buddy_signed_on(PurpleBuddy* buddy, void* data)
{
Q_UNUSED(data);
static int handle;
void *blist_handle = purple_blist_get_handle();
void *connections_handle = purple_connections_get_handle();
- void *conversations_handle = purple_conversations_get_handle();
purple_signal_connect(connections_handle, "signed-on", &handle,
PURPLE_CALLBACK(signed_on), NULL);
- purple_signal_connect(conversations_handle, "received-im-msg", &handle,
- PURPLE_CALLBACK(received_im_msg), NULL);
purple_signal_connect(blist_handle, "buddy-signed-on", &handle,
PURPLE_CALLBACK(buddy_signed_on), NULL);
- //purple_signal_connect(
}
RibbonManager::RibbonManager(QObject* parent) : QObject(parent)
{
- accounts = new RibbonAccounts(this);
+ _accounts = new RibbonAccounts(this);
+ _conversations = new RibbonConversations(this);
+ QObject::connect(_conversations, SIGNAL(event(QString,QString,QVariantMap)),
+ this, SIGNAL(event(QString,QString,QVariantMap)));
}
RibbonManager::~RibbonManager()
/* Hopefully this is an okay time for this? */
connect_to_signals();
+
+ // TODO: add more children init() calls when refactoring
+ _conversations->init();
}
const char* RibbonManager::get_version(void)
return purple_core_get_version();
}
-void RibbonManager::received_im_msg(PurpleAccount *account, char *sender, char *message,
- PurpleConversation *conv, PurpleMessageFlags flags) {
- Q_UNUSED(flags);
- if (conv==NULL) {
- conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sender);
- }
- qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << sender << purple_conversation_get_name(conv) << message;
-}
-
void RibbonManager::handleExternalEvent(QString destination, QString method, QVariantMap context)
{
// TODO: handle external event
qDebug() << "TODO: do something with" << destination << "." << method << "(" << context << ")";
if (destination == "accounts") {
- accounts->handleExternalEvent(method, context);
+ _accounts->handleExternalEvent(method, context);
}
}
// Forward declarations
class RibbonAccounts;
+class RibbonConversations;
#define UI_ID "ribbon"
// Called to configure libpurple and connect to purple signals
void init(void);
+ RibbonAccounts* accounts() { return _accounts; }
+ RibbonConversations* conversations() { return _conversations; }
// Exposes purple_get_version()
const char* get_version(void);
- // Event handlers
- void received_im_msg(PurpleAccount* account, char* sender, char* message, PurpleConversation* conv, PurpleMessageFlags flags);
-
public slots:
void handleExternalEvent(QString destination, QString method, QVariantMap context);
void event(QString source, QString signal, QVariantMap context);
private:
- // TODO: add a map of currently-open conversations?
- RibbonAccounts* accounts;
+ RibbonAccounts* _accounts;
+ RibbonConversations* _conversations;
Q_DISABLE_COPY(RibbonManager)
};