From 3a8c0a14564d3d313c28989da8253ab72d2caeda Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Sat, 20 Mar 2021 16:28:32 +0800 Subject: [PATCH] feat(frontend): Add tips when there is no network avaliable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 当无网络可用时添加提示框 Log: 当无网络可用时添加提示框 --- src/control/search-detail-view.cpp | 32 +++++++++-- src/control/search-detail-view.h | 5 ++ src/res/icons/net-disconnected.svg | 30 +++++++++++ src/resource.qrc | 1 + translations/ukui-search/bo.ts | 87 ++++++++++++++++-------------- translations/ukui-search/tr.ts | 87 ++++++++++++++++-------------- translations/ukui-search/zh_CN.ts | 87 ++++++++++++++++-------------- 7 files changed, 203 insertions(+), 126 deletions(-) create mode 100644 src/res/icons/net-disconnected.svg diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 38599b0..0632c44 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "config-file.h" SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) @@ -62,6 +63,7 @@ void SearchDetailView::clearLayout() { // delete child; // } // child = NULL; + m_noNetFrame->hide(); m_iconLabel->hide(); m_nameFrame->hide(); m_nameLabel->hide(); @@ -123,7 +125,7 @@ void SearchDetailView::setWebWidget(const QString& keyword) m_isEmpty = false; m_reload = false; if (m_webView) { - if (QString::compare(keyword, m_currentKeyword) == 0) { //关键词没有发生变化,只把原来的网页show出来 + if (QString::compare(keyword, m_currentKeyword) == 0 && m_net_enable) { //关键词没有发生变化,只把原来的网页show出来 m_webView->show(); return; } @@ -135,7 +137,7 @@ void SearchDetailView::setWebWidget(const QString& keyword) m_webView->move(0, 0); m_webView->setFixedSize(378, 522); - connect(m_webView,&QWebEngineView::loadFinished, this, [ = ](){ + connect(m_webView,&QWebEngineView::loadFinished, this, [ = ](bool is_successful){ m_reload = true; if (m_engineProfile){ m_engineProfile->clearHttpCache(); // 清理缓存 @@ -143,6 +145,13 @@ void SearchDetailView::setWebWidget(const QString& keyword) m_engineProfile->cookieStore()->deleteAllCookies(); // 清理cookie m_engineProfile->cookieStore()->deleteSessionCookies(); // 清理会话cookie } + if (is_successful) { + m_webView->show(); + m_net_enable = true; + } else { + m_noNetFrame->show(); + m_net_enable = false; + } }); connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) { if (m_reload) { @@ -178,7 +187,7 @@ void SearchDetailView::setWebWidget(const QString& keyword) // QString str = "https://wap.sogou.com/web/searchList.jsp?&keyword=" + keyword; //搜狗 m_webView->load(address); - m_webView->show(); +// m_webView->show(); } void SearchDetailView::setAppWidget(const QString &appname, const QString &path, const QString &iconpath, const QString &description) @@ -454,6 +463,23 @@ void SearchDetailView::initUI() this->setStyleSheet("QWidget#detailView{background:transparent;}"); this->setFixedWidth(378); + //没有网络的时候的提示信息 + m_noNetFrame = new QFrame(this); + m_noNetFrame->setFixedSize(378, 140); + m_noNetLyt = new QVBoxLayout(m_noNetFrame); + m_noNetIconLabel = new QLabel(m_noNetFrame); + m_noNetIconLabel->setFixedHeight(98); + m_noNetIconLabel->setPixmap(QIcon(":/res/icons/net-disconnected.svg").pixmap(QSize(98, 86))); + m_noNetIconLabel->setAlignment(Qt::AlignCenter); + m_noNetTipsLabel = new QLabel(m_noNetFrame); + m_noNetTipsLabel->setText(tr("Preview is not avaliable")); + m_noNetTipsLabel->setAlignment(Qt::AlignCenter); + m_noNetFrame->setLayout(m_noNetLyt); + m_noNetLyt->addWidget(m_noNetIconLabel); + m_noNetLyt->addWidget(m_noNetTipsLabel); + m_noNetLyt->setSpacing(12); + m_noNetFrame->move((this->width() - m_noNetFrame->width()) / 2, 160); + //图标和名称、分割线区域 m_iconLabel = new QLabel(this); m_iconLabel->setAlignment(Qt::AlignCenter); diff --git a/src/control/search-detail-view.h b/src/control/search-detail-view.h index d373f16..506baf4 100644 --- a/src/control/search-detail-view.h +++ b/src/control/search-detail-view.h @@ -89,10 +89,15 @@ private: QLabel * m_timeLabel_2 = nullptr; QFrame * m_hLine_2 = nullptr; OptionView * m_optionView = nullptr; + QFrame * m_noNetFrame = nullptr; + QVBoxLayout * m_noNetLyt = nullptr; + QLabel * m_noNetIconLabel = nullptr; + QLabel * m_noNetTipsLabel = nullptr; QWebEngineView * m_webView = nullptr; QWebEngineProfile * m_engineProfile = nullptr; bool m_reload = false; + bool m_net_enable = true; QString m_currentKeyword; Q_SIGNALS: diff --git a/src/res/icons/net-disconnected.svg b/src/res/icons/net-disconnected.svg new file mode 100644 index 0000000..4d5f99f --- /dev/null +++ b/src/res/icons/net-disconnected.svg @@ -0,0 +1,30 @@ + + + + image-viewer-app-symbolic + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/resource.qrc b/src/resource.qrc index 802cd34..018ebdd 100644 --- a/src/resource.qrc +++ b/src/resource.qrc @@ -4,5 +4,6 @@ res/icons/desktop.png res/icons/close.svg res/qt-translations/qt_zh_CN.qm + res/icons/net-disconnected.svg diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 4d225c4..9e5b6d5 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -75,12 +75,12 @@ - + Global Search - + Search @@ -137,188 +137,193 @@ SearchDetailView - + Path - + Last time modified - + Application - + Introduction: %1 - + Document + + + Preview is not avaliable + + SettingsWidget - - - + + + Search - - + + ... - + Following folders will not be searched. You can set it by adding and removing folders. - + Add ignored folders - + Please select search engine you preferred. - + baidu - + sougou - + 360 - + Cancel - + Creating ... - + ukui-search-settings - + <h2>Settings</h2> - + <h3>Index State</h3> - + <h3>File Index Settings</h3> - + <h3>Search Engine Settings</h3> - + Whether to delete this directory? - + Yes - + No - + Done - + Index Entry: %1 - + Directories - + select blocked folder - + Select - + Position: - + FileName: - + FileType: - + Choosen path is Empty! - + Choosen path is not in "home"! - + Its' parent folder has been blocked! - + Set blocked folder failed! - + OK diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index 5273c3b..6f1933a 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -75,12 +75,12 @@ ukui-ara - + Global Search Genel Arama - + Search Ara @@ -137,83 +137,88 @@ SearchDetailView - + Path Yol - + Last time modified Son değiştirilme zamanı - + Application Uygulama - + Introduction: %1 - + Document Belge + + + Preview is not avaliable + + SettingsWidget - - - + + + Search Ara - - + + ... ... - + Following folders will not be searched. You can set it by adding and removing folders. Aşağıdaki klasörler aranmayacaktır. Klasör ekleyip kaldırarak ayarlayabilirsiniz. - + Add ignored folders Göz ardı edilen klasörleri ekleyin - + Please select search engine you preferred. Lütfen tercih ettiğiniz arama motorunu seçin. - + baidu - + sougou - + 360 - + Cancel İptal - + Creating ... Oluşturuluyor... @@ -222,107 +227,107 @@ ukui-bul - + ukui-search-settings - + <h2>Settings</h2> <h2>Ayarlar</h2> - + <h3>Index State</h3> <h3>Dizin Durumu</h3> - + <h3>File Index Settings</h3> <h3>Dosya Dizini Ayarları</h3> - + <h3>Search Engine Settings</h3> <h3>SArama Motoru Ayarları</h3> - + Whether to delete this directory? Bu dizini silinsin mi? - + Yes - + No - + Done Tamam - + Index Entry: %1 Dizin Girişi: %1 - + Directories Dizinler - + select blocked folder engellenen klasörü seç - + Select Seç - + Position: Pozisyon: - + FileName: Dosya Adı: - + FileType: Dosya Türü: - + Choosen path is Empty! - + Choosen path is not in "home"! - + Its' parent folder has been blocked! - + Set blocked folder failed! - + OK diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index 5cf8bda..983c03b 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -75,12 +75,12 @@ 搜索 - + Global Search 搜索 - + Search 搜索 @@ -137,148 +137,153 @@ SearchDetailView - + Path 路径 - + Last time modified 上次修改时间 - + Application 应用 - + Introduction: %1 软件介绍: %1 - + Document 文件 + + + Preview is not avaliable + 当前预览不可用 + SettingsWidget - + ukui-search-settings 搜索 - - - + + + Search 搜索 - + <h2>Settings</h2> <h2>设置</h2> - + <h3>Index State</h3> <h3>索引状态</h3> - - + + ... - + <h3>File Index Settings</h3> <h3>文件索引设置</h3> - + Following folders will not be searched. You can set it by adding and removing folders. 搜索将不再查看以下文件夹。通过增加和删除文件夹可进行文件索引设置。 - + Add ignored folders 添加文件夹至黑名单 - + <h3>Search Engine Settings</h3> <h3>搜索引擎设置</h3> - + Please select search engine you preferred. 设置互联网搜索引擎 - + baidu 百度 - + sougou 搜狗 - + 360 360 - + Whether to delete this directory? 是否要删除此目录 - + Yes 是(Y) - + No 否(N) - + Cancel 取消 - + Choosen path is Empty! 选择的路径不存在! - + Choosen path is not in "home"! 请选择家目录下的文件夹! - + Its' parent folder has been blocked! 父文件夹已被屏蔽! - + Set blocked folder failed! - + OK 好的 - + Creating ... 正在索引 @@ -287,42 +292,42 @@ 搜索 - + Done 索引完成 - + Index Entry: %1 索引项: %1 - + Directories 文件夹 - + select blocked folder 选择屏蔽文件夹 - + Select 选择 - + Position: 位置: - + FileName: 名称: - + FileType: 类型: