Merge branch 'main' into zzh-search

This commit is contained in:
Mouse Zhang 2020-12-28 06:34:43 -06:00 committed by GitHub
commit a493cd716e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 787 additions and 47 deletions

200
appmatch/app-match.cpp Normal file
View File

@ -0,0 +1,200 @@
#include "app-match.h"
#include <glib.h>
#include "chinesecharacterstopinyin.h"
AppMatch::AppMatch(QObject *parent) : QObject(parent)
{
this->getDesktopFilePath();
}
QStringList AppMatch::startMatchApp(QString input){
input.replace(" ","");
m_soureText=input;
m_returnResult.clear();
if(input.isEmpty()){
return m_returnResult;
}
this->getAppName();
m_returnResult=m_midResult;
m_midResult.clear();
return m_returnResult;
}
void AppMatch::getAllDesktopFilePath(QString path){
GKeyFileFlags flags=G_KEY_FILE_NONE;
GKeyFile* keyfile=g_key_file_new ();
QDir dir(path);
if (!dir.exists()) {
return;
}
dir.setFilter(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot);
dir.setSorting(QDir::DirsFirst);
QFileInfoList list = dir.entryInfoList();
list.removeAll(QFileInfo("/usr/share/applications/screensavers"));
if(list.size()< 1 ) {
return;
}
int i=0;
//递归算法的核心部分
do{
QFileInfo fileInfo = list.at(i);
//如果是文件夹,递归
bool isDir = fileInfo.isDir();
if(isDir) {
getAllDesktopFilePath(fileInfo.filePath());
}
else{
//过滤LXQt、KDE
QString filePathStr=fileInfo.filePath();
if(filePathStr.contains("KDE",Qt::CaseInsensitive)||
filePathStr.contains("mate",Qt::CaseInsensitive)||
filePathStr.contains("LX",Qt::CaseInsensitive) ){
i++;
continue;
}
//过滤后缀不是.desktop的文件
if(!filePathStr.endsWith(".desktop"))
{
i++;
continue;
}
QByteArray fpbyte=filePathStr.toLocal8Bit();
char* filepath=fpbyte.data();
g_key_file_load_from_file(keyfile,filepath,flags,nullptr);
char* ret_1=g_key_file_get_locale_string(keyfile,"Desktop Entry","NoDisplay", nullptr, nullptr);
if(ret_1!=nullptr)
{
QString str=QString::fromLocal8Bit(ret_1);
if(str.contains("true"))
{
i++;
continue;
}
}
char* ret_2=g_key_file_get_locale_string(keyfile,"Desktop Entry","NotShowIn", nullptr, nullptr);
if(ret_2!=nullptr)
{
QString str=QString::fromLocal8Bit(ret_2);
if(str.contains("UKUI"))
{
i++;
continue;
}
}
//过滤中英文名为空的情况
QLocale cn;
QString language=cn.languageToString(cn.language());
if(QString::compare(language,"Chinese")==0)
{
char* nameCh=g_key_file_get_string(keyfile,"Desktop Entry","Name[zh_CN]", nullptr);
char* nameEn=g_key_file_get_string(keyfile,"Desktop Entry","Name", nullptr);
if(QString::fromLocal8Bit(nameCh).isEmpty() && QString::fromLocal8Bit(nameEn).isEmpty())
{
i++;
continue;
}
}
else {
char* name=g_key_file_get_string(keyfile,"Desktop Entry","Name", nullptr);
if(QString::fromLocal8Bit(name).isEmpty())
{
i++;
continue;
}
}
m_filePathList.append(filePathStr);
}
i++;
} while(i < list.size());
g_key_file_free(keyfile);
}
void AppMatch::getDesktopFilePath()
{
m_filePathList.clear();
getAllDesktopFilePath("/usr/share/applications/");
m_filePathList.removeAll("/usr/share/applications/software-properties-livepatch.desktop");
m_filePathList.removeAll("/usr/share/applications/mate-color-select.desktop");
m_filePathList.removeAll("/usr/share/applications/blueman-adapters.desktop");
m_filePathList.removeAll("/usr/share/applications/blueman-manager.desktop");
m_filePathList.removeAll("/usr/share/applications/mate-user-guide.desktop");
m_filePathList.removeAll("/usr/share/applications/nm-connection-editor.desktop");
m_filePathList.removeAll("/usr/share/applications/debian-uxterm.desktop");
m_filePathList.removeAll("/usr/share/applications/debian-xterm.desktop");
m_filePathList.removeAll("/usr/share/applications/im-config.desktop");
m_filePathList.removeAll("/usr/share/applications/fcitx.desktop");
m_filePathList.removeAll("/usr/share/applications/fcitx-configtool.desktop");
m_filePathList.removeAll("/usr/share/applications/onboard-settings.desktop");
m_filePathList.removeAll("/usr/share/applications/info.desktop");
m_filePathList.removeAll("/usr/share/applications/ukui-power-preferences.desktop");
m_filePathList.removeAll("/usr/share/applications/ukui-power-statistics.desktop");
m_filePathList.removeAll("/usr/share/applications/software-properties-drivers.desktop");
m_filePathList.removeAll("/usr/share/applications/software-properties-gtk.desktop");
m_filePathList.removeAll("/usr/share/applications/gnome-session-properties.desktop");
m_filePathList.removeAll("/usr/share/applications/org.gnome.font-viewer.desktop");
m_filePathList.removeAll("/usr/share/applications/xdiagnose.desktop");
m_filePathList.removeAll("/usr/share/applications/gnome-language-selector.desktop");
m_filePathList.removeAll("/usr/share/applications/mate-notification-properties.desktop");
m_filePathList.removeAll("/usr/share/applications/transmission-gtk.desktop");
m_filePathList.removeAll("/usr/share/applications/mpv.desktop");
m_filePathList.removeAll("/usr/share/applications/system-config-printer.desktop");
m_filePathList.removeAll("/usr/share/applications/org.gnome.DejaDup.desktop");
m_filePathList.removeAll("/usr/share/applications/yelp.desktop");
m_filePathList.removeAll("/usr/share/applications/peony-computer.desktop");
m_filePathList.removeAll("/usr/share/applications/peony-home.desktop");
m_filePathList.removeAll("/usr/share/applications/peony-trash.desktop");
m_filePathList.removeAll("/usr/share/applications/peony.desktop");
//v10
m_filePathList.removeAll("/usr/share/applications/mate-about.desktop");
m_filePathList.removeAll("/usr/share/applications/time.desktop");
m_filePathList.removeAll("/usr/share/applications/network.desktop");
m_filePathList.removeAll("/usr/share/applications/shares.desktop");
m_filePathList.removeAll("/usr/share/applications/mate-power-statistics.desktop");
m_filePathList.removeAll("/usr/share/applications/display-im6.desktop");
m_filePathList.removeAll("/usr/share/applications/display-im6.q16.desktop");
m_filePathList.removeAll("/usr/share/applications/openjdk-8-policytool.desktop");
m_filePathList.removeAll("/usr/share/applications/kylin-io-monitor.desktop");
m_filePathList.removeAll("/usr/share/applications/wps-office-uninstall.desktop");
m_filePathList.removeAll("/usr/share/applications/wps-office-misc.desktop");
}
void AppMatch::getAppName()
{
GKeyFileFlags flags=G_KEY_FILE_NONE;
GKeyFile* keyfile=g_key_file_new ();
QByteArray fpbyte;
QString str;
char* filepath;
char* name;
QString namestr;
for(int i=0;i<m_filePathList.size();i++){
str=m_filePathList.at(i);
fpbyte=str.toLocal8Bit();
filepath=fpbyte.data();
g_key_file_load_from_file(keyfile,filepath,flags,nullptr);
name=g_key_file_get_locale_string(keyfile,"Desktop Entry","Name", nullptr, nullptr);
namestr=QString::fromLocal8Bit(name);
appNameMatch(namestr,str);
}
g_key_file_load_from_file(keyfile,filepath,flags,nullptr);
g_key_file_free(keyfile);
}
void AppMatch::appNameMatch(QString appname,QString desktoppath){
if(appname.contains(m_soureText)){
m_midResult.append(desktoppath);
}
QString pinyin=chineseCharactersToPinyin::find(appname).toLower(); // 中文转拼音
if(pinyin.contains(m_soureText,Qt::CaseInsensitive)){
m_midResult.append(desktoppath);
}
}

29
appmatch/app-match.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef APPMATCH_H
#define APPMATCH_H
#include <QObject>
#include <QDir>
#include <QLocale>
#include <QDebug>
class AppMatch : public QObject
{
Q_OBJECT
public:
explicit AppMatch(QObject *parent = nullptr);
QStringList startMatchApp(QString input);
private:
void getAllDesktopFilePath(QString path);
void getDesktopFilePath();
void getAppName();
void appNameMatch(QString appname,QString desktoppath);
private:
QString m_soureText;
QStringList m_filePathList;
QStringList m_returnResult;
QStringList m_midResult;
};
#endif // APPMATCH_H

7
appmatch/app-match.pri Normal file
View File

@ -0,0 +1,7 @@
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/app-match.h \
SOURCES += \
$$PWD/app-match.cpp \

View File

@ -4,8 +4,10 @@ HEADERS += \
$$PWD/search-list-view.h \ $$PWD/search-list-view.h \
$$PWD/search-detail-view.h \ $$PWD/search-detail-view.h \
$$PWD/option-view.h \ $$PWD/option-view.h \
$$PWD/home-page-item.h \
SOURCES += \ SOURCES += \
$$PWD/search-list-view.cpp \ $$PWD/search-list-view.cpp \
$$PWD/search-detail-view.cpp \ $$PWD/search-detail-view.cpp \
$$PWD/option-view.cpp \ $$PWD/option-view.cpp \
$$PWD/home-page-item.cpp \

128
control/home-page-item.cpp Normal file
View File

@ -0,0 +1,128 @@
#include "home-page-item.h"
#include <QEvent>
#include <QProcess>
#include <QDebug>
#include <gio/gdesktopappinfo.h>
HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent)
{
setupUi(type, path);
}
HomePageItem::~HomePageItem()
{
}
/**
* @brief HomePageItem::setupUi item
* @param type
* @param path
*/
void HomePageItem::setupUi(const int& type, const QString& path) {
m_widget = new QWidget(this);
m_widget->setObjectName("MainWidget");
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
m_widget->installEventFilter(this);
connect(this, &HomePageItem::onItemClicked, this, [ = ]() {
switch (SearchListView::getResType(path)) {
case SearchListView::ResType::App: {
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());
g_app_info_launch(G_APP_INFO(desktopAppInfo),nullptr, nullptr, nullptr);
g_object_unref(desktopAppInfo);
break;
}
case SearchListView::ResType::Dir:
case SearchListView::ResType::File: {
QProcess * process = new QProcess;
process->start(QString("xdg-open %1").arg(path));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
break;
}
case SearchListView::ResType::Setting: {
//打开控制面板对应页面
QProcess * process = new QProcess;
process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower()));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
break;
}
default:
break;
}
});
m_iconlabel = new QLabel(m_widget);
m_namelabel = new QLabel(m_widget);
if (type == ItemType::Recent) {
m_widget->setFixedSize(265, 48);
QIcon icon;
switch (SearchListView::getResType(path)) { //可能出现文件应用等,需要根据路径判断类型
case SearchListView::ResType::App : {
icon = FileUtils::getAppIcon(path);
m_namelabel->setText(FileUtils::getAppName(path));
break;
}
case SearchListView::ResType::File : {
icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
m_namelabel->setText(FileUtils::getFileName(path));
break;
}
case SearchListView::ResType::Setting : {
icon = FileUtils::getSettingIcon(path, true);
m_namelabel->setText(FileUtils::getSettingName(path));
break;
}
case SearchListView::ResType::Dir : {
break;
}
default :
break;
}
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(24, 24))));
m_hlayout = new QHBoxLayout(m_widget);
m_iconlabel->setAlignment(Qt::AlignCenter);
m_namelabel->setAlignment(Qt::AlignCenter);
m_hlayout->addWidget(m_iconlabel);
m_hlayout->addWidget(m_namelabel);
m_hlayout->addStretch();
return;
} else if (type == ItemType::Quick) {
if (SearchListView::getResType(path) == SearchListView::ResType::Setting) {
QIcon icon = FileUtils::getSettingIcon(path, true);
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
m_namelabel->setText(FileUtils::getSettingName(path));
} else {
QIcon icon = FileUtils::getAppIcon(path);
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
m_namelabel->setText(FileUtils::getAppName(path));
}
} else {
QIcon icon = FileUtils::getAppIcon(path);
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
m_namelabel->setText(FileUtils::getAppName(path));
}
m_widget->setFixedSize(120, 120);
m_vlayout = new QVBoxLayout(m_widget);
m_vlayout->setContentsMargins(0,16,0,12);
m_iconlabel->setAlignment(Qt::AlignCenter);
m_namelabel->setAlignment(Qt::AlignCenter);
m_vlayout->addWidget(m_iconlabel);
m_vlayout->addWidget(m_namelabel);
}
bool HomePageItem::eventFilter(QObject *watched, QEvent *event){
if (watched == m_widget){
if (event->type() == QEvent::MouseButtonPress) {
Q_EMIT this->onItemClicked();
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.2); border-radius: 4px;}");
return true;
} else if (event->type() == QEvent::MouseButtonRelease) {
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
return true;
}
}
return QObject::eventFilter(watched, event);
}

40
control/home-page-item.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef HOMEPAGEITEM_H
#define HOMEPAGEITEM_H
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "file-utils.h"
#include "search-list-view.h"
class HomePageItem : public QWidget
{
Q_OBJECT
public:
explicit HomePageItem(QWidget *, const int&, const QString&);
~HomePageItem();
enum ItemType { //homepage中item的类型包括常用应用、最近打开、快捷打开
Common,
Recent,
Quick
};
protected:
bool eventFilter(QObject *, QEvent *);
private:
void setupUi(const int&, const QString&);
QWidget * m_widget = nullptr;
QHBoxLayout * m_hlayout = nullptr;
QVBoxLayout * m_vlayout = nullptr;
QLabel * m_iconlabel = nullptr;
QLabel * m_namelabel = nullptr;
Q_SIGNALS:
void onItemClicked();
};
#endif // HOMEPAGEITEM_H

View File

@ -11,6 +11,8 @@
#include <QProcess> #include <QProcess>
#include <QClipboard> #include <QClipboard>
#include <QApplication> #include <QApplication>
#include <QFileInfo>
#include <QDateTime>
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
{ {
@ -76,14 +78,54 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
hLine->setFixedHeight(1); hLine->setFixedHeight(1);
hLine->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}"); hLine->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(iconLabel);
m_layout->addWidget(nameFrame);
m_layout->addWidget(hLine);
//文件和文件夹有一个额外的详情区域
if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File) {
QFrame * detailFrame = new QFrame(this);
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
detailLyt->setContentsMargins(0,0,0,0);
QFrame * pathFrame = new QFrame(detailFrame);
QFrame * timeFrame = new QFrame(detailFrame);
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame);
QHBoxLayout * timeLyt = new QHBoxLayout(timeFrame);
QLabel * pathLabel_1 = new QLabel(pathFrame);
QLabel * pathLabel_2 = new QLabel(pathFrame);
pathLabel_1->setText(tr("Path"));
pathLabel_2->setText(path);
pathLabel_2->setMaximumWidth(500);
pathLabel_2->setWordWrap(true);
pathLyt->addWidget(pathLabel_1);
pathLyt->addStretch();
pathLyt->addWidget(pathLabel_2);
QLabel * timeLabel_1 = new QLabel(timeFrame);
QLabel * timeLabel_2 = new QLabel(timeFrame);
timeLabel_1->setText(tr("Last time modified"));
QFileInfo fileInfo(path);
timeLabel_2->setText(fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss"));
timeLyt->addWidget(timeLabel_1);
timeLyt->addStretch();
timeLyt->addWidget(timeLabel_2);
detailLyt->addWidget(pathFrame);
detailLyt->addWidget(timeFrame);
QFrame * hLine_2 = new QFrame(this);
hLine_2->setLineWidth(0);
hLine_2->setFixedHeight(1);
hLine_2->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(detailFrame);
m_layout->addWidget(hLine_2);
}
//可执行操作区域
OptionView * optionView = new OptionView(this, type); OptionView * optionView = new OptionView(this, type);
connect(optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) { connect(optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) {
execActions(type, option, path); execActions(type, option, path);
}); });
m_layout->addWidget(iconLabel);
m_layout->addWidget(nameFrame);
m_layout->addWidget(hLine);
m_layout->addWidget(optionView); m_layout->addWidget(optionView);
m_layout->addStretch(); m_layout->addStretch();
@ -96,23 +138,22 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
typeLabel->setText(tr("Application")); typeLabel->setText(tr("Application"));
break; break;
} }
case SearchListView::ResType::Dir :
case SearchListView::ResType::File : { case SearchListView::ResType::File : {
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100)))); iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
nameLabel->setText(FileUtils::getFileName(path)); nameLabel->setText(FileUtils::getFileName(path));
typeLabel->setText(tr("Document")); typeLabel->setText(tr("Document"));
break; break;
} }
case SearchListView::ResType::Setting : { case SearchListView::ResType::Setting : {
QIcon icon = FileUtils::getSettingIcon(path, true); QIcon icon = FileUtils::getSettingIcon(path, true);
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100)))); iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名 QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
nameLabel->setText(settingType); nameLabel->setText(settingType);
typeLabel->setText(FileUtils::getSettingName(path)); typeLabel->setText(FileUtils::getSettingName(path));
break; break;
} }
case SearchListView::ResType::Dir :
break;
default: default:
break; break;
} }
@ -174,6 +215,12 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
} }
case SearchListView::ResType::Setting: { case SearchListView::ResType::Setting: {
//打开控制面板对应页面 //打开控制面板对应页面
QProcess * process = new QProcess;
process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower()));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
return true;
break; break;
} }
default: default:
@ -231,7 +278,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) {
*/ */
bool SearchDetailView::openPathAction(const QString& path) { bool SearchDetailView::openPathAction(const QString& path) {
QProcess * process = new QProcess; QProcess * process = new QProcess;
process->start(QString("xdg-open %1").arg(path.left(path.length() - path.lastIndexOf("/") + 1))); process->start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/"))));
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() { connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater(); process->deleteLater();
}); });

View File

@ -12,11 +12,11 @@ public:
~SearchDetailView(); ~SearchDetailView();
void setupWidget(const int&, const QString&); void setupWidget(const int&, const QString&);
void clearLayout();
private: private:
QVBoxLayout * m_layout = nullptr; QVBoxLayout * m_layout = nullptr;
void clearLayout();
bool openAction(const int&, const QString&); bool openAction(const int&, const QString&);
bool addDesktopShortcut(const QString&); bool addDesktopShortcut(const QString&);
bool addPanelShortcut(const QString&); bool addPanelShortcut(const QString&);

View File

@ -14,7 +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);
this->setFixedHeight(list.count() * 47 + 2); int rowHeight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1;
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;}");

View File

@ -21,7 +21,7 @@ public:
}; };
int getCurrentType(); int getCurrentType();
int getResType(const QString&); static int getResType(const QString&);
private: private:
SearchItemModel * m_model = nullptr; SearchItemModel * m_model = nullptr;

View File

@ -11,9 +11,9 @@ Document::~Document()
// if(m_document) // if(m_document)
// delete m_document; // delete m_document;
// if(m_index_text) // if(m_index_text)
// delete m_index_text; // delete m_index_text;
// if(m_unique_term) // if(m_unique_term)
// delete m_unique_term; // delete m_unique_term;
} }
void Document::setData(QString data) void Document::setData(QString data)

108
index/file-searcher.cpp Normal file
View File

@ -0,0 +1,108 @@
#include "file-searcher.h"
#include <QFileInfo>
#include <QDebug>
FileSearcher::FileSearcher(QObject *parent) : QObject(parent)
{
}
void FileSearcher::onKeywordSearch(QString keyword, int begin, int num)
{
QVector<QStringList> searchResult;
try
{
qDebug()<<"--search start--";
Xapian::Database db(INDEX_PATH);
Xapian::Enquire enquire(db);
Xapian::QueryParser qp;
qp.set_default_op(Xapian::Query::OP_PHRASE);
qp.set_database(db);
auto userInput = keyword;
std::string queryStr = keyword.replace(""," ").toStdString();
// std::string s =db.get_spelling_suggestion(queryStr,10);
// qDebug()<<"spelling_suggestion!"<<QString::fromStdString(s);
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
//Creat a query
Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE);
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));
qDebug()<<userInput.at(i);
qDebug()<<QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
}
Xapian::Query queryNear =Xapian::Query(Xapian::Query::OP_NEAR, v.begin(), v.end());
Xapian::Query query = Xapian::Query(Xapian::Query::OP_AND,queryNear,queryPhrase);
//1- dir 2-file
unsigned slot = 1;
std::string value = "1";
Xapian::Query queryValue1 = Xapian::Query(Xapian::Query::OP_VALUE_GE,slot,value);
value = "0";
Xapian::Query queryValue0 = Xapian::Query(Xapian::Query::OP_VALUE_LE,1,value);
Xapian::Query queryDir = Xapian::Query(Xapian::Query::OP_AND,query,queryValue1);
Xapian::Query queryFile = Xapian::Query(Xapian::Query::OP_AND,query,queryValue0);
qDebug()<<QString::fromStdString(query.get_description());
enquire.set_query(queryDir);
//dir result
Xapian::MSet result = enquire.get_mset(begin, begin+num);
qDebug()<< "find dir results count=" <<static_cast<int>(result.get_matches_estimated());
searchResult.append(getResult(result));
enquire.set_query(queryFile);
//file result
result = enquire.get_mset(begin, begin+num);
qDebug()<< "find file results count=" <<static_cast<int>(result.get_matches_estimated());
searchResult.append(getResult(result));
qDebug()<< "--search finish--";
}
catch(const Xapian::Error &e)
{
qDebug() <<QString::fromStdString(e.get_description());
return;
}
Q_EMIT this->result(searchResult);
return;
}
QStringList FileSearcher::getResult(Xapian::MSet &result)
{
//QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist.
QStringList searchResult = QStringList();
if(result.size() == 0)
return searchResult;
for (auto it = result.begin(); it != result.end(); ++it)
{
Xapian::Document doc = it.get_document();
qDebug()<<"value!!!!"<<QString::fromStdString(doc.get_value(1));
std::string data = doc.get_data();
Xapian::weight docScoreWeight = it.get_weight();
Xapian::percent docScorePercent = it.get_percent();
QFileInfo *info = new QFileInfo(QString::fromStdString(data));
if(!info->exists())
{
// pathTobeDelete->append(QString::fromStdString(data));
qDebug()<<QString::fromStdString(data)<<"is not exist!!";
}
else
{
searchResult.append(QString::fromStdString(data));
}
qDebug()<< "doc="<< QString::fromStdString(data) << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
}
// if(!pathTobeDelete->isEmpty())
// deleteAllIndex(pathTobeDelete)
return searchResult;
}

26
index/file-searcher.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef FILESEARCHER_H
#define FILESEARCHER_H
#include <QObject>
#include <xapian.h>
#include <QStandardPaths>
#include <QVector>
#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/index_data").toStdString()
class FileSearcher : public QObject
{
Q_OBJECT
public:
explicit FileSearcher(QObject *parent = nullptr);
public Q_SLOTS:
void onKeywordSearch(QString keyword, int begin, int num);
Q_SIGNALS:
void result(QVector<QStringList> resultV);
private:
QStringList getResult(Xapian::MSet &result);
};
#endif // FILESEARCHER_H

View File

@ -77,24 +77,25 @@ IndexGenerator::~IndexGenerator()
void IndexGenerator::insertIntoDatabase(Document doc) void IndexGenerator::insertIntoDatabase(Document doc)
{ {
qDebug()<< "--index start--"; // qDebug()<< "--index start--";
Xapian::Document document = doc.getXapianDocument(); Xapian::Document document = doc.getXapianDocument();
m_indexer->set_document(document); m_indexer->set_document(document);
qDebug()<<doc.getIndexText(); // qDebug()<<doc.getIndexText();
for(auto i : doc.getIndexText()){ for(auto i : doc.getIndexText()){
m_indexer->index_text(i.toStdString()); m_indexer->index_text(i.toStdString());
} }
Xapian::docid innerId= m_datebase->replace_document(doc.getUniqueTerm(),document); Xapian::docid innerId= m_datebase->replace_document(doc.getUniqueTerm(),document);
qDebug()<<"replace doc docid="<<static_cast<int>(innerId); // qDebug()<<"replace doc docid="<<static_cast<int>(innerId);
qDebug()<< "--index finish--"; // qDebug()<< "--index finish--";
return; return;
} }
void IndexGenerator::HandlePathList(QList<QVector<QString>> *messageList) void IndexGenerator::HandlePathList(QList<QVector<QString>> *messageList)
{ {
qDebug()<<"Begin HandlePathList!"; qDebug()<<"Begin HandlePathList!";
qDebug()<<messageList->size();
// qDebug()<<QString::number(quintptr(QThread::currentThreadId())); // qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
QFuture<Document> future = QtConcurrent::mapped(*messageList,&IndexGenerator::GenerateDocument); QFuture<Document> future = QtConcurrent::mapped(*messageList,&IndexGenerator::GenerateDocument);
@ -133,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
doc.setData(sourcePath); doc.setData(sourcePath);
doc.setUniqueTerm(uniqueterm); doc.setUniqueTerm(uniqueterm);
doc.addValue(list.at(2)); doc.addValue(list.at(2));
if(list.at(2) == QString("1"))
qDebug()<<"value!!!"<<list.at(2);
doc.setIndexText(QStringList()<<index_text<<pinyin_text); doc.setIndexText(QStringList()<<index_text<<pinyin_text);
doc.setIndexText(QStringList()<<index_text); // doc.setIndexText(QStringList()<<index_text);
return doc; return doc;
} }
@ -168,7 +171,7 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr); qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
//Creat a query //Creat a query
Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE); Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE);
vector<Xapian::Query> v; std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++) for(int i=0;i<userInput.size();i++)
{ {
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString())); v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));
@ -227,7 +230,7 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
for(int i = 0;i<list->size();i++) for(int i = 0;i<list->size();i++)
{ {
QString doc = list->at(i); QString doc = list->at(i);
std::string uniqueterm = m_cryp->hash(doc.toUtf8(),QCryptographicHash::Md5).toStdString();; std::string uniqueterm = FileUtils::makeDocUterm(doc);
try try
{ {
qDebug()<<"--delete start--"; qDebug()<<"--delete start--";

View File

@ -11,7 +11,8 @@ HEADERS += \
$$PWD/messagelist-manager.h \ $$PWD/messagelist-manager.h \
$$PWD/traverse_bfs.h \ $$PWD/traverse_bfs.h \
$$PWD/messagelist-manager.h \ $$PWD/messagelist-manager.h \
$$PWD/text-content-indexer.h $$PWD/text-content-indexer.h \
$$PWD/file-searcher.h
SOURCES += \ SOURCES += \
# $$PWD/chinesecharacterstopinyin.cpp \ # $$PWD/chinesecharacterstopinyin.cpp \
@ -24,5 +25,6 @@ SOURCES += \
$$PWD/messagelist-manager.cpp \ $$PWD/messagelist-manager.cpp \
$$PWD/test-Inotify-Manager.cpp \ $$PWD/test-Inotify-Manager.cpp \
$$PWD/traverse_bfs.cpp \ $$PWD/traverse_bfs.cpp \
$$PWD/text-content-indexer.cpp $$PWD/text-content-indexer.cpp \
$$PWD/file-searcher.cpp

View File

@ -40,7 +40,9 @@ InotifyManagerRefact::~InotifyManagerRefact(){
} }
void InotifyManagerRefact::DoSomething(const QFileInfo& fileInfo){ void InotifyManagerRefact::DoSomething(const QFileInfo& fileInfo){
this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir())))); this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0"));
// if(QString(bool((fileInfo.isDir()))) == QString("1"))
// qDebug()<<"bool((fileInfo.isDir())"<<QString(fileInfo.isDir());
// this->mlm->AddMessage(QVector<QString>() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1"); // this->mlm->AddMessage(QVector<QString>() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1");
if(fileInfo.isDir()){ if(fileInfo.isDir()){
this->AddWatch(fileInfo.absoluteFilePath()); this->AddWatch(fileInfo.absoluteFilePath());

View File

@ -20,6 +20,7 @@ QIcon SearchItem::getIcon(int index) {
switch (m_searchtype) { switch (m_searchtype) {
case Settings : //设置项,返回控制面板对应插件的图标 case Settings : //设置项,返回控制面板对应插件的图标
return FileUtils::getSettingIcon(m_pathlist.at(index), false); return FileUtils::getSettingIcon(m_pathlist.at(index), false);
case Dirs :
case Files : //文件,返回文件图标 case Files : //文件,返回文件图标
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index))); return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
case Apps : //应用,返回应用图标 case Apps : //应用,返回应用图标
@ -42,6 +43,7 @@ QString SearchItem::getName(int index) {
switch (m_searchtype) { switch (m_searchtype) {
case Settings : //设置项,返回功能点名 case Settings : //设置项,返回功能点名
return FileUtils::getSettingName(m_pathlist.at(index)); return FileUtils::getSettingName(m_pathlist.at(index));
case Dirs :
case Files : //文件,返回文件名 case Files : //文件,返回文件名
return FileUtils::getFileName(m_pathlist.at(index)); return FileUtils::getFileName(m_pathlist.at(index));
case Apps : //应用,返回应用名 case Apps : //应用,返回应用名

View File

@ -5,7 +5,7 @@ SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
XmlElement(); XmlElement();
} }
QStringList SettingsMatch::matchstart(const QString &source){ QStringList SettingsMatch::startMatchApp(const QString &source){
m_sourceText=source; m_sourceText=source;
// qDebug()<<m_sourceText; // qDebug()<<m_sourceText;
QStringList settingList=matching(); QStringList settingList=matching();
@ -16,7 +16,7 @@ void SettingsMatch::XmlElement(){
QString pinyinIndex; QString pinyinIndex;
QString ChineseIndex; QString ChineseIndex;
QFile file(QString::fromLocal8Bit("::/res/search.xml")); QFile file(QString::fromLocal8Bit(":/res/search.xml"));
if (!file.open(QIODevice::ReadOnly)){ if (!file.open(QIODevice::ReadOnly)){
return; return;
} }

View File

@ -16,7 +16,7 @@ class SettingsMatch : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit SettingsMatch(QObject *parent = nullptr); explicit SettingsMatch(QObject *parent = nullptr);
QStringList matchstart(const QString &source); QStringList startMatchApp(const QString &source);
private: private:
void XmlElement(); void XmlElement();

View File

@ -25,6 +25,7 @@ ContentWidget::~ContentWidget()
void ContentWidget::initUI() { void ContentWidget::initUI() {
m_homePage = new QWidget; m_homePage = new QWidget;
m_homePageLyt = new QVBoxLayout(m_homePage); m_homePageLyt = new QVBoxLayout(m_homePage);
m_homePageLyt->setSpacing(0);
m_homePage->setLayout(m_homePageLyt); m_homePage->setLayout(m_homePageLyt);
m_resultPage = new QWidget; m_resultPage = new QWidget;
@ -56,20 +57,64 @@ void ContentWidget::initUI() {
m_detailView = new SearchDetailView(m_resultDetailArea); m_detailView = new SearchDetailView(m_resultDetailArea);
m_resultDetailArea->setWidget(m_detailView); m_resultDetailArea->setWidget(m_detailView);
m_resultDetailArea->setWidgetResizable(true); m_resultDetailArea->setWidgetResizable(true);
m_homePage->setStyleSheet("QWidget{background:pink;}");
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}"); m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}"); m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}");
this->addWidget(m_homePage); this->addWidget(m_homePage);
this->addWidget(m_resultPage); this->addWidget(m_resultPage);
setPageType(SearchItem::SearchType::All);//初始化按“全部”加载 setPage(SearchItem::SearchType::All);//初始化按“全部”加载
}
/**
* @brief ContentWidget::initHomePage homepage填充内容
* @param lists
*/
void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
for (int i = 0; i < lists.count(); i++) {
QWidget * listWidget = new QWidget(m_homePage);
QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget);
QLabel * titleLabel = new QLabel(listWidget);
QWidget * itemWidget = new QWidget(listWidget);
if (i == 1) {
titleLabel->setText(tr("Recently Opened"));
QGridLayout * layout = new QGridLayout(itemWidget);
layout->setSpacing(8);
layout->setContentsMargins(0, 0, 0, 0);
itemWidget->setLayout(layout);
for (int j = 0; j < lists.at(i).count(); j++) {
HomePageItem * item = new HomePageItem(itemWidget, i, lists.at(i).at(j));
layout->addWidget(item, j / 2, j % 2);
}
} else {
QHBoxLayout * layout = new QHBoxLayout(itemWidget);
layout->setSpacing(8);
layout->setContentsMargins(0, 0, 0, 0);
itemWidget->setLayout(layout);
Q_FOREACH(QString path, lists.at(i)){
HomePageItem * item = new HomePageItem(itemWidget, i, path);
layout->addWidget(item);
}
if (i) {
titleLabel->setText(tr("Open Quickly"));
QWidget * emptyItem = new QWidget(itemWidget);
emptyItem->setFixedSize(136, 136); //占位用widget,若后续快捷打开有扩展项可删除此widget
layout->addWidget(emptyItem);
}
else titleLabel->setText(tr("Commonly Used"));
}
itemWidgetLyt->setSpacing(6);
titleLabel->setFixedHeight(24);
itemWidgetLyt->addWidget(titleLabel);
itemWidgetLyt->addWidget(itemWidget);
m_homePageLyt->addWidget(listWidget);
}
} }
/** /**
* @brief setPageType * @brief setPageType
* @param type * @param type
*/ */
void ContentWidget::setPageType(const int& type){ void ContentWidget::setPage(const int& type){
m_currentType = type; m_currentType = type;
} }
@ -77,7 +122,7 @@ void ContentWidget::setPageType(const int& type){
* @brief ContentWidget::currentType home或searchresult * @brief ContentWidget::currentType home或searchresult
* @return * @return
*/ */
int ContentWidget::currentType() { int ContentWidget::currentPage() {
return m_currentType; return m_currentType;
} }
@ -90,7 +135,12 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
if (!m_listLyt->isEmpty()) { if (!m_listLyt->isEmpty()) {
clearSearchList(); clearSearchList();
} }
bool isEmpty = true;
for (int i = 0; i < types.count(); i ++) { for (int i = 0; i < types.count(); i ++) {
if (lists.at(i).isEmpty()) {
continue;
}
isEmpty = false;
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
QLabel * titleLabel = new QLabel(m_resultList); //表头 QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0); titleLabel->setContentsMargins(8, 0, 0, 0);
@ -108,6 +158,9 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
m_detailView->setupWidget(type, path); m_detailView->setupWidget(type, path);
}); });
} }
if (isEmpty) {
m_detailView->clearLayout(); //没有搜到结果,清空详情页
}
} }
/** /**
@ -123,6 +176,8 @@ QString ContentWidget::getTitleName(const int& type) {
return tr("Settings"); return tr("Settings");
case SearchItem::SearchType::Files : case SearchItem::SearchType::Files :
return tr("Files"); return tr("Files");
case SearchItem::SearchType::Dirs :
return tr("Dirs");
case SearchItem::SearchType::Best : case SearchItem::SearchType::Best :
return tr("Best Matches"); return tr("Best Matches");
default : default :

View File

@ -4,7 +4,9 @@
#include <QObject> #include <QObject>
#include <QStackedWidget> #include <QStackedWidget>
#include <QScrollArea> #include <QScrollArea>
#include <QGridLayout>
#include "control/search-detail-view.h" #include "control/search-detail-view.h"
#include "home-page-item.h"
class ContentWidget : public QStackedWidget class ContentWidget : public QStackedWidget
{ {
@ -13,9 +15,10 @@ public:
ContentWidget(QWidget *); ContentWidget(QWidget *);
~ContentWidget(); ~ContentWidget();
void setPageType(const int&); void setPage(const int&);
int currentType(); int currentPage();
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&); void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
void initHomePage(const QVector<QStringList>&);
private: private:
void initUI(); void initUI();
QWidget * m_homePage = nullptr; QWidget * m_homePage = nullptr;

View File

@ -1,4 +1,5 @@
#include "input-box.h" #include "input-box.h"
/** /**
* @brief ukui-search顶部搜索界面 * @brief ukui-search顶部搜索界面
*/ */
@ -62,12 +63,35 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
this->setAlignment(m_queryLineEdit,Qt::AlignCenter); this->setAlignment(m_queryLineEdit,Qt::AlignCenter);
this->addWidget(m_queryLineEdit); this->addWidget(m_queryLineEdit);
connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString))); // connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString)));
m_timer = new QTimer;
QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){
m_timer->stop();
Q_EMIT this->textChanged(m_queryLineEdit->text());
});
connect(m_queryLineEdit, &UKuiSearchLineEdit::textChanged, this, [ = ](QString text) {
if (m_isEmpty) {
m_isEmpty = false;
Q_EMIT this->textChanged(text);
} else {
if (text == "") {
m_isEmpty = true;
Q_EMIT this->textChanged(m_queryLineEdit->text());
m_timer->stop();
return;
}
m_timer->stop();
m_timer->start(0.2 * 1000);
}
});
} }
UkuiSearchBarHLayout::~UkuiSearchBarHLayout() UkuiSearchBarHLayout::~UkuiSearchBarHLayout()
{ {
if (m_timer) {
delete m_timer;
m_timer = NULL;
}
} }
/** /**

View File

@ -5,6 +5,7 @@
#include <QtDBus/QtDBus> #include <QtDBus/QtDBus>
#include <QPainter> #include <QPainter>
#include <QAction> #include <QAction>
#include <QTimer>
class UKuiSearchLineEdit; class UKuiSearchLineEdit;
@ -36,6 +37,8 @@ public:
void clearText(); void clearText();
private: private:
void initUI(); void initUI();
bool m_isEmpty = true;
QTimer * m_timer = nullptr;
UKuiSearchLineEdit *m_queryLineEdit=nullptr; UKuiSearchLineEdit *m_queryLineEdit=nullptr;

View File

@ -47,6 +47,14 @@ int main(int argc, char *argv[])
{ {
//load chinese character and pinyin file to a Map //load chinese character and pinyin file to a Map
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt"); 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<QStringList>>("QVector<QStringList>"); qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");

View File

@ -28,6 +28,8 @@
#include <QStyleOption> #include <QStyleOption>
#include <KWindowEffects> #include <KWindowEffects>
#include <QPixmap> #include <QPixmap>
#include "setting-match.h"
#include "app-match.h"
#include "kwindowsystem.h" #include "kwindowsystem.h"
#include "file-utils.h" #include "file-utils.h"
@ -35,6 +37,7 @@
//#include "inotify-manager.h" //#include "inotify-manager.h"
#include "inotify.h" #include "inotify.h"
#include "filetypefilter.h" #include "filetypefilter.h"
#include "file-searcher.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);
/** /**
@ -148,6 +151,24 @@ void MainWindow::initUi()
searchContent(text); searchContent(text);
} }
}); });
//初始化homepage
QVector<QStringList> lists;
//测试用数据
QStringList list;
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/ukui-clock.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<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"Theme/主题/更改壁纸";
lists.append(list);
lists.append(list2);
lists.append(list3);
//将搜索结果加入列表
m_contentFrame->initHomePage(lists);
} }
/** /**
@ -214,31 +235,56 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
* @param searchcontent * @param searchcontent
*/ */
void MainWindow::searchContent(QString searchcontent){ void MainWindow::searchContent(QString searchcontent){
QVector<int> types; // QVector<int> types;
QVector<QStringList> lists; // QVector<QStringList> lists;
m_lists.clear();
m_types.clear();
AppMatch * appMatchor = new AppMatch(this);
SettingsMatch * settingMatchor = new SettingsMatch(this);
//测试用数据 //测试用数据
QStringList list; QStringList list;
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; list = appMatchor->startMatchApp(searchcontent);
QStringList list2; // list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; // QStringList list2;
// list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
QStringList list3; QStringList list3;
list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题"; list3 = settingMatchor->startMatchApp(searchcontent);
types.append(SearchItem::SearchType::Apps); // list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
types.append(SearchItem::SearchType::Settings); m_types.append(SearchItem::SearchType::Apps);
types.append(SearchItem::SearchType::Files); m_types.append(SearchItem::SearchType::Settings);
// types.append(SearchItem::SearchType::Files);
lists.append(list); m_lists.append(list);
lists.append(list3); m_lists.append(list3);
lists.append(list2); // lists.append(list2);
// m_contentFrame->refreshSearchList(m_types, m_lists);
//文件搜索 //文件搜索
FileSearcher *searcher = new FileSearcher();
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);
});
searcher->onKeywordSearch(searchcontent,0,10);
// QStringList res = IndexGenerator::IndexSearch(searchcontent); // QStringList res = IndexGenerator::IndexSearch(searchcontent);
// types.append(SearchItem::SearchType::Files); // types.append(SearchItem::SearchType::Files);
// lists.append(res); // lists.append(res);
//将搜索结果加入列表 //将搜索结果加入列表
m_contentFrame->refreshSearchList(types, lists); // m_contentFrame->refreshSearchList(types, lists);
} }
//使用GSetting获取当前窗口应该使用的透明度 //使用GSetting获取当前窗口应该使用的透明度

View File

@ -73,6 +73,9 @@ private:
QGSettings * m_transparency_gsettings = nullptr; QGSettings * m_transparency_gsettings = nullptr;
double getTransparentData(); double getTransparentData();
QVector<int> m_types;
QVector<QStringList> m_lists;
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
void initUi(); void initUi();

View File

@ -22,6 +22,7 @@ include(control/control.pri)
include(appsearch/appsearch.pri) include(appsearch/appsearch.pri)
include(singleapplication/qt-single-application.pri) include(singleapplication/qt-single-application.pri)
include(settingsmatch/setting-match.pri) include(settingsmatch/setting-match.pri)
include(appmatch/app-match.pri)
LIBS = -lxapian -lgsettings-qt LIBS = -lxapian -lgsettings-qt
# Default rules for deployment. # Default rules for deployment.