[bijiben] tracker: Provides a useful Oops view if tracker is not avalaible
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] tracker: Provides a useful Oops view if tracker is not avalaible
- Date: Fri, 12 Jul 2013 21:33:39 +0000 (UTC)
commit 2bbf10de53cb63df9b5868be85f12fbd92f8a8f4
Author: Pierre-Yves Luyten <py luyten fr>
Date: Fri Jul 12 01:19:08 2013 +0200
tracker: Provides a useful Oops view if tracker is not avalaible
Tell the user something is wrong there rather crashing
more or less silently.
src/bjb-bijiben.c | 36 ++++++++++++++-----
src/bjb-empty-results-box.c | 75 ++++++++++++++++++++++++++++++------------
src/bjb-empty-results-box.h | 3 +-
src/bjb-main-toolbar.c | 1 +
src/bjb-window-base.c | 8 ++++
src/bjb-window-base.h | 1 +
src/libbiji/Makefile.am | 2 +
src/libbiji/biji-error.c | 47 ++++++++++++++++++++++++++
src/libbiji/biji-error.h | 48 +++++++++++++++++++++++++++
src/libbiji/biji-note-book.c | 61 ++++++++++++++++++++++++---------
src/libbiji/biji-note-book.h | 3 +-
11 files changed, 235 insertions(+), 50 deletions(-)
---
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 1b9f2c1..14671fe 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -44,17 +44,28 @@ G_DEFINE_TYPE (Bijiben, bijiben, GTK_TYPE_APPLICATION);
static void
bijiben_new_window_internal (GApplication *app,
GFile *file,
- BijiNoteObj *note_obj)
+ BijiNoteObj *note_obj,
+ GError *error)
{
BjbWindowBase *window;
- BijiNoteObj* note = NULL;
+ BijiNoteObj* note;
Bijiben *self;
g_return_if_fail (BIJIBEN_IS_APPLICATION (app));
self = BIJIBEN_APPLICATION (app);
+ note = NULL;
window = BJB_WINDOW_BASE (bjb_window_base_new ());
+ if (error!= NULL)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ bjb_window_base_switch_to (window, BJB_WINDOW_BASE_ERROR_TRACKER);
+ goto out;
+ }
+
+
if (file != NULL)
note = biji_note_get_new_from_file (self->priv->book,
g_file_get_path(file));
@@ -68,6 +79,8 @@ bijiben_new_window_internal (GApplication *app,
else
bjb_window_base_switch_to (window, BJB_WINDOW_BASE_MAIN_VIEW);
+
+out:
gtk_widget_show_all (GTK_WIDGET (window));
}
@@ -75,7 +88,7 @@ void
bijiben_new_window_for_note (GApplication *app,
BijiNoteObj *note)
{
- bijiben_new_window_internal(app, NULL, note);
+ bijiben_new_window_internal(app, NULL, note, NULL);
}
static void
@@ -96,7 +109,7 @@ bijiben_open (GApplication *application,
gint i;
for (i = 0; i < n_files; i++)
- bijiben_new_window_internal(application, files[i],NULL);
+ bijiben_new_window_internal(application, files[i], NULL, NULL);
}
static void
@@ -370,17 +383,20 @@ bijiben_startup (GApplication *application)
g_object_get (self->priv->settings, "color", &default_color, NULL);
gdk_rgba_parse (&color, default_color);
g_warning ("bijiben wants color %s", default_color);
- self->priv->book = biji_note_book_new (storage, &color);
- g_free (default_color);
-
- g_free (storage_path);
- g_object_unref (storage);
+ error = NULL;
+ self->priv->book = biji_note_book_new (storage, &color, &error);
+ if (error)
+ goto out;
/* Goa */
goa_client_new (NULL, on_client_got, self); // cancellable
/* Create the first window */
- bijiben_new_window_internal (application, NULL, NULL);
+ out:
+ bijiben_new_window_internal (application, NULL, NULL, error);
+ g_free (default_color);
+ g_free (storage_path);
+ g_object_unref (storage);
}
static void
diff --git a/src/bjb-empty-results-box.c b/src/bjb-empty-results-box.c
index 5265176..53b2238 100644
--- a/src/bjb-empty-results-box.c
+++ b/src/bjb-empty-results-box.c
@@ -35,25 +35,29 @@ G_DEFINE_TYPE (BjbEmptyResultsBox, bjb_empty_results_box, GTK_TYPE_GRID);
struct _BjbEmptyResultsBoxPrivate
{
+ GtkWidget *primary_label;
GtkLabel *details_label;
BjbEmptyResultsBoxType type;
};
+
static void
bjb_empty_results_box_constructed (GObject *object)
{
- BjbEmptyResultsBox *self = BJB_EMPTY_RESULTS_BOX (object);
+ BjbEmptyResultsBox *self;
+ BjbEmptyResultsBoxPrivate *priv;
GtkStyleContext *context;
- GdkPixbuf *pixbuf; // debug only
+ GdkPixbuf *pixbuf;
GtkWidget *image;
GtkWidget *labels_grid;
- GtkWidget *title_label;
gchar *label;
gchar *icons_path;
gchar *note_icon_path;
GError *error;
G_OBJECT_CLASS (bjb_empty_results_box_parent_class)->constructed (object);
+ self = BJB_EMPTY_RESULTS_BOX (object);
+ priv = self->priv;
gtk_widget_set_halign (GTK_WIDGET (self), GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE);
@@ -94,26 +98,28 @@ bjb_empty_results_box_constructed (GObject *object)
gtk_grid_set_row_spacing (GTK_GRID (labels_grid), 12);
gtk_container_add (GTK_CONTAINER (self), labels_grid);
+
label = g_strconcat ("<b><span size=\"large\">", _("No Notes Found"), "</span></b>", NULL);
- title_label = gtk_label_new (label);
- gtk_widget_set_halign (title_label, GTK_ALIGN_START);
- gtk_widget_set_vexpand (title_label, TRUE);
- gtk_label_set_use_markup (GTK_LABEL (title_label), TRUE);
- gtk_container_add (GTK_CONTAINER (labels_grid), title_label);
+ priv->primary_label = gtk_label_new (label);
+ gtk_widget_set_halign (priv->primary_label, GTK_ALIGN_START);
+ gtk_widget_set_vexpand (priv->primary_label, TRUE);
+ gtk_label_set_use_markup (GTK_LABEL (priv->primary_label), TRUE);
+ gtk_container_add (GTK_CONTAINER (labels_grid), priv->primary_label);
g_free (label);
+
self->priv->type = BJB_EMPTY_RESULTS_TYPE;
label = "";
self->priv->details_label = GTK_LABEL (gtk_label_new (label));
gtk_label_set_use_markup (GTK_LABEL (self->priv->details_label), TRUE);
- gtk_widget_set_halign (title_label, GTK_ALIGN_START);
+ gtk_widget_set_halign (priv->primary_label, GTK_ALIGN_START);
// xalign: 0,
// max_width_chars: 24,
// wrap: true
gtk_container_add (GTK_CONTAINER (labels_grid), GTK_WIDGET (self->priv->details_label));
- gtk_widget_set_valign (title_label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (priv->primary_label, GTK_ALIGN_CENTER);
gtk_widget_show_all (GTK_WIDGET (self));
}
@@ -121,23 +127,50 @@ void
bjb_empty_results_box_set_type (BjbEmptyResultsBox *self,
BjbEmptyResultsBoxType type)
{
+ gchar *label;
+
g_return_if_fail (BJB_IS_EMPTY_RESULTS_BOX (self));
if (type == self->priv->type)
return;
- if (type == BJB_EMPTY_RESULTS_NO_NOTE)
- {
- gtk_label_set_label (
- self->priv->details_label,
- _("Your notes collection is empty.\nClick the New button to create your first note."));
- }
-
- else
+ switch (type)
{
- gtk_label_set_label (
- self->priv->details_label,
- _("No result found for this research."));
+ case BJB_EMPTY_RESULTS_NO_NOTE:
+ gtk_label_set_label (
+ self->priv->details_label,
+ _("Your notes collection is empty.\nClick the New button to create your first note."));
+ break;
+
+ case BJB_EMPTY_RESULTS_NO_RESULTS:
+ gtk_label_set_label (
+ self->priv->details_label,
+ _("No result found for this research."));
+ break;
+
+
+ /*
+ * Tracker is not installed, Bijiben cannot work,
+ * do not try to workaround
+ * TODO: PK
+ */
+
+ case BJB_EMPTY_RESULTS_TRACKER:
+ label = g_strconcat ("<b><span size=\"large\">",
+ _("Oops, "),
+ "</span></b>",
+ NULL);
+ gtk_label_set_label (
+ GTK_LABEL (self->priv->primary_label), label);
+
+ gtk_label_set_label (
+ self->priv->details_label,
+ _("Please install 'Tracker' then restart the application."));
+ g_free (label);
+ break;
+
+ default:
+ break;
}
self->priv->type = type;
diff --git a/src/bjb-empty-results-box.h b/src/bjb-empty-results-box.h
index 4b212fb..c08132c 100644
--- a/src/bjb-empty-results-box.h
+++ b/src/bjb-empty-results-box.h
@@ -33,7 +33,8 @@ G_BEGIN_DECLS
typedef enum {
BJB_EMPTY_RESULTS_TYPE,
BJB_EMPTY_RESULTS_NO_NOTE,
- BJB_EMPTY_RESULTS_NO_RESULTS
+ BJB_EMPTY_RESULTS_NO_RESULTS,
+ BJB_EMPTY_RESULTS_TRACKER
} BjbEmptyResultsBoxType;
#define BJB_TYPE_EMPTY_RESULTS_BOX (bjb_empty_results_box_get_type ())
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index dab37b1..fe4fa15 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -900,6 +900,7 @@ populate_bar_switch (BjbMainToolbar *self)
/* Spinner, Empty Results */
default:
+ add_close_button (self);
break;
}
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 2a1ba56..e80783e 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -299,6 +299,14 @@ bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type)
break;
+ case BJB_WINDOW_BASE_ERROR_TRACKER:
+ bjb_empty_results_box_set_type (BJB_EMPTY_RESULTS_BOX (priv->no_note),
+ BJB_EMPTY_RESULTS_TRACKER);
+ gtk_widget_show_all (priv->no_note);
+ gtk_stack_set_visible_child_name (priv->stack, "empty");
+ break;
+
+
case BJB_WINDOW_BASE_NOTE_VIEW:
gtk_widget_show_all (GTK_WIDGET (priv->note_overlay));
gtk_stack_set_visible_child_name (priv->stack, "note-view");
diff --git a/src/bjb-window-base.h b/src/bjb-window-base.h
index 0d9f57f..d665e68 100644
--- a/src/bjb-window-base.h
+++ b/src/bjb-window-base.h
@@ -36,6 +36,7 @@ typedef enum {
BJB_WINDOW_BASE_NOTE_VIEW,
BJB_WINDOW_BASE_NO_NOTE,
BJB_WINDOW_BASE_NO_RESULT,
+ BJB_WINDOW_BASE_ERROR_TRACKER,
BJB_WINDOW_BASE_NO_VIEW
} BjbWindowViewType;
diff --git a/src/libbiji/Makefile.am b/src/libbiji/Makefile.am
index e3e5711..5c8dcea 100644
--- a/src/libbiji/Makefile.am
+++ b/src/libbiji/Makefile.am
@@ -13,6 +13,8 @@ libbiji_la_SOURCES = \
biji-collection.h \
biji-date-time.c \
biji-date-time.h \
+ biji-error.c \
+ biji-error.h \
biji-info-set.c \
biji-info-set.h \
biji-item.c \
diff --git a/src/libbiji/biji-error.c b/src/libbiji/biji-error.c
new file mode 100644
index 0000000..4923107
--- /dev/null
+++ b/src/libbiji/biji-error.c
@@ -0,0 +1,47 @@
+/*
+ * biji-error.c
+ *
+ * Copyright 2013 Pierre-Yves Luyten <py luyten fr>
+ *
+ * Bijiben 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.
+ *
+ * bijiben 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/>.
+ */
+
+#include "biji-error.h"
+
+
+
+
+static const GDBusErrorEntry dbus_error_entries[] =
+{
+ {BIJI_ERROR_TRACKER, "org.gnome.Biji.Error.Tracker"}
+};
+
+
+
+GQuark
+biji_error_quark (void)
+{
+ G_STATIC_ASSERT (G_N_ELEMENTS (dbus_error_entries) == BIJI_ERROR_NUM_ENTRIES);
+
+ static volatile gsize quark_volatile = 0;
+ g_dbus_error_register_error_domain ("biji-error-quark",
+ &quark_volatile,
+ dbus_error_entries,
+ G_N_ELEMENTS (dbus_error_entries));
+
+ return (GQuark) quark_volatile;
+}
+
+
+
diff --git a/src/libbiji/biji-error.h b/src/libbiji/biji-error.h
new file mode 100644
index 0000000..23c8367
--- /dev/null
+++ b/src/libbiji/biji-error.h
@@ -0,0 +1,48 @@
+/*
+ * biji-error.h
+ *
+ * Copyright 2013 Pierre-Yves Luyten <py luyten fr>
+ *
+ * Bijiben 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.
+ *
+ * bijiben 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/>.
+ */
+
+#ifndef _BIJI_ERROR_H
+#define _BIJI_ERROR_H
+
+
+#include <gio/gio.h>
+
+
+G_BEGIN_DECLS
+
+
+typedef enum
+{
+ BIJI_ERROR_TRACKER, /* org.gnome.Biji.Error.Tracker */
+} BijiError;
+
+
+
+#define BIJI_ERROR_NUM_ENTRIES (BIJI_ERROR_TRACKER + 1)
+
+
+#define BIJI_ERROR (biji_error_quark ())
+
+
+GQuark biji_error_quark (void);
+
+
+G_END_DECLS
+
+#endif /* _BIJI_ERROR_H */
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index c7bbf5b..ad12123 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -21,6 +21,7 @@
#include "libbiji.h"
#include "biji-local-note.h" // FIXME !!!! biji_provider_note_new ()
#include "biji-collection.h"
+#include "biji-error.h"
#include "provider/biji-local-provider.h"
#include "provider/biji-own-cloud-provider.h"
@@ -36,6 +37,7 @@ struct _BijiNoteBookPrivate
gulong note_renamed ;
GFile *location;
+ GError *error;
TrackerSparqlConnection *connection;
ZeitgeistLog *log;
GdkRGBA color;
@@ -47,6 +49,7 @@ enum {
PROP_0,
PROP_LOCATION,
PROP_COLOR,
+ PROP_ERROR,
BIJI_BOOK_PROPERTIES
};
@@ -75,8 +78,6 @@ static void
biji_note_book_init (BijiNoteBook *self)
{
BijiNoteBookPrivate *priv;
- GError *error;
-
priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_NOTE_BOOK,
BijiNoteBookPrivate);
@@ -86,16 +87,6 @@ biji_note_book_init (BijiNoteBook *self)
g_str_equal,
NULL,
g_object_unref);
-
- error = NULL;
- priv->connection = tracker_sparql_connection_get (NULL, &error);
- priv->log = biji_zeitgeist_init ();
-
- if (error)
- {
- g_warning ("Tracker db connection failed : %s", error->message);
- g_error_free (error);
- }
}
@@ -143,6 +134,10 @@ biji_note_book_set_property (GObject *object,
self->priv->location = g_value_dup_object (value);
break;
+ case PROP_ERROR:
+ self->priv->error = g_value_get_pointer (value);
+ break;
+
case PROP_COLOR:
color = g_value_get_pointer (value);
self->priv->color.red = color->red;
@@ -363,12 +358,31 @@ static void
biji_note_book_constructed (GObject *object)
{
BijiNoteBook *self;
+ BijiNoteBookPrivate *priv;
BijiProvider *provider;
gchar *filename;
GFile *cache;
+ GError *error;
+
G_OBJECT_CLASS (biji_note_book_parent_class)->constructed (object);
self = BIJI_NOTE_BOOK (object);
+ priv = self->priv;
+ error = NULL;
+
+ /* If tracker fails for some reason,
+ * do not attempt anything */
+ priv->connection = tracker_sparql_connection_get (NULL, &error);
+
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ priv->error = g_error_new (BIJI_ERROR, BIJI_ERROR_TRACKER, "Tracker is not available");
+ return;
+ }
+
+ priv->log = biji_zeitgeist_init ();
/* Ensure cache directory for icons */
filename = g_build_filename (g_get_user_cache_dir (),
@@ -415,6 +429,12 @@ biji_note_book_class_init (BijiNoteBookClass *klass)
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_ERROR] =
+ g_param_spec_pointer ("error",
+ "Unrecoverable error",
+ "Note book unrecoverable error",
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+
g_object_class_install_properties (object_class, BIJI_BOOK_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (BijiNoteBookPrivate));
}
@@ -504,13 +524,20 @@ biji_note_book_get_item_at_path (BijiNoteBook *book, const gchar *path)
return g_hash_table_lookup (book->priv->items, (gconstpointer) path);
}
+
BijiNoteBook *
-biji_note_book_new (GFile *location, GdkRGBA *color)
+biji_note_book_new (GFile *location, GdkRGBA *color, GError **error)
{
- return g_object_new(BIJI_TYPE_NOTE_BOOK,
- "location", location,
- "color", color,
- NULL);
+ BijiNoteBook *retval;
+
+ retval = g_object_new (BIJI_TYPE_NOTE_BOOK,
+ "location", location,
+ "color", color,
+ "error", *error,
+ NULL);
+
+ *error = retval->priv->error;
+ return retval;
}
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index b3b5bbe..92606ad 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -51,7 +51,8 @@ GType biji_note_book_get_type (void) G_GNUC_CONST;
BijiNoteBook *biji_note_book_new (GFile *location,
- GdkRGBA *color);
+ GdkRGBA *color,
+ GError **error);
void biji_note_book_add_goa_object (BijiNoteBook *book,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]