[niepce] Import video files to the database. File bundles are now "typed"



commit 072d3ea4c0011178871cfde1288c6f32fcdb7b14
Author: Hub Figuiere <hub figuiere net>
Date:   Sat Oct 29 11:04:52 2011 -0700

    Import video files to the database.
    File bundles are now "typed"

 src/engine/db/filebundle.cpp |   41 ++++++++++++++++++++++++++++++-----------
 src/engine/db/filebundle.hpp |   13 +++++++++++--
 src/engine/db/libfile.cpp    |    6 +++++-
 src/fwk/toolkit/mimetype.cpp |   10 +++++++---
 src/fwk/toolkit/mimetype.hpp |   42 ++++++++++++++++++++++++++----------------
 5 files changed, 79 insertions(+), 33 deletions(-)
---
diff --git a/src/engine/db/filebundle.cpp b/src/engine/db/filebundle.cpp
index 5e94047..b513623 100644
--- a/src/engine/db/filebundle.cpp
+++ b/src/engine/db/filebundle.cpp
@@ -26,34 +26,48 @@
 
 namespace eng {
 
-void 
+bool 
 FileBundle::add(const std::string & path)
 {
     // TODO make it more reliable with more tests.
-    fwk::MimeType type(path);
-    
-    if(type.isImage()) {
-        if(type.isDigicamRaw()) {
+    fwk::MimeType mime_type(path);
+    bool added = true;
+
+    if(mime_type.isImage()) {
+        if(mime_type.isDigicamRaw()) {
             if(!m_main.empty() && m_jpeg.empty()) {
                 m_jpeg = m_main;
+                m_type = LibFile::FILE_TYPE_RAW_JPEG;
+            }
+            else {
+                m_type = LibFile::FILE_TYPE_RAW;
             }
             m_main = path;
         }
         else {
             if(!m_main.empty()) {
                 m_jpeg = path;
+                m_type = LibFile::FILE_TYPE_RAW_JPEG;
             }
             else {
                 m_main = path;
+                m_type = LibFile::FILE_TYPE_IMAGE;
             }
         }
     }
-    else if(type.isXmp()) {
+    else if(mime_type.isXmp()) {
         m_xmp_sidecar = path;
     }
+    else if(mime_type.isMovie()) {
+        m_main = path;
+        m_type = LibFile::FILE_TYPE_VIDEO;
+    }
     else {
-        DBG_OUT("Unkown file %s\n", path.c_str());
+        DBG_OUT("Unkown file %s of type %s\n", path.c_str(), 
+                mime_type.string().c_str());
+        added = false;
     }
+    return added;
 }
 
 
@@ -72,11 +86,16 @@ FileBundle::filter_bundles(const fwk::FileList::Ptr & files)
         std::string basename = fwk::path_stem(*iter);
 
         if(basename != current_base) {
-            current_base = basename;
-            current_bundle = FileBundle::Ptr(new FileBundle());
-            bundles->push_back(current_bundle);
+            FileBundle::Ptr new_bundle(new FileBundle());
+            if(new_bundle->add(*iter)) {
+                bundles->push_back(new_bundle);
+                current_bundle = new_bundle;
+                current_base = basename;
+            }
+        }
+        else {
+            current_bundle->add(*iter);
         }
-        current_bundle->add(*iter);
     }
 
     return bundles;
diff --git a/src/engine/db/filebundle.hpp b/src/engine/db/filebundle.hpp
index e41be91..d241051 100644
--- a/src/engine/db/filebundle.hpp
+++ b/src/engine/db/filebundle.hpp
@@ -37,8 +37,16 @@ public:
     typedef std::list<Ptr> List;
     typedef std::tr1::shared_ptr<List> ListPtr;
 
-    /** add a file to a bundle. Will determine what type it is. */
-    void add(const std::string & path);
+    FileBundle()
+        : m_type(LibFile::FILE_TYPE_UNKNOWN)
+        { }
+    LibFile::FileType type() const
+        { return m_type; }
+
+    /** add a file to a bundle. Will determine what type it is. 
+     * @return false if it does not know about the file
+     */
+    bool add(const std::string & path);
     const std::string & main_file() const
         { return m_main; }
     const std::string & jpeg() const
@@ -48,6 +56,7 @@ public:
     
     static ListPtr filter_bundles(const fwk::FileList::Ptr & files);
 private:
+    LibFile::FileType m_type;
     std::string m_main;
     std::string m_xmp_sidecar;
     std::string m_jpeg;
diff --git a/src/engine/db/libfile.cpp b/src/engine/db/libfile.cpp
index 1a86327..bc7e201 100644
--- a/src/engine/db/libfile.cpp
+++ b/src/engine/db/libfile.cpp
@@ -91,7 +91,7 @@ void LibFile::setMetaData(int meta, int32_t v)
  * Converts a mimetype, which is expensive to calculate, into a FileType.
  * @param mime The mimetype we want to know as a filetype
  * @return the filetype
- * @todo: add the Video, JPEG+RAW file types.
+ * @todo: add the JPEG+RAW file types.
  */
 LibFile::FileType LibFile::mimetype_to_filetype(fwk::MimeType mime)
 {
@@ -103,6 +103,10 @@ LibFile::FileType LibFile::mimetype_to_filetype(fwk::MimeType mime)
     {
         return FILE_TYPE_IMAGE;
     }
+    else if(mime.isMovie())
+    {
+        return FILE_TYPE_VIDEO;
+    }
     else
     {
         return FILE_TYPE_UNKNOWN;
diff --git a/src/fwk/toolkit/mimetype.cpp b/src/fwk/toolkit/mimetype.cpp
index 0760067..457d917 100644
--- a/src/fwk/toolkit/mimetype.cpp
+++ b/src/fwk/toolkit/mimetype.cpp
@@ -62,13 +62,17 @@ bool MimeType::isDigicamRaw() const
 
 bool MimeType::isImage() const
 {
-		return Gio::content_type_is_a(m_type, "image/*");
+    return Gio::content_type_is_a(m_type, "image/*");
 }
-	
+
+bool MimeType::isMovie() const
+{
+    return Gio::content_type_is_a(m_type, "video/*");
+}	
 
 bool MimeType::isUnknown() const
 {
-		return Gio::content_type_is_unknown(m_type);
+    return Gio::content_type_is_unknown(m_type);
 }
 
 
diff --git a/src/fwk/toolkit/mimetype.hpp b/src/fwk/toolkit/mimetype.hpp
index 5d2bf71..2eef9ca 100644
--- a/src/fwk/toolkit/mimetype.hpp
+++ b/src/fwk/toolkit/mimetype.hpp
@@ -28,26 +28,36 @@
 
 namespace fwk {
 
-	class MimeType
-	{
-	public:
-		MimeType(const std::string & filename);
+class MimeType
+{
+public:
+    MimeType(const std::string & filename);
     MimeType(const Glib::RefPtr<Gio::File> & file);
-
-		bool isDigicamRaw() const;
-		bool isImage() const;
-		bool isUnknown() const;
-		bool isXmp() const;
-
-		const std::string & string() const
-			{ return m_type; }
-	private:
+    
+    bool isDigicamRaw() const;
+    bool isImage() const;
+    bool isMovie() const;
+    bool isUnknown() const;
+    bool isXmp() const;
+    
+    const std::string & string() const
+        { return m_type; }
+private:
     Glib::RefPtr<Gio::FileInfo> m_fileinfo;
     std::string m_name;
-		std::string m_type;
-	};
+    std::string m_type;
+};
 
 }
 
-
 #endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/



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