00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qlayout.h>
00026 #include <qlabel.h>
00027 #include <qbuttongroup.h>
00028 #include <qvbox.h>
00029 #include <qhbox.h>
00030 #include <qradiobutton.h>
00031 #include <qpushbutton.h>
00032 #include <qlayout.h>
00033 #include <qscrollview.h>
00034 #include <qtextbrowser.h>
00035 #include <qapplication.h>
00036
00037
00038 #include <klocale.h>
00039 #include <kglobal.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(QWidget *parent, char *name) :
00048 KDialog(parent,name,true)
00049 {
00050 KDialog *topFrame = this;
00051 QGridLayout *topLayout = new QGridLayout(topFrame,5,3);
00052 int iii = 0;
00053 setCaption( i18n("Conflict Detected"));
00054 QLabel * lab;
00055 lab = new QLabel( 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 QHBox * b_box = new QHBox( topFrame );
00061 topLayout->addMultiCellWidget(b_box, iii,iii,0,2);
00062 ++iii;
00063 QPushButton* button = new QPushButton( i18n("Take Local"), b_box );
00064 connect ( button, SIGNAL( clicked()), this, SLOT (takeIncidence1() ) );
00065 button = new QPushButton( i18n("Take New"), b_box );
00066 connect ( button, SIGNAL( clicked()), this, SLOT (takeIncidence2() ) );
00067 button = new QPushButton( i18n("Take Both"), b_box );
00068 button->setFocus();
00069 connect ( button, SIGNAL( clicked()), this, SLOT (takeBoth() ) );
00070 topLayout->setSpacing(spacingHint());
00071 topLayout->setMargin(marginHint());
00072
00073 mInc1lab = new QLabel ( i18n("Local incidence"), topFrame);
00074 topLayout->addWidget(mInc1lab ,iii,0);
00075 mInc1Sumlab = new QLabel ( i18n("Local incidence summary"), topFrame);
00076 topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2);
00077 ++iii;
00078 topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00079 mMod1lab = new QLabel ( "Set Last modified", topFrame);
00080 topLayout->addWidget(mMod1lab,iii,1);
00081 showDetails1 = new QPushButton( i18n("Show Details"),topFrame );
00082 connect ( showDetails1, SIGNAL( clicked()), this, SLOT (showIncidence1() ) );
00083 topLayout->addWidget(showDetails1,iii,2);
00084 ++iii;
00085
00086 mInc2lab = new QLabel ( "Local incidence", topFrame);
00087 topLayout->addWidget(mInc2lab,iii,0);
00088 mInc2Sumlab = new QLabel ( "Local incidence summary", topFrame);
00089 topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2);
00090 ++iii;
00091 topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00092 mMod2lab = new QLabel ( "Set Last modified", topFrame);
00093 topLayout->addWidget(mMod2lab,iii,1);
00094 showDetails2 = new QPushButton( i18n("Show Details"), topFrame);
00095 connect ( showDetails2, SIGNAL( clicked()), this, SLOT (showIncidence2() ) );
00096 topLayout->addWidget(showDetails2,iii,2);
00097 ++iii;
00098
00099 #if 0
00100
00101 diffBut = new QPushButton( i18n("Show Differences"), topFrame );
00102 connect ( diffBut, SIGNAL( clicked()), this, SLOT ( showDiff() ) );
00103 topLayout->addMultiCellWidget(diffBut, iii,iii,0,2);
00104 ++iii;
00105 #else
00106 diffBut = 0;
00107 #endif
00108 mBg = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame);
00109 topLayout->addMultiCellWidget(mBg, iii,iii,0,2);
00110 ++iii;
00111 mBg->insert( new QRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local);
00112 mBg->insert( new QRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote);
00113 mBg->insert( new QRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest );
00114 mBg->insert( new QRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask );
00115 mBg->insert( new QRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both );
00116 mBg->setButton ( chooseMode );
00117 mTbL = 0;
00118 mTbN = 0;
00119 mDisplayDiff = 0;
00120 choosedIncidence = 0;
00121 button = new QPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame );
00122 connect ( button, SIGNAL( clicked()), this, SLOT ( setSyncMode() ) );
00123 topLayout->addMultiCellWidget(button, iii,iii,0,2);
00124 }
00125
00126 KIncidenceChooser::~KIncidenceChooser()
00127 {
00128 if ( mTbL ) delete mTbL;
00129 if ( mTbN ) delete mTbN;
00130 if ( mDisplayDiff ) {
00131 delete mDisplayDiff;
00132 delete diff;
00133 }
00134 }
00135
00136 void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote )
00137 {
00138 mInc1 = local;
00139 mInc2 = remote;
00140 setLabels();
00141
00142 }
00143 KCal::Incidence* KIncidenceChooser::getIncidence( )
00144 {
00145
00146 KCal::Incidence* retval = choosedIncidence;
00147 if ( chooseMode == KIncidenceChooser::local )
00148 retval = mInc1;
00149 else if ( chooseMode == KIncidenceChooser::remote )
00150 retval = mInc2;
00151 else if ( chooseMode == KIncidenceChooser::both ) {
00152 retval = 0;
00153 }
00154 else if ( chooseMode == KIncidenceChooser::newest ) {
00155 if ( mInc1->lastModified() == mInc2->lastModified())
00156 retval = 0;
00157 if ( mInc1->lastModified() > mInc2->lastModified() )
00158 retval = mInc1;
00159 else
00160 retval = mInc2;
00161 }
00162 return retval;
00163 }
00164
00165 void KIncidenceChooser::setSyncMode()
00166 {
00167 chooseMode = mBg->selectedId ();
00168 if ( chooseMode != KIncidenceChooser::ask )
00169 QDialog::accept();
00170
00171 }
00172
00173 void KIncidenceChooser::useGlobalMode()
00174 {
00175 if ( chooseMode != KIncidenceChooser::ask )
00176 QDialog::reject();
00177 }
00178
00179 void KIncidenceChooser::setLabels()
00180 {
00181 KCal::Incidence* inc = mInc1;
00182 QLabel* des = mInc1lab;
00183 QLabel * sum = mInc1Sumlab;
00184
00185
00186 if ( inc->type() == "Event" ) {
00187 des->setText( i18n( "Local Event") );
00188 sum->setText( inc->summary().left( 30 ));
00189 if ( diffBut )
00190 diffBut->setEnabled( true );
00191 }
00192 else if ( inc->type() == "Todo" ) {
00193 des->setText( i18n( "Local Todo") );
00194 sum->setText( inc->summary().left( 30 ));
00195 if ( diffBut )
00196 diffBut->setEnabled( true );
00197
00198 }
00199 else if ( inc->type() == "Journal" ) {
00200 des->setText( i18n( "Local Journal") );
00201 sum->setText( inc->description().left( 30 ));
00202 if ( diffBut )
00203 diffBut->setEnabled( false );
00204 }
00205 mMod1lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
00206 inc = mInc2;
00207 des = mInc2lab;
00208 sum = mInc2Sumlab;
00209 if ( inc->type() == "Event" ) {
00210 des->setText( i18n( "New Event") );
00211 sum->setText( inc->summary().left( 30 ));
00212 }
00213 else if ( inc->type() == "Todo" ) {
00214 des->setText( i18n( "New Todo") );
00215 sum->setText( inc->summary().left( 30 ));
00216
00217 }
00218 else if ( inc->type() == "Journal" ) {
00219 des->setText( i18n( "New Journal") );
00220 sum->setText( inc->description().left( 30 ));
00221
00222 }
00223 mMod2lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
00224 }
00225
00226 void KIncidenceChooser::showIncidence1()
00227 {
00228 if ( mTbL ) {
00229 if ( mTbL->isVisible() ) {
00230 showDetails1->setText( i18n("Show Details"));
00231 mTbL->hide();
00232 } else {
00233 showDetails1->setText( i18n("Hide Details"));
00234 mTbL->show();
00235 mTbL->raise();
00236 }
00237 return;
00238 }
00239 mTbL = new KDialogBase( this, "", false , mInc1lab->text(), KDialogBase::Ok );
00240 mTbL->setEscapeButton( KDialogBase::Ok );
00241 connect( mTbL, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00242 QTextBrowser* textBrowser = new QTextBrowser( mTbL );
00243 mTbL->setMainWidget( textBrowser );
00244 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayStr( 0, mInc1 ) );
00245 mTbL->setMinimumSize( 400, 400 );
00246 showDetails1->setText( i18n("Hide Details"));
00247 mTbL->show();
00248 mTbL->raise();
00249 }
00250
00251 void KIncidenceChooser::detailsDialogClosed()
00252 {
00253 KDialogBase* dialog = static_cast<KDialogBase *>( const_cast<QObject *>( sender() ) );
00254 if ( dialog == mTbL )
00255 showDetails1->setText( i18n( "Show details..." ) );
00256 else
00257 showDetails2->setText( i18n( "Show details..." ) );
00258 }
00259
00260 void KIncidenceChooser::showDiff()
00261 {
00262 if ( mDisplayDiff ) {
00263 mDisplayDiff->show();
00264 mDisplayDiff->raise();
00265 return;
00266 }
00267 mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this);
00268 if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) )
00269 mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").arg( mInc1->summary().left( 20 ) ).arg( mInc2->summary().left( 20 ) ) );
00270 else
00271 mDisplayDiff->setCaption( i18n( "Differences of %1").arg( mInc1->summary().left( 20 ) ) );
00272
00273 diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2);
00274 diff->setLeftSourceTitle( i18n( "Local entry"));
00275 diff->setRightSourceTitle(i18n( "New (remote) entry") );
00276 diff->addDisplay( mDisplayDiff );
00277 diff->run();
00278 mDisplayDiff->show();
00279 mDisplayDiff->raise();
00280 }
00281
00282 void KIncidenceChooser::showIncidence2()
00283 {
00284 if ( mTbN ) {
00285 if ( mTbN->isVisible() ) {
00286 showDetails2->setText( i18n("Show Details"));
00287 mTbN->hide();
00288 } else {
00289 showDetails2->setText( i18n("Hide Details"));
00290 mTbN->show();
00291 mTbN->raise();
00292 }
00293 return;
00294 }
00295 mTbN = new KDialogBase( this, "", false , mInc2lab->text(), KDialogBase::Ok );
00296 mTbN->setEscapeButton( KDialogBase::Ok );
00297 connect( mTbN, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00298 QTextBrowser* textBrowser = new QTextBrowser( mTbN );
00299 mTbN->setMainWidget( textBrowser );
00300 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayStr( 0, mInc2 ) );
00301 mTbN->setMinimumSize( 400, 400 );
00302 showDetails2->setText( i18n("Hide Details"));
00303 mTbN->show();
00304 mTbN->raise();
00305 }
00306
00307 void KIncidenceChooser::takeIncidence1()
00308 {
00309 choosedIncidence = mInc1;
00310 QDialog::accept();
00311 }
00312
00313 void KIncidenceChooser::takeIncidence2()
00314 {
00315 choosedIncidence = mInc2;
00316 QDialog::accept();
00317 }
00318
00319 void KIncidenceChooser::takeBoth()
00320 {
00321
00322 choosedIncidence = 0;
00323 QDialog::accept();
00324 }
00325
00326
00327 #include "kincidencechooser.moc"