Merge pull request #58 from mammonsama666/0108-dev
feat(settings-widget): Use interface provided by backend.
This commit is contained in:
commit
382c63af84
|
@ -83,16 +83,17 @@ bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage)
|
|||
QStringList blockDirs = m_block_dirs_settings->allKeys();
|
||||
for(QString i:blockDirs)
|
||||
{
|
||||
if(path.startsWith(i))
|
||||
// qWarning()<<i;
|
||||
if(path.right(path.length()-1).startsWith(i))
|
||||
{
|
||||
returnMessage = QString(tr("Parent folder has been blocked!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(i.startsWith(path))
|
||||
if(i.startsWith(path.right(path.length()-1)))
|
||||
m_block_dirs_settings->remove(i);
|
||||
}
|
||||
m_block_dirs_settings->setValue(path,"0");
|
||||
m_block_dirs_settings->setValue(path.right(path.length()-1),"0");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@ FileSearcher::FileSearcher(QObject *parent) : QObject(parent)
|
|||
|
||||
void FileSearcher::onKeywordSearch(QString keyword)
|
||||
{
|
||||
m_search_result_file = new QQueue<QString>;
|
||||
m_search_result_dir = new QQueue<QString>;
|
||||
m_search_result_content = new QQueue<QPair<QString,QStringList>>;
|
||||
//file
|
||||
QtConcurrent::run([=](){
|
||||
int begin = 0;
|
||||
|
|
|
@ -43,9 +43,9 @@ private:
|
|||
QMap<QString,QStringList> getContentResult(Xapian::MSet &result,std::string &keyWord);
|
||||
|
||||
bool isBlocked(QString &path);
|
||||
QQueue<QString> *m_search_result_file;
|
||||
QQueue<QString> *m_search_result_dir;
|
||||
QQueue<QPair<QString,QStringList>> *m_search_result_content;
|
||||
QQueue<QString> *m_search_result_file = nullptr;
|
||||
QQueue<QString> *m_search_result_dir = nullptr;
|
||||
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -233,28 +233,36 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
|||
* @param searchcontent
|
||||
*/
|
||||
void MainWindow::searchContent(QString searchcontent){
|
||||
// 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 = appMatchor->startMatchApp(searchcontent);
|
||||
// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
|
||||
QStringList list3;
|
||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
||||
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||
m_types.append(SearchItem::SearchType::Apps);
|
||||
m_types.append(SearchItem::SearchType::Settings);
|
||||
m_lists.append(list);
|
||||
m_lists.append(list3);
|
||||
|
||||
//内容搜索测试用数据,每个文件(路径)对应一段文本内容
|
||||
//文件、文件夹、内容搜索
|
||||
FileSearcher *search = new FileSearcher();
|
||||
connect(search, &FileSearcher::resultDir, this, [ = ](QQueue<QString> * dirQueue) {
|
||||
qWarning()<<"dirFile---";
|
||||
});
|
||||
connect(search, &FileSearcher::resultFile, this, [ = ](QQueue<QString> * fileQueue) {
|
||||
qWarning()<<"resultFile---";
|
||||
});
|
||||
connect(search, &FileSearcher::resultContent, this, [ = ](QQueue<QPair<QString,QStringList>> * contentQueue) {
|
||||
qWarning()<<"resultContent---";
|
||||
});
|
||||
search->onKeywordSearch(searchcontent);
|
||||
//将搜索结果加入列表
|
||||
m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
|
||||
|
||||
//iaom--------this part shall be rewrite
|
||||
// connect(search, &FileSearcher::contentResult, this, [ = ](QMap<QString,QStringList> map) {
|
||||
// m_types.append(SearchItem::SearchType::Contents);
|
||||
|
@ -271,24 +279,9 @@ void MainWindow::searchContent(QString searchcontent){
|
|||
// m_lists.append(pathlist);
|
||||
// m_contentFrame->setContentList(contentList);
|
||||
// });
|
||||
QTime t1 = QTime::currentTime();
|
||||
|
||||
// search->onKeywordSearch(searchcontent);
|
||||
QTime t2 = QTime::currentTime();
|
||||
qDebug() << t1;
|
||||
qDebug() << t2;
|
||||
// m_types.append(SearchItem::SearchType::Contents);
|
||||
// QStringList pathlist;
|
||||
// pathlist<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
||||
// m_lists.append(pathlist);
|
||||
// QStringList contentList;
|
||||
// contentList<<"这是搜索结果.png的文件内容"<<"这是显示不全.mp4的文件内容"<<"这是dmesg.log的文件内容"<<"这是WiFi_AP选择.docx的文件内容";
|
||||
// m_contentFrame->setContentList(contentList);
|
||||
// m_contentFrame->refreshSearchList(m_types, m_lists);
|
||||
|
||||
//文件搜索
|
||||
|
||||
FileSearcher *searcher = new FileSearcher();
|
||||
//iaom--------this part shall be rewrite
|
||||
// connect(searcher,&FileSearcher::result,[=](QVector<QStringList> resultV){
|
||||
|
||||
|
@ -307,26 +300,12 @@ void MainWindow::searchContent(QString searchcontent){
|
|||
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
// lists.append(res);
|
||||
|
||||
//将搜索结果加入列表
|
||||
// m_contentFrame->refreshSearchList(types, lists);
|
||||
}
|
||||
|
||||
//使用GSetting获取当前窗口应该使用的透明度
|
||||
double MainWindow::getTransparentData()
|
||||
{
|
||||
return GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble();
|
||||
// if (!m_transparency_gsettings) {
|
||||
// return 0.7;
|
||||
// }
|
||||
|
||||
// QStringList keys = m_transparency_gsettings->keys();
|
||||
// if (keys.contains("transparency")) {
|
||||
// double tp = m_transparency_gsettings->get("transparency").toDouble();
|
||||
// return tp;
|
||||
// } else {
|
||||
// return 0.7;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,6 +79,7 @@ private:
|
|||
|
||||
QVector<int> m_types;
|
||||
QVector<QStringList> m_lists;
|
||||
QStringList m_dirList;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void initUi();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include "folder-list-item.h"
|
||||
#include "global-settings.h"
|
||||
|
||||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||
SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
|
||||
|
@ -12,12 +13,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
|
|||
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground);
|
||||
initUi();
|
||||
QStringList list;
|
||||
list<<"/usr/share/applications"<<"/usr/share/icons"<<
|
||||
"/usr/libs"<<"/home/zjp/UKUI/SEARCH"<<
|
||||
"/home/zjp/UKUI/UKCC"<<"/home/zjp/UKUI/SD/intel/ukui-settings-daemon"<<
|
||||
"/home/zjp/下载"<<"/home/zjp/code";
|
||||
setupBlackList(list);
|
||||
setupBlackList(GlobalSettings::getInstance()->getBlockDirs());
|
||||
}
|
||||
|
||||
SettingsWidget::~SettingsWidget()
|
||||
|
@ -178,6 +174,7 @@ void SettingsWidget::initUi() {
|
|||
* @param list 文件夹路径列表
|
||||
*/
|
||||
void SettingsWidget::setupBlackList(const QStringList& list) {
|
||||
clearLayout(m_dirListLyt);
|
||||
Q_FOREACH(QString path, list) {
|
||||
FolderListItem * item = new FolderListItem(m_dirListWidget, path);
|
||||
m_dirListLyt->addWidget(item);
|
||||
|
@ -188,6 +185,23 @@ void SettingsWidget::setupBlackList(const QStringList& list) {
|
|||
m_dirListLyt->addStretch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SettingsWidget::clearLayout 清空某个布局
|
||||
* @param layout 需要清空的布局
|
||||
*/
|
||||
void SettingsWidget::clearLayout(QLayout * layout) {
|
||||
if (! layout) return;
|
||||
QLayoutItem * child;
|
||||
while ((child = layout->takeAt(0)) != 0) {
|
||||
if(child->widget())
|
||||
{
|
||||
child->widget()->setParent(NULL);
|
||||
}
|
||||
delete child;
|
||||
}
|
||||
child = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SettingsWidget::onBtnDelClicked 删除黑名单中的目录
|
||||
* @param path 文件夹路径
|
||||
|
@ -251,9 +265,17 @@ void SettingsWidget::onBtnAddClicked() {
|
|||
fileDialog->deleteLater();
|
||||
return;
|
||||
}
|
||||
QString selectedDir;
|
||||
QString selectedDir = 0;
|
||||
QString returnMessage = 0;
|
||||
selectedDir = fileDialog->selectedFiles().first();
|
||||
qDebug()<<selectedDir;
|
||||
qDebug()<<"Selected a folder in onBtnAddClicked(): "<<selectedDir<<". ->settings-widget.cpp #238";
|
||||
if (GlobalSettings::getInstance()->setBlockDirs(selectedDir, returnMessage)) {
|
||||
setupBlackList(GlobalSettings::getInstance()->getBlockDirs());
|
||||
qDebug()<<"Add block dir in onBtnAddClicked() successed. ->settings-widget.cpp #238";
|
||||
} else {
|
||||
qWarning()<<returnMessage;
|
||||
qDebug()<<"Add block dir in onBtnAddClicked() failed. Message: "<<returnMessage<<" ->settings-widget.cpp #238";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,8 @@ public:
|
|||
private:
|
||||
void initUi();
|
||||
void setupBlackList(const QStringList &);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void clearLayout(QLayout *);
|
||||
void paintEvent(QPaintEvent *);
|
||||
//标题栏
|
||||
QVBoxLayout * m_mainLyt = nullptr;
|
||||
QFrame * m_titleFrame = nullptr;
|
||||
|
|
Loading…
Reference in New Issue