From d5d2f1de7b89d2af1a9d5a82e78cb1b172dd432c Mon Sep 17 00:00:00 2001 From: Richard Hestilow Date: Mon, 21 Jan 2002 07:16:19 +0000 Subject: [PATCH] Complete rewrite. 2002-01-21 Richard Hestilow * Complete rewrite. --- capplets/theme-switcher/ChangeLog | 4 + capplets/theme-switcher/Makefile.am | 21 +- capplets/theme-switcher/da.h | 76 -- capplets/theme-switcher/da.h-67648 | 76 -- capplets/theme-switcher/demo.c | 219 ------ capplets/theme-switcher/demo.c-45827 | 219 ------ capplets/theme-switcher/file.c | 535 -------------- capplets/theme-switcher/file.c-98078 | 535 -------------- capplets/theme-switcher/globals.c | 5 - capplets/theme-switcher/globals.c-53032 | 5 - .../gtk-theme-selector-properties.glade | 0 .../gtk-theme-selector-properties.glade-56055 | 0 .../gtk-theme-selector.desktop.in | 2 +- .../gtk-theme-selector.desktop.in.in | 2 +- .../theme-switcher/gtk-theme-selector.glade | 140 ++++ capplets/theme-switcher/gui.c | 650 ------------------ capplets/theme-switcher/gui.c-6060 | 650 ------------------ capplets/theme-switcher/install.c | 82 --- capplets/theme-switcher/install.c-64828 | 82 --- capplets/theme-switcher/lister.c | 218 ------ capplets/theme-switcher/lister.c-42011 | 218 ------ capplets/theme-switcher/main.c | 252 ++++++- capplets/theme-switcher/signals.c | 14 - capplets/theme-switcher/signals.c-20981 | 14 - 24 files changed, 386 insertions(+), 3633 deletions(-) delete mode 100644 capplets/theme-switcher/da.h delete mode 100644 capplets/theme-switcher/da.h-67648 delete mode 100644 capplets/theme-switcher/demo.c delete mode 100644 capplets/theme-switcher/demo.c-45827 delete mode 100644 capplets/theme-switcher/file.c delete mode 100644 capplets/theme-switcher/file.c-98078 delete mode 100644 capplets/theme-switcher/globals.c delete mode 100644 capplets/theme-switcher/globals.c-53032 delete mode 100644 capplets/theme-switcher/gtk-theme-selector-properties.glade delete mode 100644 capplets/theme-switcher/gtk-theme-selector-properties.glade-56055 create mode 100644 capplets/theme-switcher/gtk-theme-selector.glade delete mode 100644 capplets/theme-switcher/gui.c delete mode 100644 capplets/theme-switcher/gui.c-6060 delete mode 100644 capplets/theme-switcher/install.c delete mode 100644 capplets/theme-switcher/install.c-64828 delete mode 100644 capplets/theme-switcher/lister.c delete mode 100644 capplets/theme-switcher/lister.c-42011 delete mode 100644 capplets/theme-switcher/signals.c delete mode 100644 capplets/theme-switcher/signals.c-20981 diff --git a/capplets/theme-switcher/ChangeLog b/capplets/theme-switcher/ChangeLog index 8c954d8a0..239913bf9 100644 --- a/capplets/theme-switcher/ChangeLog +++ b/capplets/theme-switcher/ChangeLog @@ -1,3 +1,7 @@ +2002-01-21 Richard Hestilow + + * Complete rewrite. + 2002-01-14 Bradford Hovinen * Makefile.am: Update diff --git a/capplets/theme-switcher/Makefile.am b/capplets/theme-switcher/Makefile.am index e42b204a7..b411068dc 100644 --- a/capplets/theme-switcher/Makefile.am +++ b/capplets/theme-switcher/Makefile.am @@ -1,17 +1,11 @@ SUBDIRS = control -bin_PROGRAMS = gtk-theme-selector-capplet +bin_PROGRAMS = gtk2-theme-selector-capplet -gtk_theme_selector_capplet_LDADD = $(GNOMECC_CAPPLETS_LIBS) -gtk_theme_selector_capplet_SOURCES = \ - da.h \ - file.c \ - globals.c \ - lister.c \ - main.c \ - signals.c \ - gui.c \ - install.c +gtk2_theme_selector_capplet_LDADD = $(GNOMECC_CAPPLETS_LIBS) +gtk2_theme_selector_capplet_SOURCES = \ + main.c +gtk2_theme_selector_capplet_LDFLAGS = -export-dynamic @INTLTOOL_DESKTOP_RULE@ @@ -19,6 +13,9 @@ desktopdir = $(GNOMECC_DATA_DIR)/capplets/Advanced Desktop_in_files = gtk-theme-selector.desktop.in desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop) +gladedir = $(GNOMECC_DATA_DIR)/interfaces +glade_DATA = gtk-theme-selector.glade + INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS) CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES) -EXTRA_DIST = $(Desktop_in_files) +EXTRA_DIST = $(Desktop_in_files) $(glade_DATA) diff --git a/capplets/theme-switcher/da.h b/capplets/theme-switcher/da.h deleted file mode 100644 index 0ea160ff6..000000000 --- a/capplets/theme-switcher/da.h +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef struct _theme_entry -{ - gchar *name; - gchar *rc; - gchar *dir; - gchar *readme; - gchar *icon; - int row; -} ThemeEntry; - -void md(char *s); -int exists(char *s); -int isfile(char *s); -int isdir(char *s); -char **ls(char *dir, int *num); -void freestrlist(char **l, int num); -void rm(char *s); -void mv(char *s, char *ss); -void cp(char *s, char *ss); -unsigned long moddate(char *s); -int filesize(char *s); -void cd(char *s); -char *cwd(void); -int permissions(char *s); -int owner(char *s); -int group(char *s); -char *username(int uid); -char *homedir(int uid); -char *usershell(int uid); -char *atword(char *s, int num); -char *atchar(char *s, char c); -void word(char *s, int num, char *wd); -int canread(char *s); -int canwrite(char *s); -int canexec(char *s); -char *fileof(char *s); -char *fullfileof(char *s); -char *noext(char *s); -void mkdirs(char *s); - -void -free_theme_list(ThemeEntry *list, gint number); -GList* -list_themes(gchar *dir); -GList* -list_system_themes(void); -GList* -list_user_themes(void); -GtkWidget * -make_main(void); -void -update_theme_entries(GtkWidget *disp_list); -void -edit_file_to_use(gchar *file, gchar *theme, gchar *font); -void -set_tmp_rc(void); -void -use_theme(gchar *theme, gchar *font); -void -test_theme(gchar *theme, gchar *font); -gchar * -install_theme(gchar *file); - -extern GtkWidget *preview_control; -extern gchar gtkrc_tmp[1024]; diff --git a/capplets/theme-switcher/da.h-67648 b/capplets/theme-switcher/da.h-67648 deleted file mode 100644 index 0ea160ff6..000000000 --- a/capplets/theme-switcher/da.h-67648 +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef struct _theme_entry -{ - gchar *name; - gchar *rc; - gchar *dir; - gchar *readme; - gchar *icon; - int row; -} ThemeEntry; - -void md(char *s); -int exists(char *s); -int isfile(char *s); -int isdir(char *s); -char **ls(char *dir, int *num); -void freestrlist(char **l, int num); -void rm(char *s); -void mv(char *s, char *ss); -void cp(char *s, char *ss); -unsigned long moddate(char *s); -int filesize(char *s); -void cd(char *s); -char *cwd(void); -int permissions(char *s); -int owner(char *s); -int group(char *s); -char *username(int uid); -char *homedir(int uid); -char *usershell(int uid); -char *atword(char *s, int num); -char *atchar(char *s, char c); -void word(char *s, int num, char *wd); -int canread(char *s); -int canwrite(char *s); -int canexec(char *s); -char *fileof(char *s); -char *fullfileof(char *s); -char *noext(char *s); -void mkdirs(char *s); - -void -free_theme_list(ThemeEntry *list, gint number); -GList* -list_themes(gchar *dir); -GList* -list_system_themes(void); -GList* -list_user_themes(void); -GtkWidget * -make_main(void); -void -update_theme_entries(GtkWidget *disp_list); -void -edit_file_to_use(gchar *file, gchar *theme, gchar *font); -void -set_tmp_rc(void); -void -use_theme(gchar *theme, gchar *font); -void -test_theme(gchar *theme, gchar *font); -gchar * -install_theme(gchar *file); - -extern GtkWidget *preview_control; -extern gchar gtkrc_tmp[1024]; diff --git a/capplets/theme-switcher/demo.c b/capplets/theme-switcher/demo.c deleted file mode 100644 index 0f8a6ce39..000000000 --- a/capplets/theme-switcher/demo.c +++ /dev/null @@ -1,219 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include - -GtkWidget *plug; - -void -send_socket() -{ - gchar buffer[256]; - - g_snprintf(buffer, sizeof(buffer), "%11lx ", - (gulong)GDK_WINDOW_XWINDOW (preview_socket->window)); - write(prog_fd, buffer, strlen(buffer)); -} - -void -send_reread() -{ - gchar buffer[256]; - - g_snprintf(buffer, sizeof(buffer), "R "); - write(prog_fd, buffer, strlen(buffer)); -} - -static void -demo_data_in(gpointer data, gint source, GdkInputCondition condition) -{ - gchar buf[256]; - - if (condition & GDK_INPUT_EXCEPTION || - read(source, buf, 2) == 0) - gtk_main_quit(); /* Parent exited */ - else { - if (gtk_rc_reparse_all ()) - gtk_widget_reset_rc_styles(plug); - } -} - -#define NUM 50 - -static void -demo_main(int argc, char **argv, gint in_fd) -{ - gchar buf[256]; - Window window; - GtkWidget *widget, *table, *hbox; - GtkWidget *scrolled_window, *menubar, *menu; - GSList *group; - gchar *titles[2] = {N_("One"),N_("Two")}; - /* just 8 short names that will serve as samples for titles in demo */ - gchar *row1[2] = {N_("Eenie"), N_("Meenie")}; - gchar *row2[2] = {N_("Mynie"), N_("Moe")}; - gchar *row3[2] = {N_("Catcha"), N_("Tiger")}; - gchar *row4[2] = {N_("By Its"), N_("Toe")}; - gchar **rc_files; - gchar **new_rc_files; - gint rc_file_count; - gint new_count; - gchar *home_dir; - gint i; - -#ifdef ENABLE_NLS - for (i=0;i<2;i++) { - titles[i]=_(titles[i]); - row1[i]=_(row1[i]); - row2[i]=_(row2[i]); - row3[i]=_(row3[i]); - row4[i]=_(row4[i]); - } -#endif - - if (read(in_fd, buf, 12) <= 0) - /* Assume this means that our parent exited or was killed */ - exit(0); - - buf[12] = 0; - window = strtol (buf, NULL, 16); - - fcntl(0, F_SETFL, O_NONBLOCK); - - /* Strip out ~/.gtkrc from the set of initial default files. - * to suppress reading of the previous rc file. - */ - - rc_files = gtk_rc_get_default_files(); - for (rc_file_count = 0; rc_files[rc_file_count]; rc_file_count++) - /* Nothing */; - - new_rc_files = g_new (gchar *, rc_file_count + 2); - - home_dir = g_get_home_dir(); - new_count = 0; - - for (i = 0; i 0) - { - close(toProg[0]); - prog_fd = toProg[1]; - return pid; - } - else - { - /* baaaaaaaah eeeeek */ - return -1; - } -} diff --git a/capplets/theme-switcher/demo.c-45827 b/capplets/theme-switcher/demo.c-45827 deleted file mode 100644 index 0f8a6ce39..000000000 --- a/capplets/theme-switcher/demo.c-45827 +++ /dev/null @@ -1,219 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include - -GtkWidget *plug; - -void -send_socket() -{ - gchar buffer[256]; - - g_snprintf(buffer, sizeof(buffer), "%11lx ", - (gulong)GDK_WINDOW_XWINDOW (preview_socket->window)); - write(prog_fd, buffer, strlen(buffer)); -} - -void -send_reread() -{ - gchar buffer[256]; - - g_snprintf(buffer, sizeof(buffer), "R "); - write(prog_fd, buffer, strlen(buffer)); -} - -static void -demo_data_in(gpointer data, gint source, GdkInputCondition condition) -{ - gchar buf[256]; - - if (condition & GDK_INPUT_EXCEPTION || - read(source, buf, 2) == 0) - gtk_main_quit(); /* Parent exited */ - else { - if (gtk_rc_reparse_all ()) - gtk_widget_reset_rc_styles(plug); - } -} - -#define NUM 50 - -static void -demo_main(int argc, char **argv, gint in_fd) -{ - gchar buf[256]; - Window window; - GtkWidget *widget, *table, *hbox; - GtkWidget *scrolled_window, *menubar, *menu; - GSList *group; - gchar *titles[2] = {N_("One"),N_("Two")}; - /* just 8 short names that will serve as samples for titles in demo */ - gchar *row1[2] = {N_("Eenie"), N_("Meenie")}; - gchar *row2[2] = {N_("Mynie"), N_("Moe")}; - gchar *row3[2] = {N_("Catcha"), N_("Tiger")}; - gchar *row4[2] = {N_("By Its"), N_("Toe")}; - gchar **rc_files; - gchar **new_rc_files; - gint rc_file_count; - gint new_count; - gchar *home_dir; - gint i; - -#ifdef ENABLE_NLS - for (i=0;i<2;i++) { - titles[i]=_(titles[i]); - row1[i]=_(row1[i]); - row2[i]=_(row2[i]); - row3[i]=_(row3[i]); - row4[i]=_(row4[i]); - } -#endif - - if (read(in_fd, buf, 12) <= 0) - /* Assume this means that our parent exited or was killed */ - exit(0); - - buf[12] = 0; - window = strtol (buf, NULL, 16); - - fcntl(0, F_SETFL, O_NONBLOCK); - - /* Strip out ~/.gtkrc from the set of initial default files. - * to suppress reading of the previous rc file. - */ - - rc_files = gtk_rc_get_default_files(); - for (rc_file_count = 0; rc_files[rc_file_count]; rc_file_count++) - /* Nothing */; - - new_rc_files = g_new (gchar *, rc_file_count + 2); - - home_dir = g_get_home_dir(); - new_count = 0; - - for (i = 0; i 0) - { - close(toProg[0]); - prog_fd = toProg[1]; - return pid; - } - else - { - /* baaaaaaaah eeeeek */ - return -1; - } -} diff --git a/capplets/theme-switcher/file.c b/capplets/theme-switcher/file.c deleted file mode 100644 index 3baae387f..000000000 --- a/capplets/theme-switcher/file.c +++ /dev/null @@ -1,535 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "da.h" - -void -md(char *s) -{ - if ((!s) || (!*s)) - return; - mkdir(s, S_IRWXU); -} - -int -exists(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - return 1; -} - -int -isfile(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - if (st.st_blocks == 0) - return 0; - if (S_ISREG(st.st_mode)) - return 1; - return 0; -} - -int -isdir(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - if (S_ISDIR(st.st_mode)) - return 1; - return 0; -} - -int -ls_compare_func(const void *a, const void *b) -{ - return strcmp(*(char **)a, *(char **)b); -} - -char ** -ls(char *dir, int *num) -{ - int i, dirlen; - DIR *dirp; - char **names; - struct dirent *dp; - - if ((!dir) || (!*dir)) - return 0; - dirp = opendir(dir); - if (!dirp) - { - *num = 0; - return NULL; - } - - /* count # of entries in dir (worst case) */ - for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++); - if (!dirlen) - { - closedir(dirp); - *num = dirlen; - return NULL; - } - - /* load up the entries, now that we know how many to make */ - names = (char **)malloc(dirlen * sizeof(char *)); - - if (!names) - return NULL; - - rewinddir(dirp); - for (i = 0; i < dirlen;) - { - dp = readdir(dirp); - if (!dp) - break; - names[i] = (char *)malloc(strlen(dp->d_name) + 1); - if (!names) - return NULL; - strcpy(names[i], dp->d_name); - i++; - } - - if (i < dirlen) - dirlen = i; /* dir got shorter... */ - closedir(dirp); - *num = dirlen; - qsort(names, dirlen, sizeof(char *), ls_compare_func); - - return names; -} - -void -freestrlist(char **l, int num) -{ - if (!l) - return; - while (num--) - if (l[num]) - free(l[num]); - free(l); -} - -void -rm(char *s) -{ - if ((!s) || (!*s)) - return; - unlink(s); -} - -void -mv(char *s, char *ss) -{ - if ((!s) || (!ss) || (!*s) || (!*ss)) - return; - rename(s, ss); -} - -void -cp(char *s, char *ss) -{ - int i; - FILE *f, *ff; - unsigned char buf[1]; - - if ((!s) || (!ss) || (!*s) || (!*ss)) - return; - if (!exists(s)) - return; - i = filesize(s); - f = fopen(s, "r"); - if (!f) - return; - ff = fopen(ss, "w"); - if (!ff) - { - fclose(f); - return; - } - while (fread(buf, 1, 1, f)) - fwrite(buf, 1, 1, ff); - fclose(f); - fclose(ff); -} - -unsigned long -moddate(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - if (st.st_mtime > st.st_ctime) - return st.st_mtime; - else - return st.st_ctime; -} - -int -filesize(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - return (int)st.st_size; -} - -void -cd(char *s) -{ - if ((!s) || (!*s)) - return; - chdir(s); -} - -char * -cwd(void) -{ - char s[4096]; - - getcwd(s, sizeof(s)); - return strdup(s); -} - -int -permissions(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_mode; -} - -int -owner(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_uid; -} - -int -group(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_gid; -} - -char * -username(int uid) -{ - struct passwd *pass; - char *result; - - pass = getpwuid(uid); - if (pass && pass->pw_name) - result = strdup(pass->pw_name); - else - result = NULL; - endpwent(); - return result; -} - -char * -homedir(int uid) -{ - struct passwd *pass; - char *result; - - result = getenv("HOME"); - if (result) - return strdup(result); - - pass = getpwuid(uid); - if (pass && pass->pw_dir) - result = strdup(pass->pw_dir); - else - result = NULL; - endpwent(); - return result; -} - -char * -usershell(int uid) -{ - struct passwd *pass; - char *result; - - pass = getpwuid(uid); - if (pass && pass->pw_shell) - result = strdup(pass->pw_shell); - else - result = NULL; - endpwent(); - return result; -} - -char * -atword(char *s, int num) -{ - int cnt, i; - - if (!s) - return NULL; - cnt = 0; - i = 0; - - while (s[i]) - { - if ((s[i] != ' ') && (s[i] != '\t')) - { - if (i == 0) - cnt++; - else if ((s[i - 1] == ' ') || (s[i - 1] == '\t')) - cnt++; - if (cnt == num) - return &s[i]; - } - i++; - } - return NULL; -} - -char * -atchar(char *s, char c) -{ - int i; - - if (!s) - return NULL; - i = 0; - while (s[i] != 0) - { - if (s[i] == c) - return &s[i]; - i++; - } - return NULL; -} - -void -word(char *s, int num, char *wd) -{ - int cnt, i; - char *start, *finish, *ss, *w; - - if (!s) - return; - if (!wd) - return; - if (num <= 0) - { - *wd = 0; - return; - } - cnt = 0; - i = 0; - start = NULL; - finish = NULL; - ss = NULL; - w = wd; - - while (s[i]) - { - if ((cnt == num) && ((s[i] == ' ') || (s[i] == '\t'))) - { - finish = &s[i]; - break; - } - if ((s[i] != ' ') && (s[i] != '\t')) - { - if (i == 0) - { - cnt++; - if (cnt == num) - start = &s[i]; - } - else if ((s[i - 1] == ' ') || (s[i - 1] == '\t')) - { - cnt++; - if (cnt == num) - start = &s[i]; - } - } - i++; - } - if (cnt == num) - { - if ((start) && (finish)) - { - for (ss = start; ss < finish; ss++) - *wd++ = *ss; - } - else if (start) - { - for (ss = start; *ss != 0; ss++) - *wd++ = *ss; - } - *wd = 0; - } - return; -} - -int -canread(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, R_OK); -} - -int -canwrite(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, W_OK); -} - -int -canexec(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, X_OK); -} - -char * -fileof(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - p2 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '.') && (p2 < 0) && (p1 < 0)) - p2 = i; - if ((s[i] == '/') && (p1 < 0)) - p1 = i; - } - if (p2 < 0) - p2 = strlen(s); - if (p1 < 0) - p1 = 0; - for (i = 0; i < (p2 - p1 - 1); i++) - ss[i] = s[p1 + 1 + i]; - ss[i] = 0; - return strdup(ss); -} - -char * -fullfileof(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '/') && (p1 < 0)) - p1 = i; - } - p2 = strlen(s); - for (i = 0; i < (p2 - p1 - 1); i++) - ss[i] = s[p1 + 1 + i]; - ss[i] = 0; - return strdup(ss); -} - -char * -noext(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '/') && (p1 < 0)) - break; - else if (s[i] == '.') - { - p1 = i; - break; - } - } - if (p1 < 0) - return strdup(s); - p2 = strlen(s); - for (i = 0; i < p1; i++) - ss[i] = s[i]; - ss[i] = 0; - return strdup(ss); -} - -void -mkdirs(char *s) -{ - char ss[1024]; - int i, ii; - - i = 0; - ii = 0; - while (s[i]) - { - ss[ii++] = s[i]; - ss[ii] = 0; - if (s[i] == '/') - { - if (!exists(ss)) - md(ss); - else if (!isdir(ss)) - return; - } - i++; - } -} diff --git a/capplets/theme-switcher/file.c-98078 b/capplets/theme-switcher/file.c-98078 deleted file mode 100644 index 3baae387f..000000000 --- a/capplets/theme-switcher/file.c-98078 +++ /dev/null @@ -1,535 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "da.h" - -void -md(char *s) -{ - if ((!s) || (!*s)) - return; - mkdir(s, S_IRWXU); -} - -int -exists(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - return 1; -} - -int -isfile(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - if (st.st_blocks == 0) - return 0; - if (S_ISREG(st.st_mode)) - return 1; - return 0; -} - -int -isdir(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - if (S_ISDIR(st.st_mode)) - return 1; - return 0; -} - -int -ls_compare_func(const void *a, const void *b) -{ - return strcmp(*(char **)a, *(char **)b); -} - -char ** -ls(char *dir, int *num) -{ - int i, dirlen; - DIR *dirp; - char **names; - struct dirent *dp; - - if ((!dir) || (!*dir)) - return 0; - dirp = opendir(dir); - if (!dirp) - { - *num = 0; - return NULL; - } - - /* count # of entries in dir (worst case) */ - for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++); - if (!dirlen) - { - closedir(dirp); - *num = dirlen; - return NULL; - } - - /* load up the entries, now that we know how many to make */ - names = (char **)malloc(dirlen * sizeof(char *)); - - if (!names) - return NULL; - - rewinddir(dirp); - for (i = 0; i < dirlen;) - { - dp = readdir(dirp); - if (!dp) - break; - names[i] = (char *)malloc(strlen(dp->d_name) + 1); - if (!names) - return NULL; - strcpy(names[i], dp->d_name); - i++; - } - - if (i < dirlen) - dirlen = i; /* dir got shorter... */ - closedir(dirp); - *num = dirlen; - qsort(names, dirlen, sizeof(char *), ls_compare_func); - - return names; -} - -void -freestrlist(char **l, int num) -{ - if (!l) - return; - while (num--) - if (l[num]) - free(l[num]); - free(l); -} - -void -rm(char *s) -{ - if ((!s) || (!*s)) - return; - unlink(s); -} - -void -mv(char *s, char *ss) -{ - if ((!s) || (!ss) || (!*s) || (!*ss)) - return; - rename(s, ss); -} - -void -cp(char *s, char *ss) -{ - int i; - FILE *f, *ff; - unsigned char buf[1]; - - if ((!s) || (!ss) || (!*s) || (!*ss)) - return; - if (!exists(s)) - return; - i = filesize(s); - f = fopen(s, "r"); - if (!f) - return; - ff = fopen(ss, "w"); - if (!ff) - { - fclose(f); - return; - } - while (fread(buf, 1, 1, f)) - fwrite(buf, 1, 1, ff); - fclose(f); - fclose(ff); -} - -unsigned long -moddate(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - if (st.st_mtime > st.st_ctime) - return st.st_mtime; - else - return st.st_ctime; -} - -int -filesize(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (stat(s, &st) < 0) - return 0; - return (int)st.st_size; -} - -void -cd(char *s) -{ - if ((!s) || (!*s)) - return; - chdir(s); -} - -char * -cwd(void) -{ - char s[4096]; - - getcwd(s, sizeof(s)); - return strdup(s); -} - -int -permissions(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_mode; -} - -int -owner(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_uid; -} - -int -group(char *s) -{ - struct stat st; - - if ((!s) || (!*s)) - return 0; - if (!stat(s, &st) < 0) - return 0; - return st.st_gid; -} - -char * -username(int uid) -{ - struct passwd *pass; - char *result; - - pass = getpwuid(uid); - if (pass && pass->pw_name) - result = strdup(pass->pw_name); - else - result = NULL; - endpwent(); - return result; -} - -char * -homedir(int uid) -{ - struct passwd *pass; - char *result; - - result = getenv("HOME"); - if (result) - return strdup(result); - - pass = getpwuid(uid); - if (pass && pass->pw_dir) - result = strdup(pass->pw_dir); - else - result = NULL; - endpwent(); - return result; -} - -char * -usershell(int uid) -{ - struct passwd *pass; - char *result; - - pass = getpwuid(uid); - if (pass && pass->pw_shell) - result = strdup(pass->pw_shell); - else - result = NULL; - endpwent(); - return result; -} - -char * -atword(char *s, int num) -{ - int cnt, i; - - if (!s) - return NULL; - cnt = 0; - i = 0; - - while (s[i]) - { - if ((s[i] != ' ') && (s[i] != '\t')) - { - if (i == 0) - cnt++; - else if ((s[i - 1] == ' ') || (s[i - 1] == '\t')) - cnt++; - if (cnt == num) - return &s[i]; - } - i++; - } - return NULL; -} - -char * -atchar(char *s, char c) -{ - int i; - - if (!s) - return NULL; - i = 0; - while (s[i] != 0) - { - if (s[i] == c) - return &s[i]; - i++; - } - return NULL; -} - -void -word(char *s, int num, char *wd) -{ - int cnt, i; - char *start, *finish, *ss, *w; - - if (!s) - return; - if (!wd) - return; - if (num <= 0) - { - *wd = 0; - return; - } - cnt = 0; - i = 0; - start = NULL; - finish = NULL; - ss = NULL; - w = wd; - - while (s[i]) - { - if ((cnt == num) && ((s[i] == ' ') || (s[i] == '\t'))) - { - finish = &s[i]; - break; - } - if ((s[i] != ' ') && (s[i] != '\t')) - { - if (i == 0) - { - cnt++; - if (cnt == num) - start = &s[i]; - } - else if ((s[i - 1] == ' ') || (s[i - 1] == '\t')) - { - cnt++; - if (cnt == num) - start = &s[i]; - } - } - i++; - } - if (cnt == num) - { - if ((start) && (finish)) - { - for (ss = start; ss < finish; ss++) - *wd++ = *ss; - } - else if (start) - { - for (ss = start; *ss != 0; ss++) - *wd++ = *ss; - } - *wd = 0; - } - return; -} - -int -canread(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, R_OK); -} - -int -canwrite(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, W_OK); -} - -int -canexec(char *s) -{ - if ((!s) || (!*s)) - return 0; - return access(s, X_OK); -} - -char * -fileof(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - p2 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '.') && (p2 < 0) && (p1 < 0)) - p2 = i; - if ((s[i] == '/') && (p1 < 0)) - p1 = i; - } - if (p2 < 0) - p2 = strlen(s); - if (p1 < 0) - p1 = 0; - for (i = 0; i < (p2 - p1 - 1); i++) - ss[i] = s[p1 + 1 + i]; - ss[i] = 0; - return strdup(ss); -} - -char * -fullfileof(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '/') && (p1 < 0)) - p1 = i; - } - p2 = strlen(s); - for (i = 0; i < (p2 - p1 - 1); i++) - ss[i] = s[p1 + 1 + i]; - ss[i] = 0; - return strdup(ss); -} - -char * -noext(char *s) -{ - char ss[1024]; - int i, p1, p2; - - i = 0; - p1 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '/') && (p1 < 0)) - break; - else if (s[i] == '.') - { - p1 = i; - break; - } - } - if (p1 < 0) - return strdup(s); - p2 = strlen(s); - for (i = 0; i < p1; i++) - ss[i] = s[i]; - ss[i] = 0; - return strdup(ss); -} - -void -mkdirs(char *s) -{ - char ss[1024]; - int i, ii; - - i = 0; - ii = 0; - while (s[i]) - { - ss[ii++] = s[i]; - ss[ii] = 0; - if (s[i] == '/') - { - if (!exists(ss)) - md(ss); - else if (!isdir(ss)) - return; - } - i++; - } -} diff --git a/capplets/theme-switcher/globals.c b/capplets/theme-switcher/globals.c deleted file mode 100644 index 4ba604be7..000000000 --- a/capplets/theme-switcher/globals.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "da.h" - -gint prog_fd; -gchar gtkrc_tmp[1024]; -GtkWidget *preview_socket; diff --git a/capplets/theme-switcher/globals.c-53032 b/capplets/theme-switcher/globals.c-53032 deleted file mode 100644 index 4ba604be7..000000000 --- a/capplets/theme-switcher/globals.c-53032 +++ /dev/null @@ -1,5 +0,0 @@ -#include "da.h" - -gint prog_fd; -gchar gtkrc_tmp[1024]; -GtkWidget *preview_socket; diff --git a/capplets/theme-switcher/gtk-theme-selector-properties.glade b/capplets/theme-switcher/gtk-theme-selector-properties.glade deleted file mode 100644 index e69de29bb..000000000 diff --git a/capplets/theme-switcher/gtk-theme-selector-properties.glade-56055 b/capplets/theme-switcher/gtk-theme-selector-properties.glade-56055 deleted file mode 100644 index e69de29bb..000000000 diff --git a/capplets/theme-switcher/gtk-theme-selector.desktop.in b/capplets/theme-switcher/gtk-theme-selector.desktop.in index b6d961af8..89657de72 100644 --- a/capplets/theme-switcher/gtk-theme-selector.desktop.in +++ b/capplets/theme-switcher/gtk-theme-selector.desktop.in @@ -1,7 +1,7 @@ [Desktop Entry] _Name=Gtk+ Theme Selector _Comment=Select which gtk+ theme to use -Exec=gtk-theme-selector-capplet +Exec=gtk2-theme-selector-capplet Icon=gnome-ccthemes.png Terminal=0 Type=Application diff --git a/capplets/theme-switcher/gtk-theme-selector.desktop.in.in b/capplets/theme-switcher/gtk-theme-selector.desktop.in.in index b6d961af8..89657de72 100644 --- a/capplets/theme-switcher/gtk-theme-selector.desktop.in.in +++ b/capplets/theme-switcher/gtk-theme-selector.desktop.in.in @@ -1,7 +1,7 @@ [Desktop Entry] _Name=Gtk+ Theme Selector _Comment=Select which gtk+ theme to use -Exec=gtk-theme-selector-capplet +Exec=gtk2-theme-selector-capplet Icon=gnome-ccthemes.png Terminal=0 Type=Application diff --git a/capplets/theme-switcher/gtk-theme-selector.glade b/capplets/theme-switcher/gtk-theme-selector.glade new file mode 100644 index 000000000..7b0e8640c --- /dev/null +++ b/capplets/theme-switcher/gtk-theme-selector.glade @@ -0,0 +1,140 @@ + + + + + + + + Gtk+ Theme + yes + + + + + + + 4 + + + Available Themes + yes + + + + no + 4 + 4 + yes + + + automatic + automatic + in + yes + + + no + yes + + + + + yes + yes + + + + + no + 4 + yes + + + Auto Preview + yes + + + + no + + + + + Preview + yes + + + + no + + + + + Install new theme... + yes + + + + no + + + + + no + + + + + + + + + Preview + yes + + + 4 + yes + + + yes + in + + + OAFIID:GNOME_Theme_Preview + yes + + + + + + + + + + + + + + + + gtk-apply + yes + yes + 1 + yes + + + + + gtk-close + yes + yes + 2 + yes + + + + + + diff --git a/capplets/theme-switcher/gui.c b/capplets/theme-switcher/gui.c deleted file mode 100644 index 0e7286415..000000000 --- a/capplets/theme-switcher/gui.c +++ /dev/null @@ -1,650 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include -#include - -GtkWidget *preview_control; - -static gboolean ignore_change = FALSE; - -static GtkWidget *install_theme_file_sel; - -static GtkWidget *capplet_widget; -static GtkWidget *theme_list; -static GtkWidget *auto_preview; - -static ThemeEntry *current_theme = NULL; -static ThemeEntry *current_global_theme = NULL; -static ThemeEntry *initial_theme = NULL; -static ThemeEntry *last_theme = NULL; -static GtkWidget *font_sel; -static GtkWidget *font_cbox; -static gboolean initial_preview; -/* If this is TRUE, then we use the custom font */ -static gboolean initial_font_cbox; -static gchar *initial_font; -static void -click_preview(GtkWidget *widget, gpointer data); -static void -click_try(GtkWidget *widget, gpointer data); -static void -click_help(GtkWidget *widget, gpointer data); -static void -click_ok(GtkWidget *widget, gpointer data); -static void -click_revert(GtkWidget *widget, gpointer data); -static void -click_entry(GtkWidget *clist, gint row, gint col, GdkEvent *event, - gpointer data); -static void -state_changed (gboolean state); -static void -response_cb (GtkDialog *dialog, GtkResponseType response, gpointer data); - -void -send_reread(void) -{ - if (!(current_theme && current_theme->rc)) - return; - - bonobo_widget_set_property (BONOBO_WIDGET (preview_control), - "theme", TC_CORBA_string, - gtkrc_tmp, NULL); -} - -static void -auto_callback (GtkWidget *widget, gpointer data) -{ - if (ignore_change == FALSE) { - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - state_changed (TRUE); - } - -} -static void -font_callback (GtkWidget *widget, gchar *font, gpointer data) -{ - if (ignore_change == FALSE) { - state_changed (TRUE); - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - } -} -static void -use_theme_font_callback (GtkWidget *widget, gpointer data) -{ - if (ignore_change == FALSE) { - state_changed (TRUE); - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - } -} -static void -browse_dialog_ok (GtkWidget *widget, gpointer data) -{ - GtkWidget *filesel = gtk_widget_get_toplevel (widget); - gchar *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel)); - gchar *error; - - error = install_theme (filename); - - if (!error) - update_theme_entries (theme_list); - else - { - char *msg = g_strdup_printf (_("Error installing theme:\n'%s'\n%s"), - filename, error); - GtkWidget *msgbox = gnome_message_box_new (msg, - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, - NULL); - gnome_dialog_run (GNOME_DIALOG (msgbox)); - g_free (msg); - g_free (error); - } - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); - gtk_widget_destroy (filesel); -} -static void -browse_dialog_close (GtkWidget *widget, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); - gtk_widget_destroy (gtk_widget_get_toplevel (widget)); -} -static void -browse_dialog_kill (GtkWidget *widget, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); -} - -static void -install_theme_callback (GtkWidget *widget, gpointer data) -{ - GtkWidget *parent; - gtk_widget_set_sensitive (widget, FALSE); - - install_theme_file_sel = gtk_file_selection_new (_("Select a theme to install")); - gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (install_theme_file_sel)); - /* BEGIN UGLINESS. This code is stolen from gnome_dialog_set_parent. - * We want its functionality, but it takes a GnomeDialog as its argument. - * So we copy it )-: */ - - parent = gtk_widget_get_toplevel (GTK_WIDGET (widget)); - - /* We'd like to set a transient_for hint here, but it isn't - * worth the bother, since our parent window isn't in this process - */ -#if 0 - if ( gnome_preferences_get_dialog_centered() ) { - /* User wants us to center over parent */ - - gint x, y, w, h, dialog_x, dialog_y; - - if (GTK_WIDGET_VISIBLE(parent)) { - /* Throw out other positioning */ - gtk_window_set_position(GTK_WINDOW(install_theme_file_sel), - GTK_WIN_POS_NONE); - - gdk_window_get_origin (GTK_WIDGET(parent)->window, &x, &y); - gdk_window_get_size (GTK_WIDGET(parent)->window, &w, &h); - - /* The problem here is we don't know how big the dialog is. - So "centered" isn't really true. We'll go with - "kind of more or less on top" */ - dialog_x = x + w/4; - dialog_y = y + h/4; - - gtk_widget_set_uposition(GTK_WIDGET(install_theme_file_sel), - dialog_x, dialog_y); - } - } -#endif - gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (install_theme_file_sel) - ->ok_button), "clicked", - (GtkSignalFunc) browse_dialog_ok, - widget); - gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (install_theme_file_sel)->cancel_button), - "clicked", - GTK_SIGNAL_FUNC(browse_dialog_close), - widget); - gtk_signal_connect (GTK_OBJECT (install_theme_file_sel), "destroy", - GTK_SIGNAL_FUNC(browse_dialog_kill), - widget); - - if (gtk_grab_get_current ()) - gtk_grab_add (install_theme_file_sel); - - gtk_widget_show (install_theme_file_sel); - -} - -GtkWidget * -make_main(void) -{ - void *sw, *label; - GtkWidget *box, *hbox, *hbox2, *vbox; - GtkWidget *frame, *button; - GtkWidget *button_vbox; - BonoboUIContainer *container; - GConfClient *client = gconf_client_get_default (); - - capplet_widget = gtk_dialog_new_with_buttons (_("Gtk+ Theme Selector"), - NULL, -1, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - gtk_dialog_set_response_sensitive (GTK_DIALOG (capplet_widget), - GTK_RESPONSE_APPLY, FALSE); - - box = gtk_vbox_new(FALSE, GNOME_PAD); - hbox = gtk_hbox_new(TRUE, GNOME_PAD); - frame = gtk_frame_new (_("Available Themes")); - hbox2 = gtk_hbox_new(FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (hbox2), GNOME_PAD_SMALL); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), hbox2); - - /* List of available themes - */ - theme_list = gtk_clist_new (1); - gtk_signal_connect (GTK_OBJECT (theme_list), "select_row", click_entry, - NULL); - gtk_clist_set_selection_mode(GTK_CLIST(theme_list), GTK_SELECTION_BROWSE); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add (GTK_CONTAINER(sw), theme_list); - /* Mysterious allocation bug keeps shrinking hscrollbar during browse */ - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_widget_set_usize (sw, 120, -1); - - gtk_box_pack_start(GTK_BOX(hbox2), sw, TRUE, TRUE, 0); - - /* Buttons to preview, and install themes - */ - button_vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (button_vbox), GNOME_PAD_SMALL); - gtk_box_pack_start(GTK_BOX(hbox2), button_vbox, FALSE, FALSE, 0); - - label = gtk_label_new (_("Auto\nPreview")); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - auto_preview = gtk_check_button_new (); - initial_preview = gconf_client_get_bool (client, "/apps/gtk-theme-switcher/auto", NULL); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (auto_preview), - initial_preview); - gtk_signal_connect (GTK_OBJECT (auto_preview), "toggled", GTK_SIGNAL_FUNC (auto_callback), NULL); - gtk_container_add (GTK_CONTAINER (auto_preview), label); - gtk_box_pack_start (GTK_BOX (button_vbox), auto_preview, FALSE, FALSE, 0); - button = gtk_button_new_with_label (_("Preview")); - gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (click_preview), NULL); - gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0); - button = gtk_button_new_with_label (_("Install new\ntheme...")); - gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (install_theme_callback), NULL); - gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0); - - /* Font selector. - */ - frame = gtk_frame_new (_("User Font")); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - font_sel = gnome_font_picker_new (); - gnome_font_picker_set_mode (GNOME_FONT_PICKER (font_sel), - GNOME_FONT_PICKER_MODE_FONT_INFO); - initial_font = gconf_client_get_string (client, "/apps/gtk-theme-switcher/font", NULL); - - if (initial_font == NULL) { - - GtkStyle *style; - - gtk_widget_ensure_style (frame); - style = gtk_widget_get_style (frame); - - if (style->rc_style == NULL) { - /* FIXME - should really get this from X somehow */ - /* for now we just assume default gtk font */ - initial_font = g_strdup(_("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*")); - } else { - initial_font = pango_font_description_to_string (style->rc_style->font_desc); - } - } - - gnome_font_picker_set_font_name (GNOME_FONT_PICKER (font_sel), initial_font); - - gnome_font_picker_fi_set_use_font_in_label (GNOME_FONT_PICKER (font_sel), - TRUE, - 12); - gnome_font_picker_fi_set_show_size (GNOME_FONT_PICKER (font_sel), FALSE); - gtk_signal_connect (GTK_OBJECT (font_sel), - "font_set", - font_callback, - NULL); - vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), vbox); - font_cbox = gtk_check_button_new_with_label (_("Use custom font.")); - initial_font_cbox = gconf_client_get_bool (client, "/apps/gtk-theme-switcher/use_theme_font", NULL); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (font_cbox), - initial_font_cbox); - gtk_signal_connect (GTK_OBJECT (font_cbox), - "toggled", - GTK_SIGNAL_FUNC (use_theme_font_callback), - NULL); - gtk_box_pack_start (GTK_BOX (vbox), font_cbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), font_sel, FALSE, FALSE, 0); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - - gtk_widget_show_all (vbox); - - -#if 0 - readme_display = gtk_xmhtml_new(); - gtk_container_add(GTK_CONTAINER(frame2), readme_display) ; -#endif - /* Preview of theme - */ - hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL); - frame = gtk_frame_new (_("Preview")); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - container = bonobo_ui_container_new (); - preview_control = bonobo_widget_new_control ("OAFIID:GNOME_Theme_Preview", - BONOBO_OBJREF (container)); - bonobo_object_unref (BONOBO_OBJECT (container)); - - gtk_container_add(GTK_CONTAINER(frame), preview_control); - update_theme_entries(theme_list); - - g_signal_connect (G_OBJECT (capplet_widget), "response", response_cb, NULL); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (capplet_widget)->vbox), box, - TRUE, TRUE, 0); - - last_theme = NULL; - - g_object_unref (G_OBJECT (client)); - return capplet_widget; -} - -static void -click_preview(GtkWidget *widget, gpointer data) -{ - gchar *rc; - -/* if (current_theme == last_theme) - return;*/ - last_theme = current_theme; - if (!current_theme) { - return; - } - rc = current_theme->rc; - if (GTK_TOGGLE_BUTTON (font_cbox)->active) - test_theme(rc, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))); - else - { - test_theme(rc, NULL); - } - - send_reread(); -} -static void -click_help(GtkWidget *widget, gpointer data) -{ - gnome_help_display_with_doc_id (gnome_program_get (), "users-guide", "gccdesktop.html", "#GCCTHEME", NULL); -} -static void -click_try(GtkWidget *widget, gpointer data) -{ - gchar *rc; - gchar *dir; - -/* if (current_theme == current_global_theme) - return;*/ - if (!current_theme) - return; - - current_global_theme = current_theme; - rc = current_theme->rc; - dir = current_theme->dir; - - /* hack for enlightenment only!!!! */ - /* FIXME: restart what ever windowmanager you have! */ - /*g_snprintf(cmd, sizeof(cmd), "eesh -e \"restart %s/e\"", dir);*/ - /* printf("%s\n", cmd); */ - send_reread(); - if (GTK_TOGGLE_BUTTON (font_cbox)->active) - { - use_theme(rc, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))); - } - else - { - use_theme(rc, NULL); - } - gdk_error_trap_push (); - signal_apply_theme(capplet_widget); - gdk_flush(); - /* system(cmd); */ - gdk_error_trap_pop (); -} -static void -click_ok(GtkWidget *widget, gpointer data) -{ - GConfClient *client = gconf_client_get_default (); - - click_try (widget, data); - - gconf_client_set_bool (client, "/apps/gtk-theme-switcher/auto", GTK_TOGGLE_BUTTON (auto_preview)->active, NULL); - gconf_client_set_string (client, "/apps/gtk-theme-switcher/theme", current_theme->name, NULL); - gconf_client_set_bool (client, "/apps/gtk-theme-switcher/use_theme_font", - GTK_TOGGLE_BUTTON (font_cbox)->active, NULL); - - gconf_client_set_string (client, "/apps/gtk-theme-switcher/font", - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel)), NULL); - g_object_unref (G_OBJECT (client)); -} -static void -click_revert(GtkWidget *widget, gpointer data) -{ - gchar *rc; - - if (!initial_theme) - /* we hope this doesn't happen, but it could if things - * are mis-installed -jrb */ - /* Damn, I hate this code... )-: */ - return; - - rc = initial_theme->rc; - - if ((current_global_theme != initial_theme) || - (initial_font_cbox != GTK_TOGGLE_BUTTON (font_cbox)->active) || - (GTK_TOGGLE_BUTTON (font_cbox)->active && strcmp (initial_font, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))))) - { - - /* This if statement is magic to determine if we want to reset the system theme. - * It can almost certainly be cleaned up if needed. Basicly, it sees if anything has - * or if the theme has been set.. */ - send_reread(); - use_theme(rc, initial_font); - gdk_error_trap_push (); - signal_apply_theme(widget); - gdk_flush(); - gdk_error_trap_pop (); - } - current_global_theme = initial_theme; - ignore_change = TRUE; - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (auto_preview), - initial_preview); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (font_cbox), - initial_font_cbox); - if (initial_font) - gnome_font_picker_set_font_name (GNOME_FONT_PICKER (font_sel), - initial_font); - gtk_clist_select_row (GTK_CLIST (theme_list), initial_theme->row, -1); - test_theme(rc, initial_font); - send_reread(); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - ignore_change = FALSE; - current_theme = initial_theme; -} - -static void -click_entry(GtkWidget *clist, gint row, gint col, GdkEvent *event, - gpointer data) -{ - /* Load in the README file */ -#if 0 - if (readme_current) - { - g_free(readme_current); - readme_current = NULL; - } - f = fopen(readme, "r"); - if (f) - { - GString *new_readme = g_string_new (NULL); - - while (fgets(buf, 1024, f)) - g_string_append (new_readme, buf); - - fclose(f); - - gtk_xmhtml_source(GTK_XMHTML(readme_display), new_readme->str); - g_string_free (new_readme, TRUE); - } - else - gtk_xmhtml_source(GTK_XMHTML(readme_display), ""); -#endif - if (!ignore_change) - { - current_theme = gtk_clist_get_row_data (GTK_CLIST (clist), row); - - state_changed (TRUE); - - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (NULL,NULL); - } -} - -static void -item_destroy_notify (gpointer data) -{ - ThemeEntry *item = data; - - g_free(item->name); - g_free(item->rc); - g_free(item->dir); - g_free(item->icon); - - if (current_theme == item) - current_theme = NULL; - - g_free (item); -} -static gint sort_alpha(const void *a, const void *b) -{ - const ThemeEntry *A, *B; - - A = a; - B = b; - - return g_strcasecmp(A->name, B->name); -} - -static void -add_theme_list (GtkWidget *disp_list, GList *themes, gchar *d_theme, gchar *current_name) -{ - ThemeEntry *item; - GList *l; - - for (l = themes; l != NULL; l = l->next) - { - gchar *text[1] = { NULL }; - - item = l->data; - text[0] = item->name; - item->row = gtk_clist_append (GTK_CLIST(disp_list), text); - - gtk_clist_set_row_data_full (GTK_CLIST(disp_list), item->row, item, - item_destroy_notify); - - if (strcmp (d_theme, item->name) == 0) - { - current_global_theme = item; - initial_theme = item; - } - if (current_name && (strcmp (current_name, item->name) == 0)) - { - current_theme = item; - } - } -} - -void -update_theme_entries(GtkWidget *disp_list) -{ - GList *themes; - GConfClient *client = gconf_client_get_default (); - - gchar *d_theme = gconf_client_get_string (client, "/apps/gtk-theme-switcher/theme", NULL); - gchar *current_name = NULL; - - g_object_unref (G_OBJECT (client)); - - if (current_theme) - current_name = g_strdup (current_theme->name); - else - current_name = d_theme; - - current_theme = NULL; - initial_theme = NULL; - - /* Suppress an update here, because the BROWSE mode will - * cause a false initial selection - */ - ignore_change = TRUE; - - gtk_clist_clear (GTK_CLIST(disp_list)); - - themes = list_system_themes(); - themes = g_list_sort (themes, sort_alpha); - add_theme_list (disp_list, themes, d_theme, current_name); - - themes = list_user_themes(); - themes = g_list_sort (themes, sort_alpha); - add_theme_list (disp_list, themes, d_theme, current_name); - - ignore_change = FALSE; - - if (!current_theme) - current_theme = initial_theme; - - /* Suppress an update only if the current theme didn't change or - * this was the first time around - */ - if (current_theme) - { - if (current_name && - strcmp (current_theme->name, - current_name) != 0) - { - gtk_clist_select_row (GTK_CLIST (disp_list), current_theme->row, 0); - } - else - { - ignore_change = TRUE; - gtk_clist_select_row (GTK_CLIST (disp_list), current_theme->row, 0); - ignore_change = FALSE; - } - } - - if (current_name != d_theme) { - g_free (current_name); - g_free (d_theme); - } else - g_free (d_theme); - if (current_theme == NULL) - ; -} - -static void -response_cb (GtkDialog *dialog, GtkResponseType response, gpointer data) -{ - switch (response) - { - case GTK_RESPONSE_NONE: - case GTK_RESPONSE_CLOSE: - gtk_main_quit (); - break; - case GTK_RESPONSE_APPLY: - click_ok (NULL, NULL); - break; - } -} - -static void state_changed (gboolean state) -{ - gtk_dialog_set_response_sensitive (GTK_DIALOG (capplet_widget), - GTK_RESPONSE_APPLY, state); -} diff --git a/capplets/theme-switcher/gui.c-6060 b/capplets/theme-switcher/gui.c-6060 deleted file mode 100644 index 0e7286415..000000000 --- a/capplets/theme-switcher/gui.c-6060 +++ /dev/null @@ -1,650 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include -#include - -GtkWidget *preview_control; - -static gboolean ignore_change = FALSE; - -static GtkWidget *install_theme_file_sel; - -static GtkWidget *capplet_widget; -static GtkWidget *theme_list; -static GtkWidget *auto_preview; - -static ThemeEntry *current_theme = NULL; -static ThemeEntry *current_global_theme = NULL; -static ThemeEntry *initial_theme = NULL; -static ThemeEntry *last_theme = NULL; -static GtkWidget *font_sel; -static GtkWidget *font_cbox; -static gboolean initial_preview; -/* If this is TRUE, then we use the custom font */ -static gboolean initial_font_cbox; -static gchar *initial_font; -static void -click_preview(GtkWidget *widget, gpointer data); -static void -click_try(GtkWidget *widget, gpointer data); -static void -click_help(GtkWidget *widget, gpointer data); -static void -click_ok(GtkWidget *widget, gpointer data); -static void -click_revert(GtkWidget *widget, gpointer data); -static void -click_entry(GtkWidget *clist, gint row, gint col, GdkEvent *event, - gpointer data); -static void -state_changed (gboolean state); -static void -response_cb (GtkDialog *dialog, GtkResponseType response, gpointer data); - -void -send_reread(void) -{ - if (!(current_theme && current_theme->rc)) - return; - - bonobo_widget_set_property (BONOBO_WIDGET (preview_control), - "theme", TC_CORBA_string, - gtkrc_tmp, NULL); -} - -static void -auto_callback (GtkWidget *widget, gpointer data) -{ - if (ignore_change == FALSE) { - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - state_changed (TRUE); - } - -} -static void -font_callback (GtkWidget *widget, gchar *font, gpointer data) -{ - if (ignore_change == FALSE) { - state_changed (TRUE); - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - } -} -static void -use_theme_font_callback (GtkWidget *widget, gpointer data) -{ - if (ignore_change == FALSE) { - state_changed (TRUE); - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (widget,NULL); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - } -} -static void -browse_dialog_ok (GtkWidget *widget, gpointer data) -{ - GtkWidget *filesel = gtk_widget_get_toplevel (widget); - gchar *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel)); - gchar *error; - - error = install_theme (filename); - - if (!error) - update_theme_entries (theme_list); - else - { - char *msg = g_strdup_printf (_("Error installing theme:\n'%s'\n%s"), - filename, error); - GtkWidget *msgbox = gnome_message_box_new (msg, - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, - NULL); - gnome_dialog_run (GNOME_DIALOG (msgbox)); - g_free (msg); - g_free (error); - } - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); - gtk_widget_destroy (filesel); -} -static void -browse_dialog_close (GtkWidget *widget, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); - gtk_widget_destroy (gtk_widget_get_toplevel (widget)); -} -static void -browse_dialog_kill (GtkWidget *widget, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); -} - -static void -install_theme_callback (GtkWidget *widget, gpointer data) -{ - GtkWidget *parent; - gtk_widget_set_sensitive (widget, FALSE); - - install_theme_file_sel = gtk_file_selection_new (_("Select a theme to install")); - gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (install_theme_file_sel)); - /* BEGIN UGLINESS. This code is stolen from gnome_dialog_set_parent. - * We want its functionality, but it takes a GnomeDialog as its argument. - * So we copy it )-: */ - - parent = gtk_widget_get_toplevel (GTK_WIDGET (widget)); - - /* We'd like to set a transient_for hint here, but it isn't - * worth the bother, since our parent window isn't in this process - */ -#if 0 - if ( gnome_preferences_get_dialog_centered() ) { - /* User wants us to center over parent */ - - gint x, y, w, h, dialog_x, dialog_y; - - if (GTK_WIDGET_VISIBLE(parent)) { - /* Throw out other positioning */ - gtk_window_set_position(GTK_WINDOW(install_theme_file_sel), - GTK_WIN_POS_NONE); - - gdk_window_get_origin (GTK_WIDGET(parent)->window, &x, &y); - gdk_window_get_size (GTK_WIDGET(parent)->window, &w, &h); - - /* The problem here is we don't know how big the dialog is. - So "centered" isn't really true. We'll go with - "kind of more or less on top" */ - dialog_x = x + w/4; - dialog_y = y + h/4; - - gtk_widget_set_uposition(GTK_WIDGET(install_theme_file_sel), - dialog_x, dialog_y); - } - } -#endif - gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (install_theme_file_sel) - ->ok_button), "clicked", - (GtkSignalFunc) browse_dialog_ok, - widget); - gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (install_theme_file_sel)->cancel_button), - "clicked", - GTK_SIGNAL_FUNC(browse_dialog_close), - widget); - gtk_signal_connect (GTK_OBJECT (install_theme_file_sel), "destroy", - GTK_SIGNAL_FUNC(browse_dialog_kill), - widget); - - if (gtk_grab_get_current ()) - gtk_grab_add (install_theme_file_sel); - - gtk_widget_show (install_theme_file_sel); - -} - -GtkWidget * -make_main(void) -{ - void *sw, *label; - GtkWidget *box, *hbox, *hbox2, *vbox; - GtkWidget *frame, *button; - GtkWidget *button_vbox; - BonoboUIContainer *container; - GConfClient *client = gconf_client_get_default (); - - capplet_widget = gtk_dialog_new_with_buttons (_("Gtk+ Theme Selector"), - NULL, -1, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - gtk_dialog_set_response_sensitive (GTK_DIALOG (capplet_widget), - GTK_RESPONSE_APPLY, FALSE); - - box = gtk_vbox_new(FALSE, GNOME_PAD); - hbox = gtk_hbox_new(TRUE, GNOME_PAD); - frame = gtk_frame_new (_("Available Themes")); - hbox2 = gtk_hbox_new(FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (hbox2), GNOME_PAD_SMALL); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), hbox2); - - /* List of available themes - */ - theme_list = gtk_clist_new (1); - gtk_signal_connect (GTK_OBJECT (theme_list), "select_row", click_entry, - NULL); - gtk_clist_set_selection_mode(GTK_CLIST(theme_list), GTK_SELECTION_BROWSE); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add (GTK_CONTAINER(sw), theme_list); - /* Mysterious allocation bug keeps shrinking hscrollbar during browse */ - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_widget_set_usize (sw, 120, -1); - - gtk_box_pack_start(GTK_BOX(hbox2), sw, TRUE, TRUE, 0); - - /* Buttons to preview, and install themes - */ - button_vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (button_vbox), GNOME_PAD_SMALL); - gtk_box_pack_start(GTK_BOX(hbox2), button_vbox, FALSE, FALSE, 0); - - label = gtk_label_new (_("Auto\nPreview")); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - auto_preview = gtk_check_button_new (); - initial_preview = gconf_client_get_bool (client, "/apps/gtk-theme-switcher/auto", NULL); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (auto_preview), - initial_preview); - gtk_signal_connect (GTK_OBJECT (auto_preview), "toggled", GTK_SIGNAL_FUNC (auto_callback), NULL); - gtk_container_add (GTK_CONTAINER (auto_preview), label); - gtk_box_pack_start (GTK_BOX (button_vbox), auto_preview, FALSE, FALSE, 0); - button = gtk_button_new_with_label (_("Preview")); - gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (click_preview), NULL); - gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0); - button = gtk_button_new_with_label (_("Install new\ntheme...")); - gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (install_theme_callback), NULL); - gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0); - - /* Font selector. - */ - frame = gtk_frame_new (_("User Font")); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - font_sel = gnome_font_picker_new (); - gnome_font_picker_set_mode (GNOME_FONT_PICKER (font_sel), - GNOME_FONT_PICKER_MODE_FONT_INFO); - initial_font = gconf_client_get_string (client, "/apps/gtk-theme-switcher/font", NULL); - - if (initial_font == NULL) { - - GtkStyle *style; - - gtk_widget_ensure_style (frame); - style = gtk_widget_get_style (frame); - - if (style->rc_style == NULL) { - /* FIXME - should really get this from X somehow */ - /* for now we just assume default gtk font */ - initial_font = g_strdup(_("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*")); - } else { - initial_font = pango_font_description_to_string (style->rc_style->font_desc); - } - } - - gnome_font_picker_set_font_name (GNOME_FONT_PICKER (font_sel), initial_font); - - gnome_font_picker_fi_set_use_font_in_label (GNOME_FONT_PICKER (font_sel), - TRUE, - 12); - gnome_font_picker_fi_set_show_size (GNOME_FONT_PICKER (font_sel), FALSE); - gtk_signal_connect (GTK_OBJECT (font_sel), - "font_set", - font_callback, - NULL); - vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), vbox); - font_cbox = gtk_check_button_new_with_label (_("Use custom font.")); - initial_font_cbox = gconf_client_get_bool (client, "/apps/gtk-theme-switcher/use_theme_font", NULL); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (font_cbox), - initial_font_cbox); - gtk_signal_connect (GTK_OBJECT (font_cbox), - "toggled", - GTK_SIGNAL_FUNC (use_theme_font_callback), - NULL); - gtk_box_pack_start (GTK_BOX (vbox), font_cbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), font_sel, FALSE, FALSE, 0); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - - gtk_widget_show_all (vbox); - - -#if 0 - readme_display = gtk_xmhtml_new(); - gtk_container_add(GTK_CONTAINER(frame2), readme_display) ; -#endif - /* Preview of theme - */ - hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL); - frame = gtk_frame_new (_("Preview")); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); - gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); - container = bonobo_ui_container_new (); - preview_control = bonobo_widget_new_control ("OAFIID:GNOME_Theme_Preview", - BONOBO_OBJREF (container)); - bonobo_object_unref (BONOBO_OBJECT (container)); - - gtk_container_add(GTK_CONTAINER(frame), preview_control); - update_theme_entries(theme_list); - - g_signal_connect (G_OBJECT (capplet_widget), "response", response_cb, NULL); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (capplet_widget)->vbox), box, - TRUE, TRUE, 0); - - last_theme = NULL; - - g_object_unref (G_OBJECT (client)); - return capplet_widget; -} - -static void -click_preview(GtkWidget *widget, gpointer data) -{ - gchar *rc; - -/* if (current_theme == last_theme) - return;*/ - last_theme = current_theme; - if (!current_theme) { - return; - } - rc = current_theme->rc; - if (GTK_TOGGLE_BUTTON (font_cbox)->active) - test_theme(rc, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))); - else - { - test_theme(rc, NULL); - } - - send_reread(); -} -static void -click_help(GtkWidget *widget, gpointer data) -{ - gnome_help_display_with_doc_id (gnome_program_get (), "users-guide", "gccdesktop.html", "#GCCTHEME", NULL); -} -static void -click_try(GtkWidget *widget, gpointer data) -{ - gchar *rc; - gchar *dir; - -/* if (current_theme == current_global_theme) - return;*/ - if (!current_theme) - return; - - current_global_theme = current_theme; - rc = current_theme->rc; - dir = current_theme->dir; - - /* hack for enlightenment only!!!! */ - /* FIXME: restart what ever windowmanager you have! */ - /*g_snprintf(cmd, sizeof(cmd), "eesh -e \"restart %s/e\"", dir);*/ - /* printf("%s\n", cmd); */ - send_reread(); - if (GTK_TOGGLE_BUTTON (font_cbox)->active) - { - use_theme(rc, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))); - } - else - { - use_theme(rc, NULL); - } - gdk_error_trap_push (); - signal_apply_theme(capplet_widget); - gdk_flush(); - /* system(cmd); */ - gdk_error_trap_pop (); -} -static void -click_ok(GtkWidget *widget, gpointer data) -{ - GConfClient *client = gconf_client_get_default (); - - click_try (widget, data); - - gconf_client_set_bool (client, "/apps/gtk-theme-switcher/auto", GTK_TOGGLE_BUTTON (auto_preview)->active, NULL); - gconf_client_set_string (client, "/apps/gtk-theme-switcher/theme", current_theme->name, NULL); - gconf_client_set_bool (client, "/apps/gtk-theme-switcher/use_theme_font", - GTK_TOGGLE_BUTTON (font_cbox)->active, NULL); - - gconf_client_set_string (client, "/apps/gtk-theme-switcher/font", - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel)), NULL); - g_object_unref (G_OBJECT (client)); -} -static void -click_revert(GtkWidget *widget, gpointer data) -{ - gchar *rc; - - if (!initial_theme) - /* we hope this doesn't happen, but it could if things - * are mis-installed -jrb */ - /* Damn, I hate this code... )-: */ - return; - - rc = initial_theme->rc; - - if ((current_global_theme != initial_theme) || - (initial_font_cbox != GTK_TOGGLE_BUTTON (font_cbox)->active) || - (GTK_TOGGLE_BUTTON (font_cbox)->active && strcmp (initial_font, - gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_sel))))) - { - - /* This if statement is magic to determine if we want to reset the system theme. - * It can almost certainly be cleaned up if needed. Basicly, it sees if anything has - * or if the theme has been set.. */ - send_reread(); - use_theme(rc, initial_font); - gdk_error_trap_push (); - signal_apply_theme(widget); - gdk_flush(); - gdk_error_trap_pop (); - } - current_global_theme = initial_theme; - ignore_change = TRUE; - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (auto_preview), - initial_preview); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (font_cbox), - initial_font_cbox); - if (initial_font) - gnome_font_picker_set_font_name (GNOME_FONT_PICKER (font_sel), - initial_font); - gtk_clist_select_row (GTK_CLIST (theme_list), initial_theme->row, -1); - test_theme(rc, initial_font); - send_reread(); - if (!GTK_TOGGLE_BUTTON (font_cbox)->active) - gtk_widget_set_sensitive (font_sel, FALSE); - else - gtk_widget_set_sensitive (font_sel, TRUE); - ignore_change = FALSE; - current_theme = initial_theme; -} - -static void -click_entry(GtkWidget *clist, gint row, gint col, GdkEvent *event, - gpointer data) -{ - /* Load in the README file */ -#if 0 - if (readme_current) - { - g_free(readme_current); - readme_current = NULL; - } - f = fopen(readme, "r"); - if (f) - { - GString *new_readme = g_string_new (NULL); - - while (fgets(buf, 1024, f)) - g_string_append (new_readme, buf); - - fclose(f); - - gtk_xmhtml_source(GTK_XMHTML(readme_display), new_readme->str); - g_string_free (new_readme, TRUE); - } - else - gtk_xmhtml_source(GTK_XMHTML(readme_display), ""); -#endif - if (!ignore_change) - { - current_theme = gtk_clist_get_row_data (GTK_CLIST (clist), row); - - state_changed (TRUE); - - if (GTK_TOGGLE_BUTTON (auto_preview)->active) - click_preview (NULL,NULL); - } -} - -static void -item_destroy_notify (gpointer data) -{ - ThemeEntry *item = data; - - g_free(item->name); - g_free(item->rc); - g_free(item->dir); - g_free(item->icon); - - if (current_theme == item) - current_theme = NULL; - - g_free (item); -} -static gint sort_alpha(const void *a, const void *b) -{ - const ThemeEntry *A, *B; - - A = a; - B = b; - - return g_strcasecmp(A->name, B->name); -} - -static void -add_theme_list (GtkWidget *disp_list, GList *themes, gchar *d_theme, gchar *current_name) -{ - ThemeEntry *item; - GList *l; - - for (l = themes; l != NULL; l = l->next) - { - gchar *text[1] = { NULL }; - - item = l->data; - text[0] = item->name; - item->row = gtk_clist_append (GTK_CLIST(disp_list), text); - - gtk_clist_set_row_data_full (GTK_CLIST(disp_list), item->row, item, - item_destroy_notify); - - if (strcmp (d_theme, item->name) == 0) - { - current_global_theme = item; - initial_theme = item; - } - if (current_name && (strcmp (current_name, item->name) == 0)) - { - current_theme = item; - } - } -} - -void -update_theme_entries(GtkWidget *disp_list) -{ - GList *themes; - GConfClient *client = gconf_client_get_default (); - - gchar *d_theme = gconf_client_get_string (client, "/apps/gtk-theme-switcher/theme", NULL); - gchar *current_name = NULL; - - g_object_unref (G_OBJECT (client)); - - if (current_theme) - current_name = g_strdup (current_theme->name); - else - current_name = d_theme; - - current_theme = NULL; - initial_theme = NULL; - - /* Suppress an update here, because the BROWSE mode will - * cause a false initial selection - */ - ignore_change = TRUE; - - gtk_clist_clear (GTK_CLIST(disp_list)); - - themes = list_system_themes(); - themes = g_list_sort (themes, sort_alpha); - add_theme_list (disp_list, themes, d_theme, current_name); - - themes = list_user_themes(); - themes = g_list_sort (themes, sort_alpha); - add_theme_list (disp_list, themes, d_theme, current_name); - - ignore_change = FALSE; - - if (!current_theme) - current_theme = initial_theme; - - /* Suppress an update only if the current theme didn't change or - * this was the first time around - */ - if (current_theme) - { - if (current_name && - strcmp (current_theme->name, - current_name) != 0) - { - gtk_clist_select_row (GTK_CLIST (disp_list), current_theme->row, 0); - } - else - { - ignore_change = TRUE; - gtk_clist_select_row (GTK_CLIST (disp_list), current_theme->row, 0); - ignore_change = FALSE; - } - } - - if (current_name != d_theme) { - g_free (current_name); - g_free (d_theme); - } else - g_free (d_theme); - if (current_theme == NULL) - ; -} - -static void -response_cb (GtkDialog *dialog, GtkResponseType response, gpointer data) -{ - switch (response) - { - case GTK_RESPONSE_NONE: - case GTK_RESPONSE_CLOSE: - gtk_main_quit (); - break; - case GTK_RESPONSE_APPLY: - click_ok (NULL, NULL); - break; - } -} - -static void state_changed (gboolean state) -{ - gtk_dialog_set_response_sensitive (GTK_DIALOG (capplet_widget), - GTK_RESPONSE_APPLY, state); -} diff --git a/capplets/theme-switcher/install.c b/capplets/theme-switcher/install.c deleted file mode 100644 index fd586114b..000000000 --- a/capplets/theme-switcher/install.c +++ /dev/null @@ -1,82 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include - -gchar * -install_theme(gchar *file) -{ - gchar s[4096]; - gchar th[4096]; - FILE *f; - guchar buf[1024]; - gchar *theme_dir; - gchar *home; - - if (isdir(file)) - return FALSE; - - theme_dir = gtk_rc_get_theme_dir(); - if (geteuid() == 0) - g_snprintf(th, sizeof(th), "%s/", theme_dir); - else - { - home = g_get_home_dir(); - if (!home) - { - g_free(theme_dir); - return g_strdup(_("Home directory doesn't exist!\n")); - } - g_snprintf(th, sizeof(th), "%s/.themes/", home); - } - g_free(theme_dir); - - if (!isdir(th)) - md(th); - - if (!isfile(file)) - return g_strdup(_("Theme does not exist")); - - f = fopen(file, "r"); - if (f) - { - fread(buf, 1, 1000, f); - fclose(f); - if ((buf[0] == 31) && (buf[1] == 139)) - { - /*gzipped tarball */ - /*sprintf(s,"gzip -d -c < %s | tar -xf - -C %s",Theme_Tar_Ball,Theme_Path); */ - g_snprintf(s, sizeof(s), - "gzip -d -c < %s | (cd %s ; tar -xf -)", - file, th); - } - else if ((buf[257] == 'u') && (buf[258] == 's') && (buf[259] == 't') && - (buf[260] == 'a') && (buf[261] == 'r')) - { - /*vanilla tarball */ - /*sprintf(s,"tar -xf - -C %s < %s",Theme_Path,Theme_Tar_Ball); */ - g_snprintf(s, sizeof(s), - "(cd %s && tar -xf %s", - th, file); - } else - s[0] = '\0'; - - if (*s) - { - gint status = system(s); - if (status < 0) - return g_strdup(g_strerror (errno)); - else if (status != 0) - return g_strdup_printf(_("Command '%s' failed"), s); - else - return NULL; - } - else - return g_strdup(_("Unknown file format")); - } - - return FALSE; -} diff --git a/capplets/theme-switcher/install.c-64828 b/capplets/theme-switcher/install.c-64828 deleted file mode 100644 index fd586114b..000000000 --- a/capplets/theme-switcher/install.c-64828 +++ /dev/null @@ -1,82 +0,0 @@ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "da.h" -#include - -gchar * -install_theme(gchar *file) -{ - gchar s[4096]; - gchar th[4096]; - FILE *f; - guchar buf[1024]; - gchar *theme_dir; - gchar *home; - - if (isdir(file)) - return FALSE; - - theme_dir = gtk_rc_get_theme_dir(); - if (geteuid() == 0) - g_snprintf(th, sizeof(th), "%s/", theme_dir); - else - { - home = g_get_home_dir(); - if (!home) - { - g_free(theme_dir); - return g_strdup(_("Home directory doesn't exist!\n")); - } - g_snprintf(th, sizeof(th), "%s/.themes/", home); - } - g_free(theme_dir); - - if (!isdir(th)) - md(th); - - if (!isfile(file)) - return g_strdup(_("Theme does not exist")); - - f = fopen(file, "r"); - if (f) - { - fread(buf, 1, 1000, f); - fclose(f); - if ((buf[0] == 31) && (buf[1] == 139)) - { - /*gzipped tarball */ - /*sprintf(s,"gzip -d -c < %s | tar -xf - -C %s",Theme_Tar_Ball,Theme_Path); */ - g_snprintf(s, sizeof(s), - "gzip -d -c < %s | (cd %s ; tar -xf -)", - file, th); - } - else if ((buf[257] == 'u') && (buf[258] == 's') && (buf[259] == 't') && - (buf[260] == 'a') && (buf[261] == 'r')) - { - /*vanilla tarball */ - /*sprintf(s,"tar -xf - -C %s < %s",Theme_Path,Theme_Tar_Ball); */ - g_snprintf(s, sizeof(s), - "(cd %s && tar -xf %s", - th, file); - } else - s[0] = '\0'; - - if (*s) - { - gint status = system(s); - if (status < 0) - return g_strdup(g_strerror (errno)); - else if (status != 0) - return g_strdup_printf(_("Command '%s' failed"), s); - else - return NULL; - } - else - return g_strdup(_("Unknown file format")); - } - - return FALSE; -} diff --git a/capplets/theme-switcher/lister.c b/capplets/theme-switcher/lister.c deleted file mode 100644 index 79bc25506..000000000 --- a/capplets/theme-switcher/lister.c +++ /dev/null @@ -1,218 +0,0 @@ -#include "da.h" -#include -#include -#define MARK_STRING "# -- THEME AUTO-WRITTEN DO NOT EDIT\n" -static void -print_standard_stuff(FILE *fout, gchar *theme, gchar *font) -{ - gchar *homedir; - - homedir = g_strconcat ("include \"", - gnome_util_user_home(), - "/.gtkrc.mine\"\n\n", NULL); - fprintf(fout, MARK_STRING); - fprintf(fout, "include \"%s\"\n\n", theme); - if (font) - fprintf(fout, "style \"user-font\"\n{\n font=\"%s\"\n}\nwidget_class \"*\" style \"user-font\"\n\n", font); - fprintf(fout, homedir); - g_free (homedir); - fprintf(fout, MARK_STRING); -} -void -edit_file_to_use(gchar *file, gchar *theme, gchar *font) -{ - FILE *fin, *fout; - gchar tmp[4096], buf[4096]; - gchar nextline = 0, hastheme = 0; - - srand(time(NULL)); - g_snprintf(tmp, sizeof(tmp), "/tmp/gtkrc_%i", rand()); - fout = fopen(tmp, "w"); - if (!fout) - return; - fin = fopen(file, "r"); - if (!fin) - { - print_standard_stuff (fout, theme, font); - fclose(fout); - cp(tmp, file); - return; - } - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (!strcmp(MARK_STRING, buf)) - hastheme += 1; - } - rewind(fin); - if (!hastheme) - { - print_standard_stuff (fout, theme, font); - while (fgets(buf, sizeof(buf), fin)) - fprintf(fout, "%s", buf); - } - else if (hastheme == 1) - /* we keep this in for backwards compatability. */ - { - nextline = 0; - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (nextline == 1) - nextline = 0; - else if (!strcmp(MARK_STRING, buf)) - { - print_standard_stuff (fout, theme, font); - nextline = 1; - } - else if (nextline == 0) - fprintf(fout, "%s", buf); - } - } - else - { - nextline = 0; - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (!strcmp(MARK_STRING, buf)) - { - if (nextline == 0) - { - nextline = 1; - print_standard_stuff (fout, theme, font); - } - else - { - nextline = 0; - } - } else if (nextline == 0) - fprintf(fout, "%s", buf); - } - } - fclose(fin); - fclose(fout); - cp(tmp, file); - rm(tmp); -} - -void -set_tmp_rc(void) -{ - gchar s[4096], *home; - - home = g_get_home_dir (); - if (!home) - return; - g_snprintf(s, sizeof(s), "%s/.gtkrc", home); - srand(time(NULL)); - g_snprintf(gtkrc_tmp, sizeof(gtkrc_tmp), "/tmp/%i-gtkrc-%i", time(NULL), rand()); - cp(s, gtkrc_tmp); -} - -void -use_theme(gchar *theme, gchar *font) -{ - gchar s[4096], *home; - - home = g_get_home_dir (); - if (!home) - return; - g_snprintf(s, sizeof(s), "%s/.gtkrc", home); - edit_file_to_use(s, theme, font); -} - -void -test_theme(gchar *theme, gchar *font) -{ - static time_t last_written_time = 0; - time_t current_time = time (NULL); - struct utimbuf buf; - - edit_file_to_use(gtkrc_tmp, theme, font); - - if (last_written_time >= current_time) - { - current_time = last_written_time + 1; - buf.actime = current_time; - buf.modtime = current_time; - utime (gtkrc_tmp, &buf); - } - - last_written_time = current_time; -} - -void -free_theme_list(ThemeEntry *list, gint number) -{ - gint i; - - for(i = 0; i < number; i++) - { - g_free(list[i].name); - g_free(list[i].rc); - g_free(list[i].readme); - g_free(list[i].icon); - } - g_free(list); -} - -GList * -list_themes(gchar *dir) -{ - gchar **dir_listing = NULL, *tmp; - GList *list = NULL; - gint i = 0, num = 0; - - dir_listing = ls(dir, &num); - for(i = 0; i < num; i++) - { - tmp = g_strdup_printf ("%s/%s/gtk/gtkrc", dir, dir_listing[i]); - if (isfile(tmp)) - { - ThemeEntry *item = g_new0 (ThemeEntry, 1); - item->name = g_strdup(dir_listing[i]); - item->rc = g_strdup (tmp); - item->dir = g_strdup_printf ("%s/%s", dir, dir_listing[i]); - item->readme = g_strdup_printf ("%s/%s/README.html", dir, dir_listing[i]); - item->icon = g_strdup_printf ("%s/%s/ICON.png", dir, dir_listing[i]); - list = g_list_prepend (list, item); - } - g_free (tmp); - } - freestrlist(dir_listing, num); - return g_list_reverse (list); -} - -GList * -list_system_themes(void) -{ - gchar *theme_dir = NULL; - GList *list = NULL; - - theme_dir = gtk_rc_get_theme_dir(); - list = list_themes(theme_dir); - g_free(theme_dir); - return list; -} - -GList * -list_user_themes() -{ - gchar *home = NULL; - gchar *theme_dir = NULL; - GList *list = NULL; - - home = g_get_home_dir (); - if (!home) - return NULL; - - if (!isdir(home)) - return NULL; - - theme_dir = g_malloc(strlen(home) + strlen("/.themes") + 1); - sprintf(theme_dir, "%s%s", home, "/.themes"); - list = list_themes(theme_dir); - g_free(theme_dir); - return list; -} diff --git a/capplets/theme-switcher/lister.c-42011 b/capplets/theme-switcher/lister.c-42011 deleted file mode 100644 index 79bc25506..000000000 --- a/capplets/theme-switcher/lister.c-42011 +++ /dev/null @@ -1,218 +0,0 @@ -#include "da.h" -#include -#include -#define MARK_STRING "# -- THEME AUTO-WRITTEN DO NOT EDIT\n" -static void -print_standard_stuff(FILE *fout, gchar *theme, gchar *font) -{ - gchar *homedir; - - homedir = g_strconcat ("include \"", - gnome_util_user_home(), - "/.gtkrc.mine\"\n\n", NULL); - fprintf(fout, MARK_STRING); - fprintf(fout, "include \"%s\"\n\n", theme); - if (font) - fprintf(fout, "style \"user-font\"\n{\n font=\"%s\"\n}\nwidget_class \"*\" style \"user-font\"\n\n", font); - fprintf(fout, homedir); - g_free (homedir); - fprintf(fout, MARK_STRING); -} -void -edit_file_to_use(gchar *file, gchar *theme, gchar *font) -{ - FILE *fin, *fout; - gchar tmp[4096], buf[4096]; - gchar nextline = 0, hastheme = 0; - - srand(time(NULL)); - g_snprintf(tmp, sizeof(tmp), "/tmp/gtkrc_%i", rand()); - fout = fopen(tmp, "w"); - if (!fout) - return; - fin = fopen(file, "r"); - if (!fin) - { - print_standard_stuff (fout, theme, font); - fclose(fout); - cp(tmp, file); - return; - } - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (!strcmp(MARK_STRING, buf)) - hastheme += 1; - } - rewind(fin); - if (!hastheme) - { - print_standard_stuff (fout, theme, font); - while (fgets(buf, sizeof(buf), fin)) - fprintf(fout, "%s", buf); - } - else if (hastheme == 1) - /* we keep this in for backwards compatability. */ - { - nextline = 0; - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (nextline == 1) - nextline = 0; - else if (!strcmp(MARK_STRING, buf)) - { - print_standard_stuff (fout, theme, font); - nextline = 1; - } - else if (nextline == 0) - fprintf(fout, "%s", buf); - } - } - else - { - nextline = 0; - while (fgets(buf, sizeof(buf), fin)) - { - buf[sizeof(buf)-1] = '\0'; /* Be paranoid */ - if (!strcmp(MARK_STRING, buf)) - { - if (nextline == 0) - { - nextline = 1; - print_standard_stuff (fout, theme, font); - } - else - { - nextline = 0; - } - } else if (nextline == 0) - fprintf(fout, "%s", buf); - } - } - fclose(fin); - fclose(fout); - cp(tmp, file); - rm(tmp); -} - -void -set_tmp_rc(void) -{ - gchar s[4096], *home; - - home = g_get_home_dir (); - if (!home) - return; - g_snprintf(s, sizeof(s), "%s/.gtkrc", home); - srand(time(NULL)); - g_snprintf(gtkrc_tmp, sizeof(gtkrc_tmp), "/tmp/%i-gtkrc-%i", time(NULL), rand()); - cp(s, gtkrc_tmp); -} - -void -use_theme(gchar *theme, gchar *font) -{ - gchar s[4096], *home; - - home = g_get_home_dir (); - if (!home) - return; - g_snprintf(s, sizeof(s), "%s/.gtkrc", home); - edit_file_to_use(s, theme, font); -} - -void -test_theme(gchar *theme, gchar *font) -{ - static time_t last_written_time = 0; - time_t current_time = time (NULL); - struct utimbuf buf; - - edit_file_to_use(gtkrc_tmp, theme, font); - - if (last_written_time >= current_time) - { - current_time = last_written_time + 1; - buf.actime = current_time; - buf.modtime = current_time; - utime (gtkrc_tmp, &buf); - } - - last_written_time = current_time; -} - -void -free_theme_list(ThemeEntry *list, gint number) -{ - gint i; - - for(i = 0; i < number; i++) - { - g_free(list[i].name); - g_free(list[i].rc); - g_free(list[i].readme); - g_free(list[i].icon); - } - g_free(list); -} - -GList * -list_themes(gchar *dir) -{ - gchar **dir_listing = NULL, *tmp; - GList *list = NULL; - gint i = 0, num = 0; - - dir_listing = ls(dir, &num); - for(i = 0; i < num; i++) - { - tmp = g_strdup_printf ("%s/%s/gtk/gtkrc", dir, dir_listing[i]); - if (isfile(tmp)) - { - ThemeEntry *item = g_new0 (ThemeEntry, 1); - item->name = g_strdup(dir_listing[i]); - item->rc = g_strdup (tmp); - item->dir = g_strdup_printf ("%s/%s", dir, dir_listing[i]); - item->readme = g_strdup_printf ("%s/%s/README.html", dir, dir_listing[i]); - item->icon = g_strdup_printf ("%s/%s/ICON.png", dir, dir_listing[i]); - list = g_list_prepend (list, item); - } - g_free (tmp); - } - freestrlist(dir_listing, num); - return g_list_reverse (list); -} - -GList * -list_system_themes(void) -{ - gchar *theme_dir = NULL; - GList *list = NULL; - - theme_dir = gtk_rc_get_theme_dir(); - list = list_themes(theme_dir); - g_free(theme_dir); - return list; -} - -GList * -list_user_themes() -{ - gchar *home = NULL; - gchar *theme_dir = NULL; - GList *list = NULL; - - home = g_get_home_dir (); - if (!home) - return NULL; - - if (!isdir(home)) - return NULL; - - theme_dir = g_malloc(strlen(home) + strlen("/.themes") + 1); - sprintf(theme_dir, "%s%s", home, "/.themes"); - list = list_themes(theme_dir); - g_free(theme_dir); - return list; -} diff --git a/capplets/theme-switcher/main.c b/capplets/theme-switcher/main.c index 7d14c87b1..211a24b4a 100644 --- a/capplets/theme-switcher/main.c +++ b/capplets/theme-switcher/main.c @@ -1,30 +1,240 @@ +#include +#include +#include +#include -#ifdef HAVE_CONFIG_H -# include -#endif +#include +#include +#include -#include "da.h" +static GladeXML *xml; +static gchar** themes = NULL; +static GtkListStore *model; +static gboolean auto_preview; -#define THEME_SWITCHER_VERSION "0.1" +enum +{ + RESPONSE_APPLY = 1, + RESPONSE_CLOSE +}; + +static void +themes_list_add_dir (GArray *arr, const char *dirname) +{ + DIR *dir; + struct dirent *de; + const gchar *suffix = "gtk-2.0"; + + g_return_if_fail (arr != NULL); + g_return_if_fail (dirname != NULL); + + dir = opendir (dirname); + if (!dir) + return; + + while ((de = readdir (dir))) + { + char *tmp; + + if (de->d_name[0] == '.') + continue; + + tmp = g_build_filename (dirname, de->d_name, suffix, NULL); + if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) + { + g_free (tmp); + continue; + } + g_free (tmp); + + tmp = g_build_filename (dirname, de->d_name, NULL); + g_array_append_val (arr, tmp); + } + + closedir (dir); +} + +static void +themes_list_refresh (void) +{ + GArray *arr; + gchar *dir; + int i; + + if (themes) + g_strfreev (themes); + + arr = g_array_new (TRUE, TRUE, sizeof (gchar*)); + + dir = g_build_filename (g_get_home_dir (), ".themes", NULL); + themes_list_add_dir (arr, dir); + g_free (dir); + + dir = gtk_rc_get_theme_dir (); + themes_list_add_dir (arr, dir); + g_free (dir); + + themes = (gchar**) arr->data; + g_array_free (arr, FALSE); + + gtk_list_store_clear (model); + for (i = 0; themes[i] != NULL; i++) + { + GtkTreeIter iter; + gtk_list_store_append (model, &iter); + gtk_list_store_set (model, &iter, 0, g_basename (themes[i]), -1); + } +} + +static void +select_foreach_cb (GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, int *index) +{ + int *inds = gtk_tree_path_get_indices (path); + *index = *inds; +} + +static gchar* get_selected_theme (void) +{ + int index = -1; + gchar *theme; + GtkTreeView *view = GTK_TREE_VIEW (glade_xml_get_widget (xml, "tree1")); + + gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (view), (GtkTreeSelectionForeachFunc) select_foreach_cb, &index); + + if (index == -1) + return NULL; + + theme = g_build_filename (themes[index], "gtk-2.0", "gtkrc", NULL); + return theme; +} + +static void +apply_cb (void) +{ + gchar *filename = get_selected_theme (); + if (filename) + { + gconf_client_set_string (gconf_client_get_default (), "/desktop/gnome/interface/gtk_theme", filename); + g_free (filename); + } +} + +void +response_cb (GtkDialog *dialog, gint r, gpointer data) +{ + switch (r) + { + case RESPONSE_APPLY: + apply_cb (); + break; + case RESPONSE_CLOSE: + gtk_main_quit (); + break; + } +} + +void +preview_toggled_cb (GtkToggleButton *b, gpointer data) +{ + auto_preview = gtk_toggle_button_get_active (b); +} + +static void +select_cb (GtkTreeSelection *sel, GtkButton *b) +{ + GtkWidget *control; + gchar *theme; + + if (!(auto_preview || b)) + return; + + theme = get_selected_theme (); + if (!theme) + return; + + control = glade_xml_get_widget (xml, "control1"); + bonobo_widget_set_property (BONOBO_WIDGET (control), + "theme", TC_CORBA_string, + theme, NULL); + g_free (theme); +} + +void +preview_cb (GtkButton *b, gpointer data) +{ + select_cb (NULL, b); +} + +static void +fsel_ok_cb (GtkButton *b, GtkFileSelection *sel) +{ + const gchar *filename = gtk_file_selection_get_filename (sel); + gchar *command; + gchar *todir; + + if (!filename) + return; + + todir = g_build_filename (g_get_home_dir (), ".themes", NULL); + if (!g_file_test (todir, G_FILE_TEST_IS_DIR)) + mkdir (todir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + command = g_strdup_printf ("gzip -d -c < \"%s\" | tar xf - -C \"%s\"", filename, todir); + system (command); + g_free (command); + g_free (todir); + gtk_widget_destroy (GTK_WIDGET (sel)); + + themes_list_refresh (); +} + +void +install_cb (GtkButton *b, gpointer data) +{ + GtkFileSelection *sel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Select a theme to install"))); + g_signal_connect (G_OBJECT (sel->ok_button), "clicked", (GCallback) fsel_ok_cb, sel); + gtk_signal_connect_object (GTK_OBJECT (sel->cancel_button), "clicked", (GCallback) gtk_widget_destroy, G_OBJECT (sel)); + gtk_widget_show_all (GTK_WIDGET (sel)); +} + +static void +setup_list (void) +{ + GtkTreeView *view; + GtkCellRenderer *cell; + GtkTreeSelection *sel; + + model = gtk_list_store_new (1, G_TYPE_STRING); + + view = GTK_TREE_VIEW (glade_xml_get_widget (xml, "tree1")); + g_object_set (G_OBJECT (view), "model", model, NULL); + cell = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes (view, -1, "", cell, "text", 0, NULL); + + themes_list_refresh (); + + sel = gtk_tree_view_get_selection (view); + g_signal_connect (G_OBJECT (sel), "changed", (GCallback) select_cb, NULL); +} int -main(int argc, char **argv) +main (int argc, char **argv) { - GtkWidget *w; + gnome_program_init ("gtk-theme-selector", VERSION, + LIBGNOMEUI_MODULE, argc, argv, NULL); - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset (PACKAGE, "UTF-8"); - textdomain (PACKAGE); + xml = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/gtk-theme-selector.glade", NULL, NULL); + setup_list (); - set_tmp_rc(); - - gnome_program_init ("gtk-theme-selector", THEME_SWITCHER_VERSION, - LIBGNOMEUI_MODULE, argc, argv, NULL); - - w = make_main(); - gtk_widget_show_all(w); - - gtk_main(); - - return 0; + auto_preview = gconf_client_get_bool (gconf_client_get_default (), "/apps/gtk-theme-selector/auto"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (xml, "check1")), auto_preview); + + glade_xml_signal_autoconnect (xml); + gtk_main (); + + gconf_client_set_bool (gconf_client_get_default (), "/apps/gtk-theme-selector/auto", auto_preview); + + return 0; } + diff --git a/capplets/theme-switcher/signals.c b/capplets/theme-switcher/signals.c deleted file mode 100644 index feecad58c..000000000 --- a/capplets/theme-switcher/signals.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "da.h" - -void -signal_apply_theme(GtkWidget *widget) -{ - GdkEventClient rcevent; - - rcevent.type = GDK_CLIENT_EVENT; - rcevent.window = widget->window; - rcevent.send_event = TRUE; - rcevent.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); - rcevent.data_format = 8; - gdk_event_send_clientmessage_toall((GdkEvent *)&rcevent); -} diff --git a/capplets/theme-switcher/signals.c-20981 b/capplets/theme-switcher/signals.c-20981 deleted file mode 100644 index feecad58c..000000000 --- a/capplets/theme-switcher/signals.c-20981 +++ /dev/null @@ -1,14 +0,0 @@ -#include "da.h" - -void -signal_apply_theme(GtkWidget *widget) -{ - GdkEventClient rcevent; - - rcevent.type = GDK_CLIENT_EVENT; - rcevent.window = widget->window; - rcevent.send_event = TRUE; - rcevent.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); - rcevent.data_format = 8; - gdk_event_send_clientmessage_toall((GdkEvent *)&rcevent); -}