[gnome-commander] GnomeCmdFile: more C++ rework



commit 1ee137f16b11e83b08d540e886d33cccda60c499
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Thu Aug 12 19:46:32 2010 +0200

    GnomeCmdFile: more C++ rework

 src/gnome-cmd-delete-dialog.cc     |    2 +-
 src/gnome-cmd-dir.cc               |    6 ++--
 src/gnome-cmd-file-popmenu.cc      |    4 +-
 src/gnome-cmd-file-props-dialog.cc |    2 +-
 src/gnome-cmd-file.cc              |   57 +++++++++++++++---------------------
 src/gnome-cmd-file.h               |   12 ++++----
 src/tags/gnome-cmd-tags-doc.cc     |    2 +-
 src/tags/gnome-cmd-tags-exiv2.cc   |    2 +-
 src/tags/gnome-cmd-tags-file.cc    |    2 +-
 src/tags/gnome-cmd-tags-poppler.cc |    2 +-
 src/tags/gnome-cmd-tags-taglib.cc  |    2 +-
 src/utils.cc                       |   10 +++---
 12 files changed, 47 insertions(+), 56 deletions(-)
---
diff --git a/src/gnome-cmd-delete-dialog.cc b/src/gnome-cmd-delete-dialog.cc
index b30dc55..9bcf767 100644
--- a/src/gnome-cmd-delete-dialog.cc
+++ b/src/gnome-cmd-delete-dialog.cc
@@ -226,7 +226,7 @@ static gboolean update_delete_status_widgets (DeleteData *data)
                 GnomeVFSURI *uri = gnome_cmd_file_get_uri (f);
 
                 if (!gnome_vfs_uri_exists (uri))
-                    gnome_cmd_file_is_deleted (f);
+                    f->is_deleted();
             }
 
         gtk_widget_destroy (data->progwin);
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index b3841d4..12ee57c 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -275,7 +275,7 @@ GnomeCmdDir *gnome_cmd_dir_new_from_info (GnomeVFSFileInfo *info, GnomeCmdDir *p
     if (dir)
     {
         gtk_object_destroy (GTK_OBJECT (path));
-        gnome_cmd_file_update_info (GNOME_CMD_FILE (dir), info);
+        GNOME_CMD_FILE (dir)->update_info(info);
         return dir;
     }
 
@@ -306,7 +306,7 @@ GnomeCmdDir *gnome_cmd_dir_new_with_con (GnomeVFSFileInfo *info, GnomeCmdPath *p
     {
         g_free (uri_str);
         gnome_vfs_uri_unref (uri);
-        gnome_cmd_file_update_info (GNOME_CMD_FILE (dir), info);
+        GNOME_CMD_FILE (dir)->update_info(info);
         return dir;
     }
 
@@ -789,7 +789,7 @@ void gnome_cmd_dir_file_changed (GnomeCmdDir *dir, const gchar *uri_str)
 
     dir->priv->needs_mtime_update = TRUE;
 
-    gnome_cmd_file_update_info (f, info);
+    f->update_info(info);
     gnome_cmd_file_invalidate_metadata (f);
     gtk_signal_emit (GTK_OBJECT (dir), signals[FILE_CHANGED], f);
 }
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index 122e9b3..344d837 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -173,7 +173,7 @@ static void on_execute (GtkMenuItem *menu_item, GList *files)
 {
     GnomeCmdFile *f = GNOME_CMD_FILE (files->data);
 
-    gnome_cmd_file_execute (f);
+    f->execute();
 }
 
 
@@ -529,7 +529,7 @@ GtkWidget *gnome_cmd_file_popmenu_new (GnomeCmdFileList *fl)
     g_free ((gpointer) open_uiinfo[0].label);
 
     pos += 3;
-    if (gnome_cmd_file_is_executable (f) && g_list_length (files) == 1)
+    if (f->is_executable() && g_list_length (files) == 1)
         gnome_app_fill_menu (GTK_MENU_SHELL (menu), exec_uiinfo, NULL, FALSE, pos++);
 
     gnome_app_fill_menu (GTK_MENU_SHELL (menu), sep_uiinfo, NULL, FALSE, pos++);
diff --git a/src/gnome-cmd-file-props-dialog.cc b/src/gnome-cmd-file-props-dialog.cc
index 065d9b8..f4dc2e3 100644
--- a/src/gnome-cmd-file-props-dialog.cc
+++ b/src/gnome-cmd-file-props-dialog.cc
@@ -394,7 +394,7 @@ inline GtkWidget *create_properties_tab (GnomeCmdFilePropsDialogPrivate *data)
 
     add_sep (table, y++);
 
-    if (gnome_cmd_file_is_local (data->f))
+    if (data->f->is_local())
     {
         GnomeCmdDir *dir = gnome_cmd_file_get_parent_dir (data->f);
         GnomeCmdCon *con = dir ? gnome_cmd_dir_get_connection (dir) : NULL;
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 00ebb93..415adca 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -347,7 +347,7 @@ GnomeVFSResult gnome_cmd_file_rename (GnomeCmdFile *f, const gchar *new_name)
     {
         gchar *old_uri_str = gnome_cmd_file_get_uri_str (f);
 
-        gnome_cmd_file_update_info (f, new_info);
+        f->update_info(new_info);
         gnome_cmd_dir_file_renamed (get_parent_dir (f), f, old_uri_str);
         if (GNOME_CMD_IS_DIR (f))
             gnome_cmd_dir_update_path (GNOME_CMD_DIR (f));
@@ -755,7 +755,7 @@ void gnome_cmd_file_view (GnomeCmdFile *f, gint internal_viewer)
     g_return_if_fail (has_parent_dir (f));
 
     // If the file is local there is no need to download it
-    if (gnome_cmd_file_is_local (f))
+    if (f->is_local())
     {
         do_view_file (f, internal_viewer);
         return;
@@ -786,7 +786,7 @@ void gnome_cmd_file_edit (GnomeCmdFile *f)
 {
     g_return_if_fail (f != NULL);
 
-    if (!gnome_cmd_file_is_local (f))
+    if (!f->is_local())
         return;
 
     gchar *fpath = gnome_cmd_file_get_quoted_real_path (f);
@@ -816,15 +816,14 @@ void gnome_cmd_file_show_cap_paste (GnomeCmdFile *f)
 }
 
 
-void gnome_cmd_file_update_info (GnomeCmdFile *f, GnomeVFSFileInfo *info)
+void GnomeCmdFile::update_info(GnomeVFSFileInfo *info)
 {
-    g_return_if_fail (f != NULL);
     g_return_if_fail (info != NULL);
 
-    g_free (f->collate_key);
-    gnome_vfs_file_info_unref (f->info);
+    g_free (collate_key);
+    gnome_vfs_file_info_unref (this->info);
     gnome_vfs_file_info_ref (info);
-    f->info = info;
+    this->info = info;
 
     gchar *utf8_name;
 
@@ -837,64 +836,56 @@ void gnome_cmd_file_update_info (GnomeCmdFile *f, GnomeVFSFileInfo *info)
     else
         utf8_name = get_utf8 (info->name);
 
-    f->collate_key = g_utf8_collate_key_for_filename (utf8_name, -1);
+    collate_key = g_utf8_collate_key_for_filename (utf8_name, -1);
     g_free (utf8_name);
 }
 
 
-gboolean gnome_cmd_file_is_local (GnomeCmdFile *f)
+gboolean GnomeCmdFile::is_local()
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE (f), FALSE);
-
-    return gnome_cmd_dir_is_local (get_parent_dir (f));
+    return gnome_cmd_dir_is_local (get_parent_dir (this));
 }
 
 
-gboolean gnome_cmd_file_is_executable (GnomeCmdFile *f)
+gboolean GnomeCmdFile::is_executable()
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE (f), FALSE);
-
-    if (f->info->type != GNOME_VFS_FILE_TYPE_REGULAR)
+    if (info->type != GNOME_VFS_FILE_TYPE_REGULAR)
         return FALSE;
 
-    if (!gnome_cmd_file_is_local (f))
+    if (!is_local())
         return FALSE;
 
-    if (gcmd_owner.uid() == f->info->uid
-        && f->info->permissions & GNOME_VFS_PERM_USER_EXEC)
+    if (gcmd_owner.uid() == info->uid && info->permissions & GNOME_VFS_PERM_USER_EXEC)
         return TRUE;
 
-    if (gcmd_owner.gid() == f->info->gid
-        && f->info->permissions & GNOME_VFS_PERM_GROUP_EXEC)
+    if (gcmd_owner.gid() == info->gid && info->permissions & GNOME_VFS_PERM_GROUP_EXEC)
         return TRUE;
 
-    if (f->info->permissions & GNOME_VFS_PERM_OTHER_EXEC)
+    if (info->permissions & GNOME_VFS_PERM_OTHER_EXEC)
         return TRUE;
 
     return FALSE;
 }
 
 
-void gnome_cmd_file_is_deleted (GnomeCmdFile *f)
+void GnomeCmdFile::is_deleted()
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE (f));
-
-    if (has_parent_dir (f))
+    if (has_parent_dir (this))
     {
-        gchar *uri_str = gnome_cmd_file_get_uri_str (f);
-        gnome_cmd_dir_file_deleted (get_parent_dir (f), uri_str);
+        gchar *uri_str = gnome_cmd_file_get_uri_str (this);
+        gnome_cmd_dir_file_deleted (get_parent_dir (this), uri_str);
         g_free (uri_str);
     }
 }
 
 
-void gnome_cmd_file_execute (GnomeCmdFile *f)
+void GnomeCmdFile::execute()
 {
-    gchar *fpath = gnome_cmd_file_get_real_path (f);
+    gchar *fpath = gnome_cmd_file_get_real_path (this);
     gchar *dpath = g_path_get_dirname (fpath);
-    gchar *cmd = g_strdup_printf ("./%s", f->info->name);
+    gchar *cmd = g_strdup_printf ("./%s", info->name);
 
-    run_command_indir (cmd, dpath, app_needs_terminal (f));
+    run_command_indir (cmd, dpath, app_needs_terminal (this));
 
     g_free (fpath);
     g_free (dpath);
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index 86532cb..5c84b18 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -44,6 +44,12 @@ struct GnomeCmdFile
 
     char *get_collation_fname() const    {  return collate_key ? collate_key : info->name;  }
 
+    void update_info(GnomeVFSFileInfo *info);
+    gboolean is_local();
+    gboolean is_executable();
+    void is_deleted();
+    void execute();
+
     gboolean needs_update();
 
     void invalidate_tree_size();
@@ -130,12 +136,6 @@ void gnome_cmd_file_list_unref (GList *files);
 
 GnomeCmdDir *gnome_cmd_file_get_parent_dir (GnomeCmdFile *f);
 
-void gnome_cmd_file_update_info (GnomeCmdFile *f, GnomeVFSFileInfo *info);
-gboolean gnome_cmd_file_is_local (GnomeCmdFile *f);
-gboolean gnome_cmd_file_is_executable (GnomeCmdFile *f);
-void gnome_cmd_file_is_deleted (GnomeCmdFile *f);
-void gnome_cmd_file_execute (GnomeCmdFile *f);
-
 inline GnomeVFSMimeApplication *GnomeCmdFile::get_default_application()
 {
     return info->mime_type ? gnome_vfs_mime_get_default_application (info->mime_type) : NULL;
diff --git a/src/tags/gnome-cmd-tags-doc.cc b/src/tags/gnome-cmd-tags-doc.cc
index 04782eb..556d0a6 100644
--- a/src/tags/gnome-cmd-tags-doc.cc
+++ b/src/tags/gnome-cmd-tags-doc.cc
@@ -467,7 +467,7 @@ void gcmd_tags_libgsf_load_metadata(GnomeCmdFile *f)
 
     f->metadata->mark_as_accessed(TAG_DOC);
 
-    if (!gnome_cmd_file_is_local(f))  return;
+    if (!f->is_local())  return;
 
     GError *err = NULL;
     gchar *fname = gnome_cmd_file_get_real_path (f);
diff --git a/src/tags/gnome-cmd-tags-exiv2.cc b/src/tags/gnome-cmd-tags-exiv2.cc
index 9c5442b..6a738f3 100644
--- a/src/tags/gnome-cmd-tags-exiv2.cc
+++ b/src/tags/gnome-cmd-tags-exiv2.cc
@@ -382,7 +382,7 @@ void gcmd_tags_exiv2_load_metadata(GnomeCmdFile *f)
     f->metadata->mark_as_accessed(TAG_IPTC);
 #endif
 
-    if (!gnome_cmd_file_is_local(f))  return;
+    if (!f->is_local())  return;
 
     gchar *fname = gnome_cmd_file_get_real_path (f);
 
diff --git a/src/tags/gnome-cmd-tags-file.cc b/src/tags/gnome-cmd-tags-file.cc
index ab6dc64..85d168c 100644
--- a/src/tags/gnome-cmd-tags-file.cc
+++ b/src/tags/gnome-cmd-tags-file.cc
@@ -42,7 +42,7 @@ void gcmd_tags_file_load_metadata(GnomeCmdFile *f)
 
     f->metadata->mark_as_accessed(TAG_FILE);
 
-    // if (!gnome_cmd_file_is_local(f))  return;
+    // if (!f->is_local())  return;
 
     gchar *dpath = gnome_cmd_file_get_dirname(f);
 
diff --git a/src/tags/gnome-cmd-tags-poppler.cc b/src/tags/gnome-cmd-tags-poppler.cc
index 6bb3f8c..17d1ebe 100644
--- a/src/tags/gnome-cmd-tags-poppler.cc
+++ b/src/tags/gnome-cmd-tags-poppler.cc
@@ -302,7 +302,7 @@ void gcmd_tags_poppler_load_metadata(GnomeCmdFile *f)
 
     f->metadata->mark_as_accessed(TAG_PDF);
 
-    if (!gnome_cmd_file_is_local (f))  return;
+    if (!f->is_local())  return;
 
     // skip non pdf files, as pdf metatags extraction is very expensive...
     if (!strstr (f->info->mime_type, "pdf"))  return;
diff --git a/src/tags/gnome-cmd-tags-taglib.cc b/src/tags/gnome-cmd-tags-taglib.cc
index 5196405..64fc5dd 100644
--- a/src/tags/gnome-cmd-tags-taglib.cc
+++ b/src/tags/gnome-cmd-tags-taglib.cc
@@ -434,7 +434,7 @@ void gcmd_tags_taglib_load_metadata(GnomeCmdFile *finfo)
     finfo->metadata->mark_as_accessed(TAG_ID3);
     finfo->metadata->mark_as_accessed(TAG_VORBIS);
 
-    if (!gnome_cmd_file_is_local(finfo))  return;
+    if (!finfo->is_local())  return;
 
     const gchar *fname = gnome_cmd_file_get_real_path (finfo);
 
diff --git a/src/utils.cc b/src/utils.cc
index b333ff1..2ddddf0 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -517,7 +517,7 @@ void mime_exec_single (GnomeCmdFile *f)
 
     // Check if the file is a binary executable that lacks the executable bit
 
-    if (!gnome_cmd_file_is_executable (f))
+    if (!f->is_executable())
     {
         if (gnome_cmd_file_has_mime_type (f, "application/x-executable") || gnome_cmd_file_has_mime_type (f, "application/x-executable-binary"))
         {
@@ -540,11 +540,11 @@ void mime_exec_single (GnomeCmdFile *f)
 
     // If the file is executable but not a binary file, check if the user wants to exec it or open it
 
-    if (gnome_cmd_file_is_executable (f))
+    if (f->is_executable())
     {
         if (gnome_cmd_file_has_mime_type (f, "application/x-executable") || gnome_cmd_file_has_mime_type (f, "application/x-executable-binary"))
         {
-            gnome_cmd_file_execute (f);
+            f->execute();
             return;
         }
         else
@@ -560,7 +560,7 @@ void mime_exec_single (GnomeCmdFile *f)
                 if (ret != 1)
                 {
                     if (ret == 2)
-                        gnome_cmd_file_execute (f);
+                        f->execute();
                     return;
                 }
             }
@@ -578,7 +578,7 @@ void mime_exec_single (GnomeCmdFile *f)
 
     args = g_new0 (gpointer, 3);
 
-    if (gnome_cmd_file_is_local (f))
+    if (f->is_local())
     {
         args[0] = (gpointer) app;
         args[1] = (gpointer) g_strdup (gnome_cmd_file_get_real_path (f));



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