Merge pull request #8462 from mike0609king/issue892_final

Implement more prominent quota warning
This commit is contained in:
Matthieu Gallien 2025-09-18 09:01:48 +02:00 committed by GitHub
commit 3c5b76d885
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 91 additions and 0 deletions

View File

@ -287,6 +287,7 @@ bool AccountManager::restoreFromLegacySettings()
configFile.setPromptDeleteFiles(settings->value(ConfigFile::promptDeleteC, configFile.promptDeleteFiles()).toBool());
configFile.setShowCallNotifications(settings->value(ConfigFile::showCallNotificationsC, configFile.showCallNotifications()).toBool());
configFile.setShowChatNotifications(settings->value(ConfigFile::showChatNotificationsC, configFile.showChatNotifications()).toBool());
configFile.setShowQuotaWarningNotifications(settings->value(ConfigFile::showQuotaWarningNotificationsC, configFile.showQuotaWarningNotifications()).toBool());
configFile.setShowInExplorerNavigationPane(settings->value(ConfigFile::showInExplorerNavigationPaneC, configFile.showInExplorerNavigationPane()).toBool());
ClientProxy().saveProxyConfigurationFromSettings(*settings);
configFile.setUseUploadLimit(settings->value(ConfigFile::useUploadLimitC, configFile.useUploadLimit()).toInt());

View File

@ -195,6 +195,9 @@ GeneralSettings::GeneralSettings(QWidget *parent)
this, &GeneralSettings::slotToggleCallNotifications);
_ui->callNotificationsCheckBox->setToolTip(tr("Show call notification dialogs."));
connect(_ui->quotaWarningNotificationsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleQuotaWarningNotifications);
_ui->quotaWarningNotificationsCheckBox->setToolTip(tr("Show notification when quota usage exceeds 80%."));
connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane);
// Rename 'Explorer' appropriately on non-Windows
@ -298,6 +301,8 @@ void GeneralSettings::loadMiscSettings()
_ui->chatNotificationsCheckBox->setChecked(cfgFile.showChatNotifications());
_ui->callNotificationsCheckBox->setEnabled(cfgFile.optionalServerNotifications());
_ui->callNotificationsCheckBox->setChecked(cfgFile.showCallNotifications());
_ui->quotaWarningNotificationsCheckBox->setEnabled(cfgFile.optionalServerNotifications());
_ui->quotaWarningNotificationsCheckBox->setChecked(cfgFile.showQuotaWarningNotifications());
_ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane());
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
@ -594,6 +599,12 @@ void GeneralSettings::slotToggleCallNotifications(bool enable)
cfgFile.setShowCallNotifications(enable);
}
void GeneralSettings::slotToggleQuotaWarningNotifications(bool enable)
{
ConfigFile cfgFile;
cfgFile.setShowQuotaWarningNotifications(enable);
}
void GeneralSettings::slotShowInExplorerNavigationPane(bool checked)
{
ConfigFile cfgFile;

View File

@ -49,6 +49,7 @@ private slots:
void slotToggleOptionalServerNotifications(bool);
void slotToggleChatNotifications(bool);
void slotToggleCallNotifications(bool);
void slotToggleQuotaWarningNotifications(bool);
void slotShowInExplorerNavigationPane(bool);
void slotIgnoreFilesEditor();
void slotCreateDebugArchive();

View File

@ -58,6 +58,13 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="quotaWarningNotificationsCheckBox">
<property name="text">
<string>Show &amp;Quota Warning Notifications</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -24,12 +24,14 @@
#include "tray/talkreply.h"
#include "userstatusconnector.h"
#include <QtCore>
#include <QDesktopServices>
#include <QIcon>
#include <QMessageBox>
#include <QSvgRenderer>
#include <QPainter>
#include <QPushButton>
#include <QDateTime>
// time span in milliseconds which has to be between two
// refreshes of the notifications
@ -83,6 +85,7 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
connect(_account.data(), &AccountState::hasFetchedNavigationApps,
this, &User::slotRebuildNavigationAppList);
connect(_account->account().data(), &Account::accountChangedDisplayName, this, &User::nameChanged);
connect(_account->account().data(), &Account::rootFolderQuotaChanged, this, &User::slotQuotaChanged);
connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &User::hasLocalFolderChanged);
@ -1192,6 +1195,44 @@ void User::slotFetchGroupFolders()
connect(groupFolderListJob, &SimpleNetworkJob::finishedSignal, this, &User::slotGroupFoldersFetched);
}
void User::slotQuotaChanged(const int64_t &usedBytes, const int64_t &availableBytes)
{
int64_t total = usedBytes + availableBytes;
if (total <= 0 || !ConfigFile().showQuotaWarningNotifications()) {
return;
}
const auto percent = (double)usedBytes / (double)total * 100.0;
const auto percentInt = qMin(qRound(percent), 100);
qCDebug(lcActivity) << tr("Quota is updated; %1 percent of the total space is used.").arg(QString::number(percentInt));
int thresholdPassed = 0;
if (_lastQuotaPercent < 80 && percentInt >= 80) {
thresholdPassed = 80;
}
if (_lastQuotaPercent < 90 && percentInt >= 90) {
thresholdPassed = 90;
}
if (_lastQuotaPercent < 95 && percentInt >= 95) {
thresholdPassed = 95;
}
if (thresholdPassed > 0) {
_activityModel->removeActivityFromActivityList(_lastQuotaActivity);
_lastQuotaActivity._type = Activity::OpenSettingsNotificationType;
_lastQuotaActivity._dateTime = QDateTime::fromString(QDateTime::currentDateTime().toString(), Qt::ISODate);
_lastQuotaActivity._subject = tr("Quota Warning - %1 percent or more storage in use").arg(QString::number(thresholdPassed));
_lastQuotaActivity._accName = account()->displayName();
_lastQuotaActivity._id = qHash(QDateTime::currentMSecsSinceEpoch());
showDesktopNotification(_lastQuotaActivity);
_activityModel->addNotificationToActivityList(_lastQuotaActivity);
}
_lastQuotaPercent = percentInt;
}
void User::slotGroupFoldersFetched(QNetworkReply *reply)
{
Q_ASSERT(reply);

View File

@ -18,6 +18,7 @@
#include "activitydata.h"
#include "activitylistmodel.h"
#include "folderman.h"
#include "userinfo.h"
#include "userstatusconnector.h"
#include "userstatusselectormodel.h"
#include <chrono>
@ -161,6 +162,7 @@ private slots:
void slotReceivedPushActivity(OCC::Account *account);
void slotCheckExpiredActivities();
void slotGroupFoldersFetched(QNetworkReply *reply);
void slotQuotaChanged(const int64_t &usedBytes, const int64_t &availableBytes);
void checkNotifiedNotifications();
void showDesktopNotification(const QString &title, const QString &message, const long notificationId);
void showDesktopNotification(const OCC::Activity &activity);
@ -206,6 +208,10 @@ private:
int _lastTalkNotificationsReceivedCount = 0;
bool _isNotificationFetchRunning = false;
// used for quota warnings
int _lastQuotaPercent = 0;
Activity _lastQuotaActivity;
};
class UserModel : public QAbstractListModel

View File

@ -470,6 +470,7 @@ signals:
void encryptionCertificateFingerprintChanged();
void userCertificateNeedsMigrationChanged();
void rootFolderQuotaChanged(const int64_t &usedBytes, const int64_t &availableBytes);
protected Q_SLOTS:
void slotCredentialsFetched();
void slotCredentialsAsked();

View File

@ -216,6 +216,19 @@ void ConfigFile::setShowCallNotifications(bool show)
settings.sync();
}
bool ConfigFile::showQuotaWarningNotifications() const
{
const QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(showQuotaWarningNotificationsC, true).toBool() && optionalServerNotifications();
}
void ConfigFile::setShowQuotaWarningNotifications(bool show)
{
QSettings settings(configFile(), QSettings::IniFormat);
settings.setValue(showQuotaWarningNotificationsC, show);
settings.sync();
}
bool ConfigFile::showInExplorerNavigationPane() const
{
const bool defaultValue =

View File

@ -165,6 +165,9 @@ public:
[[nodiscard]] bool showCallNotifications() const;
void setShowCallNotifications(bool show);
[[nodiscard]] bool showQuotaWarningNotifications() const;
void setShowQuotaWarningNotifications(bool show);
[[nodiscard]] bool showInExplorerNavigationPane() const;
void setShowInExplorerNavigationPane(bool show);
@ -257,6 +260,7 @@ public:
static constexpr char optionalServerNotificationsC[] = "optionalServerNotifications";
static constexpr char promptDeleteC[] = "promptDeleteAllFiles";
static constexpr char showCallNotificationsC[] = "showCallNotifications";
static constexpr char showQuotaWarningNotificationsC[] = "showQuotaWarningNotifications";
static constexpr char showChatNotificationsC[] = "showChatNotifications";
static constexpr char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane";

View File

@ -2299,6 +2299,10 @@ void ProcessDirectoryJob::setFolderQuota(const FolderQuota &folderQuota)
{
_folderQuota.bytesUsed = folderQuota.bytesUsed;
_folderQuota.bytesAvailable = folderQuota.bytesAvailable;
if (_currentFolder._original.isEmpty()) {
emit updatedRootFolderQuota(_folderQuota.bytesUsed, _folderQuota.bytesAvailable);
}
}
void ProcessDirectoryJob::startAsyncLocalQuery()

View File

@ -305,6 +305,7 @@ signals:
void finished();
// The root etag of this directory was fetched
void etag(const QByteArray &, const QDateTime &time);
void updatedRootFolderQuota(const int64_t &bytesUsed, const int64_t &bytesAvailable);
private slots:
void setFolderQuota(const FolderQuota &folderQuota);

View File

@ -760,6 +760,7 @@ void SyncEngine::startSync()
_discoveryPhase->startJob(discoveryJob);
connect(discoveryJob, &ProcessDirectoryJob::etag, this, &SyncEngine::slotRootEtagReceived);
connect(discoveryJob, &ProcessDirectoryJob::updatedRootFolderQuota, account().data(), &Account::rootFolderQuotaChanged);
connect(_discoveryPhase.get(), &DiscoveryPhase::addErrorToGui, this, &SyncEngine::addErrorToGui);
}