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, &ConfigList::itemSelectionChanged,
314 this, &ConfigList::updateSelection);
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, &QApplication::aboutToQuit,
322 this, &ConfigList::saveSettings);
325 showColumn(promptColIdx);
327 setItemDelegate(new ConfigItemDelegate(this));
329 allLists.append(this);
334 ConfigList::~ConfigList()
336 allLists.removeOne(this);
339 bool ConfigList::menuSkip(struct menu *menu)
341 if (optMode == normalOpt && menu_is_visible(menu))
343 if (optMode == promptOpt && menu_has_prompt(menu))
345 if (optMode == allOpt)
350 void ConfigList::reinit(void)
352 hideColumn(nameColIdx);
355 showColumn(nameColIdx);
360 void ConfigList::setOptionMode(QAction *action)
362 if (action == showNormalAction)
364 else if (action == showAllAction)
372 void ConfigList::saveSettings(void)
374 if (!objectName().isEmpty()) {
375 configSettings->beginGroup(objectName());
376 configSettings->setValue("/showName", showName);
377 configSettings->setValue("/optionMode", (int)optMode);
378 configSettings->endGroup();
382 ConfigItem* ConfigList::findConfigItem(struct menu *menu)
384 ConfigItem* item = (ConfigItem*)menu->data;
386 for (; item; item = item->nextItem) {
387 if (this == item->listView())
394 void ConfigList::updateSelection(void)
399 if (selectedItems().count() == 0)
402 ConfigItem* item = (ConfigItem*)selectedItems().first();
407 emit menuChanged(menu);
410 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
411 if (mode == menuMode && type == P_MENU)
412 emit menuSelected(menu);
415 void ConfigList::updateList()
417 ConfigItem* last = 0;
421 if (mode != listMode)
423 QTreeWidgetItemIterator it(this);
426 item = (ConfigItem*)(*it);
429 item->testUpdateMenu(menu_is_visible(item->menu));
436 if (rootEntry != &rootmenu && (mode == singleMode ||
437 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
438 item = (ConfigItem *)topLevelItem(0);
440 item = new ConfigItem(this, 0, true);
443 if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) &&
444 rootEntry->sym && rootEntry->prompt) {
445 item = last ? last->nextSibling() : nullptr;
447 item = new ConfigItem(this, last, rootEntry, true);
449 item->testUpdateMenu(true);
451 updateMenuList(item, rootEntry);
453 resizeColumnToContents(0);
457 updateMenuList(rootEntry);
459 resizeColumnToContents(0);
462 void ConfigList::updateListForAll()
464 QListIterator<ConfigList *> it(allLists);
466 while (it.hasNext()) {
467 ConfigList *list = it.next();
473 void ConfigList::updateListAllForAll()
475 QListIterator<ConfigList *> it(allLists);
477 while (it.hasNext()) {
478 ConfigList *list = it.next();
484 void ConfigList::setValue(ConfigItem* item, tristate val)
490 sym = item->menu ? item->menu->sym : 0;
494 type = sym_get_type(sym);
498 oldval = sym_get_tristate_value(sym);
500 if (!sym_set_tristate_value(sym, val))
502 if (oldval == no && item->menu->list)
503 item->setExpanded(true);
504 ConfigList::updateListForAll();
509 void ConfigList::changeValue(ConfigItem* item)
513 int type, oldexpr, newexpr;
520 if (item->menu->list)
521 item->setExpanded(!item->isExpanded());
525 type = sym_get_type(sym);
529 oldexpr = sym_get_tristate_value(sym);
530 newexpr = sym_toggle_tristate_value(sym);
531 if (item->menu->list) {
532 if (oldexpr == newexpr)
533 item->setExpanded(!item->isExpanded());
534 else if (oldexpr == no)
535 item->setExpanded(true);
537 if (oldexpr != newexpr)
538 ConfigList::updateListForAll();
545 void ConfigList::setRootMenu(struct menu *menu)
549 if (rootEntry == menu)
551 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
558 setSelected(currentItem(), hasFocus());
559 scrollToItem(currentItem());
563 void ConfigList::setParentMenu(void)
566 struct menu *oldroot;
569 if (rootEntry == &rootmenu)
571 setRootMenu(menu_get_parent_menu(rootEntry->parent));
573 QTreeWidgetItemIterator it(this);
575 item = (ConfigItem *)(*it);
576 if (item->menu == oldroot) {
577 setCurrentItem(item);
587 * update all the children of a menu entry
588 * removes/adds the entries from the parent widget as necessary
590 * parent: either the menu list widget or a menu entry widget
591 * menu: entry to be updated
593 void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
602 while (parent->childCount() > 0)
604 delete parent->takeChild(0);
610 last = parent->firstChild();
611 if (last && !last->goParent)
613 for (child = menu->list; child; child = child->next) {
614 item = last ? last->nextSibling() : parent->firstChild();
615 type = child->prompt ? child->prompt->type : P_UNKNOWN;
619 if (!(child->flags & MENU_ROOT))
623 if (child->flags & MENU_ROOT)
630 visible = menu_is_visible(child);
631 if (!menuSkip(child)) {
632 if (!child->sym && !child->list && !child->prompt)
634 if (!item || item->menu != child)
635 item = new ConfigItem(parent, last, child, visible);
637 item->testUpdateMenu(visible);
639 if (mode == fullMode || mode == menuMode || type != P_MENU)
640 updateMenuList(item, child);
642 updateMenuList(item, 0);
647 if (item && item->menu == child) {
648 last = parent->firstChild();
651 else while (last->nextSibling() != item)
652 last = last->nextSibling();
658 void ConfigList::updateMenuList(struct menu *menu)
667 while (topLevelItemCount() > 0)
669 delete takeTopLevelItem(0);
675 last = (ConfigItem *)topLevelItem(0);
676 if (last && !last->goParent)
678 for (child = menu->list; child; child = child->next) {
679 item = last ? last->nextSibling() : (ConfigItem *)topLevelItem(0);
680 type = child->prompt ? child->prompt->type : P_UNKNOWN;
684 if (!(child->flags & MENU_ROOT))
688 if (child->flags & MENU_ROOT)
695 visible = menu_is_visible(child);
696 if (!menuSkip(child)) {
697 if (!child->sym && !child->list && !child->prompt)
699 if (!item || item->menu != child)
700 item = new ConfigItem(this, last, child, visible);
702 item->testUpdateMenu(visible);
704 if (mode == fullMode || mode == menuMode || type != P_MENU)
705 updateMenuList(item, child);
707 updateMenuList(item, 0);
712 if (item && item->menu == child) {
713 last = (ConfigItem *)topLevelItem(0);
716 else while (last->nextSibling() != item)
717 last = last->nextSibling();
723 void ConfigList::keyPressEvent(QKeyEvent* ev)
725 QTreeWidgetItem* i = currentItem();
730 if (ev->key() == Qt::Key_Escape && mode != fullMode && mode != listMode) {
731 emit parentSelected();
737 Parent::keyPressEvent(ev);
740 item = (ConfigItem*)i;
745 if (item->goParent) {
746 emit parentSelected();
752 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
753 if (type == P_MENU && rootEntry != menu &&
754 mode != fullMode && mode != menuMode) {
755 if (mode == menuMode)
756 emit menuSelected(menu);
758 emit itemSelected(menu);
774 Parent::keyPressEvent(ev);
780 void ConfigList::mousePressEvent(QMouseEvent* e)
782 //QPoint p(contentsToViewport(e->pos()));
783 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
784 Parent::mousePressEvent(e);
787 void ConfigList::mouseReleaseEvent(QMouseEvent* e)
790 ConfigItem* item = (ConfigItem*)itemAt(p);
792 enum prop_type ptype;
800 x = header()->offset() + p.x();
801 idx = header()->logicalIndexAt(x);
804 icon = item->icon(promptColIdx);
805 if (!icon.isNull()) {
806 int off = header()->sectionPosition(0) + visualRect(indexAt(p)).x() + 4; // 4 is Hardcoded image offset. There might be a way to do it properly.
807 if (x >= off && x < off + icon.availableSizes().first().width()) {
808 if (item->goParent) {
809 emit parentSelected();
813 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
814 if (ptype == P_MENU && rootEntry != menu &&
815 mode != fullMode && mode != menuMode &&
817 emit menuSelected(menu);
829 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
830 Parent::mouseReleaseEvent(e);
833 void ConfigList::mouseMoveEvent(QMouseEvent* e)
835 //QPoint p(contentsToViewport(e->pos()));
836 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
837 Parent::mouseMoveEvent(e);
840 void ConfigList::mouseDoubleClickEvent(QMouseEvent* e)
843 ConfigItem* item = (ConfigItem*)itemAt(p);
845 enum prop_type ptype;
849 if (item->goParent) {
850 emit parentSelected();
856 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
857 if (ptype == P_MENU && mode != listMode) {
858 if (mode == singleMode)
859 emit itemSelected(menu);
860 else if (mode == symbolMode)
861 emit menuSelected(menu);
862 } else if (menu->sym)
866 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
867 Parent::mouseDoubleClickEvent(e);
870 void ConfigList::focusInEvent(QFocusEvent *e)
872 struct menu *menu = NULL;
874 Parent::focusInEvent(e);
876 ConfigItem* item = (ConfigItem *)currentItem();
878 setSelected(item, true);
884 void ConfigList::contextMenuEvent(QContextMenuEvent *e)
889 headerPopup = new QMenu(this);
890 action = new QAction("Show Name", this);
891 action->setCheckable(true);
892 connect(action, &QAction::toggled,
893 this, &ConfigList::setShowName);
894 connect(this, &ConfigList::showNameChanged,
895 action, &QAction::setChecked);
896 action->setChecked(showName);
897 headerPopup->addAction(action);
900 headerPopup->exec(e->globalPos());
904 void ConfigList::setShowName(bool on)
911 emit showNameChanged(on);
914 QList<ConfigList *> ConfigList::allLists;
915 QAction *ConfigList::showNormalAction;
916 QAction *ConfigList::showAllAction;
917 QAction *ConfigList::showPromptAction;
919 void ConfigList::setAllOpen(bool open)
921 QTreeWidgetItemIterator it(this);
924 (*it)->setExpanded(open);
930 ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
931 : Parent(parent), sym(0), _menu(0)
936 if (!objectName().isEmpty()) {
937 configSettings->beginGroup(objectName());
938 setShowDebug(configSettings->value("/showDebug", false).toBool());
939 configSettings->endGroup();
940 connect(configApp, &QApplication::aboutToQuit,
941 this, &ConfigInfoView::saveSettings);
944 contextMenu = createStandardContextMenu();
945 QAction *action = new QAction("Show Debug Info", contextMenu);
947 action->setCheckable(true);
948 connect(action, &QAction::toggled,
949 this, &ConfigInfoView::setShowDebug);
950 connect(this, &ConfigInfoView::showDebugChanged,
951 action, &QAction::setChecked);
952 action->setChecked(showDebug());
953 contextMenu->addSeparator();
954 contextMenu->addAction(action);
957 void ConfigInfoView::saveSettings(void)
959 if (!objectName().isEmpty()) {
960 configSettings->beginGroup(objectName());
961 configSettings->setValue("/showDebug", showDebug());
962 configSettings->endGroup();
966 void ConfigInfoView::setShowDebug(bool b)
968 if (_showDebug != b) {
974 emit showDebugChanged(b);
978 void ConfigInfoView::setInfo(struct menu *m)
990 void ConfigInfoView::symbolInfo(void)
994 str += "<big>Symbol: <b>";
995 str += print_filter(sym->name);
996 str += "</b></big><br><br>value: ";
997 str += print_filter(sym_get_string_value(sym));
998 str += "<br>visibility: ";
999 str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n";
1001 str += debug_info(sym);
1006 void ConfigInfoView::menuInfo(void)
1010 QTextStream stream(&info);
1014 if (_menu->prompt) {
1015 stream << "<big><b>";
1016 stream << print_filter(_menu->prompt->text);
1017 stream << "</b></big>";
1021 stream << "<a href=\"s" << sym->name << "\">";
1022 stream << print_filter(sym->name);
1027 } else if (sym->name) {
1028 stream << "<big><b>";
1030 stream << "<a href=\"s" << sym->name << "\">";
1031 stream << print_filter(sym->name);
1034 stream << "</b></big>";
1036 stream << "<br><br>";
1039 stream << debug_info(sym);
1041 struct gstr help_gstr = str_new();
1043 menu_get_ext_help(_menu, &help_gstr);
1044 stream << print_filter(str_get(&help_gstr));
1045 str_free(&help_gstr);
1046 } else if (_menu->prompt) {
1047 stream << "<big><b>";
1048 stream << print_filter(_menu->prompt->text);
1049 stream << "</b></big><br><br>";
1051 if (_menu->prompt->visible.expr) {
1052 stream << " dep: ";
1053 expr_print(_menu->prompt->visible.expr,
1054 expr_print_help, &stream, E_NONE);
1055 stream << "<br><br>";
1058 stream << "defined at " << _menu->file->name << ":"
1059 << _menu->lineno << "<br><br>";
1066 QString ConfigInfoView::debug_info(struct symbol *sym)
1069 QTextStream stream(&debug);
1072 stream << print_filter(sym_type_name(sym->type));
1073 if (sym_is_choice(sym))
1074 stream << " (choice)";
1076 if (sym->rev_dep.expr) {
1077 stream << "reverse dep: ";
1078 expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE);
1081 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1082 switch (prop->type) {
1085 stream << "prompt: <a href=\"m" << sym->name << "\">";
1086 stream << print_filter(prop->text);
1087 stream << "</a><br>";
1095 stream << prop_get_type_name(prop->type);
1097 expr_print(prop->expr, expr_print_help,
1102 if (sym_is_choice(sym)) {
1103 stream << "choice: ";
1104 expr_print(prop->expr, expr_print_help,
1110 stream << "unknown property: ";
1111 stream << prop_get_type_name(prop->type);
1114 if (prop->visible.expr) {
1115 stream << " dep: ";
1116 expr_print(prop->visible.expr, expr_print_help,
1126 QString ConfigInfoView::print_filter(const QString &str)
1128 QRegExp re("[<>&\"\\n]");
1130 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1131 switch (res[i].toLatin1()) {
1133 res.replace(i, 1, "<");
1137 res.replace(i, 1, ">");
1141 res.replace(i, 1, "&");
1145 res.replace(i, 1, """);
1149 res.replace(i, 1, "<br>");
1157 void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
1159 QTextStream *stream = reinterpret_cast<QTextStream *>(data);
1161 if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1162 *stream << "<a href=\"s" << sym->name << "\">";
1163 *stream << print_filter(str);
1166 *stream << print_filter(str);
1170 void ConfigInfoView::clicked(const QUrl &url)
1172 QByteArray str = url.toEncoded();
1173 const std::size_t count = str.size();
1174 char *data = new char[count + 1];
1175 struct symbol **result;
1176 struct menu *m = NULL;
1183 memcpy(data, str.constData(), count);
1186 /* Seek for exact match */
1189 result = sym_re_search(data);
1197 /* Seek for the menu which holds the symbol */
1198 for (struct property *prop = sym->prop; prop; prop = prop->next) {
1199 if (prop->type != P_PROMPT && prop->type != P_MENU)
1206 /* Symbol is not visible as a menu */
1208 emit showDebugChanged(true);
1210 emit menuSelected(m);
1217 void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event)
1219 contextMenu->popup(event->globalPos());
1223 ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow *parent)
1224 : Parent(parent), result(NULL)
1226 setObjectName("search");
1227 setWindowTitle("Search Config");
1229 QVBoxLayout* layout1 = new QVBoxLayout(this);
1230 layout1->setContentsMargins(11, 11, 11, 11);
1231 layout1->setSpacing(6);
1233 QHBoxLayout* layout2 = new QHBoxLayout();
1234 layout2->setContentsMargins(0, 0, 0, 0);
1235 layout2->setSpacing(6);
1236 layout2->addWidget(new QLabel("Find:", this));
1237 editField = new QLineEdit(this);
1238 connect(editField, &QLineEdit::returnPressed,
1239 this, &ConfigSearchWindow::search);
1240 layout2->addWidget(editField);
1241 searchButton = new QPushButton("Search", this);
1242 searchButton->setAutoDefault(false);
1243 connect(searchButton, &QPushButton::clicked,
1244 this, &ConfigSearchWindow::search);
1245 layout2->addWidget(searchButton);
1246 layout1->addLayout(layout2);
1248 split = new QSplitter(this);
1249 split->setOrientation(Qt::Vertical);
1250 list = new ConfigList(split, "search");
1251 list->mode = listMode;
1252 info = new ConfigInfoView(split, "search");
1253 connect(list, &ConfigList::menuChanged,
1254 info, &ConfigInfoView::setInfo);
1255 connect(list, &ConfigList::menuChanged,
1256 parent, &ConfigMainWindow::setMenuLink);
1258 layout1->addWidget(split);
1264 configSettings->beginGroup("search");
1265 width = configSettings->value("/window width", parent->width() / 2).toInt();
1266 height = configSettings->value("/window height", parent->height() / 2).toInt();
1267 resize(width, height);
1268 x = configSettings->value("/window x");
1269 y = configSettings->value("/window y");
1270 if (x.isValid() && y.isValid())
1271 move(x.toInt(), y.toInt());
1272 QList<int> sizes = configSettings->readSizes("/split", &ok);
1274 split->setSizes(sizes);
1275 configSettings->endGroup();
1276 connect(configApp, &QApplication::aboutToQuit,
1277 this, &ConfigSearchWindow::saveSettings);
1280 void ConfigSearchWindow::saveSettings(void)
1282 if (!objectName().isEmpty()) {
1283 configSettings->beginGroup(objectName());
1284 configSettings->setValue("/window x", pos().x());
1285 configSettings->setValue("/window y", pos().y());
1286 configSettings->setValue("/window width", size().width());
1287 configSettings->setValue("/window height", size().height());
1288 configSettings->writeSizes("/split", split->sizes());
1289 configSettings->endGroup();
1293 void ConfigSearchWindow::search(void)
1296 struct property *prop;
1297 ConfigItem *lastItem = NULL;
1303 result = sym_re_search(editField->text().toLatin1());
1306 for (p = result; *p; p++) {
1307 for_all_prompts((*p), prop)
1308 lastItem = new ConfigItem(list, lastItem, prop->menu,
1309 menu_is_visible(prop->menu));
1314 * Construct the complete config widget
1316 ConfigMainWindow::ConfigMainWindow(void)
1324 QDesktopWidget *d = configApp->desktop();
1325 snprintf(title, sizeof(title), "%s%s",
1326 rootmenu.prompt->text,
1329 setWindowTitle(title);
1331 width = configSettings->value("/window width", d->width() - 64).toInt();
1332 height = configSettings->value("/window height", d->height() - 64).toInt();
1333 resize(width, height);
1334 x = configSettings->value("/window x");
1335 y = configSettings->value("/window y");
1336 if ((x.isValid())&&(y.isValid()))
1337 move(x.toInt(), y.toInt());
1340 ConfigItem::symbolYesIcon = QIcon(QPixmap(xpm_symbol_yes));
1341 ConfigItem::symbolModIcon = QIcon(QPixmap(xpm_symbol_mod));
1342 ConfigItem::symbolNoIcon = QIcon(QPixmap(xpm_symbol_no));
1343 ConfigItem::choiceYesIcon = QIcon(QPixmap(xpm_choice_yes));
1344 ConfigItem::choiceNoIcon = QIcon(QPixmap(xpm_choice_no));
1345 ConfigItem::menuIcon = QIcon(QPixmap(xpm_menu));
1346 ConfigItem::menubackIcon = QIcon(QPixmap(xpm_menuback));
1348 QWidget *widget = new QWidget(this);
1349 QVBoxLayout *layout = new QVBoxLayout(widget);
1350 setCentralWidget(widget);
1352 split1 = new QSplitter(widget);
1353 split1->setOrientation(Qt::Horizontal);
1354 split1->setChildrenCollapsible(false);
1356 menuList = new ConfigList(widget, "menu");
1358 split2 = new QSplitter(widget);
1359 split2->setChildrenCollapsible(false);
1360 split2->setOrientation(Qt::Vertical);
1362 // create config tree
1363 configList = new ConfigList(widget, "config");
1365 helpText = new ConfigInfoView(widget, "help");
1367 layout->addWidget(split2);
1368 split2->addWidget(split1);
1369 split1->addWidget(configList);
1370 split1->addWidget(menuList);
1371 split2->addWidget(helpText);
1373 setTabOrder(configList, helpText);
1374 configList->setFocus();
1376 backAction = new QAction(QPixmap(xpm_back), "Back", this);
1377 connect(backAction, &QAction::triggered,
1378 this, &ConfigMainWindow::goBack);
1380 QAction *quitAction = new QAction("&Quit", this);
1381 quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
1382 connect(quitAction, &QAction::triggered,
1383 this, &ConfigMainWindow::close);
1385 QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this);
1386 loadAction->setShortcut(Qt::CTRL + Qt::Key_L);
1387 connect(loadAction, &QAction::triggered,
1388 this, &ConfigMainWindow::loadConfig);
1390 saveAction = new QAction(QPixmap(xpm_save), "&Save", this);
1391 saveAction->setShortcut(Qt::CTRL + Qt::Key_S);
1392 connect(saveAction, &QAction::triggered,
1393 this, &ConfigMainWindow::saveConfig);
1395 conf_set_changed_callback(conf_changed);
1397 // Set saveAction's initial state
1399 configname = xstrdup(conf_get_configname());
1401 QAction *saveAsAction = new QAction("Save &As...", this);
1402 connect(saveAsAction, &QAction::triggered,
1403 this, &ConfigMainWindow::saveConfigAs);
1404 QAction *searchAction = new QAction("&Find", this);
1405 searchAction->setShortcut(Qt::CTRL + Qt::Key_F);
1406 connect(searchAction, &QAction::triggered,
1407 this, &ConfigMainWindow::searchConfig);
1408 singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this);
1409 singleViewAction->setCheckable(true);
1410 connect(singleViewAction, &QAction::triggered,
1411 this, &ConfigMainWindow::showSingleView);
1412 splitViewAction = new QAction(QPixmap(xpm_split_view), "Split View", this);
1413 splitViewAction->setCheckable(true);
1414 connect(splitViewAction, &QAction::triggered,
1415 this, &ConfigMainWindow::showSplitView);
1416 fullViewAction = new QAction(QPixmap(xpm_tree_view), "Full View", this);
1417 fullViewAction->setCheckable(true);
1418 connect(fullViewAction, &QAction::triggered,
1419 this, &ConfigMainWindow::showFullView);
1421 QAction *showNameAction = new QAction("Show Name", this);
1422 showNameAction->setCheckable(true);
1423 connect(showNameAction, &QAction::toggled,
1424 configList, &ConfigList::setShowName);
1425 showNameAction->setChecked(configList->showName);
1427 QActionGroup *optGroup = new QActionGroup(this);
1428 optGroup->setExclusive(true);
1429 connect(optGroup, &QActionGroup::triggered,
1430 configList, &ConfigList::setOptionMode);
1431 connect(optGroup, &QActionGroup::triggered,
1432 menuList, &ConfigList::setOptionMode);
1434 ConfigList::showNormalAction = new QAction("Show Normal Options", optGroup);
1435 ConfigList::showNormalAction->setCheckable(true);
1436 ConfigList::showAllAction = new QAction("Show All Options", optGroup);
1437 ConfigList::showAllAction->setCheckable(true);
1438 ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup);
1439 ConfigList::showPromptAction->setCheckable(true);
1441 QAction *showDebugAction = new QAction("Show Debug Info", this);
1442 showDebugAction->setCheckable(true);
1443 connect(showDebugAction, &QAction::toggled,
1444 helpText, &ConfigInfoView::setShowDebug);
1445 showDebugAction->setChecked(helpText->showDebug());
1447 QAction *showIntroAction = new QAction("Introduction", this);
1448 connect(showIntroAction, &QAction::triggered,
1449 this, &ConfigMainWindow::showIntro);
1450 QAction *showAboutAction = new QAction("About", this);
1451 connect(showAboutAction, &QAction::triggered,
1452 this, &ConfigMainWindow::showAbout);
1455 QToolBar *toolBar = addToolBar("Tools");
1456 toolBar->addAction(backAction);
1457 toolBar->addSeparator();
1458 toolBar->addAction(loadAction);
1459 toolBar->addAction(saveAction);
1460 toolBar->addSeparator();
1461 toolBar->addAction(singleViewAction);
1462 toolBar->addAction(splitViewAction);
1463 toolBar->addAction(fullViewAction);
1466 QMenu *menu = menuBar()->addMenu("&File");
1467 menu->addAction(loadAction);
1468 menu->addAction(saveAction);
1469 menu->addAction(saveAsAction);
1470 menu->addSeparator();
1471 menu->addAction(quitAction);
1474 menu = menuBar()->addMenu("&Edit");
1475 menu->addAction(searchAction);
1477 // create options menu
1478 menu = menuBar()->addMenu("&Option");
1479 menu->addAction(showNameAction);
1480 menu->addSeparator();
1481 menu->addActions(optGroup->actions());
1482 menu->addSeparator();
1483 menu->addAction(showDebugAction);
1486 menu = menuBar()->addMenu("&Help");
1487 menu->addAction(showIntroAction);
1488 menu->addAction(showAboutAction);
1490 connect(helpText, &ConfigInfoView::anchorClicked,
1491 helpText, &ConfigInfoView::clicked);
1493 connect(configList, &ConfigList::menuChanged,
1494 helpText, &ConfigInfoView::setInfo);
1495 connect(configList, &ConfigList::menuSelected,
1496 this, &ConfigMainWindow::changeMenu);
1497 connect(configList, &ConfigList::itemSelected,
1498 this, &ConfigMainWindow::changeItens);
1499 connect(configList, &ConfigList::parentSelected,
1500 this, &ConfigMainWindow::goBack);
1501 connect(menuList, &ConfigList::menuChanged,
1502 helpText, &ConfigInfoView::setInfo);
1503 connect(menuList, &ConfigList::menuSelected,
1504 this, &ConfigMainWindow::changeMenu);
1506 connect(configList, &ConfigList::gotFocus,
1507 helpText, &ConfigInfoView::setInfo);
1508 connect(menuList, &ConfigList::gotFocus,
1509 helpText, &ConfigInfoView::setInfo);
1510 connect(menuList, &ConfigList::gotFocus,
1511 this, &ConfigMainWindow::listFocusChanged);
1512 connect(helpText, &ConfigInfoView::menuSelected,
1513 this, &ConfigMainWindow::setMenuLink);
1515 QString listMode = configSettings->value("/listMode", "symbol").toString();
1516 if (listMode == "single")
1518 else if (listMode == "full")
1520 else /*if (listMode == "split")*/
1523 // UI setup done, restore splitter positions
1524 QList<int> sizes = configSettings->readSizes("/split1", &ok);
1526 split1->setSizes(sizes);
1528 sizes = configSettings->readSizes("/split2", &ok);
1530 split2->setSizes(sizes);
1533 void ConfigMainWindow::loadConfig(void)
1539 str = QFileDialog::getOpenFileName(this, "", configname);
1543 ba = str.toLocal8Bit();
1546 if (conf_read(name))
1547 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1550 configname = xstrdup(name);
1552 ConfigList::updateListAllForAll();
1555 bool ConfigMainWindow::saveConfig(void)
1557 if (conf_write(configname)) {
1558 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1561 conf_write_autoconf(0);
1566 void ConfigMainWindow::saveConfigAs(void)
1572 str = QFileDialog::getSaveFileName(this, "", configname);
1576 ba = str.toLocal8Bit();
1579 if (conf_write(name)) {
1580 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1582 conf_write_autoconf(0);
1585 configname = xstrdup(name);
1588 void ConfigMainWindow::searchConfig(void)
1591 searchWindow = new ConfigSearchWindow(this);
1592 searchWindow->show();
1595 void ConfigMainWindow::changeItens(struct menu *menu)
1597 configList->setRootMenu(menu);
1600 void ConfigMainWindow::changeMenu(struct menu *menu)
1602 menuList->setRootMenu(menu);
1605 void ConfigMainWindow::setMenuLink(struct menu *menu)
1607 struct menu *parent;
1608 ConfigList* list = NULL;
1611 if (configList->menuSkip(menu))
1614 switch (configList->mode) {
1617 parent = menu_get_parent_menu(menu);
1620 list->setRootMenu(parent);
1623 if (menu->flags & MENU_ROOT) {
1624 menuList->setRootMenu(menu);
1625 configList->clearSelection();
1628 parent = menu_get_parent_menu(menu->parent);
1632 /* Select the config view */
1633 item = configList->findConfigItem(parent);
1635 configList->setSelected(item, true);
1636 configList->scrollToItem(item);
1639 menuList->setRootMenu(parent);
1640 menuList->clearSelection();
1652 item = list->findConfigItem(menu);
1654 list->setSelected(item, true);
1655 list->scrollToItem(item);
1657 helpText->setInfo(menu);
1662 void ConfigMainWindow::listFocusChanged(void)
1664 if (menuList->mode == menuMode)
1665 configList->clearSelection();
1668 void ConfigMainWindow::goBack(void)
1670 if (configList->rootEntry == &rootmenu)
1673 configList->setParentMenu();
1676 void ConfigMainWindow::showSingleView(void)
1678 singleViewAction->setEnabled(false);
1679 singleViewAction->setChecked(true);
1680 splitViewAction->setEnabled(true);
1681 splitViewAction->setChecked(false);
1682 fullViewAction->setEnabled(true);
1683 fullViewAction->setChecked(false);
1685 backAction->setEnabled(true);
1688 menuList->setRootMenu(0);
1689 configList->mode = singleMode;
1690 if (configList->rootEntry == &rootmenu)
1691 configList->updateListAll();
1693 configList->setRootMenu(&rootmenu);
1694 configList->setFocus();
1697 void ConfigMainWindow::showSplitView(void)
1699 singleViewAction->setEnabled(true);
1700 singleViewAction->setChecked(false);
1701 splitViewAction->setEnabled(false);
1702 splitViewAction->setChecked(true);
1703 fullViewAction->setEnabled(true);
1704 fullViewAction->setChecked(false);
1706 backAction->setEnabled(false);
1708 configList->mode = menuMode;
1709 if (configList->rootEntry == &rootmenu)
1710 configList->updateListAll();
1712 configList->setRootMenu(&rootmenu);
1713 configList->setAllOpen(true);
1714 configApp->processEvents();
1715 menuList->mode = symbolMode;
1716 menuList->setRootMenu(&rootmenu);
1717 menuList->setAllOpen(true);
1719 menuList->setFocus();
1722 void ConfigMainWindow::showFullView(void)
1724 singleViewAction->setEnabled(true);
1725 singleViewAction->setChecked(false);
1726 splitViewAction->setEnabled(true);
1727 splitViewAction->setChecked(false);
1728 fullViewAction->setEnabled(false);
1729 fullViewAction->setChecked(true);
1731 backAction->setEnabled(false);
1734 menuList->setRootMenu(0);
1735 configList->mode = fullMode;
1736 if (configList->rootEntry == &rootmenu)
1737 configList->updateListAll();
1739 configList->setRootMenu(&rootmenu);
1740 configList->setFocus();
1744 * ask for saving configuration before quitting
1746 void ConfigMainWindow::closeEvent(QCloseEvent* e)
1748 if (!conf_get_changed()) {
1752 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
1753 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1754 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1755 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1756 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
1757 switch (mb.exec()) {
1758 case QMessageBox::Yes:
1764 case QMessageBox::No:
1767 case QMessageBox::Cancel:
1773 void ConfigMainWindow::showIntro(void)
1775 static const QString str =
1776 "Welcome to the qconf graphical configuration tool.\n"
1778 "For bool and tristate options, a blank box indicates the "
1779 "feature is disabled, a check indicates it is enabled, and a "
1780 "dot indicates that it is to be compiled as a module. Clicking "
1781 "on the box will cycle through the three states. For int, hex, "
1782 "and string options, double-clicking or pressing F2 on the "
1783 "Value cell will allow you to edit the value.\n"
1785 "If you do not see an option (e.g., a device driver) that you "
1786 "believe should be present, try turning on Show All Options "
1787 "under the Options menu. Enabling Show Debug Info will help you"
1788 "figure out what other options must be enabled to support the "
1789 "option you are interested in, and hyperlinks will navigate to "
1792 "Toggling Show Debug Info under the Options menu will show the "
1793 "dependencies, which you can then match by examining other "
1796 QMessageBox::information(this, "qconf", str);
1799 void ConfigMainWindow::showAbout(void)
1801 static const QString str = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n"
1802 "Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>.\n"
1804 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"
1808 QMessageBox::information(this, "qconf", str + qVersion());
1811 void ConfigMainWindow::saveSettings(void)
1813 configSettings->setValue("/window x", pos().x());
1814 configSettings->setValue("/window y", pos().y());
1815 configSettings->setValue("/window width", size().width());
1816 configSettings->setValue("/window height", size().height());
1819 switch(configList->mode) {
1835 configSettings->setValue("/listMode", entry);
1837 configSettings->writeSizes("/split1", split1->sizes());
1838 configSettings->writeSizes("/split2", split2->sizes());
1841 void ConfigMainWindow::conf_changed(void)
1844 saveAction->setEnabled(conf_get_changed());
1847 void fixup_rootmenu(struct menu *menu)
1850 static int menu_cnt = 0;
1852 menu->flags |= MENU_ROOT;
1853 for (child = menu->list; child; child = child->next) {
1854 if (child->prompt && child->prompt->type == P_MENU) {
1856 fixup_rootmenu(child);
1858 } else if (!menu_cnt)
1859 fixup_rootmenu(child);
1863 static const char *progname;
1865 static void usage(void)
1867 printf("%s [-s] <config>\n", progname);
1871 int main(int ac, char** av)
1873 ConfigMainWindow* v;
1877 if (ac > 1 && av[1][0] == '-') {
1880 conf_set_message_callback(NULL);
1893 fixup_rootmenu(&rootmenu);
1895 //zconfdump(stdout);
1897 configApp = new QApplication(ac, av);
1899 configSettings = new ConfigSettings();
1900 configSettings->beginGroup("/kconfig/qconf");
1901 v = new ConfigMainWindow();
1903 //zconfdump(stdout);
1904 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1905 configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
1909 configSettings->endGroup();
1910 delete configSettings;