-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
70 lines (62 loc) · 1.94 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
#include <QApplication>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QLocale>
#include <QSystemTrayIcon>
#include <QTranslator>
#include <QWindow>
#include "mainwindow.h"
#include "singleapp.h"
#include "traymenu.h"
int main(int argc, char* argv[]) {
auto dbus = QDBusConnection::sessionBus();
shutter::SingleApp single;
dbus.registerObject("/org/shutter_project/Shutter", &single,
QDBusConnection::ExportAllContents);
// TODO startup is racy, because here SingleApp is not yet connected to
// MainWindow. Maybe split D-Bus service to separate lock service and actual
// messaging service?
if (!dbus.registerService("org.shutter-project.ShutterQt")) {
// TODO define the interface in xml and use qdbusxml2cpp instead of
// ExportAllContents
QDBusInterface i("org.shutter-project.ShutterQt",
"/org/shutter_project/Shutter");
i.call("raise");
return 0;
}
QApplication a(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString& locale : uiLanguages) {
const QString baseName = "shutter_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
shutter::TrayMenu menu;
QSystemTrayIcon icon(QPixmap(":/shutter/icons/shutter.svg"));
icon.setContextMenu(&menu);
icon.show();
shutter::MainWindow w;
QObject::connect(&single, &shutter::SingleApp::raised, [&] {
auto f = w.windowFlags();
w.setWindowFlags(f | Qt::WindowStaysOnTopHint |
Qt::X11BypassWindowManagerHint);
w.setWindowFlags(f);
w.show();
w.activateWindow();
});
QObject::connect(&icon, &QSystemTrayIcon::activated,
[&](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger) {
if (w.isVisible()) {
w.hide();
} else {
w.show();
}
}
});
w.show();
return a.exec();
}