}
+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_)
#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>
///
TocModels toc_models_;
+
+#if (QT_VERSION >= 0x040400)
+ ///
+ QFutureWatcher<bool> autosave_watcher_;
+#endif
};
// clear session data if any.
QSettings settings;
settings.remove("views");
+
+#if (QT_VERSION >= 0x040400)
+ connect(&d.autosave_watcher_, SIGNAL(finished()), this,
+ SLOT(autoSaveFinished()));
+#endif
}
}
+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;
}
+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
}