refacotr: merge other plugins to system-tray

merge sound, shutdown, network plugins to system-tray

Change-Id: Iab7aef4c56d3e1c24b408c323ef03a8276ff43f2
This commit is contained in:
listenerri 2018-10-23 20:06:46 +08:00
parent 203a6eb96f
commit 6224d76f98
Notes: gerrit 2018-10-24 14:12:47 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Wed, 24 Oct 2018 14:12:46 +0800
Reviewed-on: https://cr.deepin.io/39184
Project: dde/dde-dock
Branch: refs/heads/master
252 changed files with 1663 additions and 47 deletions

View File

@ -1,9 +1,9 @@
add_subdirectory("datetime")
#add_subdirectory("disk-mount")
add_subdirectory("network")
add_subdirectory("shutdown")
add_subdirectory("sound")
#add_subdirectory("network")
#add_subdirectory("shutdown")
#add_subdirectory("sound")
add_subdirectory("system-tray")
add_subdirectory("trash")
add_subdirectory("keyboard-layout")

View File

@ -15,6 +15,8 @@ find_package(Qt5X11Extras REQUIRED)
find_package(DtkWidget REQUIRED)
pkg_check_modules(XCB_LIBS REQUIRED xcb-ewmh xcb xcb-image xcb-composite xtst xcb-icccm dbusmenu-qt5)
pkg_check_modules(DDE-Network-Utils REQUIRED dde-network-utils)
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} system-tray.qrc)
@ -22,6 +24,8 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
${XCB_LIBS_INCLUDE_DIRS}
${DDE-Network-Utils_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
../../interfaces)
target_link_libraries(${PLUGIN_NAME} PRIVATE
${DtkWidget_LIBRARIES}
@ -30,6 +34,8 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE
${Qt5DBus_LIBRARIES}
${Qt5Svg_LIBRARIES}
${XCB_LIBS_LIBRARIES}
${DDE-Network-Utils_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
)
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)

View File

@ -33,7 +33,7 @@ public:
virtual void setActive(const bool active) = 0;
virtual void updateIcon() = 0;
virtual void sendClick(uint8_t, int, int) = 0;
virtual void sendClick(uint8_t mouseButton, int x, int y) = 0;
virtual const QImage trayImage() = 0;
Q_SIGNALS:

View File

@ -35,8 +35,9 @@ FashionTrayItem::FashionTrayItem(Dock::Position pos, QWidget *parent)
m_trayBoxLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight, this)),
m_leftSpliter(new QLabel(this)),
m_rightSpliter(new QLabel(this)),
m_controlWidget(new FashionTrayControlWidget(m_dockPosistion, this)),
m_currentAttentionTray(nullptr)
m_controlWidget(new FashionTrayControlWidget(pos, this)),
m_currentAttentionTray(nullptr),
m_dockPosistion(pos)
{
m_leftSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
m_rightSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");

View File

@ -5,5 +5,6 @@
<file>resources/arrow_down_dark.svg</file>
<file>resources/arrow_right_dark.svg</file>
<file>resources/arrow_up_light.svg</file>
<file>system-trays/shutdown/resources/icons/normal.svg</file>
</qresource>
</RCC>

View File

@ -0,0 +1,42 @@
#include "abstracttrayloader.h"
#include <QDebug>
AbstractTrayLoader::AbstractTrayLoader(const QString &waitService, QObject *parent)
: QObject(parent),
m_dbusDaemonInterface(QDBusConnection::sessionBus().interface()),
m_waitingService(waitService)
{
}
bool AbstractTrayLoader::serviceExist()
{
bool exist = m_dbusDaemonInterface->isServiceRegistered(m_waitingService).value();
if (!exist) {
qDebug() << m_waitingService << "daemon has not started";
}
return exist;
}
void AbstractTrayLoader::waitServiceForLoad()
{
connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this, &AbstractTrayLoader::onServiceOwnerChanged, Qt::UniqueConnection);
}
void AbstractTrayLoader::onServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
{
Q_UNUSED(oldOwner);
if (m_waitingService.isEmpty() || newOwner.isEmpty()) {
return;
}
if (m_waitingService == name) {
qDebug() << m_waitingService << "daemon started, load tray and disconnect";
load();
disconnect(m_dbusDaemonInterface);
m_waitingService = QString();
}
}

View File

@ -0,0 +1,36 @@
#ifndef ABSTRACTTRAYLOADER_H
#define ABSTRACTTRAYLOADER_H
#include "abstracttraywidget.h"
#include <QDBusConnectionInterface>
#include <QObject>
class AbstractTrayLoader : public QObject
{
Q_OBJECT
public:
explicit AbstractTrayLoader(const QString &waitService, QObject *parent = nullptr);
Q_SIGNALS:
void systemTrayAdded(const QString &itemKey, AbstractTrayWidget *trayWidget);
void systemTrayRemoved(const QString &itemKey);
public Q_SLOTS:
virtual void load() = 0;
public:
inline bool waitService() { return !m_waitingService.isEmpty(); }
bool serviceExist();
void waitServiceForLoad();
private Q_SLOTS:
void onServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
private:
QDBusConnectionInterface *m_dbusDaemonInterface;
QString m_waitingService;
};
#endif // ABSTRACTTRAYLOADER_H

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "abstractnetworktraywidget.h"
#include <DDBusSender>
#include <QJsonDocument>
using namespace dde::network;
AbstractNetworkTrayWidget::AbstractNetworkTrayWidget(dde::network::NetworkDevice *device, QWidget *parent)
: AbstractTrayWidget(parent),
m_device(device),
m_path(device->path())
{
}
QSize AbstractNetworkTrayWidget::sizeHint() const
{
return QSize(26, 26);
}
const QString AbstractNetworkTrayWidget::itemContextMenu()
{
QList<QVariant> items;
items.reserve(2);
QMap<QString, QVariant> enable;
enable["itemId"] = "enable";
if (!m_device->enabled())
enable["itemText"] = tr("Enable network");
else
enable["itemText"] = tr("Disable network");
enable["isActive"] = true;
items.push_back(enable);
QMap<QString, QVariant> settings;
settings["itemId"] = "settings";
settings["itemText"] = tr("Network settings");
settings["isActive"] = true;
items.push_back(settings);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
return QJsonDocument::fromVariant(menu).toJson();
}
void AbstractNetworkTrayWidget::invokeMenuItem(const QString &menuId)
{
if (menuId == "settings")
//QProcess::startDetached("dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.ShowModule \"string:network\"");
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method("ShowModule")
.arg(QString("network"))
.call();
else if (menuId == "enable")
Q_EMIT requestSetDeviceEnable(m_path, !m_device->enabled());
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ABSTRACTNETWORKTRAYWIDGET_H
#define ABSTRACTNETWORKTRAYWIDGET_H
#include "abstracttraywidget.h"
#include <QWidget>
#include <NetworkDevice>
class AbstractNetworkTrayWidget : public AbstractTrayWidget
{
Q_OBJECT
public:
explicit AbstractNetworkTrayWidget(dde::network::NetworkDevice *device, QWidget *parent = nullptr);
public:
const QString &path() const { return m_path; }
inline const dde::network::NetworkDevice * device() { return m_device; }
virtual const QString itemContextMenu();
virtual void invokeMenuItem(const QString &menuId);
Q_SIGNALS:
void requestSetDeviceEnable(const QString &path, const bool enable) const;
protected:
QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
dde::network::NetworkDevice *m_device;
private:
QString m_path;
};
#endif // ABSTRACTNETWORKTRAYWIDGET_H

View File

@ -35,7 +35,7 @@ public:
const QString &path() const { return m_path; }
const dde::network::NetworkDevice * device() { return m_device; };
inline const dde::network::NetworkDevice * device() { return m_device; }
virtual void refreshIcon() = 0;
virtual const QString itemCommand() const;

View File

@ -22,7 +22,7 @@
#include "constants.h"
#include "wireditem.h"
#include "util/imageutil.h"
#include "../util/imageutil.h"
#include "../widgets/tipswidget.h"
#include <QPainter>

View File

@ -0,0 +1,148 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
* listenerri <listenerri@gmail.com>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wiredtraywidget.h"
#include "constants.h"
#include "../util/imageutil.h"
#include "../widgets/tipswidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QIcon>
#include <QApplication>
using namespace dde::network;
WiredTrayWidget::WiredTrayWidget(WiredDevice *device, QWidget *parent)
: AbstractNetworkTrayWidget(device, parent),
m_itemTips(new TipsWidget(this)),
m_delayTimer(new QTimer(this))
{
m_delayTimer->setSingleShot(false);
m_delayTimer->setInterval(200);
m_itemTips->setObjectName("wired-" + m_device->path());
m_itemTips->setVisible(false);
connect(m_delayTimer, &QTimer::timeout, this, &WiredTrayWidget::updateIcon);
connect(m_device, static_cast<void (NetworkDevice::*)(NetworkDevice::DeviceStatus) const>(&NetworkDevice::statusChanged),
m_delayTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
}
void WiredTrayWidget::setActive(const bool active)
{
}
void WiredTrayWidget::updateIcon()
{
QString iconName = "network-";
NetworkDevice::DeviceStatus devState = m_device->status();
if (devState != NetworkDevice::Activated)
{
if (devState < NetworkDevice::Disconnected)
iconName.append("error");
else
iconName.append("offline");
} else {
if (devState >= NetworkDevice::Prepare && devState <= NetworkDevice::Secondaries) {
m_delayTimer->start();
const quint64 index = QDateTime::currentMSecsSinceEpoch() / 200;
const int num = (index % 5) + 1;
m_icon = QPixmap(QString(":/wired/resources/wired/network-wired-symbolic-connecting%1.svg").arg(num));
update();
return;
}
if (devState == NetworkDevice::Activated)
iconName.append("online");
else
iconName.append("idle");
}
m_delayTimer->stop();
iconName.append("-symbolic");
const auto ratio = qApp->devicePixelRatio();
const int size = 16;
m_icon = QIcon::fromTheme(iconName).pixmap(size * ratio, size * ratio);
m_icon.setDevicePixelRatio(ratio);
update();
}
void WiredTrayWidget::sendClick(uint8_t mouseButton, int x, int y)
{
}
const QImage WiredTrayWidget::trayImage()
{
return m_icon.toImage();
}
QWidget *WiredTrayWidget::itemTips()
{
m_itemTips->setText(tr("Unknown"));
do {
if (m_device->status() != NetworkDevice::Activated)
{
m_itemTips->setText(tr("No Network"));
break;
}
const QJsonObject info = static_cast<WiredDevice *>(m_device)->activeConnection();
if (!info.contains("Ip4"))
break;
const QJsonObject ipv4 = info.value("Ip4").toObject();
if (!ipv4.contains("Address"))
break;
m_itemTips->setText(tr("Wired connection: %1").arg(ipv4.value("Address").toString()));
} while (false);
return m_itemTips;
}
const QString WiredTrayWidget::itemCommand() const
{
return "dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.ShowModule \"string:network\"";
}
void WiredTrayWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter painter(this);
const auto ratio = qApp->devicePixelRatio();
const int x = rect().center().x() - m_icon.rect().center().x() / ratio;
const int y = rect().center().y() - m_icon.rect().center().y() / ratio;
painter.drawPixmap(x, y, m_icon);
}
void WiredTrayWidget::resizeEvent(QResizeEvent *e)
{
AbstractNetworkTrayWidget::resizeEvent(e);
m_delayTimer->start();
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WIREDTRAYWIDGET_H
#define WIREDTRAYWIDGET_H
#include "abstractnetworktraywidget.h"
#include <QWidget>
#include <QLabel>
#include <QTimer>
#include <WiredDevice>
class TipsWidget;
class WiredTrayWidget : public AbstractNetworkTrayWidget
{
Q_OBJECT
public:
explicit WiredTrayWidget(dde::network::WiredDevice *device, QWidget *parent = nullptr);
public:
void setActive(const bool active) Q_DECL_OVERRIDE;
void updateIcon() Q_DECL_OVERRIDE;
void sendClick(uint8_t mouseButton, int x, int y) Q_DECL_OVERRIDE;
const QImage trayImage() Q_DECL_OVERRIDE;
QWidget *itemTips();
const QString itemCommand() const;
protected:
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private:
QPixmap m_icon;
TipsWidget *m_itemTips;
QTimer *m_delayTimer;
};
#endif // WIREDTRAYWIDGET_H

View File

@ -20,7 +20,7 @@
*/
#include "wirelessitem.h"
#include "util/imageutil.h"
#include "../util/imageutil.h"
#include "../widgets/tipswidget.h"
#include <QPainter>

View File

@ -0,0 +1,240 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wirelesstraywidget.h"
#include "../util/imageutil.h"
#include "../widgets/tipswidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QIcon>
using namespace dde::network;
WirelessTrayWidget::WirelessTrayWidget(WirelessDevice *device, QWidget *parent)
: AbstractNetworkTrayWidget(device, parent),
m_refershTimer(new QTimer(this)),
m_wirelessApplet(new QWidget),
m_wirelessPopup(new TipsWidget),
m_APList(nullptr),
m_reloadIcon(false)
{
m_refershTimer->setSingleShot(false);
m_refershTimer->setInterval(100);
m_wirelessApplet->setVisible(false);
m_wirelessPopup->setObjectName("wireless-" + m_device->path());
m_wirelessPopup->setVisible(false);
connect(m_device, static_cast<void (NetworkDevice::*) (const QString &statStr) const>(&NetworkDevice::statusChanged), m_refershTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
connect(static_cast<WirelessDevice *>(m_device), &WirelessDevice::activeApInfoChanged, m_refershTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
connect(static_cast<WirelessDevice *>(m_device), &WirelessDevice::activeConnectionChanged, m_refershTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
connect(m_refershTimer, &QTimer::timeout, [=] {
WirelessDevice *dev = static_cast<WirelessDevice *>(m_device);
// the status is Activated and activeApInfo is empty if the hotspot status of this wireless device is enabled
if (m_device->status() == NetworkDevice::Activated && dev->activeApInfo().isEmpty() && !dev->hotspotEnabled()) {
Q_EMIT queryActiveConnInfo();
return;
}
updateIcon();
});
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
}
WirelessTrayWidget::~WirelessTrayWidget()
{
m_APList->deleteLater();
m_APList->controlPanel()->deleteLater();
}
void WirelessTrayWidget::setActive(const bool active)
{
}
void WirelessTrayWidget::updateIcon()
{
QString type;
const auto state = m_device->status();
if (state <= NetworkDevice::Disconnected) {
type = "disconnect";
m_refershTimer->stop();
} else {
int strength = 0;
if (state == NetworkDevice::Activated) {
const auto &activeApInfo = static_cast<WirelessDevice *>(m_device)->activeApInfo();
if (!activeApInfo.isEmpty()) {
strength = activeApInfo.value("Strength").toInt();
m_refershTimer->stop();
}
} else {
strength = QTime::currentTime().msec() / 10 % 100;
if (!m_refershTimer->isActive())
m_refershTimer->start();
}
if (strength == 100)
type = "80";
else if (strength < 20)
type = "0";
else
type = QString::number(strength / 10 & ~0x1) + "0";
}
const QString key = QString("wireless-%1%2")
.arg(type)
.arg("-symbolic");
const auto ratio = qApp->devicePixelRatio();
m_reloadIcon = true;
m_pixmap = cachedPix(key, 16 * ratio);
m_pixmap.setDevicePixelRatio(ratio);
update();
}
void WirelessTrayWidget::sendClick(uint8_t mouseButton, int x, int y)
{
}
const QImage WirelessTrayWidget::trayImage()
{
return m_pixmap.toImage();
}
QWidget *WirelessTrayWidget::itemApplet()
{
return m_wirelessApplet;
}
QWidget *WirelessTrayWidget::itemTips()
{
const NetworkDevice::DeviceStatus stat = m_device->status();
m_wirelessPopup->setText(tr("No Network"));
if (stat == NetworkDevice::Activated)
{
const QJsonObject obj = static_cast<WirelessDevice *>(m_device)->activeConnectionInfo();
if (obj.contains("Ip4"))
{
const QJsonObject ip4 = obj["Ip4"].toObject();
if (ip4.contains("Address"))
{
m_wirelessPopup->setText(tr("Wireless Connection: %1").arg(ip4["Address"].toString()));
}
}
}
return m_wirelessPopup;
}
void WirelessTrayWidget::onNeedSecrets(const QString &info)
{
m_APList->onNeedSecrets(info);
}
void WirelessTrayWidget::onNeedSecretsFinished(const QString &info0, const QString &info1)
{
m_APList->onNeedSecretsFinished(info0, info1);
}
void WirelessTrayWidget::setDeviceInfo(const int index)
{
m_APList->setDeviceInfo(index);
}
bool WirelessTrayWidget::eventFilter(QObject *o, QEvent *e)
{
if (o == m_APList && e->type() == QEvent::Resize)
QMetaObject::invokeMethod(this, "adjustHeight", Qt::QueuedConnection);
if (o == m_APList && e->type() == QEvent::Show)
Q_EMIT requestWirelessScan();
return false;
}
void WirelessTrayWidget::paintEvent(QPaintEvent *e)
{
AbstractNetworkTrayWidget::paintEvent(e);
const auto ratio = qApp->devicePixelRatio();
QPainter painter(this);
painter.drawPixmap(rect().center() - m_pixmap.rect().center() / ratio, m_pixmap);
if (m_reloadIcon)
m_reloadIcon = false;
}
void WirelessTrayWidget::resizeEvent(QResizeEvent *e)
{
AbstractNetworkTrayWidget::resizeEvent(e);
m_icons.clear();
}
const QPixmap WirelessTrayWidget::cachedPix(const QString &key, const int size)
{
if (m_reloadIcon || !m_icons.contains(key)) {
m_icons.insert(key, QIcon::fromTheme(key, QIcon(":/wireless/resources/wireless/" + key + ".svg")).pixmap(size));
}
return m_icons.value(key);
}
void WirelessTrayWidget::init()
{
m_APList = new WirelessList(static_cast<WirelessDevice *>(m_device));
m_APList->installEventFilter(this);
m_APList->setObjectName("wireless-" + m_device->path());
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(m_APList->controlPanel());
vLayout->addWidget(m_APList);
vLayout->setMargin(0);
vLayout->setSpacing(0);
m_wirelessApplet->setLayout(vLayout);
connect(m_APList, &WirelessList::requestSetDeviceEnable, this, &WirelessTrayWidget::requestSetDeviceEnable);
connect(m_APList, &WirelessList::requestActiveAP, this, &WirelessTrayWidget::requestActiveAP);
connect(m_APList, &WirelessList::requestDeactiveAP, this, &WirelessTrayWidget::requestDeactiveAP);
connect(m_APList, &WirelessList::feedSecret, this, &WirelessTrayWidget::feedSecret);
connect(m_APList, &WirelessList::cancelSecret, this, &WirelessTrayWidget::cancelSecret);
connect(m_APList, &WirelessList::requestWirelessScan, this, &WirelessTrayWidget::requestWirelessScan);
connect(m_APList, &WirelessList::queryConnectionSession, this, &WirelessTrayWidget::queryConnectionSession);
connect(m_APList, &WirelessList::createApConfig, this, &WirelessTrayWidget::createApConfig);
QTimer::singleShot(0, this, [=]() {
m_refershTimer->start();
});
}
// called in eventFilter method
void WirelessTrayWidget::adjustHeight()
{
m_wirelessApplet->setFixedHeight(m_APList->height() + m_APList->controlPanel()->height());
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WIRELESSTRAYWIDGET_H
#define WIRELESSTRAYWIDGET_H
#include "constants.h"
#include "abstractnetworktraywidget.h"
#include "applet/wirelesslist.h"
#include <QHash>
#include <QLabel>
#include <WirelessDevice>
class TipsWidget;
class WirelessTrayWidget : public AbstractNetworkTrayWidget
{
Q_OBJECT
public:
explicit WirelessTrayWidget(dde::network::WirelessDevice *device, QWidget *parent = nullptr);
~WirelessTrayWidget();
public:
void setActive(const bool active) Q_DECL_OVERRIDE;
void updateIcon() Q_DECL_OVERRIDE;
void sendClick(uint8_t mouseButton, int x, int y) Q_DECL_OVERRIDE;
const QImage trayImage() Q_DECL_OVERRIDE;
QWidget *itemApplet();
QWidget *itemTips();
public Q_SLOTS:
void onNeedSecrets(const QString &info);
void onNeedSecretsFinished(const QString &info0, const QString &info1);
// set the device name displayed
// in the top-left corner of the applet
void setDeviceInfo(const int index);
Q_SIGNALS:
void requestActiveAP(const QString &devPath, const QString &apPath, const QString &uuid) const;
void requestDeactiveAP(const QString &devPath) const;
void feedSecret(const QString &connectionPath, const QString &settingName, const QString &password, const bool autoConnect);
void cancelSecret(const QString &connectionPath, const QString &settingName);
void queryActiveConnInfo();
void requestWirelessScan();
void createApConfig(const QString &devPath, const QString &apPath);
void queryConnectionSession( const QString &devPath, const QString &uuid );
protected:
bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private:
const QPixmap cachedPix(const QString &key, const int size);
private Q_SLOTS:
void init();
void adjustHeight();
private:
QTimer *m_refershTimer;
QWidget *m_wirelessApplet;
TipsWidget *m_wirelessPopup;
WirelessList *m_APList;
QHash<QString, QPixmap> m_icons;
QPixmap m_pixmap;
bool m_reloadIcon;
};
#endif // WIRELESSTRAYWIDGET_H

View File

@ -32,8 +32,8 @@
class NetworkPlugin : public QObject, PluginsItemInterface
{
Q_OBJECT
Q_INTERFACES(PluginsItemInterface)
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "network.json")
// Q_INTERFACES(PluginsItemInterface)
// Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "network.json")
public:
explicit NetworkPlugin(QObject *parent = 0);

View File

@ -0,0 +1,153 @@
#include "networktrayloader.h"
#include "item/wiredtraywidget.h"
#include "item/wirelesstraywidget.h"
using namespace dde::network;
#define NetworkItemKeyPrefix "system-tray-network-"
#define NetworkService "com.deepin.daemon.Network"
NetworkTrayLoader::NetworkTrayLoader(QObject *parent)
: AbstractTrayLoader(NetworkService, parent),
m_networkModel(nullptr),
m_networkWorker(nullptr),
m_delayRefreshTimer(new QTimer)
{
m_delayRefreshTimer->setSingleShot(true);
m_delayRefreshTimer->setInterval(2000);
connect(m_delayRefreshTimer, &QTimer::timeout, this, &NetworkTrayLoader::refreshWiredItemVisible);
}
void NetworkTrayLoader::load()
{
m_networkModel = new NetworkModel;
m_networkWorker = new NetworkWorker(m_networkModel);
connect(m_networkModel, &NetworkModel::deviceListChanged, this, &NetworkTrayLoader::onDeviceListChanged);
m_networkModel->moveToThread(qApp->thread());
m_networkWorker->moveToThread(qApp->thread());
onDeviceListChanged(m_networkModel->devices());
}
AbstractNetworkTrayWidget *NetworkTrayLoader::trayWidgetByPath(const QString &path)
{
for (auto trayWidget : m_trayWidgetsMap.values()) {
if (trayWidget->path() == path) {
return trayWidget;
}
}
Q_UNREACHABLE();
return nullptr;
}
void NetworkTrayLoader::onDeviceListChanged(const QList<dde::network::NetworkDevice *> devices)
{
QList<QString> mPaths = m_trayWidgetsMap.keys();
QList<QString> newPaths;
QList<WirelessTrayWidget *> wirelessTrayList;
for (auto device : devices) {
const QString &path = device->path();
newPaths << path;
// new device
if (!mPaths.contains(path)) {
AbstractNetworkTrayWidget *networkTray = nullptr;
switch (device->type()) {
case NetworkDevice::Wired:
networkTray = new WiredTrayWidget(static_cast<WiredDevice *>(device));
break;
case NetworkDevice::Wireless:
networkTray = new WirelessTrayWidget(static_cast<WirelessDevice *>(device));
wirelessTrayList.append(static_cast<WirelessTrayWidget *>(networkTray));
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::queryActiveConnInfo,
m_networkWorker, &NetworkWorker::queryActiveConnInfo);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::requestActiveAP,
m_networkWorker, &NetworkWorker::activateAccessPoint);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::requestDeactiveAP,
m_networkWorker, &NetworkWorker::disconnectDevice);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::feedSecret,
m_networkWorker, &NetworkWorker::feedSecret);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::cancelSecret,
m_networkWorker, &NetworkWorker::cancelSecret);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::requestWirelessScan,
m_networkWorker, &NetworkWorker::requestWirelessScan);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::createApConfig,
m_networkWorker, &NetworkWorker::createApConfig);
connect(static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::queryConnectionSession,
m_networkWorker, &NetworkWorker::queryConnectionSession);
connect(m_networkModel, &NetworkModel::needSecrets,
static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::onNeedSecrets);
connect(m_networkModel, &NetworkModel::needSecretsFinished,
static_cast<WirelessTrayWidget *>(networkTray), &WirelessTrayWidget::onNeedSecretsFinished);
m_networkWorker->queryAccessPoints(path);
m_networkWorker->requestWirelessScan();
break;
default:
Q_UNREACHABLE();
}
mPaths << path;
m_trayWidgetsMap.insert(path, networkTray);
connect(device, &dde::network::NetworkDevice::enableChanged,
m_delayRefreshTimer, static_cast<void (QTimer:: *)()>(&QTimer::start));
// connect(networkTray, &AbstractNetworkTrayWidget::requestContextMenu, this, &NetworkPlugin::contextMenuRequested);
connect(networkTray, &AbstractNetworkTrayWidget::requestSetDeviceEnable, m_networkWorker, &NetworkWorker::setDeviceEnable);
}
}
for (auto mPath : mPaths) {
// removed device
if (!newPaths.contains(mPath)) {
Q_EMIT systemTrayRemoved(NetworkItemKeyPrefix + mPath);
m_trayWidgetsMap.take(mPath)->deleteLater();
break;
}
Q_EMIT systemTrayAdded(NetworkItemKeyPrefix + mPath, m_trayWidgetsMap.value(mPath));
}
int wirelessItemCount = wirelessTrayList.size();
for (int i = 0; i < wirelessItemCount; ++i) {
QTimer::singleShot(1, [=] {
wirelessTrayList.at(i)->setDeviceInfo(wirelessItemCount == 1 ? -1 : i + 1);
});
}
m_delayRefreshTimer->start();
}
void NetworkTrayLoader::refreshWiredItemVisible()
{
bool hasWireless = false;
QList<WiredTrayWidget *> wiredTrayList;
for (auto trayWidget : m_trayWidgetsMap.values()) {
if (trayWidget->device()->type() == NetworkDevice::Wireless) {
hasWireless = true;
} else {
wiredTrayList.append(static_cast<WiredTrayWidget *>(trayWidget));
}
}
if (!hasWireless) {
return;
}
for (auto wiredTrayWidget : wiredTrayList) {
if (!wiredTrayWidget->device()->enabled()) {
Q_EMIT systemTrayRemoved(NetworkItemKeyPrefix + wiredTrayWidget->path());
} else {
Q_EMIT systemTrayAdded(NetworkItemKeyPrefix + wiredTrayWidget->path(), wiredTrayWidget);
}
}
}

View File

@ -0,0 +1,36 @@
#ifndef NETWORKTRAYLOADER_H
#define NETWORKTRAYLOADER_H
#include "../abstracttrayloader.h"
#include "item/abstractnetworktraywidget.h"
#include <QObject>
#include <NetworkWorker>
#include <NetworkModel>
class NetworkTrayLoader : public AbstractTrayLoader
{
Q_OBJECT
public:
explicit NetworkTrayLoader(QObject *parent = nullptr);
public Q_SLOTS:
void load() Q_DECL_OVERRIDE;
private:
AbstractNetworkTrayWidget *trayWidgetByPath(const QString &path);
private Q_SLOTS:
void onDeviceListChanged(const QList<dde::network::NetworkDevice *> devices);
void refreshWiredItemVisible();
private:
dde::network::NetworkModel *m_networkModel;
dde::network::NetworkWorker *m_networkWorker;
QMap<QString, AbstractNetworkTrayWidget *> m_trayWidgetsMap;
QTimer *m_delayRefreshTimer;
};
#endif // NETWORKTRAYLOADER_H

View File

Before

Width:  |  Height:  |  Size: 932 B

After

Width:  |  Height:  |  Size: 932 B

View File

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 956 B

View File

Before

Width:  |  Height:  |  Size: 980 B

After

Width:  |  Height:  |  Size: 980 B

View File

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 956 B

View File

Before

Width:  |  Height:  |  Size: 1009 B

After

Width:  |  Height:  |  Size: 1009 B

View File

Before

Width:  |  Height:  |  Size: 962 B

After

Width:  |  Height:  |  Size: 962 B

Some files were not shown because too many files have changed in this diff Show More