kitchensync

configguibarry.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2008 Eduardo Habkost <ehabkost@raisama.net>
00006     Copyright (c) 2008 Adam Williamson <awilliamson@mandriva.com>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021     USA.
00022 */
00023 
00024 #include "configguibarry.h"
00025 
00026 #include <klocale.h>
00027 
00028 #include <qlayout.h>
00029 #include <qlabel.h>
00030 #include <qdom.h>
00031 #include <qlineedit.h>
00032 
00033 ConfigGuiBarry::ConfigGuiBarry( const QSync::Member &member, QWidget *parent )
00034   : ConfigGui( member, parent )
00035 {
00036   QBoxLayout *userLayout = new QHBoxLayout( topLayout() );
00037 
00038   QLabel *pinLbl= new QLabel( i18n("PIN:"), this );
00039   userLayout->addWidget(pinLbl);
00040 
00041   mPin = new QLineEdit(this);
00042   userLayout->addWidget(mPin);
00043 
00044   mCalendar = new QCheckBox( i18n("Sync calendar"), this );
00045   userLayout->addWidget( mCalendar );
00046 
00047   mContacts = new QCheckBox( i18n("Sync contacts"), this );
00048   userLayout->addWidget( mContacts );
00049 
00050   topLayout()->addStretch( 1 );
00051 }
00052 
00053 void ConfigGuiBarry::load(const QString &cfg)
00054 {
00055         QStringList lines = QStringList::split( '\n', cfg);
00056     QString pin;
00057     uint cal = 0;
00058     uint con = 0;
00059         for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) {
00060                 QStringList options = QStringList::split( ' ', *it);
00061         if (options.count() < 1)
00062             /* invalid line */
00063             continue;
00064 
00065                 if( options[0].lower() == "device" )
00066                 {
00067             if (options.count() < 2)
00068                         /* invalid line */
00069                         continue;
00070 
00071                         pin = options[1];
00072             if (options.count() >= 3)
00073                             cal = options[2].toUInt();
00074             if (options.count() >= 4)
00075                             con = options[3].toUInt();
00076                         
00077                         mPin->setText(pin);
00078             mCalendar->setChecked( cal != 0);
00079             mContacts->setChecked( con != 0);
00080                 }
00081         }
00082 }
00083 
00084 QString ConfigGuiBarry::save() const
00085 {
00086   QString cfg;
00087   cfg = "Device " + mPin->text();
00088   if ( mCalendar->isChecked() ) cfg += " 1";
00089   else cfg += " 0";
00090   if ( mContacts->isChecked() ) cfg += " 1";
00091   else cfg += " 0";
00092 
00093   return cfg;
00094 }
KDE Home | KDE Accessibility Home | Description of Access Keys