跟随到5.2

This commit is contained in:
shenmo 2020-07-13 19:26:09 +08:00
parent 892766470c
commit b1c2b1bbc6
7 changed files with 203 additions and 82 deletions

View File

@ -17,7 +17,6 @@ downloadlist::downloadlist(QWidget *parent) :
ui->label_filename->hide(); ui->label_filename->hide();
ui->pushButton->hide(); ui->pushButton->hide();
ui->pushButton_3->hide(); ui->pushButton_3->hide();
ui->label->setStyleSheet("color:#000000");
} }
downloadlist::~downloadlist() downloadlist::~downloadlist()
@ -29,7 +28,7 @@ void downloadlist::setValue(long long value)
{ {
ui->progressBar->setValue(value); ui->progressBar->setValue(value);
ui->label_2->setText(QString::number((double)value/100)+"% ("+speed+")"); ui->label_2->setText(QString::number((double)value/100)+"% ("+speed+")");
if(ui->label_2->text()=="100%"){ if(ui->label_2->text().left(4)=="100%"){
ui->label_2->setText("已完成,等待安装"); ui->label_2->setText("已完成,等待安装");
} }
} }
@ -56,18 +55,7 @@ void downloadlist::readyInstall()
ui->pushButton->setEnabled(true); ui->pushButton->setEnabled(true);
ui->pushButton->show(); ui->pushButton->show();
ui->pushButton_2->hide(); ui->pushButton_2->hide();
system("notify-send \""+ui->label->text().toUtf8()+"下载完成,等待安装\"" +" --icon=/tmp/deepin-community-store/icon_"+QString::number(num).toUtf8()+".png"); system("notify-send \""+ui->label->text().toUtf8()+"下载完成,等待安装\"" +" --icon=/tmp/spark-store/icon_"+QString::number(num).toUtf8()+".png");
}
}
void downloadlist::choose(bool isChoosed)
{
if(isChoosed){
ui->label->setStyleSheet("color:#FFFFFF");
ui->label_2->setStyleSheet("color:#FFFFFF");
}else {
ui->label->setStyleSheet("color:#000000");
ui->label_2->setStyleSheet("color:#000000");
} }
} }
@ -96,14 +84,14 @@ void downloadlist::on_pushButton_clicked()
if(!isInstall){ if(!isInstall){
isInstall=true; isInstall=true;
ui->pushButton->setEnabled(false); ui->pushButton->setEnabled(false);
qDebug()<<"/tmp/deepin-community-store/"+ui->label_filename->text().toUtf8(); qDebug()<<"/tmp/spark-store/"+ui->label_filename->text().toUtf8();
ui->label_2->setText("正在安装,请稍候"); ui->label_2->setText("正在安装,请稍候");
QtConcurrent::run([=](){ QtConcurrent::run([=](){
QProcess installer; QProcess installer;
if(reinstall){ if(reinstall){
installer.start("pkexec ssinstall /tmp/deepin-community-store/"+ui->label_filename->text().toUtf8()); installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
}else { }else {
installer.start("pkexec ssinstall /tmp/deepin-community-store/"+ui->label_filename->text().toUtf8()); installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
} }
installer.waitForFinished(); installer.waitForFinished();
@ -130,15 +118,22 @@ void downloadlist::on_pushButton_clicked()
ui->label_2->setText("安装完成"); ui->label_2->setText("安装完成");
ui->pushButton_3->show(); ui->pushButton_3->show();
}else { }else {
ui->pushButton->hide(); ui->pushButton->show();
ui->label_2->setText("安装出现错误"); ui->pushButton->setEnabled(true);
ui->pushButton->setText("重装");
ui->label_2->setText("安装出现错误,可重新安装");
ui->pushButton_3->show(); ui->pushButton_3->show();
} }
if(notRoot){ if(notRoot){
ui->label_2->setText("安装被终止"); ui->label_2->setText("安装被终止,可重新安装");
ui->pushButton->setEnabled(true); ui->pushButton->setEnabled(true);
ui->pushButton->show();
ui->pushButton_3->hide();
} }
downloadlist::isInstall=false;
}); });
qDebug()<<ui->label_filename->text().toUtf8(); qDebug()<<ui->label_filename->text().toUtf8();
} }

View File

@ -19,7 +19,6 @@ public:
void setName(QString); void setName(QString);
QString getName(); QString getName();
void readyInstall(); void readyInstall();
void choose(bool);
bool free; bool free;
void setFileName(QString); void setFileName(QString);
void seticon(const QPixmap); void seticon(const QPixmap);

View File

@ -10,6 +10,12 @@
<height>54</height> <height>54</height>
</rect> </rect>
</property> </property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>54</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>

View File

@ -10,7 +10,7 @@ int main(int argc, char *argv[])
a.setAttribute(Qt::AA_UseHighDpiPixmaps); a.setAttribute(Qt::AA_UseHighDpiPixmaps);
a.loadTranslator(); a.loadTranslator();
a.setOrganizationName("community"); a.setOrganizationName("community");
a.setApplicationVersion(DApplication::buildVersion("1.0-beta5")); a.setApplicationVersion(DApplication::buildVersion("1.0-beta5.1"));
a.setApplicationAcknowledgementPage("https://gitee.com/deepin-community-store/deepin-community-store"); a.setApplicationAcknowledgementPage("https://gitee.com/deepin-community-store/deepin-community-store");
a.setProductIcon(QIcon::fromTheme("spark-store")); //设置Logo a.setProductIcon(QIcon::fromTheme("spark-store")); //设置Logo
a.setProductName("Spark应用商店"); a.setProductName("Spark应用商店");

View File

@ -24,14 +24,17 @@ Widget::Widget(QWidget *parent) :
{ {
QString serverUrl; QString serverUrl;
std::fstream server; std::fstream server;
ui->setupUi(this); ui->setupUi(this);
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);//用来激活接受linkClicked信号 ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);//用来激活接受linkClicked信号
ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true); ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
ui->listWidget->hide(); ui->listWidget->hide();
ui->label_setting1->hide(); ui->label_setting1->hide();
ui->pushButton_5->hide();
ui->line1_widget->setStyleSheet("background-color:#808080");
ui->line2_widget->setStyleSheet("background-color:#808080");
manager = new QNetworkAccessManager(this); manager = new QNetworkAccessManager(this);
//初始化菜单数组
left_list[0]=ui->menu_btn_main;left_menu_bg[0]=ui->menu_bg_main; left_list[0]=ui->menu_btn_main;left_menu_bg[0]=ui->menu_bg_main;
left_list[1]=ui->menu_btn_network;left_menu_bg[1]=ui->menu_bg_network; left_list[1]=ui->menu_btn_network;left_menu_bg[1]=ui->menu_bg_network;
left_list[2]=ui->menu_btn_chat;left_menu_bg[2]=ui->menu_bg_chat; left_list[2]=ui->menu_btn_chat;left_menu_bg[2]=ui->menu_bg_chat;
@ -47,30 +50,25 @@ Widget::Widget(QWidget *parent) :
left_list[12]=ui->menu_btn_theme;left_menu_bg[12]=ui->menu_bg_theme; left_list[12]=ui->menu_btn_theme;left_menu_bg[12]=ui->menu_bg_theme;
left_list[13]=ui->menu_btn_download;left_menu_bg[13]=ui->menu_bg_download; left_list[13]=ui->menu_btn_download;left_menu_bg[13]=ui->menu_bg_download;
left_list[14]=ui->menu_btn_settings;left_menu_bg[14]=ui->menu_bg_settings; left_list[14]=ui->menu_btn_settings;left_menu_bg[14]=ui->menu_bg_settings;
server.open(QDir::homePath().toUtf8()+"/.config/deepin-community-store/server.list",std::ios::in);
// system("mkdir /etc/deepin-community-store/");
// server.open("/etc/deepin-community-store/server.list",std::ios::in);
std::string lineTmp;
server.open(QDir::homePath().toUtf8()+"/.config/spark-store/server.list",std::ios::in);
std::string lineTmp;
if(server){ if(server){
while (getline(server,lineTmp)) { while (getline(server,lineTmp)) {
ui->comboBox_server->addItem(QString::fromStdString(lineTmp)); ui->comboBox_server->addItem(QString::fromStdString(lineTmp));
} }
}else { }else {
ui->comboBox_server->addItem("http://dcstore.shenmo.tech/"); ui->comboBox_server->addItem("http://store.jerrywang.top/");
} }
QSettings readConfig(QDir::homePath()+"/.config/deepin-community-store/config.ini",QSettings::IniFormat); QSettings readConfig(QDir::homePath()+"/.config/spark-store/config.ini",QSettings::IniFormat);
if(readConfig.value("server/choose").toString()!=""){ if(readConfig.value("server/choose").toString()!=""){
ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString()); ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString());
serverUrl=readConfig.value("server/choose").toString(); serverUrl=readConfig.value("server/choose").toString();
}else { }else {
serverUrl="http://dcstore.shenmo.tech/"; serverUrl="http://store.jerrywang.top/";
} }
configCanSeve=true;
qDebug()<<serverUrl;
menuUrl[0]=serverUrl + "store/#/"; menuUrl[0]=serverUrl + "store/#/";
// menuUrl[0]="http://127.0.0.1:8000/#/relations";
menuUrl[1]=serverUrl + "store/#/network/"; menuUrl[1]=serverUrl + "store/#/network/";
menuUrl[2]=serverUrl + "store/#/relations"; menuUrl[2]=serverUrl + "store/#/relations";
menuUrl[3]=serverUrl + "store/#/musicandsound"; menuUrl[3]=serverUrl + "store/#/musicandsound";
@ -83,21 +81,23 @@ Widget::Widget(QWidget *parent) :
menuUrl[10]=serverUrl + "store/#/tools/"; menuUrl[10]=serverUrl + "store/#/tools/";
menuUrl[11]=serverUrl + "store/#/others/"; menuUrl[11]=serverUrl + "store/#/others/";
menuUrl[12]=serverUrl + "store/#/themes"; menuUrl[12]=serverUrl + "store/#/themes";
configCanSeve=true;
qDebug()<<serverUrl;
ui->webView->setUrl(menuUrl[0]); ui->webView->setUrl(menuUrl[0]);
for (int i =0; i<15;i++){ for (int i =0; i<15;i++){
download_list[i].num=i; download_list[i].num=i;
} }
//分界线
QGraphicsOpacityEffect *opacityEffect_1=new QGraphicsOpacityEffect; QGraphicsOpacityEffect *opacityEffect_1=new QGraphicsOpacityEffect;
QGraphicsOpacityEffect *opacityEffect_2=new QGraphicsOpacityEffect; QGraphicsOpacityEffect *opacityEffect_2=new QGraphicsOpacityEffect;
ui->line1_widget->setStyleSheet("background-color:#808080");
ui->line2_widget->setStyleSheet("background-color:#808080");
opacityEffect_1->setOpacity(0.2); opacityEffect_1->setOpacity(0.2);
opacityEffect_2->setOpacity(0.2); opacityEffect_2->setOpacity(0.2);
ui->line1_widget->setGraphicsEffect(opacityEffect_1); ui->line1_widget->setGraphicsEffect(opacityEffect_1);
ui->line2_widget->setGraphicsEffect(opacityEffect_2); ui->line2_widget->setGraphicsEffect(opacityEffect_2);
connect(ui->webView->page(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT([=](){qDebug()<<" ";}));
download_speed.setInterval(1000); download_speed.setInterval(1000);
download_speed.start(); download_speed.start();
//计算显示网速
connect(&download_speed,&QTimer::timeout,[=](){ connect(&download_speed,&QTimer::timeout,[=](){
if(isdownload){ if(isdownload){
size1=download_size; size1=download_size;
@ -105,13 +105,13 @@ Widget::Widget(QWidget *parent) :
double bspeed; double bspeed;
bspeed=size1-size2; bspeed=size1-size2;
if(bspeed<1024){ if(bspeed<1024){
theSpeed=QString::number(bspeed)+"B"; theSpeed=QString::number(bspeed)+"B/s";
}else if (bspeed<(1024*1024)) { }else if (bspeed<(1024*1024)) {
theSpeed=QString::number(0.01*int(100*(bspeed/1024)))+"KB"; theSpeed=QString::number(0.01*int(100*(bspeed/1024)))+"KB/s";
}else if (bspeed<(1024*1024*1024)) { }else if (bspeed<(1024*1024*1024)) {
theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024))))+"MB"; theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024))))+"MB/s";
}else { }else {
theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024*1024))))+"GB"; theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024*1024))))+"GB/s";
} }
download_list[nowDownload-1].setSpeed(theSpeed); download_list[nowDownload-1].setSpeed(theSpeed);
size2=download_size; size2=download_size;
@ -126,7 +126,6 @@ Widget::Widget(QWidget *parent) :
ui->label_aptserver->setText("不存在"); ui->label_aptserver->setText("不存在");
} }
aptserver.close(); aptserver.close();
ui->pushButton_5->hide();
} }
@ -142,7 +141,7 @@ void Widget::on_webView_loadStarted()
//判断,如果末尾是/就直接访问如果是app.json就打开详情页 //判断,如果末尾是/就直接访问如果是app.json就打开详情页
if(arg1.path().right(8)=="app.json"){ if(arg1.path().right(8)=="app.json"){
load.cancel();//打开并发加载线程前关闭正在执行的线程 load.cancel();//打开并发加载线程前关闭正在执行的线程
QPixmap pixmap_null;//一个空的图片指针,用来清空先有内容 QPixmap pixmap_null;//一个空的图片,用来清空现有内容
ui->label_appicon->setPixmap(pixmap_null); ui->label_appicon->setPixmap(pixmap_null);
ui->screen_1->setPixmap(pixmap_null); ui->screen_1->setPixmap(pixmap_null);
ui->screen_2->setPixmap(pixmap_null); ui->screen_2->setPixmap(pixmap_null);
@ -174,10 +173,9 @@ void Widget::loadappinfo(QUrl arg1)
ui->label_show->setText("正在加载,请稍候"); ui->label_show->setText("正在加载,请稍候");
ui->label_show->show(); ui->label_show->show();
QProcess get_json; QProcess get_json;
QDir dir; QDir dir("/tmp");
dir.cd("/tmp"); dir.mkdir("spark-store");
dir.mkdir("deepin-community-store"); QDir::setCurrent("/tmp/spark-store");
QDir::setCurrent("/tmp/deepin-community-store");
get_json.start("wget -O app.json "+arg1.toString()); get_json.start("wget -O app.json "+arg1.toString());
get_json.waitForFinished(); get_json.waitForFinished();
QFile app_json("app.json"); QFile app_json("app.json");
@ -300,6 +298,7 @@ void Widget::chooseLeftMenu(int index)
left_menu_bg[index]->setStyleSheet("background-color:#0081FF;border-radius:8"); left_menu_bg[index]->setStyleSheet("background-color:#0081FF;border-radius:8");
if(index<=12){ if(index<=12){
ui->webView->setUrl(menuUrl[index]); ui->webView->setUrl(menuUrl[index]);
qDebug()<<menuUrl[index];
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
}else if (index==13) { }else if (index==13) {
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
@ -308,6 +307,8 @@ void Widget::chooseLeftMenu(int index)
} }
} }
void Widget::on_pushButton_clicked() void Widget::on_pushButton_clicked()
{ {
on_menu_btn_download_clicked(); on_menu_btn_download_clicked();
@ -317,12 +318,13 @@ void Widget::on_pushButton_clicked()
download_list[allDownload-1].pkgName=pkgName; download_list[allDownload-1].pkgName=pkgName;
if(fileName.isEmpty()) if(fileName.isEmpty())
{ {
fileName = "index.html"; system("notify-send 获取失败 --icon=spark-store");
return;
} }
download_list[allDownload-1].setParent(ui->listWidget); download_list[allDownload-1].setParent(ui->listWidget);
QListWidgetItem *item=new QListWidgetItem(ui->listWidget); QListWidgetItem *item=new QListWidgetItem(ui->listWidget);
item->setSizeHint(download_list[allDownload-1].size()); item->setSizeHint(download_list[allDownload-1].size());
item->setFlags(item->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
ui->listWidget->setItemWidget(item,&download_list[allDownload-1]); ui->listWidget->setItemWidget(item,&download_list[allDownload-1]);
urList.append(url); urList.append(url);
qDebug()<<"下载:"<<url; qDebug()<<"下载:"<<url;
@ -410,14 +412,7 @@ void Widget::httpFinished() //完成下载
startRequest(urList.at(nowDownload-1)); startRequest(urList.at(nowDownload-1));
} }
} }
void Widget::on_listWidget_currentRowChanged(int currentRow)
{
qDebug()<<currentRow;
for (int i=0;i<allDownload;i++) {
download_list[i].choose(false);
}
download_list[currentRow].choose(true);
}
//菜单切换逻辑 //菜单切换逻辑
void Widget::on_menu_btn_main_clicked() //主页 void Widget::on_menu_btn_main_clicked() //主页
{ {
@ -478,6 +473,18 @@ void Widget::on_menu_btn_download_clicked()
void Widget::on_menu_btn_settings_clicked() void Widget::on_menu_btn_settings_clicked()
{ {
chooseLeftMenu(14); chooseLeftMenu(14);
quint64 tmp_size=dirFileSize(QString::fromUtf8(TMP_PATH));
QString tmp_size_str;
if(tmp_size<1024){
tmp_size_str=QString::number(tmp_size)+"B";
}else if (tmp_size<(1024*1024)) {
tmp_size_str=QString::number(0.01*int(100*(tmp_size/1024)))+"KB";
}else if (tmp_size<(1024*1024*1024)) {
tmp_size_str=QString::number(0.01*int(100*(tmp_size/(1024*1024))))+"MB";
}else {
tmp_size_str=QString::number(0.01*int(100*(tmp_size/(1024*1024*1024))))+"GB";
}
ui->tmp_size_ui->setText(tmp_size_str);
} }
void Widget::on_pushButton_2_clicked() void Widget::on_pushButton_2_clicked()
{ {
@ -494,38 +501,31 @@ void Widget::on_webView_loadFinished()
ui->label_show->hide(); ui->label_show->hide();
} }
} }
void Widget::on_comboBox_server_currentIndexChanged(const QString &arg1) void Widget::on_comboBox_server_currentIndexChanged(const QString &arg1)
{ {
if(configCanSeve){ if(configCanSeve){
ui->label_setting1->show(); ui->label_setting1->show();
QSettings *setConfig=new QSettings(QDir::homePath()+"/.config/deepin-community-store/config.ini",QSettings::IniFormat); QSettings *setConfig=new QSettings(QDir::homePath()+"/.config/spark-store/config.ini",QSettings::IniFormat);
qDebug()<<arg1; qDebug()<<arg1;
setConfig->setValue("server/choose",arg1); setConfig->setValue("server/choose",arg1);
} }
} }
void Widget::on_pushButton_3_clicked() void Widget::on_pushButton_3_clicked()
{ {
QtConcurrent::run([=](){ QtConcurrent::run([=](){
ui->pushButton_3->setEnabled(false); ui->pushButton_3->setEnabled(false);
ui->comboBox_server->clear(); ui->comboBox_server->clear();
system("rm "+QDir::homePath().toUtf8()+"/.config/deepin-community-store/server.list"); QFile::remove(QDir::homePath().toUtf8()+"/.config/spark-store/server.list");
system("wget -P "+QDir::homePath().toUtf8()+"/.config/deepin-community-store http://dcstore.shenmo.tech/store/server.list"); system("wget -P "+QDir::homePath().toUtf8()+"/.config/spark-store http://dcstore.shenmo.tech/store/server.list");
std::fstream server; std::fstream server;
server.open(QDir::homePath().toUtf8()+"/.config/deepin-community-store/server.list",std::ios::in); server.open(QDir::homePath().toUtf8()+"/.config/spark-store/server.list",std::ios::in);
std::string lineTmp; std::string lineTmp;
if(server){ if(server){
while (getline(server,lineTmp)) { while (getline(server,lineTmp)) {
ui->comboBox_server->addItem(QString::fromStdString(lineTmp)); ui->comboBox_server->addItem(QString::fromStdString(lineTmp));
} }
}else { }else {
ui->comboBox_server->addItem("http://dcstore.shenmo.tech/"); ui->comboBox_server->addItem("http://store.jerrywang.top/");
} }
ui->pushButton_3->setEnabled(true); ui->pushButton_3->setEnabled(true);
ui->comboBox_server->setCurrentIndex(0); ui->comboBox_server->setCurrentIndex(0);
@ -538,20 +538,21 @@ void Widget::on_pushButton_4_clicked()
ui->pushButton_4->setEnabled(false); ui->pushButton_4->setEnabled(false);
ui->label_aptserver->setText("请稍等,正在更新"); ui->label_aptserver->setText("请稍等,正在更新");
std::fstream sourcesList; std::fstream sourcesList;
system("mkdir /tmp/spark-store"); QDir tmpdir("/tmp");
sourcesList.open("/tmp/spark-store/sparkstore.list",std::ios::out); tmpdir.mkpath("spark-store");
sourcesList.open(QString::fromUtf8(TMP_PATH).toStdString()+"/sparkstore.list",std::ios::out);
if(sourcesList){ if(sourcesList){
sourcesList<<"deb [by-hash=force] "; sourcesList<<"deb [by-hash=force] ";
sourcesList<<QString::fromUtf8(ui->comboBox_server->currentText().toUtf8()).toStdString(); sourcesList<<QString::fromUtf8(ui->comboBox_server->currentText().toUtf8()).toStdString();
sourcesList<<" /"; sourcesList<<" /";
std::fstream update; std::fstream update;
update.open("/tmp/spark-store/update.sh",std::ios::out); update.open(QString::fromUtf8(TMP_PATH).toStdString()+"/update.sh",std::ios::out);
update<<"#!/bin/sh\n"; update<<"#!/bin/sh\n";
update<<"mv /tmp/spark-store/sparkstore.list /etc/apt/sources.list.d/sparkstore.list && apt update"; update<<"mv "+QString::fromUtf8(TMP_PATH).toStdString()+"/sparkstore.list /etc/apt/sources.list.d/sparkstore.list && apt update";
update.close(); update.close();
system("chmod +x /tmp/spark-store/update.sh"); system("chmod +x "+QString::fromUtf8(TMP_PATH).toUtf8()+"/update.sh");
QProcess runupdate; QProcess runupdate;
runupdate.start("pkexec /tmp/spark-store/update.sh"); runupdate.start("pkexec "+QString::fromUtf8(TMP_PATH)+"/update.sh");
runupdate.waitForFinished(); runupdate.waitForFinished();
qDebug()<<runupdate.readAllStandardError(); qDebug()<<runupdate.readAllStandardError();
QString error=QString::fromStdString(runupdate.readAllStandardError().toStdString()); QString error=QString::fromStdString(runupdate.readAllStandardError().toStdString());
@ -592,3 +593,38 @@ void Widget::on_pushButton_5_clicked()
system("notify-send 卸载完成 --icon=spark-store"); system("notify-send 卸载完成 --icon=spark-store");
}); });
} }
void Widget::on_pushButton_6_clicked()//清空临时缓存目录
{
QtConcurrent::run([=](){
ui->pushButton_6->setEnabled(false);
QDir tmpdir("/tmp/spark-store");
tmpdir.setFilter(QDir::Files);
int quantity=int(tmpdir.count());
for (int i=0;i<quantity;i++) {
tmpdir.remove(tmpdir[i]);
}
system("notify-send 已清除所有临时缓存 --icon=spark-store");
ui->pushButton_6->setEnabled(true);
on_menu_btn_settings_clicked();
});
}
quint64 Widget::dirFileSize(const QString &path)
{
QDir dir(path);
quint64 size = 0;
//dir.entryInfoList(QDir::Files)返回文件信息
foreach(QFileInfo fileInfo, dir.entryInfoList(QDir::Files))
{
//计算文件大小
size += fileInfo.size();
}
//dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot)返回所有子目录,并进行过滤
foreach(QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
//若存在子目录则递归调用dirFileSize()函数
size += dirFileSize(path + QDir::separator() + subDir);
}
return size;
}

View File

@ -12,7 +12,10 @@
#include <QFuture> #include <QFuture>
#include <QToolButton> #include <QToolButton>
#include <QTimer> #include <QTimer>
#define LIST_MAX 99 #define LIST_MAX 99
#define TMP_PATH "/tmp/spark-store"
namespace Ui { namespace Ui {
class Widget; class Widget;
} }
@ -32,6 +35,7 @@ public:
int isdownload=false; int isdownload=false;
void loadappinfo(QUrl); void loadappinfo(QUrl);
void chooseLeftMenu(int index); void chooseLeftMenu(int index);
quint64 dirFileSize(const QString &path);
QPixmap screen[5]; QPixmap screen[5];
QFuture<void> load; QFuture<void> load;
QTimer download_speed; QTimer download_speed;
@ -67,8 +71,6 @@ private slots:
void on_menu_btn_other_clicked(); void on_menu_btn_other_clicked();
void on_listWidget_currentRowChanged(int currentRow);
void on_pushButton_clicked(); void on_pushButton_clicked();
void on_pushButton_2_clicked(); void on_pushButton_2_clicked();
@ -89,6 +91,8 @@ private slots:
void on_pushButton_5_clicked(); void on_pushButton_5_clicked();
void on_pushButton_6_clicked();
public: public:
QUrl url; QUrl url;
bool isBusy=false; bool isBusy=false;

View File

@ -836,7 +836,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -934,8 +934,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>298</width> <width>781</width>
<height>814</height> <height>815</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_17"> <layout class="QVBoxLayout" name="verticalLayout_17">
@ -1172,8 +1172,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>351</width> <width>747</width>
<height>38</height> <height>325</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -1314,7 +1314,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>765</width> <width>765</width>
<height>662</height> <height>846</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_23"> <layout class="QVBoxLayout" name="verticalLayout_23">
@ -1457,6 +1457,87 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QWidget" name="widget_9" native="true">
<layout class="QVBoxLayout" name="verticalLayout_26">
<item>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>缓存目录</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_10" native="true">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="3">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>清空</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QLabel" name="label_12">
<property name="styleSheet">
<string notr="true">color:#808080</string>
</property>
<property name="text">
<string>因为这个目录位于/tmp下所以即使你不手动清空的话其也将在系统重启时自动清空。</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>目录大小:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="tmp_size_ui">
<property name="text">
<string>0B</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>目录位置:/tmp/spark-store</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QWidget" name="widget_2" native="true"> <widget class="QWidget" name="widget_2" native="true">
<layout class="QVBoxLayout" name="verticalLayout_25"> <layout class="QVBoxLayout" name="verticalLayout_25">