rem: const QString host = KolabConfig::self()->server();   QString basedn = host;   const QString user = KolabConfig::self()->user(); int pos = user.find( "@" ); if ( pos > 0 ) { const QString h = user.mid( pos+1 ); if ( !h.isEmpty() )  basedn = h; } basedn.replace(".",",dc="); basedn.prepend("dc=");   KConfig c( "kabldaprc" ); c.setGroup( "LDAP" ); bool hasMyServer = false; uint selHosts = c.readNumEntry("NumSelectedHosts", 0); for ( uint i = 0 ; i < selHosts && !hasMyServer; ++i ) if ( c.readEntry( QString("SelectedHost%1").arg(i) ) == host ) hasMyServer = true; if ( !hasMyServer ) { c.writeEntry( "NumSelectedHosts", selHosts + 1 ); c.writeEntry( QString("SelectedHost%1").arg(selHosts), host); c.writeEntry( QString("SelectedBase%1").arg(selHosts), basedn); c.writeEntry( QString("SelectedPort%1").arg(selHosts), "389"); }
add: KRES::Manager<KABC::Resource> m( "contact" ); m.readConfig(); KABC::ResourceKolab *r = new KABC::ResourceKolab( 0 ); r->setResourceName( i18n("Kolab Server") ); r->setName( "kolab-resource" ); m.add( r ); m.setStandardResource( r ); m.writeConfig();
context:     void apply()    {      const QString host = KolabConfig::self()->server();      // Figure out the basedn      QString basedn = host;      // If the user gave a full email address, the domain name      // of that overrides the server name for the ldap dn      const QString user = KolabConfig::self()->user();      int pos = user.find( "@" );      if ( pos > 0 ) {        const QString h = user.mid( pos+1 );        if ( !h.isEmpty() )          // The user did type in a domain on the email address. Use that          basedn = h;      }      basedn.replace(".",",dc=");      basedn.prepend("dc=");      // Set the changes      KConfig c( "kabldaprc" );      c.setGroup( "LDAP" );      bool hasMyServer = false;      uint selHosts = c.readNumEntry("NumSelectedHosts", 0);      for ( uint i = 0 ; i < selHosts && !hasMyServer; ++i )        if ( c.readEntry( QString("SelectedHost%1").arg(i) ) == host )          hasMyServer = true;      if ( !hasMyServer ) {        c.writeEntry( "NumSelectedHosts", selHosts + 1 );        c.writeEntry( QString("SelectedHost%1").arg(selHosts), host);        c.writeEntry( QString("SelectedBase%1").arg(selHosts), basedn);        c.writeEntry( QString("SelectedPort%1").arg(selHosts), "389");      }    }