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