From 2041038abec43869499f29ca72e1d94067e2aff4 Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Sat, 19 Jun 2004 17:37:10 +0000 Subject: [PATCH] Re-Added directory based Next/Previous file functionality. Now, if tracker scripting is unavailable, user will still be able to use Next/Previous file commands and the slideshow feature git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8067 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ShowImageView.cpp | 62 +++++++++++++++++++++++++++- src/apps/showimage/ShowImageView.h | 1 + 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index a134af6d80..29ee16bf6e 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -1922,12 +1922,72 @@ ShowImageView::SetTrackerSelectionToCurrent() fTrackerMessenger.SendMessage(&setsel); } +bool +ShowImageView::FindNextImageByDir(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind) +{ + ASSERT(next || !rewind); + BEntry curImage(in_current); + entry_ref entry, *ref; + BDirectory parent; + BList entries; + bool found = false; + int32 cur; + + if (curImage.GetParent(&parent) != B_OK) + return false; + + while (parent.GetNextRef(&entry) == B_OK) { + if (entry != *in_current) { + entries.AddItem(new entry_ref(entry)); + } else { + // insert current ref, so we can find it easily after sorting + entries.AddItem(in_current); + } + } + + entries.SortItems(CompareEntries); + + cur = entries.IndexOf(in_current); + ASSERT(cur >= 0); + + // remove it so FreeEntries() does not delete it + entries.RemoveItem(in_current); + + if (next) { + // find the next image in the list + if (rewind) cur = 0; // start with first + for (; (ref = (entry_ref*)entries.ItemAt(cur)) != NULL; cur ++) { + if (IsImage(ref)) { + found = true; + *out_image = (const entry_ref)*ref; + break; + } + } + } else { + // find the previous image in the list + cur --; + for (; cur >= 0; cur --) { + ref = (entry_ref*)entries.ItemAt(cur); + if (IsImage(ref)) { + found = true; + *out_image = (const entry_ref)*ref; + break; + } + } + } + + FreeEntries(&entries); + return found; +} + bool ShowImageView::FindNextImage(entry_ref *in_current, entry_ref *ref, bool next, bool rewind) { // Based on similar function from BeMail! if (!fTrackerMessenger.IsValid()) - return false; + // If tracker scripting is not available, + // fall back on directory searching code + return FindNextImageByDir(in_current, ref, next, rewind); // // Ask the Tracker what the next/prev file in the window is. diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index 474de89867..34b23cbbc1 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -164,6 +164,7 @@ private: static int CompareEntries(const void* a, const void* b); void FreeEntries(BList* entries); void SetTrackerSelectionToCurrent(); + bool FindNextImageByDir(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind); bool FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind); bool ShowNextImage(bool next, bool rewind); bool FirstFile();