Fix: symbolic link makes main blocked.

This commit is contained in:
Mouse Zhang 2021-04-06 16:20:29 +08:00
parent ab2d92dc74
commit 9ca9f47320
6 changed files with 80 additions and 78 deletions

View File

@ -74,7 +74,7 @@ FirstIndex::~FirstIndex()
void FirstIndex::DoSomething(const QFileInfo& fileInfo){ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
// qDebug() << "there are some shit here"<<fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0"); // qDebug() << "there are some shit here"<<fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0");
this->q_index->enqueue(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")); this->q_index->enqueue(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0"));
for (auto i : this->targetFileTypeVec) { for (auto i : this->targetFileTypeVec) {
if (fileInfo.fileName().endsWith(i)) { if (fileInfo.fileName().endsWith(i)) {
this->q_content_index->enqueue(fileInfo.absoluteFilePath()); this->q_content_index->enqueue(fileInfo.absoluteFilePath());

View File

@ -57,7 +57,7 @@ void InotifyIndex::firstTraverse(){
dir.setPath(bfs.dequeue()); dir.setPath(bfs.dequeue());
list = dir.entryInfoList(); list = dir.entryInfoList();
for (auto i : list){ for (auto i : list){
if (i.isDir()){ if (i.isDir() && (!(i.isSymLink()))){
this->AddWatch(i.absoluteFilePath()); this->AddWatch(i.absoluteFilePath());
bfs.enqueue(i.absoluteFilePath()); bfs.enqueue(i.absoluteFilePath());
} }
@ -67,11 +67,11 @@ void InotifyIndex::firstTraverse(){
void InotifyIndex::DoSomething(const QFileInfo& fileInfo){ void InotifyIndex::DoSomething(const QFileInfo& fileInfo){
qDebug() << fileInfo.fileName() << "-------" << fileInfo.absoluteFilePath(); qDebug() << fileInfo.fileName() << "-------" << fileInfo.absoluteFilePath();
if(fileInfo.isDir()){ if(fileInfo.isDir() && (!fileInfo.isSymLink())){
this->AddWatch(fileInfo.absoluteFilePath()); this->AddWatch(fileInfo.absoluteFilePath());
} }
QQueue<QVector<QString> >* tempFile = new QQueue<QVector<QString> >; QQueue<QVector<QString> >* tempFile = new QQueue<QVector<QString> >;
tempFile->enqueue(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")); tempFile->enqueue(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0"));
IndexGenerator::getInstance()->creatAllIndex(tempFile); IndexGenerator::getInstance()->creatAllIndex(tempFile);
if (tempFile) if (tempFile)
delete tempFile; delete tempFile;
@ -178,10 +178,14 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
} }
if (event->mask & IN_ISDIR){ if (event->mask & IN_ISDIR){
AddWatch(currentPath[event->wd] + '/' + event->name); QString tmp = currentPath[event->wd] + '/' + event->name;
setPath(currentPath[event->wd] + '/' + event->name); QFileInfo fi(tmp);
if(!fi.isSymLink()){
AddWatch(tmp);
setPath(tmp);
Traverse(); Traverse();
} }
}
goto next; goto next;
} }
@ -236,10 +240,13 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
} }
} }
AddWatch(currentPath[event->wd] + '/' + event->name); QString tmp = currentPath[event->wd] + '/' + event->name;
setPath(currentPath[event->wd] + '/' + event->name); QFileInfo fi(tmp);
if(!fi.isSymLink()){
AddWatch(tmp);
setPath(tmp);
Traverse(); Traverse();
}
} }
else { else {
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name)); IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));

View File

@ -36,7 +36,7 @@ void Traverse_BFS::Traverse(){
dir.setPath(bfs.dequeue()); dir.setPath(bfs.dequeue());
list = dir.entryInfoList(); list = dir.entryInfoList();
for (auto i : list){ for (auto i : list){
if (i.isDir()){ if (i.isDir() && (!(i.isSymLink()))){
bfs.enqueue(i.absoluteFilePath()); bfs.enqueue(i.absoluteFilePath());
} }
DoSomething(i); DoSomething(i);

View File

@ -40,8 +40,6 @@
//void handler(int){ //void handler(int){
// qDebug() << "Recieved SIGTERM!"; // qDebug() << "Recieved SIGTERM!";
// GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2"); // GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
// GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2"); // GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
// GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2"); // GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2");
@ -51,16 +49,15 @@
// GlobalSettings::getInstance()->forceSync(INDEX_GENERATOR_NORMAL_EXIT); // GlobalSettings::getInstance()->forceSync(INDEX_GENERATOR_NORMAL_EXIT);
// GlobalSettings::getInstance()->forceSync(INOTIFY_NORMAL_EXIT); // GlobalSettings::getInstance()->forceSync(INOTIFY_NORMAL_EXIT);
// qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString(); // qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
// qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString(); // qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
// ::exit(0); // ::exit(0);
//// InotifyIndex::getInstance("/home")->~InotifyIndex(); // InotifyIndex::getInstance("/home")->~InotifyIndex();
// //wait linux kill this thread forcedly // //wait linux kill this thread forcedly
//// while (true); // while (true);
//} //}
@ -123,6 +120,7 @@ void centerToScreen(QWidget* widget) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// Determine whether the home directory has been created, and if not, keep waiting.
char *p_home = NULL; char *p_home = NULL;
unsigned int i = 0; unsigned int i = 0;
@ -147,12 +145,15 @@ int main(int argc, char *argv[])
::sleep(1); ::sleep(1);
} }
// Output log to file
qInstallMessageHandler(messageOutput); qInstallMessageHandler(messageOutput);
// Register meta type
qDebug() << "ukui-search main start"; qDebug() << "ukui-search main start";
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>"); qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
qRegisterMetaType<Document>("Document"); qRegisterMetaType<Document>("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)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
@ -161,6 +162,7 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif #endif
// Make sure only one ukui-search is running.
QtSingleApplication app("ukui-search", argc, argv); QtSingleApplication app("ukui-search", argc, argv);
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
@ -177,10 +179,7 @@ int main(int argc, char *argv[])
parser.process(app); parser.process(app);
}*/ }*/
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
//here need to be modified
/*-------------ukuisearchdbus Test start-----------------*/
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search"); QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
if(!fifoDir.exists()) if(!fifoDir.exists())
qDebug()<<"create fifo path"<<fifoDir.mkpath(fifoDir.absolutePath()); qDebug()<<"create fifo path"<<fifoDir.mkpath(fifoDir.absolutePath());
@ -195,11 +194,11 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
qDebug()<<"create fifo success\n"; qDebug()<<"create fifo success\n";
// Set max_user_watches to a number which is enough big.
UkuiSearchQDBus usQDBus; UkuiSearchQDBus usQDBus;
usQDBus.setInotifyMaxUserWatches(); usQDBus.setInotifyMaxUserWatches();
/*-------------ukuisearchdbus Test End-----------------*/
// load chinese character and pinyin file to a Map // load chinese character and pinyin file to a Map
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt"); FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt");
/*-------------InotyifyRefact Test Start---------------*/ /*-------------InotyifyRefact Test Start---------------*/
@ -227,7 +226,7 @@ int main(int argc, char *argv[])
// search->onKeywordSearchContent("g,e,x"); // search->onKeywordSearchContent("g,e,x");
/*-------------文本搜索 Test End-----------------*/ /*-------------文本搜索 Test End-----------------*/
// 加载国际化文件 // Load translations
QTranslator translator; QTranslator translator;
try { try {
if (! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw -1; 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!"; qDebug() << "Load translations file" << QLocale() << "failed!";
} }
//set main window to the center of screen
MainWindow *w = new MainWindow; MainWindow *w = new MainWindow;
QStringList arguments = QCoreApplication::arguments();
// centerToScreen(w); // centerToScreen(w);
// w->moveToPanel(); // w->moveToPanel();
centerToScreen(w); centerToScreen(w);
@ -259,47 +257,38 @@ int main(int argc, char *argv[])
// hints.decorations = MWM_DECOR_BORDER; // hints.decorations = MWM_DECOR_BORDER;
// XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), hints); // XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), hints);
//TODO
//wait Ping jiang before 2021.04.10
app.setActivationWindow(w); app.setActivationWindow(w);
// Processing startup parameters
if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) { if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) {
// w->moveToPanel(); // w->moveToPanel();
centerToScreen(w); centerToScreen(w);
XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints); XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints);
w->show(); 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&))); QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&)));
// qDebug() << "main start"; // Start app search thread
// FirstIndex* fi = new FirstIndex("/home");
// fi->start();
AppMatch::getAppMatch()->start(); AppMatch::getAppMatch()->start();
//wtf???
// AppMatch apm; // TODO
// apm.start(); // Set threads which in global thread pool expiry time in 5ms, some prolems here
QThreadPool::globalInstance()->setExpiryTimeout(5); 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"); FirstIndex fi("/home/zhangzihao/Desktop");
fi.start(); fi.start();
// fi.wait();
// fi->wait(); // TODO
// fi->exit(); // Inotify index start, the parameter us useless, should remove the parameter
// delete fi;
// assert(false);
InotifyIndex* ii = InotifyIndex::getInstance("/home"); InotifyIndex* ii = InotifyIndex::getInstance("/home");
// InotifyIndex ii("/home");
ii->start(); ii->start();
// qDebug() << "sigset start!";
// sigset( SIGTERM, handler);
// qDebug() << "sigset end!";
return app.exec(); return app.exec();
} }

View File

@ -53,18 +53,8 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent) QMainWindow(parent)
{ {
m_searcher = new SearchManager(); m_searcher = new SearchManager(this);
m_settingsMatch = new SettingsMatch(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 | Qt::X11BypassWindowManagerHint);
// this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); // 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_search_result_thread->quit();
// m_seach_app_thread->stop(); // m_seach_app_thread->stop();
break; break;
default:
break;
} }
return false; return false;

View File

@ -43,6 +43,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QGSettings/QGSettings> #include <QGSettings/QGSettings>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include "content-widget.h" #include "content-widget.h"
#include "input-box.h" #include "input-box.h"
#include "index/index-generator.h" #include "index/index-generator.h"
@ -63,29 +64,42 @@ public:
/** /**
* @brief Load the main window * @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(); void moveToPanel();
// The position which mainwindow shows in the center of screen where the cursor in.
void centerToScreen(QWidget* widget); void centerToScreen(QWidget* widget);
// TODO
// Wait Ping jiang.
MotifWmHints m_hints; MotifWmHints m_hints;
private: private:
// MainWindow quit when focus out.
bool nativeEvent(const QByteArray&, void*, long*); bool nativeEvent(const QByteArray&, void*, long*);
// TODO
// Not use?
QFrame * m_line = nullptr; // Vertical dividing line QFrame * m_line = nullptr; // Vertical dividing line
QFrame * m_frame = nullptr;
QFrame * m_titleFrame = nullptr;//标题栏 QFrame * m_frame = nullptr; // Main frame
QHBoxLayout * m_titleLyt = nullptr; QFrame * m_titleFrame = nullptr; // Title bar frame
QLabel * m_iconLabel = nullptr; QHBoxLayout * m_titleLyt = nullptr; // Title layout
QLabel * m_titleLabel = nullptr; QLabel * m_iconLabel = nullptr; // Icon lable
QPushButton * m_menuBtn = nullptr; QLabel * m_titleLabel = nullptr; // Title lable
SettingsWidget * m_settingsWidget = nullptr; QPushButton * m_menuBtn = nullptr; // Menu button
SettingsWidget * m_settingsWidget = nullptr; // Settings Widget
ContentWidget * m_contentFrame = nullptr;//内容栏 ContentWidget * m_contentFrame = nullptr; // Content frame
SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
SeachBarWidget * m_searchWidget = nullptr;//搜索栏 SeachBarWidget * m_searchWidget = nullptr; // Search bar
SearchBarHLayout * m_searchLayout = nullptr;
// TODO
// Not use?
bool m_winFlag = false; bool m_winFlag = false;
QGSettings * m_transparency_gsettings = nullptr; QGSettings * m_transparency_gsettings = nullptr;