imap_file.c 5.03 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1
/*
2
 * This is a plug-in for GIMP.
Sven Neumann's avatar
Sven Neumann committed
3 4 5
 *
 * Generates clickable image maps.
 *
6
 * Copyright (C) 1998-2005 Maurits Rijk  m.rijk@chello.nl
Sven Neumann's avatar
Sven Neumann committed
7
 *
8
 * This program is free software: you can redistribute it and/or modify
Sven Neumann's avatar
Sven Neumann committed
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
Sven Neumann's avatar
Sven Neumann committed
11 12 13 14 15 16 17 18
 * (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
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
20 21 22
 *
 */

23 24
#include "config.h"

25 26
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
27

Sven Neumann's avatar
Sven Neumann committed
28 29 30
#include "imap_file.h"
#include "imap_main.h"

31 32 33
#include "libgimp/stdplugins-intl.h"


Sven Neumann's avatar
Sven Neumann committed
34
static void
35 36 37
open_cb (GtkWidget *dialog,
         gint       response_id,
         gpointer   data)
Sven Neumann's avatar
Sven Neumann committed
38
{
39 40
  if (response_id == GTK_RESPONSE_OK)
    {
41
      gchar *filename;
42

43
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
44 45 46 47

      if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
        {
          do_file_error_dialog (_("Error opening file"), filename);
48
          g_free (filename);
49 50 51 52
          return;
        }

      load (filename);
53
      g_free (filename);
54 55
    }

56
  gtk_widget_hide (dialog);
Sven Neumann's avatar
Sven Neumann committed
57 58 59
}

void
60
do_file_open_dialog (void)
Sven Neumann's avatar
Sven Neumann committed
61
{
62
  static GtkWidget *dialog;
63

64 65 66
  if (! dialog)
    {
      dialog =
67
        gtk_file_chooser_dialog_new (_("Load Image Map"),
68 69 70
                                     NULL,
                                     GTK_FILE_CHOOSER_ACTION_OPEN,

71 72
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Open"),   GTK_RESPONSE_OK,
73 74 75

                                     NULL);

76
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
77 78 79 80 81
      gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                               GTK_RESPONSE_OK,
                                               GTK_RESPONSE_CANCEL,
                                               -1);

82 83 84 85 86 87
      g_signal_connect (dialog, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &dialog);
      g_signal_connect (dialog, "response",
                        G_CALLBACK (open_cb),
                        dialog);
88
    }
89

90
  gtk_window_present (GTK_WINDOW (dialog));
Sven Neumann's avatar
Sven Neumann committed
91 92 93
}

static void
94 95 96
save_cb (GtkWidget *dialog,
         gint       response_id,
         gpointer   data)
Sven Neumann's avatar
Sven Neumann committed
97
{
98 99
  if (response_id == GTK_RESPONSE_OK)
    {
100 101 102 103
      gchar *filename;

      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

104
      save_as (filename);
105
      g_free (filename);
106 107
    }

108
  gtk_widget_hide (dialog);
Sven Neumann's avatar
Sven Neumann committed
109 110 111
}

void
112
do_file_save_as_dialog (void)
Sven Neumann's avatar
Sven Neumann committed
113
{
114
  static GtkWidget *dialog;
115

116 117
  if (! dialog)
    {
118 119
      gchar *filename;

120 121 122
      dialog = gtk_file_chooser_dialog_new (_("Save Image Map"),
                                            NULL,
                                            GTK_FILE_CHOOSER_ACTION_SAVE,
123

124 125
                                            _("_Cancel"), GTK_RESPONSE_CANCEL,
                                            _("_Save"),   GTK_RESPONSE_OK,
126

127
                                            NULL);
128

129
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
130 131 132 133
      gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                               GTK_RESPONSE_OK,
                                               GTK_RESPONSE_CANCEL,
                                               -1);
134

135 136 137
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
                                                      TRUE);

138 139 140 141 142 143
      g_signal_connect (dialog, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &dialog);
      g_signal_connect (dialog, "response",
                        G_CALLBACK (save_cb),
                        dialog);
144 145 146 147 148 149 150 151 152 153 154 155

      /*  Suggest a filename based on the image name.
       *  The image name is in UTF-8 encoding.
       */
      filename = g_strconcat (get_image_name(), ".map", NULL);

      if (filename)
        {
          gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
                                             filename);
          g_free (filename);
        }
156
    }
157

158
  gtk_window_present (GTK_WINDOW (dialog));
Sven Neumann's avatar
Sven Neumann committed
159 160 161
}

void
162 163
do_file_error_dialog (const char *error,
                      const char *filename)
Sven Neumann's avatar
Sven Neumann committed
164
{
165 166
   GtkWidget *dialog;

167
   dialog = gtk_message_dialog_new_with_markup
168 169 170 171 172 173 174 175 176
     (NULL,
      GTK_DIALOG_DESTROY_WITH_PARENT,
      GTK_MESSAGE_ERROR,
      GTK_BUTTONS_CLOSE,
      "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
      error,
      gimp_filename_to_utf8 (filename));

   g_signal_connect_swapped (dialog, "response",
177 178
                             G_CALLBACK (gtk_widget_destroy),
                             dialog);
179
   gtk_dialog_run (GTK_DIALOG (dialog));
Sven Neumann's avatar
Sven Neumann committed
180
}