]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - scripts/kconfig/qconf.cc
Port xconfig to Qt5 - Fix the code so it compiles with Qt5
[mirror_ubuntu-bionic-kernel.git] / scripts / kconfig / qconf.cc
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
133c5f7c
AS
6#include <qglobal.h>
7
b1f8a45b 8#include <QMainWindow>
041fbdc2 9#include <QList>
924bbb53 10#include <qtextbrowser.h>
85eaf28a 11#include <QAction>
bea00771 12#include <QFileDialog>
76bede87 13#include <QMenu>
133c5f7c
AS
14
15#include <qapplication.h>
8d90c97e 16#include <qdesktopwidget.h>
1da177e4 17#include <qtoolbar.h>
43bf612a 18#include <qlayout.h>
1da177e4 19#include <qsplitter.h>
1da177e4 20#include <qlineedit.h>
43bf612a
RZ
21#include <qlabel.h>
22#include <qpushbutton.h>
1da177e4
LT
23#include <qmenubar.h>
24#include <qmessagebox.h>
1da177e4 25#include <qregexp.h>
133c5f7c 26#include <qevent.h>
1da177e4
LT
27
28#include <stdlib.h>
29
30#include "lkc.h"
31#include "qconf.h"
32
33#include "qconf.moc"
34#include "images.c"
35
3b9fa093
ACM
36#ifdef _
37# undef _
38# define _ qgettext
39#endif
40
1da177e4 41static QApplication *configApp;
7fc925fd 42static ConfigSettings *configSettings;
1da177e4 43
85eaf28a 44QAction *ConfigMainWindow::saveAction;
3b354c55 45
3b9fa093
ACM
46static inline QString qgettext(const char* str)
47{
43bf612a 48 return QString::fromLocal8Bit(gettext(str));
3b9fa093
ACM
49}
50
51static inline QString qgettext(const QString& str)
52{
68ccb7ef 53 return QString::fromLocal8Bit(gettext(str.toLatin1()));
3b9fa093
ACM
54}
55
00d4f8fc
BH
56ConfigSettings::ConfigSettings()
57 : QSettings("kernel.org", "qconf")
58{
59}
60
1da177e4
LT
61/**
62 * Reads a list of integer values from the application settings.
63 */
041fbdc2 64QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
1da177e4 65{
041fbdc2 66 QList<int> result;
68ccb7ef 67 QStringList entryList = value(key).toStringList();
c1f96f09
LZ
68 QStringList::Iterator it;
69
70 for (it = entryList.begin(); it != entryList.end(); ++it)
71 result.push_back((*it).toInt());
1da177e4
LT
72
73 return result;
74}
75
76/**
77 * Writes a list of integer values to the application settings.
78 */
041fbdc2 79bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
1da177e4
LT
80{
81 QStringList stringList;
041fbdc2 82 QList<int>::ConstIterator it;
1da177e4
LT
83
84 for (it = value.begin(); it != value.end(); ++it)
85 stringList.push_back(QString::number(*it));
68ccb7ef
BB
86 setValue(key, stringList);
87 return true;
1da177e4 88}
1da177e4 89
43bf612a
RZ
90ConfigLineEdit::ConfigLineEdit(ConfigView* parent)
91 : Parent(parent)
92{
93 connect(this, SIGNAL(lostFocus()), SLOT(hide()));
94}
95
68ccb7ef 96void ConfigLineEdit::show(QTreeWidgetItem *i)
1da177e4
LT
97{
98 item = i;
1da177e4
LT
99 Parent::show();
100 setFocus();
101}
102
103void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
104{
105 switch (e->key()) {
fbb86374 106 case Qt::Key_Escape:
1da177e4 107 break;
fbb86374
MH
108 case Qt::Key_Return:
109 case Qt::Key_Enter:
1da177e4
LT
110 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
39a4897c
LZ
121ConfigView*ConfigView::viewList;
122QAction *ConfigView::showNormalAction;
123QAction *ConfigView::showAllAction;
124QAction *ConfigView::showPromptAction;
1da177e4 125
7fc925fd 126ConfigView::ConfigView(QWidget* parent, const char *name)
68ccb7ef 127 : Parent(parent)
1da177e4 128{
29a70168 129 QVBoxLayout *verticalLayout = new QVBoxLayout(this);
92298b49 130 verticalLayout->setContentsMargins(0, 0, 0, 0);
29a70168 131
68ccb7ef 132 list = new QTreeWidget(this);
29a70168 133 verticalLayout->addWidget(list);
1da177e4
LT
134 lineEdit = new ConfigLineEdit(this);
135 lineEdit->hide();
29a70168 136 verticalLayout->addWidget(lineEdit);
1da177e4
LT
137
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
39a4897c 154void ConfigView::setOptionMode(QAction *act)
7fc925fd 155{
7fc925fd
RZ
156}
157
158void ConfigView::setShowName(bool b)
159{
7fc925fd
RZ
160}
161
162void ConfigView::setShowRange(bool b)
163{
7fc925fd
RZ
164}
165
166void ConfigView::setShowData(bool b)
167{
7fc925fd
RZ
168}
169
68ccb7ef 170void ConfigView::updateList(QTreeWidgetItem* item)
1da177e4 171{
1da177e4
LT
172}
173
174void ConfigView::updateListAll(void)
175{
1da177e4
LT
176}
177
43bf612a 178ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
68ccb7ef 179 : Parent(parent), sym(0), _menu(0)
43bf612a 180{
7fc925fd
RZ
181 if (name) {
182 configSettings->beginGroup(name);
68ccb7ef 183 _showDebug = configSettings->value("/showDebug", false).toBool();
7fc925fd
RZ
184 configSettings->endGroup();
185 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
186 }
187}
188
189void ConfigInfoView::saveSettings(void)
190{
68ccb7ef 191 /*if (name()) {
7fc925fd 192 configSettings->beginGroup(name());
68ccb7ef 193 configSettings->setValue("/showDebug", showDebug());
7fc925fd 194 configSettings->endGroup();
68ccb7ef 195 }*/
43bf612a
RZ
196}
197
198void ConfigInfoView::setShowDebug(bool b)
199{
200 if (_showDebug != b) {
201 _showDebug = b;
133c5f7c 202 if (_menu)
43bf612a 203 menuInfo();
ab45d190
RZ
204 else if (sym)
205 symbolInfo();
43bf612a
RZ
206 emit showDebugChanged(b);
207 }
208}
209
210void ConfigInfoView::setInfo(struct menu *m)
211{
133c5f7c 212 if (_menu == m)
b65a47e1 213 return;
133c5f7c 214 _menu = m;
6fa1da8e 215 sym = NULL;
133c5f7c 216 if (!_menu)
43bf612a 217 clear();
6fa1da8e 218 else
43bf612a
RZ
219 menuInfo();
220}
221
ab45d190
RZ
222void 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
43bf612a
RZ
238void ConfigInfoView::menuInfo(void)
239{
240 struct symbol* sym;
241 QString head, debug, help;
242
133c5f7c 243 sym = _menu->sym;
43bf612a 244 if (sym) {
133c5f7c 245 if (_menu->prompt) {
43bf612a 246 head += "<big><b>";
133c5f7c 247 head += print_filter(_(_menu->prompt->text));
43bf612a
RZ
248 head += "</b></big>";
249 if (sym->name) {
250 head += " (";
ab45d190
RZ
251 if (showDebug())
252 head += QString().sprintf("<a href=\"s%p\">", sym);
43bf612a 253 head += print_filter(sym->name);
ab45d190
RZ
254 if (showDebug())
255 head += "</a>";
43bf612a
RZ
256 head += ")";
257 }
258 } else if (sym->name) {
259 head += "<big><b>";
ab45d190
RZ
260 if (showDebug())
261 head += QString().sprintf("<a href=\"s%p\">", sym);
43bf612a 262 head += print_filter(sym->name);
ab45d190
RZ
263 if (showDebug())
264 head += "</a>";
43bf612a
RZ
265 head += "</b></big>";
266 }
267 head += "<br><br>";
268
269 if (showDebug())
270 debug = debug_info(sym);
271
d74c15f3 272 struct gstr help_gstr = str_new();
133c5f7c 273 menu_get_ext_help(_menu, &help_gstr);
d74c15f3
CR
274 help = print_filter(str_get(&help_gstr));
275 str_free(&help_gstr);
133c5f7c 276 } else if (_menu->prompt) {
43bf612a 277 head += "<big><b>";
133c5f7c 278 head += print_filter(_(_menu->prompt->text));
43bf612a
RZ
279 head += "</b></big><br><br>";
280 if (showDebug()) {
133c5f7c 281 if (_menu->prompt->visible.expr) {
43bf612a 282 debug += "&nbsp;&nbsp;dep: ";
133c5f7c 283 expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
43bf612a
RZ
284 debug += "<br><br>";
285 }
286 }
287 }
288 if (showDebug())
133c5f7c 289 debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
43bf612a
RZ
290
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:
ab45d190 312 debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
43bf612a 313 debug += print_filter(_(prop->text));
ab45d190 314 debug += "</a><br>";
43bf612a
RZ
315 break;
316 case P_DEFAULT:
93449082
RZ
317 case P_SELECT:
318 case P_RANGE:
319 case P_ENV:
320 debug += prop_get_type_name(prop->type);
321 debug += ": ";
43bf612a
RZ
322 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;
43bf612a
RZ
332 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;
68ccb7ef
BB
352 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
353 switch (res[i].toLatin1()) {
43bf612a
RZ
354 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
ab45d190 379void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
43bf612a 380{
ab45d190
RZ
381 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;
43bf612a
RZ
390}
391
924bbb53 392QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
7fc925fd 393{
924bbb53 394 QMenu* popup = Parent::createStandardContextMenu(pos);
85eaf28a 395 QAction* action = new QAction(_("Show Debug Info"), popup);
68ccb7ef 396 action->setCheckable(true);
7fc925fd
RZ
397 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
398 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
9c86235a 399 action->setChecked(showDebug());
924bbb53 400 popup->addSeparator();
68ccb7ef 401 popup->addAction(action);
7fc925fd
RZ
402 return popup;
403}
404
924bbb53 405void ConfigInfoView::contextMenuEvent(QContextMenuEvent *e)
7fc925fd 406{
924bbb53 407 Parent::contextMenuEvent(e);
7fc925fd
RZ
408}
409
63431e75 410ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name)
68ccb7ef 411 : Parent(parent), result(NULL)
43bf612a 412{
68ccb7ef 413 setWindowTitle("Search Config");
43bf612a 414
68ccb7ef
BB
415 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);
c21a2d95 421 layout2->addWidget(new QLabel(_("Find:"), this));
43bf612a
RZ
422 editField = new QLineEdit(this);
423 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
424 layout2->addWidget(editField);
c21a2d95 425 searchButton = new QPushButton(_("Search"), this);
68ccb7ef 426 searchButton->setAutoDefault(false);
43bf612a
RZ
427 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
428 layout2->addWidget(searchButton);
429 layout1->addLayout(layout2);
430
7fc925fd 431 split = new QSplitter(this);
7298b936 432 split->setOrientation(Qt::Vertical);
7fc925fd 433 list = new ConfigView(split, name);
7fc925fd 434 info = new ConfigInfoView(split, name);
43bf612a
RZ
435 connect(list->list, SIGNAL(menuChanged(struct menu *)),
436 info, SLOT(setInfo(struct menu *)));
63431e75
MC
437 connect(list->list, SIGNAL(menuChanged(struct menu *)),
438 parent, SLOT(setMenuLink(struct menu *)));
439
43bf612a 440 layout1->addWidget(split);
7fc925fd
RZ
441
442 if (name) {
68ccb7ef
BB
443 QVariant x, y;
444 int width, height;
7fc925fd
RZ
445 bool ok;
446
447 configSettings->beginGroup(name);
68ccb7ef
BB
448 width = configSettings->value("/window width", parent->width() / 2).toInt();
449 height = configSettings->value("/window height", parent->height() / 2).toInt();
7fc925fd 450 resize(width, height);
68ccb7ef
BB
451 x = configSettings->value("/window x");
452 y = configSettings->value("/window y");
453 if ((x.isValid())&&(y.isValid()))
454 move(x.toInt(), y.toInt());
041fbdc2 455 QList<int> sizes = configSettings->readSizes("/split", &ok);
7fc925fd
RZ
456 if (ok)
457 split->setSizes(sizes);
458 configSettings->endGroup();
459 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
460 }
461}
462
463void ConfigSearchWindow::saveSettings(void)
464{
68ccb7ef 465 /*if (name()) {
7fc925fd 466 configSettings->beginGroup(name());
68ccb7ef
BB
467 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());
7fc925fd
RZ
471 configSettings->writeSizes("/split", split->sizes());
472 configSettings->endGroup();
68ccb7ef 473 }*/
43bf612a
RZ
474}
475
476void ConfigSearchWindow::search(void)
477{
43bf612a
RZ
478}
479
1da177e4
LT
480/*
481 * Construct the complete config widget
482 */
483ConfigMainWindow::ConfigMainWindow(void)
f12aa704 484 : searchWindow(0)
1da177e4
LT
485{
486 QMenuBar* menu;
7fc925fd 487 bool ok;
68ccb7ef
BB
488 QVariant x, y;
489 int width, height;
a54bb701 490 char title[256];
1da177e4 491
8d90c97e 492 QDesktopWidget *d = configApp->desktop();
0954828f
AL
493 snprintf(title, sizeof(title), "%s%s",
494 rootmenu.prompt->text,
76a136c4 495 ""
76a136c4 496 );
68ccb7ef 497 setWindowTitle(title);
1da177e4 498
68ccb7ef
BB
499 width = configSettings->value("/window width", d->width() - 64).toInt();
500 height = configSettings->value("/window height", d->height() - 64).toInt();
1da177e4 501 resize(width, height);
68ccb7ef
BB
502 x = configSettings->value("/window x");
503 y = configSettings->value("/window y");
504 if ((x.isValid())&&(y.isValid()))
505 move(x.toInt(), y.toInt());
1da177e4
LT
506
507 split1 = new QSplitter(this);
7298b936 508 split1->setOrientation(Qt::Horizontal);
1da177e4
LT
509 setCentralWidget(split1);
510
7fc925fd 511 menuView = new ConfigView(split1, "menu");
1da177e4
LT
512 menuList = menuView->list;
513
514 split2 = new QSplitter(split1);
7298b936 515 split2->setOrientation(Qt::Vertical);
1da177e4
LT
516
517 // create config tree
7fc925fd 518 configView = new ConfigView(split2, "config");
1da177e4
LT
519 configList = configView->list;
520
7fc925fd 521 helpText = new ConfigInfoView(split2, "help");
68ccb7ef 522 //helpText->setTextFormat(Qt::RichText);
1da177e4
LT
523
524 setTabOrder(configList, helpText);
525 configList->setFocus();
526
527 menu = menuBar();
b1f8a45b 528 toolBar = new QToolBar("Tools", this);
29a70168 529 addToolBar(toolBar);
1da177e4 530
85eaf28a 531 backAction = new QAction(QPixmap(xpm_back), _("Back"), this);
1da177e4 532 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
68ccb7ef 533 backAction->setEnabled(false);
85eaf28a
BB
534 QAction *quitAction = new QAction(_("&Quit"), this);
535 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
1da177e4 536 connect(quitAction, SIGNAL(activated()), SLOT(close()));
85eaf28a
BB
537 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
538 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
1da177e4 539 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
85eaf28a
BB
540 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
541 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
1da177e4 542 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
3b354c55
KW
543 conf_set_changed_callback(conf_changed);
544 // Set saveAction's initial state
545 conf_changed();
85eaf28a 546 QAction *saveAsAction = new QAction(_("Save &As..."), this);
1da177e4 547 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
85eaf28a
BB
548 QAction *searchAction = new QAction(_("&Find"), this);
549 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
43bf612a 550 connect(searchAction, SIGNAL(activated()), SLOT(searchConfig()));
780505e3 551 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
68ccb7ef 552 singleViewAction->setCheckable(true);
1da177e4 553 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
780505e3 554 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
68ccb7ef 555 splitViewAction->setCheckable(true);
1da177e4 556 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
780505e3 557 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
68ccb7ef 558 fullViewAction->setCheckable(true);
1da177e4
LT
559 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
560
85eaf28a 561 QAction *showNameAction = new QAction(_("Show Name"), this);
68ccb7ef 562 showNameAction->setCheckable(true);
7fc925fd
RZ
563 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
564 connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool)));
9c86235a 565 showNameAction->setChecked(configView->showName());
85eaf28a 566 QAction *showRangeAction = new QAction(_("Show Range"), this);
68ccb7ef 567 showRangeAction->setCheckable(true);
7fc925fd
RZ
568 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
569 connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool)));
85eaf28a 570 QAction *showDataAction = new QAction(_("Show Data"), this);
68ccb7ef 571 showDataAction->setCheckable(true);
7fc925fd
RZ
572 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
573 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
39a4897c
LZ
574
575 QActionGroup *optGroup = new QActionGroup(this);
68ccb7ef 576 optGroup->setExclusive(true);
39a4897c
LZ
577 connect(optGroup, SIGNAL(selected(QAction *)), configView,
578 SLOT(setOptionMode(QAction *)));
579 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
580 SLOT(setOptionMode(QAction *)));
581
133c5f7c
AS
582 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);
68ccb7ef
BB
585 configView->showNormalAction->setCheckable(true);
586 configView->showAllAction->setCheckable(true);
587 configView->showPromptAction->setCheckable(true);
39a4897c 588
85eaf28a 589 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
68ccb7ef 590 showDebugAction->setCheckable(true);
43bf612a
RZ
591 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
592 connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool)));
9c86235a 593 showDebugAction->setChecked(helpText->showDebug());
1da177e4 594
85eaf28a 595 QAction *showIntroAction = new QAction( _("Introduction"), this);
1da177e4 596 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
85eaf28a 597 QAction *showAboutAction = new QAction( _("About"), this);
1da177e4
LT
598 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
599
600 // init tool bar
68ccb7ef 601 toolBar->addAction(backAction);
1da177e4 602 toolBar->addSeparator();
68ccb7ef
BB
603 toolBar->addAction(loadAction);
604 toolBar->addAction(saveAction);
1da177e4 605 toolBar->addSeparator();
68ccb7ef
BB
606 toolBar->addAction(singleViewAction);
607 toolBar->addAction(splitViewAction);
608 toolBar->addAction(fullViewAction);
1da177e4
LT
609
610 // create config menu
68ccb7ef
BB
611 QMenu* config = menu->addMenu(_("&File"));
612 config->addAction(loadAction);
613 config->addAction(saveAction);
614 config->addAction(saveAsAction);
76bede87 615 config->addSeparator();
68ccb7ef 616 config->addAction(quitAction);
1da177e4 617
66e7c723 618 // create edit menu
68ccb7ef
BB
619 QMenu* editMenu = menu->addMenu(_("&Edit"));
620 editMenu->addAction(searchAction);
66e7c723 621
1da177e4 622 // create options menu
68ccb7ef
BB
623 QMenu* optionMenu = menu->addMenu(_("&Option"));
624 optionMenu->addAction(showNameAction);
625 optionMenu->addAction(showRangeAction);
626 optionMenu->addAction(showDataAction);
76bede87 627 optionMenu->addSeparator();
68ccb7ef 628 optionMenu->addActions(optGroup->actions());
76bede87 629 optionMenu->addSeparator();
1da177e4
LT
630
631 // create help menu
76bede87 632 menu->addSeparator();
68ccb7ef
BB
633 QMenu* helpMenu = menu->addMenu(_("&Help"));
634 helpMenu->addAction(showIntroAction);
635 helpMenu->addAction(showAboutAction);
1da177e4 636
43bf612a
RZ
637 connect(configList, SIGNAL(menuChanged(struct menu *)),
638 helpText, SLOT(setInfo(struct menu *)));
1da177e4
LT
639 connect(configList, SIGNAL(menuSelected(struct menu *)),
640 SLOT(changeMenu(struct menu *)));
641 connect(configList, SIGNAL(parentSelected()),
642 SLOT(goBack()));
43bf612a
RZ
643 connect(menuList, SIGNAL(menuChanged(struct menu *)),
644 helpText, SLOT(setInfo(struct menu *)));
1da177e4
LT
645 connect(menuList, SIGNAL(menuSelected(struct menu *)),
646 SLOT(changeMenu(struct menu *)));
647
b65a47e1
RZ
648 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 *)),
1da177e4 653 SLOT(listFocusChanged(void)));
b65a47e1
RZ
654 connect(helpText, SIGNAL(menuSelected(struct menu *)),
655 SLOT(setMenuLink(struct menu *)));
1da177e4 656
68ccb7ef 657 QString listMode = configSettings->value("/listMode", "symbol").toString();
1da177e4
LT
658 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
041fbdc2 666 QList<int> sizes = configSettings->readSizes("/split1", &ok);
1da177e4
LT
667 if (ok)
668 split1->setSizes(sizes);
669
7fc925fd 670 sizes = configSettings->readSizes("/split2", &ok);
1da177e4
LT
671 if (ok)
672 split2->setSizes(sizes);
1da177e4
LT
673}
674
1da177e4
LT
675void ConfigMainWindow::loadConfig(void)
676{
68ccb7ef 677 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
1da177e4
LT
678 if (s.isNull())
679 return;
3b9fa093 680 if (conf_read(QFile::encodeName(s)))
c21a2d95 681 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
1da177e4
LT
682 ConfigView::updateListAll();
683}
684
bac6aa86 685bool ConfigMainWindow::saveConfig(void)
1da177e4 686{
bac6aa86 687 if (conf_write(NULL)) {
c21a2d95 688 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
bac6aa86
MM
689 return false;
690 }
691 return true;
1da177e4
LT
692}
693
694void ConfigMainWindow::saveConfigAs(void)
695{
68ccb7ef 696 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
1da177e4
LT
697 if (s.isNull())
698 return;
d49e4687 699 saveConfig();
1da177e4
LT
700}
701
43bf612a
RZ
702void ConfigMainWindow::searchConfig(void)
703{
704 if (!searchWindow)
7fc925fd 705 searchWindow = new ConfigSearchWindow(this, "search");
43bf612a
RZ
706 searchWindow->show();
707}
708
1da177e4
LT
709void ConfigMainWindow::changeMenu(struct menu *menu)
710{
76538660 711
1da177e4
LT
712}
713
b65a47e1 714void ConfigMainWindow::setMenuLink(struct menu *menu)
1da177e4 715{
1da177e4
LT
716}
717
b65a47e1
RZ
718void ConfigMainWindow::listFocusChanged(void)
719{
b65a47e1
RZ
720}
721
1da177e4
LT
722void ConfigMainWindow::goBack(void)
723{
1da177e4
LT
724}
725
726void ConfigMainWindow::showSingleView(void)
727{
780505e3
BB
728 singleViewAction->setEnabled(false);
729 singleViewAction->setChecked(true);
730 splitViewAction->setEnabled(true);
731 splitViewAction->setChecked(false);
732 fullViewAction->setEnabled(true);
733 fullViewAction->setChecked(false);
734
1da177e4 735 menuView->hide();
1da177e4
LT
736 configList->setFocus();
737}
738
739void ConfigMainWindow::showSplitView(void)
740{
780505e3
BB
741 singleViewAction->setEnabled(true);
742 singleViewAction->setChecked(false);
743 splitViewAction->setEnabled(false);
744 splitViewAction->setChecked(true);
745 fullViewAction->setEnabled(true);
746 fullViewAction->setChecked(false);
747
1da177e4
LT
748 menuView->show();
749 menuList->setFocus();
750}
751
752void ConfigMainWindow::showFullView(void)
753{
780505e3
BB
754 singleViewAction->setEnabled(true);
755 singleViewAction->setChecked(false);
756 splitViewAction->setEnabled(true);
757 splitViewAction->setChecked(false);
758 fullViewAction->setEnabled(false);
759 fullViewAction->setChecked(true);
760
1da177e4 761 menuView->hide();
1da177e4
LT
762 configList->setFocus();
763}
764
1da177e4
LT
765/*
766 * ask for saving configuration before quitting
767 * TODO ask only when something changed
768 */
769void ConfigMainWindow::closeEvent(QCloseEvent* e)
770{
b3214293 771 if (!conf_get_changed()) {
1da177e4
LT
772 e->accept();
773 return;
774 }
c21a2d95 775 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
1da177e4 776 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
c21a2d95
EG
777 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
778 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
779 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
1da177e4
LT
780 switch (mb.exec()) {
781 case QMessageBox::Yes:
bac6aa86
MM
782 if (saveConfig())
783 e->accept();
784 else
785 e->ignore();
786 break;
1da177e4
LT
787 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{
652cf982 798 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
1da177e4
LT
799 "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"
c21a2d95 808 "which you can then match by examining other options.\n\n");
1da177e4
LT
809
810 QMessageBox::information(this, "qconf", str);
811}
812
813void ConfigMainWindow::showAbout(void)
814{
c21a2d95
EG
815 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");
1da177e4
LT
817
818 QMessageBox::information(this, "qconf", str);
819}
820
821void ConfigMainWindow::saveSettings(void)
822{
68ccb7ef
BB
823 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());
1da177e4
LT
827
828 QString entry;
98403a91 829
68ccb7ef 830 configSettings->setValue("/listMode", entry);
1da177e4 831
7fc925fd
RZ
832 configSettings->writeSizes("/split1", split1->sizes());
833 configSettings->writeSizes("/split2", split2->sizes());
1da177e4
LT
834}
835
3b354c55
KW
836void ConfigMainWindow::conf_changed(void)
837{
838 if (saveAction)
839 saveAction->setEnabled(conf_get_changed());
840}
841
1da177e4
LT
842void 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{
68ccb7ef 862 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
1da177e4
LT
863 exit(0);
864}
865
866int main(int ac, char** av)
867{
868 ConfigMainWindow* v;
869 const char *name;
870
3b9fa093
ACM
871 bindtextdomain(PACKAGE, LOCALEDIR);
872 textdomain(PACKAGE);
873
1da177e4
LT
874 progname = av[0];
875 configApp = new QApplication(ac, av);
876 if (ac > 1 && av[1][0] == '-') {
877 switch (av[1][1]) {
0a1f00a1
MM
878 case 's':
879 conf_set_message_callback(NULL);
880 break;
1da177e4
LT
881 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
7fc925fd
RZ
896 configSettings = new ConfigSettings();
897 configSettings->beginGroup("/kconfig/qconf");
1da177e4
LT
898 v = new ConfigMainWindow();
899
900 //zconfdump(stdout);
1da177e4
LT
901 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
902 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
43bf612a 903 v->show();
1da177e4
LT
904 configApp->exec();
905
7fc925fd
RZ
906 configSettings->endGroup();
907 delete configSettings;
908
1da177e4
LT
909 return 0;
910}