[gnome-photos] embed, main-toolbar: Don't use ViewModel to enable/disable the buttons
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] embed, main-toolbar: Don't use ViewModel to enable/disable the buttons
- Date: Mon, 5 Dec 2016 12:59:41 +0000 (UTC)
commit 9f749767ac233270ffc58e423e83f09511bc2434
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Dec 3 10:52:03 2016 +0100
embed, main-toolbar: Don't use ViewModel to enable/disable the buttons
Taking the ViewContainer's ViewModel and passing it to the MainToolbar
was an ugly thing to do in the first place. Now that every mode has a
separate PhotosBaseManager, which acts as a GListModel, we can do this
in a better.
This further reduces our use of PhotosViewModel and clears the way for
the GtkFlowBox port.
https://bugzilla.gnome.org/show_bug.cgi?id=775562
src/photos-embed.c | 50 +++-----------------------------------------
src/photos-main-toolbar.c | 40 +++++++++++++++++++++++++----------
src/photos-main-toolbar.h | 3 --
3 files changed, 32 insertions(+), 61 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index c04b4f4..1065523 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -470,28 +470,6 @@ photos_embed_query_status_changed (PhotosEmbed *self, gboolean querying)
static void
-photos_embed_row_changed (PhotosEmbed *self)
-{
- PhotosWindowMode mode;
-
- mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-
- if (mode == PHOTOS_WINDOW_MODE_COLLECTIONS
- || mode == PHOTOS_WINDOW_MODE_FAVORITES
- || mode == PHOTOS_WINDOW_MODE_OVERVIEW
- || mode == PHOTOS_WINDOW_MODE_SEARCH)
- {
- GtkListStore *model;
- GtkWidget *view_container;
-
- view_container = photos_embed_get_view_container_from_mode (self, mode);
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (view_container));
- photos_main_toolbar_set_view_model (PHOTOS_MAIN_TOOLBAR (self->toolbar), PHOTOS_VIEW_MODEL (model));
- }
-}
-
-
-static void
photos_embed_search_changed (PhotosEmbed *self)
{
GObject *object;
@@ -541,8 +519,6 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
gpointer user_data)
{
PhotosEmbed *self = PHOTOS_EMBED (user_data);
- GtkListStore *model;
- GtkWidget *view_container;
photos_main_toolbar_reset_toolbar_mode (PHOTOS_MAIN_TOOLBAR (self->toolbar));
@@ -553,15 +529,15 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
case PHOTOS_WINDOW_MODE_COLLECTIONS:
photos_embed_prepare_for_collections (self, old_mode);
- goto set_toolbar_model;
+ break;
case PHOTOS_WINDOW_MODE_FAVORITES:
photos_embed_prepare_for_favorites (self, old_mode);
- goto set_toolbar_model;
+ break;
case PHOTOS_WINDOW_MODE_OVERVIEW:
photos_embed_prepare_for_overview (self, old_mode);
- goto set_toolbar_model;
+ break;
case PHOTOS_WINDOW_MODE_PREVIEW:
photos_embed_prepare_for_preview (self, old_mode);
@@ -569,7 +545,7 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
case PHOTOS_WINDOW_MODE_SEARCH:
photos_embed_prepare_for_search (self, old_mode);
- goto set_toolbar_model;
+ break;
case PHOTOS_WINDOW_MODE_NONE:
default:
@@ -578,11 +554,6 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
}
return;
-
- set_toolbar_model:
- view_container = photos_embed_get_view_container_from_mode (self, mode);
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (view_container));
- photos_main_toolbar_set_view_model (PHOTOS_MAIN_TOOLBAR (self->toolbar), PHOTOS_VIEW_MODEL (model));
}
@@ -611,7 +582,6 @@ photos_embed_init (PhotosEmbed *self)
{
GApplication *app;
GList *windows;
- GtkListStore *model;
PhotosSearchbar *searchbar;
PhotosSearchContextState *state;
gboolean querying;
@@ -653,29 +623,17 @@ photos_embed_init (PhotosEmbed *self)
self->overview = photos_view_container_new (PHOTOS_WINDOW_MODE_OVERVIEW, _("Photos"));
name = photos_view_container_get_name (PHOTOS_VIEW_CONTAINER (self->overview));
gtk_stack_add_titled (GTK_STACK (self->stack), self->overview, "overview", name);
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (self->overview));
- g_signal_connect_object (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
self->collections = photos_view_container_new (PHOTOS_WINDOW_MODE_COLLECTIONS, _("Albums"));
name = photos_view_container_get_name (PHOTOS_VIEW_CONTAINER (self->collections));
gtk_stack_add_titled (GTK_STACK (self->stack), self->collections, "collections", name);
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (self->collections));
- g_signal_connect_object (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
self->favorites = photos_view_container_new (PHOTOS_WINDOW_MODE_FAVORITES, _("Favorites"));
name = photos_view_container_get_name (PHOTOS_VIEW_CONTAINER (self->favorites));
gtk_stack_add_titled (GTK_STACK (self->stack), self->favorites, "favorites", name);
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (self->favorites));
- g_signal_connect_object (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
self->search = photos_view_container_new (PHOTOS_WINDOW_MODE_SEARCH, _("Search"));
gtk_stack_add_named (GTK_STACK (self->stack), self->search, "search");
- model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (self->search));
- g_signal_connect_object (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self,
G_CONNECT_SWAPPED);
self->preview = photos_preview_view_new (GTK_OVERLAY (self->stack_overlay));
gtk_stack_add_named (GTK_STACK (self->stack), self->preview, "preview");
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 9e83296..78c1208 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -282,6 +282,28 @@ photos_main_toolbar_item_active_changed (PhotosMainToolbar *self, GObject *objec
static void
+photos_main_toolbar_items_changed (PhotosMainToolbar *self)
+{
+ PhotosBaseManager *item_mngr_chld;
+ PhotosWindowMode window_mode;
+ gboolean is_empty;
+ guint n_items;
+
+ window_mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+ if (window_mode == PHOTOS_WINDOW_MODE_NONE)
+ return;
+
+ item_mngr_chld = photos_item_manager_get_for_mode (PHOTOS_ITEM_MANAGER (self->item_mngr), window_mode);
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
+
+ is_empty = n_items == 0;
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (self->search), !is_empty);
+ if (self->selection_button != NULL)
+ gtk_widget_set_sensitive (self->selection_button, !is_empty);
+}
+
+
+static void
photos_main_toolbar_select_button_clicked (PhotosMainToolbar *self)
{
photos_selection_controller_set_selection_mode (self->sel_cntrlr, TRUE);
@@ -748,6 +770,11 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
photos_header_bar_set_selection_menu (PHOTOS_HEADER_BAR (self->toolbar), GTK_BUTTON
(self->selection_menu));
self->item_mngr = g_object_ref (state->item_mngr);
+ g_signal_connect_object (self->item_mngr,
+ "items-changed",
+ G_CALLBACK (photos_main_toolbar_items_changed),
+ self,
+ G_CONNECT_SWAPPED);
self->mode_cntrlr = g_object_ref (state->mode_cntrlr);
@@ -852,6 +879,7 @@ photos_main_toolbar_reset_toolbar_mode (PhotosMainToolbar *self)
else if (window_mode == PHOTOS_WINDOW_MODE_SEARCH)
photos_main_toolbar_populate_for_search (self);
+ photos_main_toolbar_items_changed (self);
photos_main_toolbar_update_remote_display_button (self);
photos_main_toolbar_set_toolbar_title (self);
@@ -864,15 +892,3 @@ photos_main_toolbar_set_stack (PhotosMainToolbar *self, GtkStack *stack)
{
photos_header_bar_set_stack (PHOTOS_HEADER_BAR (self->toolbar), stack);
}
-
-
-void
-photos_main_toolbar_set_view_model (PhotosMainToolbar *self, PhotosViewModel *model)
-{
- gboolean is_empty;
-
- is_empty = (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 0);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (self->search), !is_empty);
- if (self->selection_button != NULL)
- gtk_widget_set_sensitive (self->selection_button, !is_empty);
-}
diff --git a/src/photos-main-toolbar.h b/src/photos-main-toolbar.h
index c87af78..3d634ca 100644
--- a/src/photos-main-toolbar.h
+++ b/src/photos-main-toolbar.h
@@ -28,7 +28,6 @@
#include <gtk/gtk.h>
#include "photos-searchbar.h"
-#include "photos-view-model.h"
G_BEGIN_DECLS
@@ -59,8 +58,6 @@ void photos_main_toolbar_reset_toolbar_mode (PhotosMainToo
void photos_main_toolbar_set_stack (PhotosMainToolbar *self, GtkStack *stack);
-void photos_main_toolbar_set_view_model (PhotosMainToolbar *self, PhotosViewModel
*model);
-
G_END_DECLS
#endif /* PHOTOS_MAIN_TOOLBAR_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]