diff --git a/src/apps/showimage/ImageCache.h b/src/apps/showimage/ImageCache.h index fad065d773..92a8ac936b 100644 --- a/src/apps/showimage/ImageCache.h +++ b/src/apps/showimage/ImageCache.h @@ -42,8 +42,9 @@ class ImageCache { public: static ImageCache& Default() { return sCache; } - status_t RetrieveImage(const entry_ref& ref, int32 page, - const BMessenger* target); + status_t RetrieveImage(const entry_ref& ref, + int32 page = 1, + const BMessenger* target = NULL); private: ImageCache(); diff --git a/src/apps/showimage/ImageFileNavigator.cpp b/src/apps/showimage/ImageFileNavigator.cpp index e876eb0740..e9d13ac313 100644 --- a/src/apps/showimage/ImageFileNavigator.cpp +++ b/src/apps/showimage/ImageFileNavigator.cpp @@ -470,6 +470,21 @@ ImageFileNavigator::HasPreviousFile() } +bool +ImageFileNavigator::GetNextFile(const entry_ref& ref, entry_ref& nextRef) +{ + return fNavigator->FindNextImage(ref, nextRef, true, false); +} + + +bool +ImageFileNavigator::GetPreviousFile(const entry_ref& ref, + entry_ref& previousRef) +{ + return fNavigator->FindNextImage(ref, previousRef, false, false); +} + + /*! Moves the current file into the trash. Returns true if a new file should be loaded, false if not. */ diff --git a/src/apps/showimage/ImageFileNavigator.h b/src/apps/showimage/ImageFileNavigator.h index fce4dc2ee4..96febd67a1 100644 --- a/src/apps/showimage/ImageFileNavigator.h +++ b/src/apps/showimage/ImageFileNavigator.h @@ -51,6 +51,11 @@ public: bool HasNextFile(); bool HasPreviousFile(); + bool GetNextFile(const entry_ref& ref, + entry_ref& nextRef); + bool GetPreviousFile(const entry_ref& ref, + entry_ref& previousRef); + bool MoveFileToTrash(); private: diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index ea0cda36d3..3617691b35 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -702,7 +702,7 @@ ShowImageWindow::MessageReceived(BMessage* message) case MSG_FILE_PREV: if (_ClosePrompt() && fNavigator.PreviousFile()) - _LoadImage(); + _LoadImage(false); break; case MSG_FILE_NEXT: @@ -976,11 +976,37 @@ ShowImageWindow::_ClosePrompt() status_t -ShowImageWindow::_LoadImage() +ShowImageWindow::_LoadImage(bool forward) { BMessenger us(this); - return ImageCache::Default().RetrieveImage(fNavigator.CurrentRef(), - fNavigator.CurrentPage(), &us); + status_t status = ImageCache::Default().RetrieveImage( + fNavigator.CurrentRef(), fNavigator.CurrentPage(), &us); + if (status != B_OK) + return status; + + // Preload previous/next images - two in the navigation direction, one + // in the opposite direction. + + entry_ref nextRef = fNavigator.CurrentRef(); + if (_PreloadImage(forward, nextRef)) + _PreloadImage(forward, nextRef); + + entry_ref previousRef = fNavigator.CurrentRef(); + _PreloadImage(!forward, previousRef); + + return B_OK; +} + + +bool +ShowImageWindow::_PreloadImage(bool forward, entry_ref& ref) +{ + entry_ref currentRef = ref; + if ((forward && !fNavigator.GetNextFile(currentRef, ref)) + || (!forward && !fNavigator.GetPreviousFile(currentRef, ref))) + return false; + + return ImageCache::Default().RetrieveImage(ref) == B_OK; } diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index 922574aabb..6181da50ba 100644 --- a/src/apps/showimage/ShowImageWindow.h +++ b/src/apps/showimage/ShowImageWindow.h @@ -64,7 +64,8 @@ private: void _SaveToFile(BMessage* message); // Handle save file panel message bool _ClosePrompt(); - status_t _LoadImage(); + status_t _LoadImage(bool forward = true); + bool _PreloadImage(bool forward, entry_ref& ref); void _ToggleFullScreen(); void _ApplySettings(); void _SavePrintOptions();