mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 04:42:03 +08:00
4.0
This commit is contained in:
295
src/pages/appintopage.cpp
Normal file
295
src/pages/appintopage.cpp
Normal file
@@ -0,0 +1,295 @@
|
||||
#include "appintopage.h"
|
||||
#include "ui_appintopage.h"
|
||||
AppIntoPage::AppIntoPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::AppIntoPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->listWidget->setViewMode(QListView::IconMode);
|
||||
ui->listWidget->setMovement(QListView::Static);
|
||||
ui->listWidget->setMaximumHeight(200);
|
||||
ui->listWidget->setFlow(QListView::TopToBottom);
|
||||
clear();
|
||||
}
|
||||
|
||||
void AppIntoPage::clear()
|
||||
{
|
||||
ui->tag_a2d->hide();
|
||||
ui->tag_uos->hide();
|
||||
ui->tag_dtk5->hide();
|
||||
ui->tag_deepin->hide();
|
||||
ui->tag_dwine2->hide();
|
||||
ui->tag_dwine5->hide();
|
||||
ui->tag_ubuntu->hide();
|
||||
ui->tag_community->hide();
|
||||
ui->icon->clear();
|
||||
ui->title->clear();
|
||||
ui->author->clear();
|
||||
ui->label_2->clear();
|
||||
ui->downloadButton->hide();
|
||||
ui->pushButton_3->hide();
|
||||
int n=ui->listWidget->count();
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
QListWidgetItem *item = ui->listWidget->takeItem(0);
|
||||
QWidget *card = ui->listWidget->itemWidget(item);
|
||||
delete card;
|
||||
card = NULL;
|
||||
delete item;
|
||||
item = NULL;
|
||||
}
|
||||
ui->listWidget->clear();
|
||||
}
|
||||
void AppIntoPage::setDownloadWidget(DownloadListWidget *w)
|
||||
{
|
||||
dw=w;
|
||||
}
|
||||
void AppIntoPage::openUrl(QUrl url)
|
||||
{
|
||||
spk=url;
|
||||
SparkAPI *api=new SparkAPI(this);
|
||||
connect(api,&SparkAPI::finishedObject,[=](QJsonObject appinfo){
|
||||
|
||||
info = appinfo;
|
||||
qDebug()<<url;
|
||||
//获取图标
|
||||
QNetworkAccessManager *naManager;
|
||||
QNetworkRequest request;
|
||||
naManager=new QNetworkAccessManager(this);
|
||||
request.setUrl(QUrl(api->getImgServerUrl()+"store"+url.path() + "/icon.png"));
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0");
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
naManager->get(request);
|
||||
QObject::connect(naManager,&QNetworkAccessManager::finished,[=](QNetworkReply *reply){
|
||||
QByteArray jpegData = reply->readAll();
|
||||
iconpixmap.loadFromData(jpegData);
|
||||
iconpixmap.scaled(210, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
ui->icon->setPixmap(iconpixmap);
|
||||
ui->icon->setScaledContents(true);
|
||||
});
|
||||
ui->title->setText(info["Name"].toString());
|
||||
ui->author->setText(info["Author"].toString());
|
||||
ui->d_author->setText(info["Author"].toString());
|
||||
ui->d_size->setText(info["Size"].toString());
|
||||
ui->d_update->setText(info["Update"].toString());
|
||||
ui->d_pkgname->setText(info["Pkgname"].toString());
|
||||
ui->d_website->setText("<a href=\""+info["Website"].toString()+"\">"+tr("Click Open"));
|
||||
ui->d_contributor->setText(info["Contributor"].toString());
|
||||
ui->label_2->setText(info["More"].toString());
|
||||
|
||||
QProcess isInstall;
|
||||
bool isInstalled;
|
||||
bool isUpdated;
|
||||
QString packagename = info["Pkgname"].toString();
|
||||
isInstall.start("dpkg -s " + info["Pkgname"].toString());
|
||||
isInstall.waitForFinished();
|
||||
int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
||||
if(error == 0)
|
||||
{
|
||||
isInstalled = true;
|
||||
|
||||
QProcess isUpdate;
|
||||
isUpdate.start("dpkg-query --showformat='${Version}' --show " + info["Pkgname"].toString());
|
||||
isUpdate.waitForFinished();
|
||||
QString localVersion = isUpdate.readAllStandardOutput();
|
||||
localVersion.replace("'", "");
|
||||
|
||||
isUpdate.start("dpkg --compare-versions " + localVersion + " ge " + info["Version"].toString());
|
||||
isUpdate.waitForFinished();
|
||||
if(!isUpdate.exitCode())
|
||||
{
|
||||
isUpdated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isUpdated = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isInstalled = false;
|
||||
isUpdated = false;
|
||||
}
|
||||
|
||||
if(isInstalled)
|
||||
{
|
||||
if(isUpdated)
|
||||
{
|
||||
ui->downloadButton->setText(tr("Reinstall"));
|
||||
ui->pushButton_3->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->downloadButton->setText(tr("Upgrade"));
|
||||
ui->pushButton_3->show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->downloadButton->setText(tr("Install"));
|
||||
ui->downloadButton->setEnabled(true);
|
||||
ui->downloadButton->show();
|
||||
}
|
||||
isDownloading();
|
||||
|
||||
QStringList taglist = info["Tags"].toString().split(";");
|
||||
QString tmp=info["img_urls"].toString();
|
||||
qDebug()<<tmp;
|
||||
if(tmp.left(2)=="[\"")
|
||||
{
|
||||
tmp.remove(0,2);
|
||||
}
|
||||
if(tmp.right(2)=="\"]")
|
||||
{
|
||||
tmp.remove(tmp.size()-2,tmp.size());
|
||||
}
|
||||
QStringList imglist = tmp.split("\",\"");
|
||||
qDebug()<<imglist;
|
||||
for(int i=0;i < imglist.size();i++)
|
||||
{
|
||||
QNetworkAccessManager *naManager;
|
||||
QNetworkRequest request;
|
||||
naManager=new QNetworkAccessManager(this);
|
||||
request.setUrl(QUrl(imglist[i]));
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0");
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
naManager->get(request);
|
||||
QObject::connect(naManager,&QNetworkAccessManager::finished,[=](QNetworkReply *reply){
|
||||
QByteArray jpegData = reply->readAll();
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(jpegData);
|
||||
pixmap.scaled(100, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
image_show *img=new image_show(this);
|
||||
img->setImage(pixmap);
|
||||
//img->setScaledContents(true);
|
||||
QListWidgetItem* pItem = new QListWidgetItem();
|
||||
pItem->setSizeHint(QSize(280, 200));
|
||||
ui->listWidget->addItem(pItem);
|
||||
ui->listWidget->setItemWidget(pItem, img);
|
||||
});
|
||||
}
|
||||
this->sltAppinfoTags(&taglist);
|
||||
disconnect(api,&SparkAPI::finished,nullptr,nullptr);
|
||||
api->deleteLater();
|
||||
});
|
||||
api->getAppInfo(url);
|
||||
}
|
||||
|
||||
void AppIntoPage::isDownloading()
|
||||
{
|
||||
switch (dw->isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())) {
|
||||
case 3:{
|
||||
ui->downloadButton->setEnabled(true);
|
||||
ui->downloadButton->setText(tr("Install"));
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
ui->downloadButton->setEnabled(false);
|
||||
ui->downloadButton->setText(tr("Downloading"));
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
ui->downloadButton->setEnabled(false);
|
||||
ui->downloadButton->setText(tr("Downloaded"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppIntoPage::sltAppinfoTags(QStringList *tagList)
|
||||
{
|
||||
foreach(const QString &tag, *tagList)
|
||||
{
|
||||
if(tag=="community")
|
||||
{
|
||||
ui->tag_community->show();
|
||||
}
|
||||
else if(tag=="ubuntu")
|
||||
{
|
||||
ui->tag_ubuntu->show();
|
||||
}
|
||||
else if(tag=="deepin")
|
||||
{
|
||||
ui->tag_deepin->show();
|
||||
}
|
||||
else if(tag=="uos")
|
||||
{
|
||||
ui->tag_uos->show();
|
||||
}
|
||||
else if(tag=="dtk5")
|
||||
{
|
||||
ui->tag_dtk5->show();
|
||||
}
|
||||
else if(tag=="dwine2")
|
||||
{
|
||||
ui->tag_dwine2->show();
|
||||
}
|
||||
else if(tag=="dwine5")
|
||||
{
|
||||
ui->tag_dwine5->show();
|
||||
}
|
||||
else if(tag=="a2d")
|
||||
{
|
||||
ui->tag_a2d->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
void AppIntoPage::setTheme(bool dark)
|
||||
{
|
||||
if(dark)
|
||||
{}else {
|
||||
//亮色模式
|
||||
QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4{background-color: #fbfbfb;border-radius:14px;border:1px solid rgb(229,229,229);}";
|
||||
ui->frame->setStyleSheet(frameStyleSheet);
|
||||
ui->frame_2->setStyleSheet(frameStyleSheet);
|
||||
ui->frame_3->setStyleSheet(frameStyleSheet);
|
||||
ui->frame_4->setStyleSheet(frameStyleSheet);
|
||||
|
||||
ui->icon_1->setPixmap(QPixmap(":/icon/light/box.svg"));
|
||||
ui->icon_2->setPixmap(QPixmap(":/icon/light/box.svg"));
|
||||
ui->icon_3->setPixmap(QPixmap(":/icon/light/calendar.svg"));
|
||||
ui->icon_4->setPixmap(QPixmap(":/icon/light/text.svg"));
|
||||
ui->icon_5->setPixmap(QPixmap(":/icon/light/folder.svg"));
|
||||
ui->icon_6->setPixmap(QPixmap(":/icon/light/globe.svg"));
|
||||
|
||||
}
|
||||
}
|
||||
AppIntoPage::~AppIntoPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AppIntoPage::on_downloadButton_clicked()
|
||||
{
|
||||
dw->addItem(info["Name"].toString(),info["Filename"].toString(),info["Pkgname"].toString(),iconpixmap,SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
|
||||
isDownloading();
|
||||
}
|
||||
|
||||
void AppIntoPage::on_pushButton_3_clicked()
|
||||
{
|
||||
QtConcurrent::run([=]()
|
||||
{
|
||||
ui->downloadButton->setEnabled(false);
|
||||
ui->pushButton_3->setEnabled(false);
|
||||
|
||||
QProcess uninstall;
|
||||
uninstall.start("pkexec", QStringList() << "apt" << "purge" << "-y" << info["Pkgname"].toString().toLower());
|
||||
uninstall.waitForFinished();
|
||||
|
||||
QProcess check;
|
||||
check.start("dpkg", QStringList() << "-s" << info["Pkgname"].toString().toLower());
|
||||
check.waitForFinished();
|
||||
|
||||
if (check.readAllStandardOutput().isEmpty())
|
||||
{
|
||||
ui->downloadButton->setText(tr("Install"));
|
||||
ui->pushButton_3->hide();
|
||||
|
||||
updatesEnabled();
|
||||
//sendNotification(tr("Uninstall succeeded"));
|
||||
}
|
||||
|
||||
ui->downloadButton->setEnabled(true);
|
||||
ui->pushButton_3->setEnabled(true);
|
||||
});
|
||||
}
|
||||
42
src/pages/appintopage.h
Normal file
42
src/pages/appintopage.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef APPINTOPAGE_H
|
||||
#define APPINTOPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
#include <QtConcurrent>
|
||||
#include "backend/sparkapi.h"
|
||||
#include "backend/image_show.h"
|
||||
#include "widgets/downloadlistwidget.h"
|
||||
namespace Ui {
|
||||
class AppIntoPage;
|
||||
}
|
||||
|
||||
class AppIntoPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void clear();
|
||||
void setDownloadWidget(DownloadListWidget *w);
|
||||
void setTheme(bool dark);
|
||||
void openUrl(QUrl url);
|
||||
explicit AppIntoPage(QWidget *parent = nullptr);
|
||||
~AppIntoPage();
|
||||
|
||||
private slots:
|
||||
void on_downloadButton_clicked();
|
||||
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
private:
|
||||
QJsonObject info;
|
||||
QPixmap iconpixmap;
|
||||
QUrl spk;
|
||||
void isDownloading();
|
||||
void sltAppinfoTags(QStringList *tagList);
|
||||
DownloadListWidget *dw;
|
||||
Ui::AppIntoPage *ui;
|
||||
};
|
||||
|
||||
#endif // APPINTOPAGE_H
|
||||
1287
src/pages/appintopage.ui
Normal file
1287
src/pages/appintopage.ui
Normal file
File diff suppressed because it is too large
Load Diff
76
src/pages/applistpage.cpp
Normal file
76
src/pages/applistpage.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "applistpage.h"
|
||||
#include "ui_applistpage.h"
|
||||
|
||||
AppListPage::AppListPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::AppListPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->webEngineView->page()->setBackgroundColor(Qt::transparent);
|
||||
}
|
||||
void AppListPage::setTheme(bool dark)
|
||||
{
|
||||
isDark=dark;
|
||||
if(dark)
|
||||
{
|
||||
|
||||
}else {
|
||||
//亮色模式
|
||||
this->setStyleSheet("#frame{background-color: #ffffff;border-radius:14px;border:1px solid rgb(229,229,229);}#webEngineView{border-radius:14px;}");
|
||||
}
|
||||
if(isSearch)
|
||||
{
|
||||
getSearchList(nowType);
|
||||
}else{
|
||||
getAppList(nowType);
|
||||
}
|
||||
}
|
||||
void AppListPage::getAppList(QString type)
|
||||
{
|
||||
isSearch=false;
|
||||
nowType=type;
|
||||
SparkAPI *api=new SparkAPI(this);
|
||||
QString url;
|
||||
if(isDark)
|
||||
{
|
||||
url=api->getServerUrl()+"store/#/dark"+type;
|
||||
}else{
|
||||
url=api->getServerUrl()+"store/#/"+type;
|
||||
}
|
||||
ui->webEngineView->setUrl(url);
|
||||
}
|
||||
|
||||
void AppListPage::getSearchList(QString keyword)
|
||||
{
|
||||
isSearch=true;
|
||||
nowType=keyword;
|
||||
SparkAPI *api=new SparkAPI(this);
|
||||
QString url;
|
||||
if(isDark)
|
||||
{
|
||||
url=api->getServerUrl()+"store/#/darksearch?keywords="+keyword;
|
||||
}else{
|
||||
url=api->getServerUrl()+"store/#/search?keywords="+keyword;
|
||||
}
|
||||
ui->webEngineView->setUrl(url);
|
||||
}
|
||||
|
||||
AppListPage::~AppListPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AppListPage::on_webEngineView_urlChanged(const QUrl &arg1)
|
||||
{
|
||||
if(arg1.path().right(8) == "app.json")
|
||||
{
|
||||
QString url = arg1.toString();
|
||||
url = url.mid(url.indexOf("/store/"));
|
||||
url = "spk:/"+url;
|
||||
url = url.mid(0,url.indexOf("/app.json"));
|
||||
qDebug() << "程序跳转链接地址:" << url;
|
||||
ui->webEngineView->back();
|
||||
emit clicked(url);
|
||||
}
|
||||
}
|
||||
|
||||
34
src/pages/applistpage.h
Normal file
34
src/pages/applistpage.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef APPLISTPAGE_H
|
||||
#define APPLISTPAGE_H
|
||||
#include <QMutex>
|
||||
#include <QWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include "backend/sparkapi.h"
|
||||
namespace Ui {
|
||||
class AppListPage;
|
||||
}
|
||||
|
||||
class AppListPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void setTheme(bool dark);
|
||||
void getSearchList(QString keyword);
|
||||
void getAppList(QString type);
|
||||
explicit AppListPage(QWidget *parent = nullptr);
|
||||
~AppListPage();
|
||||
|
||||
private:
|
||||
QMutex mutex; // 禁止多次搜索事件同时发生
|
||||
bool isDark;
|
||||
bool isSearch;
|
||||
QString nowType;
|
||||
Ui::AppListPage *ui;
|
||||
signals:
|
||||
void clicked(QUrl spk);
|
||||
private slots:
|
||||
void on_webEngineView_urlChanged(const QUrl &arg1);
|
||||
};
|
||||
|
||||
#endif // APPLISTPAGE_H
|
||||
84
src/pages/applistpage.ui
Normal file
84
src/pages/applistpage.ui
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AppListPage</class>
|
||||
<widget class="QWidget" name="AppListPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>645</width>
|
||||
<height>409</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="WebEngineView" name="webEngineView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebEngineView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>WebEngineView</class>
|
||||
<extends>QWebEngineView</extends>
|
||||
<header>widgets/common/webengineview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user