[bijiben: 10/11] Collections: initial view implementation
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben: 10/11] Collections: initial view implementation
- Date: Sun, 28 Apr 2013 23:15:07 +0000 (UTC)
commit 1f1a30d48e9af03d6674d63d7576cc43687285de
Author: Pierre-Yves Luyten <py luyten fr>
Date: Mon Apr 29 00:15:04 2013 +0200
Collections: initial view implementation
The collection can be seen and user can simply go back
src/bjb-controller.c | 62 ++++++++++++++++++++++++++++++++-
src/bjb-controller.h | 4 ++
src/bjb-main-toolbar.c | 84 +++++++++++++++++++++++++++++++------------
src/bjb-main-view.c | 8 ++++-
src/libbiji/biji-tracker.c | 70 ++++++++++++++++++++++++++++++++++++-
src/libbiji/biji-tracker.h | 8 ++++
6 files changed, 209 insertions(+), 27 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index fdd6af6..8c7ad5f 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -34,6 +34,7 @@ struct _BjbControllerPrivate
{
BijiNoteBook *book ;
gchar *needle ;
+ gchar *collection;
GtkTreeModel *model ;
GtkTreeModel *completion;
@@ -96,6 +97,7 @@ bjb_controller_init (BjbController *self)
priv->model = GTK_TREE_MODEL(store) ;
priv->items_to_show = NULL;
priv->needle = NULL;
+ priv->collection = NULL;
priv->connected = FALSE;
completion = gtk_list_store_new (1, G_TYPE_STRING);
@@ -121,6 +123,9 @@ bjb_controller_finalize (GObject *object)
g_free (priv->needle);
g_list_free (priv->items_to_show);
+ if (priv->collection)
+ g_free (priv->collection);
+
G_OBJECT_CLASS (bjb_controller_parent_class)->finalize (object);
}
@@ -363,7 +368,7 @@ update_controller_callback (GObject *source_object,
self->priv->items_to_show = result;
sort_and_update (self);
-}
+}
void
bjb_controller_apply_needle (BjbController *self)
@@ -694,3 +699,58 @@ bjb_controller_shows_item (BjbController *self)
return FALSE;
}
+
+static void
+bjb_controller_show_collection (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GList *result;
+ BjbController *self = BJB_CONTROLLER (user_data);
+
+ result = biji_get_items_with_collection_finish (source_object, res, self->priv->book);
+ self->priv->items_to_show = result;
+
+ sort_and_update (self);
+ bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_MAIN_VIEW);
+}
+
+gchar *
+bjb_controller_get_collection (BjbController *self)
+{
+ return self->priv->collection;
+}
+
+void
+bjb_controller_set_collection (BjbController *self,
+ gchar *to_open)
+{
+ /* Going back from a collection */
+ if (!to_open)
+ {
+ if (!self->priv->collection)
+ return;
+
+ bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_SPINNER_VIEW);
+ g_clear_pointer (&self->priv->collection, g_free);
+ bjb_controller_apply_needle (self);
+ bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_MAIN_VIEW);
+ return;
+ }
+
+ /* Opening an __existing__ collection */
+ bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_SPINNER_VIEW);
+ g_list_free (self->priv->items_to_show);
+
+ if (self->priv->needle)
+ g_free (self->priv->needle);
+
+ if (self->priv->collection)
+ g_free (self->priv->collection);
+
+ self->priv->needle = g_strdup ("");
+ self->priv->collection = g_strdup (to_open);
+ biji_get_items_with_collection_async (to_open,
+ bjb_controller_show_collection,
+ self);
+}
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index 21acb07..6157a39 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -76,6 +76,10 @@ void bjb_controller_disconnect (BjbController *self);
gboolean bjb_controller_shows_item (BjbController *self);
+gchar * bjb_controller_get_collection (BjbController *self);
+
+void bjb_controller_set_collection (BjbController *self, gchar *to_open);
+
G_END_DECLS
#endif /* _BJB_CONTROLLER_H_ */
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 8b023b9..ab6caa1 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -277,10 +277,15 @@ static void
update_label_for_standard (BjbMainToolbar *self)
{
BjbMainToolbarPrivate *priv = self->priv;
- gchar *needle = bjb_controller_get_needle (priv->controller);
- gchar *label ;
+ gchar *collection, *needle, *label;
- if (needle && g_strcmp0 (needle, "") !=0)
+ collection = bjb_controller_get_collection (priv->controller);
+ needle = bjb_controller_get_needle (priv->controller);
+
+ if (collection)
+ label = g_strdup_printf ("%s", collection);
+
+ else if (needle && g_strcmp0 (needle, "") !=0)
label = g_strdup_printf (_("Results for %s"), needle);
else
@@ -309,33 +314,58 @@ connect_main_view_handlers (BjbMainToolbar *self)
}
static void
+on_back_button_clicked (BjbMainToolbar *self)
+{
+ bjb_controller_set_collection (self->priv->controller, NULL);
+}
+
+static void
populate_bar_for_standard(BjbMainToolbar *self)
{
BjbMainToolbarPrivate *priv = self->priv;
GtkWidget *bin = NULL;
+ gchar *collection;
/* Label */
update_label_for_standard (self);
priv->search_handler = g_signal_connect_swapped (priv->controller,
"search-changed", G_CALLBACK(update_label_for_standard), self);
- /* New Note button */
- priv->new = gd_main_toolbar_add_button(GD_MAIN_TOOLBAR (self),
- NULL,
- _("New"),
- TRUE);
- gtk_widget_set_size_request (priv->new, 70, -1);
- bin = gtk_bin_get_child (GTK_BIN (priv->new));
+ /* Go back to all notes */
+ collection = bjb_controller_get_collection (priv->controller);
- if (bin)
+ if (collection)
{
- gint y_padding = 0;
- gtk_misc_get_padding (GTK_MISC (bin), NULL, &y_padding);
- gtk_misc_set_padding (GTK_MISC (bin), 12, y_padding);
+ GtkWidget *back, *button;
+
+ back = get_icon ("go-previous-symbolic");
+ button = gd_main_toolbar_add_button (GD_MAIN_TOOLBAR (self), NULL, NULL, TRUE);
+ gtk_container_add (GTK_CONTAINER (button), back);
+
+ g_signal_connect_swapped (button, "clicked",
+ G_CALLBACK (on_back_button_clicked), self);
}
- g_signal_connect(priv->new,"clicked",
- G_CALLBACK(on_new_note_clicked),priv->parent);
+ /* New Note button */
+ else
+ {
+ priv->new = gd_main_toolbar_add_button(GD_MAIN_TOOLBAR (self),
+ NULL,
+ _("New"),
+ TRUE);
+ gtk_widget_set_size_request (priv->new, 70, -1);
+ bin = gtk_bin_get_child (GTK_BIN (priv->new));
+
+ if (bin)
+ {
+ gint y_padding = 0;
+ gtk_misc_get_padding (GTK_MISC (bin), NULL, &y_padding);
+ gtk_misc_set_padding (GTK_MISC (bin), 12, y_padding);
+ }
+
+ g_signal_connect(priv->new,"clicked",
+ G_CALLBACK(on_new_note_clicked),priv->parent);
+ }
/* Go to selection mode */
priv->select = gd_main_toolbar_add_button(GD_MAIN_TOOLBAR (self),
@@ -695,9 +725,9 @@ populate_bar_switch(BjbMainToolbar *self)
populate_bar_for_note_view (self);
break;
+ /* Spinner, Empty Results */
default:
- g_warning ("Main Toolbar implementation is erroneous.\
- Please fill in a bug report");
+ break;
}
gtk_widget_show_all (GTK_WIDGET (self));
@@ -715,14 +745,20 @@ populate_main_toolbar(BjbMainToolbar *self)
if (view_type == BJB_WINDOW_BASE_NOTE_VIEW)
to_be = BJB_TOOLBAR_NOTE_VIEW;
- else if (bjb_main_view_get_selection_mode (priv->parent) == TRUE)
- to_be = BJB_TOOLBAR_SELECT;
+ else if (view_type == BJB_WINDOW_BASE_MAIN_VIEW)
+ {
+ if (bjb_main_view_get_selection_mode (priv->parent) == TRUE)
+ to_be = BJB_TOOLBAR_SELECT;
- else if (bjb_main_view_get_view_type (priv->parent) == GD_MAIN_VIEW_ICON)
- to_be = BJB_TOOLBAR_STD_ICON;
+ if (bjb_main_view_get_view_type (priv->parent) == GD_MAIN_VIEW_ICON)
+ to_be = BJB_TOOLBAR_STD_ICON;
- else if (bjb_main_view_get_view_type (priv->parent) == GD_MAIN_VIEW_LIST)
- to_be = BJB_TOOLBAR_STD_LIST;
+ else if (bjb_main_view_get_view_type (priv->parent) == GD_MAIN_VIEW_LIST)
+ to_be = BJB_TOOLBAR_STD_LIST;
+ }
+
+ else
+ to_be = BJB_TOOLBAR_0;
/* Simply clear then populate */
if (to_be != priv->type)
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 40ba9d8..4441dd3 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -219,7 +219,13 @@ switch_to_note (BjbMainView *view, BijiItem *to_open)
switch_to_note_view (view, BIJI_NOTE_OBJ (to_open));
}
- /* TODO : coll */
+ /* Collection
+ * TODO : check if already opened (same as above) */
+ else
+ {
+ bjb_controller_set_collection (view->priv->controller,
+ biji_item_get_title (to_open));
+ }
}
static GList *
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index c7db623..fc97543 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -199,6 +199,74 @@ biji_get_all_collections_async (GAsyncReadyCallback f,
}
GList *
+biji_get_items_with_collection_finish (GObject *source_object,
+ GAsyncResult *res,
+ BijiNoteBook *book)
+{
+ TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ GList *result = NULL;
+
+ cursor = tracker_sparql_connection_query_finish (self, res, &error);
+
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (cursor)
+ {
+ const gchar *full_path;
+ gchar *path;
+ BijiItem *item = NULL;
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL))
+ {
+ full_path = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+
+ if (g_str_has_prefix (full_path, "file://"))
+ {
+ GString *string;
+ string = g_string_new (full_path);
+ g_string_erase (string, 0, 7);
+ path = g_string_free (string, FALSE);
+ }
+ else
+ {
+ path = g_strdup (full_path);
+ }
+
+ item = biji_note_book_get_item_at_path (book, path);
+
+ /* Sorting is done in another place */
+ if (item)
+ result = g_list_prepend (result, item);
+
+ g_free (path);
+ }
+
+ g_object_unref (cursor);
+ }
+
+ return result;
+}
+
+void
+biji_get_items_with_collection_async (gchar *collection,
+ GAsyncReadyCallback f,
+ gpointer user_data)
+{
+ gchar *query;
+
+ query = g_strdup_printf ("SELECT ?s WHERE {?c nie:isPartOf ?s; nie:title '%s'}",
+ collection);
+
+ bjb_perform_query_async (query, f, user_data);
+}
+
+GList *
biji_get_notes_with_strings_or_collection_finish (GObject *source_object,
GAsyncResult *res,
BijiNoteBook *book)
@@ -237,7 +305,7 @@ biji_get_notes_with_strings_or_collection_finish (GObject *source_object,
{
path = g_strdup (full_path);
}
-
+
item = biji_note_book_get_item_at_path (book, path);
/* Sorting is done in another place */
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 41b3f5a..6e75a47 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -27,6 +27,14 @@
/* todo : find this on glib */
typedef void (*BijiFunc) (gpointer user_data);
+GList * biji_get_items_with_collection_finish (GObject *source_object,
+ GAsyncResult *res,
+ BijiNoteBook *book);
+
+void biji_get_items_with_collection_async (gchar *needle,
+ GAsyncReadyCallback f,
+ gpointer user_data);
+
/* All notes matching (either content or collections) */
GList * biji_get_notes_with_strings_or_collection_finish (GObject *source_object,
GAsyncResult *res,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]