diff --git a/qml/FileCopyProgress.qml b/qml/FileCopyProgress.qml index e1155ba6..3b93ae9e 100644 --- a/qml/FileCopyProgress.qml +++ b/qml/FileCopyProgress.qml @@ -5,6 +5,7 @@ FileCopyProgressForm { standardButtons: Dialog.Cancel id: copyFileDialog closePolicy: Popup.CloseOnEscape + property string targetPath : "" Connections { @@ -20,7 +21,7 @@ FileCopyProgressForm { onOpened: { - filesystem.startCopyFilesToRemovableDrive() + filesystem.startCopyFilesToPath(targetPath) } function updateProgress(progress) @@ -33,9 +34,4 @@ FileCopyProgressForm { console.log("Cancel copy") filesystem.abortCopy() } - - onClosed: - { - filesystem.unmountRemoveableDrive() - } } diff --git a/qml/SettingsMenu.qml b/qml/SettingsMenu.qml index 2e0c0b16..73974e77 100644 --- a/qml/SettingsMenu.qml +++ b/qml/SettingsMenu.qml @@ -115,6 +115,22 @@ SettingsMenuForm { } } + CustomFolderDialog + { + id: pictureCopyFolderDialog + title: qsTr("Select Copy Pictures Folder") + anchors.centerIn: parent + width: parent.width - 100 + height: parent.height - 100 + + onAccepted: function() + { + console.log("Selected copy folder: " + pictureCopyFolderDialog.currentFolder) + copyProgressPopup.targetPath = pictureCopyFolderDialog.currentFolder + copyProgressPopup.open() + } + } + buttonSelectPhotoDirectory.onClicked: { pictureFolderDialog.currentFolder = applicationSettings.foldername @@ -122,6 +138,12 @@ SettingsMenuForm { pictureFolderDialog.open() } + buttonCopyPhotosCustomLocation.onClicked: + { + pictureCopyFolderDialog.currentFolder = StandardPaths.writableLocation(StandardPaths.HomeLocation) + pictureCopyFolderDialog.open() + } + buttonClose.onClicked: { exitSettings() @@ -139,6 +161,7 @@ SettingsMenuForm { buttonCopyPhotos.onClicked: { + copyProgressPopup.targetPath = filesystem.getRemovableDrivePath() copyProgressPopup.open() } diff --git a/qml/SettingsMenuForm.ui.qml b/qml/SettingsMenuForm.ui.qml index 5f1fa9e3..fba36c09 100644 --- a/qml/SettingsMenuForm.ui.qml +++ b/qml/SettingsMenuForm.ui.qml @@ -21,6 +21,7 @@ Item { property alias switchPrinter: switchPrinter property alias switchPrintFromGallery: switchPrintFromGallery property alias buttonCopyPhotos: buttonCopyPhotos + property alias buttonCopyPhotosCustomLocation: buttonCopyPhotosCustomLocation property alias switchMirrorCamera: switchMirrorCamera property alias comboBoxPrinter: comboBoxPrinter property alias comboBoxCamera: comboBoxCamera @@ -117,6 +118,16 @@ Item { text: qsTr("Copy photos to removable disk") } + Button { + id: buttonCopyPhotosCustomLocation + text: qsTr("Copy photos to custom location") + } + + ToolSeparator { + Layout.fillWidth: true + orientation: Qt.Horizontal + } + DelayButton { id: buttonDeletePhotos text: qsTr("Delete all photos") diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 6c713bae..2c24c419 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -144,14 +144,23 @@ void FileSystem::unmountRemoveableDrive() unmountProcess.waitForFinished(); } -void FileSystem::startCopyFilesToRemovableDrive() +void FileSystem::startCopyFilesToPath(const QString &path) { QString imagePath = this->getImagePath(); imagePath = imagePath.right(imagePath.length() - QString("file://").length()); - QString removableDrivePath = this->getRemovableDrivePath(); - qDebug() << "Try to copy all images to removable drive"; - if(removableDrivePath.length()) + QString copyPath; + if (path.startsWith("file://", Qt::CaseInsensitive)) + { + QUrl url(path); + copyPath = QUrl(path).toLocalFile(); + } + else + { + copyPath = path; + } + + if(copyPath.length()) { QDir imageDir(imagePath); QStringList filters; @@ -161,7 +170,7 @@ void FileSystem::startCopyFilesToRemovableDrive() if(!imageDir.isEmpty() && imageDir.exists()) { qDebug() << "Image folder not empty and found removable disc. Copying..."; - m_copyFuture = QtConcurrent::run([removableDrivePath,imagePath, this]() { + m_copyFuture = QtConcurrent::run([copyPath,imagePath, this]() { QDir imageDir(imagePath); QStringList filters; filters << "*.jpg" << "*.JPG"; @@ -174,13 +183,13 @@ void FileSystem::startCopyFilesToRemovableDrive() for(i = 0; i < files.count() && !this->m_copyFuture.isCanceled(); i++) { int progress = (100 * i + 1) / files.count(); - qDebug() << "Copy file: " << imagePath + "/" + files[i] << " to: " << removableDrivePath + "/" + files[i] << " Progress: " << progress; - if(QFile::exists(removableDrivePath + "/" + files[i])) - QFile::remove(removableDrivePath + "/" + files[i]); + qDebug() << "Copy file: " << imagePath + "/" + files[i] << " to: " << copyPath + "/" + files[i] << " Progress: " << progress; + if(QFile::exists(copyPath + "/" + files[i])) + QFile::remove(copyPath + "/" + files[i]); - if(!QFile::copy(imagePath + "/" + files[i], removableDrivePath + "/" + files[i])) + if(!QFile::copy(imagePath + "/" + files[i], copyPath + "/" + files[i])) { - if(!QFile::copy(imagePath + "/collage/" + files[i], removableDrivePath + "/" + files[i])) + if(!QFile::copy(imagePath + "/collage/" + files[i], copyPath + "/" + files[i])) { qDebug() << "Copying file: " << files[i] << " was not successfull"; } @@ -211,7 +220,7 @@ void FileSystem::startCopyFilesToRemovableDrive() QString FileSystem::getRemovableDrivePath() { static QRegularExpression regexDrive("\\/dev\\/sd*"); - static QRegularExpression regexBoot("\\/boot"); + static QRegularExpression regexBoot("^/(boot|home|tmp)?$"); QList drives = QStorageInfo::mountedVolumes(); for(int i = 0; i < drives.count(); i++) { diff --git a/src/filesystem.h b/src/filesystem.h index a892f1f3..2fc96b70 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -16,14 +16,14 @@ class FileSystem : public QObject Q_INVOKABLE void checkImageFolders(); Q_INVOKABLE bool removableDriveMounted(); Q_INVOKABLE void unmountRemoveableDrive(); - Q_INVOKABLE void startCopyFilesToRemovableDrive(); + Q_INVOKABLE void startCopyFilesToPath(const QString &path); Q_INVOKABLE void abortCopy(); Q_INVOKABLE void deleteAllImages(); Q_INVOKABLE bool layoutFilesOnRemovableDrive(); Q_INVOKABLE void copyLayoutFiles(); Q_INVOKABLE QSize getImageSize(QString filename); + Q_INVOKABLE QString getRemovableDrivePath(); protected: - QString getRemovableDrivePath(); QFuture m_copyFuture; signals: void copyProgress(int progress);