Sync/SyncEvoStorageModel.cpp
/*
 * Process a single config:
 * 1. Decide whether this config is to be processed at all.
 * 2. If yes, create one row for each recognized source in this config.
 *    A source, such as "source/calendar" is "recognized", if we can give it a friendly name.
 *
 *    Friendly names are currently defined in the static hash table SyncEvoStatic::instance()->storageTypes().
 *
 *    The header, which is the "source" whose name is "", is copied to each row.
 *
 *    The rows are grouped by storage type. A separate array, m_storageTypeIndices, keeps track
 *    of where in the main array a given storage type ends, so that when a row of that type is
 *    to be added, it is added there, and the m_storageTypeIndices entry for that storage type,
 *    as well as the entries for each subsequent storage type are incremented.
 *
 * FIXME: Could this be done using references, to avoid all the copying/duplication?
 */
Process a single config:
1. Decide whether this config is to be processed at all.
2. If yes, create one row for each recognized source in this config.
A source, such as "source/calendar" is "recognized", if we can give it a friendly name.

Friendly names are currently defined in the static hash table SyncEvoStatic::instance()->storageTypes().

The header, which is the "source" whose name is "", is copied to each row.

The rows are grouped by storage type. A separate array, m_storageTypeIndices, keeps track
of where in the main array a given storage type ends, so that when a row of that type is
to be added, it is added there, and the m_storageTypeIndices entry for that storage type,
as well as the entries for each subsequent storage type are incremented.


Process a single config : 1 . Decide whether this config is to be processed at all . 2 . If yes create one row for each recognized source in this config . A source such as " source / calendar " is " recognized " if we can give it a friendly name . Friendly names are currently defined in the static hash table SyncEvoStatic :: instance () - > storageTypes () . The header which is the " source " whose name is " " is copied to each row . The rows are grouped by storage type . A separate array m_storageTypeIndices keeps track of where in the main array a given storage type ends so that when a row of that type is to be added it is added there and the m_storageTypeIndices entry for that storage type as well as the entries for each subsequent storage type are incremented .
void
MeeGo::Sync::SyncEvoStorageModel::maybeAddToList(const QString &configName, const QStringMultiMap &config, bool isTemplate)
{
  if (configName.startsWith("source-config@"))
    return;
  if (!config.contains(""))
    return;
  if (!config[""].contains("ConsumerReady") || config[""]["ConsumerReady"] != "1")
      return;
  QMapIterator<QString, QStringMap> itr(config);
  while(itr.hasNext()) {
    itr.next();
    if (SyncEvoStatic::instance()->storageTypes().contains(itr.key())) {
      if (itr.value().contains("sync") && itr.value()["sync"] != "disabled") {
        SyncEvoStorageModelItem newItem = SyncEvoStorageModelItem(configName, itr.key(), config[""], itr.value(), isTemplate);
        bool replace = false;
        int storageTypeIdx = -1;
        int idxInsert = getInsertIndex(newItem, &replace, &storageTypeIdx);
        if (idxInsert >= 0) {
          if (replace) {
            m_l[idxInsert] = newItem;
            emit dataChanged(index(idxInsert, 0), index(idxInsert, 0));
          }
          else {
            beginInsertRows(QModelIndex(), idxInsert, idxInsert);
            m_l.insert(idxInsert, newItem);
            for (int Nix = storageTypeIdx ; Nix < m_storageTypeIndices.count() ; Nix++)
              m_storageTypeIndices[Nix].set(m_storageTypeIndices[Nix].value().toInt() + 1);
            endInsertRows();
          }
        }
      }
    }
  }
}
void MeeGo :: Sync :: SyncEvoStorageModel :: maybeAddToList ( const QString & configName , const QStringMultiMap & config , bool isTemplate ) { if ( configName . startsWith ( " " ) ) return ; if ( ! config . contains ( " " ) ) return ; if ( ! config [ " " ] . contains ( " " ) || config [ " " ] [ " " ] != " " ) return ; QMapIterator < QString , QStringMap > itr ( config ) ; while ( itr . hasNext ( ) ) { itr . next ( ) ; if ( SyncEvoStatic :: instance ( ) -> storageTypes ( ) . contains ( itr . key ( ) ) ) { if ( itr . value ( ) . contains ( " " ) && itr . value ( ) [ " " ] != " " ) { SyncEvoStorageModelItem newItem = SyncEvoStorageModelItem ( configName , itr . key ( ) , config [ " " ] , itr . value ( ) , isTemplate ) ; bool replace = false ; int storageTypeIdx = -1 ; int idxInsert = getInsertIndex ( newItem , & replace , & storageTypeIdx ) ; if ( idxInsert >= 0 ) { if ( replace ) { m_l [ idxInsert ] = newItem ; emit dataChanged ( index ( idxInsert , 0 ) , index ( idxInsert , 0 ) ) ; } else { beginInsertRows ( QModelIndex ( ) , idxInsert , idxInsert ) ; m_l . insert ( idxInsert , newItem ) ; for ( int Nix = storageTypeIdx ; Nix < m_storageTypeIndices . count ( ) ; Nix ++ ) m_storageTypeIndices [ Nix ] . set ( m_storageTypeIndices [ Nix ] . value ( ) . toInt ( ) + 1 ) ; endInsertRows ( ) ; } } } } } }
Process a single config:
 1.
Process a single config : 1 .
/* Not interested if it's a local config for some other config */ /* Not interested if there's no header */ /* Not interested if this is not "ConsumerReady" */ /* For each source associated with this config ... */ /* If this type of source is recognized ... */ /* If the source has "sync" defined ... */ /* Insert the value */ /* ... and increment the index indicating where the current and all the subsequent storage types end */