kincidencechooser.cpp
00001 /* 00002 This file is part of libtdepim. 00003 00004 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program 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 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqlayout.h> 00026 #include <tqlabel.h> 00027 #include <tqbuttongroup.h> 00028 #include <tqvbox.h> 00029 #include <tqhbox.h> 00030 #include <tqradiobutton.h> 00031 #include <tqpushbutton.h> 00032 #include <tqlayout.h> 00033 #include <tqscrollview.h> 00034 #include <tqtextbrowser.h> 00035 #include <tqapplication.h> 00036 00037 00038 #include <tdelocale.h> 00039 #include <tdeglobal.h> 00040 00041 #include "kincidencechooser.h" 00042 #include "libkcal/incidence.h" 00043 #include "libkcal/incidenceformatter.h" 00044 00045 int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ; 00046 00047 KIncidenceChooser::KIncidenceChooser(TQWidget *parent, char *name) : 00048 KDialog(parent,name,true) 00049 { 00050 KDialog *topFrame = this; 00051 TQGridLayout *topLayout = new TQGridLayout(topFrame,5,3); 00052 int iii = 0; 00053 setCaption( i18n("Conflict Detected")); 00054 TQLabel * lab; 00055 lab = new TQLabel( i18n( 00056 "<qt>A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally." 00057 "<br/>NOTE: You have to check mail again to apply your changes to the server.</qt>"), topFrame); 00058 topLayout->addMultiCellWidget(lab, iii,iii,0,2); 00059 ++iii; 00060 TQHBox * b_box = new TQHBox( topFrame ); 00061 topLayout->addMultiCellWidget(b_box, iii,iii,0,2); 00062 ++iii; 00063 TQPushButton* button = new TQPushButton( i18n("Take Local"), b_box ); 00064 connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence1() ) ); 00065 button = new TQPushButton( i18n("Take New"), b_box ); 00066 connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence2() ) ); 00067 button = new TQPushButton( i18n("Take Both"), b_box ); 00068 connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeBoth() ) ); 00069 topLayout->setSpacing(spacingHint()); 00070 topLayout->setMargin(marginHint()); 00071 // text is not translated, because text has to be set later 00072 mInc1lab = new TQLabel ( i18n("Local incidence"), topFrame); 00073 topLayout->addWidget(mInc1lab ,iii,0); 00074 mInc1Sumlab = new TQLabel ( i18n("Local incidence summary"), topFrame); 00075 topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2); 00076 ++iii; 00077 topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); 00078 mMod1lab = new TQLabel ( "Set Last modified", topFrame); 00079 topLayout->addWidget(mMod1lab,iii,1); 00080 mShowDetails1 = new TQPushButton( i18n("Show Details"),topFrame ); 00081 connect ( mShowDetails1, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence1() ) ); 00082 topLayout->addWidget(mShowDetails1,iii,2); 00083 ++iii; 00084 00085 mInc2lab = new TQLabel ( "Local incidence", topFrame); 00086 topLayout->addWidget(mInc2lab,iii,0); 00087 mInc2Sumlab = new TQLabel ( "Local incidence summary", topFrame); 00088 topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2); 00089 ++iii; 00090 topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); 00091 mMod2lab = new TQLabel ( "Set Last modified", topFrame); 00092 topLayout->addWidget(mMod2lab,iii,1); 00093 mShowDetails2 = new TQPushButton( i18n("Show Details"), topFrame); 00094 connect ( mShowDetails2, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence2() ) ); 00095 topLayout->addWidget(mShowDetails2,iii,2); 00096 ++iii; 00097 // 00098 #if 0 00099 // commented out for now, because the diff code has too many bugs 00100 mDiffBut = new TQPushButton( i18n("Show Differences"), topFrame ); 00101 connect ( mDiffBut, TQT_SIGNAL( clicked()), this, TQT_SLOT ( showDiff() ) ); 00102 topLayout->addMultiCellWidget(mDiffBut, iii,iii,0,2); 00103 ++iii; 00104 #else 00105 mDiffBut = 0; 00106 #endif 00107 mBg = new TQButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame); 00108 topLayout->addMultiCellWidget(mBg, iii,iii,0,2); 00109 ++iii; 00110 mBg->insert( new TQRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local); 00111 mBg->insert( new TQRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote); 00112 mBg->insert( new TQRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest ); 00113 mBg->insert( new TQRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask ); 00114 mBg->insert( new TQRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both ); 00115 mBg->setButton ( chooseMode ); 00116 mTbL = 0; 00117 mTbN = 0; 00118 mDisplayDiff = 0; 00119 mSelIncidence = 0; 00120 button = new TQPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame ); 00121 connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT ( setSyncMode() ) ); 00122 topLayout->addMultiCellWidget(button, iii,iii,0,2); 00123 } 00124 00125 KIncidenceChooser::~KIncidenceChooser() 00126 { 00127 if ( mTbL ) delete mTbL; 00128 if ( mTbN ) delete mTbN; 00129 if ( mDisplayDiff ) { 00130 delete mDisplayDiff; 00131 delete diff; 00132 } 00133 } 00134 00135 void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote ) 00136 { 00137 mInc1 = local; 00138 mInc2 = remote; 00139 setLabels(); 00140 00141 } 00142 KCal::Incidence* KIncidenceChooser::getIncidence( ) 00143 { 00144 00145 KCal::Incidence* retval = mSelIncidence; 00146 if ( chooseMode == KIncidenceChooser::local ) 00147 retval = mInc1; 00148 else if ( chooseMode == KIncidenceChooser::remote ) 00149 retval = mInc2; 00150 else if ( chooseMode == KIncidenceChooser::both ) { 00151 retval = 0; 00152 } 00153 else if ( chooseMode == KIncidenceChooser::newest ) { 00154 if ( mInc1->lastModified() == mInc2->lastModified()) 00155 retval = 0; 00156 if ( mInc1->lastModified() > mInc2->lastModified() ) 00157 retval = mInc1; 00158 else 00159 retval = mInc2; 00160 } 00161 return retval; 00162 } 00163 00164 void KIncidenceChooser::setSyncMode() 00165 { 00166 chooseMode = mBg->selectedId (); 00167 if ( chooseMode != KIncidenceChooser::ask ) 00168 TQDialog::accept(); 00169 00170 } 00171 00172 void KIncidenceChooser::useGlobalMode() 00173 { 00174 if ( chooseMode != KIncidenceChooser::ask ) 00175 TQDialog::reject(); 00176 } 00177 00178 void KIncidenceChooser::setLabels() 00179 { 00180 KCal::Incidence* inc = mInc1; 00181 TQLabel* des = mInc1lab; 00182 TQLabel * sum = mInc1Sumlab; 00183 00184 00185 if ( inc->type() == "Event" ) { 00186 des->setText( i18n( "Local Event") ); 00187 sum->setText( inc->summary().left( 30 )); 00188 if ( mDiffBut ) 00189 mDiffBut->setEnabled( true ); 00190 } 00191 else if ( inc->type() == "Todo" ) { 00192 des->setText( i18n( "Local Todo") ); 00193 sum->setText( inc->summary().left( 30 )); 00194 if ( mDiffBut ) 00195 mDiffBut->setEnabled( true ); 00196 00197 } 00198 else if ( inc->type() == "Journal" ) { 00199 des->setText( i18n( "Local Journal") ); 00200 sum->setText( inc->description().left( 30 )); 00201 if ( mDiffBut ) 00202 mDiffBut->setEnabled( false ); 00203 } 00204 mMod1lab->setText( TDEGlobal::locale()->formatDateTime(inc->lastModified() )); 00205 inc = mInc2; 00206 des = mInc2lab; 00207 sum = mInc2Sumlab; 00208 if ( inc->type() == "Event" ) { 00209 des->setText( i18n( "New Event") ); 00210 sum->setText( inc->summary().left( 30 )); 00211 } 00212 else if ( inc->type() == "Todo" ) { 00213 des->setText( i18n( "New Todo") ); 00214 sum->setText( inc->summary().left( 30 )); 00215 00216 } 00217 else if ( inc->type() == "Journal" ) { 00218 des->setText( i18n( "New Journal") ); 00219 sum->setText( inc->description().left( 30 )); 00220 00221 } 00222 mMod2lab->setText( TDEGlobal::locale()->formatDateTime(inc->lastModified() )); 00223 } 00224 00225 void KIncidenceChooser::showIncidence1() 00226 { 00227 if ( mTbL ) { 00228 if ( mTbL->isVisible() ) { 00229 mShowDetails1->setText( i18n("Show Details")); 00230 mTbL->hide(); 00231 } else { 00232 mShowDetails1->setText( i18n("Hide Details")); 00233 mTbL->show(); 00234 mTbL->raise(); 00235 } 00236 return; 00237 } 00238 mTbL = new KDialogBase( this, "", false /*not modal*/, mInc1lab->text(), KDialogBase::Ok ); 00239 mTbL->setEscapeButton( KDialogBase::Ok ); 00240 connect( mTbL, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); 00241 TQTextBrowser* textBrowser = new TQTextBrowser( mTbL ); 00242 mTbL->setMainWidget( textBrowser ); 00243 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) ); 00244 mTbL->setMinimumSize( 400, 400 ); 00245 mShowDetails1->setText( i18n("Hide Details")); 00246 mTbL->show(); 00247 mTbL->raise(); 00248 } 00249 00250 void KIncidenceChooser::detailsDialogClosed() 00251 { 00252 KDialogBase* dialog = static_cast<KDialogBase *>( TQT_TQWIDGET( const_cast<TQT_BASE_OBJECT_NAME*>(sender()) ) ); 00253 if ( dialog == mTbL ) 00254 mShowDetails1->setText( i18n( "Show details..." ) ); 00255 else 00256 mShowDetails2->setText( i18n( "Show details..." ) ); 00257 } 00258 00259 void KIncidenceChooser::showDiff() 00260 { 00261 if ( mDisplayDiff ) { 00262 mDisplayDiff->show(); 00263 mDisplayDiff->raise(); 00264 return; 00265 } 00266 mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this); 00267 if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) ) 00268 mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").arg( mInc1->summary().left( 20 ) ).arg( mInc2->summary().left( 20 ) ) ); 00269 else 00270 mDisplayDiff->setCaption( i18n( "Differences of %1").arg( mInc1->summary().left( 20 ) ) ); 00271 00272 diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2); 00273 diff->setLeftSourceTitle( i18n( "Local entry")); 00274 diff->setRightSourceTitle(i18n( "New (remote) entry") ); 00275 diff->addDisplay( mDisplayDiff ); 00276 diff->run(); 00277 mDisplayDiff->show(); 00278 mDisplayDiff->raise(); 00279 } 00280 00281 void KIncidenceChooser::showIncidence2() 00282 { 00283 if ( mTbN ) { 00284 if ( mTbN->isVisible() ) { 00285 mShowDetails2->setText( i18n("Show Details")); 00286 mTbN->hide(); 00287 } else { 00288 mShowDetails2->setText( i18n("Hide Details")); 00289 mTbN->show(); 00290 mTbN->raise(); 00291 } 00292 return; 00293 } 00294 mTbN = new KDialogBase( this, "", false /*not modal*/, mInc2lab->text(), KDialogBase::Ok ); 00295 mTbN->setEscapeButton( KDialogBase::Ok ); 00296 connect( mTbN, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); 00297 TQTextBrowser* textBrowser = new TQTextBrowser( mTbN ); 00298 mTbN->setMainWidget( textBrowser ); 00299 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) ); 00300 mTbN->setMinimumSize( 400, 400 ); 00301 mShowDetails2->setText( i18n("Hide Details")); 00302 mTbN->show(); 00303 mTbN->raise(); 00304 } 00305 00306 void KIncidenceChooser::takeIncidence1() 00307 { 00308 mSelIncidence = mInc1; 00309 TQDialog::accept(); 00310 } 00311 00312 void KIncidenceChooser::takeIncidence2() 00313 { 00314 mSelIncidence = mInc2; 00315 TQDialog::accept(); 00316 } 00317 00318 void KIncidenceChooser::takeBoth() 00319 { 00320 00321 mSelIncidence = 0; 00322 TQDialog::accept(); 00323 } 00324 00325 00326 #include "kincidencechooser.moc"