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 | |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 310 | ConfigList::ConfigList(QWidget *parent, const char *name) |
| 311 | : QTreeWidget(parent), |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 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 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 968 | void ConfigList::setAllOpen(bool open) |
| 969 | { |
| 970 | QTreeWidgetItemIterator it(this); |
| 971 | |
| 972 | while (*it) { |
| 973 | (*it)->setExpanded(open); |
| 974 | |
| 975 | ++it; |
| 976 | } |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 979 | ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 980 | : Parent(parent), sym(0), _menu(0) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 981 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 982 | setObjectName(name); |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 983 | setOpenLinks(false); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 984 | |
| 985 | if (!objectName().isEmpty()) { |
| 986 | configSettings->beginGroup(objectName()); |
Boris Barbulovski | e039303 | 2016-11-30 14:57:52 -0800 | [diff] [blame] | 987 | setShowDebug(configSettings->value("/showDebug", false).toBool()); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 988 | configSettings->endGroup(); |
| 989 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); |
| 990 | } |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 991 | |
| 992 | contextMenu = createStandardContextMenu(); |
| 993 | QAction *action = new QAction("Show Debug Info", contextMenu); |
| 994 | |
| 995 | action->setCheckable(true); |
| 996 | connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); |
| 997 | connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setChecked(bool))); |
| 998 | action->setChecked(showDebug()); |
| 999 | contextMenu->addSeparator(); |
| 1000 | contextMenu->addAction(action); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | void ConfigInfoView::saveSettings(void) |
| 1004 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1005 | if (!objectName().isEmpty()) { |
| 1006 | configSettings->beginGroup(objectName()); |
| 1007 | configSettings->setValue("/showDebug", showDebug()); |
| 1008 | configSettings->endGroup(); |
| 1009 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | void ConfigInfoView::setShowDebug(bool b) |
| 1013 | { |
| 1014 | if (_showDebug != b) { |
| 1015 | _showDebug = b; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1016 | if (_menu) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1017 | menuInfo(); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1018 | else if (sym) |
| 1019 | symbolInfo(); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1020 | emit showDebugChanged(b); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | void ConfigInfoView::setInfo(struct menu *m) |
| 1025 | { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1026 | if (_menu == m) |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1027 | return; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1028 | _menu = m; |
Roman Zippel | 6fa1da8 | 2007-01-10 23:15:31 -0800 | [diff] [blame] | 1029 | sym = NULL; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1030 | if (!_menu) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1031 | clear(); |
Roman Zippel | 6fa1da8 | 2007-01-10 23:15:31 -0800 | [diff] [blame] | 1032 | else |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1033 | menuInfo(); |
| 1034 | } |
| 1035 | |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1036 | void ConfigInfoView::symbolInfo(void) |
| 1037 | { |
| 1038 | QString str; |
| 1039 | |
| 1040 | str += "<big>Symbol: <b>"; |
| 1041 | str += print_filter(sym->name); |
| 1042 | str += "</b></big><br><br>value: "; |
| 1043 | str += print_filter(sym_get_string_value(sym)); |
| 1044 | str += "<br>visibility: "; |
| 1045 | str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n"; |
| 1046 | str += "<br>"; |
| 1047 | str += debug_info(sym); |
| 1048 | |
| 1049 | setText(str); |
| 1050 | } |
| 1051 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1052 | void ConfigInfoView::menuInfo(void) |
| 1053 | { |
| 1054 | struct symbol* sym; |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1055 | QString info; |
| 1056 | QTextStream stream(&info); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1057 | |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1058 | sym = _menu->sym; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1059 | if (sym) { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1060 | if (_menu->prompt) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1061 | stream << "<big><b>"; |
| 1062 | stream << print_filter(_menu->prompt->text); |
| 1063 | stream << "</b></big>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1064 | if (sym->name) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1065 | stream << " ("; |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1066 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1067 | stream << "<a href=\"s" << sym->name << "\">"; |
| 1068 | stream << print_filter(sym->name); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1069 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1070 | stream << "</a>"; |
| 1071 | stream << ")"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } else if (sym->name) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1074 | stream << "<big><b>"; |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1075 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1076 | stream << "<a href=\"s" << sym->name << "\">"; |
| 1077 | stream << print_filter(sym->name); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1078 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1079 | stream << "</a>"; |
| 1080 | stream << "</b></big>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1081 | } |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1082 | stream << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1083 | |
| 1084 | if (showDebug()) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1085 | stream << debug_info(sym); |
| 1086 | |
Masahiro Yamada | a46afd1 | 2020-09-14 23:59:48 +0900 | [diff] [blame] | 1087 | struct gstr help_gstr = str_new(); |
| 1088 | |
| 1089 | menu_get_ext_help(_menu, &help_gstr); |
| 1090 | stream << print_filter(str_get(&help_gstr)); |
| 1091 | str_free(&help_gstr); |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1092 | } else if (_menu->prompt) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1093 | stream << "<big><b>"; |
| 1094 | stream << print_filter(_menu->prompt->text); |
| 1095 | stream << "</b></big><br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1096 | if (showDebug()) { |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 1097 | if (_menu->prompt->visible.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1098 | stream << " dep: "; |
| 1099 | expr_print(_menu->prompt->visible.expr, |
| 1100 | expr_print_help, &stream, E_NONE); |
| 1101 | stream << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1102 | } |
Masahiro Yamada | a46afd1 | 2020-09-14 23:59:48 +0900 | [diff] [blame] | 1103 | |
| 1104 | stream << "defined at " << _menu->file->name << ":" |
| 1105 | << _menu->lineno << "<br><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1108 | |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1109 | setText(info); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | QString ConfigInfoView::debug_info(struct symbol *sym) |
| 1113 | { |
| 1114 | QString debug; |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1115 | QTextStream stream(&debug); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1116 | |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1117 | stream << "type: "; |
| 1118 | stream << print_filter(sym_type_name(sym->type)); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1119 | if (sym_is_choice(sym)) |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1120 | stream << " (choice)"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1121 | debug += "<br>"; |
| 1122 | if (sym->rev_dep.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1123 | stream << "reverse dep: "; |
| 1124 | expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE); |
| 1125 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1126 | } |
| 1127 | for (struct property *prop = sym->prop; prop; prop = prop->next) { |
| 1128 | switch (prop->type) { |
| 1129 | case P_PROMPT: |
| 1130 | case P_MENU: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1131 | stream << "prompt: <a href=\"m" << sym->name << "\">"; |
| 1132 | stream << print_filter(prop->text); |
| 1133 | stream << "</a><br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1134 | break; |
| 1135 | case P_DEFAULT: |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1136 | case P_SELECT: |
| 1137 | case P_RANGE: |
Mauro Carvalho Chehab | 8f8499a | 2020-06-30 08:48:53 +0200 | [diff] [blame] | 1138 | case P_COMMENT: |
| 1139 | case P_IMPLY: |
| 1140 | case P_SYMBOL: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1141 | stream << prop_get_type_name(prop->type); |
| 1142 | stream << ": "; |
| 1143 | expr_print(prop->expr, expr_print_help, |
| 1144 | &stream, E_NONE); |
| 1145 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1146 | break; |
| 1147 | case P_CHOICE: |
| 1148 | if (sym_is_choice(sym)) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1149 | stream << "choice: "; |
| 1150 | expr_print(prop->expr, expr_print_help, |
| 1151 | &stream, E_NONE); |
| 1152 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1153 | } |
| 1154 | break; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1155 | default: |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1156 | stream << "unknown property: "; |
| 1157 | stream << prop_get_type_name(prop->type); |
| 1158 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1159 | } |
| 1160 | if (prop->visible.expr) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1161 | stream << " dep: "; |
| 1162 | expr_print(prop->visible.expr, expr_print_help, |
| 1163 | &stream, E_NONE); |
| 1164 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1165 | } |
| 1166 | } |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1167 | stream << "<br>"; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1168 | |
| 1169 | return debug; |
| 1170 | } |
| 1171 | |
| 1172 | QString ConfigInfoView::print_filter(const QString &str) |
| 1173 | { |
| 1174 | QRegExp re("[<>&\"\\n]"); |
| 1175 | QString res = str; |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1176 | for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { |
| 1177 | switch (res[i].toLatin1()) { |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1178 | case '<': |
| 1179 | res.replace(i, 1, "<"); |
| 1180 | i += 4; |
| 1181 | break; |
| 1182 | case '>': |
| 1183 | res.replace(i, 1, ">"); |
| 1184 | i += 4; |
| 1185 | break; |
| 1186 | case '&': |
| 1187 | res.replace(i, 1, "&"); |
| 1188 | i += 5; |
| 1189 | break; |
| 1190 | case '"': |
| 1191 | res.replace(i, 1, """); |
| 1192 | i += 6; |
| 1193 | break; |
| 1194 | case '\n': |
| 1195 | res.replace(i, 1, "<br>"); |
| 1196 | i += 4; |
| 1197 | break; |
| 1198 | } |
| 1199 | } |
| 1200 | return res; |
| 1201 | } |
| 1202 | |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1203 | 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] | 1204 | { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1205 | QTextStream *stream = reinterpret_cast<QTextStream *>(data); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1206 | |
| 1207 | if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { |
Masahiro Yamada | 510bc3cb | 2020-08-21 02:43:28 +0900 | [diff] [blame] | 1208 | *stream << "<a href=\"s" << sym->name << "\">"; |
| 1209 | *stream << print_filter(str); |
| 1210 | *stream << "</a>"; |
| 1211 | } else { |
| 1212 | *stream << print_filter(str); |
| 1213 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1216 | void ConfigInfoView::clicked(const QUrl &url) |
| 1217 | { |
| 1218 | QByteArray str = url.toEncoded(); |
| 1219 | const std::size_t count = str.size(); |
| 1220 | char *data = new char[count + 1]; |
| 1221 | struct symbol **result; |
| 1222 | struct menu *m = NULL; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1223 | |
| 1224 | if (count < 1) { |
Masahiro Yamada | c9b09a92 | 2020-07-30 02:02:39 +0900 | [diff] [blame] | 1225 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1226 | return; |
| 1227 | } |
| 1228 | |
| 1229 | memcpy(data, str.constData(), count); |
| 1230 | data[count] = '\0'; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1231 | |
| 1232 | /* Seek for exact match */ |
| 1233 | data[0] = '^'; |
| 1234 | strcat(data, "$"); |
| 1235 | result = sym_re_search(data); |
| 1236 | if (!result) { |
Masahiro Yamada | c9b09a92 | 2020-07-30 02:02:39 +0900 | [diff] [blame] | 1237 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | sym = *result; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1242 | |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1243 | /* Seek for the menu which holds the symbol */ |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1244 | for (struct property *prop = sym->prop; prop; prop = prop->next) { |
| 1245 | if (prop->type != P_PROMPT && prop->type != P_MENU) |
| 1246 | continue; |
| 1247 | m = prop->menu; |
| 1248 | break; |
| 1249 | } |
| 1250 | |
| 1251 | if (!m) { |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1252 | /* Symbol is not visible as a menu */ |
| 1253 | symbolInfo(); |
| 1254 | emit showDebugChanged(true); |
| 1255 | } else { |
| 1256 | emit menuSelected(m); |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1259 | free(result); |
Masahiro Yamada | a608b6a | 2020-09-09 07:16:37 +0900 | [diff] [blame] | 1260 | delete[] data; |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 1263 | void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event) |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1264 | { |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 1265 | contextMenu->popup(event->globalPos()); |
| 1266 | event->accept(); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1269 | ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent) |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1270 | : Parent(parent), result(NULL) |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1271 | { |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1272 | setObjectName("search"); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1273 | setWindowTitle("Search Config"); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1274 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1275 | QVBoxLayout* layout1 = new QVBoxLayout(this); |
| 1276 | layout1->setContentsMargins(11, 11, 11, 11); |
| 1277 | layout1->setSpacing(6); |
Masahiro Yamada | 9264115 | 2020-08-07 18:18:58 +0900 | [diff] [blame] | 1278 | |
| 1279 | QHBoxLayout* layout2 = new QHBoxLayout(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1280 | layout2->setContentsMargins(0, 0, 0, 0); |
| 1281 | layout2->setSpacing(6); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1282 | layout2->addWidget(new QLabel("Find:", this)); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1283 | editField = new QLineEdit(this); |
| 1284 | connect(editField, SIGNAL(returnPressed()), SLOT(search())); |
| 1285 | layout2->addWidget(editField); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1286 | searchButton = new QPushButton("Search", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1287 | searchButton->setAutoDefault(false); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1288 | connect(searchButton, SIGNAL(clicked()), SLOT(search())); |
| 1289 | layout2->addWidget(searchButton); |
| 1290 | layout1->addLayout(layout2); |
| 1291 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1292 | split = new QSplitter(this); |
Markus Heidelberg | 7298b93 | 2009-05-18 01:36:50 +0200 | [diff] [blame] | 1293 | split->setOrientation(Qt::Vertical); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1294 | list = new ConfigList(split, "search"); |
| 1295 | list->mode = listMode; |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1296 | info = new ConfigInfoView(split, "search"); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1297 | connect(list, SIGNAL(menuChanged(struct menu *)), |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1298 | info, SLOT(setInfo(struct menu *))); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1299 | connect(list, SIGNAL(menuChanged(struct menu *)), |
Marco Costalba | 63431e7 | 2006-10-05 19:12:59 +0200 | [diff] [blame] | 1300 | parent, SLOT(setMenuLink(struct menu *))); |
| 1301 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1302 | layout1->addWidget(split); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1303 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1304 | QVariant x, y; |
| 1305 | int width, height; |
| 1306 | bool ok; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1307 | |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1308 | configSettings->beginGroup("search"); |
| 1309 | width = configSettings->value("/window width", parent->width() / 2).toInt(); |
| 1310 | height = configSettings->value("/window height", parent->height() / 2).toInt(); |
| 1311 | resize(width, height); |
| 1312 | x = configSettings->value("/window x"); |
| 1313 | y = configSettings->value("/window y"); |
| 1314 | if (x.isValid() && y.isValid()) |
| 1315 | move(x.toInt(), y.toInt()); |
| 1316 | QList<int> sizes = configSettings->readSizes("/split", &ok); |
| 1317 | if (ok) |
| 1318 | split->setSizes(sizes); |
| 1319 | configSettings->endGroup(); |
| 1320 | connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | void ConfigSearchWindow::saveSettings(void) |
| 1324 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1325 | if (!objectName().isEmpty()) { |
| 1326 | configSettings->beginGroup(objectName()); |
| 1327 | configSettings->setValue("/window x", pos().x()); |
| 1328 | configSettings->setValue("/window y", pos().y()); |
| 1329 | configSettings->setValue("/window width", size().width()); |
| 1330 | configSettings->setValue("/window height", size().height()); |
| 1331 | configSettings->writeSizes("/split", split->sizes()); |
| 1332 | configSettings->endGroup(); |
| 1333 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | void ConfigSearchWindow::search(void) |
| 1337 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1338 | struct symbol **p; |
| 1339 | struct property *prop; |
| 1340 | ConfigItem *lastItem = NULL; |
| 1341 | |
| 1342 | free(result); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1343 | list->clear(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1344 | info->clear(); |
| 1345 | |
| 1346 | result = sym_re_search(editField->text().toLatin1()); |
| 1347 | if (!result) |
| 1348 | return; |
| 1349 | for (p = result; *p; p++) { |
| 1350 | for_all_prompts((*p), prop) |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1351 | lastItem = new ConfigItem(list, lastItem, prop->menu, |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1352 | menu_is_visible(prop->menu)); |
| 1353 | } |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | /* |
| 1357 | * Construct the complete config widget |
| 1358 | */ |
| 1359 | ConfigMainWindow::ConfigMainWindow(void) |
Roman Zippel | f12aa70 | 2006-11-25 11:09:31 -0800 | [diff] [blame] | 1360 | : searchWindow(0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | { |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1362 | bool ok = true; |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1363 | QVariant x, y; |
| 1364 | int width, height; |
Randy Dunlap | a54bb70 | 2007-10-20 11:18:47 -0700 | [diff] [blame] | 1365 | char title[256]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
Markus Heidelberg | 8d90c97 | 2009-05-18 01:36:52 +0200 | [diff] [blame] | 1367 | QDesktopWidget *d = configApp->desktop(); |
Arnaud Lacombe | 0954828 | 2010-08-18 01:57:13 -0400 | [diff] [blame] | 1368 | snprintf(title, sizeof(title), "%s%s", |
| 1369 | rootmenu.prompt->text, |
Michal Marek | 76a136c | 2010-09-01 17:39:27 +0200 | [diff] [blame] | 1370 | "" |
Michal Marek | 76a136c | 2010-09-01 17:39:27 +0200 | [diff] [blame] | 1371 | ); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1372 | setWindowTitle(title); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1374 | width = configSettings->value("/window width", d->width() - 64).toInt(); |
| 1375 | height = configSettings->value("/window height", d->height() - 64).toInt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | resize(width, height); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1377 | x = configSettings->value("/window x"); |
| 1378 | y = configSettings->value("/window y"); |
| 1379 | if ((x.isValid())&&(y.isValid())) |
| 1380 | move(x.toInt(), y.toInt()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 1382 | // set up icons |
| 1383 | ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes)); |
| 1384 | ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod)); |
| 1385 | ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no)); |
| 1386 | ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes)); |
| 1387 | ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no)); |
| 1388 | ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu)); |
| 1389 | ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback)); |
| 1390 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1391 | QWidget *widget = new QWidget(this); |
| 1392 | QVBoxLayout *layout = new QVBoxLayout(widget); |
| 1393 | setCentralWidget(widget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1395 | split1 = new QSplitter(widget); |
| 1396 | split1->setOrientation(Qt::Horizontal); |
| 1397 | split1->setChildrenCollapsible(false); |
| 1398 | |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1399 | menuList = new ConfigList(widget, "menu"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1401 | split2 = new QSplitter(widget); |
| 1402 | split2->setChildrenCollapsible(false); |
Markus Heidelberg | 7298b93 | 2009-05-18 01:36:50 +0200 | [diff] [blame] | 1403 | split2->setOrientation(Qt::Vertical); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
| 1405 | // create config tree |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1406 | configList = new ConfigList(widget, "config"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1408 | helpText = new ConfigInfoView(widget, "help"); |
| 1409 | |
| 1410 | layout->addWidget(split2); |
| 1411 | split2->addWidget(split1); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1412 | split1->addWidget(configList); |
| 1413 | split1->addWidget(menuList); |
Mauro Carvalho Chehab | cce1fab | 2020-04-02 11:28:00 +0200 | [diff] [blame] | 1414 | split2->addWidget(helpText); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
| 1416 | setTabOrder(configList, helpText); |
| 1417 | configList->setFocus(); |
| 1418 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1419 | backAction = new QAction(QPixmap(xpm_back), "Back", this); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1420 | connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack())); |
| 1421 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1422 | QAction *quitAction = new QAction("&Quit", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1423 | quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1424 | connect(quitAction, SIGNAL(triggered(bool)), SLOT(close())); |
| 1425 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1426 | QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1427 | loadAction->setShortcut(Qt::CTRL + Qt::Key_L); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1428 | connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig())); |
| 1429 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1430 | saveAction = new QAction(QPixmap(xpm_save), "&Save", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1431 | saveAction->setShortcut(Qt::CTRL + Qt::Key_S); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1432 | connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig())); |
| 1433 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1434 | conf_set_changed_callback(conf_changed); |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1435 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1436 | // Set saveAction's initial state |
| 1437 | conf_changed(); |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1438 | configname = xstrdup(conf_get_configname()); |
| 1439 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1440 | QAction *saveAsAction = new QAction("Save &As...", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1441 | connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1442 | QAction *searchAction = new QAction("&Find", this); |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 1443 | searchAction->setShortcut(Qt::CTRL + Qt::Key_F); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1444 | connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1445 | singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1446 | singleViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1447 | connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1448 | splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1449 | splitViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1450 | connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1451 | fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1452 | fullViewAction->setCheckable(true); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1453 | connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1455 | QAction *showNameAction = new QAction("Show Name", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1456 | showNameAction->setCheckable(true); |
Masahiro Yamada | 7930dd9 | 2020-08-29 17:14:14 +0900 | [diff] [blame] | 1457 | connect(showNameAction, SIGNAL(toggled(bool)), configList, SLOT(setShowName(bool))); |
| 1458 | showNameAction->setChecked(configList->showName); |
| 1459 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1460 | QAction *showRangeAction = new QAction("Show Range", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1461 | showRangeAction->setCheckable(true); |
Masahiro Yamada | 7930dd9 | 2020-08-29 17:14:14 +0900 | [diff] [blame] | 1462 | connect(showRangeAction, SIGNAL(toggled(bool)), configList, SLOT(setShowRange(bool))); |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1463 | |
| 1464 | QActionGroup *optGroup = new QActionGroup(this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1465 | optGroup->setExclusive(true); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1466 | connect(optGroup, SIGNAL(triggered(QAction*)), configList, |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1467 | SLOT(setOptionMode(QAction *))); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1468 | connect(optGroup, SIGNAL(triggered(QAction *)), menuList, |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1469 | SLOT(setOptionMode(QAction *))); |
| 1470 | |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 1471 | ConfigList::showNormalAction = new QAction("Show Normal Options", optGroup); |
| 1472 | ConfigList::showNormalAction->setCheckable(true); |
| 1473 | ConfigList::showAllAction = new QAction("Show All Options", optGroup); |
| 1474 | ConfigList::showAllAction->setCheckable(true); |
| 1475 | ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup); |
| 1476 | ConfigList::showPromptAction->setCheckable(true); |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 1477 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1478 | QAction *showDebugAction = new QAction("Show Debug Info", this); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1479 | showDebugAction->setCheckable(true); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1480 | connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); |
Boris Barbulovski | 9c86235 | 2015-09-22 11:36:12 -0700 | [diff] [blame] | 1481 | showDebugAction->setChecked(helpText->showDebug()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1483 | QAction *showIntroAction = new QAction("Introduction", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1484 | connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro())); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1485 | QAction *showAboutAction = new QAction("About", this); |
Boris Barbulovski | 9211993 | 2015-09-22 11:36:16 -0700 | [diff] [blame] | 1486 | connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
| 1488 | // init tool bar |
Masahiro Yamada | 860ec3f | 2020-08-07 18:18:55 +0900 | [diff] [blame] | 1489 | QToolBar *toolBar = addToolBar("Tools"); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1490 | toolBar->addAction(backAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | toolBar->addSeparator(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1492 | toolBar->addAction(loadAction); |
| 1493 | toolBar->addAction(saveAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | toolBar->addSeparator(); |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1495 | toolBar->addAction(singleViewAction); |
| 1496 | toolBar->addAction(splitViewAction); |
| 1497 | toolBar->addAction(fullViewAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1499 | // create file menu |
| 1500 | QMenu *menu = menuBar()->addMenu("&File"); |
| 1501 | menu->addAction(loadAction); |
| 1502 | menu->addAction(saveAction); |
| 1503 | menu->addAction(saveAsAction); |
| 1504 | menu->addSeparator(); |
| 1505 | menu->addAction(quitAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
Shlomi Fish | 66e7c72 | 2007-02-14 00:32:58 -0800 | [diff] [blame] | 1507 | // create edit menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1508 | menu = menuBar()->addMenu("&Edit"); |
| 1509 | menu->addAction(searchAction); |
Shlomi Fish | 66e7c72 | 2007-02-14 00:32:58 -0800 | [diff] [blame] | 1510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | // create options menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1512 | menu = menuBar()->addMenu("&Option"); |
| 1513 | menu->addAction(showNameAction); |
| 1514 | menu->addAction(showRangeAction); |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1515 | menu->addSeparator(); |
| 1516 | menu->addActions(optGroup->actions()); |
| 1517 | menu->addSeparator(); |
| 1518 | menu->addAction(showDebugAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
| 1520 | // create help menu |
Masahiro Yamada | 93ebaac | 2020-08-07 18:18:53 +0900 | [diff] [blame] | 1521 | menu = menuBar()->addMenu("&Help"); |
| 1522 | menu->addAction(showIntroAction); |
| 1523 | menu->addAction(showAboutAction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 1525 | connect (helpText, SIGNAL (anchorClicked (const QUrl &)), |
| 1526 | helpText, SLOT (clicked (const QUrl &)) ); |
| 1527 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1528 | connect(configList, SIGNAL(menuChanged(struct menu *)), |
| 1529 | helpText, SLOT(setInfo(struct menu *))); |
| 1530 | connect(configList, SIGNAL(menuSelected(struct menu *)), |
| 1531 | SLOT(changeMenu(struct menu *))); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1532 | connect(configList, SIGNAL(itemSelected(struct menu *)), |
| 1533 | SLOT(changeItens(struct menu *))); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1534 | connect(configList, SIGNAL(parentSelected()), |
| 1535 | SLOT(goBack())); |
| 1536 | connect(menuList, SIGNAL(menuChanged(struct menu *)), |
| 1537 | helpText, SLOT(setInfo(struct menu *))); |
| 1538 | connect(menuList, SIGNAL(menuSelected(struct menu *)), |
| 1539 | SLOT(changeMenu(struct menu *))); |
| 1540 | |
| 1541 | connect(configList, SIGNAL(gotFocus(struct menu *)), |
| 1542 | helpText, SLOT(setInfo(struct menu *))); |
| 1543 | connect(menuList, SIGNAL(gotFocus(struct menu *)), |
| 1544 | helpText, SLOT(setInfo(struct menu *))); |
| 1545 | connect(menuList, SIGNAL(gotFocus(struct menu *)), |
| 1546 | SLOT(listFocusChanged(void))); |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1547 | connect(helpText, SIGNAL(menuSelected(struct menu *)), |
| 1548 | SLOT(setMenuLink(struct menu *))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1550 | QString listMode = configSettings->value("/listMode", "symbol").toString(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | if (listMode == "single") |
| 1552 | showSingleView(); |
| 1553 | else if (listMode == "full") |
| 1554 | showFullView(); |
| 1555 | else /*if (listMode == "split")*/ |
| 1556 | showSplitView(); |
| 1557 | |
| 1558 | // UI setup done, restore splitter positions |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 1559 | QList<int> sizes = configSettings->readSizes("/split1", &ok); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | if (ok) |
| 1561 | split1->setSizes(sizes); |
| 1562 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1563 | sizes = configSettings->readSizes("/split2", &ok); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | if (ok) |
| 1565 | split2->setSizes(sizes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | void ConfigMainWindow::loadConfig(void) |
| 1569 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1570 | QString str; |
| 1571 | QByteArray ba; |
| 1572 | const char *name; |
| 1573 | |
| 1574 | str = QFileDialog::getOpenFileName(this, "", configname); |
| 1575 | if (str.isNull()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | return; |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1577 | |
| 1578 | ba = str.toLocal8Bit(); |
| 1579 | name = ba.data(); |
| 1580 | |
| 1581 | if (conf_read(name)) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1582 | QMessageBox::information(this, "qconf", "Unable to load configuration!"); |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1583 | |
| 1584 | free(configname); |
| 1585 | configname = xstrdup(name); |
| 1586 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 1587 | ConfigList::updateListAllForAll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1590 | bool ConfigMainWindow::saveConfig(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1592 | if (conf_write(configname)) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1593 | QMessageBox::information(this, "qconf", "Unable to save configuration!"); |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1594 | return false; |
| 1595 | } |
Masahiro Yamada | 00c864f | 2018-07-20 16:46:31 +0900 | [diff] [blame] | 1596 | conf_write_autoconf(0); |
| 1597 | |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1598 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void ConfigMainWindow::saveConfigAs(void) |
| 1602 | { |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1603 | QString str; |
| 1604 | QByteArray ba; |
| 1605 | const char *name; |
| 1606 | |
| 1607 | str = QFileDialog::getSaveFileName(this, "", configname); |
| 1608 | if (str.isNull()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | return; |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 1610 | |
| 1611 | ba = str.toLocal8Bit(); |
| 1612 | name = ba.data(); |
| 1613 | |
| 1614 | if (conf_write(name)) { |
| 1615 | QMessageBox::information(this, "qconf", "Unable to save configuration!"); |
| 1616 | } |
| 1617 | conf_write_autoconf(0); |
| 1618 | |
| 1619 | free(configname); |
| 1620 | configname = xstrdup(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1623 | void ConfigMainWindow::searchConfig(void) |
| 1624 | { |
| 1625 | if (!searchWindow) |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 1626 | searchWindow = new ConfigSearchWindow(this); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1627 | searchWindow->show(); |
| 1628 | } |
| 1629 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1630 | void ConfigMainWindow::changeItens(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1632 | configList->setRootMenu(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1635 | void ConfigMainWindow::changeMenu(struct menu *menu) |
| 1636 | { |
| 1637 | menuList->setRootMenu(menu); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1640 | void ConfigMainWindow::setMenuLink(struct menu *menu) |
| 1641 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1642 | struct menu *parent; |
| 1643 | ConfigList* list = NULL; |
| 1644 | ConfigItem* item; |
| 1645 | |
| 1646 | if (configList->menuSkip(menu)) |
| 1647 | return; |
| 1648 | |
| 1649 | switch (configList->mode) { |
| 1650 | case singleMode: |
| 1651 | list = configList; |
| 1652 | parent = menu_get_parent_menu(menu); |
| 1653 | if (!parent) |
| 1654 | return; |
| 1655 | list->setRootMenu(parent); |
| 1656 | break; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1657 | case menuMode: |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1658 | if (menu->flags & MENU_ROOT) { |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1659 | menuList->setRootMenu(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1660 | configList->clearSelection(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1661 | list = configList; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1662 | } else { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1663 | parent = menu_get_parent_menu(menu->parent); |
| 1664 | if (!parent) |
| 1665 | return; |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1666 | |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1667 | /* Select the config view */ |
| 1668 | item = configList->findConfigItem(parent); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1669 | if (item) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 1670 | configList->setSelected(item, true); |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1671 | configList->scrollToItem(item); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1672 | } |
Mauro Carvalho Chehab | c699eaa | 2020-06-30 08:26:36 +0200 | [diff] [blame] | 1673 | |
| 1674 | menuList->setRootMenu(parent); |
| 1675 | menuList->clearSelection(); |
| 1676 | list = menuList; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1677 | } |
| 1678 | break; |
| 1679 | case fullMode: |
| 1680 | list = configList; |
| 1681 | break; |
| 1682 | default: |
| 1683 | break; |
| 1684 | } |
| 1685 | |
| 1686 | if (list) { |
| 1687 | item = list->findConfigItem(menu); |
| 1688 | if (item) { |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 1689 | list->setSelected(item, true); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1690 | list->scrollToItem(item); |
| 1691 | list->setFocus(); |
Mauro Carvalho Chehab | 8a3b6e5 | 2020-06-30 08:48:35 +0200 | [diff] [blame] | 1692 | helpText->setInfo(menu); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1693 | } |
| 1694 | } |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | void ConfigMainWindow::listFocusChanged(void) |
| 1698 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1699 | if (menuList->mode == menuMode) |
| 1700 | configList->clearSelection(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void ConfigMainWindow::goBack(void) |
| 1704 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1705 | if (configList->rootEntry == &rootmenu) |
Boris Barbulovski | be596aa | 2015-09-22 11:36:28 -0700 | [diff] [blame] | 1706 | return; |
| 1707 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1708 | configList->setParentMenu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | void ConfigMainWindow::showSingleView(void) |
| 1712 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1713 | singleViewAction->setEnabled(false); |
| 1714 | singleViewAction->setChecked(true); |
| 1715 | splitViewAction->setEnabled(true); |
| 1716 | splitViewAction->setChecked(false); |
| 1717 | fullViewAction->setEnabled(true); |
| 1718 | fullViewAction->setChecked(false); |
| 1719 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1720 | backAction->setEnabled(true); |
| 1721 | |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1722 | menuList->hide(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1723 | menuList->setRootMenu(0); |
| 1724 | configList->mode = singleMode; |
| 1725 | if (configList->rootEntry == &rootmenu) |
| 1726 | configList->updateListAll(); |
| 1727 | else |
| 1728 | configList->setRootMenu(&rootmenu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | configList->setFocus(); |
| 1730 | } |
| 1731 | |
| 1732 | void ConfigMainWindow::showSplitView(void) |
| 1733 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1734 | singleViewAction->setEnabled(true); |
| 1735 | singleViewAction->setChecked(false); |
| 1736 | splitViewAction->setEnabled(false); |
| 1737 | splitViewAction->setChecked(true); |
| 1738 | fullViewAction->setEnabled(true); |
| 1739 | fullViewAction->setChecked(false); |
| 1740 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1741 | backAction->setEnabled(false); |
| 1742 | |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1743 | configList->mode = menuMode; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1744 | if (configList->rootEntry == &rootmenu) |
| 1745 | configList->updateListAll(); |
| 1746 | else |
| 1747 | configList->setRootMenu(&rootmenu); |
| 1748 | configList->setAllOpen(true); |
| 1749 | configApp->processEvents(); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 1750 | menuList->mode = symbolMode; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1751 | menuList->setRootMenu(&rootmenu); |
| 1752 | menuList->setAllOpen(true); |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1753 | menuList->show(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | menuList->setFocus(); |
| 1755 | } |
| 1756 | |
| 1757 | void ConfigMainWindow::showFullView(void) |
| 1758 | { |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 1759 | singleViewAction->setEnabled(true); |
| 1760 | singleViewAction->setChecked(false); |
| 1761 | splitViewAction->setEnabled(true); |
| 1762 | splitViewAction->setChecked(false); |
| 1763 | fullViewAction->setEnabled(false); |
| 1764 | fullViewAction->setChecked(true); |
| 1765 | |
Mauro Carvalho Chehab | af737b4d | 2020-06-30 08:26:39 +0200 | [diff] [blame] | 1766 | backAction->setEnabled(false); |
| 1767 | |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame^] | 1768 | menuList->hide(); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1769 | menuList->setRootMenu(0); |
| 1770 | configList->mode = fullMode; |
| 1771 | if (configList->rootEntry == &rootmenu) |
| 1772 | configList->updateListAll(); |
| 1773 | else |
| 1774 | configList->setRootMenu(&rootmenu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | configList->setFocus(); |
| 1776 | } |
| 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | /* |
| 1779 | * ask for saving configuration before quitting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | */ |
| 1781 | void ConfigMainWindow::closeEvent(QCloseEvent* e) |
| 1782 | { |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 1783 | if (!conf_get_changed()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | e->accept(); |
| 1785 | return; |
| 1786 | } |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1787 | QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1789 | mb.setButtonText(QMessageBox::Yes, "&Save Changes"); |
| 1790 | mb.setButtonText(QMessageBox::No, "&Discard Changes"); |
| 1791 | mb.setButtonText(QMessageBox::Cancel, "Cancel Exit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | switch (mb.exec()) { |
| 1793 | case QMessageBox::Yes: |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 1794 | if (saveConfig()) |
| 1795 | e->accept(); |
| 1796 | else |
| 1797 | e->ignore(); |
| 1798 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | case QMessageBox::No: |
| 1800 | e->accept(); |
| 1801 | break; |
| 1802 | case QMessageBox::Cancel: |
| 1803 | e->ignore(); |
| 1804 | break; |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | void ConfigMainWindow::showIntro(void) |
| 1809 | { |
Masahiro Yamada | 8c30e7e | 2020-08-29 17:14:07 +0900 | [diff] [blame] | 1810 | static const QString str = |
| 1811 | "Welcome to the qconf graphical configuration tool.\n" |
| 1812 | "\n" |
Masahiro Yamada | 37162a6 | 2020-08-29 17:14:12 +0900 | [diff] [blame] | 1813 | "For bool and tristate options, a blank box indicates the " |
| 1814 | "feature is disabled, a check indicates it is enabled, and a " |
| 1815 | "dot indicates that it is to be compiled as a module. Clicking " |
| 1816 | "on the box will cycle through the three states. For int, hex, " |
| 1817 | "and string options, double-clicking or pressing F2 on the " |
| 1818 | "Value cell will allow you to edit the value.\n" |
Masahiro Yamada | 8c30e7e | 2020-08-29 17:14:07 +0900 | [diff] [blame] | 1819 | "\n" |
| 1820 | "If you do not see an option (e.g., a device driver) that you " |
| 1821 | "believe should be present, try turning on Show All Options " |
Masahiro Yamada | 1fb7524 | 2020-08-29 17:14:08 +0900 | [diff] [blame] | 1822 | "under the Options menu. Enabling Show Debug Info will help you" |
| 1823 | "figure out what other options must be enabled to support the " |
| 1824 | "option you are interested in, and hyperlinks will navigate to " |
| 1825 | "them.\n" |
Masahiro Yamada | 8c30e7e | 2020-08-29 17:14:07 +0900 | [diff] [blame] | 1826 | "\n" |
| 1827 | "Toggling Show Debug Info under the Options menu will show the " |
| 1828 | "dependencies, which you can then match by examining other " |
| 1829 | "options.\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
| 1831 | QMessageBox::information(this, "qconf", str); |
| 1832 | } |
| 1833 | |
| 1834 | void ConfigMainWindow::showAbout(void) |
| 1835 | { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1836 | 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] | 1837 | "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n" |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1838 | "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] | 1839 | |
| 1840 | QMessageBox::information(this, "qconf", str); |
| 1841 | } |
| 1842 | |
| 1843 | void ConfigMainWindow::saveSettings(void) |
| 1844 | { |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1845 | configSettings->setValue("/window x", pos().x()); |
| 1846 | configSettings->setValue("/window y", pos().y()); |
| 1847 | configSettings->setValue("/window width", size().width()); |
| 1848 | configSettings->setValue("/window height", size().height()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
| 1850 | QString entry; |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1851 | switch(configList->mode) { |
| 1852 | case singleMode : |
| 1853 | entry = "single"; |
| 1854 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 1856 | case symbolMode : |
| 1857 | entry = "split"; |
| 1858 | break; |
| 1859 | |
| 1860 | case fullMode : |
| 1861 | entry = "full"; |
| 1862 | break; |
| 1863 | |
| 1864 | default: |
| 1865 | break; |
| 1866 | } |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 1867 | configSettings->setValue("/listMode", entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1869 | configSettings->writeSizes("/split1", split1->sizes()); |
| 1870 | configSettings->writeSizes("/split2", split2->sizes()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 1873 | void ConfigMainWindow::conf_changed(void) |
| 1874 | { |
| 1875 | if (saveAction) |
| 1876 | saveAction->setEnabled(conf_get_changed()); |
| 1877 | } |
| 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | void fixup_rootmenu(struct menu *menu) |
| 1880 | { |
| 1881 | struct menu *child; |
| 1882 | static int menu_cnt = 0; |
| 1883 | |
| 1884 | menu->flags |= MENU_ROOT; |
| 1885 | for (child = menu->list; child; child = child->next) { |
| 1886 | if (child->prompt && child->prompt->type == P_MENU) { |
| 1887 | menu_cnt++; |
| 1888 | fixup_rootmenu(child); |
| 1889 | menu_cnt--; |
| 1890 | } else if (!menu_cnt) |
| 1891 | fixup_rootmenu(child); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | static const char *progname; |
| 1896 | |
| 1897 | static void usage(void) |
| 1898 | { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 1899 | printf("%s [-s] <config>\n", progname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | exit(0); |
| 1901 | } |
| 1902 | |
| 1903 | int main(int ac, char** av) |
| 1904 | { |
| 1905 | ConfigMainWindow* v; |
| 1906 | const char *name; |
| 1907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | progname = av[0]; |
| 1909 | configApp = new QApplication(ac, av); |
| 1910 | if (ac > 1 && av[1][0] == '-') { |
| 1911 | switch (av[1][1]) { |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 1912 | case 's': |
| 1913 | conf_set_message_callback(NULL); |
| 1914 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | case 'h': |
| 1916 | case '?': |
| 1917 | usage(); |
| 1918 | } |
| 1919 | name = av[2]; |
| 1920 | } else |
| 1921 | name = av[1]; |
| 1922 | if (!name) |
| 1923 | usage(); |
| 1924 | |
| 1925 | conf_parse(name); |
| 1926 | fixup_rootmenu(&rootmenu); |
| 1927 | conf_read(NULL); |
| 1928 | //zconfdump(stdout); |
| 1929 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1930 | configSettings = new ConfigSettings(); |
| 1931 | configSettings->beginGroup("/kconfig/qconf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | v = new ConfigMainWindow(); |
| 1933 | |
| 1934 | //zconfdump(stdout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); |
| 1936 | configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 1937 | v->show(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | configApp->exec(); |
| 1939 | |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1940 | configSettings->endGroup(); |
| 1941 | delete configSettings; |
Chris Bainbridge | 5b61c7b | 2016-01-08 20:44:04 +0000 | [diff] [blame] | 1942 | delete v; |
| 1943 | delete configApp; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 1944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | return 0; |
| 1946 | } |