ldapmodel.h
00001 /* 00002 This file is part of libkldap. 00003 Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KLDAP_LDAPMODEL_H 00022 #define KLDAP_LDAPMODEL_H 00023 00024 #include <QtCore/QAbstractItemModel> 00025 00026 #include "ldapconnection.h" 00027 #include "ldapobject.h" 00028 #include "kldap_export.h" 00029 00030 namespace KLDAP { 00031 00042 class KLDAP_EXPORT LdapModel : public QAbstractItemModel 00043 { 00044 Q_OBJECT 00045 public: 00046 enum Roles { 00047 NodeTypeRole = Qt::UserRole + 1 00048 }; 00049 00050 enum LdapDataType { 00051 DistinguishedName = 0, 00052 Attribute 00053 }; 00054 00063 explicit LdapModel( QObject *parent = 0 ); 00071 explicit LdapModel( LdapConnection &connection, QObject *parent = 0 ); 00072 virtual ~LdapModel(); 00073 00080 void setConnection( LdapConnection &connection ); 00081 00082 // 00083 // Implement the usual QAbstractItemModel interface 00084 // 00088 virtual QModelIndex index( int row, int col, const QModelIndex &parent ) const; 00092 virtual QModelIndex parent( const QModelIndex &child ) const; 00096 virtual QVariant data( const QModelIndex &index, int role ) const; 00101 virtual bool setData( const QModelIndex &index, 00102 const QVariant &value, 00103 int role = Qt::EditRole ); 00107 virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; 00111 virtual Qt::ItemFlags flags( const QModelIndex &index ) const; 00115 virtual int columnCount( const QModelIndex &parent ) const; 00119 virtual int rowCount( const QModelIndex &parent ) const; 00123 virtual bool hasChildren( const QModelIndex &parent ) const; 00127 virtual bool canFetchMore( const QModelIndex &parent ) const; 00131 virtual void fetchMore( const QModelIndex &parent ); 00136 virtual bool insertRows( int row, int count, 00137 const QModelIndex &parent = QModelIndex() ); 00142 virtual bool removeRows( int row, int count, 00143 const QModelIndex &parent = QModelIndex() ); 00148 virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ); 00149 00150 // 00151 // Drag and drop support 00152 // 00157 virtual Qt::DropActions supportedDropActions() const; 00162 virtual QMimeData *mimeData( const QModelIndexList &indexes ) const; 00167 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, 00168 int row, int column, const QModelIndex &parent ); 00169 00170 // 00171 // Other public utility functions 00172 // 00182 bool hasChildrenOfType( const QModelIndex &parent, LdapDataType type ) const; 00183 00184 public Q_SLOTS: 00189 virtual void revert(); 00194 virtual bool submit(); 00195 00196 Q_SIGNALS: 00204 void ready(); 00205 00206 private: 00207 class LdapModelPrivate; 00208 LdapModelPrivate *const m_d; 00209 00210 Q_PRIVATE_SLOT( m_d, void gotSearchResult( KLDAP::LdapSearch* ) ) 00211 Q_PRIVATE_SLOT( m_d, void gotSearchData( KLDAP::LdapSearch*, const KLDAP::LdapObject& ) ) 00212 }; 00213 00214 } 00215 #endif