From acc7058e65f1bac1cc18fc9eaa636ea18f216680 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Wed, 31 Oct 2018 02:06:05 +0100 Subject: [PATCH] refactor: remove another function from Nexus --- src/chatlog/content/filetransferwidget.cpp | 19 ++++++++++++++++--- src/chatlog/content/filetransferwidget.h | 1 + src/nexus.cpp | 15 --------------- src/nexus.h | 1 - 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 86365384d..3da558b3c 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -21,7 +21,6 @@ #include "ui_filetransferwidget.h" #include "src/core/core.h" -#include "src/nexus.h" #include "src/persistence/settings.h" #include "src/widget/gui.h" #include "src/widget/style.h" @@ -124,6 +123,20 @@ FileTransferWidget::~FileTransferWidget() delete ui; } +// TODO(sudden6): remove file IO from the UI +/** + * @brief Dangerous way to find out if a path is writable. + * @param filepath Path to file which should be deleted. + * @return True, if file writeable, false otherwise. + */ +bool FileTransferWidget::tryRemoveFile(const QString& filepath) +{ + QFile tmp(filepath); + bool writable = tmp.open(QIODevice::WriteOnly); + tmp.remove(); + return writable; +} + void FileTransferWidget::autoAcceptTransfer(const QString& path) { QString filepath; @@ -142,7 +155,7 @@ void FileTransferWidget::autoAcceptTransfer(const QString& path) // Do not automatically accept the file-transfer if the path is not writable. // The user can still accept it manually. - if (Nexus::tryRemoveFile(filepath)) + if (tryRemoveFile(filepath)) Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, filepath); else qWarning() << "Cannot write to " << filepath; @@ -159,7 +172,7 @@ void FileTransferWidget::acceptTransfer(const QString& filepath) return; // test if writable - if (!Nexus::tryRemoveFile(filepath)) { + if (!tryRemoveFile(filepath)) { GUI::showWarning(tr("Location not writable", "Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or " "cancel the save dialog.", diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index cdeffe233..10b418014 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -77,6 +77,7 @@ private: static QPixmap scaleCropIntoSquare(const QPixmap& source, int targetSize); static int getExifOrientation(const char* data, const int size); static void applyTransformation(const int oritentation, QImage& image); + static bool tryRemoveFile(const QString &filepath); private: Ui::FileTransferWidget* ui; diff --git a/src/nexus.cpp b/src/nexus.cpp index 3e4ac0f0f..611189bf5 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include #include #include @@ -284,19 +282,6 @@ Widget* Nexus::getDesktopGUI() return getInstance().widget; } -/** - * @brief Dangerous way to find out if a path is writable. - * @param filepath Path to file which should be deleted. - * @return True, if file writeable, false otherwise. - */ -bool Nexus::tryRemoveFile(const QString& filepath) -{ - QFile tmp(filepath); - bool writable = tmp.open(QIODevice::WriteOnly); - tmp.remove(); - return writable; -} - #ifdef Q_OS_MAC void Nexus::retranslateUi() { diff --git a/src/nexus.h b/src/nexus.h index e455b97ac..cee767a66 100644 --- a/src/nexus.h +++ b/src/nexus.h @@ -49,7 +49,6 @@ public: static Profile* getProfile(); static void setProfile(Profile* profile); static Widget* getDesktopGUI(); - static bool tryRemoveFile(const QString& filepath); public slots: void showLogin();