kitchensync

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., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, 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 <konnectormanager.h>
00031 #include <konnectorinfo.h>
00032 #include <mainwindow.h>
00033 #include <engine.h>
00034 
00035 #include <kaboutdata.h>
00036 #include <kiconloader.h>
00037 #include <kparts/genericfactory.h>
00038 #include <kmessagebox.h>
00039 #include <kdialog.h>
00040 #include <kdialogbase.h>
00041 
00042 #include <qlabel.h>
00043 #include <qlistview.h>
00044 #include <qpushbutton.h>
00045 #include <qtextview.h>
00046 #include <qlayout.h>
00047 #include <qdatetime.h>
00048 #include <qcheckbox.h>
00049 
00050 
00051 typedef KParts::GenericFactory< KSync::SyncerPart> SyncerPartFactory;
00052 K_EXPORT_COMPONENT_FACTORY( libksync_syncerpart, SyncerPartFactory )
00053 
00054 using namespace KCal;
00055 using namespace KSync;
00056 
00057 SyncerPart::SyncerPart( QWidget *parent, const char *name,
00058                         QObject *, const char *, const QStringList & )
00059   : ActionPart( parent, name ), m_widget( 0 )
00060 {
00061   m_pixmap = KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop,
00062                                               48 );
00063 
00064   /* confirm delete will be changed later */
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 // FIXME: Move logging of all parts to common class
00142 void SyncerPart::logMessage( const QString &message )
00143 {
00144   QString text = "<b>" + QTime::currentTime().toString() + "</b>: ";
00145   text += message;
00146 
00147   mLogView->append( text );
00148 }
00149 
00150 void SyncerPart::executeAction()
00151 {
00152   logMessage( i18n("Sync Action triggered") );
00153 
00154   mCalendarSyncer.clear();
00155   mAddressBookSyncer.clear();
00156 
00157   /* set confirmDelete according user preference */
00158   mSyncUi->setConfirmDelete( core()->currentProfile().confirmDelete() );
00159 
00160   Konnector::List konnectors = core()->engine()->konnectors();
00161   Konnector *k;
00162   for( k = konnectors.first(); k; k = konnectors.next() ) {
00163     SynceeList syncees = k->syncees();
00164 
00165     if ( syncees.count() == 0 ) {
00166       logMessage( i18n("Syncee list is empty.") );
00167       continue;
00168     }
00169 
00170     CalendarSyncee *calendarSyncee = syncees.calendarSyncee();
00171     if ( calendarSyncee ) mCalendarSyncer.addSyncee( calendarSyncee );
00172 
00173     AddressBookSyncee *addressBookSyncee = syncees.addressBookSyncee();
00174     if ( addressBookSyncee ) mAddressBookSyncer.addSyncee( addressBookSyncee );
00175   }
00176 
00177   logMessage( i18n("Performing Sync") );
00178 
00179   mCalendarSyncer.sync();
00180   mAddressBookSyncer.sync();
00181 
00182   logMessage( i18n("Sync done") );
00183 }
00184 
00185 #include "syncerpart.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys