Load icon and gtk+ themes on startup.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sun, 23 Mar 2008 04:18:18 +0000 (04:18 +0000)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sun, 23 Mar 2008 04:18:18 +0000 (04:18 +0000)
lxappearance.glade
po/POTFILES.in
src/main-dlg-ui.c
src/main-dlg.c
src/main-dlg.h
src/main.c

index ae496ce..797ba6d 100644 (file)
                        <widget class="GtkTreeView" id="gtk_theme_view">
                          <property name="visible">True</property>
                          <property name="can_focus">True</property>
-                         <property name="headers_visible">True</property>
+                         <property name="headers_visible">False</property>
                          <property name="rules_hint">False</property>
                          <property name="reorderable">False</property>
                          <property name="enable_search">True</property>
                        <widget class="GtkTreeView" id="icon_theme_view">
                          <property name="visible">True</property>
                          <property name="can_focus">True</property>
-                         <property name="headers_visible">True</property>
+                         <property name="headers_visible">False</property>
                          <property name="rules_hint">False</property>
                          <property name="reorderable">False</property>
                          <property name="enable_search">True</property>
                        <widget class="GtkTreeView" id="font_view">
                          <property name="visible">True</property>
                          <property name="can_focus">True</property>
-                         <property name="headers_visible">True</property>
+                         <property name="headers_visible">False</property>
                          <property name="rules_hint">False</property>
                          <property name="reorderable">False</property>
                          <property name="enable_search">True</property>
                                  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
                                  <child>
-                                   <widget class="GtkIconView" id="iconview1">
+                                   <widget class="GtkIconView" id="icon_view">
                                      <property name="visible">True</property>
                                      <property name="can_focus">True</property>
                                      <property name="selection_mode">GTK_SELECTION_SINGLE</property>
@@ -1105,7 +1105,38 @@ Test Item 3</property>
                              </child>
 
                              <child>
-                               <placeholder/>
+                               <widget class="GtkScrolledWindow" id="scrolledwindow5">
+                                 <property name="visible">True</property>
+                                 <property name="can_focus">True</property>
+                                 <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                                 <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                                 <property name="shadow_type">GTK_SHADOW_IN</property>
+                                 <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+                                 <child>
+                                   <widget class="GtkTextView" id="text_view">
+                                     <property name="visible">True</property>
+                                     <property name="can_focus">True</property>
+                                     <property name="editable">True</property>
+                                     <property name="overwrite">False</property>
+                                     <property name="accepts_tab">True</property>
+                                     <property name="justification">GTK_JUSTIFY_LEFT</property>
+                                     <property name="wrap_mode">GTK_WRAP_NONE</property>
+                                     <property name="cursor_visible">True</property>
+                                     <property name="pixels_above_lines">0</property>
+                                     <property name="pixels_below_lines">0</property>
+                                     <property name="pixels_inside_wrap">0</property>
+                                     <property name="left_margin">0</property>
+                                     <property name="right_margin">0</property>
+                                     <property name="indent">0</property>
+                                     <property name="text" translatable="yes"></property>
+                                   </widget>
+                                 </child>
+                               </widget>
+                               <packing>
+                                 <property name="tab_expand">False</property>
+                                 <property name="tab_fill">True</property>
+                               </packing>
                              </child>
 
                              <child>
index 1d7598e..658fa3f 100644 (file)
@@ -3,4 +3,3 @@
 src/main.c
 src/main-dlg-ui.c
 src/main-dlg.c
-src/glade-support.c
index 5d48055..5ab7551 100644 (file)
@@ -85,7 +85,7 @@ create_dlg (void)
   GtkWidget *toolbutton3;
   GtkWidget *notebook2;
   GtkWidget *scrolledwindow4;
-  GtkWidget *iconview1;
+  GtkWidget *icon_view;
   GtkWidget *label12;
   GtkWidget *hbox2;
   GtkWidget *frame2;
@@ -108,6 +108,8 @@ create_dlg (void)
   GtkWidget *button1;
   GtkWidget *combobox2;
   GtkWidget *label13;
+  GtkWidget *scrolledwindow5;
+  GtkWidget *text_view;
   GtkWidget *label14;
   GtkWidget *statusbar1;
   GtkWidget *dialog_action_area1;
@@ -151,6 +153,7 @@ create_dlg (void)
   gtk_theme_view = gtk_tree_view_new ();
   gtk_widget_show (gtk_theme_view);
   gtk_container_add (GTK_CONTAINER (scrolledwindow1), gtk_theme_view);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (gtk_theme_view), FALSE);
 
   label2 = gtk_label_new (_("Window"));
   gtk_widget_show (label2);
@@ -173,6 +176,7 @@ create_dlg (void)
   icon_theme_view = gtk_tree_view_new ();
   gtk_widget_show (icon_theme_view);
   gtk_container_add (GTK_CONTAINER (scrolledwindow2), icon_theme_view);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (icon_theme_view), FALSE);
 
   label3 = gtk_label_new (_("Icon"));
   gtk_widget_show (label3);
@@ -195,6 +199,7 @@ create_dlg (void)
   font_view = gtk_tree_view_new ();
   gtk_widget_show (font_view);
   gtk_container_add (GTK_CONTAINER (scrolledwindow3), font_view);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (font_view), FALSE);
 
   table1 = gtk_table_new (2, 2, FALSE);
   gtk_widget_show (table1);
@@ -363,9 +368,9 @@ create_dlg (void)
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_SHADOW_IN);
 
-  iconview1 = gtk_icon_view_new ();
-  gtk_widget_show (iconview1);
-  gtk_container_add (GTK_CONTAINER (scrolledwindow4), iconview1);
+  icon_view = gtk_icon_view_new ();
+  gtk_widget_show (icon_view);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow4), icon_view);
 
   label12 = gtk_label_new (_("Tab1"));
   gtk_widget_show (label12);
@@ -458,9 +463,15 @@ create_dlg (void)
   gtk_widget_show (label13);
   gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 1), label13);
 
-  empty_notebook_page = gtk_vbox_new (FALSE, 0);
-  gtk_widget_show (empty_notebook_page);
-  gtk_container_add (GTK_CONTAINER (notebook2), empty_notebook_page);
+  scrolledwindow5 = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_show (scrolledwindow5);
+  gtk_container_add (GTK_CONTAINER (notebook2), scrolledwindow5);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow5), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow5), GTK_SHADOW_IN);
+
+  text_view = gtk_text_view_new ();
+  gtk_widget_show (text_view);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow5), text_view);
 
   label14 = gtk_label_new (_("Tab3"));
   gtk_widget_show (label14);
@@ -549,7 +560,7 @@ create_dlg (void)
   GLADE_HOOKUP_OBJECT (dlg, toolbutton3, "toolbutton3");
   GLADE_HOOKUP_OBJECT (dlg, notebook2, "notebook2");
   GLADE_HOOKUP_OBJECT (dlg, scrolledwindow4, "scrolledwindow4");
-  GLADE_HOOKUP_OBJECT (dlg, iconview1, "iconview1");
+  GLADE_HOOKUP_OBJECT (dlg, icon_view, "icon_view");
   GLADE_HOOKUP_OBJECT (dlg, label12, "label12");
   GLADE_HOOKUP_OBJECT (dlg, hbox2, "hbox2");
   GLADE_HOOKUP_OBJECT (dlg, frame2, "frame2");
@@ -569,6 +580,8 @@ create_dlg (void)
   GLADE_HOOKUP_OBJECT (dlg, button1, "button1");
   GLADE_HOOKUP_OBJECT (dlg, combobox2, "combobox2");
   GLADE_HOOKUP_OBJECT (dlg, label13, "label13");
+  GLADE_HOOKUP_OBJECT (dlg, scrolledwindow5, "scrolledwindow5");
+  GLADE_HOOKUP_OBJECT (dlg, text_view, "text_view");
   GLADE_HOOKUP_OBJECT (dlg, label14, "label14");
   GLADE_HOOKUP_OBJECT (dlg, statusbar1, "statusbar1");
   GLADE_HOOKUP_OBJECT_NO_REF (dlg, dialog_action_area1, "dialog_action_area1");
index 3fa6287..9c8b138 100644 (file)
@@ -8,6 +8,119 @@
 #include "main-dlg-ui.h"
 #include "glade-support.h"
 
+#define GET_WIDGET( name )  name = lookup_widget( dlg, #name )
+#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 );
+
+static GtkTreeView* gtk_theme_view = NULL;
+GtkListStore* gtk_theme_list = NULL;
+
+static GtkTreeView* icon_theme_view = NULL;
+GtkListStore* icon_theme_list = NULL;
+
+static GtkTreeView* font_view = NULL;
+GtkListStore* font_list = NULL;
+
+static on_list_sel_changed( GtkTreeSelection* sel, const char* prop )
+{
+    GtkTreeIter it;
+    GtkTreeModel* model;
+    if( gtk_tree_selection_get_selected( sel, &model, &it ) )
+    {
+        char* name;
+        gtk_tree_model_get( model, &it, 0, &name, -1 );
+        if( model == font_list )    /* this is a font */
+        {
+
+        }
+        g_object_set( gtk_settings_get_default(), prop, name, NULL );
+        g_free( name );
+    }
+}
+
+static GtkListStore* init_tree_view( GtkTreeView* view, GCallback on_sel_changed, const char* prop )
+{
+    GtkTreeViewColumn* col;
+    GtkListStore* list;
+    col = gtk_tree_view_column_new_with_attributes( NULL, gtk_cell_renderer_text_new(), "text", 0, NULL );
+    gtk_tree_view_append_column( view, col );
+    g_signal_connect( gtk_tree_view_get_selection(view), "changed", on_sel_changed, prop );
+
+    list = gtk_list_store_new( 1, G_TYPE_STRING );
+    gtk_tree_view_set_model( view, (GtkTreeModel*)list );
+    g_object_unref( list );
+    return list;
+}
+
+static void load_themes_from_dir( GtkListStore* list,
+                                                    const char* dir_path,
+                                                    const char* lookup )
+{
+    GDir* dir;
+    if( dir = g_dir_open( dir_path, 0, NULL ) )
+    {
+        char* name;
+        while( name = g_dir_read_name( dir ) )
+        {
+            char* file = g_build_filename( dir_path, name, lookup, NULL );
+            if( g_file_test( file, G_FILE_TEST_EXISTS ) )
+            {
+                GtkTreeIter it;
+                gtk_list_store_append( list, &it );
+                gtk_list_store_set( list, &it, 0, name, -1 );
+            }
+            g_free( file );
+        }
+        g_dir_close( dir );
+    }
+}
+
+static void load_from_data_dirs( GtkListStore* list,
+                                                const char* relative_path,
+                                                const char* lookup )
+{
+    const char* const *dirs = g_get_system_data_dirs();
+    const char* const *dir;
+    char* dir_path;
+    for( dir = dirs; *dir; ++dir )
+    {
+        dir_path = g_build_filename( *dir, relative_path, NULL );
+        load_themes_from_dir( list, dir_path, lookup );
+        g_free( dir_path );
+    }
+    dir_path = g_build_filename( g_get_user_data_dir(), relative_path, NULL );
+    load_themes_from_dir( list, dir_path, lookup );
+    g_free( dir_path );
+}
+
+static void load_gtk_themes( GtkListStore* list )
+{
+    load_from_data_dirs( list, "themes", "gtk-2.0" );
+}
+
+static void load_icon_themes( GtkListStore* list )
+{
+    char* path;
+    load_from_data_dirs( list, "icons", "index.theme" );
+    path = g_build_filename( g_get_home_dir(), ".icons", NULL );
+    load_themes_from_dir( list, path, "index.theme" );
+    g_free( path );
+}
+
+static void load_fonts( GtkListStore* list )
+{
+
+}
+
+void main_dlg_init( GtkWidget* dlg )
+{
+    INIT_LIST( gtk_theme, "gtk-theme-name" )
+    INIT_LIST( icon_theme, "gtk-icon-theme-name" )
+    INIT_LIST( font, "gtk-font-name" )
+
+}
 
 void
 on_apply_clicked                       (GtkButton       *button,
index 827c520..acad596 100644 (file)
@@ -1,5 +1,6 @@
 #include <gtk/gtk.h>
 
+void main_dlg_init( GtkWidget* dlg );
 
 void
 on_apply_clicked                       (GtkButton       *button,
index 24ffb7b..f4ce409 100644 (file)
@@ -26,14 +26,8 @@ main (int argc, char *argv[])
   gtk_set_locale ();
   gtk_init (&argc, &argv);
 
-  add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
-
-  /*
-   * The following code was added by Glade to create one of each component
-   * (except popup menus), just so that you see something after building
-   * the project. Delete any components that you don't want shown initially.
-   */
   dlg = create_dlg ();
+  main_dlg_init( dlg );
   gtk_widget_show (dlg);
 
   gtk_main ();