Index: sources/storage/Settings.cpp =================================================================== diff -u -r465a935949a85d3d1bebd11979737ff38ef96122 -r35db01154f90ebfdb6174033a66f5c20af82e14d --- sources/storage/Settings.cpp (.../Settings.cpp) (revision 465a935949a85d3d1bebd11979737ff38ef96122) +++ sources/storage/Settings.cpp (.../Settings.cpp) (revision 35db01154f90ebfdb6174033a66f5c20af82e14d) @@ -88,28 +88,54 @@ } for (const auto &detail : details) { + bool enableDuplicateKey = false; + QString attribute = QString("%1%2").arg(_config_attribute_tag); QString group = ""; QStringList lines = detail.content.split('\n'); for (QString line : lines) { - // ignore empty lines - if ( line.trimmed().isEmpty() ) continue; + // ----- trim the line + line = line.trimmed(); - // remove comments + // ----- ignore empty lines + if ( line.isEmpty() ) continue; + + // ----- find comments int commentPosition = line.indexOf('#'); - if ( commentPosition == 0 ) continue; // comment line - if ( commentPosition > 0 ) // inline comment - line.truncate(commentPosition); + + // ----- ignore comment line or find attributes + if ( commentPosition == 0 ) { + + // ----- find the configuration file attribute + int attributeTagPosition = line.indexOf(_config_attribute_tag); + if ( attributeTagPosition == 0 ) { + + // ----- find the attribute : duplicate_key_... + if ( line == attribute.arg( _duplicate_key_on ) ) { enableDuplicateKey = true ;} + else if ( line == attribute.arg(_duplicate_key_off ) ) { enableDuplicateKey = false ;} + + else { + LOG_EVENT_UI(( "Unknown '" + line + "' attribute in %1").arg(detail.category)); + } + } + + // next line + continue; + } + + // ----- remove inline comment + if ( commentPosition > 0 ) line.truncate(commentPosition); + + // ----- find group if (line.contains("[") && line.contains("]")) { line.replace("[","").replace("]", ""); - group = line.trimmed(); + group = line; } else { if ( group.isEmpty() ) { continue; } else { - line = line.trimmed(); if ( ! line.isEmpty() ) { QString key = ""; QString value = ""; @@ -121,7 +147,7 @@ else { key = line; } - _Settings.add(group, key, QVariant(value), detail.location, detail.category); + _Settings.add(group, key, QVariant(value), detail.location, detail.category, enableDuplicateKey); // DEBUG: qDebug() << group << key << value << location << category; } } @@ -145,7 +171,11 @@ // << vValue; QString mFileName = fileName(vCategory); QString mContent; - _Settings.add(vGroup, vKey, vValue,"", vCategory); + // -------------------------------------------------------------------------------------------------------------- + //Note: the configuration files which can be saved, are like settings and should not have duplicate values. + // as an example the Alarm volume can't have two separate duplicate entry in the settings. + // -------------------------------------------------------------------------------------------------------------- + _Settings.add(vGroup, vKey, vValue,"", vCategory, false); QString mPath = QFileInfo(mFileName).absolutePath(); if ( mPath.trimmed().isEmpty() ) { LOG_DEBUG("The settings path is empty.");