[haiku-commits] r39377 - haiku/trunk/src/apps/showimage

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 9 Nov 2010 20:09:18 +0100 (CET)

Author: axeld
Date: 2010-11-09 20:09:18 +0100 (Tue, 09 Nov 2010)
New Revision: 39377
Changeset: http://dev.haiku-os.org/changeset/39377

Modified:
   haiku/trunk/src/apps/showimage/ImageCache.h
   haiku/trunk/src/apps/showimage/ImageFileNavigator.cpp
   haiku/trunk/src/apps/showimage/ImageFileNavigator.h
   haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
   haiku/trunk/src/apps/showimage/ShowImageWindow.h
Log:
* Implemented preloading of the images around he current one; always two in the
  direction of the current navigation, and one in the opposite direction.


Modified: haiku/trunk/src/apps/showimage/ImageCache.h
===================================================================
--- haiku/trunk/src/apps/showimage/ImageCache.h 2010-11-09 16:21:18 UTC (rev 
39376)
+++ haiku/trunk/src/apps/showimage/ImageCache.h 2010-11-09 19:09:18 UTC (rev 
39377)
@@ -42,8 +42,9 @@
 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();

Modified: haiku/trunk/src/apps/showimage/ImageFileNavigator.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ImageFileNavigator.cpp       2010-11-09 
16:21:18 UTC (rev 39376)
+++ haiku/trunk/src/apps/showimage/ImageFileNavigator.cpp       2010-11-09 
19:09:18 UTC (rev 39377)
@@ -470,6 +470,21 @@
 }
 
 
+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.
 */

Modified: haiku/trunk/src/apps/showimage/ImageFileNavigator.h
===================================================================
--- haiku/trunk/src/apps/showimage/ImageFileNavigator.h 2010-11-09 16:21:18 UTC 
(rev 39376)
+++ haiku/trunk/src/apps/showimage/ImageFileNavigator.h 2010-11-09 19:09:18 UTC 
(rev 39377)
@@ -51,6 +51,11 @@
                        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:

Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2010-11-09 16:21:18 UTC 
(rev 39376)
+++ haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2010-11-09 19:09:18 UTC 
(rev 39377)
@@ -702,7 +702,7 @@
 
                case MSG_FILE_PREV:
                        if (_ClosePrompt() && fNavigator.PreviousFile())
-                               _LoadImage();
+                               _LoadImage(false);
                        break;
 
                case MSG_FILE_NEXT:
@@ -976,14 +976,40 @@
 
 
 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;
+}
+
+
 void
 ShowImageWindow::_ToggleFullScreen()
 {

Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.h
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageWindow.h    2010-11-09 16:21:18 UTC 
(rev 39376)
+++ haiku/trunk/src/apps/showimage/ShowImageWindow.h    2010-11-09 19:09:18 UTC 
(rev 39377)
@@ -64,7 +64,8 @@
                        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();


Other related posts:

  • » [haiku-commits] r39377 - haiku/trunk/src/apps/showimage - axeld