Skip to content

Commit

Permalink
Adds CLI compatibility with older QT versions
Browse files Browse the repository at this point in the history
  • Loading branch information
drognanar committed Aug 25, 2014
1 parent 6105d91 commit 6e58698
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions zeal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#include <QApplication>
#include <QLocalSocket>
#include <QProxyStyle>
#include <QCommandLineParser>

#include <string>
#include <iostream>

using namespace std;

#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
#include <QCommandLineParser>

// Sets up the command line parser.
// TODO: make compatible with older versions of QT.
void setupOptionParser(QCommandLineParser *parser) {
parser->setApplicationDescription("zeal - Offline documentation browser.");
parser->addHelpOption();
Expand All @@ -22,6 +23,7 @@ void setupOptionParser(QCommandLineParser *parser) {
"Force the application run.");
parser->addOption(forceRun);
}
#endif

#ifdef WIN32
class ZealProxyStyle : public QProxyStyle {
Expand All @@ -44,16 +46,24 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
QApplication::setApplicationName("zeal");
QApplication::setApplicationVersion(ZEAL_VERSION);
QCommandLineParser optionParser;
setupOptionParser(&optionParser);
optionParser.process(a);
#ifdef WIN32
a.setStyle(new ZealProxyStyle);
#endif

#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
QCommandLineParser optionParser;
setupOptionParser(&optionParser);
optionParser.process(a);
// Extract the command line flags.
QString queryParam = optionParser.value("query");
bool runForce = optionParser.isSet("force");
#else
QString queryParam;
if (argc > 2 && QString(argv[1]) == "--query") {
queryParam = argv[2];
}
bool runForce = false;
#endif

// detect already running instance and optionally pass a search
// query onto it.
Expand Down

0 comments on commit 6e58698

Please sign in to comment.