[gnome-photos] Selection and search should be disabled when there are no photos
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Selection and search should be disabled when there are no photos
- Date: Wed, 12 Mar 2014 08:58:56 +0000 (UTC)
commit 51f5a0ed212e232882ca201ad1b562a2158daf7d
Author: Saurav Agarwalla <saurav agarwalla92 gmail com>
Date: Thu Mar 6 19:35:07 2014 +0530
Selection and search should be disabled when there are no photos
Since the visibility of toolbar buttons now depend on the current
PhotosViewModel, we need to reset the toolbar and set the model in a
well defined order. Therefore we reset the toolbar from PhotosEmbed
before setting the model, instead of having it separately listen to
ModeController::window-mode-changed.
https://bugzilla.gnome.org/show_bug.cgi?id=725587
src/photos-embed.c | 68 ++++++++++++++++++++++++++----
src/photos-main-toolbar.c | 100 ++++++++++++++++++++++++++------------------
src/photos-main-toolbar.h | 5 ++
3 files changed, 123 insertions(+), 50 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index d2844d0..d54bfa2 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -2,6 +2,7 @@
* Photos - access, organize and share your photos on GNOME
* Copyright © 2014 Pranav Kant
* Copyright © 2012, 2013, 2014 Red Hat, Inc.
+ * Copyright © 2014 Saurav Agarwalla
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -536,6 +537,29 @@ photos_embed_query_status_changed (PhotosEmbed *self, gboolean querying)
static void
+photos_embed_row_changed (PhotosEmbed *self)
+{
+ PhotosEmbedPrivate *priv = self->priv;
+ PhotosWindowMode mode;
+
+ mode = photos_mode_controller_get_window_mode (priv->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 (priv->toolbar), PHOTOS_VIEW_MODEL (model));
+ }
+}
+
+
+static void
photos_embed_search_changed (PhotosEmbed *self)
{
PhotosEmbedPrivate *priv = self->priv;
@@ -586,17 +610,30 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
gpointer user_data)
{
PhotosEmbed *self = PHOTOS_EMBED (user_data);
+ PhotosEmbedPrivate *priv = self->priv;
- if (mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
- photos_embed_prepare_for_collections (self);
- else if (mode == PHOTOS_WINDOW_MODE_FAVORITES)
- photos_embed_prepare_for_favorites (self);
- else if (mode == PHOTOS_WINDOW_MODE_OVERVIEW)
- photos_embed_prepare_for_overview (self);
- else if (mode == PHOTOS_WINDOW_MODE_SEARCH)
- photos_embed_prepare_for_search (self);
- else
+ photos_main_toolbar_reset_toolbar_mode (PHOTOS_MAIN_TOOLBAR (priv->toolbar));
+
+ if (mode == PHOTOS_WINDOW_MODE_PREVIEW)
photos_embed_prepare_for_preview (self);
+ else
+ {
+ GtkListStore *model;
+ GtkWidget *view_container;
+
+ if (mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
+ photos_embed_prepare_for_collections (self);
+ else if (mode == PHOTOS_WINDOW_MODE_FAVORITES)
+ photos_embed_prepare_for_favorites (self);
+ else if (mode == PHOTOS_WINDOW_MODE_OVERVIEW)
+ photos_embed_prepare_for_overview (self);
+ else if (mode == PHOTOS_WINDOW_MODE_SEARCH)
+ photos_embed_prepare_for_search (self);
+
+ 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 (priv->toolbar), PHOTOS_VIEW_MODEL (model));
+ }
}
@@ -646,6 +683,7 @@ photos_embed_init (PhotosEmbed *self)
{
PhotosEmbedPrivate *priv;
GApplication *app;
+ GtkListStore *model;
PhotosSearchbar *searchbar;
PhotosSearchContextState *state;
gboolean querying;
@@ -687,15 +725,27 @@ photos_embed_init (PhotosEmbed *self)
priv->overview = photos_view_container_new (PHOTOS_WINDOW_MODE_OVERVIEW);
gtk_stack_add_titled (GTK_STACK (priv->stack), priv->overview, "overview", _("Recent"));
+ model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (priv->overview));
+ g_signal_connect_swapped (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self);
+ g_signal_connect_swapped (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self);
priv->collections = photos_view_container_new (PHOTOS_WINDOW_MODE_COLLECTIONS);
gtk_stack_add_titled (GTK_STACK (priv->stack), priv->collections, "collections", _("Albums"));
+ model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (priv->collections));
+ g_signal_connect_swapped (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self);
+ g_signal_connect_swapped (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self);
priv->favorites = photos_view_container_new (PHOTOS_WINDOW_MODE_FAVORITES);
gtk_stack_add_titled (GTK_STACK (priv->stack), priv->favorites, "favorites", _("Favorites"));
+ model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (priv->favorites));
+ g_signal_connect_swapped (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self);
+ g_signal_connect_swapped (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self);
priv->search = photos_view_container_new (PHOTOS_WINDOW_MODE_SEARCH);
gtk_stack_add_named (GTK_STACK (priv->stack), priv->search, "search");
+ model = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (priv->search));
+ g_signal_connect_swapped (model, "row-inserted", G_CALLBACK (photos_embed_row_changed), self);
+ g_signal_connect_swapped (model, "row-deleted", G_CALLBACK (photos_embed_row_changed), self);
priv->preview = photos_preview_view_new (GTK_OVERLAY (priv->stack_overlay));
gtk_stack_add_named (GTK_STACK (priv->stack), priv->preview, "preview");
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 061aa17..d9c9601 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -1,6 +1,7 @@
/*
* Photos - access, organize and share your photos on GNOME
* Copyright © 2012, 2013, 2014 Red Hat, Inc.
+ * Copyright © 2014 Saurav Agarwalla
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -52,6 +53,7 @@ struct _PhotosMainToolbarPrivate
GtkWidget *overlay;
GtkWidget *remote_display_button;
GtkWidget *searchbar;
+ GtkWidget *selection_button;
GtkWidget *selection_menu;
GtkWidget *toolbar;
PhotosBaseManager *col_mngr;
@@ -287,7 +289,7 @@ photos_main_toolbar_add_search_button (PhotosMainToolbar *self)
}
-static void
+static GtkWidget *
photos_main_toolbar_add_selection_button (PhotosMainToolbar *self)
{
PhotosMainToolbarPrivate *priv = self->priv;
@@ -304,6 +306,8 @@ photos_main_toolbar_add_selection_button (PhotosMainToolbar *self)
G_CALLBACK (photos_main_toolbar_col_active_changed),
self,
0);
+
+ return selection_button;
}
@@ -335,6 +339,12 @@ photos_main_toolbar_clear_state_data (PhotosMainToolbar *self)
priv->remote_display_button = NULL;
}
+ if (priv->selection_button != NULL)
+ {
+ gtk_widget_destroy (priv->selection_button);
+ priv->selection_button = NULL;
+ }
+
if (priv->searchbar != NULL && gtk_widget_get_parent (priv->searchbar) == GTK_WIDGET (self))
{
GVariant *state;
@@ -435,7 +445,7 @@ photos_main_toolbar_populate_for_collections (PhotosMainToolbar *self)
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->toolbar), TRUE);
photos_header_bar_set_mode (PHOTOS_HEADER_BAR (priv->toolbar), PHOTOS_HEADER_BAR_MODE_NORMAL);
- photos_main_toolbar_add_selection_button (self);
+ priv->selection_button = photos_main_toolbar_add_selection_button (self);
photos_main_toolbar_add_search_button (self);
if (gtk_widget_get_parent (priv->searchbar) == NULL)
@@ -472,7 +482,7 @@ photos_main_toolbar_populate_for_favorites (PhotosMainToolbar *self)
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->toolbar), TRUE);
photos_header_bar_set_mode (PHOTOS_HEADER_BAR (priv->toolbar), PHOTOS_HEADER_BAR_MODE_NORMAL);
- photos_main_toolbar_add_selection_button (self);
+ priv->selection_button = photos_main_toolbar_add_selection_button (self);
photos_main_toolbar_add_search_button (self);
if (gtk_widget_get_parent (priv->searchbar) == NULL)
@@ -491,7 +501,7 @@ photos_main_toolbar_populate_for_overview (PhotosMainToolbar *self)
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->toolbar), TRUE);
photos_header_bar_set_mode (PHOTOS_HEADER_BAR (priv->toolbar), PHOTOS_HEADER_BAR_MODE_NORMAL);
- photos_main_toolbar_add_selection_button (self);
+ priv->selection_button = photos_main_toolbar_add_selection_button (self);
photos_main_toolbar_add_search_button (self);
if (gtk_widget_get_parent (priv->searchbar) == NULL)
@@ -547,7 +557,7 @@ photos_main_toolbar_populate_for_search (PhotosMainToolbar *self)
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (priv->toolbar), TRUE);
photos_header_bar_set_mode (PHOTOS_HEADER_BAR (priv->toolbar), PHOTOS_HEADER_BAR_MODE_NORMAL);
- photos_main_toolbar_add_selection_button (self);
+ priv->selection_button = photos_main_toolbar_add_selection_button (self);
photos_main_toolbar_add_search_button (self);
if (gtk_widget_get_parent (priv->searchbar) == NULL)
@@ -582,37 +592,6 @@ photos_main_toolbar_populate_for_selection_mode (PhotosMainToolbar *self)
static void
-photos_main_toolbar_reset_toolbar_mode (PhotosMainToolbar *self)
-{
- PhotosMainToolbarPrivate *priv = self->priv;
- PhotosWindowMode window_mode;
- gboolean selection_mode;
-
- photos_main_toolbar_clear_toolbar (self);
- selection_mode = photos_selection_controller_get_selection_mode (priv->sel_cntrlr);
- window_mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
-
- if (selection_mode)
- photos_main_toolbar_populate_for_selection_mode (self);
- else if (window_mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
- photos_main_toolbar_populate_for_collections (self);
- else if (window_mode == PHOTOS_WINDOW_MODE_FAVORITES)
- photos_main_toolbar_populate_for_favorites (self);
- else if (window_mode == PHOTOS_WINDOW_MODE_OVERVIEW)
- photos_main_toolbar_populate_for_overview (self);
- else if (window_mode == PHOTOS_WINDOW_MODE_PREVIEW)
- photos_main_toolbar_populate_for_preview (self);
- else if (window_mode == PHOTOS_WINDOW_MODE_SEARCH)
- photos_main_toolbar_populate_for_search (self);
-
- photos_main_toolbar_update_remote_display_button (self);
-
- photos_main_toolbar_set_toolbar_title (self);
- gtk_widget_show_all (priv->toolbar);
-}
-
-
-static void
photos_main_toolbar_constructed (GObject *object)
{
PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (object);
@@ -736,11 +715,6 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
G_CONNECT_SWAPPED);
priv->mode_cntrlr = photos_mode_controller_dup_singleton ();
- g_signal_connect_object (priv->mode_cntrlr,
- "window-mode-changed",
- G_CALLBACK (photos_main_toolbar_reset_toolbar_mode),
- self,
- G_CONNECT_SWAPPED);
priv->sel_cntrlr = photos_selection_controller_dup_singleton ();
g_signal_connect_object (priv->sel_cntrlr,
@@ -819,7 +793,51 @@ photos_main_toolbar_is_focus (PhotosMainToolbar *self)
void
+photos_main_toolbar_reset_toolbar_mode (PhotosMainToolbar *self)
+{
+ PhotosMainToolbarPrivate *priv = self->priv;
+ PhotosWindowMode window_mode;
+ gboolean selection_mode;
+
+ photos_main_toolbar_clear_toolbar (self);
+ selection_mode = photos_selection_controller_get_selection_mode (priv->sel_cntrlr);
+ window_mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
+
+ if (selection_mode)
+ photos_main_toolbar_populate_for_selection_mode (self);
+ else if (window_mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
+ photos_main_toolbar_populate_for_collections (self);
+ else if (window_mode == PHOTOS_WINDOW_MODE_FAVORITES)
+ photos_main_toolbar_populate_for_favorites (self);
+ else if (window_mode == PHOTOS_WINDOW_MODE_OVERVIEW)
+ photos_main_toolbar_populate_for_overview (self);
+ else if (window_mode == PHOTOS_WINDOW_MODE_PREVIEW)
+ photos_main_toolbar_populate_for_preview (self);
+ else if (window_mode == PHOTOS_WINDOW_MODE_SEARCH)
+ photos_main_toolbar_populate_for_search (self);
+
+ photos_main_toolbar_update_remote_display_button (self);
+
+ photos_main_toolbar_set_toolbar_title (self);
+ gtk_widget_show_all (priv->toolbar);
+}
+
+
+void
photos_main_toolbar_set_stack (PhotosMainToolbar *self, GtkStack *stack)
{
photos_header_bar_set_stack (PHOTOS_HEADER_BAR (self->priv->toolbar), stack);
}
+
+
+void
+photos_main_toolbar_set_view_model (PhotosMainToolbar *self, PhotosViewModel *model)
+{
+ PhotosMainToolbarPrivate *priv = self->priv;
+ 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 (priv->search), !is_empty);
+ if (priv->selection_button != NULL)
+ gtk_widget_set_sensitive (priv->selection_button, !is_empty);
+}
diff --git a/src/photos-main-toolbar.h b/src/photos-main-toolbar.h
index f836b4d..4e8f9b6 100644
--- a/src/photos-main-toolbar.h
+++ b/src/photos-main-toolbar.h
@@ -28,6 +28,7 @@
#include <gtk/gtk.h>
#include "photos-searchbar.h"
+#include "photos-view-model.h"
G_BEGIN_DECLS
@@ -78,8 +79,12 @@ gboolean photos_main_toolbar_handle_event (PhotosMainToo
gboolean photos_main_toolbar_is_focus (PhotosMainToolbar *self);
+void photos_main_toolbar_reset_toolbar_mode (PhotosMainToolbar *self);
+
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]