1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
Adds parsing for command-line arguments/flags
This commit is contained in:
zero-one 2014-11-11 15:58:20 -08:00
parent 2b7a0e0d95
commit 64f9a24ce6

View File

@ -21,11 +21,12 @@
#include "src/widget/toxsave.h" #include "src/widget/toxsave.h"
#include "src/autoupdate.h" #include "src/autoupdate.h"
#include <QApplication> #include <QApplication>
#include <QFontDatabase> #include <QCommandLineParser>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QDateTime> #include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFontDatabase>
#include <QMutexLocker> #include <QMutexLocker>
#include <sodium.h> #include <sodium.h>
@ -57,6 +58,15 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationName("qTox"); a.setApplicationName("qTox");
a.setOrganizationName("Tox"); a.setOrganizationName("Tox");
a.setApplicationVersion("\nGit commit: " + QString(GIT_VERSION));
// Process arguments
QCommandLineParser parser;
parser.setApplicationDescription("qTox, version: " + QString(GIT_VERSION) + "\nBuilt: " + __TIME__ + " " + __DATE__);
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("uri", QObject::tr("Tox URI to parse"));
parser.process(a);
Settings::getInstance(); // Build our Settings singleton as soon as QApplication is ready, not before Settings::getInstance(); // Build our Settings singleton as soon as QApplication is ready, not before
@ -101,10 +111,9 @@ int main(int argc, char *argv[])
ipc.registerEventHandler(&toxURIEventHandler); ipc.registerEventHandler(&toxURIEventHandler);
ipc.registerEventHandler(&toxSaveEventHandler); ipc.registerEventHandler(&toxSaveEventHandler);
// Process arguments if (parser.positionalArguments().size() > 0)
if (argc >= 2)
{ {
QString firstParam(argv[1]); QString firstParam(parser.positionalArguments()[0]);
// Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit // Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit
// Otherwise we start a new qTox instance and process it ourselves // Otherwise we start a new qTox instance and process it ourselves
if (firstParam.startsWith("tox:")) if (firstParam.startsWith("tox:"))