mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 21:02:04 +08:00
实现垃圾文件计数和清理
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
#include <QtConcurrent/QtConcurrentRun>
|
||||||
|
#include <QMutexLocker>
|
||||||
|
#include <QFutureWatcher>
|
||||||
#include "spkutils.h"
|
#include "spkutils.h"
|
||||||
#include "page/spkpagesettings.h"
|
#include "page/spkpagesettings.h"
|
||||||
#include "spkmsgbox.h"
|
#include "spkmsgbox.h"
|
||||||
@@ -11,9 +14,9 @@ namespace SpkUi
|
|||||||
mMainArea = new QScrollArea();
|
mMainArea = new QScrollArea();
|
||||||
mMainLay = new QVBoxLayout(this);
|
mMainLay = new QVBoxLayout(this);
|
||||||
mSettingsWidget = new QWidget(this);
|
mSettingsWidget = new QWidget(this);
|
||||||
mSettingsUi = new Ui::SpkUiSettings;
|
ui = new Ui::SpkUiSettings;
|
||||||
|
|
||||||
mSettingsUi->setupUi(mSettingsWidget);
|
ui->setupUi(mSettingsWidget);
|
||||||
|
|
||||||
mMainLay->addWidget(mMainArea);
|
mMainLay->addWidget(mMainArea);
|
||||||
|
|
||||||
@@ -23,6 +26,25 @@ namespace SpkUi
|
|||||||
CFG->BindField("url/repo", &this->mRepoListUrl,
|
CFG->BindField("url/repo", &this->mRepoListUrl,
|
||||||
"https://d.store.deepinos.org.cn/store/server.list");
|
"https://d.store.deepinos.org.cn/store/server.list");
|
||||||
|
|
||||||
|
mBytesDownloads = mBytesResource = -1;
|
||||||
|
|
||||||
|
connect(&mFwResourceClean, &QFutureWatcher<void>::finished,
|
||||||
|
this, &SpkPageSettings::CleanedResource);
|
||||||
|
connect(&mFwResourceCount, &QFutureWatcher<void>::finished,
|
||||||
|
this, &SpkPageSettings::CountFinishResource);
|
||||||
|
connect(&mFwDownloadClean, &QFutureWatcher<void>::finished,
|
||||||
|
this, &SpkPageSettings::CleanedDownload);
|
||||||
|
connect(&mFwDownloadCount, &QFutureWatcher<void>::finished,
|
||||||
|
this, &SpkPageSettings::CountFinishDownload);
|
||||||
|
connect(ui->btnViewDownloadedContent, &QPushButton::clicked,
|
||||||
|
this, &SpkPageSettings::on_btnViewDownloadedContent_clicked);
|
||||||
|
connect(ui->btnViewResourceCache, &QPushButton::clicked,
|
||||||
|
this, &SpkPageSettings::on_btnViewResourceCache_clicked);
|
||||||
|
connect(ui->btnCleanDownloadedContent, &QPushButton::clicked,
|
||||||
|
this, &SpkPageSettings::on_btnCleanDownloadedContent_clicked);
|
||||||
|
connect(ui->btnCleanResourceCache, &QPushButton::clicked,
|
||||||
|
this, &SpkPageSettings::on_btnCleanResourceCache_clicked);
|
||||||
|
|
||||||
SetupUi();
|
SetupUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,8 +55,6 @@ namespace SpkUi
|
|||||||
|
|
||||||
void SpkPageSettings::SetupUi()
|
void SpkPageSettings::SetupUi()
|
||||||
{
|
{
|
||||||
auto ui = mSettingsUi;
|
|
||||||
|
|
||||||
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
||||||
ui->lblCleanup->setObjectName("styConfTitle");
|
ui->lblCleanup->setObjectName("styConfTitle");
|
||||||
ui->lblAdvanced->setObjectName("styConfTitle");
|
ui->lblAdvanced->setObjectName("styConfTitle");
|
||||||
@@ -45,8 +65,6 @@ namespace SpkUi
|
|||||||
|
|
||||||
void SpkPageSettings::ReadConfiguration()
|
void SpkPageSettings::ReadConfiguration()
|
||||||
{
|
{
|
||||||
auto ui = mSettingsUi;
|
|
||||||
|
|
||||||
ui->spnConcurrentResDownloads->setValue(CFG->ReadField("resource/concurrent", 5).toInt());
|
ui->spnConcurrentResDownloads->setValue(CFG->ReadField("resource/concurrent", 5).toInt());
|
||||||
ui->edtApiUrl->setText(CFG->ReadField("url/api", "").toString());
|
ui->edtApiUrl->setText(CFG->ReadField("url/api", "").toString());
|
||||||
ui->edtResourceUrl->setText(CFG->ReadField("url/res", "").toString());
|
ui->edtResourceUrl->setText(CFG->ReadField("url/res", "").toString());
|
||||||
@@ -60,8 +78,6 @@ namespace SpkUi
|
|||||||
|
|
||||||
void SpkPageSettings::SaveConfiguration()
|
void SpkPageSettings::SaveConfiguration()
|
||||||
{
|
{
|
||||||
auto ui = mSettingsUi;
|
|
||||||
|
|
||||||
CFG->SetSettings("resource/concurrent", ui->spnConcurrentResDownloads->value());
|
CFG->SetSettings("resource/concurrent", ui->spnConcurrentResDownloads->value());
|
||||||
CFG->SetField("url/api", ui->edtApiUrl->text());
|
CFG->SetField("url/api", ui->edtApiUrl->text());
|
||||||
CFG->SetField("url/res", ui->edtResourceUrl->text());
|
CFG->SetField("url/res", ui->edtResourceUrl->text());
|
||||||
@@ -69,7 +85,6 @@ namespace SpkUi
|
|||||||
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
|
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
|
||||||
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
||||||
CFG->SetField("url/repo", ui->edtRepoListUrl->text());
|
CFG->SetField("url/repo", ui->edtRepoListUrl->text());
|
||||||
|
|
||||||
if(!CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText()))
|
if(!CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText()))
|
||||||
SpkMsgBox::StaticExec(tr("Cannot change distribution servers.\n"
|
SpkMsgBox::StaticExec(tr("Cannot change distribution servers.\n"
|
||||||
"There's probably still downloads going on."),
|
"There's probably still downloads going on."),
|
||||||
@@ -83,8 +98,128 @@ namespace SpkUi
|
|||||||
QMessageBox::Warning);
|
QMessageBox::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::CountCleaning()
|
||||||
|
{
|
||||||
|
ui->lblSizeDownloadedContent->setText(tr("Counting..."));
|
||||||
|
ui->lblSizeResourceCache->setText(tr("Counting..."));
|
||||||
|
auto futureDownload = QtConcurrent::run([&]()
|
||||||
|
{
|
||||||
|
QDirIterator itr(ui->edtDownloadPath->text().replace('*', QDir::homePath()),
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
if(mMutDownload.tryLock(0))
|
||||||
|
{
|
||||||
|
int64_t size = 0;
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
QFile f(itr.next());
|
||||||
|
size += f.size();
|
||||||
|
}
|
||||||
|
mBytesDownloads = size;
|
||||||
|
mMutDownload.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
auto futureResource = QtConcurrent::run([&]()
|
||||||
|
{
|
||||||
|
QDirIterator itr(ui->edtResourceCachePath->text().replace('*', QDir::homePath()),
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
if(mMutResource.tryLock((0)))
|
||||||
|
{
|
||||||
|
int64_t size = 0;
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
QFile f(itr.next());
|
||||||
|
size += f.size();
|
||||||
|
}
|
||||||
|
mBytesResource = size;
|
||||||
|
mMutResource.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mFwDownloadCount.setFuture(futureDownload);
|
||||||
|
mFwResourceCount.setFuture(futureResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::CleanedResource()
|
||||||
|
{
|
||||||
|
ui->lblSizeResourceCache->setText(tr("Cleaned"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::CleanedDownload()
|
||||||
|
{
|
||||||
|
ui->lblSizeDownloadedContent->setText(tr("Cleaned"));
|
||||||
|
}
|
||||||
|
|
||||||
void SpkPageSettings::Activated()
|
void SpkPageSettings::Activated()
|
||||||
{
|
{
|
||||||
ReadConfiguration();
|
ReadConfiguration();
|
||||||
|
CountCleaning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::CountFinishResource()
|
||||||
|
{
|
||||||
|
if(mBytesResource >= 0)
|
||||||
|
ui->lblSizeResourceCache->setText(SpkUtils::BytesToSize(mBytesResource));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::CountFinishDownload()
|
||||||
|
{
|
||||||
|
if(mBytesDownloads >= 0)
|
||||||
|
ui->lblSizeDownloadedContent->setText(SpkUtils::BytesToSize(mBytesDownloads));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::on_btnViewResourceCache_clicked()
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl(ui->edtResourceCachePath->text().replace('*', QDir::homePath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpkPageSettings::on_btnViewDownloadedContent_clicked()
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl(ui->edtDownloadPath->text().replace('*', QDir::homePath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SpkPageSettings::on_btnCleanResourceCache_clicked()
|
||||||
|
{
|
||||||
|
ui->lblSizeResourceCache->setText(tr("Cleaning..."));
|
||||||
|
auto future = QtConcurrent::run([&]()
|
||||||
|
{
|
||||||
|
QDirIterator itr(ui->edtResourceCachePath->text().replace('*', QDir::homePath()),
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
if(mMutDownload.tryLock(0))
|
||||||
|
{
|
||||||
|
int64_t size = 0;
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
QFile f(itr.next());
|
||||||
|
f.remove();
|
||||||
|
}
|
||||||
|
mBytesDownloads = size;
|
||||||
|
mMutDownload.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mFwResourceClean.setFuture(future);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SpkPageSettings::on_btnCleanDownloadedContent_clicked()
|
||||||
|
{
|
||||||
|
ui->lblSizeDownloadedContent->setText(tr("Cleaning..."));
|
||||||
|
auto futureDownload = QtConcurrent::run([&]()
|
||||||
|
{
|
||||||
|
QDirIterator itr(ui->edtDownloadPath->text().replace('*', QDir::homePath()),
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
if(mMutDownload.tryLock(0))
|
||||||
|
{
|
||||||
|
int64_t size = 0;
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
QFile f(itr.next());
|
||||||
|
f.remove();
|
||||||
|
}
|
||||||
|
mBytesDownloads = size;
|
||||||
|
mMutDownload.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mFwDownloadClean.setFuture(futureDownload);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,7 +236,7 @@
|
|||||||
<number>-1</number>
|
<number>-1</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Download path</string>
|
<string>Download path*</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -87,4 +87,6 @@ void SpkStretchLayout::setGeometry(const QRect &rect)
|
|||||||
(i / countPerLine) * (size.height() + spacing()) + spc + origin.y());
|
(i / countPerLine) * (size.height() + spacing()) + spc + origin.y());
|
||||||
o->setGeometry(geo);
|
o->setGeometry(geo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// qDebug() << rect;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
#include <QMutex>
|
||||||
#include "page/spkpagebase.h"
|
#include "page/spkpagebase.h"
|
||||||
#include "ui_settings.h"
|
#include "ui_settings.h"
|
||||||
|
|
||||||
@@ -20,17 +22,35 @@ namespace SpkUi
|
|||||||
void ReadConfiguration();
|
void ReadConfiguration();
|
||||||
void SaveConfiguration();
|
void SaveConfiguration();
|
||||||
|
|
||||||
|
void CountCleaning();
|
||||||
|
|
||||||
virtual void Activated() override;
|
virtual void Activated() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void on_btnCleanDownloadedContent_clicked();
|
||||||
|
void on_btnCleanResourceCache_clicked();
|
||||||
|
void on_btnViewDownloadedContent_clicked();
|
||||||
|
void on_btnViewResourceCache_clicked();
|
||||||
|
|
||||||
|
void CountFinishResource();
|
||||||
|
void CountFinishDownload();
|
||||||
|
void CleanedResource();
|
||||||
|
void CleanedDownload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScrollArea *mMainArea;
|
QScrollArea *mMainArea;
|
||||||
QVBoxLayout *mMainLay;
|
QVBoxLayout *mMainLay;
|
||||||
QWidget *mSettingsWidget;
|
QWidget *mSettingsWidget;
|
||||||
Ui::SpkUiSettings *mSettingsUi;
|
Ui::SpkUiSettings *ui;
|
||||||
|
|
||||||
QString mRepoListUrl;
|
QString mRepoListUrl;
|
||||||
|
|
||||||
|
QFutureWatcher<void> mFwResourceCount,
|
||||||
|
mFwDownloadCount,
|
||||||
|
mFwResourceClean,
|
||||||
|
mFwDownloadClean;
|
||||||
|
QMutex mMutResource, mMutDownload;
|
||||||
|
int64_t mBytesResource, mBytesDownloads;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
36
lang/zh.ts
36
lang/zh.ts
@@ -408,7 +408,7 @@ Right now we are not just a Chinese group. We are discovering our way into more
|
|||||||
<message>
|
<message>
|
||||||
<location filename="../gui/spkimgviewer.cpp" line="23"/>
|
<location filename="../gui/spkimgviewer.cpp" line="23"/>
|
||||||
<source>Image Preview</source>
|
<source>Image Preview</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation>图片预览</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
@@ -798,29 +798,47 @@ to use terminal for program output.</source>
|
|||||||
<context>
|
<context>
|
||||||
<name>SpkUi::SpkPageSettings</name>
|
<name>SpkUi::SpkPageSettings</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/spkpagesettings.cpp" line="74"/>
|
<location filename="../gui/page/spkpagesettings.cpp" line="89"/>
|
||||||
<source>Cannot change distribution servers.
|
<source>Cannot change distribution servers.
|
||||||
There's probably still downloads going on.</source>
|
There's probably still downloads going on.</source>
|
||||||
<translation>无法更改分发服务器。
|
<translation>无法更改分发服务器。
|
||||||
可能是因为还有下载正在进行。</translation>
|
可能是因为还有下载正在进行。</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/spkpagesettings.cpp" line="76"/>
|
<location filename="../gui/page/spkpagesettings.cpp" line="91"/>
|
||||||
<source>Cannot set distribution server</source>
|
<source>Cannot set distribution server</source>
|
||||||
<translation>无法设置分发服务器</translation>
|
<translation>无法设置分发服务器</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/spkpagesettings.cpp" line="80"/>
|
<location filename="../gui/page/spkpagesettings.cpp" line="95"/>
|
||||||
<source>Auto mode can only be used when DDE plugin is loaded.
|
<source>Auto mode can only be used when DDE plugin is loaded.
|
||||||
Option change is not applied.</source>
|
Option change is not applied.</source>
|
||||||
<translation>自动模式只能在DDE插件加载时使用。
|
<translation>自动模式只能在DDE插件加载时使用。
|
||||||
选项更改未应用。</translation>
|
选项更改未应用。</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/spkpagesettings.cpp" line="82"/>
|
<location filename="../gui/page/spkpagesettings.cpp" line="97"/>
|
||||||
<source>Cannot set theme mode</source>
|
<source>Cannot set theme mode</source>
|
||||||
<translation>无法设置主题模式</translation>
|
<translation>无法设置主题模式</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="103"/>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="104"/>
|
||||||
|
<source>Counting...</source>
|
||||||
|
<translation>正在统计……</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="143"/>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="148"/>
|
||||||
|
<source>Cleaned</source>
|
||||||
|
<translation>已清理</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="182"/>
|
||||||
|
<location filename="../gui/page/spkpagesettings.cpp" line="205"/>
|
||||||
|
<source>Cleaning...</source>
|
||||||
|
<translation>清理中……</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>SpkUi::SpkPopup</name>
|
<name>SpkUi::SpkPopup</name>
|
||||||
@@ -939,11 +957,15 @@ Option change is not applied.</source>
|
|||||||
<source>Manual</source>
|
<source>Manual</source>
|
||||||
<translation>手动</translation>
|
<translation>手动</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Download path</source>
|
||||||
|
<translation type="vanished">下载路径</translation>
|
||||||
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/ui/settings.ui" line="239"/>
|
<location filename="../gui/page/ui/settings.ui" line="239"/>
|
||||||
<location filename="../build/ui_settings.h" line="400"/>
|
<location filename="../build/ui_settings.h" line="400"/>
|
||||||
<source>Download path</source>
|
<source>Download path*</source>
|
||||||
<translation>下载路径</translation>
|
<translation>下载路径*</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/page/ui/settings.ui" line="246"/>
|
<location filename="../gui/page/ui/settings.ui" line="246"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user