forked from blue/squawk
first thoughts about downloads path changing
This commit is contained in:
parent
da19eb86bb
commit
243edff8bd
11 changed files with 122 additions and 10 deletions
|
@ -32,3 +32,4 @@ target_include_directories(squawk PRIVATE ${LMDB_INCLUDE_DIRS})
|
|||
|
||||
add_subdirectory(handlers)
|
||||
add_subdirectory(passwordStorageEngines)
|
||||
add_subdirectory(utils)
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "../ui/squawk.h"
|
||||
#include "signalcatcher.h"
|
||||
#include "squawk.h"
|
||||
#include "utils/pathcheck.h"
|
||||
|
||||
#include <QLibraryInfo>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
@ -28,6 +30,7 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QDir>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -106,7 +109,13 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString path = Utils::downloadsPathCheck();
|
||||
if (path.size() > 0) {
|
||||
settings.setValue("downloadsPath", path);
|
||||
} else {
|
||||
qDebug() << "couldn't initialize directory for downloads, quitting";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Squawk w;
|
||||
|
|
|
@ -28,8 +28,11 @@ Core::NetworkAccess::NetworkAccess(QObject* parent):
|
|||
manager(0),
|
||||
storage("fileURLStorage"),
|
||||
downloads(),
|
||||
uploads()
|
||||
uploads(),
|
||||
currentPath()
|
||||
{
|
||||
QSettings settings;
|
||||
currentPath = settings.value("downloadsPath").toString();
|
||||
}
|
||||
|
||||
Core::NetworkAccess::~NetworkAccess()
|
||||
|
@ -515,8 +518,7 @@ bool Core::NetworkAccess::checkAndAddToUploading(const QString& acc, const QStri
|
|||
|
||||
QString Core::NetworkAccess::prepareDirectory(const QString& jid)
|
||||
{
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
path += "/" + QApplication::applicationName();
|
||||
QString path = currentPath;
|
||||
if (jid.size() > 0) {
|
||||
path += "/" + jid;
|
||||
}
|
||||
|
@ -563,3 +565,8 @@ std::list<Shared::MessageInfo> Core::NetworkAccess::reportPathInvalid(const QStr
|
|||
{
|
||||
return storage.deletedFile(path);
|
||||
}
|
||||
|
||||
void Core::NetworkAccess::moveFilesDirectory(const QString& newPath)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
|
||||
#include <set>
|
||||
|
||||
|
@ -65,6 +66,7 @@ public slots:
|
|||
void downladFile(const QString& url);
|
||||
void registerFile(const QString& url, const QString& account, const QString& jid, const QString& id);
|
||||
void registerFile(const QString& url, const QString& path, const QString& account, const QString& jid, const QString& id);
|
||||
void moveFilesDirectory(const QString& newPath);
|
||||
|
||||
private:
|
||||
void startDownload(const std::list<Shared::MessageInfo>& msgs, const QString& url);
|
||||
|
@ -87,6 +89,7 @@ private:
|
|||
UrlStorage storage;
|
||||
std::map<QString, Transfer*> downloads;
|
||||
std::map<QString, Transfer*> uploads;
|
||||
QString currentPath;
|
||||
|
||||
struct Transfer {
|
||||
std::list<Shared::MessageInfo> messages;
|
||||
|
|
4
core/utils/CMakeLists.txt
Normal file
4
core/utils/CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
target_sources(squawk PRIVATE
|
||||
pathcheck.h
|
||||
pathcheck.cpp
|
||||
)
|
47
core/utils/pathcheck.cpp
Normal file
47
core/utils/pathcheck.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "pathcheck.h"
|
||||
|
||||
QString Utils::downloadsPathCheck()
|
||||
{
|
||||
QSettings settings;
|
||||
QVariant dpv = settings.value("downloadsPath");
|
||||
QString path;
|
||||
if (!dpv.isValid()) {
|
||||
path = defaultDownloadsPath();
|
||||
qDebug() << "no downloadsPath variable in config, using default" << path;
|
||||
path = getCanonicalWritablePath(path);
|
||||
return path;
|
||||
} else {
|
||||
path = dpv.toString();
|
||||
path = getCanonicalWritablePath(path);
|
||||
if (path.size() == 0) {
|
||||
path = defaultDownloadsPath();
|
||||
qDebug() << "falling back to the default downloads path" << path;
|
||||
path = getCanonicalWritablePath(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
QString Utils::defaultDownloadsPath()
|
||||
{
|
||||
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + QApplication::applicationName();
|
||||
}
|
||||
|
||||
QString Utils::getCanonicalWritablePath(const QString& path)
|
||||
{
|
||||
QDir location(path);
|
||||
if (!location.exists()) {
|
||||
bool res = location.mkpath(location.canonicalPath());
|
||||
if (!res) {
|
||||
qDebug() << "couldn't create directory" << path;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
QFileInfo info(location.canonicalPath());
|
||||
if (info.isWritable()) {
|
||||
return location.canonicalPath();
|
||||
} else {
|
||||
qDebug() << "directory" << path << "is not writable";
|
||||
return "";
|
||||
}
|
||||
}
|
21
core/utils/pathcheck.h
Normal file
21
core/utils/pathcheck.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef PATHCHECK_H
|
||||
#define PATHCHECK_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
QString downloadsPathCheck();
|
||||
QString defaultDownloadsPath();
|
||||
|
||||
QString getCanonicalWritablePath(const QString& path);
|
||||
|
||||
}
|
||||
|
||||
#endif // PATHCHECK_H
|
Loading…
Add table
Add a link
Reference in a new issue