From: Drew Fisher Date: Tue, 13 May 2014 05:50:26 +0000 (-0700) Subject: Add a command-line argument --state-dir for purple data X-Git-Url: https://git.zarvox.org/?a=commitdiff_plain;h=fd2e5b68d2a4ffb0859359c1bc6ee421b22e67cf;p=imoo.git Add a command-line argument --state-dir for purple data --- diff --git a/ribbon/main.cpp b/ribbon/main.cpp index 28a8886..5617fd9 100644 --- a/ribbon/main.cpp +++ b/ribbon/main.cpp @@ -1,5 +1,6 @@ //#include -#include +#include +#include #include #include @@ -11,7 +12,19 @@ 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 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(); diff --git a/ribbon/ribbonmanager.cpp b/ribbon/ribbonmanager.cpp index 8f14f34..cd2cea0 100644 --- a/ribbon/ribbonmanager.cpp +++ b/ribbon/ribbonmanager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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") { diff --git a/ribbon/ribbonmanager.h b/ribbon/ribbonmanager.h index 4438ac2..be101af 100644 --- a/ribbon/ribbonmanager.h +++ b/ribbon/ribbonmanager.h @@ -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) };