#include "historydb.h" #include #include #include #include "mydebug.h" // cursor pointer used to ensure a single instance of the class. dbHistory* dbHistory::s_instance = 0; /* This function is called to create an instance of the class. * Calling the constructor publicly is not allowed. The constructor * is private and is only called by this Instance function. */ dbHistory* dbHistory::instance() { // Only allow one instance of class to be generated. if (!s_instance) s_instance = new dbHistory; return s_instance; } dbHistory::dbHistory() { history_folder = QApplication::applicationDirPath() + "/" DB_FOLDER_NAME; history_filedb = history_folder+'/'+DB_FILE_NAME; } //*********************************************************************** // read history from a specific folder // Input parameters: // Returns: //*********************************************************************** bool dbHistory::readHistory() { return true; } //*********************************************************************** // add new entry into db file // Input parameters: _new = new entry info // Returns: true = ok // false = error //*********************************************************************** bool dbHistory::addToDB(db_item_t _new) { QSettings settings( history_filedb, QSettings::IniFormat); if ( settings.status() == QSettings::NoError ) { //aggiorna il contatore settings.beginGroup("general"); settings.setValue("num_entry", listDBEntry.count()); settings.endGroup(); QString section = QString("entry%1").arg(listDBEntry.count()-1); settings.beginGroup(section); settings.setValue("error", _new.error); settings.setValue("name", _new.name); settings.setValue("path", _new.path); settings.setValue("status", _new.status); settings.setValue("timestamp", _new.timestamp); settings.setValue("where", _new.where); settings.setValue("flash_address",_new.flash_address); settings.setValue("srio_conn", _new.srio_conn); settings.setValue("spi", _new.spi); settings.endGroup(); settings.sync(); if(settings.status() == QSettings::NoError) return true; } return false; } //*********************************************************************** // add new file to history // Input parameters: // Returns: //*********************************************************************** bool dbHistory::addNewFile(QString _file, db_error_t _error, QString _where, db_status_t _status, QString _address, QString _srio, unsigned int _spi) { if (!QDir(history_folder).exists()) { MyDebug().logMsg(type_log_info, origin_msg_history, "History folder not present, create new one."); if (!QDir().mkdir(history_folder)) { MyDebug().logMsg(type_log_error, origin_msg_history, QString("ERROR create history folder %1").arg(history_folder)); return false; } } db_item_t entry_info; entry_info.error = _error; entry_info.name = QFileInfo(_file).completeBaseName(); QDir d = QFileInfo(_file).absoluteDir(); entry_info.path=d.absolutePath(); entry_info.status = _status; entry_info.timestamp = QDateTime::currentDateTime().toString("yyyy/MM/dd-hh:mm:ss"); entry_info.where = _where; entry_info.flash_address = _address; entry_info.srio_conn = _srio; entry_info.spi = _spi; listDBEntry.append(entry_info); if (!addToDB(entry_info)) { MyDebug().logMsg(type_log_error, origin_msg_history, QString("ERROR to save new entry %1").arg(entry_info.name)); return false; } return true; } //*********************************************************************** // add new file to history // Input parameters: // Returns: //*********************************************************************** void dbHistory::setParam(QString _host) { hostname = _host; } //*********************************************************************** // refresh list // Input parameters: // Returns: //*********************************************************************** void dbHistory::refreshList() { listDBEntry.clear(); QSettings settings( history_filedb, QSettings::IniFormat); if ( settings.status() == QSettings::NoError ) { settings.beginGroup("general"); int num_entry = settings.value("num_entry", 0).toInt(); settings.endGroup(); if (num_entry!=0) { QString section; for (int i = 0; i