forked from openkylin/ukui-search
Merge branch 'main' into 0111-dev
This commit is contained in:
commit
c991679741
|
@ -3,14 +3,14 @@
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
|
|
||||||
static GlobalSettings *global_instance = nullptr;
|
static GlobalSettings *global_instance_of_global_settings = nullptr;
|
||||||
|
|
||||||
GlobalSettings *GlobalSettings::getInstance()
|
GlobalSettings *GlobalSettings::getInstance()
|
||||||
{
|
{
|
||||||
if (!global_instance) {
|
if (!global_instance_of_global_settings) {
|
||||||
global_instance = new GlobalSettings;
|
global_instance_of_global_settings = new GlobalSettings;
|
||||||
}
|
}
|
||||||
return global_instance;
|
return global_instance_of_global_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
||||||
|
|
|
@ -22,10 +22,6 @@ FileSearcher::~FileSearcher()
|
||||||
|
|
||||||
void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResultFile,QQueue<QString> *searchResultDir,QQueue<QPair<QString,QStringList>> *searchResultContent)
|
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();
|
m_mutex1.lock();
|
||||||
++uniqueSymbol1;
|
++uniqueSymbol1;
|
||||||
m_mutex1.unlock();
|
m_mutex1.unlock();
|
||||||
|
@ -35,6 +31,11 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
m_mutex3.lock();
|
m_mutex3.lock();
|
||||||
++uniqueSymbol3;
|
++uniqueSymbol3;
|
||||||
m_mutex3.unlock();
|
m_mutex3.unlock();
|
||||||
|
|
||||||
|
m_search_result_file = searchResultFile;
|
||||||
|
m_search_result_dir = searchResultDir;
|
||||||
|
m_search_result_content = searchResultContent;
|
||||||
|
|
||||||
//file
|
//file
|
||||||
QtConcurrent::run([&, uniqueSymbol1, keyword](){
|
QtConcurrent::run([&, uniqueSymbol1, keyword](){
|
||||||
if(!m_search_result_file->isEmpty())
|
if(!m_search_result_file->isEmpty())
|
||||||
|
|
|
@ -2,6 +2,25 @@
|
||||||
#include "first-index.h"
|
#include "first-index.h"
|
||||||
#include <QDebug>
|
#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)
|
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
|
||||||
{
|
{
|
||||||
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||||
|
@ -37,8 +56,8 @@ FirstIndex::~FirstIndex()
|
||||||
this->q_index = nullptr;
|
this->q_index = nullptr;
|
||||||
delete this->q_content_index;
|
delete this->q_content_index;
|
||||||
this->q_content_index = nullptr;
|
this->q_content_index = nullptr;
|
||||||
delete this->p_indexGenerator;
|
// delete this->p_indexGenerator;
|
||||||
this->p_indexGenerator;
|
// this->p_indexGenerator;
|
||||||
// delete this->mlm;
|
// delete this->mlm;
|
||||||
// this->mlm = nullptr;
|
// this->mlm = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +75,12 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
|
||||||
void FirstIndex::run(){
|
void FirstIndex::run(){
|
||||||
if (this->bool_dataBaseExist){
|
if (this->bool_dataBaseExist){
|
||||||
if (this->bool_dataBaseStatusOK){
|
if (this->bool_dataBaseStatusOK){
|
||||||
this->quit();
|
|
||||||
|
//why???????????????????????????????????????????????????????????????
|
||||||
|
//why not quit?
|
||||||
|
// this->quit();
|
||||||
|
exit(0);
|
||||||
|
// return;
|
||||||
// this->wait();
|
// this->wait();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -107,7 +131,14 @@ void FirstIndex::run(){
|
||||||
//don't use it now!!!!
|
//don't use it now!!!!
|
||||||
//MouseZhangZh
|
//MouseZhangZh
|
||||||
// this->~FirstIndex();
|
// this->~FirstIndex();
|
||||||
// qDebug() << "~FirstIndex end;";
|
qDebug() << "~FirstIndex end;";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
qDebug() << "sigset start!";
|
||||||
|
sigset( SIGTERM, handler);
|
||||||
|
qDebug() << "sigset end!";
|
||||||
|
|
||||||
this->quit();
|
this->quit();
|
||||||
// this->wait();
|
// this->wait();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
#include <signal.h>
|
||||||
//#include <QtConcurrent>
|
//#include <QtConcurrent>
|
||||||
#include "traverse_bfs.h"
|
#include "traverse_bfs.h"
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
#include "index-generator.h"
|
#include "index-generator.h"
|
||||||
|
#include "inotify-index.h"
|
||||||
|
|
||||||
class FirstIndex : public QThread, public Traverse_BFS
|
class FirstIndex : public QThread, public Traverse_BFS
|
||||||
{
|
{
|
||||||
|
@ -21,7 +23,7 @@ private:
|
||||||
void operator=(const FirstIndex&) = delete;
|
void operator=(const FirstIndex&) = delete;
|
||||||
bool bool_dataBaseStatusOK = false;
|
bool bool_dataBaseStatusOK = false;
|
||||||
bool bool_dataBaseExist = false;
|
bool bool_dataBaseExist = false;
|
||||||
IndexGenerator* p_indexGenerator;
|
IndexGenerator* p_indexGenerator = nullptr;
|
||||||
|
|
||||||
//here should be refact
|
//here should be refact
|
||||||
// MessageListManager* mlm;
|
// MessageListManager* mlm;
|
||||||
|
|
|
@ -24,6 +24,8 @@ IndexGenerator *IndexGenerator::getInstance(bool rebuild)
|
||||||
if (!global_instance) {
|
if (!global_instance) {
|
||||||
global_instance = new IndexGenerator(rebuild);
|
global_instance = new IndexGenerator(rebuild);
|
||||||
}
|
}
|
||||||
|
qDebug() << "global_instance" << global_instance;
|
||||||
|
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
|
||||||
return global_instance;
|
return global_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +120,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
IndexGenerator::~IndexGenerator()
|
IndexGenerator::~IndexGenerator()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
qDebug() << "~IndexGenerator";
|
qDebug() << "~IndexGenerator";
|
||||||
if(m_datebase_path)
|
if(m_datebase_path)
|
||||||
delete m_datebase_path;
|
delete m_datebase_path;
|
||||||
|
@ -126,6 +129,9 @@ IndexGenerator::~IndexGenerator()
|
||||||
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");
|
||||||
|
|
||||||
|
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
|
||||||
|
qDebug() << "~IndexGenerator 22222222222222222222";
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator::insertIntoDatabase(Document doc)
|
void IndexGenerator::insertIntoDatabase(Document doc)
|
||||||
|
|
|
@ -10,6 +10,9 @@ InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
|
||||||
qDebug() << "setInotifyMaxUserWatches end";
|
qDebug() << "setInotifyMaxUserWatches end";
|
||||||
|
|
||||||
/*-------------ukuisearchdbus Test End-----------------*/
|
/*-------------ukuisearchdbus Test End-----------------*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_fd = inotify_init();
|
m_fd = inotify_init();
|
||||||
qDebug() << "m_fd----------->" <<m_fd;
|
qDebug() << "m_fd----------->" <<m_fd;
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
|
||||||
|
|
||||||
InotifyIndex::~InotifyIndex()
|
InotifyIndex::~InotifyIndex()
|
||||||
{
|
{
|
||||||
|
IndexGenerator::getInstance()->~IndexGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InotifyIndex::DoSomething(const QFileInfo& fileInfo){
|
void InotifyIndex::DoSomething(const QFileInfo& fileInfo){
|
||||||
|
@ -72,6 +75,11 @@ bool InotifyIndex::RemoveWatch(const QString &path){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Symbolic Link!!!!!!!!!!!!!!!!!!
|
||||||
|
* Sysmbolic link to database dir will make a Infinite loop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* MouseZhangZh
|
||||||
|
*/
|
||||||
|
|
||||||
void InotifyIndex::run(){
|
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")));
|
// 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"));
|
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
indexQueue->clear();
|
indexQueue->clear();
|
||||||
|
|
|
@ -9,11 +9,18 @@
|
||||||
#include "ukui-search-qdbus.h"
|
#include "ukui-search-qdbus.h"
|
||||||
|
|
||||||
#define BUF_LEN 1024
|
#define BUF_LEN 1024
|
||||||
|
class InotifyIndex;
|
||||||
|
static InotifyIndex* global_instance_of_index = nullptr;
|
||||||
class InotifyIndex : public QThread, public Traverse_BFS
|
class InotifyIndex : public QThread, public Traverse_BFS
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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(const QString&);
|
||||||
~InotifyIndex();
|
~InotifyIndex();
|
||||||
|
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -90,8 +90,7 @@ void centerToScreen(QWidget* widget) {
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
qInstallMessageHandler(messageOutput);
|
||||||
// qInstallMessageHandler(messageOutput);
|
|
||||||
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
|
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
@ -112,11 +111,7 @@ int main(int argc, char *argv[])
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// qDebug() << "main start";
|
|
||||||
// FirstIndex fi("/home");
|
|
||||||
// fi.start();
|
|
||||||
// InotifyIndex ii("/home");
|
|
||||||
// ii.start();
|
|
||||||
/*-------------ukuisearchdbus Test start-----------------*/
|
/*-------------ukuisearchdbus Test start-----------------*/
|
||||||
// UkuiSearchQDBus usQDBus;
|
// UkuiSearchQDBus usQDBus;
|
||||||
// usQDBus.setInotifyMaxUserWatches();
|
// usQDBus.setInotifyMaxUserWatches();
|
||||||
|
@ -171,6 +166,12 @@ int main(int argc, char *argv[])
|
||||||
// qDebug() << "main start";
|
// qDebug() << "main start";
|
||||||
// FirstIndex* fi = new FirstIndex("/home");
|
// FirstIndex* fi = new FirstIndex("/home");
|
||||||
// fi->start();
|
// fi->start();
|
||||||
|
qDebug() << "main start";
|
||||||
|
FirstIndex fi("/home");
|
||||||
|
fi.start();
|
||||||
|
InotifyIndex* ii = InotifyIndex::getInstance("/home");
|
||||||
|
// InotifyIndex ii("/home");
|
||||||
|
ii->start();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
//#include "inotify-manager.h"
|
//#include "inotify-manager.h"
|
||||||
#include "settings-widget.h"
|
#include "settings-widget.h"
|
||||||
|
|
||||||
|
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
#include "search-result.h"
|
#include "search-result.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue