[gnote] More Gio::File variants and small refactoring



commit 9911bc05dcc84d9624729466a1e906b0538353b6
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Tue Jul 31 14:19:37 2018 +0300

    More Gio::File variants and small refactoring

 src/sharp/directory.cpp | 32 +++++++++++++++++++++-----------
 src/sharp/directory.hpp |  2 ++
 2 files changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/src/sharp/directory.cpp b/src/sharp/directory.cpp
index 3670dba9..980cebc0 100644
--- a/src/sharp/directory.cpp
+++ b/src/sharp/directory.cpp
@@ -67,11 +67,7 @@ namespace sharp {
                                     const Glib::ustring & ext,
                                     std::vector<Glib::RefPtr<Gio::File>> & files)
   {
-    if(!dir || !dir->query_exists()) {
-      return;
-    }
-    auto info = dir->query_info();
-    if(!info || info->get_file_type() != Gio::FILE_TYPE_DIRECTORY) {
+    if(!directory_exists(dir)) {
       return;
     }
 
@@ -119,11 +115,7 @@ namespace sharp {
   void directory_get_directories(const Glib::RefPtr<Gio::File> & dir,
                                  std::vector<Glib::RefPtr<Gio::File>> & files)
   {
-    if(!dir || !dir->query_exists()) {
-      return;
-    }
-    auto info = dir->query_info();
-    if(!info || info->get_file_type() != Gio::FILE_TYPE_DIRECTORY) {
+    if(!directory_exists(dir)) {
       return;
     }
 
@@ -156,6 +148,19 @@ namespace sharp {
     return Glib::file_test(dir, Glib::FILE_TEST_EXISTS) && Glib::file_test(dir, Glib::FILE_TEST_IS_DIR);
   }
 
+  bool directory_exists(const Glib::RefPtr<Gio::File> & dir)
+  {
+    if(!dir || !dir->query_exists()) {
+      return false;
+    }
+    auto info = dir->query_info();
+    if(!info || info->get_file_type() != Gio::FILE_TYPE_DIRECTORY) {
+      return false;
+    }
+
+    return true;
+  }
+
   void directory_copy(const Glib::RefPtr<Gio::File> & src,
                       const Glib::RefPtr<Gio::File> & dest)
   {
@@ -195,7 +200,12 @@ namespace sharp {
 
   bool directory_create(const Glib::ustring & dir)
   {
-    return Gio::File::create_for_path(dir)->make_directory_with_parents();
+    return directory_create(Gio::File::create_for_path(dir));
+  }
+
+  bool directory_create(const Glib::RefPtr<Gio::File> & dir)
+  {
+    return dir->make_directory_with_parents();
   }
 
   bool directory_delete(const Glib::ustring & dir, bool recursive)
diff --git a/src/sharp/directory.hpp b/src/sharp/directory.hpp
index d3c4ee61..6834b37e 100644
--- a/src/sharp/directory.hpp
+++ b/src/sharp/directory.hpp
@@ -59,6 +59,7 @@ namespace sharp {
                            std::vector<Glib::RefPtr<Gio::File>> & files);
 
   bool directory_exists(const Glib::ustring & dir);
+  bool directory_exists(const Glib::RefPtr<Gio::File> & dir);
 
   /**
    * @param src The source directory (or file)
@@ -68,6 +69,7 @@ namespace sharp {
                       const Glib::RefPtr<Gio::File> & dest);
 
   bool directory_create(const Glib::ustring & dir);
+  bool directory_create(const Glib::RefPtr<Gio::File> & dir);
 
   bool directory_delete(const Glib::ustring & dir, bool recursive);
   bool directory_delete(const Glib::RefPtr<Gio::File> & dir, bool recursive);


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