[niepce] importer: don't pass bare bool for managed or single import
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] importer: don't pass bare bool for managed or single import
- Date: Thu, 1 Jun 2017 03:40:30 +0000 (UTC)
commit 3dc81f1aa5132ed128761233db2fe5a8aca5ade6
Author: Hubert Figuière <hub figuiere net>
Date: Fri May 26 21:58:38 2017 -0400
importer: don't pass bare bool for managed or single import
src/engine/db/library.cpp | 8 ++++----
src/engine/db/library.hpp | 18 ++++++++++++------
src/engine/db/test_library.cpp | 2 +-
src/engine/importer/cameraimporter.cpp | 2 +-
src/engine/importer/directoryimporter.cpp | 2 +-
src/engine/importer/iimporter.hpp | 7 ++++++-
src/engine/library/commands.cpp | 10 ++++++----
src/engine/library/commands.hpp | 14 +++++++-------
src/libraryclient/clientimpl.cpp | 5 +++--
src/libraryclient/clientimpl.hpp | 5 +++--
src/libraryclient/libraryclient.cpp | 4 ++--
src/libraryclient/libraryclient.hpp | 5 +++--
src/niepce/ui/niepcewindow.cpp | 6 ++++--
13 files changed, 53 insertions(+), 35 deletions(-)
---
diff --git a/src/engine/db/library.cpp b/src/engine/db/library.cpp
index 152330b..bff8928 100644
--- a/src/engine/db/library.cpp
+++ b/src/engine/db/library.cpp
@@ -269,10 +269,10 @@ std::string Library::getFsFile(library_id_t id)
}
-library_id_t Library::addFile(library_id_t folder_id, const std::string & file, bool manage)
+library_id_t Library::addFile(library_id_t folder_id, const std::string & file, Managed manage)
{
library_id_t ret = -1;
- DBG_ASSERT(!manage, "manage not supported");
+ DBG_ASSERT(manage == Managed::NO, "manage not supported");
DBG_ASSERT(folder_id != -1, "invalid folder ID");
try {
int32_t rating, orientation, flag;
@@ -341,7 +341,7 @@ library_id_t Library::addFile(library_id_t folder_id, const std::string & file,
library_id_t Library::addFileAndFolder(const std::string & folder,
const std::string & file,
- bool manage)
+ Managed manage)
{
LibFolder::Ptr f;
f = getFolder(folder);
@@ -353,7 +353,7 @@ library_id_t Library::addFileAndFolder(const std::string & folder,
library_id_t Library::addBundle(library_id_t folder_id,
const eng::FileBundle::Ptr & bundle,
- bool manage)
+ Managed manage)
{
library_id_t file_id = 0;
file_id = addFile(folder_id, bundle->main_file(), manage);
diff --git a/src/engine/db/library.hpp b/src/engine/db/library.hpp
index 02d675d..a70dd4a 100644
--- a/src/engine/db/library.hpp
+++ b/src/engine/db/library.hpp
@@ -73,6 +73,12 @@ public:
FILE_MOVED
};
+ /** Whether to import managed. */
+ enum class Managed {
+ NO = 0,
+ YES
+ };
+
Library(const std::string & dir, const fwk::NotificationCenter::Ptr & nc);
virtual ~Library();
@@ -93,10 +99,10 @@ public:
/** add a file to the library
* @param folder the path of the containing folder
* @param file the file path
- * @param manage pass true it the library *manage* the file. Currently unsupported.
+ * @param manage pass Managed::YES if the library *manage* the file. Currently unsupported.
*/
library_id_t addFileAndFolder(const std::string & folder,
- const std::string & file, bool manage);
+ const std::string & file, Managed manage);
/** add a fs file to the library
* @param file the file path
@@ -113,18 +119,18 @@ public:
/** add a file to the library
* @param folder_id the id of the containing folder
* @param file the file path
- * @param manage pass true it the library *manage* the file. Currently unsupported.
+ * @param manage pass Managed::YES if the library *manage* the file. Currently unsupported.
*/
- library_id_t addFile(library_id_t folder_id, const std::string & file, bool manage);
+ library_id_t addFile(library_id_t folder_id, const std::string & file, Managed manage);
/** add a bundle of files to the library
* @param folder_id the id of the containing folder
* @param bundle the bundle
- * @param manage pass true it the library *manage* the file. Currently unsupported.
+ * @param manage pass Managed::YES if the library *manage* the file. Currently unsupported.
*/
library_id_t addBundle(library_id_t folder_id,
const eng::FileBundle::Ptr & bundle,
- bool manage);
+ Managed manage);
/** add a sidecar fsfile to a bundle (file)
* @param file_id the id of the file bundle
* @param fsfile_id the id of the fsfile
diff --git a/src/engine/db/test_library.cpp b/src/engine/db/test_library.cpp
index a3f2962..c1fe75f 100644
--- a/src/engine/db/test_library.cpp
+++ b/src/engine/db/test_library.cpp
@@ -57,7 +57,7 @@ int test_main(int, char *[])
// now we have the Trash folder created at startup
BOOST_CHECK( l->size() == 3 );
- int file_id = lib.addFile(folder_added->id(), "foo/myfile", false);
+ int file_id = lib.addFile(folder_added->id(), "foo/myfile", eng::Library::Managed::NO);
BOOST_CHECK(file_id > 0);
BOOST_CHECK(lib.moveFileToFolder(file_id, 100) == false);
diff --git a/src/engine/importer/cameraimporter.cpp b/src/engine/importer/cameraimporter.cpp
index 4130325..da18e2e 100644
--- a/src/engine/importer/cameraimporter.cpp
+++ b/src/engine/importer/cameraimporter.cpp
@@ -127,7 +127,7 @@ bool CameraImporter::do_import(const std::string & source,
if (this->m_camera->download_file(imported_camera_file->folder(),
imported_camera_file->name(),
output_path)) {
- importer(output_path, true, true);
+ importer(output_path, IImporter::Import::SINGLE, Library::Managed::YES);
}
}
return true;
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index af94f62..300379f 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -94,7 +94,7 @@ bool DirectoryImporter::do_import(const std::string& source,
const FileImporter& callback)
{
// pretty trivial, we have the source path.
- callback(source, false, false);
+ callback(source, IImporter::Import::DIRECTORY, Library::Managed::NO);
// XXX return a real error
return true;
diff --git a/src/engine/importer/iimporter.hpp b/src/engine/importer/iimporter.hpp
index c30c4a8..04a2643 100644
--- a/src/engine/importer/iimporter.hpp
+++ b/src/engine/importer/iimporter.hpp
@@ -25,6 +25,7 @@
#include <functional>
#include "fwk/toolkit/thumbnail.hpp"
+#include "engine/db/library.hpp"
#include "engine/importer/importedfile.hpp"
namespace eng {
@@ -51,8 +52,12 @@ public:
const std::list<std::string>& paths,
const PreviewReady& callback) = 0;
+ enum class Import {
+ SINGLE,
+ DIRECTORY
+ };
/** file importer callback */
- typedef std::function<void (const std::string&, bool, bool)> FileImporter;
+ typedef std::function<void (const std::string&, Import, Library::Managed)> FileImporter;
/** perform import from source */
virtual bool do_import(const std::string& source,
const FileImporter& importer) = 0;
diff --git a/src/engine/library/commands.cpp b/src/engine/library/commands.cpp
index bf834cd..9086667 100644
--- a/src/engine/library/commands.cpp
+++ b/src/engine/library/commands.cpp
@@ -57,9 +57,10 @@ void Commands::cmdListAllFolders(const Library::Ptr & lib)
void Commands::cmdImportFile(const Library::Ptr & lib,
const std::string & file_path,
- bool manage)
+ Library::Managed manage)
{
- DBG_ASSERT(!manage, "managing file is currently unsupported");
+ DBG_ASSERT(manage == Library::Managed::NO,
+ "managing file is currently unsupported");
FileBundle::Ptr bundle(new FileBundle);
bundle->add(file_path);
@@ -81,9 +82,10 @@ void Commands::cmdImportFile(const Library::Ptr & lib,
void Commands::cmdImportFiles(const Library::Ptr & lib,
const std::string & folder,
- const FileList::Ptr & files, bool manage)
+ const FileList::Ptr & files, Library::Managed manage)
{
- DBG_ASSERT(!manage, "managing file is currently unsupported");
+ DBG_ASSERT(manage == Library::Managed::NO,
+ "managing file is currently unsupported");
FileBundle::ListPtr bundles = FileBundle::filter_bundles(files);
diff --git a/src/engine/library/commands.hpp b/src/engine/library/commands.hpp
index 113bac3..0a151a1 100644
--- a/src/engine/library/commands.hpp
+++ b/src/engine/library/commands.hpp
@@ -39,13 +39,13 @@ 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,
- bool manage);
+ static void cmdImportFile(const Library::Ptr & lib,
+ const std::string & path,
+ Library::Managed manage);
+ static void cmdImportFiles(const Library::Ptr & lib,
+ const std::string & folder,
+ const fwk::FileList::Ptr & files,
+ Library::Managed manage);
static void cmdQueryFolderContent(const Library::Ptr & lib,
library_id_t folder_id);
static void cmdCountFolder(const Library::Ptr & lib,
diff --git a/src/libraryclient/clientimpl.cpp b/src/libraryclient/clientimpl.cpp
index 355e3d4..5212b56 100644
--- a/src/libraryclient/clientimpl.cpp
+++ b/src/libraryclient/clientimpl.cpp
@@ -28,6 +28,7 @@
using fwk::FileList;
using eng::Op;
using eng::Commands;
+using eng::Library;
using eng::tid_t;
namespace libraryclient {
@@ -173,14 +174,14 @@ tid_t ClientImpl::processXmpUpdateQueue(bool write_xmp)
});
}
-tid_t ClientImpl::importFile(const std::string & path, bool manage)
+tid_t ClientImpl::importFile(const std::string & path, Library::Managed manage)
{
return schedule_op([path, manage](const auto& lib) {
Commands::cmdImportFile(lib, path, manage);
});
}
-tid_t ClientImpl::importFromDirectory(const std::string & dir, bool manage)
+tid_t ClientImpl::importFromDirectory(const std::string & dir, Library::Managed manage)
{
FileList::Ptr files;
diff --git a/src/libraryclient/clientimpl.hpp b/src/libraryclient/clientimpl.hpp
index 286a0b8..d694999 100644
--- a/src/libraryclient/clientimpl.hpp
+++ b/src/libraryclient/clientimpl.hpp
@@ -24,6 +24,7 @@
#include <string>
#include "fwk/base/moniker.hpp"
+#include "engine/db/library.hpp"
#include "engine/library/clienttypes.hpp"
#include "engine/library/op.hpp"
@@ -63,8 +64,8 @@ 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);
+ eng::tid_t importFile(const std::string & path, eng::Library::Managed manage);
+ eng::tid_t importFromDirectory(const std::string & dir, eng::Library::Managed manage);
protected:
const fwk::Moniker m_moniker;
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index c711efe..d05c74a 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -136,12 +136,12 @@ eng::tid_t LibraryClient::processXmpUpdateQueue(bool write_xmp)
return m_pImpl->processXmpUpdateQueue(write_xmp);
}
-void LibraryClient::importFile(const std::string & path, bool manage)
+void LibraryClient::importFile(const std::string & path, eng::Library::Managed manage)
{
m_pImpl->importFile(path, manage);
}
-void LibraryClient::importFromDirectory(const std::string & dir, bool manage)
+void LibraryClient::importFromDirectory(const std::string & dir, eng::Library::Managed manage)
{
m_pImpl->importFromDirectory(dir, manage);
}
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 5f449ef..77d89b6 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -27,6 +27,7 @@
#include "fwk/base/util.hpp"
#include "engine/library/clienttypes.hpp"
#include "engine/library/thumbnailcache.hpp"
+#include "engine/db/library.hpp"
#include "engine/db/librarytypes.hpp"
#include "engine/db/storage.hpp"
@@ -87,13 +88,13 @@ public:
* @param path the file path
* @param manage true if imported file have to be managed
*/
- void importFile(const std::string & path, bool manage);
+ void importFile(const std::string & path, eng::Library::Managed manage);
/** Import files from a directory
* @param dir the directory
* @param manage true if imports have to be managed
*/
- void importFromDirectory(const std::string & dir, bool manage);
+ void importFromDirectory(const std::string & dir, eng::Library::Managed manage);
eng::ThumbnailCache & thumbnailCache()
{ return m_thumbnailCache; }
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index c01e098..c5f8d65 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -53,6 +53,8 @@ using libraryclient::LibraryClientPtr;
using fwk::Application;
using fwk::Configuration;
using fwk::UndoHistory;
+using eng::Library;
+using eng::IImporter;
namespace ui {
@@ -270,8 +272,8 @@ void NiepceWindow::on_action_file_import()
if (importer) {
importer->do_import(
source,
- [this] (const std::string & path, bool single, bool manage) {
- if (single) {
+ [this] (const std::string & path, IImporter::Import type, Library::Managed manage) {
+ if (type == IImporter::Import::SINGLE) {
m_libClient->importFile(path, manage);
} else {
m_libClient->importFromDirectory(path, manage);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]