mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 20:45:34 +00:00
replaced dummy save implementation with a threaded dummy save implementation
This commit is contained in:
parent
d71d282952
commit
8326ac9b6f
9 changed files with 149 additions and 42 deletions
|
@ -5,11 +5,11 @@ opencs_units (. editor)
|
||||||
set (CMAKE_BUILD_TYPE DEBUG)
|
set (CMAKE_BUILD_TYPE DEBUG)
|
||||||
|
|
||||||
opencs_units (model/doc
|
opencs_units (model/doc
|
||||||
document operation
|
document operation saving
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (model/doc
|
opencs_units_noqt (model/doc
|
||||||
documentmanager stage
|
documentmanager stage savingstate savingstages
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_hdrs_noqt (model/doc
|
opencs_hdrs_noqt (model/doc
|
||||||
|
|
|
@ -2141,7 +2141,7 @@ void CSMDoc::Document::createBase()
|
||||||
|
|
||||||
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
||||||
const boost::filesystem::path& savePath, bool new_)
|
const boost::filesystem::path& savePath, bool new_)
|
||||||
: mSavePath (savePath), mTools (mData)
|
: mSavePath (savePath), mTools (mData), mSaving (*this)
|
||||||
{
|
{
|
||||||
if (files.empty())
|
if (files.empty())
|
||||||
throw std::runtime_error ("Empty content file sequence");
|
throw std::runtime_error ("Empty content file sequence");
|
||||||
|
@ -2166,9 +2166,8 @@ CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
||||||
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
||||||
connect (&mTools, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
connect (&mTools, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
||||||
|
|
||||||
// dummy implementation -> remove when proper save is implemented.
|
connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
||||||
mSaveCount = 0;
|
connect (&mSaving, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
||||||
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::Document::~Document()
|
CSMDoc::Document::~Document()
|
||||||
|
@ -2187,7 +2186,7 @@ int CSMDoc::Document::getState() const
|
||||||
if (!mUndoStack.isClean())
|
if (!mUndoStack.isClean())
|
||||||
state |= State_Modified;
|
state |= State_Modified;
|
||||||
|
|
||||||
if (mSaveCount)
|
if (mSaving.isRunning())
|
||||||
state |= State_Locked | State_Saving | State_Operation;
|
state |= State_Locked | State_Saving | State_Operation;
|
||||||
|
|
||||||
if (int operations = mTools.getRunningOperations())
|
if (int operations = mTools.getRunningOperations())
|
||||||
|
@ -2203,10 +2202,13 @@ const boost::filesystem::path& CSMDoc::Document::getSavePath() const
|
||||||
|
|
||||||
void CSMDoc::Document::save()
|
void CSMDoc::Document::save()
|
||||||
{
|
{
|
||||||
mSaveCount = 1;
|
if (mSaving.isRunning())
|
||||||
mSaveTimer.start (500);
|
throw std::logic_error (
|
||||||
|
"Failed to initiate save, because a save operation is already running.");
|
||||||
|
|
||||||
|
mSaving.start();
|
||||||
|
|
||||||
emit stateChanged (getState(), this);
|
emit stateChanged (getState(), this);
|
||||||
emit progress (1, 16, State_Saving, 1, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::UniversalId CSMDoc::Document::verify()
|
CSMWorld::UniversalId CSMDoc::Document::verify()
|
||||||
|
@ -2218,16 +2220,11 @@ CSMWorld::UniversalId CSMDoc::Document::verify()
|
||||||
|
|
||||||
void CSMDoc::Document::abortOperation (int type)
|
void CSMDoc::Document::abortOperation (int type)
|
||||||
{
|
{
|
||||||
mTools.abortOperation (type);
|
|
||||||
|
|
||||||
if (type==State_Saving)
|
if (type==State_Saving)
|
||||||
{
|
mSaving.abort();
|
||||||
mSaveCount=0;
|
else
|
||||||
mSaveTimer.stop();
|
mTools.abortOperation (type);
|
||||||
emit stateChanged (getState(), this);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CSMDoc::Document::modificationStateChanged (bool clean)
|
void CSMDoc::Document::modificationStateChanged (bool clean)
|
||||||
{
|
{
|
||||||
|
@ -2240,24 +2237,6 @@ void CSMDoc::Document::operationDone (int type)
|
||||||
emit stateChanged (getState(), this);
|
emit stateChanged (getState(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Document::saving()
|
|
||||||
{
|
|
||||||
++mSaveCount;
|
|
||||||
|
|
||||||
emit progress (mSaveCount, 16, State_Saving, 1, this);
|
|
||||||
|
|
||||||
if (mSaveCount>15)
|
|
||||||
{
|
|
||||||
//clear the stack before resetting the save state
|
|
||||||
//to avoid emitting incorrect states
|
|
||||||
mUndoStack.setClean();
|
|
||||||
|
|
||||||
mSaveCount = 0;
|
|
||||||
mSaveTimer.stop();
|
|
||||||
emit stateChanged (getState(), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const CSMWorld::Data& CSMDoc::Document::getData() const
|
const CSMWorld::Data& CSMDoc::Document::getData() const
|
||||||
{
|
{
|
||||||
return mData;
|
return mData;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "../tools/tools.hpp"
|
#include "../tools/tools.hpp"
|
||||||
|
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
#include "saving.hpp"
|
||||||
|
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
|
|
||||||
|
@ -34,14 +35,12 @@ namespace CSMDoc
|
||||||
boost::filesystem::path mSavePath;
|
boost::filesystem::path mSavePath;
|
||||||
CSMWorld::Data mData;
|
CSMWorld::Data mData;
|
||||||
CSMTools::Tools mTools;
|
CSMTools::Tools mTools;
|
||||||
|
Saving mSaving;
|
||||||
|
|
||||||
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
||||||
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
||||||
QUndoStack mUndoStack;
|
QUndoStack mUndoStack;
|
||||||
|
|
||||||
int mSaveCount; ///< dummy implementation -> remove when proper save is implemented.
|
|
||||||
QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented.
|
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
Document (const Document&);
|
Document (const Document&);
|
||||||
Document& operator= (const Document&);
|
Document& operator= (const Document&);
|
||||||
|
@ -100,9 +99,6 @@ namespace CSMDoc
|
||||||
|
|
||||||
void operationDone (int type);
|
void operationDone (int type);
|
||||||
|
|
||||||
void saving();
|
|
||||||
///< dummy implementation -> remove when proper save is implemented.
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void progress (int current, int max, int type);
|
void progress (int current, int max, int type);
|
||||||
|
|
14
apps/opencs/model/doc/saving.cpp
Normal file
14
apps/opencs/model/doc/saving.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
#include "saving.hpp"
|
||||||
|
|
||||||
|
#include "state.hpp"
|
||||||
|
|
||||||
|
#include "savingstages.hpp"
|
||||||
|
|
||||||
|
CSMDoc::Saving::Saving (Document& document)
|
||||||
|
: Operation (State_Saving, true, true), mDocument (document), mState (*this)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
appendStage (new FinalSavingStage (mDocument, mState));
|
||||||
|
}
|
25
apps/opencs/model/doc/saving.hpp
Normal file
25
apps/opencs/model/doc/saving.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef CSM_DOC_SAVING_H
|
||||||
|
#define CSM_DOC_SAVING_H
|
||||||
|
|
||||||
|
#include "operation.hpp"
|
||||||
|
#include "savingstate.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
class Document;
|
||||||
|
|
||||||
|
class Saving : public Operation
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Document& mDocument;
|
||||||
|
SavingState mState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Saving (Document& document);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
30
apps/opencs/model/doc/savingstages.cpp
Normal file
30
apps/opencs/model/doc/savingstages.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
#include "savingstages.hpp"
|
||||||
|
|
||||||
|
#include <QUndoStack>
|
||||||
|
|
||||||
|
#include "document.hpp"
|
||||||
|
#include "savingstate.hpp"
|
||||||
|
|
||||||
|
CSMDoc::FinalSavingStage::FinalSavingStage (Document& document, SavingState& state)
|
||||||
|
: mDocument (document), mState (state)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int CSMDoc::FinalSavingStage::setup()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMDoc::FinalSavingStage::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
if (mState.hasError())
|
||||||
|
{
|
||||||
|
/// \todo close stream
|
||||||
|
/// \todo delete tmp file
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/// \todo delete file, rename tmp file
|
||||||
|
mDocument.getUndoStack().setClean();
|
||||||
|
}
|
||||||
|
}
|
28
apps/opencs/model/doc/savingstages.hpp
Normal file
28
apps/opencs/model/doc/savingstages.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef CSM_DOC_SAVINGSTAGES_H
|
||||||
|
#define CSM_DOC_SAVINGSTAGES_H
|
||||||
|
|
||||||
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
class Document;
|
||||||
|
class SavingState;
|
||||||
|
|
||||||
|
class FinalSavingStage : public Stage
|
||||||
|
{
|
||||||
|
Document& mDocument;
|
||||||
|
SavingState& mState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FinalSavingStage (Document& document, SavingState& state);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||||
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
13
apps/opencs/model/doc/savingstate.cpp
Normal file
13
apps/opencs/model/doc/savingstate.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
#include "savingstate.hpp"
|
||||||
|
|
||||||
|
#include "operation.hpp"
|
||||||
|
|
||||||
|
CSMDoc::SavingState::SavingState (Operation& operation)
|
||||||
|
: mOperation (operation)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool CSMDoc::SavingState::hasError() const
|
||||||
|
{
|
||||||
|
return mOperation.hasError();
|
||||||
|
}
|
22
apps/opencs/model/doc/savingstate.hpp
Normal file
22
apps/opencs/model/doc/savingstate.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef CSM_DOC_SAVINGSTATE_H
|
||||||
|
#define CSM_DOC_SAVINGSTATE_H
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
class Operation;
|
||||||
|
|
||||||
|
class SavingState
|
||||||
|
{
|
||||||
|
Operation& mOperation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SavingState (Operation& operation);
|
||||||
|
|
||||||
|
bool hasError() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue