forked from PinappleUnderTheSea/os223
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfstartupplugin.cpp
152 lines (125 loc) · 4.03 KB
/
selfstartupplugin.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
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
#include "selfstartupplugin.h"
SelfStartupPlugin::SelfStartupPlugin(QObject *parent)
: QObject(parent)
{
}
const QString SelfStartupPlugin::pluginName() const
{
return QStringLiteral("self_startup");
}
//写配置信息
// void SelfStartupPlugin::writeConfig(Settings *settings)
// {
// QMapIterator<QString,QVariant> i(*settings);
// while(i.hasNext())
// {
// i.next();
// m_proxyInter->saveValue(this,i.key(),i.value());
// }
// }
const QString SelfStartupPlugin::pluginDisplayName() const
{
return QString("Self Startup");
}
void SelfStartupPlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
m_pluginWidget = new MainWidget;
m_appletWidget = new AppletWidget;
if (!pluginIsDisable()) {
m_proxyInter->itemAdded(this, pluginName());
// m_proxyInter->requestSetAppletVisible(this, "", true);//set applet visible
}
}
QWidget *SelfStartupPlugin::itemWidget(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_pluginWidget;
// if (itemKey == QUICK_ITEM_KEY)
// return m_pluginWidget;
// return nullptr;
}
QWidget *SelfStartupPlugin::itemPopupApplet(const QString &itemKey)
{
Q_UNUSED(itemKey);
m_appletWidget->update_widget();
return m_appletWidget;
}
// QIcon SelfStartupPlugin::icon(const DockPart &dockPart, int themeType)
// {
// if (dockPart == DockPart::QuickShow) {
// QIcon icon;
// return icon;
// }
// return QIcon();
// }
// void SelfStartupPlugin::about()
// {
// QMessageBox aboutMB(QMessageBox::NoIcon, "SelfStarupPlugin 1.0", "[About]\n\nDeepin Linux DDE Dock Self-startup plugin.\n");
// aboutMB.setIconPixmap(QPixmap(":/icon.png"));
// aboutMB.exec();
// }
// PluginFlags SelfStartupPlugin::flags() const
// {
// // 返回的插件为Type_Common-快捷区域插件, Quick_Multi快捷插件显示两列的那种,例如网络和蓝牙
// // Attribute_CanDrag该插件在任务栏上支持拖动,Attribute_CanInsert该插件支持在其前面插入其他的图标
// // Attribute_CanSetting该插件支持在控制中心设置显示或隐藏
// return PluginFlags::Type_Common // to_do
// | PluginFlags::Quick_Single
// //| PluginFlags::Attribute_CanDrag
// //| PluginFlags::Attribute_CanInsert
// | PluginFlags::Attribute_CanSetting;
// }
bool SelfStartupPlugin::pluginIsAllowDisable()
{
// 告诉 dde-dock 本插件允许禁用
return true;
}
bool SelfStartupPlugin::pluginIsDisable()
{
// 第二个参数 “disabled” 表示存储这个值的键(所有配置都是以键值对的方式存储的)
// 第三个参数表示默认值,即默认不禁用
return m_proxyInter->getValue(this, "disabled", false).toBool();
}
void SelfStartupPlugin::pluginStateSwitched()
{
// 获取当前禁用状态的反值作为新的状态值
const bool disabledNew = !pluginIsDisable();
// 存储新的状态值
m_proxyInter->saveValue(this, "disabled", disabledNew);
// 根据新的禁用状态值处理主控件的加载和卸载
if (disabledNew) {
m_proxyInter->itemRemoved(this, pluginName());
} else {
m_proxyInter->itemAdded(this, pluginName());
}
}
const QString SelfStartupPlugin::itemContextMenu(const QString &itemKey)
{
Q_UNUSED(itemKey);
QList<QVariant> items;
items.reserve(2);
QMap<QString, QVariant> about;
about["itemId"] = "about";
about["itemText"] = "about";
about["isActive"] = true;
items.push_back(about);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
// 返回 JSON 格式的菜单数据
return QJsonDocument::fromVariant(menu).toJson();
}
void SelfStartupPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
Q_UNUSED(itemKey);
Q_UNUSED(checked);
if (menuId == "about")
{
aboutDialog aboutdialog;
if(aboutdialog.exec()==QDialog::Accepted)
{
}
}
}