gimp/app/widgets/gimpfileprocview.c

323 lines
8.9 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpfileprocview.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <gegl.h>
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpmarshal.h"
#include "plug-in/gimppluginprocedure.h"
app/plug-in/Makefile.am app/plug-in/plug-in-types.h new object which keeps 2006-04-29 Michael Natterer <mitch@gimp.org> * app/plug-in/Makefile.am * app/plug-in/plug-in-types.h * app/plug-in/gimppluginmanager.[ch]: new object which keeps all plug-in related stuff that was kept in the Gimp instance. Has "menu-branch-added" and "last-plug-in-changed" signals. * app/plug-in/plug-ins.[ch]: removed, all its functions are in GimpPlugInManager now. * app/core/gimpmarshal.list: new marshaller for the new object. * app/core/gimp.[ch]: removed all plug-in related stuff and keep a GimpPlugInManager around. * app/plug-in/plug-in-data.[ch] * app/plug-in/plug-in-file.[ch] * app/plug-in/plug-in-help-domain.[ch] * app/plug-in/plug-in-locale-domain.[ch] * app/plug-in/plug-in-menu-branch.[ch] * app/plug-in/plug-ins-query.[ch]: removed... * app/plug-in/gimppluginmanager-data.[ch] * app/plug-in/gimppluginmanager-file.[ch] * app/plug-in/gimppluginmanager-help-domain.[ch] * app/plug-in/gimppluginmanager-locale-domain.[ch] * app/plug-in/gimppluginmanager-menu-branch.[ch] * app/plug-in/gimppluginmanager-query.[ch]: ...and added as methods of GimpPlugInManager. * app/plug-in/plug-in-debug.[ch] * app/plug-in/plug-in-shm.[ch]: removed... * app/plug-in/gimpplugindebug.[ch] * app/plug-in/gimppluginshm.[ch]: ...and added as properly namespeced structs with constructors and destructors. * app/core/Makefile.am * app/core/gimpenvirontable.[ch] * app/core/gimpinterpreterdb.[ch]: removed... * app/plug-in/gimpenvirontable.[ch] * app/plug-in/gimpinterpreterdb.[ch]: ...and added here unchanged. * app/core/gimp-gui.[ch] * app/gui/gui-vtable.c: remove gimp_menus_create_branch() and all related stuff. * app/actions/plug-in-actions.[ch]: connect to the plug-in-manager's "menu-path-added" signal and create menu branch actions accordingly. * app/plug-in/plug-in-context.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in-progress.c * app/plug-in/plug-in-run.[ch] * app/plug-in/plug-in.[ch] * app/app_procs.c * app/actions/file-commands.c * app/actions/plug-in-commands.c * app/core/gimpimage.c * app/dialogs/file-open-location-dialog.c * app/dialogs/file-save-dialog.c * app/file/file-open.c * app/gui/gui.c * app/menus/plug-in-menus.c * app/pdb/gimppluginprocedure.c * app/pdb/gimptemporaryprocedure.c * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.c * app/widgets/gimpfileprocview.c * app/widgets/gimphelp.c * app/widgets/gimpthumbbox.c * app/xcf/xcf.c * tools/pdbgen/pdb/context.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/message.pdb * tools/pdbgen/pdb/plug_in.pdb * tools/pdbgen/pdb/procedural_db.pdb * tools/pdbgen/pdb/progress.pdb * tools/pdbgen/pdb/undo.pdb: follow above refactoring. * app/pdb/context_cmds.c * app/pdb/drawable_cmds.c * app/pdb/fileops_cmds.c * app/pdb/help_cmds.c * app/pdb/message_cmds.c * app/pdb/plug_in_cmds.c * app/pdb/procedural_db_cmds.c * app/pdb/progress_cmds.c * app/pdb/undo_cmds.c: regenerated.
2006-04-29 06:26:51 +08:00
#include "gimpfileprocview.h"
#include "gimp-intl.h"
enum
{
COLUMN_PROC,
COLUMN_LABEL,
COLUMN_EXTENSIONS,
COLUMN_HELP_ID,
N_COLUMNS
};
enum
{
CHANGED,
LAST_SIGNAL
};
static void gimp_file_proc_view_finalize (GObject *object);
static void gimp_file_proc_view_selection_changed (GtkTreeSelection *selection,
GimpFileProcView *view);
G_DEFINE_TYPE (GimpFileProcView, gimp_file_proc_view, GTK_TYPE_TREE_VIEW)
#define parent_class gimp_file_proc_view_parent_class
static guint view_signals[LAST_SIGNAL] = { 0 };
static void
gimp_file_proc_view_class_init (GimpFileProcViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_file_proc_view_finalize;
klass->changed = NULL;
view_signals[CHANGED] = g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpFileProcViewClass,
changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
gimp_file_proc_view_init (GimpFileProcView *view)
{
}
static void
gimp_file_proc_view_finalize (GObject *object)
{
GimpFileProcView *view = GIMP_FILE_PROC_VIEW (object);
if (view->meta_extensions)
{
g_list_free_full (view->meta_extensions, (GDestroyNotify) g_free);
view->meta_extensions = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GtkWidget *
gimp_file_proc_view_new (Gimp *gimp,
GSList *procedures,
const gchar *automatic,
const gchar *automatic_help_id)
{
GtkTreeView *view;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
GtkListStore *store;
GSList *list;
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
store = gtk_list_store_new (N_COLUMNS,
GIMP_TYPE_PLUG_IN_PROCEDURE, /* COLUMN_PROC */
G_TYPE_STRING, /* COLUMN_LABEL */
G_TYPE_STRING, /* COLUMN_EXTENSIONS */
G_TYPE_STRING); /* COLUMN_HELP_ID */
view = g_object_new (GIMP_TYPE_FILE_PROC_VIEW,
"model", store,
"rules-hint", TRUE,
NULL);
g_object_unref (store);
for (list = procedures; list; list = g_slist_next (list))
{
app/plug-in/plug-in-types.h renamed to GimpPlugInProcedure and made a 2006-04-05 Michael Natterer <mitch@gimp.org> * app/plug-in/plug-in-types.h * app/plug-in/plug-in-proc-def.[ch]: renamed to GimpPlugInProcedure and made a GObject derived from GimpProcedure (instead of having a pointer to a GimpProcedure). Added image_types and file_magic utility functions taken from plug-ins.[ch]. Still lives in the same crappy files because I am undecided where to put it... * app/pdb/gimpprocedure.c (gimp_procedure_real_execute): removed switch() statement and always call the internal marshaller because GimpProcedure::execute() is properly overridden by GimpPlugInProcedure now. * app/plug-in/plug-ins.[ch]: removed the mime_type and file_magic utilities added to GimpPlugInProcedure. * app/actions/file-commands.c * app/actions/plug-in-actions.[ch] * app/actions/plug-in-commands.[ch] * app/core/gimp-gui.[ch] * app/core/gimp.[ch] * app/core/gimpimage.[ch] * app/dialogs/file-open-dialog.c * app/dialogs/file-save-dialog.c * app/dialogs/print-size-dialog.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch] * app/gui/gui-vtable.c * app/menus/plug-in-menus.[ch] * app/plug-in/plug-in-def.[ch] * app/plug-in/plug-in-message.c * app/plug-in/plug-in-rc.c * app/plug-in/plug-in-run.c * app/plug-in/plug-in.c * app/plug-in/plug-ins-query.c * app/widgets/gimpactiongroup.[ch] * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpfileprocview.[ch] * app/widgets/gimppluginaction.[ch] * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/plug_in.pdb: changed addordingly. * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
2006-04-05 16:38:33 +08:00
GimpPlugInProcedure *proc = list->data;
if (! proc->prefixes_list) /* skip URL loaders */
{
const gchar *label = gimp_procedure_get_label (GIMP_PROCEDURE (proc));
const gchar *help_id = gimp_procedure_get_help_id (GIMP_PROCEDURE (proc));
GSList *list2;
if (label)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_PROC, proc,
COLUMN_LABEL, label,
COLUMN_EXTENSIONS, proc->extensions,
COLUMN_HELP_ID, help_id,
-1);
}
for (list2 = proc->extensions_list;
list2;
list2 = g_slist_next (list2))
{
GimpFileProcView *proc_view = GIMP_FILE_PROC_VIEW (view);
const gchar *ext = list2->data;
const gchar *dot = strchr (ext, '.');
if (dot && dot != ext)
proc_view->meta_extensions =
g_list_append (proc_view->meta_extensions,
g_strdup (dot + 1));
}
}
}
if (automatic)
{
gtk_list_store_prepend (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_PROC, NULL,
COLUMN_LABEL, automatic,
COLUMN_HELP_ID, automatic_help_id,
-1);
}
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("File Type"));
gtk_tree_view_column_set_expand (column, TRUE);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"text", COLUMN_LABEL,
NULL);
gtk_tree_view_append_column (view, column);
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Extensions"));
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"text", COLUMN_EXTENSIONS,
NULL);
gtk_tree_view_append_column (view, column);
g_signal_connect (gtk_tree_view_get_selection (view), "changed",
G_CALLBACK (gimp_file_proc_view_selection_changed),
view);
return GTK_WIDGET (view);
}
app/plug-in/plug-in-types.h renamed to GimpPlugInProcedure and made a 2006-04-05 Michael Natterer <mitch@gimp.org> * app/plug-in/plug-in-types.h * app/plug-in/plug-in-proc-def.[ch]: renamed to GimpPlugInProcedure and made a GObject derived from GimpProcedure (instead of having a pointer to a GimpProcedure). Added image_types and file_magic utility functions taken from plug-ins.[ch]. Still lives in the same crappy files because I am undecided where to put it... * app/pdb/gimpprocedure.c (gimp_procedure_real_execute): removed switch() statement and always call the internal marshaller because GimpProcedure::execute() is properly overridden by GimpPlugInProcedure now. * app/plug-in/plug-ins.[ch]: removed the mime_type and file_magic utilities added to GimpPlugInProcedure. * app/actions/file-commands.c * app/actions/plug-in-actions.[ch] * app/actions/plug-in-commands.[ch] * app/core/gimp-gui.[ch] * app/core/gimp.[ch] * app/core/gimpimage.[ch] * app/dialogs/file-open-dialog.c * app/dialogs/file-save-dialog.c * app/dialogs/print-size-dialog.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch] * app/gui/gui-vtable.c * app/menus/plug-in-menus.[ch] * app/plug-in/plug-in-def.[ch] * app/plug-in/plug-in-message.c * app/plug-in/plug-in-rc.c * app/plug-in/plug-in-run.c * app/plug-in/plug-in.c * app/plug-in/plug-ins-query.c * app/widgets/gimpactiongroup.[ch] * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpfileprocview.[ch] * app/widgets/gimppluginaction.[ch] * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/plug_in.pdb: changed addordingly. * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
2006-04-05 16:38:33 +08:00
GimpPlugInProcedure *
gimp_file_proc_view_get_proc (GimpFileProcView *view,
gchar **label)
{
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_FILE_PROC_VIEW (view), NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
app/plug-in/plug-in-types.h renamed to GimpPlugInProcedure and made a 2006-04-05 Michael Natterer <mitch@gimp.org> * app/plug-in/plug-in-types.h * app/plug-in/plug-in-proc-def.[ch]: renamed to GimpPlugInProcedure and made a GObject derived from GimpProcedure (instead of having a pointer to a GimpProcedure). Added image_types and file_magic utility functions taken from plug-ins.[ch]. Still lives in the same crappy files because I am undecided where to put it... * app/pdb/gimpprocedure.c (gimp_procedure_real_execute): removed switch() statement and always call the internal marshaller because GimpProcedure::execute() is properly overridden by GimpPlugInProcedure now. * app/plug-in/plug-ins.[ch]: removed the mime_type and file_magic utilities added to GimpPlugInProcedure. * app/actions/file-commands.c * app/actions/plug-in-actions.[ch] * app/actions/plug-in-commands.[ch] * app/core/gimp-gui.[ch] * app/core/gimp.[ch] * app/core/gimpimage.[ch] * app/dialogs/file-open-dialog.c * app/dialogs/file-save-dialog.c * app/dialogs/print-size-dialog.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch] * app/gui/gui-vtable.c * app/menus/plug-in-menus.[ch] * app/plug-in/plug-in-def.[ch] * app/plug-in/plug-in-message.c * app/plug-in/plug-in-rc.c * app/plug-in/plug-in-run.c * app/plug-in/plug-in.c * app/plug-in/plug-ins-query.c * app/widgets/gimpactiongroup.[ch] * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpfileprocview.[ch] * app/widgets/gimppluginaction.[ch] * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/plug_in.pdb: changed addordingly. * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
2006-04-05 16:38:33 +08:00
GimpPlugInProcedure *proc;
if (label)
gtk_tree_model_get (model, &iter,
COLUMN_PROC, &proc,
COLUMN_LABEL, label,
-1);
else
gtk_tree_model_get (model, &iter,
COLUMN_PROC, &proc,
-1);
if (proc)
g_object_unref (proc);
return proc;
}
if (label)
*label = NULL;
return NULL;
}
gboolean
app/plug-in/plug-in-types.h renamed to GimpPlugInProcedure and made a 2006-04-05 Michael Natterer <mitch@gimp.org> * app/plug-in/plug-in-types.h * app/plug-in/plug-in-proc-def.[ch]: renamed to GimpPlugInProcedure and made a GObject derived from GimpProcedure (instead of having a pointer to a GimpProcedure). Added image_types and file_magic utility functions taken from plug-ins.[ch]. Still lives in the same crappy files because I am undecided where to put it... * app/pdb/gimpprocedure.c (gimp_procedure_real_execute): removed switch() statement and always call the internal marshaller because GimpProcedure::execute() is properly overridden by GimpPlugInProcedure now. * app/plug-in/plug-ins.[ch]: removed the mime_type and file_magic utilities added to GimpPlugInProcedure. * app/actions/file-commands.c * app/actions/plug-in-actions.[ch] * app/actions/plug-in-commands.[ch] * app/core/gimp-gui.[ch] * app/core/gimp.[ch] * app/core/gimpimage.[ch] * app/dialogs/file-open-dialog.c * app/dialogs/file-save-dialog.c * app/dialogs/print-size-dialog.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch] * app/gui/gui-vtable.c * app/menus/plug-in-menus.[ch] * app/plug-in/plug-in-def.[ch] * app/plug-in/plug-in-message.c * app/plug-in/plug-in-rc.c * app/plug-in/plug-in-run.c * app/plug-in/plug-in.c * app/plug-in/plug-ins-query.c * app/widgets/gimpactiongroup.[ch] * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpfileprocview.[ch] * app/widgets/gimppluginaction.[ch] * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/plug_in.pdb: changed addordingly. * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
2006-04-05 16:38:33 +08:00
gimp_file_proc_view_set_proc (GimpFileProcView *view,
GimpPlugInProcedure *proc)
{
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
g_return_val_if_fail (GIMP_IS_FILE_PROC_VIEW (view), FALSE);
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
app/plug-in/plug-in-types.h renamed to GimpPlugInProcedure and made a 2006-04-05 Michael Natterer <mitch@gimp.org> * app/plug-in/plug-in-types.h * app/plug-in/plug-in-proc-def.[ch]: renamed to GimpPlugInProcedure and made a GObject derived from GimpProcedure (instead of having a pointer to a GimpProcedure). Added image_types and file_magic utility functions taken from plug-ins.[ch]. Still lives in the same crappy files because I am undecided where to put it... * app/pdb/gimpprocedure.c (gimp_procedure_real_execute): removed switch() statement and always call the internal marshaller because GimpProcedure::execute() is properly overridden by GimpPlugInProcedure now. * app/plug-in/plug-ins.[ch]: removed the mime_type and file_magic utilities added to GimpPlugInProcedure. * app/actions/file-commands.c * app/actions/plug-in-actions.[ch] * app/actions/plug-in-commands.[ch] * app/core/gimp-gui.[ch] * app/core/gimp.[ch] * app/core/gimpimage.[ch] * app/dialogs/file-open-dialog.c * app/dialogs/file-save-dialog.c * app/dialogs/print-size-dialog.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch] * app/gui/gui-vtable.c * app/menus/plug-in-menus.[ch] * app/plug-in/plug-in-def.[ch] * app/plug-in/plug-in-message.c * app/plug-in/plug-in-rc.c * app/plug-in/plug-in-run.c * app/plug-in/plug-in.c * app/plug-in/plug-ins-query.c * app/widgets/gimpactiongroup.[ch] * app/widgets/gimpdnd-xds.c * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpfileprocview.[ch] * app/widgets/gimppluginaction.[ch] * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/plug_in.pdb: changed addordingly. * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
2006-04-05 16:38:33 +08:00
GimpPlugInProcedure *this;
gtk_tree_model_get (model, &iter,
COLUMN_PROC, &this,
-1);
if (this)
g_object_unref (this);
if (this == proc)
break;
}
if (iter_valid)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
gtk_tree_selection_select_iter (selection, &iter);
}
return iter_valid;
}
gchar *
gimp_file_proc_view_get_help_id (GimpFileProcView *view)
{
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_FILE_PROC_VIEW (view), NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gchar *help_id;
gtk_tree_model_get (model, &iter,
COLUMN_HELP_ID, &help_id,
-1);
return help_id;
}
return NULL;
}
static void
gimp_file_proc_view_selection_changed (GtkTreeSelection *selection,
GimpFileProcView *view)
{
g_signal_emit (view, view_signals[CHANGED], 0);
}