[niepce] * src/fwk/toolkit/mimetype.{cpp,hpp}:



commit 6e42276d486204e67831cf3a1523014c2210287c
Author: Hubert Figuiere <hub figuiere net>
Date:   Thu May 7 21:52:57 2009 -0400

    	* src/fwk/toolkit/mimetype.{cpp,hpp}:
    	Fix MimeType to make it work if the file do
    	not exist.
---
 ChangeLog                    |    4 ++++
 src/fwk/toolkit/mimetype.cpp |   22 ++++++++++++++++++----
 src/fwk/toolkit/mimetype.hpp |    1 +
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 634f387..26fc798 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-05-07  Hubert Figuiere  <hub figuiere net>
 
+	* src/fwk/toolkit/mimetype.{cpp,hpp}:
+	Fix MimeType to make it work if the file do 
+	not exist.
+
 	* configure.ac: 
 	Check for gthread.
 	
diff --git a/src/fwk/toolkit/mimetype.cpp b/src/fwk/toolkit/mimetype.cpp
index 220005e..61e849f 100644
--- a/src/fwk/toolkit/mimetype.cpp
+++ b/src/fwk/toolkit/mimetype.cpp
@@ -24,20 +24,34 @@
 
 #include "config.h"
 
+#include "fwk/utils/debug.hpp"
 #include "mimetype.hpp"
 
 namespace fwk {
 
 MimeType::MimeType(const std::string & filename)
+    : m_name(filename)
 {
-    Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename);
-    m_fileinfo = file->query_info();
-		m_type = m_fileinfo->get_content_type();
+    try {
+        Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename);
+        m_fileinfo = file->query_info();
+        m_type = m_fileinfo->get_content_type();
+    }
+    catch(const Glib::Exception &e) {
+        gboolean uncertainty = false;
+        gchar *content_type = g_content_type_guess(filename.c_str(),
+                                                         NULL, 0, &uncertainty);
+        m_type = content_type;
+        
+        g_free(content_type);
+    }
 }
 
 MimeType::MimeType(const Glib::RefPtr<Gio::File> & file)
 {
+    DBG_ASSERT(file, "file can't be NULL");
     m_fileinfo = file->query_info();
+    m_name = m_fileinfo->get_name();
 		m_type = m_fileinfo->get_content_type();
 }
 
@@ -61,7 +75,7 @@ bool MimeType::isUnknown() const
 
 bool MimeType::isXmp() const
 {
-    boost::filesystem::path path = m_fileinfo->get_name();
+    boost::filesystem::path path = m_name;
     
 #if BOOST_VERSION >= 103600
     return path.extension() == ".xmp";
diff --git a/src/fwk/toolkit/mimetype.hpp b/src/fwk/toolkit/mimetype.hpp
index e34e9da..5d2bf71 100644
--- a/src/fwk/toolkit/mimetype.hpp
+++ b/src/fwk/toolkit/mimetype.hpp
@@ -43,6 +43,7 @@ namespace fwk {
 			{ return m_type; }
 	private:
     Glib::RefPtr<Gio::FileInfo> m_fileinfo;
+    std::string m_name;
 		std::string m_type;
 	};
 



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