From 06137c23fce515382934c29a4e16301ffe133766 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 30 May 2007 01:14:31 +0000 Subject: [PATCH] add --install and --archive --- src/handlers.c | 57 ++++++++++++++++++++++++++++++-------------------- src/handlers.h | 2 ++ src/main.c | 40 ++++++++++++++++++++++++++++++++--- src/theme.c | 23 ++++++++++---------- 4 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/handlers.c b/src/handlers.c index f27148c..a22051f 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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); + } +} diff --git a/src/handlers.h b/src/handlers.h index ac0e42b..2721b84 100644 --- a/src/handlers.h +++ b/src/handlers.h @@ -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 diff --git a/src/main.c b/src/main.c index 104454e..a9c8e1c 100644 --- a/src/main.c +++ b/src/main.c @@ -19,18 +19,23 @@ #include "main.h" #include "handlers.h" +#include "theme.h" +#include "gettext.h" #include #define SN_API_NOT_YET_FROZEN #include #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(); diff --git a/src/theme.c b/src/theme.c index a273bcc..b1c8868 100644 --- a/src/theme.c +++ b/src/theme.c @@ -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) -- 2.34.1