72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
#ifndef UTILIES_H
|
|
#define UTILIES_H
|
|
|
|
#include "plugin/iwingtoolplg.h"
|
|
#include <QIcon>
|
|
#include <QKeySequence>
|
|
#include <QMimeDatabase>
|
|
#include <QString>
|
|
#include <QtDBus>
|
|
|
|
#define ProgramIcon QIcon(":/images/logo.svg")
|
|
#define ICONRES(name) QIcon(":/images/" name ".png")
|
|
#define ICONRES2(name) QIcon(":/images/" name ".svg")
|
|
|
|
// 该结构体在不同使用场合下,每个成员含义可能有所变化
|
|
// 也并不是所有的成员在同一个场合用到的
|
|
struct ToolStructInfo {
|
|
bool enabled = false;
|
|
QKeySequence seq = QKeySequence();
|
|
QString process = QString(); // 如果是文件是路径,如果是插件是插件名
|
|
QString params = QString();
|
|
|
|
// 以下仅供插件使用
|
|
int serviceID = -1;
|
|
int pluginIndex = -1;
|
|
QString provider = QString();
|
|
|
|
bool isPlugin = false;
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(ToolStructInfo)
|
|
|
|
class PluginSystem;
|
|
|
|
class Utilities {
|
|
public:
|
|
static bool activeWindowFromDock(quintptr winId) {
|
|
bool bRet = true;
|
|
// new interface use application as id
|
|
QDBusInterface dockDbusInterface("com.deepin.dde.daemon.Dock",
|
|
"/com/deepin/dde/daemon/Dock",
|
|
"com.deepin.dde.daemon.Dock");
|
|
QDBusReply<void> reply = dockDbusInterface.call("ActivateWindow", winId);
|
|
if (!reply.isValid()) {
|
|
qDebug() << "call com.deepin.dde.daemon.Dock failed" << reply.error();
|
|
bRet = false;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
static QIcon processPluginIcon(IWingToolPlg *plg) {
|
|
if (plg->pluginIcon().isNull()) {
|
|
return ICONRES("plugin");
|
|
}
|
|
return plg->pluginIcon();
|
|
}
|
|
|
|
static QIcon trimIconFromInfo(IWingToolPlg *plg, ToolStructInfo &info) {
|
|
if (info.isPlugin) {
|
|
if (plg == nullptr)
|
|
return QIcon();
|
|
return plg->pluginIcon();
|
|
} else {
|
|
QMimeDatabase db;
|
|
auto t = db.mimeTypeForFile(info.process);
|
|
return QIcon::fromTheme(t.iconName(), QIcon(t.iconName()));
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif // UTILIES_H
|