Attachment 'test.c'
Download 1 #include <stdlib.h>
2 #include <gtk/gtk.h>
3 #include <glade/glade.h>
4 #include "gpersist.h"
5
6 gboolean save_application_state (GtkWidget *w, GdkEvent *ev, GladeXML *xml)
7 {
8 g_persist_save (
9 glade_xml_get_widget (xml, "window1"),
10 G_PERSIST_SIZE, G_PERSIST_MAXIMIZED, -1);
11 g_persist_save (
12 glade_xml_get_widget (xml, "treeview1"),
13 G_PERSIST_SELECTED, -1);
14 g_persist_save (
15 glade_xml_get_widget (xml, "togglebutton1"),
16 G_PERSIST_PROPERTY, "active", -1);
17 g_persist_save (
18 glade_xml_get_widget (xml, "image4"),
19 G_PERSIST_PROPERTY, "visible", -1);
20 g_persist_save (
21 glade_xml_get_widget (xml, "notebook1"),
22 G_PERSIST_SELECTED, -1);
23 g_persist_save (
24 glade_xml_get_widget (xml, "hpaned1"),
25 G_PERSIST_POSITION, -1);
26 g_persist_save (
27 glade_xml_get_widget (xml, "vpaned1"),
28 G_PERSIST_POSITION, -1);
29 g_persist_save (
30 glade_xml_get_widget (xml, "hscale1"),
31 G_PERSIST_POSITION, -1);
32
33 return FALSE;
34 }
35
36 static void
37 on_toggle (GtkToggleButton *button, GladeXML *xml) {
38 GtkWidget *image;
39 gboolean visible;
40
41 image = glade_xml_get_widget (xml, "image4");
42 g_object_get (button, "active", &visible, NULL);
43 g_object_set (image, "visible", !visible, NULL);
44 }
45
46 static void
47 build_treeview (GladeXML *xml)
48 {
49 GtkTreeView *tv;
50 GtkListStore *store;
51 GtkCellRendererText *cell;
52 GtkTreeViewColumn *column;
53 GtkTreeIter iter1, iter2, iter3;
54 gchar *labels[] = {
55 "One", "Deux", "Drei", "Cuatro"
56 };
57 gsize i;
58
59 tv = GTK_TREE_VIEW (glade_xml_get_widget (xml, "treeview1"));
60 store = gtk_list_store_new (1, G_TYPE_STRING);
61 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
62 cell = gtk_cell_renderer_text_new ();
63 column = gtk_tree_view_column_new_with_attributes (
64 "Tree", cell, "text", 0, NULL);
65 gtk_tree_view_append_column (tv, column);
66
67 for (i = 0; i < 4; i++) {
68 gtk_list_store_append (store, &iter1);
69 gtk_list_store_set (store, &iter1, 0, labels[i], -1);
70 }
71 }
72
73 int main(int argc, char *argv[])
74 {
75 GladeXML *xml;
76 GtkWidget *w;
77
78 gtk_init (&argc, &argv);
79 glade_init ();
80 g_set_application_name ("persistantapp");
81
82 xml = glade_xml_new ("testui.glade", "window1", NULL);
83 build_treeview (xml);
84
85 w = glade_xml_get_widget (xml, "togglebutton1");
86 g_signal_connect (w, "toggled", on_toggle, xml);
87
88 w = glade_xml_get_widget (xml, "window1");
89 g_signal_connect (w, "delete-event", save_application_state, xml);
90 g_signal_connect (w, "destroy", gtk_main_quit, NULL);
91
92 g_persist_load (w);
93
94 gtk_main();
95
96 return EXIT_SUCCESS;
97 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.