修复了搜索结果页存在页边距的问题;
修复了多次搜索同时触发导致的崩溃问题。
This commit is contained in:
2020-12-05 18:45:47 +08:00
parent 14e3e7f9a2
commit b619d3cc7b
11 changed files with 402 additions and 329 deletions

View File

@@ -74,6 +74,7 @@ void AppItem::downloadIcon(QString icon)
QNetworkReply *reply = reqManager->get(QNetworkRequest(url));
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
connect(reply, &QNetworkReply::finished, this, [=] () { emit finished(); });
loop.exec();
reqManager->deleteLater();
QPixmap pixmap;

View File

@@ -26,6 +26,7 @@ protected:
signals:
void clicked(QUrl url);
void finished();
public slots:
void downloadIcon(QString icon);

View File

@@ -220,4 +220,4 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
return static_cast<QLayout *>(parent)->spacing();
}
}
//! [12]
//! [12]

View File

@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
a.setOrganizationName("spark-union");
a.setOrganizationDomain("https://www.deepinos.org/");
a.setApplicationName("Spark Store"); //不需要翻译,否则 ~/.local/share/ 下文件夹名称也被翻译为中文
a.setApplicationVersion(DApplication::buildVersion("2.0.2.5"));
a.setApplicationVersion(DApplication::buildVersion("3.0~alpha0"));
a.setApplicationAcknowledgementPage("https://gitee.com/deepin-community-store/spark-store");
a.setApplicationDescription(
QObject::tr(

View File

@@ -79,7 +79,7 @@ Widget::Widget(DBlurEffectWidget *parent) :
qDebug()<<searchEdit->text();
searchApp(searchtext);
}
searchEdit->clearEdit();
this->setFocus();
});
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType) {
@@ -721,11 +721,16 @@ void Widget::searchApp(QString text)
{
if(text.left(6)=="spk://"){
openUrl(text);
searchEdit->clearEdit();
}else {
// sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!"));
// ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度
// ui->stackedWidget->setCurrentIndex(0);
// 禁止同时进行多次搜索
if(!mutex.tryLock())
return;
// 关键字搜索处理
httpClient->get("http://search.deepinos.org.cn/appinfo/search")
.header("content-type", "application/json")
@@ -733,23 +738,24 @@ void Widget::searchApp(QString text)
.onResponse([this](QByteArray result) {
auto json = QJsonDocument::fromJson(result).array();
if (json.empty()) {
qDebug() << "搜索不到相关应用!";
sendNotification(tr("Not found relative App!"));
qDebug() << "相关应用未找到";
sendNotification(tr("Relative apps Not Found!"));
mutex.unlock();
return;
}
displaySearchApp(json);
})
.onError([](QString errorStr) {
.onError([this](QString errorStr) {
qDebug() << "请求出错:" << errorStr;
sendNotification(QString("请求出错:%1").arg(errorStr));
sendNotification(QString(tr("Request Error: %1")).arg(errorStr));
mutex.unlock();
return;
})
.timeout(10 * 1000)
.exec();
}
}
/**
* @brief 展示搜索的APP信息
*/
@@ -762,7 +768,7 @@ void Widget::displaySearchApp(QJsonArray array)
while ((item = applist_grid->takeAt(0)) != nullptr) {
item->widget()->disconnect();
delete item->widget();
delete item;
delete item;
}
item = nullptr;
@@ -780,11 +786,25 @@ void Widget::displaySearchApp(QJsonArray array)
applist_grid->addWidget(appItem);
qDebug() << "应用链接为:" << url;
connect(appItem, &AppItem::clicked, this, &Widget::openUrl);
connect(appItem, &AppItem::finished, this, [=](){
count++;
downloadIconsFinished(array.size());
});
}
ui->applist_scrollarea->widget()->setLayout(applist_grid);
qDebug() << "显示结果了吗????喵喵喵";
}
void Widget::downloadIconsFinished(int arraysize)
{
// 当前搜索列表图标全部加载完成后才允许下一次搜索
if(count == arraysize)
{
count = 0;
mutex.unlock();
}
}
void Widget::httpReadyRead()
{
if(file)

View File

@@ -14,8 +14,8 @@
#include <QToolButton>
#include <QTimer>
#include <QJsonArray>
#include <QFontDatabase>
#include <QMutex>
#include <DSettings>
#include <DBlurEffectWidget>
@@ -80,6 +80,7 @@ private slots:
void sltAppinfoFinish();
void displaySearchApp(QJsonArray array); // 展示搜索的APP信息
void downloadIconsFinished(int arraysize); // 当前搜索列表图标是否下载完成
void on_pushButton_download_clicked();
void on_pushButton_return_clicked();
@@ -150,6 +151,9 @@ private:
DSearchEdit *searchEdit=new DSearchEdit;
DTitlebar *titlebar;
int count = 0; // 记录当前搜索列表下载图标完成的个数
QMutex mutex; // 禁止多次搜索事件同时发生
QList<image_show*> label_screen;
SpkAppInfoLoaderThread appinfoLoadThread;

View File

@@ -345,7 +345,7 @@
<number>0</number>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -365,11 +365,11 @@
<number>0</number>
</property>
<item>
<widget class="QWebEngineView" name="webEngineView" native="true">
<widget class="QWebEngineView" name="webEngineView">
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="url" stdset="0">
<property name="url">
<url>
<string>about:blank</string>
</url>
@@ -489,8 +489,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>886</width>
<height>865</height>
<width>889</width>
<height>854</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
@@ -984,8 +984,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>840</width>
<height>318</height>
<width>851</width>
<height>323</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@@ -1114,8 +1114,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>886</width>
<height>921</height>
<width>889</width>
<height>858</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
@@ -1388,8 +1388,26 @@
</widget>
<widget class="QWidget" name="applist_page">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<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="QScrollArea" name="applist_scrollarea">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@@ -1401,8 +1419,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>881</width>
<height>659</height>
<width>903</width>
<height>681</height>
</rect>
</property>
</widget>