kitchensync
konnectorpairview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qtimer.h>
00023 #include <klocale.h>
00024
00025 #include "konnectorpairmanager.h"
00026
00027 #include "konnectorpairview.h"
00028
00029 KonnectorPairItem::KonnectorPairItem( KonnectorPair *pair, KListView *parent )
00030 : QObject( 0 ), QListViewItem( parent ), mPair( pair )
00031 {
00032 connect( pair->manager(), SIGNAL( synceesRead( KSync::Konnector* ) ),
00033 this, SLOT( synceesRead( KSync::Konnector* ) ) );
00034 connect( pair->manager(), SIGNAL( synceeReadError( KSync::Konnector* ) ),
00035 this, SLOT( synceeReadError( KSync::Konnector* ) ) );
00036 connect( pair->manager(), SIGNAL( synceesWritten( KSync::Konnector* ) ),
00037 this, SLOT( synceesWritten( KSync::Konnector* ) ) );
00038 connect( pair->manager(), SIGNAL( synceeWriteError( KSync::Konnector* ) ),
00039 this, SLOT( synceeWriteError( KSync::Konnector* ) ) );
00040 connect( pair->manager(), SIGNAL( syncFinished() ),
00041 this, SLOT( syncFinished() ) );
00042
00043 initialState();
00044 }
00045
00046 QString KonnectorPairItem::text( int column ) const
00047 {
00048 switch ( column ) {
00049 case 0:
00050 return i18n( "Yes" );
00051 break;
00052 case 1:
00053 return mPair->name();
00054 break;
00055 case 2:
00056 return mStatusMsg;
00057 break;
00058 default:
00059 return QString::null;
00060 }
00061 }
00062
00063 QString KonnectorPairItem::uid() const
00064 {
00065 return mPair->uid();
00066 }
00067
00068 void KonnectorPairItem::initialState()
00069 {
00070 mStatusMsg = i18n( "Press \"Sync\" to synchronize" );
00071 repaint();
00072 }
00073
00074 void KonnectorPairItem::synceesRead( Konnector *konnector )
00075 {
00076 mStatusMsg = i18n( "Retrieve data from %1..." ).arg( konnector->resourceName() );
00077 repaint();
00078 }
00079
00080 void KonnectorPairItem::synceeReadError( Konnector *konnector )
00081 {
00082 mStatusMsg = i18n( "Couldn't retrieve data from %1..." ).arg( konnector->resourceName() );
00083 repaint();
00084 }
00085
00086 void KonnectorPairItem::synceesWritten( Konnector *konnector )
00087 {
00088 mStatusMsg = i18n( "Write back data to %1..." ).arg( konnector->resourceName() );
00089 repaint();
00090 }
00091
00092 void KonnectorPairItem::synceeWriteError( Konnector *konnector )
00093 {
00094 mStatusMsg = i18n( "Couldn't write back data to %1..." ).arg( konnector->resourceName() );
00095 repaint();
00096 }
00097
00098 void KonnectorPairItem::syncFinished()
00099 {
00100 mStatusMsg = i18n( "Synchronization finished" );
00101 repaint();
00102
00103 QTimer::singleShot( 2, this, SLOT( initialState() ) );
00104 }
00105
00106
00107
00108 KonnectorPairView::KonnectorPairView( KonnectorPairManager* manager, QWidget *parent )
00109 : KListView( parent ), mManager( manager )
00110 {
00111 addColumn( i18n( "Enabled" ) );
00112 addColumn( i18n( "Name" ) );
00113 addColumn( i18n( "State" ) );
00114
00115 setAllColumnsShowFocus( true );
00116 setFullWidth( true );
00117
00118 connect( manager, SIGNAL( changed() ),
00119 this, SLOT( refreshView() ) );
00120 connect( this, SIGNAL( selectionChanged() ),
00121 this, SLOT( slotSelectionChanged() ) );
00122 connect( this, SIGNAL( currentChanged( QListViewItem* ) ),
00123 this, SLOT( slotSelectionChanged() ) );
00124 }
00125
00126 KonnectorPairView::~KonnectorPairView()
00127 {
00128 }
00129
00130 QString KonnectorPairView::selectedPair() const
00131 {
00132 KonnectorPairItem *item = static_cast<KonnectorPairItem*>( selectedItem() );
00133 if ( item )
00134 return item->uid();
00135 else
00136 return QString::null;
00137 }
00138
00139 void KonnectorPairView::refresh()
00140 {
00141 refreshView();
00142 }
00143
00144 void KonnectorPairView::refreshView()
00145 {
00146 clear();
00147
00148 KonnectorPair::List pairs = mManager->pairs();
00149 KonnectorPair::List::Iterator it;
00150 for ( it = pairs.begin(); it != pairs.end(); ++it )
00151 new KonnectorPairItem( *it, this );
00152
00153 setSelected( firstChild(), true );
00154 }
00155
00156 void KonnectorPairView::slotSelectionChanged()
00157 {
00158 emit konnectorPairSelected( selectedItem() != 0 );
00159 }
00160
00161 #include "konnectorpairview.moc"
|