aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fastiv.c47
-rw-r--r--fiv-view.c41
2 files changed, 83 insertions, 5 deletions
diff --git a/fastiv.c b/fastiv.c
index 2129d50..daa1a53 100644
--- a/fastiv.c
+++ b/fastiv.c
@@ -602,9 +602,7 @@ make_toolbar_button(const gchar *symbolic, const gchar *tooltip)
GtkWidget *button =
gtk_button_new_from_icon_name(symbolic, GTK_ICON_SIZE_BUTTON);
gtk_widget_set_tooltip_text(button, tooltip);
-// gtk_widget_set_sensitive(button, FALSE);
gtk_widget_set_focus_on_click(button, FALSE);
-
gtk_style_context_add_class(
gtk_widget_get_style_context(button), GTK_STYLE_CLASS_FLAT);
return button;
@@ -617,9 +615,7 @@ make_toolbar_toggle(const gchar *symbolic, const gchar *tooltip)
gtk_button_set_image(GTK_BUTTON(button),
gtk_image_new_from_icon_name(symbolic, GTK_ICON_SIZE_BUTTON));
gtk_widget_set_tooltip_text(button, tooltip);
-// gtk_widget_set_sensitive(button, FALSE);
gtk_widget_set_focus_on_click(button, FALSE);
-
gtk_style_context_add_class(
gtk_widget_get_style_context(button), GTK_STYLE_CLASS_FLAT);
return button;
@@ -637,6 +633,42 @@ make_separator(void)
}
static void
+on_view_actions_changed(void)
+{
+ gboolean has_image = FALSE, can_animate = FALSE;
+ gboolean has_previous = FALSE, has_next = FALSE;
+ g_object_get(g.view, "has-image", &has_image, "can-animate", &can_animate,
+ "has-previous-page", &has_previous, "has-next-page", &has_next, NULL);
+
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PAGE_FIRST], has_previous);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PAGE_PREVIOUS], has_previous);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PAGE_NEXT], has_next);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PAGE_LAST], has_next);
+
+ // We don't want these to flash during playback.
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SKIP_BACK], can_animate);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SEEK_BACK], can_animate);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PLAY_PAUSE], can_animate);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SEEK_FORWARD], can_animate);
+
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PLUS], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SCALE], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_MINUS], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_ONE], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_FIT], has_image);
+
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SMOOTH], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_SAVE], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_PRINT], has_image);
+
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_LEFT], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_MIRROR], has_image);
+ gtk_widget_set_sensitive(g.toolbar[TOOLBAR_RIGHT], has_image);
+}
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+static void
on_notify_view_scale(
GObject *object, GParamSpec *param_spec, G_GNUC_UNUSED gpointer user_data)
{
@@ -771,6 +803,13 @@ make_view_toolbar(void)
g_object_notify(G_OBJECT(g.view), "playing");
g_object_notify(G_OBJECT(g.view), "scale-to-fit");
g_object_notify(G_OBJECT(g.view), "filter");
+
+ GCallback callback = G_CALLBACK(on_view_actions_changed);
+ g_signal_connect(g.view, "notify::has-image", callback, NULL);
+ g_signal_connect(g.view, "notify::can-animate", callback, NULL);
+ g_signal_connect(g.view, "notify::has-previous-page", callback, NULL);
+ g_signal_connect(g.view, "notify::has-next-page", callback, NULL);
+ callback();
return view_toolbar;
}
diff --git a/fiv-view.c b/fiv-view.c
index 3311e2c..9a80d30 100644
--- a/fiv-view.c
+++ b/fiv-view.c
@@ -89,6 +89,10 @@ enum {
PROP_SCALE_TO_FIT,
PROP_FILTER,
PROP_PLAYING,
+ PROP_HAS_IMAGE,
+ PROP_CAN_ANIMATE,
+ PROP_HAS_PREVIOUS_PAGE,
+ PROP_HAS_NEXT_PAGE,
N_PROPERTIES
};
@@ -121,6 +125,20 @@ fiv_view_get_property(
case PROP_PLAYING:
g_value_set_boolean(value, !!self->frame_update_connection);
break;
+ case PROP_HAS_IMAGE:
+ g_value_set_boolean(value, !!self->image);
+ break;
+ case PROP_CAN_ANIMATE:
+ g_value_set_boolean(value, self->page &&
+ cairo_surface_get_user_data(self->page, &fiv_io_key_frame_next));
+ break;
+ case PROP_HAS_PREVIOUS_PAGE:
+ g_value_set_boolean(value, self->image && self->page != self->image);
+ break;
+ case PROP_HAS_NEXT_PAGE:
+ g_value_set_boolean(value, self->page &&
+ cairo_surface_get_user_data(self->page, &fiv_io_key_page_next));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
@@ -564,6 +582,13 @@ switch_page(FivView *self, cairo_surface_t *page)
start_animating(self);
gtk_widget_queue_resize(GTK_WIDGET(self));
+
+ g_object_notify_by_pspec(
+ G_OBJECT(self), view_properties[PROP_CAN_ANIMATE]);
+ g_object_notify_by_pspec(
+ G_OBJECT(self), view_properties[PROP_HAS_PREVIOUS_PAGE]);
+ g_object_notify_by_pspec(
+ G_OBJECT(self), view_properties[PROP_HAS_NEXT_PAGE]);
}
static void
@@ -821,7 +846,19 @@ fiv_view_class_init(FivViewClass *klass)
TRUE, G_PARAM_READWRITE);
view_properties[PROP_PLAYING] = g_param_spec_boolean(
"playing", "Playing animation", "An animation is running",
- TRUE, G_PARAM_READWRITE);
+ FALSE, G_PARAM_READABLE);
+ view_properties[PROP_HAS_IMAGE] = g_param_spec_boolean(
+ "has-image", "Has an image", "An image is loaded",
+ FALSE, G_PARAM_READABLE);
+ view_properties[PROP_CAN_ANIMATE] = g_param_spec_boolean(
+ "can-animate", "Can animate", "An animation is loaded",
+ FALSE, G_PARAM_READABLE);
+ view_properties[PROP_HAS_PREVIOUS_PAGE] = g_param_spec_boolean(
+ "has-previous-page", "Has a previous page", "Preceding pages exist",
+ FALSE, G_PARAM_READABLE);
+ view_properties[PROP_HAS_NEXT_PAGE] = g_param_spec_boolean(
+ "has-next-page", "Has a next page", "Following pages exist",
+ FALSE, G_PARAM_READABLE);
g_object_class_install_properties(
object_class, N_PROPERTIES, view_properties);
@@ -867,6 +904,8 @@ fiv_view_open(FivView *self, const gchar *path, GError **error)
self->image = surface;
switch_page(self, self->image);
set_scale_to_fit(self, true);
+
+ g_object_notify_by_pspec(G_OBJECT(self), view_properties[PROP_HAS_IMAGE]);
return TRUE;
}