aboutsummaryrefslogtreecommitdiff
path: root/src/lib/about.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/about.c')
-rw-r--r--src/lib/about.c94
1 files changed, 45 insertions, 49 deletions
diff --git a/src/lib/about.c b/src/lib/about.c
index 99ef3774..4fabfb1a 100644
--- a/src/lib/about.c
+++ b/src/lib/about.c
@@ -26,57 +26,52 @@
26 */ 26 */
27#include "gnunet_gtk.h" 27#include "gnunet_gtk.h"
28 28
29 29struct AboutDialogContext
30static void
31destroy_about_dialog (GtkBuilder * builder)
32{ 30{
31 GtkBuilder *builder;
33 GtkWidget *ad; 32 GtkWidget *ad;
33 GtkWidget *about_credits_notebook;
34 GtkWidget *about_license_scroller;
35 GtkTextBuffer *license_contents;
36};
34 37
35 ad = GTK_WIDGET (gtk_builder_get_object (builder, "about_window")); 38static void
36 gtk_widget_destroy (ad); 39destroy_about_dialog (struct AboutDialogContext *ctx)
37 g_object_unref (G_OBJECT (builder)); 40{
41 gtk_widget_destroy (ctx->ad);
42 g_object_unref (G_OBJECT (ctx->builder));
43 GNUNET_free (ctx);
38} 44}
39 45
40 46
41static void 47static void
42about_window_show_exclusively (GtkBuilder * builder, gchar * name) 48about_window_show_exclusively (struct AboutDialogContext *ctx, gchar * name)
43{ 49{
44 GtkWidget *about_credits_notebook;
45 GtkWidget *about_license_scroller;
46
47 about_credits_notebook =
48 GTK_WIDGET (gtk_builder_get_object (builder, "about_credits_notebook"));
49 about_license_scroller =
50 GTK_WIDGET (gtk_builder_get_object (builder, "about_license_scroller"));
51 if (name == NULL) 50 if (name == NULL)
52 { 51 {
53 gtk_widget_hide (about_credits_notebook); 52 gtk_widget_hide (ctx->about_credits_notebook);
54 gtk_widget_hide (about_license_scroller); 53 gtk_widget_hide (ctx->about_license_scroller);
55 } 54 }
56 else if (strcmp ("about_credits_notebook", name) == 0) 55 else if (strcmp ("about_credits_notebook", name) == 0)
57 { 56 {
58 gtk_widget_show (about_credits_notebook); 57 gtk_widget_show (ctx->about_credits_notebook);
59 gtk_widget_hide (about_license_scroller); 58 gtk_widget_hide (ctx->about_license_scroller);
60 } 59 }
61 else if (strcmp ("about_license_scroller", name) == 0) 60 else if (strcmp ("about_license_scroller", name) == 0)
62 { 61 {
63 gtk_widget_show (about_license_scroller); 62 gtk_widget_show (ctx->about_license_scroller);
64 gtk_widget_hide (about_credits_notebook); 63 gtk_widget_hide (ctx->about_credits_notebook);
65 } 64 }
66} 65}
67 66
68 67
69G_MODULE_EXPORT void 68G_MODULE_EXPORT void
70GNUNET_GTK_about_window_realized (GtkWidget * widget, gpointer user_data) 69GNUNET_GTK_about_window_realized (GtkWidget * widget, struct AboutDialogContext *ctx)
71{ 70{
72 GtkBuilder *builder = GTK_BUILDER (user_data);
73 GtkTextBuffer *license_contents;
74 gchar *license = NULL; 71 gchar *license = NULL;
75 const char *path; 72 const char *path;
76 char *license_path; 73 char *license_path;
77 74
78 license_contents =
79 GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "license_contents"));
80 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DOCDIR); 75 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DOCDIR);
81 if (path != NULL) 76 if (path != NULL)
82 GNUNET_asprintf (&license_path, "%s%s", path, "COPYING"); 77 GNUNET_asprintf (&license_path, "%s%s", path, "COPYING");
@@ -85,7 +80,7 @@ GNUNET_GTK_about_window_realized (GtkWidget * widget, gpointer user_data)
85 if (g_file_get_contents (license_path, &license, NULL, NULL) && 80 if (g_file_get_contents (license_path, &license, NULL, NULL) &&
86 (license != NULL)) 81 (license != NULL))
87 { 82 {
88 gtk_text_buffer_set_text (license_contents, license, -1); 83 gtk_text_buffer_set_text (ctx->license_contents, license, -1);
89 g_free (license); 84 g_free (license);
90 } 85 }
91 GNUNET_free_non_null (license_path); 86 GNUNET_free_non_null (license_path);
@@ -93,39 +88,31 @@ GNUNET_GTK_about_window_realized (GtkWidget * widget, gpointer user_data)
93 88
94 89
95G_MODULE_EXPORT void 90G_MODULE_EXPORT void
96GNUNET_GTK_about_close_button_clicked (GtkButton * widget, gpointer user_data) 91GNUNET_GTK_about_close_button_clicked (GtkButton * widget, struct AboutDialogContext *ctx)
97{ 92{
98 GtkBuilder *builder = GTK_BUILDER (user_data); 93 destroy_about_dialog (ctx);
99
100 destroy_about_dialog (builder);
101} 94}
102 95
103 96
104G_MODULE_EXPORT gboolean 97G_MODULE_EXPORT gboolean
105GNUNET_GTK_about_window_got_delete_event (GtkWidget * widget, GdkEvent * event, 98GNUNET_GTK_about_window_got_delete_event (GtkWidget * widget, GdkEvent * event,
106 gpointer user_data) 99 struct AboutDialogContext *ctx)
107{ 100{
108 GtkBuilder *builder = GTK_BUILDER (user_data); 101 destroy_about_dialog (ctx);
109
110 destroy_about_dialog (builder);
111 return FALSE; 102 return FALSE;
112} 103}
113 104
114 105
115G_MODULE_EXPORT void 106G_MODULE_EXPORT void
116GNUNET_GTK_about_credits_button_clicked (GtkButton * widget, gpointer user_data) 107GNUNET_GTK_about_credits_button_clicked (GtkButton * widget, struct AboutDialogContext *ctx)
117{ 108{
118 GtkBuilder *builder = GTK_BUILDER (user_data); 109 about_window_show_exclusively (ctx, "about_credits_notebook");
119
120 about_window_show_exclusively (builder, "about_credits_notebook");
121} 110}
122 111
123G_MODULE_EXPORT void 112G_MODULE_EXPORT void
124GNUNET_GTK_about_license_button_clicked (GtkButton * widget, gpointer user_data) 113GNUNET_GTK_about_license_button_clicked (GtkButton * widget, struct AboutDialogContext *ctx)
125{ 114{
126 GtkBuilder *builder = GTK_BUILDER (user_data); 115 about_window_show_exclusively (ctx, "about_license_scroller");
127
128 about_window_show_exclusively (builder, "about_license_scroller");
129} 116}
130 117
131 118
@@ -138,15 +125,24 @@ GNUNET_GTK_about_license_button_clicked (GtkButton * widget, gpointer user_data)
138void 125void
139GNUNET_GTK_display_about (const char *dialogfile) 126GNUNET_GTK_display_about (const char *dialogfile)
140{ 127{
141 GtkBuilder *builder; 128 struct AboutDialogContext *ctx;
142 GtkWidget *ad; 129 ctx = GNUNET_malloc (sizeof (struct AboutDialogContext));
130 ctx->builder = GNUNET_GTK_get_new_builder (dialogfile, ctx);
143 131
144 builder = GNUNET_GTK_get_new_builder (dialogfile, NULL); 132 if (ctx->builder == NULL)
145 if (builder == NULL) 133 {
134 GNUNET_free (ctx);
146 return; 135 return;
147 ad = GTK_WIDGET (gtk_builder_get_object (builder, "about_window")); 136 }
148 g_object_set_data (G_OBJECT (ad), "gnunet-gtk-builder", builder); 137 ctx->about_credits_notebook =
149 gtk_widget_show (ad); 138 GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_credits_notebook"));
139 ctx->about_license_scroller =
140 GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_license_scroller"));
141 ctx->ad = GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_window"));
142 ctx->license_contents =
143 GTK_TEXT_BUFFER (gtk_builder_get_object (ctx->builder, "license_contents"));
144 g_object_set_data (G_OBJECT (ctx->ad), "gnunet-gtk-builder", ctx->builder);
145 gtk_widget_show (ctx->ad);
150} 146}
151 147
152 148