2021-01-29 11:43:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangzihao <zhangzihao@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2021-01-10 09:01:22 +08:00
|
|
|
#ifndef INOTIFYINDEX_H
|
|
|
|
#define INOTIFYINDEX_H
|
|
|
|
|
|
|
|
#include <QThread>
|
2021-01-21 13:50:21 +08:00
|
|
|
#include <QTimer>
|
2021-01-10 09:01:22 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
#include "index-generator.h"
|
|
|
|
#include "traverse_bfs.h"
|
|
|
|
#include "ukui-search-qdbus.h"
|
2021-01-13 14:04:13 +08:00
|
|
|
#include "global-settings.h"
|
2021-01-20 17:14:14 +08:00
|
|
|
#include "file-utils.h"
|
2021-01-21 13:50:21 +08:00
|
|
|
#include "first-index.h"
|
2021-01-10 09:01:22 +08:00
|
|
|
|
2021-01-21 21:05:53 +08:00
|
|
|
#define BUF_LEN 1024000
|
2021-01-11 16:59:50 +08:00
|
|
|
class InotifyIndex;
|
|
|
|
static InotifyIndex* global_instance_of_index = nullptr;
|
2021-01-10 09:01:22 +08:00
|
|
|
class InotifyIndex : public QThread, public Traverse_BFS
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-01-11 16:59:50 +08:00
|
|
|
static InotifyIndex* getInstance(const QString& path){
|
|
|
|
if (!global_instance_of_index) {
|
|
|
|
global_instance_of_index = new InotifyIndex(path);
|
|
|
|
}
|
|
|
|
return global_instance_of_index;
|
|
|
|
}
|
2021-01-10 09:01:22 +08:00
|
|
|
InotifyIndex(const QString&);
|
|
|
|
~InotifyIndex();
|
|
|
|
|
|
|
|
bool AddWatch(const QString&);
|
|
|
|
bool RemoveWatch(const QString&);
|
|
|
|
virtual void DoSomething(const QFileInfo &) final;
|
2021-01-21 13:50:21 +08:00
|
|
|
|
|
|
|
void eventProcess(const char*, ssize_t);
|
2021-01-10 09:01:22 +08:00
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
private:
|
|
|
|
QString* m_watch_path;
|
|
|
|
int m_fd;
|
|
|
|
|
|
|
|
QMap<int, QString> currentPath;
|
|
|
|
const QVector<QString> targetFileTypeVec ={
|
|
|
|
// QString(".doc"),
|
|
|
|
QString(".docx"),
|
|
|
|
// QString(".ppt"),
|
|
|
|
// QString(".pptx"),
|
|
|
|
// QString(".xls"),
|
|
|
|
// QString(".xlsx"),
|
|
|
|
QString(".txt")};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INOTIFYINDEX_H
|