forked from openkylin/ukui-search
Home page features
This commit is contained in:
parent
de591ea6f9
commit
e91224383e
|
@ -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<QString,int> quicklycount;
|
||||
m_qSettings->beginGroup("Commonly");
|
||||
QStringList Commonly=m_qSettings->allKeys();
|
||||
for(int i=0;i<Commonly.size();i++){
|
||||
quicklycount.insert(Commonly.at(i),m_qSettings->value(Commonly.at(i)).toInt());
|
||||
}
|
||||
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++;
|
||||
}
|
||||
qSort(vec.begin(), vec.end(), [](const QPair<QString, int> &l, const QPair<QString, int> &r) {
|
||||
return (l.second > r.second);
|
||||
});
|
||||
for(int j=0;j<vec.size();j++){
|
||||
returnlist.append(vec.at(j).first);
|
||||
}
|
||||
// qDebug()<<returnlist;
|
||||
return returnlist;
|
||||
}
|
||||
|
||||
void ConfigFile::writeRecently(QString message){
|
||||
m_qSettings->beginGroup("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()<<recently;
|
||||
return recently;
|
||||
}
|
||||
|
||||
void ConfigFile::writeConfig(){
|
||||
writeCommonly(m_message);
|
||||
writeRecently(m_message);
|
||||
}
|
||||
|
||||
QMap<QString,QStringList> ConfigFile::readConfig(){
|
||||
QMap<QString,QStringList> returnresult;
|
||||
returnresult.insert("Commonly",readCommonly());
|
||||
returnresult.insert("Recently",readRecently());
|
||||
// qDebug()<<returnresult;
|
||||
return returnresult;
|
||||
}
|
||||
|
||||
void ConfigFile::receiveMessage(QString message){
|
||||
m_message=message;
|
||||
writeConfig();
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef CONFIGFILE_H
|
||||
#define CONFIGFILE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
class ConfigFile : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConfigFile(QObject *parent = nullptr);
|
||||
void writeConfig();
|
||||
QMap<QString,QStringList> 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
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in New Issue