r18957 by craig - Move autosave functionality to the doc.. cleaning up from ScribusWin

scribus-commit scribus-commit at lists.scribus.net
Thu Mar 27 20:59:58 UTC 2014


Author: craig
Date: Thu Mar 27 20:59:57 2014
New Revision: 18957

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18957
Log:
Move autosave functionality to the doc.. cleaning up from ScribusWin

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/scribuswin.cpp
    trunk/Scribus/scribus/scribuswin.h

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18957&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Thu Mar 27 20:59:57 2014
@@ -4565,8 +4565,9 @@
 	closeActiveWindowMasterPageEditor();
 	slotSelect();
 	doc->autoSaveTimer->stop();
-	disconnect(doc->autoSaveTimer, SIGNAL(timeout()), doc->WinHan, SLOT(slotAutoSave()));
-	disconnect(doc->WinHan, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
+	doc->disconnectDocSignals();
+	disconnect(doc, SIGNAL(saved(QString)));
+	disconnect(doc->WinHan, SIGNAL(AutoSaved()));
 	disconnect(ScCore->fileWatcher, SIGNAL(fileChanged(QString )), doc, SLOT(updatePict(QString)));
 	disconnect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), doc, SLOT(removePict(QString)));
 	disconnect(ScCore->fileWatcher, SIGNAL(dirChanged(QString )), doc, SLOT(updatePictDir(QString )));

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18957&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Thu Mar 27 20:59:57 2014
@@ -45,7 +45,6 @@
 #include "colorblind.h"
 #include "commonstrings.h"
 #include "desaxe/digester.h"
-//#include "desaxe/saxXML.h"
 #include "fileloader.h"
 #include "filewatcher.h"
 #include "fpoint.h"
@@ -10062,11 +10061,25 @@
 		{
 			connect(this, SIGNAL(docChanged()), m_ScMW, SLOT(slotDocCh()));
 			connect(this, SIGNAL(firstSelectedItemType(int)), m_ScMW, SLOT(HaveNewSel(int)));
-			connect(autoSaveTimer, SIGNAL(timeout()), WinHan, SLOT(slotAutoSave()));
-		}
-	}
-}
-
+			connect(this, SIGNAL(saved(QString)), WinHan, SLOT(slotSaved(QString)));
+			connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
+		}
+	}
+}
+
+void ScribusDoc::disconnectDocSignals()
+{
+	if (ScCore->usingGUI())
+	{
+		if (m_hasGUI)
+		{
+			disconnect(this, SIGNAL(docChanged()), m_ScMW, SLOT(slotDocCh()));
+			disconnect(this, SIGNAL(firstSelectedItemType(int)), m_ScMW, SLOT(HaveNewSel(int)));
+			disconnect(this, SIGNAL(saved(QString)), WinHan, SLOT(slotSaved(QString)));
+			disconnect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
+		}
+	}
+}
 
 //CB Same as RecalcPicturesRes apart from the name checking, which should be able to be removed
 void ScribusDoc::updatePict(QString name)
@@ -17098,6 +17111,16 @@
 	if (docPrefsData.docSetupPrefs.AutoSave)
 		autoSaveTimer->start(docPrefsData.docSetupPrefs.AutoSaveTime);
 	emit updateAutoSaveClock();
+}
+
+void ScribusDoc::slotAutoSave()
+{
+	if (hasName && isModified())
+	{
+		FileLoader fl(DocName);
+		if (fl.saveFile(DocName+".autosave", this, 0))
+			emit saved(DocName);
+	}
 }
 
 void ScribusDoc::setupNumerations()

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18957&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Thu Mar 27 20:59:57 2014
@@ -1127,6 +1127,7 @@
 	};
 	void recalcPicturesRes(bool applyNewRes = false);
 	void connectDocSignals();
+	void disconnectDocSignals();
 	void removeLayer(int l, bool dl = false); //FIXME: Make protected once scripter function no longer uses this directly
 	/*! \brief We call changed() whenever the document needs to know it has been changed.
 	 *  If the document is the primary document in a main window, it will signal to enable/disable
@@ -1385,6 +1386,7 @@
 	 * @brief Let the document tell whatever is listening that it has changed
 	 */
 	void docChanged();
+	void saved(QString name);
 	void updateContents();
 	void updateContents(const QRect &r);
 	void refreshItem(PageItem *);
@@ -1784,6 +1786,9 @@
 	void itemSelection_EditWeld();
 	void restartAutoSaveTimer();
 
+protected slots:
+	void slotAutoSave();
+
 //auto-numerations
 public:
 	QMap<QString, NumStruct*> numerations;
@@ -1803,6 +1808,7 @@
 	void SubmitForm();
 	void ImportData();
 	void ResetFormFields();
+
 };
 
 Q_DECLARE_METATYPE(ScribusDoc*);

Modified: trunk/Scribus/scribus/scribuswin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18957&path=/trunk/Scribus/scribus/scribuswin.cpp
==============================================================================
--- trunk/Scribus/scribus/scribuswin.cpp (original)
+++ trunk/Scribus/scribus/scribuswin.cpp Thu Mar 27 20:59:57 2014
@@ -91,23 +91,11 @@
 	setCentralWidget(newView);
 }
 
-void ScribusWin::slotAutoSave()
+void ScribusWin::slotSaved(QString newName)
 {
-	if ((m_Doc->hasName) && (m_Doc->isModified()))
-	{
-		//#8081 : change behavior of autosave, autosave writes now to an .autosave file
-		//instead of overwriting source document
-		//moveFile(m_Doc->DocName, m_Doc->DocName+".bak");
-		FileLoader fl(m_Doc->DocName);
-		if (fl.saveFile(m_Doc->DocName+".autosave", m_Doc, 0))
-		{
-			//#8081 related : do not unset modified flag until user really save file
-			//m_Doc->setModified(false);
-			setWindowTitle(QDir::toNativeSeparators(m_Doc->DocName));
-			qApp->processEvents();
-			emit AutoSaved();
-		}
-	}
+	setWindowTitle(QDir::toNativeSeparators(newName));
+	qApp->processEvents();
+	emit AutoSaved(); //TODO: to update the main window title, do this from the doc?
 }
 
 void ScribusWin::closeEvent(QCloseEvent *ce)

Modified: trunk/Scribus/scribus/scribuswin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18957&path=/trunk/Scribus/scribus/scribuswin.h
==============================================================================
--- trunk/Scribus/scribus/scribuswin.h (original)
+++ trunk/Scribus/scribus/scribuswin.h Thu Mar 27 20:59:57 2014
@@ -60,8 +60,8 @@
 	bool menuStatus(int index) const { if (index>=0 && index <=6) return MenuStat[index]; else return false; }
 	
 public slots:
-	void slotAutoSave();
-	
+	void slotSaved(QString newName);
+
 signals:
 	void AutoSaved();
 




More information about the scribus-commit mailing list