-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDDEPstatePlugin.cpp
128 lines (99 loc) · 3.28 KB
/
DDEPstatePlugin.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
//
// Created by septemberhx on 2020/5/13.
//
#include "DDEPstatePlugin.h"
#include "PStateUtils.h"
#include <QJsonObject>
#define PLUGIN_STATE_KEY "enable"
DDEPstatePlugin::DDEPstatePlugin(QObject *parent) : QObject(parent) {
}
const QString DDEPstatePlugin::pluginName() const {
return QStringLiteral("dde_pstate");
}
void DDEPstatePlugin::init(PluginProxyInterface *proxyInter) {
this->m_proxyInter = proxyInter;
switch (QLocale::system().language()) {
case QLocale::Chinese:
this->m_translator = new QTranslator(this);
this->m_translator->load(":/translations/app_zh.qm");
qApp->installTranslator(this->m_translator);
break;
case QLocale::Spanish:
this->m_translator = new QTranslator(this);
this->m_translator->load(":/translations/app_es.qm");
qApp->installTranslator(this->m_translator);
break;
default:
break;
}
this->m_pluginWidget = new DDEPstateWidget();
this->m_tipsWidget = new QLabel();
this->m_appletWidget = new PstateMainWidget();
if (!pluginIsDisable()) {
this->m_proxyInter->itemAdded(this, this->pluginName());
}
}
QWidget *DDEPstatePlugin::itemWidget(const QString &itemKey) {
Q_UNUSED(itemKey)
return this->m_pluginWidget;
}
bool DDEPstatePlugin::pluginIsAllowDisable() {
return true;
}
bool DDEPstatePlugin::pluginIsDisable() {
return !(m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
}
void DDEPstatePlugin::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 DDEPstatePlugin::pluginDisplayName() const {
return QStringLiteral("DDE Pstate");
}
QWidget *DDEPstatePlugin::itemTipsWidget(const QString &itemKey) {
Q_UNUSED(itemKey);
QJsonObject allData = PStateUtils::readAll();
QString gov = allData["cpu_governor"].toString();
if (gov == "performance") {
m_tipsWidget->setText(tr("performance"));
} else if (gov == "powersave") {
m_tipsWidget->setText(tr("powersave"));
} else {
m_tipsWidget->setText("DDE Pstate");
}
return m_tipsWidget;
}
QWidget *DDEPstatePlugin::itemPopupApplet(const QString &itemKey) {
Q_UNUSED(itemKey)
this->m_appletWidget->refresh();
return this->m_appletWidget;
}
int DDEPstatePlugin::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 DDEPstatePlugin::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);
}
void DDEPstatePlugin::pluginSettingsChanged() {
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, pluginName());
return;
}
if (m_pluginWidget) {
m_proxyInter->itemAdded(this, pluginName());
}
}
void DDEPstatePlugin::refreshIcon(const QString &itemKey) {
Q_UNUSED(itemKey)
this->m_pluginWidget->updateIcon();
}