1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>
8 #include <QApplication>
11 #include <QDesktopWidget>
12 #include <QFileDialog>
18 #include <QMessageBox>
29 static QApplication *configApp;
30 static ConfigSettings *configSettings;
32 QAction *ConfigMainWindow::saveAction;
34 ConfigSettings::ConfigSettings()
35 : QSettings("kernel.org", "qconf")
40 * Reads a list of integer values from the application settings.
42 QList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
48 QStringList entryList = value(key).toStringList();
49 QStringList::Iterator it;
51 for (it = entryList.begin(); it != entryList.end(); ++it)
52 result.push_back((*it).toInt());
63 * Writes a list of integer values to the application settings.
65 bool ConfigSettings::writeSizes(const QString& key, const QList<int>& value)
67 QStringList stringList;
68 QList<int>::ConstIterator it;
70 for (it = value.begin(); it != value.end(); ++it)
71 stringList.push_back(QString::number(*it));
72 setValue(key, stringList);
77 QIcon ConfigItem::symbolYesIcon;
78 QIcon ConfigItem::symbolModIcon;
79 QIcon ConfigItem::symbolNoIcon;
80 QIcon ConfigItem::choiceYesIcon;
81 QIcon ConfigItem::choiceNoIcon;
82 QIcon ConfigItem::menuIcon;
83 QIcon ConfigItem::menubackIcon;
86 * update the displayed of a menu entry
88 void ConfigItem::updateMenu(void)
92 struct property *prop;
99 setIcon(promptColIdx, menubackIcon);
106 prompt = menu_get_prompt(menu);
108 if (prop) switch (prop->type) {
110 if (list->mode == singleMode || list->mode == symbolMode) {
111 /* a menuconfig entry is displayed differently
112 * depending whether it's at the view root or a child.
114 if (sym && list->rootEntry == menu)
116 setIcon(promptColIdx, menuIcon);
120 setIcon(promptColIdx, QIcon());
124 setIcon(promptColIdx, QIcon());
132 setText(nameColIdx, sym->name);
134 type = sym_get_type(sym);
140 if (!sym_is_changeable(sym) && list->optMode == normalOpt) {
141 setIcon(promptColIdx, QIcon());
144 expr = sym_get_tristate_value(sym);
147 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
148 setIcon(promptColIdx, choiceYesIcon);
150 setIcon(promptColIdx, symbolYesIcon);
154 setIcon(promptColIdx, symbolModIcon);
158 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
159 setIcon(promptColIdx, choiceNoIcon);
161 setIcon(promptColIdx, symbolNoIcon);
166 setText(dataColIdx, QChar(ch));
171 setText(dataColIdx, sym_get_string_value(sym));
174 if (!sym_has_value(sym) && visible)
177 setText(promptColIdx, prompt);
180 void ConfigItem::testUpdateMenu(bool v)
188 sym_calc_value(menu->sym);
189 if (menu->flags & MENU_CHANGED) {
190 /* the menu entry changed, so update all list items */
191 menu->flags &= ~MENU_CHANGED;
192 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
194 } else if (listView()->updateAll)
200 * construct a menu entry
202 void ConfigItem::init(void)
205 ConfigList* list = listView();
206 nextItem = (ConfigItem*)menu->data;
209 if (list->mode != fullMode)
211 sym_calc_value(menu->sym);
214 enum symbol_type type = menu->sym->type;
216 // Allow to edit "int", "hex", and "string" in-place in
217 // the data column. Unfortunately, you cannot specify
218 // the flags per column. Set ItemIsEditable for all
219 // columns here, and check the column in createEditor().
220 if (type == S_INT || type == S_HEX || type == S_STRING)
221 setFlags(flags() | Qt::ItemIsEditable);
228 * destruct a menu entry
230 ConfigItem::~ConfigItem(void)
233 ConfigItem** ip = (ConfigItem**)&menu->data;
234 for (; *ip; ip = &(*ip)->nextItem) {
243 QWidget *ConfigItemDelegate::createEditor(QWidget *parent,
244 const QStyleOptionViewItem &option,
245 const QModelIndex &index) const
249 // Only the data column is editable
250 if (index.column() != dataColIdx)
253 // You cannot edit invisible menus
254 item = static_cast<ConfigItem *>(index.internalPointer());
255 if (!item || !item->menu || !menu_is_visible(item->menu))
258 return QStyledItemDelegate::createEditor(parent, option, index);
261 void ConfigItemDelegate::setModelData(QWidget *editor,
262 QAbstractItemModel *model,
263 const QModelIndex &index) const
270 lineEdit = qobject_cast<QLineEdit *>(editor);
271 // If this is not a QLineEdit, use the parent's default.
272 // (does this happen?)
276 item = static_cast<ConfigItem *>(index.internalPointer());
277 if (!item || !item->menu)
280 sym = item->menu->sym;
284 success = sym_set_string_value(sym, lineEdit->text().toUtf8().data());
286 ConfigList::updateListForAll();
288 QMessageBox::information(editor, "qconf",
289 "Cannot set the data (maybe due to out of range).\n"
290 "Setting the old value.");
291 lineEdit->setText(sym_get_string_value(sym));
295 QStyledItemDelegate::setModelData(editor, model, index);
298 ConfigList::ConfigList(QWidget *parent, const char *name)
299 : QTreeWidget(parent),
301 showName(false), mode(singleMode), optMode(normalOpt),
302 rootEntry(0), headerPopup(0)
305 setSortingEnabled(false);
306 setRootIsDecorated(true);
308 setVerticalScrollMode(ScrollPerPixel);
309 setHorizontalScrollMode(ScrollPerPixel);
311 setHeaderLabels(QStringList() << "Option" << "Name" << "Value");
313 connect(this, SIGNAL(itemSelectionChanged(void)),
314 SLOT(updateSelection(void)));
317 configSettings->beginGroup(name);
318 showName = configSettings->value("/showName", false).toBool();
319 optMode = (enum optionMode)configSettings->value("/optionMode", 0).toInt();
320 configSettings->endGroup();
321 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
324 showColumn(promptColIdx);
326 setItemDelegate(new ConfigItemDelegate(this));
328 allLists.append(this);
333 ConfigList::~ConfigList()
335 allLists.removeOne(this);
338 bool ConfigList::menuSkip(struct menu *menu)
340 if (optMode == normalOpt && menu_is_visible(menu))
342 if (optMode == promptOpt && menu_has_prompt(menu))
344 if (optMode == allOpt)
349 void ConfigList::reinit(void)
351 hideColumn(nameColIdx);
354 showColumn(nameColIdx);
359 void ConfigList::setOptionMode(QAction *action)
361 if (action == showNormalAction)
363 else if (action == showAllAction)
371 void ConfigList::saveSettings(void)
373 if (!objectName().isEmpty()) {
374 configSettings->beginGroup(objectName());
375 configSettings->setValue("/showName", showName);
376 configSettings->setValue("/optionMode", (int)optMode);
377 configSettings->endGroup();
381 ConfigItem* ConfigList::findConfigItem(struct menu *menu)
383 ConfigItem* item = (ConfigItem*)menu->data;
385 for (; item; item = item->nextItem) {
386 if (this == item->listView())
393 void ConfigList::updateSelection(void)
398 if (selectedItems().count() == 0)
401 ConfigItem* item = (ConfigItem*)selectedItems().first();
406 emit menuChanged(menu);
409 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
410 if (mode == menuMode && type == P_MENU)
411 emit menuSelected(menu);
414 void ConfigList::updateList()
416 ConfigItem* last = 0;
420 if (mode != listMode)
422 QTreeWidgetItemIterator it(this);
425 item = (ConfigItem*)(*it);
428 item->testUpdateMenu(menu_is_visible(item->menu));
435 if (rootEntry != &rootmenu && (mode == singleMode ||
436 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
437 item = (ConfigItem *)topLevelItem(0);
439 item = new ConfigItem(this, 0, true);
442 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
443 rootEntry->sym && rootEntry->prompt) {
444 item = last ? last->nextSibling() : nullptr;
446 item = new ConfigItem(this, last, rootEntry, true);
448 item->testUpdateMenu(true);
450 updateMenuList(item, rootEntry);
452 resizeColumnToContents(0);
456 updateMenuList(rootEntry);
458 resizeColumnToContents(0);
461 void ConfigList::updateListForAll()
463 QListIterator<ConfigList *> it(allLists);
465 while (it.hasNext()) {
466 ConfigList *list = it.next();
472 void ConfigList::updateListAllForAll()
474 QListIterator<ConfigList *> it(allLists);
476 while (it.hasNext()) {
477 ConfigList *list = it.next();
483 void ConfigList::setValue(ConfigItem* item, tristate val)
489 sym = item->menu ? item->menu->sym : 0;
493 type = sym_get_type(sym);
497 oldval = sym_get_tristate_value(sym);
499 if (!sym_set_tristate_value(sym, val))
501 if (oldval == no && item->menu->list)
502 item->setExpanded(true);
503 ConfigList::updateListForAll();
508 void ConfigList::changeValue(ConfigItem* item)
512 int type, oldexpr, newexpr;
519 if (item->menu->list)
520 item->setExpanded(!item->isExpanded());
524 type = sym_get_type(sym);
528 oldexpr = sym_get_tristate_value(sym);
529 newexpr = sym_toggle_tristate_value(sym);
530 if (item->menu->list) {
531 if (oldexpr == newexpr)
532 item->setExpanded(!item->isExpanded());
533 else if (oldexpr == no)
534 item->setExpanded(true);
536 if (oldexpr != newexpr)
537 ConfigList::updateListForAll();
544 void ConfigList::setRootMenu(struct menu *menu)
548 if (rootEntry == menu)
550 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
557 setSelected(currentItem(), hasFocus());
558 scrollToItem(currentItem());
562 void ConfigList::setParentMenu(void)
565 struct menu *oldroot;
568 if (rootEntry == &rootmenu)
570 setRootMenu(menu_get_parent_menu(rootEntry->parent));
572 QTreeWidgetItemIterator it(this);
574 item = (ConfigItem *)(*it);
575 if (item->menu == oldroot) {
576 setCurrentItem(item);
586 * update all the children of a menu entry
587 * removes/adds the entries from the parent widget as necessary
589 * parent: either the menu list widget or a menu entry widget
590 * menu: entry to be updated
592 void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
601 while (parent->childCount() > 0)
603 delete parent->takeChild(0);
609 last = parent->firstChild();
610 if (last && !last->goParent)
612 for (child = menu->list; child; child = child->next) {
613 item = last ? last->nextSibling() : parent->firstChild();
614 type = child->prompt ? child->prompt->type : P_UNKNOWN;
618 if (!(child->flags & MENU_ROOT))
622 if (child->flags & MENU_ROOT)
629 visible = menu_is_visible(child);
630 if (!menuSkip(child)) {
631 if (!child->sym && !child->list && !child->prompt)
633 if (!item || item->menu != child)
634 item = new ConfigItem(parent, last, child, visible);
636 item->testUpdateMenu(visible);
638 if (mode == fullMode || mode == menuMode || type != P_MENU)
639 updateMenuList(item, child);
641 updateMenuList(item, 0);
646 if (item && item->menu == child) {
647 last = parent->firstChild();
650 else while (last->nextSibling() != item)
651 last = last->nextSibling();
657 void ConfigList::updateMenuList(struct menu *menu)
666 while (topLevelItemCount() > 0)
668 delete takeTopLevelItem(0);
674 last = (ConfigItem *)topLevelItem(0);
675 if (last && !last->goParent)
677 for (child = menu->list; child; child = child->next) {
678 item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0);
679 type = child->prompt ? child->prompt->type : P_UNKNOWN;
683 if (!(child->flags & MENU_ROOT))
687 if (child->flags & MENU_ROOT)
694 visible = menu_is_visible(child);
695 if (!menuSkip(child)) {
696 if (!child->sym && !child->list && !child->prompt)
698 if (!item || item->menu != child)
699 item = new ConfigItem(this, last, child, visible);
701 item->testUpdateMenu(visible);
703 if (mode == fullMode || mode == menuMode || type != P_MENU)
704 updateMenuList(item, child);
706 updateMenuList(item, 0);
711 if (item && item->menu == child) {
712 last = (ConfigItem *)topLevelItem(0);
715 else while (last->nextSibling() != item)
716 last = last->nextSibling();
722 void ConfigList::keyPressEvent(QKeyEvent* ev)
724 QTreeWidgetItem* i = currentItem();
729 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
730 emit parentSelected();
736 Parent::keyPressEvent(ev);
739 item = (ConfigItem*)i;
744 if (item->goParent) {
745 emit parentSelected();
751 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
752 if (type == P_MENU && rootEntry != menu &&
753 mode != fullMode && mode != menuMode) {
754 if (mode == menuMode)
755 emit menuSelected(menu);
757 emit itemSelected(menu);
773 Parent::keyPressEvent(ev);
779 void ConfigList::mousePressEvent(QMouseEvent* e)
781 //QPoint p(contentsToViewport(e->pos()));
782 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
783 Parent::mousePressEvent(e);
786 void ConfigList::mouseReleaseEvent(QMouseEvent* e)
789 ConfigItem* item = (ConfigItem*)itemAt(p);
791 enum prop_type ptype;
799 x = header()->offset() + p.x();
800 idx = header()->logicalIndexAt(x);
803 icon = item->icon(promptColIdx);
804 if (!icon.isNull()) {
805 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
806 if (x >= off && x < off + icon.availableSizes().first().width()) {
807 if (item->goParent) {
808 emit parentSelected();
812 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
813 if (ptype == P_MENU && rootEntry != menu &&
814 mode != fullMode && mode != menuMode &&
816 emit menuSelected(menu);
828 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
829 Parent::mouseReleaseEvent(e);
832 void ConfigList::mouseMoveEvent(QMouseEvent* e)
834 //QPoint p(contentsToViewport(e->pos()));
835 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
836 Parent::mouseMoveEvent(e);
839 void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
842 ConfigItem* item = (ConfigItem*)itemAt(p);
844 enum prop_type ptype;
848 if (item->goParent) {
849 emit parentSelected();
855 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
856 if (ptype == P_MENU && mode != listMode) {
857 if (mode == singleMode)
858 emit itemSelected(menu);
859 else if (mode == symbolMode)
860 emit menuSelected(menu);
861 } else if (menu->sym)
865 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
866 Parent::mouseDoubleClickEvent(e);
869 void ConfigList::focusInEvent(QFocusEvent *e)
871 struct menu *menu = NULL;
873 Parent::focusInEvent(e);
875 ConfigItem* item = (ConfigItem *)currentItem();
877 setSelected(item, true);
883 void ConfigList::contextMenuEvent(QContextMenuEvent *e)
888 headerPopup = new QMenu(this);
889 action = new QAction("Show Name", this);
890 action->setCheckable(true);
891 connect(action, SIGNAL(toggled(bool)),
892 SLOT(setShowName(bool)));
893 connect(this, SIGNAL(showNameChanged(bool)),
894 action, SLOT(setChecked(bool)));
895 action->setChecked(showName);
896 headerPopup->addAction(action);
899 headerPopup->exec(e->globalPos());
903 void ConfigList::setShowName(bool on)
910 emit showNameChanged(on);
913 QList<ConfigList *> ConfigList::allLists;
914 QAction *ConfigList::showNormalAction;
915 QAction *ConfigList::showAllAction;
916 QAction *ConfigList::showPromptAction;
918 void ConfigList::setAllOpen(bool open)
920 QTreeWidgetItemIterator it(this);
923 (*it)->setExpanded(open);
929 ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
930 : Parent(parent), sym(0), _menu(0)
935 if (!objectName().isEmpty()) {
936 configSettings->beginGroup(objectName());
937 setShowDebug(configSettings->value("/showDebug", false).toBool());
938 configSettings->endGroup();
939 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
942 contextMenu = createStandardContextMenu();
943 QAction *action = new QAction("Show Debug Info", contextMenu);
945 action->setCheckable(true);
946 connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
947 connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setChecked(bool)));
948 action->setChecked(showDebug());
949 contextMenu->addSeparator();
950 contextMenu->addAction(action);
953 void ConfigInfoView::saveSettings(void)
955 if (!objectName().isEmpty()) {
956 configSettings->beginGroup(objectName());
957 configSettings->setValue("/showDebug", showDebug());
958 configSettings->endGroup();
962 void ConfigInfoView::setShowDebug(bool b)
964 if (_showDebug != b) {
970 emit showDebugChanged(b);
974 void ConfigInfoView::setInfo(struct menu *m)
986 void ConfigInfoView::symbolInfo(void)
990 str += "<big>Symbol: <b>";
991 str += print_filter(sym->name);
992 str += "</b></big><br><br>value: ";
993 str += print_filter(sym_get_string_value(sym));
994 str += "<br>visibility: ";
995 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
997 str += debug_info(sym);
1002 void ConfigInfoView::menuInfo(void)
1006 QTextStream stream(&info);
1010 if (_menu->prompt) {
1011 stream << "<big><b>";
1012 stream << print_filter(_menu->prompt->text);
1013 stream << "</b></big>";
1017 stream << "<a href=\"s" << sym->name << "\">";
1018 stream << print_filter(sym->name);
1023 } else if (sym->name) {
1024 stream << "<big><b>";
1026 stream << "<a href=\"s" << sym->name << "\">";
1027 stream << print_filter(sym->name);
1030 stream << "</b></big>";
1032 stream << "<br><br>";
1035 stream << debug_info(sym);
1037 struct gstr help_gstr = str_new();
1039 menu_get_ext_help(_menu, &help_gstr);
1040 stream << print_filter(str_get(&help_gstr));
1041 str_free(&help_gstr);
1042 } else if (_menu->prompt) {
1043 stream << "<big><b>";
1044 stream << print_filter(_menu->prompt->text);
1045 stream << "</b></big><br><br>";
1047 if (_menu->prompt->visible.expr) {
1048 stream << " dep: ";
1049 expr_print(_menu->prompt->visible.expr,
1050 expr_print_help, &stream, E_NONE);
1051 stream << "<br><br>";
1054 stream << "defined at " << _menu->file->name << ":"
1055 << _menu->lineno << "<br><br>";
1062 QString ConfigInfoView::debug_info(struct symbol *sym)
1065 QTextStream stream(&debug);
1068 stream << print_filter(sym_type_name(sym->type));
1069 if (sym_is_choice(sym))
1070 stream << " (choice)";
1072 if (sym->rev_dep.expr) {
1073 stream << "reverse dep: ";
1074 expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE);
1077 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1078 switch (prop->type) {
1081 stream << "prompt: <a href=\"m" << sym->name << "\">";
1082 stream << print_filter(prop->text);
1083 stream << "</a><br>";
1091 stream << prop_get_type_name(prop->type);
1093 expr_print(prop->expr, expr_print_help,
1098 if (sym_is_choice(sym)) {
1099 stream << "choice: ";
1100 expr_print(prop->expr, expr_print_help,
1106 stream << "unknown property: ";
1107 stream << prop_get_type_name(prop->type);
1110 if (prop->visible.expr) {
1111 stream << " dep: ";
1112 expr_print(prop->visible.expr, expr_print_help,
1122 QString ConfigInfoView::print_filter(const QString &str)
1124 QRegExp re("[<>&\"\\n]");
1126 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1127 switch (res[i].toLatin1()) {
1129 res.replace(i, 1, "<");
1133 res.replace(i, 1, ">");
1137 res.replace(i, 1, "&");
1141 res.replace(i, 1, """);
1145 res.replace(i, 1, "<br>");
1153 void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
1155 QTextStream *stream = reinterpret_cast<QTextStream *>(data);
1157 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1158 *stream << "<a href=\"s" << sym->name << "\">";
1159 *stream << print_filter(str);
1162 *stream << print_filter(str);
1166 void ConfigInfoView::clicked(const QUrl &url)
1168 QByteArray str = url.toEncoded();
1169 const std::size_t count = str.size();
1170 char *data = new char[count + 1];
1171 struct symbol **result;
1172 struct menu *m = NULL;
1179 memcpy(data, str.constData(), count);
1182 /* Seek for exact match */
1185 result = sym_re_search(data);
1193 /* Seek for the menu which holds the symbol */
1194 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1195 if (prop->type != P_PROMPT && prop->type != P_MENU)
1202 /* Symbol is not visible as a menu */
1204 emit showDebugChanged(true);
1206 emit menuSelected(m);
1213 void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event)
1215 contextMenu->popup(event->globalPos());
1219 ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent)
1220 : Parent(parent), result(NULL)
1222 setObjectName("search");
1223 setWindowTitle("Search Config");
1225 QVBoxLayout* layout1 = new QVBoxLayout(this);
1226 layout1->setContentsMargins(11, 11, 11, 11);
1227 layout1->setSpacing(6);
1229 QHBoxLayout* layout2 = new QHBoxLayout();
1230 layout2->setContentsMargins(0, 0, 0, 0);
1231 layout2->setSpacing(6);
1232 layout2->addWidget(new QLabel("Find:", this));
1233 editField = new QLineEdit(this);
1234 connect(editField, SIGNAL(returnPressed()), SLOT(search()));
1235 layout2->addWidget(editField);
1236 searchButton = new QPushButton("Search", this);
1237 searchButton->setAutoDefault(false);
1238 connect(searchButton, SIGNAL(clicked()), SLOT(search()));
1239 layout2->addWidget(searchButton);
1240 layout1->addLayout(layout2);
1242 split = new QSplitter(this);
1243 split->setOrientation(Qt::Vertical);
1244 list = new ConfigList(split, "search");
1245 list->mode = listMode;
1246 info = new ConfigInfoView(split, "search");
1247 connect(list, SIGNAL(menuChanged(struct menu *)),
1248 info, SLOT(setInfo(struct menu *)));
1249 connect(list, SIGNAL(menuChanged(struct menu *)),
1250 parent, SLOT(setMenuLink(struct menu *)));
1252 layout1->addWidget(split);
1258 configSettings->beginGroup("search");
1259 width = configSettings->value("/window width", parent->width() / 2).toInt();
1260 height = configSettings->value("/window height", parent->height() / 2).toInt();
1261 resize(width, height);
1262 x = configSettings->value("/window x");
1263 y = configSettings->value("/window y");
1264 if (x.isValid() && y.isValid())
1265 move(x.toInt(), y.toInt());
1266 QList<int> sizes = configSettings->readSizes("/split", &ok);
1268 split->setSizes(sizes);
1269 configSettings->endGroup();
1270 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
1273 void ConfigSearchWindow::saveSettings(void)
1275 if (!objectName().isEmpty()) {
1276 configSettings->beginGroup(objectName());
1277 configSettings->setValue("/window x", pos().x());
1278 configSettings->setValue("/window y", pos().y());
1279 configSettings->setValue("/window width", size().width());
1280 configSettings->setValue("/window height", size().height());
1281 configSettings->writeSizes("/split", split->sizes());
1282 configSettings->endGroup();
1286 void ConfigSearchWindow::search(void)
1289 struct property *prop;
1290 ConfigItem *lastItem = NULL;
1296 result = sym_re_search(editField->text().toLatin1());
1299 for (p = result; *p; p++) {
1300 for_all_prompts((*p), prop)
1301 lastItem = new ConfigItem(list, lastItem, prop->menu,
1302 menu_is_visible(prop->menu));
1307 * Construct the complete config widget
1309 ConfigMainWindow::ConfigMainWindow(void)
1317 QDesktopWidget *d = configApp->desktop();
1318 snprintf(title, sizeof(title), "%s%s",
1319 rootmenu.prompt->text,
1322 setWindowTitle(title);
1324 width = configSettings->value("/window width", d->width() - 64).toInt();
1325 height = configSettings->value("/window height", d->height() - 64).toInt();
1326 resize(width, height);
1327 x = configSettings->value("/window x");
1328 y = configSettings->value("/window y");
1329 if ((x.isValid())&&(y.isValid()))
1330 move(x.toInt(), y.toInt());
1333 ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes));
1334 ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod));
1335 ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no));
1336 ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes));
1337 ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no));
1338 ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu));
1339 ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback));
1341 QWidget *widget = new QWidget(this);
1342 QVBoxLayout *layout = new QVBoxLayout(widget);
1343 setCentralWidget(widget);
1345 split1 = new QSplitter(widget);
1346 split1->setOrientation(Qt::Horizontal);
1347 split1->setChildrenCollapsible(false);
1349 menuList = new ConfigList(widget, "menu");
1351 split2 = new QSplitter(widget);
1352 split2->setChildrenCollapsible(false);
1353 split2->setOrientation(Qt::Vertical);
1355 // create config tree
1356 configList = new ConfigList(widget, "config");
1358 helpText = new ConfigInfoView(widget, "help");
1360 layout->addWidget(split2);
1361 split2->addWidget(split1);
1362 split1->addWidget(configList);
1363 split1->addWidget(menuList);
1364 split2->addWidget(helpText);
1366 setTabOrder(configList, helpText);
1367 configList->setFocus();
1369 backAction = new QAction(QPixmap(xpm_back), "Back", this);
1370 connect(backAction, SIGNAL(triggered(bool)), SLOT(goBack()));
1372 QAction *quitAction = new QAction("&Quit", this);
1373 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
1374 connect(quitAction, SIGNAL(triggered(bool)), SLOT(close()));
1376 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
1377 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
1378 connect(loadAction, SIGNAL(triggered(bool)), SLOT(loadConfig()));
1380 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
1381 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
1382 connect(saveAction, SIGNAL(triggered(bool)), SLOT(saveConfig()));
1384 conf_set_changed_callback(conf_changed);
1386 // Set saveAction's initial state
1388 configname = xstrdup(conf_get_configname());
1390 QAction *saveAsAction = new QAction("Save &As...", this);
1391 connect(saveAsAction, SIGNAL(triggered(bool)), SLOT(saveConfigAs()));
1392 QAction *searchAction = new QAction("&Find", this);
1393 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
1394 connect(searchAction, SIGNAL(triggered(bool)), SLOT(searchConfig()));
1395 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
1396 singleViewAction->setCheckable(true);
1397 connect(singleViewAction, SIGNAL(triggered(bool)), SLOT(showSingleView()));
1398 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
1399 splitViewAction->setCheckable(true);
1400 connect(splitViewAction, SIGNAL(triggered(bool)), SLOT(showSplitView()));
1401 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
1402 fullViewAction->setCheckable(true);
1403 connect(fullViewAction, SIGNAL(triggered(bool)), SLOT(showFullView()));
1405 QAction *showNameAction = new QAction("Show Name", this);
1406 showNameAction->setCheckable(true);
1407 connect(showNameAction, SIGNAL(toggled(bool)), configList, SLOT(setShowName(bool)));
1408 showNameAction->setChecked(configList->showName);
1410 QActionGroup *optGroup = new QActionGroup(this);
1411 optGroup->setExclusive(true);
1412 connect(optGroup, SIGNAL(triggered(QAction*)), configList,
1413 SLOT(setOptionMode(QAction *)));
1414 connect(optGroup, SIGNAL(triggered(QAction *)), menuList,
1415 SLOT(setOptionMode(QAction *)));
1417 ConfigList::showNormalAction = new QAction("Show Normal Options", optGroup);
1418 ConfigList::showNormalAction->setCheckable(true);
1419 ConfigList::showAllAction = new QAction("Show All Options", optGroup);
1420 ConfigList::showAllAction->setCheckable(true);
1421 ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup);
1422 ConfigList::showPromptAction->setCheckable(true);
1424 QAction *showDebugAction = new QAction("Show Debug Info", this);
1425 showDebugAction->setCheckable(true);
1426 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
1427 showDebugAction->setChecked(helpText->showDebug());
1429 QAction *showIntroAction = new QAction("Introduction", this);
1430 connect(showIntroAction, SIGNAL(triggered(bool)), SLOT(showIntro()));
1431 QAction *showAboutAction = new QAction("About", this);
1432 connect(showAboutAction, SIGNAL(triggered(bool)), SLOT(showAbout()));
1435 QToolBar *toolBar = addToolBar("Tools");
1436 toolBar->addAction(backAction);
1437 toolBar->addSeparator();
1438 toolBar->addAction(loadAction);
1439 toolBar->addAction(saveAction);
1440 toolBar->addSeparator();
1441 toolBar->addAction(singleViewAction);
1442 toolBar->addAction(splitViewAction);
1443 toolBar->addAction(fullViewAction);
1446 QMenu *menu = menuBar()->addMenu("&File");
1447 menu->addAction(loadAction);
1448 menu->addAction(saveAction);
1449 menu->addAction(saveAsAction);
1450 menu->addSeparator();
1451 menu->addAction(quitAction);
1454 menu = menuBar()->addMenu("&Edit");
1455 menu->addAction(searchAction);
1457 // create options menu
1458 menu = menuBar()->addMenu("&Option");
1459 menu->addAction(showNameAction);
1460 menu->addSeparator();
1461 menu->addActions(optGroup->actions());
1462 menu->addSeparator();
1463 menu->addAction(showDebugAction);
1466 menu = menuBar()->addMenu("&Help");
1467 menu->addAction(showIntroAction);
1468 menu->addAction(showAboutAction);
1470 connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1471 helpText, SLOT (clicked (const QUrl &)) );
1473 connect(configList, SIGNAL(menuChanged(struct menu *)),
1474 helpText, SLOT(setInfo(struct menu *)));
1475 connect(configList, SIGNAL(menuSelected(struct menu *)),
1476 SLOT(changeMenu(struct menu *)));
1477 connect(configList, SIGNAL(itemSelected(struct menu *)),
1478 SLOT(changeItens(struct menu *)));
1479 connect(configList, SIGNAL(parentSelected()),
1481 connect(menuList, SIGNAL(menuChanged(struct menu *)),
1482 helpText, SLOT(setInfo(struct menu *)));
1483 connect(menuList, SIGNAL(menuSelected(struct menu *)),
1484 SLOT(changeMenu(struct menu *)));
1486 connect(configList, SIGNAL(gotFocus(struct menu *)),
1487 helpText, SLOT(setInfo(struct menu *)));
1488 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1489 helpText, SLOT(setInfo(struct menu *)));
1490 connect(menuList, SIGNAL(gotFocus(struct menu *)),
1491 SLOT(listFocusChanged(void)));
1492 connect(helpText, SIGNAL(menuSelected(struct menu *)),
1493 SLOT(setMenuLink(struct menu *)));
1495 QString listMode = configSettings->value("/listMode", "symbol").toString();
1496 if (listMode == "single")
1498 else if (listMode == "full")
1500 else /*if (listMode == "split")*/
1503 // UI setup done, restore splitter positions
1504 QList<int> sizes = configSettings->readSizes("/split1", &ok);
1506 split1->setSizes(sizes);
1508 sizes = configSettings->readSizes("/split2", &ok);
1510 split2->setSizes(sizes);
1513 void ConfigMainWindow::loadConfig(void)
1519 str = QFileDialog::getOpenFileName(this, "", configname);
1523 ba = str.toLocal8Bit();
1526 if (conf_read(name))
1527 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1530 configname = xstrdup(name);
1532 ConfigList::updateListAllForAll();
1535 bool ConfigMainWindow::saveConfig(void)
1537 if (conf_write(configname)) {
1538 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1541 conf_write_autoconf(0);
1546 void ConfigMainWindow::saveConfigAs(void)
1552 str = QFileDialog::getSaveFileName(this, "", configname);
1556 ba = str.toLocal8Bit();
1559 if (conf_write(name)) {
1560 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1562 conf_write_autoconf(0);
1565 configname = xstrdup(name);
1568 void ConfigMainWindow::searchConfig(void)
1571 searchWindow = new ConfigSearchWindow(this);
1572 searchWindow->show();
1575 void ConfigMainWindow::changeItens(struct menu *menu)
1577 configList->setRootMenu(menu);
1580 void ConfigMainWindow::changeMenu(struct menu *menu)
1582 menuList->setRootMenu(menu);
1585 void ConfigMainWindow::setMenuLink(struct menu *menu)
1587 struct menu *parent;
1588 ConfigList* list = NULL;
1591 if (configList->menuSkip(menu))
1594 switch (configList->mode) {
1597 parent = menu_get_parent_menu(menu);
1600 list->setRootMenu(parent);
1603 if (menu->flags & MENU_ROOT) {
1604 menuList->setRootMenu(menu);
1605 configList->clearSelection();
1608 parent = menu_get_parent_menu(menu->parent);
1612 /* Select the config view */
1613 item = configList->findConfigItem(parent);
1615 configList->setSelected(item, true);
1616 configList->scrollToItem(item);
1619 menuList->setRootMenu(parent);
1620 menuList->clearSelection();
1632 item = list->findConfigItem(menu);
1634 list->setSelected(item, true);
1635 list->scrollToItem(item);
1637 helpText->setInfo(menu);
1642 void ConfigMainWindow::listFocusChanged(void)
1644 if (menuList->mode == menuMode)
1645 configList->clearSelection();
1648 void ConfigMainWindow::goBack(void)
1650 if (configList->rootEntry == &rootmenu)
1653 configList->setParentMenu();
1656 void ConfigMainWindow::showSingleView(void)
1658 singleViewAction->setEnabled(false);
1659 singleViewAction->setChecked(true);
1660 splitViewAction->setEnabled(true);
1661 splitViewAction->setChecked(false);
1662 fullViewAction->setEnabled(true);
1663 fullViewAction->setChecked(false);
1665 backAction->setEnabled(true);
1668 menuList->setRootMenu(0);
1669 configList->mode = singleMode;
1670 if (configList->rootEntry == &rootmenu)
1671 configList->updateListAll();
1673 configList->setRootMenu(&rootmenu);
1674 configList->setFocus();
1677 void ConfigMainWindow::showSplitView(void)
1679 singleViewAction->setEnabled(true);
1680 singleViewAction->setChecked(false);
1681 splitViewAction->setEnabled(false);
1682 splitViewAction->setChecked(true);
1683 fullViewAction->setEnabled(true);
1684 fullViewAction->setChecked(false);
1686 backAction->setEnabled(false);
1688 configList->mode = menuMode;
1689 if (configList->rootEntry == &rootmenu)
1690 configList->updateListAll();
1692 configList->setRootMenu(&rootmenu);
1693 configList->setAllOpen(true);
1694 configApp->processEvents();
1695 menuList->mode = symbolMode;
1696 menuList->setRootMenu(&rootmenu);
1697 menuList->setAllOpen(true);
1699 menuList->setFocus();
1702 void ConfigMainWindow::showFullView(void)
1704 singleViewAction->setEnabled(true);
1705 singleViewAction->setChecked(false);
1706 splitViewAction->setEnabled(true);
1707 splitViewAction->setChecked(false);
1708 fullViewAction->setEnabled(false);
1709 fullViewAction->setChecked(true);
1711 backAction->setEnabled(false);
1714 menuList->setRootMenu(0);
1715 configList->mode = fullMode;
1716 if (configList->rootEntry == &rootmenu)
1717 configList->updateListAll();
1719 configList->setRootMenu(&rootmenu);
1720 configList->setFocus();
1724 * ask for saving configuration before quitting
1726 void ConfigMainWindow::closeEvent(QCloseEvent* e)
1728 if (!conf_get_changed()) {
1732 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
1733 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1734 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1735 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1736 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
1737 switch (mb.exec()) {
1738 case QMessageBox::Yes:
1744 case QMessageBox::No:
1747 case QMessageBox::Cancel:
1753 void ConfigMainWindow::showIntro(void)
1755 static const QString str =
1756 "Welcome to the qconf graphical configuration tool.\n"
1758 "For bool and tristate options, a blank box indicates the "
1759 "feature is disabled, a check indicates it is enabled, and a "
1760 "dot indicates that it is to be compiled as a module. Clicking "
1761 "on the box will cycle through the three states. For int, hex, "
1762 "and string options, double-clicking or pressing F2 on the "
1763 "Value cell will allow you to edit the value.\n"
1765 "If you do not see an option (e.g., a device driver) that you "
1766 "believe should be present, try turning on Show All Options "
1767 "under the Options menu. Enabling Show Debug Info will help you"
1768 "figure out what other options must be enabled to support the "
1769 "option you are interested in, and hyperlinks will navigate to "
1772 "Toggling Show Debug Info under the Options menu will show the "
1773 "dependencies, which you can then match by examining other "
1776 QMessageBox::information(this, "qconf", str);
1779 void ConfigMainWindow::showAbout(void)
1781 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
1782 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n\n"
1783 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1785 QMessageBox::information(this, "qconf", str);
1788 void ConfigMainWindow::saveSettings(void)
1790 configSettings->setValue("/window x", pos().x());
1791 configSettings->setValue("/window y", pos().y());
1792 configSettings->setValue("/window width", size().width());
1793 configSettings->setValue("/window height", size().height());
1796 switch(configList->mode) {
1812 configSettings->setValue("/listMode", entry);
1814 configSettings->writeSizes("/split1", split1->sizes());
1815 configSettings->writeSizes("/split2", split2->sizes());
1818 void ConfigMainWindow::conf_changed(void)
1821 saveAction->setEnabled(conf_get_changed());
1824 void fixup_rootmenu(struct menu *menu)
1827 static int menu_cnt = 0;
1829 menu->flags |= MENU_ROOT;
1830 for (child = menu->list; child; child = child->next) {
1831 if (child->prompt && child->prompt->type == P_MENU) {
1833 fixup_rootmenu(child);
1835 } else if (!menu_cnt)
1836 fixup_rootmenu(child);
1840 static const char *progname;
1842 static void usage(void)
1844 printf("%s [-s] <config>\n", progname);
1848 int main(int ac, char** av)
1850 ConfigMainWindow* v;
1854 if (ac > 1 && av[1][0] == '-') {
1857 conf_set_message_callback(NULL);
1870 fixup_rootmenu(&rootmenu);
1872 //zconfdump(stdout);
1874 configApp = new QApplication(ac, av);
1876 configSettings = new ConfigSettings();
1877 configSettings->beginGroup("/kconfig/qconf");
1878 v = new ConfigMainWindow();
1880 //zconfdump(stdout);
1881 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1882 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
1886 configSettings->endGroup();
1887 delete configSettings;