]> Dogcows Code - chaz/tint2/commitdiff
tint2conf : store/load selected theme
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 1 Apr 2010 21:25:11 +0000 (21:25 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 1 Apr 2010 21:25:11 +0000 (21:25 +0000)
src/tint2conf/main.c
src/tint2conf/theme_view.c

index e2229e3aa1b8160a6bc04e02f2799c0455af78ba..e77911b490a767175ce03263dd5291ba2b29f1b1 100644 (file)
@@ -299,7 +299,7 @@ static void menuProperties (void)
        if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
                gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file,  -1);
 
-               cmd = g_strdup_printf("tintwizard.py \'%s\'", file);
+               cmd = g_strdup_printf("gedit \'%s\' &", file);
                system(cmd);
 
                g_free(cmd);
@@ -311,6 +311,14 @@ static void menuProperties (void)
 static void menuQuit (void)
 {
        write_config();
+
+       if (g_path_config)
+               g_free(g_path_config);
+       if (g_path_dir)
+               g_free(g_path_dir);
+       if (g_default_theme)
+               g_free(g_default_theme);
+
    gtk_main_quit ();
 }
 
@@ -338,15 +346,16 @@ static void menuApply (void)
        GtkTreeSelection *sel;
        GtkTreeIter iter;
        GtkTreeModel *model;
-       char *file;
 
+       if (g_default_theme) {
+               g_free(g_default_theme);
+               g_default_theme = NULL;
+       }
        sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
        if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
-               gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file,  -1);
-
+               gtk_tree_model_get(model, &iter, COL_THEME_FILE, &g_default_theme,  -1);
                // overwrite tint2rc
-               copy_file(file, g_path_config);
-               g_free(file);
+               copy_file(g_default_theme, g_path_config);
 
                // restart panel
                system("killall -SIGUSR1 tint2");
@@ -405,7 +414,9 @@ static void load_theme(GtkWidget *list)
 {
        GDir *dir;
        gchar *pt1, *name, *file;
-       int found_theme = FALSE;
+       gboolean have_iter, found_theme = FALSE;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
 
        dir = g_dir_open(g_path_dir, 0, NULL);
        if (dir == NULL) return;
@@ -414,7 +425,7 @@ static void load_theme(GtkWidget *list)
                if (pt1) {
                        found_theme = TRUE;
                        name = g_build_filename (g_path_dir, file, NULL);
-             custom_list_append(name);
+                       custom_list_append(name);
                        g_free(name);
                }
        }
@@ -424,17 +435,38 @@ static void load_theme(GtkWidget *list)
                // create default theme file
                name = g_build_filename (g_get_user_config_dir(), "tint2", "default.tint2rc", NULL);
                copy_file(g_path_config, name);
-      custom_list_append(name);
+               custom_list_append(name);
                g_free(name);
        }
 
        // search default theme
-       GtkTreeIter iter;
-       GtkTreeModel *model;
-       if (g_default_theme != NULL) {
-               printf("loadTheme : defaultTheme %s\n", g_default_theme);
-               //gtk_tree_selection_select_iter(GtkTreeSelection *selection, GtkTreeIter *iter);
+       found_theme = FALSE;
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
+       have_iter = gtk_tree_model_get_iter_first(model, &iter);
+       while (have_iter) {
+               gtk_tree_model_get(model, &iter, COL_THEME_FILE, &name,  -1);
+               found_theme = (strcmp(name, g_default_theme) == 0);
+               g_free(name);
+               if (found_theme)
+                       break;
+               have_iter = gtk_tree_model_iter_next(model, &iter);
+       }
+
+       // select theme
+       GtkTreePath *path = NULL;
+       if (found_theme)
+               path = gtk_tree_model_get_path(model, &iter);
+       else {
+               have_iter = gtk_tree_model_get_iter_first(model, &iter);
+               if (have_iter)
+                       path = gtk_tree_model_get_path(model, &iter);
        }
+       if (path) {
+               gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), &iter);
+               gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(g_theme_view), path, NULL, FALSE, 0, 0);
+               gtk_tree_path_free(path);
+       }
+
 }
 
 
@@ -472,8 +504,6 @@ void read_config()
                }
        }
        g_free(path);
-       if (g_default_theme != NULL)
-               printf("readConfig : defaultTheme %s\n", g_default_theme);
 }
 
 
index a61be0b0320428a112801defa712d713002542a9..1309fea46c3f99dc0c252aa1496c7a94ce4b0b1c 100644 (file)
@@ -59,7 +59,7 @@ void custom_list_append(const gchar *name)
        snap = g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL);
        g_remove(snap);
 
-       cmd = g_strdup_printf("tint2 -c %s -s %s", name, snap);
+       cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name, snap);
        system(cmd);
        g_free(cmd);
 
This page took 0.028089 seconds and 4 git commands to generate.