forked from openkylin/ukui-search
add the feature of database won't be rebuild after restart and fix some bugs
This commit is contained in:
parent
872716e7f0
commit
e046b609f1
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -126,6 +128,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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -92,6 +92,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
|
||||
qInstallMessageHandler(messageOutput);
|
||||
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
|
@ -111,11 +112,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();
|
||||
|
@ -170,6 +167,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();
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ void MainWindow::searchContent(QString searchcontent){
|
|||
connect(search, &FileSearcher::resultContent, this, [ = ](QQueue<QPair<QString,QStringList>> * contentQueue) {
|
||||
qWarning()<<"resultContent---";
|
||||
});
|
||||
search->onKeywordSearch(searchcontent);
|
||||
// search->onKeywordSearch(searchcontent);
|
||||
//将搜索结果加入列表
|
||||
m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
||||
|
||||
|
|
Loading…
Reference in New Issue