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){
// 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) {
if (fileInfo.fileName().endsWith(i)) {
this->q_content_index->enqueue(fileInfo.absoluteFilePath());

View File

@ -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<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);
if (tempFile)
delete tempFile;
@ -178,10 +178,14 @@ 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);
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);
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));

View File

@ -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);

View File

@ -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<QString,QStringList>>("QPair<QString,QStringList>");
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))
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"<<fifoDir.mkpath(fifoDir.absolutePath());
@ -195,11 +194,11 @@ int main(int argc, char *argv[])
return -1;
}
qDebug()<<"create fifo success\n";
// Set max_user_watches to a number which is enough big.
UkuiSearchQDBus usQDBus;
usQDBus.setInotifyMaxUserWatches();
/*-------------ukuisearchdbus Test End-----------------*/
// load chinese character and pinyin file to a Map
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt");
/*-------------InotyifyRefact Test Start---------------*/
@ -227,7 +226,7 @@ int main(int argc, char *argv[])
// search->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();
}

View File

@ -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;

View File

@ -43,6 +43,7 @@
#include <QKeyEvent>
#include <QGSettings/QGSettings>
#include <QSystemTrayIcon>
#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:
// MainWindow quit when focus out.
bool nativeEvent(const QByteArray&, void*, long*);
// TODO
// Not use?
QFrame * m_line = nullptr; // Vertical dividing line
QFrame * m_frame = nullptr;
QFrame * m_titleFrame = nullptr;//标题栏
QHBoxLayout * m_titleLyt = nullptr;
QLabel * m_iconLabel = nullptr;
QLabel * m_titleLabel = nullptr;
QPushButton * m_menuBtn = nullptr;
SettingsWidget * m_settingsWidget = nullptr;
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;