#include <QDebug>
#include <QObject>
-#include <QPushButton>
#include <signal.h>
*/
signal(SIGCHLD, SIG_IGN);
- QPushButton* b = new QPushButton("Sign in");
- b->resize(100,50);
- b->show();
-
RibbonManager* purple = new RibbonManager();
purple->init();
qDebug() << "libpurple initialized, version" << purple->get_version();
- QObject::connect(b, SIGNAL(clicked()),
- purple, SLOT(sign_in_user()));
-
RibbonServer* server = new RibbonServer();
server->listen(QHostAddress::Any, 8888);
# Input
HEADERS += ribbonmanager.h \
+ ribbonaccount.h \
+ ribbonaccounts.h \
ribbonserver.h \
ribbonsocket.h
SOURCES += ribbonmanager.cpp \
+ ribbonaccount.cpp \
+ ribbonaccounts.cpp \
ribbonserver.cpp \
ribbonsocket.cpp \
main.cpp
--- /dev/null
+#include "ribbonaccount.h"
+
+RibbonAccount RibbonAccount::fromString(QString s)
+{
+ RibbonAccount value;
+ int idx = s.indexOf(":");
+ value.protocol = s.left(idx).toUtf8();
+ value.username = s.mid(idx+1).toUtf8();
+ return value;
+}
+
+bool RibbonAccount::operator<(const RibbonAccount other) const
+{
+ if (protocol < other.protocol) return true;
+ if (protocol > other.protocol) return false;
+ return username < other.username;
+}
+
+QString RibbonAccount::toString()
+{
+ return QString("%1:%2").arg(QString::fromUtf8(protocol))
+ .arg(QString::fromUtf8(username));
+}
--- /dev/null
+#ifndef RIBBONACCOUNT_H
+#define RIBBONACCOUNT_H
+
+#include <QByteArray>
+#include <QString>
+
+class RibbonAccount {
+public:
+ static RibbonAccount fromString(QString);
+ bool operator<(const RibbonAccount other) const;
+ QString toString();
+ QByteArray protocol;
+ QByteArray username;
+};
+
+#endif // RIBBONACCOUNT_H
--- /dev/null
+#include "ribbonaccounts.h"
+
+#include <QDebug>
+
+RibbonAccounts::RibbonAccounts(RibbonManager* parent) : QObject((QObject*)parent)
+{
+ _manager = parent;
+}
+
+RibbonAccounts::~RibbonAccounts()
+{
+}
+
+void RibbonAccounts::handleExternalEvent(QString method, QVariantMap params)
+{
+ qDebug() << "called" << method << "on" << params;
+ if (method == "create_account") {
+ createAccount(params["protocol"].toByteArray(),
+ params["username"].toByteArray(),
+ params["password"].toByteArray());
+ }
+}
+
+void RibbonAccounts::createAccount(QByteArray protocol, QByteArray username, QByteArray password)
+{
+ PurpleAccount *account = purple_account_new(username.data(), protocol.data());
+
+ account->ui_data = _manager;
+ purple_account_set_password(account, password.data());
+ purple_accounts_add(account);
+ purple_account_set_enabled(account, UI_ID, TRUE);
+
+ // Save a handle to this account.
+ RibbonAccount r_acct;
+ r_acct.protocol = protocol;
+ r_acct.username = username;
+ accounts[r_acct] = account;
+}
--- /dev/null
+#ifndef RIBBONACCOUNTS_H
+#define RIBBONACCOUNTS_H
+
+#include <QObject>
+#include <QString>
+#include <QVariantMap>
+#include <QList>
+
+#include <libpurple/purple.h>
+#include "ribbonmanager.h"
+#include "ribbonaccount.h"
+
+class RibbonAccounts : public QObject {
+ Q_OBJECT
+public:
+ RibbonAccounts(RibbonManager* parent = 0);
+ ~RibbonAccounts();
+public slots:
+ void handleExternalEvent(QString method, QVariantMap params);
+private:
+ RibbonManager* _manager;
+ QMap<RibbonAccount, PurpleAccount*> accounts;
+ void createAccount(QByteArray protocol, QByteArray username, QByteArray password);
+};
+
+#endif /* RIBBONACCOUNTS_H */
#include "ribbonmanager.h"
+#include "ribbonaccounts.h"
#include <QDebug>
#include <QFile>
RibbonManager::RibbonManager(QObject* parent) : QObject(parent)
{
+ accounts = new RibbonAccounts(this);
}
RibbonManager::~RibbonManager()
{
// TODO: handle external event
qDebug() << "TODO: do something with" << destination << "." << method << "(" << context << ")";
-}
-
-void RibbonManager::sign_in_user(void)
-{
- QFile file("account.txt");
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "Couldn't load account information from account.txt!";
- return;
+ if (destination == "accounts") {
+ accounts->handleExternalEvent(method, context);
}
- QByteArray protocol = file.readLine().trimmed();//this could be prpl-aim, prpl-yahoo, prpl-msn, prpl-icq, etc.
- QByteArray username = file.readLine().trimmed();
- QByteArray password = file.readLine().trimmed();
- // Allocate and enable an account.
- PurpleAccount *account = purple_account_new(username.data(), protocol.data());
- // ui_data needed for upcalls
- account->ui_data = this;
-
- purple_account_set_password(account, password.data());
- purple_accounts_add(account);
- purple_account_set_enabled(account, UI_ID, TRUE);
}
#include <QVariantMap>
#include <libpurple/purple.h>
+// Forward declarations
+class RibbonAccounts;
+
#define UI_ID "ribbon"
class RibbonManager : public QObject {
public slots:
void handleExternalEvent(QString destination, QString method, QVariantMap context);
- void sign_in_user(void);
signals:
void event(QString source, QString signal, QVariantMap context);
private:
// TODO: add a map of currently-open conversations?
+ RibbonAccounts* accounts;
Q_DISABLE_COPY(RibbonManager)
};