Skip to content

Commit 85e61ce

Browse files
committed
implement copy to custom location
1 parent b5cdf4b commit 85e61ce

5 files changed

Lines changed: 58 additions & 19 deletions

File tree

qml/FileCopyProgress.qml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ FileCopyProgressForm {
55
standardButtons: Dialog.Cancel
66
id: copyFileDialog
77
closePolicy: Popup.CloseOnEscape
8+
property string targetPath : ""
89

910
Connections
1011
{
@@ -20,7 +21,7 @@ FileCopyProgressForm {
2021

2122
onOpened:
2223
{
23-
filesystem.startCopyFilesToRemovableDrive()
24+
filesystem.startCopyFilesToPath(targetPath)
2425
}
2526

2627
function updateProgress(progress)
@@ -33,9 +34,4 @@ FileCopyProgressForm {
3334
console.log("Cancel copy")
3435
filesystem.abortCopy()
3536
}
36-
37-
onClosed:
38-
{
39-
filesystem.unmountRemoveableDrive()
40-
}
4137
}

qml/SettingsMenu.qml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,35 @@ SettingsMenuForm {
115115
}
116116
}
117117

118+
CustomFolderDialog
119+
{
120+
id: pictureCopyFolderDialog
121+
title: qsTr("Select Copy Pictures Folder")
122+
anchors.centerIn: parent
123+
width: parent.width - 100
124+
height: parent.height - 100
125+
126+
onAccepted: function()
127+
{
128+
console.log("Selected copy folder: " + pictureCopyFolderDialog.currentFolder)
129+
copyProgressPopup.targetPath = pictureCopyFolderDialog.currentFolder
130+
copyProgressPopup.open()
131+
}
132+
}
133+
118134
buttonSelectPhotoDirectory.onClicked:
119135
{
120136
pictureFolderDialog.currentFolder = applicationSettings.foldername
121137
console.log("selecting pictures folder: " + pictureFolderDialog.currentFolder)
122138
pictureFolderDialog.open()
123139
}
124140

141+
buttonCopyPhotosCustomLocation.onClicked:
142+
{
143+
pictureCopyFolderDialog.currentFolder = StandardPaths.writableLocation(StandardPaths.HomeLocation)
144+
pictureCopyFolderDialog.open()
145+
}
146+
125147
buttonClose.onClicked:
126148
{
127149
exitSettings()
@@ -139,6 +161,7 @@ SettingsMenuForm {
139161

140162
buttonCopyPhotos.onClicked:
141163
{
164+
copyProgressPopup.targetPath = filesystem.getRemovableDrivePath()
142165
copyProgressPopup.open()
143166
}
144167

qml/SettingsMenuForm.ui.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Item {
2121
property alias switchPrinter: switchPrinter
2222
property alias switchPrintFromGallery: switchPrintFromGallery
2323
property alias buttonCopyPhotos: buttonCopyPhotos
24+
property alias buttonCopyPhotosCustomLocation: buttonCopyPhotosCustomLocation
2425
property alias switchMirrorCamera: switchMirrorCamera
2526
property alias comboBoxPrinter: comboBoxPrinter
2627
property alias comboBoxCamera: comboBoxCamera
@@ -117,6 +118,16 @@ Item {
117118
text: qsTr("Copy photos to removable disk")
118119
}
119120

121+
Button {
122+
id: buttonCopyPhotosCustomLocation
123+
text: qsTr("Copy photos to custom location")
124+
}
125+
126+
ToolSeparator {
127+
Layout.fillWidth: true
128+
orientation: Qt.Horizontal
129+
}
130+
120131
DelayButton {
121132
id: buttonDeletePhotos
122133
text: qsTr("Delete all photos")

src/filesystem.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,23 @@ void FileSystem::unmountRemoveableDrive()
144144
unmountProcess.waitForFinished();
145145
}
146146

147-
void FileSystem::startCopyFilesToRemovableDrive()
147+
void FileSystem::startCopyFilesToPath(const QString &path)
148148
{
149149
QString imagePath = this->getImagePath();
150150
imagePath = imagePath.right(imagePath.length() - QString("file://").length());
151-
QString removableDrivePath = this->getRemovableDrivePath();
152-
qDebug() << "Try to copy all images to removable drive";
153151

154-
if(removableDrivePath.length())
152+
QString copyPath;
153+
if (path.startsWith("file://", Qt::CaseInsensitive))
154+
{
155+
QUrl url(path);
156+
copyPath = QUrl(path).toLocalFile();
157+
}
158+
else
159+
{
160+
copyPath = path;
161+
}
162+
163+
if(copyPath.length())
155164
{
156165
QDir imageDir(imagePath);
157166
QStringList filters;
@@ -161,7 +170,7 @@ void FileSystem::startCopyFilesToRemovableDrive()
161170
if(!imageDir.isEmpty() && imageDir.exists())
162171
{
163172
qDebug() << "Image folder not empty and found removable disc. Copying...";
164-
m_copyFuture = QtConcurrent::run([removableDrivePath,imagePath, this]() {
173+
m_copyFuture = QtConcurrent::run([copyPath,imagePath, this]() {
165174
QDir imageDir(imagePath);
166175
QStringList filters;
167176
filters << "*.jpg" << "*.JPG";
@@ -174,13 +183,13 @@ void FileSystem::startCopyFilesToRemovableDrive()
174183
for(i = 0; i < files.count() && !this->m_copyFuture.isCanceled(); i++)
175184
{
176185
int progress = (100 * i + 1) / files.count();
177-
qDebug() << "Copy file: " << imagePath + "/" + files[i] << " to: " << removableDrivePath + "/" + files[i] << " Progress: " << progress;
178-
if(QFile::exists(removableDrivePath + "/" + files[i]))
179-
QFile::remove(removableDrivePath + "/" + files[i]);
186+
qDebug() << "Copy file: " << imagePath + "/" + files[i] << " to: " << copyPath + "/" + files[i] << " Progress: " << progress;
187+
if(QFile::exists(copyPath + "/" + files[i]))
188+
QFile::remove(copyPath + "/" + files[i]);
180189

181-
if(!QFile::copy(imagePath + "/" + files[i], removableDrivePath + "/" + files[i]))
190+
if(!QFile::copy(imagePath + "/" + files[i], copyPath + "/" + files[i]))
182191
{
183-
if(!QFile::copy(imagePath + "/collage/" + files[i], removableDrivePath + "/" + files[i]))
192+
if(!QFile::copy(imagePath + "/collage/" + files[i], copyPath + "/" + files[i]))
184193
{
185194
qDebug() << "Copying file: " << files[i] << " was not successfull";
186195
}
@@ -211,7 +220,7 @@ void FileSystem::startCopyFilesToRemovableDrive()
211220
QString FileSystem::getRemovableDrivePath()
212221
{
213222
static QRegularExpression regexDrive("\\/dev\\/sd*");
214-
static QRegularExpression regexBoot("\\/boot");
223+
static QRegularExpression regexBoot("^/(boot|home|tmp)?$");
215224
QList<QStorageInfo> drives = QStorageInfo::mountedVolumes();
216225
for(int i = 0; i < drives.count(); i++)
217226
{

src/filesystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class FileSystem : public QObject
1616
Q_INVOKABLE void checkImageFolders();
1717
Q_INVOKABLE bool removableDriveMounted();
1818
Q_INVOKABLE void unmountRemoveableDrive();
19-
Q_INVOKABLE void startCopyFilesToRemovableDrive();
19+
Q_INVOKABLE void startCopyFilesToPath(const QString &path);
2020
Q_INVOKABLE void abortCopy();
2121
Q_INVOKABLE void deleteAllImages();
2222
Q_INVOKABLE bool layoutFilesOnRemovableDrive();
2323
Q_INVOKABLE void copyLayoutFiles();
2424
Q_INVOKABLE QSize getImageSize(QString filename);
25+
Q_INVOKABLE QString getRemovableDrivePath();
2526
protected:
26-
QString getRemovableDrivePath();
2727
QFuture<void> m_copyFuture;
2828
signals:
2929
void copyProgress(int progress);

0 commit comments

Comments
 (0)