add --install and --archive
authorDana Jansens <danakj@orodu.net>
Wed, 30 May 2007 01:14:31 +0000 (01:14 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 30 May 2007 01:14:31 +0000 (01:14 +0000)
src/handlers.c
src/handlers.h
src/main.c
src/theme.c

index f27148c18435b9a5622f661264de6b7e3412ea1b..a22051f4bd65f106e456a9f0ddb36e8515dc8539 100644 (file)
@@ -414,6 +414,8 @@ static void reset_theme_names(GtkWidget *w)
 
     themes = g_list_sort(themes, (GCompareFunc) strcasecmp);
 
+    gtk_list_store_clear(theme_store);
+
     /* return to regular scheduled programming */
     i = 0;
     for (it = themes; it; it = next) {
@@ -438,6 +440,8 @@ static void reset_theme_names(GtkWidget *w)
             GtkTreePath *path;
             path = gtk_tree_path_new_from_indices(i, -1);
             gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
+            gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,
+                                         FALSE, 0, 0);
         }
 
 
@@ -1300,29 +1304,7 @@ void on_install_theme_clicked(GtkButton *w, gpointer data)
     gtk_widget_destroy(d);
 
     if (path != NULL) {
-        gchar *name;
-
-        if ((name = theme_install(path))) {
-            GtkWidget *w;
-            GtkTreePath *path;
-            GList *it;
-            gint i;
-
-            w = glade_xml_get_widget(glade, "theme_names");
-            mapping = TRUE;
-            reset_theme_names(w);
-            mapping = FALSE;
-
-            /* go to the newly installed theme */
-            for (it = themes, i = 0; it; it = g_list_next(it), ++i)
-                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);
-        }
+        handlers_install_theme(path);
         g_free(path);
     }
 }
@@ -1351,3 +1333,32 @@ void on_theme_archive_clicked(GtkButton *w, gpointer data)
         g_free(path);
     }
 }
+
+void handlers_install_theme(gchar *path)
+{
+    gchar *name;
+
+    if ((name = theme_install(path))) {
+        GtkWidget *w;
+        GtkTreePath *path;
+        GList *it;
+        gint i;
+
+        w = glade_xml_get_widget(glade, "theme_names");
+        mapping = TRUE;
+        reset_theme_names(w);
+        mapping = FALSE;
+
+        /* go to the newly installed theme */
+        for (it = themes, i = 0; it; it = g_list_next(it), ++i)
+            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);
+            gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,
+                                         FALSE, 0, 0);
+        }
+
+        g_free(name);
+    }
+}
index ac0e42bfdd530aa5f72b6f30e49443a63bc3c077..2721b84f4c14d46cbe652c9d20f71c58327eec43 100644 (file)
@@ -49,4 +49,6 @@ void setup_font_display(GtkWidget *w);
 void setup_desktop_num(GtkWidget *w);
 void setup_desktop_names(GtkWidget *w);
 
+void handlers_install_theme(gchar *path);
+
 #endif
index 104454ea0d80d2862de4ae007134ac92b15469c5..a9c8e1c2f38d19375ad1b80934e0573bcb8043d2 100644 (file)
 
 #include "main.h"
 #include "handlers.h"
+#include "theme.h"
+#include "gettext.h"
 
 #include <gdk/gdkx.h>
 #define SN_API_NOT_YET_FROZEN
 #include <libsn/sn.h>
 #undef SN_API_NOT_YET_FROZEN
 
-GtkWidget *mainwin;
+GtkWidget *mainwin = NULL;
 
 GladeXML *glade;
 xmlDocPtr doc;
 xmlNodePtr root;
 
+static gchar *obc_theme_install = NULL;
+static gchar *obc_theme_archive = NULL;
+
 void obconf_error(gchar *msg)
 {
     GtkWidget *d;
@@ -46,15 +51,41 @@ void obconf_error(gchar *msg)
     gtk_widget_show(d);
 }
 
+static void parse_args(int argc, char **argv)
+{
+    int i;
+
+    for (i = 1; i < argc; ++i) {
+        if (!strcmp(argv[i], "--install")) {
+            if (i == argc - 1) /* no args left */
+                g_printerr(_("--install requires an argument\n"));
+            else
+                obc_theme_install = argv[++i];
+        }
+        else if (!strcmp(argv[i], "--archive")) {
+            if (i == argc - 1) /* no args left */
+                g_printerr(_("--archive requires an argument\n"));
+            else
+                obc_theme_archive = argv[++i];
+        }
+    }
+}
+
 int main(int argc, char **argv)
 {
     SnDisplay *sn_d;
     SnLauncheeContext *sn_cx;
     gchar *p;
 
-    parse_paths_startup();
-
     gtk_init(&argc, &argv);
+    parse_args(argc, argv);
+
+    if (obc_theme_archive) {
+        theme_archive(obc_theme_archive);
+        return;
+    }
+
+    parse_paths_startup();
 
     p = g_build_filename(GLADEDIR, "obconf.glade", NULL);
     glade = glade_xml_new(p, NULL, NULL);
@@ -137,6 +168,9 @@ int main(int argc, char **argv)
         sn_launchee_context_unref(sn_cx);
     sn_display_unref(sn_d);
 
+    if (obc_theme_install)
+        handlers_install_theme(obc_theme_install);
+
     gtk_main();
 
     parse_paths_shutdown();
index a273bcc0506f184419eda8f1726f86f44687147d..b1c886860d4a90f66883c3a209868fdf5313e28f 100644 (file)
@@ -47,18 +47,11 @@ tartype_t funcs = {
 gchar* theme_install(gchar *path)
 {
     gchar *dest;
-    gchar *curdir;
     gchar *name;
 
     if (!(dest = get_theme_dir()))
         return NULL;
 
-    curdir = g_get_current_dir();
-    if (!change_dir(dest)) {
-        g_free(curdir);
-        return NULL;
-    }
-
     if (!(name = name_from_file(path)))
         return NULL;
 
@@ -71,9 +64,6 @@ gchar* theme_install(gchar *path)
 
     g_free(dest);
 
-    change_dir(curdir);
-    g_free(curdir);
-
     return name;
 }
 
@@ -201,6 +191,7 @@ static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to)
     TAR *t;
     gchar *glob;
     gint r;
+    gchar *curdir;
 
     if (tar_open(&t, file, &funcs, O_RDONLY, 0666, TAR_GNU) == -1) {
         gtk_msg(GTK_MESSAGE_ERROR,
@@ -209,10 +200,20 @@ static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to)
         return FALSE;
     }
 
+    curdir = g_get_current_dir();
+    if (!change_dir(to)) {
+        g_free(curdir);
+        tar_close(t);
+        return FALSE;
+    }
+
     glob = g_strdup_printf("%s/openbox-3/*", theme);
-    r = tar_extract_glob(t, glob, to);
+    r = tar_extract_glob(t, glob, ".");
     g_free(glob);
 
+    change_dir(curdir);
+
+    g_free(curdir);
     tar_close(t);
 
     if (r != 0)