From e91224383eca2ce93d141b051ce03cb7b4c29a67 Mon Sep 17 00:00:00 2001 From: sunfengsheng <327123947@qq.com> Date: Tue, 29 Dec 2020 04:04:54 -0800 Subject: [PATCH] Home page features --- control/config-file.cpp | 90 +++++++++++++++++++++++++++++++++++++++++ control/config-file.h | 35 ++++++++++++++++ control/control.pri | 2 + 3 files changed, 127 insertions(+) create mode 100644 control/config-file.cpp create mode 100644 control/config-file.h diff --git a/control/config-file.cpp b/control/config-file.cpp new file mode 100644 index 0000000..0c47d34 --- /dev/null +++ b/control/config-file.cpp @@ -0,0 +1,90 @@ +#include "config-file.h" + +ConfigFile::ConfigFile(QObject *parent) : QObject(parent) +{ + QFile file(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf"); + if(!file.exists()){ + file.open( QIODevice::ReadWrite | QIODevice::Text ); + file.close(); + } + m_qSettings=new QSettings(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf",QSettings::IniFormat); + receiveMessage("ukui-panel");//测试使用 + receiveMessage("ukui-panel.desktop");//测试使用 + readConfig();//页面调用 +} + +void ConfigFile::writeCommonly(QString message){ + QStringList messagelist=message.split("/"); + QString appname=messagelist.last(); + if(!appname.contains("desktop")) + return; + m_qSettings->beginGroup("Commonly"); + QStringList quickly=m_qSettings->allKeys(); + if(quickly.contains(message)){ + m_qSettings->setValue(message,m_qSettings->value(message).toInt()+1); + }else{ + m_qSettings->setValue(message,1); + } + m_qSettings->endGroup(); +} + +QStringList ConfigFile::readCommonly(){ + QStringList returnlist; + QMap quicklycount; + m_qSettings->beginGroup("Commonly"); + QStringList Commonly=m_qSettings->allKeys(); + for(int i=0;ivalue(Commonly.at(i)).toInt()); + } + m_qSettings->endGroup(); + QMap::iterator iter =quicklycount.begin(); + QVector> vec; + QString iconamePah; + while(iter !=quicklycount.end()) { + vec.push_back(qMakePair(iter.key(), iter.value())); + iter++; + } + qSort(vec.begin(), vec.end(), [](const QPair &l, const QPair &r) { + return (l.second > r.second); + }); + for(int j=0;jbeginGroup("Recently"); + QStringList recently=m_qSettings->value("Recently").toStringList(); + m_qSettings->endGroup(); + recently.insert(0,message); + m_qSettings->beginGroup("Recently"); + m_qSettings->setValue("Recently",recently); + m_qSettings->endGroup(); +} +QStringList ConfigFile::readRecently(){ + m_qSettings->beginGroup("Recently"); + QStringList recently=m_qSettings->value("Recently").toStringList(); + m_qSettings->endGroup(); +// qDebug()< ConfigFile::readConfig(){ + QMap returnresult; + returnresult.insert("Commonly",readCommonly()); + returnresult.insert("Recently",readRecently()); +// qDebug()< +#include +#include +#include +#include +class ConfigFile : public QObject +{ + Q_OBJECT +public: + explicit ConfigFile(QObject *parent = nullptr); + void writeConfig(); + QMap readConfig(); + +private: + QSettings *m_qSettings; + QString m_message; + +private: + void writeCommonly(QString message); + QStringList readCommonly(); + void writeRecently(QString message); + QStringList readRecently(); + + +public Q_SLOTS: + void receiveMessage(QString message); + +Q_SIGNALS: + +}; + +#endif // CONFIGFILE_H diff --git a/control/control.pri b/control/control.pri index 5f7bb1a..ba747d4 100644 --- a/control/control.pri +++ b/control/control.pri @@ -1,12 +1,14 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/config-file.h \ $$PWD/search-list-view.h \ $$PWD/search-detail-view.h \ $$PWD/option-view.h \ $$PWD/home-page-item.h \ SOURCES += \ + $$PWD/config-file.cpp \ $$PWD/search-list-view.cpp \ $$PWD/search-detail-view.cpp \ $$PWD/option-view.cpp \