• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KLDAP Library

ldapobject.cpp

00001 /*
00002   This file is part of libkldap.
00003   Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
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 #include "ldapobject.h"
00022 #include "ldif.h"
00023 
00024 #include <QtCore/QSharedData>
00025 
00026 using namespace KLDAP;
00027 
00028 class LdapObject::Private : public QSharedData
00029 {
00030   public:
00031     Private()
00032     {
00033     }
00034 
00035     Private( const Private &other )
00036       : QSharedData( other )
00037     {
00038       mDn = other.mDn;
00039       mAttrs = other.mAttrs;
00040     }
00041 
00042     LdapDN mDn;
00043     LdapAttrMap mAttrs;
00044 };
00045 
00046 LdapObject::LdapObject()
00047   : d( new Private )
00048 {
00049 }
00050 
00051 LdapObject::LdapObject( const QString &dn )
00052   : d( new Private )
00053 {
00054   d->mDn = LdapDN( dn );
00055 }
00056 
00057 LdapObject::~LdapObject()
00058 {
00059 }
00060 
00061 LdapObject::LdapObject( const LdapObject &that )
00062   : d( that.d )
00063 {
00064 }
00065 
00066 LdapObject &LdapObject::operator=( const LdapObject &that )
00067 {
00068   if ( this != &that ) {
00069     d = that.d;
00070   }
00071 
00072   return *this;
00073 }
00074 
00075 void LdapObject::setDn( const LdapDN &dn )
00076 {
00077   d->mDn = dn;
00078 }
00079 
00080 void LdapObject::setDn( const QString &dn )
00081 {
00082   d->mDn = LdapDN( dn );
00083 }
00084 
00085 void LdapObject::setAttributes( const LdapAttrMap &attrs )
00086 {
00087   d->mAttrs = attrs;
00088 }
00089 
00090 LdapDN LdapObject::dn() const
00091 {
00092   return d->mDn;
00093 }
00094 
00095 const LdapAttrMap &LdapObject::attributes() const
00096 {
00097   return d->mAttrs;
00098 }
00099 
00100 QString LdapObject::toString() const
00101 {
00102   QString result = QString::fromLatin1( "dn: %1\n" ).arg( d->mDn.toString() );
00103   for ( LdapAttrMap::ConstIterator it = d->mAttrs.begin(); it != d->mAttrs.end(); ++it ) {
00104     QString attr = it.key();
00105     for ( LdapAttrValue::ConstIterator it2 = (*it).begin(); it2 != (*it).end(); ++it2 ) {
00106       result += QString::fromUtf8( Ldif::assembleLine( attr, *it2, 76 ) ) + '\n';
00107     }
00108   }
00109   return result;
00110 }
00111 
00112 void LdapObject::clear()
00113 {
00114   d->mDn.clear();
00115   d->mAttrs.clear();
00116 }
00117 
00118 void LdapObject::setValues( const QString &attributeName, const LdapAttrValue &values )
00119 {
00120   d->mAttrs[ attributeName ] = values;
00121 }
00122 
00123 void LdapObject::addValue( const QString &attributeName, const QByteArray &value )
00124 {
00125   d->mAttrs[ attributeName ].append( value );
00126 }
00127 
00128 LdapAttrValue LdapObject::values( const QString &attributeName ) const
00129 {
00130   if ( hasAttribute( attributeName ) ) {
00131     return d->mAttrs.value( attributeName );
00132   } else {
00133     return LdapAttrValue();
00134   }
00135 }
00136 
00137 QByteArray LdapObject::value( const QString &attributeName ) const
00138 {
00139   if ( hasAttribute( attributeName ) ) {
00140     return d->mAttrs.value( attributeName ).first();
00141   } else {
00142     return QByteArray();
00143   }
00144 }
00145 
00146 bool LdapObject::hasAttribute( const QString &attributeName ) const
00147 {
00148   return d->mAttrs.contains( attributeName );
00149 }

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
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