[gimp] app: allow core file procedure which don't return an image.



commit 5c9114aedf0f309013227fb3cf97f8619ad00395
Author: Jehan <jehan girinstud io>
Date:   Fri Apr 12 18:22:06 2019 +0200

    app: allow core file procedure which don't return an image.
    
    This is useful to be able to support file formats other than image
    formats. In particular I will use this in the next commit to support a
    "GIMP extension" format. When GIMP will open such file, it will
    install an extension (not open an image on canvas).
    
    This is an internal flag only, i.e. only usable from core GIMP. File
    formats which a plug-in can register are still only image file formats.

 app/dialogs/file-open-dialog.c          |  2 +-
 app/display/gimpdisplayshell-dnd.c      |  6 +++---
 app/file/file-open.c                    |  6 +++---
 app/plug-in/gimppluginmanager-file.c    | 13 +++++++------
 app/plug-in/gimppluginmanager-restore.c | 11 ++++++++---
 app/plug-in/gimppluginprocedure.c       |  7 +++++++
 app/plug-in/gimppluginprocedure.h       |  3 +++
 7 files changed, 32 insertions(+), 16 deletions(-)
---
diff --git a/app/dialogs/file-open-dialog.c b/app/dialogs/file-open-dialog.c
index 4377a358fb..b28c07b08c 100644
--- a/app/dialogs/file-open-dialog.c
+++ b/app/dialogs/file-open-dialog.c
@@ -219,7 +219,7 @@ file_open_dialog_open_image (GtkWidget           *dialog,
                                            G_OBJECT (gimp_widget_get_monitor (dialog)),
                                            &status, &error);
 
-  if (! image && status != GIMP_PDB_CANCEL)
+  if (! image && status != GIMP_PDB_SUCCESS && status != GIMP_PDB_CANCEL)
     {
       gimp_message (gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
                     _("Opening '%s' failed:\n\n%s"),
diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c
index bb4208d72a..dd550513e5 100644
--- a/app/display/gimpdisplayshell-dnd.c
+++ b/app/display/gimpdisplayshell-dnd.c
@@ -575,7 +575,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
 
               g_list_free (new_layers);
             }
-          else if (status != GIMP_PDB_CANCEL)
+          else if (status != GIMP_PDB_CANCEL && status != GIMP_PDB_SUCCESS)
             {
               warn = TRUE;
             }
@@ -591,7 +591,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
                                               G_OBJECT (gimp_widget_get_monitor (widget)),
                                               &status, &error);
 
-          if (! new_image && status != GIMP_PDB_CANCEL)
+          if (! new_image && status != GIMP_PDB_CANCEL && status != GIMP_PDB_SUCCESS)
             warn = TRUE;
         }
       else
@@ -607,7 +607,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
             {
               g_object_ref (image);
             }
-          else if (status != GIMP_PDB_CANCEL)
+          else if (status != GIMP_PDB_CANCEL && status != GIMP_PDB_SUCCESS)
             {
               warn = TRUE;
             }
diff --git a/app/file/file-open.c b/app/file/file-open.c
index fcb7fc3d5f..99f72157eb 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -224,7 +224,7 @@ file_open_image (Gimp                *gimp,
 
   *status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
 
-  if (*status == GIMP_PDB_SUCCESS)
+  if (*status == GIMP_PDB_SUCCESS && ! file_proc->generic_file_proc)
     image = gimp_value_get_image (gimp_value_array_index (return_vals, 1),
                                   gimp);
 
@@ -250,7 +250,7 @@ file_open_image (Gimp                *gimp,
           if (mime_type)
             *mime_type = g_slist_nth_data (file_proc->mime_types_list, 0);
         }
-      else
+      else if (! file_proc->generic_file_proc)
         {
           if (error && ! *error)
             g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
@@ -709,7 +709,7 @@ file_open_from_command_line (Gimp     *gimp,
                               g_object_ref (file),
                               (GDestroyNotify) g_object_unref);
     }
-  else if (status != GIMP_PDB_CANCEL && display)
+  else if (status != GIMP_PDB_SUCCESS && status != GIMP_PDB_CANCEL && display)
     {
       gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
                     _("Opening '%s' failed: %s"),
diff --git a/app/plug-in/gimppluginmanager-file.c b/app/plug-in/gimppluginmanager-file.c
index 4da5e55049..e9524478d3 100644
--- a/app/plug-in/gimppluginmanager-file.c
+++ b/app/plug-in/gimppluginmanager-file.c
@@ -74,12 +74,13 @@ gimp_plug_in_manager_register_load_handler (GimpPlugInManager *manager,
 
   procedure = GIMP_PROCEDURE (file_proc);
 
-  if ((procedure->num_args   < 3)                        ||
-      (procedure->num_values < 1)                        ||
-      ! GIMP_IS_PARAM_SPEC_INT32    (procedure->args[0]) ||
-      ! G_IS_PARAM_SPEC_STRING      (procedure->args[1]) ||
-      ! G_IS_PARAM_SPEC_STRING      (procedure->args[2]) ||
-      ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->values[0]))
+  if (((procedure->num_args   < 3)                        ||
+       (procedure->num_values < 1)                        ||
+       ! GIMP_IS_PARAM_SPEC_INT32    (procedure->args[0]) ||
+       ! G_IS_PARAM_SPEC_STRING      (procedure->args[1]) ||
+       ! G_IS_PARAM_SPEC_STRING      (procedure->args[2]) ||
+       (! file_proc->generic_file_proc &&
+        ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->values[0]))))
     {
       gimp_message (manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                     "load handler \"%s\" does not take the standard "
diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c
index 846d86019b..6476aff2cc 100644
--- a/app/plug-in/gimppluginmanager-restore.c
+++ b/app/plug-in/gimppluginmanager-restore.c
@@ -1022,9 +1022,6 @@ gimp_plug_in_manager_sort_file_procs (GimpPlugInManager *manager)
       g_free (path);
     }
 
-  /* finally, remove all raw loaders except the configured one from
-   * the list of load_procs
-   */
   list = manager->load_procs;
   while (list)
     {
@@ -1032,6 +1029,9 @@ gimp_plug_in_manager_sort_file_procs (GimpPlugInManager *manager)
 
       list = g_slist_next (list);
 
+      /* finally, remove all raw loaders except the configured one from
+       * the list of load_procs
+       */
       if (file_proc->handles_raw &&
           ! g_file_equal (gimp_plug_in_procedure_get_file (file_proc),
                           raw_plug_in))
@@ -1041,6 +1041,11 @@ gimp_plug_in_manager_sort_file_procs (GimpPlugInManager *manager)
           manager->display_load_procs =
             g_slist_remove (manager->display_load_procs, file_proc);
         }
+      /* Remove generic (non-image) loaders from the display loader
+       * list. */
+     if (file_proc->generic_file_proc)
+          manager->display_load_procs =
+            g_slist_remove (manager->display_load_procs, file_proc);
     }
 }
 
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 6761d39773..33a0dab2e2 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -1162,6 +1162,13 @@ gimp_plug_in_procedure_set_file_proc (GimpPlugInProcedure *proc,
   proc->magics_list = extensions_parse (proc->magics);
 }
 
+void
+gimp_plug_in_procedure_set_generic_file_proc (GimpPlugInProcedure *proc,
+                                              gboolean             is_generic_file_proc)
+{
+  proc->generic_file_proc = is_generic_file_proc;
+}
+
 void
 gimp_plug_in_procedure_set_priority (GimpPlugInProcedure *proc,
                                      gint                 priority)
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index e462040830..3b815a1f8f 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -57,6 +57,7 @@ struct _GimpPlugInProcedure
 
   /*  file proc specific members  */
   gboolean             file_proc;
+  gboolean             generic_file_proc; /* not returning an image. */
   gchar               *extensions;
   gchar               *prefixes;
   gchar               *magics;
@@ -121,6 +122,8 @@ void          gimp_plug_in_procedure_set_file_proc     (GimpPlugInProcedure *pro
                                                         const gchar         *extensions,
                                                         const gchar         *prefixes,
                                                         const gchar         *magics);
+void      gimp_plug_in_procedure_set_generic_file_proc (GimpPlugInProcedure *proc,
+                                                        gboolean             is_generic_file_proc);
 void          gimp_plug_in_procedure_set_priority      (GimpPlugInProcedure *proc,
                                                         gint                 priority);
 void          gimp_plug_in_procedure_set_mime_types    (GimpPlugInProcedure *proc,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]