From c0ac3492c8251bb6c0d01448959349109843edfd Mon Sep 17 00:00:00 2001 From: zhangzihao Date: Mon, 28 Dec 2020 20:29:13 +0800 Subject: [PATCH] :sparkles::sparkles::sparkles:add file type filter and some classes(not completed) --- globalsettings.cpp | 6 ++++++ globalsettings.h | 16 ++++++++++++++++ index/blockdirs.cpp | 6 ++++++ index/blockdirs.h | 16 ++++++++++++++++ index/filetypefilter.cpp | 33 +++++++++++++++++++++++++++++++++ index/filetypefilter.h | 32 ++++++++++++++++++++++++++++++++ index/index.pri | 4 ++++ index/inotify.cpp | 2 +- src/mainwindow.cpp | 16 +++++++++------- ukui-search.pro | 2 ++ 10 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 globalsettings.cpp create mode 100644 globalsettings.h create mode 100644 index/blockdirs.cpp create mode 100644 index/blockdirs.h create mode 100644 index/filetypefilter.cpp create mode 100644 index/filetypefilter.h diff --git a/globalsettings.cpp b/globalsettings.cpp new file mode 100644 index 0000000..1b0f10a --- /dev/null +++ b/globalsettings.cpp @@ -0,0 +1,6 @@ +#include "globalsettings.h" + +GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) +{ + +} diff --git a/globalsettings.h b/globalsettings.h new file mode 100644 index 0000000..c10c0c9 --- /dev/null +++ b/globalsettings.h @@ -0,0 +1,16 @@ +#ifndef GLOBALSETTINGS_H +#define GLOBALSETTINGS_H + +#include + +class GlobalSettings : public QObject +{ + Q_OBJECT +public: + explicit GlobalSettings(QObject *parent = nullptr); + +Q_SIGNALS: + +}; + +#endif // GLOBALSETTINGS_H diff --git a/index/blockdirs.cpp b/index/blockdirs.cpp new file mode 100644 index 0000000..49fc5da --- /dev/null +++ b/index/blockdirs.cpp @@ -0,0 +1,6 @@ +#include "blockdirs.h" + +BlockDirs::BlockDirs(QObject *parent) : QObject(parent) +{ + +} diff --git a/index/blockdirs.h b/index/blockdirs.h new file mode 100644 index 0000000..b0a1d20 --- /dev/null +++ b/index/blockdirs.h @@ -0,0 +1,16 @@ +#ifndef BLOCKDIRS_H +#define BLOCKDIRS_H + +#include + +class BlockDirs : public QObject +{ + Q_OBJECT +public: + explicit BlockDirs(QObject *parent = nullptr); + +Q_SIGNALS: + +}; + +#endif // BLOCKDIRS_H diff --git a/index/filetypefilter.cpp b/index/filetypefilter.cpp new file mode 100644 index 0000000..e5e104d --- /dev/null +++ b/index/filetypefilter.cpp @@ -0,0 +1,33 @@ +#include +#include "filetypefilter.h" + +FileTypeFilter::FileTypeFilter(const QString& path) : Traverse_BFS(path) +{ + this->result = new QVector(); + this->Traverse(); +} + +FileTypeFilter::~FileTypeFilter() +{ + delete this->result; + this->result = nullptr; +} + +void FileTypeFilter::DoSomething(const QFileInfo& fileInfo){ +// QMimeDatabase qmd; +// QMimeType qmt; +// qmt = qmd.mimeTypeForFile(fileInfo.fileName()); +// qDebug() << qmt.preferredSuffix(); + for (auto i : this->targetFileTypeVec){ + if (fileInfo.fileName().endsWith(i)){ +// qDebug() << fileInfo.fileName(); + this->result->append(fileInfo.absoluteFilePath()); + } + } + +} + +QVector* FileTypeFilter::getTargetFileAbsolutePath(){ + return this->result; +} + diff --git a/index/filetypefilter.h b/index/filetypefilter.h new file mode 100644 index 0000000..4d28227 --- /dev/null +++ b/index/filetypefilter.h @@ -0,0 +1,32 @@ +#ifndef FILETYPEFILTER_H +#define FILETYPEFILTER_H + +#include +#include +#include +#include +#include "traverse_bfs.h" + +class FileTypeFilter : public QObject, public Traverse_BFS +{ + Q_OBJECT +public: + explicit FileTypeFilter(const QString&); + ~FileTypeFilter(); + virtual void DoSomething(const QFileInfo&) final; + QVector* getTargetFileAbsolutePath(); + +Q_SIGNALS: +private: + const QVector targetFileTypeVec ={ QString(".doc"), + QString(".docx"), + QString(".ppt"), + QString(".pptx"), + QString(".xls"), + QString(".xlsx"), + QString(".txt")}; + QVector* result; + +}; + +#endif // FILETYPEFILTER_H diff --git a/index/index.pri b/index/index.pri index 11097a9..3018a0f 100644 --- a/index/index.pri +++ b/index/index.pri @@ -2,7 +2,9 @@ INCLUDEPATH += $$PWD HEADERS += \ # $$PWD/chinesecharacterstopinyin.h \ + $$PWD/blockdirs.h \ $$PWD/document.h \ + $$PWD/filetypefilter.h \ $$PWD/index-generator.h \ # $$PWD/inotify-manager.h \ $$PWD/inotify.h \ @@ -13,7 +15,9 @@ HEADERS += \ SOURCES += \ # $$PWD/chinesecharacterstopinyin.cpp \ + $$PWD/blockdirs.cpp \ $$PWD/document.cpp \ + $$PWD/filetypefilter.cpp \ $$PWD/index-generator.cpp \ # $$PWD/inotify-manager.cpp \ $$PWD/inotify.cpp \ diff --git a/index/inotify.cpp b/index/inotify.cpp index e975bd9..7909539 100644 --- a/index/inotify.cpp +++ b/index/inotify.cpp @@ -83,7 +83,7 @@ bool InotifyManagerRefact::RemoveWatch(const QString &path){ qDebug() << i.value(); /*--------------------------------*/ //在此调用删除索引 -// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(path)); + IndexGenerator::getInstance()->deleteAllIndex(new QStringList(path)); /*--------------------------------*/ currentPath.erase(i++); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 43dabc8..fae78a0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,6 +34,7 @@ #include "index-generator.h" //#include "inotify-manager.h" #include "inotify.h" +#include "filetypefilter.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); /** @@ -46,15 +47,16 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - + FileTypeFilter* ftf = new FileTypeFilter("/home"); + ftf->getTargetFileAbsolutePath(); /*-------------InotyifyRefact Test Start---------------*/ - QTime t1 = QTime::currentTime(); - InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); - imr->start(); - QTime t2 = QTime::currentTime(); - qDebug() << t1; - qDebug() << t2; +// QTime t1 = QTime::currentTime(); +// InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); +// imr->start(); +// QTime t2 = QTime::currentTime(); +// qDebug() << t1; +// qDebug() << t2; /*-------------InotyifyRefact Test End-----------------*/ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); diff --git a/ukui-search.pro b/ukui-search.pro index 109f0c7..72142d6 100644 --- a/ukui-search.pro +++ b/ukui-search.pro @@ -31,10 +31,12 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin HEADERS += \ file-utils.h \ + globalsettings.h \ gobject-template.h \ SOURCES += \ file-utils.cpp \ + globalsettings.cpp \ gobject-template.cpp \ PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt libbamf3 x11 xrandr xtst