kitchensync

configguifile.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 "configguifile.h"
23 
24 #include <kurlrequester.h>
25 #include <tdelocale.h>
26 #include <kdialog.h>
27 
28 #include <tqlayout.h>
29 #include <tqcheckbox.h>
30 #include <tqlabel.h>
31 #include <tqdom.h>
32 
33 ConfigGuiFile::ConfigGuiFile( const QSync::Member &member, TQWidget *parent )
34  : ConfigGui( member, parent )
35 {
36  TQBoxLayout *filenameLayout = new TQHBoxLayout( topLayout() );
37 
38  TQLabel *label = new TQLabel( i18n("Directory name:"), this );
39  filenameLayout->addWidget( label );
40 
41  mFilename = new KURLRequester( this );
42  mFilename->setMode( KFile::Directory | KFile::LocalOnly );
43  filenameLayout->addWidget( mFilename );
44 
45  TQBoxLayout *recursiveLayout = new TQHBoxLayout( topLayout() );
46 
47  mRecursive = new TQCheckBox( i18n("Sync all subdirectories"), this );
48  recursiveLayout->addWidget( mRecursive );
49 
50  topLayout()->addStretch( 1 );
51 }
52 
53 void ConfigGuiFile::load( const TQString &xml )
54 {
55  TQDomDocument doc;
56  doc.setContent( xml );
57  TQDomElement docElement = doc.documentElement();
58  TQDomNode n;
59  for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
60  TQDomElement e = n.toElement();
61  if ( e.tagName() == "path" ) {
62  mFilename->setURL( e.text() );
63  } else if ( e.tagName() == "recursive" ) {
64  mRecursive->setChecked( e.text() == "TRUE" );
65  }
66  }
67 }
68 
69 TQString ConfigGuiFile::save() const
70 {
71  TQString xml;
72  xml = "<config>";
73  xml += "<path>" + mFilename->url() + "</path>";
74  xml += "<recursive>";
75  if ( mRecursive->isChecked() ) xml += "TRUE";
76  else xml += "FALSE";
77  xml += "</recursive>";
78  xml += "</config>";
79 
80  return xml;
81 }