summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-08-20 16:37:42 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-28 09:48:45 +0300
commitf7ccea7bca79f1dc21e497872a419446f20d211e (patch)
tree87ad85a6e402908ce5c7f3439e0e25b889333c1c /scripts
parentAdd rekonf script to generate SettingsWidgets (diff)
downloadrekonq-f7ccea7bca79f1dc21e497872a419446f20d211e.tar.xz
Add Setting and MockSettings
- rename Settings to RekonqSettings
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/rekonf.py81
1 files changed, 55 insertions, 26 deletions
diff --git a/scripts/rekonf.py b/scripts/rekonf.py
index 56ded374..48706c3d 100755
--- a/scripts/rekonf.py
+++ b/scripts/rekonf.py
@@ -15,45 +15,52 @@ from xml.etree import ElementTree
def write_int_entry(entry):
'''Add a QSpinBox connected to an Int entry'''
- print(f' // { entry.attrib["name"] }')
- print(f' auto* { entry.attrib["key"] } = new QSpinBox(this);')
- print(f' { entry.attrib["key"] }->setValue({ entry.find("{*}default").text });')
- print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { entry.attrib["key"] });')
+ obj = entry.attrib['key']
+ default = entry.find('{*}default').text
+ print(f' auto* { obj } = new QSpinBox(this);')
+ print(f' { obj }->setValue(s->value("{ obj }", { default }).toInt());')
+ print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { obj });')
def write_bool_entry(entry):
'''Add a QCheckBox connected to a Bool entry'''
- print(f' // { entry.attrib["name"] }')
- print(f' auto* { entry.attrib["key"] } = new QCheckBox(tr("{ entry.attrib["name"] }"), this);')
- print(f' { entry.attrib["key"] }->setChecked({ entry.find("{*}default").text });')
- print(f' formLayout->addRow(QString(), { entry.attrib["key"] });')
+ obj = entry.attrib['key']
+ default = entry.find('{*}default').text
+ print(f' auto* { obj } = new QCheckBox(tr("{ entry.attrib["name"] }"), this);')
+ print(f' { obj }->setChecked(s->value("{ obj }", { default }).toBool());')
+ print(f' formLayout->addRow(QString(), { obj });')
def write_string_entry(entry):
'''Add a QLineEdit connected to a String entry'''
- print(f' // { entry.attrib["name"] }')
- print(f' auto* { entry.attrib["key"] } = new QLineEdit(this);')
- print(f' { entry.attrib["key"] }->setText("{ entry.find("{*}default").text }");')
- print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { entry.attrib["key"] });')
+ obj = entry.attrib['key']
+ default = entry.find('{*}default').text
+ print(f' auto* {obj} = new QLineEdit(this);')
+ print(f' {obj}->setText(s->value("{ obj }", "{ default }").toString());')
+ print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { obj });')
def write_font_entry(entry):
'''Add a QFontComboBox connected to a Font entry'''
- print(f' // { entry.attrib["name"] }')
- print(f' auto* { entry.attrib["key"] } = new QFontComboBox(this);')
- print(f' { entry.attrib["key"] }->setCurrentFont({ entry.find("{*}default").text });')
- print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { entry.attrib["key"] });')
+ obj = entry.attrib['key']
+ default = entry.find('{*}default').text
+ print(f' auto* { obj } = new QFontComboBox(this);')
+ print(f' { obj }->setCurrentFont(s->value("{ obj }", "{ default }").toString());')
+ print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { obj });')
def write_shortcut_entry(entry):
'''Add a QKeySequenceEdit connected to a Shortcut entry'''
- print(f' // { entry.attrib["name"] }')
- print(f' auto* { entry.attrib["key"] } = new QKeySequenceEdit({{ "{entry.find("{*}default").text}" }}, this);')
- print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { entry.attrib["key"] });')
+ obj = entry.attrib['key']
+ default = entry.find('{*}default').text
+ print(f' auto* { entry.attrib["key"] } = new QKeySequenceEdit(this);')
+ print(f' { obj }->setKeySequence(s->value("{ obj }", "{ default }").toString());')
+ print(f' formLayout->addRow(tr("{ entry.attrib["name"] }"), { obj });')
def generate_group_widget(root, group):
'''Generate a class based on the group name'''
+ class_group = group.attrib["name"].replace(' ', '')
class_name = group.attrib["name"].replace(' ', '') + 'SettingsWidget'
# includes
@@ -71,7 +78,8 @@ def generate_group_widget(root, group):
print(f'#include <{ include.text }>')
print('')
- print(f'{ class_name }::{ class_name }(QWidget *parent) : SettingsWidget(parent) {{')
+ print(f'{ class_name }::{ class_name }(RekonqSettings *s, QWidget *parent) : SettingsWidget(s, parent) {{')
+ print(f' s->beginGroup("{ class_group }");')
print(' auto *formLayout = new QFormLayout;')
print(' setLayout(formLayout);')
print('')
@@ -94,13 +102,26 @@ def generate_group_widget(root, group):
print(f'#error entry with unknown type { entry.attrib["type"] }')
print('')
+ print(' s->endGroup();')
print('}\n')
print(f'void { class_name }::save() {{ }}')
print(f'void { class_name }::reset() {{ }}')
-if __name__ == '__main__':
+def generate_group_ini(root, group):
+ group_name = group.attrib["name"].replace(' ', '')
+ print(f'[{ group_name }]')
+ for entry in group.findall('{http://www.kde.org/standards/kcfg/1.0}entry'):
+ if entry.find('{*}default').get('code') == 'true':
+ continue
+ entry_key = entry.attrib['key']
+ entry_val = entry.find('{*}default').text
+ print(f'{ entry_key }={ entry_val }')
+ print('')
+
+
+def main():
parser = argparse.ArgumentParser(description='Generate SettingsWidgets')
parser.add_argument('file', type=str, help='kcfg file')
parser.add_argument('--group', type=str, required=True, help='Group')
@@ -111,8 +132,16 @@ if __name__ == '__main__':
tree = ElementTree.parse(args.file)
root = tree.getroot()
- # groups
- for group in root.findall('{http://www.kde.org/standards/kcfg/1.0}group'):
- if group.attrib["name"] == args.group:
- print('// This is an automatically generated file')
- generate_group_widget(root, group)
+ if args.group == 'all':
+ for group in root.findall('{http://www.kde.org/standards/kcfg/1.0}group'):
+ generate_group_ini(root, group)
+ else:
+ for group in root.findall('{http://www.kde.org/standards/kcfg/1.0}group'):
+ if group.attrib["name"] == args.group:
+ print('// This is an automatically generated file')
+ generate_group_widget(root, group)
+ break
+
+
+if __name__ == '__main__':
+ main()