Masahiro Yamada | 0c87410 | 2018-12-18 21:13:35 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Boris Barbulovski | b4ff1de | 2015-09-22 11:36:38 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 7 | #include <QAction> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 8 | #include <QApplication> |
| 9 | #include <QCloseEvent> |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 10 | #include <QDebug> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 11 | #include <QDesktopWidget> |
Boris Barbulovski | bea0077 | 2015-09-22 11:36:04 -0700 | [diff] [blame] | 12 | #include <QFileDialog> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 13 | #include <QLabel> |
| 14 | #include <QLayout> |
| 15 | #include <QList> |
Boris Barbulovski | 76bede8 | 2015-09-22 11:36:07 -0700 | [diff] [blame] | 16 | #include <QMenu> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 17 | #include <QMenuBar> |
| 18 | #include <QMessageBox> |
| 19 | #include <QToolBar> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <stdlib.h> |
| 22 | |
| 23 | #include "lkc.h" |
| 24 | #include "qconf.h" |
| 25 | |
Masahiro Yamada | 3b54197856 | 2018-12-21 17:33:07 +0900 | [diff] [blame] | 26 | #include "images.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static QApplication *configApp; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 30 | static ConfigSettings *configSettings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 32 | QAction *ConfigMainWindow::saveAction; |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 33 | |
Ben Hutchings | 00d4f8f | 2013-10-06 19:21:31 +0100 | [diff] [blame] | 34 | ConfigSettings::ConfigSettings() |
| 35 | : QSettings("kernel.org", "qconf") |
| 36 | { |
| 37 | } |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Reads a list of integer values from the application settings. |
| 41 | */ |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 42 | QList<int> ConfigSettings::readSizes(const QString& key, bool *ok) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 44 | QList<int> result; |
Li Zefan | c1f96f0 | 2010-05-07 13:58:04 +0800 | [diff] [blame] | 45 | |
Boris Barbulovski | 83c3a1b | 2016-11-30 14:57:55 -0800 | [diff] [blame] | 46 | if (contains(key)) |
| 47 | { |
| 48 | QStringList entryList = value(key).toStringList(); |
| 49 | QStringList::Iterator it; |
| 50 | |
| 51 | for (it = entryList.begin(); it != entryList.end(); ++it) |
| 52 | result.push_back((*it).toInt()); |
| 53 | |
| 54 | *ok = true; |
| 55 | } |
| 56 | else |
| 57 | *ok = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Writes a list of integer values to the application settings. |
| 64 | */ |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 65 | bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | QStringList stringList; |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 68 | QList<int>::ConstIterator it; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | for (it = value.begin(); it != value.end(); ++it) |
| 71 | stringList.push_back(QString::number(*it)); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 72 | setValue(key, stringList); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 73 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 74 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 77 | QIcon ConfigItem::symbolYesIcon; |
| 78 | QIcon ConfigItem::symbolModIcon; |
| 79 | QIcon ConfigItem::symbolNoIcon; |
| 80 | QIcon ConfigItem::choiceYesIcon; |
| 81 | QIcon ConfigItem::choiceNoIcon; |
| 82 | QIcon ConfigItem::menuIcon; |
| 83 | QIcon ConfigItem::menubackIcon; |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 84 | |
| 85 | /* |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 86 | * update the displayed of a menu entry |
| 87 | */ |
| 88 | void ConfigItem::updateMenu(void) |
| 89 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 90 | ConfigList* list; |
| 91 | struct symbol* sym; |
| 92 | struct property *prop; |
| 93 | QString prompt; |
| 94 | int type; |
| 95 | tristate expr; |
| 96 | |
| 97 | list = listView(); |
| 98 | if (goParent) { |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 99 | setIcon(promptColIdx, menubackIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 100 | prompt = ".."; |
| 101 | goto set_prompt; |
| 102 | } |
| 103 | |
| 104 | sym = menu->sym; |
| 105 | prop = menu->prompt; |
Masahiro Yamada | 3c73ff0 | 2020-08-07 18:19:02 +0900 | [diff] [blame] | 106 | prompt = menu_get_prompt(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 107 | |
| 108 | if (prop) switch (prop->type) { |
| 109 | case P_MENU: |
| 110 | if (list->mode == singleMode || list->mode == symbolMode) { |
| 111 | /* a menuconfig entry is displayed differently |
| 112 | * depending whether it's at the view root or a child. |
| 113 | */ |
| 114 | if (sym && list->rootEntry == menu) |
| 115 | break; |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 116 | setIcon(promptColIdx, menuIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 117 | } else { |
| 118 | if (sym) |
| 119 | break; |
Masahiro Yamada | 711b875 | 2020-08-07 18:19:03 +0900 | [diff] [blame] | 120 | setIcon(promptColIdx, QIcon()); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 121 | } |
| 122 | goto set_prompt; |
| 123 | case P_COMMENT: |
Masahiro Yamada | 711b875 | 2020-08-07 18:19:03 +0900 | [diff] [blame] | 124 | setIcon(promptColIdx, QIcon()); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 125 | goto set_prompt; |
| 126 | default: |
| 127 | ; |
| 128 | } |
| 129 | if (!sym) |
| 130 | goto set_prompt; |
| 131 | |
Masahiro Yamada | 3c73ff0 | 2020-08-07 18:19:02 +0900 | [diff] [blame] | 132 | setText(nameColIdx, sym->name); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 133 | |
| 134 | type = sym_get_type(sym); |
| 135 | switch (type) { |
| 136 | case S_BOOLEAN: |
| 137 | case S_TRISTATE: |
| 138 | char ch; |
| 139 | |
Marco Ammon | baa23ec | 2019-07-04 12:50:41 +0200 | [diff] [blame] | 140 | if (!sym_is_changeable(sym) && list->optMode == normalOpt) { |
Masahiro Yamada | 711b875 | 2020-08-07 18:19:03 +0900 | [diff] [blame] | 141 | setIcon(promptColIdx, QIcon()); |
Mauro Carvalho Chehab | cf497b9 | 2020-04-02 11:27:58 +0200 | [diff] [blame] | 142 | setText(noColIdx, QString()); |
| 143 | setText(modColIdx, QString()); |
| 144 | setText(yesColIdx, QString()); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 145 | break; |
| 146 | } |
| 147 | expr = sym_get_tristate_value(sym); |
| 148 | switch (expr) { |
| 149 | case yes: |
| 150 | if (sym_is_choice_value(sym) && type == S_BOOLEAN) |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 151 | setIcon(promptColIdx, choiceYesIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 152 | else |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 153 | setIcon(promptColIdx, symbolYesIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 154 | setText(yesColIdx, "Y"); |
| 155 | ch = 'Y'; |
| 156 | break; |
| 157 | case mod: |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 158 | setIcon(promptColIdx, symbolModIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 159 | setText(modColIdx, "M"); |
| 160 | ch = 'M'; |
| 161 | break; |
| 162 | default: |
| 163 | if (sym_is_choice_value(sym) && type == S_BOOLEAN) |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 164 | setIcon(promptColIdx, choiceNoIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 165 | else |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 166 | setIcon(promptColIdx, symbolNoIcon); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 167 | setText(noColIdx, "N"); |
| 168 | ch = 'N'; |
| 169 | break; |
| 170 | } |
| 171 | if (expr != no) |
| 172 | setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0); |
| 173 | if (expr != mod) |
| 174 | setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0); |
| 175 | if (expr != yes) |
| 176 | setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); |
| 177 | |
| 178 | setText(dataColIdx, QChar(ch)); |
| 179 | break; |
| 180 | case S_INT: |
| 181 | case S_HEX: |
| 182 | case S_STRING: |
| 183 | const char* data; |
| 184 | |
| 185 | data = sym_get_string_value(sym); |
| 186 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 187 | setText(dataColIdx, data); |
| 188 | if (type == S_STRING) |
| 189 | prompt = QString("%1: %2").arg(prompt).arg(data); |
| 190 | else |
| 191 | prompt = QString("(%2) %1").arg(prompt).arg(data); |
| 192 | break; |
| 193 | } |
| 194 | if (!sym_has_value(sym) && visible) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 195 | prompt += " (NEW)"; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 196 | set_prompt: |
| 197 | setText(promptColIdx, prompt); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void ConfigItem::testUpdateMenu(bool v) |
| 201 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 202 | ConfigItem* i; |
| 203 | |
| 204 | visible = v; |
| 205 | if (!menu) |
| 206 | return; |
| 207 | |
| 208 | sym_calc_value(menu->sym); |
| 209 | if (menu->flags & MENU_CHANGED) { |
| 210 | /* the menu entry changed, so update all list items */ |
| 211 | menu->flags &= ~MENU_CHANGED; |
| 212 | for (i = (ConfigItem*)menu->data; i; i = i->nextItem) |
| 213 | i->updateMenu(); |
| 214 | } else if (listView()->updateAll) |
| 215 | updateMenu(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 219 | /* |
| 220 | * construct a menu entry |
| 221 | */ |
| 222 | void ConfigItem::init(void) |
| 223 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 224 | if (menu) { |
| 225 | ConfigList* list = listView(); |
| 226 | nextItem = (ConfigItem*)menu->data; |
| 227 | menu->data = this; |
| 228 | |
| 229 | if (list->mode != fullMode) |
| 230 | setExpanded(true); |
| 231 | sym_calc_value(menu->sym); |
| 232 | } |
| 233 | updateMenu(); |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * destruct a menu entry |
| 238 | */ |
| 239 | ConfigItem::~ConfigItem(void) |
| 240 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 241 | if (menu) { |
| 242 | ConfigItem** ip = (ConfigItem**)&menu->data; |
| 243 | for (; *ip; ip = &(*ip)->nextItem) { |
| 244 | if (*ip == this) { |
| 245 | *ip = nextItem; |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | } |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 252 | ConfigLineEdit::ConfigLineEdit(ConfigView* parent) |
| 253 | : Parent(parent) |
| 254 | { |
Boris Barbulovski | c14fa5e | 2015-09-22 11:36:21 -0700 | [diff] [blame] | 255 | connect(this, SIGNAL(editingFinished()), SLOT(hide())); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 258 | void ConfigLineEdit::show(ConfigItem* i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | item = i; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 261 | if (sym_get_string_value(item->menu->sym)) |
Masahiro Yamada | 3c73ff0 | 2020-08-07 18:19:02 +0900 | [diff] [blame] | 262 | setText(sym_get_string_value(item->menu->sym)); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 263 | else |
Mauro Carvalho Chehab | cf497b9 | 2020-04-02 11:27:58 +0200 | [diff] [blame] | 264 | setText(QString()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | Parent::show(); |
| 266 | setFocus(); |
| 267 | } |
| 268 | |
| 269 | void ConfigLineEdit::keyPressEvent(QKeyEvent* e) |
| 270 | { |
| 271 | switch (e->key()) { |
Markus Heidelberg | fbb8637 | 2009-05-18 01:36:51 +0200 | [diff] [blame] | 272 | case Qt::Key_Escape: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | break; |
Markus Heidelberg | fbb8637 | 2009-05-18 01:36:51 +0200 | [diff] [blame] | 274 | case Qt::Key_Return: |
| 275 | case Qt::Key_Enter: |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 276 | sym_set_string_value(item->menu->sym, text().toLatin1()); |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 277 | ConfigList::updateListForAll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | break; |
| 279 | default: |
| 280 | Parent::keyPressEvent(e); |
| 281 | return; |
| 282 | } |
| 283 | e->accept(); |
| 284 | parent()->list->setFocus(); |
| 285 | hide(); |
| 286 | } |
| 287 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 288 | ConfigList::ConfigList(ConfigView* p, const char *name) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 289 | : Parent(p), |
| 290 | updateAll(false), |
Masahiro Yamada | 669a1ee | 2020-08-29 17:14:11 +0900 | [diff] [blame^] | 291 | showName(false), showRange(false), mode(singleMode), optMode(normalOpt), |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 292 | rootEntry(0), headerPopup(0) |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 293 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 294 | setObjectName(name); |
Boris Barbulovski | a5225e9 | 2015-09-22 11:36:29 -0700 | [diff] [blame] | 295 | setSortingEnabled(false); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 296 | setRootIsDecorated(true); |
| 297 | |
Boris Barbulovski | f999cc0 | 2015-09-22 11:36:31 -0700 | [diff] [blame] | 298 | setVerticalScrollMode(ScrollPerPixel); |
| 299 | setHorizontalScrollMode(ScrollPerPixel); |
| 300 | |
Masahiro Yamada | 97bebbc | 2020-07-30 02:46:17 +0900 | [diff] [blame] | 301 | setHeaderLabels(QStringList() << "Option" << "Name" << "N" << "M" << "Y" << "Value"); |
Boris Barbulovski | a52cb32 | 2015-09-22 11:36:24 -0700 | [diff] [blame] | 302 | |
Boris Barbulovski | c14fa5e | 2015-09-22 11:36:21 -0700 | [diff] [blame] | 303 | connect(this, SIGNAL(itemSelectionChanged(void)), |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 304 | SLOT(updateSelection(void))); |
| 305 | |
| 306 | if (name) { |
| 307 | configSettings->beginGroup(name); |
| 308 | showName = configSettings->value("/showName", false).toBool(); |
| 309 | showRange = configSettings->value("/showRange", false).toBool(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 310 | optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt(); |
| 311 | configSettings->endGroup(); |
| 312 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); |
| 313 | } |
| 314 | |
Masahiro Yamada | abf741a | 2020-08-07 18:19:04 +0900 | [diff] [blame] | 315 | showColumn(promptColIdx); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 316 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 317 | allLists.append(this); |
| 318 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 319 | reinit(); |
| 320 | } |
| 321 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 322 | ConfigList::~ConfigList() |
| 323 | { |
| 324 | allLists.removeOne(this); |
| 325 | } |
| 326 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 327 | bool ConfigList::menuSkip(struct menu *menu) |
| 328 | { |
| 329 | if (optMode == normalOpt && menu_is_visible(menu)) |
| 330 | return false; |
| 331 | if (optMode == promptOpt && menu_has_prompt(menu)) |
| 332 | return false; |
| 333 | if (optMode == allOpt) |
| 334 | return false; |
| 335 | return true; |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 336 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 337 | |
| 338 | void ConfigList::reinit(void) |
| 339 | { |
Masahiro Yamada | abf741a | 2020-08-07 18:19:04 +0900 | [diff] [blame] | 340 | hideColumn(yesColIdx); |
| 341 | hideColumn(modColIdx); |
| 342 | hideColumn(noColIdx); |
| 343 | hideColumn(nameColIdx); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 344 | |
| 345 | if (showName) |
Masahiro Yamada | abf741a | 2020-08-07 18:19:04 +0900 | [diff] [blame] | 346 | showColumn(nameColIdx); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 347 | if (showRange) { |
Masahiro Yamada | abf741a | 2020-08-07 18:19:04 +0900 | [diff] [blame] | 348 | showColumn(noColIdx); |
| 349 | showColumn(modColIdx); |
| 350 | showColumn(yesColIdx); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 351 | } |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 352 | |
| 353 | updateListAll(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 356 | void ConfigList::setOptionMode(QAction *action) |
| 357 | { |
| 358 | if (action == showNormalAction) |
| 359 | optMode = normalOpt; |
| 360 | else if (action == showAllAction) |
| 361 | optMode = allOpt; |
| 362 | else |
| 363 | optMode = promptOpt; |
| 364 | |
| 365 | updateListAll(); |
| 366 | } |
| 367 | |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 368 | void ConfigList::saveSettings(void) |
| 369 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 370 | if (!objectName().isEmpty()) { |
| 371 | configSettings->beginGroup(objectName()); |
| 372 | configSettings->setValue("/showName", showName); |
| 373 | configSettings->setValue("/showRange", showRange); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 374 | configSettings->setValue("/optionMode", (int)optMode); |
| 375 | configSettings->endGroup(); |
| 376 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | ConfigItem* ConfigList::findConfigItem(struct menu *menu) |
| 380 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 381 | ConfigItem* item = (ConfigItem*)menu->data; |
| 382 | |
| 383 | for (; item; item = item->nextItem) { |
| 384 | if (this == item->listView()) |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | return item; |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void ConfigList::updateSelection(void) |
| 392 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 393 | struct menu *menu; |
| 394 | enum prop_type type; |
| 395 | |
Boris Barbulovski | be596aa | 2015-09-22 11:36:28 -0700 | [diff] [blame] | 396 | if (selectedItems().count() == 0) |
| 397 | return; |
| 398 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 399 | ConfigItem* item = (ConfigItem*)selectedItems().first(); |
| 400 | if (!item) |
| 401 | return; |
| 402 | |
| 403 | menu = item->menu; |
| 404 | emit menuChanged(menu); |
| 405 | if (!menu) |
| 406 | return; |
| 407 | type = menu->prompt ? menu->prompt->type : P_UNKNOWN; |
| 408 | if (mode == menuMode && type == P_MENU) |
| 409 | emit menuSelected(menu); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Masahiro Yamada | cb77043 | 2020-08-07 18:18:59 +0900 | [diff] [blame] | 412 | void ConfigList::updateList() |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 413 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 414 | ConfigItem* last = 0; |
Masahiro Yamada | cb77043 | 2020-08-07 18:18:59 +0900 | [diff] [blame] | 415 | ConfigItem *item; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 416 | |
| 417 | if (!rootEntry) { |
| 418 | if (mode != listMode) |
| 419 | goto update; |
| 420 | QTreeWidgetItemIterator it(this); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 421 | |
| 422 | while (*it) { |
| 423 | item = (ConfigItem*)(*it); |
| 424 | if (!item->menu) |
| 425 | continue; |
| 426 | item->testUpdateMenu(menu_is_visible(item->menu)); |
| 427 | |
| 428 | ++it; |
| 429 | } |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | if (rootEntry != &rootmenu && (mode == singleMode || |
| 434 | (mode == symbolMode && rootEntry->parent != &rootmenu))) { |
Boris Barbulovski | ee7298f | 2015-09-22 11:36:37 -0700 | [diff] [blame] | 435 | item = (ConfigItem *)topLevelItem(0); |
Masahiro Yamada | 4b20e10 | 2020-08-01 16:08:49 +0900 | [diff] [blame] | 436 | if (!item) |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 437 | item = new ConfigItem(this, 0, true); |
Masahiro Yamada | 4b20e10 | 2020-08-01 16:08:49 +0900 | [diff] [blame] | 438 | last = item; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 439 | } |
| 440 | if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) && |
| 441 | rootEntry->sym && rootEntry->prompt) { |
Masahiro Yamada | ccf56e5 | 2020-08-01 16:08:50 +0900 | [diff] [blame] | 442 | item = last ? last->nextSibling() : nullptr; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 443 | if (!item) |
| 444 | item = new ConfigItem(this, last, rootEntry, true); |
| 445 | else |
| 446 | item->testUpdateMenu(true); |
| 447 | |
| 448 | updateMenuList(item, rootEntry); |
| 449 | update(); |
Boris Barbulovski | f999cc0 | 2015-09-22 11:36:31 -0700 | [diff] [blame] | 450 | resizeColumnToContents(0); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | update: |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 454 | updateMenuList(rootEntry); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 455 | update(); |
Boris Barbulovski | f999cc0 | 2015-09-22 11:36:31 -0700 | [diff] [blame] | 456 | resizeColumnToContents(0); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 459 | void ConfigList::updateListForAll() |
| 460 | { |
| 461 | QListIterator<ConfigList *> it(allLists); |
| 462 | |
| 463 | while (it.hasNext()) { |
| 464 | ConfigList *list = it.next(); |
| 465 | |
| 466 | list->updateList(); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | void ConfigList::updateListAllForAll() |
| 471 | { |
| 472 | QListIterator<ConfigList *> it(allLists); |
| 473 | |
| 474 | while (it.hasNext()) { |
| 475 | ConfigList *list = it.next(); |
| 476 | |
| 477 | list->updateList(); |
| 478 | } |
| 479 | } |
| 480 | |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 481 | void ConfigList::setValue(ConfigItem* item, tristate val) |
| 482 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 483 | struct symbol* sym; |
| 484 | int type; |
| 485 | tristate oldval; |
| 486 | |
| 487 | sym = item->menu ? item->menu->sym : 0; |
| 488 | if (!sym) |
| 489 | return; |
| 490 | |
| 491 | type = sym_get_type(sym); |
| 492 | switch (type) { |
| 493 | case S_BOOLEAN: |
| 494 | case S_TRISTATE: |
| 495 | oldval = sym_get_tristate_value(sym); |
| 496 | |
| 497 | if (!sym_set_tristate_value(sym, val)) |
| 498 | return; |
| 499 | if (oldval == no && item->menu->list) |
| 500 | item->setExpanded(true); |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 501 | ConfigList::updateListForAll(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 502 | break; |
| 503 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void ConfigList::changeValue(ConfigItem* item) |
| 507 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 508 | struct symbol* sym; |
| 509 | struct menu* menu; |
| 510 | int type, oldexpr, newexpr; |
| 511 | |
| 512 | menu = item->menu; |
| 513 | if (!menu) |
| 514 | return; |
| 515 | sym = menu->sym; |
| 516 | if (!sym) { |
| 517 | if (item->menu->list) |
| 518 | item->setExpanded(!item->isExpanded()); |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | type = sym_get_type(sym); |
| 523 | switch (type) { |
| 524 | case S_BOOLEAN: |
| 525 | case S_TRISTATE: |
| 526 | oldexpr = sym_get_tristate_value(sym); |
| 527 | newexpr = sym_toggle_tristate_value(sym); |
| 528 | if (item->menu->list) { |
| 529 | if (oldexpr == newexpr) |
| 530 | item->setExpanded(!item->isExpanded()); |
| 531 | else if (oldexpr == no) |
| 532 | item->setExpanded(true); |
| 533 | } |
| 534 | if (oldexpr != newexpr) |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 535 | ConfigList::updateListForAll(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 536 | break; |
| 537 | case S_INT: |
| 538 | case S_HEX: |
| 539 | case S_STRING: |
Boris Barbulovski | e336b9f | 2015-09-22 11:36:34 -0700 | [diff] [blame] | 540 | parent()->lineEdit->show(item); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 541 | break; |
| 542 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void ConfigList::setRootMenu(struct menu *menu) |
| 546 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 547 | enum prop_type type; |
| 548 | |
| 549 | if (rootEntry == menu) |
| 550 | return; |
| 551 | type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN; |
| 552 | if (type != P_MENU) |
| 553 | return; |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 554 | updateMenuList(0); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 555 | rootEntry = menu; |
| 556 | updateListAll(); |
| 557 | if (currentItem()) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 558 | setSelected(currentItem(), hasFocus()); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 559 | scrollToItem(currentItem()); |
| 560 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | void ConfigList::setParentMenu(void) |
| 564 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 565 | ConfigItem* item; |
| 566 | struct menu *oldroot; |
| 567 | |
| 568 | oldroot = rootEntry; |
| 569 | if (rootEntry == &rootmenu) |
| 570 | return; |
| 571 | setRootMenu(menu_get_parent_menu(rootEntry->parent)); |
| 572 | |
| 573 | QTreeWidgetItemIterator it(this); |
| 574 | while (*it) { |
| 575 | item = (ConfigItem *)(*it); |
| 576 | if (item->menu == oldroot) { |
| 577 | setCurrentItem(item); |
| 578 | scrollToItem(item); |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | ++it; |
| 583 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* |
| 587 | * update all the children of a menu entry |
| 588 | * removes/adds the entries from the parent widget as necessary |
| 589 | * |
| 590 | * parent: either the menu list widget or a menu entry widget |
| 591 | * menu: entry to be updated |
| 592 | */ |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 593 | void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 594 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 595 | struct menu* child; |
| 596 | ConfigItem* item; |
| 597 | ConfigItem* last; |
| 598 | bool visible; |
| 599 | enum prop_type type; |
| 600 | |
| 601 | if (!menu) { |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 602 | while (parent->childCount() > 0) |
| 603 | { |
| 604 | delete parent->takeChild(0); |
| 605 | } |
| 606 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 607 | return; |
| 608 | } |
| 609 | |
| 610 | last = parent->firstChild(); |
| 611 | if (last && !last->goParent) |
| 612 | last = 0; |
| 613 | for (child = menu->list; child; child = child->next) { |
| 614 | item = last ? last->nextSibling() : parent->firstChild(); |
| 615 | type = child->prompt ? child->prompt->type : P_UNKNOWN; |
| 616 | |
| 617 | switch (mode) { |
| 618 | case menuMode: |
| 619 | if (!(child->flags & MENU_ROOT)) |
| 620 | goto hide; |
| 621 | break; |
| 622 | case symbolMode: |
| 623 | if (child->flags & MENU_ROOT) |
| 624 | goto hide; |
| 625 | break; |
| 626 | default: |
| 627 | break; |
| 628 | } |
| 629 | |
| 630 | visible = menu_is_visible(child); |
| 631 | if (!menuSkip(child)) { |
| 632 | if (!child->sym && !child->list && !child->prompt) |
| 633 | continue; |
| 634 | if (!item || item->menu != child) |
| 635 | item = new ConfigItem(parent, last, child, visible); |
| 636 | else |
| 637 | item->testUpdateMenu(visible); |
| 638 | |
| 639 | if (mode == fullMode || mode == menuMode || type != P_MENU) |
| 640 | updateMenuList(item, child); |
| 641 | else |
| 642 | updateMenuList(item, 0); |
| 643 | last = item; |
| 644 | continue; |
| 645 | } |
Mauro Carvalho Chehab | 60969f0 | 2020-04-02 11:28:03 +0200 | [diff] [blame] | 646 | hide: |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 647 | if (item && item->menu == child) { |
| 648 | last = parent->firstChild(); |
| 649 | if (last == item) |
| 650 | last = 0; |
| 651 | else while (last->nextSibling() != item) |
| 652 | last = last->nextSibling(); |
| 653 | delete item; |
| 654 | } |
| 655 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 658 | void ConfigList::updateMenuList(struct menu *menu) |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 659 | { |
| 660 | struct menu* child; |
| 661 | ConfigItem* item; |
| 662 | ConfigItem* last; |
| 663 | bool visible; |
| 664 | enum prop_type type; |
| 665 | |
| 666 | if (!menu) { |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 667 | while (topLevelItemCount() > 0) |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 668 | { |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 669 | delete takeTopLevelItem(0); |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | return; |
| 673 | } |
| 674 | |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 675 | last = (ConfigItem *)topLevelItem(0); |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 676 | if (last && !last->goParent) |
| 677 | last = 0; |
| 678 | for (child = menu->list; child; child = child->next) { |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 679 | item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0); |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 680 | type = child->prompt ? child->prompt->type : P_UNKNOWN; |
| 681 | |
| 682 | switch (mode) { |
| 683 | case menuMode: |
| 684 | if (!(child->flags & MENU_ROOT)) |
| 685 | goto hide; |
| 686 | break; |
| 687 | case symbolMode: |
| 688 | if (child->flags & MENU_ROOT) |
| 689 | goto hide; |
| 690 | break; |
| 691 | default: |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | visible = menu_is_visible(child); |
| 696 | if (!menuSkip(child)) { |
| 697 | if (!child->sym && !child->list && !child->prompt) |
| 698 | continue; |
| 699 | if (!item || item->menu != child) |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 700 | item = new ConfigItem(this, last, child, visible); |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 701 | else |
| 702 | item->testUpdateMenu(visible); |
| 703 | |
| 704 | if (mode == fullMode || mode == menuMode || type != P_MENU) |
| 705 | updateMenuList(item, child); |
| 706 | else |
| 707 | updateMenuList(item, 0); |
| 708 | last = item; |
| 709 | continue; |
| 710 | } |
Mauro Carvalho Chehab | 60969f0 | 2020-04-02 11:28:03 +0200 | [diff] [blame] | 711 | hide: |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 712 | if (item && item->menu == child) { |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 713 | last = (ConfigItem *)topLevelItem(0); |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 714 | if (last == item) |
| 715 | last = 0; |
| 716 | else while (last->nextSibling() != item) |
| 717 | last = last->nextSibling(); |
| 718 | delete item; |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 723 | void ConfigList::keyPressEvent(QKeyEvent* ev) |
| 724 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 725 | QTreeWidgetItem* i = currentItem(); |
| 726 | ConfigItem* item; |
| 727 | struct menu *menu; |
| 728 | enum prop_type type; |
| 729 | |
| 730 | if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) { |
| 731 | emit parentSelected(); |
| 732 | ev->accept(); |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | if (!i) { |
| 737 | Parent::keyPressEvent(ev); |
| 738 | return; |
| 739 | } |
| 740 | item = (ConfigItem*)i; |
| 741 | |
| 742 | switch (ev->key()) { |
| 743 | case Qt::Key_Return: |
| 744 | case Qt::Key_Enter: |
| 745 | if (item->goParent) { |
| 746 | emit parentSelected(); |
| 747 | break; |
| 748 | } |
| 749 | menu = item->menu; |
| 750 | if (!menu) |
| 751 | break; |
| 752 | type = menu->prompt ? menu->prompt->type : P_UNKNOWN; |
| 753 | if (type == P_MENU && rootEntry != menu && |
| 754 | mode != fullMode && mode != menuMode) { |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 755 | if (mode == menuMode) |
| 756 | emit menuSelected(menu); |
| 757 | else |
| 758 | emit itemSelected(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 759 | break; |
| 760 | } |
| 761 | case Qt::Key_Space: |
| 762 | changeValue(item); |
| 763 | break; |
| 764 | case Qt::Key_N: |
| 765 | setValue(item, no); |
| 766 | break; |
| 767 | case Qt::Key_M: |
| 768 | setValue(item, mod); |
| 769 | break; |
| 770 | case Qt::Key_Y: |
| 771 | setValue(item, yes); |
| 772 | break; |
| 773 | default: |
| 774 | Parent::keyPressEvent(ev); |
| 775 | return; |
| 776 | } |
| 777 | ev->accept(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 780 | void ConfigList::mousePressEvent(QMouseEvent* e) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 781 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 782 | //QPoint p(contentsToViewport(e->pos())); |
| 783 | //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y()); |
| 784 | Parent::mousePressEvent(e); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 787 | void ConfigList::mouseReleaseEvent(QMouseEvent* e) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 788 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 789 | QPoint p = e->pos(); |
| 790 | ConfigItem* item = (ConfigItem*)itemAt(p); |
| 791 | struct menu *menu; |
| 792 | enum prop_type ptype; |
| 793 | QIcon icon; |
| 794 | int idx, x; |
| 795 | |
| 796 | if (!item) |
| 797 | goto skip; |
| 798 | |
| 799 | menu = item->menu; |
| 800 | x = header()->offset() + p.x(); |
Boris Barbulovski | 76d53cb | 2015-09-22 11:36:35 -0700 | [diff] [blame] | 801 | idx = header()->logicalIndexAt(x); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 802 | switch (idx) { |
| 803 | case promptColIdx: |
Masahiro Yamada | 711b875 | 2020-08-07 18:19:03 +0900 | [diff] [blame] | 804 | icon = item->icon(promptColIdx); |
Boris Barbulovski | 76d53cb | 2015-09-22 11:36:35 -0700 | [diff] [blame] | 805 | if (!icon.isNull()) { |
| 806 | int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly. |
| 807 | if (x >= off && x < off + icon.availableSizes().first().width()) { |
| 808 | if (item->goParent) { |
| 809 | emit parentSelected(); |
| 810 | break; |
| 811 | } else if (!menu) |
| 812 | break; |
| 813 | ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; |
| 814 | if (ptype == P_MENU && rootEntry != menu && |
Maxime Chretien | 7eb7c106f | 2020-07-08 15:32:15 +0200 | [diff] [blame] | 815 | mode != fullMode && mode != menuMode && |
| 816 | mode != listMode) |
Boris Barbulovski | 76d53cb | 2015-09-22 11:36:35 -0700 | [diff] [blame] | 817 | emit menuSelected(menu); |
| 818 | else |
| 819 | changeValue(item); |
| 820 | } |
| 821 | } |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 822 | break; |
| 823 | case noColIdx: |
| 824 | setValue(item, no); |
| 825 | break; |
| 826 | case modColIdx: |
| 827 | setValue(item, mod); |
| 828 | break; |
| 829 | case yesColIdx: |
| 830 | setValue(item, yes); |
| 831 | break; |
| 832 | case dataColIdx: |
| 833 | changeValue(item); |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | skip: |
| 838 | //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y()); |
| 839 | Parent::mouseReleaseEvent(e); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 842 | void ConfigList::mouseMoveEvent(QMouseEvent* e) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 843 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 844 | //QPoint p(contentsToViewport(e->pos())); |
| 845 | //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y()); |
| 846 | Parent::mouseMoveEvent(e); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 849 | void ConfigList::mouseDoubleClickEvent(QMouseEvent* e) |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 850 | { |
Mauro Carvalho Chehab | e1f7769 | 2020-04-02 11:28:02 +0200 | [diff] [blame] | 851 | QPoint p = e->pos(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 852 | ConfigItem* item = (ConfigItem*)itemAt(p); |
| 853 | struct menu *menu; |
| 854 | enum prop_type ptype; |
| 855 | |
| 856 | if (!item) |
| 857 | goto skip; |
| 858 | if (item->goParent) { |
| 859 | emit parentSelected(); |
| 860 | goto skip; |
| 861 | } |
| 862 | menu = item->menu; |
| 863 | if (!menu) |
| 864 | goto skip; |
| 865 | ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; |
Maxime Chretien | 7eb7c106f | 2020-07-08 15:32:15 +0200 | [diff] [blame] | 866 | if (ptype == P_MENU && mode != listMode) { |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 867 | if (mode == singleMode) |
| 868 | emit itemSelected(menu); |
| 869 | else if (mode == symbolMode) |
| 870 | emit menuSelected(menu); |
| 871 | } else if (menu->sym) |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 872 | changeValue(item); |
| 873 | |
| 874 | skip: |
| 875 | //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y()); |
| 876 | Parent::mouseDoubleClickEvent(e); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void ConfigList::focusInEvent(QFocusEvent *e) |
| 880 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 881 | struct menu *menu = NULL; |
| 882 | |
| 883 | Parent::focusInEvent(e); |
| 884 | |
| 885 | ConfigItem* item = (ConfigItem *)currentItem(); |
| 886 | if (item) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 887 | setSelected(item, true); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 888 | menu = item->menu; |
| 889 | } |
| 890 | emit gotFocus(menu); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | void ConfigList::contextMenuEvent(QContextMenuEvent *e) |
| 894 | { |
Masahiro Yamada | fa8de0a | 2020-08-07 18:19:08 +0900 | [diff] [blame] | 895 | if (!headerPopup) { |
| 896 | QAction *action; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 897 | |
Masahiro Yamada | fa8de0a | 2020-08-07 18:19:08 +0900 | [diff] [blame] | 898 | headerPopup = new QMenu(this); |
| 899 | action = new QAction("Show Name", this); |
| 900 | action->setCheckable(true); |
| 901 | connect(action, SIGNAL(toggled(bool)), |
| 902 | parent(), SLOT(setShowName(bool))); |
| 903 | connect(parent(), SIGNAL(showNameChanged(bool)), |
Masahiro Yamada | d85de33 | 2020-08-18 01:36:29 +0900 | [diff] [blame] | 904 | action, SLOT(setChecked(bool))); |
Masahiro Yamada | fa8de0a | 2020-08-07 18:19:08 +0900 | [diff] [blame] | 905 | action->setChecked(showName); |
| 906 | headerPopup->addAction(action); |
| 907 | |
| 908 | action = new QAction("Show Range", this); |
| 909 | action->setCheckable(true); |
| 910 | connect(action, SIGNAL(toggled(bool)), |
| 911 | parent(), SLOT(setShowRange(bool))); |
| 912 | connect(parent(), SIGNAL(showRangeChanged(bool)), |
Masahiro Yamada | d85de33 | 2020-08-18 01:36:29 +0900 | [diff] [blame] | 913 | action, SLOT(setChecked(bool))); |
Masahiro Yamada | fa8de0a | 2020-08-07 18:19:08 +0900 | [diff] [blame] | 914 | action->setChecked(showRange); |
| 915 | headerPopup->addAction(action); |
Masahiro Yamada | fa8de0a | 2020-08-07 18:19:08 +0900 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | headerPopup->exec(e->globalPos()); |
| 919 | e->accept(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 922 | QList<ConfigList *> ConfigList::allLists; |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 923 | QAction *ConfigList::showNormalAction; |
| 924 | QAction *ConfigList::showAllAction; |
| 925 | QAction *ConfigList::showPromptAction; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 927 | ConfigView::ConfigView(QWidget* parent, const char *name) |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 928 | : Parent(parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Boris Barbulovski | 9bd36ed | 2015-09-22 11:36:22 -0700 | [diff] [blame] | 930 | setObjectName(name); |
Boris Barbulovski | 29a7016 | 2015-09-22 11:36:10 -0700 | [diff] [blame] | 931 | QVBoxLayout *verticalLayout = new QVBoxLayout(this); |
Boris Barbulovski | 92298b4 | 2015-09-22 11:36:11 -0700 | [diff] [blame] | 932 | verticalLayout->setContentsMargins(0, 0, 0, 0); |
Boris Barbulovski | 29a7016 | 2015-09-22 11:36:10 -0700 | [diff] [blame] | 933 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 934 | list = new ConfigList(this); |
Boris Barbulovski | 29a7016 | 2015-09-22 11:36:10 -0700 | [diff] [blame] | 935 | verticalLayout->addWidget(list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | lineEdit = new ConfigLineEdit(this); |
| 937 | lineEdit->hide(); |
Boris Barbulovski | 29a7016 | 2015-09-22 11:36:10 -0700 | [diff] [blame] | 938 | verticalLayout->addWidget(lineEdit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 941 | void ConfigView::setShowName(bool b) |
| 942 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 943 | if (list->showName != b) { |
| 944 | list->showName = b; |
| 945 | list->reinit(); |
| 946 | emit showNameChanged(b); |
| 947 | } |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | void ConfigView::setShowRange(bool b) |
| 951 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 952 | if (list->showRange != b) { |
| 953 | list->showRange = b; |
| 954 | list->reinit(); |
| 955 | emit showRangeChanged(b); |
| 956 | } |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 959 | void ConfigList::setAllOpen(bool open) |
| 960 | { |
| 961 | QTreeWidgetItemIterator it(this); |
| 962 | |
| 963 | while (*it) { |
| 964 | (*it)->setExpanded(open); |
| 965 | |
| 966 | ++it; |
| 967 | } |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 970 | ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 971 | : Parent(parent), sym(0), _menu(0) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 972 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 973 | setObjectName(name); |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 974 | setOpenLinks(false); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 975 | |
| 976 | if (!objectName().isEmpty()) { |
| 977 | configSettings->beginGroup(objectName()); |
Boris Barbulovski | e039303 | 2016-11-30 14:57:52 -0800 | [diff] [blame] | 978 | setShowDebug(configSettings->value("/showDebug", false).toBool()); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 979 | configSettings->endGroup(); |
| 980 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); |
| 981 | } |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 982 | |
| 983 | contextMenu = createStandardContextMenu(); |
| 984 | QAction *action = new QAction("Show Debug Info", contextMenu); |
| 985 | |
| 986 | action->setCheckable(true); |
| 987 | connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); |
| 988 | connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setChecked(bool))); |
| 989 | action->setChecked(showDebug()); |
| 990 | contextMenu->addSeparator(); |
| 991 | contextMenu->addAction(action); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | void ConfigInfoView::saveSettings(void) |
| 995 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 996 | if (!objectName().isEmpty()) { |
| 997 | configSettings->beginGroup(objectName()); |
| 998 | configSettings->setValue("/showDebug", showDebug()); |
| 999 | configSettings->endGroup(); |
| 1000 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | void ConfigInfoView::setShowDebug(bool b) |
| 1004 | { |
| 1005 | if (_showDebug != b) { |
| 1006 | _showDebug = b; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1007 | if (_menu) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1008 | menuInfo(); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1009 | else if (sym) |
| 1010 | symbolInfo(); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1011 | emit showDebugChanged(b); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void ConfigInfoView::setInfo(struct menu *m) |
| 1016 | { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1017 | if (_menu == m) |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1018 | return; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1019 | _menu = m; |
Roman Zippel | 6fa1da8 | 2007-01-10 23:15:31 -0800 | [diff] [blame] | 1020 | sym = NULL; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1021 | if (!_menu) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1022 | clear(); |
Roman Zippel | 6fa1da8 | 2007-01-10 23:15:31 -0800 | [diff] [blame] | 1023 | else |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1024 | menuInfo(); |
| 1025 | } |
| 1026 | |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1027 | void ConfigInfoView::symbolInfo(void) |
| 1028 | { |
| 1029 | QString str; |
| 1030 | |
| 1031 | str += "<big>Symbol: <b>"; |
| 1032 | str += print_filter(sym->name); |
| 1033 | str += "</b></big><br><br>value: "; |
| 1034 | str += print_filter(sym_get_string_value(sym)); |
| 1035 | str += "<br>visibility: "; |
| 1036 | str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n"; |
| 1037 | str += "<br>"; |
| 1038 | str += debug_info(sym); |
| 1039 | |
| 1040 | setText(str); |
| 1041 | } |
| 1042 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1043 | void ConfigInfoView::menuInfo(void) |
| 1044 | { |
| 1045 | struct symbol* sym; |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1046 | QString info; |
| 1047 | QTextStream stream(&info); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1048 | |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1049 | sym = _menu->sym; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1050 | if (sym) { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1051 | if (_menu->prompt) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1052 | stream << "<big><b>"; |
| 1053 | stream << print_filter(_menu->prompt->text); |
| 1054 | stream << "</b></big>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1055 | if (sym->name) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1056 | stream << " ("; |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1057 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1058 | stream << "<a href=\"s" << sym->name << "\">"; |
| 1059 | stream << print_filter(sym->name); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1060 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1061 | stream << "</a>"; |
| 1062 | stream << ")"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } else if (sym->name) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1065 | stream << "<big><b>"; |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1066 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1067 | stream << "<a href=\"s" << sym->name << "\">"; |
| 1068 | stream << print_filter(sym->name); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1069 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1070 | stream << "</a>"; |
| 1071 | stream << "</b></big>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1072 | } |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1073 | stream << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1074 | |
| 1075 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1076 | stream << debug_info(sym); |
| 1077 | |
Masahiro Yamada | a46afd1 | 2020-09-14 23:59:48 +0900 | [diff] [blame] | 1078 | struct gstr help_gstr = str_new(); |
| 1079 | |
| 1080 | menu_get_ext_help(_menu, &help_gstr); |
| 1081 | stream << print_filter(str_get(&help_gstr)); |
| 1082 | str_free(&help_gstr); |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1083 | } else if (_menu->prompt) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1084 | stream << "<big><b>"; |
| 1085 | stream << print_filter(_menu->prompt->text); |
| 1086 | stream << "</b></big><br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1087 | if (showDebug()) { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1088 | if (_menu->prompt->visible.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1089 | stream << " dep: "; |
| 1090 | expr_print(_menu->prompt->visible.expr, |
| 1091 | expr_print_help, &stream, E_NONE); |
| 1092 | stream << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1093 | } |
Masahiro Yamada | a46afd1 | 2020-09-14 23:59:48 +0900 | [diff] [blame] | 1094 | |
| 1095 | stream << "defined at " << _menu->file->name << ":" |
| 1096 | << _menu->lineno << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1099 | |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1100 | setText(info); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | QString ConfigInfoView::debug_info(struct symbol *sym) |
| 1104 | { |
| 1105 | QString debug; |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1106 | QTextStream stream(&debug); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1107 | |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1108 | stream << "type: "; |
| 1109 | stream << print_filter(sym_type_name(sym->type)); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1110 | if (sym_is_choice(sym)) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1111 | stream << " (choice)"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1112 | debug += "<br>"; |
| 1113 | if (sym->rev_dep.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1114 | stream << "reverse dep: "; |
| 1115 | expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE); |
| 1116 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1117 | } |
| 1118 | for (struct property *prop = sym->prop; prop; prop = prop->next) { |
| 1119 | switch (prop->type) { |
| 1120 | case P_PROMPT: |
| 1121 | case P_MENU: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1122 | stream << "prompt: <a href=\"m" << sym->name << "\">"; |
| 1123 | stream << print_filter(prop->text); |
| 1124 | stream << "</a><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1125 | break; |
| 1126 | case P_DEFAULT: |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1127 | case P_SELECT: |
| 1128 | case P_RANGE: |
Mauro Carvalho Chehab | 8f8499a | 2020-06-30 08:48:53 +0200 | [diff] [blame] | 1129 | case P_COMMENT: |
| 1130 | case P_IMPLY: |
| 1131 | case P_SYMBOL: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1132 | stream << prop_get_type_name(prop->type); |
| 1133 | stream << ": "; |
| 1134 | expr_print(prop->expr, expr_print_help, |
| 1135 | &stream, E_NONE); |
| 1136 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1137 | break; |
| 1138 | case P_CHOICE: |
| 1139 | if (sym_is_choice(sym)) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1140 | stream << "choice: "; |
| 1141 | expr_print(prop->expr, expr_print_help, |
| 1142 | &stream, E_NONE); |
| 1143 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1144 | } |
| 1145 | break; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1146 | default: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1147 | stream << "unknown property: "; |
| 1148 | stream << prop_get_type_name(prop->type); |
| 1149 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1150 | } |
| 1151 | if (prop->visible.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1152 | stream << " dep: "; |
| 1153 | expr_print(prop->visible.expr, expr_print_help, |
| 1154 | &stream, E_NONE); |
| 1155 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1156 | } |
| 1157 | } |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1158 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1159 | |
| 1160 | return debug; |
| 1161 | } |
| 1162 | |
| 1163 | QString ConfigInfoView::print_filter(const QString &str) |
| 1164 | { |
| 1165 | QRegExp re("[<>&\"\\n]"); |
| 1166 | QString res = str; |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1167 | for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { |
| 1168 | switch (res[i].toLatin1()) { |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1169 | case '<': |
| 1170 | res.replace(i, 1, "<"); |
| 1171 | i += 4; |
| 1172 | break; |
| 1173 | case '>': |
| 1174 | res.replace(i, 1, ">"); |
| 1175 | i += 4; |
| 1176 | break; |
| 1177 | case '&': |
| 1178 | res.replace(i, 1, "&"); |
| 1179 | i += 5; |
| 1180 | break; |
| 1181 | case '"': |
| 1182 | res.replace(i, 1, """); |
| 1183 | i += 6; |
| 1184 | break; |
| 1185 | case '\n': |
| 1186 | res.replace(i, 1, "<br>"); |
| 1187 | i += 4; |
| 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | return res; |
| 1192 | } |
| 1193 | |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1194 | void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1195 | { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1196 | QTextStream *stream = reinterpret_cast<QTextStream *>(data); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1199 | *stream << "<a href=\"s" << sym->name << "\">"; |
| 1200 | *stream << print_filter(str); |
| 1201 | *stream << "</a>"; |
| 1202 | } else { |
| 1203 | *stream << print_filter(str); |
| 1204 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1207 | void ConfigInfoView::clicked(const QUrl &url) |
| 1208 | { |
| 1209 | QByteArray str = url.toEncoded(); |
| 1210 | const std::size_t count = str.size(); |
| 1211 | char *data = new char[count + 1]; |
| 1212 | struct symbol **result; |
| 1213 | struct menu *m = NULL; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1214 | |
| 1215 | if (count < 1) { |
Masahiro Yamada | c9b09a92 | 2020-07-30 02:02:39 +0900 | [diff] [blame] | 1216 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1217 | return; |
| 1218 | } |
| 1219 | |
| 1220 | memcpy(data, str.constData(), count); |
| 1221 | data[count] = '\0'; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1222 | |
| 1223 | /* Seek for exact match */ |
| 1224 | data[0] = '^'; |
| 1225 | strcat(data, "$"); |
| 1226 | result = sym_re_search(data); |
| 1227 | if (!result) { |
Masahiro Yamada | c9b09a92 | 2020-07-30 02:02:39 +0900 | [diff] [blame] | 1228 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1229 | return; |
| 1230 | } |
| 1231 | |
| 1232 | sym = *result; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1233 | |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1234 | /* Seek for the menu which holds the symbol */ |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1235 | for (struct property *prop = sym->prop; prop; prop = prop->next) { |
| 1236 | if (prop->type != P_PROMPT && prop->type != P_MENU) |
| 1237 | continue; |
| 1238 | m = prop->menu; |
| 1239 | break; |
| 1240 | } |
| 1241 | |
| 1242 | if (!m) { |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1243 | /* Symbol is not visible as a menu */ |
| 1244 | symbolInfo(); |
| 1245 | emit showDebugChanged(true); |
| 1246 | } else { |
| 1247 | emit menuSelected(m); |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1248 | } |
| 1249 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1250 | free(result); |
Masahiro Yamada | a608b6a | 2020-09-09 07:16:37 +0900 | [diff] [blame] | 1251 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1252 | } |
| 1253 | |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 1254 | void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event) |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1255 | { |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 1256 | contextMenu->popup(event->globalPos()); |
| 1257 | event->accept(); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1260 | ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent) |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1261 | : Parent(parent), result(NULL) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1262 | { |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1263 | setObjectName("search"); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1264 | setWindowTitle("Search Config"); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1265 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1266 | QVBoxLayout* layout1 = new QVBoxLayout(this); |
| 1267 | layout1->setContentsMargins(11, 11, 11, 11); |
| 1268 | layout1->setSpacing(6); |
Masahiro Yamada | 9264115 | 2020-08-07 18:18:58 +0900 | [diff] [blame] | 1269 | |
| 1270 | QHBoxLayout* layout2 = new QHBoxLayout(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1271 | layout2->setContentsMargins(0, 0, 0, 0); |
| 1272 | layout2->setSpacing(6); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1273 | layout2->addWidget(new QLabel("Find:", this)); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1274 | editField = new QLineEdit(this); |
| 1275 | connect(editField, SIGNAL(returnPressed()), SLOT(search())); |
| 1276 | layout2->addWidget(editField); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1277 | searchButton = new QPushButton("Search", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1278 | searchButton->setAutoDefault(false); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1279 | connect(searchButton, SIGNAL(clicked()), SLOT(search())); |
| 1280 | layout2->addWidget(searchButton); |
| 1281 | layout1->addLayout(layout2); |
| 1282 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1283 | split = new QSplitter(this); |
Markus Heidelberg | 7298b93 | 2009-05-18 01:36:50 +0200 | [diff] [blame] | 1284 | split->setOrientation(Qt::Vertical); |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1285 | list = new ConfigView(split, "search"); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1286 | list->list->mode = listMode; |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1287 | info = new ConfigInfoView(split, "search"); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1288 | connect(list->list, SIGNAL(menuChanged(struct menu *)), |
| 1289 | info, SLOT(setInfo(struct menu *))); |
Marco Costalba | 63431e7 | 2006-10-05 19:12:59 +0200 | [diff] [blame] | 1290 | connect(list->list, SIGNAL(menuChanged(struct menu *)), |
| 1291 | parent, SLOT(setMenuLink(struct menu *))); |
| 1292 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1293 | layout1->addWidget(split); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1294 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1295 | QVariant x, y; |
| 1296 | int width, height; |
| 1297 | bool ok; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1298 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1299 | configSettings->beginGroup("search"); |
| 1300 | width = configSettings->value("/window width", parent->width() / 2).toInt(); |
| 1301 | height = configSettings->value("/window height", parent->height() / 2).toInt(); |
| 1302 | resize(width, height); |
| 1303 | x = configSettings->value("/window x"); |
| 1304 | y = configSettings->value("/window y"); |
| 1305 | if (x.isValid() && y.isValid()) |
| 1306 | move(x.toInt(), y.toInt()); |
| 1307 | QList<int> sizes = configSettings->readSizes("/split", &ok); |
| 1308 | if (ok) |
| 1309 | split->setSizes(sizes); |
| 1310 | configSettings->endGroup(); |
| 1311 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | void ConfigSearchWindow::saveSettings(void) |
| 1315 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1316 | if (!objectName().isEmpty()) { |
| 1317 | configSettings->beginGroup(objectName()); |
| 1318 | configSettings->setValue("/window x", pos().x()); |
| 1319 | configSettings->setValue("/window y", pos().y()); |
| 1320 | configSettings->setValue("/window width", size().width()); |
| 1321 | configSettings->setValue("/window height", size().height()); |
| 1322 | configSettings->writeSizes("/split", split->sizes()); |
| 1323 | configSettings->endGroup(); |
| 1324 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | void ConfigSearchWindow::search(void) |
| 1328 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1329 | struct symbol **p; |
| 1330 | struct property *prop; |
| 1331 | ConfigItem *lastItem = NULL; |
| 1332 | |
| 1333 | free(result); |
| 1334 | list->list->clear(); |
| 1335 | info->clear(); |
| 1336 | |
| 1337 | result = sym_re_search(editField->text().toLatin1()); |
| 1338 | if (!result) |
| 1339 | return; |
| 1340 | for (p = result; *p; p++) { |
| 1341 | for_all_prompts((*p), prop) |
| 1342 | lastItem = new ConfigItem(list->list, lastItem, prop->menu, |
| 1343 | menu_is_visible(prop->menu)); |
| 1344 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | /* |
| 1348 | * Construct the complete config widget |
| 1349 | */ |
| 1350 | ConfigMainWindow::ConfigMainWindow(void) |
Roman Zippel | f12aa70 | 2006-11-25 11:09:31 -0800 | [diff] [blame] | 1351 | : searchWindow(0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | { |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1353 | bool ok = true; |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1354 | QVariant x, y; |
| 1355 | int width, height; |
Randy Dunlap | a54bb70 | 2007-10-20 11:18:47 -0700 | [diff] [blame] | 1356 | char title[256]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Markus Heidelberg | 8d90c97 | 2009-05-18 01:36:52 +0200 | [diff] [blame] | 1358 | QDesktopWidget *d = configApp->desktop(); |
Arnaud Lacombe | 0954828 | 2010-08-18 01:57:13 -0400 | [diff] [blame] | 1359 | snprintf(title, sizeof(title), "%s%s", |
| 1360 | rootmenu.prompt->text, |
Michal Marek | 76a136c | 2010-09-01 17:39:27 +0200 | [diff] [blame] | 1361 | "" |
Michal Marek | 76a136c | 2010-09-01 17:39:27 +0200 | [diff] [blame] | 1362 | ); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1363 | setWindowTitle(title); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1365 | width = configSettings->value("/window width", d->width() - 64).toInt(); |
| 1366 | height = configSettings->value("/window height", d->height() - 64).toInt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | resize(width, height); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1368 | x = configSettings->value("/window x"); |
| 1369 | y = configSettings->value("/window y"); |
| 1370 | if ((x.isValid())&&(y.isValid())) |
| 1371 | move(x.toInt(), y.toInt()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 1373 | // set up icons |
| 1374 | ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes)); |
| 1375 | ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod)); |
| 1376 | ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no)); |
| 1377 | ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes)); |
| 1378 | ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no)); |
| 1379 | ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu)); |
| 1380 | ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback)); |
| 1381 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1382 | QWidget *widget = new QWidget(this); |
| 1383 | QVBoxLayout *layout = new QVBoxLayout(widget); |
| 1384 | setCentralWidget(widget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1386 | split1 = new QSplitter(widget); |
| 1387 | split1->setOrientation(Qt::Horizontal); |
| 1388 | split1->setChildrenCollapsible(false); |
| 1389 | |
| 1390 | menuView = new ConfigView(widget, "menu"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | menuList = menuView->list; |
| 1392 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1393 | split2 = new QSplitter(widget); |
| 1394 | split2->setChildrenCollapsible(false); |
Markus Heidelberg | 7298b93 | 2009-05-18 01:36:50 +0200 | [diff] [blame] | 1395 | split2->setOrientation(Qt::Vertical); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | // create config tree |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1398 | configView = new ConfigView(widget, "config"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | configList = configView->list; |
| 1400 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1401 | helpText = new ConfigInfoView(widget, "help"); |
| 1402 | |
| 1403 | layout->addWidget(split2); |
| 1404 | split2->addWidget(split1); |
| 1405 | split1->addWidget(configView); |
| 1406 | split1->addWidget(menuView); |
| 1407 | split2->addWidget(helpText); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
| 1409 | setTabOrder(configList, helpText); |
| 1410 | configList->setFocus(); |
| 1411 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1412 | backAction = new QAction(QPixmap(xpm_back), "Back", this); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1413 | connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack())); |
| 1414 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1415 | QAction *quitAction = new QAction("&Quit", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1416 | quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1417 | connect(quitAction, SIGNAL(triggered(bool)), SLOT(close())); |
| 1418 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1419 | QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1420 | loadAction->setShortcut(Qt::CTRL + Qt::Key_L); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1421 | connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig())); |
| 1422 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1423 | saveAction = new QAction(QPixmap(xpm_save), "&Save", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1424 | saveAction->setShortcut(Qt::CTRL + Qt::Key_S); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1425 | connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig())); |
| 1426 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1427 | conf_set_changed_callback(conf_changed); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1428 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1429 | // Set saveAction's initial state |
| 1430 | conf_changed(); |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1431 | configname = xstrdup(conf_get_configname()); |
| 1432 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1433 | QAction *saveAsAction = new QAction("Save &As...", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1434 | connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1435 | QAction *searchAction = new QAction("&Find", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1436 | searchAction->setShortcut(Qt::CTRL + Qt::Key_F); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1437 | connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1438 | singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1439 | singleViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1440 | connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1441 | splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1442 | splitViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1443 | connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1444 | fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1445 | fullViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1446 | connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1448 | QAction *showNameAction = new QAction("Show Name", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1449 | showNameAction->setCheckable(true); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1450 | connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool))); |
Boris Barbulovski | 9c86235 | 2015-09-22 11:36:12 -0700 | [diff] [blame] | 1451 | showNameAction->setChecked(configView->showName()); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1452 | QAction *showRangeAction = new QAction("Show Range", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1453 | showRangeAction->setCheckable(true); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1454 | connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool))); |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1455 | |
| 1456 | QActionGroup *optGroup = new QActionGroup(this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1457 | optGroup->setExclusive(true); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1458 | connect(optGroup, SIGNAL(triggered(QAction*)), configList, |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1459 | SLOT(setOptionMode(QAction *))); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1460 | connect(optGroup, SIGNAL(triggered(QAction *)), menuList, |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1461 | SLOT(setOptionMode(QAction *))); |
| 1462 | |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1463 | ConfigList::showNormalAction = new QAction("Show Normal Options", optGroup); |
| 1464 | ConfigList::showNormalAction->setCheckable(true); |
| 1465 | ConfigList::showAllAction = new QAction("Show All Options", optGroup); |
| 1466 | ConfigList::showAllAction->setCheckable(true); |
| 1467 | ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup); |
| 1468 | ConfigList::showPromptAction->setCheckable(true); |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1469 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1470 | QAction *showDebugAction = new QAction("Show Debug Info", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1471 | showDebugAction->setCheckable(true); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1472 | connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); |
Boris Barbulovski | 9c86235 | 2015-09-22 11:36:12 -0700 | [diff] [blame] | 1473 | showDebugAction->setChecked(helpText->showDebug()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1475 | QAction *showIntroAction = new QAction("Introduction", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1476 | connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1477 | QAction *showAboutAction = new QAction("About", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1478 | connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
| 1480 | // init tool bar |
Masahiro Yamada | 860ec3f | 2020-08-07 18:18:55 +0900 | [diff] [blame] | 1481 | QToolBar *toolBar = addToolBar("Tools"); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1482 | toolBar->addAction(backAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | toolBar->addSeparator(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1484 | toolBar->addAction(loadAction); |
| 1485 | toolBar->addAction(saveAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | toolBar->addSeparator(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1487 | toolBar->addAction(singleViewAction); |
| 1488 | toolBar->addAction(splitViewAction); |
| 1489 | toolBar->addAction(fullViewAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1491 | // create file menu |
| 1492 | QMenu *menu = menuBar()->addMenu("&File"); |
| 1493 | menu->addAction(loadAction); |
| 1494 | menu->addAction(saveAction); |
| 1495 | menu->addAction(saveAsAction); |
| 1496 | menu->addSeparator(); |
| 1497 | menu->addAction(quitAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | |
Shlomi Fish | 66e7c72 | 2007-02-14 00:32:58 -0800 | [diff] [blame] | 1499 | // create edit menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1500 | menu = menuBar()->addMenu("&Edit"); |
| 1501 | menu->addAction(searchAction); |
Shlomi Fish | 66e7c72 | 2007-02-14 00:32:58 -0800 | [diff] [blame] | 1502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | // create options menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1504 | menu = menuBar()->addMenu("&Option"); |
| 1505 | menu->addAction(showNameAction); |
| 1506 | menu->addAction(showRangeAction); |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1507 | menu->addSeparator(); |
| 1508 | menu->addActions(optGroup->actions()); |
| 1509 | menu->addSeparator(); |
| 1510 | menu->addAction(showDebugAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
| 1512 | // create help menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1513 | menu = menuBar()->addMenu("&Help"); |
| 1514 | menu->addAction(showIntroAction); |
| 1515 | menu->addAction(showAboutAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1517 | connect (helpText, SIGNAL (anchorClicked (const QUrl &)), |
| 1518 | helpText, SLOT (clicked (const QUrl &)) ); |
| 1519 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1520 | connect(configList, SIGNAL(menuChanged(struct menu *)), |
| 1521 | helpText, SLOT(setInfo(struct menu *))); |
| 1522 | connect(configList, SIGNAL(menuSelected(struct menu *)), |
| 1523 | SLOT(changeMenu(struct menu *))); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1524 | connect(configList, SIGNAL(itemSelected(struct menu *)), |
| 1525 | SLOT(changeItens(struct menu *))); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1526 | connect(configList, SIGNAL(parentSelected()), |
| 1527 | SLOT(goBack())); |
| 1528 | connect(menuList, SIGNAL(menuChanged(struct menu *)), |
| 1529 | helpText, SLOT(setInfo(struct menu *))); |
| 1530 | connect(menuList, SIGNAL(menuSelected(struct menu *)), |
| 1531 | SLOT(changeMenu(struct menu *))); |
| 1532 | |
| 1533 | connect(configList, SIGNAL(gotFocus(struct menu *)), |
| 1534 | helpText, SLOT(setInfo(struct menu *))); |
| 1535 | connect(menuList, SIGNAL(gotFocus(struct menu *)), |
| 1536 | helpText, SLOT(setInfo(struct menu *))); |
| 1537 | connect(menuList, SIGNAL(gotFocus(struct menu *)), |
| 1538 | SLOT(listFocusChanged(void))); |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1539 | connect(helpText, SIGNAL(menuSelected(struct menu *)), |
| 1540 | SLOT(setMenuLink(struct menu *))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1542 | QString listMode = configSettings->value("/listMode", "symbol").toString(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | if (listMode == "single") |
| 1544 | showSingleView(); |
| 1545 | else if (listMode == "full") |
| 1546 | showFullView(); |
| 1547 | else /*if (listMode == "split")*/ |
| 1548 | showSplitView(); |
| 1549 | |
| 1550 | // UI setup done, restore splitter positions |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 1551 | QList<int> sizes = configSettings->readSizes("/split1", &ok); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | if (ok) |
| 1553 | split1->setSizes(sizes); |
| 1554 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1555 | sizes = configSettings->readSizes("/split2", &ok); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | if (ok) |
| 1557 | split2->setSizes(sizes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | void ConfigMainWindow::loadConfig(void) |
| 1561 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1562 | QString str; |
| 1563 | QByteArray ba; |
| 1564 | const char *name; |
| 1565 | |
| 1566 | str = QFileDialog::getOpenFileName(this, "", configname); |
| 1567 | if (str.isNull()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | return; |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1569 | |
| 1570 | ba = str.toLocal8Bit(); |
| 1571 | name = ba.data(); |
| 1572 | |
| 1573 | if (conf_read(name)) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1574 | QMessageBox::information(this, "qconf", "Unable to load configuration!"); |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1575 | |
| 1576 | free(configname); |
| 1577 | configname = xstrdup(name); |
| 1578 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 1579 | ConfigList::updateListAllForAll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1582 | bool ConfigMainWindow::saveConfig(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1584 | if (conf_write(configname)) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1585 | QMessageBox::information(this, "qconf", "Unable to save configuration!"); |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
Masahiro Yamada | 00c864f | 2018-07-20 16:46:31 +0900 | [diff] [blame] | 1588 | conf_write_autoconf(0); |
| 1589 | |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1590 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | void ConfigMainWindow::saveConfigAs(void) |
| 1594 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1595 | QString str; |
| 1596 | QByteArray ba; |
| 1597 | const char *name; |
| 1598 | |
| 1599 | str = QFileDialog::getSaveFileName(this, "", configname); |
| 1600 | if (str.isNull()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | return; |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1602 | |
| 1603 | ba = str.toLocal8Bit(); |
| 1604 | name = ba.data(); |
| 1605 | |
| 1606 | if (conf_write(name)) { |
| 1607 | QMessageBox::information(this, "qconf", "Unable to save configuration!"); |
| 1608 | } |
| 1609 | conf_write_autoconf(0); |
| 1610 | |
| 1611 | free(configname); |
| 1612 | configname = xstrdup(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1615 | void ConfigMainWindow::searchConfig(void) |
| 1616 | { |
| 1617 | if (!searchWindow) |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1618 | searchWindow = new ConfigSearchWindow(this); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1619 | searchWindow->show(); |
| 1620 | } |
| 1621 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1622 | void ConfigMainWindow::changeItens(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1624 | configList->setRootMenu(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1627 | void ConfigMainWindow::changeMenu(struct menu *menu) |
| 1628 | { |
| 1629 | menuList->setRootMenu(menu); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1632 | void ConfigMainWindow::setMenuLink(struct menu *menu) |
| 1633 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1634 | struct menu *parent; |
| 1635 | ConfigList* list = NULL; |
| 1636 | ConfigItem* item; |
| 1637 | |
| 1638 | if (configList->menuSkip(menu)) |
| 1639 | return; |
| 1640 | |
| 1641 | switch (configList->mode) { |
| 1642 | case singleMode: |
| 1643 | list = configList; |
| 1644 | parent = menu_get_parent_menu(menu); |
| 1645 | if (!parent) |
| 1646 | return; |
| 1647 | list->setRootMenu(parent); |
| 1648 | break; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1649 | case menuMode: |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1650 | if (menu->flags & MENU_ROOT) { |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1651 | menuList->setRootMenu(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1652 | configList->clearSelection(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1653 | list = configList; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1654 | } else { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1655 | parent = menu_get_parent_menu(menu->parent); |
| 1656 | if (!parent) |
| 1657 | return; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1658 | |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1659 | /* Select the config view */ |
| 1660 | item = configList->findConfigItem(parent); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1661 | if (item) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 1662 | configList->setSelected(item, true); |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1663 | configList->scrollToItem(item); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1664 | } |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1665 | |
| 1666 | menuList->setRootMenu(parent); |
| 1667 | menuList->clearSelection(); |
| 1668 | list = menuList; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1669 | } |
| 1670 | break; |
| 1671 | case fullMode: |
| 1672 | list = configList; |
| 1673 | break; |
| 1674 | default: |
| 1675 | break; |
| 1676 | } |
| 1677 | |
| 1678 | if (list) { |
| 1679 | item = list->findConfigItem(menu); |
| 1680 | if (item) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 1681 | list->setSelected(item, true); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1682 | list->scrollToItem(item); |
| 1683 | list->setFocus(); |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1684 | helpText->setInfo(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1685 | } |
| 1686 | } |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | void ConfigMainWindow::listFocusChanged(void) |
| 1690 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1691 | if (menuList->mode == menuMode) |
| 1692 | configList->clearSelection(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void ConfigMainWindow::goBack(void) |
| 1696 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1697 | if (configList->rootEntry == &rootmenu) |
Boris Barbulovski | be596aa | 2015-09-22 11:36:28 -0700 | [diff] [blame] | 1698 | return; |
| 1699 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1700 | configList->setParentMenu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void ConfigMainWindow::showSingleView(void) |
| 1704 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1705 | singleViewAction->setEnabled(false); |
| 1706 | singleViewAction->setChecked(true); |
| 1707 | splitViewAction->setEnabled(true); |
| 1708 | splitViewAction->setChecked(false); |
| 1709 | fullViewAction->setEnabled(true); |
| 1710 | fullViewAction->setChecked(false); |
| 1711 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1712 | backAction->setEnabled(true); |
| 1713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | menuView->hide(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1715 | menuList->setRootMenu(0); |
| 1716 | configList->mode = singleMode; |
| 1717 | if (configList->rootEntry == &rootmenu) |
| 1718 | configList->updateListAll(); |
| 1719 | else |
| 1720 | configList->setRootMenu(&rootmenu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | configList->setFocus(); |
| 1722 | } |
| 1723 | |
| 1724 | void ConfigMainWindow::showSplitView(void) |
| 1725 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1726 | singleViewAction->setEnabled(true); |
| 1727 | singleViewAction->setChecked(false); |
| 1728 | splitViewAction->setEnabled(false); |
| 1729 | splitViewAction->setChecked(true); |
| 1730 | fullViewAction->setEnabled(true); |
| 1731 | fullViewAction->setChecked(false); |
| 1732 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1733 | backAction->setEnabled(false); |
| 1734 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1735 | configList->mode = menuMode; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1736 | if (configList->rootEntry == &rootmenu) |
| 1737 | configList->updateListAll(); |
| 1738 | else |
| 1739 | configList->setRootMenu(&rootmenu); |
| 1740 | configList->setAllOpen(true); |
| 1741 | configApp->processEvents(); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1742 | menuList->mode = symbolMode; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1743 | menuList->setRootMenu(&rootmenu); |
| 1744 | menuList->setAllOpen(true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | menuView->show(); |
| 1746 | menuList->setFocus(); |
| 1747 | } |
| 1748 | |
| 1749 | void ConfigMainWindow::showFullView(void) |
| 1750 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1751 | singleViewAction->setEnabled(true); |
| 1752 | singleViewAction->setChecked(false); |
| 1753 | splitViewAction->setEnabled(true); |
| 1754 | splitViewAction->setChecked(false); |
| 1755 | fullViewAction->setEnabled(false); |
| 1756 | fullViewAction->setChecked(true); |
| 1757 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1758 | backAction->setEnabled(false); |
| 1759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | menuView->hide(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1761 | menuList->setRootMenu(0); |
| 1762 | configList->mode = fullMode; |
| 1763 | if (configList->rootEntry == &rootmenu) |
| 1764 | configList->updateListAll(); |
| 1765 | else |
| 1766 | configList->setRootMenu(&rootmenu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | configList->setFocus(); |
| 1768 | } |
| 1769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | /* |
| 1771 | * ask for saving configuration before quitting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | */ |
| 1773 | void ConfigMainWindow::closeEvent(QCloseEvent* e) |
| 1774 | { |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 1775 | if (!conf_get_changed()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | e->accept(); |
| 1777 | return; |
| 1778 | } |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1779 | QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1781 | mb.setButtonText(QMessageBox::Yes, "&Save Changes"); |
| 1782 | mb.setButtonText(QMessageBox::No, "&Discard Changes"); |
| 1783 | mb.setButtonText(QMessageBox::Cancel, "Cancel Exit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | switch (mb.exec()) { |
| 1785 | case QMessageBox::Yes: |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1786 | if (saveConfig()) |
| 1787 | e->accept(); |
| 1788 | else |
| 1789 | e->ignore(); |
| 1790 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | case QMessageBox::No: |
| 1792 | e->accept(); |
| 1793 | break; |
| 1794 | case QMessageBox::Cancel: |
| 1795 | e->ignore(); |
| 1796 | break; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | void ConfigMainWindow::showIntro(void) |
| 1801 | { |
Masahiro Yamada | 8c30e7e | 2020-08-29 17:14:07 +0900 | [diff] [blame] | 1802 | static const QString str = |
| 1803 | "Welcome to the qconf graphical configuration tool.\n" |
| 1804 | "\n" |
| 1805 | "For each option, a blank box indicates the feature is " |
| 1806 | "disabled, a check indicates it is enabled, and a dot " |
| 1807 | "indicates that it is to be compiled as a module. Clicking on " |
| 1808 | "the box will cycle through the three states.\n" |
| 1809 | "\n" |
| 1810 | "If you do not see an option (e.g., a device driver) that you " |
| 1811 | "believe should be present, try turning on Show All Options " |
Masahiro Yamada | 1fb7524 | 2020-08-29 17:14:08 +0900 | [diff] [blame] | 1812 | "under the Options menu. Enabling Show Debug Info will help you" |
| 1813 | "figure out what other options must be enabled to support the " |
| 1814 | "option you are interested in, and hyperlinks will navigate to " |
| 1815 | "them.\n" |
Masahiro Yamada | 8c30e7e | 2020-08-29 17:14:07 +0900 | [diff] [blame] | 1816 | "\n" |
| 1817 | "Toggling Show Debug Info under the Options menu will show the " |
| 1818 | "dependencies, which you can then match by examining other " |
| 1819 | "options.\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
| 1821 | QMessageBox::information(this, "qconf", str); |
| 1822 | } |
| 1823 | |
| 1824 | void ConfigMainWindow::showAbout(void) |
| 1825 | { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1826 | static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n" |
Boris Barbulovski | b4ff1de | 2015-09-22 11:36:38 -0700 | [diff] [blame] | 1827 | "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n" |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1828 | "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | |
| 1830 | QMessageBox::information(this, "qconf", str); |
| 1831 | } |
| 1832 | |
| 1833 | void ConfigMainWindow::saveSettings(void) |
| 1834 | { |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1835 | configSettings->setValue("/window x", pos().x()); |
| 1836 | configSettings->setValue("/window y", pos().y()); |
| 1837 | configSettings->setValue("/window width", size().width()); |
| 1838 | configSettings->setValue("/window height", size().height()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
| 1840 | QString entry; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1841 | switch(configList->mode) { |
| 1842 | case singleMode : |
| 1843 | entry = "single"; |
| 1844 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1846 | case symbolMode : |
| 1847 | entry = "split"; |
| 1848 | break; |
| 1849 | |
| 1850 | case fullMode : |
| 1851 | entry = "full"; |
| 1852 | break; |
| 1853 | |
| 1854 | default: |
| 1855 | break; |
| 1856 | } |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1857 | configSettings->setValue("/listMode", entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1859 | configSettings->writeSizes("/split1", split1->sizes()); |
| 1860 | configSettings->writeSizes("/split2", split2->sizes()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1863 | void ConfigMainWindow::conf_changed(void) |
| 1864 | { |
| 1865 | if (saveAction) |
| 1866 | saveAction->setEnabled(conf_get_changed()); |
| 1867 | } |
| 1868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | void fixup_rootmenu(struct menu *menu) |
| 1870 | { |
| 1871 | struct menu *child; |
| 1872 | static int menu_cnt = 0; |
| 1873 | |
| 1874 | menu->flags |= MENU_ROOT; |
| 1875 | for (child = menu->list; child; child = child->next) { |
| 1876 | if (child->prompt && child->prompt->type == P_MENU) { |
| 1877 | menu_cnt++; |
| 1878 | fixup_rootmenu(child); |
| 1879 | menu_cnt--; |
| 1880 | } else if (!menu_cnt) |
| 1881 | fixup_rootmenu(child); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | static const char *progname; |
| 1886 | |
| 1887 | static void usage(void) |
| 1888 | { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1889 | printf("%s [-s] <config>\n", progname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | exit(0); |
| 1891 | } |
| 1892 | |
| 1893 | int main(int ac, char** av) |
| 1894 | { |
| 1895 | ConfigMainWindow* v; |
| 1896 | const char *name; |
| 1897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | progname = av[0]; |
| 1899 | configApp = new QApplication(ac, av); |
| 1900 | if (ac > 1 && av[1][0] == '-') { |
| 1901 | switch (av[1][1]) { |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 1902 | case 's': |
| 1903 | conf_set_message_callback(NULL); |
| 1904 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | case 'h': |
| 1906 | case '?': |
| 1907 | usage(); |
| 1908 | } |
| 1909 | name = av[2]; |
| 1910 | } else |
| 1911 | name = av[1]; |
| 1912 | if (!name) |
| 1913 | usage(); |
| 1914 | |
| 1915 | conf_parse(name); |
| 1916 | fixup_rootmenu(&rootmenu); |
| 1917 | conf_read(NULL); |
| 1918 | //zconfdump(stdout); |
| 1919 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1920 | configSettings = new ConfigSettings(); |
| 1921 | configSettings->beginGroup("/kconfig/qconf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | v = new ConfigMainWindow(); |
| 1923 | |
| 1924 | //zconfdump(stdout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); |
| 1926 | configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1927 | v->show(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | configApp->exec(); |
| 1929 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1930 | configSettings->endGroup(); |
| 1931 | delete configSettings; |
Chris Bainbridge | 5b61c7b | 2016-01-08 20:44:04 +0000 | [diff] [blame] | 1932 | delete v; |
| 1933 | delete configApp; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | return 0; |
| 1936 | } |