[bijiben] BjbController: own a reference to window, not to GdMainView
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] BjbController: own a reference to window, not to GdMainView
- Date: Wed, 24 Apr 2013 22:04:35 +0000 (UTC)
commit 4342a8bb8357b3362277a2857748c687f4b3675c
Author: Pierre-Yves Luyten <py luyten fr>
Date: Wed Apr 24 22:10:35 2013 +0200
BjbController: own a reference to window, not to GdMainView
The controller has to work with the BjbWindowBase
src/bjb-controller.c | 78 ++++++++++++++++++++++++++----------------------
src/bjb-controller.h | 13 ++++----
src/bjb-main-view.c | 7 ++--
src/bjb-window-base.c | 3 +-
src/bjb-window-base.h | 1 -
5 files changed, 53 insertions(+), 49 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index aae48d4..151c7d5 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -16,13 +16,17 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ * bjb-controler is window-wide.
+ * mainly useful for BjbMainView,
+ * it controls the window behaviour.
+ */
+
#include <libgd/gd.h>
#include "bjb-controller.h"
#include "bjb-main-view.h"
#include "bjb-window-base.h"
-#include "utils/bjb-icons-colors.h"
-
/* Gobject */
@@ -33,14 +37,7 @@ struct _BjbControllerPrivate
GtkTreeModel *model ;
GtkTreeModel *completion;
- /* Optional
- * Currently Controller is window-wide, in order to live while
- * going from main view to note view.
- * But not app-wide : each win has its controller & needle.
- *
- * gd-main-view is setup by main-view to allow choosing pixbuf
- * according to grid / list view mode */
- GdMainView *cur;
+ BjbWindowBase *window;
/* Private */
GList *notes_to_show ;
@@ -50,9 +47,10 @@ struct _BjbControllerPrivate
enum {
PROP_0,
- PROP_BOOK ,
- PROP_NEEDLE ,
- PROP_MODEL ,
+ PROP_BOOK,
+ PROP_WINDOW,
+ PROP_NEEDLE,
+ PROP_MODEL,
NUM_PROPERTIES
};
@@ -143,6 +141,9 @@ bjb_controller_get_property (GObject *object,
case PROP_BOOK:
g_value_set_object (value, self->priv->book);
break;
+ case PROP_WINDOW:
+ g_value_set_object (value, self->priv->window);
+ break;
case PROP_NEEDLE:
g_value_set_string(value, self->priv->needle);
break;
@@ -168,6 +169,9 @@ bjb_controller_set_property (GObject *object,
case PROP_BOOK:
bjb_controller_set_book(self,g_value_get_object(value));
break;
+ case PROP_WINDOW:
+ self->priv->window = g_value_get_object (value);
+ break;
case PROP_NEEDLE:
bjb_controller_set_needle(self,g_value_get_string(value));
break;
@@ -199,18 +203,15 @@ bjb_controller_add_note (BjbController *self,
/* Only append notes which are not templates. Currently useless */
if ( biji_note_obj_is_template (note) == FALSE)
{
-
/* First , if there is a gd main view , and if gd main view
- * is a list, then load the 16x16 note pixbuf
- * This is probably not correct but allows a nice list view */
- if (self->priv->cur)
- {
- if (gd_main_view_get_view_type (self->priv->cur) == GD_MAIN_VIEW_LIST)
- pix = biji_note_obj_get_emblem (note);
- }
-
- /* If no gd-main-view or if not list view,
- * load the icon for grid */
+ * is a list, then load the smaller emblem */
+ if (bjb_window_base_get_view_type (self->priv->window) == BJB_WINDOW_BASE_MAIN_VIEW
+ && bjb_window_base_get_main_view (self->priv->window)
+ && bjb_main_view_get_view_type
+ (bjb_window_base_get_main_view (self->priv->window)) == GD_MAIN_VIEW_LIST)
+ pix = biji_note_obj_get_emblem (note);
+
+ /* Else, load the icon */
if (!pix)
pix = biji_note_obj_get_icon (note);
@@ -295,7 +296,7 @@ bjb_controller_update_view (BjbController *self)
GList *notes, *l;
/* Do not update if nothing to show */
- if (!self->priv->cur)
+ if (bjb_window_base_get_view_type (self->priv->window) != BJB_WINDOW_BASE_MAIN_VIEW)
return;
notes = self->priv->notes_to_show ;
@@ -470,7 +471,8 @@ on_book_changed (BijiNoteBook *book,
/* If color changed we just amend the icon */
case BIJI_BOOK_NOTE_COLORED:
- if (gd_main_view_get_view_type (priv->cur) == GD_MAIN_VIEW_ICON
+ if (bjb_main_view_get_view_type (
+ bjb_window_base_get_main_view (self->priv->window)) == GD_MAIN_VIEW_ICON
&& bjb_controller_get_iter_at_note (self, note, &p_iter))
gtk_list_store_set (GTK_LIST_STORE (priv->model), p_iter,
GD_MAIN_COLUMN_ICON, biji_note_obj_get_icon (note), -1);
@@ -503,6 +505,8 @@ bjb_controller_connect (BjbController *self)
G_CALLBACK(on_book_changed), self);
priv->connected = TRUE;
}
+
+ bjb_controller_update_view (self);
}
void
@@ -560,6 +564,14 @@ bjb_controller_class_init (BjbControllerClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
+ properties[PROP_WINDOW] = g_param_spec_object ("window",
+ "GtkWindow",
+ "BjbWindowBase",
+ BJB_TYPE_WINDOW_BASE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
properties[PROP_NEEDLE] = g_param_spec_string ("needle",
"Needle",
"String to search notes",
@@ -581,11 +593,13 @@ bjb_controller_class_init (BjbControllerClass *klass)
}
BjbController *
-bjb_controller_new (BijiNoteBook *book,
- gchar *needle)
+bjb_controller_new (BijiNoteBook *book,
+ GtkWindow *window,
+ gchar *needle)
{
return g_object_new ( BJB_TYPE_CONTROLLER,
"book", book,
+ "window", window,
"needle", needle,
NULL);
}
@@ -631,14 +645,6 @@ bjb_controller_get_completion(BjbController *self)
return self->priv->completion ;
}
-void
-bjb_controller_set_main_view (BjbController *self, GdMainView *current)
-{
- /* Refresh the model */
- self->priv->cur = current;
- bjb_controller_update_view (self);
-}
-
gboolean
bjb_controller_shows_notes (BjbController *self)
{
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index 7c03237..fee1d74 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -23,7 +23,6 @@
#include <libbiji/libbiji.h>
#include <libgd/gd-main-view.h>
-
G_BEGIN_DECLS
#define BJB_TYPE_CONTROLLER (bjb_controller_get_type ())
@@ -40,20 +39,22 @@ typedef struct _BjbControllerPrivate BjbControllerPrivate;
struct _BjbControllerClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
struct _BjbController
{
- GObject parent_instance;
+ GObject parent_instance;
- BjbControllerPrivate *priv;
+ BjbControllerPrivate *priv;
};
GType bjb_controller_get_type (void) G_GNUC_CONST;
-BjbController * bjb_controller_new ( BijiNoteBook *book, gchar *needle ) ;
+BjbController * bjb_controller_new (BijiNoteBook *book,
+ GtkWindow *bjb_window_base,
+ gchar *needle);
void bjb_controller_apply_needle (BjbController *self);
@@ -73,8 +74,6 @@ void bjb_controller_connect (BjbController *self);
void bjb_controller_disconnect (BjbController *self);
-void bjb_controller_set_main_view (BjbController *self, GdMainView *current);
-
gboolean bjb_controller_shows_notes (BjbController *self);
G_END_DECLS
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 3ffb5f7..de932a5 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -520,7 +520,6 @@ bjb_main_view_constructed(GObject *o)
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
priv->view = gd_main_view_new (DEFAULT_VIEW);
- bjb_controller_set_main_view (priv->controller, priv->view);
/* Search entry toolbar */
priv->search_bar = bjb_search_toolbar_new (priv->window, priv->controller);
@@ -611,9 +610,9 @@ void
bjb_main_view_update_model (BjbMainView *self)
{
BjbMainViewPriv *priv = self->priv;
-
- bjb_controller_set_main_view (priv->controller,priv->view);
- gd_main_view_set_model(priv->view,bjb_controller_get_model(priv->controller));
+
+ bjb_controller_update_view (priv->controller);
+ gd_main_view_set_model (priv->view, bjb_controller_get_model (priv->controller));
}
BjbSearchToolbar *
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 19ab10a..e94e96b 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -190,12 +190,13 @@ bjb_window_base_new(void)
"hide-titlebar-when-maximized", TRUE,
NULL);
- /* Rather dirty to finish UI there. maybe bjb_w_b_set_controller */
+ /* Rather dirty to finish UI there */
priv = retval->priv;
priv->controller = bjb_controller_new
(bijiben_get_book (BIJIBEN_APPLICATION(g_application_get_default())),
+ GTK_WINDOW (retval),
priv->entry );
/* Shared toolbar */
diff --git a/src/bjb-window-base.h b/src/bjb-window-base.h
index 6d6d4ac..c2273e2 100644
--- a/src/bjb-window-base.h
+++ b/src/bjb-window-base.h
@@ -4,7 +4,6 @@
#include <gtk/gtk.h>
#include <libbiji/libbiji.h>
-#include "bjb-settings.h"
#include "bjb-controller.h"
#define BJB_TYPE_WINDOW_BASE (bjb_window_base_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]