Qt: Add web cache section to advanced

pull/3715/head
Stenzek 5 months ago
parent 3b98973f1a
commit b05e7ce52e
No known key found for this signature in database

@ -6,6 +6,11 @@
#include "settingswindow.h"
#include "settingwidgetbinder.h"
#include "util/http_cache.h"
#include "util/object_archive.h"
#include "common/error.h"
#include <QtGui/QCursor>
#include <QtWidgets/QMenu>
@ -49,6 +54,11 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(SettingsWindow* dialog, QWidget*
sif, m_ui.coversDirectory, m_ui.coversDirectoryBrowse, tr("Select Covers Directory"), m_ui.coversDirectoryOpen,
m_ui.coversDirectoryReset, "Folders", "Covers", Path::Combine(EmuFolders::DataRoot, "covers"));
connect(m_ui.refreshWebCache, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::refreshWebCacheSize);
connect(m_ui.clearWebCache, &QAbstractButton::clicked, this, &AdvancedSettingsWidget::onClearWebCacheClicked);
refreshWebCacheSize();
dialog->registerWidgetHelp(m_ui.logLevel, tr("Log Level"), tr("Information"),
tr("Sets the verbosity of messages logged. Higher levels will log more messages."));
dialog->registerWidgetHelp(m_ui.logToConsole, tr("Log To System Console"), tr("User Preference"),
@ -97,3 +107,30 @@ void AdvancedSettingsWidget::onShowDebugOptionsStateChanged()
const bool enabled = QtHost::ShouldShowDebugOptions();
emit m_dialog->debugOptionsVisibiltyChanged(enabled);
}
void AdvancedSettingsWidget::refreshWebCacheSize()
{
const auto cache = HTTPCache::GetCacheArchive();
static constexpr auto to_mb = [](s64 size) { return static_cast<u32>((size + 1048575) / 1048576); };
const u64 cache_size = cache->GetTotalSize();
const u64 object_size = cache->GetTotalObjectSize();
const size_t num_objects = cache->GetSize();
m_ui.webCacheSize->setText(tr("Current Cache Size: %1 MB (%2 MB in %3 objects)")
.arg(to_mb(cache_size))
.arg(to_mb(object_size))
.arg(num_objects));
}
void AdvancedSettingsWidget::onClearWebCacheClicked()
{
Error error;
if (!HTTPCache::Clear(&error))
{
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, "Failed to clear web cache"_L1,
QString::fromStdString(error.GetDescription()));
}
refreshWebCacheSize();
}

@ -21,6 +21,8 @@ private:
void onLogChannelsButtonClicked();
void onAnyLogSinksChanged();
void onShowDebugOptionsStateChanged();
void refreshWebCacheSize();
void onClearWebCacheClicked();
SettingsWindow* m_dialog;

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>634</width>
<height>406</height>
<height>484</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -219,6 +219,42 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="webCacheGroup">
<property name="title">
<string>Web Cache</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,0">
<item>
<widget class="QLabel" name="webCacheSize">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshWebCache">
<property name="text">
<string>Refresh</string>
</property>
<property name="icon">
<iconset theme="refresh-line"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearWebCache">
<property name="text">
<string>Clear</string>
</property>
<property name="icon">
<iconset theme="trash-fill"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

Loading…
Cancel
Save