[gnote] Add file_filename taking Gio::File arg



commit 3dba1f6ff9ceaa425b677ee8974de5920f8b7cef
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Tue Jul 31 14:29:23 2018 +0300

    Add file_filename taking Gio::File arg

 src/sharp/files.cpp           |  9 ++++++++-
 src/sharp/files.hpp           |  4 +++-
 src/test/unit/filesutests.cpp | 12 ++++++++++--
 3 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/src/sharp/files.cpp b/src/sharp/files.cpp
index ff41f830..1e40fdcf 100644
--- a/src/sharp/files.cpp
+++ b/src/sharp/files.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2017 Aurimas Cernius
+ * Copyright (C) 2011,2017-2018 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -63,6 +63,13 @@ namespace sharp {
     return Glib::path_get_basename(p);
   }
 
+  Glib::ustring file_filename(const Glib::RefPtr<Gio::File> & p)
+  {
+    if(!p)
+      return "";
+    return p->get_basename();
+  }
+
   void file_delete(const Glib::ustring & p)
   {
     g_unlink(p.c_str());
diff --git a/src/sharp/files.hpp b/src/sharp/files.hpp
index 32822cef..85fc0fa3 100644
--- a/src/sharp/files.hpp
+++ b/src/sharp/files.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2017 Aurimas Cernius
+ * Copyright (C) 2017-2018 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -28,6 +28,7 @@
 
 #include <vector>
 
+#include <giomm/file.h>
 #include <glibmm/ustring.h>
 
 namespace sharp {
@@ -41,6 +42,7 @@ namespace sharp {
   Glib::ustring file_dirname(const Glib::ustring & p);
   /** return the filename from the file path */
   Glib::ustring file_filename(const Glib::ustring & p);
+  Glib::ustring file_filename(const Glib::RefPtr<Gio::File> & p);
   void file_copy(const Glib::ustring & source, const Glib::ustring & dest);
 
   std::vector<Glib::ustring> file_read_all_lines(const Glib::ustring & path);
diff --git a/src/test/unit/filesutests.cpp b/src/test/unit/filesutests.cpp
index 80ab3da8..e5a59ec5 100644
--- a/src/test/unit/filesutests.cpp
+++ b/src/test/unit/filesutests.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2017 Aurimas Cernius
+ * Copyright (C) 2017-2018 Aurimas Cernius
  *
  * 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
@@ -46,7 +46,7 @@ SUITE(files)
     CHECK_EQUAL("/foo/bar", sharp::file_dirname("/foo/bar/"));
   }
 
-  TEST(filename)
+  TEST(filename_ustr)
   {
     CHECK_EQUAL("baz.txt", sharp::file_filename("/foo/bar/baz.txt"));
     CHECK_EQUAL("baz", sharp::file_filename("/foo/bar/baz"));
@@ -54,6 +54,14 @@ SUITE(files)
     CHECK_EQUAL("bar", sharp::file_filename("/foo/bar/"));
   }
 
+  TEST(filename_File)
+  {
+    CHECK_EQUAL("", sharp::file_filename(Glib::RefPtr<Gio::File>()));
+    CHECK_EQUAL("baz.txt", sharp::file_filename(Gio::File::create_for_path("/foo/bar/baz.txt")));
+    CHECK_EQUAL("baz", sharp::file_filename(Gio::File::create_for_path("/foo/bar/baz")));
+    CHECK_EQUAL("bar", sharp::file_filename(Gio::File::create_for_path("/foo/bar/")));
+  }
+
   TEST(exists)
   {
     Glib::ustring dir = Glib::get_current_dir();


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