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 #include <qcheckbox.h>
00033 
00034 ConfigGuiBarry::ConfigGuiBarry( const QSync::Member &member, QWidget *parent )
00035   : ConfigGui( member, parent )
00036 {
00037   QBoxLayout *userLayout = new QHBoxLayout( topLayout() );
00038 
00039   QLabel *pinLbl= new QLabel( i18n("PIN:"), this );
00040   userLayout->addWidget(pinLbl);
00041 
00042   mPin = new QLineEdit(this);
00043   userLayout->addWidget(mPin);
00044 
00045   mCalendar = new QCheckBox( i18n("Sync calendar"), this );
00046   userLayout->addWidget( mCalendar );
00047 
00048   mContacts = new QCheckBox( i18n("Sync contacts"), this );
00049   userLayout->addWidget( mContacts );
00050 
00051   topLayout()->addStretch( 1 );
00052 }
00053 
00054 void ConfigGuiBarry::load(const QString &cfg)
00055 {
00056         QStringList lines = QStringList::split( '\n', cfg);
00057     QString pin;
00058     uint cal = 0;
00059     uint con = 0;
00060         for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) {
00061                 QStringList options = QStringList::split( ' ', *it);
00062         if (options.count() < 1)
00063             /* invalid line */
00064             continue;
00065 
00066                 if( options[0].lower() == "device" )
00067                 {
00068             if (options.count() < 2)
00069                         /* invalid line */
00070                         continue;
00071 
00072                         pin = options[1];
00073             if (options.count() >= 3)
00074                             cal = options[2].toUInt();
00075             if (options.count() >= 4)
00076                             con = options[3].toUInt();
00077                         
00078                         mPin->setText(pin);
00079             mCalendar->setChecked( cal != 0);
00080             mContacts->setChecked( con != 0);
00081                 }
00082         }
00083 }
00084 
00085 QString ConfigGuiBarry::save() const
00086 {
00087   QString cfg;
00088   cfg = "Device " + mPin->text();
00089   if ( mCalendar->isChecked() ) cfg += " 1";
00090   else cfg += " 0";
00091   if ( mContacts->isChecked() ) cfg += " 1";
00092   else cfg += " 0";
00093 
00094   return cfg;
00095 }
KDE Home | KDE Accessibility Home | Description of Access Keys