diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 336fdef..0a1f4da 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -152,12 +152,14 @@ void ContentWidget::refreshSearchList(const QVector& types, const QVectoraddWidget(titleLabel); m_listLyt->addWidget(searchList); m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height()); - // if (i == 0) { // searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex())); // m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0)); // } connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) { + if(type == SearchListView::ResType::Content && !m_contentList.isEmpty()) { + m_detailView->setContent(m_contentList.at(searchList->currentIndex().row())); + } m_detailView->setupWidget(type, path); searchList->is_current_list = true; Q_EMIT this->currentItemChanged(); @@ -216,6 +218,8 @@ QString ContentWidget::getTitleName(const int& type) { return tr("Files"); case SearchItem::SearchType::Dirs : return tr("Dirs"); + case SearchItem::SearchType::Contents : + return tr("File Contents"); case SearchItem::SearchType::Best : return tr("Best Matches"); default : @@ -238,3 +242,13 @@ void ContentWidget::clearSearchList() { child = NULL; m_resultList->setFixedHeight(0); } + + +/** + * @brief ContentWidget::setContentList 文本内容搜索结果列表(包含所有文本段) + * @param list + */ +void ContentWidget::setContentList(const QStringList& list) { + m_contentList.clear(); + m_contentList = list; +} diff --git a/src/content-widget.h b/src/content-widget.h index cb70f51..3c03abe 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -19,8 +19,10 @@ public: int currentPage(); void refreshSearchList(const QVector&, const QVector&); void initHomePage(const QVector&); + void setContentList(const QStringList&); private: void initUI(); + QStringList m_contentList; QWidget * m_homePage = nullptr; QVBoxLayout * m_homePageLyt = nullptr; QWidget * m_resultPage = nullptr; diff --git a/src/control/home-page-item.cpp b/src/control/home-page-item.cpp index af5b6cf..db87111 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -31,6 +31,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) { g_object_unref(desktopAppInfo); break; } + case SearchListView::ResType::Content: case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess * process = new QProcess; @@ -65,6 +66,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) { m_namelabel->setText(FileUtils::getAppName(path)); break; } + case SearchListView::ResType::Content: case SearchListView::ResType::Dir : case SearchListView::ResType::File : { icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); diff --git a/src/control/option-view.cpp b/src/control/option-view.cpp index 3c4fb4d..224f42e 100644 --- a/src/control/option-view.cpp +++ b/src/control/option-view.cpp @@ -45,6 +45,7 @@ void OptionView::initComponent(const int& type) { setupAppOptions(); break; } + case SearchListView::ResType::Content: case SearchListView::ResType::File : { setupFileOptions(); break; diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index d020820..84b5f5e 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -47,6 +47,14 @@ void SearchDetailView::clearLayout() { child = NULL; } +/** + * @brief SearchDetailView::setContent 设置文本区域内容(仅内容搜索) + * @param text + */ +void SearchDetailView::setContent(const QString& text) { + m_contentText = text; +} + /** * @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域 * @param type 搜索类型 @@ -84,10 +92,17 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) { m_layout->addWidget(hLine); //文件和文件夹有一个额外的详情区域 - if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File) { + if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File || type == SearchListView::ResType::Content) { QFrame * detailFrame = new QFrame(this); QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame); detailLyt->setContentsMargins(0,0,0,0); + if (type == SearchListView::ResType::Content) { + QLabel * contentLabel = new QLabel(detailFrame); + contentLabel->setWordWrap(true); + contentLabel->setContentsMargins(9, 0, 9, 0); + contentLabel->setText(m_contentText); + detailLyt->addWidget(contentLabel); + } QFrame * pathFrame = new QFrame(detailFrame); QFrame * timeFrame = new QFrame(detailFrame); QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame); @@ -139,6 +154,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) { typeLabel->setText(tr("Application")); break; } + case SearchListView::ResType::Content: case SearchListView::ResType::Dir : case SearchListView::ResType::File : { QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); @@ -204,6 +220,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) { return true; break; } + case SearchListView::ResType::Content: case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess * process = new QProcess; diff --git a/src/control/search-detail-view.h b/src/control/search-detail-view.h index 5038aab..747c84a 100644 --- a/src/control/search-detail-view.h +++ b/src/control/search-detail-view.h @@ -13,10 +13,11 @@ public: void setupWidget(const int&, const QString&); void clearLayout(); + void setContent(const QString&); private: QVBoxLayout * m_layout = nullptr; - + QString m_contentText; bool openAction(const int&, const QString&); bool addDesktopShortcut(const QString&); bool addPanelShortcut(const QString&); diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index b213efa..134e1ae 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -53,6 +53,9 @@ int SearchListView::getCurrentType() { case SearchItem::SearchType::Dirs: // qDebug()<<"qDebug: One row selected, its type is dir."; return ResType::Dir; + case SearchItem::SearchType::Contents: +// qDebug()<<"qDebug: One row selected, its type is content."; + return ResType::Content; default: //All或者Best的情况,需要自己判断文件类型 return getResType(m_item->m_pathlist.at(this->currentIndex().row())); break; diff --git a/src/control/search-list-view.h b/src/control/search-list-view.h index 46a42c4..b16c99f 100644 --- a/src/control/search-list-view.h +++ b/src/control/search-list-view.h @@ -17,7 +17,8 @@ public: App, File, Setting, - Dir + Dir, + Content }; int getCurrentType(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c72d346..b8c5b74 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,15 +45,15 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { -// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test"); + // FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test"); /*-------------Inotify Test Start---------------*/ -// QTime t1 = QTime::currentTime(); -// InotifyManagerRefact* im = new InotifyManagerRefact("/home"); -// im->Traverse(); -// QTime t2 = QTime::currentTime(); -// qDebug() << t1; -// qDebug() << t2; -// im->start(); + // QTime t1 = QTime::currentTime(); + // InotifyManagerRefact* im = new InotifyManagerRefact("/home"); + // im->Traverse(); + // QTime t2 = QTime::currentTime(); + // qDebug() << t1; + // qDebug() << t2; + // im->start(); /*-------------Inotify Test End-----------------*/ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); @@ -161,7 +161,7 @@ void MainWindow::initUi() } else { m_contentFrame->setCurrentIndex(1); QTimer::singleShot(50,this,[=](){ - searchContent(text); + searchContent(text); }); } }); @@ -234,8 +234,8 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen) * @param searchcontent */ void MainWindow::searchContent(QString searchcontent){ -// QVector types; -// QVector lists; + // QVector types; + // QVector lists; m_lists.clear(); m_types.clear(); @@ -245,19 +245,46 @@ void MainWindow::searchContent(QString searchcontent){ //测试用数据 QStringList list; list = appMatchor->startMatchApp(searchcontent); -// 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"; + // list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; QStringList list3; list3 = settingMatchor->startMatchApp(searchcontent); -// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; + // list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; m_types.append(SearchItem::SearchType::Apps); m_types.append(SearchItem::SearchType::Settings); -// types.append(SearchItem::SearchType::Files); - m_lists.append(list); m_lists.append(list3); -// lists.append(list2); + + //内容搜索测试用数据,每个文件(路径)对应一段文本内容 + FileSearcher *search = new FileSearcher(); + + connect(search, &FileSearcher::contentResult, this, [ = ](QMap map) { + m_types.append(SearchItem::SearchType::Contents); + QStringList pathlist, contentList; + qDebug() << map; + for (auto i : map.keys()){ + QString temp; + pathlist << i; + for (auto s : map[i]){ + temp.append(s); + } + contentList.append(temp); + } + m_lists.append(pathlist); + m_contentFrame->setContentList(contentList); + }); + QTime t1 = QTime::currentTime(); + + search->onKeywordSearchContent(searchcontent); + QTime t2 = QTime::currentTime(); + qDebug() << t1; + qDebug() << t2; +// m_types.append(SearchItem::SearchType::Contents); +// QStringList pathlist; +// pathlist<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; +// m_lists.append(pathlist); +// QStringList contentList; +// contentList<<"这是搜索结果.png的文件内容"<<"这是显示不全.mp4的文件内容"<<"这是dmesg.log的文件内容"<<"这是WiFi_AP选择.docx的文件内容"; +// m_contentFrame->setContentList(contentList); // m_contentFrame->refreshSearchList(m_types, m_lists); //文件搜索 @@ -269,21 +296,21 @@ void MainWindow::searchContent(QString searchcontent){ QStringList list1 = resultV.at(0); QStringList list2 = resultV.at(1); -// QVector lists; + // QVector lists; m_lists.append(list1); m_lists.append(list2); -// QVector types; + // QVector types; m_types.append(SearchItem::SearchType::Dirs); m_types.append(SearchItem::SearchType::Files); m_contentFrame->refreshSearchList(m_types, m_lists); }); searcher->onKeywordSearch(searchcontent,0,10); -// QStringList res = IndexGenerator::IndexSearch(searchcontent); -// types.append(SearchItem::SearchType::Files); -// lists.append(res); + // QStringList res = IndexGenerator::IndexSearch(searchcontent); + // types.append(SearchItem::SearchType::Files); + // lists.append(res); //将搜索结果加入列表 -// m_contentFrame->refreshSearchList(types, lists); + // m_contentFrame->refreshSearchList(types, lists); } //使用GSetting获取当前窗口应该使用的透明度 @@ -319,7 +346,6 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r xcb_generic_event_t *event = (xcb_generic_event_t*)message; switch (event->response_type & ~0x80) { - qDebug()<<"YYF - event->response_type : "<response_type;//YYF 20200922 case XCB_FOCUS_OUT: this->close(); break; diff --git a/src/model/search-item.cpp b/src/model/search-item.cpp index 9037751..3296e11 100644 --- a/src/model/search-item.cpp +++ b/src/model/search-item.cpp @@ -21,6 +21,7 @@ QIcon SearchItem::getIcon(int index) { switch (m_searchtype) { case Settings : //设置项,返回控制面板对应插件的图标 return FileUtils::getSettingIcon(m_pathlist.at(index), false); + case Contents: case Dirs : case Files : //文件,返回文件图标 return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index))); @@ -52,6 +53,7 @@ QString SearchItem::getName(int index) { switch (m_searchtype) { case Settings : //设置项,返回功能点名 return FileUtils::getSettingName(m_pathlist.at(index)); + case Contents: case Dirs : case Files : //文件,返回文件名 return FileUtils::getFileName(m_pathlist.at(index)); diff --git a/src/model/search-item.h b/src/model/search-item.h index e668835..f588827 100644 --- a/src/model/search-item.h +++ b/src/model/search-item.h @@ -21,6 +21,7 @@ public: Settings, Files, Dirs, + Contents, Best };