summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Wimpress <[email protected]>2015-06-15 20:08:18 +0100
committerMartin Wimpress <[email protected]>2015-06-15 20:08:18 +0100
commit232a6c95d121fb92c372476a29fabf4846446143 (patch)
treea9cc643e8276a441d4fcd379ae0e288d515c0d66
parent77d3fe8eb9c69de333a53e54c681d27eff6ec223 (diff)
parent16ecee965b67eaf37e52c745f6369f49377e86b2 (diff)
downloadeom-232a6c95d121fb92c372476a29fabf4846446143.tar.bz2
eom-232a6c95d121fb92c372476a29fabf4846446143.tar.xz
Merge pull request #81 from NiceandGently/dev-thumbview
GTK3: fix broken thumbview
-rw-r--r--src/eom-thumb-nav.c20
-rw-r--r--src/eom-thumb-view.c175
2 files changed, 195 insertions, 0 deletions
diff --git a/src/eom-thumb-nav.c b/src/eom-thumb-nav.c
index 702b4c5..24c2431 100644
--- a/src/eom-thumb-nav.c
+++ b/src/eom-thumb-nav.c
@@ -545,8 +545,13 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode)
switch (mode)
{
case EOM_THUMB_NAV_MODE_ONE_ROW:
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview),
+ GTK_ORIENTATION_HORIZONTAL);
+#else
gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview),
G_MAXINT);
+#endif
gtk_widget_set_size_request (priv->thumbview, -1, -1);
eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview),
@@ -561,7 +566,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode)
break;
case EOM_THUMB_NAV_MODE_ONE_COLUMN:
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview),
+ GTK_ORIENTATION_VERTICAL);
+#else
gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), 1);
+#endif
gtk_widget_set_size_request (priv->thumbview, -1, -1);
eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview),
@@ -577,7 +587,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode)
break;
case EOM_THUMB_NAV_MODE_MULTIPLE_ROWS:
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview),
+ GTK_ORIENTATION_VERTICAL);
+#else
gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), -1);
+#endif
gtk_widget_set_size_request (priv->thumbview, -1, 220);
eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview),
@@ -593,7 +608,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode)
break;
case EOM_THUMB_NAV_MODE_MULTIPLE_COLUMNS:
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview),
+ GTK_ORIENTATION_VERTICAL);
+#else
gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), -1);
+#endif
gtk_widget_set_size_request (priv->thumbview, 230, -1);
eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview),
diff --git a/src/eom-thumb-view.c b/src/eom-thumb-view.c
index e52886c..aba4eba 100644
--- a/src/eom-thumb-view.c
+++ b/src/eom-thumb-view.c
@@ -38,12 +38,23 @@
#include <stdlib.h>
#include <string.h>
+#if GTK_CHECK_VERSION (3, 4, 3)
+enum {
+ PROP_0,
+ PROP_ORIENTATION
+};
+#endif
+
#define EOM_THUMB_VIEW_SPACING 0
#define EOM_THUMB_VIEW_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EOM_TYPE_THUMB_VIEW, EomThumbViewPrivate))
+#if GTK_CHECK_VERSION (3, 4, 3)
+static void eom_thumb_view_init (EomThumbView *thumbview);
+#else
G_DEFINE_TYPE (EomThumbView, eom_thumb_view, GTK_TYPE_ICON_VIEW);
+#endif
static EomImage* eom_thumb_view_get_image_from_path (EomThumbView *thumbview,
GtkTreePath *path);
@@ -51,6 +62,13 @@ static EomImage* eom_thumb_view_get_image_from_path (EomThumbView *thumbvie
static void eom_thumb_view_popup_menu (EomThumbView *widget,
GdkEventButton *event);
+#if GTK_CHECK_VERSION (3, 4, 3)
+static void eom_thumb_view_update_columns (EomThumbView *view);
+
+G_DEFINE_TYPE_WITH_CODE (EomThumbView, eom_thumb_view, GTK_TYPE_ICON_VIEW,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
+#endif
+
static gboolean
thumbview_on_query_tooltip_cb (GtkWidget *widget,
gint x,
@@ -81,6 +99,13 @@ struct _EomThumbViewPrivate {
GtkWidget *menu; /* a contextual menu for thumbnails */
GtkCellRenderer *pixbuf_cell;
gint visible_range_changed_id;
+
+#if GTK_CHECK_VERSION (3, 4, 3)
+ GtkOrientation orientation;
+ gint n_images;
+ gulong image_add_id;
+ gulong image_removed_id;
+#endif
};
/* Drag 'n Drop */
@@ -152,12 +177,29 @@ static void
eom_thumb_view_dispose (GObject *object)
{
EomThumbViewPrivate *priv = EOM_THUMB_VIEW (object)->priv;
+#if GTK_CHECK_VERSION (3, 4, 3)
+ GtkTreeModel *model;
+#endif
if (priv->visible_range_changed_id != 0) {
g_source_remove (priv->visible_range_changed_id);
priv->visible_range_changed_id = 0;
}
+#if GTK_CHECK_VERSION (3, 4, 3)
+ model = gtk_icon_view_get_model (GTK_ICON_VIEW (object));
+
+ if (model && priv->image_add_id != 0) {
+ g_signal_handler_disconnect (model, priv->image_add_id);
+ priv->image_add_id = 0;
+ }
+
+ if (model && priv->image_removed_id) {
+ g_signal_handler_disconnect (model, priv->image_removed_id);
+ priv->image_removed_id = 0;
+ }
+#endif
+
G_OBJECT_CLASS (eom_thumb_view_parent_class)->dispose (object);
}
@@ -189,6 +231,50 @@ eom_thumb_view_destroy (GtkObject *object)
#endif
}
+#if GTK_CHECK_VERSION (3, 4, 3)
+static void
+eom_thumb_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EomThumbView *view = EOM_THUMB_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, view->priv->orientation);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+eom_thumb_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EomThumbView *view = EOM_THUMB_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_ORIENTATION:
+ view->priv->orientation = g_value_get_enum (value);
+#if GTK_CHECK_VERSION (3, 4, 3)
+ eom_thumb_view_update_columns (view);
+#endif
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+#endif
+
static void
eom_thumb_view_class_init (EomThumbViewClass *class)
{
@@ -200,6 +286,13 @@ eom_thumb_view_class_init (EomThumbViewClass *class)
#endif
gobject_class->constructed = eom_thumb_view_constructed;
gobject_class->dispose = eom_thumb_view_dispose;
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gobject_class->get_property = eom_thumb_view_get_property;
+ gobject_class->set_property = eom_thumb_view_set_property;
+
+ g_object_class_override_property (gobject_class, PROP_ORIENTATION,
+ "orientation");
+#endif
gobject_class->finalize = eom_thumb_view_finalize;
#if GTK_CHECK_VERSION(3, 0, 0)
widget_class->destroy = eom_thumb_view_destroy;
@@ -616,6 +709,10 @@ eom_thumb_view_init (EomThumbView *thumbview)
thumbview->priv = EOM_THUMB_VIEW_GET_PRIVATE (thumbview);
thumbview->priv->visible_range_changed_id = 0;
+#if GTK_CHECK_VERSION (3, 4, 3)
+ thumbview->priv->image_add_id = 0;
+ thumbview->priv->image_removed_id = 0;
+#endif
}
/**
@@ -635,6 +732,45 @@ eom_thumb_view_new (void)
return GTK_WIDGET (thumbview);
}
+#if GTK_CHECK_VERSION (3, 4, 3)
+static void
+eom_thumb_view_update_columns (EomThumbView *view)
+{
+ EomThumbViewPrivate *priv;
+
+ g_return_if_fail (EOM_IS_THUMB_VIEW (view));
+
+ priv = view->priv;
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_icon_view_set_columns (GTK_ICON_VIEW (view),
+ priv->n_images);
+}
+
+static void
+eom_thumb_view_row_inserted_cb (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ EomThumbView *view)
+{
+ EomThumbViewPrivate *priv = view->priv;
+
+ priv->n_images++;
+ eom_thumb_view_update_columns (view);
+}
+
+static void
+eom_thumb_view_row_deleted_cb (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ EomThumbView *view)
+{
+ EomThumbViewPrivate *priv = view->priv;
+
+ priv->n_images--;
+ eom_thumb_view_update_columns (view);
+}
+#endif
+
/**
* eom_thumb_view_set_model:
* @thumbview: A #EomThumbView.
@@ -648,13 +784,52 @@ void
eom_thumb_view_set_model (EomThumbView *thumbview, EomListStore *store)
{
gint index;
+#if GTK_CHECK_VERSION (3, 4, 3)
+ EomThumbViewPrivate *priv;
+ GtkTreeModel *existing;
+#endif
g_return_if_fail (EOM_IS_THUMB_VIEW (thumbview));
g_return_if_fail (EOM_IS_LIST_STORE (store));
+#if GTK_CHECK_VERSION (3, 4, 3)
+ priv = thumbview->priv;
+
+ existing = gtk_icon_view_get_model (GTK_ICON_VIEW (thumbview));
+
+ if (existing != NULL) {
+ if (priv->image_add_id != 0) {
+ g_signal_handler_disconnect (existing,
+ priv->image_add_id);
+ }
+ if (priv->image_removed_id != 0) {
+ g_signal_handler_disconnect (existing,
+ priv->image_removed_id);
+
+ }
+ }
+
+ priv->image_add_id = g_signal_connect (G_OBJECT (store), "row-inserted",
+ G_CALLBACK (eom_thumb_view_row_inserted_cb),
+ thumbview);
+ priv->image_removed_id = g_signal_connect (G_OBJECT (store),
+ "row-deleted",
+ G_CALLBACK (eom_thumb_view_row_deleted_cb),
+ thumbview);
+
+ thumbview->priv->n_images = eom_list_store_length (store);
+#endif
+
index = eom_list_store_get_initial_pos (store);
+#if GTK_CHECK_VERSION (3, 4, 3)
+ gtk_icon_view_set_model (GTK_ICON_VIEW (thumbview),
+ GTK_TREE_MODEL (store));
+
+ eom_thumb_view_update_columns (thumbview);
+#else
gtk_icon_view_set_model (GTK_ICON_VIEW (thumbview), GTK_TREE_MODEL (store));
+#endif
if (index >= 0) {
GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1);