diff --git a/appmatch/app-match.cpp b/appmatch/app-match.cpp new file mode 100644 index 0000000..6d74103 --- /dev/null +++ b/appmatch/app-match.cpp @@ -0,0 +1,200 @@ +#include "app-match.h" +#include +#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 +#include +#include +#include +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 diff --git a/appmatch/app-match.pri b/appmatch/app-match.pri new file mode 100644 index 0000000..4a3d55d --- /dev/null +++ b/appmatch/app-match.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/app-match.h \ + +SOURCES += \ + $$PWD/app-match.cpp \ diff --git a/control/control.pri b/control/control.pri index 016e0c7..5f7bb1a 100644 --- a/control/control.pri +++ b/control/control.pri @@ -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 \ diff --git a/control/home-page-item.cpp b/control/home-page-item.cpp new file mode 100644 index 0000000..ad18b3e --- /dev/null +++ b/control/home-page-item.cpp @@ -0,0 +1,128 @@ +#include "home-page-item.h" +#include +#include +#include +#include + +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(&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(&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); +} diff --git a/control/home-page-item.h b/control/home-page-item.h new file mode 100644 index 0000000..7f0d3e7 --- /dev/null +++ b/control/home-page-item.h @@ -0,0 +1,40 @@ +#ifndef HOMEPAGEITEM_H +#define HOMEPAGEITEM_H + +#include +#include +#include +#include +#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 diff --git a/control/search-detail-view.cpp b/control/search-detail-view.cpp index de3cf8c..d1361d3 100644 --- a/control/search-detail-view.cpp +++ b/control/search-detail-view.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include 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(&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(&QProcess::finished), this, [ = ]() { process->deleteLater(); }); diff --git a/control/search-detail-view.h b/control/search-detail-view.h index 8a10d70..5038aab 100644 --- a/control/search-detail-view.h +++ b/control/search-detail-view.h @@ -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&); diff --git a/control/search-list-view.cpp b/control/search-list-view.cpp index b48aa52..b213efa 100644 --- a/control/search-list-view.cpp +++ b/control/search-list-view.cpp @@ -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;}"); diff --git a/control/search-list-view.h b/control/search-list-view.h index 43e44f5..665ef48 100644 --- a/control/search-list-view.h +++ b/control/search-list-view.h @@ -21,7 +21,7 @@ public: }; int getCurrentType(); - int getResType(const QString&); + static int getResType(const QString&); private: SearchItemModel * m_model = nullptr; diff --git a/index/document.cpp b/index/document.cpp index f6ea7aa..70d991b 100644 --- a/index/document.cpp +++ b/index/document.cpp @@ -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) diff --git a/index/file-searcher.cpp b/index/file-searcher.cpp new file mode 100644 index 0000000..1579fa3 --- /dev/null +++ b/index/file-searcher.cpp @@ -0,0 +1,108 @@ +#include "file-searcher.h" +#include +#include + +FileSearcher::FileSearcher(QObject *parent) : QObject(parent) +{ + +} + +void FileSearcher::onKeywordSearch(QString keyword, int begin, int num) +{ + QVector 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!"< v; + for(int i=0;iresult(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!!!!"<exists()) + { +// pathTobeDelete->append(QString::fromStdString(data)); + qDebug()< resultV); +private: + QStringList getResult(Xapian::MSet &result); +}; + +#endif // FILESEARCHER_H diff --git a/index/index-generator.cpp b/index/index-generator.cpp index d886cf8..d30fea9 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -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()<index_text(i.toStdString()); } Xapian::docid innerId= m_datebase->replace_document(doc.getUniqueTerm(),document); - qDebug()<<"replace doc docid="<(innerId); - qDebug()<< "--index finish--"; +// qDebug()<<"replace doc docid="<(innerId); +// qDebug()<< "--index finish--"; return; } void IndexGenerator::HandlePathList(QList> *messageList) { qDebug()<<"Begin HandlePathList!"; + qDebug()<size(); // qDebug()< future = QtConcurrent::mapped(*messageList,&IndexGenerator::GenerateDocument); @@ -133,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector &list) doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addValue(list.at(2)); + if(list.at(2) == QString("1")) + qDebug()<<"value!!!"< v; + std::vector v; for(int i=0;isize();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--"; diff --git a/index/index.pri b/index/index.pri index 3018a0f..96b2aba 100644 --- a/index/index.pri +++ b/index/index.pri @@ -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 diff --git a/index/inotify.cpp b/index/inotify.cpp index 7909539..f6e7b2d 100644 --- a/index/inotify.cpp +++ b/index/inotify.cpp @@ -40,7 +40,9 @@ InotifyManagerRefact::~InotifyManagerRefact(){ } void InotifyManagerRefact::DoSomething(const QFileInfo& fileInfo){ - this->mlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir())))); + this->mlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0")); +// if(QString(bool((fileInfo.isDir()))) == QString("1")) +// qDebug()<<"bool((fileInfo.isDir())"<mlm->AddMessage(QVector() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1"); if(fileInfo.isDir()){ this->AddWatch(fileInfo.absoluteFilePath()); diff --git a/model/search-item.cpp b/model/search-item.cpp index d16979a..c4dcb5b 100644 --- a/model/search-item.cpp +++ b/model/search-item.cpp @@ -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 : //应用,返回应用名 diff --git a/settingsmatch/setting-match.cpp b/settingsmatch/setting-match.cpp index 103c0ff..0447e9d 100644 --- a/settingsmatch/setting-match.cpp +++ b/settingsmatch/setting-match.cpp @@ -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()<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& 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& types, const QVectorisEmpty()) { 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& types, const QVectorsetupWidget(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 : diff --git a/src/content-widget.h b/src/content-widget.h index 90a8abd..1edb645 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -4,7 +4,9 @@ #include #include #include +#include #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&, const QVector&); + void initHomePage(const QVector&); private: void initUI(); QWidget * m_homePage = nullptr; diff --git a/src/input-box.cpp b/src/input-box.cpp index 7c2273b..7f4bed5 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -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; + } } /** diff --git a/src/input-box.h b/src/input-box.h index ea0a2e4..ab9872c 100644 --- a/src/input-box.h +++ b/src/input-box.h @@ -5,6 +5,7 @@ #include #include #include +#include class UKuiSearchLineEdit; @@ -36,6 +37,8 @@ public: void clearText(); private: void initUI(); + bool m_isEmpty = true; + QTimer * m_timer = nullptr; UKuiSearchLineEdit *m_queryLineEdit=nullptr; diff --git a/src/main.cpp b/src/main.cpp index d3230fe..cb8a9e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fae78a0..37f1211 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -28,6 +28,8 @@ #include #include #include +#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 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 types; - QVector lists; +// QVector types; +// QVector 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 resultV){ + + QStringList list1 = resultV.at(0); + QStringList list2 = resultV.at(1); + +// QVector lists; + m_lists.append(list1); + m_lists.append(list2); +// QVector 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获取当前窗口应该使用的透明度 diff --git a/src/mainwindow.h b/src/mainwindow.h index 6da0c53..37edb5a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -73,6 +73,9 @@ private: QGSettings * m_transparency_gsettings = nullptr; double getTransparentData(); + QVector m_types; + QVector m_lists; + protected: void paintEvent(QPaintEvent *); void initUi(); diff --git a/ukui-search.pro b/ukui-search.pro index 72142d6..190b9ed 100644 --- a/ukui-search.pro +++ b/ukui-search.pro @@ -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.