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