blob: c6b732092eda3c3d4fc6c476dbc37ce6bceac229 [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{
Boris Barbulovski92119932015-09-22 11:36:16 -070093 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
Roman Zippel43bf6122006-06-08 22:12:45 -070094}
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;
Boris Barbulovski92119932015-09-22 11:36:16 -0700487 bool ok = true;
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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700532 connect(backAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700536 connect(quitAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700539 connect(loadAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700542 connect(saveAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700547 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700548 QAction *searchAction = new QAction(_("&Find"), this);
549 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
Boris Barbulovski92119932015-09-22 11:36:16 -0700550 connect(searchAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700553 connect(singleViewAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700556 connect(splitViewAction, SIGNAL(triggered(bool)), 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);
Boris Barbulovski92119932015-09-22 11:36:16 -0700559 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
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)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700564 showNameAction->setChecked(configView->showName());
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700565 QAction *showRangeAction = new QAction(_("Show Range"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700566 showRangeAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700567 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700568 QAction *showDataAction = new QAction(_("Show Data"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700569 showDataAction->setCheckable(true);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700570 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
Li Zefan39a48972010-05-10 16:33:41 +0800571
572 QActionGroup *optGroup = new QActionGroup(this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700573 optGroup->setExclusive(true);
Boris Barbulovski92119932015-09-22 11:36:16 -0700574 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
Li Zefan39a48972010-05-10 16:33:41 +0800575 SLOT(setOptionMode(QAction *)));
Boris Barbulovski92119932015-09-22 11:36:16 -0700576 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
Li Zefan39a48972010-05-10 16:33:41 +0800577 SLOT(setOptionMode(QAction *)));
578
Alexander Stein133c5f72010-08-31 17:34:37 +0200579 configView->showNormalAction = new QAction(_("Show Normal Options"), optGroup);
580 configView->showAllAction = new QAction(_("Show All Options"), optGroup);
581 configView->showPromptAction = new QAction(_("Show Prompt Options"), optGroup);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700582 configView->showNormalAction->setCheckable(true);
583 configView->showAllAction->setCheckable(true);
584 configView->showPromptAction->setCheckable(true);
Li Zefan39a48972010-05-10 16:33:41 +0800585
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700586 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700587 showDebugAction->setCheckable(true);
Roman Zippel43bf6122006-06-08 22:12:45 -0700588 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
Boris Barbulovski9c862352015-09-22 11:36:12 -0700589 showDebugAction->setChecked(helpText->showDebug());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700591 QAction *showIntroAction = new QAction( _("Introduction"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -0700592 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700593 QAction *showAboutAction = new QAction( _("About"), this);
Boris Barbulovski92119932015-09-22 11:36:16 -0700594 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 // init tool bar
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700597 toolBar->addAction(backAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700599 toolBar->addAction(loadAction);
600 toolBar->addAction(saveAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 toolBar->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700602 toolBar->addAction(singleViewAction);
603 toolBar->addAction(splitViewAction);
604 toolBar->addAction(fullViewAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 // create config menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700607 QMenu* config = menu->addMenu(_("&File"));
608 config->addAction(loadAction);
609 config->addAction(saveAction);
610 config->addAction(saveAsAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -0700611 config->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700612 config->addAction(quitAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Shlomi Fish66e7c722007-02-14 00:32:58 -0800614 // create edit menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700615 QMenu* editMenu = menu->addMenu(_("&Edit"));
616 editMenu->addAction(searchAction);
Shlomi Fish66e7c722007-02-14 00:32:58 -0800617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 // create options menu
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700619 QMenu* optionMenu = menu->addMenu(_("&Option"));
620 optionMenu->addAction(showNameAction);
621 optionMenu->addAction(showRangeAction);
622 optionMenu->addAction(showDataAction);
Boris Barbulovski76bede82015-09-22 11:36:07 -0700623 optionMenu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700624 optionMenu->addActions(optGroup->actions());
Boris Barbulovski76bede82015-09-22 11:36:07 -0700625 optionMenu->addSeparator();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 // create help menu
Boris Barbulovski76bede82015-09-22 11:36:07 -0700628 menu->addSeparator();
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700629 QMenu* helpMenu = menu->addMenu(_("&Help"));
630 helpMenu->addAction(showIntroAction);
631 helpMenu->addAction(showAboutAction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Roman Zippelb65a47e2006-06-08 22:12:47 -0700633 connect(helpText, SIGNAL(menuSelected(struct menu *)),
634 SLOT(setMenuLink(struct menu *)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700636 QString listMode = configSettings->value("/listMode", "symbol").toString();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (listMode == "single")
638 showSingleView();
639 else if (listMode == "full")
640 showFullView();
641 else /*if (listMode == "split")*/
642 showSplitView();
643
644 // UI setup done, restore splitter positions
Boris Barbulovski041fbdc2015-09-22 11:36:05 -0700645 QList<int> sizes = configSettings->readSizes("/split1", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (ok)
647 split1->setSizes(sizes);
648
Roman Zippel7fc925f2006-06-08 22:12:46 -0700649 sizes = configSettings->readSizes("/split2", &ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 if (ok)
651 split2->setSizes(sizes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654void ConfigMainWindow::loadConfig(void)
655{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700656 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (s.isNull())
658 return;
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700659 if (conf_read(QFile::encodeName(s)))
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100660 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 ConfigView::updateListAll();
662}
663
Michal Marekbac6aa82011-05-25 15:10:25 +0200664bool ConfigMainWindow::saveConfig(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Michal Marekbac6aa82011-05-25 15:10:25 +0200666 if (conf_write(NULL)) {
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100667 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
Michal Marekbac6aa82011-05-25 15:10:25 +0200668 return false;
669 }
670 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673void ConfigMainWindow::saveConfigAs(void)
674{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700675 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (s.isNull())
677 return;
Arnaud Lacombed49e4682011-05-24 14:16:18 -0400678 saveConfig();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
Roman Zippel43bf6122006-06-08 22:12:45 -0700681void ConfigMainWindow::searchConfig(void)
682{
683 if (!searchWindow)
Roman Zippel7fc925f2006-06-08 22:12:46 -0700684 searchWindow = new ConfigSearchWindow(this, "search");
Roman Zippel43bf6122006-06-08 22:12:45 -0700685 searchWindow->show();
686}
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688void ConfigMainWindow::changeMenu(struct menu *menu)
689{
Boris Barbulovski76538662015-09-22 11:36:14 -0700690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Roman Zippelb65a47e2006-06-08 22:12:47 -0700693void ConfigMainWindow::setMenuLink(struct menu *menu)
694{
Roman Zippelb65a47e2006-06-08 22:12:47 -0700695}
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697void ConfigMainWindow::listFocusChanged(void)
698{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
701void ConfigMainWindow::goBack(void)
702{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705void ConfigMainWindow::showSingleView(void)
706{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700707 singleViewAction->setEnabled(false);
708 singleViewAction->setChecked(true);
709 splitViewAction->setEnabled(true);
710 splitViewAction->setChecked(false);
711 fullViewAction->setEnabled(true);
712 fullViewAction->setChecked(false);
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 menuView->hide();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 configList->setFocus();
716}
717
718void ConfigMainWindow::showSplitView(void)
719{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700720 singleViewAction->setEnabled(true);
721 singleViewAction->setChecked(false);
722 splitViewAction->setEnabled(false);
723 splitViewAction->setChecked(true);
724 fullViewAction->setEnabled(true);
725 fullViewAction->setChecked(false);
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 menuView->show();
728 menuList->setFocus();
729}
730
731void ConfigMainWindow::showFullView(void)
732{
Boris Barbulovski780505e2015-09-22 11:36:13 -0700733 singleViewAction->setEnabled(true);
734 singleViewAction->setChecked(false);
735 splitViewAction->setEnabled(true);
736 splitViewAction->setChecked(false);
737 fullViewAction->setEnabled(false);
738 fullViewAction->setChecked(true);
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 menuView->hide();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 configList->setFocus();
742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * ask for saving configuration before quitting
746 * TODO ask only when something changed
747 */
748void ConfigMainWindow::closeEvent(QCloseEvent* e)
749{
Karsten Wieseb3214292006-12-13 00:34:06 -0800750 if (!conf_get_changed()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 e->accept();
752 return;
753 }
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100754 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100756 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
757 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
758 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 switch (mb.exec()) {
760 case QMessageBox::Yes:
Michal Marekbac6aa82011-05-25 15:10:25 +0200761 if (saveConfig())
762 e->accept();
763 else
764 e->ignore();
765 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 case QMessageBox::No:
767 e->accept();
768 break;
769 case QMessageBox::Cancel:
770 e->ignore();
771 break;
772 }
773}
774
775void ConfigMainWindow::showIntro(void)
776{
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400777 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 "For each option, a blank box indicates the feature is disabled, a check\n"
779 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
780 "as a module. Clicking on the box will cycle through the three states.\n\n"
781 "If you do not see an option (e.g., a device driver) that you believe\n"
782 "should be present, try turning on Show All Options under the Options menu.\n"
783 "Although there is no cross reference yet to help you figure out what other\n"
784 "options must be enabled to support the option you are interested in, you can\n"
785 "still view the help of a grayed-out option.\n\n"
786 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100787 "which you can then match by examining other options.\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 QMessageBox::information(this, "qconf", str);
790}
791
792void ConfigMainWindow::showAbout(void)
793{
EGRY Gaborc21a2d92008-01-11 23:52:07 +0100794 static const QString str = _("qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
795 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 QMessageBox::information(this, "qconf", str);
798}
799
800void ConfigMainWindow::saveSettings(void)
801{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700802 configSettings->setValue("/window x", pos().x());
803 configSettings->setValue("/window y", pos().y());
804 configSettings->setValue("/window width", size().width());
805 configSettings->setValue("/window height", size().height());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 QString entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700809 configSettings->setValue("/listMode", entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Roman Zippel7fc925f2006-06-08 22:12:46 -0700811 configSettings->writeSizes("/split1", split1->sizes());
812 configSettings->writeSizes("/split2", split2->sizes());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
Karsten Wiese3b354c52006-12-13 00:34:08 -0800815void ConfigMainWindow::conf_changed(void)
816{
817 if (saveAction)
818 saveAction->setEnabled(conf_get_changed());
819}
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821void fixup_rootmenu(struct menu *menu)
822{
823 struct menu *child;
824 static int menu_cnt = 0;
825
826 menu->flags |= MENU_ROOT;
827 for (child = menu->list; child; child = child->next) {
828 if (child->prompt && child->prompt->type == P_MENU) {
829 menu_cnt++;
830 fixup_rootmenu(child);
831 menu_cnt--;
832 } else if (!menu_cnt)
833 fixup_rootmenu(child);
834 }
835}
836
837static const char *progname;
838
839static void usage(void)
840{
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -0700841 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 exit(0);
843}
844
845int main(int ac, char** av)
846{
847 ConfigMainWindow* v;
848 const char *name;
849
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700850 bindtextdomain(PACKAGE, LOCALEDIR);
851 textdomain(PACKAGE);
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 progname = av[0];
854 configApp = new QApplication(ac, av);
855 if (ac > 1 && av[1][0] == '-') {
856 switch (av[1][1]) {
Michal Marek0a1f00a2015-04-08 13:30:42 +0200857 case 's':
858 conf_set_message_callback(NULL);
859 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 case 'h':
861 case '?':
862 usage();
863 }
864 name = av[2];
865 } else
866 name = av[1];
867 if (!name)
868 usage();
869
870 conf_parse(name);
871 fixup_rootmenu(&rootmenu);
872 conf_read(NULL);
873 //zconfdump(stdout);
874
Roman Zippel7fc925f2006-06-08 22:12:46 -0700875 configSettings = new ConfigSettings();
876 configSettings->beginGroup("/kconfig/qconf");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 v = new ConfigMainWindow();
878
879 //zconfdump(stdout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
881 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
Roman Zippel43bf6122006-06-08 22:12:45 -0700882 v->show();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 configApp->exec();
884
Roman Zippel7fc925f2006-06-08 22:12:46 -0700885 configSettings->endGroup();
886 delete configSettings;
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 return 0;
889}