Merge branch 'main' into 0111-dev

This commit is contained in:
张佳萍 2021-01-11 20:38:38 +08:00 committed by GitHub
commit c991679741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 82 additions and 23 deletions

View File

@ -3,14 +3,14 @@
#include <QPalette>
#include "global-settings.h"
static GlobalSettings *global_instance = nullptr;
static GlobalSettings *global_instance_of_global_settings = nullptr;
GlobalSettings *GlobalSettings::getInstance()
{
if (!global_instance) {
global_instance = new GlobalSettings;
if (!global_instance_of_global_settings) {
global_instance_of_global_settings = new GlobalSettings;
}
return global_instance;
return global_instance_of_global_settings;
}
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)

View File

@ -22,10 +22,6 @@ FileSearcher::~FileSearcher()
void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResultFile,QQueue<QString> *searchResultDir,QQueue<QPair<QString,QStringList>> *searchResultContent)
{
m_search_result_file = searchResultFile;
m_search_result_dir = searchResultDir;
m_search_result_content = searchResultContent;
m_mutex1.lock();
++uniqueSymbol1;
m_mutex1.unlock();
@ -35,6 +31,11 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
m_mutex3.lock();
++uniqueSymbol3;
m_mutex3.unlock();
m_search_result_file = searchResultFile;
m_search_result_dir = searchResultDir;
m_search_result_content = searchResultContent;
//file
QtConcurrent::run([&, uniqueSymbol1, keyword](){
if(!m_search_result_file->isEmpty())

View File

@ -2,6 +2,25 @@
#include "first-index.h"
#include <QDebug>
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");
qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
// InotifyIndex::getInstance("/home")->~InotifyIndex();
qDebug() << "~IndexGenerator() end!" << endl;
//wait linux kill this thread forcedly
// while (true);
}
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
{
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
@ -37,8 +56,8 @@ FirstIndex::~FirstIndex()
this->q_index = nullptr;
delete this->q_content_index;
this->q_content_index = nullptr;
delete this->p_indexGenerator;
this->p_indexGenerator;
// delete this->p_indexGenerator;
// this->p_indexGenerator;
// delete this->mlm;
// this->mlm = nullptr;
}
@ -56,7 +75,12 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
void FirstIndex::run(){
if (this->bool_dataBaseExist){
if (this->bool_dataBaseStatusOK){
this->quit();
//why???????????????????????????????????????????????????????????????
//why not quit?
// this->quit();
exit(0);
// return;
// this->wait();
}
else{
@ -107,7 +131,14 @@ void FirstIndex::run(){
//don't use it now!!!!
//MouseZhangZh
// this->~FirstIndex();
// qDebug() << "~FirstIndex end;";
qDebug() << "~FirstIndex end;";
qDebug() << "sigset start!";
sigset( SIGTERM, handler);
qDebug() << "sigset end!";
this->quit();
// this->wait();
}

View File

@ -3,10 +3,12 @@
#include <QThread>
#include <QtConcurrent/QtConcurrent>
#include <signal.h>
//#include <QtConcurrent>
#include "traverse_bfs.h"
#include "global-settings.h"
#include "index-generator.h"
#include "inotify-index.h"
class FirstIndex : public QThread, public Traverse_BFS
{
@ -21,7 +23,7 @@ private:
void operator=(const FirstIndex&) = delete;
bool bool_dataBaseStatusOK = false;
bool bool_dataBaseExist = false;
IndexGenerator* p_indexGenerator;
IndexGenerator* p_indexGenerator = nullptr;
//here should be refact
// MessageListManager* mlm;

View File

@ -24,6 +24,8 @@ IndexGenerator *IndexGenerator::getInstance(bool rebuild)
if (!global_instance) {
global_instance = new IndexGenerator(rebuild);
}
qDebug() << "global_instance" << global_instance;
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
return global_instance;
}
@ -118,6 +120,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
IndexGenerator::~IndexGenerator()
{
QMutexLocker locker(&m_mutex);
qDebug() << "~IndexGenerator";
if(m_datebase_path)
delete m_datebase_path;
@ -126,6 +129,9 @@ IndexGenerator::~IndexGenerator()
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"2");
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE,"2");
GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"2");
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
qDebug() << "~IndexGenerator 22222222222222222222";
}
void IndexGenerator::insertIntoDatabase(Document doc)

View File

@ -10,6 +10,9 @@ InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
qDebug() << "setInotifyMaxUserWatches end";
/*-------------ukuisearchdbus Test End-----------------*/
m_fd = inotify_init();
qDebug() << "m_fd----------->" <<m_fd;
@ -19,7 +22,7 @@ InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
InotifyIndex::~InotifyIndex()
{
IndexGenerator::getInstance()->~IndexGenerator();
}
void InotifyIndex::DoSomething(const QFileInfo& fileInfo){
@ -72,6 +75,11 @@ bool InotifyIndex::RemoveWatch(const QString &path){
return true;
}
/*
* Symbolic Link!!!!!!!!!!!!!!!!!!
* Sysmbolic link to database dir will make a Infinite loop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* MouseZhangZh
*/
void InotifyIndex::run(){
@ -110,6 +118,7 @@ void InotifyIndex::run(){
/*--------------------------------*/
// IndexGenerator::getInstance()->creatAllIndex(QQueue<QVector<QString>>(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")));
qDebug() << QString(currentPath[event->wd] + '/' + event->name);
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
indexQueue->clear();

View File

@ -9,11 +9,18 @@
#include "ukui-search-qdbus.h"
#define BUF_LEN 1024
class InotifyIndex;
static InotifyIndex* global_instance_of_index = nullptr;
class InotifyIndex : public QThread, public Traverse_BFS
{
Q_OBJECT
public:
static InotifyIndex* getInstance(const QString& path){
if (!global_instance_of_index) {
global_instance_of_index = new InotifyIndex(path);
}
return global_instance_of_index;
}
InotifyIndex(const QString&);
~InotifyIndex();

View File

@ -90,8 +90,7 @@ void centerToScreen(QWidget* widget) {
int main(int argc, char *argv[])
{
// qInstallMessageHandler(messageOutput);
qInstallMessageHandler(messageOutput);
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
@ -112,11 +111,7 @@ int main(int argc, char *argv[])
parser.process(app);
}*/
// qDebug() << "main start";
// FirstIndex fi("/home");
// fi.start();
// InotifyIndex ii("/home");
// ii.start();
/*-------------ukuisearchdbus Test start-----------------*/
// UkuiSearchQDBus usQDBus;
// usQDBus.setInotifyMaxUserWatches();
@ -171,6 +166,12 @@ int main(int argc, char *argv[])
// qDebug() << "main start";
// FirstIndex* fi = new FirstIndex("/home");
// fi->start();
qDebug() << "main start";
FirstIndex fi("/home");
fi.start();
InotifyIndex* ii = InotifyIndex::getInstance("/home");
// InotifyIndex ii("/home");
ii->start();
return app.exec();
}

View File

@ -32,6 +32,8 @@
//#include "inotify-manager.h"
#include "settings-widget.h"
#include "global-settings.h"
#include "search-result.h"