Merge pull request #66 from mammonsama666/0111-dev
feat(searchList): Confirm interface with backend.
This commit is contained in:
commit
fa3f2c32b9
|
@ -37,7 +37,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
m_search_result_content = searchResultContent;
|
m_search_result_content = searchResultContent;
|
||||||
|
|
||||||
//file
|
//file
|
||||||
QtConcurrent::run([&, uniqueSymbol1](){
|
QtConcurrent::run([&, uniqueSymbol1, keyword](){
|
||||||
if(!m_search_result_file->isEmpty())
|
if(!m_search_result_file->isEmpty())
|
||||||
m_search_result_file->clear();
|
m_search_result_file->clear();
|
||||||
int begin = 0;
|
int begin = 0;
|
||||||
|
@ -55,7 +55,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
});
|
});
|
||||||
// Q_EMIT this->resultFile(m_search_result_file);
|
// Q_EMIT this->resultFile(m_search_result_file);
|
||||||
//dir
|
//dir
|
||||||
QtConcurrent::run([&, uniqueSymbol2](){
|
QtConcurrent::run([&, uniqueSymbol2, keyword](){
|
||||||
if(!m_search_result_dir->isEmpty())
|
if(!m_search_result_dir->isEmpty())
|
||||||
m_search_result_dir->clear();
|
m_search_result_dir->clear();
|
||||||
int begin = 0;
|
int begin = 0;
|
||||||
|
@ -73,13 +73,14 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
});
|
});
|
||||||
// Q_EMIT this->resultDir(m_search_result_dir);
|
// Q_EMIT this->resultDir(m_search_result_dir);
|
||||||
//content
|
//content
|
||||||
QtConcurrent::run([&, uniqueSymbol3](){
|
QtConcurrent::run([&, uniqueSymbol3, keyword](){
|
||||||
if(!m_search_result_content->isEmpty())
|
if(!m_search_result_content->isEmpty())
|
||||||
m_search_result_content->clear();
|
m_search_result_content->clear();
|
||||||
int begin = 0;
|
int begin = 0;
|
||||||
int num = 5;
|
int num = 5;
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
while(total<20)
|
while(total<20)
|
||||||
{
|
{
|
||||||
keywordSearchContent(uniqueSymbol3,keyword,begin,num);
|
keywordSearchContent(uniqueSymbol3,keyword,begin,num);
|
||||||
|
@ -329,14 +330,18 @@ QMap<QString,QStringList> FileSearcher::getContentResult(size_t uniqueSymbol, Xa
|
||||||
m_mutex3.lock();
|
m_mutex3.lock();
|
||||||
if(uniqueSymbol == FileSearcher::uniqueSymbol3)
|
if(uniqueSymbol == FileSearcher::uniqueSymbol3)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_search_result_content->enqueue(qMakePair(path,snippets));
|
m_search_result_content->enqueue(qMakePair(path,snippets));
|
||||||
m_mutex3.unlock();
|
m_mutex3.unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_mutex3.unlock();
|
m_mutex3.unlock();
|
||||||
exit(0);
|
break;
|
||||||
|
// exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "after";
|
||||||
searchResult.insert(path,snippets);
|
searchResult.insert(path,snippets);
|
||||||
qDebug()<< "path="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
|
qDebug()<< "path="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,13 @@ public:
|
||||||
explicit FileSearcher(QObject *parent = nullptr);
|
explicit FileSearcher(QObject *parent = nullptr);
|
||||||
~FileSearcher();
|
~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:
|
public Q_SLOTS:
|
||||||
void onKeywordSearch(QString keyword,QQueue<QString> *searchResultFile,QQueue<QString> *searchResultDir,QQueue<QPair<QString,QStringList>> *searchResultContent);
|
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<QString> *m_search_result_dir = nullptr;
|
||||||
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
|
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
|
||||||
bool m_searching = false;
|
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
|
#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));
|
// m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0));
|
||||||
// }
|
// }
|
||||||
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
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->setContent(m_contentList.at(searchList->currentIndex().row()), keyword);
|
||||||
}
|
}
|
||||||
m_detailView->setupWidget(type, path);
|
m_detailView->setupWidget(type, path);
|
||||||
|
@ -198,7 +198,6 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
||||||
return;
|
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 获取表头
|
* @brief ContentWidget::getTitleName 获取表头
|
||||||
* @param type 搜索类型
|
* @param type 搜索类型
|
||||||
|
@ -257,6 +392,16 @@ QString ContentWidget::getTitleName(const int& type) {
|
||||||
* @param layout 需要清空的布局
|
* @param layout 需要清空的布局
|
||||||
*/
|
*/
|
||||||
void ContentWidget::clearLayout(QLayout * 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;
|
if (! layout) return;
|
||||||
QLayoutItem * child;
|
QLayoutItem * child;
|
||||||
while ((child = layout->takeAt(0)) != 0) {
|
while ((child = layout->takeAt(0)) != 0) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
void setPage(const int&);
|
void setPage(const int&);
|
||||||
int currentPage();
|
int currentPage();
|
||||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&, const QString&);
|
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 initHomePage();
|
||||||
void setContentList(const QStringList&);
|
void setContentList(const QStringList&);
|
||||||
private:
|
private:
|
||||||
|
@ -36,6 +37,9 @@ private:
|
||||||
QVBoxLayout * m_detailLyt = nullptr;
|
QVBoxLayout * m_detailLyt = nullptr;
|
||||||
|
|
||||||
SearchDetailView * m_detailView = nullptr;
|
SearchDetailView * m_detailView = nullptr;
|
||||||
|
SearchListView * m_fileListView = nullptr;
|
||||||
|
SearchListView * m_dirListView = nullptr;
|
||||||
|
SearchListView * m_contentListView = nullptr;
|
||||||
|
|
||||||
int m_currentType = 0;
|
int m_currentType = 0;
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
|
||||||
this->setHeaderHidden(true);
|
this->setHeaderHidden(true);
|
||||||
this->setColumnWidth(0, 20);
|
this->setColumnWidth(0, 20);
|
||||||
this->setColumnWidth(1, 80);
|
this->setColumnWidth(1, 80);
|
||||||
int rowHeight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
|
rowheight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
|
||||||
this->setFixedHeight(list.count() * rowHeight + 2);
|
this->setFixedHeight(list.count() * rowheight + 2);
|
||||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
this->setAutoFillBackground(false);
|
this->setAutoFillBackground(false);
|
||||||
this->setStyleSheet("QWidget{background:transparent;}");
|
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() {
|
int SearchListView::getCurrentType() {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
|
|
|
@ -26,7 +26,12 @@ public:
|
||||||
static int getResType(const QString&);
|
static int getResType(const QString&);
|
||||||
|
|
||||||
bool is_current_list = false;
|
bool is_current_list = false;
|
||||||
|
int rowheight = 0;
|
||||||
|
|
||||||
|
void appendItem(QString);
|
||||||
|
void removeItem(QString);
|
||||||
|
void clear();
|
||||||
|
bool isHidden = false;
|
||||||
private:
|
private:
|
||||||
SearchItemModel * m_model = nullptr;
|
SearchItemModel * m_model = nullptr;
|
||||||
SearchItem * m_item = nullptr;
|
SearchItem * m_item = nullptr;
|
||||||
|
|
|
@ -65,7 +65,7 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
||||||
|
|
||||||
// connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString)));
|
// connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString)));
|
||||||
m_timer = new QTimer;
|
m_timer = new QTimer;
|
||||||
QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){
|
connect(m_timer, &QTimer::timeout, this, [ = ](){
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||||
});
|
});
|
||||||
|
@ -76,8 +76,8 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
||||||
} else {
|
} else {
|
||||||
if (text == "") {
|
if (text == "") {
|
||||||
m_isEmpty = true;
|
m_isEmpty = true;
|
||||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
|
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
|
|
|
@ -85,14 +85,13 @@ void centerToScreen(QWidget* widget) {
|
||||||
int desk_y = desk_rect.height();
|
int desk_y = desk_rect.height();
|
||||||
int x = widget->width();
|
int x = widget->width();
|
||||||
int y = widget->height();
|
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[])
|
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_EnableHighDpiScaling);
|
||||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,14 @@
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <KWindowEffects>
|
#include <KWindowEffects>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include "libsearch.h"
|
|
||||||
#include "kwindowsystem.h"
|
#include "kwindowsystem.h"
|
||||||
|
|
||||||
//#include "inotify-manager.h"
|
//#include "inotify-manager.h"
|
||||||
#include "settings-widget.h"
|
#include "settings-widget.h"
|
||||||
|
|
||||||
|
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
|
#include "search-result.h"
|
||||||
|
|
||||||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +48,8 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent)
|
QMainWindow(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
m_searcher = new FileSearcher();
|
||||||
// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test");
|
// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test");
|
||||||
/*-------------Inotify Test Start---------------*/
|
/*-------------Inotify Test Start---------------*/
|
||||||
// QTime t1 = QTime::currentTime();
|
// QTime t1 = QTime::currentTime();
|
||||||
|
@ -80,6 +84,21 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
this->setPalette(pal);
|
this->setPalette(pal);
|
||||||
this->update();
|
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()
|
MainWindow::~MainWindow()
|
||||||
|
@ -174,9 +193,9 @@ void MainWindow::initUi()
|
||||||
m_contentFrame->setCurrentIndex(0);
|
m_contentFrame->setCurrentIndex(0);
|
||||||
} else {
|
} else {
|
||||||
m_contentFrame->setCurrentIndex(1);
|
m_contentFrame->setCurrentIndex(1);
|
||||||
QTimer::singleShot(50,this,[=](){
|
// QTimer::singleShot(50,this,[=](){
|
||||||
searchContent(text);
|
searchContent(text);
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -190,13 +209,11 @@ void MainWindow::initUi()
|
||||||
*/
|
*/
|
||||||
void MainWindow::bootOptionsFilter(QString opt)
|
void MainWindow::bootOptionsFilter(QString opt)
|
||||||
{
|
{
|
||||||
|
clearSearchResult();
|
||||||
if (opt == "-s" || opt == "-show") {
|
this->show();
|
||||||
clearSearchResult();
|
this->raise();
|
||||||
this->show();
|
this->activateWindow();
|
||||||
this->raise();
|
m_search_result_thread->start();
|
||||||
this->activateWindow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,83 +252,25 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
||||||
* @param searchcontent
|
* @param searchcontent
|
||||||
*/
|
*/
|
||||||
void MainWindow::searchContent(QString searchcontent){
|
void MainWindow::searchContent(QString searchcontent){
|
||||||
|
m_keyword = searchcontent;
|
||||||
m_lists.clear();
|
m_lists.clear();
|
||||||
m_types.clear();
|
m_types.clear();
|
||||||
|
|
||||||
AppMatch * appMatchor = new AppMatch(this);
|
AppMatch * appMatchor = new AppMatch(this);
|
||||||
SettingsMatch * settingMatchor = new SettingsMatch(this);
|
SettingsMatch * settingMatchor = new SettingsMatch(this);
|
||||||
//应用与设置搜索
|
//应用与设置搜索
|
||||||
QStringList list;
|
QStringList appList;
|
||||||
list = appMatchor->startMatchApp(searchcontent);
|
appList = appMatchor->startMatchApp(searchcontent);
|
||||||
QStringList list3;
|
QStringList settingList;
|
||||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
settingList = settingMatchor->startMatchApp(searchcontent);
|
||||||
m_types.append(SearchItem::SearchType::Apps);
|
m_types.append(SearchItem::SearchType::Apps);
|
||||||
m_types.append(SearchItem::SearchType::Settings);
|
m_types.append(SearchItem::SearchType::Settings);
|
||||||
m_lists.append(list);
|
m_lists.append(appList);
|
||||||
m_lists.append(list3);
|
m_lists.append(settingList);
|
||||||
|
|
||||||
//文件、文件夹、内容搜索
|
|
||||||
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_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
||||||
|
|
||||||
//iaom--------this part shall be rewrite
|
//文件、文件夹、内容搜索
|
||||||
// connect(search, &FileSearcher::contentResult, this, [ = ](QMap<QString,QStringList> map) {
|
this->m_searcher->onKeywordSearch(searchcontent, m_search_result_file, m_search_result_dir, m_search_result_content);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用GSetting获取当前窗口应该使用的透明度
|
//使用GSetting获取当前窗口应该使用的透明度
|
||||||
|
@ -339,6 +298,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
switch (event->response_type & ~0x80) {
|
switch (event->response_type & ~0x80) {
|
||||||
case XCB_FOCUS_OUT:
|
case XCB_FOCUS_OUT:
|
||||||
this->hide();
|
this->hide();
|
||||||
|
m_search_result_thread->quit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,12 @@
|
||||||
#include "input-box.h"
|
#include "input-box.h"
|
||||||
#include "index/index-generator.h"
|
#include "index/index-generator.h"
|
||||||
#include "settings-widget.h"
|
#include "settings-widget.h"
|
||||||
|
#include "libsearch.h"
|
||||||
|
|
||||||
|
class SearchResult;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
friend class SearchResult;
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -80,6 +83,15 @@ private:
|
||||||
QVector<int> m_types;
|
QVector<int> m_types;
|
||||||
QVector<QStringList> m_lists;
|
QVector<QStringList> m_lists;
|
||||||
QStringList m_dirList;
|
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:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void initUi();
|
void initUi();
|
||||||
|
|
|
@ -103,6 +103,13 @@ QVariant SearchItemModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant();
|
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
|
* @brief SearchItemModel::setItem 传入存储数据的item
|
||||||
* @param item
|
* @param item
|
||||||
|
@ -110,3 +117,23 @@ QVariant SearchItemModel::data(const QModelIndex &index, int role) const
|
||||||
void SearchItemModel::setItem(SearchItem * item) {
|
void SearchItemModel::setItem(SearchItem * item) {
|
||||||
m_item = 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;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) 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;
|
// QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
|
|
||||||
void setItem(SearchItem *);
|
void setItem(SearchItem *);
|
||||||
|
|
||||||
|
void appendItem(QString);
|
||||||
|
void removeItem(QString);
|
||||||
|
void clear();
|
||||||
|
|
||||||
private :
|
private :
|
||||||
SearchItem * m_item = nullptr;
|
SearchItem * m_item = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,3 +82,26 @@ void SearchItem::setSearchList(const int& type, const QStringList& searchResult)
|
||||||
m_searchtype = type;
|
m_searchtype = type;
|
||||||
m_pathlist = searchResult;
|
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 setSearchList(const int&, const QStringList&);
|
||||||
|
void appendItem(QString);
|
||||||
|
void removeItem(QString);
|
||||||
|
int getCurrentSize();
|
||||||
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// SearchItem * m_parent = nullptr;
|
// 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 文件夹路径
|
* @param path 文件夹路径
|
||||||
*/
|
*/
|
||||||
void SettingsWidget::onBtnDelClicked(const QString& path) {
|
void SettingsWidget::onBtnDelClicked(const QString& path) {
|
||||||
qDebug()<<path;
|
QString returnMessage;
|
||||||
Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) {
|
if (GlobalSettings::getInstance()->setBlockDirs(path, returnMessage, true)) {
|
||||||
if (item->getPath() == path) {
|
qDebug()<<"Remove block dir in onBtnDelClicked() successed.";
|
||||||
item->deleteLater();
|
Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) {
|
||||||
item = NULL;
|
if (item->getPath() == path) {
|
||||||
return;
|
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 \
|
input-box.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
|
search-result.cpp \
|
||||||
settings-widget.cpp \
|
settings-widget.cpp \
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ HEADERS += \
|
||||||
content-widget.h \
|
content-widget.h \
|
||||||
input-box.h \
|
input-box.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
|
search-result.h \
|
||||||
settings-widget.h
|
settings-widget.h
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
|
|
Loading…
Reference in New Issue