Merge branch 'main' into zzh-search
This commit is contained in:
commit
a493cd716e
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/app-match.h \
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/app-match.cpp \
|
|
@ -4,8 +4,10 @@ HEADERS += \
|
|||
$$PWD/search-list-view.h \
|
||||
$$PWD/search-detail-view.h \
|
||||
$$PWD/option-view.h \
|
||||
$$PWD/home-page-item.h \
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/search-list-view.cpp \
|
||||
$$PWD/search-detail-view.cpp \
|
||||
$$PWD/option-view.cpp \
|
||||
$$PWD/home-page-item.cpp \
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -11,6 +11,8 @@
|
|||
#include <QProcess>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
|
||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -76,14 +78,54 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
hLine->setFixedHeight(1);
|
||||
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);
|
||||
connect(optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) {
|
||||
execActions(type, option, path);
|
||||
});
|
||||
|
||||
m_layout->addWidget(iconLabel);
|
||||
m_layout->addWidget(nameFrame);
|
||||
m_layout->addWidget(hLine);
|
||||
m_layout->addWidget(optionView);
|
||||
m_layout->addStretch();
|
||||
|
||||
|
@ -96,23 +138,22 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
typeLabel->setText(tr("Application"));
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir :
|
||||
case SearchListView::ResType::File : {
|
||||
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));
|
||||
typeLabel->setText(tr("Document"));
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Setting : {
|
||||
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); //配置项所属控制面板插件名
|
||||
nameLabel->setText(settingType);
|
||||
typeLabel->setText(FileUtils::getSettingName(path));
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir :
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -174,6 +215,12 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
default:
|
||||
|
@ -231,7 +278,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) {
|
|||
*/
|
||||
bool SearchDetailView::openPathAction(const QString& path) {
|
||||
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, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
|
|
|
@ -12,11 +12,11 @@ public:
|
|||
~SearchDetailView();
|
||||
|
||||
void setupWidget(const int&, const QString&);
|
||||
void clearLayout();
|
||||
|
||||
private:
|
||||
QVBoxLayout * m_layout = nullptr;
|
||||
|
||||
void clearLayout();
|
||||
bool openAction(const int&, const QString&);
|
||||
bool addDesktopShortcut(const QString&);
|
||||
bool addPanelShortcut(const QString&);
|
||||
|
|
|
@ -14,7 +14,8 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
|
|||
this->setHeaderHidden(true);
|
||||
this->setColumnWidth(0, 20);
|
||||
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->setAutoFillBackground(false);
|
||||
this->setStyleSheet("QWidget{background:transparent;}");
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
};
|
||||
|
||||
int getCurrentType();
|
||||
int getResType(const QString&);
|
||||
static int getResType(const QString&);
|
||||
|
||||
private:
|
||||
SearchItemModel * m_model = nullptr;
|
||||
|
|
|
@ -11,9 +11,9 @@ Document::~Document()
|
|||
// if(m_document)
|
||||
// delete m_document;
|
||||
// if(m_index_text)
|
||||
// delete m_index_text;
|
||||
// delete m_index_text;
|
||||
// if(m_unique_term)
|
||||
// delete m_unique_term;
|
||||
// delete m_unique_term;
|
||||
}
|
||||
|
||||
void Document::setData(QString data)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -77,24 +77,25 @@ IndexGenerator::~IndexGenerator()
|
|||
|
||||
void IndexGenerator::insertIntoDatabase(Document doc)
|
||||
{
|
||||
qDebug()<< "--index start--";
|
||||
// qDebug()<< "--index start--";
|
||||
Xapian::Document document = doc.getXapianDocument();
|
||||
m_indexer->set_document(document);
|
||||
qDebug()<<doc.getIndexText();
|
||||
// qDebug()<<doc.getIndexText();
|
||||
|
||||
for(auto i : doc.getIndexText()){
|
||||
m_indexer->index_text(i.toStdString());
|
||||
}
|
||||
|
||||
Xapian::docid innerId= m_datebase->replace_document(doc.getUniqueTerm(),document);
|
||||
qDebug()<<"replace doc docid="<<static_cast<int>(innerId);
|
||||
qDebug()<< "--index finish--";
|
||||
// qDebug()<<"replace doc docid="<<static_cast<int>(innerId);
|
||||
// qDebug()<< "--index finish--";
|
||||
return;
|
||||
}
|
||||
|
||||
void IndexGenerator::HandlePathList(QList<QVector<QString>> *messageList)
|
||||
{
|
||||
qDebug()<<"Begin HandlePathList!";
|
||||
qDebug()<<messageList->size();
|
||||
// qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
|
||||
QFuture<Document> future = QtConcurrent::mapped(*messageList,&IndexGenerator::GenerateDocument);
|
||||
|
||||
|
@ -133,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
|
|||
doc.setData(sourcePath);
|
||||
doc.setUniqueTerm(uniqueterm);
|
||||
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);
|
||||
// doc.setIndexText(QStringList()<<index_text);
|
||||
return doc;
|
||||
|
||||
}
|
||||
|
@ -168,7 +171,7 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
|
|||
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
|
||||
//Creat a query
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
QString doc = list->at(i);
|
||||
std::string uniqueterm = m_cryp->hash(doc.toUtf8(),QCryptographicHash::Md5).toStdString();;
|
||||
std::string uniqueterm = FileUtils::makeDocUterm(doc);
|
||||
try
|
||||
{
|
||||
qDebug()<<"--delete start--";
|
||||
|
|
|
@ -11,7 +11,8 @@ HEADERS += \
|
|||
$$PWD/messagelist-manager.h \
|
||||
$$PWD/traverse_bfs.h \
|
||||
$$PWD/messagelist-manager.h \
|
||||
$$PWD/text-content-indexer.h
|
||||
$$PWD/text-content-indexer.h \
|
||||
$$PWD/file-searcher.h
|
||||
|
||||
SOURCES += \
|
||||
# $$PWD/chinesecharacterstopinyin.cpp \
|
||||
|
@ -24,5 +25,6 @@ SOURCES += \
|
|||
$$PWD/messagelist-manager.cpp \
|
||||
$$PWD/test-Inotify-Manager.cpp \
|
||||
$$PWD/traverse_bfs.cpp \
|
||||
$$PWD/text-content-indexer.cpp
|
||||
$$PWD/text-content-indexer.cpp \
|
||||
$$PWD/file-searcher.cpp
|
||||
|
||||
|
|
|
@ -40,7 +40,9 @@ InotifyManagerRefact::~InotifyManagerRefact(){
|
|||
}
|
||||
|
||||
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");
|
||||
if(fileInfo.isDir()){
|
||||
this->AddWatch(fileInfo.absoluteFilePath());
|
||||
|
|
|
@ -20,6 +20,7 @@ QIcon SearchItem::getIcon(int index) {
|
|||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回控制面板对应插件的图标
|
||||
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
||||
case Dirs :
|
||||
case Files : //文件,返回文件图标
|
||||
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||
case Apps : //应用,返回应用图标
|
||||
|
@ -42,6 +43,7 @@ QString SearchItem::getName(int index) {
|
|||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回功能点名
|
||||
return FileUtils::getSettingName(m_pathlist.at(index));
|
||||
case Dirs :
|
||||
case Files : //文件,返回文件名
|
||||
return FileUtils::getFileName(m_pathlist.at(index));
|
||||
case Apps : //应用,返回应用名
|
||||
|
|
|
@ -5,7 +5,7 @@ SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
|
|||
XmlElement();
|
||||
}
|
||||
|
||||
QStringList SettingsMatch::matchstart(const QString &source){
|
||||
QStringList SettingsMatch::startMatchApp(const QString &source){
|
||||
m_sourceText=source;
|
||||
// qDebug()<<m_sourceText;
|
||||
QStringList settingList=matching();
|
||||
|
@ -16,7 +16,7 @@ void SettingsMatch::XmlElement(){
|
|||
QString pinyinIndex;
|
||||
QString ChineseIndex;
|
||||
|
||||
QFile file(QString::fromLocal8Bit("::/res/search.xml"));
|
||||
QFile file(QString::fromLocal8Bit(":/res/search.xml"));
|
||||
if (!file.open(QIODevice::ReadOnly)){
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class SettingsMatch : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsMatch(QObject *parent = nullptr);
|
||||
QStringList matchstart(const QString &source);
|
||||
QStringList startMatchApp(const QString &source);
|
||||
|
||||
private:
|
||||
void XmlElement();
|
||||
|
|
|
@ -25,6 +25,7 @@ ContentWidget::~ContentWidget()
|
|||
void ContentWidget::initUI() {
|
||||
m_homePage = new QWidget;
|
||||
m_homePageLyt = new QVBoxLayout(m_homePage);
|
||||
m_homePageLyt->setSpacing(0);
|
||||
m_homePage->setLayout(m_homePageLyt);
|
||||
|
||||
m_resultPage = new QWidget;
|
||||
|
@ -56,20 +57,64 @@ void ContentWidget::initUI() {
|
|||
m_detailView = new SearchDetailView(m_resultDetailArea);
|
||||
m_resultDetailArea->setWidget(m_detailView);
|
||||
m_resultDetailArea->setWidgetResizable(true);
|
||||
m_homePage->setStyleSheet("QWidget{background:pink;}");
|
||||
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
||||
m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}");
|
||||
this->addWidget(m_homePage);
|
||||
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 预留的接口,为指定类别搜索调整界面内容
|
||||
* @param type
|
||||
*/
|
||||
void ContentWidget::setPageType(const int& type){
|
||||
void ContentWidget::setPage(const int& type){
|
||||
m_currentType = type;
|
||||
}
|
||||
|
||||
|
@ -77,7 +122,7 @@ void ContentWidget::setPageType(const int& type){
|
|||
* @brief ContentWidget::currentType 返回当前内容页(home或searchresult)
|
||||
* @return
|
||||
*/
|
||||
int ContentWidget::currentType() {
|
||||
int ContentWidget::currentPage() {
|
||||
return m_currentType;
|
||||
}
|
||||
|
||||
|
@ -90,7 +135,12 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
|||
if (!m_listLyt->isEmpty()) {
|
||||
clearSearchList();
|
||||
}
|
||||
bool isEmpty = true;
|
||||
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
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
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);
|
||||
});
|
||||
}
|
||||
if (isEmpty) {
|
||||
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,6 +176,8 @@ QString ContentWidget::getTitleName(const int& type) {
|
|||
return tr("Settings");
|
||||
case SearchItem::SearchType::Files :
|
||||
return tr("Files");
|
||||
case SearchItem::SearchType::Dirs :
|
||||
return tr("Dirs");
|
||||
case SearchItem::SearchType::Best :
|
||||
return tr("Best Matches");
|
||||
default :
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#include <QObject>
|
||||
#include <QStackedWidget>
|
||||
#include <QScrollArea>
|
||||
#include <QGridLayout>
|
||||
#include "control/search-detail-view.h"
|
||||
#include "home-page-item.h"
|
||||
|
||||
class ContentWidget : public QStackedWidget
|
||||
{
|
||||
|
@ -13,9 +15,10 @@ public:
|
|||
ContentWidget(QWidget *);
|
||||
~ContentWidget();
|
||||
|
||||
void setPageType(const int&);
|
||||
int currentType();
|
||||
void setPage(const int&);
|
||||
int currentPage();
|
||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
||||
void initHomePage(const QVector<QStringList>&);
|
||||
private:
|
||||
void initUI();
|
||||
QWidget * m_homePage = nullptr;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "input-box.h"
|
||||
|
||||
/**
|
||||
* @brief ukui-search顶部搜索界面
|
||||
*/
|
||||
|
@ -62,12 +63,35 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
|||
this->setAlignment(m_queryLineEdit,Qt::AlignCenter);
|
||||
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()
|
||||
{
|
||||
|
||||
if (m_timer) {
|
||||
delete m_timer;
|
||||
m_timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QtDBus/QtDBus>
|
||||
#include <QPainter>
|
||||
#include <QAction>
|
||||
#include <QTimer>
|
||||
|
||||
class UKuiSearchLineEdit;
|
||||
|
||||
|
@ -36,6 +37,8 @@ public:
|
|||
void clearText();
|
||||
private:
|
||||
void initUI();
|
||||
bool m_isEmpty = true;
|
||||
QTimer * m_timer = nullptr;
|
||||
|
||||
UKuiSearchLineEdit *m_queryLineEdit=nullptr;
|
||||
|
||||
|
|
|
@ -47,6 +47,14 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
//load chinese character and pinyin file to a Map
|
||||
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>");
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <QStyleOption>
|
||||
#include <KWindowEffects>
|
||||
#include <QPixmap>
|
||||
#include "setting-match.h"
|
||||
#include "app-match.h"
|
||||
#include "kwindowsystem.h"
|
||||
|
||||
#include "file-utils.h"
|
||||
|
@ -35,6 +37,7 @@
|
|||
//#include "inotify-manager.h"
|
||||
#include "inotify.h"
|
||||
#include "filetypefilter.h"
|
||||
#include "file-searcher.h"
|
||||
|
||||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||
/**
|
||||
|
@ -148,6 +151,24 @@ void MainWindow::initUi()
|
|||
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
|
||||
*/
|
||||
void MainWindow::searchContent(QString searchcontent){
|
||||
QVector<int> types;
|
||||
QVector<QStringList> lists;
|
||||
// QVector<int> types;
|
||||
// QVector<QStringList> lists;
|
||||
m_lists.clear();
|
||||
m_types.clear();
|
||||
|
||||
AppMatch * appMatchor = new AppMatch(this);
|
||||
SettingsMatch * settingMatchor = new SettingsMatch(this);
|
||||
|
||||
//测试用数据
|
||||
QStringList list;
|
||||
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
|
||||
QStringList list2;
|
||||
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
||||
list = appMatchor->startMatchApp(searchcontent);
|
||||
// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
|
||||
// QStringList list2;
|
||||
// list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
||||
QStringList list3;
|
||||
list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||
types.append(SearchItem::SearchType::Apps);
|
||||
types.append(SearchItem::SearchType::Settings);
|
||||
types.append(SearchItem::SearchType::Files);
|
||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
||||
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||
m_types.append(SearchItem::SearchType::Apps);
|
||||
m_types.append(SearchItem::SearchType::Settings);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
|
||||
lists.append(list);
|
||||
lists.append(list3);
|
||||
lists.append(list2);
|
||||
m_lists.append(list);
|
||||
m_lists.append(list3);
|
||||
// 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);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
// lists.append(res);
|
||||
|
||||
//将搜索结果加入列表
|
||||
m_contentFrame->refreshSearchList(types, lists);
|
||||
// m_contentFrame->refreshSearchList(types, lists);
|
||||
}
|
||||
|
||||
//使用GSetting获取当前窗口应该使用的透明度
|
||||
|
|
|
@ -73,6 +73,9 @@ private:
|
|||
QGSettings * m_transparency_gsettings = nullptr;
|
||||
double getTransparentData();
|
||||
|
||||
QVector<int> m_types;
|
||||
QVector<QStringList> m_lists;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void initUi();
|
||||
|
|
|
@ -22,6 +22,7 @@ include(control/control.pri)
|
|||
include(appsearch/appsearch.pri)
|
||||
include(singleapplication/qt-single-application.pri)
|
||||
include(settingsmatch/setting-match.pri)
|
||||
include(appmatch/app-match.pri)
|
||||
|
||||
LIBS = -lxapian -lgsettings-qt
|
||||
# Default rules for deployment.
|
||||
|
|
Loading…
Reference in New Issue