Add ukcc plugin.

This commit is contained in:
iaom 2021-10-28 20:46:39 +08:00
parent 25bae31cff
commit 66a8df1a51
12 changed files with 799 additions and 3 deletions

3
debian/control vendored
View File

@ -19,7 +19,8 @@ Build-Depends: debhelper (>=9.0.0),
libuchardet-dev,
libpoppler-qt5-dev,
libukui-log4qt-dev,
libqt5xdg-dev
libqt5xdg-dev,
libukcc-dev
Standards-Version: 4.5.0
Homepage: https://www.ukui.org/
Vcs-Git: https://github.com/ukui/ukui-search.git

View File

@ -3,3 +3,7 @@ etc/xdg/autostart/*.desktop
usr/share/applications/*.desktop
frontend/.qm/*.qm usr/share/ukui-search/translations
usr/share/glib-2.0/schemas/*.xml
usr/lib/*/ukui-control-center/*
usr/share/ukui-search/search-ukcc-plugin/translations/*
usr/share/ukui-search/search-ukcc-plugin/image/*

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 59 (86127) - https://sketch.com -->
<title>360</title>
<desc>Created with Sketch.</desc>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="搜索设置-添加/删除2" transform="translate(-1476.000000, -630.000000)">
<g id="编组-11" transform="translate(1471.000000, 630.000000)">
<rect id="矩形备份-15" x="0" y="0" width="24" height="24"></rect>
<g id="360" transform="translate(7.000000, 3.000000)" fill-rule="nonzero">
<path d="M16.3973402,16.1013473 C16.3973402,15.1220886 17.1776523,14.3264408 18.1680485,14.3264408 C19.1584446,14.3264408 19.9087447,15.1220886 19.9087447,16.1013473 C19.9087447,17.0806061 19.1284326,17.9068557 18.1680485,17.9068557 C17.2076643,17.9068557 16.3973402,17.1112079 16.3973402,16.1013473 Z" id="路径" fill="#FF9932"></path>
<path d="M16.4273522,12.4597288 L13.8763318,11.4192664 C13.6662478,11.3274609 13.6662478,11.1744517 13.7562838,10.9602389 C13.9963798,10.3482021 14.1164278,9.64435991 14.1164278,8.97111953 C14.1164278,6.03334326 11.6854554,3.55459454 8.80430297,3.55459452 C5.92315053,3.5545945 3.49217813,6.06394509 3.49217811,8.97111953 C3.49217811,9.64435993 3.67225014,10.378804 3.91234618,10.9908407 C3.9723702,11.113248 3.9723702,11.2662572 3.91234618,11.3886646 C3.85232217,11.4804701 3.79229817,11.3886646 3.70226216,11.4192664 L1.09121773,12.2761178 C1.06120574,12.3067197 1.00118172,12.3067197 0.971169723,12.3067197 C0.791097696,12.3067197 0.671049665,12.2149141 0.61102567,12.0313031 C0.220869599,11.0214425 0.0107855548,10.011582 0.0107855548,8.97111953 C0.0107855548,4.04422391 3.9723702,0.0047815345 8.80430297,0.0047815345 C13.6362358,0.0047815345 17.5978204,4.01362206 17.5978204,8.94051768 C17.5978204,10.1033874 17.3877363,11.2050535 16.9975803,12.245516 C16.9675683,12.3373215 16.8775323,12.429127 16.7574842,12.4597288 C16.6974602,12.4903307 16.6674482,12.4903307 16.6074242,12.4903307 C16.5474002,12.4903307 16.4873762,12.4903307 16.4273522,12.4597288 Z" id="路径" fill="#0FB264"></path>
<path d="M0.971169723,13.0717656 C0.821109694,12.7657472 0.701061683,12.4597288 0.581013652,12.1537105 C0.520989636,12.0007013 0.520989636,11.8782939 0.520989636,11.8170903 C0.520989636,10.8378315 1.30130176,10.0421838 2.29169792,10.0421838 C3.01198603,10.0421838 3.64223814,10.5012113 3.9423582,11.1438499 C3.9723702,11.2050536 4.06240621,11.3886646 4.12243023,11.4804701 C5.02279038,13.2553766 6.82351066,14.3876445 8.77429098,14.3876445 C10.6950593,14.3876445 12.4657676,13.2859784 13.3961397,11.5722756 C13.4861757,11.3886646 13.7262718,10.9602389 13.7562838,10.9602389 C14.0564038,10.3482021 14.5966199,10.0727856 15.256884,10.0727856 C16.2472802,10.0727856 17.0275923,10.8684333 17.0275923,11.8476921 C17.0275923,11.9700995 17.0275923,12.1231086 16.9375563,12.3067197 L16.7574842,12.7657472 L16.7574842,12.796349 C16.7274722,12.8881545 16.6974602,12.9493582 16.6374362,13.0411637 C15.136836,16.0707455 12.1356355,17.9680593 8.77429098,17.9680593 C5.47297044,17.9068556 2.50178197,16.0707455 0.971169723,13.0717656 L0.971169723,13.0717656 Z" id="路径" fill="#FF9932"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><title>add</title><g opacity="0.85"><polygon points="16 7 9 7 9 0 7 0 7 7 0 7 0 9 7 9 7 16 9 16 9 9 16 9 16 7"/></g></svg>

After

Width:  |  Height:  |  Size: 217 B

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 59 (86127) - https://sketch.com -->
<title>sougou</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="24.2116501%" y1="13.4446809%" x2="84.5451665%" y2="97.3997161%" id="linearGradient-1">
<stop stop-color="#FD8449" offset="0%"></stop>
<stop stop-color="#FA4D23" offset="100%"></stop>
</linearGradient>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="搜索设置-添加/删除2" transform="translate(-1442.000000, -630.000000)">
<g id="编组-10" transform="translate(1442.000000, 630.000000)">
<rect id="矩形备份-12" x="0" y="0" width="24" height="24"></rect>
<g id="搜狗" transform="translate(2.000000, 2.000000)" fill="url(#linearGradient-1)" fill-rule="nonzero">
<path d="M17.811,16.201375 L18.535,16.706375 C17.4840306,17.9285167 16.1537307,18.8790739 14.657,19.477375 L14.657,19.477375 L14.206,18.723375 C15.5948993,18.1884192 16.8323353,17.3227289 17.811,16.201375 L17.811,16.201375 Z M9.999,0.004375 C15.52,0.004375 19.998,4.345375 20,9.702375 C19.9986243,11.9758025 19.1802151,14.1730148 17.694,15.893375 L17.694,15.893375 L16.97,15.388375 C18.3483127,13.814701 19.1087129,11.7943105 19.11,9.702375 C19.11,4.822375 15.031,0.867375 9.998,0.867375 C4.967,0.867375 0.888,4.822375 0.888,9.702375 C0.888,14.579375 4.967,18.534375 9.999,18.534375 C11.1498074,18.5349329 12.2908639,18.3234001 13.365,17.910375 L13.365,17.910375 L13.816,18.664375 C12.607,19.150375 11.309,19.399375 9.999,19.397387 C4.475,19.397387 0,15.056375 0,9.699375 C0,4.345375 4.475,0.004375 9.999,0.004375 Z M4.774,5.817375 C7.913,2.471375 15.885,5.403375 15.885,5.403375 L15.885,5.403375 L15.885,7.583375 C15.885,7.583375 14.095,6.692375 10.575,6.416375 C7.606,6.183375 8.645,7.350375 8.645,7.350375 C10.535,8.406375 12.213,8.803375 12.213,8.803375 C16.463,9.891375 16.213,11.475375 16.213,11.475375 C16.108,18.140375 4.368,13.990375 4.368,13.990375 L4.368,13.990375 L4.521,11.526375 C6.464,13.289375 10.031,13.264375 10.031,13.264375 C14.688,12.874375 10.945,11.214375 10.945,11.214375 C8.042,10.487375 5.872,9.267375 4.807,8.307375 C3.741,7.347375 4.774,5.817375 4.774,5.817375 Z" id="形状结合"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,35 @@
QT += widgets
TEMPLATE = lib
TARGET = $$qtLibraryTarget(search-ukcc-plugin)
target.path = $$[QT_INSTALL_LIBS]/ukui-control-center/
CONFIG += plugin link_pkgconfig c++11 lrelease
PKGCONFIG += gio-2.0 gio-unix-2.0 gsettings-qt
LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt
LIBS += -lukcc
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += search.cpp
HEADERS += search.h
TRANSLATIONS += translations/zh_CN.ts
images.files = image/*
images.path = /usr/share/ukui-search/search-ukcc-plugin/image/
qm_files.files = translations/* $$OUT_PWD/.qm/*.qm
qm_files.path = /usr/share/ukui-search/search-ukcc-plugin/translations
INSTALLS += target images qm_files
DISTFILES += \
./image/360.svg \
./image/baidu.scg \
./image/sougou.svg \
./image/add.svg

View File

@ -0,0 +1,440 @@
#include "search.h"
#include <QTranslator>
#include <QApplication>
Search::Search()
{
QTranslator* translator = new QTranslator(this);
if(!translator->load("/usr/share/ukui-search/search-ukcc-plugin/translations/" + QLocale::system().name())) {
qWarning() << "/usr/share/ukui-search/search-ukcc-plugin/translations/" + QLocale::system().name() << "load failed";
}
QApplication::installTranslator(translator);
m_plugin_name = tr("Search");
m_plugin_type = SEARCH_F;
initUi();
setupConnection();
m_dirSettings = new QSettings(QDir::homePath() + CONFIG_FILE, QSettings::NativeFormat, this);
m_dirSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
initBlockDirsList();
}
Search::~Search()
{
delete m_pluginWidget;
if (m_gsettings) {
delete m_gsettings;
m_gsettings = nullptr;
}
}
QString Search::plugini18nName()
{
return m_plugin_name;
}
int Search::pluginTypes()
{
return m_plugin_type;
}
QWidget *Search::pluginUi()
{
m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
const QByteArray id(UKUI_SEARCH_SCHEMAS);
if (QGSettings::isSchemaInstalled(id)) {
m_gsettings = new QGSettings(id, QByteArray(), this);
//按钮状态初始化
if (m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
//当前是否使用索引搜索/暴力搜索
bool is_index_search_on = m_gsettings->get(SEARCH_METHOD_KEY).toBool();
m_searchMethodBtn->setChecked(is_index_search_on);
} else {
m_searchMethodBtn->setEnabled(false);
}
if (m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
//当前网页搜索的搜索引擎
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
m_webEngineFrame->mCombox->setCurrentIndex(m_webEngineFrame->mCombox->findData(engine));
} else {
m_webEngineFrame->mCombox->setEnabled(false);
}
//监听gsettings值改变更新控制面板UI
connect(m_gsettings, &QGSettings::changed, this, [ = ](const QString &key) {
if (key == SEARCH_METHOD_KEY) {
bool is_index_search_on = m_gsettings->get(SEARCH_METHOD_KEY).toBool();
m_searchMethodBtn->blockSignals(true);
m_searchMethodBtn->setChecked(is_index_search_on);
m_searchMethodBtn->blockSignals(false);
} else if (key == WEB_ENGINE_KEY) {
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
m_webEngineFrame->mCombox->blockSignals(true);
m_webEngineFrame->mCombox->setCurrentIndex(m_webEngineFrame->mCombox->findData(engine));
m_webEngineFrame->mCombox->blockSignals(false);
}
});
connect(m_searchMethodBtn, &SwitchButton::checkedChanged, this, [ = ](bool checked) {
if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
m_gsettings->set(SEARCH_METHOD_KEY, checked);
}
});
connect(m_webEngineFrame->mCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
m_gsettings->set(WEB_ENGINE_KEY, m_webEngineFrame->mCombox->currentData().toString());
}
});
} else {
qCritical() << UKUI_SEARCH_SCHEMAS << " not installed!\n";
m_searchMethodBtn->setEnabled(false);
m_webEngineFrame->mCombox->setEnabled(false);
}
return m_pluginWidget;
}
const QString Search::name() const
{
return QStringLiteral("Search");
}
QString Search::translationPath() const
{
return QStringLiteral("/usr/share/ukui-search/search-ukcc-plugin/translations/%1.ts");
}
bool Search::isShowOnHomePage() const
{
return true;
}
QIcon Search::icon() const
{
return QIcon();
}
bool Search::isEnable() const
{
return true;
}
/**
* @brief Search::initUi UI
*/
void Search::initUi()
{
m_pluginWidget = new QWidget;
m_mainLyt = new QVBoxLayout(m_pluginWidget);
m_pluginWidget->setLayout(m_mainLyt);
m_titleLabel = new TitleLabel(m_setFrame);
m_titleLabel->setText(tr("Search"));
m_mainLyt->addWidget(m_titleLabel);
//设置搜索模式部分的ui
m_setFrame = new QFrame(m_pluginWidget);
m_setFrame->setFrameShape(QFrame::Shape::Box);
m_setFrameLyt = new QVBoxLayout(m_setFrame);
m_setFrameLyt->setContentsMargins(0, 0, 0, 0);
m_setFrameLyt->setSpacing(0);
m_searchMethodFrame = new QFrame(m_setFrame);
m_searchMethodFrame->setMinimumWidth(550);
m_searchMethodLyt = new QHBoxLayout(m_searchMethodFrame);
m_searchMethodLyt->setContentsMargins(16, 18, 16, 21);
m_searchMethodFrame->setLayout(m_searchMethodLyt);
m_descFrame = new QFrame(m_searchMethodFrame);
m_descFrameLyt = new QVBoxLayout(m_descFrame);
m_descFrameLyt->setContentsMargins(0, 0, 0, 0);
m_descFrame->setLayout(m_descFrameLyt);
m_descLabel1 = new QLabel(m_descFrame);
m_descLabel2 = new QLabel(m_descFrame);
//~ contents_path /Search/Create index
m_descLabel1->setText(tr("Create index"));
m_descLabel2->setText(tr("Creating index can help you getting results quickly."));
m_descLabel2->setEnabled(false);
m_descFrameLyt->addWidget(m_descLabel1);
m_descFrameLyt->addWidget(m_descLabel2);
m_searchMethodBtn = new SwitchButton(m_searchMethodFrame);
m_searchMethodLyt->addWidget(m_descFrame);
m_searchMethodLyt->addStretch();
m_searchMethodLyt->addWidget(m_searchMethodBtn);
m_setFrameLyt->addWidget(m_searchMethodFrame);
QFrame *line = new QFrame(m_setFrame);
line->setFixedHeight(1);
line->setLineWidth(0);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
m_setFrameLyt->addWidget(line);
//设置网页搜索引擎部分的ui
//~ contents_path /Search/Default web searching engine
m_webEngineFrame = new ComboxFrame(tr("Default web searching engine"), m_searchMethodFrame);
m_webEngineFrame->setContentsMargins(8, 0, 16, 0);
m_webEngineFrame->setFixedHeight(56);
m_webEngineFrame->setMinimumWidth(550);
m_webEngineFrame->mCombox->insertItem(0, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/baidu.svg"), tr("baidu"), "baidu");
m_webEngineFrame->mCombox->insertItem(1, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/sougou.svg"), tr("sougou"), "sougou");
m_webEngineFrame->mCombox->insertItem(2, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/360.svg"), tr("360"), "360");
m_setFrameLyt->addWidget(m_webEngineFrame);
m_mainLyt->addWidget(m_setFrame);
//设置黑名单文件夹部分的ui
m_blockDirTitleLabel = new TitleLabel(m_pluginWidget);
//~ contents_path /Search/Block Folders
m_blockDirTitleLabel->setText(tr("Block Folders"));
m_blockDirDescLabel = new QLabel(m_pluginWidget);
m_blockDirDescLabel->setWordWrap(true);
m_blockDirDescLabel->setText(tr("Following folders will not be searched. You can set it by adding and removing folders."));
m_blockDirsFrame = new QFrame(m_pluginWidget);
m_blockDirsFrame->setFrameShape(QFrame::Shape::Box);
m_blockDirsLyt = new QVBoxLayout(m_blockDirsFrame);
m_blockDirsLyt->setDirection(QBoxLayout::BottomToTop);
m_blockDirsFrame->setLayout(m_blockDirsLyt);
m_blockDirsLyt->setContentsMargins(0, 0, 0, 0);
m_blockDirsLyt->setSpacing(2);
QFrame * m_addBlockDirFrame = new QFrame(m_blockDirsFrame);
m_addBlockDirFrame->setFrameShape(QFrame::Shape::NoFrame);
m_addBlockDirFrame->setFixedHeight(60);
m_addBlockDirWidget = new HoverWidget("", m_addBlockDirFrame);
m_addBlockDirWidget->setFixedHeight(60);
// m_addBlockDirWidget->setObjectName("addBlockDirWidget");
// QPalette pal;
// QBrush brush = pal.highlight(); //获取window的色值
// QColor highLightColor = brush.color();
// QString stringColor = QString("rgba(%1,%2,%3)") //叠加20%白色
// .arg(highLightColor.red()*0.8 + 255*0.2)
// .arg(highLightColor.green()*0.8 + 255*0.2)
// .arg(highLightColor.blue()*0.8 + 255*0.2);
// m_addBlockDirWidget->setStyleSheet(QString("HoverWidget#addBlockDirWidget{background: palette(button);\
// border-radius: 4px;}\
// HoverWidget:hover:!pressed#addBlockDirWidget{background: %1; \
// border-radius: 4px;}").arg(stringColor));
m_addBlockDirIcon = new QLabel(m_addBlockDirWidget);
m_addBlockDirIcon->setPixmap(QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/add.svg").pixmap(12, 12));
m_addBlockDirIcon->setProperty("useIconHighlightEffect", true);
m_addBlockDirIcon->setProperty("iconHighlightEffectMode", 1);
m_addBlockDirLabel = new QLabel(m_addBlockDirWidget);
m_addBlockDirLabel->setText(tr("Choose folder"));
m_addBlockDirLyt = new QHBoxLayout(m_addBlockDirWidget);
m_addBlockDirWidget->setLayout(m_addBlockDirLyt);
m_blockDirsLyt->addWidget(m_addBlockDirWidget);
m_addBlockDirLyt->addStretch();
m_addBlockDirLyt->addWidget(m_addBlockDirIcon);
m_addBlockDirLyt->addWidget(m_addBlockDirLabel);
m_addBlockDirLyt->addStretch();
m_mainLyt->addSpacing(32);
m_mainLyt->addWidget(m_blockDirTitleLabel);
m_mainLyt->addWidget(m_blockDirDescLabel);
m_mainLyt->addWidget(m_blockDirsFrame);
m_mainLyt->addStretch();
m_mainLyt->setContentsMargins(0, 0, 40, 0);
}
/**
* @brief Search::getBlockDirs
*/
void Search::getBlockDirs()
{
m_blockDirs.clear();
if (m_dirSettings)
m_blockDirs = m_dirSettings->allKeys();
}
/**
* @brief Search::setBlockDir
* @param dirPath
* @param is_add
* @return 0 !0
*/
int Search::setBlockDir(const QString &dirPath, const bool &is_add)
{
if (!is_add) {
if (dirPath.isEmpty()) {
return ReturnCode::PathEmpty;
}
//删除黑名单目录
m_dirSettings->remove(dirPath);
removeBlockDirFromList(dirPath);
return ReturnCode::Succeed;
}
if (!dirPath.startsWith(QDir::homePath())) {
return ReturnCode::NotInHomeDir;
}
QString pathKey = dirPath.right(dirPath.length() - 1);
for (QString dir : m_blockDirs) {
if (pathKey == dir) {
return ReturnCode::HasBeenBlocked;
}
if (pathKey.startsWith(dir)) {
return ReturnCode::ParentExist;
}
//有它的子文件夹已被添加,删除这些子文件夹
if (dir.startsWith(pathKey)) {
m_dirSettings->remove(dir);
removeBlockDirFromList("/" + dir);
}
}
m_dirSettings->setValue(pathKey, "0");
appendBlockDirToList(dirPath);
return ReturnCode::Succeed;
}
/**
* @brief Search::initBlockDirsList
*/
void Search::initBlockDirsList()
{
getBlockDirs();
for (QString path: m_blockDirs) {
QString wholePath = QString("/%1").arg(path);
if (QFileInfo(wholePath).isDir() && path.startsWith("home")) {
appendBlockDirToList(wholePath);
}
}
}
void Search::appendBlockDirToList(const QString &path)
{
HoverWidget * dirWidget = new HoverWidget(path, m_blockDirsFrame);
dirWidget->setObjectName(path);
dirWidget->setMinimumWidth(550);
dirWidget->setAttribute(Qt::WA_DeleteOnClose);
QHBoxLayout * dirWidgetLyt = new QHBoxLayout(dirWidget);
dirWidgetLyt->setSpacing(8);
dirWidgetLyt->setContentsMargins(0, 0, 0, 0);
dirWidget->setLayout(dirWidgetLyt);
QFrame * dirFrame = new QFrame(dirWidget);
dirFrame->setFrameShape(QFrame::Shape::Box);
dirFrame->setFixedHeight(50);
QHBoxLayout * dirFrameLayout = new QHBoxLayout(dirFrame);
dirFrameLayout->setSpacing(16);
dirFrameLayout->setContentsMargins(16, 0, 16, 0);
QLabel * iconLabel = new QLabel(dirFrame);
QLabel * pathLabel = new QLabel(dirFrame);
dirFrameLayout->addWidget(iconLabel);
iconLabel->setPixmap(QIcon::fromTheme("inode-directory").pixmap(QSize(24, 24)));
pathLabel->setText(path);
dirFrameLayout->addWidget(pathLabel);
dirFrameLayout->addStretch();
QPushButton * delBtn = new QPushButton(dirFrame);
delBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
delBtn->setFixedSize(30, 30);
delBtn->setToolTip(tr("delete"));
delBtn->setProperty("isWindowButton", 0x2);
delBtn->setProperty("useIconHighlightEffect", 0x8);
delBtn->setFlat(true);
delBtn->hide();
dirFrameLayout->addWidget(delBtn);
dirWidgetLyt->addWidget(dirFrame);
// dirWidgetLyt->addWidget(delBtn);
QFrame *line = new QFrame(m_blockDirsFrame);
line->setFixedHeight(1);
line->setLineWidth(0);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
// m_setFrameLyt->addWidget(line);
m_blockDirsLyt->addWidget(line);
m_blockDirsLyt->addWidget(dirWidget);
connect(delBtn, &QPushButton::clicked, this, [ = ]() {
setBlockDir(path, false);
getBlockDirs();
m_blockDirsLyt->removeWidget(line);
line->deleteLater();
});
connect(dirWidget, &HoverWidget::enterWidget, this, [ = ]() {
delBtn->show();
});
connect(dirWidget, &HoverWidget::leaveWidget, this, [ = ]() {
delBtn->hide();
});
}
void Search::removeBlockDirFromList(const QString &path)
{
HoverWidget * delDirWidget = m_blockDirsFrame->findChild<HoverWidget *>(path);
if (delDirWidget) {
qDebug() << "Delete folder succeed! path = " << path;
delDirWidget->close();
}
}
void Search::setupConnection()
{
connect(m_addBlockDirWidget, &HoverWidget::widgetClicked, this, &Search::onBtnAddFolderClicked);
}
void Search::onBtnAddFolderClicked()
{
QFileDialog * fileDialog = new QFileDialog(m_pluginWidget);
// fileDialog->setFileMode(QFileDialog::Directory); //允许查看文件和文件夹,但只允许选择文件夹
fileDialog->setFileMode(QFileDialog::DirectoryOnly); //只允许查看文件夹
// fileDialog->setViewMode(QFileDialog::Detail);
fileDialog->setDirectory(QDir::homePath());
fileDialog->setNameFilter(tr("Directories"));
fileDialog->setWindowTitle(tr("select blocked folder"));
fileDialog->setLabelText(QFileDialog::Accept, tr("Select"));
fileDialog->setLabelText(QFileDialog::LookIn, tr("Position: "));
fileDialog->setLabelText(QFileDialog::FileName, tr("FileName: "));
fileDialog->setLabelText(QFileDialog::FileType, tr("FileType: "));
fileDialog->setLabelText(QFileDialog::Reject, tr("Cancel"));
if(fileDialog->exec() != QDialog::Accepted) {
fileDialog->deleteLater();
return;
}
QString selectedDir = 0;
selectedDir = fileDialog->selectedFiles().first();
qDebug() << "Selected a folder in onBtnAddClicked(): " << selectedDir;
int returnCode = setBlockDir(selectedDir, true);
switch (returnCode) {
case ReturnCode::Succeed :
qDebug() << "Add blocked folder succeed! path = " << selectedDir;
getBlockDirs();
break;
case ReturnCode::PathEmpty :
qWarning() << "Add blocked folder failed, choosen path is empty! path = " << selectedDir;
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, choosen path is empty!"));
break;
case ReturnCode::NotInHomeDir :
qWarning() << "Add blocked folder failed, it is not in home path! path = " << selectedDir;
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, it is not in home path!"));
break;
case ReturnCode::ParentExist :
qWarning() << "Add blocked folder failed, its parent dir is exist! path = " << selectedDir;
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, its parent dir is exist!"));
break;
case ReturnCode::HasBeenBlocked :
qWarning() << "Add blocked folder failed, it has been already blocked! path = " << selectedDir;
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, it has been already blocked!"));
break;
default:
break;
}
}

110
search-ukcc-plugin/search.h Normal file
View File

@ -0,0 +1,110 @@
#ifndef SEARCH_H
#define SEARCH_H
#include <QObject>
#include <QGSettings>
#include <QDebug>
#include <QVBoxLayout>
#include <QLabel>
#include <QFrame>
#include <QSettings>
#include <QFileDialog>
#include <QTextCodec>
#include <QPushButton>
#include <QMessageBox>
#include <ukcc/interface/interface.h>
#include <ukcc/widgets/comboboxitem.h>
#include <ukcc/widgets/switchbutton.h>
#include <ukcc/widgets/hoverwidget.h>
#include <ukcc/widgets/switchbutton.h>
#include <ukcc/widgets/comboxframe.h>
#include <ukcc/widgets/titlelabel.h>
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define SEARCH_METHOD_KEY "indexSearch"
#define WEB_ENGINE_KEY "webEngine"
//TODO
#define CONFIG_FILE "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf"
enum ReturnCode {
Succeed,
PathEmpty,
NotInHomeDir,
ParentExist,
HasBeenBlocked
};
class Search : public QObject, CommonInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
Q_INTERFACES(CommonInterface)
public:
explicit Search();
~Search();
QString plugini18nName() Q_DECL_OVERRIDE;
int pluginTypes() Q_DECL_OVERRIDE;
QWidget * pluginUi() Q_DECL_OVERRIDE;
const QString name() const Q_DECL_OVERRIDE;
QString translationPath() const;
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
private:
QWidget * m_pluginWidget = nullptr;
QString m_plugin_name = "";
int m_plugin_type = 0;
QGSettings * m_gsettings = nullptr;
void initUi();
QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr;
QFrame *m_setFrame = nullptr;
QVBoxLayout *m_setFrameLyt = nullptr;
//设置搜索模式
QFrame *m_descFrame = nullptr;
QVBoxLayout *m_descFrameLyt = nullptr;
QLabel *m_descLabel1 = nullptr;
QLabel *m_descLabel2 = nullptr;
QFrame *m_searchMethodFrame = nullptr;
QHBoxLayout *m_searchMethodLyt = nullptr;
// QLabel *m_searchMethodLabel = nullptr;
SwitchButton * m_searchMethodBtn = nullptr;
//设置搜索引擎
TitleLabel * m_webEngineLabel = nullptr;
ComboxFrame * m_webEngineFrame = nullptr;
QVBoxLayout * m_webEngineLyt = nullptr;
//设置黑名单
TitleLabel * m_blockDirTitleLabel = nullptr;
QLabel * m_blockDirDescLabel = nullptr;
QFrame * m_blockDirsFrame = nullptr;
QVBoxLayout * m_blockDirsLyt = nullptr;
HoverWidget * m_addBlockDirWidget = nullptr;
QLabel * m_addBlockDirIcon = nullptr;
QLabel * m_addBlockDirLabel = nullptr;
QHBoxLayout * m_addBlockDirLyt = nullptr;
QStringList m_blockDirs;
QSettings * m_dirSettings = nullptr;
void getBlockDirs();
int setBlockDir(const QString &dirPath, const bool &is_add = true);
void appendBlockDirToList(const QString &path);
void removeBlockDirFromList(const QString &path);
void initBlockDirsList();
// void refreshBlockDirsList();
void setupConnection();
private slots:
void onBtnAddFolderClicked();
};
#endif // SEARCH_H

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Search</class>
<widget class="QWidget" name="Search">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>784</width>
<height>630</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>Search</name>
<message>
<location filename="../search.cpp" line="13"/>
<location filename="../search.cpp" line="125"/>
<source>Search</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="149"/>
<source>Create index</source>
<translation></translation>
<extra-contents_path>/Search/Create index</extra-contents_path>
</message>
<message>
<location filename="../search.cpp" line="150"/>
<source>Creating index can help you getting results quickly.</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="169"/>
<source>Default web searching engine</source>
<translation></translation>
<extra-contents_path>/Search/Default web searching engine</extra-contents_path>
</message>
<message>
<location filename="../search.cpp" line="173"/>
<source>baidu</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="174"/>
<source>sougou</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="175"/>
<source>360</source>
<translation>360</translation>
</message>
<message>
<location filename="../search.cpp" line="183"/>
<source>Block Folders</source>
<translation></translation>
<extra-contents_path>/Search/Block Folders</extra-contents_path>
</message>
<message>
<location filename="../search.cpp" line="186"/>
<source>Following folders will not be searched. You can set it by adding and removing folders.</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="228"/>
<source>Choose folder</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="341"/>
<source>delete</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="396"/>
<source>Directories</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="397"/>
<source>select blocked folder</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="398"/>
<source>Select</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="399"/>
<source>Position: </source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="400"/>
<source>FileName: </source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="401"/>
<source>FileType: </source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="402"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="418"/>
<location filename="../search.cpp" line="422"/>
<location filename="../search.cpp" line="426"/>
<location filename="../search.cpp" line="430"/>
<source>Warning</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="418"/>
<source>Add blocked folder failed, choosen path is empty!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="422"/>
<source>Add blocked folder failed, it is not in home path!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="426"/>
<source>Add blocked folder failed, its parent dir is exist!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="430"/>
<source>Add blocked folder failed, it has been already blocked!</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -1,9 +1,9 @@
TEMPLATE = subdirs
SUBDIRS += $$PWD/libchinese-segmentation \
$$PWD/libsearch \
# $$PWD/src \
$$PWD/frontend \
$$PWD/ukuisearch-systemdbus
$$PWD/ukuisearch-systemdbus \
$$PWD/search-ukcc-plugin
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the