aboutsummaryrefslogtreecommitdiff
path: root/src/lib/about.c
blob: 594b48830ad12b18ff3b19906fc4f3c72d6b707a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
     This file is part of GNUnet
     Copyright (C) 2005, 2006, 2010, 2011 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file src/lib/about.c
 * @brief code to display an about dialog
 * @author Christian Grothoff
 * @author Igor Wronsky
 */
#include "gnunet_gtk.h"

/**
 * Context for an about dialog.
 */
struct AboutDialogContext
{
  /**
   * Gtk builder for access to the widgets.
   */
  GtkBuilder *builder;

  /**
   * The main window of the dialog.
   */
  GtkWidget *ad;

  /**
   * Credits notebook.
   */
  GtkWidget *about_credits_notebook;

  /**
   * License notebook.
   */
  GtkWidget *about_license_scroller;

  /**
   * Buffer with the license text.
   */
  GtkTextBuffer *license_contents;
};


/**
 * Destroy all resources associated with the about dialog.
 *
 * @param ctx the dialog's context
 */
static void
destroy_about_dialog (struct AboutDialogContext *ctx)
{
  gtk_widget_destroy (ctx->ad);
  g_object_unref (G_OBJECT (ctx->builder));
  GNUNET_free (ctx);
}


/**
 * Helper function that makes one and only one of the
 * three areas of the dialog visible.
 *
 * @param ctx the dialog context
 * @param name name of the area to make visible, NULL for default
 */
static void
about_window_show_exclusively (struct AboutDialogContext *ctx,
                               const gchar * name)
{
  if (NULL == name)
  {
    gtk_widget_hide (ctx->about_credits_notebook);
    gtk_widget_hide (ctx->about_license_scroller);
  }
  else if (strcmp ("about_credits_notebook", name) == 0)
  {
    gtk_widget_show (ctx->about_credits_notebook);
    gtk_widget_hide (ctx->about_license_scroller);
  }
  else if (strcmp ("about_license_scroller", name) == 0)
  {
    gtk_widget_show (ctx->about_license_scroller);
    gtk_widget_hide (ctx->about_credits_notebook);
  }
}


/**
 * The about window has been realized; load the license file
 * from our resource directory.
 *
 * @param widget unused
 * @param ctx the dialog context
 */
G_MODULE_EXPORT void
GNUNET_GTK_about_window_realized (GtkWidget * widget,
                                  struct AboutDialogContext *ctx)
{
  gchar *license = NULL;
  const char *path;
  char *license_path;

  path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DOCDIR);
  if (path != NULL)
    GNUNET_asprintf (&license_path, "%s%s", path, "COPYING");
  else
    license_path = GNUNET_strdup ("COPYING");
  if (g_file_get_contents (license_path, &license, NULL, NULL) &&
      (license != NULL))
  {
    gtk_text_buffer_set_text (ctx->license_contents, license, -1);
    g_free (license);
  }
  GNUNET_free_non_null (license_path);
}


/**
 * The user clicked the "close" button, close the dialog.
 *
 * @param widget the button that was clicked
 * @param ctx our dialog context
 */
G_MODULE_EXPORT void
GNUNET_GTK_about_close_button_clicked (GtkButton * widget,
                                       struct AboutDialogContext *ctx)
{
  destroy_about_dialog (ctx);
}


/**
 * The user pushed the "delete" button, close the dialog.
 *
 * @param widget the widget that received the button
 * @param event the button event
 * @param ctx our dialog context
 */
G_MODULE_EXPORT gboolean
GNUNET_GTK_about_window_got_delete_event (GtkWidget * widget,
                                          GdkEvent * event,
                                          struct AboutDialogContext *ctx)
{
  destroy_about_dialog (ctx);
  return FALSE;
}


/**
 * The user clicked the "credits" button, display the credits.
 *
 * @param widget the button that was clicked
 * @param ctx our dialog context
 */
G_MODULE_EXPORT void
GNUNET_GTK_about_credits_button_clicked (GtkButton * widget,
                                         struct AboutDialogContext *ctx)
{
  about_window_show_exclusively (ctx, "about_credits_notebook");
}


/**
 * The user clicked the "license" button, display the license.
 *
 * @param widget the button that was clicked
 * @param ctx our dialog context
 */
G_MODULE_EXPORT void
GNUNET_GTK_about_license_button_clicked (GtkButton * widget,
                                         struct AboutDialogContext *ctx)
{
  about_window_show_exclusively (ctx, "about_license_scroller");
}


/**
 * This displays an about dialog.  The dialog must be called
 * "about_window" with "about_credits_notebook" and
 * "about_license_scroller" and "about_license_contents" being the
 * respective subdialogs.
 *
 * @param dialogfile name of the glade file containing the dialog
 */
void
GNUNET_GTK_display_about (const char *dialogfile)
{
  struct AboutDialogContext *ctx;

  ctx = GNUNET_new (struct AboutDialogContext);
  ctx->builder = GNUNET_GTK_get_new_builder (dialogfile, ctx);

  if (NULL == ctx->builder)
  {
    GNUNET_free (ctx);
    return;
  }
  ctx->about_credits_notebook =
      GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_credits_notebook"));
  ctx->about_license_scroller =
      GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_license_scroller"));
  ctx->ad = GTK_WIDGET (gtk_builder_get_object (ctx->builder, "about_window"));
  ctx->license_contents =
      GTK_TEXT_BUFFER (gtk_builder_get_object (ctx->builder, "license_contents"));
  gtk_widget_show (ctx->ad);
}


/* end of about.c */