kconfig/conf: add command line options' description
[linux-2.6.git] / scripts / kconfig / gconf.c
index 9f5aabd..9f44380 100644 (file)
@@ -30,18 +30,16 @@ enum {
        SINGLE_VIEW, SPLIT_VIEW, FULL_VIEW
 };
 
+enum {
+       OPT_NORMAL, OPT_ALL, OPT_PROMPT
+};
+
 static gint view_mode = FULL_VIEW;
 static gboolean show_name = TRUE;
 static gboolean show_range = TRUE;
 static gboolean show_value = TRUE;
-static gboolean show_all = FALSE;
-static gboolean show_debug = FALSE;
 static gboolean resizeable = FALSE;
-
-static gboolean config_changed = FALSE;
-
-static char nohelp_text[] =
-    N_("Sorry, no help available for this option yet.\n");
+static int opt_mode = OPT_NORMAL;
 
 GtkWidget *main_wnd = NULL;
 GtkWidget *tree1_w = NULL;     // left  frame
@@ -50,6 +48,8 @@ GtkWidget *text_w = NULL;
 GtkWidget *hpaned = NULL;
 GtkWidget *vpaned = NULL;
 GtkWidget *back_btn = NULL;
+GtkWidget *save_btn = NULL;
+GtkWidget *save_menu_item = NULL;
 
 GtkTextTag *tag1, *tag2;
 GdkColor color;
@@ -75,51 +75,16 @@ static void display_tree_part(void);
 static void update_tree(struct menu *src, GtkTreeIter * dst);
 static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row);
 static gchar **fill_row(struct menu *menu);
-
+static void conf_changed(void);
 
 /* Helping/Debugging Functions */
 
-
-const char *dbg_print_stype(int val)
+const char *dbg_sym_flags(int val)
 {
        static char buf[256];
 
        bzero(buf, 256);
 
-       if (val == S_UNKNOWN)
-               strcpy(buf, "unknown");
-       if (val == S_BOOLEAN)
-               strcpy(buf, "boolean");
-       if (val == S_TRISTATE)
-               strcpy(buf, "tristate");
-       if (val == S_INT)
-               strcpy(buf, "int");
-       if (val == S_HEX)
-               strcpy(buf, "hex");
-       if (val == S_STRING)
-               strcpy(buf, "string");
-       if (val == S_OTHER)
-               strcpy(buf, "other");
-
-#ifdef DEBUG
-       printf("%s", buf);
-#endif
-
-       return buf;
-}
-
-const char *dbg_print_flags(int val)
-{
-       static char buf[256];
-
-       bzero(buf, 256);
-
-       if (val & SYMBOL_YES)
-               strcat(buf, "yes/");
-       if (val & SYMBOL_MOD)
-               strcat(buf, "mod/");
-       if (val & SYMBOL_NO)
-               strcat(buf, "no/");
        if (val & SYMBOL_CONST)
                strcat(buf, "const/");
        if (val & SYMBOL_CHECK)
@@ -128,8 +93,6 @@ const char *dbg_print_flags(int val)
                strcat(buf, "choice/");
        if (val & SYMBOL_CHOICEVAL)
                strcat(buf, "choiceval/");
-       if (val & SYMBOL_PRINTED)
-               strcat(buf, "printed/");
        if (val & SYMBOL_VALID)
                strcat(buf, "valid/");
        if (val & SYMBOL_OPTIONAL)
@@ -138,46 +101,14 @@ const char *dbg_print_flags(int val)
                strcat(buf, "write/");
        if (val & SYMBOL_CHANGED)
                strcat(buf, "changed/");
-       if (val & SYMBOL_NEW)
-               strcat(buf, "new/");
        if (val & SYMBOL_AUTO)
                strcat(buf, "auto/");
 
        buf[strlen(buf) - 1] = '\0';
-#ifdef DEBUG
-       printf("%s", buf);
-#endif
 
        return buf;
 }
 
-const char *dbg_print_ptype(int val)
-{
-       static char buf[256];
-
-       bzero(buf, 256);
-
-       if (val == P_UNKNOWN)
-               strcpy(buf, "unknown");
-       if (val == P_PROMPT)
-               strcpy(buf, "prompt");
-       if (val == P_COMMENT)
-               strcpy(buf, "comment");
-       if (val == P_MENU)
-               strcpy(buf, "menu");
-       if (val == P_DEFAULT)
-               strcpy(buf, "default");
-       if (val == P_CHOICE)
-               strcpy(buf, "choice");
-
-#ifdef DEBUG
-       printf("%s", buf);
-#endif
-
-       return buf;
-}
-
-
 void replace_button_icon(GladeXML * xml, GdkDrawable * window,
                         GtkStyle * style, gchar * btn_name, gchar ** xpm)
 {
@@ -202,7 +133,6 @@ void init_main_window(const gchar * glade_file)
        GladeXML *xml;
        GtkWidget *widget;
        GtkTextBuffer *txtbuf;
-       char title[256];
        GtkStyle *style;
 
        xml = glade_xml_new(glade_file, "window1", NULL);
@@ -232,6 +162,10 @@ void init_main_window(const gchar * glade_file)
        gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
                                       show_value);
 
+       save_btn = glade_xml_get_widget(xml, "button3");
+       save_menu_item = glade_xml_get_widget(xml, "save1");
+       conf_set_changed_callback(conf_changed);
+
        style = gtk_widget_get_style(main_wnd);
        widget = glade_xml_get_widget(xml, "toolbar1");
 
@@ -275,9 +209,7 @@ void init_main_window(const gchar * glade_file)
                                          /*"style", PANGO_STYLE_OBLIQUE, */
                                          NULL);
 
-       sprintf(title, _("Linux Kernel v%s Configuration"),
-               getenv("KERNELRELEASE"));
-       gtk_window_set_title(GTK_WINDOW(main_wnd), title);
+       gtk_window_set_title(GTK_WINDOW(main_wnd), rootmenu.prompt->text);
 
        gtk_widget_show(main_wnd);
 }
@@ -321,7 +253,7 @@ void init_left_tree(void)
 
        gtk_tree_view_set_model(view, model1);
        gtk_tree_view_set_headers_visible(view, TRUE);
-       gtk_tree_view_set_rules_hint(view, FALSE);
+       gtk_tree_view_set_rules_hint(view, TRUE);
 
        column = gtk_tree_view_column_new();
        gtk_tree_view_append_column(view, column);
@@ -353,8 +285,6 @@ void init_left_tree(void)
 static void renderer_edited(GtkCellRendererText * cell,
                            const gchar * path_string,
                            const gchar * new_text, gpointer user_data);
-static void renderer_toggled(GtkCellRendererToggle * cellrenderertoggle,
-                            gchar * arg1, gpointer user_data);
 
 void init_right_tree(void)
 {
@@ -366,7 +296,7 @@ void init_right_tree(void)
 
        gtk_tree_view_set_model(view, model2);
        gtk_tree_view_set_headers_visible(view, TRUE);
-       gtk_tree_view_set_rules_hint(view, FALSE);
+       gtk_tree_view_set_rules_hint(view, TRUE);
 
        column = gtk_tree_view_column_new();
        gtk_tree_view_append_column(view, column);
@@ -388,8 +318,6 @@ void init_right_tree(void)
                                            "inconsistent", COL_BTNINC,
                                            "visible", COL_BTNVIS,
                                            "radio", COL_BTNRAD, NULL);
-       /*g_signal_connect(G_OBJECT(renderer), "toggled",
-          G_CALLBACK(renderer_toggled), NULL); */
        renderer = gtk_cell_renderer_text_new();
        gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
                                        renderer, FALSE);
@@ -464,19 +392,10 @@ static void text_insert_help(struct menu *menu)
 {
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
-       const char *prompt = menu_get_prompt(menu);
-       gchar *name;
-       const char *help = _(nohelp_text);
-
-       if (!menu->sym)
-               help = "";
-       else if (menu->sym->help)
-               help = _(menu->sym->help);
+       const char *prompt = _(menu_get_prompt(menu));
+       struct gstr help = str_new();
 
-       if (menu->sym && menu->sym->name)
-               name = g_strdup_printf(_(menu->sym->name));
-       else
-               name = g_strdup("");
+       menu_get_ext_help(menu, &help);
 
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
        gtk_text_buffer_get_bounds(buffer, &start, &end);
@@ -486,14 +405,11 @@ static void text_insert_help(struct menu *menu)
        gtk_text_buffer_get_end_iter(buffer, &end);
        gtk_text_buffer_insert_with_tags(buffer, &end, prompt, -1, tag1,
                                         NULL);
-       gtk_text_buffer_insert_at_cursor(buffer, " ", 1);
-       gtk_text_buffer_get_end_iter(buffer, &end);
-       gtk_text_buffer_insert_with_tags(buffer, &end, name, -1, tag1,
-                                        NULL);
        gtk_text_buffer_insert_at_cursor(buffer, "\n\n", 2);
        gtk_text_buffer_get_end_iter(buffer, &end);
-       gtk_text_buffer_insert_with_tags(buffer, &end, help, -1, tag2,
+       gtk_text_buffer_insert_with_tags(buffer, &end, str_get(&help), -1, tag2,
                                         NULL);
+       str_free(&help);
 }
 
 
@@ -520,14 +436,14 @@ static void text_insert_msg(const char *title, const char *message)
 
 /* Main Windows Callbacks */
 
-void on_save1_activate(GtkMenuItem * menuitem, gpointer user_data);
+void on_save_activate(GtkMenuItem * menuitem, gpointer user_data);
 gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
                                 gpointer user_data)
 {
        GtkWidget *dialog, *label;
        gint result;
 
-       if (config_changed == FALSE)
+       if (!conf_get_changed())
                return FALSE;
 
        dialog = gtk_dialog_new_with_buttons(_("Warning !"),
@@ -551,7 +467,7 @@ gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
        result = gtk_dialog_run(GTK_DIALOG(dialog));
        switch (result) {
        case GTK_RESPONSE_YES:
-               on_save1_activate(NULL, NULL);
+               on_save_activate(NULL, NULL);
                return FALSE;
        case GTK_RESPONSE_NO:
                return FALSE;
@@ -629,12 +545,10 @@ void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
 }
 
 
-void on_save1_activate(GtkMenuItem * menuitem, gpointer user_data)
+void on_save_activate(GtkMenuItem * menuitem, gpointer user_data)
 {
        if (conf_write(NULL))
                text_insert_msg(_("Error"), _("Unable to save configuration !"));
-
-       config_changed = FALSE;
 }
 
 
@@ -720,20 +634,29 @@ void on_show_data1_activate(GtkMenuItem * menuitem, gpointer user_data)
 
 
 void
-on_show_all_options1_activate(GtkMenuItem * menuitem, gpointer user_data)
+on_set_option_mode1_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
-       show_all = GTK_CHECK_MENU_ITEM(menuitem)->active;
+       opt_mode = OPT_NORMAL;
+       gtk_tree_store_clear(tree2);
+       display_tree(&rootmenu);        /* instead of update_tree to speed-up */
+}
 
+
+void
+on_set_option_mode2_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+       opt_mode = OPT_ALL;
        gtk_tree_store_clear(tree2);
-       display_tree(&rootmenu);        // instead of update_tree to speed-up
+       display_tree(&rootmenu);        /* instead of update_tree to speed-up */
 }
 
 
 void
-on_show_debug_info1_activate(GtkMenuItem * menuitem, gpointer user_data)
+on_set_option_mode3_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
-       show_debug = GTK_CHECK_MENU_ITEM(menuitem)->active;
-       update_tree(&rootmenu, NULL);
+       opt_mode = OPT_PROMPT;
+       gtk_tree_store_clear(tree2);
+       display_tree(&rootmenu);        /* instead of update_tree to speed-up */
 }
 
 
@@ -741,8 +664,7 @@ void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
 {
        GtkWidget *dialog;
        const gchar *intro_text = _(
-           "Welcome to gkc, the GTK+ graphical kernel configuration tool\n"
-           "for Linux.\n"
+           "Welcome to gkc, the GTK+ graphical configuration tool\n"
            "For each option, a blank box indicates the feature is disabled, a\n"
            "check indicates it is enabled, and a dot indicates that it is to\n"
            "be compiled as a module.  Clicking on the box will cycle through the three states.\n"
@@ -827,16 +749,9 @@ void on_load_clicked(GtkButton * button, gpointer user_data)
 }
 
 
-void on_save_clicked(GtkButton * button, gpointer user_data)
-{
-       on_save1_activate(NULL, user_data);
-}
-
-
 void on_single_clicked(GtkButton * button, gpointer user_data)
 {
        view_mode = SINGLE_VIEW;
-       gtk_paned_set_position(GTK_PANED(hpaned), 0);
        gtk_widget_hide(tree1_w);
        current = &rootmenu;
        display_tree_part();
@@ -862,7 +777,6 @@ void on_split_clicked(GtkButton * button, gpointer user_data)
 void on_full_clicked(GtkButton * button, gpointer user_data)
 {
        view_mode = FULL_VIEW;
-       gtk_paned_set_position(GTK_PANED(hpaned), 0);
        gtk_widget_hide(tree1_w);
        if (tree2)
                gtk_tree_store_clear(tree2);
@@ -907,7 +821,6 @@ static void renderer_edited(GtkCellRendererText * cell,
 
        sym_set_string_value(sym, new_def);
 
-       config_changed = TRUE;
        update_tree(&rootmenu, NULL);
 
        gtk_tree_path_free(path);
@@ -938,7 +851,6 @@ static void change_sym_value(struct menu *menu, gint col)
                if (!sym_tristate_within_range(sym, newval))
                        newval = yes;
                sym_set_tristate_value(sym, newval);
-               config_changed = TRUE;
                if (view_mode == FULL_VIEW)
                        update_tree(&rootmenu, NULL);
                else if (view_mode == SPLIT_VIEW) {
@@ -972,35 +884,6 @@ static void toggle_sym_value(struct menu *menu)
                display_tree_part();    //fixme: keep exp/coll
 }
 
-static void renderer_toggled(GtkCellRendererToggle * cell,
-                            gchar * path_string, gpointer user_data)
-{
-       GtkTreePath *path, *sel_path = NULL;
-       GtkTreeIter iter, sel_iter;
-       GtkTreeSelection *sel;
-       struct menu *menu;
-
-       path = gtk_tree_path_new_from_string(path_string);
-       if (!gtk_tree_model_get_iter(model2, &iter, path))
-               return;
-
-       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree2_w));
-       if (gtk_tree_selection_get_selected(sel, NULL, &sel_iter))
-               sel_path = gtk_tree_model_get_path(model2, &sel_iter);
-       if (!sel_path)
-               goto out1;
-       if (gtk_tree_path_compare(path, sel_path))
-               goto out2;
-
-       gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
-       toggle_sym_value(menu);
-
-      out2:
-       gtk_tree_path_free(sel_path);
-      out1:
-       gtk_tree_path_free(path);
-}
-
 static gint column2index(GtkTreeViewColumn * column)
 {
        gint i;
@@ -1191,12 +1074,13 @@ static gchar **fill_row(struct menu *menu)
        bzero(row, sizeof(row));
 
        row[COL_OPTION] =
-           g_strdup_printf("%s %s", menu_get_prompt(menu),
-                           sym ? (sym->
-                                  flags & SYMBOL_NEW ? "(NEW)" : "") :
-                           "");
+           g_strdup_printf("%s %s", _(menu_get_prompt(menu)),
+                           sym && !sym_has_value(sym) ? "(NEW)" : "");
 
-       if (show_all && !menu_is_visible(menu))
+       if (opt_mode == OPT_ALL && !menu_is_visible(menu))
+               row[COL_COLOR] = g_strdup("DarkGray");
+       else if (opt_mode == OPT_PROMPT &&
+                       menu_has_prompt(menu) && !menu_is_visible(menu))
                row[COL_COLOR] = g_strdup("DarkGray");
        else
                row[COL_COLOR] = g_strdup("Black");
@@ -1243,7 +1127,7 @@ static gchar **fill_row(struct menu *menu)
 
                if (def_menu)
                        row[COL_VALUE] =
-                           g_strdup(menu_get_prompt(def_menu));
+                           g_strdup(_(menu_get_prompt(def_menu)));
        }
        if (sym->flags & SYMBOL_CHOICEVAL)
                row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
@@ -1255,6 +1139,7 @@ static gchar **fill_row(struct menu *menu)
                        row[COL_BTNVIS] = GINT_TO_POINTER(TRUE);
                if (sym_is_choice(sym))
                        break;
+               /* fall through */
        case S_TRISTATE:
                val = sym_get_tristate_value(sym);
                switch (val) {
@@ -1419,16 +1304,20 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
                       menu2 ? menu_get_prompt(menu2) : "nil");
 #endif
 
-               if (!menu_is_visible(child1) && !show_all) {    // remove node
+               if ((opt_mode == OPT_NORMAL && !menu_is_visible(child1)) ||
+                   (opt_mode == OPT_PROMPT && !menu_has_prompt(child1)) ||
+                   (opt_mode == OPT_ALL    && !menu_get_prompt(child1))) {
+
+                       /* remove node */
                        if (gtktree_iter_find_node(dst, menu1) != NULL) {
                                memcpy(&tmp, child2, sizeof(GtkTreeIter));
                                valid = gtk_tree_model_iter_next(model2,
                                                                 child2);
                                gtk_tree_store_remove(tree2, &tmp);
                                if (!valid)
-                                       return; // next parent
+                                       return;         /* next parent */
                                else
-                                       goto reparse;   // next child
+                                       goto reparse;   /* next child */
                        } else
                                continue;
                }
@@ -1497,17 +1386,19 @@ static void display_tree(struct menu *menu)
                    && (tree == tree2))
                        continue;
 
-               if (menu_is_visible(child) || show_all)
+               if ((opt_mode == OPT_NORMAL && menu_is_visible(child)) ||
+                   (opt_mode == OPT_PROMPT && menu_has_prompt(child)) ||
+                   (opt_mode == OPT_ALL    && menu_get_prompt(child)))
                        place_node(child, fill_row(child));
 #ifdef DEBUG
                printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
                printf("%s", child->flags & MENU_ROOT ? "rootmenu | " : "");
-               dbg_print_ptype(ptype);
+               printf("%s", prop_get_type_name(ptype));
                printf(" | ");
                if (sym) {
-                       dbg_print_stype(sym->type);
+                       printf("%s", sym_type_name(sym->type));
                        printf(" | ");
-                       dbg_print_flags(sym->flags);
+                       printf("%s", dbg_sym_flags(sym->flags));
                        printf("\n");
                } else
                        printf("\n");
@@ -1519,6 +1410,12 @@ static void display_tree(struct menu *menu)
                 if (((menu != &rootmenu) && !(menu->flags & MENU_ROOT))
                    || (view_mode == FULL_VIEW)
                    || (view_mode == SPLIT_VIEW))*/
+
+               /* Change paned position if the view is not in 'split mode' */
+               if (view_mode == SINGLE_VIEW || view_mode == FULL_VIEW) {
+                       gtk_paned_set_position(GTK_PANED(hpaned), 0);
+               }
+
                if (((view_mode == SINGLE_VIEW) && (menu->flags & MENU_ROOT))
                    || (view_mode == FULL_VIEW)
                    || (view_mode == SPLIT_VIEW)) {
@@ -1577,10 +1474,6 @@ int main(int ac, char *av[])
        char *env;
        gchar *glade_file;
 
-#ifndef LKC_DIRECT_LINK
-       kconfig_load();
-#endif
-
        bindtextdomain(PACKAGE, LOCALEDIR);
        bind_textdomain_codeset(PACKAGE, "UTF-8");
        textdomain(PACKAGE);
@@ -1602,12 +1495,6 @@ int main(int ac, char *av[])
        else
                glade_file = g_strconcat(g_get_current_dir(), "/", av[0], ".glade", NULL);
 
-       /* Load the interface and connect signals */
-       init_main_window(glade_file);
-       init_tree_model();
-       init_left_tree();
-       init_right_tree();
-
        /* Conf stuffs */
        if (ac > 1 && av[1][0] == '-') {
                switch (av[1][1]) {
@@ -1627,6 +1514,12 @@ int main(int ac, char *av[])
        fixup_rootmenu(&rootmenu);
        conf_read(NULL);
 
+       /* Load the interface and connect signals */
+       init_main_window(glade_file);
+       init_tree_model();
+       init_left_tree();
+       init_right_tree();
+
        switch (view_mode) {
        case SINGLE_VIEW:
                display_tree_part();
@@ -1643,3 +1536,10 @@ int main(int ac, char *av[])
 
        return 0;
 }
+
+static void conf_changed(void)
+{
+       bool changed = conf_get_changed();
+       gtk_widget_set_sensitive(save_btn, changed);
+       gtk_widget_set_sensitive(save_menu_item, changed);
+}