feat(homepage): Init & refresh homepage with interface provided by ConfigFile.
Description: 加入初始化和刷新Homepage的接口调用 Log: 加入初始化和刷新Homepage的接口调用
This commit is contained in:
parent
cc54028c35
commit
443c434019
|
@ -2,6 +2,7 @@
|
|||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include "config-file.h"
|
||||
|
||||
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
||||
{
|
||||
|
@ -56,6 +57,10 @@ void ContentWidget::initUI() {
|
|||
m_resultListArea->setWidget(m_resultList);
|
||||
m_resultListArea->setWidgetResizable(true);
|
||||
m_detailView = new SearchDetailView(m_resultDetailArea);
|
||||
connect(m_detailView, &SearchDetailView::configFileChanged, this, [ = ]() {
|
||||
clearLayout(m_homePageLyt);
|
||||
initHomePage();
|
||||
});
|
||||
m_resultDetailArea->setWidget(m_detailView);
|
||||
m_resultDetailArea->setWidgetResizable(true);
|
||||
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
||||
|
@ -70,13 +75,29 @@ void ContentWidget::initUI() {
|
|||
* @brief ContentWidget::initHomePage 向homepage填充内容
|
||||
* @param lists 三个列表:常用,最近,快捷
|
||||
*/
|
||||
void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
||||
void ContentWidget::initHomePage() {
|
||||
QVector<QStringList> lists;
|
||||
QMap<QString, QStringList> map = ConfigFile::readConfig();
|
||||
QStringList commonlyList;
|
||||
commonlyList = map.value("Commonly");
|
||||
QStringList recentlyList;
|
||||
recentlyList = map.value("Recently");
|
||||
QStringList quicklyList;
|
||||
quicklyList<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"Theme/主题/更改壁纸";
|
||||
lists.append(commonlyList);
|
||||
lists.append(recentlyList);
|
||||
lists.append(quicklyList);
|
||||
|
||||
for (int i = 0; i < lists.count(); i++) {
|
||||
if (lists.at(i).isEmpty())
|
||||
continue;
|
||||
QWidget * listWidget = new QWidget(m_homePage);
|
||||
QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget);
|
||||
QLabel * titleLabel = new QLabel(listWidget);
|
||||
QWidget * itemWidget = new QWidget(listWidget);
|
||||
if (i == 1) {
|
||||
if (lists.at(i).length() <= 2) itemWidget->setFixedHeight(48);
|
||||
else itemWidget->setFixedHeight(112);
|
||||
titleLabel->setText(tr("Recently Opened"));
|
||||
QGridLayout * layout = new QGridLayout(itemWidget);
|
||||
layout->setSpacing(8);
|
||||
|
@ -87,6 +108,7 @@ void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|||
layout->addWidget(item, j / 2, j % 2);
|
||||
}
|
||||
} else {
|
||||
itemWidget->setFixedHeight(136);
|
||||
QHBoxLayout * layout = new QHBoxLayout(itemWidget);
|
||||
layout->setSpacing(8);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
@ -95,12 +117,12 @@ void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|||
HomePageItem * item = new HomePageItem(itemWidget, i, path);
|
||||
layout->addWidget(item);
|
||||
}
|
||||
if (i) {
|
||||
titleLabel->setText(tr("Open Quickly"));
|
||||
for (int j = 0; j < 4 - lists.at(i).length(); j++) {
|
||||
QWidget * emptyItem = new QWidget(itemWidget);
|
||||
emptyItem->setFixedSize(136, 136); //占位用widget,若后续快捷打开有扩展项,可删除此widget
|
||||
emptyItem->setFixedSize(136, 136); //占位用widget,少于4项会补全后方占位
|
||||
layout->addWidget(emptyItem);
|
||||
}
|
||||
if (i) titleLabel->setText(tr("Open Quickly"));
|
||||
else titleLabel->setText(tr("Commonly Used"));
|
||||
}
|
||||
itemWidgetLyt->setSpacing(6);
|
||||
|
@ -109,6 +131,7 @@ void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|||
itemWidgetLyt->addWidget(itemWidget);
|
||||
m_homePageLyt->addWidget(listWidget);
|
||||
}
|
||||
m_homePageLyt->addStretch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,7 +158,8 @@ int ContentWidget::currentPage() {
|
|||
*/
|
||||
void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<QStringList>& lists, const QString& keyword) {
|
||||
if (!m_listLyt->isEmpty()) {
|
||||
clearSearchList();
|
||||
clearLayout(m_listLyt);
|
||||
m_resultList->setFixedHeight(0);
|
||||
}
|
||||
bool isEmpty = true;
|
||||
QStringList bestList;
|
||||
|
@ -229,11 +253,13 @@ QString ContentWidget::getTitleName(const int& type) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::clearSearchList 清空搜索结果列表
|
||||
* @brief ContentWidget::clearLayout 清空搜索结果列表
|
||||
* @param layout 需要清空的布局
|
||||
*/
|
||||
void ContentWidget::clearSearchList() {
|
||||
void ContentWidget::clearLayout(QLayout * layout) {
|
||||
if (! layout) return;
|
||||
QLayoutItem * child;
|
||||
while ((child = m_listLyt->takeAt(0)) != 0) {
|
||||
while ((child = layout->takeAt(0)) != 0) {
|
||||
if(child->widget())
|
||||
{
|
||||
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
|
||||
|
@ -241,7 +267,6 @@ void ContentWidget::clearSearchList() {
|
|||
delete child;
|
||||
}
|
||||
child = NULL;
|
||||
m_resultList->setFixedHeight(0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,10 +18,11 @@ public:
|
|||
void setPage(const int&);
|
||||
int currentPage();
|
||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&, const QString&);
|
||||
void initHomePage(const QVector<QStringList>&);
|
||||
void initHomePage();
|
||||
void setContentList(const QStringList&);
|
||||
private:
|
||||
void initUI();
|
||||
void clearHomepage();
|
||||
QStringList m_contentList;
|
||||
QWidget * m_homePage = nullptr;
|
||||
QVBoxLayout * m_homePageLyt = nullptr;
|
||||
|
@ -44,7 +45,7 @@ Q_SIGNALS:
|
|||
void currentItemChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void clearSearchList();
|
||||
void clearLayout(QLayout *);
|
||||
};
|
||||
|
||||
#endif // CONTENTWIDGET_H
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
#include "config-file.h"
|
||||
|
||||
void ConfigFile::writeCommonly(QString message){
|
||||
bool ConfigFile::writeCommonly(QString message){
|
||||
QSettings *m_qSettings=new QSettings(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf",QSettings::IniFormat);
|
||||
QStringList messagelist=message.split("/");
|
||||
QString appname=messagelist.last();
|
||||
if(!appname.contains("desktop"))
|
||||
return;
|
||||
return false;
|
||||
m_qSettings->beginGroup("Commonly");
|
||||
QStringList quickly=m_qSettings->allKeys();
|
||||
if(quickly.contains(message)){
|
||||
if(quickly.contains(message.mid(1, message.length()-1))){
|
||||
m_qSettings->setValue(message,m_qSettings->value(message).toInt()+1);
|
||||
}else{
|
||||
m_qSettings->setValue(message,1);
|
||||
}
|
||||
m_qSettings->endGroup();
|
||||
if(m_qSettings)
|
||||
delete m_qSettings;
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList ConfigFile::readCommonly(){
|
||||
|
@ -28,7 +31,6 @@ QStringList ConfigFile::readCommonly(){
|
|||
m_qSettings->endGroup();
|
||||
QMap<QString, int>::iterator iter =quicklycount.begin();
|
||||
QVector<QPair<QString, int>> vec;
|
||||
QString iconamePah;
|
||||
while(iter !=quicklycount.end()) {
|
||||
vec.push_back(qMakePair(iter.key(), iter.value()));
|
||||
iter++;
|
||||
|
@ -37,14 +39,14 @@ QStringList ConfigFile::readCommonly(){
|
|||
return (l.second > r.second);
|
||||
});
|
||||
for(int j=0;j<vec.size();j++){
|
||||
returnlist.append(vec.at(j).first);
|
||||
returnlist.append("/" + vec.at(j).first);
|
||||
}
|
||||
if(m_qSettings)
|
||||
delete m_qSettings;
|
||||
return returnlist;
|
||||
return returnlist.mid(0, 4);
|
||||
}
|
||||
|
||||
void ConfigFile::writeRecently(QString message){
|
||||
bool ConfigFile::writeRecently(QString message){
|
||||
QSettings *m_qSettings=new QSettings(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf",QSettings::IniFormat);
|
||||
|
||||
m_qSettings->beginGroup("Recently");
|
||||
|
@ -54,11 +56,18 @@ void ConfigFile::writeRecently(QString message){
|
|||
recently.removeOne(message);
|
||||
}
|
||||
recently.insert(0,message);
|
||||
|
||||
m_qSettings->beginGroup("Recently");
|
||||
qWarning()<<m_qSettings->value("Recently").toStringList().length();
|
||||
if (m_qSettings->value("Recently").toStringList().length() >= 20) {
|
||||
m_qSettings->setValue("Recently",QStringList(recently.mid(0, 20)));
|
||||
} else {
|
||||
m_qSettings->setValue("Recently",recently);
|
||||
}
|
||||
m_qSettings->endGroup();
|
||||
if(m_qSettings)
|
||||
delete m_qSettings;
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList ConfigFile::readRecently(){
|
||||
|
@ -69,12 +78,13 @@ QStringList ConfigFile::readRecently(){
|
|||
m_qSettings->endGroup();
|
||||
if(m_qSettings)
|
||||
delete m_qSettings;
|
||||
return recently;
|
||||
return recently.mid(0, 4);
|
||||
}
|
||||
|
||||
void ConfigFile::writeConfig(QString message){
|
||||
writeCommonly(message);
|
||||
writeRecently(message);
|
||||
bool ConfigFile::writeConfig(QString message){
|
||||
bool isWriteCommonlyDone = writeCommonly(message);
|
||||
bool isWriteRecentlyDone = writeRecently(message);
|
||||
return (isWriteCommonlyDone || isWriteRecentlyDone);
|
||||
}
|
||||
|
||||
QMap<QString,QStringList> ConfigFile::readConfig(){
|
||||
|
|
|
@ -10,13 +10,13 @@ class ConfigFile : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void writeConfig(QString message);
|
||||
static bool writeConfig(QString message);
|
||||
static QMap<QString,QStringList> readConfig();
|
||||
static void receiveMessage(QString message);
|
||||
private:
|
||||
static void writeCommonly(QString message);
|
||||
static bool writeCommonly(QString message);
|
||||
static QStringList readCommonly();
|
||||
static void writeRecently(QString message);
|
||||
static bool writeRecently(QString message);
|
||||
static QStringList readRecently();
|
||||
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include "config-file.h"
|
||||
|
||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -75,6 +76,7 @@ QString SearchDetailView::getHtmlText(const QString & text, const QString & keyw
|
|||
htmlString.append(QString(text.at(i)));
|
||||
}
|
||||
}
|
||||
htmlString.replace("\n", "<br />");//替换换行符
|
||||
return htmlString;
|
||||
}
|
||||
|
||||
|
@ -241,6 +243,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
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);
|
||||
writeConfigFile(path);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
@ -252,6 +255,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
writeConfigFile(path);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
@ -262,6 +266,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
writeConfigFile(path);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
@ -270,6 +275,17 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::writeConfigFile 将打开过的文件或应用或配置项记录下来并发出刷新Homepage的请求
|
||||
* @param path 待写入的文件路径
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::writeConfigFile(const QString& path) {
|
||||
if (ConfigFile::writeConfig(path)) {
|
||||
Q_EMIT this->configFileChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::addDesktopShortcut 添加到桌面快捷方式
|
||||
* @return
|
||||
|
|
|
@ -25,8 +25,10 @@ private:
|
|||
bool openPathAction(const QString&);
|
||||
bool copyPathAction(const QString&);
|
||||
QString getHtmlText(const QString&, const QString&);
|
||||
Q_SIGNALS:
|
||||
bool writeConfigFile(const QString&);
|
||||
|
||||
Q_SIGNALS:
|
||||
void configFileChanged();
|
||||
private Q_SLOTS:
|
||||
void execActions(const int&, const int&, const QString&);
|
||||
};
|
||||
|
|
|
@ -181,22 +181,7 @@ void MainWindow::initUi()
|
|||
});
|
||||
|
||||
//初始化homepage
|
||||
QVector<QStringList> 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<<QString("%1/下载").arg(QDir::homePath())<<"/home/zjp/ukui/NM/v10/kylin-nm/README.md"<<"Theme/主题/更改壁纸"<<"/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);
|
||||
m_contentFrame->initHomePage();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue