mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(files): Add maximum size to autoaccept downloads
This commit is contained in:
parent
939f2c865a
commit
c8716e9c45
|
@ -183,6 +183,8 @@ void Settings::loadGlobal()
|
|||
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(),
|
||||
QStandardPaths::LocateDirectory))
|
||||
.toString();
|
||||
autoAcceptMaxSize =
|
||||
static_cast<size_t>(s.value("autoAcceptMaxSize", 20 << 20 /*20 MB*/).toLongLong());
|
||||
stylePreference = static_cast<StyleType>(s.value("stylePreference", 1).toInt());
|
||||
}
|
||||
s.endGroup();
|
||||
|
@ -499,6 +501,7 @@ void Settings::saveGlobal()
|
|||
s.setValue("busySound", busySound);
|
||||
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
|
||||
s.setValue("autoSaveEnabled", autoSaveEnabled);
|
||||
s.setValue("autoAcceptMaxSize", static_cast<qlonglong>(autoAcceptMaxSize));
|
||||
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
|
||||
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
|
||||
{
|
||||
QMutexLocker locker(&bigLock);
|
||||
|
|
|
@ -186,6 +186,7 @@ signals:
|
|||
void enableLoggingChanged(bool enabled);
|
||||
void autoAwayTimeChanged(int minutes);
|
||||
void globalAutoAcceptDirChanged(const QString& path);
|
||||
void autoAcceptMaxSizeChanged(size_t size);
|
||||
void checkUpdatesChanged(bool enabled);
|
||||
void widgetDataChanged(const QString& key);
|
||||
|
||||
|
@ -438,6 +439,9 @@ public:
|
|||
QString getGlobalAutoAcceptDir() const;
|
||||
void setGlobalAutoAcceptDir(const QString& dir);
|
||||
|
||||
size_t getMaxAutoAcceptSize() const;
|
||||
void setMaxAutoAcceptSize(size_t size);
|
||||
|
||||
bool getAutoGroupInvite(const ToxPk& id) const override;
|
||||
void setAutoGroupInvite(const ToxPk& id, bool accept) override;
|
||||
|
||||
|
@ -627,6 +631,7 @@ private:
|
|||
QHash<QString, QString> autoAccept;
|
||||
bool autoSaveEnabled;
|
||||
QString globalAutoAcceptDir;
|
||||
size_t autoAcceptMaxSize;
|
||||
|
||||
QList<Request> friendRequests;
|
||||
|
||||
|
|
|
@ -339,12 +339,16 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
|
||||
const Settings& settings = Settings::getInstance();
|
||||
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);
|
||||
// global autosave to global directory
|
||||
} else if (settings.getAutoSaveEnabled()) {
|
||||
tfWidget->autoAcceptTransfer(settings.getGlobalAutoAcceptDir());
|
||||
}
|
||||
|
||||
Widget::getInstance()->updateFriendActivity(f);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "ui_generalsettings.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <cmath>
|
||||
|
||||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
|
@ -148,8 +149,10 @@ GeneralForm::GeneralForm(SettingsWidget* myParent)
|
|||
|
||||
bodyUI->autoAwaySpinBox->setValue(s.getAutoAwayTime());
|
||||
bodyUI->autoSaveFilesDir->setText(s.getGlobalAutoAcceptDir());
|
||||
bodyUI->maxAutoAcceptSizeMB->setValue(static_cast<double>(s.getMaxAutoAcceptSize()) / 1024 / 1024);
|
||||
bodyUI->autoacceptFiles->setChecked(s.getAutoSaveEnabled());
|
||||
|
||||
|
||||
#ifndef QTOX_PLATFORM_EXT
|
||||
bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
|
||||
bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable
|
||||
|
@ -244,6 +247,14 @@ void GeneralForm::on_autoSaveFilesDir_clicked()
|
|||
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()
|
||||
{
|
||||
Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());
|
||||
|
|
|
@ -53,6 +53,7 @@ private slots:
|
|||
void on_cbFauxOfflineMessaging_stateChanged();
|
||||
|
||||
void on_autoacceptFiles_stateChanged();
|
||||
void on_maxAutoAcceptSizeMB_editingFinished();
|
||||
void on_autoSaveFilesDir_clicked();
|
||||
void on_checkUpdates_stateChanged();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1312</width>
|
||||
<height>580</height>
|
||||
<height>511</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -39,8 +39,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1276</width>
|
||||
<height>587</height>
|
||||
<width>1298</width>
|
||||
<height>497</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0">
|
||||
|
@ -278,6 +278,13 @@ instead of closing itself.</string>
|
|||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</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">
|
||||
<widget class="QPushButton" name="autoSaveFilesDir">
|
||||
<property name="sizePolicy">
|
||||
|
@ -291,13 +298,6 @@ instead of closing itself.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QCheckBox" name="autoacceptFiles">
|
||||
<property name="sizePolicy">
|
||||
|
@ -314,6 +314,20 @@ instead of closing itself.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue
Block a user