groupconfigcommon.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00019 USA. 00020 */ 00021 00022 00023 #include <kdialog.h> 00024 #include <klineedit.h> 00025 #include <klocale.h> 00026 #include <kdebug.h> 00027 00028 #include <tqlabel.h> 00029 #include <tqlayout.h> 00030 #include <tqcheckbox.h> 00031 00032 #include <libqopensync/group.h> 00033 #include <libqopensync/conversion.h> 00034 #include <libqopensync/environment.h> 00035 00036 #include "syncprocess.h" 00037 #include "syncprocessmanager.h" 00038 00039 #include "groupconfigcommon.h" 00040 00041 ObjectTypeSelector::ObjectTypeSelector( TQWidget *parent ) 00042 : TQWidget( parent ) 00043 { 00044 TQGridLayout *layout = new TQGridLayout( this ); 00045 layout->setMargin( 0 ); 00046 00047 const QSync::Conversion conversion = SyncProcessManager::self()->environment()->conversion(); 00048 00049 TQMap<TQString, TQString> objectTypeMap; 00050 objectTypeMap.insert( "contact", i18n( "Contacts" ) ); 00051 objectTypeMap.insert( "event", i18n( "Events" ) ); 00052 objectTypeMap.insert( "todo", i18n( "To-dos" ) ); 00053 objectTypeMap.insert( "note", i18n( "Notes" ) ); 00054 00055 TQStringList objectTypes = conversion.objectTypes(); 00056 00057 // reorder the entries so that contact and event are the first one 00058 qHeapSort( objectTypes ); 00059 00060 TQStringList reoderedObjectTypes, stack; 00061 for ( uint i = 0; i < objectTypes.count(); ++i ) { 00062 if ( objectTypes[ i ] == "contact" || objectTypes[ i ] == "event" ) 00063 reoderedObjectTypes.append( objectTypes[ i ] ); 00064 else 00065 stack.append( objectTypes[ i ] ); 00066 } 00067 reoderedObjectTypes += stack; 00068 00069 TQStringList::ConstIterator it; 00070 00071 int row = 0; 00072 int col = 0; 00073 for( it = reoderedObjectTypes.begin(); it != reoderedObjectTypes.end(); ++it ) { 00074 TQString objectType = *it; 00075 00076 // Don't display object type "data". Object type "data" is a kind of wildcard - so don't filter * 00077 if ( objectType == "data" ) 00078 continue; 00079 00080 TQCheckBox *objectCheckBox = new TQCheckBox( objectTypeMap[ objectType ], this ); 00081 layout->addWidget( objectCheckBox, row, col ); 00082 mObjectTypeChecks.insert( objectType, objectCheckBox ); 00083 00084 col++; 00085 if ( (row == 0 && col == 2) || col == 3 ) { 00086 col = 0; 00087 row++; 00088 } 00089 } 00090 } 00091 00092 void ObjectTypeSelector::load( const QSync::Group &group ) 00093 { 00094 const QSync::GroupConfig config = group.config(); 00095 00096 const TQStringList objectTypes = config.activeObjectTypes(); 00097 00098 // Enable everything on the inital load 00099 bool initialLoad = false; 00100 if ( objectTypes.isEmpty() ) 00101 initialLoad = true; 00102 00103 TQMap<TQString, TQCheckBox*>::ConstIterator it; 00104 for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) { 00105 TQCheckBox *check = it.data(); 00106 check->setChecked( objectTypes.contains( it.key() ) || initialLoad ); 00107 } 00108 } 00109 00110 void ObjectTypeSelector::save( QSync::Group group ) 00111 { 00112 TQStringList objectTypes; 00113 00114 TQMap<TQString,TQCheckBox *>::ConstIterator it; 00115 for( it = mObjectTypeChecks.begin(); it != mObjectTypeChecks.end(); ++it ) { 00116 TQCheckBox *check = it.data(); 00117 if ( check->isChecked() ) 00118 objectTypes.append( it.key() ); 00119 } 00120 00121 // Always add object type "data" 00122 objectTypes.append( "data" ); 00123 00124 QSync::GroupConfig config = group.config(); 00125 config.setActiveObjectTypes( objectTypes ); 00126 } 00127 00128 GroupConfigCommon::GroupConfigCommon( TQWidget *parent ) 00129 : TQWidget( parent ) 00130 { 00131 TQGridLayout *layout = new TQGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() ); 00132 00133 layout->addWidget( new TQLabel( i18n( "Name:" ), this ), 0, 0 ); 00134 00135 mGroupName = new KLineEdit( this ); 00136 layout->addWidget( mGroupName, 0, 1 ); 00137 00138 layout->addWidget( new TQLabel( i18n( "Object Types to be Synchronized:"), this ), 1, 0, TQt::AlignTop ); 00139 00140 mObjectTypeSelector = new ObjectTypeSelector( this ); 00141 layout->addWidget( mObjectTypeSelector, 1, 1 ); 00142 00143 layout->setRowStretch( 2, 1 ); 00144 } 00145 00146 void GroupConfigCommon::setSyncProcess( SyncProcess *syncProcess ) 00147 { 00148 mSyncProcess = syncProcess; 00149 00150 mGroupName->setText( mSyncProcess->group().name() ); 00151 mObjectTypeSelector->load( mSyncProcess->group() ); 00152 } 00153 00154 void GroupConfigCommon::save() 00155 { 00156 mSyncProcess->group().setName( mGroupName->text() ); 00157 mObjectTypeSelector->save( mSyncProcess->group() ); 00158 }