//#include <QtCore/QCoreApplication>
-#include <QtGui/QApplication>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QCommandLineParser>
#include <QDebug>
#include <QObject>
int main(int argc, char** argv)
{
- QApplication* app = new QApplication(argc, argv);
+ QCoreApplication* app = new QCoreApplication(argc, argv);
+ QCoreApplication::setApplicationName("ribbon");
+ QCoreApplication::setApplicationVersion("0.0.1");
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("libpurple controlled over a socket");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption state_dir(QStringList() << "d" << "state-dir",
+ "Use <directory> for state.", "directory");
+ parser.addOption(state_dir);
+ parser.process(*app);
+
//GMainLoop *loop = g_main_loop_new(NULL, FALSE);
/* libpurple's built-in DNS resolution forks processes to perform
signal(SIGCHLD, SIG_IGN);
RibbonManager* purple = new RibbonManager();
- purple->init();
+ QString prpl_state_dir = parser.value(state_dir);
+ purple->init(prpl_state_dir);
qDebug() << "libpurple initialized, version" << purple->get_version();
#include <QDebug>
#include <QFile>
#include <QDateTime>
+#include <QStandardPaths>
#include <libpurple/purple.h>
#include <cstdio>
{
}
-void RibbonManager::init(void)
+void RibbonManager::init(QString custom_dir)
{
- /* optional:
- purple_util_set_user_dir(CUSTOM_USER_DIRECTORY);
- */
+ /* optional: */
+ if (!custom_dir.isEmpty() ) {
+ purple_util_set_user_dir(custom_dir.toUtf8().constData());
+ _state_dir = custom_dir;
+ } else {
+ _state_dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QString("/.purple");
+ }
+ qDebug() << "Using state dir" << _state_dir;
/* Enable debugging messages */
purple_debug_set_enabled(FALSE);
return purple_core_get_version();
}
+QString RibbonManager::get_state_dir(void)
+{
+ return _state_dir;
+}
+
void RibbonManager::handleExternalEvent(QString destination, QString method, QVariantMap context)
{
if (destination == "accounts") {
~RibbonManager();
// Called to configure libpurple and connect to purple signals
- void init(void);
+ void init(QString state_dir);
RibbonAccounts* accounts() { return _accounts; }
RibbonBlist* blist() { return _blist; }
RibbonConversations* conversations() { return _conversations; }
// Exposes purple_get_version()
const char* get_version(void);
+ QString get_state_dir(void);
public slots:
void handleExternalEvent(QString destination, QString method, QVariantMap context);
RibbonBlist* _blist;
RibbonConnections* _connections;
RibbonConversations* _conversations;
+ QString _state_dir;
Q_DISABLE_COPY(RibbonManager)
};