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