Downloads folder now is movable

This commit is contained in:
Blue 2022-02-19 21:31:49 +03:00
parent d8b5ccb2da
commit 73b1b58a96
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
16 changed files with 141 additions and 12 deletions

View file

@ -304,7 +304,11 @@ void Core::MessageHandler::performSending(Shared::Message data, bool newMessage)
//so, the final path changes. Let's assume it changes always since it costs me close to nothing
QString attachPath = data.getAttachPath();
if (attachPath.size() > 0) {
changes.insert("attachPath", attachPath);
QString squawkified = Shared::squawkifyPath(attachPath);
changes.insert("attachPath", squawkified);
if (attachPath != squawkified) {
data.setAttachPath(squawkified);
}
}
if (ri != 0) {

View file

@ -29,6 +29,7 @@
#include <shared/message.h>
#include <shared/messageinfo.h>
#include <shared/pathcheck.h>
namespace Core {

View file

@ -160,6 +160,7 @@ int main(int argc, char *argv[])
QObject::connect(&w, &Squawk::uploadVCard, squawk, &Core::Squawk::uploadVCard);
QObject::connect(&w, &Squawk::responsePassword, squawk, &Core::Squawk::responsePassword);
QObject::connect(&w, &Squawk::localPathInvalid, squawk, &Core::Squawk::onLocalPathInvalid);
QObject::connect(&w, &Squawk::changeDownloadsPath, squawk, &Core::Squawk::changeDownloadsPath);
QObject::connect(squawk, &Core::Squawk::newAccount, &w, &Squawk::newAccount);
QObject::connect(squawk, &Core::Squawk::addContact, &w, &Squawk::addContact);

View file

@ -438,10 +438,10 @@ void Core::NetworkAccess::onUploadProgress(qint64 bytesReceived, qint64 bytesTot
QString Core::NetworkAccess::getFileRemoteUrl(const QString& path)
{
QString p;
QString p = Shared::squawkifyPath(path);
try {
p = storage.getUrl(path);
p = storage.getUrl(p);
} catch (const Archive::NotFound& err) {
} catch (...) {
@ -574,10 +574,16 @@ std::list<Shared::MessageInfo> Core::NetworkAccess::reportPathInvalid(const QStr
void Core::NetworkAccess::moveFilesDirectory(const QString& newPath)
{
QDir dir;
if (dir.rename(currentPath, newPath)) {
currentPath = newPath;
} else {
QDir dir(currentPath);
bool success = true;
qDebug() << "moving" << currentPath << "to" << newPath;
for (QFileInfo fileInfo : dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System)) {
QString fileName = fileInfo.fileName();
success = dir.rename(fileName, newPath + QDir::separator() + fileName) && success;
}
if (!success) {
qDebug() << "couldn't move downloads directory, most probably downloads will be broken";
}
currentPath = newPath;
}

View file

@ -785,3 +785,9 @@ void Core::Squawk::onLocalPathInvalid(const QString& path)
}
}
}
void Core::Squawk::changeDownloadsPath(const QString& path)
{
network.moveFilesDirectory(path);
}

View file

@ -123,6 +123,7 @@ public slots:
void uploadVCard(const QString& account, const Shared::VCard& card);
void responsePassword(const QString& account, const QString& password);
void onLocalPathInvalid(const QString& path);
void changeDownloadsPath(const QString& path);
private:
typedef std::deque<Account*> Accounts;