]> git.zarvox.org Git - imoo.git/commitdiff
Add a command-line argument --state-dir for purple data
authorDrew Fisher <drew.m.fisher@gmail.com>
Tue, 13 May 2014 05:50:26 +0000 (22:50 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Tue, 13 May 2014 05:50:50 +0000 (22:50 -0700)
ribbon/main.cpp
ribbon/ribbonmanager.cpp
ribbon/ribbonmanager.h

index 28a88868b167bd13e0f5f145a5f9f44430dfe09c..5617fd949a2f0474021d55684b7037f556ea9631 100644 (file)
@@ -1,5 +1,6 @@
 //#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
@@ -21,7 +34,8 @@ int main(int argc, char** argv)
        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();
 
index 8f14f349949e04a5bda0c5bf429a19ba8b5757dc..cd2cea062f9f98853c15b21720e9baeb0a2f4dd2 100644 (file)
@@ -7,6 +7,7 @@
 #include <QDebug>
 #include <QFile>
 #include <QDateTime>
+#include <QStandardPaths>
 #include <libpurple/purple.h>
 #include <cstdio>
 
@@ -142,11 +143,16 @@ RibbonManager::~RibbonManager()
 {
 }
 
-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);
@@ -177,6 +183,11 @@ const char* RibbonManager::get_version(void)
        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") {
index 4438ac2f4b4759d7a48e528ae104dea75a4b82fc..be101afbc98f62045700af3af34f4a073f3be32e 100644 (file)
@@ -20,7 +20,7 @@ public:
        ~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; }
@@ -28,6 +28,7 @@ public:
 
        // Exposes purple_get_version()
        const char* get_version(void);
+       QString get_state_dir(void);
 
 public slots:
        void handleExternalEvent(QString destination, QString method, QVariantMap context);
@@ -40,6 +41,7 @@ private:
        RibbonBlist* _blist;
        RibbonConnections* _connections;
        RibbonConversations* _conversations;
+       QString _state_dir;
        Q_DISABLE_COPY(RibbonManager)
 };