summaryrefslogtreecommitdiffstats
path: root/kitchensync/src/configguildap.cpp
blob: b5ebd02ea0a91e69641c41c44c0124e6d05fb87e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
    This file is part of KitchenSync.

    Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    USA.
*/

#include "configguildap.h"

#include <tqcheckbox.h>
#include <tqdom.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqspinbox.h>

#include <kcombobox.h>
#include <kdialog.h>
#include <klineedit.h>
#include <klocale.h>

ConfigGuiLdap::ConfigGuiLdap( const QSync::Member &member, TQWidget *tqparent )
  : ConfigGui( member, tqparent )
{
  initGUI();

  mSearchScope->insertItem( i18n( "Base" ) );
  mSearchScope->insertItem( i18n( "One" ) );
  mSearchScope->insertItem( i18n( "Sub" ) );
}

void ConfigGuiLdap::load( const TQString &xml )
{
  TQDomDocument doc;
  doc.setContent( xml );
  TQDomElement docElement = doc.documentElement();
  TQDomNode node;
  for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
    TQDomElement element = node.toElement();
    if ( element.tagName() == "servername" ) {
      mLdapWidget->setHost( element.text() );
    } else if ( element.tagName() == "serverport" ) {
      mLdapWidget->setPort( element.text().toInt() );
    } else if ( element.tagName() == "binddn" ) {
      mLdapWidget->setBindDN( element.text() );
    } else if ( element.tagName() == "password" ) {
      mLdapWidget->setPassword( element.text() );
    } else if ( element.tagName() == "anonymous" ) { 
        mLdapWidget->setAuthAnon( element.text().toInt() == 1 );
    } else if ( element.tagName() == "searchbase" ) {
      mLdapWidget->setDn( element.text() );
    } else if ( element.tagName() == "searchfilter" ) {
      mLdapWidget->setFilter( element.text() );
    } else if ( element.tagName() == "storebase" ) {
      mLdapWidget->setDn( element.text() );
    } else if ( element.tagName() == "keyattr" ) {
      mKeyAttribute->setText( element.text() );
    } else if ( element.tagName() == "scope" ) {
      TQStringList list;
      list << "base" << "one" << "sub";
      for ( uint i = 0; i < list.count(); ++i )
        if ( list[ i ] == element.text() )
          mSearchScope->setCurrentItem( i );

    } else if ( element.tagName() == "authmech" ) {
      if ( element.text() == "SIMPLE" ) {
        mLdapWidget->setAuthSimple( true );
      }
    } else if ( element.tagName() == "encryption" ) {
        mEncryption->setChecked( element.text().toInt() == 1 );
    } else if ( element.tagName() == "ldap_read" ) {
      mReadLdap->setChecked( element.text().toInt() == 1 );
    } else if ( element.tagName() == "ldap_write" ) {
      mWriteLdap->setChecked( element.text().toInt() == 1 );
    }
  }
}

TQString ConfigGuiLdap::save() const
{
  TQString config = "<config>\n";

  config += TQString( "<servername>%1</servername>\n" ).tqarg( mLdapWidget->host() );
  config += TQString( "<serverport>%1</serverport>\n" ).tqarg( mLdapWidget->port() );
  config += TQString( "<binddn>%1</binddn>\n" ).tqarg( mLdapWidget->bindDN() );
  config += TQString( "<password>%1</password>\n" ).tqarg( mLdapWidget->password() );
  config += TQString( "<anonymous>%1</anonymous>\n" ).tqarg( mLdapWidget->isAuthAnon() ? "1" : "0" );
  config += TQString( "<searchbase>%1</searchbase>\n" ).tqarg( mLdapWidget->dn() );
  config += TQString( "<searchfilter>%1</searchfilter>\n" ).tqarg( mLdapWidget->filter() );
  config += TQString( "<storebase>%1</storebase>\n" ).tqarg( mLdapWidget->dn() );
  config += TQString( "<keyattr>%1</keyattr>\n" ).tqarg( mKeyAttribute->text() );

  TQStringList scopes;
  scopes << "base" << "one" << "sub";

  config += TQString( "<scope>%1</scope>\n" ).tqarg( scopes[ mSearchScope->currentItem() ] );

  config += TQString( "<authmech>SIMPLE</authmech>\n" );
  config += TQString( "<encryption>%1</encryption>\n" ).tqarg( mEncryption->isChecked() ? "1" : "0" );

  config += TQString( "<ldap_read>%1</ldap_read>\n" ).tqarg( mReadLdap->isChecked() ? "1" : "0" );
  config += TQString( "<ldap_write>%1</ldap_write>\n" ).tqarg( mWriteLdap->isChecked() ? "1" : "0" );

  config += "</config>";

  return config;
}

void ConfigGuiLdap::initGUI()
{
  TQGridLayout *tqlayout = new TQGridLayout( topLayout(), 12, 4, KDialog::spacingHint() );
  tqlayout->setMargin( KDialog::marginHint() );

  mLdapWidget = new KABC::LdapConfigWidget( KABC::LdapConfigWidget::W_HOST |
                                            KABC::LdapConfigWidget::W_PORT |
                                            KABC::LdapConfigWidget::W_USER |
                                            KABC::LdapConfigWidget::W_PASS |
                                            KABC::LdapConfigWidget::W_BINDDN |
                                            KABC::LdapConfigWidget::W_DN |
                                            KABC::LdapConfigWidget::W_FILTER |
                                            KABC::LdapConfigWidget::W_AUTHBOX, this );

  mKeyAttribute = new KLineEdit( this );
  mSearchScope = new KComboBox( this );
  mEncryption = new TQCheckBox( i18n( "Use encryption" ), this );
  mReadLdap = new TQCheckBox( i18n( "Load data from LDAP" ), this );
  mWriteLdap = new TQCheckBox( i18n( "Save data to LDAP" ), this );

  tqlayout->addMultiCellWidget( mLdapWidget, 0, 9, 0, 3 );
  tqlayout->addWidget( new TQLabel( i18n( "Key Attribute:" ), this ), 10, 0 );
  tqlayout->addMultiCellWidget( mKeyAttribute, 10, 10, 1, 2 );
  tqlayout->addWidget( new TQLabel( i18n( "Search Scope:" ), this ), 11, 0 );
  tqlayout->addMultiCellWidget( mSearchScope, 11, 11, 1, 2 );
  tqlayout->addWidget( mEncryption, 12, 0 );
  tqlayout->addWidget( mReadLdap, 13, 0 );
  tqlayout->addWidget( mWriteLdap, 13, 3 );

}

#include "configguildap.moc"