[niepce] Issue #31 - Only list media files we can import
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Issue #31 - Only list media files we can import
- Date: Sat, 20 Oct 2018 15:15:44 +0000 (UTC)
commit 27fd65ad961d73b77f50f3932370722230ae085f
Author: Hubert Figuière <hub figuiere net>
Date: Sat Oct 20 11:12:13 2018 -0400
Issue #31 - Only list media files we can import
https://gitlab.gnome.org/GNOME/niepce/issues/31
build.rs | 1 +
src/Makefile.am | 1 +
src/engine/importer/directoryimporter.cpp | 4 +--
src/fwk/toolkit/mimetype.rs | 2 +-
src/fwk/utils/files.cpp | 8 ++++++
src/fwk/utils/files.hpp | 1 +
src/fwk/utils/files.rs | 43 +++++++++++++++++++++++++++++++
src/fwk/utils/mod.rs | 1 +
8 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/build.rs b/build.rs
index 47d54ee..9d1c335 100644
--- a/build.rs
+++ b/build.rs
@@ -70,6 +70,7 @@ fn main() {
.with_parse_exclude(&["exempi", "chrono"])
.exclude_item("GtkWindow")
.exclude_item("GtkToolbar")
+ .exclude_item("GFileInfo")
.with_crate(&crate_dir);
if let Ok(bindings) = cbuilder.generate() {
diff --git a/src/Makefile.am b/src/Makefile.am
index 35aac27..696052b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ RUST_SOURCES = \
@top_srcdir@/src/fwk/toolkit/mimetype.rs \
@top_srcdir@/src/fwk/toolkit/mod.rs \
@top_srcdir@/src/fwk/utils/exempi.rs \
+ @top_srcdir@/src/fwk/utils/files.rs \
@top_srcdir@/src/fwk/utils/mod.rs \
@top_srcdir@/src/lib.rs \
@top_srcdir@/src/libraryclient/clientimpl.rs \
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index 6eb50f4..2a031ba 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -2,7 +2,7 @@
/*
* niepce - engine/importer/directoryimporter.cpp
*
- * Copyright (C) 2014-2017 Hubert Figuière
+ * Copyright (C) 2014-2018 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
@@ -66,7 +66,7 @@ bool DirectoryImporter::list_source_content(const std::string & source,
{
auto files =
fwk::FileList::getFilesFromDirectory(source,
- &fwk::filter_xmp_out);
+ &fwk::filter_only_media);
std::list<ImportedFilePtr> content;
for(const auto & entry : *files)
diff --git a/src/fwk/toolkit/mimetype.rs b/src/fwk/toolkit/mimetype.rs
index 0d55477..2708084 100644
--- a/src/fwk/toolkit/mimetype.rs
+++ b/src/fwk/toolkit/mimetype.rs
@@ -50,7 +50,7 @@ pub struct MimeType {
mtype: MType,
}
-fn guess_type(gmtype: &str) -> MType {
+pub fn guess_type(gmtype: &str) -> MType {
if gio::content_type_is_a(&gmtype, "image/*") {
if gio::content_type_is_a(&gmtype, "image/x-dcraw") {
return MType::Image(IsRaw::Yes);
diff --git a/src/fwk/utils/files.cpp b/src/fwk/utils/files.cpp
index 02f8abe..b155858 100644
--- a/src/fwk/utils/files.cpp
+++ b/src/fwk/utils/files.cpp
@@ -27,6 +27,8 @@
#include "files.hpp"
#include "pathutils.hpp"
+#include "rust_bindings.hpp"
+
namespace fwk {
std::string make_tmp_dir(const std::string& base)
@@ -67,6 +69,12 @@ bool filter_xmp_out(const Glib::RefPtr<Gio::FileInfo> & file)
return filter_ext(file, ext);
}
+bool filter_only_media(const Glib::RefPtr<Gio::FileInfo> & file)
+{
+ return ffi::file_is_media(file->gobj());
+}
+
+
FileList::FileList()
{
diff --git a/src/fwk/utils/files.hpp b/src/fwk/utils/files.hpp
index c4f593b..7c53478 100644
--- a/src/fwk/utils/files.hpp
+++ b/src/fwk/utils/files.hpp
@@ -42,6 +42,7 @@ bool filter_none(const Glib::RefPtr<Gio::FileInfo> & file);
bool filter_ext(const Glib::RefPtr<Gio::FileInfo> & file,
const std::string & ext);
bool filter_xmp_out(const Glib::RefPtr<Gio::FileInfo> & file);
+bool filter_only_media(const Glib::RefPtr<Gio::FileInfo> & file);
#endif
class FileList;
diff --git a/src/fwk/utils/files.rs b/src/fwk/utils/files.rs
new file mode 100644
index 0000000..9807a46
--- /dev/null
+++ b/src/fwk/utils/files.rs
@@ -0,0 +1,43 @@
+/*
+ * niepce - fwk/utils/files.rs
+ *
+ * Copyright (C) 2018 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use glib::translate::*;
+use gio;
+use gio_sys;
+use gio::prelude::*;
+
+use fwk::toolkit::mimetype::{
+ guess_type,
+ MType
+};
+
+#[no_mangle]
+pub unsafe extern "C" fn file_is_media(finfo: *mut gio_sys::GFileInfo) -> bool {
+ let fileinfo = gio::FileInfo::from_glib_none(finfo);
+ if let Some(gmtype) = fileinfo.get_content_type() {
+ let t = guess_type(&gmtype);
+ return match t {
+ MType::Image(_) |
+ MType::Movie => true,
+ _ => false
+ };
+ }
+
+ false
+}
diff --git a/src/fwk/utils/mod.rs b/src/fwk/utils/mod.rs
index fefeea7..765dc18 100644
--- a/src/fwk/utils/mod.rs
+++ b/src/fwk/utils/mod.rs
@@ -18,3 +18,4 @@
*/
pub mod exempi;
+pub mod files;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]