Skip to content

Commit

Permalink
feat: support to reset all keys for configuration
Browse files Browse the repository at this point in the history
  reset all keys's value.
  • Loading branch information
18202781743 committed Jan 8, 2024
1 parent e1e22fc commit 9c9f71c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 39 deletions.
38 changes: 38 additions & 0 deletions dconfig-center/dde-dconfig-editor/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ MainWindow::MainWindow(QWidget *parent) :
}
});

resourceListView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(resourceListView, &QWidget::customContextMenuRequested, this, [this](const QPoint&) {
if (auto model = qobject_cast<QStandardItemModel*>(resourceListView->model())){
const auto index = resourceListView->currentIndex();
if (!index.isValid())
return;
const auto &type = model->data(index, ConfigUserRole + 1).toInt();
if (type & ConfigType::ResourceType || type == ConfigType::SubpathType) {
const auto &appid = model->data(index, ConfigUserRole + 2).toString();
const auto &resourceId = model->data(index, ConfigUserRole + 3).toString();
const auto &subpath = model->data(index, ConfigUserRole + 4).toString();
if (resourceId.isEmpty()) {
qWarning() << "error" << appid << resourceId;
return;
}
onCustomResourceMenuRequested(appid, resourceId, subpath);
}
}
});

// set history
DTitlebar *titlebar = this->titlebar();
titlebar->setIcon(QIcon(APP_ICON));
Expand Down Expand Up @@ -287,6 +307,24 @@ void MainWindow::refreshResourceKeys(const QString &appid, const QString &resour
contentView->refreshResourceKeys(appid, resourceId, subpath, matchKeyId);
}

void MainWindow::onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath)
{
QMenu menu(resourceListView);

QAction *resetCmdAction = menu.addAction(tr("reset value"));

connect(resetCmdAction, &QAction::triggered, this, [this, appid, resource, subpath] {
QScopedPointer<ValueHandler> getter(new ValueHandler(appid, resource, subpath));
QScopedPointer<ConfigGetter> manager(getter->createManager());
const auto keys = manager->keyList();
for (const auto &item : qAsConst(keys)) {
manager->reset(item);
}
refreshResourceKeys(appid, resource, subpath);
});
menu.exec(QCursor::pos());
}

void MainWindow::installTranslate()
{
DTitlebar *titlebar = this->titlebar();
Expand Down
2 changes: 2 additions & 0 deletions dconfig-center/dde-dconfig-editor/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ private slots:
void refreshResourceSubpaths(QStandardItemModel *model, const QString &appid, const QString &resourceId);

void refreshResourceKeys(const QString &appid, const QString &resourceId, const QString &subpath, const QString &matchKeyId = QString());

void onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath);
private:
void installTranslate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
<context>
<name>Content</name>
<message>
<location filename="../mainwindow.cpp" line="551"/>
<location filename="../mainwindow.cpp" line="591"/>
<source>export</source>
<translation>导出</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="552"/>
<location filename="../mainwindow.cpp" line="592"/>
<source>copy value</source>
<translation>复制值</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="553"/>
<location filename="../mainwindow.cpp" line="593"/>
<source>convert to cmd</source>
<translation>复制命令</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="554"/>
<location filename="../mainwindow.cpp" line="594"/>
<source>reset value</source>
<translation>重置</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="563"/>
<location filename="../mainwindow.cpp" line="603"/>
<source>export current configuration</source>
<translation>导出当前配置</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="563"/>
<location filename="../mainwindow.cpp" line="603"/>
<source>file(*.csv)</source>
<translation>文件(*.csv)</translation>
</message>
Expand Down Expand Up @@ -85,57 +85,62 @@
<translation>输入应用Id</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="74"/>
<location filename="../mainwindow.cpp" line="75"/>
<source>resource</source>
<translation>配置Id</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="75"/>
<location filename="../mainwindow.cpp" line="76"/>
<source>input filter resource</source>
<translation>输入配置Id</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="92"/>
<location filename="../mainwindow.cpp" line="93"/>
<source>keys</source>
<translation>配置项Key值</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="93"/>
<location filename="../mainwindow.cpp" line="94"/>
<source>input filter keys</source>
<translation>输入配置项Key值</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="156"/>
<location filename="../mainwindow.cpp" line="177"/>
<source>setting history</source>
<translation>修改历史</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="170"/>
<location filename="../mainwindow.cpp" line="191"/>
<source>export</source>
<translation>导出</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="177"/>
<location filename="../mainwindow.cpp" line="198"/>
<source>OEM</source>
<translation>定制镜像</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="292"/>
<location filename="../mainwindow.cpp" line="314"/>
<source>reset value</source>
<translation>重置</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="331"/>
<source>config language</source>
<translation>配置语言</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="293"/>
<location filename="../mainwindow.cpp" line="332"/>
<source>default</source>
<translation>默认</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="295"/>
<location filename="../mainwindow.cpp" line="334"/>
<source>chinese</source>
<translation>中文</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="297"/>
<location filename="../mainwindow.cpp" line="336"/>
<source>english</source>
<translation>英文</translation>
</message>
Expand Down
15 changes: 11 additions & 4 deletions dconfig-center/dde-dconfig/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ int CommandManager::setCommand()
int CommandManager::resetCommand()
{
// reset命令,设置指定配置项
if (!isSetAppid() || !isSetResourceid() || !isSetKey()) {
outpuSTDError("not set appid, resource or key.");
if (!isSetAppid() || !isSetResourceid()) {
outpuSTDError("not set appid, resource");
return 1;
}

Expand All @@ -307,7 +307,14 @@ int CommandManager::resetCommand()
{
QScopedPointer<ConfigGetter> manager(handler.createManager());
if (manager) {
manager->reset(key);
if (isSetKey()) {
manager->reset(key);
} else {
const auto keys = manager->keyList();
for (const auto &item : qAsConst(keys)) {
manager->reset(item);
}
}
} else {
outpuSTDError(QString("not create value handler for appid=%1, resource=%2, subpath=%3.").arg(appid, resourceid, subpathid));
return 1;
Expand Down Expand Up @@ -401,7 +408,7 @@ int main(int argc, char *argv[])
setOption.setFlags(setOption.flags() ^ QCommandLineOption::HiddenFromHelp);
parser.addOption(setOption);

QCommandLineOption resetOption("reset", QCoreApplication::translate("main", "reset configure item 's value."));
QCommandLineOption resetOption("reset", QCoreApplication::translate("main", "reset configure item's value, reset all configure item's value if not `-k` option."));
resetOption.setFlags(resetOption.flags() ^ QCommandLineOption::HiddenFromHelp);
parser.addOption(resetOption);

Expand Down
36 changes: 18 additions & 18 deletions dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,86 @@
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="358"/>
<location filename="../main.cpp" line="365"/>
<source>A console tool to get and set configuration items for DTK Config.</source>
<translation>用于管理DTK提供的配置策略的CLI工具</translation>
</message>
<message>
<location filename="../main.cpp" line="361"/>
<location filename="../main.cpp" line="368"/>
<source>operate configure items of the user uid.</source>
<translation>用户uid, 用户的唯一ID,对指定用户的配置项进行读写等操作</translation>
</message>
<message>
<location filename="../main.cpp" line="364"/>
<location filename="../main.cpp" line="371"/>
<source>appid for a specific application,
it is empty string if we need to manage application independent configuration.
second positional argument as appid if not the option</source>
<translation>应用Id,应用程序的唯一ID,当管理应用无关配置时此值为空,如果没有设置这个选项,则使用第二个位置参数当作此选项值</translation>
</message>
<message>
<location filename="../main.cpp" line="369"/>
<location filename="../main.cpp" line="376"/>
<source>resource id for configure name,
it&apos;s value is same as `a` option if not the option.</source>
<translation>配置Id,配置描述文件的唯一标识,是配置描述文件的文件名,如果没有设置这个选项,则值与应用Id的值相同</translation>
</message>
<message>
<location filename="../main.cpp" line="373"/>
<location filename="../main.cpp" line="380"/>
<source>subpath for configure.</source>
<translation>子目录,配置描述文件安装可包含子路径,支持配置描述文件的优先级,通常情况下不设置此值</translation>
</message>
<message>
<location filename="../main.cpp" line="376"/>
<location filename="../main.cpp" line="383"/>
<source>configure item&apos;s key.
three positional argument as key if not the option</source>
<translation>配置项Key值,如果没有设置这个选项,则使用第三个位置参数当作此选项值</translation>
</message>
<message>
<location filename="../main.cpp" line="380"/>
<location filename="../main.cpp" line="387"/>
<source>new value to set configure item.</source>
<translation>需要设置的配置项值,此选项在set模式下工作</translation>
</message>
<message>
<location filename="../main.cpp" line="383"/>
<location filename="../main.cpp" line="390"/>
<source>working prefix directory.</source>
<translation>配置策略的工作目录前缀,通常情况下不设置此值</translation>
</message>
<message>
<location filename="../main.cpp" line="386"/>
<location filename="../main.cpp" line="393"/>
<source>method for the configure item.</source>
<translation>指定配置项的字段信息,用于获取配置项的详细信息,值为{name | discription | visibility | permissions | version | isDefaultValue}其中一个,此选项在get模式下工作</translation>
</message>
<message>
<location filename="../main.cpp" line="389"/>
<location filename="../main.cpp" line="396"/>
<source>language for the configuration item.</source>
<translation>指定语言,此选项在get模式下工作,并且需要指定method选项</translation>
</message>
<message>
<location filename="../main.cpp" line="392"/>
<location filename="../main.cpp" line="399"/>
<source>list configure information with appid, resource or subpath.</source>
<translation>list模式,列出可配置的应用Id,配置Id,及子目录</translation>
</message>
<message>
<location filename="../main.cpp" line="396"/>
<location filename="../main.cpp" line="403"/>
<source>query content for configure, including the configure item&apos;s all keys, value ...</source>
<translation>get模式,用于查询指定配置项的信息</translation>
</message>
<message>
<location filename="../main.cpp" line="400"/>
<location filename="../main.cpp" line="407"/>
<source>set configure item &apos;s value.</source>
<translation>set模式,用于设置配置项的值</translation>
</message>
<message>
<location filename="../main.cpp" line="404"/>
<source>reset configure item &apos;s value.</source>
<translation>reset模式,用于重置配置项的值,此会清除对应的缓存值</translation>
<location filename="../main.cpp" line="411"/>
<source>reset configure item&apos;s value, reset all configure item&apos;s value if not `-k` option.</source>
<translation>reset模式,用于重置配置项的值,此会清除对应的缓存值,若没有指定`-k`选项,则重置此配置文件的所有缓存值</translation>
</message>
<message>
<location filename="../main.cpp" line="408"/>
<location filename="../main.cpp" line="415"/>
<source>watch value changed for some configure item.</source>
<translation>watch模式,用于监听配置项的更改</translation>
</message>
<message>
<location filename="../main.cpp" line="412"/>
<location filename="../main.cpp" line="419"/>
<source>start dde-dconfig-editor as a gui configure tool.</source>
<translation>gui模式,用于启动GUI工具,需要安装对应的GUI工具dde-dconfig-editor</translation>
</message>
Expand Down

0 comments on commit 9c9f71c

Please sign in to comment.