home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-20  |  4.8 KB  |  173 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "config.h"
  25.  
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28.  
  29. #include "libgimp/stdplugins-intl.h"
  30. #include "libgimp/gimpui.h"
  31.  
  32. #include "imap_default_dialog.h"
  33. #include "imap_file.h"
  34. #include "imap_main.h"
  35. #include "imap_table.h"
  36.  
  37. static void
  38. open_cb(GtkWidget *widget, gpointer data)
  39. {
  40.    char *filename;
  41.    struct stat buf;
  42.    int err;
  43.  
  44.    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data));
  45.    err = stat(filename, &buf);
  46.    if (!err && (buf.st_mode & S_IFREG)) {
  47.       gtk_widget_hide((GtkWidget*) data);
  48.       load(filename);
  49.    } else {
  50.       do_file_error_dialog(_("Error opening file"), filename);
  51.    }
  52. }
  53.  
  54. void
  55. do_file_open_dialog(void)
  56. {
  57.    static GtkWidget *dialog;
  58.    if (!dialog) {
  59.       dialog = gtk_file_selection_new(_("Load Imagemap"));
  60.       gimp_dialog_set_icon (GTK_WINDOW (dialog));
  61.       gtk_signal_connect_object(
  62.      GTK_OBJECT(GTK_FILE_SELECTION(dialog)->cancel_button),
  63.      "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(dialog));
  64.       gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
  65.              "clicked", GTK_SIGNAL_FUNC(open_cb), dialog);
  66.    }
  67.    gtk_widget_show(dialog);
  68. }
  69.  
  70. static void
  71. really_overwrite(gpointer data)
  72. {
  73.    gtk_widget_hide((GtkWidget*) data);
  74.    save_as(gtk_file_selection_get_filename(GTK_FILE_SELECTION(data)));
  75. }
  76.  
  77. static void
  78. do_file_exists_dialog(gpointer data)
  79. {
  80.    static DefaultDialog_t *dialog;
  81.  
  82.    if (!dialog) {
  83.       dialog = make_default_dialog(_("File exists!"));
  84.       default_dialog_hide_apply_button(dialog);
  85.       default_dialog_set_ok_cb(dialog, really_overwrite, data);
  86.       default_dialog_set_label(
  87.      dialog,
  88.      _("File already exists.\n"
  89.      "  Do you really want to overwrite?  "));
  90.    }
  91.    default_dialog_show(dialog);
  92. }
  93.  
  94. static void
  95. save_cb(GtkWidget *widget, gpointer data)
  96. {
  97.    char *filename;
  98.    struct stat buf;
  99.    int err;
  100.  
  101.    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data));
  102.    err = stat(filename, &buf);
  103.    if (err) {
  104.       gtk_widget_hide((GtkWidget*) data);
  105.       save_as(filename);
  106.    } else {            /* File exists */
  107.       if (buf.st_mode & S_IFREG) {
  108.      do_file_exists_dialog(data);
  109.       } else {
  110.                 /* Fix me! */
  111.       }
  112.    }
  113. }
  114.  
  115. void
  116. do_file_save_as_dialog(void)
  117. {
  118.    static GtkWidget *dialog;
  119.    if (!dialog) {
  120.       dialog = gtk_file_selection_new(_("Save Imagemap"));
  121.       gimp_dialog_set_icon (GTK_WINDOW (dialog));
  122.       gtk_signal_connect_object(
  123.      GTK_OBJECT(GTK_FILE_SELECTION(dialog)->cancel_button),
  124.      "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(dialog));
  125.       gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
  126.              "clicked", GTK_SIGNAL_FUNC(save_cb), dialog);
  127.    }
  128.    gtk_widget_show(dialog);
  129. }
  130.  
  131. typedef struct {
  132.    DefaultDialog_t *dialog;
  133.    GtkWidget *error;
  134.    GtkWidget *filename;
  135. } FileErrorDialog_t;
  136.  
  137. static FileErrorDialog_t*
  138. create_file_error_dialog()
  139. {
  140.    FileErrorDialog_t *file_dialog = g_new(FileErrorDialog_t, 1);
  141.    DefaultDialog_t *dialog;
  142.    GtkWidget *table;
  143.  
  144.    file_dialog->dialog = dialog = make_default_dialog(_("Error"));
  145.    default_dialog_hide_apply_button(dialog);
  146.    default_dialog_hide_cancel_button(dialog);
  147.  
  148.    table = gtk_table_new(2, 1, FALSE);
  149.    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
  150.    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->dialog)->vbox), table, 
  151.               TRUE, TRUE, 10);
  152.    gtk_widget_show(table);
  153.  
  154.    file_dialog->error = create_label_in_table(table, 0, 0, "");
  155.    file_dialog->filename = create_label_in_table(table, 1, 0, "");
  156.  
  157.    return file_dialog;
  158. }
  159.  
  160. void
  161. do_file_error_dialog(const char *error, const char *filename)
  162. {
  163.    static FileErrorDialog_t *dialog;
  164.    
  165.    if (!dialog)
  166.       dialog = create_file_error_dialog();
  167.  
  168.    gtk_label_set_text(GTK_LABEL(dialog->error), error);
  169.    gtk_label_set_text(GTK_LABEL(dialog->filename), filename);
  170.  
  171.    default_dialog_show(dialog->dialog);
  172. }
  173.