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