-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some unit tests. Mostly for platformthemeplugin. Log: add some unit tests
- Loading branch information
Showing
14 changed files
with
1,111 additions
and
32 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
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,81 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
#include "filedialogmanagerservice.h" | ||
#include <QUuid> | ||
#include <QDBusConnection> | ||
FileDialogManagerService::FileDialogManagerService(const QString &service, | ||
const QString &path) | ||
: m_service{service}, | ||
m_path{path}, | ||
m_useFileChooserDialog{true}, | ||
m_errorMsg{} | ||
{ | ||
registerAll(); | ||
} | ||
|
||
FileDialogManagerService::~FileDialogManagerService() | ||
{ | ||
unregisterAll(); | ||
} | ||
|
||
bool FileDialogManagerService::registerAll() | ||
{ | ||
QDBusConnection conn = QDBusConnection::sessionBus(); | ||
if (!conn.registerService(m_service)) { | ||
m_errorMsg = QString("Cannot register service %1").arg(m_service); | ||
return false; | ||
} | ||
if (!conn.registerObject(m_path, this, QDBusConnection::ExportAllContents)) { | ||
m_errorMsg = QString("Cannot register object %1").arg(m_path); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool FileDialogManagerService::unregisterAll() | ||
{ | ||
QDBusConnection conn = QDBusConnection::sessionBus(); | ||
conn.unregisterObject(m_path); | ||
if (!conn.unregisterService(m_service)) { | ||
m_errorMsg = QString("Cannot unregister service %1").arg(m_service); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
QList<QDBusObjectPath> FileDialogManagerService::dialogs() | ||
{ | ||
return m_dialogMap.keys(); | ||
} | ||
|
||
QDBusObjectPath FileDialogManagerService::createDialog(const QString key) | ||
{ | ||
QString path{"/com/deepin/filemanager/filedialog/"}; | ||
if (key.isEmpty()) { | ||
path.append(QUuid::createUuid().toRfc4122().toHex()); | ||
} else { | ||
path.append(key); | ||
} | ||
FileDialogService *dialogService = new FileDialogService(path); | ||
m_dialogMap.insert(QDBusObjectPath{path}, dialogService); | ||
return QDBusObjectPath{path}; | ||
} | ||
|
||
void FileDialogManagerService::destroyDialog(const QDBusObjectPath &path) | ||
{ | ||
auto dialog = m_dialogMap.find(path); | ||
dialog.value()->deleteLater(); | ||
m_dialogMap.erase(dialog); | ||
} | ||
|
||
bool FileDialogManagerService::isUseFileChooserDialog() | ||
{ | ||
return m_useFileChooserDialog; | ||
} | ||
|
||
QString FileDialogManagerService::errorString() | ||
{ | ||
return m_errorMsg; | ||
} |
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,58 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
#ifndef FILEDIALOGMANAGERSERVICE_H | ||
#define FILEDIALOGMANAGERSERVICE_H | ||
#include <QDBusContext> | ||
#include <QDBusObjectPath> | ||
#include "filedialogservice.h" | ||
#include <QDBusConnection> | ||
|
||
class FileDialogManagerService : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "com.deepin.filemanager.filedialogmanager") | ||
Q_CLASSINFO("D-Bus Introspection", "" | ||
" <interface name=\"com.deepin.filemanager.filedialogmanager\">\n" | ||
" <method name=\"createDialog\">\n" | ||
" <arg direction=\"in\" type=\"s\" name=\"key\"/>\n" | ||
" <arg direction=\"out\" type=\"o\" name=\"path\"/>\n" | ||
" </method>\n" | ||
" <method name=\"destroyDialog\">\n" | ||
" <arg direction=\"in\" type=\"o\" name=\"path\"/>\n" | ||
" </method>\n" | ||
" <method name=\"dialogs\">\n" | ||
" <arg direction=\"out\" type=\"ao\" name=\"dialogObjectList\"/>\n" | ||
" </method>\n" | ||
" <method name=\"errorString\">\n" | ||
" <arg direction=\"out\" type=\"s\" name=\"error\"/>\n" | ||
" </method>\n" | ||
" <method name=\"isUseFileChooserDialog\">\n" | ||
" <arg direction=\"out\" type=\"b\" name=\"ok\"/>\n" | ||
" </method>\n" | ||
" </interface>\n" | ||
"") | ||
|
||
public: | ||
FileDialogManagerService(const QString &service, const QString &path); | ||
~FileDialogManagerService(); | ||
|
||
public Q_SLOTS: | ||
Q_SCRIPTABLE QDBusObjectPath createDialog(const QString key); | ||
void destroyDialog(const QDBusObjectPath &path); | ||
QList<QDBusObjectPath> dialogs(); | ||
QString errorString(); | ||
bool isUseFileChooserDialog(); | ||
|
||
private: | ||
bool registerAll(); | ||
bool unregisterAll(); | ||
QMap<QDBusObjectPath, FileDialogService*> m_dialogMap; | ||
QString m_service; | ||
QString m_path; | ||
bool m_useFileChooserDialog; | ||
QString m_errorMsg; | ||
}; | ||
|
||
#endif // FILEDIALOGMANAGERSERVICE_H |
Oops, something went wrong.