Browse Source

refactor: remove another function from Nexus

reviewable/pr5418/r3
sudden6 7 years ago
parent
commit
acc7058e65
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 19
      src/chatlog/content/filetransferwidget.cpp
  2. 1
      src/chatlog/content/filetransferwidget.h
  3. 15
      src/nexus.cpp
  4. 1
      src/nexus.h

19
src/chatlog/content/filetransferwidget.cpp

@ -21,7 +21,6 @@ @@ -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() @@ -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) @@ -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) @@ -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.",

1
src/chatlog/content/filetransferwidget.h

@ -77,6 +77,7 @@ private: @@ -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;

15
src/nexus.cpp

@ -31,8 +31,6 @@ @@ -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() @@ -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()
{

1
src/nexus.h

@ -49,7 +49,6 @@ public: @@ -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();

Loading…
Cancel
Save