-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSmartDirPlugin.cpp
124 lines (95 loc) · 3.39 KB
/
SmartDirPlugin.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
114
115
116
117
118
119
120
121
122
123
124
//
// Created by septemberhx on 2020/6/6.
//
#include "SmartDirPlugin.h"
#include "SmartDirSettings.h"
#include <QApplication>
#include <QDesktopWidget>
#define PLUGIN_STATE_KEY "enable"
SmartDirPlugin::SmartDirPlugin(QObject *parent) : QObject(parent) {
}
const QString SmartDirPlugin::pluginName() const {
return "dde-smart-dir";
}
void SmartDirPlugin::init(PluginProxyInterface *proxyInter) {
this->m_proxyInter = proxyInter;
this->m_smartDirWidget = new SmartDirWidget();
this->m_smartDirWidget->applySettings(*SmartDirSettings::instance());
this->m_pluginWidget = new SmartDirPluginWidget();
this->m_settingWidget = new SmartDirSettingWidget();
connect(this->m_settingWidget, &SmartDirSettingWidget::closed, this->m_smartDirWidget, &SmartDirWidget::reloadData);
if (!pluginIsDisable()) {
this->m_proxyInter->itemAdded(this, this->pluginName());
}
}
QWidget *SmartDirPlugin::itemWidget(const QString &itemKey) {
return this->m_pluginWidget;
}
QWidget *SmartDirPlugin::itemPopupApplet(const QString &itemKey) {
return this->m_smartDirWidget;
}
bool SmartDirPlugin::pluginIsAllowDisable() {
return true;
}
bool SmartDirPlugin::pluginIsDisable() {
return !(m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
}
void SmartDirPlugin::pluginStateSwitched() {
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, pluginName());
return;
}
if (m_pluginWidget) {
m_proxyInter->itemAdded(this, pluginName());
}
}
const QString SmartDirPlugin::pluginDisplayName() const {
return tr("DDE Smart Dir");
}
void SmartDirPlugin::pluginSettingsChanged() {
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, pluginName());
return;
}
if (m_pluginWidget) {
m_proxyInter->itemAdded(this, pluginName());
}
}
int SmartDirPlugin::itemSortKey(const QString &itemKey) {
Q_UNUSED(itemKey)
const QString key = QString("pos_%1").arg(Dock::Efficient);
return m_proxyInter->getValue(this, key, 5).toInt();
}
void SmartDirPlugin::setSortKey(const QString &itemKey, const int order) {
Q_UNUSED(itemKey)
const QString key = QString("pos_%1").arg(Dock::Efficient);
m_proxyInter->saveValue(this, key, order);
}
const QString SmartDirPlugin::itemContextMenu(const QString &itemKey) {
Q_UNUSED(itemKey)
QList<QVariant> items;
items.reserve(1);
QMap<QString, QVariant> open;
open["itemId"] = "settings";
open["itemText"] = tr("Settings");
open["isActive"] = true;
items.push_back(open);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
// 返回 JSON 格式的菜单数据
return QJsonDocument::fromVariant(menu).toJson();
}
void SmartDirPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) {
Q_UNUSED(itemKey)
// 根据上面接口设置的 id 执行不同的操作
if (menuId == "settings") {
this->m_settingWidget->loadData();
int screenNum = QApplication::desktop()->screenNumber(this->m_smartDirWidget);
this->m_settingWidget->move(QApplication::desktop()->screen(screenNum)->rect().center() - this->m_settingWidget->rect().center());
this->m_settingWidget->show();
this->m_settingWidget->show();
}
}