Skip to content

Commit

Permalink
+ issue #175: Auto save function
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Sep 4, 2015
1 parent 9253572 commit 9cb6329
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/Gui/Application.cpp
Expand Up @@ -87,6 +87,7 @@
#include "DlgOnlineHelpImp.h"
#include "SpaceballEvent.h"
#include "Control.h"
#include "DocumentRecovery.h"
#include "TaskView/TaskView.h"

#include "SplitView3DInventor.h"
Expand Down Expand Up @@ -1913,7 +1914,8 @@ void Application::checkForPreviousCrashes()
if (tmp.rmdir(it->filePath()))
countDeletedDocs++;
}
else {
// search for the existance of a recovery file
else if (doc_dir.exists(QLatin1String("fc_recovery_file.fcstd"))) {
// store the transient directory in case it's not empty
restoreDocFiles << *it;
}
Expand All @@ -1930,6 +1932,8 @@ void Application::checkForPreviousCrashes()
}

if (!restoreDocFiles.isEmpty()) {
//TODO:
Gui::Dialog::DocumentRecovery dlg(restoreDocFiles, Gui::getMainWindow());
if (dlg.foundDocuments())
dlg.exec();
}
}
22 changes: 19 additions & 3 deletions src/Gui/AutoSaver.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
Expand All @@ -25,6 +25,8 @@

#ifndef _PreComp_
# include <QApplication>
# include <QFile>
# include <QTextStream>
# include <boost/bind.hpp>
#endif

Expand Down Expand Up @@ -97,8 +99,22 @@ void AutoSaver::saveDocument(const std::string& name)
Gui::WaitCursor wc;
App::Document* doc = App::GetApplication().getDocument(name.c_str());
if (doc) {
// Write recovery meta file
QFile file(QString::fromLatin1("%1/fc_recovery_file.xml")
.arg(QString::fromUtf8(doc->TransientDir.getValue())));
if (file.open(QFile::WriteOnly)) {
QTextStream str(&file);
str.setCodec("UTF-8");
str << "<?xml version='1.0' encoding='utf-8'?>" << endl
<< "<AutoRecovery SchemaVersion=\"1\">" << endl;
str << " <Status>Created</Status>" << endl;
str << " <Label>" << doc->Label.getValue() << "</Label>" << endl; // store the document's current label
str << "</AutoRecovery>" << endl;
file.close();
}

std::string fn = doc->TransientDir.getValue();
fn += "/fc_autosave_file.fcstd";
fn += "/fc_recovery_file.fcstd";
Base::FileInfo tmp(fn);

// make sure to tmp. disable saving thumbnails because this causes trouble if the
Expand All @@ -121,7 +137,7 @@ void AutoSaver::saveDocument(const std::string& name)
if (file.is_open()) {
Base::ZipWriter writer(file);

writer.setComment(doc->Label.getValue()); // store the document's current label
writer.setComment("AutoRecovery file");
writer.setLevel(1); // apparently the fastest compression
writer.putNextEntry("Document.xml");

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/AutoSaver.h
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -202,6 +202,7 @@ set(Gui_MOC_HDRS
DlgUndoRedo.h
DockWindow.h
DockWindowManager.h
DocumentRecovery.h
EditorView.h
FileDialog.h
Flag.h
Expand Down Expand Up @@ -303,6 +304,7 @@ SET(Gui_UIC_SRCS
DlgTreeWidget.ui
DlgLocationAngle.ui
DlgLocationPos.ui
DocumentRecovery.ui
DownloadManager.ui
DownloadItem.ui
MouseButtons.ui
Expand Down Expand Up @@ -375,6 +377,7 @@ SET(Dialog_CPP_SRCS
DownloadDialog.cpp
DownloadItem.cpp
DownloadManager.cpp
DocumentRecovery.cpp
)

SET(Dialog_HPP_SRCS
Expand Down Expand Up @@ -405,6 +408,7 @@ SET(Dialog_HPP_SRCS
DownloadDialog.h
DownloadItem.h
DownloadManager.h
DocumentRecovery.h
)

SET(Dialog_SRCS
Expand Down Expand Up @@ -432,6 +436,7 @@ SET(Dialog_SRCS
DlgTreeWidget.ui
DownloadManager.ui
DownloadItem.ui
DocumentRecovery.ui
MouseButtons.ui
InputVector.ui
Placement.ui
Expand Down

0 comments on commit 9cb6329

Please sign in to comment.