kitchensync

configguisyncmlhttp.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19  USA.
20 */
21 
22 #include "configguisyncmlhttp.h"
23 
24 #include <kcombobox.h>
25 #include <kdialog.h>
26 #include <klineedit.h>
27 #include <tdelocale.h>
28 #include <kurlrequester.h>
29 
30 #include <tqcheckbox.h>
31 #include <tqdom.h>
32 #include <tqlabel.h>
33 #include <tqlayout.h>
34 #include <tqspinbox.h>
35 #include <tqtabwidget.h>
36 #include <tqvbox.h>
37 
38 ConfigGuiSyncmlHttp::ConfigGuiSyncmlHttp( const QSync::Member &member, TQWidget *parent )
39  : ConfigGui( member, parent ), mUrl( 0 ), mPort( 0 )
40 {
41 
42  TQTabWidget *tabWidget = new TQTabWidget( this );
43  topLayout()->addWidget( tabWidget );
44 
45  // Connection
46  TQWidget *connectionWidget = new TQWidget( tabWidget );
47  TQVBoxLayout *connectionLayout = new TQVBoxLayout( connectionWidget,
48  KDialog::marginHint(), KDialog::spacingHint() );
49 
50  tabWidget->addTab( connectionWidget, i18n( "Connection" ) );
51 
52  mGridLayout = new TQGridLayout( connectionLayout );
53 
54  TQLabel *label = new TQLabel( i18n("Port:"), connectionWidget );
55  mGridLayout->addWidget( label, 0, 0 );
56 
57  mPort = new TQSpinBox( connectionWidget );
58  mPort->setMinValue( 1 );
59  mPort->setMaxValue( 65536 );
60  mGridLayout->addWidget( mPort, 0, 1 );
61 
62  // Database
63  TQWidget *databaseWidget = new TQWidget( tabWidget );
64  TQVBoxLayout *databaseLayout = new TQVBoxLayout( databaseWidget,
65  KDialog::marginHint(), KDialog::spacingHint() );
66 
67  tabWidget->addTab( databaseWidget, i18n( "Databases" ) );
68 
69  mGridLayout = new TQGridLayout( databaseLayout );
70  addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 );
71  addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 );
72  addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 );
73 
74  mContactDb->insertItem( "addressbook" );
75  mContactDb->insertItem( "contacts" );
76 
77  mCalendarDb->insertItem( "agenda" );
78  mCalendarDb->insertItem( "calendar" );
79 
80  mNoteDb->insertItem( "notes" );
81 
82 
83  // Options
84  TQWidget *optionWidget = new TQWidget( tabWidget );
85  TQVBoxLayout *optionLayout = new TQVBoxLayout( optionWidget,
86  KDialog::marginHint(), KDialog::spacingHint() );
87 
88  tabWidget->addTab( optionWidget, i18n( "Options" ) );
89 
90  mGridLayout = new TQGridLayout( optionLayout );
91 
92  label = new TQLabel( i18n("User name:"), optionWidget );
93  mGridLayout->addWidget( label, 0, 0 );
94 
95  mUsername = new KLineEdit( optionWidget );
96  mGridLayout->addWidget( mUsername, 0, 1 );
97 
98  label = new TQLabel( i18n("Password:"), optionWidget );
99  mGridLayout->addWidget( label, 1, 0 );
100 
101  mPassword = new KLineEdit( optionWidget );
102  mPassword->setEchoMode( TQLineEdit::Password );
103  mGridLayout->addWidget( mPassword, 1, 1 );
104 
105 
106  mUseStringTable = new TQCheckBox( i18n("Use String Table"), optionWidget );
107  mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 );
108 
109  mOnlyReplace = new TQCheckBox( i18n("Only Replace Entries"), optionWidget );
110  mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 );
111 
112  // Url
113  label = new TQLabel( i18n("URL:"), optionWidget );
114  mGridLayout->addWidget( label, 4, 0 );
115 
116  mUrl = new KLineEdit( optionWidget );
117  mGridLayout->addWidget( mUrl, 4, 1 );
118 
119  // recvLimit
120  label = new TQLabel( i18n("Receive Limit:"), optionWidget );
121  mGridLayout->addWidget( label, 5, 0 );
122 
123  mRecvLimit = new TQSpinBox( optionWidget );
124  mRecvLimit->setMinValue( 1 );
125  mRecvLimit->setMaxValue( 65536 );
126  mGridLayout->addWidget( mRecvLimit, 5, 1 );
127 
128  // maxObjSize
129  label = new TQLabel( i18n("Maximum Object Size"), optionWidget );
130  mGridLayout->addWidget( label, 6, 0 );
131 
132  mMaxObjSize = new TQSpinBox( optionWidget );
133  mMaxObjSize->setMinValue( 1 );
134  mMaxObjSize->setMaxValue( 65536 );
135  mGridLayout->addWidget( mMaxObjSize, 6, 1 );
136 
137  topLayout()->addStretch( 1 );
138 }
139 
140 void ConfigGuiSyncmlHttp::addLineEdit( TQWidget *parent, const TQString &text, KComboBox **edit, int row )
141 {
142  TQLabel *label = new TQLabel( text, parent);
143  mGridLayout->addWidget( label, row, 0 );
144 
145  *edit = new KComboBox( true, parent );
146  mGridLayout->addWidget( *edit, row, 1 );
147 }
148 
149 void ConfigGuiSyncmlHttp::load( const TQString &xml )
150 {
151  TQDomDocument document;
152  document.setContent( xml );
153 
154  TQDomElement docElement = document.documentElement();
155  TQDomNode node;
156 
157  for ( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
158  TQDomElement element = node.toElement();
159  if ( element.tagName() == "username" ) {
160  mUsername->setText( element.text() );
161  } else if ( element.tagName() == "password" ) {
162  mPassword->setText( element.text() );
163  } else if ( element.tagName() == "url" ) {
164  if ( mUrl )
165  mUrl->setText( element.text() );
166  } else if ( element.tagName() == "port" ) {
167  if ( mPort )
168  mPort->setValue( element.text().toInt() );
169  } else if ( element.tagName() == "recvLimit" ) {
170  if ( mRecvLimit )
171  mRecvLimit->setValue( element.text().toInt() );
172  } else if ( element.tagName() == "maxObjSize" ) {
173  if ( mMaxObjSize )
174  mMaxObjSize->setValue( element.text().toInt() );
175  } else if ( element.tagName() == "usestringtable" ) {
176  mUseStringTable->setChecked( element.text() == "1" );
177  } else if ( element.tagName() == "onlyreplace" ) {
178  mOnlyReplace->setChecked( element.text() == "1" );
179  } else if ( element.tagName() == "contact_db" ) {
180  mContactDb->setCurrentText( element.text() );
181  } else if ( element.tagName() == "calendar_db" ) {
182  mCalendarDb->setCurrentText( element.text() );
183  } else if ( element.tagName() == "note_db" ) {
184  mNoteDb->setCurrentText( element.text() );
185  }
186  }
187 }
188 
189 TQString ConfigGuiSyncmlHttp::save() const
190 {
191  TQString xml;
192  xml = "<config>\n";
193  xml += "<username>" + mUsername->text() + "</username>\n";
194  xml += "<password>" + mPassword->text() + "</password>\n";
195 
196  xml += "<url>" + mUrl->text() + "</url>\n";
197  xml += "<port>" + TQString::number( mPort->value() ) + "</port>\n";
198  // Receive Limit
199  xml += "<recvLimit>" + TQString::number( mRecvLimit->value() ) + "</recvLimit>\n";
200 
201  // Maximal Object Size
202  xml += "<maxObjSize>" + TQString::number( mMaxObjSize->value() ) + "</maxObjSize>\n";
203 
204  xml += "<usestringtable>";
205  if ( mUseStringTable->isChecked() )
206  xml += "1";
207  else
208  xml += "0";
209  xml += "</usestringtable>\n";
210 
211  xml += "<onlyreplace>";
212  if ( mOnlyReplace->isChecked() )
213  xml += "1";
214  else
215  xml += "0";
216  xml += "</onlyreplace>\n";
217 
218  xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n";
219  xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n";
220  xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n";
221  xml += "</config>";
222 
223  return xml;
224 }
225 
226 #include "configguisyncmlhttp.moc"
227