From 9ca9f4732007dcbbd71609df3b9ef8c080b0efd6 Mon Sep 17 00:00:00 2001 From: Mouse Zhang Date: Tue, 6 Apr 2021 16:20:29 +0800 Subject: [PATCH] Fix: symbolic link makes main blocked. --- libsearch/index/first-index.cpp | 6 +-- libsearch/index/inotify-index.cpp | 27 ++++++++----- libsearch/index/traverse_bfs.cpp | 2 +- src/main.cpp | 67 +++++++++++++------------------ src/mainwindow.cpp | 14 ++----- src/mainwindow.h | 42 ++++++++++++------- 6 files changed, 80 insertions(+), 78 deletions(-) diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index 4d38903..9b60726 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -74,9 +74,9 @@ FirstIndex::~FirstIndex() void FirstIndex::DoSomething(const QFileInfo& fileInfo){ // qDebug() << "there are some shit here"<q_index->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")); - for (auto i : this->targetFileTypeVec){ - if (fileInfo.fileName().endsWith(i)){ + this->q_index->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0")); + for (auto i : this->targetFileTypeVec) { + if (fileInfo.fileName().endsWith(i)) { this->q_content_index->enqueue(fileInfo.absoluteFilePath()); } } diff --git a/libsearch/index/inotify-index.cpp b/libsearch/index/inotify-index.cpp index a224efc..24bf91a 100644 --- a/libsearch/index/inotify-index.cpp +++ b/libsearch/index/inotify-index.cpp @@ -57,7 +57,7 @@ void InotifyIndex::firstTraverse(){ dir.setPath(bfs.dequeue()); list = dir.entryInfoList(); for (auto i : list){ - if (i.isDir()){ + if (i.isDir() && (!(i.isSymLink()))){ this->AddWatch(i.absoluteFilePath()); bfs.enqueue(i.absoluteFilePath()); } @@ -67,11 +67,11 @@ void InotifyIndex::firstTraverse(){ void InotifyIndex::DoSomething(const QFileInfo& fileInfo){ qDebug() << fileInfo.fileName() << "-------" << fileInfo.absoluteFilePath(); - if(fileInfo.isDir()){ + if(fileInfo.isDir() && (!fileInfo.isSymLink())){ this->AddWatch(fileInfo.absoluteFilePath()); } QQueue >* tempFile = new QQueue >; - tempFile->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")); + tempFile->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0")); IndexGenerator::getInstance()->creatAllIndex(tempFile); if (tempFile) delete tempFile; @@ -178,9 +178,13 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ } if (event->mask & IN_ISDIR){ - AddWatch(currentPath[event->wd] + '/' + event->name); - setPath(currentPath[event->wd] + '/' + event->name); - Traverse(); + QString tmp = currentPath[event->wd] + '/' + event->name; + QFileInfo fi(tmp); + if(!fi.isSymLink()){ + AddWatch(tmp); + setPath(tmp); + Traverse(); + } } goto next; } @@ -236,10 +240,13 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ } } - AddWatch(currentPath[event->wd] + '/' + event->name); - setPath(currentPath[event->wd] + '/' + event->name); - Traverse(); - + QString tmp = currentPath[event->wd] + '/' + event->name; + QFileInfo fi(tmp); + if(!fi.isSymLink()){ + AddWatch(tmp); + setPath(tmp); + Traverse(); + } } else { IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name)); diff --git a/libsearch/index/traverse_bfs.cpp b/libsearch/index/traverse_bfs.cpp index dad3794..67d811a 100644 --- a/libsearch/index/traverse_bfs.cpp +++ b/libsearch/index/traverse_bfs.cpp @@ -36,7 +36,7 @@ void Traverse_BFS::Traverse(){ dir.setPath(bfs.dequeue()); list = dir.entryInfoList(); for (auto i : list){ - if (i.isDir()){ + if (i.isDir() && (!(i.isSymLink()))){ bfs.enqueue(i.absoluteFilePath()); } DoSomething(i); diff --git a/src/main.cpp b/src/main.cpp index 8fff0fe..ad93af2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,8 +40,6 @@ //void handler(int){ // qDebug() << "Recieved SIGTERM!"; - - // GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2"); // GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2"); // GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2"); @@ -51,16 +49,15 @@ // GlobalSettings::getInstance()->forceSync(INDEX_GENERATOR_NORMAL_EXIT); // GlobalSettings::getInstance()->forceSync(INOTIFY_NORMAL_EXIT); - // qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString(); // qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString(); // ::exit(0); -//// InotifyIndex::getInstance("/home")->~InotifyIndex(); +// InotifyIndex::getInstance("/home")->~InotifyIndex(); // //wait linux kill this thread forcedly -//// while (true); +// while (true); //} @@ -123,6 +120,7 @@ void centerToScreen(QWidget* widget) { int main(int argc, char *argv[]) { + // Determine whether the home directory has been created, and if not, keep waiting. char *p_home = NULL; unsigned int i = 0; @@ -147,12 +145,15 @@ int main(int argc, char *argv[]) ::sleep(1); } + // Output log to file qInstallMessageHandler(messageOutput); + // Register meta type qDebug() << "ukui-search main start"; qRegisterMetaType>("QPair"); qRegisterMetaType("Document"); + // If qt version bigger than 5.12, enable high dpi scaling and use high dpi pixmaps? #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); @@ -161,6 +162,7 @@ int main(int argc, char *argv[]) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif + // Make sure only one ukui-search is running. QtSingleApplication app("ukui-search", argc, argv); app.setQuitOnLastWindowClosed(false); @@ -177,10 +179,7 @@ int main(int argc, char *argv[]) parser.process(app); }*/ - - //here need to be modified - /*-------------ukuisearchdbus Test start-----------------*/ - + // Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running. QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search"); if(!fifoDir.exists()) qDebug()<<"create fifo path"<onKeywordSearchContent("g,e,x"); /*-------------文本搜索 Test End-----------------*/ - // 加载国际化文件 + // Load translations QTranslator translator; try { if (! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw -1; @@ -244,9 +243,8 @@ int main(int argc, char *argv[]) qDebug() << "Load translations file" << QLocale() << "failed!"; } - + //set main window to the center of screen MainWindow *w = new MainWindow; - QStringList arguments = QCoreApplication::arguments(); // centerToScreen(w); // w->moveToPanel(); centerToScreen(w); @@ -259,47 +257,38 @@ int main(int argc, char *argv[]) // hints.decorations = MWM_DECOR_BORDER; // XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), hints); + //TODO + //wait Ping jiang before 2021.04.10 app.setActivationWindow(w); + // Processing startup parameters if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) { // w->moveToPanel(); centerToScreen(w); XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints); w->show(); } -// if(arguments.size()>1) -// w->searchContent(arguments.at(1)); + + // TODO + // Wait Ping jiang before 2021.04.10 QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&))); -// qDebug() << "main start"; -// FirstIndex* fi = new FirstIndex("/home"); -// fi->start(); + // Start app search thread AppMatch::getAppMatch()->start(); - //wtf??? -// AppMatch apm; -// apm.start(); + + // TODO + // Set threads which in global thread pool expiry time in 5ms, some prolems here QThreadPool::globalInstance()->setExpiryTimeout(5); -// QThreadPool::globalInstance()->clear(); -// setAutoDelete(true); - -// FirstIndex fi("/home/zhangzihao/Desktop/qwerty"); -// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty"); + // TODO + // First insdex start, the parameter us useless, should remove the parameter FirstIndex fi("/home/zhangzihao/Desktop"); fi.start(); -// fi.wait(); -// fi->wait(); -// fi->exit(); -// delete fi; -// assert(false); + + // TODO + // Inotify index start, the parameter us useless, should remove the parameter InotifyIndex* ii = InotifyIndex::getInstance("/home"); -// InotifyIndex ii("/home"); ii->start(); -// qDebug() << "sigset start!"; -// sigset( SIGTERM, handler); -// qDebug() << "sigset end!"; - - return app.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 43b2859..227c691 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -53,18 +53,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - m_searcher = new SearchManager(); + m_searcher = new SearchManager(this); m_settingsMatch = new SettingsMatch(this); - // FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test"); - /*-------------Inotify Test Start---------------*/ - // QTime t1 = QTime::currentTime(); - // InotifyManagerRefact* im = new InotifyManagerRefact("/home"); - // im->Traverse(); - // QTime t2 = QTime::currentTime(); - // qDebug() << t1; - // qDebug() << t2; - // im->start(); - /*-------------Inotify Test End-----------------*/ // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); @@ -454,6 +444,8 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r m_search_result_thread->quit(); // m_seach_app_thread->stop(); break; + default: + break; } return false; diff --git a/src/mainwindow.h b/src/mainwindow.h index 7384b31..c9aa0e6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,6 +43,7 @@ #include #include #include + #include "content-widget.h" #include "input-box.h" #include "index/index-generator.h" @@ -63,29 +64,42 @@ public: /** * @brief Load the main window */ - void searchContent(QString searchcontent); + + // The parameter:keyword is the word or sentence which users want to search. + void searchContent(QString keyword); + + // The position which mainwindow shows follow the ukui-panel. void moveToPanel(); + + // The position which mainwindow shows in the center of screen where the cursor in. void centerToScreen(QWidget* widget); + + // TODO + // Wait Ping jiang. MotifWmHints m_hints; private: - bool nativeEvent(const QByteArray&, void *, long *); - QFrame * m_line = nullptr;//Vertical dividing line - QFrame * m_frame = nullptr; + // MainWindow quit when focus out. + bool nativeEvent(const QByteArray&, void*, long*); - QFrame * m_titleFrame = nullptr;//标题栏 - QHBoxLayout * m_titleLyt = nullptr; - QLabel * m_iconLabel = nullptr; - QLabel * m_titleLabel = nullptr; - QPushButton * m_menuBtn = nullptr; - SettingsWidget * m_settingsWidget = nullptr; + // TODO + // Not use? + QFrame * m_line = nullptr; // Vertical dividing line - ContentWidget * m_contentFrame = nullptr;//内容栏 - - SeachBarWidget * m_searchWidget = nullptr;//搜索栏 - SearchBarHLayout * m_searchLayout = nullptr; + QFrame * m_frame = nullptr; // Main frame + QFrame * m_titleFrame = nullptr; // Title bar frame + QHBoxLayout * m_titleLyt = nullptr; // Title layout + QLabel * m_iconLabel = nullptr; // Icon lable + QLabel * m_titleLabel = nullptr; // Title lable + QPushButton * m_menuBtn = nullptr; // Menu button + SettingsWidget * m_settingsWidget = nullptr; // Settings Widget + ContentWidget * m_contentFrame = nullptr; // Content frame + SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout + SeachBarWidget * m_searchWidget = nullptr; // Search bar + // TODO + // Not use? bool m_winFlag = false; QGSettings * m_transparency_gsettings = nullptr;