[gthumb] slideshow: added back the random order option
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] slideshow: added back the random order option
- Date: Mon, 16 Aug 2010 11:01:23 +0000 (UTC)
commit 6805be543544b3eca8328b1c6b5649793afeac93
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Aug 15 11:14:25 2010 +0200
slideshow: added back the random order option
[bug #621244]
extensions/slideshow/actions.c | 2 +
extensions/slideshow/callbacks.c | 25 ++++++++++-
.../slideshow/data/gthumb-slideshow.schemas.in | 13 ++++++
.../slideshow/data/ui/slideshow-preferences.ui | 15 ++++++-
extensions/slideshow/gth-slideshow-preferences.c | 17 ++++++-
extensions/slideshow/gth-slideshow-preferences.h | 4 +-
extensions/slideshow/gth-slideshow.c | 43 ++++++++++++++++---
extensions/slideshow/gth-slideshow.h | 30 +++++++------
extensions/slideshow/preferences.c | 15 ++++++-
extensions/slideshow/preferences.h | 1 +
10 files changed, 136 insertions(+), 29 deletions(-)
---
diff --git a/extensions/slideshow/actions.c b/extensions/slideshow/actions.c
index d940672..17dcc97 100644
--- a/extensions/slideshow/actions.c
+++ b/extensions/slideshow/actions.c
@@ -85,11 +85,13 @@ gth_browser_activate_action_view_slideshow (GtkAction *action,
gth_slideshow_set_delay (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_int32 (location->info, "slideshow::delay"));
gth_slideshow_set_automatic (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::automatic"));
gth_slideshow_set_wrap_around (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::wrap-around"));
+ gth_slideshow_set_random_order (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::random-order"));
}
else {
gth_slideshow_set_delay (GTH_SLIDESHOW (slideshow), (guint) (1000.0 * eel_gconf_get_float (PREF_SLIDESHOW_CHANGE_DELAY, 5.0)));
gth_slideshow_set_automatic (GTH_SLIDESHOW (slideshow), eel_gconf_get_boolean (PREF_SLIDESHOW_AUTOMATIC, TRUE));
gth_slideshow_set_wrap_around (GTH_SLIDESHOW (slideshow), eel_gconf_get_boolean (PREF_SLIDESHOW_WRAP_AROUND, FALSE));
+ gth_slideshow_set_random_order (GTH_SLIDESHOW (slideshow), eel_gconf_get_boolean (PREF_SLIDESHOW_RANDOM_ORDER, FALSE));
}
if (g_file_info_get_attribute_status (location->info, "slideshow::playlist") == G_FILE_ATTRIBUTE_STATUS_SET)
diff --git a/extensions/slideshow/callbacks.c b/extensions/slideshow/callbacks.c
index 45d45be..eeeb81e 100644
--- a/extensions/slideshow/callbacks.c
+++ b/extensions/slideshow/callbacks.c
@@ -151,6 +151,10 @@ ss__gth_catalog_read_metadata (GthCatalog *catalog,
g_value_hash_set_boolean (catalog->attributes,
"slideshow::wrap-around",
g_file_info_get_attribute_boolean (file_data->info, "slideshow::wrap-around"));
+ if (g_file_info_get_attribute_status (file_data->info, "slideshow::random-order") == G_FILE_ATTRIBUTE_STATUS_SET)
+ g_value_hash_set_boolean (catalog->attributes,
+ "slideshow::random-order",
+ g_file_info_get_attribute_boolean (file_data->info, "slideshow::random-order"));
if (g_file_info_get_attribute_status (file_data->info, "slideshow::delay") == G_FILE_ATTRIBUTE_STATUS_SET)
g_value_hash_set_int (catalog->attributes,
"slideshow::delay",
@@ -194,6 +198,14 @@ ss__gth_catalog_write_metadata (GthCatalog *catalog,
"slideshow::wrap-around",
G_FILE_ATTRIBUTE_STATUS_SET);
}
+ if (g_value_hash_is_set (catalog->attributes, "slideshow::random-order")) {
+ g_file_info_set_attribute_boolean (file_data->info,
+ "slideshow::random-order",
+ g_value_hash_get_boolean (catalog->attributes, "slideshow::random-order"));
+ g_file_info_set_attribute_status (file_data->info,
+ "slideshow::random-order",
+ G_FILE_ATTRIBUTE_STATUS_SET);
+ }
if (g_value_hash_is_set (catalog->attributes, "slideshow::delay")) {
g_file_info_set_attribute_int32 (file_data->info,
"slideshow::delay",
@@ -242,6 +254,9 @@ ss__gth_catalog_read_from_doc (GthCatalog *catalog,
g_value_hash_set_boolean (catalog->attributes,
"slideshow::wrap-around",
g_strcmp0 (dom_element_get_attribute (node, "wrap-around"), "true") == 0);
+ g_value_hash_set_boolean (catalog->attributes,
+ "slideshow::random-order",
+ g_strcmp0 (dom_element_get_attribute (node, "random-order"), "true") == 0);
for (child = node->first_child; child; child = child->next_sibling) {
if (g_strcmp0 (child->tag_name, "delay") == 0) {
@@ -303,6 +318,7 @@ ss__gth_catalog_write_to_doc (GthCatalog *catalog,
"personalize", (g_value_hash_get_boolean_or_default (catalog->attributes, "slideshow::personalize", FALSE) ? "true" : "false"),
"automatic", (g_value_hash_get_boolean_or_default (catalog->attributes, "slideshow::automatic", FALSE) ? "true" : "false"),
"wrap-around", (g_value_hash_get_boolean_or_default (catalog->attributes, "slideshow::wrap-around", FALSE) ? "true" : "false"),
+ "random-order", (g_value_hash_get_boolean_or_default (catalog->attributes, "slideshow::random-order", FALSE) ? "true" : "false"),
NULL);
dom_element_append_child (root, slideshow);
@@ -358,7 +374,8 @@ ss__dlg_catalog_properties (GtkBuilder *builder,
slideshow_preferences = gth_slideshow_preferences_new (current_transition,
eel_gconf_get_boolean (PREF_SLIDESHOW_AUTOMATIC, TRUE),
(int) (1000.0 * eel_gconf_get_float (PREF_SLIDESHOW_CHANGE_DELAY, 5.0)),
- eel_gconf_get_boolean (PREF_SLIDESHOW_WRAP_AROUND, FALSE));
+ eel_gconf_get_boolean (PREF_SLIDESHOW_WRAP_AROUND, FALSE),
+ eel_gconf_get_boolean (PREF_SLIDESHOW_RANDOM_ORDER, FALSE));
gtk_widget_set_sensitive (gth_slideshow_preferences_get_widget (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences), "personalize_box"), FALSE);
g_free (current_transition);
@@ -367,7 +384,8 @@ ss__dlg_catalog_properties (GtkBuilder *builder,
slideshow_preferences = gth_slideshow_preferences_new (g_value_hash_get_string (catalog->attributes, "slideshow::transition"),
g_value_hash_get_boolean (catalog->attributes, "slideshow::automatic"),
g_value_hash_get_int (catalog->attributes, "slideshow::delay"),
- g_value_hash_get_boolean (catalog->attributes, "slideshow::wrap-around"));
+ g_value_hash_get_boolean (catalog->attributes, "slideshow::wrap-around"),
+ g_value_hash_get_boolean (catalog->attributes, "slideshow::random-order"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gth_slideshow_preferences_get_widget (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences), "personalize_checkbutton")), TRUE);
gtk_widget_set_sensitive (gth_slideshow_preferences_get_widget (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences), "personalize_box"), TRUE);
}
@@ -423,6 +441,9 @@ ss__dlg_catalog_properties_save (GtkBuilder *builder,
g_value_hash_set_boolean (catalog->attributes,
"slideshow::wrap-around",
gth_slideshow_preferences_get_wrap_around (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences)));
+ g_value_hash_set_boolean (catalog->attributes,
+ "slideshow::random-order",
+ gth_slideshow_preferences_get_random_order (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences)));
files = gth_slideshow_preferences_get_audio_files (GTH_SLIDESHOW_PREFERENCES (slideshow_preferences));
g_value_hash_set_stringv (catalog->attributes,
diff --git a/extensions/slideshow/data/gthumb-slideshow.schemas.in b/extensions/slideshow/data/gthumb-slideshow.schemas.in
index 0cf6bb6..19c7e1b 100644
--- a/extensions/slideshow/data/gthumb-slideshow.schemas.in
+++ b/extensions/slideshow/data/gthumb-slideshow.schemas.in
@@ -53,5 +53,18 @@
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/gthumb/ext/slideshow/random-order</key>
+ <applyto>/apps/gthumb/ext/slideshow/random-order</applyto>
+ <owner>gthumb</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short></short>
+ <long>
+ </long>
+ </locale>
+ </schema>
+
</schemalist>
</gconfschemafile>
diff --git a/extensions/slideshow/data/ui/slideshow-preferences.ui b/extensions/slideshow/data/ui/slideshow-preferences.ui
index b9bd262..afb8d6d 100644
--- a/extensions/slideshow/data/ui/slideshow-preferences.ui
+++ b/extensions/slideshow/data/ui/slideshow-preferences.ui
@@ -3,9 +3,9 @@
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAdjustment" id="delay_adjustment">
+ <property name="value">5</property>
<property name="lower">0.10000000000000001</property>
<property name="upper">100</property>
- <property name="value">5</property>
<property name="step_increment">0.10000000000000001</property>
</object>
<object class="GtkListStore" id="files_liststore">
@@ -176,6 +176,19 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="random_order_checkbutton">
+ <property name="label" translatable="yes">R_andom order</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/extensions/slideshow/gth-slideshow-preferences.c b/extensions/slideshow/gth-slideshow-preferences.c
index c58fae5..2114f29 100644
--- a/extensions/slideshow/gth-slideshow-preferences.c
+++ b/extensions/slideshow/gth-slideshow-preferences.c
@@ -237,7 +237,8 @@ gth_slideshow_preferences_construct (GthSlideshowPreferences *self,
const char *current_transition,
gboolean automatic,
int delay,
- gboolean wrap_around)
+ gboolean wrap_around,
+ gboolean random_order)
{
GtkListStore *model;
GtkCellRenderer *renderer;
@@ -291,6 +292,7 @@ gth_slideshow_preferences_construct (GthSlideshowPreferences *self,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "automatic_checkbutton")), automatic);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (_gtk_builder_get_widget (self->priv->builder, "change_delay_spinbutton")), ((float) delay) / 1000.0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "wrap_around_checkbutton")), wrap_around);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "random_order_checkbutton")), random_order);
/* signals */
@@ -317,7 +319,8 @@ GtkWidget *
gth_slideshow_preferences_new (const char *transition,
gboolean automatic,
int delay,
- gboolean wrap_around)
+ gboolean wrap_around,
+ gboolean random_order)
{
GtkWidget *widget;
@@ -326,7 +329,8 @@ gth_slideshow_preferences_new (const char *transition,
transition,
automatic,
delay,
- wrap_around);
+ wrap_around,
+ random_order);
return widget;
}
@@ -426,6 +430,13 @@ gth_slideshow_preferences_get_wrap_around (GthSlideshowPreferences *self)
}
+gboolean
+gth_slideshow_preferences_get_random_order (GthSlideshowPreferences *self)
+{
+ return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder, "random_order_checkbutton")));
+}
+
+
char **
gth_slideshow_preferences_get_audio_files (GthSlideshowPreferences *self)
{
diff --git a/extensions/slideshow/gth-slideshow-preferences.h b/extensions/slideshow/gth-slideshow-preferences.h
index 409666b..c7445bd 100644
--- a/extensions/slideshow/gth-slideshow-preferences.h
+++ b/extensions/slideshow/gth-slideshow-preferences.h
@@ -52,7 +52,8 @@ GType gth_slideshow_preferences_get_type (void);
GtkWidget * gth_slideshow_preferences_new (const char *transition,
gboolean automatic,
int delay,
- gboolean wrap_around);
+ gboolean wrap_around,
+ gboolean random_order);
void gth_slideshow_preferences_set_audio (GthSlideshowPreferences *self,
char **files);
GtkWidget * gth_slideshow_preferences_get_widget (GthSlideshowPreferences *self,
@@ -62,6 +63,7 @@ char * gth_slideshow_preferences_get_transition_id (GthSlideshowPreferen
gboolean gth_slideshow_preferences_get_automatic (GthSlideshowPreferences *self);
int gth_slideshow_preferences_get_delay (GthSlideshowPreferences *self);
gboolean gth_slideshow_preferences_get_wrap_around (GthSlideshowPreferences *self);
+gboolean gth_slideshow_preferences_get_random_order (GthSlideshowPreferences *self);
char ** gth_slideshow_preferences_get_audio_files (GthSlideshowPreferences *self);
G_END_DECLS
diff --git a/extensions/slideshow/gth-slideshow.c b/extensions/slideshow/gth-slideshow.c
index b2972dc..bdcff06 100644
--- a/extensions/slideshow/gth-slideshow.c
+++ b/extensions/slideshow/gth-slideshow.c
@@ -75,6 +75,7 @@ struct _GthSlideshowPrivate {
#endif
gboolean paused;
gboolean animating;
+ gboolean random_order;
};
@@ -96,6 +97,28 @@ _gth_slideshow_close (GthSlideshow *self)
}
+static int
+shuffle_func (gconstpointer a,
+ gconstpointer b)
+{
+ return g_random_int_range (-1, 2);
+}
+
+
+
+static void
+_gth_slideshow_reset_current (GthSlideshow *self)
+{
+ if (self->priv->random_order)
+ self->priv->file_list = g_list_sort (self->priv->file_list, shuffle_func);
+
+ if (self->priv->direction == GTH_SLIDESHOW_DIRECTION_FORWARD)
+ self->priv->current = g_list_first (self->priv->file_list);
+ else
+ self->priv->current = g_list_last (self->priv->file_list);
+}
+
+
static void
_gth_slideshow_load_current_image (GthSlideshow *self)
{
@@ -113,11 +136,7 @@ _gth_slideshow_load_current_image (GthSlideshow *self)
_gth_slideshow_close (self);
return;
}
-
- if (self->priv->direction == GTH_SLIDESHOW_DIRECTION_FORWARD)
- self->priv->current = g_list_first (self->priv->file_list);
- else
- self->priv->current = g_list_last (self->priv->file_list);
+ _gth_slideshow_reset_current (self);
}
requested_file = (GthFileData *) self->priv->current->data;
@@ -239,6 +258,7 @@ gth_slideshow_init (GthSlideshow *self)
self->priv->paused = FALSE;
self->priv->animating = FALSE;
self->priv->direction = GTH_SLIDESHOW_DIRECTION_FORWARD;
+ self->priv->random_order = FALSE;
self->priv->preloader = gth_image_preloader_new ();
g_signal_connect (self->priv->preloader,
@@ -383,6 +403,8 @@ gth_slideshow_show_cb (GtkWidget *widget,
if (! self->priv->first_show)
return;
+ self->priv->first_show = FALSE;
+
#if HAVE_GSTREAMER
if ((self->priv->audio_files != NULL)
&& (self->priv->audio_files[0] != NULL)
@@ -404,8 +426,8 @@ gth_slideshow_show_cb (GtkWidget *widget,
}
#endif
+ _gth_slideshow_reset_current (self);
_gth_slideshow_load_current_image (self);
- self->priv->first_show = FALSE;
}
@@ -418,7 +440,6 @@ _gth_slideshow_construct (GthSlideshow *self,
self->priv->projector = projector;
self->priv->browser = _g_object_ref (browser);
self->priv->file_list = _g_object_list_ref (file_list);
- self->priv->current = self->priv->file_list;
self->priv->one_loaded = FALSE;
self->priv->projector->construct (self);
@@ -486,6 +507,14 @@ gth_slideshow_set_playlist (GthSlideshow *self,
}
+void
+gth_slideshow_set_random_order (GthSlideshow *self,
+ gboolean random)
+{
+ self->priv->random_order = random;
+}
+
+
/* -- default projector -- */
diff --git a/extensions/slideshow/gth-slideshow.h b/extensions/slideshow/gth-slideshow.h
index c3ceb65..f0154d7 100644
--- a/extensions/slideshow/gth-slideshow.h
+++ b/extensions/slideshow/gth-slideshow.h
@@ -76,20 +76,22 @@ extern GthProjector default_projector;
extern GthProjector clutter_projector;
#endif /* HAVE_CLUTTER */
-GType gth_slideshow_get_type (void);
-GtkWidget * gth_slideshow_new (GthProjector *projector,
- GthBrowser *browser,
- GList *file_list /* GthFileData */);
-void gth_slideshow_set_delay (GthSlideshow *self,
- guint msecs);
-void gth_slideshow_set_automatic (GthSlideshow *self,
- gboolean automatic);
-void gth_slideshow_set_wrap_around (GthSlideshow *self,
- gboolean wrap_around);
-void gth_slideshow_set_transitions (GthSlideshow *self,
- GList *transitions);
-void gth_slideshow_set_playlist (GthSlideshow *self,
- char **files);
+GType gth_slideshow_get_type (void);
+GtkWidget * gth_slideshow_new (GthProjector *projector,
+ GthBrowser *browser,
+ GList *file_list /* GthFileData */);
+void gth_slideshow_set_delay (GthSlideshow *self,
+ guint msecs);
+void gth_slideshow_set_automatic (GthSlideshow *self,
+ gboolean automatic);
+void gth_slideshow_set_wrap_around (GthSlideshow *self,
+ gboolean wrap_around);
+void gth_slideshow_set_transitions (GthSlideshow *self,
+ GList *transitions);
+void gth_slideshow_set_playlist (GthSlideshow *self,
+ char **files);
+void gth_slideshow_set_random_order (GthSlideshow *self,
+ gboolean random);
G_END_DECLS
diff --git a/extensions/slideshow/preferences.c b/extensions/slideshow/preferences.c
index 5f10d8b..3c8dbd9 100644
--- a/extensions/slideshow/preferences.c
+++ b/extensions/slideshow/preferences.c
@@ -73,6 +73,14 @@ wrap_around_checkbutton_toggled_cb (GtkToggleButton *button,
static void
+random_order_checkbutton_toggled_cb (GtkToggleButton *button,
+ BrowserData *data)
+{
+ eel_gconf_set_boolean (PREF_SLIDESHOW_RANDOM_ORDER, gtk_toggle_button_get_active (button));
+}
+
+
+static void
change_delay_spinbutton_value_changed_cb (GtkSpinButton *spinbutton,
BrowserData *data)
{
@@ -97,7 +105,8 @@ ss__dlg_preferences_construct_cb (GtkWidget *dialog,
data->preferences_page = gth_slideshow_preferences_new (current_transition,
eel_gconf_get_boolean (PREF_SLIDESHOW_AUTOMATIC, TRUE),
(int) (1000.0 * eel_gconf_get_float (PREF_SLIDESHOW_CHANGE_DELAY, 5.0)),
- eel_gconf_get_boolean (PREF_SLIDESHOW_WRAP_AROUND, FALSE));
+ eel_gconf_get_boolean (PREF_SLIDESHOW_WRAP_AROUND, FALSE),
+ eel_gconf_get_boolean (PREF_SLIDESHOW_RANDOM_ORDER, FALSE));
gtk_widget_show (data->preferences_page);
g_free (current_transition);
@@ -117,6 +126,10 @@ ss__dlg_preferences_construct_cb (GtkWidget *dialog,
"toggled",
G_CALLBACK (wrap_around_checkbutton_toggled_cb),
data);
+ g_signal_connect (gth_slideshow_preferences_get_widget (GTH_SLIDESHOW_PREFERENCES (data->preferences_page), "random_order_checkbutton"),
+ "toggled",
+ G_CALLBACK (random_order_checkbutton_toggled_cb),
+ data);
g_signal_connect (gth_slideshow_preferences_get_widget (GTH_SLIDESHOW_PREFERENCES (data->preferences_page), "change_delay_spinbutton"),
"value-changed",
G_CALLBACK (change_delay_spinbutton_value_changed_cb),
diff --git a/extensions/slideshow/preferences.h b/extensions/slideshow/preferences.h
index 8fba224..1d5d8dc 100644
--- a/extensions/slideshow/preferences.h
+++ b/extensions/slideshow/preferences.h
@@ -28,6 +28,7 @@
#define PREF_SLIDESHOW_WRAP_AROUND "/apps/gthumb/ext/slideshow/wrap_around"
#define PREF_SLIDESHOW_AUTOMATIC "/apps/gthumb/ext/slideshow/automatic"
#define PREF_SLIDESHOW_TRANSITION "/apps/gthumb/ext/slideshow/transition"
+#define PREF_SLIDESHOW_RANDOM_ORDER "/apps/gthumb/ext/slideshow/random-order"
#define DEFAULT_TRANSITION "random"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]