kitchensync

mainwidget.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@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 <qlayout.h>
00023 
00024 #include <kaboutdata.h>
00025 #include <kaction.h>
00026 #include <klistview.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 #include <kpassivepopup.h>
00030 #include <kstdaction.h>
00031 #include <kxmlguiclient.h>
00032 
00033 #include "engine.h"
00034 #include "konnectorpairview.h"
00035 #include "konnectorpairmanager.h"
00036 #include "logdialog.h"
00037 #include "paireditordialog.h"
00038 
00039 #include "mainwidget.h"
00040 
00041 MainWidget::MainWidget( KXMLGUIClient *guiClient, QWidget *widget, const char *name )
00042   : QWidget( widget, name ), mGUIClient( guiClient )
00043 {
00044   mManager = new KonnectorPairManager( this );
00045   mManager->load();
00046 
00047   mEngine = new KSync::Engine();
00048 
00049   mLogDialog = new LogDialog( this );
00050   mLogDialog->hide();
00051 
00052   initGUI();
00053 
00054   connect( mView, SIGNAL( konnectorPairSelected( bool ) ),
00055            this, SLOT( konnectorPairSelected( bool ) ) );
00056   connect( mEngine, SIGNAL( error( const QString& ) ),
00057            this, SLOT( engineError( const QString& ) ) );
00058 
00059   mView->refresh();
00060 }
00061 
00062 MainWidget::~MainWidget()
00063 {
00064   mManager->save();
00065 
00066   delete mManager;
00067   mManager = 0;
00068 
00069   delete mEngine;
00070   mEngine = 0;
00071 }
00072 
00073 KActionCollection *MainWidget::actionCollection() const
00074 {
00075   return mGUIClient->actionCollection();
00076 }
00077 
00078 KAboutData *MainWidget::aboutData()
00079 {
00080   KAboutData *about = new KAboutData( "multisynk", I18N_NOOP( "MultiSynK" ),
00081                                       "0.1", I18N_NOOP( "The KDE Syncing Application" ),
00082                                       KAboutData::License_GPL_V2,
00083                                       I18N_NOOP( "(c) 2004, The KDE PIM Team" ) );
00084   about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer" ), "tokoe@kde.org" );
00085 
00086   return about;
00087 }
00088 
00089 void MainWidget::addPair()
00090 {
00091   PairEditorDialog dlg( this );
00092 
00093   KonnectorPair *pair = new KonnectorPair;
00094   dlg.setPair( pair );
00095 
00096   if ( dlg.exec() )
00097     mManager->add( dlg.pair() );
00098   else
00099     delete pair;
00100 }
00101 
00102 void MainWidget::editPair()
00103 {
00104   QString uid = mView->selectedPair();
00105 
00106   if ( uid.isEmpty() )
00107     return;
00108 
00109   KonnectorPair *pair = mManager->pair( uid );
00110   if ( !pair )
00111     return;
00112 
00113   PairEditorDialog dlg( this );
00114   dlg.setPair( pair );
00115 
00116   if ( dlg.exec() )
00117     mManager->change( dlg.pair() );
00118 }
00119 
00120 void MainWidget::deletePair()
00121 {
00122   QString uid = mView->selectedPair();
00123 
00124   if ( !uid.isEmpty() ) {
00125     KonnectorPair *pair = mManager->pair( uid );
00126     int result = KMessageBox::questionYesNo( this, i18n( "Do you really want to delete '%1'?" ).arg( pair->name() ),
00127                                              i18n( "Delete Synchronization Pair" ), KStdGuiItem::del(), KStdGuiItem::cancel() );
00128     if ( result == KMessageBox::Yes )
00129       mManager->remove( uid );
00130   }
00131 }
00132 
00133 void MainWidget::showLog()
00134 {
00135   mLogDialog->show();
00136   mLogDialog->raise();
00137 }
00138 
00139 void MainWidget::startSync()
00140 {
00141   QString uid = mView->selectedPair();
00142 
00143   if ( uid.isEmpty() )
00144     return;
00145 
00146   KonnectorPair *pair = mManager->pair( uid );
00147 
00148   disconnect( pair->manager(), SIGNAL( synceesRead( KSync::Konnector* ) ),
00149               mEngine, SLOT( slotSynceesRead( KSync::Konnector* ) ) );
00150   disconnect( pair->manager(), SIGNAL( synceeReadError( KSync::Konnector* ) ),
00151               mEngine, SLOT( slotSynceeReadError( KSync::Konnector* ) ) );
00152   disconnect( pair->manager(), SIGNAL( synceesWritten( KSync::Konnector* ) ),
00153               mEngine, SLOT( slotSynceesWritten( KSync::Konnector* ) ) );
00154   disconnect( pair->manager(), SIGNAL( synceeWriteError( KSync::Konnector* ) ),
00155               mEngine, SLOT( slotSynceeWriteError( KSync::Konnector* ) ) );
00156   disconnect( mEngine, SIGNAL( doneSync() ),
00157               this, SLOT( syncDone() ) );
00158 
00159 
00160   connect( pair->manager(), SIGNAL( synceesRead( KSync::Konnector* ) ),
00161            mEngine, SLOT( slotSynceesRead( KSync::Konnector* ) ) );
00162   connect( pair->manager(), SIGNAL( synceeReadError( KSync::Konnector* ) ),
00163            mEngine, SLOT( slotSynceeReadError( KSync::Konnector* ) ) );
00164   connect( pair->manager(), SIGNAL( synceesWritten( KSync::Konnector* ) ),
00165            mEngine, SLOT( slotSynceesWritten( KSync::Konnector* ) ) );
00166   connect( pair->manager(), SIGNAL( synceeWriteError( KSync::Konnector* ) ),
00167            mEngine, SLOT( slotSynceeWriteError( KSync::Konnector* ) ) );
00168   connect( mEngine, SIGNAL( doneSync() ),
00169            this, SLOT( syncDone() ) );
00170 
00171   mEngine->go( pair );
00172 }
00173 
00174 void MainWidget::syncDone()
00175 {
00176   QString uid = mView->selectedPair();
00177 
00178   if ( uid.isEmpty() )
00179     return;
00180 
00181   KonnectorPair *pair = mManager->pair( uid );
00182 
00183   disconnect( pair->manager(), SIGNAL( synceesRead( KSync::Konnector* ) ),
00184               mEngine, SLOT( slotSynceesRead( KSync::Konnector* ) ) );
00185   disconnect( pair->manager(), SIGNAL( synceeReadError( KSync::Konnector* ) ),
00186               mEngine, SLOT( slotSynceeReadError( KSync::Konnector* ) ) );
00187   disconnect( pair->manager(), SIGNAL( synceesWritten( KSync::Konnector* ) ),
00188               mEngine, SLOT( slotSynceesWritten( KSync::Konnector* ) ) );
00189   disconnect( pair->manager(), SIGNAL( synceeWriteError( KSync::Konnector* ) ),
00190               mEngine, SLOT( slotSynceeWriteError( KSync::Konnector* ) ) );
00191   disconnect( mEngine, SIGNAL( doneSync() ),
00192               this, SLOT( syncDone() ) );
00193 }
00194 
00195 void MainWidget::konnectorPairSelected( bool state )
00196 {
00197   mEditAction->setEnabled( state );
00198   mDeleteAction->setEnabled( state );
00199   mSyncAction->setEnabled( state );
00200 }
00201 
00202 void MainWidget::engineError( const QString &message )
00203 {
00204   KPassivePopup::message( message, this );
00205 }
00206 
00207 void MainWidget::initGUI()
00208 {
00209   QVBoxLayout *layout = new QVBoxLayout( this );
00210 
00211   mView = new KonnectorPairView( mManager, this );
00212   layout->addWidget( mView );
00213 
00214   new KAction( i18n( "New..." ), "filenew", 0, this, SLOT( addPair() ),
00215                actionCollection(), "new" );
00216   mEditAction = new KAction( i18n( "Edit..." ), "edit", 0, this,
00217                              SLOT( editPair() ), actionCollection(), "edit" );
00218   mEditAction->setEnabled( false );
00219 
00220   mDeleteAction = new KAction( i18n( "Delete..." ), "editdelete", 0, this,
00221                                SLOT( deletePair() ), actionCollection(), "delete" );
00222   mDeleteAction->setEnabled( false );
00223 
00224   new KAction( i18n( "Log" ), "filefind", 0, this, SLOT( showLog() ),
00225                actionCollection(), "log" );
00226 
00227   mSyncAction = new KAction( i18n( "Sync..." ), "hotsync", 0, this,
00228                              SLOT( startSync() ), actionCollection(), "sync" );
00229   mSyncAction->setEnabled( false );
00230 }
00231 
00232 #include "mainwidget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys