summaryrefslogtreecommitdiffstats
path: root/kitchensync/src/multiconflictdialog.cpp
blob: 996ef08af51ee2e3f41e77b88f69a4c2fdd3361b (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
    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 <kwidgetlist.h>

#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>

#include "memberinfo.h"

#include "multiconflictdialog.h"

class ChangeItem : public KWidgetListItem
{
  public:
    ChangeItem( KWidgetList *parent, const QSync::SyncChange &change )
      : KWidgetListItem( parent ),
        mChange( change )
    {
      QGridLayout *layout = new QGridLayout( this, 2, 1, KDialog::marginHint(), KDialog::spacingHint() );

      MemberInfo mi( change.member() );
      layout->addWidget( new QLabel( mi.name(), this ), 0, 0 );

      QString type;
      switch ( change.changeType() ) {
        case QSync::SyncChange::UnknownChange:
          type = i18n( "Unknown" );
          break;
        case QSync::SyncChange::AddedChange:
          type = i18n( "Added" );
          break;
        case QSync::SyncChange::DeletedChange:
          type = i18n( "Deleted" );
          break;
        case QSync::SyncChange::ModifiedChange:
          type = i18n( "Modified" );
          break;
        case QSync::SyncChange::UnmodifiedChange:
        default:
          type = i18n( "Unmodified" );
          break;
      }

      layout->addWidget( new QLabel( type, this ), 1, 0 );
    }

    QSync::SyncChange change() const { return mChange; }

  private:
    QSync::SyncChange mChange;
};

MultiConflictDialog::MultiConflictDialog( QSync::SyncMapping &mapping, QWidget *parent )
  : ConflictDialog( mapping, parent )
{
  initGUI();

  for ( int i = 0; i < mMapping.changesCount(); ++i ) {
    QSync::SyncChange change = mMapping.changeAt( i );
    if ( change.isValid() ) {
      ChangeItem *item = new ChangeItem( mWidgetList, change );
      mWidgetList->appendItem( item );
    }
  }

  mWidgetList->setFocus();
}

MultiConflictDialog::~MultiConflictDialog()
{
}

void MultiConflictDialog::useSelectedChange()
{
  ChangeItem *item = static_cast<ChangeItem*>( mWidgetList->selectedItem() );
  if ( !item )
    return;

  mMapping.solve( item->change() );

  accept();
}

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

  accept();
}

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

  accept();
}

void MultiConflictDialog::initGUI()
{
  QGridLayout *layout = new QGridLayout( this, 3, 3, KDialog::marginHint(), KDialog::spacingHint() );

  layout->addMultiCellWidget( new QLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 2 );

  mWidgetList = new KWidgetList( this );
  layout->addMultiCellWidget( mWidgetList, 1, 1, 0, 2 );

  QPushButton *button = new QPushButton( i18n( "Use Selected Item" ), this );
  connect( button, SIGNAL( clicked() ), SLOT( useSelectedChange() ) );
  layout->addWidget( button, 2, 0 );

  button = new QPushButton( i18n( "Duplicate Items" ), this );
  connect( button, SIGNAL( clicked() ), SLOT( duplicateChange() ) );
  layout->addWidget( button, 2, 1 );

  button = new QPushButton( i18n( "Ignore Conflict" ), this );
  connect( button, SIGNAL( clicked() ), SLOT( ignoreChange() ) );
  layout->addWidget( button, 2, 2 );
}

#include "multiconflictdialog.moc"