kitchensync Library API Documentation

syncerpart.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library 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 GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
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 // FIXME: Move logging of all parts to common class
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"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:47:07 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003