gnome-commander r2157 - in trunk: . src src/intviewer



Author: epiotr
Date: Fri Oct  3 23:09:53 2008
New Revision: 2157
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2157&view=rev

Log:
Pass GnomeCmdFile to intviewer (instead of previous file path)

Modified:
   trunk/ChangeLog
   trunk/src/gnome-cmd-file-list.cc
   trunk/src/gnome-cmd-file.cc
   trunk/src/gnome-cmd-file.h
   trunk/src/intviewer/viewer-window.cc
   trunk/src/intviewer/viewer-window.h

Modified: trunk/src/gnome-cmd-file-list.cc
==============================================================================
--- trunk/src/gnome-cmd-file-list.cc	(original)
+++ trunk/src/gnome-cmd-file-list.cc	Fri Oct  3 23:09:53 2008
@@ -1935,8 +1935,7 @@
     if (finfo->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
         create_error_dialog (_("Not an ordinary file: %s"), finfo->info->name);
     else
-        gnome_cmd_file_view (finfo, internal_viewer!=-1 ? internal_viewer :
-                                                          gnome_cmd_data_get_use_internal_viewer ());
+        gnome_cmd_file_view (finfo, internal_viewer);
 }
 
 

Modified: trunk/src/gnome-cmd-file.cc
==============================================================================
--- trunk/src/gnome-cmd-file.cc	(original)
+++ trunk/src/gnome-cmd-file.cc	Fri Oct  3 23:09:53 2008
@@ -172,6 +172,24 @@
     return f;
 }
 
+GnomeCmdFile *gnome_cmd_file_new_from_local_path (const char *local_full_path)
+{
+    g_return_val_if_fail (local_full_path != NULL, NULL);
+
+    gchar *text_uri = gnome_vfs_get_uri_from_local_path (local_full_path);
+
+    g_return_val_if_fail (text_uri != NULL, NULL);
+
+    const GnomeVFSFileInfoOptions infoOpts = (GnomeVFSFileInfoOptions) (GNOME_VFS_FILE_INFO_FOLLOW_LINKS|GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
+    GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+    GnomeVFSResult res = gnome_vfs_get_file_info (text_uri, info, infoOpts);
+
+    g_free (text_uri);
+
+    return res == GNOME_VFS_OK ? gnome_cmd_file_new (info, NULL) : NULL;
+}
+
+
 
 void gnome_cmd_file_invalidate_metadata (GnomeCmdFile *f)
 {
@@ -687,7 +705,7 @@
 }
 
 
-static void do_view_file (const gchar *path, gint internal_viewer)
+inline void do_view_file (GnomeCmdFile *f, gint internal_viewer=-1)
 {
     if (internal_viewer==-1)
         internal_viewer = gnome_cmd_data_get_use_internal_viewer ();
@@ -695,31 +713,31 @@
     switch (internal_viewer)
     {
         case TRUE : {
-                        GViewer *viewer = (GViewer *) gviewer_window_file_view (path, NULL);
-                        gtk_widget_show (GTK_WIDGET(viewer));
-                        gdk_window_set_icon (GTK_WIDGET(viewer)->window, NULL,
+                        GtkWidget *viewer = gviewer_window_file_view (f);
+                        gtk_widget_show (viewer);
+                        gdk_window_set_icon (viewer->window, NULL,
                                              IMAGE_get_pixmap (PIXMAP_INTERNAL_VIEWER),
                                              IMAGE_get_mask (PIXMAP_INTERNAL_VIEWER));
                     }
                     break;
 
         case FALSE: {
-                        gchar *arg = g_shell_quote (path);
-                        gchar *command = g_strdup_printf (gnome_cmd_data_get_viewer (), arg);
+                        gchar *filename = gnome_cmd_file_get_quoted_name (f);
+                        gchar *command = g_strdup_printf (gnome_cmd_data_get_viewer (), filename);
                         run_command (command, FALSE);
-                        g_free (arg);
-                        g_free (command);
+                        g_free (filename);
                     }
                     break;
+
+        default: break;
     }
 }
 
 
-static void on_file_downloaded_for_view (gchar *path)
+static void on_file_downloaded_for_view (GnomeCmdFile *f)
 {
-    do_view_file (path, -1);
-
-    g_free (path);
+    do_view_file (f);
+    gnome_cmd_file_unref (f);
 }
 
 
@@ -728,26 +746,20 @@
     g_return_if_fail (f != NULL);
     g_return_if_fail (has_parent_dir (f));
 
-    gchar *path_str;
-    GnomeCmdPath *path;
-    GnomeVFSURI *src_uri, *dest_uri;
-
     // If the file is local there is no need to download it
-    if (gnome_cmd_dir_is_local (get_parent_dir (f)))
+    if (gnome_cmd_file_is_local (f))
     {
-        gchar *fpath = gnome_cmd_file_get_real_path (f);
-        do_view_file (fpath, internal_viewer);
-        g_free (fpath);
+        do_view_file (f, internal_viewer);
         return;
     }
 
     // The file is remote, let's download it to a temporary file first
-    path_str = get_temp_download_filepath (gnome_cmd_file_get_name (f));
-    if (!path_str) return;
+    gchar *path_str = get_temp_download_filepath (gnome_cmd_file_get_name (f));
+    if (!path_str)  return;
 
-    path = gnome_cmd_plain_path_new (path_str);
-    src_uri = gnome_cmd_file_get_uri (f);
-    dest_uri = gnome_cmd_con_create_uri (get_home_con (), path);
+    GnomeCmdPath *path = gnome_cmd_plain_path_new (path_str);
+    GnomeVFSURI *src_uri = gnome_cmd_file_get_uri (f);
+    GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), path);
 
     g_printerr ("Copying to: %s\n", path_str);
     gtk_object_destroy (GTK_OBJECT (path));
@@ -757,7 +769,10 @@
                                  GNOME_VFS_XFER_FOLLOW_LINKS,
                                  GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
                                  GTK_SIGNAL_FUNC (on_file_downloaded_for_view),
-                                 path_str);
+                                 gnome_cmd_file_new_from_local_path (path_str));
+
+    // FIXME: unref src_uri & dest_uri ?
+    g_free (path_str);
 }
 
 

Modified: trunk/src/gnome-cmd-file.h
==============================================================================
--- trunk/src/gnome-cmd-file.h	(original)
+++ trunk/src/gnome-cmd-file.h	Fri Oct  3 23:09:53 2008
@@ -56,6 +56,7 @@
 
 GtkType gnome_cmd_file_get_type ();
 
+GnomeCmdFile *gnome_cmd_file_new_from_local_path (const gchar *local_full_path);
 GnomeCmdFile *gnome_cmd_file_new (GnomeVFSFileInfo *info, GnomeCmdDir *dir);
 void gnome_cmd_file_setup (GnomeCmdFile *f, GnomeVFSFileInfo *info, GnomeCmdDir *dir);
 

Modified: trunk/src/intviewer/viewer-window.cc
==============================================================================
--- trunk/src/intviewer/viewer-window.cc	(original)
+++ trunk/src/intviewer/viewer-window.cc	Fri Oct  3 23:09:53 2008
@@ -91,6 +91,7 @@
 
     int current_scale_index;
 
+    GnomeCmdFile *f;
     gchar *filename;
     guint statusbar_ctx_id;
     gboolean status_bar_msg;
@@ -166,18 +167,20 @@
     public functions
     (defined in the header file)
 *****************************************/
-GtkWidget *gviewer_window_file_view (const gchar * filename, GViewerWindowSettings *initial_settings)
+
+GtkWidget *gviewer_window_file_view (GnomeCmdFile *f, GViewerWindowSettings *initial_settings)
 {
+    GViewerWindowSettings set;
+
     if (!initial_settings)
     {
-        GViewerWindowSettings set;
         gviewer_window_load_settings(&set);
         initial_settings = &set;
     }
 
     GtkWidget *w = gviewer_window_new(initial_settings);
 
-    gviewer_window_load_file(GVIEWER_WINDOW(w), filename);
+    gviewer_window_load_file (GVIEWER_WINDOW(w), f);
 
     if (initial_settings)
         gviewer_window_set_settings(GVIEWER_WINDOW(w), initial_settings);
@@ -186,18 +189,17 @@
 }
 
 
-void gviewer_window_load_file (GViewerWindow *obj, const gchar *filename)
+void gviewer_window_load_file (GViewerWindow *obj, GnomeCmdFile *f)
 {
-    g_return_if_fail (obj);
-    g_return_if_fail (filename);
+    g_return_if_fail(obj!=NULL);
+    g_return_if_fail (f!=NULL);
 
     g_free (obj->priv->filename);
 
-    obj->priv->filename = g_strdup (filename);
-
-    gviewer_load_file(obj->priv->viewer, filename);
-
-    gtk_window_set_title(GTK_WINDOW (obj), obj->priv->filename);
+    obj->priv->f = f;
+    obj->priv->filename = gnome_cmd_file_get_real_path (f);
+    gviewer_load_file (obj->priv->viewer, obj->priv->filename);
+    gtk_window_set_title (GTK_WINDOW(obj), obj->priv->filename);
 }
 
 

Modified: trunk/src/intviewer/viewer-window.h
==============================================================================
--- trunk/src/intviewer/viewer-window.h	(original)
+++ trunk/src/intviewer/viewer-window.h	Fri Oct  3 23:09:53 2008
@@ -25,6 +25,9 @@
 #ifndef __GVIEWER_WINDOW_H__
 #define __GVIEWER_WINDOW_H__
 
+#include "gnome-cmd-includes.h"
+#include "gnome-cmd-file.h"
+
 #define GVIEWER_WINDOW(obj) \
     GTK_CHECK_CAST (obj, gviewer_window_get_type (), GViewerWindow)
 #define GVIEWER_WINDOW_CLASS(clss) \
@@ -72,9 +75,9 @@
 
 GtkWidget *gviewer_window_new (GViewerWindowSettings *initial_settings);
 
-void gviewer_window_load_file (GViewerWindow *obj, const gchar *filename);
+void gviewer_window_load_file (GViewerWindow *obj, GnomeCmdFile *f);
 
-GtkWidget *gviewer_window_file_view (const gchar * filename, GViewerWindowSettings *initial_settings);
+GtkWidget *gviewer_window_file_view (GnomeCmdFile *f, GViewerWindowSettings *initial_settings=NULL);
 
 void gviewer_window_get_current_settings(GViewerWindow *obj, /* out */ GViewerWindowSettings *settings);
 void gviewer_window_set_settings(GViewerWindow *obj, /*in*/ GViewerWindowSettings *settings);



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