mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Merge "add shutdown plugin context menu"
This commit is contained in:
commit
c42fd64d58
37
plugins/shutdown/dbus/dbusaccount.cpp
Normal file
37
plugins/shutdown/dbus/dbusaccount.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusAccount -p dbusaccount com.deepin.daemon.Accounts.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "dbusaccount.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class DBusAccount
|
||||
*/
|
||||
|
||||
DBusAccount::DBusAccount(QObject *parent)
|
||||
: QDBusAbstractInterface(staticService(), staticInterfacePath(), staticInterfaceName(), QDBusConnection::systemBus(), parent)
|
||||
{
|
||||
QDBusConnection::systemBus().connect(this->service(), this->path(), "org.freedesktop.DBus.Properties", "PropertiesChanged","sa{sv}as", this, SLOT(__propertyChanged__(QDBusMessage)));
|
||||
}
|
||||
|
||||
DBusAccount::~DBusAccount()
|
||||
{
|
||||
QDBusConnection::systemBus().disconnect(service(), path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", "sa{sv}as", this, SLOT(propertyChanged(QDBusMessage)));
|
||||
}
|
||||
|
86
plugins/shutdown/dbus/dbusaccount.h
Normal file
86
plugins/shutdown/dbus/dbusaccount.h
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusAccount -p dbusaccount com.deepin.daemon.Accounts.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef DBUSACCOUNT_H_1439464396
|
||||
#define DBUSACCOUNT_H_1439464396
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
/*
|
||||
* Proxy class for interface com.deepin.daemon.Accounts
|
||||
*/
|
||||
class DBusAccount: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_SLOT void __propertyChanged__(const QDBusMessage &msg)
|
||||
{
|
||||
QList<QVariant> arguments = msg.arguments();
|
||||
if (3 != arguments.count()) {
|
||||
return;
|
||||
}
|
||||
QString interfaceName = msg.arguments().at(0).toString();
|
||||
if (interfaceName != "com.deepin.daemon.Accounts") {
|
||||
return;
|
||||
}
|
||||
QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>());
|
||||
QStringList keys = changedProps.keys();
|
||||
foreach(const QString & prop, keys) {
|
||||
const QMetaObject *self = metaObject();
|
||||
for (int i = self->propertyOffset(); i < self->propertyCount(); ++i) {
|
||||
QMetaProperty p = self->property(i);
|
||||
if (p.name() == prop) {
|
||||
Q_EMIT p.notifySignal().invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
static inline const char *staticService()
|
||||
{ return "com.deepin.daemon.Accounts"; }
|
||||
static inline const char *staticInterfacePath()
|
||||
{ return "/com/deepin/daemon/Accounts"; }
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "com.deepin.daemon.Accounts"; }
|
||||
|
||||
public:
|
||||
DBusAccount(QObject *parent = 0);
|
||||
|
||||
~DBusAccount();
|
||||
|
||||
Q_PROPERTY(QStringList UserList READ userList)
|
||||
inline QStringList userList() const
|
||||
{ return qvariant_cast< QStringList >(property("UserList")); }
|
||||
};
|
||||
|
||||
//namespace com {
|
||||
// namespace deepin {
|
||||
// namespace daemon {
|
||||
// typedef ::DBusAccount Accounts;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endif
|
@ -80,7 +80,10 @@ void PluginWidget::mousePressEvent(QMouseEvent *e)
|
||||
|
||||
const QPoint p(e->pos() - rect().center());
|
||||
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
|
||||
{
|
||||
emit requestContextMenu(SHUTDOWN_KEY);
|
||||
return;
|
||||
}
|
||||
|
||||
return QWidget::mousePressEvent(e);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#define SHUTDOWN_KEY "shutdown"
|
||||
|
||||
class PluginWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -14,6 +16,9 @@ class PluginWidget : public QWidget
|
||||
public:
|
||||
explicit PluginWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestContextMenu(const QString &itemKey) const;
|
||||
|
||||
protected:
|
||||
QSize sizeHint() const;
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
@ -38,7 +38,10 @@ void PowerStatusWidget::mousePressEvent(QMouseEvent *e)
|
||||
|
||||
const QPoint p(e->pos() - rect().center());
|
||||
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
|
||||
{
|
||||
emit requestContextMenu(POWER_KEY);
|
||||
return;
|
||||
}
|
||||
|
||||
return QWidget::mousePressEvent(e);
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#define POWER_KEY "power"
|
||||
|
||||
class PowerStatusWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -12,6 +14,9 @@ class PowerStatusWidget : public QWidget
|
||||
public:
|
||||
explicit PowerStatusWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestContextMenu(const QString &itemKey) const;
|
||||
|
||||
protected:
|
||||
QSize sizeHint() const;
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
@ -14,13 +14,15 @@ HEADERS += \
|
||||
shutdownplugin.h \
|
||||
dbus/dbuspower.h \
|
||||
pluginwidget.h \
|
||||
powerstatuswidget.h
|
||||
powerstatuswidget.h \
|
||||
dbus/dbusaccount.h
|
||||
|
||||
SOURCES += \
|
||||
shutdownplugin.cpp \
|
||||
dbus/dbuspower.cpp \
|
||||
pluginwidget.cpp \
|
||||
powerstatuswidget.cpp
|
||||
powerstatuswidget.cpp \
|
||||
dbus/dbusaccount.cpp
|
||||
|
||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||
INSTALLS += target
|
||||
|
@ -1,10 +1,8 @@
|
||||
#include "shutdownplugin.h"
|
||||
#include "dbus/dbusaccount.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#define POWER_KEY "power"
|
||||
#define SHUTDOWN_KEY "shutdown"
|
||||
|
||||
ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
|
||||
@ -21,6 +19,8 @@ ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
||||
"padding:5px 10px;");
|
||||
|
||||
connect(m_powerInter, &DBusPower::BatteryPercentageChanged, this, &ShutdownPlugin::updateBatteryVisible);
|
||||
connect(m_shutdownWidget, &PluginWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu);
|
||||
connect(m_powerStatusWidget, &PowerStatusWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu);
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::pluginName() const
|
||||
@ -81,6 +81,68 @@ const QString ShutdownPlugin::itemCommand(const QString &itemKey)
|
||||
return QString();
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
||||
{
|
||||
QList<QVariant> items;
|
||||
items.reserve(6);
|
||||
|
||||
const Dock::DisplayMode mode = displayMode();
|
||||
|
||||
if (mode == Dock::Fashion || itemKey == SHUTDOWN_KEY)
|
||||
{
|
||||
QMap<QString, QVariant> shutdown;
|
||||
shutdown["itemId"] = "shutdown";
|
||||
shutdown["itemText"] = tr("Shut down");
|
||||
shutdown["isActive"] = true;
|
||||
items.push_back(shutdown);
|
||||
|
||||
QMap<QString, QVariant> reboot;
|
||||
reboot["itemId"] = "reboot";
|
||||
reboot["itemText"] = tr("Restart");
|
||||
reboot["isActive"] = true;
|
||||
items.push_back(reboot);
|
||||
|
||||
QMap<QString, QVariant> logout;
|
||||
logout["itemId"] = "logout";
|
||||
logout["itemText"] = tr("Log out");
|
||||
logout["isActive"] = true;
|
||||
items.push_back(logout);
|
||||
|
||||
QMap<QString, QVariant> suspend;
|
||||
suspend["itemId"] = "suspend";
|
||||
suspend["itemText"] = tr("Suspend");
|
||||
suspend["isActive"] = true;
|
||||
items.push_back(suspend);
|
||||
|
||||
DBusAccount *accountInter = new DBusAccount(this);
|
||||
if (accountInter->userList().count() > 1)
|
||||
{
|
||||
QMap<QString, QVariant> switchUser;
|
||||
switchUser["itemId"] = "switchUser";
|
||||
switchUser["itemText"] = tr("Switch account");
|
||||
switchUser["isActive"] = true;
|
||||
items.push_back(switchUser);
|
||||
}
|
||||
accountInter->deleteLater();
|
||||
}
|
||||
|
||||
if (mode == Dock::Fashion || itemKey == POWER_KEY)
|
||||
{
|
||||
QMap<QString, QVariant> power;
|
||||
power["itemId"] = "power";
|
||||
power["itemText"] = tr("Power settings");
|
||||
power["isActive"] = true;
|
||||
items.push_back(power);
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> menu;
|
||||
menu["items"] = items;
|
||||
menu["checkableMenu"] = false;
|
||||
menu["singleCheck"] = false;
|
||||
|
||||
return QJsonDocument::fromVariant(menu).toJson();
|
||||
}
|
||||
|
||||
void ShutdownPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||
{
|
||||
Q_UNUSED(displayMode);
|
||||
@ -99,3 +161,8 @@ void ShutdownPlugin::updateBatteryVisible()
|
||||
else if (exist)
|
||||
m_proxyInter->itemAdded(this, POWER_KEY);
|
||||
}
|
||||
|
||||
void ShutdownPlugin::requestContextMenu(const QString &itemKey)
|
||||
{
|
||||
m_proxyInter->requestContextMenu(this, itemKey);
|
||||
}
|
||||
|
@ -23,10 +23,12 @@ public:
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
QWidget *itemTipsWidget(const QString &itemKey);
|
||||
const QString itemCommand(const QString &itemKey);
|
||||
const QString itemContextMenu(const QString &itemKey);
|
||||
void displayModeChanged(const Dock::DisplayMode displayMode);
|
||||
|
||||
private:
|
||||
void updateBatteryVisible();
|
||||
void requestContextMenu(const QString &itemKey);
|
||||
|
||||
private:
|
||||
PluginWidget *m_shutdownWidget;
|
||||
|
Loading…
x
Reference in New Issue
Block a user