libkdepim Library API Documentation

kincidencechooser.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qbuttongroup.h>
00027 #include <qvbox.h>
00028 #include <qhbox.h>
00029 #include <qradiobutton.h>
00030 #include <qpushbutton.h>
00031 #include <qlayout.h>
00032 #include <qscrollview.h>
00033 #include <qtextbrowser.h>
00034 #include <qapplication.h>
00035 
00036 
00037 #include <klocale.h>
00038 #include <kglobal.h>
00039 
00040 #include "kincidencechooser.h"
00041 #include "kincidenceformatter.h"
00042 
00043 int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ;
00044 
00045 KIncidenceChooser::KIncidenceChooser(QWidget *parent, char *name) :
00046     KDialog(parent,name,true)
00047 {
00048     KDialog *topFrame = this;
00049     QGridLayout *topLayout = new QGridLayout(topFrame,5,3);
00050     int iii = 0;
00051     setCaption( i18n("Conflict detected"));
00052     QLabel * lab;
00053     lab = new QLabel( i18n(
00054                         "<qt>A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally."
00055                         "<br/>NOTE: You have to check mail again to apply your changes to the server!</qt>"), topFrame);
00056     topLayout->addMultiCellWidget(lab, iii,iii,0,2);
00057     ++iii;
00058     QHBox * b_box = new QHBox( topFrame );
00059     topLayout->addMultiCellWidget(b_box, iii,iii,0,2);
00060     ++iii;
00061     QPushButton* button = new QPushButton( i18n("Take local"), b_box );
00062     connect ( button, SIGNAL( clicked()), this, SLOT (takeIncidence1() ) );
00063     button = new QPushButton( i18n("Take new"), b_box );
00064     connect ( button, SIGNAL( clicked()), this, SLOT (takeIncidence2() ) );
00065     button = new QPushButton( i18n("Take both"), b_box );
00066     connect ( button, SIGNAL( clicked()), this, SLOT (takeBoth() ) );
00067     topLayout->setSpacing(spacingHint());
00068     topLayout->setMargin(marginHint());
00069     // text is not translated, because text has to be set later
00070     mInc1lab = new QLabel ( i18n("Local incidence"), topFrame);
00071     topLayout->addWidget(mInc1lab ,iii,0);
00072     mInc1Sumlab = new QLabel ( i18n("Local incidence summary"), topFrame);
00073     topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2);
00074     ++iii;
00075     topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00076     mMod1lab = new QLabel ( "Set Last modified", topFrame);
00077     topLayout->addWidget(mMod1lab,iii,1);
00078     showDetails1 = new QPushButton( i18n("Show details..."),topFrame );
00079     connect ( showDetails1, SIGNAL( clicked()), this, SLOT (showIncidence1() ) );
00080     topLayout->addWidget(showDetails1,iii,2);
00081     ++iii;
00082 
00083     mInc2lab = new QLabel ( "Local incidence", topFrame);
00084     topLayout->addWidget(mInc2lab,iii,0);
00085     mInc2Sumlab = new QLabel ( "Local incidence summary", topFrame);
00086     topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2);
00087     ++iii;
00088     topLayout->addWidget( new QLabel ( i18n("Last modified:"), topFrame) ,iii,0);
00089     mMod2lab = new QLabel ( "Set Last modified", topFrame);
00090     topLayout->addWidget(mMod2lab,iii,1);
00091     showDetails2 = new QPushButton( i18n("Show details..."), topFrame);
00092     connect ( showDetails2, SIGNAL( clicked()), this, SLOT (showIncidence2() ) );
00093     topLayout->addWidget(showDetails2,iii,2);
00094     ++iii;
00095     //
00096 #if 0
00097     // commented out for now, because the diff code has too many bugs
00098     diffBut = new QPushButton( i18n("Show differences"), topFrame );
00099     connect ( diffBut, SIGNAL( clicked()), this, SLOT ( showDiff() ) );
00100     topLayout->addMultiCellWidget(diffBut, iii,iii,0,2);
00101     ++iii;
00102 #else
00103     diffBut = 0;
00104 #endif
00105     mBg = new QButtonGroup ( 1,  Qt::Horizontal, i18n("Sync Preferences"), topFrame);
00106     topLayout->addMultiCellWidget(mBg, iii,iii,0,2);
00107     ++iii;
00108     mBg->insert( new QRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local);
00109     mBg->insert( new QRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ),  KIncidenceChooser::remote);
00110     mBg->insert( new QRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest );
00111     mBg->insert( new QRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask );
00112     mBg->insert( new QRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both );
00113     mBg->setButton ( chooseMode );
00114     mTbL = 0;
00115     mTbN =  0;
00116     mDisplayDiff = 0;
00117     choosedIncidence = 0;
00118     button = new QPushButton( i18n("Apply this to all conflicts of this sync"), topFrame );
00119     connect ( button, SIGNAL( clicked()), this, SLOT ( setSyncMode() ) );
00120     topLayout->addMultiCellWidget(button, iii,iii,0,2);
00121 }
00122 
00123 KIncidenceChooser::~KIncidenceChooser()
00124 {
00125     if ( mTbL ) delete mTbL;
00126     if ( mTbN ) delete mTbN;
00127     if ( mDisplayDiff ) {
00128         delete mDisplayDiff;
00129         delete diff;
00130     }
00131 }
00132 
00133 void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote )
00134 {
00135     mInc1 = local;
00136     mInc2 = remote;
00137     setLabels();
00138 
00139 }
00140 KCal::Incidence* KIncidenceChooser::getIncidence( )
00141 {
00142 
00143     KCal::Incidence* retval = choosedIncidence;
00144     if ( chooseMode == KIncidenceChooser::local )
00145         retval = mInc1;
00146     else  if ( chooseMode == KIncidenceChooser::remote )
00147         retval = mInc2;
00148     else  if ( chooseMode == KIncidenceChooser::both ) {
00149         retval = 0;
00150     }
00151     else  if ( chooseMode == KIncidenceChooser::newest ) {
00152         if ( mInc1->lastModified() == mInc2->lastModified())
00153             retval = 0;
00154         if ( mInc1->lastModified() >  mInc2->lastModified() )
00155             retval =  mInc1;
00156         else
00157             retval = mInc2;
00158     }
00159     return retval;
00160 }
00161 
00162 void KIncidenceChooser::setSyncMode()
00163 {
00164     chooseMode = mBg->selectedId ();
00165     if ( chooseMode != KIncidenceChooser::ask )
00166         QDialog::accept();
00167 
00168 }
00169 
00170 void KIncidenceChooser::useGlobalMode()
00171 {
00172     if ( chooseMode != KIncidenceChooser::ask )
00173         QDialog::reject();
00174 }
00175 
00176 void KIncidenceChooser::setLabels()
00177 {
00178     Incidence* inc = mInc1;
00179     QLabel* des = mInc1lab;
00180     QLabel * sum = mInc1Sumlab;
00181 
00182 
00183     if ( inc->type() == "Event" ) {
00184         des->setText( i18n( "Local Event") );
00185         sum->setText( inc->summary().left( 30 ));
00186         if ( diffBut )
00187             diffBut->setEnabled( true );
00188     }
00189     else if ( inc->type() == "Todo" ) {
00190         des->setText( i18n( "Local Todo") );
00191         sum->setText( inc->summary().left( 30 ));
00192         if ( diffBut )
00193             diffBut->setEnabled( true );
00194 
00195     }
00196     else if ( inc->type() == "Journal" ) {
00197         des->setText( i18n( "Local Journal") );
00198         sum->setText( inc->description().left( 30 ));
00199         if ( diffBut )
00200             diffBut->setEnabled( false );
00201     }
00202     mMod1lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
00203     inc = mInc2;
00204     des = mInc2lab;
00205     sum = mInc2Sumlab;
00206     if ( inc->type() == "Event" ) {
00207         des->setText( i18n( "New Event") );
00208         sum->setText( inc->summary().left( 30 ));
00209     }
00210     else if ( inc->type() == "Todo" ) {
00211         des->setText( i18n( "New Todo") );
00212         sum->setText( inc->summary().left( 30 ));
00213 
00214     }
00215     else if ( inc->type() == "Journal" ) {
00216         des->setText( i18n( "New Journal") );
00217         sum->setText( inc->description().left( 30 ));
00218 
00219     }
00220     mMod2lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
00221 }
00222 
00223 void KIncidenceChooser::showIncidence1()
00224 {
00225     if ( mTbL ) {
00226         if ( mTbL->isVisible() ) {
00227             showDetails1->setText( i18n("Show details...") );
00228             mTbL->hide();
00229         } else {
00230             showDetails1->setText( i18n("Hide details") );
00231             mTbL->show();
00232             mTbL->raise();
00233         }
00234         return;
00235     }
00236     mTbL = new KDialogBase( this, "", false /*not modal*/, mInc1lab->text(), KDialogBase::Ok );
00237     mTbL->setEscapeButton( KDialogBase::Ok );
00238     connect( mTbL, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00239     QTextBrowser* textBrowser = new QTextBrowser( mTbL );
00240     mTbL->setMainWidget( textBrowser );
00241     textBrowser->setText( KIncidenceFormatter::instance()->getFormattedText( mInc1 )  );
00242     mTbL->setMinimumSize( 400, 400 );
00243     showDetails1->setText( i18n("Hide details"));
00244     mTbL->show();
00245     mTbL->raise();
00246 }
00247 
00248 void KIncidenceChooser::detailsDialogClosed()
00249 {
00250     KDialogBase* dialog = static_cast<KDialogBase *>( const_cast<QObject *>( sender() ) );
00251     if ( dialog == mTbL )
00252         showDetails1->setText( i18n( "Show details..." ) );
00253     else
00254         showDetails2->setText( i18n( "Show details..." ) );
00255 }
00256 
00257 void KIncidenceChooser::showDiff()
00258 {
00259     if ( mDisplayDiff ) {
00260         mDisplayDiff->show();
00261         mDisplayDiff->raise();
00262         return;
00263     }
00264     mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this);
00265     if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) )
00266         mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").arg( mInc1->summary().left( 20 ) ).arg( mInc2->summary().left( 20 ) ) );
00267     else
00268         mDisplayDiff->setCaption( i18n( "Differences of %1").arg( mInc1->summary().left( 20 ) ) );
00269 
00270     diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2);
00271     diff->setLeftSourceTitle(  i18n( "Local entry"));
00272     diff->setRightSourceTitle(i18n( "New (remote)  entry") );
00273     diff->addDisplay( mDisplayDiff );
00274     diff->run();
00275     mDisplayDiff->show();
00276     mDisplayDiff->raise();
00277 }
00278 
00279 void KIncidenceChooser::showIncidence2()
00280 {
00281    if ( mTbN ) {
00282         if ( mTbN->isVisible() ) {
00283             showDetails2->setText( i18n("Show details..."));
00284             mTbN->hide();
00285         } else {
00286             showDetails2->setText( i18n("Hide details"));
00287             mTbN->show();
00288             mTbN->raise();
00289         }
00290         return;
00291     }
00292     mTbN = new KDialogBase( this, "", false /*not modal*/, mInc2lab->text(), KDialogBase::Ok );
00293     mTbN->setEscapeButton( KDialogBase::Ok );
00294     connect( mTbN, SIGNAL( okClicked() ), this, SLOT( detailsDialogClosed() ) );
00295     QTextBrowser* textBrowser = new QTextBrowser( mTbN );
00296     mTbN->setMainWidget( textBrowser );
00297     textBrowser->setText( KIncidenceFormatter::instance()->getFormattedText( mInc2 )  );
00298     mTbN->setMinimumSize( 400, 400 );
00299     showDetails2->setText( i18n("Hide details") );
00300     mTbN->show();
00301     mTbN->raise();
00302 }
00303 
00304 void KIncidenceChooser::takeIncidence1()
00305 {
00306     choosedIncidence = mInc1;
00307     QDialog::accept();
00308 }
00309 
00310 void KIncidenceChooser::takeIncidence2()
00311 {
00312     choosedIncidence = mInc2;
00313     QDialog::accept();
00314 }
00315 
00316 void KIncidenceChooser::takeBoth()
00317 {
00318 
00319     choosedIncidence = 0;
00320     QDialog::accept();
00321 }
00322 
00323 
00324 #include "kincidencechooser.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jan 31 15:53:22 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003