View Issue Details

IDProjectCategoryView StatusLast Update
0007966ScribusUsabilitypublic2019-11-24 10:55
Reporterale Assigned Toale  
PrioritylowSeverityfeatureReproducibilityN/A
Status closedResolutionduplicate 
Product Version1.3.5svn 
Target Version1.5.5Fixed in Version 
Summary0007966: [PATCH] alert for missing images
Descriptionif an image has been placed in a document but has been moved to another place on the disk, when opening the .sla file a dialog should popup asking to the user if he wants to search for the image (and replace its location) or ignore it.

the user should be warned that he should not move the images, since they are not embedded.
Additional Informationthis feature should be enabled by default, but it should be easy to disable it (like the open/new dialog when starting scribus).
 
Tags#rottenpatch, patch
PatchYes

Relationships

related to 0011791 assignedale [PATCH] Choose directory for missing image 
related to 0008914 closedale change image folder 

Activities

cezaryece

2012-08-21 13:51

developer   ~0028850

Not perfect, but attached provide solution for that.

cezaryece

2012-08-21 17:12

developer  

missingFiles.diff (6,597 bytes)
diff --git a/Scribus/scribus/canvasmode_normal.cpp b/Scribus/scribus/canvasmode_normal.cpp
index 7cf09ab..803e947 100644
--- a/Scribus/scribus/canvasmode_normal.cpp
+++ b/Scribus/scribus/canvasmode_normal.cpp
@@ -1476,6 +1476,7 @@ void CanvasMode_Normal::importToPage()
 		m_doc->useRaster = savedAlignGrid;
 		m_doc->SnapGuides = savedAlignGuides;
 		m_doc->SnapElement = savedAlignElement;
+		m_ScMW->checkMissingImages();
 		m_doc->setLoading(false);
 		m_doc->view()->DrawNew();
 		if (m_doc->m_Selection->count() > 0)
diff --git a/Scribus/scribus/scribus.cpp b/Scribus/scribus/scribus.cpp
index 331736f..58e3a03 100644
--- a/Scribus/scribus/scribus.cpp
+++ b/Scribus/scribus/scribus.cpp
@@ -229,6 +229,7 @@ for which a new license (GPL+exception) is in place.
 #include "urllauncher.h"
 #include "util.h"
 #include "util_formats.h"
+#include "util_file.h"
 #include "util_ghostscript.h"
 #include "util_icon.h"
 #include "util_math.h"
@@ -4134,6 +4135,7 @@ bool ScribusMainWindow::loadDoc(QString fileName)
 			Apply_MasterPage(doc->DocPages.at(p)->MPageNam, p, false);
 		}
 		view->reformPages(false);
+		checkMissingImages();
 		doc->setLoading(false);
 /*		if (fileLoader->FileType > FORMATID_NATIVEIMPORTEND)
 		{
@@ -10313,3 +10315,29 @@ void ScribusMainWindow::updateTableMenuActions()
 	scrActions["tableAdjustTableToFrame"]->setEnabled(table);
 }
 
+void ScribusMainWindow::checkMissingImages()
+{
+	QMap<QString, PageItem*> missingMap;
+	for (int a = 0; a < doc->Items->count(); ++a)
+	{
+		PageItem *currItem = doc->Items->at(a);
+		if (!currItem->Pfile.isEmpty())
+		{
+			QFileInfo fi = QFileInfo(currItem->Pfile);
+			if (!fi.exists())
+				missingMap.insert(fi.absoluteFilePath(), currItem);
+		}
+	}
+
+	if (!missingMap.isEmpty())
+	{
+		QMap<QString, QString> replaceMap = fileFinder(missingMap.keys(), this);
+		foreach (QString filePath, replaceMap.keys())
+		{
+			PageItem* item = missingMap.value(filePath);
+			item->loadImage(replaceMap.value(filePath), false);
+		}
+		doc->updatePic();
+	}
+}
+
diff --git a/Scribus/scribus/scribus.h b/Scribus/scribus/scribus.h
index e79d311..74d2801 100644
--- a/Scribus/scribus/scribus.h
+++ b/Scribus/scribus/scribus.h
@@ -518,7 +518,8 @@ public slots:
 	 * canvas modes/gestures.
 	 */
 	void updateTableMenuActions();
-
+	//! \brief check for missing externals files (images for now)
+	void checkMissingImages();
 signals:
 	void AppModeChanged(int oldMode, int newMode);
 	void TextStyle(const ParagraphStyle&);
diff --git a/Scribus/scribus/util_file.cpp b/Scribus/scribus/util_file.cpp
index 589ebd8..10713f4 100644
--- a/Scribus/scribus/util_file.cpp
+++ b/Scribus/scribus/util_file.cpp
@@ -13,14 +13,19 @@ for which a new license (GPL+exception) is in place.
 # include <utime.h>
 #endif
 
+#include <QCheckBox>
 #include <QDataStream>
 #include <QDir>
 #include <QFile>
 #include <QFileInfo>
+#include <QList>
+#include <QMap>
 #include <QString>
 #include <QProcess>
 #include <QTemporaryFile>
+#include <QWidget>
 
+#include "ui/customfdialog.h"
 #include "scstreamfilter.h"
 
 bool copyData(QIODevice& src, QIODevice& dest)
@@ -230,3 +235,88 @@ bool fileInPath(const QString& filename)
 	}
 	return false;
 }
+
+QMap<QString, QString> fileFinder(QList<QString> filesList, QWidget* parent)
+{
+	QString searchPath = QString();
+	bool reUsePath = false;
+	QMap<QString, QString> resultMap;
+	foreach (QString sPath, filesList)
+		resultMap.insert(sPath, QString());
+	QMap<QString, QString> replacePaths; //map for remember replaced paths
+	foreach (QString filePath, filesList)
+	{
+		QFileInfo fi = QFileInfo(filePath);
+		if (fi.exists())
+		{
+			resultMap.insert(filePath, filePath);
+			continue;
+		}
+
+		QString sPath = fi.absolutePath();
+		QString dPath = QString();
+		if (replacePaths.contains(sPath))
+		{
+			dPath = replacePaths.value(sPath);
+			QFile f(dPath + "/" + fi.fileName());
+			if (f.exists())
+			{
+				resultMap.insert(filePath, dPath + "/" + fi.fileName());
+				continue;
+			}
+			if (!searchPath.isEmpty())
+			{
+				QFile f(searchPath + "/" + fi.fileName());
+				if (f.exists())
+				{
+					resultMap.insert(filePath, searchPath + "/" + fi.fileName());
+					continue;
+				}
+				else
+					searchPath.clear();
+			}
+		}
+		QString wdir = QDir::fromNativeSeparators( fi.path() );
+		QString fname = fi.fileName();
+		
+		CustomFDialog *dia = new CustomFDialog(parent, wdir, QWidget::tr("Find Missing External File: ") + fi.filePath(), QString(), fdShowPreview + fdExistingFiles);
+		QCheckBox* usePath = new QCheckBox(dia);
+		usePath->setText( QWidget::tr("Search other missing files in selected directory"));
+		usePath->setToolTip( QWidget::tr("If other missing files were found then first they will searched in that directory and dialog does not appear."));
+		usePath->setChecked(reUsePath);
+		dia->addWidgets(usePath);
+		QCheckBox* stopSearch = new QCheckBox(dia);
+		stopSearch->setText( QWidget::tr("Stop searching of missing files"));
+		stopSearch->setChecked(false);
+		dia->addWidgets(stopSearch);
+		dia->setSelection(fname);
+		
+		if (dia->exec() == QDialog::Accepted)
+		{
+			fname = dia->selectedFile();
+			if (!fname.isEmpty())
+			{
+				fi = QFileInfo(fname);
+				resultMap.insert(filePath, fi.absoluteFilePath());
+				replacePaths.insert(wdir, fi.absolutePath());
+				if (usePath->isChecked())
+				{
+					searchPath = fi.absolutePath();
+					reUsePath = true;
+				}
+				else
+				{
+					searchPath.clear();
+					reUsePath = false;
+				}
+			}
+		}
+		if (stopSearch->isChecked())
+		{
+			delete dia;
+			break;
+		}
+		delete dia;
+	}
+	return resultMap;
+}
diff --git a/Scribus/scribus/util_file.h b/Scribus/scribus/util_file.h
index 933cdf8..33e7531 100644
--- a/Scribus/scribus/util_file.h
+++ b/Scribus/scribus/util_file.h
@@ -8,10 +8,12 @@ for which a new license (GPL+exception) is in place.
 #define _UTIL_FILE_H
 
 #include "scribusapi.h"
-
+#include <QList>
+#include <QMap>
 class QDataStream;
 class QString;
 class ScStreamFilter;
+class QWidget;
 
 /**
 * @brief Copy a source file to a target
@@ -83,4 +85,15 @@ bool SCRIBUS_API touchFile(const QString& file);
 **/
 bool SCRIBUS_API fileInPath(const QString& filename);
 
+/**
+ * @brief Ask user for missing files
+ *
+ * FileFinder can be used for asking user for some missing files
+ * FileFinder takes list of missing files paths
+ * and returns map of replaced paths
+ * Dirs where files was found are stored and used for next searches
+ * for minimalize asks to user
+ */
+QMap<QString, QString> SCRIBUS_API fileFinder(QList<QString> filesList, QWidget* parent);
+
 #endif
missingFiles.diff (6,597 bytes)

ale

2019-11-24 10:55

manager   ~0047130

0011791 is a better ticket for this...

Issue History

Date Modified Username Field Change
2009-04-22 11:39 ale New Issue
2009-04-22 21:35 christoph_s Target Version => 1.3.6
2009-05-15 18:27 christoph_s Status new => acknowledged
2012-08-21 13:51 cezaryece Note Added: 0028850
2012-08-21 13:51 cezaryece File Added: missingImages.diff
2012-08-21 17:12 cezaryece File Deleted: missingImages.diff
2012-08-21 17:12 cezaryece File Added: missingFiles.diff
2014-07-03 05:27 Kunda Tag Attached: patch
2014-07-03 05:27 Kunda Target Version 1.5.0 => 1.5.1
2014-07-13 19:42 Kunda Summary alert for missinig images => [PATCH] alert for missinig images
2014-08-11 18:47 Kunda Summary [PATCH] alert for missinig images => [PATCH] alert for missing images
2014-09-18 23:10 Kunda Relationship added related to 0008914
2014-09-18 23:12 Kunda Relationship added related to 0011791
2014-10-24 22:57 Kunda Patch => Yes
2016-01-23 17:17 cbradney Target Version 1.5.1 => 1.5.3
2016-12-08 22:04 Kunda Target Version 1.5.3 => 1.5.4
2018-04-30 13:03 jghali Target Version 1.5.4 => 1.5.5
2018-05-02 08:41 JLuc Tag Attached: #rottenpatch
2019-11-24 10:55 ale Assigned To => ale
2019-11-24 10:55 ale Status acknowledged => closed
2019-11-24 10:55 ale Resolution open => duplicate
2019-11-24 10:55 ale Note Added: 0047130