27 #include <tqbuttongroup.h>
30 #include <tqradiobutton.h>
31 #include <tqpushbutton.h>
33 #include <tqscrollview.h>
34 #include <tqtextbrowser.h>
35 #include <tqapplication.h>
38 #include <tdelocale.h>
39 #include <tdeglobal.h>
41 #include "kincidencechooser.h"
42 #include "libkcal/incidence.h"
43 #include "libkcal/incidenceformatter.h"
45 int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ;
48 KDialog(parent,name,true)
50 KDialog *topFrame =
this;
51 TQGridLayout *topLayout =
new TQGridLayout(topFrame,5,3);
53 setCaption( i18n(
"Conflict Detected"));
55 lab =
new TQLabel( i18n(
56 "<qt>A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally."
57 "<br/>NOTE: You have to check mail again to apply your changes to the server.</qt>"), topFrame);
58 topLayout->addMultiCellWidget(lab, iii,iii,0,2);
60 TQHBox * b_box =
new TQHBox( topFrame );
61 topLayout->addMultiCellWidget(b_box, iii,iii,0,2);
63 TQPushButton* button =
new TQPushButton( i18n(
"Take Local"), b_box );
64 connect ( button, TQ_SIGNAL( clicked()),
this, TQ_SLOT (takeIncidence1() ) );
65 button =
new TQPushButton( i18n(
"Take New"), b_box );
66 connect ( button, TQ_SIGNAL( clicked()),
this, TQ_SLOT (takeIncidence2() ) );
67 button =
new TQPushButton( i18n(
"Take Both"), b_box );
68 connect ( button, TQ_SIGNAL( clicked()),
this, TQ_SLOT (takeBoth() ) );
69 topLayout->setSpacing(spacingHint());
70 topLayout->setMargin(marginHint());
72 mInc1lab =
new TQLabel ( i18n(
"Local incidence"), topFrame);
73 topLayout->addWidget(mInc1lab ,iii,0);
74 mInc1Sumlab =
new TQLabel ( i18n(
"Local incidence summary"), topFrame);
75 topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2);
77 topLayout->addWidget(
new TQLabel ( i18n(
"Last modified:"), topFrame) ,iii,0);
78 mMod1lab =
new TQLabel (
"Set Last modified", topFrame);
79 topLayout->addWidget(mMod1lab,iii,1);
80 mShowDetails1 =
new TQPushButton( i18n(
"Show Details"),topFrame );
81 connect ( mShowDetails1, TQ_SIGNAL( clicked()),
this, TQ_SLOT (showIncidence1() ) );
82 topLayout->addWidget(mShowDetails1,iii,2);
85 mInc2lab =
new TQLabel (
"Local incidence", topFrame);
86 topLayout->addWidget(mInc2lab,iii,0);
87 mInc2Sumlab =
new TQLabel (
"Local incidence summary", topFrame);
88 topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2);
90 topLayout->addWidget(
new TQLabel ( i18n(
"Last modified:"), topFrame) ,iii,0);
91 mMod2lab =
new TQLabel (
"Set Last modified", topFrame);
92 topLayout->addWidget(mMod2lab,iii,1);
93 mShowDetails2 =
new TQPushButton( i18n(
"Show Details"), topFrame);
94 connect ( mShowDetails2, TQ_SIGNAL( clicked()),
this, TQ_SLOT (showIncidence2() ) );
95 topLayout->addWidget(mShowDetails2,iii,2);
100 mDiffBut =
new TQPushButton( i18n(
"Show Differences"), topFrame );
101 connect ( mDiffBut, TQ_SIGNAL( clicked()),
this, TQ_SLOT ( showDiff() ) );
102 topLayout->addMultiCellWidget(mDiffBut, iii,iii,0,2);
107 mBg =
new TQButtonGroup ( 1, TQt::Horizontal, i18n(
"Sync Preferences"), topFrame);
108 topLayout->addMultiCellWidget(mBg, iii,iii,0,2);
110 mBg->insert(
new TQRadioButton ( i18n(
"Take local entry on conflict"), mBg ), KIncidenceChooser::local);
111 mBg->insert(
new TQRadioButton ( i18n(
"Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote);
112 mBg->insert(
new TQRadioButton ( i18n(
"Take newest entry on conflict"), mBg ), KIncidenceChooser::newest );
113 mBg->insert(
new TQRadioButton ( i18n(
"Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask );
114 mBg->insert(
new TQRadioButton ( i18n(
"Take both on conflict"), mBg ), KIncidenceChooser::both );
115 mBg->setButton ( chooseMode );
120 button =
new TQPushButton( i18n(
"Apply This to All Conflicts of This Sync"), topFrame );
121 connect ( button, TQ_SIGNAL( clicked()),
this, TQ_SLOT ( setSyncMode() ) );
122 topLayout->addMultiCellWidget(button, iii,iii,0,2);
125 KIncidenceChooser::~KIncidenceChooser()
127 if ( mTbL )
delete mTbL;
128 if ( mTbN )
delete mTbN;
129 if ( mDisplayDiff ) {
135 void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote )
142 KCal::Incidence* KIncidenceChooser::getIncidence( )
145 KCal::Incidence* retval = mSelIncidence;
146 if ( chooseMode == KIncidenceChooser::local )
148 else if ( chooseMode == KIncidenceChooser::remote )
150 else if ( chooseMode == KIncidenceChooser::both ) {
153 else if ( chooseMode == KIncidenceChooser::newest ) {
154 if ( mInc1->lastModified() == mInc2->lastModified())
156 if ( mInc1->lastModified() > mInc2->lastModified() )
164 void KIncidenceChooser::setSyncMode()
166 chooseMode = mBg->selectedId ();
167 if ( chooseMode != KIncidenceChooser::ask )
172 void KIncidenceChooser::useGlobalMode()
174 if ( chooseMode != KIncidenceChooser::ask )
178 void KIncidenceChooser::setLabels()
180 KCal::Incidence* inc = mInc1;
181 TQLabel* des = mInc1lab;
182 TQLabel * sum = mInc1Sumlab;
185 if ( inc->type() ==
"Event" ) {
186 des->setText( i18n(
"Local Event") );
187 sum->setText( inc->summary().left( 30 ));
189 mDiffBut->setEnabled(
true );
191 else if ( inc->type() ==
"Todo" ) {
192 des->setText( i18n(
"Local Todo") );
193 sum->setText( inc->summary().left( 30 ));
195 mDiffBut->setEnabled(
true );
198 else if ( inc->type() ==
"Journal" ) {
199 des->setText( i18n(
"Local Journal") );
200 sum->setText( inc->description().left( 30 ));
202 mDiffBut->setEnabled(
false );
204 mMod1lab->setText( TDEGlobal::locale()->formatDateTime(inc->lastModified() ));
208 if ( inc->type() ==
"Event" ) {
209 des->setText( i18n(
"New Event") );
210 sum->setText( inc->summary().left( 30 ));
212 else if ( inc->type() ==
"Todo" ) {
213 des->setText( i18n(
"New Todo") );
214 sum->setText( inc->summary().left( 30 ));
217 else if ( inc->type() ==
"Journal" ) {
218 des->setText( i18n(
"New Journal") );
219 sum->setText( inc->description().left( 30 ));
222 mMod2lab->setText( TDEGlobal::locale()->formatDateTime(inc->lastModified() ));
225 void KIncidenceChooser::showIncidence1()
228 if ( mTbL->isVisible() ) {
229 mShowDetails1->setText( i18n(
"Show Details"));
232 mShowDetails1->setText( i18n(
"Hide Details"));
238 mTbL =
new KDialogBase(
this,
"",
false , mInc1lab->text(), KDialogBase::Ok );
239 mTbL->setEscapeButton( KDialogBase::Ok );
240 connect( mTbL, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( detailsDialogClosed() ) );
241 TQTextBrowser* textBrowser =
new TQTextBrowser( mTbL );
242 mTbL->setMainWidget( textBrowser );
243 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) );
244 mTbL->setMinimumSize( 400, 400 );
245 mShowDetails1->setText( i18n(
"Hide Details"));
250 void KIncidenceChooser::detailsDialogClosed()
252 KDialogBase* dialog =
static_cast<KDialogBase *
>(
const_cast<TQObject*
>(sender())) ;
253 if ( dialog == mTbL )
254 mShowDetails1->setText( i18n(
"Show details..." ) );
256 mShowDetails2->setText( i18n(
"Show details..." ) );
259 void KIncidenceChooser::showDiff()
261 if ( mDisplayDiff ) {
262 mDisplayDiff->show();
263 mDisplayDiff->raise();
266 mDisplayDiff =
new KPIM::HTMLDiffAlgoDisplay (
this);
267 if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) )
268 mDisplayDiff->setCaption( i18n(
"Differences of %1 and %2").arg( mInc1->summary().left( 20 ) ).arg( mInc2->summary().left( 20 ) ) );
270 mDisplayDiff->setCaption( i18n(
"Differences of %1").arg( mInc1->summary().left( 20 ) ) );
272 diff =
new KPIM::CalendarDiffAlgo( mInc1, mInc2);
273 diff->setLeftSourceTitle( i18n(
"Local entry"));
274 diff->setRightSourceTitle(i18n(
"New (remote) entry") );
275 diff->addDisplay( mDisplayDiff );
277 mDisplayDiff->show();
278 mDisplayDiff->raise();
281 void KIncidenceChooser::showIncidence2()
284 if ( mTbN->isVisible() ) {
285 mShowDetails2->setText( i18n(
"Show Details"));
288 mShowDetails2->setText( i18n(
"Hide Details"));
294 mTbN =
new KDialogBase(
this,
"",
false , mInc2lab->text(), KDialogBase::Ok );
295 mTbN->setEscapeButton( KDialogBase::Ok );
296 connect( mTbN, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( detailsDialogClosed() ) );
297 TQTextBrowser* textBrowser =
new TQTextBrowser( mTbN );
298 mTbN->setMainWidget( textBrowser );
299 textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) );
300 mTbN->setMinimumSize( 400, 400 );
301 mShowDetails2->setText( i18n(
"Hide Details"));
306 void KIncidenceChooser::takeIncidence1()
308 mSelIncidence = mInc1;
312 void KIncidenceChooser::takeIncidence2()
314 mSelIncidence = mInc2;
318 void KIncidenceChooser::takeBoth()
326 #include "kincidencechooser.moc"
KIncidenceChooser(TQWidget *parent=0, char *name=0)
Initialize dialog and pages.