[gnome-photos] edit-palette: Use a separate derived class for the rows
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] edit-palette: Use a separate derived class for the rows
- Date: Fri, 27 Nov 2015 14:24:49 +0000 (UTC)
commit 8be1b74b29e9ed9b564579f2cfbdda30ebc6b2cc
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Nov 27 14:47:33 2015 +0100
edit-palette: Use a separate derived class for the rows
src/Makefile.am | 2 +
src/photos-edit-palette-row.c | 221 +++++++++++++++++++++++++++++++++++++++++
src/photos-edit-palette-row.h | 55 ++++++++++
src/photos-edit-palette.c | 87 ++---------------
4 files changed, 287 insertions(+), 78 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0289db1..fff4154 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,6 +74,8 @@ gnome_photos_SOURCES = \
photos-edit-bar.h \
photos-edit-palette.c \
photos-edit-palette.h \
+ photos-edit-palette-row.c \
+ photos-edit-palette-row.h \
photos-embed.c \
photos-embed.h \
photos-empty-results-box.c \
diff --git a/src/photos-edit-palette-row.c b/src/photos-edit-palette-row.c
new file mode 100644
index 0000000..66ab162
--- /dev/null
+++ b/src/photos-edit-palette-row.c
@@ -0,0 +1,221 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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 "photos-edit-palette-row.h"
+
+
+struct _PhotosEditPaletteRow
+{
+ GtkListBoxRow parent_instance;
+ GtkWidget *details_revealer;
+ PhotosTool *tool;
+ GtkSizeGroup *size_group;
+};
+
+struct _PhotosEditPaletteRowClass
+{
+ GtkListBoxRowClass parent_class;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SIZE_GROUP,
+ PROP_TOOL
+};
+
+
+G_DEFINE_TYPE (PhotosEditPaletteRow, photos_edit_palette_row, GTK_TYPE_LIST_BOX_ROW);
+
+
+static void
+photos_edit_palette_row_constructed (GObject *object)
+{
+ PhotosEditPaletteRow *self = PHOTOS_EDIT_PALETTE_ROW (object);
+ GtkWidget *grid0;
+ GtkWidget *grid1;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *tool_widget;
+ const gchar *icon_name;
+ const gchar *name;
+ gchar *name_markup;
+
+ G_OBJECT_CLASS (photos_edit_palette_row_parent_class)->constructed (object);
+
+ grid0 = gtk_grid_new ();
+ gtk_widget_set_margin_bottom (grid0, 6);
+ gtk_widget_set_margin_start (grid0, 18);
+ gtk_widget_set_margin_end (grid0, 18);
+ gtk_widget_set_margin_top (grid0, 6);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid0), GTK_ORIENTATION_VERTICAL);
+ gtk_container_add (GTK_CONTAINER (self), grid0);
+
+ grid1 = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_HORIZONTAL);
+ gtk_grid_set_column_spacing (GTK_GRID (grid1), 12);
+ gtk_container_add (GTK_CONTAINER (grid0), grid1);
+
+ icon_name = photos_tool_get_icon_name (self->tool);
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (grid1), image);
+
+ name = photos_tool_get_name (self->tool);
+ label = gtk_label_new (NULL);
+ name_markup = g_strdup_printf ("<b>%s</b>", name);
+ gtk_label_set_markup (GTK_LABEL (label), name_markup);
+ gtk_container_add (GTK_CONTAINER (grid1), label);
+
+ self->details_revealer = gtk_revealer_new ();
+ gtk_revealer_set_transition_type (GTK_REVEALER (self->details_revealer),
+ GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
+ gtk_container_add (GTK_CONTAINER (grid0), self->details_revealer);
+
+ tool_widget = photos_tool_get_widget (self->tool);
+ gtk_widget_set_margin_bottom (tool_widget, 12);
+ gtk_widget_set_margin_top (tool_widget, 12);
+ gtk_container_add (GTK_CONTAINER (self->details_revealer), tool_widget);
+ gtk_size_group_add_widget (self->size_group, tool_widget);
+
+ g_signal_connect_swapped (self->tool, "hide-requested", G_CALLBACK (photos_edit_palette_row_hide_details),
self);
+
+ gtk_widget_show_all (GTK_WIDGET (self));
+
+ g_free (name_markup);
+ g_clear_object (&self->size_group); /* We will not need it any more */
+}
+
+
+static void
+photos_edit_palette_row_dispose (GObject *object)
+{
+ PhotosEditPaletteRow *self = PHOTOS_EDIT_PALETTE_ROW (object);
+
+ g_clear_object (&self->size_group);
+
+ G_OBJECT_CLASS (photos_edit_palette_row_parent_class)->dispose (object);
+}
+
+
+static void
+photos_edit_palette_row_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosEditPaletteRow *self = PHOTOS_EDIT_PALETTE_ROW (object);
+
+ switch (prop_id)
+ {
+ case PROP_TOOL:
+ g_value_set_object (value, self->tool);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_edit_palette_row_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ PhotosEditPaletteRow *self = PHOTOS_EDIT_PALETTE_ROW (object);
+
+ switch (prop_id)
+ {
+ case PROP_SIZE_GROUP:
+ self->size_group = GTK_SIZE_GROUP (g_value_dup_object (value));
+ break;
+
+ case PROP_TOOL:
+ self->tool = PHOTOS_TOOL (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_edit_palette_row_init (PhotosEditPaletteRow *self)
+{
+}
+
+
+static void
+photos_edit_palette_row_class_init (PhotosEditPaletteRowClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructed = photos_edit_palette_row_constructed;
+ object_class->dispose = photos_edit_palette_row_dispose;
+ object_class->get_property = photos_edit_palette_row_get_property;
+ object_class->set_property = photos_edit_palette_row_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_SIZE_GROUP,
+ g_param_spec_object ("size-group",
+ "GtkSizeGroup object",
+ "Ensures the same width for all tool widgets",
+ GTK_TYPE_SIZE_GROUP,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_TOOL,
+ g_param_spec_object ("tool",
+ "PhotosTool object",
+ "The tool associated with this row",
+ PHOTOS_TYPE_TOOL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+}
+
+
+GtkWidget *
+photos_edit_palette_row_new (PhotosTool *tool, GtkSizeGroup *size_group)
+{
+ return g_object_new (PHOTOS_TYPE_EDIT_PALETTE_ROW, "size-group", size_group, "tool", tool, NULL);
+}
+
+
+PhotosTool *
+photos_edit_palette_row_get_tool (PhotosEditPaletteRow *self)
+{
+ return self->tool;
+}
+
+
+void
+photos_edit_palette_row_hide_details (PhotosEditPaletteRow *self)
+{
+ gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), TRUE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->details_revealer), FALSE);
+}
+
+
+void
+photos_edit_palette_row_show_details (PhotosEditPaletteRow *self)
+{
+ gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), FALSE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->details_revealer), TRUE);
+}
diff --git a/src/photos-edit-palette-row.h b/src/photos-edit-palette-row.h
new file mode 100644
index 0000000..1d42af4
--- /dev/null
+++ b/src/photos-edit-palette-row.h
@@ -0,0 +1,55 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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_EDIT_PALETTE_ROW_H
+#define PHOTOS_EDIT_PALETTE_ROW_H
+
+#include <gtk/gtk.h>
+
+#include "photos-tool.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_EDIT_PALETTE_ROW (photos_edit_palette_row_get_type ())
+
+#define PHOTOS_EDIT_PALETTE_ROW(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_EDIT_PALETTE_ROW, PhotosEditPaletteRow))
+
+#define PHOTOS_IS_EDIT_PALETTE_ROW(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_EDIT_PALETTE_ROW))
+
+typedef struct _PhotosEditPaletteRow PhotosEditPaletteRow;
+typedef struct _PhotosEditPaletteRowClass PhotosEditPaletteRowClass;
+
+GType photos_edit_palette_row_get_type (void) G_GNUC_CONST;
+
+GtkWidget *photos_edit_palette_row_new (PhotosTool *tool, GtkSizeGroup
*size_group);
+
+PhotosTool *photos_edit_palette_row_get_tool (PhotosEditPaletteRow *self);
+
+void photos_edit_palette_row_hide_details (PhotosEditPaletteRow *self);
+
+void photos_edit_palette_row_show_details (PhotosEditPaletteRow *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_EDIT_PALETTE_ROW_H */
diff --git a/src/photos-edit-palette.c b/src/photos-edit-palette.c
index 326acd9..2dca952 100644
--- a/src/photos-edit-palette.c
+++ b/src/photos-edit-palette.c
@@ -24,6 +24,7 @@
#include <gio/gio.h>
#include "photos-edit-palette.h"
+#include "photos-edit-palette-row.h"
#include "photos-item-manager.h"
#include "photos-search-context.h"
#include "photos-tool.h"
@@ -73,18 +74,7 @@ photos_edit_palette_extensions_sort_func (gconstpointer a, gconstpointer b)
static void
-photos_edit_palette_hide_requested (GtkListBoxRow *row)
-{
- GtkRevealer *revealer;
-
- revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (row), "edit-tool-details-revealer"));
- gtk_revealer_set_reveal_child (revealer, FALSE);
- gtk_list_box_row_set_activatable (row, TRUE);
-}
-
-
-static void
-photos_edit_palette_hide_requested_second (PhotosEditPalette *self)
+photos_edit_palette_hide_requested (PhotosEditPalette *self)
{
g_signal_emit (self, signals[TOOL_CHANGED], 0, NULL);
}
@@ -97,13 +87,7 @@ photos_edit_palette_window_mode_changed (PhotosEditPalette *self, PhotosWindowMo
gint i;
for (i = 0; (row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self), i)) != NULL; i++)
- {
- GtkRevealer *revealer;
-
- gtk_list_box_row_set_activatable (row, TRUE);
- revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (row), "edit-tool-details-revealer"));
- gtk_revealer_set_reveal_child (revealer, FALSE);
- }
+ photos_edit_palette_row_hide_details (PHOTOS_EDIT_PALETTE_ROW (row));
g_signal_emit (self, signals[TOOL_CHANGED], 0, NULL);
}
@@ -114,25 +98,20 @@ photos_edit_palette_row_activated (GtkListBox *box, GtkListBoxRow *row)
{
PhotosEditPalette *self = PHOTOS_EDIT_PALETTE (box);
GtkListBoxRow *other_row;
- GtkRevealer *revealer;
PhotosTool *tool;
gint i;
- gtk_list_box_row_set_activatable (row, FALSE);
- revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (row), "edit-tool-details-revealer"));
- gtk_revealer_set_reveal_child (revealer, TRUE);
+ photos_edit_palette_row_show_details (PHOTOS_EDIT_PALETTE_ROW (row));
for (i = 0; (other_row = gtk_list_box_get_row_at_index (box, i)) != NULL; i++)
{
if (other_row == row)
continue;
- gtk_list_box_row_set_activatable (other_row, TRUE);
- revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (other_row), "edit-tool-details-revealer"));
- gtk_revealer_set_reveal_child (revealer, FALSE);
+ photos_edit_palette_row_hide_details (PHOTOS_EDIT_PALETTE_ROW (other_row));
}
- tool = PHOTOS_TOOL (g_object_get_data (G_OBJECT (row), "edit-tool"));
+ tool = photos_edit_palette_row_get_tool (PHOTOS_EDIT_PALETTE_ROW (row));
g_signal_emit (self, signals[TOOL_CHANGED], 0, tool);
}
@@ -202,66 +181,18 @@ photos_edit_palette_init (PhotosEditPalette *self)
{
GIOExtension *extension = (GIOExtension *) l->data;
GType type;
- GtkWidget *grid0;
- GtkWidget *grid1;
- GtkWidget *image;
- GtkWidget *label;
- GtkWidget *revealer;
GtkWidget *row;
- GtkWidget *tool_widget;
PhotosTool *tool;
- const gchar *icon_name;
- const gchar *name;
- gchar *name_markup;
type = g_io_extension_get_type (extension);
tool = PHOTOS_TOOL (g_object_new (type, NULL));
self->tools = g_list_prepend (self->tools, g_object_ref (tool));
- row = gtk_list_box_row_new ();
- g_object_set_data_full (G_OBJECT (row), "edit-tool", g_object_ref (tool), g_object_unref);
+ row = photos_edit_palette_row_new (tool, self->size_group);
gtk_container_add (GTK_CONTAINER (self), row);
- grid0 = gtk_grid_new ();
- gtk_widget_set_margin_bottom (grid0, 6);
- gtk_widget_set_margin_start (grid0, 18);
- gtk_widget_set_margin_end (grid0, 18);
- gtk_widget_set_margin_top (grid0, 6);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid0), GTK_ORIENTATION_VERTICAL);
- gtk_container_add (GTK_CONTAINER (row), grid0);
-
- grid1 = gtk_grid_new ();
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_HORIZONTAL);
- gtk_grid_set_column_spacing (GTK_GRID (grid1), 12);
- gtk_container_add (GTK_CONTAINER (grid0), grid1);
-
- icon_name = photos_tool_get_icon_name (tool);
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
- gtk_container_add (GTK_CONTAINER (grid1), image);
-
- name = photos_tool_get_name (tool);
- label = gtk_label_new (NULL);
- name_markup = g_strdup_printf ("<b>%s</b>", name);
- gtk_label_set_markup (GTK_LABEL (label), name_markup);
- gtk_container_add (GTK_CONTAINER (grid1), label);
-
- revealer = gtk_revealer_new ();
- gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
- g_object_set_data (G_OBJECT (row), "edit-tool-details-revealer", revealer);
- gtk_container_add (GTK_CONTAINER (grid0), revealer);
-
- tool_widget = photos_tool_get_widget (tool);
- gtk_widget_set_margin_bottom (tool_widget, 12);
- gtk_widget_set_margin_top (tool_widget, 12);
- gtk_container_add (GTK_CONTAINER (revealer), tool_widget);
- gtk_size_group_add_widget (self->size_group, tool_widget);
-
- g_signal_connect_swapped (tool, "hide-requested", G_CALLBACK (photos_edit_palette_hide_requested),
row);
- g_signal_connect_swapped (tool,
- "hide-requested",
- G_CALLBACK (photos_edit_palette_hide_requested_second),
- self);
- g_free (name_markup);
+ g_signal_connect_swapped (tool, "hide-requested", G_CALLBACK (photos_edit_palette_hide_requested),
self);
+
g_object_unref (tool);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]