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:
parent
de773efec7
commit
acc7058e65
|
@ -21,7 +21,6 @@
|
||||||
#include "ui_filetransferwidget.h"
|
#include "ui_filetransferwidget.h"
|
||||||
|
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/nexus.h"
|
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/widget/gui.h"
|
#include "src/widget/gui.h"
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
|
@ -124,6 +123,20 @@ FileTransferWidget::~FileTransferWidget()
|
||||||
delete ui;
|
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)
|
void FileTransferWidget::autoAcceptTransfer(const QString& path)
|
||||||
{
|
{
|
||||||
QString filepath;
|
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.
|
// Do not automatically accept the file-transfer if the path is not writable.
|
||||||
// The user can still accept it manually.
|
// The user can still accept it manually.
|
||||||
if (Nexus::tryRemoveFile(filepath))
|
if (tryRemoveFile(filepath))
|
||||||
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, filepath);
|
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, filepath);
|
||||||
else
|
else
|
||||||
qWarning() << "Cannot write to " << filepath;
|
qWarning() << "Cannot write to " << filepath;
|
||||||
|
@ -159,7 +172,7 @@ void FileTransferWidget::acceptTransfer(const QString& filepath)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// test if writable
|
// test if writable
|
||||||
if (!Nexus::tryRemoveFile(filepath)) {
|
if (!tryRemoveFile(filepath)) {
|
||||||
GUI::showWarning(tr("Location not writable", "Title of permissions popup"),
|
GUI::showWarning(tr("Location not writable", "Title of permissions popup"),
|
||||||
tr("You do not have permission to write that location. Choose another, or "
|
tr("You do not have permission to write that location. Choose another, or "
|
||||||
"cancel the save dialog.",
|
"cancel the save dialog.",
|
||||||
|
|
|
@ -77,6 +77,7 @@ private:
|
||||||
static QPixmap scaleCropIntoSquare(const QPixmap& source, int targetSize);
|
static QPixmap scaleCropIntoSquare(const QPixmap& source, int targetSize);
|
||||||
static int getExifOrientation(const char* data, const int size);
|
static int getExifOrientation(const char* data, const int size);
|
||||||
static void applyTransformation(const int oritentation, QImage& image);
|
static void applyTransformation(const int oritentation, QImage& image);
|
||||||
|
static bool tryRemoveFile(const QString &filepath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FileTransferWidget* ui;
|
Ui::FileTransferWidget* ui;
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QFile>
|
|
||||||
#include <QImageReader>
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <vpx/vpx_image.h>
|
#include <vpx/vpx_image.h>
|
||||||
|
@ -284,19 +282,6 @@ Widget* Nexus::getDesktopGUI()
|
||||||
return getInstance().widget;
|
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
|
#ifdef Q_OS_MAC
|
||||||
void Nexus::retranslateUi()
|
void Nexus::retranslateUi()
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
static Profile* getProfile();
|
static Profile* getProfile();
|
||||||
static void setProfile(Profile* profile);
|
static void setProfile(Profile* profile);
|
||||||
static Widget* getDesktopGUI();
|
static Widget* getDesktopGUI();
|
||||||
static bool tryRemoveFile(const QString& filepath);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showLogin();
|
void showLogin();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user