kitchensync

multiconflictdialog.cpp
00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <kdialog.h>
00022 #include <tdelocale.h>
00023 #include <kwidgetlist.h>
00024 
00025 #include <tqlabel.h>
00026 #include <tqlayout.h>
00027 #include <tqpushbutton.h>
00028 
00029 #include "memberinfo.h"
00030 
00031 #include "multiconflictdialog.h"
00032 
00033 class ChangeItem : public KWidgetListItem
00034 {
00035   public:
00036     ChangeItem( KWidgetList *parent, const QSync::SyncChange &change )
00037       : KWidgetListItem( parent ),
00038         mChange( change )
00039     {
00040       TQGridLayout *layout = new TQGridLayout( this, 2, 1, KDialog::marginHint(), KDialog::spacingHint() );
00041 
00042       MemberInfo mi( change.member() );
00043       layout->addWidget( new TQLabel( mi.name(), this ), 0, 0 );
00044 
00045       TQString type;
00046       switch ( change.changeType() ) {
00047         case QSync::SyncChange::UnknownChange:
00048           type = i18n( "Unknown" );
00049           break;
00050         case QSync::SyncChange::AddedChange:
00051           type = i18n( "Added" );
00052           break;
00053         case QSync::SyncChange::DeletedChange:
00054           type = i18n( "Deleted" );
00055           break;
00056         case QSync::SyncChange::ModifiedChange:
00057           type = i18n( "Modified" );
00058           break;
00059         case QSync::SyncChange::UnmodifiedChange:
00060         default:
00061           type = i18n( "Unmodified" );
00062           break;
00063       }
00064 
00065       layout->addWidget( new TQLabel( type, this ), 1, 0 );
00066     }
00067 
00068     QSync::SyncChange change() const { return mChange; }
00069 
00070   private:
00071     QSync::SyncChange mChange;
00072 };
00073 
00074 MultiConflictDialog::MultiConflictDialog( QSync::SyncMapping &mapping, TQWidget *parent )
00075   : ConflictDialog( mapping, parent )
00076 {
00077   initGUI();
00078 
00079   for ( int i = 0; i < mMapping.changesCount(); ++i ) {
00080     QSync::SyncChange change = mMapping.changeAt( i );
00081     if ( change.isValid() ) {
00082       ChangeItem *item = new ChangeItem( mWidgetList, change );
00083       mWidgetList->appendItem( item );
00084     }
00085   }
00086 
00087   mWidgetList->setFocus();
00088 }
00089 
00090 MultiConflictDialog::~MultiConflictDialog()
00091 {
00092 }
00093 
00094 void MultiConflictDialog::useSelectedChange()
00095 {
00096   ChangeItem *item = static_cast<ChangeItem*>( mWidgetList->selectedItem() );
00097   if ( !item )
00098     return;
00099 
00100   mMapping.solve( item->change() );
00101 
00102   accept();
00103 }
00104 
00105 void MultiConflictDialog::duplicateChange()
00106 {
00107   mMapping.duplicate();
00108 
00109   accept();
00110 }
00111 
00112 void MultiConflictDialog::ignoreChange()
00113 {
00114   mMapping.ignore();
00115 
00116   accept();
00117 }
00118 
00119 void MultiConflictDialog::initGUI()
00120 {
00121   TQGridLayout *layout = new TQGridLayout( this, 3, 3, KDialog::marginHint(), KDialog::spacingHint() );
00122 
00123   layout->addMultiCellWidget( new TQLabel( i18n( "A conflict has appeared, please solve it manually." ), this ), 0, 0, 0, 2 );
00124 
00125   mWidgetList = new KWidgetList( this );
00126   layout->addMultiCellWidget( mWidgetList, 1, 1, 0, 2 );
00127 
00128   TQPushButton *button = new TQPushButton( i18n( "Use Selected Item" ), this );
00129   connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( useSelectedChange() ) );
00130   layout->addWidget( button, 2, 0 );
00131 
00132   button = new TQPushButton( i18n( "Duplicate Items" ), this );
00133   connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( duplicateChange() ) );
00134   layout->addWidget( button, 2, 1 );
00135 
00136   button = new TQPushButton( i18n( "Ignore Conflict" ), this );
00137   connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( ignoreChange() ) );
00138   layout->addWidget( button, 2, 2 );
00139 }
00140 
00141 #include "multiconflictdialog.moc"