Port xconfig to Qt5 - update signals
[deliverable/linux.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{
92119937 93 connect(this, SIGNAL(editingFinished()), SLOT(hide()));
43bf612a
RZ
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;
92119937 487 bool ok = true;
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);
92119937 532 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
68ccb7ef 533 backAction->setEnabled(false);
85eaf28a
BB
534 QAction *quitAction = new QAction(_("&Quit"), this);
535 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
92119937 536 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
85eaf28a
BB
537 QAction *loadAction = new QAction(QPixmap(xpm_load), _("&Load"), this);
538 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
92119937 539 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
85eaf28a
BB
540 saveAction = new QAction(QPixmap(xpm_save), _("&Save"), this);
541 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
92119937 542 connect(saveAction, SIGNAL(triggered(bool)), 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);
92119937 547 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
85eaf28a
BB
548 QAction *searchAction = new QAction(_("&Find"), this);
549 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
92119937 550 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
780505e3 551 singleViewAction = new QAction(QPixmap(xpm_single_view), _("Single View"), this);
68ccb7ef 552 singleViewAction->setCheckable(true);
92119937 553 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
780505e3 554 splitViewAction = new QAction(QPixmap(xpm_split_view), _("Split View"), this);
68ccb7ef 555 splitViewAction->setCheckable(true);
92119937 556 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
780505e3 557 fullViewAction = new QAction(QPixmap(xpm_tree_view), _("Full View"), this);
68ccb7ef 558 fullViewAction->setCheckable(true);
92119937 559 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
1da177e4 560
85eaf28a 561 QAction *showNameAction = new QAction(_("Show Name"), this);
68ccb7ef 562 showNameAction->setCheckable(true);
7fc925fd 563 connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool)));
9c86235a 564 showNameAction->setChecked(configView->showName());
85eaf28a 565 QAction *showRangeAction = new QAction(_("Show Range"), this);
68ccb7ef 566 showRangeAction->setCheckable(true);
7fc925fd 567 connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool)));
85eaf28a 568 QAction *showDataAction = new QAction(_("Show Data"), this);
68ccb7ef 569 showDataAction->setCheckable(true);
7fc925fd 570 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
39a4897c
LZ
571
572 QActionGroup *optGroup = new QActionGroup(this);
68ccb7ef 573 optGroup->setExclusive(true);
92119937 574 connect(optGroup, SIGNAL(triggered(QAction*)), configView,
39a4897c 575 SLOT(setOptionMode(QAction *)));
92119937 576 connect(optGroup, SIGNAL(triggered(QAction *)), menuView,
39a4897c
LZ
577 SLOT(setOptionMode(QAction *)));
578
133c5f7c
AS
579 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);
68ccb7ef
BB
582 configView->showNormalAction->setCheckable(true);
583 configView->showAllAction->setCheckable(true);
584 configView->showPromptAction->setCheckable(true);
39a4897c 585
85eaf28a 586 QAction *showDebugAction = new QAction( _("Show Debug Info"), this);
68ccb7ef 587 showDebugAction->setCheckable(true);
43bf612a 588 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
9c86235a 589 showDebugAction->setChecked(helpText->showDebug());
1da177e4 590
85eaf28a 591 QAction *showIntroAction = new QAction( _("Introduction"), this);
92119937 592 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
85eaf28a 593 QAction *showAboutAction = new QAction( _("About"), this);
92119937 594 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
1da177e4
LT
595
596 // init tool bar
68ccb7ef 597 toolBar->addAction(backAction);
1da177e4 598 toolBar->addSeparator();
68ccb7ef
BB
599 toolBar->addAction(loadAction);
600 toolBar->addAction(saveAction);
1da177e4 601 toolBar->addSeparator();
68ccb7ef
BB
602 toolBar->addAction(singleViewAction);
603 toolBar->addAction(splitViewAction);
604 toolBar->addAction(fullViewAction);
1da177e4
LT
605
606 // create config menu
68ccb7ef
BB
607 QMenu* config = menu->addMenu(_("&File"));
608 config->addAction(loadAction);
609 config->addAction(saveAction);
610 config->addAction(saveAsAction);
76bede87 611 config->addSeparator();
68ccb7ef 612 config->addAction(quitAction);
1da177e4 613
66e7c723 614 // create edit menu
68ccb7ef
BB
615 QMenu* editMenu = menu->addMenu(_("&Edit"));
616 editMenu->addAction(searchAction);
66e7c723 617
1da177e4 618 // create options menu
68ccb7ef
BB
619 QMenu* optionMenu = menu->addMenu(_("&Option"));
620 optionMenu->addAction(showNameAction);
621 optionMenu->addAction(showRangeAction);
622 optionMenu->addAction(showDataAction);
76bede87 623 optionMenu->addSeparator();
68ccb7ef 624 optionMenu->addActions(optGroup->actions());
76bede87 625 optionMenu->addSeparator();
1da177e4
LT
626
627 // create help menu
76bede87 628 menu->addSeparator();
68ccb7ef
BB
629 QMenu* helpMenu = menu->addMenu(_("&Help"));
630 helpMenu->addAction(showIntroAction);
631 helpMenu->addAction(showAboutAction);
1da177e4 632
b65a47e1
RZ
633 connect(helpText, SIGNAL(menuSelected(struct menu *)),
634 SLOT(setMenuLink(struct menu *)));
1da177e4 635
68ccb7ef 636 QString listMode = configSettings->value("/listMode", "symbol").toString();
1da177e4
LT
637 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
041fbdc2 645 QList<int> sizes = configSettings->readSizes("/split1", &ok);
1da177e4
LT
646 if (ok)
647 split1->setSizes(sizes);
648
7fc925fd 649 sizes = configSettings->readSizes("/split2", &ok);
1da177e4
LT
650 if (ok)
651 split2->setSizes(sizes);
1da177e4
LT
652}
653
1da177e4
LT
654void ConfigMainWindow::loadConfig(void)
655{
68ccb7ef 656 QString s = QFileDialog::getOpenFileName(this, "", conf_get_configname());
1da177e4
LT
657 if (s.isNull())
658 return;
3b9fa093 659 if (conf_read(QFile::encodeName(s)))
c21a2d95 660 QMessageBox::information(this, "qconf", _("Unable to load configuration!"));
1da177e4
LT
661 ConfigView::updateListAll();
662}
663
bac6aa86 664bool ConfigMainWindow::saveConfig(void)
1da177e4 665{
bac6aa86 666 if (conf_write(NULL)) {
c21a2d95 667 QMessageBox::information(this, "qconf", _("Unable to save configuration!"));
bac6aa86
MM
668 return false;
669 }
670 return true;
1da177e4
LT
671}
672
673void ConfigMainWindow::saveConfigAs(void)
674{
68ccb7ef 675 QString s = QFileDialog::getSaveFileName(this, "", conf_get_configname());
1da177e4
LT
676 if (s.isNull())
677 return;
d49e4687 678 saveConfig();
1da177e4
LT
679}
680
43bf612a
RZ
681void ConfigMainWindow::searchConfig(void)
682{
683 if (!searchWindow)
7fc925fd 684 searchWindow = new ConfigSearchWindow(this, "search");
43bf612a
RZ
685 searchWindow->show();
686}
687
1da177e4
LT
688void ConfigMainWindow::changeMenu(struct menu *menu)
689{
76538660 690
1da177e4
LT
691}
692
b65a47e1 693void ConfigMainWindow::setMenuLink(struct menu *menu)
1da177e4 694{
1da177e4
LT
695}
696
b65a47e1
RZ
697void ConfigMainWindow::listFocusChanged(void)
698{
b65a47e1
RZ
699}
700
1da177e4
LT
701void ConfigMainWindow::goBack(void)
702{
1da177e4
LT
703}
704
705void ConfigMainWindow::showSingleView(void)
706{
780505e3
BB
707 singleViewAction->setEnabled(false);
708 singleViewAction->setChecked(true);
709 splitViewAction->setEnabled(true);
710 splitViewAction->setChecked(false);
711 fullViewAction->setEnabled(true);
712 fullViewAction->setChecked(false);
713
1da177e4 714 menuView->hide();
1da177e4
LT
715 configList->setFocus();
716}
717
718void ConfigMainWindow::showSplitView(void)
719{
780505e3
BB
720 singleViewAction->setEnabled(true);
721 singleViewAction->setChecked(false);
722 splitViewAction->setEnabled(false);
723 splitViewAction->setChecked(true);
724 fullViewAction->setEnabled(true);
725 fullViewAction->setChecked(false);
726
1da177e4
LT
727 menuView->show();
728 menuList->setFocus();
729}
730
731void ConfigMainWindow::showFullView(void)
732{
780505e3
BB
733 singleViewAction->setEnabled(true);
734 singleViewAction->setChecked(false);
735 splitViewAction->setEnabled(true);
736 splitViewAction->setChecked(false);
737 fullViewAction->setEnabled(false);
738 fullViewAction->setChecked(true);
739
1da177e4 740 menuView->hide();
1da177e4
LT
741 configList->setFocus();
742}
743
1da177e4
LT
744/*
745 * ask for saving configuration before quitting
746 * TODO ask only when something changed
747 */
748void ConfigMainWindow::closeEvent(QCloseEvent* e)
749{
b3214293 750 if (!conf_get_changed()) {
1da177e4
LT
751 e->accept();
752 return;
753 }
c21a2d95 754 QMessageBox mb("qconf", _("Save configuration?"), QMessageBox::Warning,
1da177e4 755 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
c21a2d95
EG
756 mb.setButtonText(QMessageBox::Yes, _("&Save Changes"));
757 mb.setButtonText(QMessageBox::No, _("&Discard Changes"));
758 mb.setButtonText(QMessageBox::Cancel, _("Cancel Exit"));
1da177e4
LT
759 switch (mb.exec()) {
760 case QMessageBox::Yes:
bac6aa86
MM
761 if (saveConfig())
762 e->accept();
763 else
764 e->ignore();
765 break;
1da177e4
LT
766 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{
652cf982 777 static const QString str = _("Welcome to the qconf graphical configuration tool.\n\n"
1da177e4
LT
778 "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"
c21a2d95 787 "which you can then match by examining other options.\n\n");
1da177e4
LT
788
789 QMessageBox::information(this, "qconf", str);
790}
791
792void ConfigMainWindow::showAbout(void)
793{
c21a2d95
EG
794 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");
1da177e4
LT
796
797 QMessageBox::information(this, "qconf", str);
798}
799
800void ConfigMainWindow::saveSettings(void)
801{
68ccb7ef
BB
802 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());
1da177e4
LT
806
807 QString entry;
98403a91 808
68ccb7ef 809 configSettings->setValue("/listMode", entry);
1da177e4 810
7fc925fd
RZ
811 configSettings->writeSizes("/split1", split1->sizes());
812 configSettings->writeSizes("/split2", split2->sizes());
1da177e4
LT
813}
814
3b354c55
KW
815void ConfigMainWindow::conf_changed(void)
816{
817 if (saveAction)
818 saveAction->setEnabled(conf_get_changed());
819}
820
1da177e4
LT
821void 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{
68ccb7ef 841 printf(_("%s [-s] <config>\n").toLatin1().constData(), progname);
1da177e4
LT
842 exit(0);
843}
844
845int main(int ac, char** av)
846{
847 ConfigMainWindow* v;
848 const char *name;
849
3b9fa093
ACM
850 bindtextdomain(PACKAGE, LOCALEDIR);
851 textdomain(PACKAGE);
852
1da177e4
LT
853 progname = av[0];
854 configApp = new QApplication(ac, av);
855 if (ac > 1 && av[1][0] == '-') {
856 switch (av[1][1]) {
0a1f00a1
MM
857 case 's':
858 conf_set_message_callback(NULL);
859 break;
1da177e4
LT
860 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
7fc925fd
RZ
875 configSettings = new ConfigSettings();
876 configSettings->beginGroup("/kconfig/qconf");
1da177e4
LT
877 v = new ConfigMainWindow();
878
879 //zconfdump(stdout);
1da177e4
LT
880 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
881 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
43bf612a 882 v->show();
1da177e4
LT
883 configApp->exec();
884
7fc925fd
RZ
885 configSettings->endGroup();
886 delete configSettings;
887
1da177e4
LT
888 return 0;
889}
This page took 1.032624 seconds and 5 git commands to generate.