[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/akonadi/akonadi_next
From:       Kevin Ottens <ervin () kde ! org>
Date:       2009-07-20 13:33:34
Message-ID: 1248096814.229757.1486.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 999758 by ervin:

Allow to change the label of a favorite. Make the labels persistent.


 M  +52 -2     favoritecollectionsmodel.cpp  
 M  +2 -0      favoritecollectionsmodel.h  


--- trunk/KDE/kdepim/akonadi/akonadi_next/favoritecollectionsmodel.cpp #999757:999758
@@ -41,6 +41,19 @@
     {
     }
 
+    QString labelForCollection( const Collection &c )
+    {
+      if ( labelMap.contains( c.id() ) ) {
+        return labelMap[c.id()];
+      }
+
+      EntityTreeModel *model = qobject_cast<EntityTreeModel*>( q->sourceModel() );
+      Q_ASSERT( model!=0 );
+
+      QModelIndex index = model->indexForCollection( model->collectionForId( c.id() \
) ); +      return model->data(index).toString();
+    }
+
     void clearAndUpdateSelection()
     {
       q->selectionModel()->clear();
@@ -64,9 +77,13 @@
       KSharedConfigPtr config = KGlobal::config();
       KConfigGroup group = config->group( "FavoriteCollectionsModel" );
       QList<qint64> ids = group.readEntry( "FavoriteCollectionIds", QList<qint64>() \
); +      QStringList labels = group.readEntry( "FavoriteCollectionLabels", \
QStringList() );  
-      foreach ( qint64 id, ids ) {
-        collections << Collection( id );
+      for ( int i=0; i<ids.size(); ++i ) {
+        collections << Collection( ids[i] );
+        if ( i<labels.size() ) {
+          labelMap[ ids[i] ] = labels[i];
+        }
       }
 
     }
@@ -74,19 +91,24 @@
     void saveConfig()
     {
       QList<qint64> ids;
+      QStringList labels;
+
       foreach ( const Collection &c, collections ) {
         ids << c.id();
+        labels << labelForCollection( c );
       }
 
       KSharedConfigPtr config = KGlobal::config();
       KConfigGroup group = config->group( "FavoriteCollectionsModel" );
       group.writeEntry( "FavoriteCollectionIds", ids );
+      group.writeEntry( "FavoriteCollectionLabels", labels );
       config->sync();
     }
 
     FavoriteCollectionsModel * const q;
 
     Collection::List collections;
+    QHash<qint64, QString> labelMap;
 };
 
 FavoriteCollectionsModel::FavoriteCollectionsModel( EntityTreeModel *source, QObject \
*parent ) @@ -113,6 +135,7 @@
 void FavoriteCollectionsModel::setCollections( const Collection::List &collections )
 {
   d->collections = collections;
+  d->labelMap.clear();
   d->clearAndUpdateSelection();
   d->saveConfig();
 }
@@ -127,6 +150,7 @@
 void FavoriteCollectionsModel::removeCollection( const Collection &collection )
 {
   d->collections.removeAll( collection );
+  d->labelMap.remove( collection.id() );
 
   EntityTreeModel *model = qobject_cast<EntityTreeModel*>( sourceModel() );
   Q_ASSERT( model!=0 );
@@ -144,6 +168,32 @@
   return d->collections;
 }
 
+void Akonadi::FavoriteCollectionsModel::setFavoriteLabel( const Collection \
&collection, const QString &label ) +{
+  Q_ASSERT( d->collections.contains( collection ) );
+  d->labelMap[ collection.id() ] = label;
+  d->saveConfig();
+
+  EntityTreeModel *model = qobject_cast<EntityTreeModel*>( sourceModel() );
+  Q_ASSERT( model!=0 );
+
+  QModelIndex sourceIndex = model->indexForCollection( model->collectionForId( \
collection.id() ) ); +  QModelIndex index = mapFromSource( sourceIndex );
+  emit dataChanged( index, index );
+}
+
+QVariant Akonadi::FavoriteCollectionsModel::data( const QModelIndex &index, int \
role) const +{
+  if ( index.column()==0 && role == Qt::DisplayRole ) {
+    QModelIndex sourceIndex = mapToSource( index );
+    Collection c = sourceModel()->data( sourceIndex, EntityTreeModel::CollectionRole \
).value<Collection>(); +
+    return d->labelForCollection( c );
+  } else {
+    return SelectionProxyModel::data( index, role );
+  }
+}
+
 QVariant FavoriteCollectionsModel::headerData( int section, Qt::Orientation \
orientation, int role) const  {
   if ( section == 0
--- trunk/KDE/kdepim/akonadi/akonadi_next/favoritecollectionsmodel.h #999757:999758
@@ -51,10 +51,12 @@
     void setCollections( const Collection::List &collections );
     void addCollection( const Collection &collection );
     void removeCollection( const Collection &collection );
+    void setFavoriteLabel( const Collection &collection, const QString &label );
 
   public:
     Collection::List collections() const;
 
+    virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) \
                const;
     virtual QVariant headerData( int section, Qt::Orientation orientation, int role \
= Qt::DisplayRole ) const;  
   private:


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic