Try to enable installing new icon themes.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 19:27:09 +0000 (03:27 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 19:27:09 +0000 (03:27 +0800)
Makefile.am
scripts/install-icon-theme.sh [new file with mode: 0755]
src/icon-theme.c
src/utils.c
src/utils.h

index e5a3db4..470666d 100644 (file)
@@ -2,5 +2,16 @@ NULL=
 
 SUBDIRS=src po data
 
+support_scriptdir=$(datadir)/lxappearance2
+support_script_DATA= \
+        scripts/install-icon-theme.sh \
+        $(NULL)
+
 EXTRA_DIST = \
+       $(support_script_DATA) \
        $(NULL)
+
+install-data-hook:
+       for script in $(DESTDIR)$(support_scriptdir)/*.sh; do \
+           chmod +x $$script; \
+       done
diff --git a/scripts/install-icon-theme.sh b/scripts/install-icon-theme.sh
new file mode 100755 (executable)
index 0000000..a9f0e70
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Script used to install new icon theme.
+# Copyright (C) 2008 paulliu, pcman
+# License: GNU GPL
+
+# test argc
+if (test $# -ne 1)
+then
+  echo Usage: $0 compressed_file
+  exit
+fi
+
+# make temp dir
+THEME_DIR=$HOME/.icons
+mkdir -p $THEME_DIR
+TMPDIR=`mktemp -d $THEME_DIR/XXXXXXX`
+
+BASE=`basename $1`
+
+# decompress
+if [ `basename -- $BASE .tar.gz` != "$BASE" ]
+then
+        tar -C $TMPDIR -xzf $1
+elif [ `basename -- $BASE .tar.bz2` != "$BASE" ]
+then
+        tar -C $TMPDIR -xjf $1
+fi
+
+# install
+cd $TMPDIR
+DLIST=`find -name 'index.theme' -exec dirname {} \;`
+for DIR in $DLIST
+do
+    basename "$DIR"
+    mv -f "$DIR" "$THEME_DIR"
+done
+
+cd ..
+# clear temp dir
+rm -rf $TMPDIR
index 2611ded..632c0fe 100644 (file)
@@ -22,6 +22,7 @@
 #include "icon-theme.h"
 #include "lxappearance2.h"
 #include <string.h>
+#include "utils.h"
 
 gint icon_theme_cmp_name(IconTheme* t, const char* name)
 {
@@ -155,6 +156,11 @@ static void on_icon_theme_sel_changed(GtkTreeSelection* tree_sel, gpointer user_
     }
 }
 
+static void on_install_theme_clicked(GtkButton* btn, gpointer user_data)
+{
+    install_icon_theme(gtk_widget_get_toplevel(btn));
+}
+
 void icon_theme_init(GtkBuilder* b)
 {
     GSList* l;
@@ -220,4 +226,7 @@ void icon_theme_init(GtkBuilder* b)
 
     /* load "gtk-icon-sizes" */
     icon_sizes_init(b);
+
+    GtkWidget* btn = gtk_builder_get_object(b, "install_icon_theme");
+    g_signal_connect(btn, "clicked", G_CALLBACK(on_install_theme_clicked), NULL);
 }
index 5596ea7..471f0ae 100644 (file)
  */
 
 #include "utils.h"
+#include <glib/gi18n.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+
+static void on_pid_exit(GPid pid, gint status, gpointer user_data)
+{
+    GtkDialog* dlg = GTK_DIALOG(user_data);
+    gtk_dialog_response(dlg, GTK_RESPONSE_CLOSE);
+    g_debug("pid exit");
+}
+
+static void on_progress_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
+{
+    GPid* ppid = (GPid*)user_data;
+    int status;
+    kill(*ppid, SIGTERM);
+    waitpid(*ppid, &status, WNOHANG);
+}
+
+void show_progress_for_pid(GtkWindow* parent, const char* title, const char* msg, GPid pid)
+{
+    GtkWidget* dlg = gtk_dialog_new_with_buttons(title, parent,
+                            GTK_DIALOG_NO_SEPARATOR|GTK_DIALOG_MODAL,
+                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
+    guint child_watch = g_child_watch_add(pid, on_pid_exit, dlg);
+    GtkWidget* vbox = gtk_dialog_get_content_area(dlg);
+    GtkWidget* label = gtk_label_new(msg);
+    gtk_widget_show(label);
+    gtk_box_pack_start(vbox, label, FALSE, TRUE, 0);
+    g_signal_connect(dlg, "response", G_CALLBACK(on_progress_dlg_response), &pid);
+    gtk_dialog_run(dlg);
+    g_source_remove(child_watch);
+    gtk_widget_destroy(dlg);
+}
+
+gboolean install_icon_theme(GtkWindow* parent)
+{
+    GtkFileFilter* filter = gtk_file_filter_new();
+    char* file = NULL;
+    GPid pid = -1;
+    GtkWidget* fc = gtk_file_chooser_dialog_new( _("Select an icon theme"), NULL,
+                                        GTK_FILE_CHOOSER_ACTION_OPEN,
+                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                        GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL );
+
+    gtk_file_filter_add_pattern( filter, "*.tar.gz" );
+    gtk_file_filter_add_pattern( filter, "*.tar.bz2" );
+    gtk_file_filter_set_name( filter, _("*.tar.gz, *.tar.bz2 (Icon Theme)") );
+
+    gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(fc), filter );
+    gtk_file_chooser_set_filter( GTK_FILE_CHOOSER(fc), filter );
+
+    if( gtk_dialog_run( (GtkDialog*)fc ) == GTK_RESPONSE_OK )
+    {
+        file = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(fc) );
+        char* argv[]={
+            PACKAGE_DATA_DIR"/install-icon-theme.sh",
+            file, NULL };
+        g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
+        g_debug("%s\n%s\npid = %d", file, argv[0], pid);
+    }
+    gtk_widget_destroy( fc );
+
+    if(pid >=0)
+        show_progress_for_pid(parent, "Install themes", "Installing...", pid);
+    g_free(file);
+}
 
index 10b1af9..5bf12c0 100644 (file)
@@ -26,6 +26,9 @@
 
 G_BEGIN_DECLS
 
+void show_progress_for_pid(GtkWindow* parent, const char* title, const char* msg, GPid pid);
+
+gboolean install_icon_theme(GtkWindow* parent);
 
 G_END_DECLS