00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "mainwidget.h"
00023
00024 #include "groupconfigdialog.h"
00025 #include "groupview.h"
00026 #include "syncprocess.h"
00027 #include "syncprocessmanager.h"
00028
00029 #include <libqopensync/environment.h>
00030
00031 #include <tdeaboutdata.h>
00032 #include <tdeaction.h>
00033 #include <kdebug.h>
00034 #include <kinputdialog.h>
00035 #include <tdelistview.h>
00036 #include <tdelocale.h>
00037 #include <tdemessagebox.h>
00038 #include <kstdaction.h>
00039 #include <kxmlguiclient.h>
00040
00041 #include <tqlayout.h>
00042
00043 MainWidget::MainWidget( KXMLGUIClient *guiClient, TQWidget *widget, const char *name )
00044 : TQWidget( widget, name ), mGUIClient( guiClient )
00045 {
00046 initGUI();
00047 initActions();
00048
00050 int count = SyncProcessManager::self()->count();
00051 for ( int i = 0; i < count; ++i ) {
00052 SyncProcessManager::self()->at( i )->applyObjectTypeFilter();
00053 }
00056 mGroupView->updateView();
00057
00058 connect( SyncProcessManager::self(), TQT_SIGNAL( changed() ),
00059 mGroupView, TQT_SLOT( updateView() ) );
00060 connect( SyncProcessManager::self(), TQT_SIGNAL( syncProcessChanged( SyncProcess* ) ),
00061 mGroupView, TQT_SLOT( updateSyncProcess( SyncProcess* ) ) );
00062
00063 enableActions();
00064 }
00065
00066 MainWidget::~MainWidget()
00067 {
00068 }
00069
00070 KXMLGUIClient *MainWidget::guiClient() const
00071 {
00072 return mGUIClient;
00073 }
00074
00075 TDEAboutData *MainWidget::aboutData()
00076 {
00077 TDEAboutData *about = new TDEAboutData( "kitchensync", I18N_NOOP( "KitchenSync" ),
00078 "0.1", I18N_NOOP( "The TDE Syncing Application" ),
00079 TDEAboutData::License_GPL_V2,
00080 I18N_NOOP( "(c) 2005, The KDE PIM Team" ) );
00081 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer" ), "tokoe@kde.org" );
00082 about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00083
00084 return about;
00085 }
00086
00087 void MainWidget::initGUI()
00088 {
00089 TQVBoxLayout *topLayout = new TQVBoxLayout( this );
00090
00091 mGroupView = new GroupView( this );
00092 topLayout->addWidget( mGroupView );
00093
00094 connect( mGroupView, TQT_SIGNAL( addGroup() ), TQT_SLOT( addGroup() ) );
00095 connect( mGroupView, TQT_SIGNAL( synchronizeGroup( SyncProcess* ) ),
00096 TQT_SLOT( sync( SyncProcess* ) ) );
00097 connect( mGroupView, TQT_SIGNAL( abortSynchronizeGroup( SyncProcess* ) ),
00098 TQT_SLOT( abortSync( SyncProcess* ) ) );
00099 connect( mGroupView, TQT_SIGNAL( configureGroup( SyncProcess* ) ),
00100 TQT_SLOT( editGroup( SyncProcess* ) ) );
00101 }
00102
00103 void MainWidget::initActions()
00104 {
00105 mActionSynchronize = new TDEAction( i18n("Synchronize"), "hotsync", 0, TQT_TQOBJECT(this), TQT_SLOT( sync() ),
00106 mGUIClient->actionCollection(), "sync" );
00107 mActionAddGroup = new TDEAction( i18n("Add Group..."), "document-new", 0, TQT_TQOBJECT(this), TQT_SLOT( addGroup() ),
00108 mGUIClient->actionCollection(), "add_group" );
00109 mActionDeleteGroup = new TDEAction( i18n("Delete Group..."), "edit-delete", 0, TQT_TQOBJECT(this), TQT_SLOT( deleteGroup() ),
00110 mGUIClient->actionCollection(), "delete_group" );
00111 mActionEditGroup = new TDEAction( i18n("Edit Group..."), "edit", 0, TQT_TQOBJECT(this), TQT_SLOT( editGroup() ),
00112 mGUIClient->actionCollection(), "edit_group" );
00113 }
00114
00115 void MainWidget::enableActions()
00116 {
00117 bool state = ( SyncProcessManager::self()->count() > 0 );
00118
00119 mActionSynchronize->setEnabled( state );
00120 mActionDeleteGroup->setEnabled( state );
00121 mActionEditGroup->setEnabled( state );
00122 }
00123
00124 void MainWidget::addGroup()
00125 {
00126 bool ok;
00127 TQString name = KInputDialog::getText( i18n("Create Synchronization Group"),
00128 i18n("Name for new synchronization group."), TQString(), &ok, this );
00129 if ( ok ) {
00130 SyncProcessManager::self()->addGroup( name );
00131 enableActions();
00132
00133 SyncProcess *process = SyncProcessManager::self()->byGroupName( name );
00134 if ( process )
00135 editGroup( process );
00136 }
00137 }
00138
00139 void MainWidget::deleteGroup()
00140 {
00141 SyncProcess *syncProcess = mGroupView->selectedSyncProcess();
00142 if ( syncProcess ) {
00143 int result = KMessageBox::warningContinueCancel( this,
00144 i18n("Delete synchronization group '%1'?").arg( syncProcess->group().name() ) );
00145 if ( result == KMessageBox::Continue ) {
00146 SyncProcessManager::self()->remove( syncProcess );
00147 enableActions();
00148 }
00149 }
00150 }
00151
00152 void MainWidget::editGroup()
00153 {
00154 editGroup( mGroupView->selectedSyncProcess() );
00155 }
00156
00157 void MainWidget::editGroup( SyncProcess *syncProcess )
00158 {
00159 if ( syncProcess ) {
00160 GroupConfigDialog dlg( this, syncProcess );
00161 dlg.exec();
00162
00163 enableActions();
00164 }
00165 }
00166
00167 void MainWidget::sync()
00168 {
00169 sync( mGroupView->selectedSyncProcess() );
00170 }
00171
00172 void MainWidget::sync( SyncProcess *syncProcess )
00173 {
00174 if ( syncProcess ) {
00175 syncProcess->reinitEngine();
00176 QSync::Result result = syncProcess->engine()->synchronize();
00177 if ( result ) {
00178 tqDebug( "%s", result.message().latin1() );
00179 } else {
00180 tqDebug( "synchronization worked" );
00181 }
00182 }
00183 }
00184
00185 void MainWidget::abortSync( SyncProcess *syncProcess )
00186 {
00187 if ( syncProcess )
00188 syncProcess->engine()->abort();
00189 }
00190
00191 #include "mainwidget.moc"