24 #include <klineedit.h>
25 #include <tdelocale.h>
30 #include <tqcheckbox.h>
32 #include <libqopensync/group.h>
33 #include <libqopensync/conversion.h>
34 #include <libqopensync/environment.h>
36 #include "syncprocess.h"
37 #include "syncprocessmanager.h"
39 #include "groupconfigcommon.h"
41 ObjectTypeSelector::ObjectTypeSelector( TQWidget *parent )
44 TQGridLayout *layout =
new TQGridLayout(
this );
45 layout->setMargin( 0 );
47 const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion();
49 TQMap<TQString, TQString> objectTypeMap;
50 objectTypeMap.insert(
"contact", i18n(
"Contacts" ) );
51 objectTypeMap.insert(
"event", i18n(
"Events" ) );
52 objectTypeMap.insert(
"todo", i18n(
"To-dos" ) );
53 objectTypeMap.insert(
"note", i18n(
"Notes" ) );
55 TQStringList objectTypes = conversion.objectTypes();
58 qHeapSort( objectTypes );
60 TQStringList reoderedObjectTypes, stack;
61 for ( uint i = 0; i < objectTypes.count(); ++i ) {
62 if ( objectTypes[ i ] ==
"contact" || objectTypes[ i ] ==
"event" )
63 reoderedObjectTypes.append( objectTypes[ i ] );
65 stack.append( objectTypes[ i ] );
67 reoderedObjectTypes += stack;
69 TQStringList::ConstIterator it;
73 for( it = reoderedObjectTypes.begin(); it != reoderedObjectTypes.end(); ++it ) {
74 TQString objectType = *it;
77 if ( objectType ==
"data" )
80 TQCheckBox *objectCheckBox =
new TQCheckBox( objectTypeMap[ objectType ],
this );
81 layout->addWidget( objectCheckBox, row, col );
82 mObjectTypeChecks.insert( objectType, objectCheckBox );
85 if ( (row == 0 && col == 2) || col == 3 ) {
92 void ObjectTypeSelector::load(
const QSync::Group &group )
94 const QSync::GroupConfig config = group.config();
96 const TQStringList objectTypes = config.activeObjectTypes();
99 bool initialLoad =
false;
100 if ( objectTypes.isEmpty() )
103 TQMap<TQString, TQCheckBox*>::ConstIterator it;
104 for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) {
105 TQCheckBox *check = it.data();
106 check->setChecked( objectTypes.contains( it.key() ) || initialLoad );
110 void ObjectTypeSelector::save( QSync::Group group )
112 TQStringList objectTypes;
114 TQMap<TQString,TQCheckBox *>::ConstIterator it;
115 for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) {
116 TQCheckBox *check = it.data();
117 if ( check->isChecked() )
118 objectTypes.append( it.key() );
122 objectTypes.append(
"data" );
124 QSync::GroupConfig config = group.config();
125 config.setActiveObjectTypes( objectTypes );
128 GroupConfigCommon::GroupConfigCommon( TQWidget *parent )
131 TQGridLayout *layout =
new TQGridLayout(
this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
133 layout->addWidget(
new TQLabel( i18n(
"Name:" ),
this ), 0, 0 );
135 mGroupName =
new KLineEdit(
this );
136 layout->addWidget( mGroupName, 0, 1 );
138 layout->addWidget(
new TQLabel( i18n(
"Object Types to be Synchronized:"),
this ), 1, 0, TQt::AlignTop );
140 mObjectTypeSelector =
new ObjectTypeSelector(
this );
141 layout->addWidget( mObjectTypeSelector, 1, 1 );
143 layout->setRowStretch( 2, 1 );
146 void GroupConfigCommon::setSyncProcess( SyncProcess *syncProcess )
148 mSyncProcess = syncProcess;
150 mGroupName->setText( mSyncProcess->group().name() );
151 mObjectTypeSelector->load( mSyncProcess->group() );
154 void GroupConfigCommon::save()
156 mSyncProcess->group().setName( mGroupName->text() );
157 mObjectTypeSelector->save( mSyncProcess->group() );