diff --git a/README.md b/README.md index c00ecf2..d375118 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,17 @@ # ukui-search -[WIP] UKUI Search is a user-wide desktop search feature of UKUI desktop environment. +[dWIP] UKUI Search is a user-wide desktop search feature of UKUI desktop environment. + +Build from source + + + git clone https://github.com/ukui/ukui-search.git + + cd ukui-search && mkdir build && cd build + + qmake .. && make + + sudo make install + + /usr/bin/ukui-search diff --git a/data/ukui-search-menu.desktop b/data/ukui-search-menu.desktop index 07b5690..085b75c 100644 --- a/data/ukui-search-menu.desktop +++ b/data/ukui-search-menu.desktop @@ -9,6 +9,7 @@ Exec=/usr/bin/ukui-search -s Type=Application Icon=kylin-search X-UKUI-AutoRestart=true +NoDisplay=true OnlyShowIn=UKUI X-UKUI-Autostart-Phase=Application Terminal=false diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 8b0e317..03a8977 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -138,6 +138,7 @@ QString escapeHtml(const QString & str) { void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginIface::ResultInfo &info) { + clearLayout(m_descFrameLyt); m_iconLabel->setPixmap(info.icon.pixmap(info.icon.actualSize(ICON_SIZE))); m_iconLabel->show(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); @@ -147,6 +148,7 @@ void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginI m_pluginLabel->setText(plugin_name); m_nameFrame->show(); m_line_1->show(); + if (info.description.length() > 0) { //NEW_TODO 样式待优化 clearLayout(m_descFrameLyt); @@ -154,7 +156,7 @@ void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginI QLabel * descLabel = new QLabel(m_descFrame); descLabel->setTextFormat(Qt::PlainText); descLabel->setWordWrap(true); - QString show_desc = desc.key + ": " + desc.value; + QString show_desc = desc.key + " " + desc.value; descLabel->setText(show_desc); m_descFrameLyt->addWidget(descLabel); } @@ -162,10 +164,10 @@ void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginI m_line_2->show(); } clearLayout(m_actionFrameLyt); -// Q_FOREACH (auto action, info.actionList) { -// ActionLabel * actionLabel = new ActionLabel(action, info.key, plugin_name, m_actionFrame); -// m_actionFrameLyt->addWidget(actionLabel); -// } + Q_FOREACH (SearchPluginIface::Actioninfo actioninfo, SearchPluginManager::getInstance()->getPlugin(plugin_name)->getActioninfo(info.type)) { + ActionLabel * actionLabel = new ActionLabel(actioninfo.displayName, info.actionKey, actioninfo.actionkey, plugin_name, info.type, m_actionFrame); + m_actionFrameLyt->addWidget(actionLabel); + } m_actionFrame->show(); } @@ -248,7 +250,7 @@ void DetailWidget::paintEvent(QPaintEvent * event) void DetailWidget::clearLayout(QLayout *layout) { - if(! layout) return; + if(!layout) return; QLayoutItem * child; while((child = layout->takeAt(0)) != 0) { if(child->widget()) { @@ -259,11 +261,13 @@ void DetailWidget::clearLayout(QLayout *layout) child = NULL; } -ActionLabel::ActionLabel(const QString &action, const QString &key, const QString &plugin, QWidget *parent) : QLabel(parent) +ActionLabel::ActionLabel(const QString &action, const QString &key, const int &ActionKey, const QString &pluginId, const int type, QWidget *parent) : QLabel(parent) { m_action = action; m_key = key; - m_plugin = plugin; + m_actionKey = ActionKey; + m_type = type; + m_pluginId = pluginId; this->initUi(); this->installEventFilter(this); } @@ -287,10 +291,10 @@ bool ActionLabel::eventFilter(QObject *watched, QEvent *event) this->setForegroundRole(QPalette::Dark); return true; } else if(event->type() == QEvent::MouseButtonRelease) { - SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin); -// if (plugin) -// plugin->openAction(m_action, m_key); -// else + SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_pluginId); + if (plugin) + plugin->openAction(m_actionKey, m_key, m_type); + else qWarning()<<"Get plugin failed!"; this->setForegroundRole(QPalette::Light); return true; diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 86016fa..02fc13a 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -25,7 +25,7 @@ #include #include #include "result-view.h" -#include "plugininterface/search-plugin-iface.h" +#include "search-plugin-iface.h" namespace Zeeker { class ResultArea : public QScrollArea @@ -100,13 +100,15 @@ class ActionLabel : public QLabel { Q_OBJECT public: - ActionLabel(const QString &action, const QString &key, const QString &plugin, QWidget *parent = nullptr); + ActionLabel(const QString &action, const QString &key, const int &ActionKey, const QString &pluginId, const int type = 0, QWidget *parent = nullptr); ~ActionLabel() = default; private: void initUi(); QString m_action; QString m_key; - QString m_plugin; + int m_actionKey; + int m_type = 0; + QString m_pluginId; protected: bool eventFilter(QObject *, QEvent *); diff --git a/frontend/control/stack-pages/search-page.cpp b/frontend/control/stack-pages/search-page.cpp index 5542b74..9d39956 100644 --- a/frontend/control/stack-pages/search-page.cpp +++ b/frontend/control/stack-pages/search-page.cpp @@ -21,7 +21,7 @@ #include "search-page.h" using namespace Zeeker; -#define RESULT_WIDTH 240 +#define RESULT_WIDTH 298 #define DETAIL_WIDTH 400 SearchPage::SearchPage(QWidget *parent) : QWidget(parent) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 49f34d4..2350a0d 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -42,12 +42,12 @@ #define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings" #define SEARCH_METHOD_KEY "indexSearch" #define WEB_ENGINE_KEY "webEngine" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 590 +#define WINDOW_WIDTH 680 +#define WINDOW_HEIGHT 600 #define TITLE_HEIGHT 40 #define WINDOW_ICON_SIZE 24 #define SETTING_BTN_SIZE 30 -#define SEARCH_BAR_SIZE 44 +#define SEARCH_BAR_SIZE 48 #define ASK_INDEX_TIME 5*1000 #define RESEARCH_TIME 10*1000 diff --git a/frontend/view/result-view-delegate.cpp b/frontend/view/result-view-delegate.cpp index 814e53b..908c28a 100644 --- a/frontend/view/result-view-delegate.cpp +++ b/frontend/view/result-view-delegate.cpp @@ -12,6 +12,13 @@ void ResultViewDelegate::setSearchKeyword(const QString ®FindKeyWords) m_regFindKeyWords = regFindKeyWords; } +QSize ResultViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QSize size = QStyledItemDelegate::sizeHint(option,index); + size.setHeight(size.height() + 10); + return size; +} + void ResultViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QStyleOptionViewItemV4 optionV4 = option; initStyleOption(&optionV4, index); @@ -30,7 +37,7 @@ void ResultViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4); - textRect.adjust(0, -5, 0, 0); + textRect.adjust(0, 0, 0, 0); painter->save(); painter->translate(textRect.topLeft()); painter->setClipRect(textRect.translated(-textRect.topLeft())); diff --git a/frontend/view/result-view-delegate.h b/frontend/view/result-view-delegate.h index 7e885a4..7dcd1af 100644 --- a/frontend/view/result-view-delegate.h +++ b/frontend/view/result-view-delegate.h @@ -35,6 +35,8 @@ public: explicit ResultViewDelegate(QObject *parent = nullptr); ~ResultViewDelegate() = default; void setSearchKeyword(const QString &); +protected: + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; private: QString m_regFindKeyWords = 0; void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override; diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 254ea43..4d1cf6d 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -104,11 +104,11 @@ bool AppSearchPlugin::addPanelShortcut(const QString& path) { if(iface.isValid()) { QDBusReply isExist = iface.call("CheckIfExist", path); if(isExist) { - qWarning() << "qDebug: Add shortcut to panel failed, because it is already existed!"; + qWarning() << "Add shortcut to panel failed, because it is already existed!"; return false; } QDBusReply ret = iface.call("AddToTaskbar", path); - qDebug() << "qDebug: Add shortcut to panel successed!"; + qDebug() << "Add shortcut to panel successed!"; return true; } return false; diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index fb3ef49..15f6429 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -97,19 +97,6 @@ void FirstIndex::run() { QTime t1 = QTime::currentTime(); // Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running. - QDir fifoDir = QDir(QDir::homePath() + "/.config/org.ukui/ukui-search"); - if(!fifoDir.exists()) - qDebug() << "create fifo path" << fifoDir.mkpath(fifoDir.absolutePath()); - - unlink(UKUI_SEARCH_PIPE_PATH); - int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777); - if(retval == -1) { - qCritical() << "creat fifo error!!"; - syslog(LOG_ERR, "creat fifo error!!\n"); - assert(false); - return; - } - qDebug() << "create fifo success\n"; QString indexDataBaseStatus = IndexStatusRecorder::getInstance()->getStatus(INDEX_DATABASE_STATE).toString(); QString contentIndexDataBaseStatus = IndexStatusRecorder::getInstance()->getStatus(CONTENT_INDEX_DATABASE_STATE).toString(); diff --git a/libsearch/index/searchmethodmanager.cpp b/libsearch/index/searchmethodmanager.cpp index dc073cb..bfdc7ee 100644 --- a/libsearch/index/searchmethodmanager.cpp +++ b/libsearch/index/searchmethodmanager.cpp @@ -13,6 +13,21 @@ void SearchMethodManager::searchMethod(FileUtils::SearchMethod sm) { qWarning("enum class error!!!\n"); } if(FileUtils::SearchMethod::INDEXSEARCH == sm && 0 == FileUtils::_index_status) { + + // Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running. + QDir fifoDir = QDir(QDir::homePath() + "/.config/org.ukui/ukui-search"); + if(!fifoDir.exists()) + qDebug() << "create fifo path" << fifoDir.mkpath(fifoDir.absolutePath()); + + unlink(UKUI_SEARCH_PIPE_PATH); + int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777); + if(retval == -1) { + qCritical() << "creat fifo error!!"; + syslog(LOG_ERR, "creat fifo error!!\n"); + assert(false); + return; + } + qDebug() << "create fifo success\n"; qWarning() << "start first index"; m_fi.start(); qWarning() << "start inotify index"; diff --git a/libsearch/plugininterface/plugin-interface.pri b/libsearch/plugininterface/plugin-interface.pri index 592db4d..3885713 100644 --- a/libsearch/plugininterface/plugin-interface.pri +++ b/libsearch/plugininterface/plugin-interface.pri @@ -2,6 +2,9 @@ INCLUDEPATH += $$PWD \ HEADERS += \ $$PWD/plugin-iface.h \ + $$PWD/preview-page-plugin-iface.h \ $$PWD/search-plugin-iface.h \ $$PWD/data-queue.h +SOURCES += + diff --git a/libsearch/plugininterface/preview-page-plugin-iface.h b/libsearch/plugininterface/preview-page-plugin-iface.h new file mode 100644 index 0000000..869f6a2 --- /dev/null +++ b/libsearch/plugininterface/preview-page-plugin-iface.h @@ -0,0 +1,47 @@ +#ifndef PREVIEWPAGEPLUGINIFACE_H +#define PREVIEWPAGEPLUGINIFACE_H +#include +#include +#include +#include "plugin-iface.h" + +#define PreviewPagePluginIface_iid "org.ukui.ukui-search.plugin-iface.PreviewPagePluginInterface" + +namespace Zeeker { + +class PreviewPageIface; + +class PreviewPagePluginIface : public PluginInterface +{ +public: + virtual ~PreviewPagePluginIface() {} + + virtual PreviewPageIface *createPreviewPage() = 0; +}; + +class PreviewPageIface +{ +public: + enum PreviewType { + Attribute, + Text, + Pictrue, + PDF, + OfficeDoc, + Other + }; + + virtual ~PreviewPageIface() {} + + virtual void prepare(const QString &uri, PreviewType type) = 0; + virtual void prepare(const QString &uri) = 0; + virtual void startPreview() = 0; + virtual void cancel() = 0; + virtual void closePreviewPage() = 0; +}; + +} + +Q_DECLARE_INTERFACE(Zeeker::PreviewPagePluginIface, PreviewPagePluginIface_iid) + +#endif // PREVIEWPAGEPLUGINIFACE_H