Merge pull request #275 from iaom/0630-new-frontend

0703
This commit is contained in:
张佳萍 2021-07-05 19:12:39 +08:00 committed by GitHub
commit 10147b7752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 117 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -25,7 +25,7 @@
#include <QPainter>
#include <QStyleOption>
#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 *);

View File

@ -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)

View File

@ -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

View File

@ -12,6 +12,13 @@ void ResultViewDelegate::setSearchKeyword(const QString &regFindKeyWords)
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()));

View File

@ -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;

View File

@ -104,11 +104,11 @@ bool AppSearchPlugin::addPanelShortcut(const QString& path) {
if(iface.isValid()) {
QDBusReply<bool> 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<QVariant> ret = iface.call("AddToTaskbar", path);
qDebug() << "qDebug: Add shortcut to panel successed!";
qDebug() << "Add shortcut to panel successed!";
return true;
}
return false;

View File

@ -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();

View File

@ -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";

View File

@ -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 +=

View File

@ -0,0 +1,47 @@
#ifndef PREVIEWPAGEPLUGINIFACE_H
#define PREVIEWPAGEPLUGINIFACE_H
#include <QPluginLoader>
#include <QtPlugin>
#include <QString>
#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