feat(searchList): Confirm interface with backend.
Description: 接口对接 Log: 接口对接
This commit is contained in:
parent
872716e7f0
commit
51fd7e19bf
|
@ -36,7 +36,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
|||
++uniqueSymbol3;
|
||||
m_mutex3.unlock();
|
||||
//file
|
||||
QtConcurrent::run([&, uniqueSymbol1](){
|
||||
QtConcurrent::run([&, uniqueSymbol1, keyword](){
|
||||
if(!m_search_result_file->isEmpty())
|
||||
m_search_result_file->clear();
|
||||
int begin = 0;
|
||||
|
@ -54,7 +54,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
|||
});
|
||||
// Q_EMIT this->resultFile(m_search_result_file);
|
||||
//dir
|
||||
QtConcurrent::run([&, uniqueSymbol2](){
|
||||
QtConcurrent::run([&, uniqueSymbol2, keyword](){
|
||||
if(!m_search_result_dir->isEmpty())
|
||||
m_search_result_dir->clear();
|
||||
int begin = 0;
|
||||
|
@ -72,13 +72,14 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
|||
});
|
||||
// Q_EMIT this->resultDir(m_search_result_dir);
|
||||
//content
|
||||
QtConcurrent::run([&, uniqueSymbol3](){
|
||||
QtConcurrent::run([&, uniqueSymbol3, keyword](){
|
||||
if(!m_search_result_content->isEmpty())
|
||||
m_search_result_content->clear();
|
||||
int begin = 0;
|
||||
int num = 5;
|
||||
int resultCount = 0;
|
||||
int total = 0;
|
||||
|
||||
while(total<20)
|
||||
{
|
||||
keywordSearchContent(uniqueSymbol3,keyword,begin,num);
|
||||
|
@ -328,14 +329,18 @@ QMap<QString,QStringList> FileSearcher::getContentResult(size_t uniqueSymbol, Xa
|
|||
m_mutex3.lock();
|
||||
if(uniqueSymbol == FileSearcher::uniqueSymbol3)
|
||||
{
|
||||
|
||||
m_search_result_content->enqueue(qMakePair(path,snippets));
|
||||
m_mutex3.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex3.unlock();
|
||||
exit(0);
|
||||
break;
|
||||
// exit(0);
|
||||
}
|
||||
|
||||
qDebug() << "after";
|
||||
searchResult.insert(path,snippets);
|
||||
qDebug()<< "path="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,13 @@ public:
|
|||
explicit FileSearcher(QObject *parent = nullptr);
|
||||
~FileSearcher();
|
||||
|
||||
static size_t uniqueSymbol1;
|
||||
static size_t uniqueSymbol2;
|
||||
static size_t uniqueSymbol3;
|
||||
static QMutex m_mutex1;
|
||||
static QMutex m_mutex2;
|
||||
static QMutex m_mutex3;
|
||||
|
||||
public Q_SLOTS:
|
||||
void onKeywordSearch(QString keyword,QQueue<QString> *searchResultFile,QQueue<QString> *searchResultDir,QQueue<QPair<QString,QStringList>> *searchResultContent);
|
||||
|
||||
|
@ -50,12 +57,6 @@ private:
|
|||
QQueue<QString> *m_search_result_dir = nullptr;
|
||||
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
|
||||
bool m_searching = false;
|
||||
static size_t uniqueSymbol1;
|
||||
static size_t uniqueSymbol2;
|
||||
static size_t uniqueSymbol3;
|
||||
static QMutex m_mutex1;
|
||||
static QMutex m_mutex2;
|
||||
static QMutex m_mutex3;
|
||||
};
|
||||
|
||||
#endif // FILESEARCHER_H
|
||||
|
|
|
@ -182,7 +182,7 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
|||
// 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()) {
|
||||
if(type == SearchItem::SearchType::Contents && !m_contentList.isEmpty()) {
|
||||
m_detailView->setContent(m_contentList.at(searchList->currentIndex().row()), keyword);
|
||||
}
|
||||
m_detailView->setupWidget(type, path);
|
||||
|
@ -198,7 +198,6 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (isEmpty) {
|
||||
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
||||
return;
|
||||
|
@ -228,6 +227,142 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::appendSearchItem 向列表添加一项搜索结果
|
||||
* @param type 类型
|
||||
* @param path 路径
|
||||
* @param contents 文件内容
|
||||
*/
|
||||
void ContentWidget::appendSearchItem(const int& type, const QString& path, const QString& keyword, QStringList contents) {
|
||||
switch (type) {
|
||||
case SearchItem::SearchType::Files: {
|
||||
if (!m_fileListView) {
|
||||
m_fileListView = new SearchListView(m_resultList, QStringList(), type, keyword);
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_fileListView);
|
||||
connect(m_fileListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
||||
m_detailView->setupWidget(type, path);
|
||||
m_fileListView->is_current_list = true;
|
||||
Q_EMIT this->currentItemChanged();
|
||||
m_fileListView->is_current_list = false;
|
||||
});
|
||||
connect(this, &ContentWidget::currentItemChanged, m_fileListView, [ = ]() {
|
||||
if (! m_fileListView->is_current_list) {
|
||||
m_fileListView->blockSignals(true);
|
||||
m_fileListView->clearSelection();
|
||||
m_fileListView->blockSignals(false);
|
||||
}
|
||||
});
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->height() + titleLabel->height());
|
||||
}
|
||||
if (m_fileListView->isHidden) {
|
||||
m_fileListView->isHidden = false;
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_fileListView);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->height() + titleLabel->height());
|
||||
}
|
||||
m_fileListView->appendItem(path);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->rowheight);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case SearchItem::SearchType::Dirs: {
|
||||
if (!m_dirListView) {
|
||||
m_dirListView = new SearchListView(m_resultList, QStringList(), type, keyword);
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_dirListView);
|
||||
connect(m_dirListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
||||
m_detailView->setupWidget(type, path);
|
||||
m_dirListView->is_current_list = true;
|
||||
Q_EMIT this->currentItemChanged();
|
||||
m_dirListView->is_current_list = false;
|
||||
});
|
||||
connect(this, &ContentWidget::currentItemChanged, m_dirListView, [ = ]() {
|
||||
if (! m_dirListView->is_current_list) {
|
||||
m_dirListView->blockSignals(true);
|
||||
m_dirListView->clearSelection();
|
||||
m_dirListView->blockSignals(false);
|
||||
}
|
||||
});
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->height() + titleLabel->height());
|
||||
}
|
||||
if (m_dirListView->isHidden) {
|
||||
m_dirListView->isHidden = false;
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_dirListView);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->height() + titleLabel->height());
|
||||
}
|
||||
m_dirListView->appendItem(path);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->rowheight);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case SearchItem::SearchType::Contents: {
|
||||
if (!m_contentListView) {
|
||||
m_contentListView = new SearchListView(m_resultList, QStringList(), type, keyword);
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_contentListView);
|
||||
connect(m_contentListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
||||
m_detailView->setContent(m_contentList.at(m_contentListView->currentIndex().row()), keyword);
|
||||
m_detailView->setupWidget(type, path);
|
||||
m_contentListView->is_current_list = true;
|
||||
Q_EMIT this->currentItemChanged();
|
||||
m_contentListView->is_current_list = false;
|
||||
});
|
||||
connect(this, &ContentWidget::currentItemChanged, m_contentListView, [ = ]() {
|
||||
if (! m_contentListView->is_current_list) {
|
||||
m_contentListView->blockSignals(true);
|
||||
m_contentListView->clearSelection();
|
||||
m_contentListView->blockSignals(false);
|
||||
}
|
||||
});
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->height() + titleLabel->height());
|
||||
}
|
||||
if (m_contentListView->isHidden) {
|
||||
m_contentListView->isHidden = false;
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||
titleLabel->setText(getTitleName(type));
|
||||
m_listLyt->addWidget(titleLabel);
|
||||
m_listLyt->addWidget(m_contentListView);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->height() + titleLabel->height());
|
||||
}
|
||||
m_contentListView->appendItem(path);
|
||||
m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->rowheight);
|
||||
QString temp;
|
||||
for (auto s : contents){
|
||||
temp.append(s);
|
||||
}
|
||||
m_contentList.append(temp);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::getTitleName 获取表头
|
||||
* @param type 搜索类型
|
||||
|
@ -257,6 +392,16 @@ QString ContentWidget::getTitleName(const int& type) {
|
|||
* @param layout 需要清空的布局
|
||||
*/
|
||||
void ContentWidget::clearLayout(QLayout * layout) {
|
||||
if (m_fileListView) {
|
||||
m_fileListView->clear();
|
||||
}
|
||||
if (m_dirListView) {
|
||||
m_dirListView->clear();
|
||||
}
|
||||
if (m_contentListView) {
|
||||
m_contentListView->clear();
|
||||
}
|
||||
m_contentList.clear();
|
||||
if (! layout) return;
|
||||
QLayoutItem * child;
|
||||
while ((child = layout->takeAt(0)) != 0) {
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
void setPage(const int&);
|
||||
int currentPage();
|
||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&, const QString&);
|
||||
void appendSearchItem(const int& type, const QString& path, const QString& keyword, QStringList contents = QStringList());
|
||||
void initHomePage();
|
||||
void setContentList(const QStringList&);
|
||||
private:
|
||||
|
@ -36,6 +37,9 @@ private:
|
|||
QVBoxLayout * m_detailLyt = nullptr;
|
||||
|
||||
SearchDetailView * m_detailView = nullptr;
|
||||
SearchListView * m_fileListView = nullptr;
|
||||
SearchListView * m_dirListView = nullptr;
|
||||
SearchListView * m_contentListView = nullptr;
|
||||
|
||||
int m_currentType = 0;
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
|
|||
this->setHeaderHidden(true);
|
||||
this->setColumnWidth(0, 20);
|
||||
this->setColumnWidth(1, 80);
|
||||
int rowHeight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
|
||||
this->setFixedHeight(list.count() * rowHeight + 2);
|
||||
rowheight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
|
||||
this->setFixedHeight(list.count() * rowheight + 2);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setAutoFillBackground(false);
|
||||
this->setStyleSheet("QWidget{background:transparent;}");
|
||||
|
@ -41,6 +41,29 @@ SearchListView::~SearchListView()
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchListView::appendItem
|
||||
*/
|
||||
void SearchListView::appendItem(QString path) {
|
||||
m_model->appendItem(path);
|
||||
rowheight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
|
||||
this->setFixedHeight(m_item->getCurrentSize() * rowheight + 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchListView::removeItem
|
||||
*/
|
||||
void SearchListView::removeItem(QString path) {
|
||||
m_model->removeItem(path);
|
||||
}
|
||||
|
||||
void SearchListView::clear()
|
||||
{
|
||||
m_model->clear();
|
||||
this->setFixedHeight(0);
|
||||
this->isHidden = true;
|
||||
}
|
||||
|
||||
//获取当前选项所属搜索类型
|
||||
int SearchListView::getCurrentType() {
|
||||
switch (m_type) {
|
||||
|
|
|
@ -26,7 +26,12 @@ public:
|
|||
static int getResType(const QString&);
|
||||
|
||||
bool is_current_list = false;
|
||||
int rowheight = 0;
|
||||
|
||||
void appendItem(QString);
|
||||
void removeItem(QString);
|
||||
void clear();
|
||||
bool isHidden = false;
|
||||
private:
|
||||
SearchItemModel * m_model = nullptr;
|
||||
SearchItem * m_item = nullptr;
|
||||
|
|
|
@ -65,7 +65,7 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
|||
|
||||
// connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString)));
|
||||
m_timer = new QTimer;
|
||||
QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){
|
||||
connect(m_timer, &QTimer::timeout, this, [ = ](){
|
||||
m_timer->stop();
|
||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||
});
|
||||
|
@ -76,8 +76,8 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
|||
} else {
|
||||
if (text == "") {
|
||||
m_isEmpty = true;
|
||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||
m_timer->stop();
|
||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||
return;
|
||||
}
|
||||
m_timer->stop();
|
||||
|
|
|
@ -85,13 +85,14 @@ void centerToScreen(QWidget* widget) {
|
|||
int desk_y = desk_rect.height();
|
||||
int x = widget->width();
|
||||
int y = widget->height();
|
||||
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
||||
// widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
qInstallMessageHandler(messageOutput);
|
||||
// qInstallMessageHandler(messageOutput);
|
||||
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
|
|
|
@ -28,12 +28,12 @@
|
|||
#include <QStyleOption>
|
||||
#include <KWindowEffects>
|
||||
#include <QPixmap>
|
||||
#include "libsearch.h"
|
||||
#include "kwindowsystem.h"
|
||||
|
||||
//#include "inotify-manager.h"
|
||||
#include "settings-widget.h"
|
||||
#include "global-settings.h"
|
||||
#include "search-result.h"
|
||||
|
||||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||
/**
|
||||
|
@ -46,6 +46,8 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
|
|||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent)
|
||||
{
|
||||
|
||||
m_searcher = new FileSearcher();
|
||||
// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test");
|
||||
/*-------------Inotify Test Start---------------*/
|
||||
// QTime t1 = QTime::currentTime();
|
||||
|
@ -80,6 +82,21 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
this->setPalette(pal);
|
||||
this->update();
|
||||
});
|
||||
|
||||
m_search_result_file = new QQueue<QString>;
|
||||
m_search_result_dir = new QQueue<QString>;
|
||||
m_search_result_content = new QQueue<QPair<QString,QStringList>>;
|
||||
m_search_result_thread = new SearchResult(this);
|
||||
// m_search_result_thread->start();
|
||||
connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) {
|
||||
m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path, m_keyword);
|
||||
});
|
||||
connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) {
|
||||
m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path, m_keyword);
|
||||
});
|
||||
connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) {
|
||||
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_keyword, pair.second);
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -174,9 +191,9 @@ void MainWindow::initUi()
|
|||
m_contentFrame->setCurrentIndex(0);
|
||||
} else {
|
||||
m_contentFrame->setCurrentIndex(1);
|
||||
QTimer::singleShot(50,this,[=](){
|
||||
// QTimer::singleShot(50,this,[=](){
|
||||
searchContent(text);
|
||||
});
|
||||
// });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -190,13 +207,11 @@ void MainWindow::initUi()
|
|||
*/
|
||||
void MainWindow::bootOptionsFilter(QString opt)
|
||||
{
|
||||
|
||||
if (opt == "-s" || opt == "-show") {
|
||||
clearSearchResult();
|
||||
this->show();
|
||||
this->raise();
|
||||
this->activateWindow();
|
||||
}
|
||||
clearSearchResult();
|
||||
this->show();
|
||||
this->raise();
|
||||
this->activateWindow();
|
||||
m_search_result_thread->start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,83 +250,25 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
|||
* @param searchcontent
|
||||
*/
|
||||
void MainWindow::searchContent(QString searchcontent){
|
||||
m_keyword = searchcontent;
|
||||
m_lists.clear();
|
||||
m_types.clear();
|
||||
|
||||
AppMatch * appMatchor = new AppMatch(this);
|
||||
SettingsMatch * settingMatchor = new SettingsMatch(this);
|
||||
//应用与设置搜索
|
||||
QStringList list;
|
||||
list = appMatchor->startMatchApp(searchcontent);
|
||||
QStringList list3;
|
||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
||||
QStringList appList;
|
||||
appList = appMatchor->startMatchApp(searchcontent);
|
||||
QStringList settingList;
|
||||
settingList = settingMatchor->startMatchApp(searchcontent);
|
||||
m_types.append(SearchItem::SearchType::Apps);
|
||||
m_types.append(SearchItem::SearchType::Settings);
|
||||
m_lists.append(list);
|
||||
m_lists.append(list3);
|
||||
|
||||
//文件、文件夹、内容搜索
|
||||
FileSearcher *search = new FileSearcher();
|
||||
connect(search, &FileSearcher::resultDir, this, [ = ](QQueue<QString> * dirQueue) {
|
||||
qWarning()<<"resultDir---";
|
||||
QString firstDir;
|
||||
while(1)
|
||||
{
|
||||
if(!dirQueue->isEmpty()){
|
||||
firstDir = dirQueue->at(0);
|
||||
qWarning()<<"firstDir"<<firstDir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
connect(search, &FileSearcher::resultFile, this, [ = ](QQueue<QString> * fileQueue) {
|
||||
qWarning()<<"resultFile---";
|
||||
});
|
||||
connect(search, &FileSearcher::resultContent, this, [ = ](QQueue<QPair<QString,QStringList>> * contentQueue) {
|
||||
qWarning()<<"resultContent---";
|
||||
});
|
||||
search->onKeywordSearch(searchcontent);
|
||||
//将搜索结果加入列表
|
||||
m_lists.append(appList);
|
||||
m_lists.append(settingList);
|
||||
m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
||||
|
||||
//iaom--------this part shall be rewrite
|
||||
// connect(search, &FileSearcher::contentResult, this, [ = ](QMap<QString,QStringList> 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);
|
||||
// });
|
||||
|
||||
// search->onKeywordSearch(searchcontent);
|
||||
|
||||
//iaom--------this part shall be rewrite
|
||||
// connect(searcher,&FileSearcher::result,[=](QVector<QStringList> resultV){
|
||||
|
||||
// QStringList list1 = resultV.at(0);
|
||||
// QStringList list2 = resultV.at(1);
|
||||
|
||||
// // QVector<QStringList> lists;
|
||||
// m_lists.append(list1);
|
||||
// m_lists.append(list2);
|
||||
// // QVector<int> types;
|
||||
// m_types.append(SearchItem::SearchType::Dirs);
|
||||
// m_types.append(SearchItem::SearchType::Files);
|
||||
// m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
||||
// });
|
||||
// searcher->onKeywordSearch(searchcontent,0,10);
|
||||
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
// lists.append(res);
|
||||
//文件、文件夹、内容搜索
|
||||
this->m_searcher->onKeywordSearch(searchcontent, m_search_result_file, m_search_result_dir, m_search_result_content);
|
||||
}
|
||||
|
||||
//使用GSetting获取当前窗口应该使用的透明度
|
||||
|
@ -339,6 +296,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
|||
switch (event->response_type & ~0x80) {
|
||||
case XCB_FOCUS_OUT:
|
||||
this->hide();
|
||||
m_search_result_thread->quit();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,12 @@
|
|||
#include "input-box.h"
|
||||
#include "index/index-generator.h"
|
||||
#include "settings-widget.h"
|
||||
#include "libsearch.h"
|
||||
|
||||
class SearchResult;
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
friend class SearchResult;
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -80,6 +83,15 @@ private:
|
|||
QVector<int> m_types;
|
||||
QVector<QStringList> m_lists;
|
||||
QStringList m_dirList;
|
||||
|
||||
QQueue<QString> *m_search_result_file = nullptr;
|
||||
QQueue<QString> *m_search_result_dir = nullptr;
|
||||
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
|
||||
SearchResult * m_search_result_thread = nullptr;
|
||||
QString m_keyword = 0;
|
||||
|
||||
FileSearcher* m_searcher = nullptr;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void initUi();
|
||||
|
|
|
@ -103,6 +103,13 @@ QVariant SearchItemModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool SearchItemModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
this->beginInsertRows(parent, row, count);
|
||||
this->endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::setItem 传入存储数据的item
|
||||
* @param item
|
||||
|
@ -110,3 +117,23 @@ QVariant SearchItemModel::data(const QModelIndex &index, int role) const
|
|||
void SearchItemModel::setItem(SearchItem * item) {
|
||||
m_item = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::appendItem
|
||||
*/
|
||||
void SearchItemModel::appendItem(QString path) {
|
||||
m_item->appendItem(path);
|
||||
this->insertRow(rowCount(QModelIndex()) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::removeItem
|
||||
*/
|
||||
void SearchItemModel::removeItem(QString path) {
|
||||
m_item->removeItem(path);
|
||||
}
|
||||
|
||||
void SearchItemModel::clear()
|
||||
{
|
||||
m_item->clear();
|
||||
}
|
||||
|
|
|
@ -27,10 +27,15 @@ public:
|
|||
int columnCount(const QModelIndex &parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex())override;
|
||||
// QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
void setItem(SearchItem *);
|
||||
|
||||
void appendItem(QString);
|
||||
void removeItem(QString);
|
||||
void clear();
|
||||
|
||||
private :
|
||||
SearchItem * m_item = nullptr;
|
||||
};
|
||||
|
|
|
@ -82,3 +82,26 @@ void SearchItem::setSearchList(const int& type, const QStringList& searchResult)
|
|||
m_searchtype = type;
|
||||
m_pathlist = searchResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItem::appendItem
|
||||
*/
|
||||
void SearchItem::appendItem(QString path) {
|
||||
m_pathlist.append(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItem::removeItem
|
||||
*/
|
||||
void SearchItem::removeItem(QString path) {
|
||||
m_pathlist.removeOne(path);
|
||||
}
|
||||
|
||||
int SearchItem::getCurrentSize() {
|
||||
return m_pathlist.length();
|
||||
}
|
||||
|
||||
void SearchItem::clear()
|
||||
{
|
||||
m_pathlist.clear();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ public:
|
|||
};
|
||||
|
||||
void setSearchList(const int&, const QStringList&);
|
||||
void appendItem(QString);
|
||||
void removeItem(QString);
|
||||
int getCurrentSize();
|
||||
void clear();
|
||||
|
||||
private:
|
||||
// SearchItem * m_parent = nullptr;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#include "search-result.h"
|
||||
#include <QTimer>
|
||||
|
||||
SearchResult::SearchResult(QObject * parent) : QThread(parent)
|
||||
{
|
||||
m_mainwindow = static_cast<MainWindow *>(parent);
|
||||
}
|
||||
|
||||
SearchResult::~SearchResult()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SearchResult::run()
|
||||
{
|
||||
int emptyLists = 0;
|
||||
while(!isInterruptionRequested()) {
|
||||
emptyLists = 0;
|
||||
m_mainwindow->m_searcher->m_mutex1.lock();
|
||||
if (!m_mainwindow->m_search_result_file->isEmpty()) {
|
||||
Q_EMIT this->searchResultFile(m_mainwindow->m_search_result_file->dequeue());
|
||||
m_mainwindow->m_searcher->m_mutex1.unlock();
|
||||
} else {
|
||||
emptyLists ++;
|
||||
m_mainwindow->m_searcher->m_mutex1.unlock();
|
||||
}
|
||||
m_mainwindow->m_searcher->m_mutex2.lock();
|
||||
if (!m_mainwindow->m_search_result_dir->isEmpty()) {
|
||||
Q_EMIT this->searchResultDir(m_mainwindow->m_search_result_dir->dequeue());
|
||||
m_mainwindow->m_searcher->m_mutex2.unlock();
|
||||
} else {
|
||||
emptyLists ++;
|
||||
m_mainwindow->m_searcher->m_mutex2.unlock();
|
||||
}
|
||||
m_mainwindow->m_searcher->m_mutex3.lock();
|
||||
if (!m_mainwindow->m_search_result_content->isEmpty())
|
||||
qDebug() << m_mainwindow->m_search_result_content->head();
|
||||
if (!m_mainwindow->m_search_result_content->isEmpty()) {
|
||||
Q_EMIT this->searchResultContent(m_mainwindow->m_search_result_content->dequeue());
|
||||
m_mainwindow->m_searcher->m_mutex3.unlock();
|
||||
} else {
|
||||
emptyLists ++;
|
||||
m_mainwindow->m_searcher->m_mutex3.unlock();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef SEARCHRESULT_H
|
||||
#define SEARCHRESULT_H
|
||||
#include <QThread>
|
||||
#include <QWaitCondition>
|
||||
#include "mainwindow.h"
|
||||
|
||||
class SearchResult : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SearchResult(QObject * parent = nullptr);
|
||||
~SearchResult();
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
MainWindow * m_mainwindow = nullptr;
|
||||
|
||||
Q_SIGNALS:
|
||||
void searchResultFile(const QString&);
|
||||
void searchResultDir(const QString&);
|
||||
// void searchResultContent(const QString&, const QStringList&);
|
||||
void searchResultContent(const QPair<QString, QStringList>);
|
||||
|
||||
};
|
||||
#endif // SEARCHRESULT_H
|
|
@ -207,13 +207,20 @@ void SettingsWidget::clearLayout(QLayout * layout) {
|
|||
* @param path 文件夹路径
|
||||
*/
|
||||
void SettingsWidget::onBtnDelClicked(const QString& path) {
|
||||
qDebug()<<path;
|
||||
Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) {
|
||||
if (item->getPath() == path) {
|
||||
item->deleteLater();
|
||||
item = NULL;
|
||||
return;
|
||||
QString returnMessage;
|
||||
if (GlobalSettings::getInstance()->setBlockDirs(path, returnMessage, true)) {
|
||||
qDebug()<<"Remove block dir in onBtnDelClicked() successed.";
|
||||
Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) {
|
||||
if (item->getPath() == path) {
|
||||
item->deleteLater();
|
||||
item = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
qWarning()<<returnMessage;
|
||||
qDebug()<<"Remove block dir in onBtnAddClicked() failed. Message: "<<returnMessage;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ SOURCES += \
|
|||
input-box.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
search-result.cpp \
|
||||
settings-widget.cpp \
|
||||
|
||||
|
||||
|
@ -36,6 +37,7 @@ HEADERS += \
|
|||
content-widget.h \
|
||||
input-box.h \
|
||||
mainwindow.h \
|
||||
search-result.h \
|
||||
settings-widget.h
|
||||
|
||||
# Default rules for deployment.
|
||||
|
|
Loading…
Reference in New Issue