Skip to content

Commit

Permalink
refacotr: remove all v23 tags
Browse files Browse the repository at this point in the history
The system version number will continue to evolve, the new version of this DFM do not have to consider the compatibility of v20

log: as title
  • Loading branch information
Johnson-zs committed Jul 1, 2024
1 parent 9c5df37 commit 6b935e1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 142 deletions.
14 changes: 4 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ else()
endif()

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR}CMake REQUIRED)
#if no debug, can't out in codke define key '__FUNCTION__' and so on
add_definitions(-DQT_MESSAGELOGCONTEXT)

Expand All @@ -47,15 +46,10 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()

#Indentify the version
if (${DEEPIN_OS_VERSION} MATCHES "23")
add_definitions(-DCOMPILE_ON_V23)
set(COMPLIE_ON_V23 TRUE)
message("COMPILE ON v23")
else()
add_definitions(-DCOMPILE_ON_V20)
set(COMPLIE_ON_V20 TRUE)
message("COMPILE ON v20")
endif()
# TODO: remove it
add_definitions(-DCOMPILE_ON_V23)
set(COMPLIE_ON_V23 TRUE)
message("COMPILE ON v23")

# TODO(zhangs): enable it
# Disbale qDebug(), qInfo(), qWaring(), qCritical()
Expand Down
21 changes: 12 additions & 9 deletions src/apps/dde-desktop/data/applications/dfm-open.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

sys_name=$(grep "^SystemName=" /etc/os-version | cut -d'=' -f2)
sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2)
# sys_name=$(grep "^SystemName=" /etc/os-version | cut -d'=' -f2)
# sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2)

# this is for adapt the new ApplicationManager.
# open computer/trash root with 'gio open',
Expand All @@ -16,11 +16,14 @@ sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2)
# So, after opening a directory with xdg-open,
# the application's cgroup can be categorized into the file manager as expected.

if [ "$sys_name" = "Deepin" ] && [ "$sys_ver" = "23" ]; then
echo "open $1 with xdg-open."
xdg-open $1
else
echo "open $1 with gio open."
gio open $1
fi
# if [ "$sys_name" = "Deepin" ] && [ "$sys_ver" = "23" ]; then
# echo "open $1 with xdg-open."
# xdg-open $1
# else
# echo "open $1 with gio open."
# gio open $1
# fi

echo "open $1 with xdg-open."
xdg-open $1

25 changes: 10 additions & 15 deletions src/dfm-base/utils/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@
#include <sys/stat.h>
#include <linux/limits.h>

#ifdef COMPILE_ON_V23
# define APPEARANCE_SERVICE "org.deepin.dde.Appearance1"
# define APPEARANCE_PATH "/org/deepin/dde/Appearance1"
#else
# define APPEARANCE_SERVICE "com.deepin.daemon.Appearance"
# define APPEARANCE_PATH "/com/deepin/daemon/Appearance"
#endif
#define APPEARANCE_SERVICE "org.deepin.dde.Appearance1"
#define APPEARANCE_PATH "/org/deepin/dde/Appearance1"

namespace dfmbase {

Expand Down Expand Up @@ -772,16 +767,16 @@ QString FileUtils::toUnicode(const QByteArray &data, const QString &fileName)
if (data.isEmpty())
return QString();

// const QByteArray &encoding = detectCharset(data, fileName);
// const QByteArray &encoding = detectCharset(data, fileName);

// if (QTextCodec *codec = QTextCodec::codecForName(encoding)) {
// return codec->toUnicode(data);
// }
// if (QTextCodec *codec = QTextCodec::codecForName(encoding)) {
// return codec->toUnicode(data);
// }

// // auto decoder = QStringDecoder(QStringEncoder::System);
// // QString decoding = decoder.decode(encoding);
// // if (!decoding.isEmpty())
// // return decoding;
// // auto decoder = QStringDecoder(QStringEncoder::System);
// // QString decoding = decoder.decode(encoding);
// // if (!decoding.isEmpty())
// // return decoding;

return QString::fromLocal8Bit(data);
}
Expand Down
128 changes: 20 additions & 108 deletions src/dfm-base/utils/universalutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,25 @@
#include <QRegularExpression>
#include <DUtil>

#ifdef COMPILE_ON_V23
# define APP_MANAGER_SERVICE "org.desktopspec.ApplicationManager1"
# define APP_MANAGER_PATH_PREFIX "/org/desktopspec/ApplicationManager1"
# define APP_INTERFACE "org.desktopspec.ApplicationManager1.Application"

# define SYSTEM_SYSTEMINFO_SERVICE "org.deepin.dde.SystemInfo1"
# define SYSTEM_SYSTEMINFO_PATH "/org/deepin/dde/SystemInfo1"
# define SYSTEM_SYSTEMINFO_INTERFACE "org.deepin.dde.SystemInfo1"

# define DEAMON_SYSTEMINFO_SERVICE "org.deepin.daemon.SystemInfo1"
# define DEAMON_SYSTEMINFO_PATH "/org/deepin/daemon/SystemInfo1"
# define DEAMON_SYSTEMINFO_INTERFACE "org.deepin.daemon.SystemInfo1"

# define DEAMON_DOCK_SERVICE "org.deepin.dde.daemon.Dock1"
# define DEAMON_DOCK_PATH "/org/deepin/dde/daemon/Dock1"
# define DEAMON_DOCK_INTERFACE "org.deepin.dde.daemon.Dock1"

# define DDE_LOCKSERVICE_SERVICE "org.deepin.dde.LockService1"
# define DDE_LOCKSERVICE_PATH "/org/deepin/dde/LockService1"
# define DDE_LOCKSERVICE_INTERFACE "org.deepin.dde.LockService1"
#else
# define APP_MANAGER_SERVICE "com.deepin.SessionManager"
# define APP_MANAGER_PATH "/com/deepin/StartManager"
# define APP_MANAGER_INTERFACE "com.deepin.StartManager"

# define SYSTEM_SYSTEMINFO_SERVICE "com.deepin.system.SystemInfo"
# define SYSTEM_SYSTEMINFO_PATH "/com/deepin/system/SystemInfo"
# define SYSTEM_SYSTEMINFO_INTERFACE "com.deepin.system.SystemInfo"

# define DEAMON_SYSTEMINFO_SERVICE "com.deepin.daemon.SystemInfo"
# define DEAMON_SYSTEMINFO_PATH "/com/deepin/daemon/SystemInfo"
# define DEAMON_SYSTEMINFO_INTERFACE "com.deepin.daemon.SystemInfo"

# define DEAMON_DOCK_SERVICE "com.deepin.dde.daemon.Dock"
# define DEAMON_DOCK_PATH "/com/deepin/dde/daemon/Dock"
# define DEAMON_DOCK_INTERFACE "com.deepin.dde.daemon.Dock"

# define DDE_LOCKSERVICE_SERVICE "com.deepin.dde.LockService"
# define DDE_LOCKSERVICE_PATH "/com/deepin/dde/LockService"
# define DDE_LOCKSERVICE_INTERFACE "com.deepin.dde.LockService"
#endif
#define APP_MANAGER_SERVICE "org.desktopspec.ApplicationManager1"
#define APP_MANAGER_PATH_PREFIX "/org/desktopspec/ApplicationManager1"
#define APP_INTERFACE "org.desktopspec.ApplicationManager1.Application"

#define SYSTEM_SYSTEMINFO_SERVICE "org.deepin.dde.SystemInfo1"
#define SYSTEM_SYSTEMINFO_PATH "/org/deepin/dde/SystemInfo1"
#define SYSTEM_SYSTEMINFO_INTERFACE "org.deepin.dde.SystemInfo1"

#define DEAMON_SYSTEMINFO_SERVICE "org.deepin.daemon.SystemInfo1"
#define DEAMON_SYSTEMINFO_PATH "/org/deepin/daemon/SystemInfo1"
#define DEAMON_SYSTEMINFO_INTERFACE "org.deepin.daemon.SystemInfo1"

#define DEAMON_DOCK_SERVICE "org.deepin.dde.daemon.Dock1"
#define DEAMON_DOCK_PATH "/org/deepin/dde/daemon/Dock1"
#define DEAMON_DOCK_INTERFACE "org.deepin.dde.daemon.Dock1"

#define DDE_LOCKSERVICE_SERVICE "org.deepin.dde.LockService1"
#define DDE_LOCKSERVICE_PATH "/org/deepin/dde/LockService1"
#define DDE_LOCKSERVICE_INTERFACE "org.deepin.dde.LockService1"

namespace dfmbase {

Expand Down Expand Up @@ -260,39 +238,13 @@ bool UniversalUtils::checkLaunchAppInterface()
initStatus = false;
return;
}
#ifndef COMPILE_ON_V23
QDBusInterface introspect(APP_MANAGER_SERVICE,
APP_MANAGER_PATH,
"org.freedesktop.DBus.Introspectable",
QDBusConnection::sessionBus());
introspect.setTimeout(1000);
QDBusPendingReply<QString> reply = introspect.asyncCallWithArgumentList(QStringLiteral("Introspect"), {});
reply.waitForFinished();
if (reply.isFinished() && reply.isValid() && !reply.isError()) {
QString xmlCode = reply.argumentAt(0).toString();
if (xmlCode.contains(APP_MANAGER_INTERFACE)) {
if (xmlCode.contains("LaunchApp")) {
initStatus = true;
} else {
qCWarning(logDFMBase) << QString("%1 : doesn't have LaunchApp interface.").arg(APP_MANAGER_SERVICE);
initStatus = false;
}
} else {
qCWarning(logDFMBase) << QString("%1 : Introspect error").arg(APP_MANAGER_SERVICE) << xmlCode;
initStatus = false;
}
} else {
initStatus = false;
}
#endif
});
return initStatus;
}

bool UniversalUtils::launchAppByDBus(const QString &desktopFile, const QStringList &filePaths)
{
#ifdef COMPILE_ON_V23
const auto &file = QFileInfo{desktopFile};
const auto &file = QFileInfo { desktopFile };
constexpr auto kDesktopSuffix { u8"desktop" };

if (file.suffix() != kDesktopSuffix) {
Expand All @@ -311,52 +263,12 @@ bool UniversalUtils::launchAppByDBus(const QString &desktopFile, const QStringLi
auto reply = appManager.callWithArgumentList(QDBus::Block, QStringLiteral("Launch"), { QVariant::fromValue(QString {}), QVariant::fromValue(filePaths), QVariant::fromValue(QVariantMap {}) });

return reply.type() == QDBusMessage::ReplyMessage;

#else
QDBusInterface appManager(APP_MANAGER_SERVICE,
APP_MANAGER_PATH,
APP_MANAGER_INTERFACE,
QDBusConnection::sessionBus());

QList<QVariant> argumentList;
argumentList << QVariant::fromValue(desktopFile) << QVariant::fromValue(static_cast<uint>(QX11Info::getTimestamp())) << QVariant::fromValue(filePaths);
appManager.asyncCallWithArgumentList(QStringLiteral("LaunchApp"), argumentList);
return true;
#endif
}

bool UniversalUtils::runCommand(const QString &cmd, const QStringList &args, const QString &wd)
{
#ifdef COMPILE_ON_V23
qCDebug(logDFMBase) << "new AM wouldn't provide any method to run Command, so launch cmd by qt:" << cmd << args;
return QProcess::startDetached(cmd, args, wd);
#else
if (checkLaunchAppInterface()) {
qCDebug(logDFMBase) << "launch cmd by dbus:" << cmd << args;
QDBusInterface appManager(APP_MANAGER_SERVICE,
APP_MANAGER_PATH,
APP_MANAGER_INTERFACE,
QDBusConnection::sessionBus());

QList<QVariant> argumentList;
argumentList << QVariant::fromValue(cmd) << QVariant::fromValue(args);

if (!wd.isEmpty()) {
QVariantMap opt = { { "dir", wd } };
argumentList << QVariant::fromValue(opt);
appManager.asyncCallWithArgumentList(QStringLiteral("RunCommandWithOptions"), argumentList);
} else {
appManager.asyncCallWithArgumentList(QStringLiteral("RunCommand"), argumentList);
}

return true;
} else {
qCDebug(logDFMBase) << "launch cmd by qt:" << cmd << args;
return QProcess::startDetached(cmd, args, wd);
}

return false;
#endif
}

int UniversalUtils::dockHeight()
Expand Down

0 comments on commit 6b935e1

Please sign in to comment.