kitchensync

configguisynce.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 "configguisynce.h"
00023 
00024 #include <qdom.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qcheckbox.h>
00028 
00029 #include <klineedit.h>
00030 #include <kdialog.h>
00031 #include <klocale.h>
00032 
00033 ConfigGuiSynce::ConfigGuiSynce( const QSync::Member &member, QWidget *parent )
00034   : ConfigGui( member, parent )
00035 {
00036   initGUI();
00037 }
00038 
00039 void ConfigGuiSynce::load( const QString &xml )
00040 {
00041   QDomDocument doc;
00042   doc.setContent( xml );
00043   QDomElement docElement = doc.documentElement();
00044   QDomNode node;
00045   for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
00046     QDomElement element = node.toElement();
00047     if ( element.tagName() == "contact" ) {
00048       mContacts->setChecked( element.text().toInt() == 1 );
00049     } else if ( element.tagName() == "todos" ) {
00050       mTodos->setChecked( element.text().toInt() == 1 );
00051     } else if ( element.tagName() == "calendar" ) {
00052       mCalendar->setChecked( element.text().toInt() == 1 );
00053     } else if ( element.tagName() == "file" ) {
00054       mFile->setText( element.text() );
00055     }
00056   }
00057 }
00058 
00059 QString ConfigGuiSynce::save() const
00060 {
00061   QString config = "<config>\n";
00062 
00063   config += QString( "<contact>%1</contact>\n" ).arg( mContacts->isChecked() ? "1" : "0" );
00064   config += QString( "<todos>%1</todos>\n" ).arg( mTodos->isChecked() ? "1" : "0" );
00065   config += QString( "<calendar>%1</calendar>\n" ).arg( mCalendar->isChecked() ? "1" : "0" );
00066   config += QString( "<file>%1</file>\n" ).arg( mFile->text() );
00067 
00068   config += "</config>";
00069 
00070   return config;
00071 }
00072 
00073 void ConfigGuiSynce::initGUI()
00074 {
00075   QGridLayout *layout = new QGridLayout( topLayout(), 12, 2, KDialog::spacingHint() );
00076   layout->setMargin( KDialog::marginHint() );
00077 
00078   mContacts = new QCheckBox( this );
00079   mContacts->setText( "Sync Contacts" );
00080   layout->addMultiCellWidget( mContacts, 0, 0, 0, 1 );
00081 
00082   mTodos = new QCheckBox( this );
00083   mTodos->setText( "Sync \'Todo\' items" );
00084   layout->addMultiCellWidget( mTodos, 1, 1, 0, 1 );
00085 
00086   mCalendar = new QCheckBox( this );
00087   mCalendar->setText( "Sync Calendar" );
00088   layout->addMultiCellWidget( mCalendar, 2, 2, 0, 1 );
00089 
00090   layout->addWidget( new QLabel( i18n( "File:" ), this ), 3, 0 );
00091   mFile = new KLineEdit( this );
00092   layout->addWidget( mFile, 3, 1 );
00093 }