更新项目结构

This commit is contained in:
metanoia1989
2020-11-13 22:57:37 +08:00
parent 8972425c7c
commit 66ef37c1ca
75 changed files with 465 additions and 43 deletions

14
src/appitem.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include "appitem.h"
#include "ui_appitem.h"
AppItem::AppItem(QWidget *parent) :
QWidget(parent),
ui(new Ui::AppItem)
{
ui->setupUi(this);
}
AppItem::~AppItem()
{
delete ui;
}

22
src/appitem.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef APPITEM_H
#define APPITEM_H
#include <QWidget>
namespace Ui {
class AppItem;
}
class AppItem : public QWidget
{
Q_OBJECT
public:
explicit AppItem(QWidget *parent = nullptr);
~AppItem();
private:
Ui::AppItem *ui;
};
#endif // APPITEM_H

21
src/appitem.ui Normal file
View File

@@ -0,0 +1,21 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>AppItem</class>
<widget name="AppItem" class="QWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>

37
src/big_image.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "big_image.h"
#include <QHBoxLayout>
#include <QtConcurrent>
big_image::big_image(DBlurEffectWidget *parent) : DBlurEffectWidget(parent)
{
// m_image->setParent(this);
QHBoxLayout *layout=new QHBoxLayout;
setLayout(layout);
layout->addWidget(m_image);
layout->setMargin(0);
m_image->setAlignment(Qt::AlignCenter);
// m_image->setMaximumSize(1360,768);
setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);//设置图片对话框总在最前
setRadius(0);
setMaskAlpha(60);
setMaskColor(QColor("#000000"));
}
void big_image::mousePressEvent(QMouseEvent *)
{
hide();
m_image->clear();
}
void big_image::setimage(QPixmap image)
{
m_image->setPixmap(image);
}
void big_image::focusOutEvent(QFocusEvent *)
{
hide();
m_image->clear();
}

25
src/big_image.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef BIG_IMAGE_H
#define BIG_IMAGE_H
#include <QWidget>
#include <DBlurEffectWidget>
#include <QMouseEvent>
#include <QLabel>
DWIDGET_USE_NAMESPACE
class big_image : public DBlurEffectWidget
{
Q_OBJECT
public:
explicit big_image(DBlurEffectWidget *parent = nullptr);
void mousePressEvent(QMouseEvent *event);
QLabel *m_image=new QLabel;
void setimage(QPixmap);
void focusOutEvent(QFocusEvent *event);
signals:
public slots:
};
#endif // BIG_IMAGE_H

219
src/downloadlist.cpp Normal file
View File

@@ -0,0 +1,219 @@
#include "downloadlist.h"
#include "ui_downloadlist.h"
#include "widget.h"
#include <QDebug>
#include <QIcon>
#include <QPixmap>
#include <QtConcurrent>
#include <QProcess>
#include <QTextBrowser>
bool downloadlist::isInstall=false;
downloadlist::downloadlist(QWidget *parent) :
QWidget(parent),
ui(new Ui::downloadlist)
{
ui->setupUi(this);
ui->pushButton_install->setEnabled(false);
ui->progressBar->setValue(0);
ui->label_filename->hide();
ui->pushButton_install->hide();
ui->pushButton_3->hide();
ui->widget_spinner->start();
ui->widget_spinner->hide();
action_dpkg->setText(tr("dpkg"));
action_gdebi->setText(tr("gdebi"));
action_deepin->setText(tr("deepin deb installer"));
connect(action_dpkg,&QAction::triggered,[=](){downloadlist::install(1);});
connect(action_gdebi,&QAction::triggered,[=](){downloadlist::install(0);});
connect(action_deepin,&QAction::triggered,[=](){downloadlist::install(2);});
menu_install->addAction(action_gdebi);
//ssinstall命令存在时再加入该选项
QFile ssinstall("/bin/ssinstall");
ssinstall.open(QIODevice::ReadOnly);
if(ssinstall.isOpen()){
menu_install->addAction(action_dpkg);
}
QFile deepin("/bin/deepin-deb-installer");
deepin.open(QIODevice::ReadOnly);
if(deepin.isOpen()){
menu_install->addAction(action_deepin);
}
}
downloadlist::~downloadlist()
{
delete ui;
}
void downloadlist::setValue(long long value)
{
ui->progressBar->setValue(int(value));
ui->label_2->setText(QString::number(double(value)/100)+"% ("+speed+")");
if(ui->label_2->text().left(4)=="100%"){
ui->label_2->setText(tr("Downloaded, waiting to install"));
}
}
void downloadlist::setMax(long long max)
{
ui->progressBar->setMaximum(int(max));
}
void downloadlist::setName(QString name)
{
ui->label->setText(name);
}
QString downloadlist::getName()
{
return ui->label_filename->text();
}
void downloadlist::readyInstall()
{
if(ui->progressBar->value()!= ui->progressBar->maximum() && !close){
ui->progressBar->hide();
ui->pushButton_install->show();
ui->pushButton_2->hide();
Widget::sendNotification(tr("Failed to download %1").arg(ui->label->text()), 5000,
"/tmp/spark-store/icon_"+QString::number(num).toUtf8()+".png");
ui->label_2->setText(tr("Download FailedCheck Your Connection"));
ui->pushButton_install->setEnabled(false);
return;
}
if(!close){
ui->progressBar->hide();
ui->pushButton_install->setEnabled(true);
ui->pushButton_install->show();
ui->pushButton_2->hide();
Widget::sendNotification(tr("Finished downloading %1, awaiting to install").arg(ui->label->text()), 5000,
"/tmp/spark-store/icon_"+QString::number(num).toUtf8()+".png");
}
}
void downloadlist::setFileName(QString fileName)
{
ui->label_filename->setText(fileName);
}
void downloadlist::seticon(const QPixmap icon)
{
ui->label_3->setPixmap(icon);
}
void downloadlist::closeDownload()
{
on_pushButton_2_clicked();
}
void downloadlist::setSpeed(QString s)
{
speed=s;
}
void downloadlist::install(int t)
{
if(!isInstall){
isInstall=true;
ui->pushButton_install->hide();
ui->widget_spinner->show();
qDebug()<<"/tmp/spark-store/"+ui->label_filename->text().toUtf8();
ui->label_2->setText(tr("Installing"));
QtConcurrent::run([=](){
QProcess installer;
if(!reinstall){
switch (t) {
case 0:
installer.start("pkexec gdebi -n /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
case 1:
installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
case 2:
installer.start("deepin-deb-installer /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
}
}else {
switch (t) {
case 0:
installer.start("pkexec gdebi -n /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
case 1:
installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
case 2:
installer.start("deepin-deb-installer /tmp/spark-store/"+ui->label_filename->text().toUtf8());
break;
}
}
bool haveError=false;
bool notRoot=false;
installer.waitForFinished();
out=installer.readAllStandardOutput();
QStringList everyOut=out.split("\n");
for (int i=0;i<everyOut.size();i++) {
if(everyOut[i].left(2)=="E:"){
haveError=true;
}
if(everyOut[i].right(14)=="Not authorized"){
notRoot=true;
}
}
QProcess isInstall;
isInstall.start("dpkg -s "+pkgName);
isInstall.waitForFinished();
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
if(error==0){
ui->pushButton_install->hide();
ui->label_2->setText(tr("Finish"));
ui->pushButton_3->show();
}else {
ui->pushButton_install->show();
ui->pushButton_install->setText(tr("Retry"));
ui->label_2->setText(tr("Error happened in dpkg progress , you can try it again"));
ui->pushButton_3->show();
}
if(notRoot){
ui->label_2->setText(tr("dpkg progress had been abortedyou can retry installation"));
ui->pushButton_install->show();
ui->pushButton_3->hide();
}
ui->widget_spinner->hide();
downloadlist::isInstall=false;
});
qDebug()<<ui->label_filename->text().toUtf8();
}
}
void downloadlist::on_pushButton_install_clicked()
{
//弹出菜单
menu_install->exec(cursor().pos());
}
void downloadlist::on_pushButton_2_clicked()
{
ui->label_2->setText(tr("Download canceled"));
ui->pushButton_2->setEnabled(false);
ui->progressBar->hide();
close=true;
}
void downloadlist::on_pushButton_3_clicked()
{
output_w.layout()->addWidget(textbrowser);
textbrowser->setLineWidth(0);
textbrowser->setText(out);
output_w.layout()->setMargin(20);
output_w.setTitle(ui->label->text());
output_w.setMinimumHeight(600);
output_w.setAttribute(Qt::WA_TranslucentBackground);
output_w.show();
}

57
src/downloadlist.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef DOWNLOADLIST_H
#define DOWNLOADLIST_H
#include <QWidget>
#include <DDialog>
#include <QTextBrowser>
#include <QMenu>
#include <QAction>
DWIDGET_USE_NAMESPACE
namespace Ui {
class downloadlist;
}
class downloadlist : public QWidget
{
Q_OBJECT
public:
explicit downloadlist(QWidget *parent = nullptr);
~downloadlist();
void setValue(long long);
void setMax(long long);
void setName(QString);
QString getName();
void readyInstall();
bool free;
void setFileName(QString);
void seticon(const QPixmap);
void closeDownload();
void setSpeed(QString);
int num;
bool close=false;
QString out;
DDialog output_w;
QTextBrowser *textbrowser=new QTextBrowser;
bool reinstall=false;
QString pkgName;
QMenu *menu_install=new QMenu;
QAction *action_gdebi=new QAction;
QAction *action_dpkg=new QAction;
QAction *action_deepin=new QAction;
void install(int);
private slots:
void on_pushButton_install_clicked();
// void on_pushButton_maninst_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::downloadlist *ui;
static bool isInstall;
QString speed;
};
//bool downloadlist::isInstall=false;
#endif // DOWNLOADLIST_H

294
src/downloadlist.ui Normal file
View File

@@ -0,0 +1,294 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>downloadlist</class>
<widget class="QWidget" name="downloadlist">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>54</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>54</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<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>4</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="maximumSize">
<size>
<width>48</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>icon</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_filename">
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
</font>
</property>
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>10</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>Waiting to download</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="DSpinner" name="widget_spinner" native="true">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_install">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Install</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Info</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>DSpinner</class>
<extends>QWidget</extends>
<header location="global">dspinner.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

46
src/image_show.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "image_show.h"
#include <QHBoxLayout>
#include <QDebug>
#include <QPainter>
#include <DDialog>
#include <DBlurEffectWidget>
#include <DWidgetUtil>
#include <DApplication>
#include <QDesktopWidget>
DWIDGET_USE_NAMESPACE
image_show::image_show(QWidget *parent) : QWidget(parent)
{
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(m_label);
setLayout(layout);
m_label->setText("layout");
}
void image_show::setImage(QPixmap image)
{
QImage screen0;
screen0=image.toImage();
// QPainter painter(&screen0);
QImage re_screen1;
QImage re_screen0=screen0.scaled(QSize(400,300),Qt::KeepAspectRatio,Qt::SmoothTransformation);
desktop_w=DApplication::desktop()->width();
desktop_h=DApplication::desktop()->height();
if(screen0.width()>(desktop_w-20) || screen0.height()>(desktop_h-20)){
re_screen1=screen0.scaled(QSize(desktop_w-20,desktop_h-20),Qt::KeepAspectRatio,Qt::SmoothTransformation);
m_image=QPixmap::fromImage(re_screen1);
}else {
m_image=image;
}
m_label->setPixmap(QPixmap::fromImage(re_screen0));
}
void image_show::mousePressEvent(QMouseEvent *)
{
m_dialog->setimage(m_image);
m_dialog->showFullScreen();
m_dialog->setFixedSize(desktop_w,desktop_h);
m_dialog->move(0,0);/*
moveToCenter(m_dialog);*/
}

32
src/image_show.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef IMAGE_SHOW_H
#define IMAGE_SHOW_H
#include <QWidget>
#include <QMouseEvent>
#include <QLabel>
#include <QPixmap>
#include <DDialog>
#include <DBlurEffectWidget>
#include <big_image.h>
DWIDGET_USE_NAMESPACE
class image_show : public QWidget
{
Q_OBJECT
public:
explicit image_show(QWidget *parent = nullptr);
void setImage(QPixmap);
int desktop_w;
int desktop_h;
private:
QLabel *m_label=new QLabel;
QPixmap m_image;
QLabel image;
big_image *m_dialog=new big_image;
void mousePressEvent(QMouseEvent *event);
signals:
public slots:
};
#endif // IMAGE_SHOW_H

88
src/main.cpp Normal file
View File

@@ -0,0 +1,88 @@
#include <DApplication>
#include <DWidgetUtil> //Dtk::Widget::moveToCenter(&w); 要调用它就得引用DWidgetUtil
#include <QDesktopWidget>
#include <widget.h>
#include <QTranslator>
#include <DAboutDialog>
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
DApplication::loadDXcbPlugin(); //让bar处在标题栏中
DApplication a(argc, argv);
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
a.loadTranslator();//载入翻译
/* Customized DAboutDialog (Can't work on other distro like Ubuntu...)
*
* DAboutDialog dialog;
* a.setAboutDialog(&dialog);
* dialog.setLicense(QObject::tr("We publish this program under GPL V3"));
* dialog.setVersion(DApplication::buildVersion("Version 2.0.2.5"));
* dialog.setProductIcon(QIcon::fromTheme("spark-store")); //设置Logo
* dialog.setProductName(QLabel::tr("Spark Store"));
* dialog.setDescription(
* QObject::tr(
* "<span style=' font-size:10pt;font-weight:60;'>An appstore powered by deepin community</span><br/>"
* "<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
* "<span style=' font-size:12pt;'>Spark developers</span>"
* )
* );
* dialog.setProductName(QLabel::tr("Spark Store"));
* dialog.setCompanyLogo(QPixmap(":/Logo-Spark.png"));
* dialog.setWebsiteName(QObject::tr("The Spark Project"));
* dialog.setWebsiteLink("https://gitee.com/deepin-community-store");
*/
a.setProductName(QLabel::tr("Spark Store"));
a.setProductIcon(QIcon::fromTheme("spark-store")); //设置Logo
a.setOrganizationName("spark-union");
a.setOrganizationDomain("https://www.deepinos.org/");
a.setApplicationName(QLabel::tr("Spark Store"));
a.setApplicationVersion(DApplication::buildVersion("2.0.2.5"));
a.setApplicationAcknowledgementPage("https://gitee.com/deepin-community-store/spark-store");
a.setApplicationDescription(
QObject::tr(
"<span style='font-size:10pt;font-weight:60;'>An appstore powered by deepin community</span><br/>"
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style='font-size:12pt;'>Spark developers</span><br/><br/>"
"Published under GPL V3"
)
);
Widget w;
QDesktopWidget *s=DApplication::desktop();
int d_w=s->width();
int d_h=s->height();
if(d_w<=1366){
w.setMinimumWidth(925);
w.resize(925,650);
}else if(d_w<=1920){
w.setMinimumWidth(1180);
w.resize(1180,760);
}else {
w.setMinimumWidth(1180);
w.resize(1180,760);
}
if(d_h<=768){
w.setMinimumHeight(650);
w.resize(925,650);
}else if(d_h<=1080){
w.setMinimumHeight(760);
w.resize(1180,760);
}else {
w.setMinimumHeight(760);
w.resize(1180,760);
}
QString arg1=argv[1];
if(arg1.left(6)=="spk://"){
w.openUrl(QUrl(argv[1]));
}
//让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w);
w.show();
return a.exec();
}

37
src/progressload.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "progressload.h"
ProgressLoad::ProgressLoad(QWidget *parent) : QWidget(parent)
{
m_progess=new QWidget(this);
m_progess->move(0,0);
m_progess->show();
timer=new QTimer;
value=0;
timer->setInterval(10);
timer->start();
connect(timer,&QTimer::timeout,[=](){
m_progess->setFixedWidth(width()/100*value);
m_progess->setFixedHeight(height());
});
}
void ProgressLoad::setValue(int v)
{
value=v;
m_progess->setFixedWidth(width()/100*value);
}
void ProgressLoad::setTheme(bool dark, QColor color)
{
if(dark){
plt.setColor(QPalette::Background,QColor(28,28,28));
setAutoFillBackground(true);
setPalette(plt);
}else {
plt.setColor(QPalette::Background,QColor(255,255,255));
setAutoFillBackground(true);
setPalette(plt);
}
m_progess->setStyleSheet("background-color:"+color.name());
}

24
src/progressload.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef PROGRESSLOAD_H
#define PROGRESSLOAD_H
#include <QWidget>
#include <QTimer>
#include <QPalette>
class ProgressLoad : public QWidget
{
Q_OBJECT
public:
explicit ProgressLoad(QWidget *parent = nullptr);
void setValue(int v);
void setTheme(bool dark,QColor color);
signals:
public slots:
private:
QWidget *m_progess;
int value;
QTimer *timer;
QPalette plt;
};
#endif // PROGRESSLOAD_H

75
src/spark-store.pro Normal file
View File

@@ -0,0 +1,75 @@
#-------------------------------------------------
#
# Project created by QtCreator 2019-06-30T12:53:03
#
#-------------------------------------------------
QT += core gui network concurrent webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 link_pkgconfig
PKGCONFIG += dtkwidget glib-2.0 gdk-pixbuf-2.0 libnotify
TARGET = spark-store
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
appitem.cpp \
widget.cpp \
downloadlist.cpp \
image_show.cpp \
big_image.cpp \
progressload.cpp \
workerthreads.cpp
HEADERS += \
appitem.h \
widget.h \
downloadlist.h \
image_show.h \
big_image.h \
progressload.h \
workerthreads.h
FORMS += \
appitem.ui \
widget.ui \
downloadlist.ui
RESOURCES += \
../assets/icons.qrc
DISTFILES += \
../assets/tags/a2d-small.png \
../assets/tags/a2d.png \
../assets/tags/community-small.png \
../assets/tags/community.png \
../assets/tags/deepin-small.png \
../assets/tags/dtk-small.png \
../assets/tags/ubuntu-small.png \
../assets/tags/ubuntu.png \
../assets/tags/uos-small.png \
../assets/tags/community.svg \
../assets/tags/deepin.svg \
../assets/tags/logo_icon.svg \
../assets/tags/uos.svg
TRANSLATIONS = ../trans/spark-store_en.ts \
../trans/spark-store_zh_CN.ts
../trans/spark-store_fr.ts\
DEFINES += QT_APP_DEBUG
include(../third-party/QtNetworkService/QtNetworkService.pri)

1220
src/widget.cpp Normal file

File diff suppressed because it is too large Load Diff

154
src/widget.h Normal file
View File

@@ -0,0 +1,154 @@
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QUrl>
#include <QFile>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <downloadlist.h>
#include <QJsonObject>
#include <QProcess>
#include <QFuture>
#include <QFutureWatcher>
#include <QToolButton>
#include <QTimer>
#include <QFontDatabase>
#include <DSettings>
#include <DBlurEffectWidget>
#include <DSpinner>
#include <DWaterProgress>
#include <QLabel>
#include <DTitlebar>
#include <DSearchEdit>
#include <progressload.h>
#include "workerthreads.h"
#include "image_show.h"
#define LIST_MAX 99 //一次最多下载数量
#define TMP_PATH "/tmp/spark-store"
DWIDGET_USE_NAMESPACE
namespace Ui {
class Widget;
}
namespace AeaQt {
class HttpClient;
}
class Widget : public DBlurEffectWidget
{
Q_OBJECT
public:
explicit Widget(DBlurEffectWidget *parent = nullptr);
~Widget();
void startRequest(QUrl url);
void searchApp(QString);
int nowDownload=0;
int allDownload=0;
int isdownload=false;
void opensetting(); //打开设置页面
void openUrl(QUrl);
void setTheme(bool,QColor);
DTitlebar* getTitlebar();
static void sendNotification(const QString &message, const int msTimeout = 5000, const QString &icon = "spark-store");
static void sendNotification(const char *message, const int msTimeout = 5000, const QString &icon = "spark-store");
private slots:
void httpFinished();
void httpReadyRead();
void updateDataReadProgress(qint64,qint64);
// SpkAppInfoLoaderThread的槽函数
void sltAppinfoResetUi();
void sltAppinfoTags(QStringList *tagList);
void sltAppinfoDetails(QString *name, QString *details, QString *info,
QString *website, QString *packageName,
QUrl *fileUrl, bool isInstalled);
void sltAppinfoIcon(QPixmap *icon);
void sltAppinfoScreenshot(QPixmap *picture, int index);
void sltAppinfoFinish();
void on_pushButton_download_clicked();
void on_pushButton_return_clicked();
void on_comboBox_server_currentIndexChanged(const QString &arg1);
void on_pushButton_updateServer_clicked();
void on_pushButton_updateApt_clicked();
void on_pushButton_uninstall_clicked();
void on_pushButton_clear_clicked();
void on_pushButton_website_clicked();
void on_pushButton_clicked();
void on_btn_openDir_clicked();
void on_stackedWidget_currentChanged(int arg1);
void on_webEngineView_urlChanged(const QUrl &arg1);
void on_webEngineView_loadStarted();
void on_webEngineView_loadProgress(int progress);
void on_webEngineView_loadFinished(bool arg1);
void on_pushButton_refresh_clicked();
void on_pushButton_translate_clicked();
public:
QUrl url;
downloadlist download_list[LIST_MAX];
Ui::Widget *ui;
QNetworkAccessManager *manager;
QNetworkReply *reply;
QList<QUrl> urList;
QFile *file;
QString appName;
QString urladdress;
QString pkgName;
QString appweb;
bool themeIsDark;
QFont font;
private:
void initUI();
void initConfig();
int loadappinfo(QUrl);
void chooseLeftMenu(int index);
void setfoot(int);
void updatefoot();
void updateUI();
quint64 dirFileSize(const QString &path);
private:
QPushButton * left_list[15];
QUrl menuUrl[13];
ProgressLoad *m_loadweb;
QLabel *m_loaderror=new QLabel;
QString serverUrl;
bool configCanSave=false;
bool isBusy=false;
int nowMenu=0; //定位当前菜单
long download_size=0;
long size1=0;
long size2=0;
QPixmap screen[5];
QFuture<void> load;
QFutureWatcher<void> watchScreenshotLoad;
QTimer download_speed;
QString type_name;
QColor main_color;
int foot;
DSearchEdit *searchEdit=new DSearchEdit;
DTitlebar *titlebar;
QList<image_show*> label_screen;
SpkAppInfoLoaderThread appinfoLoadThread;
AeaQt::HttpClient *httpClient;
};
#endif // WIDGET_H

1477
src/widget.ui Normal file

File diff suppressed because it is too large Load Diff

152
src/workerthreads.cpp Normal file
View File

@@ -0,0 +1,152 @@
#include <QProcess>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include "workerthreads.h"
#include "widget.h"
void SpkAppInfoLoaderThread::run()
{
emit requestResetUi();
QProcess get_json;
QString urladdress, deatils, more, packagename, appweb;
QDir dir("/tmp");
bool isInstalled;
dir.mkdir("spark-store");
QDir::setCurrent("/tmp/spark-store");
get_json.start("curl -o app.json " + targetUrl.toString());
if(waitDownload(get_json) == -1)
return;
if(get_json.exitCode())
{
Widget::sendNotification(tr("Failed to download app info. Please check internet connection."));
}
QFile app_json("app.json");
if(app_json.open(QIODevice::ReadOnly)){
// 成功得到json文件
QByteArray json_array = app_json.readAll();
// 将路径转化为相应源的下载路径
urladdress = targetUrl.toString().left(targetUrl.toString().length()-8);
QStringList downloadurl=urladdress.split("/");
QString deburl = serverUrl;
deburl = deburl.left(urladdress.length()-1);
urladdress = "https://cdn.jsdelivr.net/gh/Jerrywang959/jsonpng@master/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
urladdress = urladdress.left(urladdress.length()-1);
for (int i=3;i<downloadurl.size();i++) {
urladdress+="/"+downloadurl[i];
deburl+="/"+downloadurl[i];
}
// 路径转化完成
QJsonObject json= QJsonDocument::fromJson(json_array).object();
QString appName = json["Name"].toString();
QUrl fileUrl = deburl + json["Filename"].toString();
// 软件信息加载
QString details;
details = tr("PkgName: ") + json["Pkgname"].toString()+"\n";
details += tr("Version: ") + json["Version"].toString()+"\n";
if(json["Author"].toString() != "" && json["Author"].toString() != " "){
details += tr("Author: ") + json["Author"].toString() + "\n";
}
if(json["Website"].toString() != "" && json["Website"].toString() != " "){
details += tr("Official Site: ") + json["Website"].toString() + "\n";
//ui->pushButton_website->show(); move to setinfo slot
appweb=json["Website"].toString();
}
details+=tr("Contributor: ")+json["Contributor"].toString()+"\n";
details+=tr("Update Time: ")+json["Update"].toString()+"\n";
details+=tr("Installed Size: ")+json["Size"].toString()+"\n";
more = json["More"].toString();
QProcess isInstall;
packagename = json["Pkgname"].toString();
isInstall.start("dpkg -s "+json["Pkgname"].toString());
isInstall.waitForFinished();
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
if(error==0)
isInstalled = true;
else
isInstalled = false;
emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
//tag加载
QString tags=json["Tags"].toString();
QStringList tagList=tags.split(";");
emit requestSetTags(&tagList);
// 图标加载
get_json.start("curl -o icon.png "+urladdress+"icon.png");
if(waitDownload(get_json) == -1)
return;
if(!get_json.exitCode()) {
QPixmap appicon("icon.png");
emit finishedIconLoad(&appicon);
}
else
Widget::sendNotification(tr("Failed to load application icon."));
// 截图展示加载
QPixmap screenshotCache[5];
for (int i = 0; i < 5; i++) {
QString cmd = "curl -o screen_"+QString::number(i+1)+".png "+urladdress+"screen_"+QString::number(i+1)+".png";
get_json.start(cmd);
if(waitDownload(get_json) == -1)
return;
bool s = screenshotCache[i].load(QString(TMP_PATH) + "/screen_"+QString::number(i+1)+".png");
if(s){
emit finishedScreenshotLoad(&screenshotCache[i], i);
}else{
emit finishedScreenshotLoad(nullptr, i);
QFile::remove("screen_"+QString::number(i+1)+".png");
break;
}
}
emit finishAllLoading();
}
}
void SpkAppInfoLoaderThread::setUrl(const QUrl &url)
{
targetUrl = url;
}
void SpkAppInfoLoaderThread::setServer(const QString &server)
{
serverUrl = server;
}
void SpkAppInfoLoaderThread::downloadFinished(int exitcode, QProcess::ExitStatus status)
{
Q_UNUSED(exitcode);
Q_UNUSED(status);
qDebug() << "Finish one download";
finishedDownload = true;
}
int SpkAppInfoLoaderThread::waitDownload(QProcess& downloader)
{
while(!downloader.waitForFinished(100))
{
if(downloader.state() == QProcess::NotRunning)
return -1;
if(this->isInterruptionRequested())
{
downloader.terminate();
downloader.waitForFinished(-1);
qDebug() << "Appinfo loader thread was forcefully terminated";
return -1;
}
}
return 0;
}

36
src/workerthreads.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef WORKERTHREADS_H
#define WORKERTHREADS_H
#include <QThread>
#include <QPixmap>
#include <QUrl>
#include <QProcess>
class SpkAppInfoLoaderThread Q_DECL_FINAL : public QThread
{
Q_OBJECT
public:
//explicit SpkAppInfoLoaderThread() = default;
void run() Q_DECL_OVERRIDE;
public slots:
void setUrl(const QUrl &url);
void setServer(const QString &server);
void downloadFinished(int exitcode, QProcess::ExitStatus status);
signals:
void requestResetUi();
void requestSetTags(QStringList *tagList);
void requestSetAppInformation(QString *name, QString *details, QString *info,
QString *website, QString *packageName,
QUrl *fileUrl, bool isInstalled);
void finishedIconLoad(QPixmap *icon);
void finishedScreenshotLoad(QPixmap *icon, int index); // 该信号必须以BlockingQueued方式连接
void finishAllLoading(); // 该信号必须以BlockingQueued方式连接
private:
int waitDownload(QProcess& downloader);
QUrl targetUrl;
QString serverUrl;
bool finishedDownload = false;
int downloaderRetval = 0;
};
#endif // WORKERTHREADS_H