summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/eom-thumb-nav.c20
-rw-r--r--src/eom-thumb-view.c107
2 files changed, 127 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 1a8f4f1..aba4eba 100644
--- a/src/eom-thumb-view.c
+++ b/src/eom-thumb-view.c
@@ -63,6 +63,8 @@ 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
@@ -100,6 +102,9 @@ struct _EomThumbViewPrivate {
#if GTK_CHECK_VERSION (3, 4, 3)
GtkOrientation orientation;
+ gint n_images;
+ gulong image_add_id;
+ gulong image_removed_id;
#endif
};
@@ -172,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);
}
@@ -242,6 +264,9 @@ eom_thumb_view_set_property (GObject *object,
{
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);
@@ -684,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
}
/**
@@ -703,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.
@@ -716,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);