Merge branch '0621-dev' into 'dev-unity'

[Fix] Tray icon click won't work after Win+D; Close inotify fd after closed file index service.

See merge request kylin-desktop/ukui-search!42
This commit is contained in:
PengfeiZhang 2021-06-26 06:47:59 +00:00
commit 91c13ca43d
3 changed files with 20 additions and 5 deletions

View File

@ -483,8 +483,10 @@ void FileUtils::getDocxTextContent(QString &path, QString &textcontent) {
if(!file.open(QuaZip::mdUnzip)) if(!file.open(QuaZip::mdUnzip))
return; return;
if(!file.setCurrentFile("word/document.xml", QuaZip::csSensitive)) if(!file.setCurrentFile("word/document.xml", QuaZip::csSensitive)) {
file.close();
return; return;
}
QuaZipFile fileR(&file); QuaZipFile fileR(&file);
fileR.open(QIODevice::ReadOnly); //读取方式打开 fileR.open(QIODevice::ReadOnly); //读取方式打开
@ -545,8 +547,10 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent) {
if(i.startsWith(prefix)) if(i.startsWith(prefix))
fileList << i; fileList << i;
} }
if(fileList.isEmpty()) if(fileList.isEmpty()) {
file.close();
return; return;
}
for(int i = 0; i < fileList.size(); ++i){ for(int i = 0; i < fileList.size(); ++i){
QString name = prefix + QString::number(i + 1) + ".xml"; QString name = prefix + QString::number(i + 1) + ".xml";
@ -650,8 +654,10 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent) {
if(!file.open(QuaZip::mdUnzip)) if(!file.open(QuaZip::mdUnzip))
return; return;
if(!file.setCurrentFile("xl/sharedStrings.xml", QuaZip::csSensitive)) if(!file.setCurrentFile("xl/sharedStrings.xml", QuaZip::csSensitive)) {
file.close();
return; return;
}
QuaZipFile fileR(&file); QuaZipFile fileR(&file);
fileR.open(QIODevice::ReadOnly); fileR.open(QIODevice::ReadOnly);
@ -706,8 +712,10 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent) {
void FileUtils::getPdfTextContent(QString &path, QString &textcontent) { void FileUtils::getPdfTextContent(QString &path, QString &textcontent) {
Poppler::Document *doc = Poppler::Document::load(path); Poppler::Document *doc = Poppler::Document::load(path);
if(doc->isLocked()) if(doc->isLocked()) {
delete doc;
return; return;
}
const QRectF qf; const QRectF qf;
int pageNum = doc->numPages(); int pageNum = doc->numPages();
for(int i = 0; i < pageNum; ++i) { for(int i = 0; i < pageNum; ++i) {

View File

@ -1,6 +1,7 @@
#include "inotify-watch.h" #include "inotify-watch.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <malloc.h> #include <malloc.h>
#include <errno.h>
using namespace Zeeker; using namespace Zeeker;
static InotifyWatch* global_instance_InotifyWatch = nullptr; static InotifyWatch* global_instance_InotifyWatch = nullptr;
@ -65,7 +66,7 @@ bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase)
// qDebug() << i.value(); // qDebug() << i.value();
if(i.value().length() > path.length()) { if(i.value().length() > path.length()) {
if(i.value().startsWith(path)) { if(i.value().startsWith(path)) {
qDebug() << "remove path: " << i.value(); // qDebug() << "remove path: " << i.value();
inotify_rm_watch(m_inotifyFd, currentPath.key(path)); inotify_rm_watch(m_inotifyFd, currentPath.key(path));
currentPath.erase(i++); currentPath.erase(i++);
} else { } else {
@ -132,6 +133,8 @@ void InotifyWatch::run()
if (m_inotifyFd > 0) { if (m_inotifyFd > 0) {
qDebug()<<"Inotify init success!"; qDebug()<<"Inotify init success!";
} else { } else {
printf("errno=%d\n",errno);
printf("Mesg:%s\n",strerror(errno));
Q_ASSERT_X(0, "InotifyWatch", "Failed to initialize inotify"); Q_ASSERT_X(0, "InotifyWatch", "Failed to initialize inotify");
} }
@ -205,10 +208,12 @@ void InotifyWatch::run()
assert(false); assert(false);
} }
} }
qDebug() << "Leave watch loop";
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) { if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3"); IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3");
removeWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false); removeWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false);
} }
close(m_inotifyFd);
// fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC); // fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC);
// m_notifier = new QSocketNotifier(m_inotifyFd, QSocketNotifier::Read); // m_notifier = new QSocketNotifier(m_inotifyFd, QSocketNotifier::Read);
// connect(m_notifier, &QSocketNotifier::activated, this, &InotifyWatch::slotEvent, Qt::DirectConnection); // connect(m_notifier, &QSocketNotifier::activated, this, &InotifyWatch::slotEvent, Qt::DirectConnection);

View File

@ -129,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent) :
this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入 this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入
this->raise(); this->raise();
this->activateWindow(); this->activateWindow();
} else if(this->isVisible()&&!this->isActiveWindow()) {
this->activateWindow();
} else { } else {
tryHideMainwindow(); tryHideMainwindow();
} }