forked from openkylin/ukui-search
Merge pull request #61 from MouseZhangZh/0107-dev
🗑🗑🗑delete files unuseful from git, but they're still exist.
This commit is contained in:
commit
af19c6c94d
|
@ -1,22 +0,0 @@
|
|||
#include "blockdirs.h"
|
||||
|
||||
//优先级先放一下
|
||||
BlockDirs::BlockDirs(QObject *parent) : QObject(parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int BlockDirs::setValue(const QString& path, const int &type)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
int BlockDirs::removeValue(const QString& path, const int &type)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
int BlockDirs::getValues()
|
||||
{
|
||||
return FAILED;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef BLOCKDIRS_H
|
||||
#define BLOCKDIRS_H
|
||||
|
||||
#include <QObject>
|
||||
#include "global-settings.h"
|
||||
|
||||
#ifndef MYTYPE
|
||||
#define MYTYPE
|
||||
#define MYDIR 0
|
||||
#define MYFILE 1
|
||||
#endif // MYTYPE
|
||||
|
||||
#ifndef SETVALUERESULT
|
||||
#define SETVALUERESULT
|
||||
#define DONOTHING 1
|
||||
#define FAILED -1
|
||||
#define SUCCESSED 0
|
||||
#endif // SETVALUERESULT
|
||||
|
||||
class BlockDirs : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BlockDirs(QObject *parent = nullptr);
|
||||
int setValue(const QString&, const int&);
|
||||
int removeValue(const QString&, const int&);
|
||||
int getValues();
|
||||
Q_SIGNALS:
|
||||
|
||||
};
|
||||
|
||||
#endif // BLOCKDIRS_H
|
|
@ -7,7 +7,6 @@
|
|||
#include "traverse_bfs.h"
|
||||
#include "global-settings.h"
|
||||
#include "index-generator.h"
|
||||
#include "messagelist-manager.h"
|
||||
|
||||
class FirstIndex : public QThread, public Traverse_BFS
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ INCLUDEPATH += $$PWD
|
|||
|
||||
HEADERS += \
|
||||
# $$PWD/chinesecharacterstopinyin.h \
|
||||
$$PWD/blockdirs.h \
|
||||
$$PWD/document.h \
|
||||
$$PWD/filetypefilter.h \
|
||||
$$PWD/file-reader.h \
|
||||
|
@ -10,8 +9,6 @@ HEADERS += \
|
|||
$$PWD/index-generator.h \
|
||||
# $$PWD/inotify-manager.h \
|
||||
$$PWD/inotify-index.h \
|
||||
$$PWD/inotify.h \
|
||||
$$PWD/messagelist-manager.h \
|
||||
$$PWD/traverse_bfs.h \
|
||||
# $$PWD/text-content-indexer.h \
|
||||
$$PWD/file-searcher.h \
|
||||
|
@ -19,7 +16,6 @@ HEADERS += \
|
|||
|
||||
SOURCES += \
|
||||
# $$PWD/chinesecharacterstopinyin.cpp \
|
||||
$$PWD/blockdirs.cpp \
|
||||
$$PWD/document.cpp \
|
||||
$$PWD/filetypefilter.cpp \
|
||||
$$PWD/file-reader.cpp \
|
||||
|
@ -27,9 +23,6 @@ SOURCES += \
|
|||
$$PWD/index-generator.cpp \
|
||||
# $$PWD/inotify-manager.cpp \
|
||||
$$PWD/inotify-index.cpp \
|
||||
$$PWD/inotify.cpp \
|
||||
$$PWD/messagelist-manager.cpp \
|
||||
$$PWD/test-Inotify-Manager.cpp \
|
||||
$$PWD/traverse_bfs.cpp \
|
||||
# $$PWD/text-content-indexer.cpp \
|
||||
$$PWD/file-searcher.cpp \
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
#include "inotify.h"
|
||||
#include "ukui-search-qdbus.h"
|
||||
|
||||
InotifyManagerRefact::InotifyManagerRefact(const QString& path) : Traverse_BFS(path)
|
||||
{
|
||||
|
||||
/*-------------ukuisearchdbus Test start-----------------*/
|
||||
qDebug() << "setInotifyMaxUserWatches start";
|
||||
UkuiSearchQDBus usQDBus;
|
||||
usQDBus.setInotifyMaxUserWatches();
|
||||
qDebug() << "setInotifyMaxUserWatches end";
|
||||
|
||||
/*-------------ukuisearchdbus Test End-----------------*/
|
||||
|
||||
|
||||
// dirPath = new QMap<QString, QStringList>();
|
||||
m_fd = inotify_init();
|
||||
qDebug() << "m_fd----------->" <<m_fd;
|
||||
num2string.insert(IN_ACCESS, "IN_ACCESS");
|
||||
num2string.insert(IN_MODIFY, "IN_MODIFY");
|
||||
num2string.insert(IN_ATTRIB, "IN_ATTRIB");
|
||||
num2string.insert(IN_CLOSE_WRITE, "IN_CLOSE_WRITE");
|
||||
num2string.insert(IN_CLOSE_NOWRITE, "IN_CLOSE_NOWRITE");
|
||||
num2string.insert(IN_CLOSE, "IN_CLOSE");
|
||||
num2string.insert(IN_OPEN, "IN_OPEN");
|
||||
num2string.insert(IN_MOVED_FROM, "IN_MOVED_FROM");
|
||||
num2string.insert(IN_MOVED_TO, "IN_MOVED_TO");
|
||||
num2string.insert(IN_MOVE, "IN_MOVE");
|
||||
num2string.insert(IN_CREATE, "IN_CREATE");
|
||||
num2string.insert(IN_DELETE, "IN_DELETE");
|
||||
num2string.insert(IN_DELETE_SELF, "IN_DELETE_SELF");
|
||||
num2string.insert(IN_MOVE_SELF, "IN_MOVE_SELF");
|
||||
num2string.insert(IN_UNMOUNT, "IN_UNMOUNT");
|
||||
num2string.insert(IN_Q_OVERFLOW, "IN_Q_OVERFLOW");
|
||||
num2string.insert(IN_IGNORED, "IN_IGNORED");
|
||||
// this->mlm = new MessageListManager();
|
||||
|
||||
this->AddWatch("/home");
|
||||
this->Traverse();
|
||||
this->SendRestMessage();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
InotifyManagerRefact::~InotifyManagerRefact(){
|
||||
// delete this->mlm;
|
||||
// this->mlm = nullptr;
|
||||
// delete dirPath;
|
||||
// dirPath = nullptr;
|
||||
}
|
||||
|
||||
void InotifyManagerRefact::DoSomething(const QFileInfo& fileInfo){
|
||||
// this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0"));
|
||||
// if(QString(bool((fileInfo.isDir()))) == QString("1"))
|
||||
// qDebug()<<"bool((fileInfo.isDir())"<<QString(fileInfo.isDir());
|
||||
// this->mlm->AddMessage(QVector<QString>() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1");
|
||||
if(fileInfo.isDir()){
|
||||
this->AddWatch(fileInfo.absoluteFilePath());
|
||||
}
|
||||
// else{
|
||||
// this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir()))));
|
||||
// }
|
||||
}
|
||||
|
||||
void InotifyManagerRefact::SendRestMessage()
|
||||
{
|
||||
// this->mlm->SendMessage();
|
||||
}
|
||||
|
||||
bool InotifyManagerRefact::AddWatch(const QString &path){
|
||||
//m_fd = inotify_init();
|
||||
// qDebug() << "m_fd: " <<m_fd;
|
||||
//int ret = inotify_add_watch(m_fd, path.toStdString().c_str(), IN_ALL_EVENTS);
|
||||
int ret = inotify_add_watch(m_fd, path.toStdString().c_str(), (IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE));
|
||||
Q_ASSERT(ret == 0);
|
||||
if (ret == -1) {
|
||||
qDebug() << "AddWatch error:" << path;
|
||||
return false;
|
||||
}
|
||||
currentPath[ret] = path;
|
||||
//qDebug() << "Watch:" << path;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InotifyManagerRefact::RemoveWatch(const QString &path){
|
||||
int ret = inotify_rm_watch(m_fd, currentPath.key(path));
|
||||
if (ret){
|
||||
qDebug() << "remove path error";
|
||||
return false;
|
||||
}
|
||||
// qDebug() << "remove path: " << path;
|
||||
|
||||
for (QMap<int, QString>::Iterator i = currentPath.begin(); i != currentPath.end();){
|
||||
if (i.value().length() > path.length()){
|
||||
if (i.value().mid(0, path.length()) == path){
|
||||
qDebug() << i.value();
|
||||
/*--------------------------------*/
|
||||
//在此调用删除索引
|
||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(path));
|
||||
/*--------------------------------*/
|
||||
currentPath.erase(i++);
|
||||
}
|
||||
else{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
qDebug() << path;
|
||||
//这个貌似不用删,先mark一下
|
||||
//currentPath.remove(currentPath.key(path));
|
||||
return true;
|
||||
}
|
||||
|
||||
void InotifyManagerRefact::run(){
|
||||
|
||||
char * p;
|
||||
char buf[BUF_LEN] __attribute__((aligned(8)));
|
||||
|
||||
ssize_t numRead;
|
||||
|
||||
for (;;) { /* Read events forever */
|
||||
numRead = read(m_fd, buf, BUF_LEN);
|
||||
if (numRead == 0) {
|
||||
qDebug() << "read() from inotify fd returned 0!";
|
||||
}
|
||||
if (numRead == -1) {
|
||||
qDebug() << "read";
|
||||
}
|
||||
qDebug() << "Read " << numRead << " bytes from inotify fd";
|
||||
|
||||
/* Process all of the events in buffer returned by read() */
|
||||
|
||||
for (p = buf; p < buf + numRead;) {
|
||||
struct inotify_event * event = reinterpret_cast<inotify_event *>(p);
|
||||
if(event->name[0] != '.'){
|
||||
// if(true){
|
||||
//这个位运算不要在意,只是懒得把文件夹、文件和事件排列组合了,只是看一下事件的类型
|
||||
qDebug() << "Read Event: " << num2string[(event->mask & 0x0000ffff)] << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd;
|
||||
//num2string[event->mask & 0x0000ffff]
|
||||
// IndexGenerator::getInstance()->creatAllIndex(new QStringList(currentPath[event->wd] + event->name));
|
||||
|
||||
/*--------------------------------*/
|
||||
|
||||
//传创建或移动过来的文件路径
|
||||
if((event->mask & IN_CREATE) | (event->mask & IN_MOVED_TO)){
|
||||
//添加监视要先序遍历,先添加top节点
|
||||
if (event->mask & IN_ISDIR){
|
||||
AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||
this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||
Traverse();
|
||||
}
|
||||
// else {
|
||||
|
||||
//IndexGenerator::getInstance()->creatAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||
// this->mlm->AddMessage(QVector<QString>() << event->name << (currentPath[event->wd] + '/' + event->name) << QString(bool((event->mask & IN_ISDIR))));
|
||||
// this->mlm->SendMessage();
|
||||
// }
|
||||
}
|
||||
else if((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){
|
||||
if (event->mask & IN_ISDIR){
|
||||
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
||||
}
|
||||
// else {
|
||||
//这里调用删除索引
|
||||
// this->mlm->AddMessage(QVector<QString>() << event->name << (currentPath[event->wd] + '/' + event->name) << QString(bool((event->mask & IN_ISDIR))));
|
||||
// this->mlm->SendDeleteMessage();
|
||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||
// }
|
||||
}
|
||||
/*--------------------------------*/
|
||||
}
|
||||
p += sizeof(struct inotify_event) + event->len;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
//aborted --MouseZhangZh
|
||||
#ifndef INOTIFY_H
|
||||
#define INOTIFY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <unistd.h>
|
||||
#include <sys/inotify.h>
|
||||
#include "traverse_bfs.h"
|
||||
#include "messagelist-manager.h"
|
||||
#define BUF_LEN 1024
|
||||
|
||||
class InotifyManagerRefact : public QThread, public Traverse_BFS
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InotifyManagerRefact(const QString&);
|
||||
~InotifyManagerRefact();
|
||||
|
||||
bool AddWatch(const QString&);
|
||||
bool RemoveWatch(const QString&);
|
||||
virtual void DoSomething(const QFileInfo &) final;
|
||||
void SendRestMessage();
|
||||
Q_SIGNALS:
|
||||
protected:
|
||||
void run() override;
|
||||
private:
|
||||
QString *m_watch_path;
|
||||
int m_fd;
|
||||
QMap<int, QString> currentPath;
|
||||
QMap<int, QString> num2string;
|
||||
// MessageListManager* mlm;
|
||||
|
||||
QMap<QString, QStringList>* dirPath;
|
||||
};
|
||||
|
||||
#endif // INOTIFY_H
|
|
@ -1,64 +0,0 @@
|
|||
#include "messagelist-manager.h"
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
//#include <unistd.h>
|
||||
|
||||
MessageListManager::MessageListManager(){
|
||||
this->messageList = new QList<QVector<QString>>();
|
||||
this->ig = IndexGenerator::getInstance();
|
||||
// indexGeneratorThread = new QThread();
|
||||
// this->ig->moveToThread(indexGeneratorThread);
|
||||
// connect(this,&MessageListManager::Send, this->ig, &IndexGenerator::creatAllIndex/*, Qt::QueuedConnection*/);
|
||||
// connect(this,&MessageListManager::Send1, this->ig, [=](QStringList *l){
|
||||
// qDebug()<<"send"<<*l;
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
MessageListManager::~MessageListManager(){
|
||||
delete this->messageList;
|
||||
// delete this->indexGeneratorThread;
|
||||
//delete this->ig;
|
||||
|
||||
this->messageList = nullptr;
|
||||
this->ig = nullptr;
|
||||
// this->indexGeneratorThread = nullptr;
|
||||
}
|
||||
|
||||
void MessageListManager::AddMessage(const QVector<QString>& pathVec){
|
||||
this->messageList->append(pathVec);
|
||||
if (static_cast<size_t>(this->messageList->length()) >= this->length){
|
||||
this->SendMessage();
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageListManager::SendMessage(){
|
||||
//Q_EMIT Send(this->messageList);
|
||||
if (this->messageList->empty()){
|
||||
return true;
|
||||
}
|
||||
|
||||
// Q_EMIT Send(this->messageList);
|
||||
// qDebug() << "emit";
|
||||
this->ig->creatAllIndex(this->messageList);
|
||||
|
||||
//sleep(1);
|
||||
this->messageList->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessageListManager::SendDeleteMessage(){
|
||||
if (this->messageList->empty()){
|
||||
return true;
|
||||
}
|
||||
|
||||
// this->ig->deleteAllIndex(this->messageList);
|
||||
this->messageList->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MessageListManager::SetAutoSendMessageLength(const size_t& length){
|
||||
this->length = length;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
//aborted --MouseZhangZh
|
||||
#ifndef MESSAGELISTMANAGER_H
|
||||
#define MESSAGELISTMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "index-generator.h"
|
||||
|
||||
class MessageListManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MessageListManager();
|
||||
~MessageListManager();
|
||||
|
||||
void AddMessage(const QVector<QString>&);
|
||||
bool SendMessage();
|
||||
bool SendDeleteMessage();
|
||||
void SetAutoSendMessageLength(const size_t&);
|
||||
|
||||
private:
|
||||
// QStringList* messageList;
|
||||
QList<QVector<QString>>* messageList;
|
||||
|
||||
size_t length = 80000;
|
||||
IndexGenerator* ig;
|
||||
// QThread* indexGeneratorThread;
|
||||
|
||||
Q_SIGNALS:
|
||||
bool Send(QStringList*);
|
||||
};
|
||||
|
||||
#endif // MESSAGELISTMANAGER_H
|
|
@ -1,131 +0,0 @@
|
|||
#include <QTime>
|
||||
#include <QDebug>
|
||||
#include "inotify-manager.h"
|
||||
#include "chinesecharacterstopinyin.h"
|
||||
#include "inotify.h"
|
||||
|
||||
void testTraverse(void){
|
||||
/*-------------Inotify Test Start---------------*/
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// InotifyManager* im = new InotifyManager();
|
||||
// im->AddWatch("/home");
|
||||
// im->Traverse_BFS("/home", true);
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
// im->start();
|
||||
/*-------------Inotify Test End-----------------*/
|
||||
|
||||
/*-------------PinyinSearch Test Start---------------*/
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// QString test("test");
|
||||
// qDebug() << IndexGenerator::IndexSearch(test);
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
/*-------------PinyinSearch Test End-----------------*/
|
||||
|
||||
/*-------------InotyifyRefact Test Start---------------*/
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
|
||||
// imr->AddWatch("/home");
|
||||
// imr->setPath("/home");
|
||||
// imr->Traverse();
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
/*-------------InotyifyRefact Test End-----------------*/
|
||||
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void removeTone(){
|
||||
/*-------------Remove Tone Start---------------*/
|
||||
qDebug() << chineseCharactersToPinyin::find("z测试策士xl123123");
|
||||
|
||||
QFile file("://index/pinyinWithTone.txt");
|
||||
QFile fileOut("/home/zhangzihao/ukui/ns/ukui-search/index/pinyinWithoutTone.txt");
|
||||
fileOut.open(QIODevice::WriteOnly/* | QIODevice::Text*/);
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qDebug("File: '%s' open failed!", file.fileName().toStdString().c_str());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while(!file.atEnd()) {
|
||||
QString content = QString::fromUtf8(file.readLine());
|
||||
content.replace("ā", "a")
|
||||
.replace("á", "a")
|
||||
.replace("ǎ", "a")
|
||||
.replace("à", "a")
|
||||
.replace("ō", "o")
|
||||
.replace("ó", "o")
|
||||
.replace("ǒ", "o")
|
||||
.replace("ò", "o")
|
||||
.replace("ê", "e")
|
||||
.replace("ē", "e")
|
||||
.replace("é", "e")
|
||||
.replace("ě", "e")
|
||||
.replace("è", "e")
|
||||
.replace("ī", "i")
|
||||
.replace("í", "i")
|
||||
.replace("ǐ", "i")
|
||||
.replace("ì", "i")
|
||||
.replace("ū", "u")
|
||||
.replace("ú", "u")
|
||||
.replace("ǔ", "u")
|
||||
.replace("ù", "u")
|
||||
//l和n后面的ü写作v
|
||||
.replace("lǖ", "lv")
|
||||
.replace("lǘ", "lv")
|
||||
.replace("lǚ", "lv")
|
||||
.replace("lǜ", "lv")
|
||||
.replace("lü", "lv")
|
||||
.replace("nǖ", "nv")
|
||||
.replace("nǘ", "nv")
|
||||
.replace("nǚ", "nv")
|
||||
.replace("nǜ", "nv")
|
||||
.replace("nü", "nv")
|
||||
//l和n后面的ü替换之后,其他的ü替换为u
|
||||
.replace("ǖ", "u")
|
||||
.replace("ǘ", "u")
|
||||
.replace("ǚ", "u")
|
||||
.replace("ǜ", "u")
|
||||
.replace("ü", "u")
|
||||
.replace("ê", "e")
|
||||
.replace("ɑ", "a")
|
||||
.replace("", "m")
|
||||
.replace("ń", "n")
|
||||
.replace("", "n")
|
||||
.replace("ɡ", "g");
|
||||
//去除同音不同调
|
||||
//QString content = QString::fromUtf8(file.readLine());
|
||||
|
||||
QStringList temp = content.split(" ").first().split(",").toSet().toList();
|
||||
QString outContent;
|
||||
for (auto i : temp){
|
||||
outContent += i;
|
||||
outContent += ",";
|
||||
}
|
||||
outContent = outContent.left(outContent.size() - 1);
|
||||
outContent += " ";
|
||||
outContent += content.split(" ").last().trimmed();
|
||||
outContent += "\n";
|
||||
fileOut.write(outContent.toUtf8());
|
||||
// temp.toSet().toList();
|
||||
//content.split(" ").first().split(",")
|
||||
|
||||
//map[content.split(" ").last().trimmed()] = content.split(" ").first().split(",");
|
||||
|
||||
|
||||
// ā á ǎ à ō ó ǒ ò ê ē é ě è ī í ǐ ì ū ú ǔ ù ǖ ǘ ǚ ǜ ü ê ɑ ń ň ɡ
|
||||
// fileOut.write(content.toUtf8());
|
||||
qDebug() << content;
|
||||
}
|
||||
|
||||
file.close();
|
||||
fileOut.close();
|
||||
/*-------------Remove Tone End-----------------*/
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
#include "index/file-searcher.h"
|
||||
#include "appsearch/app-match.h"
|
||||
#include "settingsearch/setting-match.h"
|
||||
#include "index/inotify.h"
|
||||
#include "file-utils.h"
|
||||
#include "global-settings.h"
|
||||
#include "index/first-index.h"
|
||||
|
|
Loading…
Reference in New Issue