You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
327 lines
11 KiB
327 lines
11 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of libtdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
|
||
|
As a special exception, permission is given to link this program
|
||
14 years ago
|
with any edition of TQt, and distribute the resulting executable,
|
||
|
without including the source code for TQt in the source distribution.
|
||
15 years ago
|
*/
|
||
|
|
||
15 years ago
|
#include <tqlayout.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqbuttongroup.h>
|
||
|
#include <tqvbox.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqscrollview.h>
|
||
|
#include <tqtextbrowser.h>
|
||
|
#include <tqapplication.h>
|
||
15 years ago
|
|
||
|
|
||
|
#include <klocale.h>
|
||
|
#include <kglobal.h>
|
||
|
|
||
|
#include "kincidencechooser.h"
|
||
|
#include "libkcal/incidence.h"
|
||
|
#include "libkcal/incidenceformatter.h"
|
||
|
|
||
|
int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ;
|
||
|
|
||
13 years ago
|
KIncidenceChooser::KIncidenceChooser(TQWidget *parent, char *name) :
|
||
|
KDialog(parent,name,true)
|
||
15 years ago
|
{
|
||
|
KDialog *topFrame = this;
|
||
15 years ago
|
TQGridLayout *topLayout = new TQGridLayout(topFrame,5,3);
|
||
15 years ago
|
int iii = 0;
|
||
|
setCaption( i18n("Conflict Detected"));
|
||
15 years ago
|
TQLabel * lab;
|
||
|
lab = new TQLabel( i18n(
|
||
15 years ago
|
"<qt>A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally."
|
||
|
"<br/>NOTE: You have to check mail again to apply your changes to the server.</qt>"), topFrame);
|
||
|
topLayout->addMultiCellWidget(lab, iii,iii,0,2);
|
||
|
++iii;
|
||
15 years ago
|
TQHBox * b_box = new TQHBox( topFrame );
|
||
15 years ago
|
topLayout->addMultiCellWidget(b_box, iii,iii,0,2);
|
||
|
++iii;
|
||
15 years ago
|
TQPushButton* button = new TQPushButton( i18n("Take Local"), b_box );
|
||
|
connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence1() ) );
|
||
|
button = new TQPushButton( i18n("Take New"), b_box );
|
||
|
connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence2() ) );
|
||
|
button = new TQPushButton( i18n("Take Both"), b_box );
|
||
|
connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeBoth() ) );
|
||
15 years ago
|
topLayout->setSpacing(spacingHint());
|
||
|
topLayout->setMargin(marginHint());
|
||
|
// text is not translated, because text has to be set later
|
||
15 years ago
|
mInc1lab = new TQLabel ( i18n("Local incidence"), topFrame);
|
||
15 years ago
|
topLayout->addWidget(mInc1lab ,iii,0);
|
||
15 years ago
|
mInc1Sumlab = new TQLabel ( i18n("Local incidence summary"), topFrame);
|
||
15 years ago
|
topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2);
|
||
|
++iii;
|
||
15 years ago
|
topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0);
|
||
|
mMod1lab = new TQLabel ( "Set Last modified", topFrame);
|
||
15 years ago
|
topLayout->addWidget(mMod1lab,iii,1);
|
||
14 years ago
|
mShowDetails1 = new TQPushButton( i18n("Show Details"),topFrame );
|
||
|
connect ( mShowDetails1, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence1() ) );
|
||
|
topLayout->addWidget(mShowDetails1,iii,2);
|
||
15 years ago
|
++iii;
|
||
|
|
||
15 years ago
|
mInc2lab = new TQLabel ( "Local incidence", topFrame);
|
||
15 years ago
|
topLayout->addWidget(mInc2lab,iii,0);
|
||
15 years ago
|
mInc2Sumlab = new TQLabel ( "Local incidence summary", topFrame);
|
||
15 years ago
|
topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2);
|
||
|
++iii;
|
||
15 years ago
|
topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0);
|
||
|
mMod2lab = new TQLabel ( "Set Last modified", topFrame);
|
||
15 years ago
|
topLayout->addWidget(mMod2lab,iii,1);
|
||
14 years ago
|
mShowDetails2 = new TQPushButton( i18n("Show Details"), topFrame);
|
||
|
connect ( mShowDetails2, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence2() ) );
|
||
|
topLayout->addWidget(mShowDetails2,iii,2);
|
||
15 years ago
|
++iii;
|
||
|
//
|
||
|
#if 0
|
||
|
// commented out for now, because the diff code has too many bugs
|
||
14 years ago
|
mDiffBut = new TQPushButton( i18n("Show Differences"), topFrame );
|
||
|
connect ( mDiffBut, TQT_SIGNAL( clicked()), this, TQT_SLOT ( showDiff() ) );
|
||
|
topLayout->addMultiCellWidget(mDiffBut, iii,iii,0,2);
|
||
15 years ago
|
++iii;
|
||
|
#else
|
||
14 years ago
|
mDiffBut = 0;
|
||
15 years ago
|
#endif
|
||
14 years ago
|
mBg = new TQButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame);
|
||
15 years ago
|
topLayout->addMultiCellWidget(mBg, iii,iii,0,2);
|
||
|
++iii;
|
||
15 years ago
|
mBg->insert( new TQRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local);
|
||
|
mBg->insert( new TQRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote);
|
||
|
mBg->insert( new TQRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest );
|
||
|
mBg->insert( new TQRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask );
|
||
|
mBg->insert( new TQRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both );
|
||
15 years ago
|
mBg->setButton ( chooseMode );
|
||
|
mTbL = 0;
|
||
|
mTbN = 0;
|
||
|
mDisplayDiff = 0;
|
||
14 years ago
|
mSelIncidence = 0;
|
||
15 years ago
|
button = new TQPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame );
|
||
|
connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT ( setSyncMode() ) );
|
||
15 years ago
|
topLayout->addMultiCellWidget(button, iii,iii,0,2);
|
||
|
}
|
||
|
|
||
|
KIncidenceChooser::~KIncidenceChooser()
|
||
|
{
|
||
|
if ( mTbL ) delete mTbL;
|
||
|
if ( mTbN ) delete mTbN;
|
||
|
if ( mDisplayDiff ) {
|
||
|
delete mDisplayDiff;
|
||
|
delete diff;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote )
|
||
|
{
|
||
|
mInc1 = local;
|
||
|
mInc2 = remote;
|
||
|
setLabels();
|
||
|
|
||
|
}
|
||
|
KCal::Incidence* KIncidenceChooser::getIncidence( )
|
||
|
{
|
||
|
|
||
14 years ago
|
KCal::Incidence* retval = mSelIncidence;
|
||
15 years ago
|
if ( chooseMode == KIncidenceChooser::local )
|
||
|
retval = mInc1;
|
||
|
else if ( chooseMode == KIncidenceChooser::remote )
|
||
|
retval = mInc2;
|
||
|
else if ( chooseMode == KIncidenceChooser::both ) {
|
||
|
retval = 0;
|
||
|
}
|
||
|
else if ( chooseMode == KIncidenceChooser::newest ) {
|
||
|
if ( mInc1->lastModified() == mInc2->lastModified())
|
||
|
retval = 0;
|
||
|
if ( mInc1->lastModified() > mInc2->lastModified() )
|
||
|
retval = mInc1;
|
||
|
else
|
||
|
retval = mInc2;
|
||
|
}
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::setSyncMode()
|
||
|
{
|
||
|
chooseMode = mBg->selectedId ();
|
||
|
if ( chooseMode != KIncidenceChooser::ask )
|
||
15 years ago
|
TQDialog::accept();
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::useGlobalMode()
|
||
|
{
|
||
|
if ( chooseMode != KIncidenceChooser::ask )
|
||
15 years ago
|
TQDialog::reject();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KIncidenceChooser::setLabels()
|
||
|
{
|
||
|
KCal::Incidence* inc = mInc1;
|
||
15 years ago
|
TQLabel* des = mInc1lab;
|
||
|
TQLabel * sum = mInc1Sumlab;
|
||
15 years ago
|
|
||
|
|
||
|
if ( inc->type() == "Event" ) {
|
||
|
des->setText( i18n( "Local Event") );
|
||
|
sum->setText( inc->summary().left( 30 ));
|
||
14 years ago
|
if ( mDiffBut )
|
||
|
mDiffBut->setEnabled( true );
|
||
15 years ago
|
}
|
||
|
else if ( inc->type() == "Todo" ) {
|
||
|
des->setText( i18n( "Local Todo") );
|
||
|
sum->setText( inc->summary().left( 30 ));
|
||
14 years ago
|
if ( mDiffBut )
|
||
|
mDiffBut->setEnabled( true );
|
||
15 years ago
|
|
||
|
}
|
||
|
else if ( inc->type() == "Journal" ) {
|
||
|
des->setText( i18n( "Local Journal") );
|
||
|
sum->setText( inc->description().left( 30 ));
|
||
14 years ago
|
if ( mDiffBut )
|
||
|
mDiffBut->setEnabled( false );
|
||
15 years ago
|
}
|
||
|
mMod1lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
|
||
|
inc = mInc2;
|
||
|
des = mInc2lab;
|
||
|
sum = mInc2Sumlab;
|
||
|
if ( inc->type() == "Event" ) {
|
||
|
des->setText( i18n( "New Event") );
|
||
|
sum->setText( inc->summary().left( 30 ));
|
||
|
}
|
||
|
else if ( inc->type() == "Todo" ) {
|
||
|
des->setText( i18n( "New Todo") );
|
||
|
sum->setText( inc->summary().left( 30 ));
|
||
|
|
||
|
}
|
||
|
else if ( inc->type() == "Journal" ) {
|
||
|
des->setText( i18n( "New Journal") );
|
||
|
sum->setText( inc->description().left( 30 ));
|
||
|
|
||
|
}
|
||
|
mMod2lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() ));
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::showIncidence1()
|
||
|
{
|
||
|
if ( mTbL ) {
|
||
|
if ( mTbL->isVisible() ) {
|
||
14 years ago
|
mShowDetails1->setText( i18n("Show Details"));
|
||
15 years ago
|
mTbL->hide();
|
||
|
} else {
|
||
14 years ago
|
mShowDetails1->setText( i18n("Hide Details"));
|
||
15 years ago
|
mTbL->show();
|
||
|
mTbL->raise();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
mTbL = new KDialogBase( this, "", false /*not modal*/, mInc1lab->text(), KDialogBase::Ok );
|
||
|
mTbL->setEscapeButton( KDialogBase::Ok );
|
||
15 years ago
|
connect( mTbL, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) );
|
||
|
TQTextBrowser* textBrowser = new TQTextBrowser( mTbL );
|
||
15 years ago
|
mTbL->setMainWidget( textBrowser );
|
||
|
textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) );
|
||
|
mTbL->setMinimumSize( 400, 400 );
|
||
14 years ago
|
mShowDetails1->setText( i18n("Hide Details"));
|
||
15 years ago
|
mTbL->show();
|
||
|
mTbL->raise();
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::detailsDialogClosed()
|
||
|
{
|
||
14 years ago
|
KDialogBase* dialog = static_cast<KDialogBase *>( TQT_TQWIDGET( const_cast<TQT_BASE_OBJECT_NAME*>(sender()) ) );
|
||
15 years ago
|
if ( dialog == mTbL )
|
||
14 years ago
|
mShowDetails1->setText( i18n( "Show details..." ) );
|
||
15 years ago
|
else
|
||
14 years ago
|
mShowDetails2->setText( i18n( "Show details..." ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KIncidenceChooser::showDiff()
|
||
|
{
|
||
|
if ( mDisplayDiff ) {
|
||
|
mDisplayDiff->show();
|
||
|
mDisplayDiff->raise();
|
||
|
return;
|
||
|
}
|
||
|
mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this);
|
||
|
if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) )
|
||
14 years ago
|
mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").tqarg( mInc1->summary().left( 20 ) ).tqarg( mInc2->summary().left( 20 ) ) );
|
||
15 years ago
|
else
|
||
14 years ago
|
mDisplayDiff->setCaption( i18n( "Differences of %1").tqarg( mInc1->summary().left( 20 ) ) );
|
||
15 years ago
|
|
||
|
diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2);
|
||
|
diff->setLeftSourceTitle( i18n( "Local entry"));
|
||
|
diff->setRightSourceTitle(i18n( "New (remote) entry") );
|
||
|
diff->addDisplay( mDisplayDiff );
|
||
|
diff->run();
|
||
|
mDisplayDiff->show();
|
||
|
mDisplayDiff->raise();
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::showIncidence2()
|
||
|
{
|
||
|
if ( mTbN ) {
|
||
|
if ( mTbN->isVisible() ) {
|
||
14 years ago
|
mShowDetails2->setText( i18n("Show Details"));
|
||
15 years ago
|
mTbN->hide();
|
||
|
} else {
|
||
14 years ago
|
mShowDetails2->setText( i18n("Hide Details"));
|
||
15 years ago
|
mTbN->show();
|
||
|
mTbN->raise();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
mTbN = new KDialogBase( this, "", false /*not modal*/, mInc2lab->text(), KDialogBase::Ok );
|
||
|
mTbN->setEscapeButton( KDialogBase::Ok );
|
||
15 years ago
|
connect( mTbN, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) );
|
||
|
TQTextBrowser* textBrowser = new TQTextBrowser( mTbN );
|
||
15 years ago
|
mTbN->setMainWidget( textBrowser );
|
||
|
textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) );
|
||
|
mTbN->setMinimumSize( 400, 400 );
|
||
14 years ago
|
mShowDetails2->setText( i18n("Hide Details"));
|
||
15 years ago
|
mTbN->show();
|
||
|
mTbN->raise();
|
||
|
}
|
||
|
|
||
|
void KIncidenceChooser::takeIncidence1()
|
||
|
{
|
||
14 years ago
|
mSelIncidence = mInc1;
|
||
15 years ago
|
TQDialog::accept();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KIncidenceChooser::takeIncidence2()
|
||
|
{
|
||
14 years ago
|
mSelIncidence = mInc2;
|
||
15 years ago
|
TQDialog::accept();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KIncidenceChooser::takeBoth()
|
||
|
{
|
||
|
|
||
14 years ago
|
mSelIncidence = 0;
|
||
15 years ago
|
TQDialog::accept();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
#include "kincidencechooser.moc"
|