forked from openkylin/ukui-search
文件索引增加配置索引目录和黑名单功能;顺便解决了一点编译问题。
This commit is contained in:
parent
5abd667bb8
commit
24a94db0c6
|
@ -25,13 +25,13 @@ AppDBManager::~AppDBManager()
|
|||
}
|
||||
void AppDBManager::initDateBaseConnection()
|
||||
{
|
||||
if(!m_database->isValid()) {
|
||||
qWarning() << m_database->lastError();
|
||||
if(!m_database.isValid()) {
|
||||
qWarning() << m_database.lastError();
|
||||
QApplication::quit();
|
||||
}
|
||||
m_database->setDatabaseName(APP_DATABASE_PATH);
|
||||
if(!m_database->open()) {
|
||||
qWarning() << m_database->lastError();
|
||||
m_database.setDatabaseName(APP_DATABASE_PATH);
|
||||
if(!m_database.open()) {
|
||||
qWarning() << m_database.lastError();
|
||||
QApplication::quit();
|
||||
}
|
||||
//todo: 建表
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
private:
|
||||
explicit AppDBManager(QObject *parent = nullptr);
|
||||
~AppDBManager();
|
||||
QSqlDatabase *m_database = nullptr;
|
||||
QSqlDatabase m_database;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ HEADERS += \
|
|||
$$PWD/app-info-table-private.h \
|
||||
$$PWD/app-info-table.h
|
||||
|
||||
SOURCES += \ \
|
||||
SOURCES += \
|
||||
$$PWD/app-db-manager.cpp \
|
||||
$$PWD/app-info-table.cpp
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
//#include <QtConcurrent>
|
||||
#include "first-index.h"
|
||||
#include "dir-watcher.h"
|
||||
#include <QDebug>
|
||||
|
||||
#define NEW_QUEUE(a) a = new QQueue<QString>(); qDebug("---------------------------%s %s %s new at %d..",__FILE__,__FUNCTION__,#a,__LINE__);
|
||||
|
@ -158,8 +159,13 @@ void FirstIndex::run() {
|
|||
sem.acquire(4);
|
||||
sem.acquire(1);
|
||||
mutex1.unlock();
|
||||
this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
this->Traverse();
|
||||
|
||||
qInfo() << "index dir" << DirWatcher::getDirWatcher()->currentindexableDir();
|
||||
qInfo() << "index block dir" << DirWatcher::getDirWatcher()->currentBlackListOfIndex();
|
||||
setPath(DirWatcher::getDirWatcher()->currentindexableDir());
|
||||
setBlockPath(DirWatcher::getDirWatcher()->currentBlackListOfIndex());
|
||||
Traverse();
|
||||
|
||||
FileUtils::_max_index_count = this->q_index->length();
|
||||
qDebug() << "max_index_count:" << FileUtils::_max_index_count;
|
||||
sem.release(5);
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
#include "inotify-watch.h"
|
||||
#include "dir-watcher.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
using namespace UkuiSearch;
|
||||
static InotifyWatch* global_instance_InotifyWatch = nullptr;
|
||||
|
||||
UkuiSearch::InotifyWatch *UkuiSearch::InotifyWatch::getInstance(const QString &path)
|
||||
UkuiSearch::InotifyWatch *UkuiSearch::InotifyWatch::getInstance()
|
||||
{
|
||||
if(!global_instance_InotifyWatch) {
|
||||
global_instance_InotifyWatch = new InotifyWatch(path);
|
||||
global_instance_InotifyWatch = new InotifyWatch();
|
||||
}
|
||||
return global_instance_InotifyWatch;
|
||||
}
|
||||
|
||||
UkuiSearch::InotifyWatch::InotifyWatch(const QString &path): Traverse_BFS(path)
|
||||
UkuiSearch::InotifyWatch::InotifyWatch(): Traverse_BFS()
|
||||
{
|
||||
qDebug() << "setInotifyMaxUserWatches start";
|
||||
UkuiSearchQDBus usQDBus;
|
||||
|
@ -98,17 +99,40 @@ void InotifyWatch::DoSomething(const QFileInfo &info)
|
|||
void InotifyWatch::firstTraverse()
|
||||
{
|
||||
QQueue<QString> bfs;
|
||||
bfs.enqueue(this->path);
|
||||
for(QString blockPath : m_blockList) {
|
||||
for(QString path : m_pathList) {
|
||||
if(FileUtils::isOrUnder(path, blockPath)) {
|
||||
m_pathList.removeOne(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(QString path : m_pathList) {
|
||||
addWatch(path);
|
||||
bfs.enqueue(path);
|
||||
}
|
||||
|
||||
QFileInfoList list;
|
||||
QDir dir;
|
||||
QStringList tmpList = m_blockList;
|
||||
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
dir.setSorting(QDir::DirsFirst);
|
||||
while(!bfs.empty()) {
|
||||
dir.setPath(bfs.dequeue());
|
||||
list = dir.entryInfoList();
|
||||
for(auto i : list) {
|
||||
bool isBlocked = false;
|
||||
for(QString path : tmpList) {
|
||||
if(i.absoluteFilePath() == path) {
|
||||
isBlocked = true;
|
||||
tmpList.removeOne(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isBlocked)
|
||||
continue;
|
||||
|
||||
if(i.isDir() && (!(i.isSymLink()))) {
|
||||
this->addWatch(i.absoluteFilePath());
|
||||
addWatch(i.absoluteFilePath());
|
||||
bfs.enqueue(i.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
@ -147,9 +171,9 @@ void InotifyWatch::run()
|
|||
}
|
||||
}
|
||||
|
||||
this->addWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
this->firstTraverse();
|
||||
setPath(DirWatcher::getDirWatcher()->currentindexableDir());
|
||||
setBlockPath(DirWatcher::getDirWatcher()->currentBlackListOfIndex());
|
||||
firstTraverse();
|
||||
|
||||
int fifo_fd;
|
||||
char buffer[2];
|
||||
|
@ -385,6 +409,13 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len)
|
|||
// qDebug("mask:0x%x,",event->mask);
|
||||
if(event->name[0] != '.') {
|
||||
QString path = currentPath[event->wd] + '/' + event->name;
|
||||
|
||||
//过滤黑名单下的信号
|
||||
for(QString i : m_blockList) {
|
||||
if(FileUtils::isOrUnder(path, i))
|
||||
goto next;
|
||||
}
|
||||
|
||||
//Create top dir first, traverse it last.
|
||||
if(event->mask & IN_CREATE) {
|
||||
// qDebug() << "IN_CREATE";
|
||||
|
@ -397,7 +428,7 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len)
|
|||
if(event->mask & IN_ISDIR) {
|
||||
if(!QFileInfo(path).isSymLink()){
|
||||
addWatch(path);
|
||||
setPath(path);
|
||||
setPath(QStringList() << path);
|
||||
Traverse();
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +468,7 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len)
|
|||
|
||||
if(!QFileInfo(path).isSymLink()){
|
||||
addWatch(path);
|
||||
setPath(path);
|
||||
setPath(QStringList() << path);
|
||||
Traverse();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,7 @@ class InotifyWatch : public QThread, public Traverse_BFS
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static InotifyWatch* getInstance(const QString& path);
|
||||
static InotifyWatch* getInstance();
|
||||
|
||||
bool addWatch(const QString &path);
|
||||
bool removeWatch(const QString &path, bool removeFromDatabase = true);
|
||||
|
@ -34,7 +34,7 @@ protected:
|
|||
private Q_SLOTS:
|
||||
void slotEvent(char *buf, ssize_t len);
|
||||
private:
|
||||
explicit InotifyWatch(const QString& path);
|
||||
explicit InotifyWatch();
|
||||
~InotifyWatch();
|
||||
char * filter();
|
||||
void eventProcess(int socket);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#include "search-method-manager.h"
|
||||
#include "dir-watcher.h"
|
||||
using namespace UkuiSearch;
|
||||
static SearchMethodManager* global_instance = nullptr;
|
||||
|
||||
SearchMethodManager::SearchMethodManager()
|
||||
{
|
||||
m_iw = InotifyWatch::getInstance(HOME_PATH);
|
||||
m_iw = InotifyWatch::getInstance();
|
||||
|
||||
}
|
||||
|
||||
SearchMethodManager *SearchMethodManager::getInstance()
|
||||
|
|
|
@ -18,17 +18,29 @@
|
|||
*
|
||||
*/
|
||||
#include "traverse_bfs.h"
|
||||
#include "file-utils.h"
|
||||
using namespace UkuiSearch;
|
||||
Traverse_BFS::Traverse_BFS(const QString& path) {
|
||||
Traverse_BFS::Traverse_BFS(const QStringList &path) {
|
||||
Q_ASSERT('/' == path.at(0));
|
||||
this->path = path;
|
||||
m_pathList = path;
|
||||
}
|
||||
|
||||
void Traverse_BFS::Traverse() {
|
||||
QQueue<QString> bfs;
|
||||
bfs.enqueue(this->path);
|
||||
for(QString blockPath : m_blockList) {
|
||||
for(QString path : m_pathList) {
|
||||
if(FileUtils::isOrUnder(path, blockPath)) {
|
||||
m_pathList.removeOne(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(QString path : m_pathList) {
|
||||
bfs.enqueue(path);
|
||||
}
|
||||
|
||||
QFileInfoList list;
|
||||
QDir dir;
|
||||
QStringList tmpList = m_blockList;
|
||||
// QDir::Hidden
|
||||
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
dir.setSorting(QDir::DirsFirst);
|
||||
|
@ -36,6 +48,17 @@ void Traverse_BFS::Traverse() {
|
|||
dir.setPath(bfs.dequeue());
|
||||
list = dir.entryInfoList();
|
||||
for(auto i : list) {
|
||||
bool isBlocked = false;
|
||||
for(QString path : tmpList) {
|
||||
if(i.absoluteFilePath() == path) {
|
||||
isBlocked = true;
|
||||
tmpList.removeOne(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isBlocked)
|
||||
continue;
|
||||
|
||||
if(i.isDir() && (!(i.isSymLink()))) {
|
||||
bfs.enqueue(i.absoluteFilePath());
|
||||
}
|
||||
|
@ -44,6 +67,11 @@ void Traverse_BFS::Traverse() {
|
|||
}
|
||||
}
|
||||
|
||||
void Traverse_BFS::setPath(const QString& path) {
|
||||
this->path = path;
|
||||
void Traverse_BFS::setPath(const QStringList &pathList) {
|
||||
m_pathList = pathList;
|
||||
}
|
||||
|
||||
void Traverse_BFS::setBlockPath(const QStringList &pathList)
|
||||
{
|
||||
m_blockList =pathList;
|
||||
}
|
||||
|
|
|
@ -31,10 +31,12 @@ public:
|
|||
void Traverse();
|
||||
virtual ~Traverse_BFS() = default;
|
||||
virtual void DoSomething(const QFileInfo&) = 0;
|
||||
void setPath(const QString&);
|
||||
void setPath(const QStringList&);
|
||||
void setBlockPath(const QStringList &pathList);
|
||||
protected:
|
||||
Traverse_BFS(const QString&);
|
||||
QString path = "/home";
|
||||
Traverse_BFS(const QStringList&);
|
||||
QStringList m_pathList;
|
||||
QStringList m_blockList;
|
||||
private:
|
||||
Traverse_BFS(const Traverse_BFS&) = delete;
|
||||
void operator=(const Traverse_BFS&) = delete;
|
||||
|
|
|
@ -6,4 +6,5 @@ INCLUDEPATH += $$PWD/pluginmanage
|
|||
INCLUDEPATH += $$PWD/settingsearch
|
||||
INCLUDEPATH += $$PWD/appsearch
|
||||
INCLUDEPATH += $$PWD/searchinterface
|
||||
INCLUDEPATH += $$PWD/dirwatcher
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <QDebug>
|
||||
#include "ukui-search-service.h"
|
||||
#include "dir-watcher.h"
|
||||
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
|
||||
#define SEARCH_METHOD_KEY "indexSearch"
|
||||
using namespace UkuiSearch;
|
||||
|
@ -14,6 +15,7 @@ UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &app
|
|||
this->parseCmd(msg, true);
|
||||
});
|
||||
|
||||
DirWatcher::getDirWatcher();
|
||||
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt");
|
||||
initGsettings();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ TARGET = ukui-search-service
|
|||
VERSION = 1.0.0
|
||||
DEFINES += VERSION='\\"$${VERSION}\\"'
|
||||
CONFIG += c++11 link_pkgconfig no_keywords lrelease
|
||||
PKGCONFIG += gsettings-qt
|
||||
PKGCONFIG += gsettings-qt gio-unix-2.0
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
|
|
Loading…
Reference in New Issue