-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathlaunchercontroller.cpp
More file actions
234 lines (193 loc) · 6.4 KB
/
launchercontroller.cpp
File metadata and controls
234 lines (193 loc) · 6.4 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "launchercontroller.h"
#include <QDir>
#include <QTimer>
#include <QSettings>
#include <QStandardPaths>
#include <DGuiApplicationHelper>
#include <QCommandLineParser>
#include <launcher1adaptor.h>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QLoggingCategory>
#include <private/qguiapplication_p.h>
DGUI_USE_NAMESPACE
namespace {
Q_LOGGING_CATEGORY(logController, "org.deepin.dde.launchpad.controller")
}
LauncherController::LauncherController(QObject *parent)
: QObject(parent)
, optShow(QStringList{"s", "show"}, tr("Show launcher (hidden by default)"))
, optToggle(QStringList{"t", "toggle"}, tr("Toggle launcher visibility"))
, m_timer(new QTimer(this))
, m_launcher1Adaptor(new Launcher1Adaptor(this))
, m_visible(false)
{
// TODO: settings should be managed in somewhere else.
const QString settingBasePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
const QString settingPath(QDir(settingBasePath).absoluteFilePath("settings.ini"));
QSettings settings(settingPath, QSettings::NativeFormat);
m_currentFrame = settings.value("current_frame", "WindowedFrame").toString();
qCInfo(logController) << "Current frame mode:" << m_currentFrame;
// Interval set to 500=>1000ms for issue https://github.com/linuxdeepin/developer-center/issues/8137
m_timer->setInterval(1000);
m_timer->setSingleShot(true);
connect(m_timer, &QTimer::timeout, this, [this] {
if (m_pendingHide) {
m_pendingHide = false;
setVisible(false);
}
});
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::newProcessInstance,
this, [this](qint64 pid, const QStringList & args) {
Q_UNUSED(pid)
QCommandLineParser parser;
parser.addOption(optShow);
parser.addOption(optToggle);
parser.parse(args);
if (parser.isSet(optShow)) {
setVisible(true);
} else if (parser.isSet(optToggle)) {
setVisible(!visible());
}
});
// for dbus adapter signals.
connect(this, &LauncherController::visibleChanged, this, [this](bool isVisible){
if (isVisible) {
emit Shown();
} else {
emit Closed();
}
emit VisibleChanged(isVisible);
});
}
void LauncherController::Exit()
{
qApp->quit();
}
void LauncherController::Hide()
{
setVisible(false);
}
void LauncherController::Show()
{
setVisible(true);
}
void LauncherController::ShowByMode(qlonglong in0)
{
Q_UNUSED(in0)
// the original launcher implementation did nothing while calling this dbus API
// I guess we can deprecate this API.
}
void LauncherController::Toggle()
{
if (m_timer->isActive()) {
qDebug() << "hit";
m_pendingHide = false;
m_timer->stop();
return;
}
setVisible(!visible());
}
LauncherController::~LauncherController()
{
}
bool LauncherController::visible() const
{
return m_visible;
}
void LauncherController::setVisible(bool visible)
{
if (visible == m_visible) return;
m_visible = visible;
emit visibleChanged(m_visible);
}
bool LauncherController::isFullScreenFrame() const
{
return m_currentFrame == QStringLiteral("FullscreenFrame");
}
QString LauncherController::currentFrame() const
{
return m_currentFrame;
}
void LauncherController::setCurrentFrame(const QString &frame)
{
if (m_currentFrame == frame) return;
const QString settingBasePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
const QString settingPath(QDir(settingBasePath).absoluteFilePath("settings.ini"));
QSettings settings(settingPath, QSettings::NativeFormat);
settings.setValue("current_frame", frame);
m_currentFrame = frame;
qDebug() << "set current frame:" << m_currentFrame;
m_pendingHide = false;
m_timer->start();
emit currentFrameChanged();
}
QString LauncherController::currentScreen() const
{
return m_currentScreen;
}
void LauncherController::setCurrentScreen(const QString &screen)
{
if (m_currentScreen == screen) return;
m_currentScreen = screen;
qCInfo(logController) << "Current screen changed to:" << m_currentScreen;
emit currentScreenChanged();
}
// We need to hide the launcher when it lost focus, but clicking the launcher icon on the taskbar/dock will also trigger
// `Toggle()`, which will show the launcher even if it just get hid caused by losting focus. Thus, we added a timer to
// mark it as we just hide it, and check if the timer is running while calling `Toggle()`. This function will do nothing
// if it's already hidden (`Toggle()` get triggered before `hideWithTimer()` get called).
void LauncherController::hideWithTimer()
{
if (visible()) {
if (m_timer->isActive()) {
m_pendingHide = true;
return;
}
if (m_avoidHide) {
qDebug() << "hide with timer";
setVisible(false);
}
}
}
void LauncherController::cancelHide()
{
m_pendingHide = false;
}
QFont LauncherController::adjustFontWeight(const QFont &f, QFont::Weight weight)
{
QFont font(f);
font.setWeight(weight);
return font;
}
void LauncherController::closeAllPopups()
{
QGuiApplicationPrivate *qAppPrivate = QGuiApplicationPrivate::instance();
Q_ASSERT(qAppPrivate);
qAppPrivate->closeAllPopups();
}
void LauncherController::setAvoidHide(bool avoidHide)
{
m_avoidHide = avoidHide;
}
void LauncherController::showHelp()
{
// 由于当前只有调用 “启动器”,才能跳转到帮助文档的启动器目录。使用launcher 以及launchpad等字段,无法跳转到启动器目录。
QString helpTitle = "启动器";
const QString &dmanInterface = "com.deepin.Manual.Open";
QDBusMessage message = QDBusMessage::createMethodCall(dmanInterface, "/com/deepin/Manual/Open", dmanInterface, "OpenTitle");
message << "dde" << helpTitle;
QDBusConnection::sessionBus().asyncCall(message);
}
//首次从全屏切换到窗口时候,会出现焦点丢失抖动问题,从而导致启动器窗口不显示,所以采用此方法处理。
void LauncherController::setCurrentFrameToWindowedFrame()
{
setVisible(false);
QTimer::singleShot(100, this, [this]() {
setCurrentFrame("WindowedFrame");
setVisible(true);
});
}