summaryrefslogtreecommitdiffstats
path: root/mandriva/2010.2/kdepim/configguibarry.cpp
blob: 2d163d017bae99287825f3cd0a9b121cdae7efc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    This file is part of KitchenSync.

    Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
    Copyright (c) 2008 Eduardo Habkost <ehabkost@raisama.net>
    Copyright (c) 2008 Adam Williamson <awilliamson@mandriva.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    USA.
*/

#include "configguibarry.h"

#include <klocale.h>

#include <qlayout.h>
#include <qlabel.h>
#include <qdom.h>
#include <qlineedit.h>
#include <qcheckbox.h>

ConfigGuiBarry::ConfigGuiBarry( const QSync::Member &member, QWidget *parent )
  : ConfigGui( member, parent )
{
  QBoxLayout *userLayout = new QHBoxLayout( topLayout() );

  QLabel *pinLbl= new QLabel( i18n("PIN:"), this );
  userLayout->addWidget(pinLbl);

  mPin = new QLineEdit(this);
  userLayout->addWidget(mPin);

  mCalendar = new QCheckBox( i18n("Sync calendar"), this );
  userLayout->addWidget( mCalendar );

  mContacts = new QCheckBox( i18n("Sync contacts"), this );
  userLayout->addWidget( mContacts );

  topLayout()->addStretch( 1 );
}

void ConfigGuiBarry::load(const QString &cfg)
{
        QStringList lines = QStringList::split( '\n', cfg);
	QString pin;
	uint cal = 0;
	uint con = 0;
        for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) {
                QStringList options = QStringList::split( ' ', *it);
		if (options.count() < 1)
			/* invalid line */
			continue;

                if( options[0].lower() == "device" )
                {
			if (options.count() < 2)
            			/* invalid line */
            			continue;

                        pin = options[1];
			if (options.count() >= 3)
                        	cal = options[2].toUInt();
			if (options.count() >= 4)
	                        con = options[3].toUInt();
                        
                        mPin->setText(pin);
			mCalendar->setChecked( cal != 0);
			mContacts->setChecked( con != 0);
                }
        }
}

QString ConfigGuiBarry::save() const
{
  QString cfg;
  cfg = "Device " + mPin->text();
  if ( mCalendar->isChecked() ) cfg += " 1";
  else cfg += " 0";
  if ( mContacts->isChecked() ) cfg += " 1";
  else cfg += " 0";

  return cfg;
}