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

Merge pull request #5373

Mick Sayson (2):
      refactor(files): clang-format generated whitespace changes
      feat(files): Add maximum size to autoaccept downloads
This commit is contained in:
Anthony Bilinski 2018-10-12 14:28:11 -07:00
commit 2ecfbf7f28
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
6 changed files with 108 additions and 42 deletions

View File

@ -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();
@ -272,9 +274,9 @@ void Settings::loadGlobal()
enableTestSound = s.value("enableTestSound", true).toBool(); enableTestSound = s.value("enableTestSound", true).toBool();
audioBitrate = s.value("audioBitrate", 64).toInt(); audioBitrate = s.value("audioBitrate", 64).toInt();
enableBackend2 = false; enableBackend2 = false;
#ifdef USE_FILTERAUDIO #ifdef USE_FILTERAUDIO
enableBackend2 = s.value("enableBackend2", false).toBool(); enableBackend2 = s.value("enableBackend2", false).toBool();
#endif #endif
} }
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);

View File

@ -43,8 +43,11 @@ namespace Db {
enum class syncType; enum class syncType;
} }
class Settings : public QObject, public ICoreSettings, public IFriendSettings, class Settings : public QObject,
public IAudioSettings, public IVideoSettings public ICoreSettings,
public IFriendSettings,
public IAudioSettings,
public IVideoSettings
{ {
Q_OBJECT Q_OBJECT
@ -91,8 +94,8 @@ class Settings : public QObject, public ICoreSettings, public IFriendSettings,
Q_PROPERTY(QString dateFormat READ getDateFormat WRITE setDateFormat NOTIFY dateFormatChanged FINAL) Q_PROPERTY(QString dateFormat READ getDateFormat WRITE setDateFormat NOTIFY dateFormatChanged FINAL)
Q_PROPERTY(bool statusChangeNotificationEnabled READ getStatusChangeNotificationEnabled WRITE Q_PROPERTY(bool statusChangeNotificationEnabled READ getStatusChangeNotificationEnabled WRITE
setStatusChangeNotificationEnabled NOTIFY statusChangeNotificationEnabledChanged FINAL) setStatusChangeNotificationEnabled NOTIFY statusChangeNotificationEnabledChanged FINAL)
Q_PROPERTY(bool spellCheckingEnabled READ getSpellCheckingEnabled WRITE Q_PROPERTY(bool spellCheckingEnabled READ getSpellCheckingEnabled WRITE setSpellCheckingEnabled
setSpellCheckingEnabled NOTIFY spellCheckingEnabledChanged FINAL) NOTIFY spellCheckingEnabledChanged FINAL)
// Privacy // Privacy
Q_PROPERTY(bool typingNotification READ getTypingNotification WRITE setTypingNotification NOTIFY Q_PROPERTY(bool typingNotification READ getTypingNotification WRITE setTypingNotification NOTIFY
@ -105,8 +108,8 @@ class Settings : public QObject, public ICoreSettings, public IFriendSettings,
audioInDevEnabledChanged FINAL) audioInDevEnabledChanged FINAL)
Q_PROPERTY(qreal audioInGainDecibel READ getAudioInGainDecibel WRITE setAudioInGainDecibel Q_PROPERTY(qreal audioInGainDecibel READ getAudioInGainDecibel WRITE setAudioInGainDecibel
NOTIFY audioInGainDecibelChanged FINAL) NOTIFY audioInGainDecibelChanged FINAL)
Q_PROPERTY(qreal audioThreshold READ getAudioThreshold WRITE setAudioThreshold Q_PROPERTY(qreal audioThreshold READ getAudioThreshold WRITE setAudioThreshold NOTIFY
NOTIFY audioThresholdChanged FINAL) audioThresholdChanged FINAL)
Q_PROPERTY(QString outDev READ getOutDev WRITE setOutDev NOTIFY outDevChanged FINAL) Q_PROPERTY(QString outDev READ getOutDev WRITE setOutDev NOTIFY outDevChanged FINAL)
Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY
audioOutDevEnabledChanged FINAL) audioOutDevEnabledChanged FINAL)
@ -183,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);
@ -352,8 +356,14 @@ public:
void setAudioThreshold(qreal percent) override; void setAudioThreshold(qreal percent) override;
int getOutVolume() const override; int getOutVolume() const override;
int getOutVolumeMin() const override { return 0; } int getOutVolumeMin() const override
int getOutVolumeMax() const override { return 100; } {
return 0;
}
int getOutVolumeMax() const override
{
return 100;
}
void setOutVolume(int volume) override; void setOutVolume(int volume) override;
int getAudioBitrate() const override; int getAudioBitrate() const override;
@ -429,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;
@ -491,8 +504,8 @@ public:
void saveFriendSettings(const ToxPk& id) override; void saveFriendSettings(const ToxPk& id) override;
void removeFriendSettings(const ToxPk& id) override; void removeFriendSettings(const ToxPk& id) override;
SIGNAL_IMPL(Settings, autoAcceptCallChanged, SIGNAL_IMPL(Settings, autoAcceptCallChanged, const ToxPk& id,
const ToxPk& id, IFriendSettings::AutoAcceptCallFlags accept) IFriendSettings::AutoAcceptCallFlags accept)
SIGNAL_IMPL(Settings, autoGroupInviteChanged, const ToxPk& id, bool accept) SIGNAL_IMPL(Settings, autoGroupInviteChanged, const ToxPk& id, bool accept)
SIGNAL_IMPL(Settings, autoAcceptDirChanged, const ToxPk& id, const QString& dir) SIGNAL_IMPL(Settings, autoAcceptDirChanged, const ToxPk& id, const QString& dir)
SIGNAL_IMPL(Settings, contactNoteChanged, const ToxPk& id, const QString& note) SIGNAL_IMPL(Settings, contactNoteChanged, const ToxPk& id, const QString& note)
@ -508,10 +521,10 @@ public:
bool getDontGroupWindows() const; bool getDontGroupWindows() const;
void setDontGroupWindows(bool value); void setDontGroupWindows(bool value);
bool getGroupchatPosition() const; bool getGroupchatPosition() const;
void setGroupchatPosition(bool value); void setGroupchatPosition(bool value);
bool getShowIdenticons() const; bool getShowIdenticons() const;
void setShowIdenticons(bool value); void setShowIdenticons(bool value);
@ -618,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;

View File

@ -234,7 +234,7 @@ void ChatForm::onSendTriggered()
} }
void ChatForm::onFileNameChanged(const ToxPk& friendPk) void ChatForm::onFileNameChanged(const ToxPk& friendPk)
{ {
if(friendPk != f->getPublicKey()) { if (friendPk != f->getPublicKey()) {
return; return;
} }
@ -266,8 +266,8 @@ void ChatForm::onTextEditChanged()
void ChatForm::onAttachClicked() void ChatForm::onAttachClicked()
{ {
QStringList paths = QStringList paths = QFileDialog::getOpenFileNames(Q_NULLPTR, tr("Send a file"),
QFileDialog::getOpenFileNames(Q_NULLPTR, tr("Send a file"), QDir::homePath(), nullptr, nullptr); QDir::homePath(), nullptr, nullptr);
if (paths.isEmpty()) { if (paths.isEmpty()) {
return; return;
@ -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);
@ -509,8 +513,8 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
if (isFirst || isAfter) { if (isFirst || isAfter) {
if (isFirst || (isAfter && parameter.date < getFirstDate())) { if (isFirst || (isAfter && parameter.date < getFirstDate())) {
const QString pk = f->getPublicKey().toString(); const QString pk = f->getPublicKey().toString();
if ((isFirst || parameter.date >= history->getStartDateChatHistory(pk).date()) && if ((isFirst || parameter.date >= history->getStartDateChatHistory(pk).date())
loadHistory(phrase, parameter)) { && loadHistory(phrase, parameter)) {
return; return;
} }
@ -520,7 +524,8 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
} else { } else {
if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstDate()) { if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstDate()) {
const QString pk = f->getPublicKey().toString(); const QString pk = f->getPublicKey().toString();
if (parameter.date >= history->getStartDateChatHistory(pk).date() && loadHistory(phrase, parameter)) { if (parameter.date >= history->getStartDateChatHistory(pk).date()
&& loadHistory(phrase, parameter)) {
return; return;
} }
} }
@ -555,7 +560,8 @@ void ChatForm::onSearchUp(const QString& phrase, const ParameterSearch& paramete
if (!isSearch) { if (!isSearch) {
const QString pk = f->getPublicKey().toString(); const QString pk = f->getPublicKey().toString();
const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); const QDateTime newBaseDate =
history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
if (!newBaseDate.isValid()) { if (!newBaseDate.isValid()) {
emit messageNotFoundShow(SearchDirection::Up); emit messageNotFoundShow(SearchDirection::Up);
@ -648,7 +654,7 @@ void ChatForm::onReceiptReceived(quint32 friendId, int receipt)
} }
} }
void ChatForm::onAvatarChanged(const ToxPk &friendPk, const QPixmap& pic) void ChatForm::onAvatarChanged(const ToxPk& friendPk, const QPixmap& pic)
{ {
if (friendPk != f->getPublicKey()) { if (friendPk != f->getPublicKey()) {
return; return;
@ -1058,7 +1064,7 @@ void ChatForm::SendMessageStr(QString msg)
} }
ChatMessage::Ptr ma = createSelfMessage(part, timestamp, isAction, false); ChatMessage::Ptr ma = createSelfMessage(part, timestamp, isAction, false);
if (history && Settings::getInstance().getEnableLogging()) { if (history && Settings::getInstance().getEnableLogging()) {
auto* offMsgEngine = getOfflineMsgEngine(); auto* offMsgEngine = getOfflineMsgEngine();
QString selfPk = Core::getInstance()->getSelfId().toString(); QString selfPk = Core::getInstance()->getSelfId().toString();
@ -1083,7 +1089,8 @@ void ChatForm::SendMessageStr(QString msg)
bool ChatForm::loadHistory(const QString& phrase, const ParameterSearch& parameter) bool ChatForm::loadHistory(const QString& phrase, const ParameterSearch& parameter)
{ {
const QString pk = f->getPublicKey().toString(); const QString pk = f->getPublicKey().toString();
const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter); const QDateTime newBaseDate =
history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
if (newBaseDate.isValid() && getFirstDate().isValid() && newBaseDate.date() < getFirstDate()) { if (newBaseDate.isValid() && getFirstDate().isValid() && newBaseDate.date() < getFirstDate()) {
searchAfterLoadHistory = true; searchAfterLoadHistory = true;
@ -1133,7 +1140,8 @@ void ChatForm::onExportChat()
ToxPk authorPk(ToxId(it.sender).getPublicKey()); ToxPk authorPk(ToxId(it.sender).getPublicKey());
QString author = getMsgAuthorDispName(authorPk, it.dispName); QString author = getMsgAuthorDispName(authorPk, it.dispName);
buffer = buffer % QString{datestamp % '\t' % timestamp % '\t' % author % '\t' % it.message % '\n'}; buffer = buffer
% QString{datestamp % '\t' % timestamp % '\t' % author % '\t' % it.message % '\n'};
} }
file.write(buffer.toUtf8()); file.write(buffer.toUtf8());
file.close(); file.close();

View File

@ -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,11 +149,12 @@ 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( bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
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
#endif #endif
@ -245,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());

View File

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

View File

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