Merge pull request #59 from MouseZhangZh/0107-dev
🍱🍱🍱add multithread build index and our config file have some problems
This commit is contained in:
commit
2a09482b18
|
@ -17,6 +17,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
|||
{
|
||||
m_settings = new QSettings("org.ukui", "ukui-search", this);
|
||||
m_block_dirs_settings = new QSettings("org.ukui","ukui-search-block-dirs",this);
|
||||
this->forceSync();
|
||||
//the default number of transparency in mainwindow is 0.7
|
||||
//if someone changes the num in mainwindow, here should be modified too
|
||||
m_cache.insert(TRANSPARENCY_KEY, 0.7);
|
||||
|
@ -32,6 +33,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
|||
}
|
||||
m_cache.remove(TRANSPARENCY_KEY);
|
||||
m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble());
|
||||
|
||||
}
|
||||
|
||||
GlobalSettings::~GlobalSettings()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//aborted --MouseZhangZh
|
||||
#ifndef FILETYPEFILTER_H
|
||||
#define FILETYPEFILTER_H
|
||||
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
//#include <QtConcurrent>
|
||||
#include "first-index.h"
|
||||
#include <QDebug>
|
||||
|
||||
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
|
||||
{
|
||||
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||
QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||
|
||||
qDebug() << "indexDataBaseStatus: " << indexDataBaseStatus;
|
||||
qDebug() << "contentIndexDataBaseStatus: " << contentIndexDataBaseStatus;
|
||||
|
||||
|
||||
if (indexDataBaseStatus == "" || contentIndexDataBaseStatus == ""){
|
||||
this->bool_dataBaseExist = false;
|
||||
}
|
||||
if (indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2"){
|
||||
this->bool_dataBaseStatusOK = false;
|
||||
}
|
||||
|
||||
this->q_index = new QQueue<QVector<QString>>();
|
||||
this->q_content_index = new QQueue<QString>();
|
||||
|
||||
// this->mlm = new MessageListManager();
|
||||
}
|
||||
|
||||
FirstIndex::~FirstIndex()
|
||||
{
|
||||
delete this->q_index;
|
||||
this->q_index = nullptr;
|
||||
this->q_content_index = nullptr;
|
||||
delete this->q_content_index;
|
||||
// delete this->mlm;
|
||||
// this->mlm = nullptr;
|
||||
}
|
||||
|
||||
void FirstIndex::DoSomething(const QFileInfo& fileInfo){
|
||||
// qDebug() << "there are some shit here";
|
||||
this->q_index->enqueue(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0"));
|
||||
for (auto i : this->targetFileTypeVec){
|
||||
if (fileInfo.fileName().endsWith(i)){
|
||||
this->q_content_index->enqueue(fileInfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FirstIndex::run(){
|
||||
if (this->bool_dataBaseExist){
|
||||
if (this->bool_dataBaseStatusOK){
|
||||
this->quit();
|
||||
// this->wait();
|
||||
}
|
||||
else{
|
||||
//if the parameter is false, index won't be rebuild
|
||||
//if it is true, index will be rebuild
|
||||
this->p_indexGenerator = IndexGenerator::getInstance(true);
|
||||
}
|
||||
}
|
||||
else{
|
||||
this->p_indexGenerator = IndexGenerator::getInstance(false);
|
||||
}
|
||||
QSemaphore sem(5);
|
||||
QMutex mutex1, mutex2, mutex3;
|
||||
mutex1.lock();
|
||||
mutex2.lock();
|
||||
mutex3.lock();
|
||||
sem.acquire(4);
|
||||
QtConcurrent::run([&](){
|
||||
sem.acquire(1);
|
||||
mutex1.unlock();
|
||||
this->Traverse();
|
||||
sem.release(5);
|
||||
});
|
||||
QtConcurrent::run([&](){
|
||||
sem.acquire(2);
|
||||
mutex2.unlock();
|
||||
qDebug() << "index start;";
|
||||
this->p_indexGenerator->creatAllIndex(this->q_index);
|
||||
qDebug() << "index end;";
|
||||
sem.release(2);
|
||||
});
|
||||
QtConcurrent::run([&](){
|
||||
sem.acquire(2);
|
||||
mutex3.unlock();
|
||||
qDebug() << "content index start;";
|
||||
this->p_indexGenerator->creatAllIndex(this->q_content_index);
|
||||
qDebug() << "content index end;";
|
||||
sem.release(2);
|
||||
});
|
||||
mutex1.lock();
|
||||
mutex2.lock();
|
||||
mutex3.lock();
|
||||
sem.acquire(5);
|
||||
mutex1.unlock();
|
||||
mutex2.unlock();
|
||||
mutex3.unlock();
|
||||
qDebug() << "first index end;";
|
||||
this->quit();
|
||||
// this->wait();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef FIRSTINDEX_H
|
||||
#define FIRSTINDEX_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
//#include <QtConcurrent>
|
||||
#include "traverse_bfs.h"
|
||||
#include "global-settings.h"
|
||||
#include "index-generator.h"
|
||||
#include "messagelist-manager.h"
|
||||
|
||||
class FirstIndex : public QThread, public Traverse_BFS
|
||||
{
|
||||
public:
|
||||
FirstIndex(const QString&);
|
||||
~FirstIndex();
|
||||
virtual void DoSomething(const QFileInfo &) final;
|
||||
protected:
|
||||
void run() override;
|
||||
private:
|
||||
FirstIndex(const FirstIndex&) = delete;
|
||||
void operator=(const FirstIndex&) = delete;
|
||||
bool bool_dataBaseStatusOK = false;
|
||||
bool bool_dataBaseExist = false;
|
||||
IndexGenerator* p_indexGenerator;
|
||||
|
||||
//here should be refact
|
||||
// MessageListManager* mlm;
|
||||
|
||||
//test
|
||||
QQueue<QVector<QString>>* q_index;
|
||||
QQueue<QString>* q_content_index;
|
||||
const QVector<QString> targetFileTypeVec ={
|
||||
// QString(".doc"),
|
||||
QString(".docx"),
|
||||
// QString(".ppt"),
|
||||
// QString(".pptx"),
|
||||
// QString(".xls"),
|
||||
// QString(".xlsx"),
|
||||
QString(".txt")};
|
||||
};
|
||||
|
||||
#endif // FIRSTINDEX_H
|
|
@ -117,6 +117,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
|
|||
|
||||
IndexGenerator::~IndexGenerator()
|
||||
{
|
||||
qDebug() << "~IndexGenerator";
|
||||
if(m_datebase_path)
|
||||
delete m_datebase_path;
|
||||
if(m_database_content)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <xapian.h>
|
||||
#include <QObject>
|
||||
|
||||
//#include <QtConcurrent/QtConcurrent>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QCryptographicHash>
|
||||
|
|
|
@ -6,11 +6,11 @@ HEADERS += \
|
|||
$$PWD/document.h \
|
||||
$$PWD/filetypefilter.h \
|
||||
$$PWD/file-reader.h \
|
||||
$$PWD/first-index.h \
|
||||
$$PWD/index-generator.h \
|
||||
# $$PWD/inotify-manager.h \
|
||||
$$PWD/inotify.h \
|
||||
$$PWD/messagelist-manager.h \
|
||||
$$PWD/messagelisttemplate.h \
|
||||
$$PWD/traverse_bfs.h \
|
||||
# $$PWD/text-content-indexer.h \
|
||||
$$PWD/file-searcher.h \
|
||||
|
@ -22,11 +22,11 @@ SOURCES += \
|
|||
$$PWD/document.cpp \
|
||||
$$PWD/filetypefilter.cpp \
|
||||
$$PWD/file-reader.cpp \
|
||||
$$PWD/first-index.cpp \
|
||||
$$PWD/index-generator.cpp \
|
||||
# $$PWD/inotify-manager.cpp \
|
||||
$$PWD/inotify.cpp \
|
||||
$$PWD/messagelist-manager.cpp \
|
||||
$$PWD/messagelisttemplate.cpp \
|
||||
$$PWD/test-Inotify-Manager.cpp \
|
||||
$$PWD/traverse_bfs.cpp \
|
||||
# $$PWD/text-content-indexer.cpp \
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//aborted --MouseZhangZh
|
||||
#ifndef INOTIFY_H
|
||||
#define INOTIFY_H
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ MessageListManager::MessageListManager(){
|
|||
|
||||
MessageListManager::~MessageListManager(){
|
||||
delete this->messageList;
|
||||
delete this->indexGeneratorThread;
|
||||
// delete this->indexGeneratorThread;
|
||||
//delete this->ig;
|
||||
|
||||
this->messageList = nullptr;
|
||||
this->ig = nullptr;
|
||||
this->indexGeneratorThread = nullptr;
|
||||
// this->indexGeneratorThread = nullptr;
|
||||
}
|
||||
|
||||
void MessageListManager::AddMessage(const QVector<QString>& pathVec){
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//aborted --MouseZhangZh
|
||||
#ifndef MESSAGELISTMANAGER_H
|
||||
#define MESSAGELISTMANAGER_H
|
||||
|
||||
|
@ -22,7 +23,7 @@ private:
|
|||
|
||||
size_t length = 80000;
|
||||
IndexGenerator* ig;
|
||||
QThread* indexGeneratorThread;
|
||||
// QThread* indexGeneratorThread;
|
||||
|
||||
Q_SIGNALS:
|
||||
bool Send(QStringList*);
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
#include "messagelisttemplate.h"
|
||||
#include <QtConcurrent>
|
||||
|
||||
//重构部分,暂时不要调用
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::MessageVectorTemplate(SOMETHINGINSTANCE* somethingInstance)
|
||||
{
|
||||
this->somethingInstance = somethingInstance;
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::addMessage(const MESSAGETYPE& message)
|
||||
{
|
||||
this->messageVec->append(message);
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::sendMessage()
|
||||
{
|
||||
QtConcurrent::run(
|
||||
[&](){
|
||||
// if (this->m_mutex.try_lock(this->m_time)){
|
||||
// std::cout << "send_test_time" << std::endl;
|
||||
// this->m_mutex.unlock();
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::sendDeleteMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
void MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::setAutoSendMessageLength(const size_t& length)
|
||||
{
|
||||
this->m_length = length;
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
void MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::setAutoSendMessageTime(const size_t& time)
|
||||
{
|
||||
this->m_time = time;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
#ifndef MESSAGELISTTEMPLATE_H
|
||||
#define MESSAGELISTTEMPLATE_H
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
class MessageVectorTemplate
|
||||
{
|
||||
public:
|
||||
MessageVectorTemplate(SOMETHINGINSTANCE*);
|
||||
|
||||
bool addMessage(const MESSAGETYPE&);
|
||||
bool sendMessage();
|
||||
bool sendDeleteMessage();
|
||||
void setAutoSendMessageLength(const size_t&);
|
||||
void setAutoSendMessageTime(const size_t&);
|
||||
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::vector<MESSAGETYPE>> messageVec = std::make_shared<std::vector<MESSAGETYPE>>();
|
||||
std::unique_ptr<SOMETHINGINSTANCE> somethingInstance;
|
||||
|
||||
size_t m_length = 80000;
|
||||
size_t m_time = 1000;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
#endif // MESSAGELISTTEMPLATE_H
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
Traverse_BFS::Traverse_BFS(const QString& path)
|
||||
{
|
||||
Q_ASSERT('/' == path.at(0));
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
class Traverse_BFS
|
||||
{
|
||||
public:
|
||||
explicit Traverse_BFS(const QString&);
|
||||
void Traverse();
|
||||
virtual void DoSomething(const QFileInfo&) = 0;
|
||||
void setPath(const QString&);
|
||||
protected:
|
||||
explicit Traverse_BFS(const QString&);
|
||||
private:
|
||||
Traverse_BFS(const Traverse_BFS&) = delete;
|
||||
void operator=(const Traverse_BFS&) = delete;
|
||||
QString path = "/home";
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "index/inotify.h"
|
||||
#include "file-utils.h"
|
||||
#include "global-settings.h"
|
||||
#include "index/first-index.h"
|
||||
|
||||
#include "index/filetypefilter.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
QT += core concurrent xml widgets dbus
|
||||
QT += core xml widgets dbus concurrent
|
||||
VERSION = 0.0.1
|
||||
|
||||
TARGET = ukui-search
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -38,7 +38,8 @@ void messageOutput(QtMsgType type, const QMessageLogContext &context, const QStr
|
|||
QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit();
|
||||
|
||||
bool showDebug = true;
|
||||
QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log";
|
||||
// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log";
|
||||
QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search.log";
|
||||
if (!QFile::exists(logFilePath)) {
|
||||
showDebug = false;
|
||||
}
|
||||
|
@ -89,6 +90,12 @@ void centerToScreen(QWidget* widget) {
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
qInstallMessageHandler(messageOutput);
|
||||
|
||||
qDebug() << "main start";
|
||||
FirstIndex* fi = new FirstIndex("/home");
|
||||
fi->start();
|
||||
/*-------------ukuisearchdbus Test start-----------------*/
|
||||
// UkuiSearchQDBus usQDBus;
|
||||
// usQDBus.setInotifyMaxUserWatches();
|
||||
|
@ -127,7 +134,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
QtSingleApplication app("ukui-search", argc, argv);
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
qInstallMessageHandler(messageOutput);
|
||||
|
||||
qDebug() << "main start x2";
|
||||
|
||||
if(app.isRunning())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue