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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
This file is part of KitchenSync.
Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
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 <kdialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kdebug.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qcheckbox.h>
#include <libqopensync/group.h>
#include <libqopensync/conversion.h>
#include <libqopensync/environment.h>
#include "syncprocess.h"
#include "syncprocessmanager.h"
#include "groupconfigcommon.h"
ObjectTypeSelector::ObjectTypeSelector( QWidget *parent )
: QWidget( parent )
{
QGridLayout *layout = new QGridLayout( this );
layout->setMargin( 0 );
const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion();
QMap<QString, QString> objectTypeMap;
objectTypeMap.insert( "contact", i18n( "Contacts" ) );
objectTypeMap.insert( "event", i18n( "Events" ) );
objectTypeMap.insert( "todo", i18n( "To-dos" ) );
objectTypeMap.insert( "note", i18n( "Notes" ) );
QStringList objectTypes = conversion.objectTypes();
// reorder the entries so that contact and event are the first one
qHeapSort( objectTypes );
QStringList reoderedObjectTypes, stack;
for ( uint i = 0; i < objectTypes.count(); ++i ) {
if ( objectTypes[ i ] == "contact" || objectTypes[ i ] == "event" )
reoderedObjectTypes.append( objectTypes[ i ] );
else
stack.append( objectTypes[ i ] );
}
reoderedObjectTypes += stack;
QStringList::ConstIterator it;
int row = 0;
int col = 0;
for( it = reoderedObjectTypes.begin(); it != reoderedObjectTypes.end(); ++it ) {
QString objectType = *it;
// Don't display object type "data". Object type "data" is a kind of wildcard - so don't filter *
if ( objectType == "data" )
continue;
QCheckBox *objectCheckBox = new QCheckBox( objectTypeMap[ objectType ], this );
layout->addWidget( objectCheckBox, row, col );
mObjectTypeChecks.insert( objectType, objectCheckBox );
col++;
if ( (row == 0 && col == 2) || col == 3 ) {
col = 0;
row++;
}
}
}
void ObjectTypeSelector::load( const QSync::Group &group )
{
const QSync::GroupConfig config = group.config();
const QStringList objectTypes = config.activeObjectTypes();
// Enable everything on the inital load
bool initialLoad = false;
if ( objectTypes.isEmpty() )
initialLoad = true;
QMap<QString, QCheckBox*>::ConstIterator it;
for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) {
QCheckBox *check = it.data();
check->setChecked( objectTypes.contains( it.key() ) || initialLoad );
}
}
void ObjectTypeSelector::save( QSync::Group group )
{
QStringList objectTypes;
QMap<QString,QCheckBox *>::ConstIterator it;
for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) {
QCheckBox *check = it.data();
if ( check->isChecked() )
objectTypes.append( it.key() );
}
// Always add object type "data"
objectTypes.append( "data" );
QSync::GroupConfig config = group.config();
config.setActiveObjectTypes( objectTypes );
}
GroupConfigCommon::GroupConfigCommon( QWidget *parent )
: QWidget( parent )
{
QGridLayout *layout = new QGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
layout->addWidget( new QLabel( i18n( "Name:" ), this ), 0, 0 );
mGroupName = new KLineEdit( this );
layout->addWidget( mGroupName, 0, 1 );
layout->addWidget( new QLabel( i18n( "Object Types to be Synchronized:"), this ), 1, 0, Qt::AlignTop );
mObjectTypeSelector = new ObjectTypeSelector( this );
layout->addWidget( mObjectTypeSelector, 1, 1 );
layout->setRowStretch( 2, 1 );
}
void GroupConfigCommon::setSyncProcess( SyncProcess *syncProcess )
{
mSyncProcess = syncProcess;
mGroupName->setText( mSyncProcess->group().name() );
mObjectTypeSelector->load( mSyncProcess->group() );
}
void GroupConfigCommon::save()
{
mSyncProcess->group().setName( mGroupName->text() );
mObjectTypeSelector->save( mSyncProcess->group() );
}
|