21 #include <tdeapplication.h>
23 #include <tdeglobal.h>
24 #include <tdeglobalsettings.h>
25 #include <kiconloader.h>
26 #include <tdelocale.h>
27 #include <kpassivepopup.h>
28 #include <kurllabel.h>
33 #include <tqprogressbar.h>
36 #include "memberinfo.h"
37 #include "multiconflictdialog.h"
38 #include "singleconflictdialog.h"
39 #include "syncprocessmanager.h"
41 #include "groupitem.h"
43 GroupItem::GroupItem( KWidgetList *parent, SyncProcess *process )
44 : KWidgetListItem( parent ), mSyncProcess( process ),
45 mCallbackHandler( new QSync::CallbackHandler ),
46 mProcessedItems( 0 ), mMaxProcessedItems( 0 ),
47 mSynchronizing( false )
50 boldFont.setBold(
true );
51 boldFont.setPointSize( boldFont.pointSize() + 2 );
53 TQGridLayout *layout =
new TQGridLayout(
this, 4, 4, KDialog::marginHint(), KDialog::spacingHint() );
55 mBox =
new TQVBox(
this );
57 mProgressBar =
new TQProgressBar(
this );
58 mProgressBar->setTotalSteps( 100 );
60 mTime =
new TQLabel(
this );
61 mSyncAction =
new KURLLabel(
"exec:/sync", i18n(
"Synchronize Now" ),
this );
62 mConfigureAction =
new KURLLabel(
"exec:/config", i18n(
"Configure" ),
this );
65 TQHBox* hbox =
new TQHBox(
this );
70 icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_summary", TDEIcon::Desktop );
72 mIcon =
new TQLabel( hbox );
73 mIcon->setPixmap( icon );
74 mIcon->setFixedSize( mIcon->sizeHint() );
75 mIcon->setPaletteBackgroundColor( colorGroup().mid() );
77 mGroupName =
new TQLabel( hbox );
78 mGroupName->setAlignment( AlignLeft | AlignVCenter );
79 mGroupName->setIndent( KDialog::spacingHint() );
80 mGroupName->setFont( boldFont );
81 mGroupName->setPaletteForegroundColor( colorGroup().light() );
82 mGroupName->setPaletteBackgroundColor( colorGroup().mid() );
84 mStatus =
new TQLabel( hbox );
85 mStatus->setAlignment( TQt::AlignRight );
86 mStatus->setAlignment( AlignRight | AlignVCenter );
87 mStatus->setIndent( KDialog::spacingHint() );
88 mStatus->setFont( boldFont );
89 mStatus->setPaletteForegroundColor( colorGroup().light() );
90 mStatus->setPaletteBackgroundColor( colorGroup().mid() );
91 mStatus->setText( i18n(
"Ready" ) );
93 hbox->setPaletteBackgroundColor( colorGroup().mid() );
94 hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
96 layout->addMultiCellWidget( hbox, 0, 0, 0, 3 );
97 layout->addMultiCellWidget( mBox, 1, 1, 0, 3 );
98 layout->addWidget( mTime, 2, 0 );
99 layout->addWidget( mSyncAction, 2, 1 );
100 layout->addWidget( mConfigureAction, 2, 2 );
101 layout->addWidget( mProgressBar, 2, 3 );
102 layout->setColStretch( 0, 1 );
103 layout->setRowStretch( 3, 1 );
105 setPaletteBackgroundColor( kapp->palette().active().base() );
107 connect( mCallbackHandler, TQT_SIGNAL( conflict( QSync::SyncMapping ) ),
108 this, TQT_SLOT( conflict( QSync::SyncMapping ) ) );
109 connect( mCallbackHandler, TQT_SIGNAL( change(
const QSync::SyncChangeUpdate& ) ),
110 this, TQT_SLOT( change(
const QSync::SyncChangeUpdate& ) ) );
111 connect( mCallbackHandler, TQT_SIGNAL( mapping(
const QSync::SyncMappingUpdate& ) ),
112 this, TQT_SLOT( mapping(
const QSync::SyncMappingUpdate& ) ) );
113 connect( mCallbackHandler, TQT_SIGNAL( engine(
const QSync::SyncEngineUpdate& ) ),
114 this, TQT_SLOT( engine(
const QSync::SyncEngineUpdate& ) ) );
115 connect( mCallbackHandler, TQT_SIGNAL( member(
const QSync::SyncMemberUpdate& ) ),
116 this, TQT_SLOT( member(
const QSync::SyncMemberUpdate& ) ) );
117 connect( mSyncAction, TQT_SIGNAL( leftClickedURL() ),
118 this, TQT_SLOT( synchronize() ) );
119 connect( mConfigureAction, TQT_SIGNAL( leftClickedURL() ),
120 this, TQT_SLOT( configure() ) );
121 connect( mSyncProcess, TQT_SIGNAL( engineChanged( QSync::Engine* ) ),
122 this, TQT_SLOT( engineChanged( QSync::Engine* ) ) );
124 mCallbackHandler->setEngine( mSyncProcess->engine() );
126 setSelectionForegroundColor( TDEGlobalSettings::textColor() );
127 setSelectionBackgroundColor( TDEGlobalSettings::alternateBackgroundColor() );
132 GroupItem::~GroupItem()
134 delete mCallbackHandler;
135 mCallbackHandler = 0;
138 void GroupItem::update()
142 mGroupName->setText( i18n(
"Group: %1" ).arg( mSyncProcess->group().name() ) );
144 TQDateTime dateTime = mSyncProcess->group().lastSynchronization();
145 if ( dateTime.isValid() )
146 mTime->setText( i18n(
"Last synchronized on: %1" ).arg( TDEGlobal::locale()->formatDateTime( dateTime ) ) );
148 mTime->setText( i18n(
"Not synchronized yet" ) );
150 mProgressBar->reset();
151 mProgressBar->hide();
153 QSync::Group group = mSyncProcess->group();
154 QSync::Group::Iterator memberIt( group.begin() );
155 QSync::Group::Iterator memberEndIt( group.end() );
157 for ( ; memberIt != memberEndIt; ++memberIt ) {
158 MemberItem *item =
new MemberItem( mBox, mSyncProcess, *memberIt );
160 item->setStatusMessage( i18n(
"Ready" ) );
161 mMemberItems.append( item );
165 void GroupItem::clear()
167 mGroupName->setText( TQString() );
169 TQValueList<MemberItem*>::Iterator it;
170 for ( it = mMemberItems.begin(); it != mMemberItems.end(); ++it )
173 mMemberItems.clear();
176 void GroupItem::conflict( QSync::SyncMapping mapping )
178 if ( mapping.changesCount() == 2 ) {
179 SingleConflictDialog dlg( mapping,
this );
182 MultiConflictDialog dlg( mapping,
this );
187 void GroupItem::change(
const QSync::SyncChangeUpdate &update )
189 switch ( update.type() ) {
190 case QSync::SyncChangeUpdate::Received:
192 mStatus->setText( i18n(
"%1 entries read" ).arg( mProcessedItems ) );
194 case QSync::SyncChangeUpdate::ReceivedInfo:
195 mStatus->setText( i18n(
"Receive information" ) );
197 case QSync::SyncChangeUpdate::Sent:
199 mStatus->setText( i18n(
"%1 entries written" ).arg( mMaxProcessedItems - mProcessedItems ) );
201 mProgressBar->show();
205 if ( mMaxProcessedItems != 0 )
206 progress = (mProcessedItems * 100) / mMaxProcessedItems;
211 mProgressBar->setProgress( 100 - progress );
214 case QSync::SyncChangeUpdate::WriteError:
215 mStatus->setText( i18n(
"Error" ) );
216 KPassivePopup::message( update.result().message(),
this );
218 case QSync::SyncChangeUpdate::ReceiveError:
219 mStatus->setText( i18n(
"Error" ) );
220 KPassivePopup::message( update.result().message(),
this );
223 mStatus->setText( TQString() );
228 void GroupItem::mapping(
const QSync::SyncMappingUpdate& )
232 void GroupItem::engine(
const QSync::SyncEngineUpdate &update )
234 switch ( update.type() ) {
235 case QSync::SyncEngineUpdate::EndPhaseConnected:
236 mStatus->setText( i18n(
"Connected" ) );
237 mProgressBar->setProgress( 0 );
238 mSynchronizing =
true;
239 mSyncAction->setText(
"Abort Synchronization" );
241 case QSync::SyncEngineUpdate::EndPhaseRead:
242 mStatus->setText( i18n(
"Data read" ) );
244 case QSync::SyncEngineUpdate::EndPhaseWrite:
245 mStatus->setText( i18n(
"Data written" ) );
246 mProgressBar->setProgress( 100 );
247 mProcessedItems = mMaxProcessedItems = 0;
249 case QSync::SyncEngineUpdate::EndPhaseDisconnected:
250 mStatus->setText( i18n(
"Disconnected" ) );
252 case QSync::SyncEngineUpdate::Error:
253 mStatus->setText( i18n(
"Synchronization failed" ) );
254 KPassivePopup::message( update.result().message(),
this );
257 mSynchronizing =
false;
258 mSyncAction->setText( i18n(
"Synchronize Now" ) );
260 case QSync::SyncEngineUpdate::SyncSuccessfull:
261 mStatus->setText( i18n(
"Successfully synchronized" ) );
262 mSyncProcess->group().setLastSynchronization( TQDateTime::currentDateTime() );
263 mSyncProcess->group().save();
266 mSynchronizing =
false;
267 mSyncAction->setText( i18n(
"Synchronize Now" ) );
269 case QSync::SyncEngineUpdate::PrevUnclean:
270 mStatus->setText( i18n(
"Previous synchronization failed" ) );
272 case QSync::SyncEngineUpdate::EndConflicts:
273 mStatus->setText( i18n(
"Conflicts solved" ) );
274 mMaxProcessedItems = mProcessedItems;
277 mStatus->setText( TQString() );
282 void GroupItem::member(
const QSync::SyncMemberUpdate &update )
284 TQValueList<MemberItem*>::Iterator it;
285 for ( it = mMemberItems.begin(); it != mMemberItems.end(); ++it ) {
286 if ( (*it)->member() == update.member() ) {
287 switch ( update.type() ) {
288 case QSync::SyncMemberUpdate::Connected:
289 (*it)->setStatusMessage( i18n(
"Connected" ) );
291 case QSync::SyncMemberUpdate::SentChanges:
292 (*it)->setStatusMessage( i18n(
"Changes read" ) );
294 case QSync::SyncMemberUpdate::CommittedAll:
295 (*it)->setStatusMessage( i18n(
"Changes written" ) );
297 case QSync::SyncMemberUpdate::Disconnected:
298 (*it)->setStatusMessage( i18n(
"Disconnected" ) );
300 case QSync::SyncMemberUpdate::ConnectError:
301 (*it)->setStatusMessage( i18n(
"Error: %1" ).arg( update.result().message() ) );
303 case QSync::SyncMemberUpdate::GetChangesError:
304 (*it)->setStatusMessage( i18n(
"Error: %1" ).arg( update.result().message() ) );
306 case QSync::SyncMemberUpdate::CommittedAllError:
307 (*it)->setStatusMessage( i18n(
"Error: %1" ).arg( update.result().message() ) );
309 case QSync::SyncMemberUpdate::SyncDoneError:
310 (*it)->setStatusMessage( i18n(
"Error: %1" ).arg( update.result().message() ) );
312 case QSync::SyncMemberUpdate::DisconnectedError:
313 (*it)->setStatusMessage( i18n(
"Error: %1" ).arg( update.result().message() ) );
324 void GroupItem::synchronize()
326 if ( !mSynchronizing )
327 emit synchronizeGroup( mSyncProcess );
329 emit abortSynchronizeGroup( mSyncProcess );
332 void GroupItem::configure()
334 emit configureGroup( mSyncProcess );
339 void GroupItem::engineChanged( QSync::Engine *engine )
343 mCallbackHandler->setEngine( engine );
348 MemberItem::MemberItem( TQWidget *parent, SyncProcess *process,
349 const QSync::Member &member )
350 : TQWidget( parent ), mSyncProcess( process ), mMember( member )
353 boldFont.setBold(
true );
355 MemberInfo mi( member );
357 TQPixmap icon = mi.smallIcon();
359 QSync::Plugin plugin = member.plugin();
361 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
363 TQHBox* box =
new TQHBox(
this );
365 box->setSpacing( 6 );
366 layout->addWidget( box );
368 mIcon =
new TQLabel( box );
369 mIcon->setPixmap( icon );
370 mIcon->setAlignment( TQt::AlignTop );
371 mIcon->setFixedWidth( mIcon->sizeHint().width() );
373 TQVBox *nameBox =
new TQVBox( box );
374 mMemberName =
new TQLabel( nameBox );
375 mMemberName->setFont( boldFont );
376 mDescription =
new TQLabel( nameBox );
378 mStatus =
new TQLabel( box );
380 mMemberName->setText( member.name() );
381 mDescription->setText( plugin.longName() );
384 void MemberItem::setStatusMessage(
const TQString &msg )
386 mStatus->setText( msg );
389 #include "groupitem.moc"