diff --git a/src/control/config-file.cpp b/src/control/config-file.cpp index 4acb11e..b1817a2 100644 --- a/src/control/config-file.cpp +++ b/src/control/config-file.cpp @@ -1,19 +1,7 @@ #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){ + 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")) @@ -29,6 +17,7 @@ void ConfigFile::writeCommonly(QString message){ } QStringList ConfigFile::readCommonly(){ + QSettings *m_qSettings=new QSettings(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf",QSettings::IniFormat); QStringList returnlist; QMap quicklycount; m_qSettings->beginGroup("Commonly"); @@ -50,42 +39,57 @@ QStringList ConfigFile::readCommonly(){ for(int j=0;jbeginGroup("Recently"); QStringList recently=m_qSettings->value("Recently").toStringList(); m_qSettings->endGroup(); + if(recently.contains(message)){ + recently.removeOne(message); + } recently.insert(0,message); m_qSettings->beginGroup("Recently"); m_qSettings->setValue("Recently",recently); m_qSettings->endGroup(); + if(m_qSettings) + delete m_qSettings; } QStringList ConfigFile::readRecently(){ + QSettings *m_qSettings=new QSettings(QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search.conf",QSettings::IniFormat); + 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()< readConfig(); - + static void writeConfig(QString message); + static QMap readConfig(); + static void receiveMessage(QString message); 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: + static void writeCommonly(QString message); + static QStringList readCommonly(); + static void writeRecently(QString message); + static QStringList readRecently(); };