r16665 by craig - #9845: Stop the overzealous FileWatcher from setting the doc to modified all the time

scribus-commit scribus-commit at lists.scribus.net
Wed Jun 15 22:10:38 UTC 2011


Author: craig
Date: Wed Jun 15 22:10:38 2011
New Revision: 16665

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16665
Log:
#9845: Stop the overzealous FileWatcher from setting the doc to modified all the time

Modified:
    trunk/Scribus/scribus/filewatcher.cpp
    trunk/Scribus/scribus/filewatcher.h
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/filewatcher.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16665&path=/trunk/Scribus/scribus/filewatcher.cpp
==============================================================================
--- trunk/Scribus/scribus/filewatcher.cpp (original)
+++ trunk/Scribus/scribus/filewatcher.cpp Wed Jun 15 22:10:38 2011
@@ -16,6 +16,7 @@
 #define usleep(t) Sleep((t > 1000) ? (t / 1000) : 1)
 #endif
 
+#include <QDebug>
 #include <QStringList>
 
 #include "filewatcher.h"
@@ -53,8 +54,13 @@
 	return m_timeOut;
 }
 
-void FileWatcher::addFile(QString fileName, bool fast)
-{
+void FileWatcher::addFile(QString fileName, bool fast, ScribusDoc* doc)
+{
+	if (fileName.isEmpty())
+	{
+		qDebug()<<"Attempt to add empty filename to filewatcher";
+		return;
+	}
 	watchTimer->stop();
 	if (!watchedFiles.contains(fileName))
 	{
@@ -66,6 +72,7 @@
 		fi.refCount = 1;
 		fi.isDir = fi.info.isDir();
 		fi.fast = fast;
+		fi.doc = doc;
 		watchedFiles.insert(fileName, fi);
 	}
 	else
@@ -139,6 +146,7 @@
 	QStringList toRemove;
 	
 	QMap<QString, fileMod>::Iterator it;
+//	qDebug()<<files();
 	for ( it = watchedFiles.begin(); !(m_stateFlags & FileCheckMustStop) && it != watchedFiles.end(); ++it )
 	{
 		it.value().info.refresh();
@@ -193,13 +201,16 @@
 			}
 		}
 		else
-		 {
+		{
+			qDebug()<<it.key();
 			it.value().pending = false;
 			time = it.value().info.lastModified();
 			if (time != it.value().timeInfo)
 			{
+//				qDebug()<<"Times different: last modified:"<<time<<"\t recorded time:"<<it.value().timeInfo;
 				if (it.value().isDir)
 				{
+//					qDebug()<<"dir, ignoring"<<it.key();
 					it.value().timeInfo = time;
 					if (!(m_stateFlags & FileCheckMustStop))
 						emit dirChanged(it.key());
@@ -210,6 +221,7 @@
 					usleep(100);
 					it.value().info.refresh();
 					uint sizen = it.value().info.size();
+//					qDebug()<<"Size comparison"<<sizeo<<sizen<<it.key();
 					while (sizen != sizeo)
 					{
 						sizeo = sizen;

Modified: trunk/Scribus/scribus/filewatcher.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16665&path=/trunk/Scribus/scribus/filewatcher.h
==============================================================================
--- trunk/Scribus/scribus/filewatcher.h (original)
+++ trunk/Scribus/scribus/filewatcher.h Wed Jun 15 22:10:38 2011
@@ -16,6 +16,7 @@
 
 #include "scribusapi.h"
 
+#include "scribusdoc.h"
 class SCRIBUS_API FileWatcher : public QObject
 {
 	Q_OBJECT
@@ -34,7 +35,7 @@
 	
 public slots:
 	//Add a file to the watch list for monitoring
-	void addFile(QString fileName, bool fast = false);
+	void addFile(QString fileName, bool fast = false, ScribusDoc* doc=0); //see struct note for doc var
 	//Remove a file from the watch list
 	void removeFile(QString fileName);
 	//Add a directory to the watch list for monitoring
@@ -58,6 +59,8 @@
 		int refCount;
 		bool isDir;
 		bool fast;
+		ScribusDoc* doc; //CB Added as part of #9845 but unused for now, we could avoid scanning docs in updatePict() if we used this
+
 	};
 
 	typedef enum

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16665&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp (original)
+++ trunk/Scribus/scribus/prefsmanager.cpp Wed Jun 15 22:10:38 2011
@@ -892,7 +892,7 @@
 		if (fd.exists())
 		{
 			mw->RecentDocs.append(appPrefs.uiPrefs.RecentDocs[m]);
-			ScCore->fileWatcher->addFile(appPrefs.uiPrefs.RecentDocs[m]);
+			//#9845: ScCore->fileWatcher->addFile(appPrefs.uiPrefs.RecentDocs[m]);
 		}
 	}
 	mw->rebuildRecentFileMenu();

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16665&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Wed Jun 15 22:10:38 2011
@@ -3204,7 +3204,8 @@
 	if (RecentDocs.indexOf(fn) == -1)
 	{
 		RecentDocs.prepend(fn);
-		ScCore->fileWatcher->addFile(fn);
+		//#9845, why are we tracking doc changes, see also removeRecent:
+		//ScCore->fileWatcher->addFile(fn);
 	}
 	else
 	{
@@ -3219,8 +3220,8 @@
 	if (RecentDocs.indexOf(fn) != -1)
 	{
 		RecentDocs.removeAll(fn);
-		if (!fromFileWatcher)
-			ScCore->fileWatcher->removeFile(fn);
+		//#9845: if (!fromFileWatcher)
+		//#9845:	ScCore->fileWatcher->removeFile(fn);
 	}
 	rebuildRecentFileMenu();
 }

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16665&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Wed Jun 15 22:10:38 2011
@@ -4655,7 +4655,8 @@
 		if (m_hasGUI)
 		{
 			QFileInfo fi(pageItem->Pfile);
-			ScCore->fileWatcher->addDir(fi.absolutePath());
+			//#9845, why are we tracking dir changes when we are tracking the file itself
+			//ScCore->fileWatcher->addDir(fi.absolutePath());
 			ScCore->fileWatcher->addFile(pageItem->Pfile);
 		}
 	}
@@ -7517,6 +7518,7 @@
 //CB Same as RecalcPicturesRes apart from the name checking, which should be able to be removed
 void ScribusDoc::updatePict(QString name)
 {
+	bool updated=false;
 	QList<PageItem*> allItems;
 	for (int a = 0; a < DocItems.count(); ++a)
 	{
@@ -7535,6 +7537,7 @@
 				loadPict(currItem->Pfile, currItem, true);
 				currItem->setImageFlippedH(fho);
 				currItem->setImageFlippedV(fvo);
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -7556,6 +7559,7 @@
 				loadPict(currItem->Pfile, currItem, true);
 				currItem->setImageFlippedH(fho);
 				currItem->setImageFlippedV(fvo);
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -7577,6 +7581,7 @@
 				loadPict(currItem->Pfile, currItem, true);
 				currItem->setImageFlippedH(fho);
 				currItem->setImageFlippedV(fvo);
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -7602,6 +7607,7 @@
 					loadPict(currItem->Pfile, currItem, true);
 					currItem->setImageFlippedH(fho);
 					currItem->setImageFlippedV(fvo);
+					updated=true;
 				}
 			}
 			allItems.clear();
@@ -7609,12 +7615,16 @@
 		PageItem *ite = pa.items.at(0);
 		docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(pa.items, 1.0);
 	}
-	regionsChanged()->update(QRectF());
-	changed();
+	if (updated)
+	{
+		regionsChanged()->update(QRectF());
+		changed();
+	}
 }
 
 void ScribusDoc::updatePictDir(QString name)
 {
+	bool updated=false;
 	QList<PageItem*> allItems;
 	for (int a = 0; a < DocItems.count(); ++a)
 	{
@@ -7641,6 +7651,7 @@
 							currItem->setImageFlippedH(fho);
 							currItem->setImageFlippedV(fvo);
 							ScCore->fileWatcher->addFile(currItem->Pfile);
+							updated=true;
 						}
 					}
 				}
@@ -7673,6 +7684,7 @@
 							currItem->setImageFlippedH(fho);
 							currItem->setImageFlippedV(fvo);
 							ScCore->fileWatcher->addFile(currItem->Pfile);
+							updated=true;
 						}
 					}
 				}
@@ -7705,6 +7717,7 @@
 							currItem->setImageFlippedH(fho);
 							currItem->setImageFlippedV(fvo);
 							ScCore->fileWatcher->addFile(currItem->Pfile);
+							updated=true;
 						}
 					}
 				}
@@ -7741,6 +7754,7 @@
 								currItem->setImageFlippedH(fho);
 								currItem->setImageFlippedV(fvo);
 								ScCore->fileWatcher->addFile(currItem->Pfile);
+								updated=true;
 							}
 						}
 					}
@@ -7751,8 +7765,11 @@
 			docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(pa.items, 1.0);
 		}
 	}
-	regionsChanged()->update(QRectF());
-	changed();
+	if (updated)
+	{
+		regionsChanged()->update(QRectF());
+		changed();
+	}
 }
 
 //CB Same as updatePict apart from the name checking, this should be able to be removed
@@ -7967,6 +7984,7 @@
 
 void ScribusDoc::removePict(QString name)
 {
+	bool updated=false;
 	QList<PageItem*> allItems;
 	for (int a = 0; a < DocItems.count(); ++a)
 	{
@@ -7982,6 +8000,7 @@
 			{
 				currItem->PictureIsAvailable = false;
 				currItem->pixm = ScImage();
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -8000,6 +8019,7 @@
 			{
 				currItem->PictureIsAvailable = false;
 				currItem->pixm = ScImage();
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -8018,6 +8038,7 @@
 			{
 				currItem->PictureIsAvailable = false;
 				currItem->pixm = ScImage();
+				updated=true;
 			}
 		}
 		allItems.clear();
@@ -8040,6 +8061,7 @@
 				{
 					currItem->PictureIsAvailable = false;
 					currItem->pixm = ScImage();
+					updated=true;
 				}
 			}
 			allItems.clear();
@@ -8047,8 +8069,11 @@
 		PageItem *ite = pa.items.at(0);
 		docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(pa.items, 1.0);
 	}
-	regionsChanged()->update(QRectF());
-	changed();
+	if (updated)
+	{
+		regionsChanged()->update(QRectF());
+		changed();
+	}
 }
 
 




More information about the scribus-commit mailing list