Commit 31b396b5 authored by Martin Straka's avatar Martin Straka

Select target folder for attachment saving (issue #22)

parent 33b0d751
......@@ -365,9 +365,14 @@ void Files::saveAttachmentsToDisk(const QString &userName, qint64 msgId)
return;
}
QString path = QFileDialog::getExistingDirectory(0,
tr("Select Directory"),
getBasePathBasedOnPlatform(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
foreach (const FileDb::FileData &file, filelist) {
QByteArray data = QByteArray::fromBase64(file.content.toUtf8());
writeFileToDir(file.filename, msgId, data);
writeFileToDir(path, file.filename, msgId, data);
}
}
......
......@@ -222,23 +222,17 @@ QString writeTemporaryFile(const QString &fileName, const QByteArray &data,
}
QString writeFileToDir(const QString &fileName, qint64 msgId,
const QByteArray &data, bool deleteOnError)
QString writeFileToDir(const QString &basePath, const QString &fileName,
qint64 msgId, const QByteArray &data, bool deleteOnError)
{
if (fileName.isEmpty()) {
Q_ASSERT(0);
return QString();
}
Q_UNUSED(msgId);
QString basePath = getBasePathBasedOnPlatform();
QString filePath = setFilePath(basePath, QString::number(msgId));
if (filePath.isEmpty()) {
qDebug() << "No location to write file to.";
if (fileName.isEmpty() || basePath.isEmpty()) {
Q_ASSERT(0);
return QString();
}
return writeFile(filePath, fileName, data, deleteOnError);
return writeFile(basePath, fileName, data, deleteOnError);
}
......
......@@ -101,6 +101,7 @@ QString writeTemporaryFile(const QString &fileName,
/*!
* @brief Create and write data to specific dir.
*
* @param[in] basePath Path to target folder.
* @param[in] fileName File name.
* @param[in] msgId Message ID.
* @param[in] data Data to be written into file.
......@@ -108,8 +109,8 @@ QString writeTemporaryFile(const QString &fileName,
* written.
* @return Full path to written file on success, empty string on failure.
*/
QString writeFileToDir(const QString &fileName, qint64 msgId,
const QByteArray &data, bool deleteOnError = false);
QString writeFileToDir(const QString &basePath, const QString &fileName,
qint64 msgId, const QByteArray &data, bool deleteOnError = false);
/*!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment