44
55#include " NetPlugin.h"
66#include < QLabel>
7+
78#include < QDebug>
89
910DWIDGET_USE_NAMESPACE
@@ -22,7 +23,7 @@ NetPlugin::NetPlugin(QObject *parent)
2223 */
2324const QString NetPlugin::pluginName () const
2425{
25- return " datetime" ; // MonitorNet
26+ return " datetime" ;
2627}
2728
2829/* !
@@ -49,24 +50,92 @@ QWidget *NetPlugin::itemWidget(const QString &itemKey)
4950 return m_winDockNet;
5051}
5152
53+ /* !
54+ * \brief NetPlugin::pluginIsAllowDisable 插件是否允许被禁用
55+ * \return 告诉 dde-dock 本插件允许禁用
56+ */
57+ bool NetPlugin::pluginIsAllowDisable ()
58+ {
59+ return true ;
60+ }
61+
62+ /* !
63+ * \brief NetPlugin::pluginIsDisable 插件是否被禁用
64+ * \return 插件是否被禁用的状态
65+ * \note getValue() 的第二个参数 “disabled” 表示存储这个值的键(所有配置都是以键值对的方式存储的)
66+ * 第三个参数表示默认值,即默认不禁用
67+ */
68+ bool NetPlugin::pluginIsDisable ()
69+ {
70+ return m_proxyInter->getValue (this , " disabled" , false ).toBool ();
71+ }
72+
73+ /* !
74+ * \brief NetPlugin::pluginStateSwitched 插件状态切换
75+ */
76+ void NetPlugin::pluginStateSwitched ()
77+ {
78+ // 将旧的 "禁用状态" 数值取反后,保存到 key-val 中
79+ const bool disableState = !pluginIsDisable ();
80+ m_proxyInter->saveValue (this , " disabled" , disableState);
81+
82+ // 根据新的禁用状态值,处理主控的加载与卸载
83+ if (disableState)
84+ m_proxyInter->itemRemoved (this , pluginName ());
85+ else
86+ m_proxyInter->itemAdded (this , pluginName ());
87+ }
88+
89+ /* !
90+ * \brief NetPlugin::pluginDisplayName 插件在 dock 的右键时候,显示名称
91+ * \return 插件在 dock 右键显示的预称
92+ */
93+ const QString NetPlugin::pluginDisplayName () const
94+ {
95+ return QString (" MonitorNet" );
96+ }
97+
98+ /* !
99+ * \brief NetPlugin::itemContextMenu 插件右键后现实的菜单列表
100+ * \param itemKey
101+ * \return 返回 JSON 格式的菜单数据
102+ * \note 增加右键菜单功能需要实现此两个接口:itemContextMenu + invokedMenuItem
103+ */
52104const QString NetPlugin::itemContextMenu (const QString &itemKey)
53105{
54106 Q_UNUSED (itemKey);
55107
56- QList<QVariant> items;
57- items.reserve (1 );
58-
59108 QMap<QString, QVariant> update;
60109 update[" itemId" ] = " update" ;
61110 update[" itemText" ] = " 刷新" ;
62111 update[" isActive" ] = true ;
112+
113+ QList<QVariant> items;
114+ items.reserve (1 );
63115 items.push_back (update);
64116
65117 QMap<QString, QVariant> menu;
66118 menu[" items" ] = items;
67119 menu[" checkableMenu" ] = false ;
68120 menu[" singleCheck" ] = false ;
69121
70- // 返回 JSON 格式的菜单数据
71122 return QJsonDocument::fromVariant (menu).toJson ();
72123}
124+
125+ /* !
126+ * \brief NetPlugin::invokedMenuItem 菜单项被点击后的回调函数
127+ * \param itemKey
128+ * \param menuId menu item ID
129+ * \param checked
130+ * \note * \note 增加右键菜单功能需要实现此两个接口:itemContextMenu + invokedMenuItem
131+ */
132+ void NetPlugin::invokedMenuItem (const QString &itemKey, const QString &menuId, const bool checked)
133+ {
134+ Q_UNUSED (itemKey)
135+ Q_UNUSED (checked)
136+
137+ if (menuId == " update" ) {
138+ m_proxyInter->itemRemoved (this , pluginName ());
139+ m_proxyInter->itemAdded (this , pluginName ());
140+ }
141+ }
0 commit comments