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