]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/LoaderQueue.C
Rename insets/insetxxx to insets/InsetXxx, part 1
[lyx.git] / src / graphics / LoaderQueue.C
index f7332d06eb48ec5f495925ce6f54ffa977c85ebb..aca489598b4375237c75094a18d7361101f9a3e4 100644 (file)
@@ -5,10 +5,13 @@
  *
  * \author Alfredo Braunstein
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
+#include <config.h>
+
 #include "LoaderQueue.h"
+#include "GraphicsCacheItem.h"
 
 #include "debug.h"
 
 using std::endl;
 using std::list;
 
-
-namespace grfx {
+namespace lyx {
+namespace graphics {
 
 int LoaderQueue::s_numimages_ = 5;
 int LoaderQueue::s_millisecs_ = 500;
 
+
 LoaderQueue & LoaderQueue::get()
 {
        static LoaderQueue singleton;
@@ -32,18 +36,18 @@ LoaderQueue & LoaderQueue::get()
 
 void LoaderQueue::loadNext()
 {
-       emptyBucket();
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
+       LYXERR(Debug::GRAPHICS) << "LoaderQueue: "
                                << cache_queue_.size()
                                << " items in the queue" << endl;
        int counter = s_numimages_;
        while (cache_queue_.size() && counter--) {
-               if(cache_queue_.front()->status() == WaitingToLoad)
-                       cache_queue_.front()->startLoading();
-               cache_set_.erase(cache_queue_.front());
+               Cache::ItemPtr ptr = cache_queue_.front();
+               cache_set_.erase(ptr);
                cache_queue_.pop_front();
+               if (ptr->status() == WaitingToLoad)
+                       ptr->startLoading();
        }
-       if (cache_queue_.size() || bucket_.size()) {
+       if (cache_queue_.size()) {
                startLoader();
        } else {
                stopLoader();
@@ -55,7 +59,7 @@ void LoaderQueue::setPriority(int numimages , int millisecs)
 {
        s_numimages_ = numimages;
        s_millisecs_ = millisecs;
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue:  priority set to "
+       LYXERR(Debug::GRAPHICS) << "LoaderQueue:  priority set to "
                                << s_numimages_ << " images at a time, "
                                << s_millisecs_ << " milliseconds between calls"
                                << endl;
@@ -69,20 +73,9 @@ LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
 }
 
 
-void LoaderQueue::emptyBucket()
-{
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue: emptying bucket"
-                               << endl;
-       while (! bucket_.empty()) {
-               addToQueue(bucket_.front());
-               bucket_.pop();
-       }
-}
-
-
 void LoaderQueue::startLoader()
 {
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
+       LYXERR(Debug::GRAPHICS) << "LoaderQueue: waking up" << endl;
        running_ = true ;
        timer.setTimeout(s_millisecs_);
        timer.start();
@@ -93,7 +86,7 @@ void LoaderQueue::stopLoader()
 {
        timer.stop();
        running_ = false ;
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
+       LYXERR(Debug::GRAPHICS) << "LoaderQueue: I'm going to sleep" << endl;
 }
 
 
@@ -104,14 +97,6 @@ bool LoaderQueue::running() const
 
 
 void LoaderQueue::touch(Cache::ItemPtr const & item)
-{
-       if (! running_)
-               startLoader();
-       bucket_.push(item);
-}
-
-
-void LoaderQueue::addToQueue(Cache::ItemPtr const & item)
 {
        if (! cache_set_.insert(item).second) {
                list<Cache::ItemPtr>::iterator
@@ -124,7 +109,10 @@ void LoaderQueue::addToQueue(Cache::ItemPtr const & item)
                        cache_queue_.erase(it);
        }
        cache_queue_.push_front(item);
+       if (!running_)
+               startLoader();
 }
 
 
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx