configguisyncmlhttp.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00019 USA. 00020 */ 00021 00022 #include "configguisyncmlhttp.h" 00023 00024 #include <kcombobox.h> 00025 #include <kdialog.h> 00026 #include <klineedit.h> 00027 #include <tdelocale.h> 00028 #include <kurlrequester.h> 00029 00030 #include <tqcheckbox.h> 00031 #include <tqdom.h> 00032 #include <tqlabel.h> 00033 #include <tqlayout.h> 00034 #include <tqspinbox.h> 00035 #include <tqtabwidget.h> 00036 #include <tqvbox.h> 00037 00038 ConfigGuiSyncmlHttp::ConfigGuiSyncmlHttp( const QSync::Member &member, TQWidget *parent ) 00039 : ConfigGui( member, parent ), mUrl( 0 ), mPort( 0 ) 00040 { 00041 00042 TQTabWidget *tabWidget = new TQTabWidget( this ); 00043 topLayout()->addWidget( tabWidget ); 00044 00045 // Connection 00046 TQWidget *connectionWidget = new TQWidget( tabWidget ); 00047 TQVBoxLayout *connectionLayout = new TQVBoxLayout( connectionWidget, 00048 KDialog::marginHint(), KDialog::spacingHint() ); 00049 00050 tabWidget->addTab( connectionWidget, i18n( "Connection" ) ); 00051 00052 mGridLayout = new TQGridLayout( connectionLayout ); 00053 00054 TQLabel *label = new TQLabel( i18n("Port:"), connectionWidget ); 00055 mGridLayout->addWidget( label, 0, 0 ); 00056 00057 mPort = new TQSpinBox( connectionWidget ); 00058 mPort->setMinValue( 1 ); 00059 mPort->setMaxValue( 65536 ); 00060 mGridLayout->addWidget( mPort, 0, 1 ); 00061 00062 // Database 00063 TQWidget *databaseWidget = new TQWidget( tabWidget ); 00064 TQVBoxLayout *databaseLayout = new TQVBoxLayout( databaseWidget, 00065 KDialog::marginHint(), KDialog::spacingHint() ); 00066 00067 tabWidget->addTab( databaseWidget, i18n( "Databases" ) ); 00068 00069 mGridLayout = new TQGridLayout( databaseLayout ); 00070 addLineEdit( databaseWidget, i18n("Contact Database:"), &mContactDb, 0 ); 00071 addLineEdit( databaseWidget, i18n("Calendar Database:"), &mCalendarDb, 1 ); 00072 addLineEdit( databaseWidget, i18n("Note Database:"), &mNoteDb, 2 ); 00073 00074 mContactDb->insertItem( "addressbook" ); 00075 mContactDb->insertItem( "contacts" ); 00076 00077 mCalendarDb->insertItem( "agenda" ); 00078 mCalendarDb->insertItem( "calendar" ); 00079 00080 mNoteDb->insertItem( "notes" ); 00081 00082 00083 // Options 00084 TQWidget *optionWidget = new TQWidget( tabWidget ); 00085 TQVBoxLayout *optionLayout = new TQVBoxLayout( optionWidget, 00086 KDialog::marginHint(), KDialog::spacingHint() ); 00087 00088 tabWidget->addTab( optionWidget, i18n( "Options" ) ); 00089 00090 mGridLayout = new TQGridLayout( optionLayout ); 00091 00092 label = new TQLabel( i18n("User name:"), optionWidget ); 00093 mGridLayout->addWidget( label, 0, 0 ); 00094 00095 mUsername = new KLineEdit( optionWidget ); 00096 mGridLayout->addWidget( mUsername, 0, 1 ); 00097 00098 label = new TQLabel( i18n("Password:"), optionWidget ); 00099 mGridLayout->addWidget( label, 1, 0 ); 00100 00101 mPassword = new KLineEdit( optionWidget ); 00102 mPassword->setEchoMode( TQLineEdit::Password ); 00103 mGridLayout->addWidget( mPassword, 1, 1 ); 00104 00105 00106 mUseStringTable = new TQCheckBox( i18n("Use String Table"), optionWidget ); 00107 mGridLayout->addMultiCellWidget( mUseStringTable, 2, 2, 0, 1 ); 00108 00109 mOnlyReplace = new TQCheckBox( i18n("Only Replace Entries"), optionWidget ); 00110 mGridLayout->addMultiCellWidget( mOnlyReplace, 3, 3, 0, 1 ); 00111 00112 // Url 00113 label = new TQLabel( i18n("URL:"), optionWidget ); 00114 mGridLayout->addWidget( label, 4, 0 ); 00115 00116 mUrl = new KLineEdit( optionWidget ); 00117 mGridLayout->addWidget( mUrl, 4, 1 ); 00118 00119 // recvLimit 00120 label = new TQLabel( i18n("Receive Limit:"), optionWidget ); 00121 mGridLayout->addWidget( label, 5, 0 ); 00122 00123 mRecvLimit = new TQSpinBox( optionWidget ); 00124 mRecvLimit->setMinValue( 1 ); 00125 mRecvLimit->setMaxValue( 65536 ); 00126 mGridLayout->addWidget( mRecvLimit, 5, 1 ); 00127 00128 // maxObjSize 00129 label = new TQLabel( i18n("Maximum Object Size"), optionWidget ); 00130 mGridLayout->addWidget( label, 6, 0 ); 00131 00132 mMaxObjSize = new TQSpinBox( optionWidget ); 00133 mMaxObjSize->setMinValue( 1 ); 00134 mMaxObjSize->setMaxValue( 65536 ); 00135 mGridLayout->addWidget( mMaxObjSize, 6, 1 ); 00136 00137 topLayout()->addStretch( 1 ); 00138 } 00139 00140 void ConfigGuiSyncmlHttp::addLineEdit( TQWidget *parent, const TQString &text, KComboBox **edit, int row ) 00141 { 00142 TQLabel *label = new TQLabel( text, parent); 00143 mGridLayout->addWidget( label, row, 0 ); 00144 00145 *edit = new KComboBox( true, parent ); 00146 mGridLayout->addWidget( *edit, row, 1 ); 00147 } 00148 00149 void ConfigGuiSyncmlHttp::load( const TQString &xml ) 00150 { 00151 TQDomDocument document; 00152 document.setContent( xml ); 00153 00154 TQDomElement docElement = document.documentElement(); 00155 TQDomNode node; 00156 00157 for ( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { 00158 TQDomElement element = node.toElement(); 00159 if ( element.tagName() == "username" ) { 00160 mUsername->setText( element.text() ); 00161 } else if ( element.tagName() == "password" ) { 00162 mPassword->setText( element.text() ); 00163 } else if ( element.tagName() == "url" ) { 00164 if ( mUrl ) 00165 mUrl->setText( element.text() ); 00166 } else if ( element.tagName() == "port" ) { 00167 if ( mPort ) 00168 mPort->setValue( element.text().toInt() ); 00169 } else if ( element.tagName() == "recvLimit" ) { 00170 if ( mRecvLimit ) 00171 mRecvLimit->setValue( element.text().toInt() ); 00172 } else if ( element.tagName() == "maxObjSize" ) { 00173 if ( mMaxObjSize ) 00174 mMaxObjSize->setValue( element.text().toInt() ); 00175 } else if ( element.tagName() == "usestringtable" ) { 00176 mUseStringTable->setChecked( element.text() == "1" ); 00177 } else if ( element.tagName() == "onlyreplace" ) { 00178 mOnlyReplace->setChecked( element.text() == "1" ); 00179 } else if ( element.tagName() == "contact_db" ) { 00180 mContactDb->setCurrentText( element.text() ); 00181 } else if ( element.tagName() == "calendar_db" ) { 00182 mCalendarDb->setCurrentText( element.text() ); 00183 } else if ( element.tagName() == "note_db" ) { 00184 mNoteDb->setCurrentText( element.text() ); 00185 } 00186 } 00187 } 00188 00189 TQString ConfigGuiSyncmlHttp::save() const 00190 { 00191 TQString xml; 00192 xml = "<config>\n"; 00193 xml += "<username>" + mUsername->text() + "</username>\n"; 00194 xml += "<password>" + mPassword->text() + "</password>\n"; 00195 00196 xml += "<url>" + mUrl->text() + "</url>\n"; 00197 xml += "<port>" + TQString::number( mPort->value() ) + "</port>\n"; 00198 // Receive Limit 00199 xml += "<recvLimit>" + TQString::number( mRecvLimit->value() ) + "</recvLimit>\n"; 00200 00201 // Maximal Object Size 00202 xml += "<maxObjSize>" + TQString::number( mMaxObjSize->value() ) + "</maxObjSize>\n"; 00203 00204 xml += "<usestringtable>"; 00205 if ( mUseStringTable->isChecked() ) 00206 xml += "1"; 00207 else 00208 xml += "0"; 00209 xml += "</usestringtable>\n"; 00210 00211 xml += "<onlyreplace>"; 00212 if ( mOnlyReplace->isChecked() ) 00213 xml += "1"; 00214 else 00215 xml += "0"; 00216 xml += "</onlyreplace>\n"; 00217 00218 xml += "<contact_db>" + mContactDb->currentText() + "</contact_db>\n"; 00219 xml += "<calendar_db>" + mCalendarDb->currentText() + "</calendar_db>\n"; 00220 xml += "<note_db>" + mNoteDb->currentText() + "</note_db>\n"; 00221 xml += "</config>"; 00222 00223 return xml; 00224 } 00225 00226 #include "configguisyncmlhttp.moc" 00227