1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:19:55 +00:00
openmw-tes3mp/apps/opencs/model/doc/loader.cpp

66 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;
bool new_ = iter->second;
mDocuments.erase (iter);
try
{
document->setupData (new_);
emit documentLoaded (document);
}
catch (const std::exception& e)
{
emit documentNotLoaded (document, e.what());
}
}
2014-04-29 12:17:25 +00:00
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document, bool new_)
2014-04-24 13:09:25 +00:00
{
mDocuments.push_back (std::make_pair (document, new_));
}
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;
}
}
}