1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: remove another function from Nexus

This commit is contained in:
sudden6 2018-10-31 02:06:05 +01:00
parent de773efec7
commit acc7058e65
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
4 changed files with 17 additions and 19 deletions

View File

@ -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.",

View File

@ -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;

View File

@ -31,8 +31,6 @@
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QFile>
#include <QImageReader>
#include <QThread>
#include <cassert>
#include <vpx/vpx_image.h>
@ -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()
{

View File

@ -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();