Browse Source

feat(files): Add maximum size to autoaccept downloads

reviewable/pr5373/r3
Mick Sayson 7 years ago
parent
commit
c8716e9c45
  1. 19
      src/persistence/settings.cpp
  2. 5
      src/persistence/settings.h
  3. 14
      src/widget/form/chatform.cpp
  4. 11
      src/widget/form/settings/generalform.cpp
  5. 1
      src/widget/form/settings/generalform.h
  6. 34
      src/widget/form/settings/generalsettings.ui

19
src/persistence/settings.cpp

@ -183,6 +183,8 @@ void Settings::loadGlobal()
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::locate(QStandardPaths::HomeLocation, QString(),
QStandardPaths::LocateDirectory)) QStandardPaths::LocateDirectory))
.toString(); .toString();
autoAcceptMaxSize =
static_cast<size_t>(s.value("autoAcceptMaxSize", 20 << 20 /*20 MB*/).toLongLong());
stylePreference = static_cast<StyleType>(s.value("stylePreference", 1).toInt()); stylePreference = static_cast<StyleType>(s.value("stylePreference", 1).toInt());
} }
s.endGroup(); s.endGroup();
@ -499,6 +501,7 @@ void Settings::saveGlobal()
s.setValue("busySound", busySound); s.setValue("busySound", busySound);
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging); s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("autoSaveEnabled", autoSaveEnabled); s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("autoAcceptMaxSize", static_cast<qlonglong>(autoAcceptMaxSize));
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir); s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
s.setValue("stylePreference", static_cast<int>(stylePreference)); s.setValue("stylePreference", static_cast<int>(stylePreference));
} }
@ -1509,6 +1512,22 @@ void Settings::setGlobalAutoAcceptDir(const QString& newValue)
} }
} }
size_t Settings::getMaxAutoAcceptSize() const
{
QMutexLocker locker{&bigLock};
return autoAcceptMaxSize;
}
void Settings::setMaxAutoAcceptSize(size_t size)
{
QMutexLocker locker{&bigLock};
if (size != autoAcceptMaxSize) {
autoAcceptMaxSize = size;
emit autoAcceptMaxSizeChanged(autoAcceptMaxSize);
}
}
const QFont& Settings::getChatMessageFont() const const QFont& Settings::getChatMessageFont() const
{ {
QMutexLocker locker(&bigLock); QMutexLocker locker(&bigLock);

5
src/persistence/settings.h

@ -186,6 +186,7 @@ signals:
void enableLoggingChanged(bool enabled); void enableLoggingChanged(bool enabled);
void autoAwayTimeChanged(int minutes); void autoAwayTimeChanged(int minutes);
void globalAutoAcceptDirChanged(const QString& path); void globalAutoAcceptDirChanged(const QString& path);
void autoAcceptMaxSizeChanged(size_t size);
void checkUpdatesChanged(bool enabled); void checkUpdatesChanged(bool enabled);
void widgetDataChanged(const QString& key); void widgetDataChanged(const QString& key);
@ -438,6 +439,9 @@ public:
QString getGlobalAutoAcceptDir() const; QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir); void setGlobalAutoAcceptDir(const QString& dir);
size_t getMaxAutoAcceptSize() const;
void setMaxAutoAcceptSize(size_t size);
bool getAutoGroupInvite(const ToxPk& id) const override; bool getAutoGroupInvite(const ToxPk& id) const override;
void setAutoGroupInvite(const ToxPk& id, bool accept) override; void setAutoGroupInvite(const ToxPk& id, bool accept) override;
@ -627,6 +631,7 @@ private:
QHash<QString, QString> autoAccept; QHash<QString, QString> autoAccept;
bool autoSaveEnabled; bool autoSaveEnabled;
QString globalAutoAcceptDir; QString globalAutoAcceptDir;
size_t autoAcceptMaxSize;
QList<Request> friendRequests; QList<Request> friendRequests;

14
src/widget/form/chatform.cpp

@ -339,12 +339,16 @@ void ChatForm::onFileRecvRequest(ToxFile file)
const Settings& settings = Settings::getInstance(); const Settings& settings = Settings::getInstance();
QString autoAcceptDir = settings.getAutoAcceptDir(f->getPublicKey()); QString autoAcceptDir = settings.getAutoAcceptDir(f->getPublicKey());
// there is auto-accept for that contact
if (!autoAcceptDir.isEmpty()) { if (autoAcceptDir.isEmpty() && settings.getAutoSaveEnabled()) {
autoAcceptDir = settings.getGlobalAutoAcceptDir();
}
auto maxAutoAcceptSize = settings.getMaxAutoAcceptSize();
bool autoAcceptSizeCheckPassed = maxAutoAcceptSize == 0 || maxAutoAcceptSize >= file.filesize;
if (!autoAcceptDir.isEmpty() && autoAcceptSizeCheckPassed) {
tfWidget->autoAcceptTransfer(autoAcceptDir); tfWidget->autoAcceptTransfer(autoAcceptDir);
// global autosave to global directory
} else if (settings.getAutoSaveEnabled()) {
tfWidget->autoAcceptTransfer(settings.getGlobalAutoAcceptDir());
} }
Widget::getInstance()->updateFriendActivity(f); Widget::getInstance()->updateFriendActivity(f);

11
src/widget/form/settings/generalform.cpp

@ -21,6 +21,7 @@
#include "ui_generalsettings.h" #include "ui_generalsettings.h"
#include <QFileDialog> #include <QFileDialog>
#include <cmath>
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/coreav.h" #include "src/core/coreav.h"
@ -148,8 +149,10 @@ GeneralForm::GeneralForm(SettingsWidget* myParent)
bodyUI->autoAwaySpinBox->setValue(s.getAutoAwayTime()); bodyUI->autoAwaySpinBox->setValue(s.getAutoAwayTime());
bodyUI->autoSaveFilesDir->setText(s.getGlobalAutoAcceptDir()); bodyUI->autoSaveFilesDir->setText(s.getGlobalAutoAcceptDir());
bodyUI->maxAutoAcceptSizeMB->setValue(static_cast<double>(s.getMaxAutoAcceptSize()) / 1024 / 1024);
bodyUI->autoacceptFiles->setChecked(s.getAutoSaveEnabled()); bodyUI->autoacceptFiles->setChecked(s.getAutoSaveEnabled());
#ifndef QTOX_PLATFORM_EXT #ifndef QTOX_PLATFORM_EXT
bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets, bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable
@ -244,6 +247,14 @@ void GeneralForm::on_autoSaveFilesDir_clicked()
bodyUI->autoSaveFilesDir->setText(directory); bodyUI->autoSaveFilesDir->setText(directory);
} }
void GeneralForm::on_maxAutoAcceptSizeMB_editingFinished()
{
auto newMaxSizeMB = bodyUI->maxAutoAcceptSizeMB->value();
auto newMaxSizeB = std::lround(newMaxSizeMB * 1024 * 1024);
Settings::getInstance().setMaxAutoAcceptSize(newMaxSizeB);
}
void GeneralForm::on_checkUpdates_stateChanged() void GeneralForm::on_checkUpdates_stateChanged()
{ {
Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked()); Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());

1
src/widget/form/settings/generalform.h

@ -53,6 +53,7 @@ private slots:
void on_cbFauxOfflineMessaging_stateChanged(); void on_cbFauxOfflineMessaging_stateChanged();
void on_autoacceptFiles_stateChanged(); void on_autoacceptFiles_stateChanged();
void on_maxAutoAcceptSizeMB_editingFinished();
void on_autoSaveFilesDir_clicked(); void on_autoSaveFilesDir_clicked();
void on_checkUpdates_stateChanged(); void on_checkUpdates_stateChanged();

34
src/widget/form/settings/generalsettings.ui

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1312</width> <width>1312</width>
<height>580</height> <height>511</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -39,8 +39,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1276</width> <width>1298</width>
<height>587</height> <height>497</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0">
@ -278,6 +278,13 @@ instead of closing itself.</string>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Default directory to save files:</string>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="autoSaveFilesDir"> <widget class="QPushButton" name="autoSaveFilesDir">
<property name="sizePolicy"> <property name="sizePolicy">
@ -291,13 +298,6 @@ instead of closing itself.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Default directory to save files:</string>
</property>
</widget>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="autoacceptFiles"> <widget class="QCheckBox" name="autoacceptFiles">
<property name="sizePolicy"> <property name="sizePolicy">
@ -314,6 +314,20 @@ instead of closing itself.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="maxAutoAcceptSizeLabel">
<property name="text">
<string>Max autoaccept file size (0 to disable):</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="maxAutoAcceptSizeMB">
<property name="suffix">
<string> MB</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

Loading…
Cancel
Save