Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,11 @@ install(DIRECTORY assets/deepin-compressor DESTINATION ${CMAKE_INSTALL_DATADIR}/

# 支持压缩的格式
#install(FILES conf/compressor-singlecompress.conf DESTINATION ${CMAKE_INSTALL_DATADIR}/deepin-compressor/compressedformat/)

# Install DBus service file
install(FILES ${CMAKE_CURRENT_LIST_DIR}/com.deepin.Compressor.service
DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services/)

# Install DBus interface XML file
install(FILES ${CMAKE_CURRENT_LIST_DIR}/com.deepin.Compressor.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/interfaces/)
3 changes: 3 additions & 0 deletions src/com.deepin.Compressor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=com.deepin.Compressor
Exec=/usr/bin/deepin-compressor
35 changes: 35 additions & 0 deletions src/com.deepin.Compressor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.deepin.Compressor">
<method name="showWindow">
<arg direction="out" type="b"/>
</method>
<method name="hideWindow">
<arg direction="out" type="b"/>
</method>
<method name="raiseWindow">
<arg direction="out" type="b"/>
</method>
<method name="raise">
<arg direction="in" type="s" name="sFile"/>
<arg direction="out" type="b"/>
</method>
<method name="quitWindow">
<arg direction="out" type="b"/>
</method>
<method name="compressFiles">
<arg direction="in" type="as" name="filePaths"/>
<arg direction="out" type="b"/>
</method>
<method name="extractFiles">
<arg direction="in" type="s" name="archivePath"/>
<arg direction="in" type="s" name="destinationPath"/>
<arg direction="out" type="b"/>
</method>
<method name="previewArchive">
<arg direction="in" type="s" name="archivePath"/>
<arg direction="out" type="b"/>
</method>
</interface>
</node>
15 changes: 8 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,31 @@ int main(int argc, char *argv[])
showWatermark(sJsonStr, &w);

qDebug() << "Creating DBus adaptor and connecting to session bus";
ApplicationAdaptor adaptor(&app);
ApplicationAdaptor adaptor(&w);
QDBusConnection dbus = QDBusConnection::sessionBus();

if(!orderObject){
qDebug() << "Registering standard DBus service";
if (dbus.registerService("com.deepin.compressor")) {
if (dbus.registerService("com.deepin.Compressor")) {
dbus.registerObject("/com/deepin/Compressor", &w);
qDebug() << "DBus service registered successfully, moving window to center";
Dtk::Widget::moveToCenter(&w);
} else {
qWarning() << "Failed to register standard DBus service";
qWarning() << "Failed to register standard DBus service:" << dbus.lastError().message();
}
} else {
qDebug() << "Registering WPS-specific DBus service";
QString serviceName = "com.deepin.compressor"+QString::number(QGuiApplication::applicationPid());
QString serviceName = "com.deepin.Compressor"+QString::number(QGuiApplication::applicationPid());
if (dbus.registerService(serviceName)) {
qDebug() << "WPS DBus service registered successfully";
QString objectPath = "/"+QString::number(QGuiApplication::applicationPid());
dbus.registerObject(objectPath, &app);
QString objectPath = "/com/deepin/Compressor/"+QString::number(QGuiApplication::applicationPid());
dbus.registerObject(objectPath, &w);
adaptor.setCompressFile(newfilelist.first());
Dtk::Widget::moveToCenter(&w);
w.setProperty(ORDER_JSON, sJsonStr);
qDebug() << "Window properties set for WPS mode";
} else {
qWarning() << "Failed to register WPS DBus service";
qWarning() << "Failed to register WPS DBus service:" << dbus.lastError().message();
}

qDebug() << "Connecting to WPS cryptfs DBus interface";
Expand Down
132 changes: 122 additions & 10 deletions src/source/common/dbusadpator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dbusadpator.h"
#include "mainwindow.h"

Check warning on line 7 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "mainwindow.h" not found.
#include "archivemanager.h"

Check warning on line 8 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "archivemanager.h" not found.

#include <QFileInfo>

Check warning on line 10 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtDebug>

Check warning on line 11 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DSettings>

Check warning on line 12 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "dbusadpator.h"
#include <QMainWindow>

Check warning on line 13 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMainWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusInterface>

Check warning on line 14 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusReply>

Check warning on line 15 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusReply> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 16 in src/source/common/dbusadpator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.

const QString SOPENLIST = "openfiles";

ApplicationAdaptor::ApplicationAdaptor(QApplication *application)
: QDBusAbstractAdaptor(application), app(application)
ApplicationAdaptor::ApplicationAdaptor(MainWindow *mainwindow)
: QDBusAbstractAdaptor(mainwindow), m_mainWindow(mainwindow)
{
qDebug() << "ApplicationAdaptor initialized";
connect(application, SIGNAL(aboutToQuit()), SIGNAL(aboutToQuit()));
connect(application, SIGNAL(focusChanged(QWidget*, QWidget*)),
SLOT(focusChangedSlot(QWidget*, QWidget*)));
}

void ApplicationAdaptor::setMainWindow(MainWindow *mainWindow)
{
m_mainWindow = mainWindow;
}

/**
* @brief setCurOpenFile 设置当前的压缩包文件名
Expand All @@ -32,16 +38,18 @@
m_sFile = sFile;
}


void ApplicationAdaptor::raise(const QString &sFile)
bool ApplicationAdaptor::raise(const QString &sFile)
{
qDebug() << "Raise window request for file:" << sFile;
if(m_sFile.isEmpty() || m_sFile.isNull()) {
qWarning() << "No compress file set, cannot raise window";
return;
return false;
}
if(m_curShowWidget && (m_sFile == sFile))
if(m_curShowWidget && (m_sFile == sFile)) {
m_curShowWidget->activateWindow();
return true;
}
return false;
}

void ApplicationAdaptor::onActiveWindow(qint64 pid)
Expand Down Expand Up @@ -84,5 +92,109 @@
}
}
}
}

// Window management methods
bool ApplicationAdaptor::showWindow()
{
if (m_mainWindow) {
m_mainWindow->show();
m_mainWindow->raise();
m_mainWindow->activateWindow();
return true;
}
return false;
}

bool ApplicationAdaptor::hideWindow()
{
if (m_mainWindow) {
m_mainWindow->hide();
return true;
}
return false;
}

bool ApplicationAdaptor::raiseWindow()
{
if (m_mainWindow) {
m_mainWindow->raise();
m_mainWindow->activateWindow();
return true;
}
return false;
}

bool ApplicationAdaptor::quitWindow()
{
if (m_mainWindow) {
m_mainWindow->close();
return true;
}
return false;
}

bool ApplicationAdaptor::compressFiles(const QStringList &filePaths)
{
if (filePaths.isEmpty()) {
qWarning() << "No files provided for compression";
return false;
}

if (!m_mainWindow) {
qWarning() << "MainWindow not available";
return false;
}

for (const QString &filePath : filePaths) {
if (!QFileInfo::exists(filePath)) {
qWarning() << "File does not exist:" << filePath;
return false;
}
}

showWindow();
m_mainWindow->slotDragSelectedFiles(QStringList{filePaths});
return true;
}

bool ApplicationAdaptor::extractFiles(const QString &archivePath, const QString &destinationPath)
{
if (!QFileInfo::exists(archivePath)) {
qWarning() << "Archive file does not exist:" << archivePath;
return false;
}

if (!m_mainWindow) {
qWarning() << "MainWindow not available";
return false;
}

QFileInfo destInfo(destinationPath);
if (!destInfo.isDir() || !destInfo.isWritable()) {
qWarning() << "Destination path is not a writable directory:" << destinationPath;
return false;
}

showWindow();
m_mainWindow->slotDragSelectedFiles(QStringList{archivePath});
m_mainWindow->slotUncompressClicked(destinationPath);
return true;
}

bool ApplicationAdaptor::previewArchive(const QString &archivePath)
{
if (!QFileInfo::exists(archivePath)) {
qWarning() << "Archive file does not exist:" << archivePath;
return false;
}

if (!m_mainWindow) {
qWarning() << "MainWindow not available";
return false;
}

showWindow();
m_mainWindow->slotDragSelectedFiles(QStringList{archivePath});
return true;
}
59 changes: 49 additions & 10 deletions src/source/common/dbusadpator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,87 @@
#ifndef DBUS_ADAPTOR
#define DBUS_ADAPTOR

#include <QtDBus/QDBusAbstractAdaptor>

#include "QApplication"
#include <QDBusAbstractAdaptor>

Check warning on line 7 in src/source/common/dbusadpator.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusAbstractAdaptor> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QApplication>
#include <QWidget>
#include <QSettings>
#include <QStringList>

class MainWindow;

/**
* @file d-bus适配器,开放归档管理器d-bus接口
*/
class ApplicationAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.deepin.compressor")
Q_CLASSINFO("D-Bus Interface", "com.deepin.Compressor")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.deepin.compressor\">\n"
" <interface name=\"com.deepin.Compressor\">\n"

" <method name=\"showWindow\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"hideWindow\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"raiseWindow\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"quitWindow\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"compressFiles\">\n"
" <arg direction=\"in\" type=\"as\" name=\"filePaths\"/>\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"extractFiles\">\n"
" <arg direction=\"in\" type=\"s\" name=\"archivePath\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"destinationPath\"/>\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"previewArchive\">\n"
" <arg direction=\"in\" type=\"s\" name=\"archivePath\"/>\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"raise\">\n"
" <arg direction=\"in\" type=\"none\" name=\"raise\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"sFile\"/>\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"

" </interface>\n")

public:
ApplicationAdaptor(QApplication *application);
ApplicationAdaptor(MainWindow *mainwindow);
/**
* @brief setCurOpenFile 设置当前的压缩包文件名
* @param sFile 压缩包文件名
*/
void setCompressFile(const QString &sFile);

void setMainWindow(MainWindow *mainWindow);

public Q_SLOTS:
/**
* @brief raise dbus接口
* @param sFile 压缩包文件名的窗口激活
*/
void raise(const QString &sFile);
bool raise(const QString &sFile);
/**
* @brief onActiveWindow 激活窗口
* @param pid 对应进程id
*/
void onActiveWindow(qint64 pid);

// Window management methods
bool showWindow();
bool hideWindow();
bool raiseWindow();
bool quitWindow();

// Compression related methods
bool compressFiles(const QStringList &filePaths);
bool extractFiles(const QString &archivePath, const QString &destinationPath);
bool previewArchive(const QString &archivePath);

private slots:
/**
* @brief focusChangedSlot 激活窗口切换
Expand All @@ -61,6 +99,7 @@
QApplication *app = nullptr; //运行应用程序实例
QWidget *m_curShowWidget = nullptr; //当前显示窗口
QString m_sFile; //压缩包文件名
MainWindow *m_mainWindow = nullptr; //主窗口指针
};

#endif /* ifndef _DMR_DBUS_ADAPTOR */
12 changes: 12 additions & 0 deletions src/source/compressorapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "compressorapplication.h"
#include "mainwindow.h"
#include "common/dbusadpator.h"

#include <QDBusConnection>
#include <QDBusError>

#include <DCheckBox>
#include <DSuggestButton>
Expand All @@ -16,6 +20,14 @@ CompressorApplication::CompressorApplication(int &argc, char **argv)
: DApplication(argc, argv)
{
qDebug() << "CompressorApplication constructor";

// Register DBus service
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerService("com.deepin.Compressor")) {
qWarning() << "Failed to register DBus service:" << connection.lastError().message();
} else {
qDebug() << "DBus service registered successfully";
}
}

CompressorApplication::~CompressorApplication()
Expand Down
Loading