diff --git a/app/gui/oven_control/config.cpp b/app/gui/oven_control/config.cpp index 8b79997..15aace2 100644 --- a/app/gui/oven_control/config.cpp +++ b/app/gui/oven_control/config.cpp @@ -30,6 +30,7 @@ Config::Config(QObject *parent) : QObject(parent) { memcpy(config_format,config_format_kr,MAX_CONFIG_COUNT*64); loadConfig(); + loadFavorite(); // m_setFavorite.insert(2); // m_setFavorite.insert(3); // m_setFavorite.insert(1); @@ -253,11 +254,48 @@ QList Config::getConstSortedFavorite(){ } bool Config::loadFavorite(void){ - + bool rst; + uint32_t itemp; + QFile file(FAVORITE_FILE_NAME); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)){ + m_setFavorite.clear(); + while(!file.atEnd()){ + QByteArray line = file.readLine(); + QString strTemp = tr(line); + itemp = strTemp.toInt(&rst,10); + if(rst && itemp < (uint32_t)config_invalid) { + m_setFavorite.insert(itemp); + qDebug()<< "load favorite index " << itemp; + } + } + file.close(); + qDebug() << "loading Favorite Menu Success"; + } + else{ + qDebug() << "Favorite File Not Found"; + } return false; } bool Config::saveFavorite(void){ + bool rst; + uint32_t itemp; + QFile file(FAVORITE_FILE_NAME); + if(file.open(QIODevice::WriteOnly | QIODevice::Text)){ + QTextStream out(&file); + QSetIterator itr(m_setFavorite); + while(itr.hasNext()){ + itemp = itr.next(); + out << itemp << "\n"; + qDebug() << "save favorite index" << itemp; + } + file.close(); + qDebug()<<"saving Favorite menu success"; + return true; + } + else{ + qDebug() << "saving favorite fail"; + } return false; } diff --git a/app/gui/oven_control/configwindow.cpp b/app/gui/oven_control/configwindow.cpp index 04c50d6..8c1e924 100644 --- a/app/gui/oven_control/configwindow.cpp +++ b/app/gui/oven_control/configwindow.cpp @@ -60,9 +60,11 @@ void ConfigWindow::on_backButton_clicked() dlg->exec(); if(dlg->result() == QDialog::Accepted){ cfg->saveConfig(); + cfg->saveFavorite(); } else{ cfg->loadConfig(); + cfg->loadFavorite(); } close(); }