blob: d134a89bfdced88c53424c384b1323651add0fd4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
Alexander Stein133c5f72010-08-31 17:34:37 +02006#include <qglobal.h>
7
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07008#include <QMainWindow>
Boris Barbulovski041fbdc2015-09-22 11:36:05 -07009#include <QList>
Boris Barbulovski924bbb52015-09-22 11:36:06 -070010#include <qtextbrowser.h>
Boris Barbulovski85eaf282015-09-22 11:36:03 -070011#include <QAction>
Boris Barbulovskibea00772015-09-22 11:36:04 -070012#include <QFileDialog>
Boris Barbulovski76bede82015-09-22 11:36:07 -070013#include <QMenu>
Alexander Stein133c5f72010-08-31 17:34:37 +020014
15#include <qapplication.h>
Markus Heidelberg8d90c972009-05-18 01:36:52 +020016#include <qdesktopwidget.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <qtoolbar.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070018#include <qlayout.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <qsplitter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <qlineedit.h>
Roman Zippel43bf6122006-06-08 22:12:45 -070021#include <qlabel.h>
22#include <qpushbutton.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <qmenubar.h>
24#include <qmessagebox.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <qregexp.h>
Alexander Stein133c5f72010-08-31 17:34:37 +020026#include <qevent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <stdlib.h>
29
30#include "lkc.h"
31#include "qconf.h"
32
33#include "qconf.moc"
34#include "images.c"
35
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070036#ifdef _
37# undef _
38# define _ qgettext
39#endif
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static QApplication *configApp;
Roman Zippel7fc925f2006-06-08 22:12:46 -070042static ConfigSettings *configSettings;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Boris Barbulovski85eaf282015-09-22 11:36:03 -070044QAction *ConfigMainWindow::saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -080045
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070046static inline QString qgettext(const char* str)
47{
Roman Zippel43bf6122006-06-08 22:12:45 -070048 return QString::fromLocal8Bit(gettext(str));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070049}
50
51static inline QString qgettext(const QString& str)
52{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070053 return QString::fromLocal8Bit(gettext(str.toLatin1()));
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070054}
55
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010056ConfigSettings::ConfigSettings()
57 : QSettings("kernel.org", "qconf")
58{
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/**
62 * Reads a list of integer values from the application settings.
63 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070064QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070066 QList<int> result;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070067 QStringList entryList = value(key).toStringList();
Li Zefanc1f96f02010-05-07 13:58:04 +080068 QStringList::Iterator it;
69
70 for (it = entryList.begin(); it != entryList.end(); ++it)
71 result.push_back((*it).toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 return result;
74}
75
76/**
77 * Writes a list of integer values to the application settings.
78 */
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070079bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 QStringList stringList;
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070082 QList<int>::ConstIterator it;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 for (it = value.begin(); it != value.end(); ++it)
85 stringList.push_back(QString::number(*it));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070086 setValue(key, stringList);
87 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Roman Zippel43bf6122006-06-08 22:12:45 -070090ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
91 : Parent(parent)
92{
93 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
94}
95
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070096void ConfigLineEdit::show(QTreeWidgetItem *i)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 item = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 Parent::show();
100 setFocus();
101}
102
103void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
104{
105 switch (e->key()) {
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200106 case Qt::Key_Escape:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 break;
Markus Heidelbergfbb86372009-05-18 01:36:51 +0200108 case Qt::Key_Return:
109 case Qt::Key_Enter:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 parent()->updateList(item);
111 break;
112 default:
113 Parent::keyPressEvent(e);
114 return;
115 }
116 e->accept();
117 parent()->list->setFocus();
118 hide();
119}
120
Li Zefan39a48972010-05-10 16:33:41 +0800121ConfigView*ConfigView::viewList;
122QAction *ConfigView::showNormalAction;
123QAction *ConfigView::showAllAction;
124QAction *ConfigView::showPromptAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Roman Zippel7fc925f2006-06-08 22:12:46 -0700126ConfigView::ConfigView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700127 : Parent(parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Boris Barbulovski29a70162015-09-22 11:36:10 -0700129 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
Boris Barbulovski92298b42015-09-22 11:36:11 -0700130 verticalLayout->setContentsMargins(0, 0, 0, 0);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700131
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700132 list = new QTreeWidget(this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700133 verticalLayout->addWidget(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 lineEdit = new ConfigLineEdit(this);
135 lineEdit->hide();
Boris Barbulovski29a70162015-09-22 11:36:10 -0700136 verticalLayout->addWidget(lineEdit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 this->nextView = viewList;
139 viewList = this;
140}
141
142ConfigView::~ConfigView(void)
143{
144 ConfigView** vp;
145
146 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
147 if (*vp == this) {
148 *vp = nextView;
149 break;
150 }
151 }
152}
153
Li Zefan39a48972010-05-10 16:33:41 +0800154void ConfigView::setOptionMode(QAction *act)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700155{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700156}
157
158void ConfigView::setShowName(bool b)
159{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700160}
161
162void ConfigView::setShowRange(bool b)
163{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700164}
165
166void ConfigView::setShowData(bool b)
167{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700168}
169
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700170void ConfigView::updateList(QTreeWidgetItem* item)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700171{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
174void ConfigView::updateListAll(void)
175{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Roman Zippel43bf6122006-06-08 22:12:45 -0700178ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700179 : Parent(parent), sym(0), _menu(0)
Roman Zippel43bf6122006-06-08 22:12:45 -0700180{
Roman Zippel7fc925f2006-06-08 22:12:46 -0700181 if (name) {
182 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700183 _showDebug = configSettings->value("/showDebug", false).toBool();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700184 configSettings->endGroup();
185 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
186 }
187}
188
189void ConfigInfoView::saveSettings(void)
190{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700191 /*if (name()) {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700192 configSettings->beginGroup(name());
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700193 configSettings->setValue("/showDebug", showDebug());
Roman Zippel7fc925f2006-06-08 22:12:46 -0700194 configSettings->endGroup();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700195 }*/
Roman Zippel43bf6122006-06-08 22:12:45 -0700196}
197
198void ConfigInfoView::setShowDebug(bool b)
199{
200 if (_showDebug != b) {
201 _showDebug = b;
Alexander Stein133c5f72010-08-31 17:34:37 +0200202 if (_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700203 menuInfo();
Roman Zippelab45d192006-06-08 22:12:47 -0700204 else if (sym)
205 symbolInfo();
Roman Zippel43bf6122006-06-08 22:12:45 -0700206 emit showDebugChanged(b);
207 }
208}
209
210void ConfigInfoView::setInfo(struct menu *m)
211{
Alexander Stein133c5f72010-08-31 17:34:37 +0200212 if (_menu == m)
Roman Zippelb65a47e2006-06-08 22:12:47 -0700213 return;
Alexander Stein133c5f72010-08-31 17:34:37 +0200214 _menu = m;
Roman Zippel6fa1da82007-01-10 23:15:31 -0800215 sym = NULL;
Alexander Stein133c5f72010-08-31 17:34:37 +0200216 if (!_menu)
Roman Zippel43bf6122006-06-08 22:12:45 -0700217 clear();
Roman Zippel6fa1da82007-01-10 23:15:31 -0800218 else
Roman Zippel43bf6122006-06-08 22:12:45 -0700219 menuInfo();
220}
221
Roman Zippelab45d192006-06-08 22:12:47 -0700222void ConfigInfoView::symbolInfo(void)
223{
224 QString str;
225
226 str += "<big>Symbol: <b>";
227 str += print_filter(sym->name);
228 str += "</b></big><br><br>value: ";
229 str += print_filter(sym_get_string_value(sym));
230 str += "<br>visibility: ";
231 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
232 str += "<br>";
233 str += debug_info(sym);
234
235 setText(str);
236}
237
Roman Zippel43bf6122006-06-08 22:12:45 -0700238void ConfigInfoView::menuInfo(void)
239{
240 struct symbol* sym;
241 QString head, debug, help;
242
Alexander Stein133c5f72010-08-31 17:34:37 +0200243 sym = _menu->sym;
Roman Zippel43bf6122006-06-08 22:12:45 -0700244 if (sym) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200245 if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700246 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +0200247 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -0700248 head += "</b></big>";
249 if (sym->name) {
250 head += " (";
Roman Zippelab45d192006-06-08 22:12:47 -0700251 if (showDebug())
252 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -0700253 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -0700254 if (showDebug())
255 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -0700256 head += ")";
257 }
258 } else if (sym->name) {
259 head += "<big><b>";
Roman Zippelab45d192006-06-08 22:12:47 -0700260 if (showDebug())
261 head += QString().sprintf("<a href=\"s%p\">", sym);
Roman Zippel43bf6122006-06-08 22:12:45 -0700262 head += print_filter(sym->name);
Roman Zippelab45d192006-06-08 22:12:47 -0700263 if (showDebug())
264 head += "</a>";
Roman Zippel43bf6122006-06-08 22:12:45 -0700265 head += "</b></big>";
266 }
267 head += "<br><br>";
268
269 if (showDebug())
270 debug = debug_info(sym);
271
Cheng Renquand74c15f2009-07-12 16:11:47 +0800272 struct gstr help_gstr = str_new();
Alexander Stein133c5f72010-08-31 17:34:37 +0200273 menu_get_ext_help(_menu, &help_gstr);
Cheng Renquand74c15f2009-07-12 16:11:47 +0800274 help = print_filter(str_get(&help_gstr));
275 str_free(&help_gstr);
Alexander Stein133c5f72010-08-31 17:34:37 +0200276 } else if (_menu->prompt) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700277 head += "<big><b>";
Alexander Stein133c5f72010-08-31 17:34:37 +0200278 head += print_filter(_(_menu->prompt->text));
Roman Zippel43bf6122006-06-08 22:12:45 -0700279 head += "</b></big><br><br>";
280 if (showDebug()) {
Alexander Stein133c5f72010-08-31 17:34:37 +0200281 if (_menu->prompt->visible.expr) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700282 debug += "&nbsp;&nbsp;dep: ";
Alexander Stein133c5f72010-08-31 17:34:37 +0200283 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
Roman Zippel43bf6122006-06-08 22:12:45 -0700284 debug += "<br><br>";
285 }
286 }
287 }
288 if (showDebug())
Alexander Stein133c5f72010-08-31 17:34:37 +0200289 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
Roman Zippel43bf6122006-06-08 22:12:45 -0700290
291 setText(head + debug + help);
292}
293
294QString ConfigInfoView::debug_info(struct symbol *sym)
295{
296 QString debug;
297
298 debug += "type: ";
299 debug += print_filter(sym_type_name(sym->type));
300 if (sym_is_choice(sym))
301 debug += " (choice)";
302 debug += "<br>";
303 if (sym->rev_dep.expr) {
304 debug += "reverse dep: ";
305 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
306 debug += "<br>";
307 }
308 for (struct property *prop = sym->prop; prop; prop = prop->next) {
309 switch (prop->type) {
310 case P_PROMPT:
311 case P_MENU:
Roman Zippelab45d192006-06-08 22:12:47 -0700312 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
Roman Zippel43bf6122006-06-08 22:12:45 -0700313 debug += print_filter(_(prop->text));
Roman Zippelab45d192006-06-08 22:12:47 -0700314 debug += "</a><br>";
Roman Zippel43bf6122006-06-08 22:12:45 -0700315 break;
316 case P_DEFAULT:
Roman Zippel93449082008-01-14 04:50:54 +0100317 case P_SELECT:
318 case P_RANGE:
319 case P_ENV:
320 debug += prop_get_type_name(prop->type);
321 debug += ": ";
Roman Zippel43bf6122006-06-08 22:12:45 -0700322 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
323 debug += "<br>";
324 break;
325 case P_CHOICE:
326 if (sym_is_choice(sym)) {
327 debug += "choice: ";
328 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
329 debug += "<br>";
330 }
331 break;
Roman Zippel43bf6122006-06-08 22:12:45 -0700332 default:
333 debug += "unknown property: ";
334 debug += prop_get_type_name(prop->type);
335 debug += "<br>";
336 }
337 if (prop->visible.expr) {
338 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
339 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
340 debug += "<br>";
341 }
342 }
343 debug += "<br>";
344
345 return debug;
346}
347
348QString ConfigInfoView::print_filter(const QString &str)
349{
350 QRegExp re("[<>&\"\\n]");
351 QString res = str;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700352 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
353 switch (res[i].toLatin1()) {
Roman Zippel43bf6122006-06-08 22:12:45 -0700354 case '<':
355 res.replace(i, 1, "&lt;");
356 i += 4;
357 break;
358 case '>':
359 res.replace(i, 1, "&gt;");
360 i += 4;
361 break;
362 case '&':
363 res.replace(i, 1, "&amp;");
364 i += 5;
365 break;
366 case '"':
367 res.replace(i, 1, "&quot;");
368 i += 6;
369 break;
370 case '\n':
371 res.replace(i, 1, "<br>");
372 i += 4;
373 break;
374 }
375 }
376 return res;
377}
378
Roman Zippelab45d192006-06-08 22:12:47 -0700379void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
Roman Zippel43bf6122006-06-08 22:12:45 -0700380{
Roman Zippelab45d192006-06-08 22:12:47 -0700381 QString* text = reinterpret_cast<QString*>(data);
382 QString str2 = print_filter(str);
383
384 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
385 *text += QString().sprintf("<a href=\"s%p\">", sym);
386 *text += str2;
387 *text += "</a>";
388 } else
389 *text += str2;
Roman Zippel43bf6122006-06-08 22:12:45 -0700390}
391
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700392QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700393{
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700394 QMenu* popup = Parent::createStandardContextMenu(pos);
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700395 QAction* action = new QAction(_("Show Debug Info"), popup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700396 action->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700397 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
398 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700399 action->setChecked(showDebug());
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700400 popup->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700401 popup->addAction(action);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700402 return popup;
403}
404
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700405void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700406{
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700407 Parent::contextMenuEvent(e);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700408}
409
Marco Costalba63431e72006-10-05 19:12:59 +0200410ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700411 : Parent(parent), result(NULL)
Roman Zippel43bf6122006-06-08 22:12:45 -0700412{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700413 setWindowTitle("Search Config");
Roman Zippel43bf6122006-06-08 22:12:45 -0700414
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700415 QVBoxLayout* layout1 = new QVBoxLayout(this);
416 layout1->setContentsMargins(11, 11, 11, 11);
417 layout1->setSpacing(6);
418 QHBoxLayout* layout2 = new QHBoxLayout(0);
419 layout2->setContentsMargins(0, 0, 0, 0);
420 layout2->setSpacing(6);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100421 layout2->addWidget(new QLabel(_("Find:"), this));
Roman Zippel43bf6122006-06-08 22:12:45 -0700422 editField = new QLineEdit(this);
423 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
424 layout2->addWidget(editField);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100425 searchButton = new QPushButton(_("Search"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700426 searchButton->setAutoDefault(false);
Roman Zippel43bf6122006-06-08 22:12:45 -0700427 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
428 layout2->addWidget(searchButton);
429 layout1->addLayout(layout2);
430
Roman Zippel7fc925f2006-06-08 22:12:46 -0700431 split = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +0200432 split->setOrientation(Qt::Vertical);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700433 list = new ConfigView(split, name);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700434 info = new ConfigInfoView(split, name);
Roman Zippel43bf6122006-06-08 22:12:45 -0700435 connect(list->list, SIGNAL(menuChanged(struct menu *)),
436 info, SLOT(setInfo(struct menu *)));
Marco Costalba63431e72006-10-05 19:12:59 +0200437 connect(list->list, SIGNAL(menuChanged(struct menu *)),
438 parent, SLOT(setMenuLink(struct menu *)));
439
Roman Zippel43bf6122006-06-08 22:12:45 -0700440 layout1->addWidget(split);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700441
442 if (name) {
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700443 QVariant x, y;
444 int width, height;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700445 bool ok;
446
447 configSettings->beginGroup(name);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700448 width = configSettings->value("/window width", parent->width() / 2).toInt();
449 height = configSettings->value("/window height", parent->height() / 2).toInt();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700450 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700451 x = configSettings->value("/window x");
452 y = configSettings->value("/window y");
453 if ((x.isValid())&&(y.isValid()))
454 move(x.toInt(), y.toInt());
Boris Barbulovski041fbdc2015-09-22 11:36:05 -0700455 QList<int> sizes = configSettings->readSizes("/split", &ok);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700456 if (ok)
457 split->setSizes(sizes);
458 configSettings->endGroup();
459 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
460 }
461}
462
463void ConfigSearchWindow::saveSettings(void)
464{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700465 /*if (name()) {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700466 configSettings->beginGroup(name());
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700467 configSettings->setValue("/window x", pos().x());
468 configSettings->setValue("/window y", pos().y());
469 configSettings->setValue("/window width", size().width());
470 configSettings->setValue("/window height", size().height());
Roman Zippel7fc925f2006-06-08 22:12:46 -0700471 configSettings->writeSizes("/split", split->sizes());
472 configSettings->endGroup();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700473 }*/
Roman Zippel43bf6122006-06-08 22:12:45 -0700474}
475
476void ConfigSearchWindow::search(void)
477{
Roman Zippel43bf6122006-06-08 22:12:45 -0700478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480/*
481 * Construct the complete config widget
482 */
483ConfigMainWindow::ConfigMainWindow(void)
Roman Zippelf12aa702006-11-25 11:09:31 -0800484 : searchWindow(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 QMenuBar* menu;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700487 bool ok;
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700488 QVariant x, y;
489 int width, height;
Randy Dunlapa54bb702007-10-20 11:18:47 -0700490 char title[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Markus Heidelberg8d90c972009-05-18 01:36:52 +0200492 QDesktopWidget *d = configApp->desktop();
Arnaud Lacombe09548282010-08-18 01:57:13 -0400493 snprintf(title, sizeof(title), "%s%s",
494 rootmenu.prompt->text,
Michal Marek76a136c2010-09-01 17:39:27 +0200495 ""
Michal Marek76a136c2010-09-01 17:39:27 +0200496 );
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700497 setWindowTitle(title);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700499 width = configSettings->value("/window width", d->width() - 64).toInt();
500 height = configSettings->value("/window height", d->height() - 64).toInt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 resize(width, height);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700502 x = configSettings->value("/window x");
503 y = configSettings->value("/window y");
504 if ((x.isValid())&&(y.isValid()))
505 move(x.toInt(), y.toInt());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 split1 = new QSplitter(this);
Markus Heidelberg7298b932009-05-18 01:36:50 +0200508 split1->setOrientation(Qt::Horizontal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 setCentralWidget(split1);
510
Roman Zippel7fc925f2006-06-08 22:12:46 -0700511 menuView = new ConfigView(split1, "menu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 menuList = menuView->list;
513
514 split2 = new QSplitter(split1);
Markus Heidelberg7298b932009-05-18 01:36:50 +0200515 split2->setOrientation(Qt::Vertical);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 // create config tree
Roman Zippel7fc925f2006-06-08 22:12:46 -0700518 configView = new ConfigView(split2, "config");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 configList = configView->list;
520
Roman Zippel7fc925f2006-06-08 22:12:46 -0700521 helpText = new ConfigInfoView(split2, "help");
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700522 //helpText->setTextFormat(Qt::RichText);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 setTabOrder(configList, helpText);
525 configList->setFocus();
526
527 menu = menuBar();
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700528 toolBar = new QToolBar("Tools", this);
Boris Barbulovski29a70162015-09-22 11:36:10 -0700529 addToolBar(toolBar);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700531 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700533 backAction->setEnabled(false);
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700534 QAction *quitAction = new QAction(_("&Quit"), this);
535 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 connect(quitAction, SIGNAL(activated()), SLOT(close()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700537 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
538 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700540 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
541 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
Karsten Wiese3b354c52006-12-13 00:34:08 -0800543 conf_set_changed_callback(conf_changed);
544 // Set saveAction's initial state
545 conf_changed();
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700546 QAction *saveAsAction = new QAction(_("Save &As..."), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700548 QAction *searchAction = new QAction(_("&Find"), this);
549 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Roman Zippel43bf6122006-06-08 22:12:45 -0700550 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
Boris Barbulovski780505e2015-09-22 11:36:13 -0700551 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700552 singleViewAction->setCheckable(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -0700554 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700555 splitViewAction->setCheckable(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
Boris Barbulovski780505e2015-09-22 11:36:13 -0700557 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700558 fullViewAction->setCheckable(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
560
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700561 QAction *showNameAction = new QAction(_("Show Name"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700562 showNameAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700563 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
564 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700565 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700566 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700567 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700568 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
569 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700570 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700571 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700572 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
573 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
Li Zefan39a48972010-05-10 16:33:41 +0800574
575 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700576 optGroup->setExclusive(true);
Li Zefan39a48972010-05-10 16:33:41 +0800577 connect(optGroup, SIGNAL(selected(QAction *)), configView,
578 SLOT(setOptionMode(QAction *)));
579 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
580 SLOT(setOptionMode(QAction *)));
581
Alexander Stein133c5f72010-08-31 17:34:37 +0200582 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
583 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
584 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700585 configView->showNormalAction->setCheckable(true);
586 configView->showAllAction->setCheckable(true);
587 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +0800588
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700589 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700590 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -0700591 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
592 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700593 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700595 QAction *showIntroAction = new QAction( _("Introduction"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700597 QAction *showAboutAction = new QAction( _("About"), this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
599
600 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700601 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700603 toolBar->addAction(loadAction);
604 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700606 toolBar->addAction(singleViewAction);
607 toolBar->addAction(splitViewAction);
608 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 // create config menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700611 QMenu* config = menu->addMenu(_("&File"));
612 config->addAction(loadAction);
613 config->addAction(saveAction);
614 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -0700615 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700616 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Shlomi Fish66e7c722007-02-14 00:32:58 -0800618 // create edit menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700619 QMenu* editMenu = menu->addMenu(_("&Edit"));
620 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -0800621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 // create options menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700623 QMenu* optionMenu = menu->addMenu(_("&Option"));
624 optionMenu->addAction(showNameAction);
625 optionMenu->addAction(showRangeAction);
626 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -0700627 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700628 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -0700629 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -0700632 menu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700633 QMenu* helpMenu = menu->addMenu(_("&Help"));
634 helpMenu->addAction(showIntroAction);
635 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Roman Zippel43bf6122006-06-08 22:12:45 -0700637 connect(configList, SIGNAL(menuChanged(struct menu *)),
638 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 connect(configList, SIGNAL(menuSelected(struct menu *)),
640 SLOT(changeMenu(struct menu *)));
641 connect(configList, SIGNAL(parentSelected()),
642 SLOT(goBack()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700643 connect(menuList, SIGNAL(menuChanged(struct menu *)),
644 helpText, SLOT(setInfo(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 connect(menuList, SIGNAL(menuSelected(struct menu *)),
646 SLOT(changeMenu(struct menu *)));
647
Roman Zippelb65a47e2006-06-08 22:12:47 -0700648 connect(configList, SIGNAL(gotFocus(struct menu *)),
649 helpText, SLOT(setInfo(struct menu *)));
650 connect(menuList, SIGNAL(gotFocus(struct menu *)),
651 helpText, SLOT(setInfo(struct menu *)));
652 connect(menuList, SIGNAL(gotFocus(struct menu *)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 SLOT(listFocusChanged(void)));
Roman Zippelb65a47e2006-06-08 22:12:47 -0700654 connect(helpText, SIGNAL(menuSelected(struct menu *)),
655 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700657 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 if (listMode == "single")
659 showSingleView();
660 else if (listMode == "full")
661 showFullView();
662 else /*if (listMode == "split")*/
663 showSplitView();
664
665 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -0700666 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (ok)
668 split1->setSizes(sizes);
669
Roman Zippel7fc925f2006-06-08 22:12:46 -0700670 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 if (ok)
672 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675void ConfigMainWindow::loadConfig(void)
676{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700677 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (s.isNull())
679 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700680 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100681 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 ConfigView::updateListAll();
683}
684
Michal Marekbac6aa82011-05-25 15:10:25 +0200685bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Michal Marekbac6aa82011-05-25 15:10:25 +0200687 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100688 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +0200689 return false;
690 }
691 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
694void ConfigMainWindow::saveConfigAs(void)
695{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700696 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if (s.isNull())
698 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -0400699 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
Roman Zippel43bf6122006-06-08 22:12:45 -0700702void ConfigMainWindow::searchConfig(void)
703{
704 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700705 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -0700706 searchWindow->show();
707}
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709void ConfigMainWindow::changeMenu(struct menu *menu)
710{
Boris Barbulovski76538662015-09-22 11:36:14 -0700711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
713
Roman Zippelb65a47e2006-06-08 22:12:47 -0700714void ConfigMainWindow::setMenuLink(struct menu *menu)
715{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700716}
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718void ConfigMainWindow::listFocusChanged(void)
719{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
721
722void ConfigMainWindow::goBack(void)
723{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
726void ConfigMainWindow::showSingleView(void)
727{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700728 singleViewAction->setEnabled(false);
729 singleViewAction->setChecked(true);
730 splitViewAction->setEnabled(true);
731 splitViewAction->setChecked(false);
732 fullViewAction->setEnabled(true);
733 fullViewAction->setChecked(false);
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 menuView->hide();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 configList->setFocus();
737}
738
739void ConfigMainWindow::showSplitView(void)
740{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700741 singleViewAction->setEnabled(true);
742 singleViewAction->setChecked(false);
743 splitViewAction->setEnabled(false);
744 splitViewAction->setChecked(true);
745 fullViewAction->setEnabled(true);
746 fullViewAction->setChecked(false);
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 menuView->show();
749 menuList->setFocus();
750}
751
752void ConfigMainWindow::showFullView(void)
753{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700754 singleViewAction->setEnabled(true);
755 singleViewAction->setChecked(false);
756 splitViewAction->setEnabled(true);
757 splitViewAction->setChecked(false);
758 fullViewAction->setEnabled(false);
759 fullViewAction->setChecked(true);
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 menuView->hide();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 configList->setFocus();
763}
764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765/*
766 * ask for saving configuration before quitting
767 * TODO ask only when something changed
768 */
769void ConfigMainWindow::closeEvent(QCloseEvent* e)
770{
Karsten Wieseb3214292006-12-13 00:34:06 -0800771 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 e->accept();
773 return;
774 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100775 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100777 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
778 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
779 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 switch (mb.exec()) {
781 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +0200782 if (saveConfig())
783 e->accept();
784 else
785 e->ignore();
786 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 case QMessageBox::No:
788 e->accept();
789 break;
790 case QMessageBox::Cancel:
791 e->ignore();
792 break;
793 }
794}
795
796void ConfigMainWindow::showIntro(void)
797{
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400798 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 "For each option, a blank box indicates the feature is disabled, a check\n"
800 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
801 "as a module. Clicking on the box will cycle through the three states.\n\n"
802 "If you do not see an option (e.g., a device driver) that you believe\n"
803 "should be present, try turning on Show All Options under the Options menu.\n"
804 "Although there is no cross reference yet to help you figure out what other\n"
805 "options must be enabled to support the option you are interested in, you can\n"
806 "still view the help of a grayed-out option.\n\n"
807 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100808 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 QMessageBox::information(this, "qconf", str);
811}
812
813void ConfigMainWindow::showAbout(void)
814{
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100815 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
816 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 QMessageBox::information(this, "qconf", str);
819}
820
821void ConfigMainWindow::saveSettings(void)
822{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700823 configSettings->setValue("/window x", pos().x());
824 configSettings->setValue("/window y", pos().y());
825 configSettings->setValue("/window width", size().width());
826 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 QString entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700830 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Roman Zippel7fc925f2006-06-08 22:12:46 -0700832 configSettings->writeSizes("/split1", split1->sizes());
833 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
Karsten Wiese3b354c52006-12-13 00:34:08 -0800836void ConfigMainWindow::conf_changed(void)
837{
838 if (saveAction)
839 saveAction->setEnabled(conf_get_changed());
840}
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842void fixup_rootmenu(struct menu *menu)
843{
844 struct menu *child;
845 static int menu_cnt = 0;
846
847 menu->flags |= MENU_ROOT;
848 for (child = menu->list; child; child = child->next) {
849 if (child->prompt && child->prompt->type == P_MENU) {
850 menu_cnt++;
851 fixup_rootmenu(child);
852 menu_cnt--;
853 } else if (!menu_cnt)
854 fixup_rootmenu(child);
855 }
856}
857
858static const char *progname;
859
860static void usage(void)
861{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700862 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 exit(0);
864}
865
866int main(int ac, char** av)
867{
868 ConfigMainWindow* v;
869 const char *name;
870
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700871 bindtextdomain(PACKAGE, LOCALEDIR);
872 textdomain(PACKAGE);
873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 progname = av[0];
875 configApp = new QApplication(ac, av);
876 if (ac > 1 && av[1][0] == '-') {
877 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +0200878 case 's':
879 conf_set_message_callback(NULL);
880 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 case 'h':
882 case '?':
883 usage();
884 }
885 name = av[2];
886 } else
887 name = av[1];
888 if (!name)
889 usage();
890
891 conf_parse(name);
892 fixup_rootmenu(&rootmenu);
893 conf_read(NULL);
894 //zconfdump(stdout);
895
Roman Zippel7fc925f2006-06-08 22:12:46 -0700896 configSettings = new ConfigSettings();
897 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 v = new ConfigMainWindow();
899
900 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
902 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700903 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 configApp->exec();
905
Roman Zippel7fc925f2006-06-08 22:12:46 -0700906 configSettings->endGroup();
907 delete configSettings;
908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return 0;
910}