1
#include "ui/mainwindow.h"
3
#include <QApplication>
4
#include <QCommandLineParser>
6
#include <QLocalSocket>
7
#include <QStandardPaths>
11
#include <QProxyStyle>
12
#include <QStyleOption>
15
struct CommandLineParameters
21
CommandLineParameters parseCommandLine(const QCoreApplication &app)
23
QCommandLineParser parser;
24
parser.setApplicationDescription(QObject::tr("Zeal - Offline documentation browser."));
25
parser.addHelpOption();
26
parser.addVersionOption();
28
/// TODO: [Qt 5.4] parser.addOption({{"f", "force"}, "Force the application run."});
29
parser.addOption(QCommandLineOption({QStringLiteral("f"), QStringLiteral("force")},
30
QObject::tr("Force the application run.")));
31
parser.addOption(QCommandLineOption({QStringLiteral("q"), QStringLiteral("query")},
32
QObject::tr("Query <search term>."),
33
QStringLiteral("term")));
37
parser.isSet(QStringLiteral("force")),
38
parser.value(QStringLiteral("query"))
42
/// TODO: Verify if this bug still exists in Qt 5.2+
44
class ZealProxyStyle : public QProxyStyle
47
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter,
48
const QWidget *widget = 0) const
50
if (element == PE_FrameLineEdit && option->styleObject) {
51
option->styleObject->setProperty("_q_no_animation", true);
52
// Workaround for a probable bug in QWindowsVistaStyle - for example opening the 'String (CommandEvent)'
53
// item from wxPython docset (available at http://wxpython.org/Phoenix/docsets) causes very high CPU usage.
54
// Some rough debugging shows that the 'd->startAnimation(t);' call in QWindowsVistaStyle::drawPrimitive
55
// is the cuplrit and setting _q_no_animation to true here fixes the issue.
57
return QProxyStyle::drawPrimitive(element, option, painter, widget);
62
int main(int argc, char *argv[])
64
QCoreApplication::setApplicationName(QStringLiteral("Zeal"));
65
QCoreApplication::setApplicationVersion(ZEAL_VERSION);
66
QCoreApplication::setOrganizationDomain(QStringLiteral("zealdocs.org"));
67
QCoreApplication::setOrganizationName(QStringLiteral("Zeal"));
69
QApplication qapp(argc, argv);
72
qapp.setStyle(new ZealProxyStyle());
75
const CommandLineParameters clParams = parseCommandLine(qapp);
77
// Detect already running instance and optionally pass a search query to it.
78
if (!clParams.force) {
79
QScopedPointer<QLocalSocket> socket(new QLocalSocket());
80
socket->connectToServer(serverName);
82
if (socket->waitForConnected(500)) {
83
if (!clParams.query.isEmpty()) {
84
socket->write(clParams.query.toLocal8Bit());
87
QTextStream(stdout) << QObject::tr("Already running. Terminating.") << endl;
95
// 1. user's data directory (same as docsets dir, but in icons/)
96
// 2. executable directory/icons
97
// 3. on unix, standard/legacy install location
98
// 4. current directory/icons
99
QStringList searchPaths;
100
searchPaths << QStandardPaths::locateAll(QStandardPaths::DataLocation, QStringLiteral("icons"),
101
QStandardPaths::LocateDirectory);
102
searchPaths << QDir(QCoreApplication::applicationDirPath())
103
.absoluteFilePath(QStringLiteral("icons"));
105
searchPaths << QStringLiteral("/usr/share/pixmaps/zeal");
107
searchPaths << QStringLiteral("./icons");
108
QDir::setSearchPaths(QStringLiteral("icons"), searchPaths);
110
QScopedPointer<MainWindow> mainWindow(new MainWindow());
112
if (!mainWindow->startHidden())
115
if (!clParams.query.isEmpty())
116
mainWindow->bringToFrontAndSearch(clParams.query);