mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
For Qt4.4 and up: Detach Buffer autosave into a new thread.
* Buffer: new clone() method. When this new autosave method is used the old autoSave() is not of course. * GuiView: clone the current document buffer and save it in a new thread. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32512 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a4c7e69d7a
commit
622e3b1e4d
@ -356,6 +356,17 @@ Buffer::~Buffer()
|
||||
}
|
||||
|
||||
|
||||
Buffer * Buffer::clone() const
|
||||
{
|
||||
Buffer * clone = new Buffer(fileName().absFilename(), false);
|
||||
clone->d->file_fully_loaded = true;
|
||||
clone->d->params = d->params;
|
||||
clone->d->inset = static_cast<InsetText *>(d->inset->clone());
|
||||
clone->d->inset->setBuffer(*clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::changed() const
|
||||
{
|
||||
if (d->wa_)
|
||||
|
@ -130,6 +130,9 @@ public:
|
||||
/// Destructor
|
||||
~Buffer();
|
||||
|
||||
///
|
||||
Buffer * clone() const;
|
||||
|
||||
/** High-level interface to buffer functionality.
|
||||
This function parses a command string and executes it.
|
||||
*/
|
||||
|
@ -102,6 +102,13 @@
|
||||
#include <QUrl>
|
||||
#include <QScrollBar>
|
||||
|
||||
// QtConcurrent was introduced in Qt 4.4
|
||||
#if (QT_VERSION >= 0x040400)
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QtConcurrentRun>
|
||||
#endif
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <sstream>
|
||||
@ -290,6 +297,11 @@ public:
|
||||
|
||||
///
|
||||
TocModels toc_models_;
|
||||
|
||||
#if (QT_VERSION >= 0x040400)
|
||||
///
|
||||
QFutureWatcher<bool> autosave_watcher_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -350,6 +362,11 @@ GuiView::GuiView(int id)
|
||||
// clear session data if any.
|
||||
QSettings settings;
|
||||
settings.remove("views");
|
||||
|
||||
#if (QT_VERSION >= 0x040400)
|
||||
connect(&d.autosave_watcher_, SIGNAL(finished()), this,
|
||||
SLOT(autoSaveFinished()));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -359,6 +376,16 @@ GuiView::~GuiView()
|
||||
}
|
||||
|
||||
|
||||
void GuiView::autoSaveFinished()
|
||||
{
|
||||
#if (QT_VERSION >= 0x040400)
|
||||
docstring const msg = d.autosave_watcher_.result()
|
||||
? _("Automatic save done.") : _("Automatic save failed!");
|
||||
message(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void GuiView::saveLayout() const
|
||||
{
|
||||
QSettings settings;
|
||||
@ -1195,12 +1222,39 @@ BufferView const * GuiView::currentBufferView() const
|
||||
}
|
||||
|
||||
|
||||
static bool saveAndDestroyBuffer(Buffer * buffer, FileName const & fname)
|
||||
{
|
||||
bool failed = true;
|
||||
FileName const tmp_ret = FileName::tempName("lyxauto");
|
||||
if (!tmp_ret.empty()) {
|
||||
if (buffer->writeFile(tmp_ret))
|
||||
failed = !tmp_ret.moveTo(fname);
|
||||
}
|
||||
if (failed) {
|
||||
// failed to write/rename tmp_ret so try writing direct
|
||||
failed = buffer->writeFile(fname);
|
||||
}
|
||||
delete buffer;
|
||||
return !failed;
|
||||
}
|
||||
|
||||
|
||||
void GuiView::autoSave()
|
||||
{
|
||||
LYXERR(Debug::INFO, "Running autoSave()");
|
||||
|
||||
if (documentBufferView())
|
||||
documentBufferView()->buffer().autoSave();
|
||||
Buffer * buffer = documentBufferView()
|
||||
? &documentBufferView()->buffer() : 0;
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
#if (QT_VERSION >= 0x040400)
|
||||
QFuture<bool> f = QtConcurrent::run(saveAndDestroyBuffer, buffer->clone(),
|
||||
buffer->getAutosaveFilename());
|
||||
d.autosave_watcher_.setFuture(f);
|
||||
#else
|
||||
buffer->autoSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,6 +180,9 @@ private Q_SLOTS:
|
||||
void normalSizedIcons();
|
||||
void bigSizedIcons();
|
||||
|
||||
/// For completion of Buffer autosave thread.
|
||||
void autoSaveFinished();
|
||||
|
||||
private:
|
||||
/// Open given child document in current buffer directory.
|
||||
void openChildDocument(std::string const & filename);
|
||||
|
Loading…
Reference in New Issue
Block a user