kitchensync

configguibarry.cpp

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