kitchensync

multiconflictdialog.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include <kdialog.h>
22 #include <tdelocale.h>
23 #include <kwidgetlist.h>
24 
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqpushbutton.h>
28 
29 #include "memberinfo.h"
30 
31 #include "multiconflictdialog.h"
32 
33 class ChangeItem : public KWidgetListItem
34 {
35  public:
36  ChangeItem( KWidgetList *parent, const QSync::SyncChange &change )
37  : KWidgetListItem( parent ),
38  mChange( change )
39  {
40  TQGridLayout *layout = new TQGridLayout( this, 2, 1, KDialog::marginHint(), KDialog::spacingHint() );
41 
42  MemberInfo mi( change.member() );
43  layout->addWidget( new TQLabel( mi.name(), this ), 0, 0 );
44 
45  TQString type;
46  switch ( change.changeType() ) {
47  case QSync::SyncChange::UnknownChange:
48  type = i18n( "Unknown" );
49  break;
50  case QSync::SyncChange::AddedChange:
51  type = i18n( "Added" );
52  break;
53  case QSync::SyncChange::DeletedChange:
54  type = i18n( "Deleted" );
55  break;
56  case QSync::SyncChange::ModifiedChange:
57  type = i18n( "Modified" );
58  break;
59  case QSync::SyncChange::UnmodifiedChange:
60  default:
61  type = i18n( "Unmodified" );
62  break;
63  }
64 
65  layout->addWidget( new TQLabel( type, this ), 1, 0 );
66  }
67 
68  QSync::SyncChange change() const { return mChange; }
69 
70  private:
71  QSync::SyncChange mChange;
72 };
73 
74 MultiConflictDialog::MultiConflictDialog( QSync::SyncMapping &mapping, TQWidget *parent )
75  : ConflictDialog( mapping, parent )
76 {
77  initGUI();
78 
79  for ( int i = 0; i < mMapping.changesCount(); ++i ) {
80  QSync::SyncChange change = mMapping.changeAt( i );
81  if ( change.isValid() ) {
82  ChangeItem *item = new ChangeItem( mWidgetList, change );
83  mWidgetList->appendItem( item );
84  }
85  }
86 
87  mWidgetList->setFocus();
88 }
89 
90 MultiConflictDialog::~MultiConflictDialog()
91 {
92 }
93 
94 void MultiConflictDialog::useSelectedChange()
95 {
96  ChangeItem *item = static_cast<ChangeItem*>( mWidgetList->selectedItem() );
97  if ( !item )
98  return;
99 
100  mMapping.solve( item->change() );
101 
102  accept();
103 }
104 
105 void MultiConflictDialog::duplicateChange()
106 {
107  mMapping.duplicate();
108 
109  accept();
110 }
111 
112 void MultiConflictDialog::ignoreChange()
113 {
114  mMapping.ignore();
115 
116  accept();
117 }
118 
119 void MultiConflictDialog::initGUI()
120 {
121  TQGridLayout *layout = new TQGridLayout( this, 3, 3, KDialog::marginHint(), KDialog::spacingHint() );
122 
123  layout->addMultiCellWidget( new TQLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 2 );
124 
125  mWidgetList = new KWidgetList( this );
126  layout->addMultiCellWidget( mWidgetList, 1, 1, 0, 2 );
127 
128  TQPushButton *button = new TQPushButton( i18n( "Use Selected Item" ), this );
129  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( useSelectedChange() ) );
130  layout->addWidget( button, 2, 0 );
131 
132  button = new TQPushButton( i18n( "Duplicate Items" ), this );
133  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( duplicateChange() ) );
134  layout->addWidget( button, 2, 1 );
135 
136  button = new TQPushButton( i18n( "Ignore Conflict" ), this );
137  connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( ignoreChange() ) );
138  layout->addWidget( button, 2, 2 );
139 }
140 
141 #include "multiconflictdialog.moc"
Base class for SingleConflictDialog and MultiConflictDialog.