[gnome-photos] Add PhotosModeController
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosModeController
- Date: Mon, 23 Apr 2012 23:11:48 +0000 (UTC)
commit b95039047991593c7cc8b5b24c32a0a7006f3efa
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Apr 23 17:20:51 2012 +0200
Add PhotosModeController
src/Makefile.am | 80 ++++++++++++++++
src/photos-application.c | 10 ++
src/photos-enums.c.template | 51 ++++++++++
src/photos-enums.h.template | 34 +++++++
src/photos-marshalers.list | 1 +
src/photos-mode-controller.c | 216 ++++++++++++++++++++++++++++++++++++++++++
src/photos-mode-controller.h | 84 ++++++++++++++++
7 files changed, 476 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bb1526b..68ba782 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,13 +1,33 @@
bin_PROGRAMS = gnome-photos
+gnome_photos_built_sources = \
+ photos-enums.c \
+ photos-enums.h \
+ photos-marshalers.c \
+ photos-marshalers.h \
+ $(NULL)
+
gnome_photos_SOURCES = \
+ $(gnome_photos_built_sources) \
photos-application.c \
photos-application.h \
photos-main-window.c \
photos-main-window.h \
+ photos-mode-controller.c \
+ photos-mode-controller.h \
photos-main.c \
$(NULL)
+BUILT_SOURCES = \
+ $(gnome_photos_built_sources) \
+ $(NULL)
+
+EXTRA_DIST = \
+ photos-enums.c.template \
+ photos-enums.h.template \
+ photos-marshalers.list \
+ $(null)
+
AM_CPPFLAGS = \
-DPACKAGE_LOCALE_DIR=\""${datadir}/locale"\" \
$(CLUTTER_GTK_CFLAGS) \
@@ -26,3 +46,63 @@ gnome_photos_LDADD = \
$(GTK_LIBS) \
$(TRACKER_LIBS) \
$(NULL)
+
+CLEANFILES = \
+ xgen-etbc \
+ xgen-etbh \
+ xgen-tmc \
+ xgen-tmh \
+ $(NULL)
+
+DISTCLEANFILES = \
+ $(gnome_photos_built_sources) \
+ stamp-photos-enums.h \
+ stamp-photos-marshalers.h \
+ $(NULL)
+
+photos-enums.h: stamp-photos-enums.h
+ @true
+
+stamp-photos-enums.h: photos-enums.h.template
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && ( glib-mkenums \
+ --template photos-enums.h.template $(gnome_photos_SOURCES) ) >> xgen-etbh \
+ && ( cmp -s xgen-etbh photos-enums.h || cp xgen-etbh photos-enums.h ) \
+ && rm -f xgen-etbh \
+ && echo timestamp > $(@F) \
+ )
+
+photos-enums.c: photos-enums.c.template
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && ( glib-mkenums \
+ --template photos-enums.c.template $(gnome_photos_SOURCES) ) >> xgen-etbc \
+ && ( cmp -s xgen-etbc photos-enums.c || cp xgen-etbc photos-enums.c ) \
+ && rm -f xgen-etbc \
+ )
+
+photos-marshalers.h: stamp-photos-marshalers.h
+ @true
+
+stamp-photos-marshalers.h: photos-marshalers.list Makefile
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && ( glib-genmarshal \
+ --prefix=_photos_marshal \
+ --header photos-marshalers.list ) >> xgen-tmh \
+ && ( cmp -s xgen-tmh photos-marshalers.h || cp xgen-tmh photos-marshalers.h ) \
+ && rm -f xgen-tmh \
+ && echo timestamp > $(@F) \
+ )
+
+photos-marshalers.c: photos-marshalers.list photos-marshalers.h Makefile
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && echo "#include \"photos-marshalers.h\"" > xgen-tmc \
+ && ( glib-genmarshal \
+ --prefix=_photos_marshal \
+ --body photos-marshalers.list ) >> xgen-tmc \
+ && cp xgen-tmc photos-marshalers.c \
+ && rm -f xgen-tmc \
+ )
diff --git a/src/photos-application.c b/src/photos-application.c
index 91f6845..ffd3589 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -29,11 +29,13 @@
#include "photos-application.h"
#include "photos-main-window.h"
+#include "photos-mode-controller.h"
struct _PhotosApplicationPrivate
{
GtkWidget *main_window;
+ PhotosModeController *controller;
TrackerSparqlConnection *connection;
};
@@ -100,6 +102,8 @@ photos_application_startup (GApplication *application)
return;
}
+ priv->controller = photos_mode_controller_new ();
+
action = g_simple_action_new ("about", NULL);
g_signal_connect (action, "activate", G_CALLBACK (photos_application_about), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
@@ -136,6 +140,12 @@ photos_application_dispose (GObject *object)
PhotosApplication *self = PHOTOS_APPLICATION (object);
PhotosApplicationPrivate *priv = self->priv;
+ if (priv->controller != NULL)
+ {
+ g_object_unref (priv->controller);
+ priv->controller = NULL;
+ }
+
if (priv->connection != NULL)
{
g_object_unref (priv->connection);
diff --git a/src/photos-enums.c.template b/src/photos-enums.c.template
new file mode 100644
index 0000000..cf3c0a7
--- /dev/null
+++ b/src/photos-enums.c.template
@@ -0,0 +1,51 @@
+/*** BEGIN file-header ***/
+
+#include "config.h"
+
+#include "photos-enums.h"
+#include "photos-mode-controller.h"
+
+/*** END file-header ***/
+
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+
+/*** BEGIN value-header ***/
+
+GType
+ enum_name@_get_type (void)
+{
+ static GType etype = 0;
+ if (G_UNLIKELY(etype == 0)) {
+ static const G Type@Value values[] = {
+
+/*** END value-header ***/
+
+
+/*** BEGIN value-production ***/
+
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+
+/*** END value-production ***/
+
+
+/*** BEGIN value-tail ***/
+
+ { 0, NULL, NULL }
+ };
+ etype = g_ type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ }
+ return etype;
+}
+
+/*** END value-tail ***/
+
+
+/*** BEGIN file-tail ***/
+
+/*** END file-tail ***/
diff --git a/src/photos-enums.h.template b/src/photos-enums.h.template
new file mode 100644
index 0000000..63b6942
--- /dev/null
+++ b/src/photos-enums.h.template
@@ -0,0 +1,34 @@
+/*** BEGIN file-header ***/
+
+#ifndef PHOTOS_ENUMS_H
+#define PHOTOS_ENUMS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*** END file-header ***/
+
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+
+/*** BEGIN value-header ***/
+
+GType @enum_name _get_type (void) G_GNUC_CONST;
+#define PHOTOS_TYPE_ ENUMSHORT@ (@enum_name _get_type ())
+
+/*** END value-header ***/
+
+
+/*** BEGIN file-tail ***/
+
+G_END_DECLS
+
+#endif /* PHOTOS_ENUMS_H */
+
+/*** END file-tail ***/
\ No newline at end of file
diff --git a/src/photos-marshalers.list b/src/photos-marshalers.list
new file mode 100644
index 0000000..438c55c
--- /dev/null
+++ b/src/photos-marshalers.list
@@ -0,0 +1 @@
+VOID:ENUM,ENUM
diff --git a/src/photos-mode-controller.c b/src/photos-mode-controller.c
new file mode 100644
index 0000000..910a3a9
--- /dev/null
+++ b/src/photos-mode-controller.c
@@ -0,0 +1,216 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <clutter-gtk/clutter-gtk.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-enums.h"
+#include "photos-marshalers.h"
+#include "photos-mode-controller.h"
+
+
+struct _PhotosModeControllerPrivate
+{
+ PhotosWindowMode mode;
+ gboolean fullscreen;
+ gboolean can_fullscreen;
+};
+
+enum
+{
+ CAN_FULLSCREEN_CHANGED,
+ FULLSCREEN_CHANGED,
+ WINDOW_MODE_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE (PhotosModeController, photos_mode_controller, G_TYPE_OBJECT);
+
+
+static GObject *
+photos_mode_controller_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = G_OBJECT_CLASS (photos_mode_controller_parent_class)->constructor (type,
+ n_construct_params,
+ construct_params);
+ g_object_add_weak_pointer (self, (gpointer) &self);
+ return self;
+ }
+
+ return g_object_ref (self);
+}
+
+
+static void
+photos_mode_controller_init (PhotosModeController *self)
+{
+ PhotosModeControllerPrivate *priv;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_MODE_CONTROLLER, PhotosModeControllerPrivate);
+ priv = self->priv;
+
+ priv->mode = PHOTOS_WINDOW_MODE_NONE;
+ priv->fullscreen = FALSE;
+ priv->can_fullscreen = FALSE;
+}
+
+
+static void
+photos_mode_controller_class_init (PhotosModeControllerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructor = photos_mode_controller_constructor;
+
+ signals[CAN_FULLSCREEN_CHANGED] = g_signal_new ("can-fullscreen-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosModeControllerClass,
+ can_fullscreen_changed),
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ signals[FULLSCREEN_CHANGED] = g_signal_new ("fullscreen-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosModeControllerClass,
+ fullscreen_changed),
+ NULL, /*accumulator */
+ NULL, /* accu_data */
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
+
+ signals[WINDOW_MODE_CHANGED] = g_signal_new ("window-mode-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosModeControllerClass,
+ window_mode_changed),
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ _photos_marshal_VOID__ENUM_ENUM,
+ G_TYPE_NONE,
+ 2,
+ PHOTOS_TYPE_WINDOW_MODE,
+ PHOTOS_TYPE_WINDOW_MODE);
+
+ g_type_class_add_private (class, sizeof (PhotosModeControllerPrivate));
+}
+
+
+PhotosModeController *
+photos_mode_controller_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_MODE_CONTROLLER, NULL);
+}
+
+
+PhotosWindowMode
+photos_mode_controller_get_can_fullscreen (PhotosModeController *self)
+{
+ return self->priv->can_fullscreen;
+}
+
+
+PhotosWindowMode
+photos_mode_controller_get_fullscreen (PhotosModeController *self)
+{
+ return self->priv->fullscreen;
+}
+
+
+PhotosWindowMode
+photos_mode_controller_get_window_mode (PhotosModeController *self)
+{
+ return self->priv->mode;
+}
+
+
+void
+photos_mode_controller_toggle_fullscreen (PhotosModeController *self)
+{
+ photos_mode_controller_set_fullscreen (self, !self->priv->fullscreen);
+}
+
+
+void
+photos_mode_controller_set_can_fullscreen (PhotosModeController *self, gboolean can_fullscreen)
+{
+ PhotosModeControllerPrivate *priv = self->priv;
+
+ priv->can_fullscreen = can_fullscreen;
+ if (!priv->can_fullscreen && priv->fullscreen)
+ photos_mode_controller_set_fullscreen (self, FALSE);
+
+ g_signal_emit (self, signals[CAN_FULLSCREEN_CHANGED], 0);
+}
+
+
+void
+photos_mode_controller_set_fullscreen (PhotosModeController *self, gboolean fullscreen)
+{
+ PhotosModeControllerPrivate *priv = self->priv;
+
+ if (priv->mode != PHOTOS_WINDOW_MODE_PREVIEW)
+ return;
+
+ if (priv->fullscreen == fullscreen)
+ return;
+
+ if (fullscreen && !priv->can_fullscreen)
+ return;
+
+ priv->fullscreen = fullscreen;
+ g_signal_emit (self, signals[FULLSCREEN_CHANGED], 0, priv->fullscreen);
+}
+
+
+void
+photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindowMode mode)
+{
+ PhotosModeControllerPrivate *priv = self->priv;
+ PhotosWindowMode old_mode;
+
+ old_mode = priv->mode;
+
+ if (old_mode == mode)
+ return;
+
+ if (mode == PHOTOS_WINDOW_MODE_OVERVIEW)
+ photos_mode_controller_set_can_fullscreen (self, FALSE);
+
+ priv->mode = mode;
+ g_signal_emit (self, signals[WINDOW_MODE_CHANGED], 0, priv->mode, old_mode);
+}
diff --git a/src/photos-mode-controller.h b/src/photos-mode-controller.h
new file mode 100644
index 0000000..2db54cd
--- /dev/null
+++ b/src/photos-mode-controller.h
@@ -0,0 +1,84 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_MODE_CONTROLLER_H
+#define PHOTOS_MODE_CONTROLLER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_MODE_CONTROLLER (photos_mode_controller_get_type ())
+#define PHOTOS_MODE_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PHOTOS_TYPE_MODE_CONTROLLER, PhotosModeController))
+#define PHOTOS_MODE_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PHOTOS_TYPE_MODE_CONTROLLER, PhotosModeControllerClass))
+#define PHOTOS_IS_MODE_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PHOTOS_TYPE_MODE_CONTROLLER))
+#define PHOTOS_IS_MODE_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PHOTOS_TYPE_MODE_CONTROLLER))
+#define PHOTOS_MODE_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PHOTOS_TYPE_MODE_CONTROLLER, PhotosModeControllerClass))
+
+typedef enum
+{
+ PHOTOS_WINDOW_MODE_NONE,
+ PHOTOS_WINDOW_MODE_OVERVIEW,
+ PHOTOS_WINDOW_MODE_PREVIEW
+} PhotosWindowMode;
+
+typedef struct _PhotosModeController PhotosModeController;
+typedef struct _PhotosModeControllerClass PhotosModeControllerClass;
+typedef struct _PhotosModeControllerPrivate PhotosModeControllerPrivate;
+
+struct _PhotosModeController
+{
+ GObject parent_instance;
+ PhotosModeControllerPrivate *priv;
+};
+
+struct _PhotosModeControllerClass
+{
+ GObjectClass parent_class;
+
+ void (*can_fullscreen_changed) (PhotosModeController *self);
+ void (*fullscreen_changed) (PhotosModeController *self, gboolean fullscreen);
+ void (*window_mode_changed) (PhotosModeController *self, PhotosWindowMode mode, PhotosWindowMode old_mode);
+};
+
+GType photos_mode_controller_get_type (void) G_GNUC_CONST;
+
+PhotosModeController *photos_mode_controller_new (void);
+
+PhotosWindowMode photos_mode_controller_get_can_fullscreen (PhotosModeController *self);
+
+PhotosWindowMode photos_mode_controller_get_fullscreen (PhotosModeController *self);
+
+PhotosWindowMode photos_mode_controller_get_window_mode (PhotosModeController *self);
+
+void photos_mode_controller_toggle_fullscreen (PhotosModeController *self);
+
+void photos_mode_controller_set_can_fullscreen (PhotosModeController *self,
+ gboolean can_fullscreen);
+
+void photos_mode_controller_set_fullscreen (PhotosModeController *self,
+ gboolean fullscreen);
+
+void photos_mode_controller_set_window_mode (PhotosModeController *self,
+ PhotosWindowMode mode);
+
+G_END_DECLS
+
+#endif /* PHOTOS_MODE_CONTROLLER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]