Merging upstream version 0.4.0.
[debian/lxappearance.git] / src / demo.c
CommitLineData
08024023
DB
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <gtk/gtk.h>
c93a68c7 6#include <glib/gi18n.h>
08024023 7#include "demo.h"
08024023 8
8df2f63a 9extern gboolean under_lxsession; /* wether lxsession-xsettings daemon is active */
08024023
DB
10
11static GtkIconView* icon_view = NULL;
12
13static void load_demo_icons()
14{
eddc0c49 15 static const char* icon_names[]={
c93a68c7
DB
16 "user-home",
17 "user-desktop",
18 "folder",
19 "folder-remote",
20 "user-trash",
21 "x-office-document",
22 "application-x-executable",
23 "image-x-generic",
24 "text-x-generic",
25 "text-html"
08024023
DB
26 };
27
28 int i;
29 GtkIconTheme* theme = gtk_icon_theme_get_default();
30 GtkListStore* demo_icon_list;
31
32 demo_icon_list = gtk_list_store_new( 2, GDK_TYPE_PIXBUF, G_TYPE_STRING );
33
34 for( i = 0; i < G_N_ELEMENTS(icon_names); ++i )
35 {
36 GtkTreeIter it;
37 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, icon_names[i], 32, 0, NULL );
38 gtk_list_store_append( demo_icon_list, &it );
39 gtk_list_store_set( demo_icon_list, &it, 0, icon, 1, icon_names[i], -1 );
40 if( icon )
41 g_object_unref( icon );
42 }
eddc0c49 43 gtk_icon_view_set_model( icon_view, GTK_TREE_MODEL(demo_icon_list) );
08024023
DB
44 g_object_unref( demo_icon_list );
45}
46
47static void load_demo_tree_view( GtkTreeView* view )
48{
49 GtkListStore* list;
50 int i;
51 char str[256];
52
53 for( i = 0; i < 3; ++i )
54 {
55 GtkTreeViewColumn* col;
56 g_snprintf( str, 256, "%s %d", _("Column"), i + 1 );
57 col = gtk_tree_view_column_new_with_attributes( "Column 1", gtk_cell_renderer_text_new(), "text", i, NULL );
58 gtk_tree_view_append_column( view, col );
59 }
60
61 list = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
62 for( i = 0; i < 3; ++i )
63 {
64 GtkTreeIter it;
65 g_snprintf( str, 256, "%s %d", _("Item"), i + 1 );
66 gtk_list_store_append( list, &it );
67 gtk_list_store_set( list, &it, 0, str, 1, str, 2, str, -1 );
68 }
69 gtk_tree_view_set_model( view, (GtkTreeModel*)list );
70 g_object_unref( list );
71}
72
73void show_demo( GdkNativeWindow wid )
74{
c93a68c7
DB
75 GtkBuilder* builder = gtk_builder_new();
76 GtkWidget* demo;
08024023
DB
77 GtkWidget* plug;
78 GtkWidget* top_vbox;
79 GtkToolbarStyle tb_style;
80 GtkWidget* tree_view;
81
c93a68c7
DB
82 gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/lxappearance/demo.ui", NULL);
83 demo = (GtkWidget*)gtk_builder_get_object(builder, "demo");
84
08024023 85 g_object_get( gtk_settings_get_default(), "gtk-toolbar-style", &tb_style, NULL );
c93a68c7 86 gtk_toolbar_set_style (GTK_TOOLBAR (gtk_builder_get_object(builder, "toolbar")), tb_style );
08024023 87
c93a68c7
DB
88 icon_view = GTK_ICON_VIEW( gtk_builder_get_object(builder, "icon_view" ) );
89 tree_view = (GtkWidget*)gtk_builder_get_object(builder, "demo_treeview" );
08024023
DB
90
91 gtk_icon_view_set_pixbuf_column( icon_view, 0 );
92 gtk_icon_view_set_text_column( icon_view, 1 );
08024023
DB
93
94 load_demo_icons();
95 load_demo_tree_view( (GtkTreeView*)tree_view );
96
97 gtk_widget_show_all( demo );
98
8df2f63a
DB
99 /* lxsession settings daemon is active and we don't use gtkrc files. */
100 if( under_lxsession )
08024023
DB
101 {
102 /* The demo window and the main dialog are in the same process */
103 GtkWidget* demo_box = (GtkWidget*)wid;
eddc0c49 104 gtk_container_add( GTK_CONTAINER(demo_box), demo );
08024023
DB
105 g_signal_connect( gtk_icon_theme_get_default(), "changed", G_CALLBACK( load_demo_icons ), NULL );
106 }
107 else
108 {
109 /* we are in another process with a different gtkrc file. */
110 plug = gtk_plug_new( wid ); /* plug our demo window into the main process */
111 gtk_container_add( (GtkContainer*)plug, demo );
112 gtk_widget_show( plug );
113 }
c93a68c7 114 g_object_unref(builder);
08024023 115}