-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
32 changed files
with
1,157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
20 changes: 20 additions & 0 deletions
20
panels/dock/appruntimeitem/translations/org.deepin.ds.dock.appruntimeitem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.