From 1827b8335e06941edb3a3c226b0fb271f3c467c0 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 8 Jan 2021 20:48:20 +0800 Subject: [PATCH] feat(settings-widget): Use interface provided by backend. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 调用黑名单和搜索的接口 Log: 调用黑名单和搜索的接口 --- libsearch/global-settings.cpp | 7 +++-- libsearch/index/file-searcher.cpp | 3 ++ libsearch/index/file-searcher.h | 6 ++-- src/mainwindow.cpp | 51 +++++++++---------------------- src/mainwindow.h | 1 + src/settings-widget.cpp | 38 ++++++++++++++++++----- src/settings-widget.h | 5 +-- 7 files changed, 59 insertions(+), 52 deletions(-) diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index 591231c..054a272 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -83,16 +83,17 @@ bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage) QStringList blockDirs = m_block_dirs_settings->allKeys(); for(QString i:blockDirs) { - if(path.startsWith(i)) +// qWarning()<remove(i); } - m_block_dirs_settings->setValue(path,"0"); + m_block_dirs_settings->setValue(path.right(path.length()-1),"0"); return true; } diff --git a/libsearch/index/file-searcher.cpp b/libsearch/index/file-searcher.cpp index 9379fbd..cb535e6 100644 --- a/libsearch/index/file-searcher.cpp +++ b/libsearch/index/file-searcher.cpp @@ -12,6 +12,9 @@ FileSearcher::FileSearcher(QObject *parent) : QObject(parent) void FileSearcher::onKeywordSearch(QString keyword) { + m_search_result_file = new QQueue; + m_search_result_dir = new QQueue; + m_search_result_content = new QQueue>; //file QtConcurrent::run([=](){ int begin = 0; diff --git a/libsearch/index/file-searcher.h b/libsearch/index/file-searcher.h index 79ce686..834bdb7 100644 --- a/libsearch/index/file-searcher.h +++ b/libsearch/index/file-searcher.h @@ -43,9 +43,9 @@ private: QMap getContentResult(Xapian::MSet &result,std::string &keyWord); bool isBlocked(QString &path); - QQueue *m_search_result_file; - QQueue *m_search_result_dir; - QQueue> *m_search_result_content; + QQueue *m_search_result_file = nullptr; + QQueue *m_search_result_dir = nullptr; + QQueue> *m_search_result_content = nullptr; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 50e5250..a801a7c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -233,28 +233,36 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen) * @param searchcontent */ void MainWindow::searchContent(QString searchcontent){ - // QVector types; - // QVector lists; m_lists.clear(); m_types.clear(); AppMatch * appMatchor = new AppMatch(this); SettingsMatch * settingMatchor = new SettingsMatch(this); - - //测试用数据 + //应用与设置搜索 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 list3; list3 = settingMatchor->startMatchApp(searchcontent); - // list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; 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 * dirQueue) { + qWarning()<<"dirFile---"; + }); + connect(search, &FileSearcher::resultFile, this, [ = ](QQueue * fileQueue) { + qWarning()<<"resultFile---"; + }); + connect(search, &FileSearcher::resultContent, this, [ = ](QQueue> * contentQueue) { + qWarning()<<"resultContent---"; + }); + search->onKeywordSearch(searchcontent); + //将搜索结果加入列表 + m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent); + //iaom--------this part shall be rewrite // connect(search, &FileSearcher::contentResult, this, [ = ](QMap map) { // m_types.append(SearchItem::SearchType::Contents); @@ -271,24 +279,9 @@ void MainWindow::searchContent(QString searchcontent){ // m_lists.append(pathlist); // m_contentFrame->setContentList(contentList); // }); - QTime t1 = QTime::currentTime(); // search->onKeywordSearch(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); - //文件搜索 - - FileSearcher *searcher = new FileSearcher(); //iaom--------this part shall be rewrite // connect(searcher,&FileSearcher::result,[=](QVector resultV){ @@ -307,26 +300,12 @@ void MainWindow::searchContent(QString searchcontent){ // QStringList res = IndexGenerator::IndexSearch(searchcontent); // types.append(SearchItem::SearchType::Files); // lists.append(res); - - //将搜索结果加入列表 - // m_contentFrame->refreshSearchList(types, lists); } //使用GSetting获取当前窗口应该使用的透明度 double MainWindow::getTransparentData() { return GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble(); -// if (!m_transparency_gsettings) { -// return 0.7; -// } - -// QStringList keys = m_transparency_gsettings->keys(); -// if (keys.contains("transparency")) { -// double tp = m_transparency_gsettings->get("transparency").toDouble(); -// return tp; -// } else { -// return 0.7; -// } } /** diff --git a/src/mainwindow.h b/src/mainwindow.h index 34886ac..3ab57d6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -79,6 +79,7 @@ private: QVector m_types; QVector m_lists; + QStringList m_dirList; protected: void paintEvent(QPaintEvent *); void initUi(); diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index 20a00c2..529c452 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -5,6 +5,7 @@ #include #include #include "folder-list-item.h" +#include "global-settings.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) @@ -12,12 +13,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); this->setAttribute(Qt::WA_TranslucentBackground); initUi(); - QStringList list; - list<<"/usr/share/applications"<<"/usr/share/icons"<< - "/usr/libs"<<"/home/zjp/UKUI/SEARCH"<< - "/home/zjp/UKUI/UKCC"<<"/home/zjp/UKUI/SD/intel/ukui-settings-daemon"<< - "/home/zjp/下载"<<"/home/zjp/code"; - setupBlackList(list); + setupBlackList(GlobalSettings::getInstance()->getBlockDirs()); } SettingsWidget::~SettingsWidget() @@ -178,6 +174,7 @@ void SettingsWidget::initUi() { * @param list 文件夹路径列表 */ void SettingsWidget::setupBlackList(const QStringList& list) { + clearLayout(m_dirListLyt); Q_FOREACH(QString path, list) { FolderListItem * item = new FolderListItem(m_dirListWidget, path); m_dirListLyt->addWidget(item); @@ -188,6 +185,23 @@ void SettingsWidget::setupBlackList(const QStringList& list) { m_dirListLyt->addStretch(); } +/** + * @brief SettingsWidget::clearLayout 清空某个布局 + * @param layout 需要清空的布局 + */ +void SettingsWidget::clearLayout(QLayout * layout) { + if (! layout) return; + QLayoutItem * child; + while ((child = layout->takeAt(0)) != 0) { + if(child->widget()) + { + child->widget()->setParent(NULL); + } + delete child; + } + child = NULL; +} + /** * @brief SettingsWidget::onBtnDelClicked 删除黑名单中的目录 * @param path 文件夹路径 @@ -251,9 +265,17 @@ void SettingsWidget::onBtnAddClicked() { fileDialog->deleteLater(); return; } - QString selectedDir; + QString selectedDir = 0; + QString returnMessage = 0; selectedDir = fileDialog->selectedFiles().first(); - qDebug()<settings-widget.cpp #238"; + if (GlobalSettings::getInstance()->setBlockDirs(selectedDir, returnMessage)) { + setupBlackList(GlobalSettings::getInstance()->getBlockDirs()); + qDebug()<<"Add block dir in onBtnAddClicked() successed. ->settings-widget.cpp #238"; + } else { + qWarning()<settings-widget.cpp #238"; + } } /** diff --git a/src/settings-widget.h b/src/settings-widget.h index f7c8d5c..4100798 100644 --- a/src/settings-widget.h +++ b/src/settings-widget.h @@ -23,8 +23,9 @@ public: private: void initUi(); - void setupBlackList(const QStringList&); - void paintEvent(QPaintEvent *event); + void setupBlackList(const QStringList &); + void clearLayout(QLayout *); + void paintEvent(QPaintEvent *); //标题栏 QVBoxLayout * m_mainLyt = nullptr; QFrame * m_titleFrame = nullptr;