~ubuntu-branches/ubuntu/breezy/gimp/breezy

« back to all changes in this revision

Viewing changes to app/dialogs/tips-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-10-04 19:04:46 UTC
  • Revision ID: james.westby@ubuntu.com-20051004190446-ukh32kwk56s4sjhu
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpbase/gimpbase.h"
 
24
#include "libgimpwidgets/gimpwidgets.h"
 
25
 
 
26
#include "dialogs-types.h"
 
27
 
 
28
#include "config/gimpguiconfig.h"
 
29
 
 
30
#include "core/gimp.h"
 
31
 
 
32
#include "widgets/gimphelp-ids.h"
 
33
#include "widgets/gimppropwidgets.h"
 
34
 
 
35
#include "tips-dialog.h"
 
36
#include "tips-parser.h"
 
37
 
 
38
#include "gimp-intl.h"
 
39
 
 
40
 
 
41
static GtkWidget * tips_button_new     (const gchar *label,
 
42
                                        gboolean     back);
 
43
static void        tips_set_labels     (GimpTip     *tip);
 
44
static void        tips_dialog_destroy (GtkWidget   *widget,
 
45
                                        gpointer     data);
 
46
static void        tips_show_previous  (GtkWidget   *widget,
 
47
                                        gpointer     data);
 
48
static void        tips_show_next      (GtkWidget   *widget,
 
49
                                        gpointer     data);
 
50
 
 
51
 
 
52
static GtkWidget *tips_dialog   = NULL;
 
53
static GtkWidget *welcome_label = NULL;
 
54
static GtkWidget *thetip_label  = NULL;
 
55
static GList     *tips          = NULL;
 
56
static GList     *current_tip   = NULL;
 
57
static gint       tips_count    = 0;
 
58
 
 
59
 
 
60
GtkWidget *
 
61
tips_dialog_create (Gimp *gimp)
 
62
{
 
63
  GimpGuiConfig *config;
 
64
  GtkWidget     *vbox;
 
65
  GtkWidget     *vbox2;
 
66
  GtkWidget     *hbox;
 
67
  GtkWidget     *bbox;
 
68
  GtkWidget     *button;
 
69
  GdkPixbuf     *wilber;
 
70
  gchar         *filename;
 
71
 
 
72
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
73
 
 
74
  if (!tips)
 
75
    {
 
76
      GError *error = NULL;
 
77
      gchar  *filename;
 
78
 
 
79
      filename = g_build_filename (gimp_data_directory (), "tips",
 
80
                                   "gimp-tips.xml", NULL);
 
81
 
 
82
      tips = gimp_tips_from_file (filename, &error);
 
83
 
 
84
      if (!tips)
 
85
        {
 
86
          GimpTip *tip;
 
87
 
 
88
          if (error->code == G_FILE_ERROR_NOENT)
 
89
            {
 
90
              tip = gimp_tip_new (_("<b>Your GIMP tips file appears to be missing!</b>"),
 
91
                                  NULL);
 
92
              tip->thetip = g_strdup_printf (_("There should be a file called '%s'. "
 
93
                                               "Please check your installation."),
 
94
                                             filename);
 
95
            }
 
96
          else
 
97
            {
 
98
              tip = gimp_tip_new (_("<b>The GIMP tips file could not be parsed!</b>"),
 
99
                                  error->message);
 
100
            }
 
101
 
 
102
          tips = g_list_prepend (tips, tip);
 
103
          g_error_free (error);
 
104
        }
 
105
      else if (error)
 
106
        {
 
107
          g_printerr ("Error while parsing '%s': %s\n",
 
108
                      filename, error->message);
 
109
          g_error_free (error);
 
110
        }
 
111
 
 
112
      g_free (filename);
 
113
    }
 
114
 
 
115
  tips_count = g_list_length (tips);
 
116
 
 
117
  config = GIMP_GUI_CONFIG (gimp->config);
 
118
 
 
119
  if (config->last_tip >= tips_count || config->last_tip < 0)
 
120
    config->last_tip = 0;
 
121
 
 
122
  current_tip = g_list_nth (tips, config->last_tip);
 
123
 
 
124
  if (tips_dialog)
 
125
    return tips_dialog;
 
126
 
 
127
  tips_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
128
  gtk_window_set_type_hint (GTK_WINDOW (tips_dialog),
 
129
                            GDK_WINDOW_TYPE_HINT_DIALOG);
 
130
  gtk_window_set_role (GTK_WINDOW (tips_dialog), "gimp-tip-of-the-day");
 
131
  gtk_window_set_title (GTK_WINDOW (tips_dialog), _("GIMP Tip of the Day"));
 
132
  gtk_window_set_position (GTK_WINDOW (tips_dialog), GTK_WIN_POS_CENTER);
 
133
  gtk_window_set_resizable (GTK_WINDOW (tips_dialog), TRUE);
 
134
 
 
135
  g_signal_connect (tips_dialog, "delete_event",
 
136
                    G_CALLBACK (gtk_widget_destroy),
 
137
                    NULL);
 
138
 
 
139
  g_signal_connect (tips_dialog, "destroy",
 
140
                    G_CALLBACK (tips_dialog_destroy),
 
141
                    config);
 
142
 
 
143
  vbox = gtk_vbox_new (FALSE, 0);
 
144
  gtk_container_add (GTK_CONTAINER (tips_dialog), vbox);
 
145
  gtk_widget_show (vbox);
 
146
 
 
147
  hbox = gtk_hbox_new (FALSE, 6);
 
148
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
 
149
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
 
150
  gtk_widget_show (hbox);
 
151
 
 
152
  vbox2 = gtk_vbox_new (FALSE, 6);
 
153
  gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
 
154
  gtk_widget_show (vbox2);
 
155
 
 
156
  welcome_label = gtk_label_new (NULL);
 
157
  gtk_label_set_justify (GTK_LABEL (welcome_label), GTK_JUSTIFY_LEFT);
 
158
  gtk_label_set_line_wrap (GTK_LABEL (welcome_label), TRUE);
 
159
  gtk_misc_set_alignment (GTK_MISC (welcome_label), 0.5, 0.5);
 
160
  gtk_box_pack_start (GTK_BOX (vbox2), welcome_label, FALSE, FALSE, 0);
 
161
 
 
162
  thetip_label = gtk_label_new (NULL);
 
163
  gtk_label_set_justify (GTK_LABEL (thetip_label), GTK_JUSTIFY_LEFT);
 
164
  gtk_label_set_line_wrap (GTK_LABEL (thetip_label), TRUE);
 
165
  gtk_misc_set_alignment (GTK_MISC (thetip_label), 0.5, 0.5);
 
166
  gtk_box_pack_start (GTK_BOX (vbox2), thetip_label, TRUE, TRUE, 0);
 
167
  gtk_widget_show (thetip_label);
 
168
 
 
169
  vbox2 = gtk_vbox_new (FALSE, 0);
 
170
  gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
 
171
  gtk_widget_show (vbox2);
 
172
 
 
173
  filename = g_build_filename (gimp_data_directory (),
 
174
                               "images", "wilber-tips.png", NULL);
 
175
  wilber = gdk_pixbuf_new_from_file (filename, NULL);
 
176
  g_free (filename);
 
177
 
 
178
  if (wilber)
 
179
    {
 
180
      GtkWidget *image;
 
181
 
 
182
      image = gtk_image_new_from_pixbuf (wilber);
 
183
      g_object_unref (wilber);
 
184
 
 
185
      gtk_box_pack_start (GTK_BOX (vbox2), image, TRUE, FALSE, 0);
 
186
      gtk_widget_show (image);
 
187
    }
 
188
 
 
189
  hbox = gtk_hbox_new (FALSE, 12);
 
190
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
 
191
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
 
192
  gtk_widget_show (hbox);
 
193
 
 
194
  button = gimp_prop_check_button_new (G_OBJECT (config), "show-tips",
 
195
                                       _("Show tip next time GIMP starts"));
 
196
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
197
  gtk_widget_show (button);
 
198
 
 
199
  bbox = gtk_hbutton_box_new ();
 
200
  gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
 
201
  gtk_widget_show (bbox);
 
202
 
 
203
  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
 
204
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
 
205
  gtk_window_set_default (GTK_WINDOW (tips_dialog), button);
 
206
  gtk_container_add (GTK_CONTAINER (bbox), button);
 
207
  gtk_widget_show (button);
 
208
 
 
209
  g_signal_connect_swapped (button, "clicked",
 
210
                            G_CALLBACK (gtk_widget_destroy),
 
211
                            tips_dialog);
 
212
 
 
213
  bbox = gtk_hbutton_box_new ();
 
214
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
 
215
  gtk_box_set_spacing (GTK_BOX (bbox), 6);
 
216
  gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
 
217
  gtk_widget_show (bbox);
 
218
 
 
219
  button = tips_button_new (_("_Previous tip"), TRUE);
 
220
  gtk_widget_set_sensitive (button, (tips_count > 1));
 
221
  gtk_container_add (GTK_CONTAINER (bbox), button);
 
222
  gtk_widget_show (button);
 
223
 
 
224
  g_signal_connect (button, "clicked",
 
225
                    G_CALLBACK (tips_show_previous),
 
226
                    NULL);
 
227
 
 
228
  button = tips_button_new (_("_Next tip"), FALSE);
 
229
  gtk_widget_set_sensitive (button, (tips_count > 1));
 
230
  gtk_container_add (GTK_CONTAINER (bbox), button);
 
231
  gtk_widget_show (button);
 
232
 
 
233
  g_signal_connect (button, "clicked",
 
234
                    G_CALLBACK (tips_show_next),
 
235
                    NULL);
 
236
 
 
237
  gimp_help_connect (tips_dialog, gimp_standard_help_func,
 
238
                     GIMP_HELP_TIPS_DIALOG, NULL);
 
239
 
 
240
  tips_set_labels (current_tip->data);
 
241
 
 
242
  return tips_dialog;
 
243
}
 
244
 
 
245
static void
 
246
tips_dialog_destroy (GtkWidget *widget,
 
247
                     gpointer   data)
 
248
{
 
249
  GimpGuiConfig *config = GIMP_GUI_CONFIG (data);
 
250
 
 
251
  /* the last-shown-tip is saved in sessionrc */
 
252
  config->last_tip = g_list_position (tips, current_tip);
 
253
 
 
254
  tips_dialog = NULL;
 
255
  current_tip = NULL;
 
256
 
 
257
  gimp_tips_free (tips);
 
258
  tips = NULL;
 
259
}
 
260
 
 
261
 
 
262
static GtkWidget *
 
263
tips_button_new (const gchar *text,
 
264
                 gboolean     back)
 
265
{
 
266
  GtkWidget *button;
 
267
  GtkWidget *label;
 
268
  GtkWidget *image;
 
269
  GtkWidget *hbox;
 
270
 
 
271
  hbox = gtk_hbox_new (FALSE, 2);
 
272
 
 
273
  label = gtk_label_new_with_mnemonic (text);
 
274
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
 
275
 
 
276
  if (back)
 
277
    gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
 
278
  else
 
279
    gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
 
280
 
 
281
  gtk_widget_show (label);
 
282
 
 
283
  image = gtk_image_new_from_stock (back ?
 
284
                                    GTK_STOCK_GO_BACK : GTK_STOCK_GO_FORWARD,
 
285
                                    GTK_ICON_SIZE_BUTTON);
 
286
 
 
287
  if (back)
 
288
    gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
 
289
  else
 
290
    gtk_box_pack_end (GTK_BOX (hbox), image, FALSE, FALSE, 0);
 
291
 
 
292
  gtk_widget_show (image);
 
293
 
 
294
  button = gtk_button_new ();
 
295
  gtk_container_add (GTK_CONTAINER (button), hbox);
 
296
  gtk_widget_show (hbox);
 
297
 
 
298
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
 
299
 
 
300
  return button;
 
301
}
 
302
 
 
303
static void
 
304
tips_set_labels (GimpTip *tip)
 
305
{
 
306
  g_return_if_fail (tip != NULL);
 
307
 
 
308
  if (tip->welcome)
 
309
    gtk_widget_show (welcome_label);
 
310
  else
 
311
    gtk_widget_hide (welcome_label);
 
312
 
 
313
  gtk_label_set_markup (GTK_LABEL (welcome_label), tip->welcome);
 
314
  gtk_label_set_markup (GTK_LABEL (thetip_label), tip->thetip);
 
315
}
 
316
 
 
317
static void
 
318
tips_show_previous (GtkWidget *widget,
 
319
                    gpointer  data)
 
320
{
 
321
  current_tip = current_tip->prev ? current_tip->prev : g_list_last (tips);
 
322
 
 
323
  tips_set_labels (current_tip->data);
 
324
}
 
325
 
 
326
static void
 
327
tips_show_next (GtkWidget *widget,
 
328
                gpointer   data)
 
329
{
 
330
  current_tip = current_tip->next ? current_tip->next : tips;
 
331
 
 
332
  tips_set_labels (current_tip->data);
 
333
}