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 connect ( button, SIGNAL( clicked()), this, SLOT (takeBoth() ) );
00069 topLayout->setSpacing(spacingHint());
00070 topLayout->setMargin(marginHint());
00071
00072 mInc1lab = new QLabel ( i18n("Local incidence"), topFrame);
00073 topLayout->addWidget(mInc1lab ,iii,0);
00074 mInc1Sumlab = new QLabel ( i18n("Local incidence summary"), topFrame);
00075 topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2);
00076 ++iii;
00077 topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00078 mMod1lab = new QLabel ( "Set Last modified", topFrame);
00079 topLayout->addWidget(mMod1lab,iii,1);
00080 showDetails1 = new QPushButton( i18n("Show Details"),topFrame );
00081 connect ( showDetails1, SIGNAL( clicked()), this, SLOT (showIncidence1() ) );
00082 topLayout->addWidget(showDetails1,iii,2);
00083 ++iii;
00084
00085 mInc2lab = new QLabel ( "Local incidence", topFrame);
00086 topLayout->addWidget(mInc2lab,iii,0);
00087 mInc2Sumlab = new QLabel ( "Local incidence summary", topFrame);
00088 topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2);
00089 ++iii;
00090 topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00091 mMod2lab = new QLabel ( "Set Last modified", topFrame);
00092 topLayout->addWidget(mMod2lab,iii,1);
00093 showDetails2 = new QPushButton( i18n("Show Details"), topFrame);
00094 connect ( showDetails2, SIGNAL( clicked()), this, SLOT (showIncidence2() ) );
00095 topLayout->addWidget(showDetails2,iii,2);
00096 ++iii;
00097
00098 #if 0
00099
00100 diffBut = new QPushButton( i18n("Show Differences"), topFrame );
00101 connect ( diffBut, SIGNAL( clicked()), this, SLOT ( showDiff() ) );
00102 topLayout->addMultiCellWidget(diffBut, iii,iii,0,2);
00103 ++iii;
00104 #else
00105 diffBut = 0;
00106 #endif
00107 mBg = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame);
00108 topLayout->addMultiCellWidget(mBg, iii,iii,0,2);
00109 ++iii;
00110 mBg->insert( new QRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local);
00111 mBg->insert( new QRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote);
00112 mBg->insert( new QRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest );
00113 mBg->insert( new QRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask );
00114 mBg->insert( new QRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both );
00115 mBg->setButton ( chooseMode );
00116 mTbL = 0;
00117 mTbN = 0;
00118 mDisplayDiff = 0;
00119 choosedIncidence = 0;
00120 button = new QPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame );
00121 connect ( button, SIGNAL( clicked()), this, 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 = choosedIncidence;
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 QDialog::accept();
00169
00170 }
00171
00172 void KIncidenceChooser::useGlobalMode()
00173 {
00174 if ( chooseMode != KIncidenceChooser::ask )
00175 QDialog::reject();
00176 }
00177
00178 void KIncidenceChooser::setLabels()
00179 {
00180 KCal::Incidence* inc = mInc1;
00181 QLabel* des = mInc1lab;
00182 QLabel * sum = mInc1Sumlab;
00183
00184
00185 if ( inc->type() == "Event" ) {
00186 des->setText( i18n( "Local Event") );
00187 sum->setText( inc->summary().left( 30 ));
00188 if ( diffBut )
00189 diffBut->setEnabled( true );
00190 }
00191 else if ( inc->type() == "Todo" ) {
00192 des->setText( i18n( "Local Todo") );
00193 sum->setText( inc->summary().left( 30 ));
00194 if ( diffBut )
00195 diffBut->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 ( diffBut )
00202 diffBut->setEnabled( false );
00203 }
00204 mMod1lab->setText( KGlobal::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( KGlobal::locale()->formatDateTime(inc->lastModified() ));
00223 }
00224
00225 void KIncidenceChooser::showIncidence1()
00226 {
00227 if ( mTbL ) {
00228 if ( mTbL->isVisible() ) {
00229 showDetails1->setText( i18n("Show Details"));
00230 mTbL->hide();
00231 } else {
00232 showDetails1->setText( i18n("Hide Details"));
00233 mTbL->show();
00234 mTbL->raise();
00235 }
00236 return;
00237 }
00238 mTbL = new KDialogBase( this, "", false , mInc1lab->text(), KDialogBase::Ok );
00239 mTbL->setEscapeButton( KDialogBase::Ok );
00240 connect( mTbL, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00241 QTextBrowser* textBrowser = new QTextBrowser( mTbL );
00242 mTbL->setMainWidget( textBrowser );
00243 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) );
00244 mTbL->setMinimumSize( 400, 400 );
00245 showDetails1->setText( i18n("Hide Details"));
00246 mTbL->show();
00247 mTbL->raise();
00248 }
00249
00250 void KIncidenceChooser::detailsDialogClosed()
00251 {
00252 KDialogBase* dialog = static_cast<KDialogBase *>( const_cast<QObject *>( sender() ) );
00253 if ( dialog == mTbL )
00254 showDetails1->setText( i18n( "Show details..." ) );
00255 else
00256 showDetails2->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 showDetails2->setText( i18n("Show Details"));
00286 mTbN->hide();
00287 } else {
00288 showDetails2->setText( i18n("Hide Details"));
00289 mTbN->show();
00290 mTbN->raise();
00291 }
00292 return;
00293 }
00294 mTbN = new KDialogBase( this, "", false , mInc2lab->text(), KDialogBase::Ok );
00295 mTbN->setEscapeButton( KDialogBase::Ok );
00296 connect( mTbN, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00297 QTextBrowser* textBrowser = new QTextBrowser( mTbN );
00298 mTbN->setMainWidget( textBrowser );
00299 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) );
00300 mTbN->setMinimumSize( 400, 400 );
00301 showDetails2->setText( i18n("Hide Details"));
00302 mTbN->show();
00303 mTbN->raise();
00304 }
00305
00306 void KIncidenceChooser::takeIncidence1()
00307 {
00308 choosedIncidence = mInc1;
00309 QDialog::accept();
00310 }
00311
00312 void KIncidenceChooser::takeIncidence2()
00313 {
00314 choosedIncidence = mInc2;
00315 QDialog::accept();
00316 }
00317
00318 void KIncidenceChooser::takeBoth()
00319 {
00320
00321 choosedIncidence = 0;
00322 QDialog::accept();
00323 }
00324
00325
00326 #include "kincidencechooser.moc"