• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/clients

collectionattributespage.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2008 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "collectionattributespage.h"
00021 
00022 #include <akonadi/attributefactory.h>
00023 #include <akonadi/collection.h>
00024 
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027 
00028 #include <QStandardItemModel>
00029 
00030 using namespace Akonadi;
00031 
00032 CollectionAttributePage::CollectionAttributePage(QWidget * parent) :
00033     CollectionPropertiesPage( parent ),
00034     mModel( 0 )
00035 {
00036   setPageTitle( i18n( "Attributes" ) );
00037   ui.setupUi( this );
00038 
00039   connect( ui.addButton, SIGNAL(clicked()), SLOT(addAttribute()) );
00040   connect( ui.deleteButton, SIGNAL(clicked()), SLOT(delAttribute()) );
00041 }
00042 
00043 void CollectionAttributePage::load(const Collection & col)
00044 {
00045   Attribute::List list = col.attributes();
00046   mModel = new QStandardItemModel( list.count(), 2 );
00047   QStringList labels;
00048   labels << i18n( "Attribute" ) << i18n( "Value" );
00049   mModel->setHorizontalHeaderLabels( labels );
00050 
00051   for ( int i = 0; i < list.count(); ++i ) {
00052     QModelIndex index = mModel->index( i, 0 );
00053     Q_ASSERT( index.isValid() );
00054     mModel->setData( index, QString::fromLatin1( list[i]->type() ) );
00055     mModel->item( i, 0 )->setEditable( false );
00056     index = mModel->index( i, 1 );
00057     Q_ASSERT( index.isValid() );
00058     mModel->setData( index, QString::fromLatin1( list[i]->serialized() ) );
00059     mModel->itemFromIndex( index )->setFlags( Qt::ItemIsEditable | mModel->flags( index ) );
00060   }
00061   ui.attrView->setModel( mModel );
00062   connect( mModel, SIGNAL(itemChanged(QStandardItem*)), SLOT(attributeChanged(QStandardItem*)) );
00063 }
00064 
00065 void CollectionAttributePage::save(Collection & col)
00066 {
00067   foreach ( const QString &del, mDeleted )
00068     col.removeAttribute( del.toLatin1() );
00069   for ( int i = 0; i < mModel->rowCount(); ++i ) {
00070     const QModelIndex typeIndex = mModel->index( i, 0 );
00071     Q_ASSERT( typeIndex.isValid() );
00072     if ( !mChanged.contains( typeIndex.data().toString() ) )
00073       continue;
00074     const QModelIndex valueIndex = mModel->index( i, 1 );
00075     Q_ASSERT( valueIndex.isValid() );
00076     Attribute* attr = AttributeFactory::createAttribute( mModel->data( typeIndex ).toString().toLatin1() );
00077     Q_ASSERT( attr );
00078     attr->deserialize( mModel->data( valueIndex ).toString().toLatin1() );
00079     col.addAttribute( attr );
00080   }
00081 }
00082 
00083 void CollectionAttributePage::addAttribute()
00084 {
00085   if ( ui.attrName->text().isEmpty() )
00086     return;
00087   const QString attr = ui.attrName->text();
00088   mChanged.insert( attr );
00089   mDeleted.remove( attr );
00090   const int row = mModel->rowCount();
00091   mModel->insertRow( row );
00092   QModelIndex index = mModel->index( row, 0 );
00093   Q_ASSERT( index.isValid() );
00094   mModel->setData( index, attr );
00095   ui.attrName->clear();
00096 }
00097 
00098 void CollectionAttributePage::delAttribute()
00099 {
00100   QModelIndexList selection = ui.attrView->selectionModel()->selectedRows();
00101   if ( selection.count() != 1 )
00102     return;
00103   const QString attr = selection.first().data().toString();
00104   mChanged.remove( attr );
00105   mDeleted.insert( attr );
00106   mModel->removeRow( selection.first().row() );
00107 }
00108 
00109 void CollectionAttributePage::attributeChanged( QStandardItem *item )
00110 {
00111   const QString attr = mModel->data( mModel->index( item->row(), 0 ) ).toString();
00112   mDeleted.remove( attr );
00113   mChanged.insert( attr );
00114 }
00115 
00116 #include "collectionattributespage.moc"

akonadi/clients

Skip menu "akonadi/clients"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal