feat: shutdown plugin support hibernate

https://github.com/linuxdeepin/internal-discussion/issues/820

Change-Id: Ifa3b35ba6bab8677b5246cd9ecf2279877966891
This commit is contained in:
listenerri 2019-01-15 09:54:45 +08:00
parent e2a791eb4a
commit 60b5d9e0c2
Notes: gerrit 2019-01-15 16:16:05 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+1: 流年匆忙 <justforlxz@gmail.com>
Verified+1: liuwen123 <liuwen@linuxdeepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Tue, 15 Jan 2019 16:16:04 +0800
Reviewed-on: https://cr.deepin.io/41327
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 23 additions and 0 deletions

View File

@ -127,6 +127,14 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
suspend["isActive"] = true;
items.push_back(suspend);
if (checkSwap()) {
QMap<QString, QVariant> hibernate;
hibernate["itemId"] = "Hibernate";
hibernate["itemText"] = tr("Hibernate");
hibernate["isActive"] = true;
items.push_back(hibernate);
}
QMap<QString, QVariant> lock;
lock["itemId"] = "Lock";
lock["itemText"] = tr("Lock");
@ -222,3 +230,17 @@ void ShutdownPlugin::loadPlugin()
m_proxyInter->itemAdded(this, pluginName());
displayModeChanged(displayMode());
}
bool ShutdownPlugin::checkSwap()
{
QFile file("/proc/swaps");
if (file.open(QIODevice::Text | QIODevice::ReadOnly)) {
const QString &body = file.readAll();
file.close();
QRegularExpression re("\\spartition\\s");
QRegularExpressionMatch match = re.match(body);
return match.hasMatch();
}
return false;
}

View File

@ -57,6 +57,7 @@ public:
private:
void loadPlugin();
bool checkSwap();
private:
bool m_pluginLoaded;