[nautilus/wip/csoriano/desktop-split: 14/53] files-view: use inheritance for scripts vars



commit 4838936120f0106d1ab947d8c2ba271a4094d264
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Mar 18 16:58:31 2016 +0100

    files-view: use inheritance for scripts vars
    
    When a script is present we set some environment variables to allow
    the scripts to work with them.
    
    For example, we set a environment variable for selected items.
    However, some views have special links, like the desktop. Therefore we
    need special treatment for those.
    
    Use inheritance instead of doing special casing in the parent class
    for this case.

 src/nautilus-desktop-canvas-view.c |   56 ++++++++++++++++++++++++++++++++++++
 src/nautilus-files-view.c          |   43 +++++++++++++--------------
 src/nautilus-files-view.h          |    6 ++++
 3 files changed, 83 insertions(+), 22 deletions(-)
---
diff --git a/src/nautilus-desktop-canvas-view.c b/src/nautilus-desktop-canvas-view.c
index 1d2e903..aaf9694 100644
--- a/src/nautilus-desktop-canvas-view.c
+++ b/src/nautilus-desktop-canvas-view.c
@@ -70,6 +70,9 @@ static char*    real_get_backing_uri                              (NautilusFiles
 static void     real_check_empty_states                           (NautilusFilesView           *view);
 static gboolean real_special_link_in_selection                    (NautilusFilesView           *view,
                                                                    GList                       *selection);
+static char *   real_get_file_paths_or_uris_as_newline_delimited_string (NautilusFilesView *view,
+                                                                         GList             *selection,
+                                                                         gboolean           get_paths);
 static void     nautilus_desktop_canvas_view_update_canvas_container_fonts  (NautilusDesktopCanvasView      
*view);
 static void     font_changed_callback                             (gpointer                callback_data);
 
@@ -296,6 +299,8 @@ nautilus_desktop_canvas_view_class_init (NautilusDesktopCanvasViewClass *class)
        vclass->end_loading = nautilus_desktop_canvas_view_end_loading;
        vclass->get_backing_uri = real_get_backing_uri;
        vclass->check_empty_states = real_check_empty_states;
+       vclass->get_file_paths_or_uris_as_newline_delimited_string = 
real_get_file_paths_or_uris_as_newline_delimited_string;
+
         vclass->special_link_in_selection = real_special_link_in_selection;
 
        g_type_class_add_private (class, sizeof (NautilusDesktopCanvasViewDetails));
@@ -622,6 +627,57 @@ real_get_backing_uri (NautilusFilesView *view)
         return uri;
 }
 
+static char *
+real_get_file_paths_or_uris_as_newline_delimited_string (NautilusFilesView *view,
+                                                         GList             *selection,
+                                                         gboolean           get_paths)
+{
+        char *path;
+        char *uri;
+        char *result;
+        NautilusDesktopLink *link;
+        GString *expanding_string;
+        GList *node;
+        GFile *location;
+
+        expanding_string = g_string_new ("");
+        for (node = selection; node != NULL; node = node->next) {
+                uri = NULL;
+                if (NAUTILUS_IS_DESKTOP_ICON_FILE (node->data)) {
+                        link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (node->data));
+                        if (link != NULL) {
+                                location = nautilus_desktop_link_get_activation_location (link);
+                                uri = g_file_get_uri (location);
+                                g_object_unref (location);
+                                g_object_unref (G_OBJECT (link));
+                        }
+                } else {
+                        uri = nautilus_file_get_uri (NAUTILUS_FILE (node->data));
+                }
+                if (uri == NULL) {
+                        continue;
+                }
+
+                if (get_paths) {
+                        path = g_filename_from_uri (uri, NULL, NULL);
+                        if (path != NULL) {
+                                g_string_append (expanding_string, path);
+                                g_free (path);
+                                g_string_append (expanding_string, "\n");
+                        }
+                } else {
+                        g_string_append (expanding_string, uri);
+                        g_string_append (expanding_string, "\n");
+                }
+                g_free (uri);
+        }
+
+        result = expanding_string->str;
+        g_string_free (expanding_string, FALSE);
+
+        return result;
+}
+
 static void
 real_update_context_menus (NautilusFilesView *view)
 {
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 2a964bd..8a22489 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -4441,32 +4441,28 @@ get_file_names_as_parameter_array (GList             *selection,
         return parameters;
 }
 
+static char*
+nautilus_files_view_get_file_paths_or_uris_as_newline_delimited_string (NautilusFilesView *view,
+                                                                        GList             *selection,
+                                                                        gboolean           get_paths)
+{
+        return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS 
(view))->get_file_paths_or_uris_as_newline_delimited_string (view, selection, get_paths);
+}
+
 static char *
-get_file_paths_or_uris_as_newline_delimited_string (GList    *selection,
-                                                    gboolean  get_paths)
+real_get_file_paths_or_uris_as_newline_delimited_string (NautilusFilesView *view,
+                                                         GList             *selection,
+                                                         gboolean           get_paths)
 {
         char *path;
         char *uri;
         char *result;
-        NautilusDesktopLink *link;
         GString *expanding_string;
         GList *node;
-        GFile *location;
 
         expanding_string = g_string_new ("");
         for (node = selection; node != NULL; node = node->next) {
-                uri = NULL;
-                if (NAUTILUS_IS_DESKTOP_ICON_FILE (node->data)) {
-                        link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (node->data));
-                        if (link != NULL) {
-                                location = nautilus_desktop_link_get_activation_location (link);
-                                uri = g_file_get_uri (location);
-                                g_object_unref (location);
-                                g_object_unref (G_OBJECT (link));
-                        }
-                } else {
-                        uri = nautilus_file_get_uri (NAUTILUS_FILE (node->data));
-                }
+                uri = nautilus_file_get_uri (NAUTILUS_FILE (node->data));
                 if (uri == NULL) {
                         continue;
                 }
@@ -4492,15 +4488,17 @@ get_file_paths_or_uris_as_newline_delimited_string (GList    *selection,
 }
 
 static char *
-get_file_paths_as_newline_delimited_string (GList *selection)
+get_file_paths_as_newline_delimited_string (NautilusFilesView *view,
+                                            GList             *selection)
 {
-        return get_file_paths_or_uris_as_newline_delimited_string (selection, TRUE);
+        return nautilus_files_view_get_file_paths_or_uris_as_newline_delimited_string (view, selection, 
TRUE);
 }
 
 static char *
-get_file_uris_as_newline_delimited_string (GList *selection)
+get_file_uris_as_newline_delimited_string (NautilusFilesView *view,
+                                           GList             *selection)
 {
-        return get_file_paths_or_uris_as_newline_delimited_string (selection, FALSE);
+        return nautilus_files_view_get_file_paths_or_uris_as_newline_delimited_string (view, selection, 
FALSE);
 }
 
 /* returns newly allocated strings for setting the environment variables */
@@ -4520,13 +4518,13 @@ get_strings_for_environment_variables (NautilusFilesView  *view,
         if (g_str_has_prefix (directory_uri, "file:") ||
             eel_uri_is_desktop (directory_uri) ||
             eel_uri_is_trash (directory_uri)) {
-                *file_paths = get_file_paths_as_newline_delimited_string (selected_files);
+                *file_paths = get_file_paths_as_newline_delimited_string (view, selected_files);
         } else {
                 *file_paths = g_strdup ("");
         }
         g_free (directory_uri);
 
-        *uris = get_file_uris_as_newline_delimited_string (selected_files);
+        *uris = get_file_uris_as_newline_delimited_string (view, selected_files);
 
         *uri = nautilus_directory_get_uri (view->details->model);
         if (eel_uri_is_desktop (*uri)) {
@@ -7979,6 +7977,7 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
         klass->update_actions_state = real_update_actions_state;
         klass->check_empty_states = real_check_empty_states;
         klass->special_link_in_selection = real_special_link_in_selection;
+        klass->get_file_paths_or_uris_as_newline_delimited_string = 
real_get_file_paths_or_uris_as_newline_delimited_string;
 
         copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
 
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index ccd0583..b979f61 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -268,6 +268,12 @@ struct NautilusFilesViewClass {
          * home and other special links. */
         gboolean       (* special_link_in_selection)   (NautilusFilesView *view,
                                                         GList             *selection);
+        /* Use this when the scripts environment vars are being set, for selected files, etc.,
+         * if the subclassed view has some special links that need conversion to
+         * normal uris */
+        char *         (* get_file_paths_or_uris_as_newline_delimited_string) (NautilusFilesView *view,
+                                                                               GList             *selection,
+                                                                               gboolean           get_paths);
 };
 
 /* GObject support */


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