[PATCH] qconf: fix SIGSEGV on empty menu items
[linux-2.6.git] / scripts / kconfig / qconf.cc
index 425ce5c..a8ffc32 100644 (file)
@@ -38,6 +38,8 @@
 static QApplication *configApp;
 static ConfigSettings *configSettings;
 
+QAction *ConfigMainWindow::saveAction;
+
 static inline QString qgettext(const char* str)
 {
        return QString::fromLocal8Bit(gettext(str));
@@ -381,6 +383,18 @@ void ConfigList::saveSettings(void)
        }
 }
 
+ConfigItem* ConfigList::findConfigItem(struct menu *menu)
+{
+       ConfigItem* item = (ConfigItem*)menu->data;
+
+       for (; item; item = item->nextItem) {
+               if (this == item->listView())
+                       break;
+       }
+
+       return item;
+}
+
 void ConfigList::updateSelection(void)
 {
        struct menu *menu;
@@ -524,6 +538,7 @@ void ConfigList::setRootMenu(struct menu *menu)
        rootEntry = menu;
        updateListAll();
        setSelected(currentItem(), hasFocus());
+       ensureItemVisible(currentItem());
 }
 
 void ConfigList::setParentMenu(void)
@@ -766,14 +781,16 @@ skip:
 
 void ConfigList::focusInEvent(QFocusEvent *e)
 {
-       Parent::focusInEvent(e);
+       struct menu *menu = NULL;
 
-       QListViewItem* item = currentItem();
-       if (!item)
-               return;
+       Parent::focusInEvent(e);
 
-       setSelected(item, TRUE);
-       emit gotFocus();
+       ConfigItem* item = (ConfigItem *)currentItem();
+       if (item) {
+               setSelected(item, TRUE);
+               menu = item->menu;
+       }
+       emit gotFocus(menu);
 }
 
 void ConfigList::contextMenuEvent(QContextMenuEvent *e)
@@ -783,7 +800,7 @@ void ConfigList::contextMenuEvent(QContextMenuEvent *e)
                        QAction *action;
 
                        headerPopup = new QPopupMenu(this);
-                       action = new QAction("Show Name", 0, this);
+                       action = new QAction(NULL, "Show Name", 0, this);
                          action->setToggleAction(TRUE);
                          connect(action, SIGNAL(toggled(bool)),
                                  parent(), SLOT(setShowName(bool)));
@@ -791,7 +808,7 @@ void ConfigList::contextMenuEvent(QContextMenuEvent *e)
                                  action, SLOT(setOn(bool)));
                          action->setOn(showName);
                          action->addTo(headerPopup);
-                       action = new QAction("Show Range", 0, this);
+                       action = new QAction(NULL, "Show Range", 0, this);
                          action->setToggleAction(TRUE);
                          connect(action, SIGNAL(toggled(bool)),
                                  parent(), SLOT(setShowRange(bool)));
@@ -799,7 +816,7 @@ void ConfigList::contextMenuEvent(QContextMenuEvent *e)
                                  action, SLOT(setOn(bool)));
                          action->setOn(showRange);
                          action->addTo(headerPopup);
-                       action = new QAction("Show Data", 0, this);
+                       action = new QAction(NULL, "Show Data", 0, this);
                          action->setToggleAction(TRUE);
                          connect(action, SIGNAL(toggled(bool)),
                                  parent(), SLOT(setShowData(bool)));
@@ -908,6 +925,8 @@ ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
                configSettings->endGroup();
                connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
        }
+
+       has_dbg_info = 0;
 }
 
 void ConfigInfoView::saveSettings(void)
@@ -933,11 +952,16 @@ void ConfigInfoView::setShowDebug(bool b)
 
 void ConfigInfoView::setInfo(struct menu *m)
 {
+       if (menu == m)
+               return;
        menu = m;
-       if (!menu)
+       if (!menu) {
+               has_dbg_info = 0;
                clear();
-       else
+       } else {
+               has_dbg_info = 1;
                menuInfo();
+       }
 }
 
 void ConfigInfoView::setSource(const QString& name)
@@ -954,6 +978,7 @@ void ConfigInfoView::setSource(const QString& name)
                if (sscanf(p, "m%p", &m) == 1 && menu != m) {
                        menu = m;
                        menuInfo();
+                       emit menuSelected(menu);
                }
                break;
        case 's':
@@ -971,6 +996,9 @@ void ConfigInfoView::symbolInfo(void)
 {
        QString str;
 
+       if (!has_dbg_info)
+               return;
+
        str += "<big>Symbol: <b>";
        str += print_filter(sym->name);
        str += "</b></big><br><br>value: ";
@@ -1143,7 +1171,7 @@ void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char
 QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos)
 {
        QPopupMenu* popup = Parent::createPopupMenu(pos);
-       QAction* action = new QAction("Show Debug Info", 0, popup);
+       QAction* action = new QAction(NULL,"Show Debug Info", 0, popup);
          action->setToggleAction(TRUE);
          connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
          connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
@@ -1241,6 +1269,7 @@ void ConfigSearchWindow::search(void)
  * Construct the complete config widget
  */
 ConfigMainWindow::ConfigMainWindow(void)
+       : searchWindow(0)
 {
        QMenuBar* menu;
        bool ok;
@@ -1287,8 +1316,11 @@ ConfigMainWindow::ConfigMainWindow(void)
          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()));
-       QAction *saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
+       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("Search", "&Search", CTRL+Key_F, this);
@@ -1380,10 +1412,14 @@ ConfigMainWindow::ConfigMainWindow(void)
        connect(menuList, SIGNAL(menuSelected(struct menu *)),
                SLOT(changeMenu(struct menu *)));
 
-       connect(configList, SIGNAL(gotFocus(void)),
-               SLOT(listFocusChanged(void)));
-       connect(menuList, SIGNAL(gotFocus(void)),
+       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")
@@ -1403,18 +1439,6 @@ ConfigMainWindow::ConfigMainWindow(void)
                split2->setSizes(sizes);
 }
 
-/*
- * display a new help entry as soon as a new menu entry is selected
- */
-void ConfigMainWindow::setHelp(QListViewItem* item)
-{
-       struct menu* menu = 0;
-
-       if (item)
-               menu = ((ConfigItem*)item)->menu;
-       helpText->setInfo(menu);
-}
-
 void ConfigMainWindow::loadConfig(void)
 {
        QString s = QFileDialog::getOpenFileName(".config", NULL, this);
@@ -1453,17 +1477,62 @@ void ConfigMainWindow::changeMenu(struct menu *menu)
        backAction->setEnabled(TRUE);
 }
 
-void ConfigMainWindow::listFocusChanged(void)
+void ConfigMainWindow::setMenuLink(struct menu *menu)
 {
-       if (menuList->hasFocus()) {
-               if (menuList->mode == menuMode)
+       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();
-               setHelp(menuList->selectedItem());
-       } else if (configList->hasFocus()) {
-               setHelp(configList->selectedItem());
+                       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;
@@ -1529,7 +1598,7 @@ void ConfigMainWindow::showFullView(void)
  */
 void ConfigMainWindow::closeEvent(QCloseEvent* e)
 {
-       if (!sym_change_count) {
+       if (!conf_get_changed()) {
                e->accept();
                return;
        }
@@ -1602,6 +1671,12 @@ void ConfigMainWindow::saveSettings(void)
        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;