diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-02-09 11:25:29 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2011-02-09 11:25:29 +0100 |
commit | 4b30c6797f13d3c960b4b6924f389f9d7ee1d78b (patch) | |
tree | 87e92ad27c6fe5e5e8debe77daec54f72b24341c | |
parent | b750a6ac58a2fbd32e8ddcbe26c1ba52499462ec (diff) | |
download | tracker-4b30c6797f13d3c960b4b6924f389f9d7ee1d78b.tar.gz |
plugins/nautilus: Don't crash if we can't get a SPARQL connection
-rw-r--r-- | src/plugins/nautilus/tracker-tags-view.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/src/plugins/nautilus/tracker-tags-view.c b/src/plugins/nautilus/tracker-tags-view.c index 8d377114c..6ac6436f2 100644 --- a/src/plugins/nautilus/tracker-tags-view.c +++ b/src/plugins/nautilus/tracker-tags-view.c @@ -101,11 +101,18 @@ tracker_tags_view_class_init (TrackerTagsViewClass *klass) static void tracker_tags_view_init (TrackerTagsView *tv) { + GError *error = NULL; + tv->private = TRACKER_TAGS_VIEW_GET_PRIVATE (tv); tv->private->cancellable = g_cancellable_new (); tv->private->connection = tracker_sparql_connection_get (tv->private->cancellable, - NULL); + &error); + if (!tv->private->connection) { + g_critical ("Couldn't get a proper SPARQL connection: '%s'", + error ? error->message : "unknown error"); + g_clear_error (&error); + } tv->private->files = NULL; @@ -432,6 +439,13 @@ tags_view_query_files_for_tag_id (TagData *td) { gchar *query; + if (!td->tv->private->connection) { + g_warning ("Can't query files for tag id '%s', " + "no SPARQL connection available", + td->tag_id); + return; + } + query = g_strdup_printf ("SELECT ?url " "WHERE {" " ?urn a rdfs:Resource ;" @@ -596,6 +610,13 @@ tags_view_add_tag (TrackerTagsView *tv, GString *query; gint files; + if (!tv->private->connection) { + g_warning ("Can't add tag '%s', " + "no SPARQL connection available", + tag); + return; + } + gtk_widget_set_sensitive (tv->private->entry, FALSE); files = g_list_length (tv->private->files); @@ -763,6 +784,14 @@ tags_view_model_toggle_row (TrackerTagsView *tv, gtk_widget_set_sensitive (tv->private->entry, FALSE); + if (!tv->private->connection) { + g_warning ("Can't update tags, " + "no SPARQL connection available"); + g_free (id); + g_free (query); + return; + } + g_debug ("Running query:'%s'\n", query); td = tag_data_new (id, &iter, TRUE, selection, 1, tv); @@ -843,6 +872,13 @@ tags_view_remove_tag (TrackerTagsView *tv, TagData *td_copy; gchar *query; + if (!tv->private->connection) { + g_warning ("Can't remove tag '%s', " + "no SPARQL connection available", + td->tag_id); + return; + } + query = g_strdup_printf ("DELETE { " " <%s> a rdfs:Resource " "}", @@ -1043,15 +1079,20 @@ tags_view_create_ui (TrackerTagsView *tv) G_CALLBACK (tags_view_model_row_selected_cb), tv); - tracker_sparql_connection_query_async (tv->private->connection, - "SELECT ?urn ?label " - "WHERE {" - " ?urn a nao:Tag ;" - " nao:prefLabel ?label . " - "} ORDER BY ?label", - tv->private->cancellable, - tags_view_add_tags_cb, - tv); + if (tv->private->connection) { + tracker_sparql_connection_query_async (tv->private->connection, + "SELECT ?urn ?label " + "WHERE {" + " ?urn a nao:Tag ;" + " nao:prefLabel ?label . " + "} ORDER BY ?label", + tv->private->cancellable, + tags_view_add_tags_cb, + tv); + } else { + g_warning ("Can't query for tags, " + "no SPARQL connection available"); + } gtk_widget_show_all (GTK_WIDGET (tv)); gtk_widget_grab_focus (entry); |