forked from DanielBorgesOliveira/onedrive_tray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (65 loc) · 2.89 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <QApplication>
#include <QDebug>
#ifndef QT_NO_SYSTEMTRAYICON
#include <QMessageBox>
#include <libgen.h>
#include <window.h>
#include <iconinfo.h>
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(systray);
QApplication app(argc, argv);
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
app.setOrganizationName("onedrive_tray");
app.setApplicationName("onedrive_tray");
app.setApplicationDisplayName("System tray for OneDrive");
app.setApplicationVersion("2.0");
app.setWindowIcon(QIcon(IconInfo::onedriveIconPathName()));
// Define the command line parameters
QCommandLineParser parser;
parser.setApplicationDescription("Run and control OneDrive from the system tray");
parser.addHelpOption();
QCommandLineOption onedrivePathOption(QStringList() << "p" << "onedrive-path", "Path to the OneDrive program", "path");
parser.addOption(onedrivePathOption);
QCommandLineOption onedriveArgsOption(QStringList() << "a" << "onedrive-args", "Arguments passed to OneDrive", "args");
parser.addOption(onedriveArgsOption);
QCommandLineOption silentFailOption(QStringList() << "s" << "silent-fail", "No error message displayed when no system tray is detected");
parser.addOption(silentFailOption);
parser.process(app);
QString onedrivePath = parser.value(onedrivePathOption);
QString onedriveArgs = parser.value(onedriveArgsOption);
bool silent = parser.isSet(silentFailOption);
// Translator of predefined Qt objects (QColorDialog for example)
QTranslator qtTranslator;
if (qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
app.installTranslator(&qtTranslator);
// Translator of the application
QTranslator appTranslator;
// Loads path + filename + prefix + ui language name + suffix (".qm" if the suffix is not specified)
if (appTranslator.load(QLocale(), app.applicationName(), "_", app.applicationDirPath()))
app.installTranslator(&appTranslator);
else
qDebug().noquote() << "Translation not found for" << QLocale().languageToString(QLocale().language()) << "language" << QLocale().uiLanguages() << ".";
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
if (!silent) {
QMessageBox::critical(0, QObject::tr("OneDrive"), QObject::tr("I couldn't detect any system tray on this system."));
}
return 1;
}
QApplication::setQuitOnLastWindowClosed(false);
Window window(onedrivePath, onedriveArgs);
return app.exec();
}
#else
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString text("QSystemTrayIcon is not supported on this platform");
QLabel *label = new QLabel(text);
label->setWordWrap(true);
label->show();
qDebug() << text;
app.exec();
}
#endif