qulogic/libgnt

Merged default branch
soc.2013.gobjectification.plugins
2014-04-29, Ankit Vani
48a4725807b1
Merged default branch
  • +2 -0
    gnt.h
  • +6 -0
    gntbox.c
  • +11 -0
    gntbox.h
  • +13 -4
    gntcolors.c
  • +2 -0
    gntmain.c
  • +29 -10
    gntmenu.c
  • +38 -0
    gntmenuitem.c
  • +40 -0
    gntmenuitem.h
  • --- a/gnt.h Fri Apr 25 16:55:07 2014 +0530
    +++ b/gnt.h Tue Apr 29 03:19:51 2014 +0530
    @@ -64,6 +64,8 @@
    *
    * You have to call this before #gnt_init. You might want to call this
    * with %NULL, to free the resources, but not before a call to #gnt_quit.
    + *
    + * Since: 2.8.0
    */
    void gnt_set_config_dir(const gchar *config_dir);
    --- a/gntbox.c Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntbox.c Tue Apr 29 03:19:51 2014 +0530
    @@ -677,6 +677,12 @@
    widget->parent = GNT_WIDGET(b);
    }
    +void gnt_box_add_widget_in_front(GntBox *b, GntWidget *widget)
    +{
    + b->list = g_list_prepend(b->list, widget);
    + widget->parent = GNT_WIDGET(b);
    +}
    +
    void gnt_box_set_title(GntBox *b, const char *title)
    {
    char *prev = b->title;
    --- a/gntbox.h Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntbox.h Tue Apr 29 03:19:51 2014 +0530
    @@ -125,6 +125,17 @@
    void gnt_box_add_widget(GntBox *box, GntWidget *widget);
    /**
    + * gnt_box_add_widget_in_front:
    + * @box: The box
    + * @widget: The widget to add
    + *
    + * Add a widget in the box at its front.
    + *
    + * Since: 2.8.0
    + */
    +void gnt_box_add_widget_in_front(GntBox *b, GntWidget *widget);
    +
    +/**
    * gnt_box_set_title:
    * @box: The box
    * @title: The title to set
    --- a/gntcolors.c Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntcolors.c Tue Apr 29 03:19:51 2014 +0530
    @@ -177,10 +177,15 @@
    {
    GError *error = NULL;
    gsize nkeys;
    - char **keys = g_key_file_get_keys(kfile, "colors", &nkeys, &error);
    + char **keys;
    - if (error)
    - {
    + if (!g_key_file_has_group(kfile, "colors")) {
    + gnt_color_pairs_parse(kfile);
    + return;
    + }
    +
    + keys = g_key_file_get_keys(kfile, "colors", &nkeys, &error);
    + if (error) {
    gnt_warning("%s", error->message);
    g_error_free(error);
    error = NULL;
    @@ -223,8 +228,12 @@
    {
    GError *error = NULL;
    gsize nkeys;
    - char **keys = g_key_file_get_keys(kfile, "colorpairs", &nkeys, &error);
    + char **keys;
    + if (!g_key_file_has_group(kfile, "colorpairs"))
    + return;
    +
    + keys = g_key_file_get_keys(kfile, "colorpairs", &nkeys, &error);
    if (error)
    {
    gnt_warning("%s", error->message);
    --- a/gntmain.c Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntmain.c Tue Apr 29 03:19:51 2014 +0530
    @@ -466,7 +466,9 @@
    g_io_channel_unref(channel);
    +#if 0
    gnt_warning("setting up IO (%d)", channel_read_callback);
    +#endif
    }
    static gboolean
    --- a/gntmenu.c Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntmenu.c Tue Apr 29 03:19:51 2014 +0530
    @@ -87,7 +87,13 @@
    for (i = 0, iter = menu->list; iter; iter = iter->next, i++) {
    GntMenuItem *item = GNT_MENU_ITEM(iter->data);
    - type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT);
    + if (!gnt_menuitem_is_visible(item))
    + continue;
    + type = ' ';
    + if (item->callback || item->submenu)
    + type |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
    + else
    + type |= gnt_color_pair(GNT_COLOR_DISABLED);
    if (i == menu->selected)
    type |= A_REVERSE;
    item->priv.x = getcurx(widget->window) + widget->priv.x;
    @@ -119,7 +125,7 @@
    static void
    menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent)
    {
    - char trigger[4] = "\0 )\0";
    + char trigger[] = "\0 )\0";
    g_return_if_fail(item != NULL);
    @@ -130,9 +136,12 @@
    gnt_tree_add_choice(GNT_TREE(menu), item,
    gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, " "), parent, NULL);
    gnt_tree_set_choice(GNT_TREE(menu), item, gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item)));
    - } else
    + } else {
    gnt_tree_add_row_last(GNT_TREE(menu), item,
    gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, item->submenu ? ">" : " "), parent);
    + if (!item->callback && !item->submenu)
    + gnt_tree_set_row_color(GNT_TREE(menu), item, GNT_COLOR_DISABLED);
    + }
    if (0 && item->submenu) {
    GntMenu *sub = GNT_MENU(item->submenu);
    @@ -305,15 +314,25 @@
    }
    if (menu->type == GNT_MENU_TOPLEVEL) {
    + GntMenuItem *item;
    + GList *it;
    if (strcmp(text, GNT_KEY_LEFT) == 0) {
    - if (menu->selected == 0)
    - menu->selected = g_list_length(menu->list) - 1;
    - else
    - menu->selected--;
    + do {
    + if (menu->selected == 0)
    + menu->selected = g_list_length(menu->list) - 1;
    + else
    + menu->selected--;
    + it = g_list_nth(menu->list, menu->selected);
    + item = it ? it->data : NULL;
    + } while (!gnt_menuitem_is_visible(item));
    } else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
    - menu->selected++;
    - if (menu->selected >= g_list_length(menu->list))
    - menu->selected = 0;
    + do {
    + menu->selected++;
    + if (menu->selected >= g_list_length(menu->list))
    + menu->selected = 0;
    + it = g_list_nth(menu->list, menu->selected);
    + item = it ? it->data : NULL;
    + } while (!gnt_menuitem_is_visible(item));
    } else if (strcmp(text, GNT_KEY_ENTER) == 0 ||
    strcmp(text, GNT_KEY_DOWN) == 0) {
    gnt_widget_activate(widget);
    --- a/gntmenuitem.c Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntmenuitem.c Tue Apr 29 03:19:51 2014 +0530
    @@ -65,6 +65,14 @@
    static void
    gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
    {
    + GntMenuItem *item = GNT_MENU_ITEM(instance);
    +#if 0
    + GntMenuItemPriv *priv = &item->priv;
    +
    + priv->visible = TRUE;
    +#else
    + item->visible = TRUE;
    +#endif
    }
    /******************************************************************************
    @@ -157,3 +165,33 @@
    return FALSE;
    }
    +void
    +gnt_menuitem_set_visible(GntMenuItem *item, gboolean visible)
    +{
    +#if 0
    + GntMenuItemPriv *priv = &item->priv;
    +
    + priv->visible = visible;
    +#else
    + item->visible = visible;
    +#endif
    +}
    +
    +gboolean
    +gnt_menuitem_is_visible(GntMenuItem *item)
    +{
    + g_return_val_if_fail(GNT_IS_MENU_ITEM(item), FALSE);
    +
    +#if 0
    + return item->priv.visible;
    +#else
    + return item->visible;
    +#endif
    +}
    +
    +void
    +gnt_menuitem_set_text(GntMenuItem *item, const gchar *text)
    +{
    + g_free(item->text);
    + item->text = g_strdup(text);
    +}
    --- a/gntmenuitem.h Fri Apr 25 16:55:07 2014 +0530
    +++ b/gntmenuitem.h Tue Apr 29 03:19:51 2014 +0530
    @@ -74,6 +74,9 @@
    GntMenuItemCallback callback;
    GntMenu *submenu;
    +
    + /*< private >*/
    + gboolean visible;
    };
    struct _GntMenuItemClass
    @@ -195,6 +198,43 @@
    */
    gboolean gnt_menuitem_activate(GntMenuItem *item);
    +/**
    + * gnt_menuitem_set_visible:
    + * @item: The menuitem.
    + * @visible: %TRUE to make @item visible, %FALSE to hide it.
    + *
    + * Sets @item visible or not.
    + *
    + * Since: 2.8.0
    + */
    +void
    +gnt_menuitem_set_visible(GntMenuItem *item, gboolean visible);
    +
    +/**
    + * gnt_menuitem_is_visible:
    + * @item: The menuitem.
    + *
    + * Checks, if the @item is visible.
    + *
    + * Returns: %TRUE, if the @item is visible.
    + *
    + * Since: 2.8.0
    + */
    +gboolean
    +gnt_menuitem_is_visible(GntMenuItem *item);
    +
    +/**
    + * gnt_menuitem_set_text:
    + * @item: The menuitem.
    + * @text: The new text.
    + *
    + * Changes the text for an @item.
    + *
    + * Since: 2.8.0
    + */
    +void
    +gnt_menuitem_set_text(GntMenuItem *item, const gchar *text);
    +
    G_END_DECLS
    #endif /* GNT_MENUITEM_H */