From 435359aaec47c630f9ca54bdbd6871375a9f7037 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 30 May 2007 00:03:24 +0000 Subject: [PATCH] more moving code around --- src/handlers.c | 53 +++++--------------------------------------------- src/theme.c | 40 +++++++++++++++++++++++++++++++------ src/theme.h | 2 +- 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/src/handlers.c b/src/handlers.c index 1a91234..24f2acd 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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); } } diff --git a/src/theme.c b/src/theme.c index 4cde0d7..57cdc47 100644 --- a/src/theme.c +++ b/src/theme.c @@ -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) { diff --git a/src/theme.h b/src/theme.h index e02eb6a..d678774 100644 --- a/src/theme.h +++ b/src/theme.h @@ -3,6 +3,6 @@ #include -gboolean theme_install(gchar *path, gchar *theme); +gchar* theme_install(gchar *path); #endif -- 2.34.1