21 #include "resourceldapkioconfig.h" 
   22 #include "resourceldapkio.h" 
   24 #include <kio/netaccess.h> 
   25 #include <kacceleratormanager.h> 
   26 #include <kcombobox.h> 
   28 #include <klocalizedstring.h> 
   29 #include <klineedit.h> 
   30 #include <kmessagebox.h> 
   31 #include <kpagewidget.h> 
   34 #include <QtCore/QPointer> 
   38 #include <QPushButton> 
   40 #include <QRadioButton> 
   44 ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( 
QWidget *parent )
 
   45   : KRES::ConfigWidget( parent )
 
   50   mCfg = 
new KLDAP::LdapConfigWidget(
 
   51         KLDAP::LdapConfigWidget::W_USER |
 
   52         KLDAP::LdapConfigWidget::W_PASS |
 
   53         KLDAP::LdapConfigWidget::W_BINDDN |
 
   54         KLDAP::LdapConfigWidget::W_REALM |
 
   55         KLDAP::LdapConfigWidget::W_HOST |
 
   56         KLDAP::LdapConfigWidget::W_PORT |
 
   57         KLDAP::LdapConfigWidget::W_VER |
 
   58         KLDAP::LdapConfigWidget::W_DN |
 
   59         KLDAP::LdapConfigWidget::W_FILTER |
 
   60         KLDAP::LdapConfigWidget::W_TIMELIMIT |
 
   61         KLDAP::LdapConfigWidget::W_SIZELIMIT |
 
   62         KLDAP::LdapConfigWidget::W_SECBOX |
 
   63         KLDAP::LdapConfigWidget::W_AUTHBOX,
 
   66   mSubTree = 
new QCheckBox( i18n( 
"Sub-tree query" ), 
this );
 
   67   KHBox *box = 
new KHBox( 
this );
 
   68   box->setSpacing( -1 );
 
   69   mEditButton = 
new QPushButton( i18n( 
"Edit Attributes..." ), box );
 
   70   mCacheButton = 
new QPushButton( i18n( 
"Offline Use..." ), box );
 
   76   connect( mEditButton, SIGNAL(clicked()), SLOT(editAttributes()) );
 
   77   connect( mCacheButton, SIGNAL(clicked()), SLOT(editCache()) );
 
   82   ResourceLDAPKIO *resource = 
dynamic_cast<ResourceLDAPKIO*
>( res );
 
   85     kDebug() << 
"cast failed";
 
   89   mCfg->setUser( resource->user() );
 
   90   mCfg->setPassword( resource->password() );
 
   91   mCfg->setRealm( resource->realm() );
 
   92   mCfg->setBindDn( resource->bindDN() );
 
   93   mCfg->setHost( resource->host() );
 
   94   mCfg->setPort( resource->port() );
 
   95   mCfg->setVersion( resource->ver() );
 
   96   mCfg->setTimeLimit( resource->timeLimit() );
 
   97   mCfg->setSizeLimit( resource->sizeLimit() );
 
   98   mCfg->setDn( KLDAP::LdapDN( resource->dn() ) );
 
   99   mCfg->setFilter( resource->filter() );
 
  100   mCfg->setMech( resource->mech() );
 
  101   if ( resource->isTLS() ) {
 
  102     mCfg->setSecurity( KLDAP::LdapConfigWidget::TLS );
 
  103   } 
else if ( resource->isSSL() ) {
 
  104     mCfg->setSecurity( KLDAP::LdapConfigWidget::SSL );
 
  106     mCfg->setSecurity( KLDAP::LdapConfigWidget::None );
 
  108   if ( resource->isAnonymous() ) {
 
  109     mCfg->setAuth( KLDAP::LdapConfigWidget::Anonymous );
 
  110   } 
else if ( resource->isSASL() ) {
 
  111     mCfg->setAuth( KLDAP::LdapConfigWidget::SASL );
 
  113     mCfg->setAuth( KLDAP::LdapConfigWidget::Simple );
 
  115   mSubTree->setChecked( resource->isSubTree() );
 
  116   mAttributes = resource->attributes();
 
  117   mRDNPrefix = resource->RDNPrefix();
 
  118   mCachePolicy = resource->cachePolicy();
 
  119   mCacheDst = resource->cacheDst();
 
  120   mAutoCache = resource->autoCache();
 
  125   ResourceLDAPKIO *resource = 
dynamic_cast<ResourceLDAPKIO*
>( res );
 
  128     kDebug() << 
"cast failed";
 
  132   resource->setUser( mCfg->user() );
 
  133   resource->setPassword( mCfg->password() );
 
  134   resource->setRealm( mCfg->realm() );
 
  135   resource->setBindDN( mCfg->bindDn() );
 
  136   resource->setHost( mCfg->host() );
 
  137   resource->setPort( mCfg->port() );
 
  138   resource->setVer( mCfg->version() );
 
  139   resource->setTimeLimit( mCfg->timeLimit() );
 
  140   resource->setSizeLimit( mCfg->sizeLimit() );
 
  141   resource->setDn( mCfg->dn().toString() );
 
  142   resource->setFilter( mCfg->filter() );
 
  143   resource->setIsAnonymous( mCfg->auth() ==
 
  144                             KLDAP::LdapConfigWidget::Anonymous );
 
  145   resource->setIsSASL( mCfg->auth() == KLDAP::LdapConfigWidget::SASL );
 
  146   resource->setMech( mCfg->mech() );
 
  147   resource->setIsTLS( mCfg->security() == KLDAP::LdapConfigWidget::TLS );
 
  148   resource->setIsSSL( mCfg->security() == KLDAP::LdapConfigWidget::SSL );
 
  149   resource->setIsSubTree( mSubTree->isChecked() );
 
  150   resource->setAttributes( mAttributes );
 
  151   resource->setRDNPrefix( mRDNPrefix );
 
  152   resource->setCachePolicy( mCachePolicy );
 
  157 void ResourceLDAPKIOConfig::editAttributes()
 
  160   if ( dlg->exec() && dlg ) {
 
  161     mAttributes = dlg->attributes();
 
  162     mRDNPrefix = dlg->rdnprefix();
 
  168 void ResourceLDAPKIOConfig::editCache()
 
  174   src.setScope( mSubTree->isChecked() ? KLDAP::LdapUrl::Sub : KLDAP::LdapUrl::One );
 
  175   if ( !mAttributes.empty() ) {
 
  178     for ( it = mAttributes.
begin(); it != mAttributes.
end(); ++it ) {
 
  183     src.setAttributes( attr );
 
  188   if ( dlg->exec() && dlg ) {
 
  189     mCachePolicy = dlg->cachePolicy();
 
  190     mAutoCache = dlg->autoCache();
 
  201   setCaption( i18n( 
"Attributes Configuration" ) );
 
  202   setButtons( Ok | Cancel );
 
  203   setDefaultButton( Ok );
 
  205   showButtonSeparator( 
true );
 
  207   mNameDict.insert( 
QLatin1String( 
"objectClass" ), i18n( 
"Object classes" ) );
 
  208   mNameDict.insert( 
QLatin1String( 
"commonName" ), i18n( 
"Common name" ) );
 
  209   mNameDict.insert( 
QLatin1String( 
"formattedName" ), i18n( 
"Formatted name" ) );
 
  210   mNameDict.insert( 
QLatin1String( 
"familyName" ), i18n( 
"Family name" ) );
 
  211   mNameDict.insert( 
QLatin1String( 
"givenName" ), i18n( 
"Given name" ) );
 
  212   mNameDict.insert( 
QLatin1String( 
"organization" ), i18n( 
"Organization" ) );
 
  213   mNameDict.insert( 
QLatin1String( 
"title" ), i18nc( 
"job title", 
"Title" ) );
 
  214   mNameDict.insert( 
QLatin1String( 
"street" ), i18n( 
"Street" ) );
 
  215   mNameDict.insert( 
QLatin1String( 
"state" ), i18nc( 
"state/province", 
"State" ) );
 
  217   mNameDict.insert( 
QLatin1String( 
"postalcode" ), i18n( 
"Postal code" ) );
 
  218   mNameDict.insert( 
QLatin1String( 
"mail" ), i18nc( 
"email address", 
"Email" ) );
 
  219   mNameDict.insert( 
QLatin1String( 
"mailAlias" ), i18n( 
"Email alias" ) );
 
  220   mNameDict.insert( 
QLatin1String( 
"phoneNumber" ), i18n( 
"Telephone number" ) );
 
  221   mNameDict.insert( 
QLatin1String( 
"telephoneNumber" ), i18n( 
"Work telephone number" ) );
 
  222   mNameDict.insert( 
QLatin1String( 
"facsimileTelephoneNumber" ), i18n( 
"Fax number" ) );
 
  223   mNameDict.insert( 
QLatin1String( 
"mobile" ), i18n( 
"Cell phone number" ) );
 
  224   mNameDict.insert( 
QLatin1String( 
"pager" ), i18n( 
"Pager" ) );
 
  225   mNameDict.insert( 
QLatin1String( 
"description" ), i18n( 
"Note" ) );
 
  227   mNameDict.insert( 
QLatin1String( 
"jpegPhoto" ), i18n( 
"Photo" ) );
 
  245   mDefaultMap.insert( 
QLatin1String( 
"facsimileTelephoneNumber" ),
 
  265   mMapList.append( attributes );
 
  266   mMapList.append( kolab2Map );
 
  267   mMapList.append( kolab3Map );
 
  268   mMapList.append( netscapeMap );
 
  269   mMapList.append( evolutionMap );
 
  270   mMapList.append( outlookMap );
 
  273   setMainWidget( page );
 
  276   QLabel *label = 
new QLabel( i18n( 
"Template:" ), page );
 
  278   mMapCombo = 
new KComboBox( page );
 
  281   mMapCombo->addItem( i18n( 
"User Defined" ) );
 
  282   mMapCombo->addItem( i18n( 
"Kolab 2" ) );
 
  283   mMapCombo->addItem( i18n( 
"Kolab 3" ) );
 
  284   mMapCombo->addItem( i18n( 
"Netscape" ) );
 
  285   mMapCombo->addItem( i18n( 
"Evolution" ) );
 
  286   mMapCombo->addItem( i18n( 
"Outlook" ) );
 
  287   connect( mMapCombo, SIGNAL(activated(
int)), SLOT(mapChanged(
int)) );
 
  289   label = 
new QLabel( i18n( 
"RDN prefix attribute:" ), page );
 
  291   mRDNCombo = 
new KComboBox( page );
 
  293   mRDNCombo->addItem( i18n( 
"commonName" ) );
 
  294   mRDNCombo->addItem( i18n( 
"UID" ) );
 
  295   mRDNCombo->setCurrentIndex( rdnprefix );
 
  299   for ( i = 2, it = attributes.
begin(); it != attributes.
end(); ++it, ++i ) {
 
  300     if ( mNameDict[ it.
key() ].isEmpty() ) {
 
  304     if ( ( i - 2 ) == ( mNameDict.count() >> 1 ) ) {
 
  308     kDebug() << 
"itkey:" << it.
key() << 
"i:" << i;
 
  310     KLineEdit *lineedit = 
new KLineEdit( page );
 
  311     mLineEditDict.insert( it.
key(), lineedit );
 
  312     lineedit->setText( it.
value() );
 
  318   for ( i = 1; i < mMapCombo->count(); ++i ) {
 
  320     while ( it2 != mLineEditDict.
constEnd() ) {
 
  321       if ( mMapList[ i ].contains( it2.
key() ) ) {
 
  322         if ( mMapList[ i ][ it2.
key() ] != it2.
value()->text() ) {
 
  326         if ( mDefaultMap[ it2.
key() ] != it2.
value()->text() ) {
 
  332     if ( it2 != mLineEditDict.
constEnd() ) {
 
  333       mMapCombo->setCurrentIndex( i );
 
  338   KAcceleratorManager::manage( 
this );
 
  341 AttributesDialog::~AttributesDialog()
 
  351   while ( it != mLineEditDict.
constEnd() ) {
 
  358 int AttributesDialog::rdnprefix()
 const 
  360   return mRDNCombo->currentIndex();
 
  363 void AttributesDialog::mapChanged( 
int pos )
 
  368   for ( it = mDefaultMap.
begin(); it != mDefaultMap.
end(); ++it ) {
 
  369     mLineEditDict[ it.
key() ]->setText( it.
value() );
 
  372   for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].
end(); ++it ) {
 
  373     if ( !it.
value().isEmpty() ) {
 
  374       KLineEdit *le = mLineEditDict[ it.
key() ];
 
  376         le->setText( it.
value() );
 
  382 OfflineDialog::OfflineDialog( 
bool autoCache, 
int cachePolicy, 
const KUrl &src,
 
  386   setCaption( i18n( 
"Offline Configuration" ) );
 
  387   setButtons( Ok | Cancel );
 
  388   setDefaultButton( Ok );
 
  390   showButtonSeparator( 
true );
 
  393   setMainWidget( page );
 
  398   mCacheBox = 
new QGroupBox( i18n( 
"Offline Cache Policy" ), page );
 
  404   bt = 
new QRadioButton( i18n( 
"Do not use offline cache" ), mCacheBox );
 
  407   mCacheGroup->addButton( bt );
 
  409   bt = 
new QRadioButton( i18n( 
"Use local copy if no connection" ), mCacheBox );
 
  411   mCacheGroup->addButton( bt );
 
  413   bt = 
new QRadioButton( i18n( 
"Always use local copy" ), mCacheBox );
 
  415   mCacheGroup->addButton( bt );
 
  417   if ( mCacheGroup->button( cachePolicy ) ) {
 
  418     mCacheGroup->button( cachePolicy )->setDown( 
true );
 
  421   mAutoCache = 
new QCheckBox( i18n( 
"Refresh offline cache automatically" ),
 
  423   mAutoCache->setChecked( autoCache );
 
  424   mAutoCache->setEnabled( bt->
isChecked() );
 
  426   connect( bt, SIGNAL(toggled(
bool)), mAutoCache, SLOT(setEnabled(
bool)) );
 
  429   connect( lcache, SIGNAL(clicked()), SLOT(loadCache()) );
 
  436 OfflineDialog::~OfflineDialog()
 
  440 bool OfflineDialog::autoCache()
 const 
  442   return mAutoCache->isChecked();
 
  445 int OfflineDialog::cachePolicy()
 const 
  447   return mCacheGroup->checkedId();
 
  450 void OfflineDialog::loadCache()
 
  452   if ( KIO::NetAccess::download( mSrc, mDst, 
this ) ) {
 
  453     KMessageBox::information( 
this,
 
  454       i18n( 
"Successfully downloaded directory server contents." ) );
 
  456     KMessageBox::error( 
this,
 
  457       i18n( 
"An error occurred downloading directory server contents into file %1.", mDst ) );
 
const Key key(const T &value) const
const_iterator constBegin() const
void setBuddy(QWidget *buddy)
void append(const T &value)
const_iterator constEnd() const
QFuture< void > map(Sequence &sequence, MapFunction function)
void setMargin(int margin)
const T value(const Key &key) const
const Key key(const T &value) const
const_iterator constBegin() const
iterator insert(const Key &key, const T &value)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
const T value(const Key &key) const