forked from linuxdeepin/dde-device-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·113 lines (94 loc) · 3.37 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
103
104
105
106
107
108
109
110
111
112
113
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <DApplication>
#include <QDesktopWidget>
#include <DLog>
#include <QDebug>
#include <QFile>
#include <QTranslator>
#include <QLocale>
#include <QIcon>
#include <QDBusMetaType>
#include "app/cmdmanager.h"
#include "view/mainwindow.h"
#include "dplatformwindowhandle.h"
#include "dialogs/messagedialog.h"
#include "app/singletonapp.h"
#include "utils/udisksutils.h"
#include <QProcessEnvironment>
#include <QX11Info>
#include <X11/Xlib.h>
DCORE_USE_NAMESPACE
//DWIDGET_BEGIN_NAMESPACE
#include <pwd.h>
int main(int argc, char *argv[])
{
//Logger
DLogManager::registerConsoleAppender();
qDBusRegisterMetaType<QPair<bool,QString>>();
qDBusRegisterMetaType<QByteArrayList>();
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
bool isWayland = false;
if (XDG_SESSION_TYPE == QLatin1String("wayland") ||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
isWayland = true;
}
//Load DXcbPlugin
if (!isWayland)
DApplication::loadDXcbPlugin();
DApplication a(argc, argv);
//Singleton app handle
bool isSingletonApp = SingletonApp::instance()->setSingletonApplication("dde-device-formatter");
if(!isSingletonApp)
return 0;
//Load translation
QTranslator *translator = new QTranslator(QCoreApplication::instance());
translator->load("/usr/share/dde-device-formatter/translations/dde-device-formatter_"
+QLocale::system().name()+".qm");
a.installTranslator(translator);
a.setOrganizationName("deepin");
a.setApplicationName(QObject::tr("dde device formatter"));
a.setApplicationVersion("1.0");
a.setWindowIcon(QIcon::fromTheme("dde-file-manager", QIcon::fromTheme("system-file-manager")));
a.setQuitOnLastWindowClosed(true);
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
//Command line
CMDManager::instance()->process(a);
// Check if we need display help text.
if (CMDManager::instance()->positionalArguments().isEmpty()) {
CMDManager::instance()->showHelp();
}
//Check if exists path
const QString path = CMDManager::instance()->getPath();
if (path.isEmpty() || !path.startsWith("/dev/") || !QFile::exists(path)) {
QString message = QObject::tr("Device does not exist");
MessageDialog d(message, 0);
d.exec();
return 0;
}
//Check if the device is read-only
UDisksBlock blk(path);
if (blk.isReadOnly()){
QString message = QObject::tr("The device is read-only");
MessageDialog d(message, 0);
d.exec();
return 0;
}
MainWindow* w = new MainWindow(path);
w->show();
QRect rect = w->geometry();
rect.moveCenter(qApp->desktop()->screenGeometry(w).center());
w->move(rect.x(), rect.y());
if(CMDManager::instance()->isSet("m")){
int parentWinId = CMDManager::instance()->getWinId();
int winId = w->winId();
if(parentWinId != -1)
if (!isWayland)
qDebug() << XSetTransientForHint(QX11Info::display(), (Window)winId, (Window)parentWinId);
}
int code = a.exec();
quick_exit(code);
}