summaryrefslogtreecommitdiff
path: root/src/core/ViewCollection.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-12-17 19:58:25 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-12-17 19:58:25 +0100
commit4cb46f4de4b881e5b1f65af017dca6f3917e55e5 (patch)
treefb359e210d2d9c30f5ad36a447ea29b62ae9bb56 /src/core/ViewCollection.vala
parent841f952294b349b2b8e2afb5305ce34a3b59bb4b (diff)
parentf5a0cee8ccecc7b6c6c2d8e9fb6f6eecd53531fe (diff)
Update upstream source from tag 'upstream/0.32.4'
Update to upstream version '0.32.4' with Debian dir 51798a6af1c9b7e48f979c020d72f3c5ddd964a6
Diffstat (limited to 'src/core/ViewCollection.vala')
-rw-r--r--src/core/ViewCollection.vala51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/core/ViewCollection.vala b/src/core/ViewCollection.vala
index 7e13fb0..c3848c1 100644
--- a/src/core/ViewCollection.vala
+++ b/src/core/ViewCollection.vala
@@ -298,6 +298,33 @@ public class ViewCollection : DataCollection {
add_many(copy_view);
}
+ // for use in shuffled slideshow
+ public ViewCollection shuffled_copy(Photo? start = null) {
+ ViewCollection shuffled = new ViewCollection("shuffled copy of " + to_string());
+
+ Gee.Collection<DataObject> data = get_all();
+ Gee.ArrayList<DataObject> data_copy = new Gee.ArrayList<DataObject>();
+ foreach (DataObject object in data) {
+ DataView view = (DataView) object;
+ if (view.get_source() is PhotoSource &&
+ (start == null || view.get_source() != start)) {
+ data_copy.add(new PhotoView((PhotoSource) ((DataView) object).get_source()));
+ }
+ }
+
+ for (int ctr = data_copy.size - 1; ctr > 0; ctr--) {
+ int rand = GLib.Random.int_range(0, ctr + 1);
+ DataObject temp = data_copy.get(rand);
+ data_copy.set(rand, data_copy.get(ctr));
+ data_copy.set(ctr, temp);
+ }
+
+ if (start != null)
+ shuffled.add(new PhotoView(start));
+ shuffled.add_many(data_copy);
+ return shuffled;
+ }
+
public bool is_view_filter_installed(ViewFilter f) {
return filters.contains(f);
}
@@ -740,12 +767,30 @@ public class ViewCollection : DataCollection {
// _something_...
return get_first();
}
+
+ public virtual DataView? get_first_photo() {
+ if (get_count() < 1)
+ return null;
+
+ DataView dv = get_first();
+ int num_views = get_count();
+
+ while ((dv != null) && (index_of(dv) < (num_views))) {
+ if (dv.get_source() is PhotoSource)
+ return dv;
+ else
+ dv = get_next(dv);
+ }
+
+ return null;
+ }
public virtual DataView? get_last() {
return (get_count() > 0) ? (DataView?) get_at(get_count() - 1) : null;
}
- public virtual DataView? get_next(DataView view) {
+ public virtual DataView? get_next(DataView view, out bool? wrapped = null) {
+ wrapped = false;
if (get_count() == 0)
return null;
@@ -754,8 +799,10 @@ public class ViewCollection : DataCollection {
return null;
index++;
- if (index >= get_count())
+ if (index >= get_count()) {
index = 0;
+ wrapped = true;
+ }
return (DataView?) get_at(index);
}