Skip to content

Commit

Permalink
fix: V20、V23接口兼容
Browse files Browse the repository at this point in the history
V20、V23接口兼容

Log: V20、V23接口兼容
  • Loading branch information
feeengli committed Aug 22, 2023
1 parent 966f898 commit b0df1f0
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 160 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ option(DOTEST "option for test" OFF)
# 是否开启单元测试编译
#set(DOTEST ON)

# 判断系统环境
#file(STRINGS "/etc/os-version" MAJOR_STR REGEX "MajorVersion")
execute_process(COMMAND cat /etc/os-version OUTPUT_VARIABLE OS_INFO_STR)
string(REGEX MATCHALL "MajorVersion=[0-9]+" MAJOR_STR "${OS_INFO_STR}")
string(REGEX MATCH "[0-9]+" MAJOR_VERSION "${MAJOR_STR}")
if (MAJOR_VERSION MATCHES "23")
message("--------------------- OS_BUILD_V23 on")
add_definitions(-DOS_BUILD_V23)
endif()

include(GNUInstallDirs)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
Expand Down
32 changes: 30 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,41 @@ Source: deepin-system-monitor
Section: utils
Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends: debhelper (>= 11), cmake, pkg-config, qtbase5-dev, qttools5-dev, libdtkwidget-dev, libxcb1-dev, libqt5x11extras5-dev, libxext-dev, libpcap-dev, qttools5-dev-tools, libicu-dev, deepin-gettext-tools, libxcb-util0-dev, libxcb-icccm4-dev, libnl-3-dev, libnl-route-3-dev, libudev-dev, libgsettings-qt-dev, dde-dock-dev, libgtest-dev, libgmock-dev, libdwayland-dev
Build-Depends:
debhelper (>= 11),
cmake,
pkg-config,
qtbase5-dev,
qttools5-dev,
libdtkwidget-dev,
libxcb1-dev,
libqt5x11extras5-dev,
libxext-dev,
libpcap-dev,
qttools5-dev-tools,
libicu-dev,
deepin-gettext-tools,
libxcb-util0-dev,
libxcb-icccm4-dev,
libnl-3-dev,
libnl-route-3-dev,
libudev-dev,
libgsettings-qt-dev,
dde-dock-dev,
libgtest-dev,
libgmock-dev,
libdwayland-dev | libkf5wayland-dev
Standards-Version: 3.9.8
Homepage: https://github.com/linuxdeepin/deepin-system-monitor

Package: deepin-system-monitor
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libcap2-bin, libdwaylandclient5, libdwaylandserver5,deepin-service-manager
Depends: ${shlibs:Depends},
${misc:Depends},
libcap2-bin,
libdwaylandclient5 | libkf5waylandclient5,
libdwaylandserver5 | libkf5waylandserver5,
deepin-service-manager
Recommends: uos-reporter, deepin-event-log
Replaces: deepin-system-monitor-plugin
Description: A system monitor tool.
Expand Down
24 changes: 23 additions & 1 deletion deepin-system-monitor-main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ check_symbol_exists(SYS_getrandom "sys/syscall.h" HAVE_SYS_GETRANDOM)
include(FindPkgConfig)
if (USE_DEEPIN_WAYLAND)
find_package(DWayland)
find_package(KF5Wayland)
if (DWayland_FOUND)
message("DWayland founded.")
add_definitions(-DDWAYLAND)
elseif(KF5Wayland_FOUND)
message("KF5Wayland founded.")
add_definitions(-DKF5WAYLAND)
endif()
endif()

find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Gui REQUIRED)
Expand All @@ -52,6 +61,9 @@ find_package(DtkCore REQUIRED)
find_package(DtkGui REQUIRED)
find_package(DtkWidget REQUIRED)
find_library(LIB_PCAP NAMES pcap REQUIRED)
if(NOT OS_BUILD_V23)
find_library(LIB_PROCPS NAMES procps REQUIRED)
endif()
find_library(LIB_XCB NAMES xcb REQUIRED)
find_library(LIB_XEXT NAMES Xext REQUIRED)
find_library(LIB_ICCCM NAMES xcb-icccm REQUIRED)
Expand Down Expand Up @@ -592,8 +604,18 @@ set(LIBS
${LIB_UDEV_LIBRARIES}
${DFrameworkDBus_LIBRARIES} # chinalife
)
if(NOT OS_BUILD_V23)
list(APPEND LIBS
${LIB_PROCPS}
)
endif()

if (USE_DEEPIN_WAYLAND)
list(APPEND LIBS DWaylandClient DWaylandServer)
if (OS_BUILD_V23)
list(APPEND LIBS DWaylandClient DWaylandServer)
else()
list(APPEND LIBS KF5::WaylandClient KF5::WaylandServer)
endif()
endif()

file(GLOB APP_TS_FILES LIST_DIRECTORIES false translations/*.ts)
Expand Down
2 changes: 2 additions & 0 deletions deepin-system-monitor-main/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ void WaylandSearchCentered()

if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
WaylandCentered = true;
#ifdef OS_BUILD_V23
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell");
#endif
} else {
WaylandCentered = false;
}
Expand Down
10 changes: 6 additions & 4 deletions deepin-system-monitor-main/dbus/dbusalarmnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#include <QDebug>
#include <QDateTime>

#ifdef OS_BUILD_V23
const QString NotificationService = "org.deepin.dde.Notification1";
const QString NotificationPath = "/org/deepin/dde/Notification1";
const QString NotificationInterface = "org.deepin.dde.Notification1";

//const QString NotificationService = "com.deepin.dde.Notification";
//const QString NotificationPath = "/com/deepin/dde/Notification";
//const QString NotificationInterface = "com.deepin.dde.Notification";
#else
const QString NotificationService = "com.deepin.dde.Notification";
const QString NotificationPath = "/com/deepin/dde/Notification";
const QString NotificationInterface = "com.deepin.dde.Notification";
#endif

#define AlarmMessageTimeOut 10000
QMutex DBusAlarmNotify::mutex;
Expand Down
57 changes: 42 additions & 15 deletions deepin-system-monitor-main/gui/dialog/systemprotectionsetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ int SystemProtectionSetting::m_lastValidCPUValue = 0;
int SystemProtectionSetting::m_lastValidMemoryValue = 0;
int SystemProtectionSetting::m_lastValidInternalValue = 0;


#ifdef OS_BUILD_V23
const QString AppearanceService = "org.deepin.dde.Appearance1";
const QString AppearancePath = "/org/deepin/dde/Appearance1";
const QString AppearanceInterface = "org.deepin.dde.Appearance1";

const QString ControlCenterService = "org.deepin.dde.ControlCenter1";
const QString ControlCenterPath = "/org/deepin/dde/ControlCenter1";
const QString ControlCenterInterface = "org.deepin.dde.ControlCenter1";
#else
const QString AppearanceService = "com.deepin.daemon.Appearance";
const QString AppearancePath = "/com/deepin/daemon/Appearance";
const QString AppearanceInterface = "com.deepin.daemon.Appearance";

const QString ControlCenterService = "com.deepin.dde.ControlCenter";
const QString ControlCenterPath = "/com/deepin/dde/ControlCenter";
const QString ControlCenterInterface = "com.deepin.dde.ControlCenter";
#endif

Q_GLOBAL_STATIC(SystemProtectionSetting, theInstance)

Expand All @@ -55,9 +71,9 @@ bool changeWidgetFontSizeByDiffWithSystem(QWidget *widget, double diff)

// 获取系统字体大小设置

QDBusInterface interface("org.deepin.dde.Appearance1",
"/org/deepin/dde/Appearance1",
"org.deepin.dde.Appearance1");
QDBusInterface interface(AppearanceService,
AppearancePath,
AppearanceInterface);
// 获取失败,返回
if (interface.isValid() == false) {
return false;
Expand Down Expand Up @@ -476,14 +492,17 @@ void SystemProtectionSetting::onMessgaeSetting(QVariant value)

if (genericName.isEmpty() == false) {
// 跳转到设置页并指定Item
QDBusMessage showDDEControlCenterPage = QDBusMessage::createMethodCall("org.deepin.dde.ControlCenter1",
"/org/deepin/dde/ControlCenter1",
"org.deepin.dde.ControlCenter1",
QDBusMessage showDDEControlCenterPage = QDBusMessage::createMethodCall(ControlCenterService,
ControlCenterPath,
ControlCenterInterface,
"ShowPage");
QList<QVariant> args;
#ifdef OS_BUILD_V23
args << QString("notification/%1").append(genericName);
// args.append("notification");
// args.append(genericName);
#else
args.append("notification");
args.append(genericName);
#endif
showDDEControlCenterPage.setArguments(args);

QDBusMessage replyMsg = QDBusConnection::sessionBus().call(showDDEControlCenterPage);
Expand All @@ -496,10 +515,18 @@ void SystemProtectionSetting::onMessgaeSetting(QVariant value)
} else {
// 跳转到设置页
// qdbus org.deepin.dde.ControlCenter1 /org/deepin/dde/ControlCenter1 org.deepin.dde.ControlCenter1.ShowModule notification
QDBusMessage showDDEControlCenter = QDBusMessage::createMethodCall("org.deepin.dde.ControlCenter1",
"/org/deepin/dde/ControlCenter1",
"org.deepin.dde.ControlCenter1",
#ifdef OS_BUILD_V23
QDBusMessage showDDEControlCenter = QDBusMessage::createMethodCall(ControlCenterService,
ControlCenterPath,
ControlCenterInterface,
"ShowPage");
#else
QDBusMessage showDDEControlCenter = QDBusMessage::createMethodCall("com.deepin.dde.ControlCenter",
"/com/deepin/dde/ControlCenter",
"com.deepin.dde.ControlCenter",
"ShowModule");
#endif

QList<QVariant> args;
args << "notification";
showDDEControlCenter.setArguments(args);
Expand Down Expand Up @@ -585,9 +612,9 @@ void SystemProtectionSetting::onUpdateNewBackend()
{
// 创建新的数据后端,应对可能的设置数据变化
QString strConfigPath = QString("%1/%2/%3/protection.conf")
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation))
.arg(qApp->organizationName())
.arg(qApp->applicationName());
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation))
.arg(qApp->organizationName())
.arg(qApp->applicationName());

Dtk::Core::QSettingBackend *newBackend = new QSettingBackend(strConfigPath);
// 为DSetting更新数据后端
Expand Down
46 changes: 1 addition & 45 deletions deepin-system-monitor-main/gui/process_table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,50 +228,7 @@ void ProcessTableView::openExecDirWithFM()
whichProcess.waitForFinished();
QString output(whichProcess.readAllStandardOutput());

QString path = QString(output.split("\n")[0]).trimmed();
// 读取persistent目录
if (path.isEmpty()) {
char nsPath[PATH_MAX] = {0}, nsSelfPath[PATH_MAX] = {0};
auto nsSize = readlink(QString("/proc/%1/ns/pid").arg(pid).toStdString().c_str(), nsPath, PATH_MAX);
auto nsSelfSize = readlink(QString("/proc/self/ns/pid").toStdString().c_str(), nsSelfPath, PATH_MAX);
if (nsSize > 0 && nsSelfSize > 0) {
QString nsPathStr(nsPath), nsSelfPathStr(nsSelfPath);
if (nsPathStr != nsSelfPathStr) {
Process preProc = proc, curProc = proc;
int count = 0;
// 100次循环
while (curProc.name() != "ll-box" && curProc.pid() != 0 && count != 100) {
preProc = curProc;
curProc = ProcessDB::instance()->processSet()->getProcessById(preProc.ppid());
count++;
}
if (curProc.pid() != 0 || count != 100) {
pid = preProc.pid();
}
char exePath[PATH_MAX] = {0};
auto exeSize = readlink(QString("/proc/%1/exe").arg(pid).toStdString().c_str(), exePath, PATH_MAX);
if (exeSize > 0) {
QString exeStr(exePath);
QFile file(QString("/proc/%1/mountinfo").arg(pid));
if (file.open(QIODevice::ReadOnly)) {
QString devStr;
do {
QString line = file.readLine();
auto works = line.split(" ", QString::SkipEmptyParts);
if (works.size() > 9 && exeStr.startsWith(works[4]) && works[9].startsWith("/dev")) {
devStr = works[9];
if (!devStr.isEmpty()) {
path = "/persistent" + works[3] + exeStr.right(exeStr.size() - works[4].size());
}
break;
}
} while (!file.atEnd());
file.close();
}
}
}
}
}
const QString &path = QString(output.split("\n")[0]).trimmed();
common::openFilePathItem(path);
}
// Find flatpak application location.
Expand Down Expand Up @@ -345,7 +302,6 @@ void ProcessTableView::killProcess()
{"process_name", proc.name()}
};
EventLogUtils::get().writeLogs(obj);

ProcessDB::instance()->killProcess(qvariant_cast<pid_t>(m_selectedPID));
} else {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void XWinKillPreviewWidget::initUI()
// default forbid style cursor
m_defaultCursor = QCursor(Qt::ForbiddenCursor);

QTimer::singleShot(800, this, [ = ] {
QTimer::singleShot(500, this, [ = ] {
// show background window in all screens
for (auto screen : QApplication::screens())
{
Expand Down
7 changes: 7 additions & 0 deletions deepin-system-monitor-main/gui/xwin_kill_preview_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
// 使用 USE_DEEPIN_WAYLAND 宏决定编译时是否支持 wayland
// 如果支持,用全局变量 WaylandCentered 运行时控制
#ifdef USE_DEEPIN_WAYLAND
#ifdef DWAYLAND
#include <DWayland/Client/clientmanagement.h>
#include <DWayland/Client/registry.h>
#include <DWayland/Client/connection_thread.h>
#include <DWayland/Client/event_queue.h>
#else
#include <KF5/KWayland/Client/clientmanagement.h>
#include <KF5/KWayland/Client/registry.h>
#include <KF5/KWayland/Client/connection_thread.h>
#include <KF5/KWayland/Client/event_queue.h>
#endif

using namespace KWayland::Client;
#endif // USE_DEEPIN_WAYLAND
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/model/process_table_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,4 @@ qreal ProcessTableModel::getTotalDiskWrite()
diskwrite += proc.writeBps();
}
return diskwrite;
}
}
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/process/desktop_entry_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inline const DesktopEntry DesktopEntryCache::entry(const QString &name) const
inline const DesktopEntry DesktopEntryCache::entryWithSubName(const QString &subName) const
{
for (auto &key : m_cache.keys()) {
if (key.toLower().compare(subName) == 0)
if (key.toLower().compare(subName) == 0)
return m_cache[key];
}
for (auto &key : m_cache.keys()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ DesktopEntry DesktopEntryCacheUpdater::createEntry(const QFileInfo &fileInfo)
}

// startup wm class & name
auto wmclass = dde.stringValue("StartupWMClass").toLower();;
auto wmclass = dde.stringValue("StartupWMClass").toLower();
if (!wmclass.isEmpty()) {
entry->startup_wm_class = wmclass;
entry->name = wmclass;
Expand Down
Loading

0 comments on commit b0df1f0

Please sign in to comment.