[gnome-photos/wip/rishi/collection: 3/15] item-manager: Use switches for enums instead of if-else
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 3/15] item-manager: Use switches for enums instead of if-else
- Date: Fri, 28 Jul 2017 13:01:22 +0000 (UTC)
commit 1bed4e43a986f06865e15a93e88e815d217716c5
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jul 28 12:16:55 2017 +0200
item-manager: Use switches for enums instead of if-else
Using a switch statement lets the compiler warn us through
-Wswitch-enum whenever we extend the enumeration range. An if-else
block does not do that.
src/photos-item-manager.c | 59 ++++++++++++++++++++++++++++++--------------
1 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index a5a0751..25b8f5c 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1319,14 +1319,22 @@ photos_mode_controller_go_back (PhotosModeController *self)
g_return_if_fail (old_mode != PHOTOS_WINDOW_MODE_NONE);
- if (self->mode == PHOTOS_WINDOW_MODE_EDIT)
+ switch (self->mode)
{
+ case PHOTOS_WINDOW_MODE_EDIT:
g_return_if_fail (self->load_state == PHOTOS_LOAD_STATE_FINISHED);
g_return_if_fail (old_mode == PHOTOS_WINDOW_MODE_PREVIEW);
- }
- else
- {
+ break;
+
+ case PHOTOS_WINDOW_MODE_NONE:
+ case PHOTOS_WINDOW_MODE_COLLECTIONS:
+ case PHOTOS_WINDOW_MODE_FAVORITES:
+ case PHOTOS_WINDOW_MODE_OVERVIEW:
+ case PHOTOS_WINDOW_MODE_PREVIEW:
+ case PHOTOS_WINDOW_MODE_SEARCH:
+ default:
g_return_if_fail (old_mode != PHOTOS_WINDOW_MODE_PREVIEW);
+ break;
}
g_queue_pop_head (self->history);
@@ -1339,29 +1347,42 @@ photos_mode_controller_go_back (PhotosModeController *self)
photos_item_manager_update_fullscreen (self);
photos_item_manager_clear_active_item_load (self);
- if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW)
+ switch (old_mode)
{
+ case PHOTOS_WINDOW_MODE_EDIT:
+ break;
+
+ case PHOTOS_WINDOW_MODE_PREVIEW:
self->load_state = PHOTOS_LOAD_STATE_NONE;
g_set_object (&self->active_object, G_OBJECT (self->active_collection));
g_signal_emit_by_name (self, "active-changed", self->active_object);
- }
- else if (old_mode != PHOTOS_WINDOW_MODE_EDIT)
- {
- gboolean active_collection_changed = FALSE;
+ break;
- if (self->active_collection != NULL)
- {
- g_clear_object (&self->active_collection);
- active_collection_changed = TRUE;
- }
+ case PHOTOS_WINDOW_MODE_NONE:
+ case PHOTOS_WINDOW_MODE_COLLECTIONS:
+ case PHOTOS_WINDOW_MODE_FAVORITES:
+ case PHOTOS_WINDOW_MODE_OVERVIEW:
+ case PHOTOS_WINDOW_MODE_SEARCH:
+ default:
+ {
+ gboolean active_collection_changed = FALSE;
- g_clear_object (&self->active_object);
- self->load_state = PHOTOS_LOAD_STATE_NONE;
+ if (self->active_collection != NULL)
+ {
+ g_clear_object (&self->active_collection);
+ active_collection_changed = TRUE;
+ }
- g_signal_emit_by_name (self, "active-changed", self->active_object);
+ g_clear_object (&self->active_object);
+ self->load_state = PHOTOS_LOAD_STATE_NONE;
- if (active_collection_changed)
- g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
+ g_signal_emit_by_name (self, "active-changed", self->active_object);
+
+ if (active_collection_changed)
+ g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
+
+ break;
+ }
}
g_signal_emit (self, signals[WINDOW_MODE_CHANGED], 0, self->mode, old_mode);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]