Fix: UI stuck occasionally.

This commit is contained in:
iaom 2021-09-08 15:31:47 +08:00
parent ea93efee7a
commit 091dac9d73
6 changed files with 29 additions and 19 deletions

View File

@ -19,6 +19,7 @@
*/ */
#include "app-match.h" #include "app-match.h"
#include <glib.h> #include <glib.h>
#include <qt5xdg/XdgIcon>
#include "file-utils.h" #include "file-utils.h"
#include "app-search-plugin.h" #include "app-search-plugin.h"
#define ANDROID_APP_DESKTOP_PATH QDir::homePath() + "/.local/share/applications/" #define ANDROID_APP_DESKTOP_PATH QDir::homePath() + "/.local/share/applications/"
@ -252,8 +253,6 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
QMapIterator<NameString, QStringList> iter(m_installAppMap); QMapIterator<NameString, QStringList> iter(m_installAppMap);
while(iter.hasNext()) { while(iter.hasNext()) {
iter.next(); iter.next();
// list = iter.value();
// name.app_name = iter.key().app_name;
if(iter.key().app_name.contains(keyWord, Qt::CaseInsensitive)) { if(iter.key().app_name.contains(keyWord, Qt::CaseInsensitive)) {
SearchPluginIface::ResultInfo ri; SearchPluginIface::ResultInfo ri;
creatResultInfo(ri, iter, true); creatResultInfo(ri, iter, true);
@ -261,17 +260,17 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) { if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
searchResult->enqueue(ri); searchResult->enqueue(ri);
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
continue;
} else { } else {
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
break; return;
} }
// installed.insert(name, list);
continue;
} }
QStringList pinyinlist; QStringList pinyinlist;
pinyinlist = FileUtils::findMultiToneWords(iter.key().app_name); pinyinlist = FileUtils::findMultiToneWords(iter.key().app_name);
bool matched = false;
for(int i = 0; i < pinyinlist.size() / 2; i++) { for(int i = 0; i < pinyinlist.size() / 2; i++) {
QString shouzimu = pinyinlist.at(2 * i + 1); // 中文转首字母 QString shouzimu = pinyinlist.at(2 * i + 1); // 中文转首字母
if(shouzimu.contains(keyWord, Qt::CaseInsensitive)) { if(shouzimu.contains(keyWord, Qt::CaseInsensitive)) {
@ -281,12 +280,12 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) { if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
searchResult->enqueue(ri); searchResult->enqueue(ri);
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
matched = true;
break;
} else { } else {
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
break; return;
} }
// installed.insert(name, list);
break;
} }
if(keyWord.size() < 2) if(keyWord.size() < 2)
break; break;
@ -298,14 +297,17 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) { if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
searchResult->enqueue(ri); searchResult->enqueue(ri);
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
matched = true;
break;
} else { } else {
AppSearchPlugin::m_mutex.lock(); AppSearchPlugin::m_mutex.unlock();
break; return;
} }
// installed.insert(name, list);
break;
} }
} }
if(matched) {
continue;
}
QStringList tmpList; QStringList tmpList;
tmpList << iter.value().at(2) << iter.value().at(3); tmpList << iter.value().at(2) << iter.value().at(3);
for(QString s : tmpList) { for(QString s : tmpList) {
@ -316,12 +318,11 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) { if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
searchResult->enqueue(ri); searchResult->enqueue(ri);
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
break;
} else { } else {
AppSearchPlugin::m_mutex.unlock(); AppSearchPlugin::m_mutex.unlock();
break; return;
} }
// installed.insert(name, list);
continue;
} }
} }
} }
@ -397,7 +398,8 @@ void AppMatch::getInstalledAppsVersion(QString appname) {
void AppMatch::creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled) void AppMatch::creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled)
{ {
ri.icon = QIcon::fromTheme(iter.value().at(1), QIcon(":/res/icons/desktop.png")); // ri.icon = QIcon::fromTheme(iter.value().at(1), QIcon(":/res/icons/desktop.png"));
ri.icon = XdgIcon::fromTheme(iter.value().at(1), QIcon(":/res/icons/desktop.png"));
ri.name = iter.key().app_name; ri.name = iter.key().app_name;
ri.actionKey = iter.value().at(0); ri.actionKey = iter.value().at(0);
ri.type = 0; //0 means installed apps. ri.type = 0; //0 means installed apps.

View File

@ -838,6 +838,12 @@ QString FileUtils::chineseSubString(const std::string &myStr, int start, int len
return sub; return sub;
} }
QIcon FileUtils::iconFromTheme(const QString &name, const QIcon &iconDefault)
{
QMutexLocker locker(&iconMutex);
return QIcon::fromTheme(name, iconDefault);
}
QString FileUtils::getHtmlText(const QString &text, const QString &keyword) QString FileUtils::getHtmlText(const QString &text, const QString &keyword)
{ {
QString htmlString; QString htmlString;

View File

@ -94,6 +94,7 @@ public:
static bool copyPath(QString &path); static bool copyPath(QString &path);
static QString escapeHtml(const QString & str); static QString escapeHtml(const QString & str);
static QString chineseSubString(const std::string &myStr,int start,int length); static QString chineseSubString(const std::string &myStr,int start,int length);
static QIcon iconFromTheme(const QString& name, const QIcon &iconDefault);
static size_t _max_index_count; static size_t _max_index_count;
static size_t _current_index_count; //this one has been Abandoned,do not use it. static size_t _current_index_count; //this one has been Abandoned,do not use it.
static unsigned short _index_status; static unsigned short _index_status;

View File

@ -232,8 +232,8 @@ void InotifyWatch::run()
void InotifyWatch::slotEvent(char *buf, ssize_t len) void InotifyWatch::slotEvent(char *buf, ssize_t len)
{ {
// eventProcess(socket); // eventProcess(socket);
++FileUtils::_index_status;
if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) { if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
++FileUtils::_index_status;
pid_t pid; pid_t pid;
pid = fork(); pid = fork();
if(pid == 0) { if(pid == 0) {

View File

@ -33,7 +33,7 @@ include(notesearch/notesearch.pri)
include(settingsearch/settingsearch.pri) include(settingsearch/settingsearch.pri)
LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation
LIBS += -lxapian -lquazip5 -luchardet #-L/usr/local/lib/libjemalloc -ljemalloc LIBS += -lxapian -lquazip5 -luchardet -lQt5Xdg#-L/usr/local/lib/libjemalloc -ljemalloc
SOURCES += \ SOURCES += \
file-utils.cpp \ file-utils.cpp \

View File

@ -1,6 +1,7 @@
#include "note-search-plugin.h" #include "note-search-plugin.h"
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <qt5xdg/xdgicon.h>
#include "file-utils.h" #include "file-utils.h"
#include "chinese-segmentation.h" #include "chinese-segmentation.h"
using namespace Zeeker; using namespace Zeeker;
@ -183,7 +184,7 @@ void NoteSearch::run() {
dbusArgs.endArray(); dbusArgs.endArray();
qDebug() << str; qDebug() << str;
SearchPluginIface::ResultInfo ri = { SearchPluginIface::ResultInfo ri = {
icon : QIcon::fromTheme("kylin-notebook"), icon : XdgIcon::fromTheme("kylin-notebook", QIcon(":/res/icons/desktop.png")),
name : str.at(1), name : str.at(1),
description : QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo { description : QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo {
key : QString(tr("Note Description:")), key : QString(tr("Note Description:")),