📄 qconf.cc
字号:
popup->insertSeparator(); action->addTo(popup); return popup;}void ConfigInfoView::contentsContextMenuEvent(QContextMenuEvent *e){ Parent::contentsContextMenuEvent(e);}ConfigSearchWindow::ConfigSearchWindow(ConfigMainWindow* parent, const char *name) : Parent(parent, name), result(NULL){ setCaption("Search Config"); QVBoxLayout* layout1 = new QVBoxLayout(this, 11, 6); QHBoxLayout* layout2 = new QHBoxLayout(0, 0, 6); layout2->addWidget(new QLabel("Find:", this)); editField = new QLineEdit(this); connect(editField, SIGNAL(returnPressed()), SLOT(search())); layout2->addWidget(editField); searchButton = new QPushButton("Search", this); searchButton->setAutoDefault(FALSE); connect(searchButton, SIGNAL(clicked()), SLOT(search())); layout2->addWidget(searchButton); layout1->addLayout(layout2); split = new QSplitter(this); split->setOrientation(QSplitter::Vertical); list = new ConfigView(split, name); list->list->mode = listMode; info = new ConfigInfoView(split, name); connect(list->list, SIGNAL(menuChanged(struct menu *)), info, SLOT(setInfo(struct menu *))); connect(list->list, SIGNAL(menuChanged(struct menu *)), parent, SLOT(setMenuLink(struct menu *))); layout1->addWidget(split); if (name) { int x, y, width, height; bool ok; configSettings->beginGroup(name); width = configSettings->readNumEntry("/window width", parent->width() / 2); height = configSettings->readNumEntry("/window height", parent->height() / 2); resize(width, height); x = configSettings->readNumEntry("/window x", 0, &ok); if (ok) y = configSettings->readNumEntry("/window y", 0, &ok); if (ok) move(x, y); QValueList<int> sizes = configSettings->readSizes("/split", &ok); if (ok) split->setSizes(sizes); configSettings->endGroup(); connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); }}void ConfigSearchWindow::saveSettings(void){ if (name()) { configSettings->beginGroup(name()); configSettings->writeEntry("/window x", pos().x()); configSettings->writeEntry("/window y", pos().y()); configSettings->writeEntry("/window width", size().width()); configSettings->writeEntry("/window height", size().height()); configSettings->writeSizes("/split", split->sizes()); configSettings->endGroup(); }}void ConfigSearchWindow::search(void){ struct symbol **p; struct property *prop; ConfigItem *lastItem = NULL; free(result); list->list->clear(); info->clear(); result = sym_re_search(editField->text().latin1()); if (!result) return; for (p = result; *p; p++) { for_all_prompts((*p), prop) lastItem = new ConfigItem(list->list, lastItem, prop->menu, menu_is_visible(prop->menu)); }}/* * Construct the complete config widget */ConfigMainWindow::ConfigMainWindow(void) : searchWindow(0){ QMenuBar* menu; bool ok; int x, y, width, height; char title[256]; QWidget *d = configApp->desktop(); snprintf(title, sizeof(title), _("Linux Kernel v%s Configuration"), getenv("KERNELVERSION")); setCaption(title); width = configSettings->readNumEntry("/window width", d->width() - 64); height = configSettings->readNumEntry("/window height", d->height() - 64); resize(width, height); x = configSettings->readNumEntry("/window x", 0, &ok); if (ok) y = configSettings->readNumEntry("/window y", 0, &ok); if (ok) move(x, y); split1 = new QSplitter(this); split1->setOrientation(QSplitter::Horizontal); setCentralWidget(split1); menuView = new ConfigView(split1, "menu"); menuList = menuView->list; split2 = new QSplitter(split1); split2->setOrientation(QSplitter::Vertical); // create config tree configView = new ConfigView(split2, "config"); configList = configView->list; helpText = new ConfigInfoView(split2, "help"); helpText->setTextFormat(Qt::RichText); setTabOrder(configList, helpText); configList->setFocus(); menu = menuBar(); toolBar = new QToolBar("Tools", this); backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this); connect(backAction, SIGNAL(activated()), SLOT(goBack())); backAction->setEnabled(FALSE); QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this); connect(quitAction, SIGNAL(activated()), SLOT(close())); QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this); connect(loadAction, SIGNAL(activated()), SLOT(loadConfig())); saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this); connect(saveAction, SIGNAL(activated()), SLOT(saveConfig())); conf_set_changed_callback(conf_changed); // Set saveAction's initial state conf_changed(); QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this); connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs())); QAction *searchAction = new QAction("Find", "&Find", CTRL+Key_F, this); connect(searchAction, SIGNAL(activated()), SLOT(searchConfig())); QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this); connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView())); QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this); connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView())); QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this); connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView())); QAction *showNameAction = new QAction(NULL, "Show Name", 0, this); showNameAction->setToggleAction(TRUE); connect(showNameAction, SIGNAL(toggled(bool)), configView, SLOT(setShowName(bool))); connect(configView, SIGNAL(showNameChanged(bool)), showNameAction, SLOT(setOn(bool))); showNameAction->setOn(configView->showName()); QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this); showRangeAction->setToggleAction(TRUE); connect(showRangeAction, SIGNAL(toggled(bool)), configView, SLOT(setShowRange(bool))); connect(configView, SIGNAL(showRangeChanged(bool)), showRangeAction, SLOT(setOn(bool))); showRangeAction->setOn(configList->showRange); QAction *showDataAction = new QAction(NULL, "Show Data", 0, this); showDataAction->setToggleAction(TRUE); connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool))); connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool))); showDataAction->setOn(configList->showData); QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this); showAllAction->setToggleAction(TRUE); connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool))); connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool))); showAllAction->setOn(configList->showAll); QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this); showDebugAction->setToggleAction(TRUE); connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); connect(helpText, SIGNAL(showDebugChanged(bool)), showDebugAction, SLOT(setOn(bool))); showDebugAction->setOn(helpText->showDebug()); QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this); connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro())); QAction *showAboutAction = new QAction(NULL, "About", 0, this); connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout())); // init tool bar backAction->addTo(toolBar); toolBar->addSeparator(); loadAction->addTo(toolBar); saveAction->addTo(toolBar); toolBar->addSeparator(); singleViewAction->addTo(toolBar); splitViewAction->addTo(toolBar); fullViewAction->addTo(toolBar); // create config menu QPopupMenu* config = new QPopupMenu(this); menu->insertItem("&File", config); loadAction->addTo(config); saveAction->addTo(config); saveAsAction->addTo(config); config->insertSeparator(); quitAction->addTo(config); // create edit menu QPopupMenu* editMenu = new QPopupMenu(this); menu->insertItem("&Edit", editMenu); searchAction->addTo(editMenu); // create options menu QPopupMenu* optionMenu = new QPopupMenu(this); menu->insertItem("&Option", optionMenu); showNameAction->addTo(optionMenu); showRangeAction->addTo(optionMenu); showDataAction->addTo(optionMenu); optionMenu->insertSeparator(); showAllAction->addTo(optionMenu); showDebugAction->addTo(optionMenu); // create help menu QPopupMenu* helpMenu = new QPopupMenu(this); menu->insertSeparator(); menu->insertItem("&Help", helpMenu); showIntroAction->addTo(helpMenu); showAboutAction->addTo(helpMenu); connect(configList, SIGNAL(menuChanged(struct menu *)), helpText, SLOT(setInfo(struct menu *))); connect(configList, SIGNAL(menuSelected(struct menu *)), SLOT(changeMenu(struct menu *))); connect(configList, SIGNAL(parentSelected()), SLOT(goBack())); connect(menuList, SIGNAL(menuChanged(struct menu *)), helpText, SLOT(setInfo(struct menu *))); connect(menuList, SIGNAL(menuSelected(struct menu *)), SLOT(changeMenu(struct menu *))); connect(configList, SIGNAL(gotFocus(struct menu *)), helpText, SLOT(setInfo(struct menu *))); connect(menuList, SIGNAL(gotFocus(struct menu *)), helpText, SLOT(setInfo(struct menu *))); connect(menuList, SIGNAL(gotFocus(struct menu *)), SLOT(listFocusChanged(void))); connect(helpText, SIGNAL(menuSelected(struct menu *)), SLOT(setMenuLink(struct menu *))); QString listMode = configSettings->readEntry("/listMode", "symbol"); if (listMode == "single") showSingleView(); else if (listMode == "full") showFullView(); else /*if (listMode == "split")*/ showSplitView(); // UI setup done, restore splitter positions QValueList<int> sizes = configSettings->readSizes("/split1", &ok); if (ok) split1->setSizes(sizes); sizes = configSettings->readSizes("/split2", &ok); if (ok) split2->setSizes(sizes);}void ConfigMainWindow::loadConfig(void){ QString s = QFileDialog::getOpenFileName(".config", NULL, this); if (s.isNull()) return; if (conf_read(QFile::encodeName(s))) QMessageBox::information(this, "qconf", "Unable to load configuration!"); ConfigView::updateListAll();}void ConfigMainWindow::saveConfig(void){ if (conf_write(NULL)) QMessageBox::information(this, "qconf", "Unable to save configuration!");}void ConfigMainWindow::saveConfigAs(void){ QString s = QFileDialog::getSaveFileName(".config", NULL, this); if (s.isNull()) return; if (conf_write(QFile::encodeName(s))) QMessageBox::information(this, "qconf", "Unable to save configuration!");}void ConfigMainWindow::searchConfig(void){ if (!searchWindow) searchWindow = new ConfigSearchWindow(this, "search"); searchWindow->show();}void ConfigMainWindow::changeMenu(struct menu *menu){ configList->setRootMenu(menu); if (configList->rootEntry->parent == &rootmenu) backAction->setEnabled(FALSE); else backAction->setEnabled(TRUE);}void ConfigMainWindow::setMenuLink(struct menu *menu){ struct menu *parent; ConfigList* list = NULL; ConfigItem* item; if (!menu_is_visible(menu) && !configView->showAll()) return; switch (configList->mode) { case singleMode: list = configList; parent = menu_get_parent_menu(menu); if (!parent) return; list->setRootMenu(parent); break; case symbolMode: if (menu->flags & MENU_ROOT) { configList->setRootMenu(menu); configList->clearSelection(); list = menuList; } else { list = configList; parent = menu_get_parent_menu(menu->parent); if (!parent) return; item = menuList->findConfigItem(parent); if (item) { menuList->setSelected(item, TRUE); menuList->ensureItemVisible(item); } list->setRootMenu(parent); } break; case fullMode: list = configList; break; } if (list) { item = list->findConfigItem(menu); if (item) { list->setSelected(item, TRUE); list->ensureItemVisible(item); list->setFocus(); } }}void ConfigMainWindow::listFocusChanged(void){ if (menuList->mode == menuMode) configList->clearSelection();}void ConfigMainWindow::goBack(void){ ConfigItem* item; configList->setParentMenu(); if (configList->rootEntry == &rootmenu) backAction->setEnabled(FALSE); item = (ConfigItem*)menuList->selectedItem(); while (item) { if (item->menu == configList->rootEntry) { menuList->setSelected(item, TRUE); break; } item = (ConfigItem*)item->parent(); }}void ConfigMainWindow::showSingleView(void){ menuView->hide(); menuList->setRootMenu(0); configList->mode = singleMode; if (configList->rootEntry == &rootmenu) configList->updateListAll(); else configList->setRootMenu(&rootmenu); configList->setAllOpen(TRUE); configList->setFocus();}void ConfigMainWindow::showSplitView(void){ configList->mode = symbolMode; if (configList->rootEntry == &rootmenu) configList->updateListAll(); else configList->setRootMenu(&rootmenu); configList->setAllOpen(TRUE); configApp->processEvents(); menuList->mode = menuMode; menuList->setRootMenu(&rootmenu); menuList->setAllOpen(TRUE); menuView->show(); menuList->setFocus();}void ConfigMainWindow::showFullView(void){ menuView->hide(); menuList->setRootMenu(0); configList->mode = fullMode; if (configList->rootEntry == &rootmenu) configList->updateListAll(); else configList->setRootMenu(&rootmenu); configList->setAllOpen(FALSE); configList->setFocus();}/* * ask for saving configuration before quitting * TODO ask only when something changed */void ConfigMainWindow::closeEvent(QCloseEvent* e){ if (!conf_get_changed()) { e->accept(); return; } QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); mb.setButtonText(QMessageBox::Yes, "&Save Changes"); mb.setButtonText(QMessageBox::No, "&Discard Changes"); mb.setButtonText(QMessageBox::Cancel, "Cancel Exit"); switch (mb.exec()) { case QMessageBox::Yes: conf_write(NULL); case QMessageBox::No: e->accept(); break; case QMessageBox::Cancel: e->ignore(); break; }}void ConfigMainWindow::showIntro(void){ static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n" "For each option, a blank box indicates the feature is disabled, a check\n" "indicates it is enabled, and a dot indicates that it is to be compiled\n" "as a module. Clicking on the box will cycle through the three states.\n\n" "If you do not see an option (e.g., a device driver) that you believe\n" "should be present, try turning on Show All Options under the Options menu.\n" "Although there is no cross reference yet to help you figure out what other\n" "options must be enabled to support the option you are interested in, you can\n" "still view the help of a grayed-out option.\n\n" "Toggling Show Debug Info under the Options menu will show the dependencies,\n" "which you can then match by examining other options.\n\n"; QMessageBox::information(this, "qconf", str);}void ConfigMainWindow::showAbout(void){ static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n" "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"; QMessageBox::information(this, "qconf", str);}void ConfigMainWindow::saveSettings(void){ configSettings->writeEntry("/window x", pos().x()); configSettings->writeEntry("/window y", pos().y()); configSettings->writeEntry("/window width", size().width()); configSettings->writeEntry("/window height", size().height()); QString entry; switch(configList->mode) { case singleMode : entry = "single"; break; case symbolMode : entry = "split"; break; case fullMode : entry = "full"; break; } configSettings->writeEntry("/listMode", entry); configSettings->writeSizes("/split1", split1->sizes()); configSettings->writeSizes("/split2", split2->sizes());}void ConfigMainWindow::conf_changed(void){ if (saveAction) saveAction->setEnabled(conf_get_changed());}void fixup_rootmenu(struct menu *menu){ struct menu *child; static int menu_cnt = 0; menu->flags |= MENU_ROOT; for (child = menu->list; child; child = child->next) { if (child->prompt && child->prompt->type == P_MENU) { menu_cnt++; fixup_rootmenu(child); menu_cnt--; } else if (!menu_cnt) fixup_rootmenu(child); }}static const char *progname;static void usage(void){ printf("%s <config>\n", progname); exit(0);}int main(int ac, char** av){ ConfigMainWindow* v; const char *name; bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE);#ifndef LKC_DIRECT_LINK kconfig_load();#endif progname = av[0]; configApp = new QApplication(ac, av); if (ac > 1 && av[1][0] == '-') { switch (av[1][1]) { case 'h': case '?': usage(); } name = av[2]; } else name = av[1]; if (!name) usage(); conf_parse(name); fixup_rootmenu(&rootmenu); conf_read(NULL); //zconfdump(stdout); configSettings = new ConfigSettings(); configSettings->beginGroup("/kconfig/qconf"); v = new ConfigMainWindow(); //zconfdump(stdout); configApp->setMainWidget(v); configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); v->show(); configApp->exec(); configSettings->endGroup(); delete configSettings; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -