kitchensync

configguijescs.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2007 Anirudh Ramesh <abattoir@abattoir.in>
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 "configguijescs.h"
00023 
00024 #include <tqcheckbox.h>
00025 #include <tqdom.h>
00026 #include <tqlabel.h>
00027 #include <tqlayout.h>
00028 
00029 #include <klineedit.h>
00030 #include <kdialog.h>
00031 #include <tdelocale.h>
00032 
00033 ConfigGuiJescs::ConfigGuiJescs( const QSync::Member &member, TQWidget *parent )
00034   : ConfigGui( member, parent )
00035 {
00036   initGUI();
00037 }
00038 
00039 void ConfigGuiJescs::load( const TQString &xml )
00040 {
00041   TQDomDocument doc;
00042   doc.setContent( xml );
00043   TQDomElement docElement = doc.documentElement();
00044   TQDomNode node;
00045   for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
00046     TQDomElement element = node.toElement();
00047     if ( element.tagName() == "url" ) {
00048       mUrl->setText( element.text() );
00049     } else if ( element.tagName() == "username" ) {
00050       mUsername->setText( element.text() );
00051     } else if ( element.tagName() == "password" ) {
00052       mPassword->setText( element.text() );
00053     } else if ( element.tagName() == "del_notify" ) {
00054       mDelNotify->setChecked( element.text() == "1" );
00055     }
00056   }
00057 }
00058 
00059 TQString ConfigGuiJescs::save() const
00060 {
00061   int delNotifyState;
00062   TQString config = "<config>\n";
00063 
00064   config += TQString( "<url>%1</url>\n" ).arg( mUrl->text() );
00065   config += TQString( "<username>%1</username>\n" ).arg( mUsername->text() );
00066   config += TQString( "<password>%1</password>\n" ).arg( mPassword->text() );
00067   if ( mDelNotify->isChecked() ) { delNotifyState = 1;
00068   }  else { delNotifyState = 0;
00069   }
00070   config += TQString( "<del_notify>%1</del_notify>\n" ).arg( delNotifyState );
00071 
00072   config += "</config>";
00073 
00074   return config;
00075 }
00076 
00077 void ConfigGuiJescs::initGUI()
00078 {
00079   TQGridLayout *layout = new TQGridLayout( topLayout(), 12, 3, KDialog::spacingHint() );
00080   layout->setMargin( KDialog::marginHint() );
00081 
00082   layout->addWidget( new TQLabel( i18n( "URL:" ), this ), 0, 0 );
00083   mUrl = new KLineEdit( this );
00084   layout->addMultiCellWidget( mUrl, 0, 0, 1, 2 );
00085 
00086   layout->addWidget( new TQLabel( i18n( "Username:" ), this ), 1, 0 );
00087   mUsername = new KLineEdit( this );
00088   layout->addMultiCellWidget( mUsername, 1, 1, 1, 2 );
00089 
00090   layout->addWidget( new TQLabel( i18n( "Password:" ), this ), 2, 0 );
00091   mPassword = new KLineEdit( this );
00092   mPassword->setEchoMode( KLineEdit::Password );
00093   layout->addMultiCellWidget( mPassword, 2, 2, 1, 2 );
00094 
00095   mDelNotify = new TQCheckBox( this );
00096   mDelNotify->setText( "Notify attendees about event/task deletion" );
00097   layout->addMultiCellWidget( mDelNotify, 3, 3, 0, 2 );
00098 }