mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 12:22:05 +08:00
实现垃圾文件计数和清理
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QMutexLocker>
|
||||
#include <QFutureWatcher>
|
||||
#include "spkutils.h"
|
||||
#include "page/spkpagesettings.h"
|
||||
#include "spkmsgbox.h"
|
||||
@@ -11,9 +14,9 @@ namespace SpkUi
|
||||
mMainArea = new QScrollArea();
|
||||
mMainLay = new QVBoxLayout(this);
|
||||
mSettingsWidget = new QWidget(this);
|
||||
mSettingsUi = new Ui::SpkUiSettings;
|
||||
ui = new Ui::SpkUiSettings;
|
||||
|
||||
mSettingsUi->setupUi(mSettingsWidget);
|
||||
ui->setupUi(mSettingsWidget);
|
||||
|
||||
mMainLay->addWidget(mMainArea);
|
||||
|
||||
@@ -23,6 +26,25 @@ namespace SpkUi
|
||||
CFG->BindField("url/repo", &this->mRepoListUrl,
|
||||
"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();
|
||||
}
|
||||
|
||||
@@ -33,8 +55,6 @@ namespace SpkUi
|
||||
|
||||
void SpkPageSettings::SetupUi()
|
||||
{
|
||||
auto ui = mSettingsUi;
|
||||
|
||||
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
||||
ui->lblCleanup->setObjectName("styConfTitle");
|
||||
ui->lblAdvanced->setObjectName("styConfTitle");
|
||||
@@ -45,8 +65,6 @@ namespace SpkUi
|
||||
|
||||
void SpkPageSettings::ReadConfiguration()
|
||||
{
|
||||
auto ui = mSettingsUi;
|
||||
|
||||
ui->spnConcurrentResDownloads->setValue(CFG->ReadField("resource/concurrent", 5).toInt());
|
||||
ui->edtApiUrl->setText(CFG->ReadField("url/api", "").toString());
|
||||
ui->edtResourceUrl->setText(CFG->ReadField("url/res", "").toString());
|
||||
@@ -60,8 +78,6 @@ namespace SpkUi
|
||||
|
||||
void SpkPageSettings::SaveConfiguration()
|
||||
{
|
||||
auto ui = mSettingsUi;
|
||||
|
||||
CFG->SetSettings("resource/concurrent", ui->spnConcurrentResDownloads->value());
|
||||
CFG->SetField("url/api", ui->edtApiUrl->text());
|
||||
CFG->SetField("url/res", ui->edtResourceUrl->text());
|
||||
@@ -69,7 +85,6 @@ namespace SpkUi
|
||||
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
|
||||
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
||||
CFG->SetField("url/repo", ui->edtRepoListUrl->text());
|
||||
|
||||
if(!CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText()))
|
||||
SpkMsgBox::StaticExec(tr("Cannot change distribution servers.\n"
|
||||
"There's probably still downloads going on."),
|
||||
@@ -83,8 +98,128 @@ namespace SpkUi
|
||||
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()
|
||||
{
|
||||
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>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Download path</string>
|
||||
<string>Download path*</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -49,7 +49,7 @@ QLayoutItem *SpkStretchLayout::itemAt(int i) const
|
||||
|
||||
QLayoutItem *SpkStretchLayout::takeAt(int i)
|
||||
{
|
||||
return i >=0 && i < mItems.size() ? mItems.takeAt(i) : nullptr;
|
||||
return i >= 0 && i < mItems.size() ? mItems.takeAt(i) : nullptr;
|
||||
}
|
||||
|
||||
void SpkStretchLayout::setGeometry(const QRect &rect)
|
||||
@@ -87,4 +87,6 @@ void SpkStretchLayout::setGeometry(const QRect &rect)
|
||||
(i / countPerLine) * (size.height() + spacing()) + spc + origin.y());
|
||||
o->setGeometry(geo);
|
||||
}
|
||||
|
||||
// qDebug() << rect;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFutureWatcher>
|
||||
#include <QMutex>
|
||||
#include "page/spkpagebase.h"
|
||||
#include "ui_settings.h"
|
||||
|
||||
@@ -20,17 +22,35 @@ namespace SpkUi
|
||||
void ReadConfiguration();
|
||||
void SaveConfiguration();
|
||||
|
||||
void CountCleaning();
|
||||
|
||||
virtual void Activated() override;
|
||||
|
||||
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:
|
||||
QScrollArea *mMainArea;
|
||||
QVBoxLayout *mMainLay;
|
||||
QWidget *mSettingsWidget;
|
||||
Ui::SpkUiSettings *mSettingsUi;
|
||||
Ui::SpkUiSettings *ui;
|
||||
|
||||
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>
|
||||
<location filename="../gui/spkimgviewer.cpp" line="23"/>
|
||||
<source>Image Preview</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>图片预览</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
@@ -798,29 +798,47 @@ to use terminal for program output.</source>
|
||||
<context>
|
||||
<name>SpkUi::SpkPageSettings</name>
|
||||
<message>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="74"/>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="89"/>
|
||||
<source>Cannot change distribution servers.
|
||||
There's probably still downloads going on.</source>
|
||||
<translation>无法更改分发服务器。
|
||||
可能是因为还有下载正在进行。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="76"/>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="91"/>
|
||||
<source>Cannot set distribution server</source>
|
||||
<translation>无法设置分发服务器</translation>
|
||||
</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.
|
||||
Option change is not applied.</source>
|
||||
<translation>自动模式只能在DDE插件加载时使用。
|
||||
选项更改未应用。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="82"/>
|
||||
<location filename="../gui/page/spkpagesettings.cpp" line="97"/>
|
||||
<source>Cannot set theme mode</source>
|
||||
<translation>无法设置主题模式</translation>
|
||||
</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>
|
||||
<name>SpkUi::SpkPopup</name>
|
||||
@@ -939,11 +957,15 @@ Option change is not applied.</source>
|
||||
<source>Manual</source>
|
||||
<translation>手动</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Download path</source>
|
||||
<translation type="vanished">下载路径</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../gui/page/ui/settings.ui" line="239"/>
|
||||
<location filename="../build/ui_settings.h" line="400"/>
|
||||
<source>Download path</source>
|
||||
<translation>下载路径</translation>
|
||||
<source>Download path*</source>
|
||||
<translation>下载路径*</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../gui/page/ui/settings.ui" line="246"/>
|
||||
|
||||
Reference in New Issue
Block a user