Commit 1bb5cd8d authored by Karel Slaný's avatar Karel Slaný

Renamed some functions in order to make their behaviour more clear.

parent dbdfcda0
......@@ -188,7 +188,7 @@ void Files::openAttachment(const QString &fileName,
return;
}
QString filePath(writeFile(datovkaTmpFolderPath(), fileName,
QString filePath(writeFile(appTmpDirPath(), fileName,
base64ToRaw(base64Data)));
if (!filePath.isEmpty()) {
......@@ -285,8 +285,8 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
deleteAllFromFolder(DATOVKA_MAIL_DIR_NAME);
QString targetPath(datovkaEmailFolderPath(QString::number(msgId)));
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
QString targetPath(appEmailDirPath(QString::number(msgId)));
foreach (const FileDb::FileData &file, filelist) {
QString fileName = file.filename;
......@@ -528,8 +528,8 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
deleteAllFromFolder(DATOVKA_MAIL_DIR_NAME);
QString targetPath(datovkaEmailFolderPath(msgIdStr));
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
QString targetPath(appEmailDirPath(msgIdStr));
for (int row = 0; row < attachModel->rowCount(); ++row) {
QModelIndex idx(attachModel->index(row));
......@@ -593,7 +593,7 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
return;
}
QString filePath(datovkaMessageFolderPath(msgIdStr));
QString filePath(appMsgAttachDirPath(msgIdStr));
QString destPath;
foreach (const FileDb::FileData &file, filelist) {
......@@ -617,7 +617,7 @@ void Files::saveAttachmentsToDiskZfo(const QVariant &attachModelVariant,
return;
}
QString targetPath(datovkaMessageFolderPath(msgIdStr));
QString targetPath(appMsgAttachDirPath(msgIdStr));
QString destPath;
for (int row = 0; row < attachModel->rowCount(); ++row) {
......@@ -663,7 +663,7 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
#else
QString tmpEmailFile = writeFile(
datovkaEmailFolderPath(QString::number(msgId)),
appEmailDirPath(QString::number(msgId)),
QString::number(msgId) + "_mail.eml", emailMessage.toUtf8());
QDesktopServices::openUrl(QUrl::fromLocalFile(tmpEmailFile));
......
......@@ -21,7 +21,6 @@
* the two.
*/
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QRegExp>
......@@ -39,39 +38,39 @@
*/
#define ILL_FNAME_REP "_"
QString datovkaBaseFolderPath(void)
QString appAttachDirPath(void)
{
return getDefaultAttachmentSaveLocation() + QDir::separator() +
QString(DATOVKA_BASE_DIR_NAME);
QLatin1String(DATOVKA_BASE_DIR_NAME);
}
QString datovkaCertificateFolderPath(void)
QString appCertDirPath(void)
{
return setDatovkaPath(getDefaultAttachmentSaveLocation(),
DATOVKA_CERT_DIR_NAME);
}
QString datovkaEmailFolderPath(const QString &msgIdStr)
QString appEmailDirPath(const QString &msgIdStr)
{
return setDatovkaPath(getDefaultAttachmentSaveLocation(),
QString(DATOVKA_MAIL_DIR_NAME) + QDir::separator() + msgIdStr);
}
QString datovkaMessageFolderPath(const QString &msgIdStr)
QString appMsgAttachDirPath(const QString &msgIdStr)
{
return setDatovkaPath(getDefaultAttachmentSaveLocation(), msgIdStr);
}
QString datovkaTmpFolderPath(void)
QString appTmpDirPath(void)
{
return setDatovkaPath(getDefaultAttachmentSaveLocation(),
DATOVKA_TEMP_DIR_NAME);
}
void deleteAllFromFolder(const QString &folderName)
void removeDirFromDocLoc(const QString &dirName)
{
QString folderPath =
setDatovkaPath(getDefaultAttachmentSaveLocation(), folderName);
QString folderPath(
setDatovkaPath(getDefaultAttachmentSaveLocation(), dirName));
if (folderPath.isEmpty()) {
return;
......@@ -122,24 +121,23 @@ QString getDefaultDbAndConfigLocation(void)
return existingWritableLocation(QStandardPaths::AppDataLocation);
}
QStringList getZfoFilesFromDir(const QString &importDir, bool includeSubDir)
QStringList zfoFilesFromDir(const QString &dirPath, bool subdirs)
{
QStringList filters("*.zfo");
QStringList fileList, filePathList;
QDir directory(QDir::home());
if (includeSubDir) {
QDirIterator it(importDir, filters, QDir::Files,
if (subdirs) {
QDirIterator it(dirPath, filters, QDir::Files,
QDirIterator::Subdirectories);
while (it.hasNext()) {
filePathList.append(it.next());
}
} else {
directory.setPath(importDir);
directory.setPath(dirPath);
fileList = directory.entryList(filters);
foreach (const QString &file, fileList) {
filePathList.append(importDir +
QDir::separator() + file);
filePathList.append(dirPath + QDir::separator() + file);
}
}
......@@ -176,8 +174,8 @@ QString nonconflictingFileName(QString filePath)
QString setDatovkaPath(const QString &basePath, const QString &folderName)
{
QString newPath = basePath;
QString destPath(QString(DATOVKA_BASE_DIR_NAME) + QDir::separator()
+ folderName);
QString destPath(QLatin1String(DATOVKA_BASE_DIR_NAME) +
QDir::separator() + folderName);
QDir dir(basePath);
if (dir.mkpath(destPath)) {
newPath = basePath + QDir::separator() + destPath;
......@@ -185,7 +183,7 @@ QString setDatovkaPath(const QString &basePath, const QString &folderName)
}
if (!dir.exists()) {
qCritical() << "Loaction for file could not be created.";
qCritical("%s", "Location for file could not be created.");
return QString();
}
......@@ -202,7 +200,7 @@ QString writeFile(const QString &filePath, const QString &fileName,
QFile fout(nonconflictingFileName(filePath + QDir::separator()
+ nameCopy));
if (!fout.open(QIODevice::WriteOnly)) {
qCritical() << "Cant open file " << nameCopy;
qCritical("Cannot open file '%s'.", nameCopy.toUtf8().constData());
return QString();
}
......
......@@ -27,7 +27,7 @@
#include <QString>
/*!
* @brief Datovka file store folder names.
* @brief Datovka file store directory names.
*/
#define DATOVKA_BASE_DIR_NAME "Datovka"
#define DATOVKA_CERT_DIR_NAME "Certs"
......@@ -35,48 +35,51 @@
#define DATOVKA_TEMP_DIR_NAME "Temp"
/*!
* @brief Return base Datovka folder path.
* @brief Return path to location where the application stores the attachments.
*
* @return Full path to location where Datovka can store attachments.
* @return Full path.
*/
QString datovkaBaseFolderPath(void);
QString appAttachDirPath(void);
/*!
* @brief Return path to Datovka certificate folder.
* @brief Return path to location where the application stores certificates.
*
* @return Full path to location where certificates can be stored.
* @return Full path.
*/
QString datovkaCertificateFolderPath(void);
QString appCertDirPath(void);
/*!
* @brief Return path to Datovka email folder.
* @brief Return path to location where email content (attachments) can be
* stored.
*
* @param[in] msgIdStr Message ID string.
* @return Full path to location where files for email can be stored.
* @param[in] msgIdStr String containing message identifier.
* @return Full path containing the supplied identifier.
*/
QString datovkaEmailFolderPath(const QString &msgIdStr);
QString appEmailDirPath(const QString &msgIdStr);
/*!
* @brief Return path for attachment saving.
* @brief Return path to location where attachments of a particular message
* can be stored.
*
* @param[in] msgIdStr Message ID string.
* @return Full path to location where attachment files can be stored.
* @param[in] msgIdStr String containing message identifier.
* @return Full path containing the supplied identifier.
*/
QString datovkaMessageFolderPath(const QString &msgIdStr);
QString appMsgAttachDirPath(const QString &msgIdStr);
/*!
* @brief Return path for Datovka tmp folder.
* @brief Return path to location where temporary files can be stored.
*
* @return Full path to location where apliaction temporary files can be stored.
* @return Full path to temporary folder.
*/
QString datovkaTmpFolderPath(void);
QString appTmpDirPath(void);
/*!
* @brief Delete all files and subdirs from specific folder.
* @brief Remove directory from application document storage including its
* content.
*
* @param[in] folderName Folder name.
* @param[in] dirName Directory name.
*/
void deleteAllFromFolder(const QString &folderName);
void removeDirFromDocLoc(const QString &dirName);
/*!
* @brief Returns name of existing directory to store data to.
......@@ -101,13 +104,15 @@ QString getDefaultAttachmentSaveLocation(void);
QString getDefaultDbAndConfigLocation(void);
/*!
* @brief Get paths of ZFO files from selected folder.
* @brief Get full paths of ZFO files in supplied directory.
*
* @note Does Not follow symbolic links.
*
* @param[in] importDir Import source directory path.
* @param[in] includeSubDir Include subdirectories.
* @return List of full path to ZFO files.
* @param[in] dirPath Directory path.
* @param[in] subdirs Include subdirectories.
* @return List of full paths of found zfo files.
*/
QStringList getZfoFilesFromDir(const QString &importDir, bool includeSubDir);
QStringList zfoFilesFromDir(const QString &dirPath, bool subdirs);
/*!
* @brief Check if file with given path exists.
......@@ -118,11 +123,13 @@ QStringList getZfoFilesFromDir(const QString &importDir, bool includeSubDir);
QString nonconflictingFileName(QString filePath);
/*!
* @brief Set file destination path and dir.
* @brief Return path to directory in supplied base path. Create directory if it
* does not exist.
*
* @param[in] basePath Base path based on the platform.
* @param[in] folderName Target folder name.
* @return Full path to new location.
* @param[in] basePath Base path.
* @param[in] dirName Directory name.
* @return Full path to directory in supplied base path if directory exists or
* it could be created. Empty sting otherwise.
*/
QString setDatovkaPath(const QString &basePath, const QString &folderName);
......
......@@ -137,7 +137,7 @@ QString IsdsWrapper::importZfoMessages(const QString &userName,
QStringList filePathList = fileList;
if (1 == fileList.count()) {
if (!QFileInfo(fileList.at(0)).isFile()) {
filePathList = getZfoFilesFromDir(fileList.at(0), true);
filePathList = zfoFilesFromDir(fileList.at(0), true);
if (filePathList.isEmpty()) {
return tr("No zfo files in the selected directory.");
}
......
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