Skip to content

Commit f0bf2ad

Browse files
committed
feat: support to reset all keys for configuration
reset all keys's value.
1 parent 9a6370d commit f0bf2ad

File tree

5 files changed

+91
-39
lines changed

5 files changed

+91
-39
lines changed

dconfig-center/dde-dconfig-editor/mainwindow.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ MainWindow::MainWindow(QWidget *parent) :
151151
}
152152
});
153153

154+
resourceListView->setContextMenuPolicy(Qt::CustomContextMenu);
155+
connect(resourceListView, &QWidget::customContextMenuRequested, this, [this](const QPoint&) {
156+
if (auto model = qobject_cast<QStandardItemModel*>(resourceListView->model())){
157+
const auto index = resourceListView->currentIndex();
158+
if (!index.isValid())
159+
return;
160+
const auto &type = model->data(index, ConfigUserRole + 1).toInt();
161+
if (type & ConfigType::ResourceType || type == ConfigType::SubpathType) {
162+
const auto &appid = model->data(index, ConfigUserRole + 2).toString();
163+
const auto &resourceId = model->data(index, ConfigUserRole + 3).toString();
164+
const auto &subpath = model->data(index, ConfigUserRole + 4).toString();
165+
if (resourceId.isEmpty()) {
166+
qWarning() << "error" << appid << resourceId;
167+
return;
168+
}
169+
onCustomResourceMenuRequested(appid, resourceId, subpath);
170+
}
171+
}
172+
});
173+
154174
// set history
155175
DTitlebar *titlebar = this->titlebar();
156176
titlebar->setIcon(QIcon(APP_ICON));
@@ -287,6 +307,24 @@ void MainWindow::refreshResourceKeys(const QString &appid, const QString &resour
287307
contentView->refreshResourceKeys(appid, resourceId, subpath, matchKeyId);
288308
}
289309

310+
void MainWindow::onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath)
311+
{
312+
QMenu menu(resourceListView);
313+
314+
QAction *resetCmdAction = menu.addAction(tr("reset value"));
315+
316+
connect(resetCmdAction, &QAction::triggered, this, [this, appid, resource, subpath] {
317+
QScopedPointer<ValueHandler> getter(new ValueHandler(appid, resource, subpath));
318+
QScopedPointer<ConfigGetter> manager(getter->createManager());
319+
const auto keys = manager->keyList();
320+
for (const auto &item : qAsConst(keys)) {
321+
manager->reset(item);
322+
}
323+
refreshResourceKeys(appid, resource, subpath);
324+
});
325+
menu.exec(QCursor::pos());
326+
}
327+
290328
void MainWindow::installTranslate()
291329
{
292330
DTitlebar *titlebar = this->titlebar();

dconfig-center/dde-dconfig-editor/mainwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ private slots:
116116
void refreshResourceSubpaths(QStandardItemModel *model, const QString &appid, const QString &resourceId);
117117

118118
void refreshResourceKeys(const QString &appid, const QString &resourceId, const QString &subpath, const QString &matchKeyId = QString());
119+
120+
void onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath);
119121
private:
120122
void installTranslate();
121123

dconfig-center/dde-dconfig-editor/translates/dde-dconfig-editor_zh_CN.ts

+22-17
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
<context>
55
<name>Content</name>
66
<message>
7-
<location filename="../mainwindow.cpp" line="551"/>
7+
<location filename="../mainwindow.cpp" line="591"/>
88
<source>export</source>
99
<translation>导出</translation>
1010
</message>
1111
<message>
12-
<location filename="../mainwindow.cpp" line="552"/>
12+
<location filename="../mainwindow.cpp" line="592"/>
1313
<source>copy value</source>
1414
<translation>复制值</translation>
1515
</message>
1616
<message>
17-
<location filename="../mainwindow.cpp" line="553"/>
17+
<location filename="../mainwindow.cpp" line="593"/>
1818
<source>convert to cmd</source>
1919
<translation>复制命令</translation>
2020
</message>
2121
<message>
22-
<location filename="../mainwindow.cpp" line="554"/>
22+
<location filename="../mainwindow.cpp" line="594"/>
2323
<source>reset value</source>
2424
<translation>重置</translation>
2525
</message>
2626
<message>
27-
<location filename="../mainwindow.cpp" line="563"/>
27+
<location filename="../mainwindow.cpp" line="603"/>
2828
<source>export current configuration</source>
2929
<translation>导出当前配置</translation>
3030
</message>
3131
<message>
32-
<location filename="../mainwindow.cpp" line="563"/>
32+
<location filename="../mainwindow.cpp" line="603"/>
3333
<source>file(*.csv)</source>
3434
<translation>文件(*.csv)</translation>
3535
</message>
@@ -85,57 +85,62 @@
8585
<translation>输入应用Id</translation>
8686
</message>
8787
<message>
88-
<location filename="../mainwindow.cpp" line="74"/>
88+
<location filename="../mainwindow.cpp" line="75"/>
8989
<source>resource</source>
9090
<translation>配置Id</translation>
9191
</message>
9292
<message>
93-
<location filename="../mainwindow.cpp" line="75"/>
93+
<location filename="../mainwindow.cpp" line="76"/>
9494
<source>input filter resource</source>
9595
<translation>输入配置Id</translation>
9696
</message>
9797
<message>
98-
<location filename="../mainwindow.cpp" line="92"/>
98+
<location filename="../mainwindow.cpp" line="93"/>
9999
<source>keys</source>
100100
<translation>配置项Key值</translation>
101101
</message>
102102
<message>
103-
<location filename="../mainwindow.cpp" line="93"/>
103+
<location filename="../mainwindow.cpp" line="94"/>
104104
<source>input filter keys</source>
105105
<translation>输入配置项Key值</translation>
106106
</message>
107107
<message>
108-
<location filename="../mainwindow.cpp" line="156"/>
108+
<location filename="../mainwindow.cpp" line="177"/>
109109
<source>setting history</source>
110110
<translation>修改历史</translation>
111111
</message>
112112
<message>
113-
<location filename="../mainwindow.cpp" line="170"/>
113+
<location filename="../mainwindow.cpp" line="191"/>
114114
<source>export</source>
115115
<translation>导出</translation>
116116
</message>
117117
<message>
118-
<location filename="../mainwindow.cpp" line="177"/>
118+
<location filename="../mainwindow.cpp" line="198"/>
119119
<source>OEM</source>
120120
<translation>定制镜像</translation>
121121
</message>
122122
<message>
123-
<location filename="../mainwindow.cpp" line="292"/>
123+
<location filename="../mainwindow.cpp" line="314"/>
124+
<source>reset value</source>
125+
<translation>重置</translation>
126+
</message>
127+
<message>
128+
<location filename="../mainwindow.cpp" line="331"/>
124129
<source>config language</source>
125130
<translation>配置语言</translation>
126131
</message>
127132
<message>
128-
<location filename="../mainwindow.cpp" line="293"/>
133+
<location filename="../mainwindow.cpp" line="332"/>
129134
<source>default</source>
130135
<translation>默认</translation>
131136
</message>
132137
<message>
133-
<location filename="../mainwindow.cpp" line="295"/>
138+
<location filename="../mainwindow.cpp" line="334"/>
134139
<source>chinese</source>
135140
<translation>中文</translation>
136141
</message>
137142
<message>
138-
<location filename="../mainwindow.cpp" line="297"/>
143+
<location filename="../mainwindow.cpp" line="336"/>
139144
<source>english</source>
140145
<translation>英文</translation>
141146
</message>

dconfig-center/dde-dconfig/main.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ int CommandManager::setCommand()
293293
int CommandManager::resetCommand()
294294
{
295295
// reset命令,设置指定配置项
296-
if (!isSetAppid() || !isSetResourceid() || !isSetKey()) {
297-
outpuSTDError("not set appid, resource or key.");
296+
if (!isSetAppid() || !isSetResourceid()) {
297+
outpuSTDError("not set appid, resource");
298298
return 1;
299299
}
300300

@@ -307,7 +307,14 @@ int CommandManager::resetCommand()
307307
{
308308
QScopedPointer<ConfigGetter> manager(handler.createManager());
309309
if (manager) {
310-
manager->reset(key);
310+
if (isSetKey()) {
311+
manager->reset(key);
312+
} else {
313+
const auto keys = manager->keyList();
314+
for (const auto &item : qAsConst(keys)) {
315+
manager->reset(item);
316+
}
317+
}
311318
} else {
312319
outpuSTDError(QString("not create value handler for appid=%1, resource=%2, subpath=%3.").arg(appid, resourceid, subpathid));
313320
return 1;
@@ -401,7 +408,7 @@ int main(int argc, char *argv[])
401408
setOption.setFlags(setOption.flags() ^ QCommandLineOption::HiddenFromHelp);
402409
parser.addOption(setOption);
403410

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

dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,86 @@
44
<context>
55
<name>main</name>
66
<message>
7-
<location filename="../main.cpp" line="358"/>
7+
<location filename="../main.cpp" line="365"/>
88
<source>A console tool to get and set configuration items for DTK Config.</source>
99
<translation>用于管理DTK提供的配置策略的CLI工具</translation>
1010
</message>
1111
<message>
12-
<location filename="../main.cpp" line="361"/>
12+
<location filename="../main.cpp" line="368"/>
1313
<source>operate configure items of the user uid.</source>
1414
<translation>用户uid, 用户的唯一ID,对指定用户的配置项进行读写等操作</translation>
1515
</message>
1616
<message>
17-
<location filename="../main.cpp" line="364"/>
17+
<location filename="../main.cpp" line="371"/>
1818
<source>appid for a specific application,
1919
it is empty string if we need to manage application independent configuration.
2020
second positional argument as appid if not the option</source>
2121
<translation>应用Id,应用程序的唯一ID,当管理应用无关配置时此值为空,如果没有设置这个选项,则使用第二个位置参数当作此选项值</translation>
2222
</message>
2323
<message>
24-
<location filename="../main.cpp" line="369"/>
24+
<location filename="../main.cpp" line="376"/>
2525
<source>resource id for configure name,
2626
it&apos;s value is same as `a` option if not the option.</source>
2727
<translation>配置Id,配置描述文件的唯一标识,是配置描述文件的文件名,如果没有设置这个选项,则值与应用Id的值相同</translation>
2828
</message>
2929
<message>
30-
<location filename="../main.cpp" line="373"/>
30+
<location filename="../main.cpp" line="380"/>
3131
<source>subpath for configure.</source>
3232
<translation>子目录,配置描述文件安装可包含子路径,支持配置描述文件的优先级,通常情况下不设置此值</translation>
3333
</message>
3434
<message>
35-
<location filename="../main.cpp" line="376"/>
35+
<location filename="../main.cpp" line="383"/>
3636
<source>configure item&apos;s key.
3737
three positional argument as key if not the option</source>
3838
<translation>配置项Key值,如果没有设置这个选项,则使用第三个位置参数当作此选项值</translation>
3939
</message>
4040
<message>
41-
<location filename="../main.cpp" line="380"/>
41+
<location filename="../main.cpp" line="387"/>
4242
<source>new value to set configure item.</source>
4343
<translation>需要设置的配置项值,此选项在set模式下工作</translation>
4444
</message>
4545
<message>
46-
<location filename="../main.cpp" line="383"/>
46+
<location filename="../main.cpp" line="390"/>
4747
<source>working prefix directory.</source>
4848
<translation>配置策略的工作目录前缀,通常情况下不设置此值</translation>
4949
</message>
5050
<message>
51-
<location filename="../main.cpp" line="386"/>
51+
<location filename="../main.cpp" line="393"/>
5252
<source>method for the configure item.</source>
5353
<translation>指定配置项的字段信息,用于获取配置项的详细信息,值为{name | discription | visibility | permissions | version | isDefaultValue}其中一个,此选项在get模式下工作</translation>
5454
</message>
5555
<message>
56-
<location filename="../main.cpp" line="389"/>
56+
<location filename="../main.cpp" line="396"/>
5757
<source>language for the configuration item.</source>
5858
<translation>指定语言,此选项在get模式下工作,并且需要指定method选项</translation>
5959
</message>
6060
<message>
61-
<location filename="../main.cpp" line="392"/>
61+
<location filename="../main.cpp" line="399"/>
6262
<source>list configure information with appid, resource or subpath.</source>
6363
<translation>list模式,列出可配置的应用Id,配置Id,及子目录</translation>
6464
</message>
6565
<message>
66-
<location filename="../main.cpp" line="396"/>
66+
<location filename="../main.cpp" line="403"/>
6767
<source>query content for configure, including the configure item&apos;s all keys, value ...</source>
6868
<translation>get模式,用于查询指定配置项的信息</translation>
6969
</message>
7070
<message>
71-
<location filename="../main.cpp" line="400"/>
71+
<location filename="../main.cpp" line="407"/>
7272
<source>set configure item &apos;s value.</source>
7373
<translation>set模式,用于设置配置项的值</translation>
7474
</message>
7575
<message>
76-
<location filename="../main.cpp" line="404"/>
77-
<source>reset configure item &apos;s value.</source>
78-
<translation>reset模式,用于重置配置项的值,此会清除对应的缓存值</translation>
76+
<location filename="../main.cpp" line="411"/>
77+
<source>reset configure item&apos;s value, reset all configure item&apos;s value if not `-k` option.</source>
78+
<translation>reset模式,用于重置配置项的值,此会清除对应的缓存值,若没有指定`-k`选项,则重置此配置文件的所有缓存值</translation>
7979
</message>
8080
<message>
81-
<location filename="../main.cpp" line="408"/>
81+
<location filename="../main.cpp" line="415"/>
8282
<source>watch value changed for some configure item.</source>
8383
<translation>watch模式,用于监听配置项的更改</translation>
8484
</message>
8585
<message>
86-
<location filename="../main.cpp" line="412"/>
86+
<location filename="../main.cpp" line="419"/>
8787
<source>start dde-dconfig-editor as a gui configure tool.</source>
8888
<translation>gui模式,用于启动GUI工具,需要安装对应的GUI工具dde-dconfig-editor</translation>
8989
</message>

0 commit comments

Comments
 (0)