From 9a6b2f607eac2b01e600b5ac6af923a887487434 Mon Sep 17 00:00:00 2001 From: zhangpengfei Date: Sat, 26 Dec 2020 21:11:17 +0800 Subject: [PATCH] Modified file search interface. --- index/file-searcher.cpp | 91 +++++++++++++++++++++++++-------------- index/file-searcher.h | 10 +++-- index/index-generator.cpp | 6 ++- index/inotify.cpp | 4 +- src/main.cpp | 8 ++++ src/mainwindow.cpp | 58 ++++++++++++++----------- 6 files changed, 112 insertions(+), 65 deletions(-) diff --git a/index/file-searcher.cpp b/index/file-searcher.cpp index 0baaa47..1579fa3 100644 --- a/index/file-searcher.cpp +++ b/index/file-searcher.cpp @@ -1,13 +1,15 @@ #include "file-searcher.h" +#include +#include FileSearcher::FileSearcher(QObject *parent) : QObject(parent) { } -void FileSearcher::onKeywordSearch(QString keyword) +void FileSearcher::onKeywordSearch(QString keyword, int begin, int num) { - QStringList searchResult; + QVector searchResult; try { qDebug()<<"--search start--"; @@ -19,14 +21,14 @@ void FileSearcher::onKeywordSearch(QString keyword) qp.set_database(db); auto userInput = keyword; - std::string queryStr = indexText.replace(""," ").toStdString(); + std::string queryStr = keyword.replace(""," ").toStdString(); // std::string s =db.get_spelling_suggestion(queryStr,10); // qDebug()<<"spelling_suggestion!"< v; + std::vector v; for(int i=0;iexists()) + { +// pathTobeDelete->append(QString::fromStdString(data)); + qDebug()< resultV); +private: + QStringList getResult(Xapian::MSet &result); }; #endif // FILESEARCHER_H diff --git a/index/index-generator.cpp b/index/index-generator.cpp index e3c2542..d30fea9 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -134,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector &list) doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addValue(list.at(2)); + if(list.at(2) == QString("1")) + qDebug()<<"value!!!"< v; + std::vector v; for(int i=0;imlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir())))); + this->mlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0")); +// if(QString(bool((fileInfo.isDir()))) == QString("1")) +// qDebug()<<"bool((fileInfo.isDir())"<mlm->AddMessage(QVector() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1"); if(fileInfo.isDir()){ this->AddWatch(fileInfo.absoluteFilePath()); diff --git a/src/main.cpp b/src/main.cpp index d3230fe..d73bfdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,14 @@ int main(int argc, char *argv[]) { //load chinese character and pinyin file to a Map FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt"); + /*-------------InotyifyRefact Test Start---------------*/ + QTime t1 = QTime::currentTime(); + InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); + imr->start(); + QTime t2 = QTime::currentTime(); + qDebug() << t1; + qDebug() << t2; + /*-------------InotyifyRefact Test End-----------------*/ qRegisterMetaType>("QVector"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e5782a2..1e366c8 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 "file-searcher.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); /** @@ -46,17 +47,6 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - - - /*-------------InotyifyRefact Test Start---------------*/ - 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); this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); @@ -228,31 +218,47 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen) * @param searchcontent */ void MainWindow::searchContent(QString searchcontent){ - QVector types; - QVector lists; +// QVector types; +// QVector lists; //测试用数据 - QStringList list; - list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; - QStringList list2; - list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; - QStringList list3; - list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; - types.append(SearchItem::SearchType::Apps); - types.append(SearchItem::SearchType::Settings); - types.append(SearchItem::SearchType::Files); +// QStringList list; +// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; +// QStringList list2; +// list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; +// QStringList list3; +// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; +// types.append(SearchItem::SearchType::Apps); +// types.append(SearchItem::SearchType::Settings); +// types.append(SearchItem::SearchType::Files); - lists.append(list); - lists.append(list3); - lists.append(list2); +// lists.append(list); +// lists.append(list3); +// lists.append(list2); //文件搜索 + + FileSearcher *searcher = new FileSearcher(); + + connect(searcher,&FileSearcher::result,[=](QVector resultV){ + + QStringList list1 = resultV.at(0); +// QStringList list2 = resultV.at(1); + + QVector lists; + lists.append(list1); + QVector types; + types.append(SearchItem::SearchType::Files); +// types.append(SearchItem::SearchType::Files); + m_contentFrame->refreshSearchList(types, lists); + }); + searcher->onKeywordSearch(searchcontent,0,10); // QStringList res = IndexGenerator::IndexSearch(searchcontent); // types.append(SearchItem::SearchType::Files); // lists.append(res); //将搜索结果加入列表 - m_contentFrame->refreshSearchList(types, lists); +// m_contentFrame->refreshSearchList(types, lists); } //使用GSetting获取当前窗口应该使用的透明度