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