ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #05019
[Merge] lp:~verzegnassi-stefano/ubuntu-docviewer-app/30-reboot-contenthub-dont-import-if-already-imported into lp:ubuntu-docviewer-app/reboot
Stefano Verzegnassi has proposed merging lp:~verzegnassi-stefano/ubuntu-docviewer-app/30-reboot-contenthub-dont-import-if-already-imported into lp:ubuntu-docviewer-app/reboot with lp:~verzegnassi-stefano/ubuntu-docviewer-app/10-reboot-contenthub-switch-to-qml-apis as a prerequisite.
Commit message:
[ContentHub] Check if a file has been already imported in the past, and don't import it if that's the case
Requested reviews:
Ubuntu Document Viewer Developers (ubuntu-docviewer-dev)
Related bugs:
Bug #1432394 in Ubuntu Document Viewer App: "[content-hub] Do not create new copy of a document, if it already exists in $HOME/Documents"
https://bugs.launchpad.net/ubuntu-docviewer-app/+bug/1432394
For more details, see:
https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/30-reboot-contenthub-dont-import-if-already-imported/+merge/271468
[ContentHub] Check if a file has been already imported in the past, and don't import it if that's the case
--
Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~verzegnassi-stefano/ubuntu-docviewer-app/30-reboot-contenthub-dont-import-if-already-imported into lp:ubuntu-docviewer-app/reboot.
=== modified file 'src/app/qml/common/ContentHubProxy.qml'
--- src/app/qml/common/ContentHubProxy.qml 2015-09-19 11:56:00 +0000
+++ src/app/qml/common/ContentHubProxy.qml 2015-09-19 11:56:00 +0000
@@ -53,10 +53,20 @@
if (DocumentViewer.isFileSupported(sourcePath)) {
var documentsLocation = DocumentViewer.getXdgDocumentsLocation()
- var destPath = DocumentViewer.buildDestinationPath(documentsLocation, sourcePath);
-
- internal.importDocument(sourcePath, destPath)
-
+
+ // Check if we have already imported the same document in the past.
+ var earlierImportedFile = DocumentViewer.checkIfFileAlreadyImported(sourcePath, [documentsLocation])
+ if (earlierImportedFile.length > 0) {
+ // Document has been already imported in the past.
+ // Append the path of the earlier copy of the
+ // document in our model, so we can open it instead.
+ importedDocsModel.append({ path: earlierImportedFile })
+ } else {
+ // No document has been found, so we can safely copy it.
+ var destPath = DocumentViewer.buildDestinationPath(documentsLocation, sourcePath);
+
+ internal.importDocument(sourcePath, destPath)
+ }
} else {
// Document is not supported, append its entry into the
// rejected documents model, so that we can inform the
=== modified file 'src/plugin/file-qml-plugin/documentviewersingleton.cpp'
--- src/plugin/file-qml-plugin/documentviewersingleton.cpp 2015-09-19 11:56:00 +0000
+++ src/plugin/file-qml-plugin/documentviewersingleton.cpp 2015-09-19 11:56:00 +0000
@@ -20,6 +20,8 @@
#include <QDir>
#include <QMimeDatabase>
#include <QStandardPaths>
+#include <QDirIterator>
+#include <QDateTime>
bool DocumentViewerSingleton::exists(const QString &path)
{
@@ -119,3 +121,39 @@
return destination;
}
+
+// Return the path of the file, if found in the storageLocation paths,
+// otherwise return an empty string.
+// Used for prevent importing of a second copy of a file through ContentHub.
+QString DocumentViewerSingleton::checkIfFileAlreadyImported(const QString &filePath, const QStringList &storageLocationList)
+{
+ QFileInfo fi(filePath);
+ QStringList files;
+
+ // Get the list of all the files in the watched folders
+ Q_FOREACH(const QString &storageLocation, storageLocationList) {
+ QDirIterator dir(storageLocation, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
+ QDirIterator::Subdirectories);
+
+ while (dir.hasNext())
+ {
+ dir.next();
+ files.append(dir.filePath());
+ }
+ }
+
+ // Check if there's a file with the same name in the list
+ Q_FOREACH(const QString &file, files) {
+ if (file.endsWith(fi.fileName())) {
+ // Seems there could be already the same file in the watched
+ // folders. Check also size and lastModified date.
+ QFileInfo fileToCheck(file);
+
+ if (fi.size() == fileToCheck.size() &&
+ fi.lastModified() == fileToCheck.lastModified())
+ return file;
+ }
+ }
+
+ return QString();
+}
=== modified file 'src/plugin/file-qml-plugin/documentviewersingleton.h'
--- src/plugin/file-qml-plugin/documentviewersingleton.h 2015-09-19 11:56:00 +0000
+++ src/plugin/file-qml-plugin/documentviewersingleton.h 2015-09-19 11:56:00 +0000
@@ -32,6 +32,8 @@
Q_INVOKABLE static QString getXdgDocumentsLocation();
Q_INVOKABLE static QString buildDestinationPath(const QString &destinationDir, const QString &sourcePath);
+
+ Q_INVOKABLE static QString checkIfFileAlreadyImported(const QString &filePath, const QStringList &storageLocationList);
};
#endif // DOCUMENTVIEWERSINGLETON_H
Follow ups