This commit is contained in:
寂静的羽夏 2022-10-19 10:09:54 +08:00
parent ea9688991c
commit 42123144ed
21 changed files with 581 additions and 281 deletions

View File

@ -26,6 +26,10 @@
  本软件定位是本地生产力基础工具,旨在快速启动和使用高效工具。本人不考虑像 utool 和 quicker 之类提供插件商店。该程序不会进行与网络相关的任何操作,所有的插件安装都是本地的。如果有仅本地的需要,待该软件出 beta 之后,可以尝试该软件,发现 Bug 并递交修复。
## Wiki
  教程文档已撰写完毕,点击 [此链接](https://code.gitlink.org.cn/wingsummer/WingTool/wiki/%E7%AE%80%E4%BB%8B) 进行学习如何使用。
## 效果图
<p align="center">
@ -48,3 +52,10 @@
<p align="center">感谢支持</p>
</p>
## 相关仓库
* Gitea : https://code.gitlink.org.cn/wingsummer/WingTool
* Gitee : https://gitee.com/wing-cloud/wing-tool
* Github : https://github.com/Wing-summer/WingTool
* Gitlink : https://www.gitlink.org.cn/wingsummer/WingTool

View File

@ -4,7 +4,15 @@
TestPlugin::TestPlugin(QObject *parent) {
Q_UNUSED(parent);
qRegisterMetaType<TestService>("TestService");
}
int TestPlugin::sdkVersion() { return SDKVERSION; }
QString TestPlugin::signature() { return WINGSUMMER; }
TestPlugin::~TestPlugin() { testmenu->deleteLater(); }
bool TestPlugin::preInit() {
dialog = new QDialog;
dialog->setFixedSize(400, 400);
dialog->setWindowTitle("TestPluginConsole");
@ -20,29 +28,19 @@ TestPlugin::TestPlugin(QObject *parent) {
testmenu = new QAction;
testmenu->setIcon(QIcon(":/TestPlugin/logo.svg"));
testmenu->setText("TestMenu");
return true;
}
int TestPlugin::sdkVersion() { return SDKVERSION; }
QString TestPlugin::signature() { return WINGSUMMER; }
TestPlugin::~TestPlugin() { testmenu->deleteLater(); }
bool TestPlugin::init(QList<WingPluginInfo> loadedplugin) {
Q_UNUSED(loadedplugin);
dialog->show();
auto s = GETPLUGINQM("TestPlugin.qm");
if (!translator.load(s) || !QApplication::installTranslator(&translator)) {
QMessageBox::critical(nullptr, "Error", "Error Loading File!",
QMessageBox::Ok);
return false;
}
return true;
}
void TestPlugin::unload() {
dialog->close();
delete dialog;
testmenu->deleteLater();
}
QString TestPlugin::pluginName() { return "TestPlugin"; }
@ -73,47 +71,23 @@ HookIndex TestPlugin::getHookSubscribe() { return HookIndex::None; }
QObject *TestPlugin::trayRegisteredMenu() { return testmenu; }
QString TestPlugin::translatorFile() { return "TestPlugin.qm"; }
QVariant TestPlugin::pluginServicePipe(int serviceID, QList<QVariant> params) {
Q_UNUSED(params);
switch (serviceID) {
case HostService:
if (params.first() == LoadedPluginMsg) {
testhotkey = registerHotkey(
QKeySequence(Qt::KeyboardModifier::ControlModifier |
Qt::KeyboardModifier::AltModifier | Qt::Key_Q));
if (testhotkey.isNull()) {
tbinfo->append(QString("registerHotkey Error!"));
}
case PLUGINLOADING:
break;
case PLUGINLOADED: {
testhotkey = registerHotkey(
QKeySequence(Qt::KeyboardModifier::ControlModifier |
Qt::KeyboardModifier::AltModifier | Qt::Key_Q));
if (testhotkey.isNull()) {
tbinfo->append(QString("registerHotkey Error!"));
}
break;
case RemoteCallRes:
break;
case HotKeyTriggered:
tbinfo->append(QString("HotKeyTriggered : %1")
.arg(params.first().value<QUuid>().toString()));
break;
case 0:
if (params.count()) {
auto param = params.first();
if (param.canConvert(QMetaType::Int)) {
tbinfo->append(QString("[func1 call] : %1").arg(param.value<int>()));
}
}
break;
case 1:
if (params.count()) {
QStringList res;
for (auto &item : params) {
if (item.canConvert(QMetaType::QString)) {
res.append(item.value<QString>());
} else if (item.canConvert(QMetaType::QStringList)) {
res += item.value<QStringList>();
}
}
tbinfo->append(QString("[func2 call] : ") + res.join(';'));
}
break;
case 2:
dialog->setVisible(!dialog->isVisible());
} break;
default:
tbinfo->append(QString("GetMessage : %1").arg(serviceID));
break;
}
return QVariant();
@ -123,6 +97,10 @@ void TestPlugin::onPluginCenter() {
QMessageBox::information(nullptr, "Settings", "You Clicked Settings!");
}
void TestPlugin::hotkeyTirggered(QUuid id) {
tbinfo->append(QString("HotKeyTriggered : %1").arg(id.toString()));
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(TestPlugin, IWingToolPlg)
#endif // QT_VERSION < 0x050000

View File

@ -50,6 +50,7 @@ public:
QString signature() override;
~TestPlugin() override;
bool preInit() override;
bool init(QList<WingPluginInfo> loadedplugin) override;
void unload() override;
QString pluginName() override;
@ -64,11 +65,14 @@ public:
HookIndex getHookSubscribe() override;
QObject *trayRegisteredMenu() override;
QString translatorFile() override;
public slots:
QVariant pluginServicePipe(int serviceID, QList<QVariant> params) override;
virtual void onPluginCenter() override;
void hotkeyTirggered(QUuid id) override;
private:
QUuid testhotkey;
QDialog *dialog;

View File

@ -102,6 +102,14 @@ Qt::KeyboardModifiers AppManager::getKeyModifiers() const {
return monitor.getKeyModifiers();
}
Qt::MouseButtons AppManager::getMouseButtons() const {
return monitor.getMouseButtons();
}
bool AppManager::isRegistered(QKeySequence &seq) const {
return registeredSeq.contains(seq);
}
void AppManager::setToolIcon(int index, QIcon icon, QString tip) {
toolwin.setIcon(index, icon, tip);
}

View File

@ -26,6 +26,8 @@ public:
void clearHotkey();
Qt::KeyboardModifiers getKeyModifiers() const;
Qt::MouseButtons getMouseButtons() const;
bool isRegistered(QKeySequence &seq) const;
signals:
void buttonPress(Qt::MouseButton btn, int x, int y);

View File

@ -69,6 +69,8 @@ Qt::KeyboardModifiers EventMonitor::getKeyModifiers() const {
return keyModifiers;
}
Qt::MouseButtons EventMonitor::getMouseButtons() const { return mouseBtns; }
void EventMonitor::callback(XPointer ptr, XRecordInterceptData *data) {
(reinterpret_cast<EventMonitor *>(ptr))->handleRecordEvent(data);
}
@ -85,6 +87,7 @@ void EventMonitor::handleRecordEvent(XRecordInterceptData *data) {
switch (event->u.u.detail) {
case Button1: {
btn = Qt::MouseButton::LeftButton;
mouseBtns.setFlag(Qt::MouseButton::LeftButton);
auto clicknow = std::chrono::system_clock::now();
double diff_ms =
@ -104,15 +107,19 @@ void EventMonitor::handleRecordEvent(XRecordInterceptData *data) {
} break;
case Button2:
btn = Qt::MouseButton::MiddleButton;
mouseBtns.setFlag(Qt::MouseButton::MiddleButton);
break;
case Button3:
btn = Qt::MouseButton::RightButton;
mouseBtns.setFlag(Qt::MouseButton::RightButton);
break;
case XButton_1:
btn = Qt::MouseButton::XButton1;
mouseBtns.setFlag(Qt::MouseButton::XButton1);
break;
case XButton_2:
btn = Qt::MouseButton::XButton2;
mouseBtns.setFlag(Qt::MouseButton::XButton2);
break;
}
@ -137,18 +144,23 @@ void EventMonitor::handleRecordEvent(XRecordInterceptData *data) {
switch (event->u.u.detail) {
case Button1:
btn = Qt::MouseButton::LeftButton;
mouseBtns.setFlag(Qt::MouseButton::LeftButton, false);
break;
case Button2:
btn = Qt::MouseButton::MiddleButton;
mouseBtns.setFlag(Qt::MouseButton::MiddleButton, false);
break;
case Button3:
btn = Qt::MouseButton::RightButton;
mouseBtns.setFlag(Qt::MouseButton::RightButton, false);
break;
case XButton_1:
btn = Qt::MouseButton::XButton1;
mouseBtns.setFlag(Qt::MouseButton::XButton1, false);
break;
case XButton_2:
btn = Qt::MouseButton::XButton2;
mouseBtns.setFlag(Qt::MouseButton::XButton2, false);
break;
}
emit buttonRelease(btn, event->u.keyButtonPointer.rootX,

View File

@ -47,6 +47,7 @@ public:
~EventMonitor() override;
Qt::KeyboardModifiers getKeyModifiers() const;
Qt::MouseButtons getMouseButtons() const;
signals:
void buttonPress(Qt::MouseButton btn, int x, int y); // 当鼠标按键被按下时
@ -71,6 +72,7 @@ private:
std::chrono::system_clock::time_point clickbefore;
Qt::KeyboardModifiers keyModifiers;
Qt::MouseButtons mouseBtns;
};
#endif

View File

@ -275,6 +275,13 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
tbtoolinfo->append(QObject::tr("Version:") +
QString::number(plg->pluginVersion()));
tbtoolinfo->append(QObject::tr("Author:") + plg->pluginAuthor());
tbplginfo->append("");
auto fm = tbplginfo->currentCharFormat();
tbplginfo->insertHtml(
QString("<p>%1<a href=\"%2\" title=\"%2\">%2</a></p>")
.arg(QObject::tr("Web:"))
.arg(plg->pluginWebsite()));
tbplginfo->setCurrentCharFormat(fm);
tbtoolinfo->append(QObject::tr("Comment:") + plg->pluginComment());
tbtoolinfo->append(QObject::tr("Provider:") +
plgsys->pluginProvider(plg));
@ -300,6 +307,7 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
tvlayout->addWidget(gw, 0, Qt::AlignCenter);
tbtoolinfo = new DTextBrowser(w);
tbtoolinfo->setUndoRedoEnabled(false);
tbtoolinfo->setOpenExternalLinks(true);
tvlayout->addWidget(tbtoolinfo);
group = new DButtonBox(this);
@ -520,8 +528,9 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
tbplginfo->setUndoRedoEnabled(false);
tbplginfo->setText(tr("No selected plugin."));
tbplginfo->setLineWrapMode(DTextBrowser::LineWrapMode::NoWrap);
tbplginfo->setOpenExternalLinks(true);
pvlayout->addWidget(tbplginfo, 1);
pvlayout->addWidget(tbplginfo);
auto btnplgset = new DPushButton(tr("PluginCenter"), w);
connect(btnplgset, &DPushButton::clicked, this, [=] {
auto plg = plgsys->plugin(lwplgs->currentRow());
@ -548,6 +557,12 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
tbplginfo->append(QObject::tr("Version:") +
QString::number(plg->pluginVersion()));
tbplginfo->append(QObject::tr("Author:") + plg->pluginAuthor());
tbplginfo->append("");
auto fm = tbplginfo->currentCharFormat();
tbplginfo->insertHtml(QString("<p>%1<a href=\"%2\" title=\"%2\">%2</a></p>")
.arg(QObject::tr("Web:"))
.arg(plg->pluginWebsite()));
tbplginfo->setCurrentCharFormat(fm);
tbplginfo->append(QObject::tr("Comment:") + plg->pluginComment());
tbplginfo->append(QObject::tr("Provider:") + plgsys->pluginProvider(plg));
@ -559,7 +574,7 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
auto len = srv.count();
for (auto i = 0; i < len; i++) {
tbplginfo->append(
QString("\t%1 : %2 ( %3 )").arg(i).arg(srvtr[i]).arg(srv[i]));
QString("\t%1 : %2 ( %3 )").arg(i + 1).arg(srvtr[i]).arg(srv[i]));
}
tbplginfo->append(tr("RegisteredHotkey:"));
@ -618,7 +633,7 @@ bool CenterWindow::runTask(ToolStructInfo record) {
for (auto &item : params) {
ps.append(item);
}
plgsys->pluginCall(record.provider, record.serviceID, ps);
plgsys->pluginCall(record.provider, record.serviceID + 1, ps);
return true;
}

View File

@ -25,6 +25,7 @@ PluginSelDialog::PluginSelDialog(DDialog *parent)
tbplginfo->setUndoRedoEnabled(false);
tbplginfo->setText(tr("No selected plugin."));
tbplginfo->setLineWrapMode(DTextBrowser::LineWrapMode::NoWrap);
tbplginfo->setOpenExternalLinks(true);
connect(lsplgs, &DListWidget::itemSelectionChanged, this, [=] {
tbplginfo->clear();
@ -38,6 +39,12 @@ PluginSelDialog::PluginSelDialog(DDialog *parent)
tbplginfo->append(QObject::tr("Version:") +
QString::number(plg->pluginVersion()));
tbplginfo->append(QObject::tr("Author:") + plg->pluginAuthor());
tbplginfo->append("");
auto fm = tbplginfo->currentCharFormat();
tbplginfo->insertHtml(QString("<p>%1<a href=\"%2\" title=\"%2\">%2</a></p>")
.arg(QObject::tr("Web:"))
.arg(plg->pluginWebsite()));
tbplginfo->setCurrentCharFormat(fm);
tbplginfo->append(QObject::tr("Comment:") + plg->pluginComment());
tbplginfo->append(QObject::tr("Provider:") + plgsys->pluginProvider(plg));
tbplginfo->append(QObject::tr("Services:"));
@ -47,7 +54,7 @@ PluginSelDialog::PluginSelDialog(DDialog *parent)
auto len = srvs.count();
for (auto i = 0; i < len; i++) {
tbplginfo->append(
QString("\t%1 : %2 ( %3 )").arg(i).arg(trsrvs[i]).arg(srvs[i]));
QString("\t%1 : %2 ( %3 )").arg(i + 1).arg(trsrvs[i]).arg(srvs[i]));
}
});

View File

@ -56,7 +56,7 @@ void RunDialog::on_accept() {
params.append(item);
}
auto res = plgsys->pluginCall(plgsys->pluginProvider(plg),
cbService->currentIndex(), params);
cbService->currentIndex() + 1, params);
done(res);
}

View File

@ -114,6 +114,12 @@ void ShortCutEditDialog::on_accept() {
return;
}
if (manager->isRegistered(res.seq)) {
DMessageManager::instance()->sendMessage(this, ProgramIcon,
tr("HotkeyRegistered"));
return;
}
res.isPlugin = ps->getSelectedIndex() >= 0;
if (res.isPlugin) {

View File

@ -50,28 +50,7 @@ ToolEditDialog::ToolEditDialog(ToolStructInfo res, DMainWindow *parent)
connect(fcicon, &DFileChooserEdit::textChanged, this, [=] {
auto name = fcicon->text().trimmed();
this->res.iconpath = name;
if (name.isEmpty()) {
sicon = QIcon();
this->refreshIcon();
return;
}
if (QIcon::hasThemeIcon(name)) {
sicon = QIcon::fromTheme(name);
} else {
if (QFile::exists(name)) {
QPixmap img;
if (img.load(name)) {
auto icon = QIcon((img.width() > 64 || img.height() > 64)
? img.scaled(64, 64, Qt::KeepAspectRatio)
: img);
sicon = icon;
} else {
sicon = QIcon();
DMessageManager::instance()->sendMessage(this, ProgramIcon,
tr("InvalidIcon"));
}
}
}
sicon = name.isEmpty() ? QIcon() : Utilities::trimIconFromFile(name);
this->refreshIcon();
});
connect(fcicon, &DFileChooserEdit::fileChoosed, this,

View File

@ -11,3 +11,14 @@
## 有关 issue
&emsp;&emsp;本软件定位是本地生产力基础工具,旨在快速启动和使用高效工具。本人不考虑像 utool 和 quicker 之类提供插件商店。该程序不会进行与网络相关的任何操作,所有的插件安装都是本地的。如果有仅本地的需要,待该软件出 beta 之后,可以尝试该软件,发现 Bug 并递交修复。
## WIKI
&emsp;&emsp;教程文档已撰写完毕,点击 [此链接](https://code.gitlink.org.cn/wingsummer/WingTool/wiki/%E7%AE%80%E4%BB%8B) 进行学习如何使用。
## 相关仓库
* Gitea : https://code.gitlink.org.cn/wingsummer/WingTool
* Gitee : https://gitee.com/wing-cloud/wing-tool
* Github : https://github.com/Wing-summer/WingTool
* Gitlink : https://www.gitlink.org.cn/wingsummer/WingTool

Binary file not shown.

View File

@ -127,33 +127,33 @@
<message>
<location filename="../dialog/centerwindow.cpp" line="157"/>
<location filename="../dialog/centerwindow.cpp" line="197"/>
<location filename="../dialog/centerwindow.cpp" line="374"/>
<location filename="../dialog/centerwindow.cpp" line="412"/>
<location filename="../dialog/centerwindow.cpp" line="378"/>
<location filename="../dialog/centerwindow.cpp" line="416"/>
<source>Add</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="160"/>
<location filename="../dialog/centerwindow.cpp" line="200"/>
<location filename="../dialog/centerwindow.cpp" line="380"/>
<location filename="../dialog/centerwindow.cpp" line="415"/>
<location filename="../dialog/centerwindow.cpp" line="384"/>
<location filename="../dialog/centerwindow.cpp" line="419"/>
<source>Remove</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="163"/>
<location filename="../dialog/centerwindow.cpp" line="198"/>
<location filename="../dialog/centerwindow.cpp" line="310"/>
<location filename="../dialog/centerwindow.cpp" line="386"/>
<location filename="../dialog/centerwindow.cpp" line="413"/>
<location filename="../dialog/centerwindow.cpp" line="312"/>
<location filename="../dialog/centerwindow.cpp" line="390"/>
<location filename="../dialog/centerwindow.cpp" line="417"/>
<source>Edit</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="166"/>
<location filename="../dialog/centerwindow.cpp" line="202"/>
<location filename="../dialog/centerwindow.cpp" line="404"/>
<location filename="../dialog/centerwindow.cpp" line="417"/>
<location filename="../dialog/centerwindow.cpp" line="408"/>
<location filename="../dialog/centerwindow.cpp" line="421"/>
<source>Clear</source>
<translation></translation>
</message>
@ -195,7 +195,7 @@
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="265"/>
<location filename="../dialog/centerwindow.cpp" line="287"/>
<location filename="../dialog/centerwindow.cpp" line="288"/>
<source>FakeName:</source>
<translation></translation>
</message>
@ -206,164 +206,164 @@
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="268"/>
<location filename="../dialog/centerwindow.cpp" line="289"/>
<location filename="../dialog/centerwindow.cpp" line="290"/>
<source>Params:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="282"/>
<location filename="../dialog/centerwindow.cpp" line="291"/>
<location filename="../dialog/centerwindow.cpp" line="283"/>
<location filename="../dialog/centerwindow.cpp" line="292"/>
<source>NoTool</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="286"/>
<location filename="../dialog/centerwindow.cpp" line="287"/>
<source>[File]</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="288"/>
<location filename="../dialog/centerwindow.cpp" line="289"/>
<source>FileName:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="324"/>
<location filename="../dialog/centerwindow.cpp" line="326"/>
<source>Swap</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="352"/>
<location filename="../dialog/centerwindow.cpp" line="355"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="392"/>
<location filename="../dialog/centerwindow.cpp" line="419"/>
<location filename="../dialog/centerwindow.cpp" line="396"/>
<location filename="../dialog/centerwindow.cpp" line="423"/>
<source>Up</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="398"/>
<location filename="../dialog/centerwindow.cpp" line="421"/>
<location filename="../dialog/centerwindow.cpp" line="402"/>
<location filename="../dialog/centerwindow.cpp" line="425"/>
<source>Down</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="423"/>
<location filename="../dialog/centerwindow.cpp" line="427"/>
<source>TopMost</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="456"/>
<location filename="../dialog/centerwindow.cpp" line="460"/>
<source>DownMost</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="507"/>
<location filename="../dialog/centerwindow.cpp" line="511"/>
<source>ToolBox</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="519"/>
<location filename="../dialog/centerwindow.cpp" line="533"/>
<location filename="../dialog/centerwindow.cpp" line="523"/>
<location filename="../dialog/centerwindow.cpp" line="538"/>
<source>No selected plugin.</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="523"/>
<location filename="../dialog/centerwindow.cpp" line="528"/>
<source>PluginCenter</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="540"/>
<location filename="../dialog/centerwindow.cpp" line="545"/>
<source>Name:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="563"/>
<location filename="../dialog/centerwindow.cpp" line="569"/>
<source>RegisteredHotkey:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="569"/>
<location filename="../dialog/centerwindow.cpp" line="575"/>
<source>Plugins</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="588"/>
<location filename="../dialog/centerwindow.cpp" line="594"/>
<source>About</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="593"/>
<location filename="../dialog/centerwindow.cpp" line="599"/>
<source>ThanksForSponsor</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="600"/>
<location filename="../dialog/centerwindow.cpp" line="606"/>
<source>Sponsor</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="627"/>
<location filename="../dialog/centerwindow.cpp" line="643"/>
<location filename="../dialog/centerwindow.cpp" line="633"/>
<location filename="../dialog/centerwindow.cpp" line="649"/>
<source>runErr</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="648"/>
<location filename="../dialog/centerwindow.cpp" line="654"/>
<source>err</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="648"/>
<location filename="../dialog/centerwindow.cpp" line="654"/>
<source>openErr</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="717"/>
<location filename="../dialog/centerwindow.cpp" line="809"/>
<location filename="../dialog/centerwindow.cpp" line="723"/>
<location filename="../dialog/centerwindow.cpp" line="815"/>
<source>ClearSuccess</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="727"/>
<location filename="../dialog/centerwindow.cpp" line="733"/>
<source>HotkeyRegisterFail</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="763"/>
<location filename="../dialog/centerwindow.cpp" line="769"/>
<source>PleaseSelectOne</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="915"/>
<location filename="../dialog/centerwindow.cpp" line="927"/>
<location filename="../dialog/centerwindow.cpp" line="921"/>
<location filename="../dialog/centerwindow.cpp" line="933"/>
<source>Config (*.wtcfg)</source>
<translation> (*.wtcfg)</translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="921"/>
<location filename="../dialog/centerwindow.cpp" line="927"/>
<source>ExportSuccess</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="933"/>
<location filename="../dialog/centerwindow.cpp" line="939"/>
<source>ImportSuccess</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="938"/>
<location filename="../dialog/centerwindow.cpp" line="944"/>
<source>Warn</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="938"/>
<location filename="../dialog/centerwindow.cpp" line="944"/>
<source>ResetSettings</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="949"/>
<location filename="../dialog/centerwindow.cpp" line="955"/>
<source>[%1] RunErr</source>
<translation>%1</translation>
</message>
@ -381,27 +381,27 @@
<translation></translation>
</message>
<message>
<location filename="../dialog/pluginseldialog.cpp" line="32"/>
<location filename="../dialog/pluginseldialog.cpp" line="33"/>
<source>Name:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/pluginseldialog.cpp" line="61"/>
<location filename="../dialog/pluginseldialog.cpp" line="63"/>
<source>Select</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/pluginseldialog.cpp" line="66"/>
<location filename="../dialog/pluginseldialog.cpp" line="68"/>
<source>NoSelection</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/pluginseldialog.cpp" line="72"/>
<location filename="../dialog/pluginseldialog.cpp" line="74"/>
<source>NoPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/pluginseldialog.cpp" line="75"/>
<location filename="../dialog/pluginseldialog.cpp" line="77"/>
<source>Cancel</source>
<translation></translation>
</message>
@ -409,84 +409,90 @@
<context>
<name>PluginSystem</name>
<message>
<location filename="../plugin/pluginsystem.cpp" line="150"/>
<location filename="../plugin/pluginsystem.cpp" line="148"/>
<source>PluginLoadingBegin : %1</source>
<translation>%1</translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="153"/>
<location filename="../plugin/pluginsystem.cpp" line="151"/>
<source>ErrLoadPluginSign</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="158"/>
<location filename="../plugin/pluginsystem.cpp" line="156"/>
<source>ErrLoadPluginSDKVersion</source>
<translation> SDK </translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="163"/>
<location filename="../plugin/pluginsystem.cpp" line="161"/>
<source>ErrLoadPluginNoName</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="170"/>
<location filename="../plugin/pluginsystem.cpp" line="180"/>
<source>ErrLoadPreInitPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="191"/>
<source>ErrLoadPluginNoHandler</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="178"/>
<location filename="../plugin/pluginsystem.cpp" line="185"/>
<location filename="../plugin/pluginsystem.cpp" line="203"/>
<location filename="../plugin/pluginsystem.cpp" line="214"/>
<source>ErrLoadPluginProvider</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="207"/>
<location filename="../plugin/pluginsystem.cpp" line="245"/>
<source>[InvaildPlgSrvArg]</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="219"/>
<location filename="../plugin/pluginsystem.cpp" line="257"/>
<location filename="../plugin/pluginsystem.cpp" line="273"/>
<source>ErLoadPluginService</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="228"/>
<location filename="../plugin/pluginsystem.cpp" line="287"/>
<source>ErrLoadInitPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="250"/>
<location filename="../plugin/pluginsystem.cpp" line="317"/>
<source>PluginInitRegister</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="266"/>
<location filename="../plugin/pluginsystem.cpp" line="333"/>
<source>InvaildPlgMenu in loading %1</source>
<translation> %1 </translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="369"/>
<location filename="../plugin/pluginsystem.cpp" line="575"/>
<source>PluginLoaded : %1 %2</source>
<translation>%1 %2</translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="375"/>
<location filename="../plugin/pluginsystem.cpp" line="581"/>
<source>PluginLoadingEx</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="497"/>
<location filename="../plugin/pluginsystem.cpp" line="505"/>
<location filename="../plugin/pluginsystem.cpp" line="684"/>
<location filename="../plugin/pluginsystem.cpp" line="692"/>
<source>[remoteCallVaildErr]</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="526"/>
<location filename="../plugin/pluginsystem.cpp" line="713"/>
<source>[remoteCallArgErr]</source>
<translation></translation>
</message>
<message>
<location filename="../plugin/pluginsystem.cpp" line="553"/>
<location filename="../plugin/pluginsystem.cpp" line="740"/>
<source>[remoteCallEx]</source>
<translation></translation>
</message>
@ -513,95 +519,107 @@
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="273"/>
<location filename="../dialog/centerwindow.cpp" line="544"/>
<location filename="../dialog/pluginseldialog.cpp" line="36"/>
<location filename="../dialog/centerwindow.cpp" line="549"/>
<location filename="../dialog/pluginseldialog.cpp" line="37"/>
<source>Catagory:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="275"/>
<location filename="../dialog/centerwindow.cpp" line="546"/>
<location filename="../dialog/pluginseldialog.cpp" line="38"/>
<location filename="../dialog/centerwindow.cpp" line="551"/>
<location filename="../dialog/pluginseldialog.cpp" line="39"/>
<source>Version:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="277"/>
<location filename="../dialog/centerwindow.cpp" line="548"/>
<location filename="../dialog/pluginseldialog.cpp" line="40"/>
<location filename="../dialog/centerwindow.cpp" line="553"/>
<location filename="../dialog/pluginseldialog.cpp" line="41"/>
<source>Author:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="278"/>
<location filename="../dialog/centerwindow.cpp" line="549"/>
<location filename="../dialog/pluginseldialog.cpp" line="41"/>
<location filename="../dialog/centerwindow.cpp" line="554"/>
<location filename="../dialog/pluginseldialog.cpp" line="42"/>
<source>Web:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="279"/>
<location filename="../dialog/centerwindow.cpp" line="555"/>
<location filename="../dialog/pluginseldialog.cpp" line="43"/>
<source>Comment:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="279"/>
<location filename="../dialog/centerwindow.cpp" line="550"/>
<location filename="../dialog/pluginseldialog.cpp" line="42"/>
<location filename="../dialog/centerwindow.cpp" line="280"/>
<location filename="../dialog/centerwindow.cpp" line="556"/>
<location filename="../dialog/pluginseldialog.cpp" line="44"/>
<source>Provider:</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/centerwindow.cpp" line="552"/>
<location filename="../dialog/pluginseldialog.cpp" line="43"/>
<location filename="../dialog/centerwindow.cpp" line="558"/>
<location filename="../dialog/pluginseldialog.cpp" line="45"/>
<source>Services:</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="53"/>
<location filename="../main.cpp" line="59"/>
<location filename="../main.cpp" line="169"/>
<location filename="../main.cpp" line="54"/>
<location filename="../main.cpp" line="60"/>
<location filename="../main.cpp" line="176"/>
<source>WingTool</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="61"/>
<location filename="../main.cpp" line="62"/>
<source>A powerful plugin toolbox for Deepin.</source>
<translation> Deepin </translation>
</message>
<message>
<location filename="../main.cpp" line="131"/>
<location filename="../main.cpp" line="132"/>
<source>ErrorLoadingSettings</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="91"/>
<location filename="../main.cpp" line="92"/>
<source>ShowMain</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="135"/>
<location filename="../main.cpp" line="136"/>
<source>Err</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="136"/>
<location filename="../main.cpp" line="137"/>
<source>ErrResetSettings</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="151"/>
<location filename="../main.cpp" line="152"/>
<source>About</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="158"/>
<location filename="../main.cpp" line="159"/>
<source>Wiki</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="165"/>
<source>Sponsor</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="165"/>
<location filename="../main.cpp" line="172"/>
<location filename="../main.cpp" line="179"/>
<source>Exit</source>
<translation>退</translation>
</message>
<message>
<location filename="../main.cpp" line="173"/>
<location filename="../main.cpp" line="180"/>
<source>ConfirmExit</source>
<translation></translation>
</message>
@ -636,7 +654,7 @@
<translation></translation>
</message>
<message>
<location filename="../utilities.h" line="125"/>
<location filename="../utilities.h" line="115"/>
<source>FakeName:%1
Process:%2
Service:%3
@ -647,7 +665,7 @@ Params:%4</source>
%4</translation>
</message>
<message>
<location filename="../utilities.h" line="131"/>
<location filename="../utilities.h" line="121"/>
<source>FakeName:%1
Process:%2
Params:%3</source>
@ -666,12 +684,12 @@ Params:%3</source>
<message>
<location filename="../dialog/rundialog.cpp" line="9"/>
<source>Plugin</source>
<translation></translation>
<translation></translation>
</message>
<message>
<location filename="../dialog/rundialog.cpp" line="21"/>
<source>Service</source>
<translation></translation>
<translation></translation>
</message>
<message>
<location filename="../dialog/rundialog.cpp" line="31"/>
@ -734,7 +752,12 @@ Params:%3</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/shortcuteditdialog.cpp" line="130"/>
<location filename="../dialog/shortcuteditdialog.cpp" line="119"/>
<source>HotkeyRegistered</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/shortcuteditdialog.cpp" line="136"/>
<source>NoProcessSet</source>
<translation></translation>
</message>
@ -781,13 +804,13 @@ Params:%3</source>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="26"/>
<location filename="../dialog/tooleditdialog.cpp" line="88"/>
<location filename="../dialog/tooleditdialog.cpp" line="67"/>
<source>Service</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="32"/>
<location filename="../dialog/tooleditdialog.cpp" line="88"/>
<location filename="../dialog/tooleditdialog.cpp" line="67"/>
<source>FilePath</source>
<translation></translation>
</message>
@ -802,32 +825,27 @@ Params:%3</source>
<translation> (*.png *.svg *.jpg *.jpeg)</translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="71"/>
<source>InvalidIcon</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="120"/>
<location filename="../dialog/tooleditdialog.cpp" line="99"/>
<source>Param</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="126"/>
<location filename="../dialog/tooleditdialog.cpp" line="105"/>
<source>FakeName</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="135"/>
<location filename="../dialog/tooleditdialog.cpp" line="114"/>
<source>IconPreview</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="159"/>
<location filename="../dialog/tooleditdialog.cpp" line="140"/>
<source>NoVaildIconSet</source>
<translation></translation>
</message>
<message>
<location filename="../dialog/tooleditdialog.cpp" line="177"/>
<location filename="../dialog/tooleditdialog.cpp" line="157"/>
<source>NoVaildProcessSet</source>
<translation></translation>
</message>

View File

@ -8,6 +8,7 @@
#include <DApplicationSettings>
#include <DGuiApplicationHelper>
#include <DWidgetUtil>
#include <QDesktopServices>
#include <QMenu>
#include <QMessageBox>
#include <QSystemTrayIcon>
@ -155,6 +156,12 @@ int main(int argc, char *argv[]) {
w.raise();
});
sysmenu.addAction(ac);
ac = new QAction(QObject::tr("Wiki"), menu);
QObject::connect(ac, &QAction::triggered, [=] {
QDesktopServices::openUrl(QUrl("https://code.gitlink.org.cn/wingsummer/"
"WingTool/wiki/%E7%AE%80%E4%BB%8B"));
});
sysmenu.addAction(ac);
ac = new QAction(QObject::tr("Sponsor"), menu);
QObject::connect(ac, &QAction::triggered, [&w] {
w.show(CenterWindow::TabPage::Sponsor);

View File

@ -17,36 +17,24 @@
#define WINGSUMMER "wingsummer"
#define LoadingPluginMsg QVariant::fromValue('l')
#define LoadedPluginMsg QVariant::fromValue('L')
#ifndef Q_MOC_RUN
#define PLUGINSRV
#define PLUGININT
#endif
#define PLUGINSRVTAG "PLUGINSRV"
#define PLUGININTTAG "PLUGININT"
/*=================================*/
// 插件系统预定义服务号,全部为负数
// 如果服务号为非负数,则表示为插件服务
#define HostService -1 // 插件加载消息服务
#define RemoteCallRes -2 // 远程调用结果服务
#define HotKeyTriggered -3 // 热键触发服务
#define HotKeyReleased -4 //热键释放服务
#define HotkeyEnableChanged -5 // 热键状态更改服务
#define PLUGINLOADING -1 // 插件加载中消息
#define PLUGINLOADED -2 // 插件加载完消息
/*=================================*/
struct WingPluginInfo {
QString pluginName;
QString pluginAuthor;
uint pluginVersion;
QString provider;
QString pluginComment;
};
enum class MouseWheelEvent { None, Up, Down, Left, Right };
Q_DECLARE_METATYPE(MouseWheelEvent)
@ -57,7 +45,8 @@ enum class RemoteCallError {
Unkown, // 回调未知错误,通常由于未处理异常导致
PluginNotFound, // 找不到的插件
ServiceNotFound, // 找到插件,但没有找到对应的服务
ArgError // 调用的参数出现问题
ArgError, // 调用的参数出现问题
MessageIDError // 发送消息的 ID 错误,基本发送了小于 0 的消息
};
Q_DECLARE_METATYPE(RemoteCallError)
@ -75,6 +64,8 @@ enum HookIndex {
};
Q_DECLARE_METATYPE(HookIndex)
struct WingPluginInfo;
class IWingToolPlg : public QObject {
Q_OBJECT
public:
@ -96,8 +87,11 @@ public:
virtual QString signature() = 0;
// 析构函数
virtual ~IWingToolPlg() {}
// 插件初始化函数
// 插件预初始化,主要初始化服务以备正式初始化使用,可选
// 如果预初始化失败,则插件会被卸载
// 注:如果提供翻译文件名,此时就已经被加载
virtual bool preInit() { return true; }
// 插件初始化函数,如果初始化失败,则插件会被卸载
virtual bool init(QList<WingPluginInfo> loadedplugin) = 0;
// 插件卸载函数
virtual void unload() = 0;
@ -125,9 +119,12 @@ public:
// 但非必要不要弄,因为这样的插件多了,反而麻烦了,一个插件仅有一项
// 类型仅支持 QMenu* 或者 QAction* 否则不载入
virtual QObject *trayRegisteredMenu() { return nullptr; }
// 插件的语言包文件名,如果空插件系统默认不加载
// 如果有需要还请手动加载
virtual QString translatorFile() { return QString(); }
signals:
// 注册热键,如果被占用则返回 -1 表示失败(通常是重复),
// 注册热键,如果被占用则返回表示失败(通常是重复),
// 大于等于 0 则表示成功,返回句柄
QUuid registerHotkey(QKeySequence keyseq);
@ -150,6 +147,41 @@ signals:
QVariant sendRemoteMessage(const QString provider, int id,
QList<QVariant> params, RemoteCallError &err);
// 查询某个插件是否存在
bool isProviderExists(const QString provider);
// 查询某个插件服务是否含有所述服务
bool isServiceExists(const QString provider, const QString callback);
// 查询某个插件服务是否接口
bool isInterfaceExists(const QString provider, const QString callback);
// 获取服务的参数类型
QList<int> getServiceParamTypes(const QString provider,
const QString callback);
// 获取接口的参数类型
QVector<QList<int>> getInterfaceParamTypes(const QString provider,
const QString callback);
// 获取全局按下的修饰键序列
Qt::KeyboardModifiers getPressedKeyModifiers();
// 获取全局按下的鼠标按键序列
Qt::MouseButtons getPressedMouseButtons();
// 获取所有插件提供者名称
QStringList getPluginProviders();
// 获取插件信息
WingPluginInfo getPluginInfo(const QString provider);
// 获取插件的所有服务名isTr 指示是否使用本地化的
QStringList getPluginServices(const QString provider, bool isTr = false);
// 获取所有插件的所有接口名(注:无去重,可能有重复项)
QStringList getPluginInterfaces(const QString provider);
public slots:
// 宿主开始回调函数时候使用,第一个参数是函数服务索引,第二个是参数集合
virtual QVariant pluginServicePipe(int serviceID, QList<QVariant> params) = 0;
@ -202,22 +234,29 @@ public slots:
}
// 当插件注册的热键触发时会触发该函数
virtual void hotkeyTirggered(int index) { Q_UNUSED(index); }
virtual void hotkeyTirggered(QUuid id) { Q_UNUSED(id); }
// 如果插件注册的热键被释放时会触发该函数
virtual void hotkeyReleased(int index) { Q_UNUSED(index); }
virtual void hotkeyReleased(QUuid id) { Q_UNUSED(id); }
// 如果插件注册的热键启用状态改变时会触发该函数
virtual void hotkeyEnableChanged(bool value, int index) {
virtual void hotkeyEnableChanged(bool value, QUuid id) {
Q_UNUSED(value);
Q_UNUSED(index);
}
// 当系统选词更改时触发该函数(仅 X11 有效Deepin 支持)
virtual void selectionTextChanged(const QString &selectedText) {
Q_UNUSED(selectedText);
Q_UNUSED(id);
}
};
#define IWINGPLUGIN_INTERFACE_IID "com.wingsummer.iwingtoolplg"
Q_DECLARE_INTERFACE(IWingToolPlg, IWINGPLUGIN_INTERFACE_IID)
struct WingPluginInfo {
QString pluginName;
QString pluginAuthor;
IWingToolPlg::Catagorys pluginCatagory;
uint pluginVersion;
QString provider;
QString pluginComment;
QString pluginWebsite;
HookIndex HookSubscribe;
QString translatorFile;
};
#endif // IWINGTOOLPLG_H

View File

@ -19,6 +19,8 @@ PluginSystem::PluginSystem(QMenu *systray, QObject *parent)
InitDispathcer(HookIndex::MouseWheel);
InitDispathcer(HookIndex::DoubleClicked);
InitDispathcer(HookIndex::MouseDrag);
InitDispathcer(HookIndex::ButtonPress);
InitDispathcer(HookIndex::ButtonRelease);
// 初始化类别插件容器
#define InitCatagory(catagory) \
@ -74,14 +76,12 @@ PluginSystem::PluginSystem(QMenu *systray, QObject *parent)
[=](const Hotkey *hotkey) {
if (hotkey->isHostHotkey())
return;
auto uuid = uhmap.key(const_cast<Hotkey *>(hotkey), QUuid());
if (uuid.isNull())
return;
int id;
auto plg = this->loopUpHotkey(uuid, id);
auto plg = this->loopUpHotkey(uuid);
if (plg)
plg->pluginServicePipe(HotKeyTriggered, {uuid});
plg->hotkeyTirggered(uuid);
});
connect(manager, &AppManager::hotkeyReleased, this,
[=](const Hotkey *hotkey) {
@ -91,23 +91,20 @@ PluginSystem::PluginSystem(QMenu *systray, QObject *parent)
auto uuid = uhmap.key(const_cast<Hotkey *>(hotkey), QUuid());
if (uuid.isNull())
return;
int id;
auto plg = this->loopUpHotkey(uuid, id);
auto plg = this->loopUpHotkey(uuid);
if (plg)
plg->pluginServicePipe(HotKeyReleased, {uuid});
plg->hotkeyReleased(uuid);
});
connect(manager, &AppManager::hotkeyEnableChanged, this,
[=](bool value, const Hotkey *hotkey) {
if (hotkey->isHostHotkey())
return;
auto uuid = uhmap.key(const_cast<Hotkey *>(hotkey), QUuid());
if (uuid.isNull())
return;
int id;
auto plg = this->loopUpHotkey(uuid, id);
auto plg = this->loopUpHotkey(uuid);
if (plg)
plg->pluginServicePipe(HotkeyEnableChanged, {value, uuid});
plg->hotkeyEnableChanged(value, uuid);
});
LoadPlugin();
@ -144,6 +141,7 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
QPluginLoader loader(fileinfo.absoluteFilePath());
QList<WingPluginInfo> loadedplginfos;
QList<QVariant> emptyparam;
QTranslator *translator = nullptr;
try {
auto p = qobject_cast<IWingToolPlg *>(loader.instance());
@ -165,10 +163,37 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
return;
}
auto trans = p->translatorFile();
if (trans.length()) {
translator = new QTranslator(this);
auto s = GETPLUGINQM(trans);
if (!translator->load(s) ||
!QApplication::installTranslator(translator)) {
dError(QString("Error Loading translatorFile in %1")
.arg(p->pluginName()));
translator->deleteLater();
translator = nullptr;
}
}
if (!p->preInit()) {
dError(tr("ErrLoadPreInitPlugin"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
auto handler = p->serviceHandler();
if (handler.isNull()) {
dError(tr("ErrLoadPluginNoHandler"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
@ -177,6 +202,10 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
if (clsname == nullptr) {
dError(tr("ErrLoadPluginProvider"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
@ -184,6 +213,10 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
if (provider.isEmpty() || loadedProvider.contains(provider)) {
dError(tr("ErrLoadPluginProvider"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
@ -195,13 +228,16 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
// 暂时缓存一下原函数名称和参数个数,供之后的函数名本地化之用
QVector<const char *> tmpfunc;
QVector<int> tmpfuncargc;
for (auto i = 0; i < srvc; i++) {
auto m = meta->method(i);
bool isinterface = false;
if (strcmp(PLUGINSRVTAG, m.tag())) {
continue;
if (strcmp(PLUGININTTAG, m.tag())) {
continue;
}
isinterface = true;
}
auto argc = m.parameterCount();
@ -210,34 +246,57 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
QString("%1/10").arg(m.parameterCount()));
continue;
}
tmpfuncargc.append(argc);
record.services.append(m);
tmpfunc.append(m.name());
auto name = QString::fromUtf8(m.name());
record.serviceNames.append(name);
if (isinterface) {
record.interfaces.append(m);
auto name = QString::fromUtf8(m.name());
record.interfaceNames.append(name);
} else {
auto name = QString::fromUtf8(m.name());
if (record.serviceNames.contains(name)) {
dError(tr("ErLoadPluginService"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
record.services.append(m);
tmpfunc.append(m.name());
record.serviceNames.append(name);
}
}
if (record.services.isEmpty()) {
dError(tr("ErLoadPluginService"));
p->unload();
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
// 检查完毕后,就可以进入真正的加载环节
emit p->pluginServicePipe(HostService, {LoadingPluginMsg});
emit p->pluginServicePipe(PLUGINLOADING, emptyparam);
if (!p->init(loadedplginfos)) {
dError(tr("ErrLoadInitPlugin"));
p->unload();
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
return;
}
auto len = tmpfunc.count();
for (auto i = 0; i < len; i++) {
for (auto item : tmpfunc) {
record.servicetrNames.append(
QCoreApplication::translate(clsname, tmpfunc[i]) +
QString(" [%1]").arg(tmpfuncargc[i]));
QCoreApplication::translate(clsname, item));
}
WingPluginInfo info;
@ -246,12 +305,16 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
info.pluginAuthor = p->pluginAuthor();
info.pluginComment = p->pluginComment();
info.pluginVersion = p->pluginVersion();
info.pluginWebsite = p->pluginWebsite();
info.HookSubscribe = p->getHookSubscribe();
info.pluginCatagory = p->pluginCatagory();
info.translatorFile = p->translatorFile();
loadedplginfos << info;
m_plgs << p;
loadedProvider << provider;
dWarning(tr("PluginInitRegister"));
dInfo(tr("PluginInitRegister"));
// 看看有没有要注册的托盘
@ -288,6 +351,8 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
INSERTSUBSCRIBE(HookIndex::MouseWheel);
INSERTSUBSCRIBE(HookIndex::DoubleClicked);
INSERTSUBSCRIBE(HookIndex::MouseDrag);
INSERTSUBSCRIBE(HookIndex::ButtonPress);
INSERTSUBSCRIBE(HookIndex::ButtonRelease);
// 连接信号
connect(p, &IWingToolPlg::registerHotkey, this,
@ -375,6 +440,10 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
connect(p, &IWingToolPlg::sendRemoteMessage, this,
[=](const QString provider, int id, QList<QVariant> params,
RemoteCallError &err) {
if (id < 0) {
err = RemoteCallError::MessageIDError;
return QVariant();
}
auto sender = qobject_cast<IWingToolPlg *>(QObject::sender());
if (sender == nullptr) {
err = RemoteCallError::Unkown;
@ -394,8 +463,115 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
err = RemoteCallError::Success;
return res;
});
connect(p, &IWingToolPlg::isProviderExists, this,
[=](const QString provider) {
return loadedProvider.contains(provider);
});
connect(p, &IWingToolPlg::isServiceExists, this,
[=](const QString provider, const QString callback) {
if (callback.trimmed().isEmpty())
return false;
auto plg = plugin(pluginIndexByProvider(provider));
if (plg == nullptr)
return false;
return m_plgrec[plg].serviceNames.contains(callback);
});
connect(p, &IWingToolPlg::isInterfaceExists, this,
[=](const QString provider, const QString callback) {
if (callback.trimmed().isEmpty())
return false;
auto plg = plugin(pluginIndexByProvider(provider));
if (plg == nullptr)
return false;
return m_plgrec[plg].interfaceNames.contains(callback);
});
connect(p, &IWingToolPlg::getServiceParamTypes, this,
[=](const QString provider, const QString callback) {
auto res = QList<int>();
if (callback.trimmed().isEmpty())
return res;
auto plg = plugin(pluginIndexByProvider(provider));
if (plg == nullptr)
return res;
auto &rec = m_plgrec[plg];
auto &srvs = rec.serviceNames;
int id = srvs.indexOf(callback);
if (id < 0)
return res;
auto m = rec.services[id];
auto len = m.parameterCount();
for (auto i = 0; i < len; i++) {
res.append(m.parameterType(i));
}
return res;
});
connect(p, &IWingToolPlg::getInterfaceParamTypes, this,
[=](const QString provider, const QString callback) {
auto res = QVector<QList<int>>();
if (callback.trimmed().isEmpty())
return res;
auto index = this->pluginIndexByProvider(provider);
if (index < 0)
return res;
auto &rec = m_plgrec[m_plgs[index]];
auto &srvs = rec.interfaceNames;
int id = 0;
for (;; id++) {
id = srvs.indexOf(callback, id);
if (id < 0)
return res;
emit p->pluginServicePipe(HostService, {LoadedPluginMsg});
QList<int> infos;
auto m = rec.interfaces[id];
auto len = m.parameterCount();
for (auto i = 0; i < len; i++) {
infos.append(m.parameterType(i));
}
res.append(infos);
}
});
connect(p, &IWingToolPlg::getPressedKeyModifiers, this,
[=] { return this->manager->getKeyModifiers(); });
connect(p, &IWingToolPlg::getPressedMouseButtons, this,
[=] { return this->manager->getMouseButtons(); });
connect(p, &IWingToolPlg::getPluginProviders, this,
[=] { return loadedProvider; });
connect(p, &IWingToolPlg::getPluginInfo, this,
[=](const QString provider) {
auto plg = plugin(pluginIndexByProvider(provider));
WingPluginInfo info{};
if (plg) {
info.provider = provider;
info.pluginName = plg->pluginName();
info.pluginAuthor = plg->pluginAuthor();
info.pluginComment = plg->pluginComment();
info.pluginVersion = plg->pluginVersion();
info.pluginWebsite = plg->pluginWebsite();
info.HookSubscribe = plg->getHookSubscribe();
info.pluginCatagory = plg->pluginCatagory();
info.translatorFile = plg->translatorFile();
}
return info;
});
connect(p, &IWingToolPlg::getPluginServices, this,
[=](const QString provider, bool isTr) {
auto plg = plugin(pluginIndexByProvider(provider));
if (plg) {
return isTr ? this->pluginServicetrNames(plg)
: this->pluginServiceNames(plg);
}
return QStringList();
});
connect(p, &IWingToolPlg::getPluginInterfaces, this,
[=](const QString provider) {
auto plg = plugin(pluginIndexByProvider(provider));
if (plg) {
return m_plgrec[plg].interfaceNames;
}
return QStringList();
});
emit p->pluginServicePipe(PLUGINLOADED, emptyparam);
dInfo(tr("PluginLoaded : %1 %2").arg(p->pluginName()).arg(provider));
} else {
dError(loader.errorString());
@ -404,6 +580,10 @@ void PluginSystem::loadPlugin(QFileInfo fileinfo) {
} catch (...) {
dError(tr("PluginLoadingEx"));
loader.unload();
if (translator) {
QApplication::removeTranslator(translator);
translator->deleteLater();
}
}
}
}
@ -469,57 +649,36 @@ QString PluginSystem::pluginProvider(IWingToolPlg *plg) {
bool PluginSystem::hasRegisteredMenu() { return plgmenuCount > 0; }
IWingToolPlg *PluginSystem::loopUpHotkey(QUuid uuid, int &index) {
IWingToolPlg *PluginSystem::loopUpHotkey(QUuid uuid) {
for (auto plg : m_plgs) {
auto res = m_plgrec[plg].hotkeyuid.indexOf(uuid);
if (res >= 0) {
index = res;
auto res = m_plgrec[plg].hotkeyuid.contains(uuid);
if (res)
return plg;
}
}
return nullptr;
}
int PluginSystem::remoteCall(IWingToolPlg *plg, QString &callback,
QVector<QVariant> params, QVariant &ret) {
// 开始查询有没有对应的函数
auto &srvn = m_plgrec[plg].serviceNames;
auto id = 0;
auto &srv = m_plgrec[plg].services;
for (;; id++) {
id = srvn.indexOf(callback, id);
if (id < 0)
break;
// 先检查一下参数个数
auto &m = srv[id];
if (params.count() != m.parameterCount()) {
continue;
auto id = getCallID(plg, callback, params, false); // 先检查服务有没有
if (!id) {
// 再检查非隐藏服务有没有
id = getCallID(plg, callback, params, true);
if (!id) {
return CALL_INVALID;
}
// 检查类型是否合格
auto len = params.count();
bool invalid = false;
for (auto i = 0; i < len; i++) {
if (!params[i].canConvert(m.parameterType(i))) {
invalid = true;
break;
}
}
if (invalid)
continue;
return remoteCall(plg, id, params, ret);
}
return CALL_INVALID;
return remoteCall(plg, id, params, ret);
}
int PluginSystem::remoteCall(IWingToolPlg *plg, int callID,
QVector<QVariant> params, QVariant &ret) {
if (!callID)
return CALL_INVALID;
auto caller = m_plgrec[plg].services[callID];
auto caller = callID > 0 ? m_plgrec[plg].services[callID - 1]
: m_plgrec[plg].interfaces[-callID - 1];
if (!caller.isValid()) {
dError(tr("[remoteCallVaildErr]") +
@ -584,3 +743,40 @@ int PluginSystem::remoteCall(IWingToolPlg *plg, int callID,
return CALL_EXCEPTION;
}
}
int PluginSystem::getCallID(IWingToolPlg *plg, QString &callback,
QVector<QVariant> params, bool isInterface) {
auto &srvn =
isInterface ? m_plgrec[plg].interfaceNames : m_plgrec[plg].serviceNames;
auto id = 0;
auto &srv = m_plgrec[plg].services;
for (;; id++) {
id = srvn.indexOf(callback, id);
if (id < 0)
break;
// 先检查一下参数个数
auto &m = srv[id];
if (params.count() != m.parameterCount()) {
continue;
}
// 检查类型是否合格
auto len = params.count();
bool invalid = false;
for (auto i = 0; i < len; i++) {
if (!params[i].canConvert(m.parameterType(i))) {
invalid = true;
break;
}
}
if (invalid)
continue;
id++;
return isInterface ? -id : id;
}
return 0;
}

View File

@ -47,11 +47,13 @@ public:
bool hasRegisteredMenu();
private:
IWingToolPlg *loopUpHotkey(QUuid uuid, int &index);
IWingToolPlg *loopUpHotkey(QUuid uuid);
int remoteCall(IWingToolPlg *plg, QString &callback, QVector<QVariant> params,
QVariant &ret);
int remoteCall(IWingToolPlg *plg, int callID, QVector<QVariant> params,
QVariant &ret);
int getCallID(IWingToolPlg *plg, QString &callback, QVector<QVariant> params,
bool isInterface);
private:
struct PluginRecord {
@ -59,6 +61,9 @@ private:
QList<QUuid> hotkeyuid;
QList<QMetaMethod> services;
QList<QMetaMethod> interfaces;
QStringList interfaceNames;
QStringList serviceNames; // 插件服务名缓存
QStringList servicetrNames; // 插件服务本地化名称缓存
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@ -29,7 +29,7 @@ struct ToolStructInfo {
QIcon icon = QIcon(); // 缓存
// 以下仅供插件使用
int serviceID = -1;
int serviceID = -1; // 这个 ID 比服务 CALLID 小 1
int pluginIndex = -1;
QString provider = QString();
QString serviceName = QString(); // 函数服务名缓存