45
46
QGridLayout *layout = new QGridLayout( widget );
47
mAddButton = new QPushButton( i18n( "Add" ) );
48
mRemoveButton = new QPushButton( i18n( "Remove" ) );
49
mStandardButton = new QPushButton( i18n( "Set as Standard" ) );
48
mAddButton = new QPushButton( i18nc( "@action:button", "Add..." ) );
49
mEditButton = new QPushButton( i18nc( "@action:button", "Edit..." ) );
50
mRemoveButton = new QPushButton( i18nc( "@action:button", "Remove" ) );
51
mStandardButton = new QPushButton( i18nc( "@action:button", "Set as Standard" ) );
51
53
mView = new QTreeView;
52
54
mView->setRootIsDecorated( false );
54
layout->addWidget( mView, 0, 0, 4, 1 );
56
layout->addWidget( mView, 0, 0, 5, 1 );
55
57
layout->addWidget( mAddButton, 0, 1 );
56
layout->addWidget( mRemoveButton, 1, 1 );
57
layout->addWidget( mStandardButton, 2, 1 );
58
layout->addWidget( mEditButton, 1, 1 );
59
layout->addWidget( mRemoveButton, 2, 1 );
60
layout->addWidget( mStandardButton, 3, 1 );
61
layout->setRowStretch( 4, 1 );
59
63
connect( mAddButton, SIGNAL(clicked()), SLOT(slotAdd()) );
64
connect( mEditButton, SIGNAL(clicked()), SLOT(slotEdit()) );
60
65
connect( mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()) );
61
66
connect( mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()) );
63
mRemoveButton->setEnabled( false );
64
mStandardButton->setEnabled( false );
66
68
mModel = new IMModel( this );
68
70
mView->setModel( mModel );
71
73
connect( mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
72
74
this, SLOT(slotUpdateButtons()) );
75
connect( mView, SIGNAL(doubleClicked(QModelIndex)),
76
this, SLOT(slotEdit()) );
75
80
void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
85
90
void IMEditorDialog::slotAdd()
87
mModel->insertRow( mModel->rowCount() );
92
IMItemDialog d( this );
93
d.setCaption( i18nc( "@title:window", "Add IM Address" ) );
95
IMAddress newAddress = d.address();
96
int addedRow = mModel->rowCount();
97
mModel->insertRow( addedRow );
99
mModel->setData( mModel->index( addedRow, 0 ), newAddress.protocol(), IMModel::ProtocolRole );
100
mModel->setData( mModel->index( addedRow, 1 ), newAddress.name(), Qt::EditRole );
104
void IMEditorDialog::slotEdit()
106
const int currentRow = mView->currentIndex().row();
107
if ( currentRow < 0 ) {
111
IMItemDialog d( this );
112
d.setCaption( i18nc( "@title:window", "Edit IM Address" ) );
113
d.setAddress( mModel->addresses().at( currentRow ) );
116
IMAddress editedAddress = d.address();
117
mModel->setData( mModel->index( currentRow, 0 ), editedAddress.protocol(),
118
IMModel::ProtocolRole );
119
mModel->setData( mModel->index( currentRow, 1 ), editedAddress.name(),
90
124
void IMEditorDialog::slotRemove()
92
const QModelIndex currentIndex = mView->currentIndex();
93
if ( !currentIndex.isValid() )
96
if ( KMessageBox::warningContinueCancel( this,
97
i18nc( "Instant messaging", "Do you really want to delete the selected address?" ),
98
i18n( "Confirm Delete" ), KStandardGuiItem::del() ) != KMessageBox::Continue ) {
102
mModel->removeRow( currentIndex.row() );
126
const int currentRow = mView->currentIndex().row();
127
if ( currentRow < 0 ) {
131
if ( KMessageBox::warningContinueCancel(
133
i18nc( "@info Instant messaging",
134
"Do you really want to delete the selected <resource>%1</resource> address?",
135
mModel->data( mModel->index( currentRow, 0 ), Qt::DisplayRole ).toString() ),
136
i18nc( "@title:window", "Confirm Delete Resource" ),
137
KStandardGuiItem::del() ) != KMessageBox::Continue ) {
141
mModel->removeRow( currentRow );
105
144
void IMEditorDialog::slotSetStandard()
107
const QModelIndex currentIndex = mView->currentIndex();
108
if ( !currentIndex.isValid() )
146
const int currentRow = mView->currentIndex().row();
147
if ( currentRow < 0 ) {
111
151
// set current index as preferred and all other as non-preferred
112
152
for ( int i = 0; i < mModel->rowCount(); ++i ) {
113
153
const QModelIndex index = mModel->index( i, 0 );
114
mModel->setData( index, (index.row() == currentIndex.row()), IMModel::IsPreferredRole );
154
mModel->setData( index, ( index.row() == currentRow ), IMModel::IsPreferredRole );
120
160
const QModelIndex currentIndex = mView->currentIndex();
122
162
mRemoveButton->setEnabled( currentIndex.isValid() );
123
mStandardButton->setEnabled( currentIndex.isValid() );
163
mEditButton->setEnabled( currentIndex.isValid() );
165
mStandardButton->setEnabled( currentIndex.isValid() &&
166
!mModel->data( currentIndex, IMModel::IsPreferredRole ).toBool() );
126
169
#include "imeditordialog.moc"