delete unuseful files

This commit is contained in:
zhangzihao 2021-01-10 16:32:16 +08:00
parent 2b89f0a414
commit 417400e8b7
8 changed files with 0 additions and 408 deletions

View File

@ -1,8 +0,0 @@
#include "chinesecharacterstopinyin.h"
chineseCharactersToPinyin::chineseCharactersToPinyin(QObject *parent) : QObject(parent)
{
map = loadHanziTable("://index/pinyinWithoutTone.txt");
}

View File

@ -1,56 +0,0 @@
#ifndef CHINESECHARACTERSTOPINYIN_H
#define CHINESECHARACTERSTOPINYIN_H
#include <QObject>
#include <QMap>
#include <QFile>
class chineseCharactersToPinyin : public QObject
{
Q_OBJECT
public:
explicit chineseCharactersToPinyin(QObject *parent = nullptr);
static QString find(const QString &hanzi)
{
static QMap<QString, QStringList> map = loadHanziTable("://index/pinyinWithoutTone.txt");
// static QMap<QString, QStringList> map;
QString output;
QStringList stringList = hanzi.split("");
/* 遍历查找汉字-拼音对照表的内容并将汉字替换为拼音 */
for (const QString &str : stringList) {
if (map.contains(str))
output += map[str].first();
else
output += str;
}
return output;
}
Q_SIGNALS:
private:
static QMap<QString, QStringList> map;
/* 加载汉字对照表 */
static QMap<QString, QStringList> loadHanziTable(const QString &fileName)
{
QMap<QString, QStringList> map;
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
qDebug("File: '%s' open failed!", file.fileName().toStdString().c_str());
return map;
}
/* 读取汉字对照表文件并转换为QMap存储 */
while(!file.atEnd()) {
QString content = QString::fromUtf8(file.readLine());
map[content.split(" ").last().trimmed()] = content.split(" ").first().split(",");
}
file.close();
return map;
}
};
#endif // CHINESECHARACTERSTOPINYIN_H

View File

@ -5,7 +5,6 @@
#include "chinese-segmentation.h" #include "chinese-segmentation.h"
#include "file-utils.h" #include "file-utils.h"
#include "index-generator.h" #include "index-generator.h"
#include "chinesecharacterstopinyin.h"
#include "global-settings.h" #include "global-settings.h"
#include <QtConcurrent> #include <QtConcurrent>

View File

@ -1,30 +1,24 @@
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
HEADERS += \ HEADERS += \
# $$PWD/chinesecharacterstopinyin.h \
$$PWD/document.h \ $$PWD/document.h \
$$PWD/filetypefilter.h \ $$PWD/filetypefilter.h \
$$PWD/file-reader.h \ $$PWD/file-reader.h \
$$PWD/first-index.h \ $$PWD/first-index.h \
$$PWD/index-generator.h \ $$PWD/index-generator.h \
# $$PWD/inotify-manager.h \
$$PWD/inotify-index.h \ $$PWD/inotify-index.h \
$$PWD/traverse_bfs.h \ $$PWD/traverse_bfs.h \
# $$PWD/text-content-indexer.h \
$$PWD/file-searcher.h \ $$PWD/file-searcher.h \
$$PWD/ukui-search-qdbus.h $$PWD/ukui-search-qdbus.h
SOURCES += \ SOURCES += \
# $$PWD/chinesecharacterstopinyin.cpp \
$$PWD/document.cpp \ $$PWD/document.cpp \
$$PWD/filetypefilter.cpp \ $$PWD/filetypefilter.cpp \
$$PWD/file-reader.cpp \ $$PWD/file-reader.cpp \
$$PWD/first-index.cpp \ $$PWD/first-index.cpp \
$$PWD/index-generator.cpp \ $$PWD/index-generator.cpp \
# $$PWD/inotify-manager.cpp \
$$PWD/inotify-index.cpp \ $$PWD/inotify-index.cpp \
$$PWD/traverse_bfs.cpp \ $$PWD/traverse_bfs.cpp \
# $$PWD/text-content-indexer.cpp \
$$PWD/file-searcher.cpp \ $$PWD/file-searcher.cpp \
$$PWD/ukui-search-qdbus.cpp $$PWD/ukui-search-qdbus.cpp

View File

@ -1,226 +0,0 @@
#include "inotify-manager.h"
#include "index-generator.h"
#include "messagelist-manager.h"
bool InotifyManager::Traverse_BFS(const QString& path, int autoSendMessageLength){
qDebug() << "BFS start-----------------------------";
this->mlm->SetAutoSendMessageLength(autoSendMessageLength);
QQueue<QString> bfs;
bfs.enqueue(path);
QFileInfoList list;
QDir dir;
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){
// qDebug() << i.absoluteFilePath();
if (i.isDir()){
AddWatch(i.absoluteFilePath());
bfs.enqueue(i.absoluteFilePath());
}
else{
this->mlm->AddMessage(i.absoluteFilePath());
//continue;
}
}
}
this->mlm->SendMessage();
qDebug() << "BFS end-----------------------------";
return true;
}
//the DFS method is aborted
bool InotifyManager::Traverse_DFS(const QString& path, const bool& CREATORDELETE){
QDir dir(path);
if (!dir.exists()) {
return false;
}
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
dir.setSorting(QDir::DirsFirst);
QFileInfoList list = dir.entryInfoList();
int i = 0;
do {
if(list.size()==0){
break;
}
QFileInfo fileInfo = list.at(i);
bool bisDir = fileInfo.isDir();
if (fileInfo.fileName().at(0) != '.'){
if (bisDir) {
// qDebug() << QString("Path: %0/%1")
// .arg(fileInfo.path())
// .arg(fileInfo.fileName());
qDebug() << "inotify-manager traverse: " << fileInfo.filePath();
if (CREATORDELETE){
AddWatch(fileInfo.filePath());
}
Traverse_DFS(fileInfo.filePath(), CREATORDELETE);
if (!CREATORDELETE){
RemoveWatch(fileInfo.filePath());
}
} else {
// qDebug() << QString("File: %0/%1")
// .arg(fileInfo.path())
// .arg(fileInfo.fileName());
//IndexGenerator::getInstance()->creatAllIndex(new QStringList(fileInfo.filePath()));
}
}
i++;
} while (i < list.size());
return true;
}
bool InotifyManager::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!=-1);
if (ret == -1) {
qDebug() << "AddWatch error:" << path;
return false;
}
currentPath[ret] = path;
qDebug() << "ret: " <<ret;
qDebug() << "Watch:" << path;
return true;
}
//暂时没用
bool InotifyManager::AddWatchList(const QStringList &paths){
m_fd = inotify_init();
qDebug() << "m_fd----------->" <<m_fd;
for (const QString& p:paths) {
int ret = inotify_add_watch(m_fd, p.toStdString().c_str(), IN_ALL_EVENTS);
if (ret == -1) {
return false;
}
}
return true;
}
bool InotifyManager::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 InotifyManager::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);
Traverse_BFS(currentPath[event->wd] + '/' + event->name);
}
else {
//IndexGenerator::getInstance()->creatAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
this->mlm->AddMessage(currentPath[event->wd] + '/' + event->name);
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(currentPath[event->wd] + '/' + event->name);
this->mlm->SendDeleteMessage();
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
}
}
/*--------------------------------*/
}
p += sizeof(struct inotify_event) + event->len;
}
}
}
InotifyManager::InotifyManager()
{
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();
return;
}

View File

@ -1,44 +0,0 @@
#ifndef INOTIFYMANAGER_H
#define INOTIFYMANAGER_H
#include <QObject>
#include <QThread>
#include <unistd.h>
#include <sys/inotify.h>
#include <QDebug>
#include <QDir>
#include <QQueue>
#include "messagelist-manager.h"
//#define EVENT_NUM 12
#define BUF_LEN 1024
class InotifyManager : public QThread
{
Q_OBJECT
public:
explicit InotifyManager();
//the DFS method is aborted
bool Traverse_DFS(const QString&, const bool&);//true->create, false->delete
bool Traverse_BFS(const QString&, int autoSendMessageLength = 80000);
//typedef bool (*AddWatch)(const QString&);
//AddWatch cmp;
bool AddWatch(const QString&);
bool AddWatchList(const QStringList&);
bool RemoveWatch(const QString&);
protected:
void run() override;
private:
QString *m_watch_path;
int m_fd;
QMap<int, QString> currentPath;
QMap<int, QString> num2string;
MessageListManager* mlm;
};
void testTraverse(void);
#endif // INOTIFYMANAGER_H

View File

@ -1,38 +0,0 @@
#include "text-content-indexer.h"
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QDebug>
TextContentIndexer::TextContentIndexer(QObject *parent) : QObject(parent)
{
}
void TextContentIndexer::creatContentdata()
{
}
void TextContentIndexer::setFileList(QStringList *filelist)
{
m_file_list = filelist;
}
void TextContentIndexer::begin()
{
}
bool TextContentIndexer::getPlaintextFileContent(QString path)
{
QFile file(path);
if(!file.open(QIODevice::ReadOnly))
return false;
QTextStream *stream = new QTextStream(&file);
QString content = stream->readAll();
qDebug()<<content;
return true;
}

View File

@ -1,29 +0,0 @@
#ifndef TEXTCONTENTINDEXER_H
#define TEXTCONTENTINDEXER_H
#include "document.h"
#include <QObject>
#include <QStringList>
#include <QString>
class TextContentIndexer : public QObject
{
Q_OBJECT
public:
explicit TextContentIndexer(QObject *parent = nullptr);
void setFileList(QStringList *filelist);
void begin();
bool getPlaintextFileContent(QString path);
Q_SIGNALS:
bool finish();
private:
void creatContentdata();
QStringList *m_file_list;
Document *m_current_document;
Q_SIGNALS:
};
#endif // TEXTCONTENTINDEXER_H