📄 qconf.cc
字号:
SLOT(listFocusChanged(void))); connect(menuList, SIGNAL(gotFocus(void)), SLOT(listFocusChanged(void)));#if QT_VERSION >= 300 QString listMode = configSettings->readEntry("/kconfig/qconf/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("/kconfig/qconf/split1", &ok); if (ok) split1->setSizes(sizes); sizes = configSettings->readSizes("/kconfig/qconf/split2", &ok); if (ok) split2->setSizes(sizes);#else showSplitView();#endif delete configSettings;}static QString print_filter(const QString &str){ QRegExp re("[<>&\"\\n]"); QString res = str; for (int i = 0; (i = res.find(re, i)) >= 0;) { switch (res[i].latin1()) { case '<': res.replace(i, 1, "<"); i += 4; break; case '>': res.replace(i, 1, ">"); i += 4; break; case '&': res.replace(i, 1, "&"); i += 5; break; case '"': res.replace(i, 1, """); i += 6; break; case '\n': res.replace(i, 1, "<br>"); i += 4; break; } } return res;}static void expr_print_help(void *data, const char *str){ reinterpret_cast<QString*>(data)->append(print_filter(str));}/* * display a new help entry as soon as a new menu entry is selected */void ConfigMainWindow::setHelp(QListViewItem* item){ struct symbol* sym; struct menu* menu = 0; configList->parent()->lineEdit->hide(); if (item) menu = ((ConfigItem*)item)->menu; if (!menu) { helpText->setText(QString::null); return; } QString head, debug, help; menu = ((ConfigItem*)item)->menu; sym = menu->sym; if (sym) { if (menu->prompt) { head += "<big><b>"; head += print_filter(_(menu->prompt->text)); head += "</b></big>"; if (sym->name) { head += " ("; head += print_filter(_(sym->name)); head += ")"; } } else if (sym->name) { head += "<big><b>"; head += print_filter(_(sym->name)); head += "</b></big>"; } head += "<br><br>"; if (showDebug) { debug += "type: "; debug += print_filter(sym_type_name(sym->type)); if (sym_is_choice(sym)) debug += " (choice)"; debug += "<br>"; if (sym->rev_dep.expr) { debug += "reverse dep: "; expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } for (struct property *prop = sym->prop; prop; prop = prop->next) { switch (prop->type) { case P_PROMPT: case P_MENU: debug += "prompt: "; debug += print_filter(_(prop->text)); debug += "<br>"; break; case P_DEFAULT: debug += "default: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; case P_CHOICE: if (sym_is_choice(sym)) { debug += "choice: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } break; case P_SELECT: debug += "select: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; case P_RANGE: debug += "range: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; default: debug += "unknown property: "; debug += prop_get_type_name(prop->type); debug += "<br>"; } if (prop->visible.expr) { debug += " dep: "; expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } } debug += "<br>"; } help = print_filter(_(sym->help)); } else if (menu->prompt) { head += "<big><b>"; head += print_filter(_(menu->prompt->text)); head += "</b></big><br><br>"; if (showDebug) { if (menu->prompt->visible.expr) { debug += " dep: "; expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); debug += "<br><br>"; } } } if (showDebug) debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno); helpText->setText(head + debug + help);}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::changeMenu(struct menu *menu){ configList->setRootMenu(menu); backAction->setEnabled(TRUE);}void ConfigMainWindow::listFocusChanged(void){ if (menuList->hasFocus()) { if (menuList->mode == menuMode) configList->clearSelection(); setHelp(menuList->selectedItem()); } else if (configList->hasFocus()) { setHelp(configList->selectedItem()); }}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();}void ConfigMainWindow::setShowAll(bool b){ if (configList->showAll == b) return; configList->showAll = b; configList->updateListAll(); menuList->showAll = b; menuList->updateListAll();}void ConfigMainWindow::setShowDebug(bool b){ if (showDebug == b) return; showDebug = b;}void ConfigMainWindow::setShowName(bool b){ if (configList->showName == b) return; configList->showName = b; configList->reinit(); menuList->showName = b; menuList->reinit();}void ConfigMainWindow::setShowRange(bool b){ if (configList->showRange == b) return; configList->showRange = b; configList->reinit(); menuList->showRange = b; menuList->reinit();}void ConfigMainWindow::setShowData(bool b){ if (configList->showData == b) return; configList->showData = b; configList->reinit(); menuList->showData = b; menuList->reinit();}/* * ask for saving configuration before quitting * TODO ask only when something changed */void ConfigMainWindow::closeEvent(QCloseEvent* e){ if (!sym_change_count) { 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 busybox 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://bugs.busybox.net/\n"; QMessageBox::information(this, "qconf", str);}void ConfigMainWindow::saveSettings(void){#if QT_VERSION >= 300 ConfigSettings *configSettings = new ConfigSettings; configSettings->writeEntry("/kconfig/qconf/window x", pos().x()); configSettings->writeEntry("/kconfig/qconf/window y", pos().y()); configSettings->writeEntry("/kconfig/qconf/window width", size().width()); configSettings->writeEntry("/kconfig/qconf/window height", size().height()); configSettings->writeEntry("/kconfig/qconf/showName", configList->showName); configSettings->writeEntry("/kconfig/qconf/showRange", configList->showRange); configSettings->writeEntry("/kconfig/qconf/showData", configList->showData); configSettings->writeEntry("/kconfig/qconf/showAll", configList->showAll); configSettings->writeEntry("/kconfig/qconf/showDebug", showDebug); QString entry; switch(configList->mode) { case singleMode : entry = "single"; break; case symbolMode : entry = "split"; break; case fullMode : entry = "full"; break; } configSettings->writeEntry("/kconfig/qconf/listMode", entry); configSettings->writeSizes("/kconfig/qconf/split1", split1->sizes()); configSettings->writeSizes("/kconfig/qconf/split2", split2->sizes()); delete configSettings;#endif}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); v = new ConfigMainWindow(); //zconfdump(stdout); v->show(); configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings())); configApp->exec(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -