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