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