forked from mirror/openmw-tes3mp
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -86,6 +86,8 @@ void CSMDoc::DocumentManager::documentLoaded (Document *document)
|
|||
|
||||
void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::string& error)
|
||||
{
|
||||
// emit loadingStopped (document, false, error);
|
||||
emit loadingStopped (document, false, error);
|
||||
|
||||
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
|
||||
/// appropriate way.
|
||||
|
||||
void removeDocument (Document *document);
|
||||
///< Emits the lastDocumentDeleted signal, if applicable.
|
||||
|
||||
void setResourceDir (const boost::filesystem::path& parResDir);
|
||||
|
||||
private:
|
||||
|
@ -61,6 +58,11 @@ namespace CSMDoc
|
|||
///< 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.
|
||||
|
||||
public slots:
|
||||
|
||||
void removeDocument (CSMDoc::Document *document);
|
||||
///< Emits the lastDocumentDeleted signal, if applicable.
|
||||
|
||||
signals:
|
||||
|
||||
void documentAdded (CSMDoc::Document *document);
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
emit cancel (mDocument);
|
||||
cancel();
|
||||
}
|
||||
|
||||
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||
: mDocument (document)
|
||||
: mDocument (document), mAborted (false)
|
||||
{
|
||||
setWindowTitle (("Opening " + document->getSavePath().filename().string()).c_str());
|
||||
|
||||
|
@ -52,10 +52,16 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||
mRecordProgress->setTextVisible (true);
|
||||
mRecordProgress->setValue (0);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox (QDialogButtonBox::Cancel, Qt::Horizontal,
|
||||
this);
|
||||
// error message
|
||||
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);
|
||||
|
||||
|
@ -63,7 +69,7 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||
|
||||
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)
|
||||
|
@ -73,10 +79,9 @@ void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
|||
mFileProgress->setValue (mFileProgress->value()+1);
|
||||
|
||||
mRecordProgress->setValue (0);
|
||||
mRecordProgress->setMaximum (steps);
|
||||
mRecordProgress->setMaximum (steps>0 ? steps : 1);
|
||||
}
|
||||
|
||||
|
||||
void CSVDoc::LoadingDocument::nextRecord()
|
||||
{
|
||||
int value = mRecordProgress->value()+1;
|
||||
|
@ -85,9 +90,22 @@ void CSVDoc::LoadingDocument::nextRecord()
|
|||
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()
|
||||
{
|
||||
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 *)),
|
||||
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,
|
||||
const std::string& error)
|
||||
{
|
||||
if (completed || error.empty())
|
||||
{
|
||||
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
||||
iter!=mDocuments.end(); ++iter)
|
||||
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())
|
||||
{
|
||||
delete iter->second;
|
||||
mDocuments.erase (iter);
|
||||
break;
|
||||
}
|
||||
else if (!completed && !error.empty())
|
||||
{
|
||||
iter->second->abort (error);
|
||||
// Leave the window open for now (wait for the user to close it)
|
||||
mDocuments.erase (iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
class QLabel;
|
||||
class QProgressBar;
|
||||
class QDialogButtonBox;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
|
@ -25,6 +26,9 @@ namespace CSVDoc
|
|||
QLabel *mFile;
|
||||
QProgressBar *mFileProgress;
|
||||
QProgressBar *mRecordProgress;
|
||||
bool mAborted;
|
||||
QDialogButtonBox *mButtons;
|
||||
QLabel *mError;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -38,6 +42,8 @@ namespace CSVDoc
|
|||
|
||||
void nextRecord();
|
||||
|
||||
void abort (const std::string& error);
|
||||
|
||||
private slots:
|
||||
|
||||
void cancel();
|
||||
|
@ -45,6 +51,10 @@ namespace CSVDoc
|
|||
signals:
|
||||
|
||||
void cancel (CSMDoc::Document *document);
|
||||
///< Stop loading process.
|
||||
|
||||
void close (CSMDoc::Document *document);
|
||||
///< Close stopped loading process.
|
||||
};
|
||||
|
||||
class Loader : public QObject
|
||||
|
@ -63,6 +73,8 @@ namespace CSVDoc
|
|||
|
||||
void cancel (CSMDoc::Document *document);
|
||||
|
||||
void close (CSMDoc::Document *document);
|
||||
|
||||
public slots:
|
||||
|
||||
void add (CSMDoc::Document *document);
|
||||
|
|
|
@ -103,6 +103,10 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|||
connect (
|
||||
&mLoader, SIGNAL (cancel (CSMDoc::Document *)),
|
||||
&mDocumentManager, SIGNAL (cancelLoading (CSMDoc::Document *)));
|
||||
|
||||
connect (
|
||||
&mLoader, SIGNAL (close (CSMDoc::Document *)),
|
||||
&mDocumentManager, SLOT (removeDocument (CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
CSVDoc::ViewManager::~ViewManager()
|
||||
|
|
Loading…
Reference in a new issue