~ubuntu-branches/ubuntu/raring/kdepimlibs/raring-proposed

« back to all changes in this revision

Viewing changes to akonadi/contact/editor/im/imeditordialog.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Thomas
  • Date: 2012-05-24 21:48:49 UTC
  • mto: This revision was merged to the branch mainline in revision 120.
  • Revision ID: package-import@ubuntu.com-20120524214849-jg6g61f1r51u3mgo
Tags: upstream-4.8.80a
ImportĀ upstreamĀ versionĀ 4.8.80a

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "imeditordialog.h"
24
24
 
25
25
#include "imdelegate.h"
 
26
#include "imitemdialog.h"
26
27
 
27
28
#include <QtCore/QStringList>
28
29
#include <QtGui/QGridLayout>
35
36
IMEditorDialog::IMEditorDialog( QWidget *parent )
36
37
  : KDialog( parent )
37
38
{
38
 
  setCaption( i18n( "Edit Instant Messaging Addresses" ) );
 
39
  setCaption( i18nc( "@title:window", "Edit Instant Messaging Addresses" ) );
39
40
  setButtons( Ok | Cancel );
40
41
  setDefaultButton( Ok );
41
42
 
44
45
 
45
46
  QGridLayout *layout = new QGridLayout( widget );
46
47
 
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" ) );
50
52
 
51
53
  mView = new QTreeView;
52
54
  mView->setRootIsDecorated( false );
53
55
 
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 );
58
62
 
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()) );
62
67
 
63
 
  mRemoveButton->setEnabled( false );
64
 
  mStandardButton->setEnabled( false );
65
 
 
66
68
  mModel = new IMModel( this );
67
69
 
68
70
  mView->setModel( mModel );
70
72
 
71
73
  connect( mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
72
74
           this, SLOT(slotUpdateButtons()) );
 
75
  connect( mView, SIGNAL(doubleClicked(QModelIndex)),
 
76
           this, SLOT(slotEdit()) );
 
77
  slotUpdateButtons();
73
78
}
74
79
 
75
80
void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
84
89
 
85
90
void IMEditorDialog::slotAdd()
86
91
{
87
 
  mModel->insertRow( mModel->rowCount() );
 
92
  IMItemDialog d( this );
 
93
  d.setCaption( i18nc( "@title:window", "Add IM Address" ) );
 
94
  if ( d.exec() ) {
 
95
    IMAddress newAddress = d.address();
 
96
    int addedRow = mModel->rowCount();
 
97
    mModel->insertRow( addedRow );
 
98
 
 
99
    mModel->setData( mModel->index( addedRow, 0 ), newAddress.protocol(), IMModel::ProtocolRole );
 
100
    mModel->setData( mModel->index( addedRow, 1 ), newAddress.name(), Qt::EditRole );
 
101
  }
 
102
}
 
103
 
 
104
void IMEditorDialog::slotEdit()
 
105
{
 
106
  const int currentRow = mView->currentIndex().row();
 
107
  if ( currentRow < 0 ) {
 
108
    return;
 
109
  }
 
110
 
 
111
  IMItemDialog d( this );
 
112
  d.setCaption( i18nc( "@title:window", "Edit IM Address" ) );
 
113
  d.setAddress( mModel->addresses().at( currentRow ) );
 
114
 
 
115
  if ( d.exec() ) {
 
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(),
 
120
                     Qt::EditRole );
 
121
  }
88
122
}
89
123
 
90
124
void IMEditorDialog::slotRemove()
91
125
{
92
 
  const QModelIndex currentIndex = mView->currentIndex();
93
 
  if ( !currentIndex.isValid() )
94
 
    return;
95
 
 
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 ) {
99
 
    return;
100
 
  }
101
 
 
102
 
  mModel->removeRow( currentIndex.row() );
 
126
  const int currentRow = mView->currentIndex().row();
 
127
  if ( currentRow < 0 ) {
 
128
    return;
 
129
  }
 
130
 
 
131
  if ( KMessageBox::warningContinueCancel(
 
132
         this,
 
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 ) {
 
138
    return;
 
139
  }
 
140
 
 
141
  mModel->removeRow( currentRow );
103
142
}
104
143
 
105
144
void IMEditorDialog::slotSetStandard()
106
145
{
107
 
  const QModelIndex currentIndex = mView->currentIndex();
108
 
  if ( !currentIndex.isValid() )
 
146
  const int currentRow = mView->currentIndex().row();
 
147
  if ( currentRow < 0 ) {
109
148
    return;
 
149
  }
110
150
 
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 );
115
155
  }
116
156
}
117
157
 
120
160
  const QModelIndex currentIndex = mView->currentIndex();
121
161
 
122
162
  mRemoveButton->setEnabled( currentIndex.isValid() );
123
 
  mStandardButton->setEnabled( currentIndex.isValid() );
 
163
  mEditButton->setEnabled( currentIndex.isValid() );
 
164
 
 
165
  mStandardButton->setEnabled( currentIndex.isValid() &&
 
166
                               !mModel->data( currentIndex, IMModel::IsPreferredRole ).toBool() );
124
167
}
125
168
 
126
169
#include "imeditordialog.moc"