]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/LoaderQueue.C
clean code to export between different flavours, output different code for sgml to...
[lyx.git] / src / graphics / LoaderQueue.C
index 85f8311b51b25ad4413897d6ec90ddceba29f3a1..c21726d5562ff1a80958c06e8abf5ea40442ace8 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;
@@ -30,20 +34,20 @@ LoaderQueue & LoaderQueue::get()
 }
 
 
-void LoaderQueue::loadNext() 
+void LoaderQueue::loadNext()
 {
-       emptyBucket();
        lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
                                << cache_queue_.size()
-                               << " items in the queue" << endl; 
+                               << " 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();
@@ -57,28 +61,17 @@ void LoaderQueue::setPriority(int numimages , int millisecs)
        s_millisecs_ = millisecs;
        lyxerr[Debug::GRAPHICS] << "LoaderQueue:  priority set to "
                                << s_numimages_ << " images at a time, "
-                               << s_millisecs_ << " milliseconds between calls" 
+                               << s_millisecs_ << " milliseconds between calls"
                                << endl;
 }
-       
 
-LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME), 
+
+LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
                             running_(false)
 {
        timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
 }
 
-       
-void LoaderQueue::emptyBucket()
-{
-       lyxerr[Debug::GRAPHICS] << "LoaderQueue: emptying bucket" 
-                               << endl;
-       while (! bucket_.empty()) {
-               addToQueue(bucket_.front());
-               bucket_.pop();
-       }
-}
-
 
 void LoaderQueue::startLoader()
 {
@@ -104,27 +97,22 @@ 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 
+               list<Cache::ItemPtr>::iterator
                        it = cache_queue_.begin();
-               list<Cache::ItemPtr>::iterator 
+               list<Cache::ItemPtr>::iterator
                        end = cache_queue_.end();
-               
+
                it = std::find(it, end, item);
                if (it != end)
                        cache_queue_.erase(it);
-       } 
+       }
        cache_queue_.push_front(item);
+       if (!running_)
+               startLoader();
 }
 
 
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx