kitchensync

configguisynce.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2007 Anirudh Ramesh <abattoir@abattoir.in>
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 "configguisynce.h"
23 
24 #include <tqdom.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqcheckbox.h>
28 
29 #include <klineedit.h>
30 #include <kdialog.h>
31 #include <tdelocale.h>
32 
33 ConfigGuiSynce::ConfigGuiSynce( const QSync::Member &member, TQWidget *parent )
34  : ConfigGui( member, parent )
35 {
36  initGUI();
37 }
38 
39 void ConfigGuiSynce::load( const TQString &xml )
40 {
41  TQDomDocument doc;
42  doc.setContent( xml );
43  TQDomElement docElement = doc.documentElement();
44  TQDomNode node;
45  for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
46  TQDomElement element = node.toElement();
47  if ( element.tagName() == "contact" ) {
48  mContacts->setChecked( element.text().toInt() == 1 );
49  } else if ( element.tagName() == "todos" ) {
50  mTodos->setChecked( element.text().toInt() == 1 );
51  } else if ( element.tagName() == "calendar" ) {
52  mCalendar->setChecked( element.text().toInt() == 1 );
53  } else if ( element.tagName() == "file" ) {
54  mFile->setText( element.text() );
55  }
56  }
57 }
58 
59 TQString ConfigGuiSynce::save() const
60 {
61  TQString config = "<config>\n";
62 
63  config += TQString( "<contact>%1</contact>\n" ).arg( mContacts->isChecked() ? "1" : "0" );
64  config += TQString( "<todos>%1</todos>\n" ).arg( mTodos->isChecked() ? "1" : "0" );
65  config += TQString( "<calendar>%1</calendar>\n" ).arg( mCalendar->isChecked() ? "1" : "0" );
66  config += TQString( "<file>%1</file>\n" ).arg( mFile->text() );
67 
68  config += "</config>";
69 
70  return config;
71 }
72 
73 void ConfigGuiSynce::initGUI()
74 {
75  TQGridLayout *layout = new TQGridLayout( topLayout(), 12, 2, KDialog::spacingHint() );
76  layout->setMargin( KDialog::marginHint() );
77 
78  mContacts = new TQCheckBox( this );
79  mContacts->setText( "Sync Contacts" );
80  layout->addMultiCellWidget( mContacts, 0, 0, 0, 1 );
81 
82  mTodos = new TQCheckBox( this );
83  mTodos->setText( "Sync \'Todo\' items" );
84  layout->addMultiCellWidget( mTodos, 1, 1, 0, 1 );
85 
86  mCalendar = new TQCheckBox( this );
87  mCalendar->setText( "Sync Calendar" );
88  layout->addMultiCellWidget( mCalendar, 2, 2, 0, 1 );
89 
90  layout->addWidget( new TQLabel( i18n( "File:" ), this ), 3, 0 );
91  mFile = new KLineEdit( this );
92  layout->addWidget( mFile, 3, 1 );
93 }