summaryrefslogtreecommitdiffstats
path: root/kitchensync/src/singleconflictdialog.cpp
blob: 3c11cd05804e16f5a96fed61b1599f28bfca1dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
    This file is part of KitchenSync.

    Copyright (c) 2005 Tobias Koenig <tokoe@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.
*/

#include <kdialog.h>
#include <klocale.h>

#include <tqlabel.h>
#include <layout.h>
#include <tqpushbutton.h>

#include "addresseediffalgo.h"
#include "genericdiffalgo.h"
#include "htmldiffalgodisplay.h"
#include "memberinfo.h"

#include "singleconflictdialog.h"

SingleConflictDialog::SingleConflictDialog( QSync::SyncMapping &mapping, TQWidget *parent )
  : ConflictDialog( mapping, parent ), mDiffAlgo( 0 )
{
  initGUI();

  TQString format = mapping.changeAt( 0 ).objectFormatName();
  QSync::SyncChange leftChange = mapping.changeAt( 0 );
  QSync::SyncChange rightChange = mapping.changeAt( 1 );

  if ( format == "file" ) {
    mDiffAlgo = new KSync::GenericDiffAlgo( leftChange.data(), rightChange.data() );
  } else if ( format == "vcard" ) {
  } else if ( format == "calendar" ) {
  } else if ( format == "xml-contact" ) {
    mDiffAlgo = new KSync::AddresseeDiffAlgo( leftChange.data(), rightChange.data() );
  }

  MemberInfo miLeft( leftChange.member() );
  mDiffAlgoDisplay->setLeftSourceTitle( miLeft.name() );
  MemberInfo miRight( rightChange.member() );
  mDiffAlgoDisplay->setRightSourceTitle( miRight.name() );

  if ( mDiffAlgo ) {
    mDiffAlgo->addDisplay( mDiffAlgoDisplay );
    mDiffAlgo->run();
  }
}

SingleConflictDialog::~SingleConflictDialog()
{
  delete mDiffAlgo;
  mDiffAlgo = 0;
}

void SingleConflictDialog::useFirstChange()
{
  mMapping.solve( mMapping.changeAt( 0 ) );

  accept();
}

void SingleConflictDialog::useSecondChange()
{
  mMapping.solve( mMapping.changeAt( 1 ) );

  accept();
}

void SingleConflictDialog::duplicateChange()
{
  mMapping.duplicate();

  accept();
}

void SingleConflictDialog::ignoreChange()
{
  mMapping.ignore();

  accept();
}

void SingleConflictDialog::initGUI()
{
  TQGridLayout *layout = new TQGridLayout( this, 3, 4, KDialog::marginHint(), KDialog::spacingHint() );

  layout->addMultiCellWidget( new TQLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 3 );
  mDiffAlgoDisplay = new KSync::HTMLDiffAlgoDisplay( this );

  layout->addMultiCellWidget( mDiffAlgoDisplay, 1, 1, 0, 3 );

  TQPushButton *button = new TQPushButton( i18n( "Use Item" ), this );
  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( useFirstChange() ) );
  layout->addWidget( button, 2, 0 );

  button = new TQPushButton( i18n( "Duplicate Items" ), this );
  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( duplicateChange() ) );
  layout->addWidget( button, 2, 1 );

  button = new TQPushButton( i18n( "Ignore Conflict" ), this );
  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( ignoreChange() ) );
  layout->addWidget( button, 2, 2 );

  button = new TQPushButton( i18n( "Use Item" ), this );
  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( useSecondChange() ) );
  layout->addWidget( button, 2, 3 );
}

#include "singleconflictdialog.moc"