summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-12-17 19:58:04 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-12-17 19:58:04 +0100
commitf5a0cee8ccecc7b6c6c2d8e9fb6f6eecd53531fe (patch)
tree4fe410ce27a30bc752d350aa042dae8fd042d0a1 /src/core
parent87ba373882f475f02a524a120b59ea9fcccf14e5 (diff)
New upstream version 0.32.4upstream/0.32.4upstream
Diffstat (limited to 'src/core')
-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);
}