[gnome-photos/wip/foo: 4/7] Add PhotosHeaderBar
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/foo: 4/7] Add PhotosHeaderBar
- Date: Mon, 25 Mar 2013 12:44:59 +0000 (UTC)
commit cbcf46d4246c2e41debf929ca7c996bc05b82948
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Mar 24 20:59:47 2013 +0100
Add PhotosHeaderBar
configure.ac | 1 +
src/Makefile.am | 2 +
src/photos-header-bar.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++
src/photos-header-bar.h | 92 ++++++++++++++++++++++++
4 files changed, 272 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7fe76e6..81f4c4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,7 @@ PKG_CHECK_MODULES(LIBRSVG, [librsvg-2.0 >= $LIBRSVG_MIN_VERSION])
PKG_CHECK_MODULES(TRACKER, [tracker-miner-0.16 tracker-sparql-0.16])
LIBGD_INIT([
+ header-bar
main-toolbar
main-icon-view
main-view
diff --git a/src/Makefile.am b/src/Makefile.am
index e197dfa..9779ab9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,8 @@ gnome_photos_SOURCES = \
photos-error-box.h \
photos-filterable.c \
photos-filterable.h \
+ photos-header-bar.c \
+ photos-header-bar.h \
photos-indexing-notification.c \
photos-indexing-notification.h \
photos-item-manager.c \
diff --git a/src/photos-header-bar.c b/src/photos-header-bar.c
new file mode 100644
index 0000000..d71e90b
--- /dev/null
+++ b/src/photos-header-bar.c
@@ -0,0 +1,177 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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.
+ */
+
+/* Based on code from:
+ * + Clocks
+ */
+
+
+#include "config.h"
+
+#include "photos-header-bar.h"
+
+
+struct _PhotosHeaderBarPrivate
+{
+ GtkWidget *selection_menu;
+ GtkWidget *stack_switcher;
+ PhotosHeaderBarMode mode;
+};
+
+
+G_DEFINE_TYPE (PhotosHeaderBar, photos_header_bar, GD_TYPE_HEADER_BAR);
+
+
+static void
+photos_header_bar_realize (GtkWidget *widget)
+{
+ PhotosHeaderBar *self = PHOTOS_HEADER_BAR (widget);
+ PhotosHeaderBarPrivate *priv = self->priv;
+
+ GTK_WIDGET_CLASS (photos_header_bar_parent_class)->realize (widget);
+
+ if (priv->mode == PHOTOS_HEADER_BAR_MODE_NONE)
+ photos_header_bar_set_mode (self, PHOTOS_HEADER_BAR_MODE_NORMAL);
+}
+
+
+static void
+photos_header_bar_dispose (GObject *object)
+{
+ PhotosHeaderBar *self = PHOTOS_HEADER_BAR (object);
+ PhotosHeaderBarPrivate *priv = self->priv;
+
+ g_clear_object (&priv->selection_menu);
+ g_clear_object (&priv->stack_switcher);
+
+ G_OBJECT_CLASS (photos_header_bar_parent_class)->dispose (object);
+}
+
+
+static void
+photos_header_bar_init (PhotosHeaderBar *self)
+{
+ PhotosHeaderBarPrivate *priv;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_HEADER_BAR, PhotosHeaderBarPrivate);
+ priv = self->priv;
+
+ priv->stack_switcher = g_object_ref_sink (gd_stack_switcher_new ());
+}
+
+
+static void
+photos_header_bar_class_init (PhotosHeaderBarClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->dispose = photos_header_bar_dispose;
+ widget_class->realize = photos_header_bar_realize;
+
+ g_type_class_add_private (class, sizeof (PhotosHeaderBarPrivate));
+}
+
+
+GtkWidget *
+photos_header_bar_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_HEADER_BAR, NULL);
+}
+
+
+void
+photos_header_bar_clear (PhotosHeaderBar *self)
+{
+ GList *children;
+ GList *l;
+
+ photos_header_bar_set_mode (self, PHOTOS_HEADER_BAR_MODE_NORMAL);
+ children = gtk_container_get_children (GTK_CONTAINER (self));
+ for (l = children; l != NULL; l = l->next)
+ gtk_widget_destroy (GTK_WIDGET (l->data));
+}
+
+
+void
+photos_header_bar_set_mode (PhotosHeaderBar *self, PhotosHeaderBarMode mode)
+{
+ PhotosHeaderBarPrivate *priv = self->priv;
+ GtkStyleContext *context;
+ GtkWidget *custom_title = NULL;
+
+ if (priv->mode == mode || !gtk_widget_get_realized (GTK_WIDGET (self)))
+ return;
+
+ priv->mode = mode;
+ context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+ switch (priv->mode)
+ {
+ case PHOTOS_HEADER_BAR_MODE_NORMAL:
+ gtk_style_context_remove_class (context, "selection-mode");
+ custom_title = priv->stack_switcher;
+ break;
+
+ case PHOTOS_HEADER_BAR_MODE_SELECTION:
+ gtk_style_context_add_class (context, "selection-mode");
+ custom_title = priv->selection_menu;
+ break;
+
+ case PHOTOS_HEADER_BAR_MODE_STANDALONE:
+ gtk_style_context_remove_class (context, "selection-mode");
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ gd_header_bar_set_custom_title (GD_HEADER_BAR (self), custom_title);
+}
+
+
+void
+photos_header_bar_set_selection_menu (PhotosHeaderBar *self, GdHeaderButton *selection_menu)
+{
+ PhotosHeaderBarPrivate *priv = self->priv;
+
+ if (priv->selection_menu == GTK_WIDGET (selection_menu))
+ return;
+
+ g_clear_object (&priv->selection_menu);
+ if (selection_menu != NULL)
+ {
+ GtkStyleContext *context;
+
+ priv->selection_menu = g_object_ref_sink (selection_menu);
+ context = gtk_widget_get_style_context (priv->selection_menu);
+ gtk_style_context_add_class (context, "selection-menu");
+ }
+
+ if (priv->mode == PHOTOS_HEADER_BAR_MODE_SELECTION)
+ gd_header_bar_set_custom_title (GD_HEADER_BAR (self), priv->selection_menu);
+}
+
+
+void
+photos_header_bar_set_stack (PhotosHeaderBar *self, GdStack *stack)
+{
+ gd_stack_switcher_set_stack (GD_STACK_SWITCHER (self->priv->stack_switcher), stack);
+}
diff --git a/src/photos-header-bar.h b/src/photos-header-bar.h
new file mode 100644
index 0000000..0546dc7
--- /dev/null
+++ b/src/photos-header-bar.h
@@ -0,0 +1,92 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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.
+ */
+
+/* Based on code from:
+ * + Clocks
+ */
+
+#ifndef PHOTOS_HEADER_BAR_H
+#define PHOTOS_HEADER_BAR_H
+
+#include <libgd/gd.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_HEADER_BAR (photos_header_bar_get_type ())
+
+#define PHOTOS_HEADER_BAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_HEADER_BAR, PhotosHeaderBar))
+
+#define PHOTOS_HEADER_BAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_HEADER_BAR, PhotosHeaderBarClass))
+
+#define PHOTOS_IS_HEADER_BAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_HEADER_BAR))
+
+#define PHOTOS_IS_HEADER_BAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_HEADER_BAR))
+
+#define PHOTOS_HEADER_BAR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_HEADER_BAR, PhotosHeaderBarClass))
+
+typedef enum
+{
+ PHOTOS_HEADER_BAR_MODE_NONE,
+ PHOTOS_HEADER_BAR_MODE_NORMAL,
+ PHOTOS_HEADER_BAR_MODE_SELECTION,
+ PHOTOS_HEADER_BAR_MODE_STANDALONE
+} PhotosHeaderBarMode;
+
+typedef struct _PhotosHeaderBar PhotosHeaderBar;
+typedef struct _PhotosHeaderBarClass PhotosHeaderBarClass;
+typedef struct _PhotosHeaderBarPrivate PhotosHeaderBarPrivate;
+
+struct _PhotosHeaderBar
+{
+ GdHeaderBar parent_instance;
+ PhotosHeaderBarPrivate *priv;
+};
+
+struct _PhotosHeaderBarClass
+{
+ GdHeaderBarClass parent_class;
+};
+
+GType photos_header_bar_get_type (void) G_GNUC_CONST;
+
+GtkWidget *photos_header_bar_new (void);
+
+void photos_header_bar_clear (PhotosHeaderBar *self);
+
+void photos_header_bar_set_mode (PhotosHeaderBar *self, PhotosHeaderBarMode
mode);
+
+void photos_header_bar_set_selection_menu (PhotosHeaderBar *self,
+ GdHeaderButton *selection_menu);
+
+void photos_header_bar_set_stack (PhotosHeaderBar *self, GdStack *stack);
+
+G_END_DECLS
+
+#endif /* PHOTOS_HEADER_BAR_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]