Skip to content

Commit

Permalink
feat: add appruntimeitem plugin
Browse files Browse the repository at this point in the history
Add a plugin to count application running time and manage application running.

Log: Add a plugin to count application running time and manage application running.
  • Loading branch information
wjyrich committed Oct 21, 2024
1 parent ac43f6b commit bcd4bdd
Show file tree
Hide file tree
Showing 32 changed files with 1,157 additions and 0 deletions.
1 change: 1 addition & 0 deletions panels/dock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ add_subdirectory(showdesktop)
add_subdirectory(taskmanager)
add_subdirectory(tray)
add_subdirectory(multitaskview)
add_subdirectory(appruntimeitem)

# dock qml element(include Dock.xx defines and DockCompositor)
file(
Expand Down
47 changes: 47 additions & 0 deletions panels/dock/appruntimeitem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

if (BUILD_WITH_X11)
find_package(XCB REQUIRED)
add_library(dock-appruntimeitem SHARED
appruntimeitem.cpp
appruntimeitem.h
windowmanager.cpp
windowmanager.h
xcbgetinfo.h
xcbgetinfo.cpp
qmlappruntime.qrc
${CMAKE_SOURCE_DIR}/panels/dock/dockiteminfo.cpp
${CMAKE_SOURCE_DIR}/panels/dock/dockiteminfo.h
${CMAKE_SOURCE_DIR}/panels/dock/taskmanager/x11utils.h
${CMAKE_SOURCE_DIR}/panels/dock/taskmanager/x11utils.cpp
${CMAKE_SOURCE_DIR}/panels/dock/taskmanager/abstractwindow.h
${CMAKE_SOURCE_DIR}/panels/dock/taskmanager/x11window.h
${CMAKE_SOURCE_DIR}/panels/dock/taskmanager/x11window.cpp

#${CMAKE_SOURCE_DIR}/panels/dock/constants.h
)

include_directories(${CMAKE_SOURCE_DIR}/panels/dock)
include_directories(${CMAKE_SOURCE_DIR}/panels/dock/taskmanager)

target_include_directories(dock-appruntimeitem PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/../"
"${CMAKE_SOURCE_DIR}/panels/dock"
)


target_link_libraries(dock-appruntimeitem PRIVATE
dde-shell-frame
${XCB_LIBRARIES}
)
target_link_libraries(dock-appruntimeitem PRIVATE
dde-shell-frame
)

ds_install_package(PACKAGE org.deepin.ds.dock.appruntimeitem TARGET dock-appruntimeitem)
ds_handle_package_translation(PACKAGE org.deepin.ds.dock.appruntimeitem)

install(FILES "package/icons/appruntime.svg" DESTINATION share/dde-dock/icons/dcc-setting)
endif(BUILD_WITH_X11)
86 changes: 86 additions & 0 deletions panels/dock/appruntimeitem/appruntimeitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "appruntimeitem.h"
#include "applet.h"
#include "pluginfactory.h"

#include "../constants.h"

#include <DDBusSender>
#include <DDciIcon>
#include <DGuiApplicationHelper>

#include <QGuiApplication>
#include <QBuffer>
#include<QQuickView>
#include<QQmlContext>
#include <QtQml>

DGUI_USE_NAMESPACE

namespace dock {
AppRuntimeItem::AppRuntimeItem(QObject *parent)
: DApplet(parent)
, m_Visible(true)
, m_appRuntimeVisible(false){}

void AppRuntimeItem::toggleruntimeitem()
{
m_xcbGetInfo.reset(new XcbGetInfo());
m_windowManager.reset(new WindowManager());
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowInfoChanged,
m_windowManager.data(), &WindowManager::setWindowInfoForeground,
Qt::QueuedConnection);
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowInfoChangedForeground,
m_windowManager.data(), &WindowManager::setWindowInfoForeground,
Qt::QueuedConnection);
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowInfoChangedBackground,
m_windowManager.data(), &WindowManager::setWindowInfoBackground,
Qt::QueuedConnection);
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowDestroyChanged,
m_windowManager.data(), &WindowManager::WindowDestroyInfo,
Qt::QueuedConnection);
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowLeaveChangedInactiveName,
m_windowManager.data(), &WindowManager::setWindowInfoInActive,
Qt::QueuedConnection);
connect(m_xcbGetInfo.data(), &XcbGetInfo::windowEnterChangedActiveName,
m_windowManager.data(), &WindowManager::setWindowInfoActive,
Qt::QueuedConnection);
qmlRegisterSingletonInstance<XcbGetInfo>("XcbModule", 1, 0, "XcbGetInstance", m_xcbGetInfo.data());
qmlRegisterSingletonInstance<WindowManager>("WindowModule", 1, 0, "WindowManagerInstance", m_windowManager.data());
}

DockItemInfo AppRuntimeItem::dockItemInfo()
{
DockItemInfo info;
info.name = "appruntime";
info.displayName = tr("appruntime");
info.itemKey = "appruntime";
info.settingKey = "appruntime";
info.visible = m_Visible;
info.dccIcon = DCCIconPath + "appruntime.svg";
return info;
}
void AppRuntimeItem::setVisible(bool visible)
{
if (m_Visible != visible) {
m_Visible = visible;

Q_EMIT visibleChanged(visible);
}
}

void AppRuntimeItem::onappruntimeVisibleChanged(bool visible)
{
if (m_appRuntimeVisible != visible) {
m_appRuntimeVisible = visible;
Q_EMIT appruntimeVisibleChanged(visible);
}
}

D_APPLET_CLASS(AppRuntimeItem)
}

#include "appruntimeitem.moc"
51 changes: 51 additions & 0 deletions panels/dock/appruntimeitem/appruntimeitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once
#include "applet.h"
#include "dsglobal.h"
#include "dockiteminfo.h"

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QThread>
#include <QObject>
#include <QDebug>
#include <QQmlContext>
#include <QQuickWindow>

#include "windowmanager.h"
#include "xcbgetinfo.h"
#include "qmlengine.h"

namespace dock {

class AppRuntimeItem : public DS_NAMESPACE::DApplet
{
Q_OBJECT
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(bool appruntimeVisible READ appruntimeVisible NOTIFY appruntimeVisibleChanged)
public:
explicit AppRuntimeItem(QObject *parent = nullptr);
Q_INVOKABLE void toggleruntimeitem();
Q_INVOKABLE DockItemInfo dockItemInfo();
inline bool visible() const { return m_Visible;}
Q_INVOKABLE void setVisible(bool visible);
Q_INVOKABLE bool appruntimeVisible() const { return m_appRuntimeVisible; }

Q_SIGNALS:
void visibleChanged(bool);
void appruntimeVisibleChanged(bool);

private Q_SLOTS:
void onappruntimeVisibleChanged(bool);

private:
bool m_Visible;
bool m_appRuntimeVisible;
QScopedPointer<XcbGetInfo> m_xcbGetInfo;
QScopedPointer<WindowManager> m_windowManager;
};

}
95 changes: 95 additions & 0 deletions panels/dock/appruntimeitem/package/ShowRuntimeMenu.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.1

import WindowModule 1.0
import XcbModule 1.0

ApplicationWindow {
visible: true
width: 800
height: 400
title: "AppMonitor"
Component.onCompleted: {
XcbGetInstance.getAllOpenedWiondws();
XcbGetInstance.startGetinfo();
}
Column {
anchors.fill: parent

Row {
spacing: 10
width: parent.width
height: 40

Text { text: "AppName"; width: parent.width / 2 }
Text { text: "WindowsId"; width: parent.width / 4 }
Text { text: "RunTime"; width: parent.width / 4 }
}

ListView {
id: listView
anchors.fill: parent
anchors.topMargin: 30
model: WindowManagerInstance

delegate: Item {
width: listView.width
height: 30

Row {
width: parent.width
height: parent.height
spacing: 10

Text {
text: model.name
width: listView.width / 2
elide: Text.ElideRight
horizontalAlignment: Text.AlignLeft
}
Text {
text: model.id
width: listView.width / 4
}
Text {
id: elapsedTimeText
text: "00h:00m:00s"
width: listView.width / 4
}

Timer {
id: timer
interval: 1000
running: true
repeat: true
onTriggered: {
var now = new Date();
var elapsedTime = now - model.startTime;

var hours = Math.floor(elapsedTime / (1000 * 60 * 60));
elapsedTime %= (1000 * 60 * 60);

var minutes = Math.floor(elapsedTime / (1000 * 60));
elapsedTime %= (1000 * 60);

var seconds = Math.floor(elapsedTime / 1000);

var displayText = "";
displayText += (hours < 10 ? "0" + hours : hours) + "h:";
displayText += (minutes < 10 ? "0" + minutes : minutes) + "m:";
displayText += (seconds < 10 ? "0" + seconds : seconds) + "s";

elapsedTimeText.text = displayText;
}
}
}
}
}
}
}

53 changes: 53 additions & 0 deletions panels/dock/appruntimeitem/package/appruntimeitem.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15

import org.deepin.ds 1.0
import org.deepin.dtk 1.0 as D
import org.deepin.ds.dock 1.0

AppletItem {
id: appruntimeitem
property int dockSize: Panel.rootObject.dockSize
property int dockOrder: 1
implicitWidth: Panel.rootObject.useColumnLayout ? dockSize : 30
implicitHeight: Panel.rootObject.useColumnLayout ? 30 : dockSize
property bool shouldVisible: Applet.visible
property D.Palette toolButtonColor: DockPalette.toolButtonColor
property D.Palette toolButtonBorderColor: DockPalette.toolButtonBorderColor
property bool isMenuVisible: false

PanelToolTip {
id: toolTip
text: qsTr("appruntime")
toolTipX: DockPanelPositioner.x
toolTipY: DockPanelPositioner.y
}
AppletItemButton {
id: button
anchors.centerIn: parent
icon.name: "qrc:/ddeshell/package/icons/appruntime.svg"
isActive: Applet.appruntimeVisible
onClicked: {
Applet.toggleruntimeitem()
isMenuVisible = !isMenuVisible
menuLoader.source = isMenuVisible ? "qrc:/ddeshell/package/ShowRuntimeMenu.qml" : ""
}
Loader {
id: menuLoader
anchors.fill: parent
}
onHoveredChanged: {
if (hovered) {
var point = Applet.rootObject.mapToItem(null, Applet.rootObject.width / 2, Applet.rootObject.height / 2)
toolTip.DockPanelPositioner.bounding = Qt.rect(point.x, point.y, toolTip.width, toolTip.height)
toolTip.open()

} else {
toolTip.close()
}
}
}
}
1 change: 1 addition & 0 deletions panels/dock/appruntimeitem/package/icons/appruntime.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions panels/dock/appruntimeitem/package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Plugin": {
"Version": "1.0",
"Id": "org.deepin.ds.dock.appruntimeitem",
"Url": "appruntimeitem.qml",
"Parent": "org.deepin.ds.dock"
}
}
6 changes: 6 additions & 0 deletions panels/dock/appruntimeitem/qmlappruntime.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/ddeshell">
<file>package/icons/appruntime.svg</file>
<file>package/ShowRuntimeMenu.qml</file>
</qresource>
</RCC>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>appruntimeitem</name>
<message>
<location filename="../package/appruntimeitem.qml" line="24"/>
<source>appruntime</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>dock::AppRuntimeItem</name>
<message>
<location filename="../appruntimeitem.cpp" line="39"/>
<source>appruntime</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Loading

0 comments on commit bcd4bdd

Please sign in to comment.