Add few convenient macros config_group_* for easy group members add.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Tue, 18 Feb 2014 13:35:59 +0000 (15:35 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Tue, 18 Feb 2014 13:35:59 +0000 (15:35 +0200)
src/conf.h
src/configurator.c
src/panel.c
src/plugins/dclock.c
src/plugins/dirmenu.c
src/plugins/launchbar.c
src/plugins/menu.c
src/plugins/space.c
src/plugins/wincmd.c

index 8b82f20..9a44054 100644 (file)
@@ -76,6 +76,18 @@ gboolean config_setting_remove(config_setting_t * parent, const char * name);
 gboolean config_setting_remove_elem(config_setting_t * parent, unsigned int index);
 gboolean config_setting_destroy(config_setting_t * setting);
 
+#define config_group_set_int(_group,_name,_value) \
+        config_setting_set_int(config_setting_add(_group, _name, \
+                                                  PANEL_CONF_TYPE_INT), \
+                               _value)
+#define config_group_set_string(_group,_name,_value) \
+        config_setting_set_string(config_setting_add(_group, _name, \
+                                                     PANEL_CONF_TYPE_STRING), \
+                               _value)
+#define config_group_add_subgroup(_group,_name) \
+        config_setting_add(config_setting_add(_group, "", PANEL_CONF_TYPE_LIST), \
+                           _name, PANEL_CONF_TYPE_GROUP)
+
 PanelConfType config_setting_type(const config_setting_t * setting);
 #define config_setting_is_group(_s) config_setting_type(_s) == PANEL_CONF_TYPE_GROUP
 #define config_setting_is_list(_s) config_setting_type(_s) == PANEL_CONF_TYPE_LIST
index 505a30f..71f788c 100644 (file)
@@ -512,7 +512,7 @@ on_plugin_expand_toggled(GtkCellRendererToggle* render, char* path, GtkTreeView*
             gtk_box_query_child_packing( GTK_BOX(panel->box), pl, &old_expand, &fill, &padding, &pack_type );
             gtk_box_set_child_packing( GTK_BOX(panel->box), pl, expand, fill, padding, pack_type );
             if (expand)
-                config_setting_set_int(config_setting_add(s, "expand", PANEL_CONF_TYPE_INT), 1);
+                config_group_set_int(s, "expand", 1);
             else
                 config_setting_remove(s, "expand");
         }
index 84d2543..56dab1f 100644 (file)
@@ -665,9 +665,7 @@ found_edge:
     new_panel->name = gen_panel_name(new_panel->edge,new_panel->monitor);
 
     /* create new config with first group "Global" */
-    config_setting_add(config_setting_add(config_root_setting(new_panel->config),
-                                          "", PANEL_CONF_TYPE_LIST),
-                       "Global", PANEL_CONF_TYPE_GROUP);
+    config_group_add_subgroup(config_root_setting(new_panel->config), "Global");
     panel_configure(new_panel, 0);
     panel_normalize_configuration(new_panel);
     panel_start_gui(new_panel);
index 3bffefb..a97a450 100644 (file)
@@ -402,21 +402,12 @@ static gboolean dclock_apply_configuration(gpointer user_data)
     }
 
     /* Save configuration */
-    config_setting_set_string(config_setting_add(dc->settings, "ClockFmt",
-                                              PANEL_CONF_TYPE_STRING),
-                              dc->clock_format);
-    config_setting_set_string(config_setting_add(dc->settings, "TooltipFmt",
-                                              PANEL_CONF_TYPE_STRING),
-                              dc->tooltip_format);
-    config_setting_set_string(config_setting_add(dc->settings, "Action",
-                                              PANEL_CONF_TYPE_STRING),
-                              dc->action);
-    config_setting_set_int(config_setting_add(dc->settings, "BoldFont",
-                                              PANEL_CONF_TYPE_INT), dc->bold);
-    config_setting_set_int(config_setting_add(dc->settings, "IconOnly",
-                                              PANEL_CONF_TYPE_INT), dc->icon_only);
-    config_setting_set_int(config_setting_add(dc->settings, "CenterText",
-                                              PANEL_CONF_TYPE_INT), dc->center_text);
+    config_group_set_string(dc->settings, "ClockFmt", dc->clock_format);
+    config_group_set_string(dc->settings, "TooltipFmt", dc->tooltip_format);
+    config_group_set_string(dc->settings, "Action", dc->action);
+    config_group_set_int(dc->settings, "BoldFont", dc->bold);
+    config_group_set_int(dc->settings, "IconOnly", dc->icon_only);
+    config_group_set_int(dc->settings, "CenterText", dc->center_text);
     return FALSE;
 }
 
index 4cf5400..4501f36 100644 (file)
@@ -342,15 +342,9 @@ static gboolean dirmenu_apply_configuration(gpointer user_data)
     }
 
     /* Save configuration */
-    config_setting_set_string(config_setting_add(dm->settings, "path",
-                                                 PANEL_CONF_TYPE_STRING),
-                              dm->path);
-    config_setting_set_string(config_setting_add(dm->settings, "name",
-                                                 PANEL_CONF_TYPE_STRING),
-                              dm->name);
-    config_setting_set_string(config_setting_add(dm->settings, "image",
-                                                 PANEL_CONF_TYPE_STRING),
-                              dm->image);
+    config_group_set_string(dm->settings, "path", dm->path);
+    config_group_set_string(dm->settings, "name", dm->name);
+    config_group_set_string(dm->settings, "image", dm->image);
 
     lxpanel_button_set_icon(p, ((dm->image != NULL) ? dm->image : "file-manager"),
                             panel_get_icon_size(dm->panel));
index 613f3b2..ee19c99 100644 (file)
@@ -428,12 +428,8 @@ static void launchbar_configure_add_button(GtkButton * widget, LaunchbarPlugin *
         g_object_unref(pix);
         path = fm_path_to_str(sel_path);
         /* g_debug("*** path '%s'",path); */
-        btn->settings = config_setting_add(config_setting_add(lb->settings, "",
-                                                              PANEL_CONF_TYPE_LIST),
-                                           "Button", PANEL_CONF_TYPE_GROUP);
-        config_setting_set_string(config_setting_add(btn->settings, "id",
-                                                     PANEL_CONF_TYPE_STRING),
-                                  path);
+        btn->settings = config_group_add_subgroup(lb->settings, "Button");
+        config_group_set_string(btn->settings, "id", path);
         g_free(path);
         fm_path_unref(sel_path);
     }
index c12070a..f094cbe 100644 (file)
@@ -961,20 +961,12 @@ menu_constructor(Panel *panel, config_setting_t *settings)
         config_setting_add(settings, "system", PANEL_CONF_TYPE_GROUP);
         config_setting_add(settings, "separator", PANEL_CONF_TYPE_GROUP);
         s = config_setting_add(settings, "item", PANEL_CONF_TYPE_GROUP);
-            config_setting_set_string(config_setting_add(s, "command",
-                                                         PANEL_CONF_TYPE_STRING),
-                                      "run");
+            config_group_set_string(s, "command", "run");
         config_setting_add(settings, "separator", PANEL_CONF_TYPE_GROUP);
         s = config_setting_add(settings, "item", PANEL_CONF_TYPE_GROUP);
-            config_setting_set_string(config_setting_add(s, "command",
-                                                         PANEL_CONF_TYPE_STRING),
-                                      "logout");
-            config_setting_set_string(config_setting_add(s, "image",
-                                                         PANEL_CONF_TYPE_STRING),
-                                      "gnome-logout");
-        config_setting_set_string(config_setting_add(m->settings, "image",
-                                                     PANEL_CONF_TYPE_STRING),
-                                  DEFAULT_MENU_ICON);
+            config_group_set_string(s, "command", "logout");
+            config_group_set_string(s, "image", "gnome-logout");
+        config_group_set_string(m->settings, "image", DEFAULT_MENU_ICON);
     }
 
     if (!read_submenu(m, m->settings, FALSE)) {
@@ -994,12 +986,8 @@ static gboolean apply_config(gpointer user_data)
     if( m->fname ) {
         lxpanel_button_set_icon(m->img, m->fname, panel_get_icon_size(m->panel));
     }
-    config_setting_set_string(config_setting_add(m->settings, "image",
-                                                 PANEL_CONF_TYPE_STRING),
-                              m->fname);
-    config_setting_set_string(config_setting_add(m->settings, "name",
-                                                 PANEL_CONF_TYPE_STRING),
-                              m->caption);
+    config_group_set_string(m->settings, "image", m->fname);
+    config_group_set_string(m->settings, "name", m->caption);
     return FALSE;
 }
 
index c74c11e..93ed009 100644 (file)
@@ -78,8 +78,7 @@ static gboolean space_apply_configuration(gpointer user_data)
     else
         gtk_widget_set_size_request(p, 2, sp->size);
     /* Save config values */
-    config_setting_set_int(config_setting_add(sp->settings, "Size",
-                                              PANEL_CONF_TYPE_INT), sp->size);
+    config_group_set_int(sp->settings, "Size", sp->size);
     return FALSE;
 }
 
index 38d727e..5f3da89 100644 (file)
@@ -211,18 +211,12 @@ static gboolean wincmd_apply_configuration(gpointer user_data)
     WinCmdPlugin * wc = lxpanel_plugin_get_data(p);
 
     /* Just save settings */
-    config_setting_set_string(config_setting_add(wc->settings, "image",
-                                                 PANEL_CONF_TYPE_STRING),
-                              wc->image);
-    config_setting_set_string(config_setting_add(wc->settings, "Button1",
-                                                 PANEL_CONF_TYPE_STRING),
-                              wincmd_names[wc->button_1_command]);
-    config_setting_set_string(config_setting_add(wc->settings, "Button2",
-                                                 PANEL_CONF_TYPE_STRING),
-                              wincmd_names[wc->button_2_command]);
-    config_setting_set_int(config_setting_add(wc->settings, "Toggle",
-                                              PANEL_CONF_TYPE_INT),
-                           wc->toggle_preference);
+    config_group_set_string(wc->settings, "image", wc->image);
+    config_group_set_string(wc->settings, "Button1",
+                            wincmd_names[wc->button_1_command]);
+    config_group_set_string(wc->settings, "Button2",
+                            wincmd_names[wc->button_2_command]);
+    config_group_set_int(wc->settings, "Toggle", wc->toggle_preference);
     return FALSE;
 }