293 lines
9.7 KiB
C
293 lines
9.7 KiB
C
|
/*
|
||
|
* pat plug-in version 1.01
|
||
|
* Loads/exports version 1 PIKA .pat files, by Tim Newsome <drz@frody.bloke.com>
|
||
|
*
|
||
|
* PIKA - Photo and Image Kooker Application
|
||
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "config.h"
|
||
|
|
||
|
#include <libpika/pika.h>
|
||
|
#include <libpika/pikaui.h>
|
||
|
|
||
|
#include "libpika/stdplugins-intl.h"
|
||
|
|
||
|
|
||
|
#define SAVE_PROC "file-pat-save"
|
||
|
#define PLUG_IN_BINARY "file-pat"
|
||
|
|
||
|
|
||
|
typedef struct _Pat Pat;
|
||
|
typedef struct _PatClass PatClass;
|
||
|
|
||
|
struct _Pat
|
||
|
{
|
||
|
PikaPlugIn parent_instance;
|
||
|
};
|
||
|
|
||
|
struct _PatClass
|
||
|
{
|
||
|
PikaPlugInClass parent_class;
|
||
|
};
|
||
|
|
||
|
|
||
|
#define PAT_TYPE (pat_get_type ())
|
||
|
#define PAT (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PAT_TYPE, Pat))
|
||
|
|
||
|
GType pat_get_type (void) G_GNUC_CONST;
|
||
|
|
||
|
static GList * pat_query_procedures (PikaPlugIn *plug_in);
|
||
|
static PikaProcedure * pat_create_procedure (PikaPlugIn *plug_in,
|
||
|
const gchar *name);
|
||
|
|
||
|
static PikaValueArray * pat_save (PikaProcedure *procedure,
|
||
|
PikaRunMode run_mode,
|
||
|
PikaImage *image,
|
||
|
gint n_drawables,
|
||
|
PikaDrawable **drawables,
|
||
|
GFile *file,
|
||
|
const PikaValueArray *args,
|
||
|
gpointer run_data);
|
||
|
|
||
|
static gboolean save_dialog (PikaImage *image,
|
||
|
PikaProcedure *procedure,
|
||
|
GObject *config);
|
||
|
|
||
|
|
||
|
G_DEFINE_TYPE (Pat, pat, PIKA_TYPE_PLUG_IN)
|
||
|
|
||
|
PIKA_MAIN (PAT_TYPE)
|
||
|
DEFINE_STD_SET_I18N
|
||
|
|
||
|
|
||
|
static void
|
||
|
pat_class_init (PatClass *klass)
|
||
|
{
|
||
|
PikaPlugInClass *plug_in_class = PIKA_PLUG_IN_CLASS (klass);
|
||
|
|
||
|
plug_in_class->query_procedures = pat_query_procedures;
|
||
|
plug_in_class->create_procedure = pat_create_procedure;
|
||
|
plug_in_class->set_i18n = STD_SET_I18N;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pat_init (Pat *pat)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
static GList *
|
||
|
pat_query_procedures (PikaPlugIn *plug_in)
|
||
|
{
|
||
|
return g_list_append (NULL, g_strdup (SAVE_PROC));
|
||
|
}
|
||
|
|
||
|
static PikaProcedure *
|
||
|
pat_create_procedure (PikaPlugIn *plug_in,
|
||
|
const gchar *name)
|
||
|
{
|
||
|
PikaProcedure *procedure = NULL;
|
||
|
|
||
|
if (! strcmp (name, SAVE_PROC))
|
||
|
{
|
||
|
procedure = pika_save_procedure_new (plug_in, name,
|
||
|
PIKA_PDB_PROC_TYPE_PLUGIN,
|
||
|
pat_save, NULL, NULL);
|
||
|
|
||
|
pika_procedure_set_image_types (procedure, "*");
|
||
|
|
||
|
pika_procedure_set_menu_label (procedure, _("PIKA pattern"));
|
||
|
pika_procedure_set_icon_name (procedure, PIKA_ICON_PATTERN);
|
||
|
|
||
|
pika_procedure_set_documentation (procedure,
|
||
|
_("Exports PIKA pattern file (.PAT)"),
|
||
|
_("New PIKA patterns can be created "
|
||
|
"by exporting them in the "
|
||
|
"appropriate place with this plug-in."),
|
||
|
SAVE_PROC);
|
||
|
pika_procedure_set_attribution (procedure,
|
||
|
"Tim Newsome",
|
||
|
"Tim Newsome",
|
||
|
"1997");
|
||
|
|
||
|
pika_file_procedure_set_format_name (PIKA_FILE_PROCEDURE (procedure),
|
||
|
_("Pattern"));
|
||
|
pika_file_procedure_set_mime_types (PIKA_FILE_PROCEDURE (procedure),
|
||
|
"image/x-pika-pat");
|
||
|
pika_file_procedure_set_extensions (PIKA_FILE_PROCEDURE (procedure),
|
||
|
"pat");
|
||
|
pika_file_procedure_set_handles_remote (PIKA_FILE_PROCEDURE (procedure),
|
||
|
TRUE);
|
||
|
|
||
|
PIKA_PROC_ARG_STRING (procedure, "description",
|
||
|
_("_Description"),
|
||
|
_("Short description of the pattern"),
|
||
|
_("PIKA Pattern"),
|
||
|
PIKA_PARAM_READWRITE);
|
||
|
}
|
||
|
|
||
|
return procedure;
|
||
|
}
|
||
|
|
||
|
static PikaValueArray *
|
||
|
pat_save (PikaProcedure *procedure,
|
||
|
PikaRunMode run_mode,
|
||
|
PikaImage *image,
|
||
|
gint n_drawables,
|
||
|
PikaDrawable **drawables,
|
||
|
GFile *file,
|
||
|
const PikaValueArray *args,
|
||
|
gpointer run_data)
|
||
|
{
|
||
|
PikaProcedureConfig *config;
|
||
|
PikaPDBStatusType status = PIKA_PDB_SUCCESS;
|
||
|
PikaExportReturn export = PIKA_EXPORT_CANCEL;
|
||
|
gchar *description;
|
||
|
GError *error = NULL;
|
||
|
|
||
|
config = pika_procedure_create_config (procedure);
|
||
|
pika_procedure_config_begin_run (config, image, run_mode, args);
|
||
|
|
||
|
g_object_get (config,
|
||
|
"description", &description,
|
||
|
NULL);
|
||
|
|
||
|
if (! description || ! strlen (description))
|
||
|
{
|
||
|
gchar *name = g_path_get_basename (pika_file_get_utf8_name (file));
|
||
|
|
||
|
if (g_str_has_suffix (name, ".pat"))
|
||
|
name[strlen (name) - 4] = '\0';
|
||
|
|
||
|
if (strlen (name))
|
||
|
g_object_set (config,
|
||
|
"description", name,
|
||
|
NULL);
|
||
|
|
||
|
g_free (name);
|
||
|
}
|
||
|
|
||
|
g_free (description);
|
||
|
|
||
|
switch (run_mode)
|
||
|
{
|
||
|
case PIKA_RUN_INTERACTIVE:
|
||
|
case PIKA_RUN_WITH_LAST_VALS:
|
||
|
pika_ui_init (PLUG_IN_BINARY);
|
||
|
|
||
|
export = pika_export_image (&image, &n_drawables, &drawables, "PAT",
|
||
|
PIKA_EXPORT_CAN_HANDLE_GRAY |
|
||
|
PIKA_EXPORT_CAN_HANDLE_RGB |
|
||
|
PIKA_EXPORT_CAN_HANDLE_INDEXED |
|
||
|
PIKA_EXPORT_CAN_HANDLE_ALPHA);
|
||
|
|
||
|
if (export == PIKA_EXPORT_CANCEL)
|
||
|
return pika_procedure_new_return_values (procedure, PIKA_PDB_CANCEL,
|
||
|
NULL);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (run_mode == PIKA_RUN_INTERACTIVE)
|
||
|
{
|
||
|
if (! save_dialog (image, procedure, G_OBJECT (config)))
|
||
|
status = PIKA_PDB_CANCEL;
|
||
|
}
|
||
|
|
||
|
if (status == PIKA_PDB_SUCCESS)
|
||
|
{
|
||
|
PikaValueArray *save_retvals;
|
||
|
PikaValueArray *args;
|
||
|
|
||
|
g_object_get (config,
|
||
|
"description", &description,
|
||
|
NULL);
|
||
|
|
||
|
args = pika_value_array_new_from_types (NULL,
|
||
|
PIKA_TYPE_RUN_MODE, PIKA_RUN_NONINTERACTIVE,
|
||
|
PIKA_TYPE_IMAGE, image,
|
||
|
G_TYPE_INT, n_drawables,
|
||
|
PIKA_TYPE_OBJECT_ARRAY, NULL,
|
||
|
G_TYPE_FILE, file,
|
||
|
G_TYPE_STRING, description,
|
||
|
G_TYPE_NONE);
|
||
|
pika_value_set_object_array (pika_value_array_index (args, 3),
|
||
|
PIKA_TYPE_ITEM, (GObject **) drawables, n_drawables);
|
||
|
|
||
|
save_retvals = pika_pdb_run_procedure_array (pika_get_pdb (),
|
||
|
"file-pat-save-internal",
|
||
|
args);
|
||
|
pika_value_array_unref (args);
|
||
|
|
||
|
if (PIKA_VALUES_GET_ENUM (save_retvals, 0) != PIKA_PDB_SUCCESS)
|
||
|
{
|
||
|
g_set_error (&error, 0, 0,
|
||
|
"Running procedure 'file-pat-save-internal' "
|
||
|
"failed: %s",
|
||
|
pika_pdb_get_last_error (pika_get_pdb ()));
|
||
|
|
||
|
status = PIKA_PDB_EXECUTION_ERROR;
|
||
|
}
|
||
|
|
||
|
pika_value_array_unref (save_retvals);
|
||
|
}
|
||
|
|
||
|
pika_procedure_config_end_run (config, status);
|
||
|
g_object_unref (config);
|
||
|
|
||
|
if (export == PIKA_EXPORT_EXPORT)
|
||
|
{
|
||
|
pika_image_delete (image);
|
||
|
g_free (drawables);
|
||
|
}
|
||
|
|
||
|
return pika_procedure_new_return_values (procedure, status, error);
|
||
|
}
|
||
|
|
||
|
static gboolean
|
||
|
save_dialog (PikaImage *image,
|
||
|
PikaProcedure *procedure,
|
||
|
GObject *config)
|
||
|
{
|
||
|
GtkWidget *dialog;
|
||
|
GtkWidget *entry;
|
||
|
GtkWidget *real_entry;
|
||
|
gboolean run;
|
||
|
|
||
|
dialog = pika_save_procedure_dialog_new (PIKA_SAVE_PROCEDURE (procedure),
|
||
|
PIKA_PROCEDURE_CONFIG (config),
|
||
|
image);
|
||
|
|
||
|
entry = pika_procedure_dialog_get_widget (PIKA_PROCEDURE_DIALOG (dialog),
|
||
|
"description", PIKA_TYPE_LABEL_ENTRY);
|
||
|
real_entry = pika_label_entry_get_entry (PIKA_LABEL_ENTRY (entry));
|
||
|
gtk_entry_set_max_length (GTK_ENTRY (real_entry), 256);
|
||
|
gtk_entry_set_width_chars (GTK_ENTRY (real_entry), 20);
|
||
|
gtk_entry_set_activates_default (GTK_ENTRY (real_entry), TRUE);
|
||
|
|
||
|
pika_procedure_dialog_fill (PIKA_PROCEDURE_DIALOG (dialog), NULL);
|
||
|
|
||
|
gtk_widget_show (dialog);
|
||
|
|
||
|
run = pika_procedure_dialog_run (PIKA_PROCEDURE_DIALOG (dialog));
|
||
|
|
||
|
gtk_widget_destroy (dialog);
|
||
|
|
||
|
return run;
|
||
|
}
|