gnome-commander r1563 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Mon Feb 11 22:12:05 2008
New Revision: 1563
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1563&view=rev

Log:
Simplify error handling for MIME retrieving

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-app.h
   branches/gcmd-1-3/src/gnome-cmd-file-popmenu.cc
   branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc

Modified: branches/gcmd-1-3/src/gnome-cmd-app.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-app.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-app.h	Mon Feb 11 22:12:05 2008
@@ -20,6 +20,7 @@
 #ifndef __GNOME_CMD_APP_H__
 #define __GNOME_CMD_APP_H__
 
+#include "gnome-cmd-file.h"
 #include "gnome-cmd-pixmap.h"
 
 typedef enum
@@ -84,4 +85,9 @@
 
 GnomeCmdPixmap *gnome_cmd_app_get_pixmap (GnomeCmdApp *app);
 
+inline GnomeVFSMimeApplication *gnome_cmd_app_get_default_application (GnomeCmdFile *finfo)
+{
+    return finfo && finfo->info->mime_type ? gnome_vfs_mime_get_default_application (finfo->info->mime_type) : NULL;
+}
+
 #endif // __GNOME_CMD_APP_H__

Modified: branches/gcmd-1-3/src/gnome-cmd-file-popmenu.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-popmenu.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-popmenu.cc	Mon Feb 11 22:12:05 2008
@@ -92,29 +92,25 @@
     for (; files; files = files->next)
     {
         GnomeCmdFile *finfo = (GnomeCmdFile *) files->data;
+        GnomeVFSMimeApplication *vfs_app = gnome_cmd_app_get_default_application (finfo);
 
-        if (!finfo->info->mime_type)
-            gnome_cmd_show_message (NULL, finfo->info->name, "Couldn't retrieve mime type of the file.");
-        else
+        if (vfs_app)
         {
-            GnomeVFSMimeApplication *vfs_app = gnome_vfs_mime_get_default_application (finfo->info->mime_type);
+            OpenWithData *data = (OpenWithData *) g_hash_table_lookup (hash, vfs_app->id);
 
-            if (vfs_app)
+            if (!data)
             {
-                OpenWithData *data = (OpenWithData *) g_hash_table_lookup (hash, vfs_app->id);
-
-                if (!data)
-                {
-                    data = g_new0 (OpenWithData, 1);
-                    data->app = gnome_cmd_app_new_from_vfs_app (vfs_app);
-                    data->files = NULL;
-                    g_hash_table_insert (hash, vfs_app->id, data);
-                }
-
-                gnome_vfs_mime_application_free (vfs_app);
-                data->files = g_list_append (data->files, finfo);
+                data = g_new0 (OpenWithData, 1);
+                data->app = gnome_cmd_app_new_from_vfs_app (vfs_app);
+                data->files = NULL;
+                g_hash_table_insert (hash, vfs_app->id, data);
             }
+
+            gnome_vfs_mime_application_free (vfs_app);
+            data->files = g_list_append (data->files, finfo);
         }
+        else
+            gnome_cmd_show_message (NULL, finfo->info->name, "Couldn't retrieve MIME type of the file.");
     }
 
     g_hash_table_foreach (hash, (GHFunc) htcb_exec_with_app, NULL);

Modified: branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-props-dialog.cc	Mon Feb 11 22:12:05 2008
@@ -408,17 +408,12 @@
         label = create_bold_label (dialog, _("Opens with:"));
         table_add (table, label, 0, y, GTK_FILL);
 
-        if (data->finfo->info->mime_type)
-        {
-            GnomeVFSMimeApplication *vfs_app = gnome_vfs_mime_get_default_application (data->finfo->info->mime_type);
+        GnomeVFSMimeApplication *vfs_app = gnome_cmd_app_get_default_application (data->finfo);
 
-            if (vfs_app)
-            {
-                data->app_label = label = create_label (dialog, vfs_app->name);
-                gnome_vfs_mime_application_free (vfs_app);
-            }
-            else
-                label = create_label (dialog, _("No default application registered"));
+        if (vfs_app)
+        {
+            data->app_label = label = create_label (dialog, vfs_app->name);
+            gnome_vfs_mime_application_free (vfs_app);
         }
         else
             label = create_label (dialog, _("No default application registered"));



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