1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 09:55:35 +00:00
OpenMW/apps/opencs/model/doc/loader.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

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
{
document->setupData();
2014-04-24 13:09:25 +00:00
emit documentLoaded (document);
}
catch (const std::exception& e)
{
emit documentNotLoaded (document, e.what());
}
}
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
2014-04-24 13:09:25 +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;
}
}
}