12 static gzFile gzf = NULL;
14 #define gtk_msg(type, args...) \
17 msgw = gtk_message_dialog_new(GTK_WINDOW(mainwin), \
18 GTK_DIALOG_DESTROY_WITH_PARENT | \
23 gtk_dialog_run(GTK_DIALOG(msgw)); \
24 gtk_widget_destroy(msgw); \
27 static int gzopen_frontend(const char *path, int oflags, int mode);
28 static int gzclose_frontend(int nothing);
29 static ssize_t gzread_frontend(int nothing, void *buf, size_t s);
30 static ssize_t gzwrite_frontend(int nothing, const void *buf, size_t s);
31 static gchar *get_theme_dir();
32 static gboolean change_dir(const gchar *dir);
33 static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to);
36 (openfunc_t) gzopen_frontend,
37 (closefunc_t) gzclose_frontend,
38 (readfunc_t) gzread_frontend,
39 (writefunc_t) gzwrite_frontend
42 static gchar *get_theme_dir()
47 dir = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".themes", NULL);
49 if (r == -1 && errno != EEXIST) {
50 gtk_msg(GTK_MESSAGE_ERROR,
51 _("Unable to create directory \"%s\": %s"),
52 dir, strerror(errno));
60 static gboolean change_dir(const gchar *dir)
62 if (chdir(dir) == -1) {
63 gtk_msg(GTK_MESSAGE_ERROR, _("Unable to move to directory \"%s\": %s"),
64 dir, strerror(errno));
70 static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to)
76 if (tar_open(&t, file, &funcs, 0, O_RDONLY, TAR_GNU) == -1) {
77 gtk_msg(GTK_MESSAGE_ERROR,
78 _("Unable to open the file \"%s\": %s"),
79 file, strerror(errno));
83 glob = g_strdup_printf("%s/openbox-3/*", theme);
84 r = tar_extract_glob(t, glob, to);
90 gtk_msg(GTK_MESSAGE_ERROR,
91 _("Unable to extract the file \"%s\".\nIt does not appear to be a valid Openbox theme archive (in tar.gz format)."),
92 file, strerror(errno));
97 gboolean install_theme(gchar *path, gchar *theme)
102 if (!(dest = get_theme_dir()))
105 curdir = g_get_current_dir();
106 if (!change_dir(dest)) {
111 if (install_theme_to(theme, path, dest))
112 gtk_msg(GTK_MESSAGE_INFO, _("%s was installed to %s"), theme, dest);
122 static int gzopen_frontend(const char *path, int oflags, int mode)
126 if ((fd = open(path, oflags, mode)) < 0) return -1;
127 if (!(gzf = gzdopen(fd, "rb"))) return -1;
131 static int gzclose_frontend(int nothing)
133 g_return_val_if_fail(gzf != NULL, 0);
137 static ssize_t gzread_frontend(int nothing, void *buf, size_t s)
139 return gzread(gzf, buf, s);
142 static ssize_t gzwrite_frontend(int nothing, const void *buf, size_t s)
144 return gzwrite(gzf, buf, s);