syncerpart.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "syncerpart.h"
00023
00024 #include "calendarsyncee.h"
00025 #include "addressbooksyncee.h"
00026
00027 #include <konnectorview.h>
00028 #include <syncuikde.h>
00029 #include <konnector.h>
00030 #include <configwidget.h>
00031 #include <konnectormanager.h>
00032 #include <konnectorinfo.h>
00033 #include <mainwindow.h>
00034 #include <engine.h>
00035
00036 #include <kaboutdata.h>
00037 #include <kiconloader.h>
00038 #include <kparts/genericfactory.h>
00039 #include <kmessagebox.h>
00040 #include <kdialog.h>
00041 #include <kdialogbase.h>
00042
00043 #include <qlabel.h>
00044 #include <qlistview.h>
00045 #include <qpushbutton.h>
00046 #include <qtextview.h>
00047 #include <qlayout.h>
00048 #include <qdatetime.h>
00049 #include <qcheckbox.h>
00050
00051
00052 typedef KParts::GenericFactory< KSync::SyncerPart> SyncerPartFactory;
00053 K_EXPORT_COMPONENT_FACTORY( libksync_syncerpart, SyncerPartFactory )
00054
00055 using namespace KCal;
00056 using namespace KSync;
00057
00058 SyncerPart::SyncerPart( QWidget *parent, const char *name,
00059 QObject *, const char *, const QStringList & )
00060 : ActionPart( parent, name ), m_widget( 0 )
00061 {
00062 m_pixmap = KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop,
00063 48 );
00064
00065 mSyncUi = new SyncUiKde( parent, true, true );
00066
00067 mCalendarSyncer.setSyncUi( mSyncUi );
00068 mAddressBookSyncer.setSyncUi( mSyncUi );
00069 }
00070
00071 KAboutData *SyncerPart::createAboutData()
00072 {
00073 return new KAboutData( "KSyncSyncerPart", I18N_NOOP("Sync SyncerPart Part"),
00074 "0.0" );
00075 }
00076
00077 SyncerPart::~SyncerPart()
00078 {
00079 delete m_widget;
00080
00081 delete mSyncUi;
00082 }
00083
00084 QString SyncerPart::type() const
00085 {
00086 return QString::fromLatin1("SyncerPart");
00087 }
00088
00089 QString SyncerPart::title() const
00090 {
00091 return i18n("Synchronizer");
00092 }
00093
00094 QString SyncerPart::description() const
00095 {
00096 return i18n("Synchronizer");
00097 }
00098
00099 QPixmap *SyncerPart::pixmap()
00100 {
00101 return &m_pixmap;
00102 }
00103
00104 QString SyncerPart::iconName() const
00105 {
00106 return QString::fromLatin1("kcmsystem");
00107 }
00108
00109 bool SyncerPart::hasGui() const
00110 {
00111 return true;
00112 }
00113
00114 QWidget *SyncerPart::widget()
00115 {
00116 if( !m_widget ) {
00117 m_widget = new QWidget;
00118 QBoxLayout *topLayout = new QVBoxLayout( m_widget );
00119 topLayout->setSpacing( KDialog::spacingHint() );
00120
00121
00122 QBoxLayout *konnectorLayout = new QHBoxLayout( topLayout );
00123
00124 mKonnectorView = new KonnectorView( m_widget );
00125 konnectorLayout->addWidget( mKonnectorView, 1 );
00126
00127 QFrame *konnectorFrame = new QFrame( m_widget );
00128 konnectorFrame->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00129 konnectorLayout->addWidget( konnectorFrame, 1 );
00130
00131
00132 mLogView = new QTextView( m_widget );
00133 mLogView->setTextFormat( LogText );
00134 topLayout->addWidget( mLogView );
00135
00136 logMessage( i18n("Ready.") );
00137 }
00138 return m_widget;
00139 }
00140
00141 void SyncerPart::slotProgress( Konnector *k, const Progress &p )
00142 {
00143 logMessage( i18n("Got Progress from Konnector at address %1: %2").arg( (long)k ).arg( p.text() ) );
00144 }
00145
00146 void SyncerPart::slotError( Konnector *k, const Error &e )
00147 {
00148 logMessage( i18n("Got Progress from Konnector at address %1: %2").arg( (long)k ).arg( e.text() ) );
00149 }
00150
00151
00152 void SyncerPart::logMessage( const QString &message )
00153 {
00154 QString text = "<b>" + QTime::currentTime().toString() + "</b>: ";
00155 text += message;
00156
00157 mLogView->append( text );
00158 }
00159
00160 void SyncerPart::executeAction()
00161 {
00162 logMessage( i18n("Sync Action triggered") );
00163
00164 mCalendarSyncer.clear();
00165 mAddressBookSyncer.clear();
00166
00167 Konnector::List konnectors = core()->engine()->konnectors();
00168 Konnector *k;
00169 for( k = konnectors.first(); k; k = konnectors.next() ) {
00170 SynceeList syncees = k->syncees();
00171
00172 if ( syncees.count() == 0 ) {
00173 logMessage( i18n("Syncee list is empty.") );
00174 continue;
00175 }
00176
00177 CalendarSyncee *calendarSyncee = syncees.calendarSyncee();
00178 if ( calendarSyncee ) mCalendarSyncer.addSyncee( calendarSyncee );
00179
00180 AddressBookSyncee *addressBookSyncee = syncees.addressBookSyncee();
00181 if ( addressBookSyncee ) mAddressBookSyncer.addSyncee( addressBookSyncee );
00182 }
00183
00184 logMessage( i18n("Performing Sync") );
00185
00186 mCalendarSyncer.sync();
00187 mAddressBookSyncer.sync();
00188
00189 logMessage( i18n("Sync done") );
00190 }
00191
00192 #include "syncerpart.moc"
This file is part of the documentation for kitchensync Library Version 3.3.2.