From dd0605d0ba8556c46fad298ff0a7efa914eea4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=9A=E5=AD=90?= Date: Sun, 11 Dec 2022 01:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E4=BA=AB=E5=92=8C=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8C=89=E9=92=AE=EF=BC=8C=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=92=8C=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E3=80=81=E8=AF=BB=E5=8F=96=E7=BC=93=E5=AD=98=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mainwindow-dtk.cpp | 14 ++--- src/pages/appintopage.cpp | 26 ++++++++++ src/pages/appintopage.h | 5 ++ src/pages/appintopage.ui | 8 +-- src/pages/settingspage.cpp | 103 ++++++++++++++++++++++++++++++++++++- src/pages/settingspage.h | 15 ++++++ 6 files changed, 159 insertions(+), 12 deletions(-) diff --git a/src/mainwindow-dtk.cpp b/src/mainwindow-dtk.cpp index 116a2f8..f760f83 100644 --- a/src/mainwindow-dtk.cpp +++ b/src/mainwindow-dtk.cpp @@ -37,7 +37,10 @@ MainWindow::MainWindow(QWidget *parent) menu->addAction(setting); ui->titlebar->setMenu(menu); - connect(setting, &QAction::triggered, this, [=]{switchPage(AppPageSettings);}); + connect(setting, &QAction::triggered, this, [=]{ + switchPage(AppPageSettings); + ui->settingspage->updateUI(); + }); //主题切换 connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType) { if (themeType == DGuiApplicationHelper::DarkType) { @@ -107,10 +110,6 @@ MainWindow::MainWindow(QWidget *parent) connect(backButtom, &QPushButton::clicked, [=]() { ui->stackedWidget->setCurrentIndex(pageHistory.at(pageHistory.count() - 2)); - if (pageHistory.at(pageHistory.count() - 1) == 3) { - ui->appintopage->clear(); - } - pageHistory.removeLast(); if (pageHistory.count() > 1) { backButtom->show(); @@ -139,7 +138,6 @@ MainWindow::MainWindow(QWidget *parent) ui->buttonGroup->buttons()[i]->setStyleSheet("QPushButton{qproperty-icon: url(data/images/userMangaer/teacher.png);}"); connect(ui->buttonGroup->buttons()[i], &QPushButton::toggled, [=](bool checked) { if (checked == true) { - ui->appintopage->clear(); updateUi(i); } }); @@ -169,7 +167,9 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->applistpage_1, &AppListPage::clicked, this, [=](QUrl spk) { openUrl(spk); }); - + connect(ui->settingspage, &SettingsPage::openUrl, this, [=](QUrl spk) { + openUrl(spk); + }); emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType()); } diff --git a/src/pages/appintopage.cpp b/src/pages/appintopage.cpp index ab5efe9..0ce91a2 100644 --- a/src/pages/appintopage.cpp +++ b/src/pages/appintopage.cpp @@ -51,6 +51,7 @@ void AppIntoPage::openUrl(QUrl url) { spk=url; SparkAPI *api=new SparkAPI(this); + clear(); connect(api,&SparkAPI::finishedObject,[=](QJsonObject appinfo){ info = appinfo; @@ -316,3 +317,28 @@ void AppIntoPage::on_pushButton_3_clicked() ui->pushButton_3->setEnabled(true); }); } + +void AppIntoPage::on_shareButton_clicked() +{ + qDebug() << "Share" << spk; + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(spk.toString()); +} + + +void AppIntoPage::on_updateButton_clicked() +{ + QString feedbackSpk = "spk://store/chat/store.spark-app.feedback"; + QFile actionSubmissionClientStatus("/opt/durapps/store.spark-app.feedback"); + if (actionSubmissionClientStatus.exists()) + { + qDebug() << "反馈器存在"; + QProcess::startDetached("sh /opt/durapps/store.spark-app.feedback/launch.sh"); + } + else{ + qDebug() << "反馈器不存在,跳转页面"; + openUrl(feedbackSpk); + } +} + diff --git a/src/pages/appintopage.h b/src/pages/appintopage.h index 91cbefb..905c2d9 100644 --- a/src/pages/appintopage.h +++ b/src/pages/appintopage.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "backend/sparkapi.h" #include "backend/image_show.h" #include "widgets/downloadlistwidget.h" @@ -29,6 +30,10 @@ private slots: void on_pushButton_3_clicked(); + void on_shareButton_clicked(); + + void on_updateButton_clicked(); + private: QJsonObject info; QPixmap iconpixmap; diff --git a/src/pages/appintopage.ui b/src/pages/appintopage.ui index 1d72151..04663ac 100644 --- a/src/pages/appintopage.ui +++ b/src/pages/appintopage.ui @@ -529,16 +529,16 @@ - + - PushButton + Share - + - PushButton + Request Update diff --git a/src/pages/settingspage.cpp b/src/pages/settingspage.cpp index 243d1d8..1f8d1cc 100644 --- a/src/pages/settingspage.cpp +++ b/src/pages/settingspage.cpp @@ -1,6 +1,6 @@ #include "settingspage.h" #include "ui_settingspage.h" - +bool SettingsPage::isdownload = false; SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent), ui(new Ui::SettingsPage) @@ -116,3 +116,104 @@ void SettingsPage::on_comboBox_server_currentIndexChanged(const QString &arg1) } } +void SettingsPage::setIsDownload(bool isdownload) +{ + SettingsPage::isdownload = isdownload; +} + +void SettingsPage::updateUI() +{ + if(isdownload) + { + ui->pushButton_clear->setEnabled(false); + } + else + { + ui->pushButton_clear->setEnabled(true); + } + // 显示缓存占用空间 + 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); +} + +quint64 SettingsPage::dirFileSize(const QString &path) +{ + QDir dir(path); + quint64 size = 0; + // dir.entryInfoList(QDir::Files); // 返回文件信息 + foreach(QFileInfo fileInfo, dir.entryInfoList(QDir::Files)) + { + // 计算文件大小 + size += quint64(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; +} + +void SettingsPage::on_pushButton_updateApt_clicked() +{ + QtConcurrent::run([=]() + { + ui->pushButton_updateApt->setEnabled(false); + ui->label_aptserver->setText(tr("Updating, please wait...")); + + emit openUrl(QUrl("spk://store/tools/spark-store")); + ui->label_aptserver->setText(tr("")); + + ui->pushButton_updateApt->setEnabled(true); + }); +} + + +void SettingsPage::on_pushButton_clear_clicked() +{ + QtConcurrent::run([=]() + { + ui->pushButton_clear->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]); + } + ui->pushButton_clear->setEnabled(true); + updateUI(); + }); +} + + +void SettingsPage::on_pushButton_clearWebCache_clicked() +{ + QtConcurrent::run([=]() + { + QString dataLocal = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + QDir cacheDir(dataLocal ); + cacheDir.removeRecursively(); + }); +} + diff --git a/src/pages/settingspage.h b/src/pages/settingspage.h index 15bde5f..9a1efcb 100644 --- a/src/pages/settingspage.h +++ b/src/pages/settingspage.h @@ -8,6 +8,8 @@ #include #include #include "../backend/sparkapi.h" +#define TMP_PATH "/tmp/spark-store" + namespace Ui { class SettingsPage; } @@ -17,6 +19,8 @@ class SettingsPage : public QWidget Q_OBJECT public: + static void setIsDownload(bool isdownload); + void updateUI(); explicit SettingsPage(QWidget *parent = nullptr); void setTheme(bool dark); ~SettingsPage(); @@ -26,11 +30,22 @@ private slots: void on_comboBox_server_currentIndexChanged(const QString &arg1); + void on_pushButton_updateApt_clicked(); + + void on_pushButton_clear_clicked(); + + void on_pushButton_clearWebCache_clicked(); + private: + static bool isdownload; bool configCanSave; + quint64 dirFileSize(const QString &path); void readServerList(); void initConfig(); Ui::SettingsPage *ui; + +signals: + void openUrl(QUrl spk); }; #endif // SETTINGSPAGE_H