-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (53 loc) · 1.73 KB
/
Copy pathmain.cpp
File metadata and controls
70 lines (53 loc) · 1.73 KB
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
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <DApplication>
#include <DLog>
#include <PolkitQt1/Subject>
#include "policykitlistener.h"
#include "accessible.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
DWIDGET_USE_NAMESPACE
DCORE_USE_NAMESPACE
#define APP_NAME "dde-polkit-agent"
#define APP_DISPLAY_NAME "Deepin Polkit Agent"
#define AUTH_DBUS_PATH "/com/deepin/dde/Polkit1/AuthAgent"
int main(int argc, char *argv[])
{
DApplication a(argc, argv);
a.setOrganizationName("deepin");
a.setApplicationName(APP_NAME);
a.setApplicationDisplayName(APP_DISPLAY_NAME);
a.setApplicationVersion("0.1");
a.setQuitOnLastWindowClosed(false);
QAccessible::installFactory(accessibleFactory);
DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
if (!a.setSingleInstance(APP_NAME, DApplication::UserScope)) {
qWarning() << "polkit is running!";
return 0;
}
PolkitQt1::UnixSessionSubject session(getpid());
PolicyKitListener listener;
if (!listener.registerListener(session, AUTH_DBUS_PATH)) {
qWarning() << "register listener failed!";
return -1;
}
// create PID file to ~/.cache/deepin/dde-polkit-agent
const QString cachePath = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
QDir dir(cachePath);
if (!dir.exists()) {
dir.mkpath(cachePath);
}
QFile PID(cachePath + QDir::separator() + "pid");
if (PID.open(QIODevice::WriteOnly)) {
QTextStream out(&PID);
out << getpid();
PID.close();
}
a.loadTranslator();
return a.exec();
}