1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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.
23
#include "libgimpbase/gimpbase.h"
24
#include "libgimpwidgets/gimpwidgets.h"
26
#include "dialogs-types.h"
28
#include "config/gimpguiconfig.h"
30
#include "core/gimp.h"
32
#include "widgets/gimphelp-ids.h"
33
#include "widgets/gimppropwidgets.h"
35
#include "tips-dialog.h"
36
#include "tips-parser.h"
38
#include "gimp-intl.h"
41
static GtkWidget * tips_button_new (const gchar *label,
43
static void tips_set_labels (GimpTip *tip);
44
static void tips_dialog_destroy (GtkWidget *widget,
46
static void tips_show_previous (GtkWidget *widget,
48
static void tips_show_next (GtkWidget *widget,
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;
61
tips_dialog_create (Gimp *gimp)
63
GimpGuiConfig *config;
72
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
79
filename = g_build_filename (gimp_data_directory (), "tips",
80
"gimp-tips.xml", NULL);
82
tips = gimp_tips_from_file (filename, &error);
88
if (error->code == G_FILE_ERROR_NOENT)
90
tip = gimp_tip_new (_("<b>Your GIMP tips file appears to be missing!</b>"),
92
tip->thetip = g_strdup_printf (_("There should be a file called '%s'. "
93
"Please check your installation."),
98
tip = gimp_tip_new (_("<b>The GIMP tips file could not be parsed!</b>"),
102
tips = g_list_prepend (tips, tip);
103
g_error_free (error);
107
g_printerr ("Error while parsing '%s': %s\n",
108
filename, error->message);
109
g_error_free (error);
115
tips_count = g_list_length (tips);
117
config = GIMP_GUI_CONFIG (gimp->config);
119
if (config->last_tip >= tips_count || config->last_tip < 0)
120
config->last_tip = 0;
122
current_tip = g_list_nth (tips, config->last_tip);
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);
135
g_signal_connect (tips_dialog, "delete_event",
136
G_CALLBACK (gtk_widget_destroy),
139
g_signal_connect (tips_dialog, "destroy",
140
G_CALLBACK (tips_dialog_destroy),
143
vbox = gtk_vbox_new (FALSE, 0);
144
gtk_container_add (GTK_CONTAINER (tips_dialog), vbox);
145
gtk_widget_show (vbox);
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);
152
vbox2 = gtk_vbox_new (FALSE, 6);
153
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
154
gtk_widget_show (vbox2);
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);
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);
169
vbox2 = gtk_vbox_new (FALSE, 0);
170
gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
171
gtk_widget_show (vbox2);
173
filename = g_build_filename (gimp_data_directory (),
174
"images", "wilber-tips.png", NULL);
175
wilber = gdk_pixbuf_new_from_file (filename, NULL);
182
image = gtk_image_new_from_pixbuf (wilber);
183
g_object_unref (wilber);
185
gtk_box_pack_start (GTK_BOX (vbox2), image, TRUE, FALSE, 0);
186
gtk_widget_show (image);
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);
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);
199
bbox = gtk_hbutton_box_new ();
200
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
201
gtk_widget_show (bbox);
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);
209
g_signal_connect_swapped (button, "clicked",
210
G_CALLBACK (gtk_widget_destroy),
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);
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);
224
g_signal_connect (button, "clicked",
225
G_CALLBACK (tips_show_previous),
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);
233
g_signal_connect (button, "clicked",
234
G_CALLBACK (tips_show_next),
237
gimp_help_connect (tips_dialog, gimp_standard_help_func,
238
GIMP_HELP_TIPS_DIALOG, NULL);
240
tips_set_labels (current_tip->data);
246
tips_dialog_destroy (GtkWidget *widget,
249
GimpGuiConfig *config = GIMP_GUI_CONFIG (data);
251
/* the last-shown-tip is saved in sessionrc */
252
config->last_tip = g_list_position (tips, current_tip);
257
gimp_tips_free (tips);
263
tips_button_new (const gchar *text,
271
hbox = gtk_hbox_new (FALSE, 2);
273
label = gtk_label_new_with_mnemonic (text);
274
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
277
gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
279
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
281
gtk_widget_show (label);
283
image = gtk_image_new_from_stock (back ?
284
GTK_STOCK_GO_BACK : GTK_STOCK_GO_FORWARD,
285
GTK_ICON_SIZE_BUTTON);
288
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
290
gtk_box_pack_end (GTK_BOX (hbox), image, FALSE, FALSE, 0);
292
gtk_widget_show (image);
294
button = gtk_button_new ();
295
gtk_container_add (GTK_CONTAINER (button), hbox);
296
gtk_widget_show (hbox);
298
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
304
tips_set_labels (GimpTip *tip)
306
g_return_if_fail (tip != NULL);
309
gtk_widget_show (welcome_label);
311
gtk_widget_hide (welcome_label);
313
gtk_label_set_markup (GTK_LABEL (welcome_label), tip->welcome);
314
gtk_label_set_markup (GTK_LABEL (thetip_label), tip->thetip);
318
tips_show_previous (GtkWidget *widget,
321
current_tip = current_tip->prev ? current_tip->prev : g_list_last (tips);
323
tips_set_labels (current_tip->data);
327
tips_show_next (GtkWidget *widget,
330
current_tip = current_tip->next ? current_tip->next : tips;
332
tips_set_labels (current_tip->data);