Support installing icon themes.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 29 Mar 2008 01:07:16 +0000 (01:07 +0000)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 29 Mar 2008 01:07:16 +0000 (01:07 +0000)
Makefile.am
lxappearance.glade
scripts/install-icon-theme.sh [new file with mode: 0755]
src/main-dlg-ui.c
src/main-dlg.c
src/main.c

index 78c2992..0bda9cc 100644 (file)
@@ -2,29 +2,14 @@
 
 SUBDIRS = src po
 
-EXTRA_DIST = \
-       autogen.sh \
-       lxappearance.glade \
-       lxappearance.gladep
-
-install-data-local:
-       @$(NORMAL_INSTALL)
-       if test -d $(srcdir)/pixmaps; then \
-         $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \
-         for pixmap in $(srcdir)/pixmaps/*; do \
-           if test -f $$pixmap; then \
-             $(INSTALL_DATA) $$pixmap $(DESTDIR)$(pkgdatadir)/pixmaps; \
-           fi \
-         done \
-       fi
+scriptdir=$(datadir)/lxappearance
+script_DATA= \
+        scripts/install-icon-theme.sh
 
-dist-hook:
-       if test -d pixmaps; then \
-         mkdir $(distdir)/pixmaps; \
-         for pixmap in pixmaps/*; do \
-           if test -f $$pixmap; then \
-             cp -p $$pixmap $(distdir)/pixmaps; \
-           fi \
-         done \
-       fi
+install-data-hook:
+       for script in $(scriptdir)/*.sh; do \
+           chmod +x $$script; \
+       done
 
+EXTRA_DIST = \
+       autogen.sh
index bf13223..53de8c6 100644 (file)
@@ -6,7 +6,7 @@
 <widget class="GtkDialog" id="dlg">
   <property name="title" translatable="yes">Appearance Settings</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
-  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="window_position">GTK_WIN_POS_CENTER</property>
   <property name="modal">False</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</property>
diff --git a/scripts/install-icon-theme.sh b/scripts/install-icon-theme.sh
new file mode 100755 (executable)
index 0000000..882ea01
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Script used to install new icon theme.
+# Copyright (C) 2008 pauliu, pcman
+# License: GNU GPL
+
+# test argc
+if (test $# -ne 1)
+then
+  echo Usage: $0 compressed_file
+  exit
+fi
+
+# make temp dir
+TMPDIR=`mktemp -d /tmp/icon-theme-XXXXXXX`
+
+# decompress
+if [ `basename -- $1 .tar.gz` != $1 ]
+then
+        tar -C $TMPDIR -xzf $1
+elif [ `basename -- $1 .tar.bz2` != $1 ]
+then
+        tar -C $TMPDIR -xjf $1
+fi
+
+# create destdir
+if [ -z "$XDG_DATA_HOME" ]
+then
+    export XDG_DATA_HOME="$HOME/.local/share";
+fi
+THEME_DIR="$XDG_DATA_HOME/icons"
+mkdir -p "$THEME_DIR"
+
+# install
+cd $TMPDIR
+DLIST=`find -name 'index.theme' -exec dirname {} \;`
+for DIR in $DLIST
+do
+    basename "$DIR"
+    mv -f "$DIR" "$THEME_DIR"
+done
+
+# clear temp dir
+rm -rf $TMPDIR
index a30167c..ca5c6d9 100644 (file)
@@ -68,6 +68,7 @@ create_dlg (void)
 
   dlg = gtk_dialog_new ();
   gtk_window_set_title (GTK_WINDOW (dlg), _("Appearance Settings"));
+  gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
   gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_DIALOG);
 
   dialog_vbox1 = GTK_DIALOG (dlg)->vbox;
index 8687c02..7d156fd 100644 (file)
@@ -22,7 +22,7 @@
 #define INIT_LIST(name, prop) \
     GET_WIDGET( name##_view ); \
     name##_list = init_tree_view( name##_view, G_CALLBACK(on_list_sel_changed), prop ); \
-    load_##name##s( name##_list );
+    load_##name##s( name##_list, name##_name );
 
 static GtkTreeView* gtk_theme_view = NULL;
 static GtkListStore* gtk_theme_list = NULL;
@@ -33,9 +33,9 @@ static GtkListStore* icon_theme_list = NULL;
 static char* gtk_theme_name = NULL;
 static char* icon_theme_name = NULL;
 static char* font_name = NULL;
-static GtkToolbarStyle tb_style = GTK_TOOLBAR_BOTH_HORIZ;
+static GtkToolbarStyle tb_style = GTK_TOOLBAR_BOTH;
 
-static char tmp_rc_file[] = "/tmp/gtkrc-2.0-XXXXXX";
+extern char tmp_rc_file[];
 static char* rc_file = NULL;
 
 /*
@@ -204,23 +204,23 @@ static void load_from_data_dirs( GtkListStore* list,
     g_free( dir_path );
 }
 
-static void load_gtk_themes( GtkListStore* list )
+static void load_gtk_themes( GtkListStore* list, const char* cur_sel )
 {
     char* path;
     GtkTreeSelection* sel = gtk_tree_view_get_selection( gtk_theme_view );
-    load_from_data_dirs( list, "themes", "gtk-2.0", sel, gtk_theme_name );
+    load_from_data_dirs( list, "themes", "gtk-2.0", sel, cur_sel );
     path = g_build_filename( g_get_home_dir(), ".themes", NULL );
-    load_themes_from_dir( list, path, "gtk-2.0", sel, icon_theme_name );
+    load_themes_from_dir( list, path, "gtk-2.0", sel, cur_sel );
     g_free( path );
 }
 
-static void load_icon_themes( GtkListStore* list )
+static void load_icon_themes( GtkListStore* list, const char* cur_sel )
 {
     char* path;
     GtkTreeSelection* sel = gtk_tree_view_get_selection( icon_theme_view );
-    load_from_data_dirs( list, "icons", "index.theme", sel, icon_theme_name );
+    load_from_data_dirs( list, "icons", "index.theme", sel, cur_sel );
     path = g_build_filename( g_get_home_dir(), ".icons", NULL );
-    load_themes_from_dir( list, path, "index.theme", sel, icon_theme_name );
+    load_themes_from_dir( list, path, "index.theme", sel, cur_sel );
     g_free( path );
 }
 
@@ -231,10 +231,17 @@ static void load_fonts( GtkListStore* list )
 }
 */
 
-static void on_demo_loaded( GtkSocket* socket, GtkWidget* dlg )
+gboolean center_win( GtkWindow* dlg )
 {
-    gtk_window_set_position( (GtkWindow*)dlg, GTK_WIN_POS_CENTER );
     gtk_widget_show( dlg );
+    return FALSE;
+}
+
+static void on_demo_loaded( GtkSocket* socket, GtkWidget* dlg )
+{
+    /* sleep for 0.8 sec for loading of the demo window */
+    /* FIXME: we need a better way to do this, such as IPC */
+    g_timeout_add_full( G_PRIORITY_LOW, 800, (GSourceFunc)center_win, dlg, NULL );
     g_signal_handlers_disconnect_by_func( socket, on_demo_loaded, dlg );
 }
 
@@ -254,8 +261,6 @@ void main_dlg_init( GtkWidget* dlg )
     else
         rc_file = g_build_filename( g_get_home_dir(), ".gtkrc-2.0", NULL );
 
-    mkstemp( tmp_rc_file );
-
     g_object_get( gtk_settings_get_default(),
                         "gtk-theme-name", &gtk_theme_name,
                         "gtk-icon-theme-name", &icon_theme_name,
@@ -329,7 +334,6 @@ on_font_changed                        (GtkFontButton   *fontbutton,
     reload_demo_process();
 }
 
-
 void
 on_install_theme_clicked               (GtkButton       *button,
                                         gpointer         user_data)
@@ -349,7 +353,18 @@ on_install_theme_clicked               (GtkButton       *button,
 
     if( gtk_dialog_run( (GtkDialog*)fc ) == GTK_RESPONSE_OK )
     {
-
+        char* file = gtk_file_chooser_get_filename( fc );
+        char* argv[]={
+            PACKAGE_DATA_DIR"/lxappearance/install-icon-theme.sh",
+            file, NULL };
+        int status = 0;
+        if( g_spawn_sync( NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &status, NULL ) && 0 == status )
+        {
+            /* reload all icon themes */
+            gtk_list_store_clear( icon_theme_list );
+            load_icon_themes( icon_theme_list, "" );
+        }
+        g_free( file );
     }
 
     gtk_widget_destroy( fc );
index feceb13..e3fb94b 100644 (file)
@@ -9,11 +9,14 @@
 
 #include <gtk/gtk.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "main-dlg-ui.h"
 #include "demo.h"
 #include "glade-support.h"
 
+char tmp_rc_file[] = "/tmp/gtkrc-2.0-XXXXXX";
+
 int main (int argc, char *argv[])
 {
     GtkWidget *dlg;
@@ -36,6 +39,8 @@ int main (int argc, char *argv[])
         return 0;
     }
 
+    mkstemp( tmp_rc_file );
+
     gtk_set_locale ();
     gtk_init (&argc, &argv);
 
@@ -46,6 +51,8 @@ int main (int argc, char *argv[])
     main_dlg_init( dlg );
 
     gtk_main ();
+
+    unlink( tmp_rc_file );
     return 0;
 }