forked from linuxdeepin/dde-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
102 lines (80 loc) · 2.95 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <gtk/gtk.h>
#include "mainframe.h"
#include "dbuslauncherframe.h"
#include "model/appsmanager.h"
#include "dbusservices/dbuslauncherservice.h"
#include <QCommandLineParser>
#include <QTranslator>
#include <unistd.h>
#include <dapplication.h>
#include <DLog>
DWIDGET_USE_NAMESPACE
DUTIL_USE_NAMESPACE
#define PROP_GTK_ICON_THEME_NAME "gtk-icon-theme-name"
void iconThemeChanged(GtkSettings *gsettings, GParamSpec *pspec, gpointer udata)
{
Q_UNUSED(gsettings)
Q_UNUSED(udata)
Q_ASSERT(!strcmp(g_param_spec_get_name(pspec), PROP_GTK_ICON_THEME_NAME));
AppsManager::instance()->refreshAppIconCache();
}
int main(int argv, char *args[])
{
DApplication::loadDXcbPlugin();
DApplication app(argv, args);
app.setQuitOnLastWindowClosed(false);
app.setOrganizationName("deepin");
app.setApplicationName("dde-launcher");
app.setApplicationVersion("3.0");
#ifdef QT_DEBUG
DLogManager::registerConsoleAppender();
#else
DLogManager::registerFileAppender();
#endif
const bool quit = !app.setSingleInstance(QString("dde-launcher_%1").arg(getuid()));
QCommandLineOption showOption(QStringList() << "s" << "show", "show launcher(hide for default.)");
QCommandLineOption toggleOption(QStringList() << "t" << "toggle", "toggle launcher visible.");
QCommandLineParser cmdParser;
cmdParser.setApplicationDescription("DDE Launcher");
cmdParser.addHelpOption();
cmdParser.addVersionOption();
cmdParser.addOption(showOption);
cmdParser.addOption(toggleOption);
// cmdParser.addPositionalArgument("mode", "show and toogle to <mode>");
cmdParser.process(app);
// QStringList positionArgs = cmdParser.positionalArguments();
if (quit)
{
DBusLauncherFrame launcherFrame;
do {
if (!launcherFrame.isValid())
break;
if (cmdParser.isSet(toggleOption))
launcherFrame.Toggle();
else if (cmdParser.isSet(showOption))
launcherFrame.Show();
} while (false);
return 0;
}
// INFO: what's this?
setlocale(LC_ALL, "");
QTranslator translator;
translator.load("/usr/share/dde-launcher/translations/dde-launcher_" +
QLocale::system().name() + ".qm");
app.installTranslator(&translator);
MainFrame launcher;
DBusLauncherService service(&launcher);
Q_UNUSED(service);
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerService("com.deepin.dde.Launcher") ||
!connection.registerObject("/com/deepin/dde/Launcher", &launcher))
qWarning() << "register dbus service failed";
#ifndef QT_DEBUG
if (/*!positionArgs.isEmpty() && */cmdParser.isSet(showOption))
#endif
launcher.show();
// monitor gtk icon theme changed
GtkSettings *gs = gtk_settings_get_default();
g_signal_connect(gs, "notify::" PROP_GTK_ICON_THEME_NAME, G_CALLBACK(iconThemeChanged), NULL);
return app.exec();
}