more moving code around
authorDana Jansens <danakj@orodu.net>
Wed, 30 May 2007 00:03:24 +0000 (00:03 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 30 May 2007 00:03:24 +0000 (00:03 +0000)
src/handlers.c
src/theme.c
src/theme.h

index 1a9123484b08bd3ee1d7dde51151ad8edd555ce0..24f2acd32d96ef0b2e4eac725a8de6522b6c2cda 100644 (file)
@@ -1300,52 +1300,9 @@ void on_install_theme_clicked(GtkButton *w, gpointer data)
     gtk_widget_destroy(d);
 
     if (path != NULL) {
-        /* decipher the theme name from the file name */
-        gchar *fname = g_path_get_basename(path);
-        gchar *themename = NULL;
-        gint len = strlen(fname);
-
-        if (len > 4 &&
-            (fname[len-4] == '.' && fname[len-3] == 'o' &&
-             fname[len-2] == 'b' && fname[len-1] == 't')/* ||
-            (fname[len-4] == '.' && fname[len-3] == 't' &&
-            fname[len-2] == 'g' && fname[len-1] == 'z')*/)
-        {
-            fname[len-4] = '\0';
-            themename = strdup(fname);
-            fname[len-4] = '.';
-        }
-/*
-        else if (len > 7 &&
-                 (fname[len-7] == '.' && fname[len-6] == 't' &&
-                  fname[len-5] == 'a' && fname[len-4] == 'r' &&
-                  fname[len-3] == '.' && fname[len-2] == 'g' &&
-                  fname[len-1] == 'z'))
-        {
-            fname[len-7] = '\0';
-            themename = strdup(fname);
-            fname[len-7] = '.';
-        }
-*/
-
-        if (themename == NULL) {
-            GtkWidget *w;
-
-            w = gtk_message_dialog_new(GTK_WINDOW(mainwin),
-                                       GTK_DIALOG_DESTROY_WITH_PARENT |
-                                       GTK_DIALOG_MODAL,
-                                       GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_OK,
-                                       _("Unable to determine the theme's name rom \"%s\".  File name should be ThemeName.obt."),
-                                       fname);
-            gtk_dialog_run(GTK_DIALOG(w));
-            gtk_widget_destroy(w);
-            g_free(fname);
-            g_free(path);
-            return;
-        }
+        gchar *name;
 
-        if (theme_install(path, themename)) {
+        if ((name = theme_install(path))) {
             GtkWidget *w;
             GtkTreePath *path;
             GList *it;
@@ -1358,14 +1315,14 @@ void on_install_theme_clicked(GtkButton *w, gpointer data)
 
             /* go to the newly installed theme */
             for (it = themes, i = 0; it; it = g_list_next(it), ++i)
-                if (!strcmp(it->data, themename)) break;
+                if (!strcmp(it->data, name)) break;
             if (it) {
                 path = gtk_tree_path_new_from_indices(i, -1);
                 gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
             }
+
+            g_free(name);
         }
-        g_free(fname);
-        g_free(themename);
         g_free(path);
     }
 }
index 4cde0d7814f612ddf6eca7a0c98a96c95481ca5f..57cdc47b90b3a40ef1b4c67febe7657d7c4c2da7 100644 (file)
@@ -31,6 +31,7 @@ static ssize_t gzwrite_frontend(int nothing, const void *buf, size_t s);
 static gchar *get_theme_dir();
 static gboolean change_dir(const gchar *dir);
 static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to);
+static gchar* name_from_file(const gchar *path);
 
 tartype_t funcs = {
     (openfunc_t) gzopen_frontend,
@@ -39,29 +40,33 @@ tartype_t funcs = {
     (writefunc_t) gzwrite_frontend
 };
 
-gboolean theme_install(gchar *path, gchar *theme)
+gchar* theme_install(gchar *path)
 {
     gchar *dest;
     gchar *curdir;
+    gchar *name;
 
     if (!(dest = get_theme_dir()))
-        return FALSE;
+        return NULL;
 
     curdir = g_get_current_dir();
     if (!change_dir(dest)) {
         g_free(curdir);
-        return FALSE;
+        return NULL;
     }
 
-    if (install_theme_to(theme, path, dest))
-        gtk_msg(GTK_MESSAGE_INFO, _("%s was installed to %s"), theme, dest);
+    if (!(name = name_from_file(path)))
+        return NULL;
+
+    if (install_theme_to(name, path, dest))
+        gtk_msg(GTK_MESSAGE_INFO, _("\"%s\" was installed to %s"), name, dest);
 
     g_free(dest);
 
     change_dir(curdir);
     g_free(curdir);
 
-    return TRUE;
+    return name;
 }
 
 static gchar *get_theme_dir()
@@ -82,6 +87,29 @@ static gchar *get_theme_dir()
     return dir;
 }
 
+static gchar* name_from_file(const gchar *path)
+{
+    /* decipher the theme name from the file name */
+    gchar *fname = g_path_get_basename(path);
+    gint len = strlen(fname);
+    gchar *name = NULL;
+
+    if (len > 4 &&
+        (fname[len-4] == '.' && fname[len-3] == 'o' &&
+         fname[len-2] == 'b' && fname[len-1] == 't'))
+    {
+        fname[len-4] = '\0';
+        name = strdup(fname);
+        fname[len-4] = '.';
+    }
+
+    if (name == NULL)
+        gtk_msg(GTK_MESSAGE_ERROR,
+                _("Unable to determine the theme's name from \"%s\".  File name should be ThemeName.obt."), fname);
+
+    return name;
+}
+
 static gboolean change_dir(const gchar *dir)
 {
     if (chdir(dir) == -1) {
index e02eb6af30567556f89a5abbdf5d98902cc281a1..d678774380c329c38d7fe06085ea6812c2148a5d 100644 (file)
@@ -3,6 +3,6 @@
 
 #include <glib.h>
 
-gboolean theme_install(gchar *path, gchar *theme);
+gchar* theme_install(gchar *path);
 
 #endif