kitchensync

configguifile.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 "configguifile.h"
00023 
00024 #include <kurlrequester.h>
00025 #include <klocale.h>
00026 #include <kdialog.h>
00027 
00028 #include <qlayout.h>
00029 #include <qcheckbox.h>
00030 #include <qlabel.h>
00031 #include <qdom.h>
00032 
00033 ConfigGuiFile::ConfigGuiFile( const QSync::Member &member, QWidget *parent )
00034   : ConfigGui( member, parent )
00035 {
00036   QBoxLayout *filenameLayout = new QHBoxLayout( topLayout() );
00037 
00038   QLabel *label = new QLabel( i18n("Directory name:"), this );
00039   filenameLayout->addWidget( label );
00040 
00041   mFilename = new KURLRequester( this );
00042   mFilename->setMode( KFile::Directory | KFile::LocalOnly );
00043   filenameLayout->addWidget( mFilename );
00044 
00045   QBoxLayout *recursiveLayout = new QHBoxLayout( topLayout() );
00046 
00047   mRecursive = new QCheckBox( i18n("Sync all subdirectories"), this );
00048   recursiveLayout->addWidget( mRecursive );
00049 
00050   topLayout()->addStretch( 1 );
00051 }
00052 
00053 void ConfigGuiFile::load( const QString &xml )
00054 {
00055   QDomDocument doc;
00056   doc.setContent( xml );
00057   QDomElement docElement = doc.documentElement();
00058   QDomNode n;
00059   for( n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
00060     QDomElement e = n.toElement();
00061     if ( e.tagName() == "path" ) {
00062       mFilename->setURL( e.text() );
00063     } else if ( e.tagName() == "recursive" ) {
00064       mRecursive->setChecked( e.text() == "TRUE" );
00065     }
00066   }
00067 }
00068 
00069 QString ConfigGuiFile::save()
00070 {
00071   QString xml;
00072   xml = "<config>";
00073   xml += "<path>" + mFilename->url() + "</path>";
00074   xml += "<recursive>";
00075   if ( mRecursive->isChecked() ) xml += "TRUE";
00076   else xml += "FALSE";
00077   xml += "</recursive>";
00078   xml += "</config>";
00079 
00080   return xml;
00081 }
KDE Home | KDE Accessibility Home | Description of Access Keys