update
This commit is contained in:
parent
b454513cac
commit
883250a38c
|
@ -22,7 +22,7 @@
|
|||
|
||||
  现在工具处于开发状态,很多功能并没有完成:
|
||||
|
||||
1. 配置相关(已完成 90%)
|
||||
1. 配置相关(已完成 95%)
|
||||
2. 语言本地化(已完成 0%)
|
||||
|
||||
  如下是已完成的功能:
|
||||
|
|
|
@ -20,6 +20,12 @@ SettingManager *SettingManager::instance() { return m_instance; }
|
|||
|
||||
bool SettingManager::loadSettings(QString filename) {
|
||||
|
||||
#define CORRECTINFO(info) \
|
||||
info.pluginIndex = plgsys->pluginIndexByProvider(info.provider); \
|
||||
if (info.isPlugin) { \
|
||||
info.process = plgsys->plugin(info.pluginIndex)->pluginName(); \
|
||||
}
|
||||
|
||||
QString strConfigPath = filename.isEmpty()
|
||||
? QString("%1/%2/%3/config.conf")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
|
@ -73,7 +79,7 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
continue;
|
||||
}
|
||||
// 经历过重重检验,合格入库
|
||||
|
||||
CORRECTINFO(buf);
|
||||
emit addHotKeyInfo(buf);
|
||||
} else {
|
||||
// 如果是打开文件就没这么多事情了
|
||||
|
@ -86,13 +92,16 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
}
|
||||
}
|
||||
|
||||
// 下面继续读取 ToolWin 相关信息,只有8条
|
||||
for (auto i = 0; i < 8; i++) {
|
||||
ToolStructInfo buf{true};
|
||||
// 下面继续读取 ToolWin 相关信息
|
||||
for (auto i = 0; i < 9; i++) {
|
||||
ToolStructInfo buf;
|
||||
|
||||
// 对于 ToolWin 来说,这个成员是决定性的
|
||||
// 只有这个标志位有效,这个工具才有意义
|
||||
|
||||
stream >> buf.enabled;
|
||||
if (!buf.enabled)
|
||||
continue;
|
||||
stream >> buf.isPlugin;
|
||||
if (buf.isPlugin) {
|
||||
stream >> buf.serviceID;
|
||||
|
@ -110,6 +119,7 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
continue;
|
||||
}
|
||||
// 经历过重重检验,合格入库
|
||||
CORRECTINFO(buf);
|
||||
emit setToolWinInfo(i, buf);
|
||||
} else { // 如果是打开文件就没这么多事情了
|
||||
QByteArray arr;
|
||||
|
@ -122,7 +132,6 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
}
|
||||
|
||||
// 下面读取 WinTool 相关信息
|
||||
|
||||
stream >> len; // 先读一下有几个
|
||||
for (auto i = 0; i < len; i++) {
|
||||
ToolStructInfo buf;
|
||||
|
@ -137,6 +146,7 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
buf.provider = QString::fromUtf8(arr);
|
||||
stream >> arr;
|
||||
buf.params = QString::fromUtf8(arr);
|
||||
stream >> arr;
|
||||
auto pi = plgsys->pluginIndexByProvider(buf.provider);
|
||||
// 找不到了,插件丢失或者不兼容
|
||||
if (pi < 0)
|
||||
|
@ -145,7 +155,9 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
if (!Utilities::isPluginCompatible(plgsys->plugin(pi), arr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 经历过重重检验,合格入库
|
||||
CORRECTINFO(buf);
|
||||
emit addWinToolInfo(buf);
|
||||
} else {
|
||||
QByteArray arr;
|
||||
|
@ -160,6 +172,7 @@ bool SettingManager::loadSettings(QString filename) {
|
|||
// 如果没有,就加载默认配置
|
||||
emit loadedGeneral();
|
||||
}
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,9 @@ CenterWindow::CenterWindow(DMainWindow *parent) : DMainWindow(parent) {
|
|||
connect(b, &DButtonBoxButton::clicked, this,
|
||||
[=] { this->on_importSettings(); });
|
||||
blist.append(b);
|
||||
b = new DButtonBoxButton(tr("Save"), this);
|
||||
connect(b, &DButtonBoxButton::clicked, this, [=] { sm->saveSettings(); });
|
||||
blist.append(b);
|
||||
b = new DButtonBoxButton(tr("Reset"), this);
|
||||
connect(b, &DButtonBoxButton::clicked, this,
|
||||
[=] { this->on_resetSettings(); });
|
||||
|
@ -895,18 +898,19 @@ void CenterWindow::setoolWinInfo(int index, ToolStructInfo &info) {
|
|||
toolinfos[index] = info;
|
||||
auto icon =
|
||||
Utilities::trimIconFromInfo(plgsys->plugin(info.pluginIndex), info);
|
||||
auto ilbl = lbls[sellbl];
|
||||
auto ilbl = lbls[index];
|
||||
ilbl->setIcon(icon);
|
||||
manager->setToolIcon(sellbl, icon);
|
||||
manager->setToolIcon(index, icon);
|
||||
}
|
||||
|
||||
void CenterWindow::addWinToolInfo(ToolStructInfo &info) {
|
||||
wintoolinfos << info;
|
||||
wintoolinfos.append(info);
|
||||
auto item = new QListWidgetItem(
|
||||
Utilities::trimIconFromInfo(plgsys->plugin(info.pluginIndex), info),
|
||||
Utilities::getProgramName(info));
|
||||
item->setToolTip(info.process);
|
||||
lstoolwin->addItem(item);
|
||||
wintool.addItem(info);
|
||||
}
|
||||
|
||||
void CenterWindow::initGeneralSettings() {
|
||||
|
@ -1086,15 +1090,13 @@ void CenterWindow::getConfig(QDataStream &f) {
|
|||
}
|
||||
}
|
||||
|
||||
// 下面继续存储 ToolWin 相关信息,只有8条
|
||||
// 下面继续存储 ToolWin 相关信息
|
||||
for (auto i = 0; i < 9; i++) {
|
||||
if (i == 4) // 抛掉空的
|
||||
continue;
|
||||
|
||||
auto &p = toolinfos[i];
|
||||
// 对于 ToolWin 来说,enabled 是决定性的
|
||||
// 只有这个标志位有效,这个工具才有意义
|
||||
// 只存有意义的即可
|
||||
f << p.enabled;
|
||||
if (p.enabled) {
|
||||
f << p.isPlugin;
|
||||
if (p.isPlugin) {
|
||||
|
|
20
utilities.h
20
utilities.h
|
@ -66,7 +66,9 @@ public:
|
|||
QBuffer b(&buffer);
|
||||
QDataStream f(&b);
|
||||
|
||||
b.open(QBuffer::WriteOnly);
|
||||
f << plg->isTool() << plg->pluginServices();
|
||||
b.close();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -76,11 +78,15 @@ public:
|
|||
|
||||
QBuffer b(&old);
|
||||
QDataStream f(&b);
|
||||
|
||||
b.open(QBuffer::ReadOnly);
|
||||
bool isTool;
|
||||
f >> isTool;
|
||||
if (isTool != plg->isTool()) // 以前你是工具项目之一,后面不是了,肯定不兼容
|
||||
|
||||
// 以前你是工具项目之一,后面不是了,肯定不兼容
|
||||
if (isTool != plg->isTool()) {
|
||||
b.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList services;
|
||||
f >> services;
|
||||
|
@ -89,15 +95,19 @@ public:
|
|||
auto len = services.count();
|
||||
|
||||
// 服务比原来的都少了,肯定不兼容
|
||||
if (srv.count() < len)
|
||||
if (srv.count() < len) {
|
||||
b.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 开始评判函数,函数名不一致会导致错误的函数调用
|
||||
for (auto i = 0; i < len; i++) {
|
||||
if (srv[i] != services[i])
|
||||
if (srv[i] != services[i]) {
|
||||
b.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
b.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue