r24518 by jghali - #16488: Image file getting deleted on closing document
scribus-commit
scribus-commit at lists.scribus.net
Mon Feb 22 20:21:58 UTC 2021
Author: jghali
Date: Mon Feb 22 20:21:58 2021
New Revision: 24518
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24518
Log:
#16488: Image file getting deleted on closing document
Modified:
trunk/Scribus/scribus/filewatcher.cpp
trunk/Scribus/scribus/filewatcher.h
trunk/Scribus/scribus/pageitem.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.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=24518&path=/trunk/Scribus/scribus/filewatcher.cpp
==============================================================================
--- trunk/Scribus/scribus/filewatcher.cpp (original)
+++ trunk/Scribus/scribus/filewatcher.cpp Mon Feb 22 20:21:58 2021
@@ -15,6 +15,7 @@
#endif
#include <QDebug>
+#include <QDir>
#include <QStringList>
#include "filewatcher.h"
@@ -42,7 +43,7 @@
void FileWatcher::setTimeOut(int newTimeOut, bool restartTimer)
{
- m_timeOut=newTimeOut;
+ m_timeOut = newTimeOut;
if (restartTimer)
start();
}
@@ -59,11 +60,13 @@
qDebug()<<"Attempt to add empty filename to filewatcher";
return;
}
- m_watchTimer->stop();
- if (!m_watchedFiles.contains(fileName))
+ QString qtFileName = QDir::fromNativeSeparators(fileName);
+
+ m_watchTimer->stop();
+ if (!m_watchedFiles.contains(qtFileName))
{
struct fileMod fi;
- fi.info = QFileInfo(fileName);
+ fi.info = QFileInfo(qtFileName);
fi.timeInfo = fi.info.lastModified();
fi.pendingCount = 0;
fi.pending = false;
@@ -71,22 +74,23 @@
fi.isDir = fi.info.isDir();
fi.fast = fast;
fi.doc = doc;
- m_watchedFiles.insert(fileName, fi);
+ m_watchedFiles.insert(qtFileName, fi);
}
else
- m_watchedFiles[fileName].refCount++;
+ m_watchedFiles[qtFileName].refCount++;
if (!(m_stateFlags & TimerStopped))
m_watchTimer->start(m_timeOut);
}
void FileWatcher::removeFile(const QString& fileName)
{
- m_watchTimer->stop();
- if (m_watchedFiles.contains(fileName))
- {
- m_watchedFiles[fileName].refCount--;
- if (m_watchedFiles[fileName].refCount == 0)
- m_watchedFiles.remove(fileName);
+ QString qtFileName = QDir::fromNativeSeparators(fileName);
+ m_watchTimer->stop();
+ if (m_watchedFiles.contains(qtFileName))
+ {
+ m_watchedFiles[qtFileName].refCount--;
+ if (m_watchedFiles[qtFileName].refCount == 0)
+ m_watchedFiles.remove(qtFileName);
}
if (!(m_stateFlags & TimerStopped))
m_watchTimer->start(m_timeOut);
@@ -127,6 +131,12 @@
bool FileWatcher::isActive()
{
return (m_stateFlags & AddRemoveBlocked);
+}
+
+bool FileWatcher::isWatching(const QString& fileName)
+{
+ QString qtFileName = QDir::fromNativeSeparators(fileName);
+ return m_watchedFiles.contains(qtFileName);
}
QList<QString> FileWatcher::files()
@@ -227,7 +237,7 @@
m_watchedFiles.clear();
else
{
- for (int i=0; i<toRemove.count(); ++i)
+ for (int i = 0; i<toRemove.count(); ++i)
m_watchedFiles.remove(toRemove[i]);
m_stateFlags &= ~AddRemoveBlocked;
m_stateFlags &= ~TimerStopped;
Modified: trunk/Scribus/scribus/filewatcher.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/filewatcher.h
==============================================================================
--- trunk/Scribus/scribus/filewatcher.h (original)
+++ trunk/Scribus/scribus/filewatcher.h Mon Feb 22 20:21:58 2021
@@ -24,9 +24,11 @@
public:
FileWatcher(QObject* parent);
~FileWatcher() override;
+
+ // Get if file check loop is running
bool isActive();
- // Get if file check loop is running
- void isFileCheckRunning();
+ // Check if a file is currently being watched
+ bool isWatching(const QString& fileName);
// Set the timer length in milliseconds
void setTimeOut(const int newTimeOut, const bool restartTimer=false);
// Get the timer length
Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Mon Feb 22 20:21:58 2021
@@ -717,9 +717,9 @@
if (isTextFrame())
{
- if (!asTextFrame()->isInChain() && itemText.length() >0)
- {
- for (int pos=0; pos < itemText.length(); ++pos)
+ if (!asTextFrame()->isInChain() && itemText.length() > 0)
+ {
+ for (int pos = 0; pos < itemText.length(); ++pos)
{
if (itemText.hasMark(pos))
{
@@ -10442,7 +10442,7 @@
isInlineImage = true;
isTempFile = true;
copyFile(Pfile, fileName);
- Pfile = fileName;
+ Pfile = QDir::fromNativeSeparators(fileName);
delete tempFile;
}
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp Mon Feb 22 20:21:58 2021
@@ -6,6 +6,14 @@
*/
#include "scribus12format.h"
#include "scribus12formatimpl.h"
+
+#include <QApplication>
+#include <QByteArray>
+#include <QCursor>
+#include <QDir>
+#include <QFileInfo>
+#include <QList>
+#include <QMessageBox>
#include "../../formatidlist.h"
#include "commonstrings.h"
@@ -28,13 +36,6 @@
#include "util_color.h"
#include "util_layer.h"
#include "util_math.h"
-#include <QCursor>
-#include <QFileInfo>
-#include <QList>
-#include <QByteArray>
-#include <QApplication>
-#include <QMessageBox>
-
// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
// do. That documentatation is not duplicated here.
@@ -1615,6 +1616,9 @@
OB->Pfile = Relative2Path(obj->attribute("PFILE" ,""), baseDir);
OB->Pfile2 = Relative2Path(obj->attribute("PFILE2",""), baseDir);
OB->Pfile3 = Relative2Path(obj->attribute("PFILE3",""), baseDir);
+ OB->Pfile = QDir::fromNativeSeparators(OB->Pfile);
+ OB->Pfile2 = QDir::fromNativeSeparators(OB->Pfile2);
+ OB->Pfile3 = QDir::fromNativeSeparators(OB->Pfile3);
OB->ImageProfile = obj->attribute("PRFILE","");
OB->ImageIntent = (eRenderIntent) obj->attribute("IRENDER", "1").toInt();
OB->EmbeddedProfile = obj->attribute("EPROF","");
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp Mon Feb 22 20:21:58 2021
@@ -13,6 +13,7 @@
#include <QByteArray>
#include <QCursor>
// #include <QDebug>
+#include <QDir>
#include <QFileInfo>
#include <QIODevice>
#include <QList>
@@ -2635,14 +2636,17 @@
outFil.write(inlineImageData);
outFil.close();
currItem->isInlineImage = true;
- currItem->Pfile = fileName;
+ currItem->Pfile = QDir::fromNativeSeparators(fileName);
currItem->isTempFile = true;
}
delete tempFile;
}
}
else
+ {
currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
+ }
}
currItem->ImageProfile = attrs.valueAsString("PRFILE", "");
currItem->ImageIntent = (eRenderIntent) attrs.valueAsInt("IRENDER", 1);
@@ -2910,6 +2914,9 @@
currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , ""), baseDir);
currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
+ currItem->Pfile2 = QDir::fromNativeSeparators(currItem->Pfile2);
+ currItem->Pfile3 = QDir::fromNativeSeparators(currItem->Pfile3);
currItem->ImageProfile = attrs.valueAsString("PRFILE", "");
currItem->ImageIntent = (eRenderIntent) attrs.valueAsInt("IRENDER" , 1);
currItem->EmbeddedProfile = attrs.valueAsString("EPROF", "");
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp Mon Feb 22 20:21:58 2021
@@ -6,6 +6,15 @@
*/
#include "scribus13format.h"
#include "scribus13formatimpl.h"
+
+#include <QApplication>
+#include <QByteArray>
+#include <QCursor>
+#include <QDataStream>
+// #include <QDebug>
+#include <QDir>
+#include <QFileInfo>
+#include <QMessageBox>
#include "../../formatidlist.h"
#include "commonstrings.h"
@@ -31,14 +40,6 @@
#include "ui/missing.h"
#include "ui/scmessagebox.h"
-
-#include <QCursor>
-// #include <QDebug>
-#include <QFileInfo>
-#include <QByteArray>
-#include <QDataStream>
-#include <QApplication>
-#include <QMessageBox>
// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
// do. That documentatation is not duplicated here.
@@ -1529,7 +1530,8 @@
currItem->setImageXYScale(scx, scy);
currItem->setImageXYOffset(offsX, offsY);
currItem->setImageRotation(rot);
- currItem->Pfile = Relative2Path(obj->attribute("PFILE"), baseDir);
+ currItem->Pfile = Relative2Path(obj->attribute("PFILE"), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
currItem->ImageProfile = obj->attribute("PRFILE","");
currItem->ImageIntent = (eRenderIntent) obj->attribute("IRENDER", "1").toInt();
currItem->EmbeddedProfile = obj->attribute("EPROF","");
@@ -1824,6 +1826,9 @@
currItem->Pfile = Relative2Path(obj->attribute("PFILE" ,""), baseDir);
currItem->Pfile2 = Relative2Path(obj->attribute("PFILE2",""), baseDir);
currItem->Pfile3 = Relative2Path(obj->attribute("PFILE3",""), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
+ currItem->Pfile2 = QDir::fromNativeSeparators(currItem->Pfile2);
+ currItem->Pfile3 = QDir::fromNativeSeparators(currItem->Pfile3);
currItem->ImageProfile = obj->attribute("PRFILE","");
currItem->ImageIntent = (eRenderIntent) obj->attribute("IRENDER", "1").toInt();
currItem->EmbeddedProfile = obj->attribute("EPROF","");
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp Mon Feb 22 20:21:58 2021
@@ -13,6 +13,7 @@
#include <QByteArray>
#include <QCursor>
// #include <QDebug>
+#include <QDir>
#include <QFileInfo>
#include <QList>
#include <QScopedPointer>
@@ -5303,14 +5304,17 @@
outFil.write(inlineImageData);
outFil.close();
currItem->isInlineImage = true;
- currItem->Pfile = fileName;
+ currItem->Pfile = QDir::fromNativeSeparators(fileName);
currItem->isTempFile = true;
}
delete tempFile;
}
}
else
+ {
currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
+ }
#ifdef HAVE_OSG
if (currItem->isOSGFrame())
{
@@ -5659,6 +5663,9 @@
currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , ""), baseDir);
currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
+ currItem->Pfile = QDir::fromNativeSeparators(currItem->Pfile);
+ currItem->Pfile2 = QDir::fromNativeSeparators(currItem->Pfile2);
+ currItem->Pfile3 = QDir::fromNativeSeparators(currItem->Pfile3);
currItem->ImageProfile = attrs.valueAsString("PRFILE", "");
currItem->ImageIntent = (eRenderIntent) attrs.valueAsInt("IRENDER" , 1);
currItem->EmbeddedProfile = attrs.valueAsString("EPROF", "");
Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Mon Feb 22 20:21:58 2021
@@ -3926,7 +3926,7 @@
QString fileName = CFileDialog(wdir, tr("Filename and Path for Image"), tr("All Files (*)"), fiB.fileName(), fdHidePreviewCheckBox);
if (!fileName.isEmpty())
{
- if (ScCore->fileWatcher->files().contains(currItem->Pfile) != 0)
+ if (ScCore->fileWatcher->isWatching(currItem->Pfile))
ScCore->fileWatcher->removeFile(currItem->Pfile);
docContext->set("place_as", fileName.left(fileName.lastIndexOf("/")));
if (overwrite(this, fileName))
@@ -3943,7 +3943,7 @@
}
else
{
- if (ScCore->fileWatcher->files().contains(currItem->Pfile) != 0)
+ if (ScCore->fileWatcher->isWatching(currItem->Pfile))
ScCore->fileWatcher->removeFile(currItem->Pfile);
currItem->makeImageInline();
ScCore->fileWatcher->addFile(currItem->Pfile);
Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24518&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Mon Feb 22 20:21:58 2021
@@ -5623,9 +5623,10 @@
{
if (!reload)
{
- if ((ScCore->fileWatcher->files().contains(pageItem->Pfile) != 0) && (pageItem->imageIsAvailable))
- {
- ScCore->fileWatcher->removeFile(pageItem->Pfile);
+ if (pageItem->imageIsAvailable)
+ {
+ if (ScCore->fileWatcher->isWatching(pageItem->Pfile))
+ ScCore->fileWatcher->removeFile(pageItem->Pfile);
if (pageItem->isTempFile)
{
QFile::remove(pageItem->Pfile);
@@ -11054,7 +11055,7 @@
PageItem *currItem = itemSelection->itemAt(i);
if (currItem->isImageFrame())
{
- if ((ScCore->fileWatcher->files().contains(currItem->Pfile) != 0) && (currItem->imageIsAvailable))
+ if (ScCore->fileWatcher->isWatching(currItem->Pfile) && currItem->imageIsAvailable)
ScCore->fileWatcher->removeFile(currItem->Pfile);
}
currItem->clearContents();
@@ -11185,7 +11186,7 @@
itemList = groupOfItem(Items, currItem);
if (itemList == nullptr)
continue;
- if ((currItem->isImageFrame()) && ((ScCore->fileWatcher->files().contains(currItem->Pfile) != 0) && (currItem->imageIsAvailable)))
+ if (currItem->isImageFrame() && ScCore->fileWatcher->isWatching(currItem->Pfile) && currItem->imageIsAvailable)
ScCore->fileWatcher->removeFile(currItem->Pfile);
//delete marks pointed to that item
for (int a=0; a < m_docMarksList.count(); a++)
More information about the scribus-commit
mailing list