[niepce: 10/12] library: add a single file import command to the libraryclient.



commit f88974ac932908013c9fa780e35f7995a714fe92
Author: Hubert Figuière <hub figuiere net>
Date:   Wed Oct 21 08:56:23 2015 -0400

    library: add a single file import command to the libraryclient.

 src/engine/library/commands.cpp     |   33 +++++++++++++++++++++++++++++----
 src/engine/library/commands.hpp     |    5 ++++-
 src/libraryclient/clientimpl.cpp    |    7 ++++++-
 src/libraryclient/clientimpl.hpp    |    3 ++-
 src/libraryclient/libraryclient.cpp |    7 ++++++-
 src/libraryclient/libraryclient.hpp |   10 ++++++++--
 6 files changed, 55 insertions(+), 10 deletions(-)
---
diff --git a/src/engine/library/commands.cpp b/src/engine/library/commands.cpp
index bc8a38b..4fd8e17 100644
--- a/src/engine/library/commands.cpp
+++ b/src/engine/library/commands.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - library/commands.cpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 #include <boost/any.hpp>
 
 #include "fwk/base/debug.hpp"
+#include "fwk/utils/pathutils.hpp"
 #include "engine/db/library.hpp"
 #include "engine/db/libfolder.hpp"
 #include "engine/db/libfile.hpp"
@@ -54,7 +55,32 @@ void Commands::cmdListAllFolders(const Library::Ptr & lib)
     // notify folder added l
     lib->notify(Library::NotifyType::ADDED_FOLDERS, boost::any(l));
 }
-       
+
+void Commands::cmdImportFile(const Library::Ptr & lib,
+                              const std::string & file_path,
+                              bool manage)
+{
+    DBG_ASSERT(!manage, "managing file is currently unsupported");
+
+    FileBundle::Ptr bundle(new FileBundle);
+    bundle->add(file_path);
+
+    std::string folder = fwk::path_dirname(file_path);
+
+    LibFolder::Ptr pf;
+    pf = lib->getFolder(folder);
+    if(!pf) {
+        pf = lib->addFolder(folder);
+        LibFolder::ListPtr l(new LibFolder::List);
+        l->push_back(pf);
+        lib->notify(Library::NotifyType::ADDED_FOLDERS,
+                    boost::any(l));
+    }
+    lib->addBundle(pf->id(), bundle, manage);
+    lib->notify(Library::NotifyType::ADDED_FILES,
+                boost::any());
+}
+
 void Commands::cmdImportFiles(const Library::Ptr & lib, 
                               const std::string & folder, 
                               const FileList::Ptr & files, bool manage)
@@ -65,8 +91,7 @@ void Commands::cmdImportFiles(const Library::Ptr & lib,
 
     LibFolder::Ptr pf;
     pf = lib->getFolder(folder);
-    if(pf == NULL)
-    {
+    if(!pf) {
         pf = lib->addFolder(folder);
         LibFolder::ListPtr l( new LibFolder::List );
         l->push_back(pf);
diff --git a/src/engine/library/commands.hpp b/src/engine/library/commands.hpp
index f670508..113bac3 100644
--- a/src/engine/library/commands.hpp
+++ b/src/engine/library/commands.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - engine/library/commands.hpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,6 +39,9 @@ public:
 
                static void cmdListAllFolders(const Library::Ptr & lib);
                static void cmdListAllKeywords(const Library::Ptr & lib);
+               static void cmdImportFile(const Library::Ptr & lib,
+                               const std::string & path,
+                               bool manage);
                static void cmdImportFiles(const Library::Ptr & lib, 
                                const std::string & folder, 
                                const fwk::FileList::Ptr & files, 
diff --git a/src/libraryclient/clientimpl.cpp b/src/libraryclient/clientimpl.cpp
index 8a18aad..3c29165 100644
--- a/src/libraryclient/clientimpl.cpp
+++ b/src/libraryclient/clientimpl.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/clientimpl.cpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -167,6 +167,11 @@ tid_t ClientImpl::processXmpUpdateQueue(bool write_xmp)
                                  _1, write_xmp));
 }
 
+tid_t ClientImpl::importFile(const std::string & path, bool manage)
+{
+    return schedule_op(std::bind(&Commands::cmdImportFile,
+                                 _1, path, manage));
+}
 
 tid_t ClientImpl::importFromDirectory(const std::string & dir, bool manage)
 {
diff --git a/src/libraryclient/clientimpl.hpp b/src/libraryclient/clientimpl.hpp
index f72e190..89e5a75 100644
--- a/src/libraryclient/clientimpl.hpp
+++ b/src/libraryclient/clientimpl.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/clientimpl.hpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -63,6 +63,7 @@ public:
 
     eng::tid_t processXmpUpdateQueue(bool write_xmp);
 
+    eng::tid_t importFile(const std::string & path, bool manage);
     eng::tid_t importFromDirectory(const std::string & dir, bool manage);
 
 protected:
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index 114be43..261ec20 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/libraryclient.cpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -138,6 +138,11 @@ eng::tid_t LibraryClient::processXmpUpdateQueue(bool write_xmp)
     return m_pImpl->processXmpUpdateQueue(write_xmp);
 }
 
+void LibraryClient::importFile(const std::string & path, bool manage)
+{
+    m_pImpl->importFile(path, manage);
+}
+
 void LibraryClient::importFromDirectory(const std::string & dir, bool manage)
 {
     m_pImpl->importFromDirectory(dir, manage);
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 3045810..fbaf9f9 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/libraryclient.hpp
  *
- * Copyright (C) 2007-2013 Hubert Figuiere
+ * Copyright (C) 2007-2015 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -82,7 +82,13 @@ public:
     
     /** tell to process the Xmp update Queue */
     eng::tid_t processXmpUpdateQueue(bool write_xmp);
-    
+
+    /** Import file
+     * @param path the file path
+     * @param manage true if imported file have to be managed
+     */
+    void importFile(const std::string & path, bool manage);
+
     /** Import files from a directory
      * @param dir the directory
      * @param manage true if imports have to be managed


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