akonadi
agenttypemodel.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "agenttypemodel.h"
00021 #include "agenttype.h"
00022 #include "agentmanager.h"
00023
00024 #include <QtCore/QStringList>
00025 #include <QtGui/QIcon>
00026
00027 using namespace Akonadi;
00028
00032 class AgentTypeModel::Private
00033 {
00034 public:
00035 Private( AgentTypeModel *parent )
00036 : mParent( parent )
00037 {
00038 mTypes = AgentManager::self()->types();
00039 }
00040
00041 AgentTypeModel *mParent;
00042 AgentType::List mTypes;
00043
00044 void typeAdded( const AgentType &agentType );
00045 void typeRemoved( const AgentType &agentType );
00046 };
00047
00048 void AgentTypeModel::Private::typeAdded( const AgentType &agentType )
00049 {
00050 mTypes.append( agentType );
00051
00052 emit mParent->layoutChanged();
00053 }
00054
00055 void AgentTypeModel::Private::typeRemoved( const AgentType &agentType )
00056 {
00057 mTypes.removeAll( agentType );
00058
00059 emit mParent->layoutChanged();
00060 }
00061
00062 AgentTypeModel::AgentTypeModel( QObject *parent )
00063 : QAbstractItemModel( parent ), d( new Private( this ) )
00064 {
00065 connect( AgentManager::self(), SIGNAL( typeAdded( const Akonadi::AgentType& ) ),
00066 this, SLOT( typeAdded( const Akonadi::AgentType& ) ) );
00067 connect( AgentManager::self(), SIGNAL( typeRemoved( const Akonadi::AgentType& ) ),
00068 this, SLOT( typeRemoved( const Akonadi::AgentType& ) ) );
00069 }
00070
00071 AgentTypeModel::~AgentTypeModel()
00072 {
00073 delete d;
00074 }
00075
00076 int AgentTypeModel::columnCount( const QModelIndex& ) const
00077 {
00078 return 1;
00079 }
00080
00081 int AgentTypeModel::rowCount( const QModelIndex& ) const
00082 {
00083 return d->mTypes.count();
00084 }
00085
00086 QVariant AgentTypeModel::data( const QModelIndex &index, int role ) const
00087 {
00088 if ( !index.isValid() )
00089 return QVariant();
00090
00091 if ( index.row() < 0 || index.row() >= d->mTypes.count() )
00092 return QVariant();
00093
00094 const AgentType &type = d->mTypes[ index.row() ];
00095
00096 switch ( role ) {
00097 case Qt::DisplayRole:
00098 return type.name();
00099 break;
00100 case Qt::DecorationRole:
00101 return type.icon();
00102 break;
00103 case TypeRole:
00104 {
00105 QVariant var;
00106 var.setValue( type );
00107 return var;
00108 }
00109 break;
00110 case IdentifierRole:
00111 return type.identifier();
00112 break;
00113 case DescriptionRole:
00114 return type.description();
00115 break;
00116 case MimeTypesRole:
00117 return type.mimeTypes();
00118 break;
00119 case CapabilitiesRole:
00120 return type.capabilities();
00121 break;
00122 default:
00123 break;
00124 }
00125 return QVariant();
00126 }
00127
00128 QModelIndex AgentTypeModel::index( int row, int column, const QModelIndex& ) const
00129 {
00130 if ( row < 0 || row >= d->mTypes.count() )
00131 return QModelIndex();
00132
00133 if ( column != 0 )
00134 return QModelIndex();
00135
00136 return createIndex( row, column, 0 );
00137 }
00138
00139 QModelIndex AgentTypeModel::parent( const QModelIndex& ) const
00140 {
00141 return QModelIndex();
00142 }
00143
00144 #include "agenttypemodel.moc"