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
|
/*
* This is a plug-in for the GIMP.
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
*
* 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.
*
*/
#include "config.h"
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "imap_file.h"
#include "imap_main.h"
#include "imap_misc.h"
#include "libgimp/stdplugins-intl.h"
static void
open_cb (GtkWidget *dialog,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
gchar *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
do_file_error_dialog (_("Error opening file"), filename);
g_free (filename);
return;
}
load (filename);
g_free (filename);
}
gtk_widget_hide (dialog);
}
void
do_file_open_dialog (void)
{
static GtkWidget *dialog;
if (! dialog)
{
dialog =
gtk_file_chooser_dialog_new (_("Load Imagemap"),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (open_cb),
dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
static void
really_overwrite_cb (GtkMessageDialog *dialog,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_YES)
{
gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (data));
save_as (filename);
g_free (filename);
}
gtk_widget_destroy (GTK_WIDGET (dialog));
gtk_widget_hide (GTK_WIDGET (data));
}
static void
do_file_exists_dialog (GtkWidget *parent)
{
GtkWidget *dialog;
gchar *message;
message =
g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n"
"%s",
_("File already exists"),
_("Do you really want to overwrite?"));
dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
message);
g_free (message);
g_signal_connect (dialog, "response",
G_CALLBACK (really_overwrite_cb),
parent);
gtk_widget_show (dialog);
}
static void
save_cb (GtkWidget *dialog,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
gchar *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
do_file_exists_dialog (dialog);
g_free (filename);
return;
}
save_as (filename);
g_free (filename);
}
gtk_widget_hide (dialog);
}
void
do_file_save_as_dialog (void)
{
static GtkWidget *dialog;
if (! dialog)
{
dialog =
gtk_file_chooser_dialog_new (_("Save Imagemap"),
NULL,
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (save_cb),
dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
void
do_file_error_dialog (const char *error,
const char *filename)
{
static Alert_t *alert;
if (!alert)
alert = create_alert (GTK_STOCK_DIALOG_ERROR);
alert_set_text(alert, error, gimp_filename_to_utf8 (filename));
default_dialog_show (alert->dialog);
}
|