2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-12-17 22:34:12 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-12-16 21:37:03 +00:00
|
|
|
|
1999-03-07 12:56:03 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-16 21:37:03 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-05-21 20:30:16 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 22:36:18 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-09-13 15:15:23 +00:00
|
|
|
#include "dialogs-types.h"
|
2000-12-29 15:22:01 +00:00
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
|
2003-08-21 15:54:47 +00:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2002-11-22 18:06:36 +00:00
|
|
|
|
2001-04-17 21:43:29 +00:00
|
|
|
#include "tips-dialog.h"
|
2002-02-25 02:52:33 +00:00
|
|
|
#include "tips-parser.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2000-04-27 17:27:28 +00:00
|
|
|
|
2007-06-06 22:42:45 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RESPONSE_PREVIOUS = 1,
|
|
|
|
RESPONSE_NEXT = 2
|
|
|
|
};
|
|
|
|
|
2008-08-04 13:56:07 +00:00
|
|
|
static void tips_dialog_set_tip (GimpTip *tip);
|
|
|
|
static void tips_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response);
|
|
|
|
static void tips_dialog_destroy (GtkWidget *widget,
|
|
|
|
GimpGuiConfig *config);
|
|
|
|
static void more_button_clicked (GtkWidget *button,
|
|
|
|
Gimp *gimp);
|
2001-01-24 22:36:18 +00:00
|
|
|
|
|
|
|
|
2008-08-04 13:56:07 +00:00
|
|
|
static GtkWidget *tips_dialog = NULL;
|
|
|
|
static GtkWidget *tip_label = NULL;
|
|
|
|
static GtkWidget *more_button = NULL;
|
|
|
|
static GList *tips = NULL;
|
|
|
|
static GList *current_tip = NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
|
2001-04-18 16:39:34 +00:00
|
|
|
GtkWidget *
|
2002-11-18 20:50:31 +00:00
|
|
|
tips_dialog_create (Gimp *gimp)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2002-11-18 20:50:31 +00:00
|
|
|
GimpGuiConfig *config;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
2006-06-20 18:28:06 +00:00
|
|
|
GtkWidget *image;
|
2007-06-06 22:42:45 +00:00
|
|
|
gint tips_count;
|
2002-11-18 20:50:31 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-02-25 02:52:33 +00:00
|
|
|
if (!tips)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2002-02-25 02:52:33 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *filename;
|
|
|
|
|
2003-09-15 15:24:52 +00:00
|
|
|
filename = g_build_filename (gimp_data_directory (), "tips",
|
2002-02-25 02:52:33 +00:00
|
|
|
"gimp-tips.xml", NULL);
|
2002-02-25 16:48:30 +00:00
|
|
|
|
2002-02-25 18:36:03 +00:00
|
|
|
tips = gimp_tips_from_file (filename, &error);
|
2002-02-25 02:52:33 +00:00
|
|
|
|
2006-10-09 13:06:26 +00:00
|
|
|
if (! tips)
|
2002-02-25 02:52:33 +00:00
|
|
|
{
|
2003-09-15 15:24:52 +00:00
|
|
|
GimpTip *tip;
|
|
|
|
|
2008-03-27 21:02:15 +00:00
|
|
|
if (! error)
|
2003-09-15 15:24:52 +00:00
|
|
|
{
|
2008-03-28 07:50:11 +00:00
|
|
|
tip = gimp_tip_new (_("The GIMP tips file is empty!"), NULL);
|
2008-03-27 21:02:15 +00:00
|
|
|
}
|
|
|
|
else if (error->code == G_FILE_ERROR_NOENT)
|
|
|
|
{
|
2008-03-28 07:50:11 +00:00
|
|
|
tip = gimp_tip_new (_("The GIMP tips file appears to be "
|
|
|
|
"missing!"),
|
|
|
|
_("There should be a file called '%s'. "
|
2008-03-27 21:02:15 +00:00
|
|
|
"Please check your installation."),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
2003-09-15 15:24:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-28 07:50:11 +00:00
|
|
|
tip = gimp_tip_new (_("The GIMP tips file could not be parsed!"),
|
|
|
|
"%s", error->message);
|
2003-09-15 15:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tips = g_list_prepend (tips, tip);
|
|
|
|
}
|
|
|
|
else if (error)
|
|
|
|
{
|
2004-05-10 17:36:37 +00:00
|
|
|
g_printerr ("Error while parsing '%s': %s\n",
|
2003-09-15 15:24:52 +00:00
|
|
|
filename, error->message);
|
2002-02-25 02:52:33 +00:00
|
|
|
}
|
2004-01-09 22:10:04 +00:00
|
|
|
|
2008-03-28 07:50:11 +00:00
|
|
|
g_clear_error (&error);
|
2004-01-09 22:10:04 +00:00
|
|
|
g_free (filename);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2002-02-25 02:52:33 +00:00
|
|
|
tips_count = g_list_length (tips);
|
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
config = GIMP_GUI_CONFIG (gimp->config);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
if (config->last_tip >= tips_count || config->last_tip < 0)
|
|
|
|
config->last_tip = 0;
|
|
|
|
|
|
|
|
current_tip = g_list_nth (tips, config->last_tip);
|
2002-02-25 16:48:30 +00:00
|
|
|
|
2001-04-18 16:39:34 +00:00
|
|
|
if (tips_dialog)
|
|
|
|
return tips_dialog;
|
|
|
|
|
2007-06-06 22:42:45 +00:00
|
|
|
tips_dialog = gimp_dialog_new (_("GIMP Tip of the Day"),
|
|
|
|
"gimp-tip-of-the-day",
|
|
|
|
NULL, 0, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
button = gtk_dialog_add_button (GTK_DIALOG (tips_dialog),
|
|
|
|
_("_Previous Tip"), RESPONSE_PREVIOUS);
|
|
|
|
gtk_button_set_image (GTK_BUTTON (button),
|
|
|
|
gtk_image_new_from_stock (GTK_STOCK_GO_BACK,
|
|
|
|
GTK_ICON_SIZE_BUTTON));
|
|
|
|
|
|
|
|
button = gtk_dialog_add_button (GTK_DIALOG (tips_dialog),
|
|
|
|
_("_Next Tip"), RESPONSE_NEXT);
|
|
|
|
gtk_button_set_image (GTK_BUTTON (button),
|
|
|
|
gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,
|
|
|
|
GTK_ICON_SIZE_BUTTON));
|
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (tips_dialog),
|
|
|
|
RESPONSE_NEXT, tips_count > 1);
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (tips_dialog),
|
|
|
|
RESPONSE_PREVIOUS, tips_count > 1);
|
|
|
|
|
|
|
|
g_signal_connect (tips_dialog, "response",
|
|
|
|
G_CALLBACK (tips_dialog_response),
|
2002-01-25 18:34:33 +00:00
|
|
|
NULL);
|
2003-01-05 22:07:10 +00:00
|
|
|
g_signal_connect (tips_dialog, "destroy",
|
2006-04-12 12:49:29 +00:00
|
|
|
G_CALLBACK (tips_dialog_destroy),
|
|
|
|
config);
|
2001-04-18 16:39:34 +00:00
|
|
|
|
2007-06-06 22:42:45 +00:00
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (tips_dialog)->vbox),
|
|
|
|
vbox, TRUE, TRUE, 0);
|
2001-04-18 16:39:34 +00:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2004-05-04 14:21:13 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2007-06-06 22:42:45 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
2001-04-18 16:39:34 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2008-08-04 13:56:07 +00:00
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
2001-04-18 16:39:34 +00:00
|
|
|
|
2006-06-20 18:28:06 +00:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_INFO, GTK_ICON_SIZE_DIALOG);
|
2008-08-04 13:56:07 +00:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
|
2008-03-28 07:50:11 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
|
2006-06-20 18:28:06 +00:00
|
|
|
gtk_widget_show (image);
|
2001-04-18 16:39:34 +00:00
|
|
|
|
2008-03-28 07:50:11 +00:00
|
|
|
gtk_container_set_focus_chain (GTK_CONTAINER (hbox), NULL);
|
|
|
|
|
2008-08-04 13:56:07 +00:00
|
|
|
tip_label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (tip_label), TRUE);
|
|
|
|
gtk_label_set_justify (GTK_LABEL (tip_label), GTK_JUSTIFY_LEFT);
|
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (tip_label), TRUE);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (tip_label), 0.5, 0.0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), tip_label, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (tip_label);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
more_button = gtk_link_button_new_with_label ("http://docs.gimp.org/",
|
|
|
|
_("Learn more"));
|
|
|
|
gtk_widget_show (more_button);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), more_button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
g_signal_connect (more_button, "clicked",
|
|
|
|
G_CALLBACK (more_button_clicked),
|
|
|
|
gimp);
|
|
|
|
|
2008-03-27 21:02:15 +00:00
|
|
|
tips_dialog_set_tip (current_tip->data);
|
2002-02-26 16:55:09 +00:00
|
|
|
|
2001-04-18 16:39:34 +00:00
|
|
|
return tips_dialog;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
1999-12-17 22:34:12 +00:00
|
|
|
static void
|
2008-08-04 13:56:07 +00:00
|
|
|
tips_dialog_destroy (GtkWidget *widget,
|
|
|
|
GimpGuiConfig *config)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2002-11-18 20:50:31 +00:00
|
|
|
/* the last-shown-tip is saved in sessionrc */
|
|
|
|
config->last_tip = g_list_position (tips, current_tip);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
tips_dialog = NULL;
|
2002-02-25 16:48:30 +00:00
|
|
|
current_tip = NULL;
|
2002-11-18 20:50:31 +00:00
|
|
|
|
2002-02-25 02:52:33 +00:00
|
|
|
gimp_tips_free (tips);
|
|
|
|
tips = NULL;
|
1999-12-17 22:34:12 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2007-06-06 22:42:45 +00:00
|
|
|
static void
|
|
|
|
tips_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response)
|
2004-11-12 01:36:33 +00:00
|
|
|
{
|
2007-06-06 22:42:45 +00:00
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case RESPONSE_PREVIOUS:
|
|
|
|
current_tip = current_tip->prev ? current_tip->prev : g_list_last (tips);
|
2008-03-27 21:02:15 +00:00
|
|
|
tips_dialog_set_tip (current_tip->data);
|
2007-06-06 22:42:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RESPONSE_NEXT:
|
|
|
|
current_tip = current_tip->next ? current_tip->next : tips;
|
2008-03-27 21:02:15 +00:00
|
|
|
tips_dialog_set_tip (current_tip->data);
|
2007-06-06 22:42:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
break;
|
|
|
|
}
|
2004-11-12 01:36:33 +00:00
|
|
|
}
|
|
|
|
|
1999-12-17 22:34:12 +00:00
|
|
|
static void
|
2008-03-27 21:02:15 +00:00
|
|
|
tips_dialog_set_tip (GimpTip *tip)
|
1999-12-17 22:34:12 +00:00
|
|
|
{
|
2002-02-25 16:48:30 +00:00
|
|
|
g_return_if_fail (tip != NULL);
|
2002-02-25 02:52:33 +00:00
|
|
|
|
2008-08-04 13:56:07 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (tip_label), tip->text);
|
|
|
|
|
|
|
|
/* set the URI to unset the "visited" state */
|
|
|
|
gtk_link_button_set_uri (GTK_LINK_BUTTON (more_button),
|
|
|
|
"http://docs.gimp.org/");
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (more_button, tip->help_id != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
more_button_clicked (GtkWidget *button,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpTip *tip = current_tip->data;
|
|
|
|
|
|
|
|
if (tip->help_id)
|
|
|
|
gimp_help (gimp, NULL, NULL, tip->help_id);
|
2002-02-25 16:48:30 +00:00
|
|
|
}
|