[gnome-games/wip/aplazas/run-uri: 3/21] tracker: Add MimeTypeTrackerQuery.is_uri_valid()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/run-uri: 3/21] tracker: Add MimeTypeTrackerQuery.is_uri_valid()
- Date: Thu, 13 Apr 2017 14:21:50 +0000 (UTC)
commit 46bbf9666c090255e88e82c7a17940d889017950
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Apr 13 13:12:49 2017 +0200
tracker: Add MimeTypeTrackerQuery.is_uri_valid()
Add this method to check that the received URIs correspond to existing
files of the queried type.
This replaces the usage of the corresponding method from UriGameFactory
which has never really been used and will be removed in the next commit.
src/tracker/mime-type-tracker-query.vala | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker/mime-type-tracker-query.vala b/src/tracker/mime-type-tracker-query.vala
index c68f282..3bca944 100644
--- a/src/tracker/mime-type-tracker-query.vala
+++ b/src/tracker/mime-type-tracker-query.vala
@@ -16,7 +16,25 @@ public class Games.MimeTypeTrackerQuery : Object, TrackerQuery {
public bool is_cursor_valid (Tracker.Sparql.Cursor cursor) {
var uri = cursor.get_string (0);
- return uri_game_factory.is_uri_valid (uri);
+ return is_uri_valid (uri);
+ }
+
+ public bool is_uri_valid (string uri) {
+ var file = File.new_for_uri (uri);
+ if (!file.query_exists ())
+ return false;
+
+ try {
+ var info = file.query_info ("standard::content-type", FileQueryInfoFlags.NONE);
+ var actual_type = info.get_content_type ();
+
+ return ContentType.is_a (actual_type, mime_type);
+ }
+ catch (Error e) {
+ debug (e.message);
+
+ return false;
+ }
}
public void process_cursor (Tracker.Sparql.Cursor cursor) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]