mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
handle exceptions thrown during loading and report them to the user
This commit is contained in:
parent
e9c2f24faa
commit
492620c8cf
5 changed files with 72 additions and 23 deletions
|
@ -59,7 +59,7 @@ void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::
|
||||||
mLoader.hasThingsToDo().wakeAll();
|
mLoader.hasThingsToDo().wakeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::DocumentManager::removeDocument (Document *document)
|
void CSMDoc::DocumentManager::removeDocument (CSMDoc::Document *document)
|
||||||
{
|
{
|
||||||
std::vector<Document *>::iterator iter = std::find (mDocuments.begin(), mDocuments.end(), document);
|
std::vector<Document *>::iterator iter = std::find (mDocuments.begin(), mDocuments.end(), document);
|
||||||
|
|
||||||
|
@ -86,6 +86,8 @@ void CSMDoc::DocumentManager::documentLoaded (Document *document)
|
||||||
|
|
||||||
void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::string& error)
|
void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::string& error)
|
||||||
{
|
{
|
||||||
// emit loadingStopped (document, false, error);
|
emit loadingStopped (document, false, error);
|
||||||
removeDocument (document);
|
|
||||||
|
if (error.empty()) // do not remove the document yet, if we have an error
|
||||||
|
removeDocument (document);
|
||||||
}
|
}
|
|
@ -43,9 +43,6 @@ namespace CSMDoc
|
||||||
///< \param new_ Do not load the last content file in \a files and instead create in an
|
///< \param new_ Do not load the last content file in \a files and instead create in an
|
||||||
/// appropriate way.
|
/// appropriate way.
|
||||||
|
|
||||||
void removeDocument (Document *document);
|
|
||||||
///< Emits the lastDocumentDeleted signal, if applicable.
|
|
||||||
|
|
||||||
void setResourceDir (const boost::filesystem::path& parResDir);
|
void setResourceDir (const boost::filesystem::path& parResDir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -61,6 +58,11 @@ namespace CSMDoc
|
||||||
///< Document load has been interrupted either because of a call to abortLoading
|
///< Document load has been interrupted either because of a call to abortLoading
|
||||||
/// or a problem during loading). In the former case error will be an empty string.
|
/// or a problem during loading). In the former case error will be an empty string.
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void removeDocument (CSMDoc::Document *document);
|
||||||
|
///< Emits the lastDocumentDeleted signal, if applicable.
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void documentAdded (CSMDoc::Document *document);
|
void documentAdded (CSMDoc::Document *document);
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
|
void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
emit cancel (mDocument);
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
: mDocument (document)
|
: mDocument (document), mAborted (false)
|
||||||
{
|
{
|
||||||
setWindowTitle (("Opening " + document->getSavePath().filename().string()).c_str());
|
setWindowTitle (("Opening " + document->getSavePath().filename().string()).c_str());
|
||||||
|
|
||||||
|
@ -52,10 +52,16 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
mRecordProgress->setTextVisible (true);
|
mRecordProgress->setTextVisible (true);
|
||||||
mRecordProgress->setValue (0);
|
mRecordProgress->setValue (0);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox (QDialogButtonBox::Cancel, Qt::Horizontal,
|
// error message
|
||||||
this);
|
mError = new QLabel (this);
|
||||||
|
mError->setWordWrap (true);
|
||||||
|
|
||||||
layout->addWidget (buttonBox);
|
layout->addWidget (mError);
|
||||||
|
|
||||||
|
// buttons
|
||||||
|
mButtons = new QDialogButtonBox (QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||||
|
|
||||||
|
layout->addWidget (mButtons);
|
||||||
|
|
||||||
setLayout (layout);
|
setLayout (layout);
|
||||||
|
|
||||||
|
@ -63,7 +69,7 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
connect (buttonBox, SIGNAL (rejected()), this, SLOT (cancel()));
|
connect (mButtons, SIGNAL (rejected()), this, SLOT (cancel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
||||||
|
@ -73,10 +79,9 @@ void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
||||||
mFileProgress->setValue (mFileProgress->value()+1);
|
mFileProgress->setValue (mFileProgress->value()+1);
|
||||||
|
|
||||||
mRecordProgress->setValue (0);
|
mRecordProgress->setValue (0);
|
||||||
mRecordProgress->setMaximum (steps);
|
mRecordProgress->setMaximum (steps>0 ? steps : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::nextRecord()
|
void CSVDoc::LoadingDocument::nextRecord()
|
||||||
{
|
{
|
||||||
int value = mRecordProgress->value()+1;
|
int value = mRecordProgress->value()+1;
|
||||||
|
@ -85,9 +90,22 @@ void CSVDoc::LoadingDocument::nextRecord()
|
||||||
mRecordProgress->setValue (value);
|
mRecordProgress->setValue (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVDoc::LoadingDocument::abort (const std::string& error)
|
||||||
|
{
|
||||||
|
mAborted = true;
|
||||||
|
mError->setText (QString::fromUtf8 (("Loading failed: " + error).c_str()));
|
||||||
|
mButtons->setStandardButtons (QDialogButtonBox::Close);
|
||||||
|
}
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::cancel()
|
void CSVDoc::LoadingDocument::cancel()
|
||||||
{
|
{
|
||||||
emit cancel (mDocument);
|
if (!mAborted)
|
||||||
|
emit cancel (mDocument);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit close (mDocument);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,21 +125,32 @@ void CSVDoc::Loader::add (CSMDoc::Document *document)
|
||||||
|
|
||||||
connect (loading, SIGNAL (cancel (CSMDoc::Document *)),
|
connect (loading, SIGNAL (cancel (CSMDoc::Document *)),
|
||||||
this, SIGNAL (cancel (CSMDoc::Document *)));
|
this, SIGNAL (cancel (CSMDoc::Document *)));
|
||||||
|
connect (loading, SIGNAL (close (CSMDoc::Document *)),
|
||||||
|
this, SIGNAL (close (CSMDoc::Document *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,
|
void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,
|
||||||
const std::string& error)
|
const std::string& error)
|
||||||
{
|
{
|
||||||
|
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.begin();
|
||||||
|
|
||||||
|
for (; iter!=mDocuments.end(); ++iter)
|
||||||
|
if (iter->first==document)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (iter==mDocuments.end())
|
||||||
|
return;
|
||||||
|
|
||||||
if (completed || error.empty())
|
if (completed || error.empty())
|
||||||
{
|
{
|
||||||
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
delete iter->second;
|
||||||
iter!=mDocuments.end(); ++iter)
|
mDocuments.erase (iter);
|
||||||
if (iter->first==document)
|
}
|
||||||
{
|
else if (!completed && !error.empty())
|
||||||
delete iter->second;
|
{
|
||||||
mDocuments.erase (iter);
|
iter->second->abort (error);
|
||||||
break;
|
// Leave the window open for now (wait for the user to close it)
|
||||||
}
|
mDocuments.erase (iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
|
class QDialogButtonBox;
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
|
@ -25,6 +26,9 @@ namespace CSVDoc
|
||||||
QLabel *mFile;
|
QLabel *mFile;
|
||||||
QProgressBar *mFileProgress;
|
QProgressBar *mFileProgress;
|
||||||
QProgressBar *mRecordProgress;
|
QProgressBar *mRecordProgress;
|
||||||
|
bool mAborted;
|
||||||
|
QDialogButtonBox *mButtons;
|
||||||
|
QLabel *mError;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -38,6 +42,8 @@ namespace CSVDoc
|
||||||
|
|
||||||
void nextRecord();
|
void nextRecord();
|
||||||
|
|
||||||
|
void abort (const std::string& error);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
|
@ -45,6 +51,10 @@ namespace CSVDoc
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void cancel (CSMDoc::Document *document);
|
void cancel (CSMDoc::Document *document);
|
||||||
|
///< Stop loading process.
|
||||||
|
|
||||||
|
void close (CSMDoc::Document *document);
|
||||||
|
///< Close stopped loading process.
|
||||||
};
|
};
|
||||||
|
|
||||||
class Loader : public QObject
|
class Loader : public QObject
|
||||||
|
@ -63,6 +73,8 @@ namespace CSVDoc
|
||||||
|
|
||||||
void cancel (CSMDoc::Document *document);
|
void cancel (CSMDoc::Document *document);
|
||||||
|
|
||||||
|
void close (CSMDoc::Document *document);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void add (CSMDoc::Document *document);
|
void add (CSMDoc::Document *document);
|
||||||
|
|
|
@ -103,6 +103,10 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
||||||
connect (
|
connect (
|
||||||
&mLoader, SIGNAL (cancel (CSMDoc::Document *)),
|
&mLoader, SIGNAL (cancel (CSMDoc::Document *)),
|
||||||
&mDocumentManager, SIGNAL (cancelLoading (CSMDoc::Document *)));
|
&mDocumentManager, SIGNAL (cancelLoading (CSMDoc::Document *)));
|
||||||
|
|
||||||
|
connect (
|
||||||
|
&mLoader, SIGNAL (close (CSMDoc::Document *)),
|
||||||
|
&mDocumentManager, SLOT (removeDocument (CSMDoc::Document *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVDoc::ViewManager::~ViewManager()
|
CSVDoc::ViewManager::~ViewManager()
|
||||||
|
|
Loading…
Reference in a new issue