00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "imeditordialog.h"
00024
00025 #include "imdelegate.h"
00026
00027 #include <QtCore/QStringList>
00028 #include <QtGui/QGridLayout>
00029 #include <QtGui/QPushButton>
00030 #include <QtGui/QTreeView>
00031
00032 #include <klocale.h>
00033 #include <kmessagebox.h>
00034
00035 IMEditorDialog::IMEditorDialog( QWidget *parent )
00036 : KDialog( parent )
00037 {
00038 setCaption( i18n( "Edit Instant Messaging Address" ) );
00039 setButtons( Ok | Cancel );
00040 setDefaultButton( Ok );
00041
00042 QWidget *widget = new QWidget( this );
00043 setMainWidget( widget );
00044
00045 QGridLayout *layout = new QGridLayout( widget );
00046
00047 mAddButton = new QPushButton( i18n( "Add" ) );
00048 mRemoveButton = new QPushButton( i18n( "Remove" ) );
00049 mStandardButton = new QPushButton( i18n( "Set as Standard" ) );
00050
00051 mView = new QTreeView;
00052 mView->setRootIsDecorated( false );
00053
00054 layout->addWidget( mView, 0, 0, 4, 1 );
00055 layout->addWidget( mAddButton, 0, 1 );
00056 layout->addWidget( mRemoveButton, 1, 1 );
00057 layout->addWidget( mStandardButton, 2, 1 );
00058
00059 connect( mAddButton, SIGNAL( clicked() ), SLOT( slotAdd() ) );
00060 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) );
00061 connect( mStandardButton, SIGNAL( clicked()), SLOT( slotSetStandard() ) );
00062
00063 mRemoveButton->setEnabled( false );
00064 mStandardButton->setEnabled( false );
00065
00066 mModel = new IMModel( this );
00067
00068 mView->setModel( mModel );
00069 mView->setItemDelegate( new IMDelegate( this ) );
00070
00071 connect( mView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
00072 this, SLOT( slotUpdateButtons() ) );
00073 }
00074
00075 void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
00076 {
00077 mModel->setAddresses( addresses );
00078 }
00079
00080 IMAddress::List IMEditorDialog::addresses() const
00081 {
00082 return mModel->addresses();
00083 }
00084
00085 void IMEditorDialog::slotAdd()
00086 {
00087 mModel->insertRow( mModel->rowCount() );
00088 }
00089
00090 void IMEditorDialog::slotRemove()
00091 {
00092 const QModelIndex currentIndex = mView->currentIndex();
00093 if ( !currentIndex.isValid() )
00094 return;
00095
00096 if ( KMessageBox::warningContinueCancel( this,
00097 i18nc( "Instant messaging", "Do you really want to delete the selected address?" ),
00098 i18n( "Confirm Delete" ), KStandardGuiItem::del() ) != KMessageBox::Continue ) {
00099 return;
00100 }
00101
00102 mModel->removeRow( currentIndex.row() );
00103 }
00104
00105 void IMEditorDialog::slotSetStandard()
00106 {
00107 const QModelIndex currentIndex = mView->currentIndex();
00108 if ( !currentIndex.isValid() )
00109 return;
00110
00111
00112 for ( int i = 0; i < mModel->rowCount(); ++i ) {
00113 const QModelIndex index = mModel->index( i, 0 );
00114 mModel->setData( index, (index.row() == currentIndex.row()), IMModel::IsPreferredRole );
00115 }
00116 }
00117
00118 void IMEditorDialog::slotUpdateButtons()
00119 {
00120 const QModelIndex currentIndex = mView->currentIndex();
00121
00122 mRemoveButton->setEnabled( currentIndex.isValid() );
00123 mStandardButton->setEnabled( currentIndex.isValid() );
00124 }
00125
00126 #include "imeditordialog.moc"