2014-04-24 13:09:25 +00:00
|
|
|
|
|
|
|
#include "loader.hpp"
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "document.hpp"
|
|
|
|
|
|
|
|
CSMDoc::Loader::Loader()
|
|
|
|
{
|
|
|
|
QTimer *timer = new QTimer (this);
|
|
|
|
|
|
|
|
connect (timer, SIGNAL (timeout()), this, SLOT (load()));
|
|
|
|
timer->start (1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWaitCondition& CSMDoc::Loader::hasThingsToDo()
|
|
|
|
{
|
|
|
|
return mThingsToDo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Loader::load()
|
|
|
|
{
|
|
|
|
if (mDocuments.empty())
|
|
|
|
{
|
|
|
|
mMutex.lock();
|
|
|
|
mThingsToDo.wait (&mMutex);
|
|
|
|
mMutex.unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<Document *, bool> >::iterator iter = mDocuments.begin();
|
|
|
|
|
|
|
|
Document *document = iter->first;
|
|
|
|
|
|
|
|
mDocuments.erase (iter);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-04-29 12:27:44 +00:00
|
|
|
document->setupData();
|
2014-04-24 13:09:25 +00:00
|
|
|
emit documentLoaded (document);
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
emit documentNotLoaded (document, e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-29 12:27:44 +00:00
|
|
|
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
|
2014-04-24 13:09:25 +00:00
|
|
|
{
|
2014-04-29 12:27:44 +00:00
|
|
|
mDocuments.push_back (std::make_pair (document, false));
|
2014-04-24 13:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Loader::abortLoading (Document *document)
|
|
|
|
{
|
|
|
|
for (std::vector<std::pair<Document *, bool> >::iterator iter = mDocuments.begin();
|
|
|
|
iter!=mDocuments.end(); ++iter)
|
|
|
|
{
|
|
|
|
if (iter->first==document)
|
|
|
|
{
|
|
|
|
mDocuments.erase (iter);
|
|
|
|
emit documentNotLoaded (document, "");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|