2020-01-17 17:23:40 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2020-03-14 21:36:23 +08:00
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2.1, or (at your option)
|
2020-01-17 17:23:40 +08:00
|
|
|
|
* 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 "taskview.h"
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
|
#include <QDebug>
|
2020-03-01 22:46:04 +08:00
|
|
|
|
#include <QToolBar>
|
|
|
|
|
|
#include <QStyle>
|
2020-03-10 15:10:00 +08:00
|
|
|
|
#include <QDBusInterface>
|
|
|
|
|
|
#include <QDBusReply>
|
2020-03-25 19:09:58 +08:00
|
|
|
|
#include "../panel/customstyle.h"
|
|
|
|
|
|
#include <QPalette>
|
|
|
|
|
|
#include <QToolTip>
|
2020-05-08 21:40:12 +08:00
|
|
|
|
|
|
|
|
|
|
#define UKUI_PANEL_SETTINGS "org.ukui.panel.settings"
|
|
|
|
|
|
#define SHOW_TASKVIEW "showtaskview"
|
2020-06-12 17:07:20 +08:00
|
|
|
|
|
2020-03-25 19:09:58 +08:00
|
|
|
|
TaskViewButton::TaskViewButton(){
|
2020-06-12 17:07:20 +08:00
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2020-03-25 19:09:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
TaskViewButton::~TaskViewButton(){
|
|
|
|
|
|
}
|
2020-02-13 09:05:46 +08:00
|
|
|
|
TaskView::TaskView(const IUKUIPanelPluginStartupInfo &startupInfo) :
|
2020-01-17 17:23:40 +08:00
|
|
|
|
QObject(),
|
|
|
|
|
|
IUKUIPanelPlugin(startupInfo)
|
|
|
|
|
|
{
|
2021-06-28 11:40:57 +08:00
|
|
|
|
qDebug()<<"Plugin-Taskview :: TaskView start";
|
2020-03-25 19:09:58 +08:00
|
|
|
|
mButton =new TaskViewButton();
|
|
|
|
|
|
mButton->setStyle(new CustomStyle());
|
2020-06-12 17:07:20 +08:00
|
|
|
|
mButton->setIcon(QIcon::fromTheme("taskview",QIcon("/usr/share/ukui-panel/panel/img/taskview.svg")));
|
2021-01-08 10:43:52 +08:00
|
|
|
|
QTimer::singleShot(5000,[this] {mButton->setToolTip(tr("Show Taskview")); });
|
2020-05-08 21:40:12 +08:00
|
|
|
|
|
2020-06-12 17:07:20 +08:00
|
|
|
|
/* hide/show taskview
|
|
|
|
|
|
* Monitor gsettings to set TaskViewButton size
|
|
|
|
|
|
*/
|
2020-05-08 21:40:12 +08:00
|
|
|
|
const QByteArray id(UKUI_PANEL_SETTINGS);
|
|
|
|
|
|
if(QGSettings::isSchemaInstalled(id))
|
|
|
|
|
|
gsettings = new QGSettings(id);
|
|
|
|
|
|
connect(gsettings, &QGSettings::changed, this, [=] (const QString &key){
|
2020-06-12 17:07:20 +08:00
|
|
|
|
if(key==SHOW_TASKVIEW)
|
|
|
|
|
|
realign();
|
2020-05-08 21:40:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2020-01-17 17:23:40 +08:00
|
|
|
|
realign();
|
2021-06-28 11:40:57 +08:00
|
|
|
|
qDebug()<<"Plugin-Taskview :: TaskView end";
|
2020-01-17 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-13 09:05:46 +08:00
|
|
|
|
TaskView::~TaskView()
|
2020-01-17 17:23:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-12 17:07:20 +08:00
|
|
|
|
/* 隐藏任务视图按钮的逻辑是将buttton的大小设置为0*/
|
2020-02-13 09:05:46 +08:00
|
|
|
|
void TaskView::realign()
|
2020-01-17 17:23:40 +08:00
|
|
|
|
{
|
2020-05-08 21:40:12 +08:00
|
|
|
|
if(gsettings->get(SHOW_TASKVIEW).toBool())
|
|
|
|
|
|
mButton->setFixedSize(panel()->panelSize(),panel()->panelSize());
|
|
|
|
|
|
else
|
2020-05-20 20:16:19 +08:00
|
|
|
|
mButton->setFixedSize(0,0);
|
2020-03-25 19:09:58 +08:00
|
|
|
|
mButton->setIconSize(QSize(panel()->iconSize(),panel()->iconSize()));
|
2020-01-17 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-12 17:07:20 +08:00
|
|
|
|
/* 两种方式可调用任务视图
|
2020-11-09 15:39:02 +08:00
|
|
|
|
* 1.调用Dbus接口
|
2020-06-12 17:07:20 +08:00
|
|
|
|
* 2.调用二进制
|
|
|
|
|
|
*/
|
2020-03-25 19:09:58 +08:00
|
|
|
|
void TaskViewButton::mousePressEvent(QMouseEvent *event)
|
2020-01-17 17:23:40 +08:00
|
|
|
|
{
|
2020-04-10 17:46:14 +08:00
|
|
|
|
const Qt::MouseButton b = event->button();
|
2020-11-09 15:39:02 +08:00
|
|
|
|
//调用dbus接口
|
|
|
|
|
|
#if 0
|
2020-11-03 17:24:52 +08:00
|
|
|
|
QString object = QString(getenv("DISPLAY"));
|
|
|
|
|
|
object = object.trimmed().replace(":", "_").replace(".", "_").replace("-", "_");
|
|
|
|
|
|
object = "/org/ukui/WindowSwitch/display/" + object;
|
|
|
|
|
|
QDBusInterface interface("org.ukui.WindowSwitch", object,
|
2020-06-12 17:07:20 +08:00
|
|
|
|
"org.ukui.WindowSwitch",
|
|
|
|
|
|
QDBusConnection::sessionBus());
|
2020-03-10 15:10:00 +08:00
|
|
|
|
if (!interface.isValid()) {
|
|
|
|
|
|
qCritical() << QDBusConnection::sessionBus().lastError().message();
|
|
|
|
|
|
}
|
2020-04-10 17:46:14 +08:00
|
|
|
|
|
|
|
|
|
|
if (Qt::LeftButton == b && interface.isValid())
|
|
|
|
|
|
{
|
2020-06-12 17:07:20 +08:00
|
|
|
|
/* Call binary display task view
|
|
|
|
|
|
* system("ukui-window-switch --show-workspace");
|
|
|
|
|
|
*/
|
2020-04-10 17:46:14 +08:00
|
|
|
|
|
2020-06-12 17:07:20 +08:00
|
|
|
|
/*调用远程的value方法*/
|
2020-04-10 17:46:14 +08:00
|
|
|
|
QDBusReply<bool> reply = interface.call("handleWorkspace");
|
|
|
|
|
|
if (reply.isValid()) {
|
|
|
|
|
|
if (!reply.value())
|
|
|
|
|
|
qWarning() << "Handle Workspace View Failed";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
qCritical() << "Call Dbus method failed";
|
|
|
|
|
|
}
|
2020-03-10 15:10:00 +08:00
|
|
|
|
}
|
2020-11-09 15:39:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
//调用命令
|
|
|
|
|
|
if (Qt::LeftButton == b){
|
|
|
|
|
|
system("ukui-window-switch --show-workspace");
|
|
|
|
|
|
}
|
2020-04-10 17:46:14 +08:00
|
|
|
|
|
2020-03-25 19:09:58 +08:00
|
|
|
|
QWidget::mousePressEvent(event);
|
2020-03-01 22:46:04 +08:00
|
|
|
|
}
|