• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
  • editor
  • im
imeditordialog.cpp
1 /*
2 IM address editor widget for KDE PIM
3 
4 Copyright 2004,2010 Will Stephenson <wstephenson@kde.org>
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) version 3, or any
10 later version accepted by the membership of KDE e.V. (or its
11 successor approved by the membership of KDE e.V.), which shall
12 act as a proxy defined in Section 6 of version 3 of the license.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "imeditordialog.h"
24 
25 #include "imdelegate.h"
26 #include "imitemdialog.h"
27 
28 #include <QtCore/QStringList>
29 #include <QGridLayout>
30 #include <QPushButton>
31 #include <QTreeView>
32 
33 #include <klocale.h>
34 #include <kmessagebox.h>
35 
36 IMEditorDialog::IMEditorDialog( QWidget *parent )
37  : KDialog( parent )
38 {
39  setCaption( i18nc( "@title:window", "Edit Instant Messaging Addresses" ) );
40  setButtons( Ok | Cancel );
41  setDefaultButton( Ok );
42 
43  QWidget *widget = new QWidget( this );
44  setMainWidget( widget );
45 
46  QGridLayout *layout = new QGridLayout( widget );
47 
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" ) );
52 
53  mView = new QTreeView;
54  mView->setRootIsDecorated( false );
55 
56  layout->addWidget( mView, 0, 0, 5, 1 );
57  layout->addWidget( mAddButton, 0, 1 );
58  layout->addWidget( mEditButton, 1, 1 );
59  layout->addWidget( mRemoveButton, 2, 1 );
60  layout->addWidget( mStandardButton, 3, 1 );
61  layout->setRowStretch( 4, 1 );
62 
63  connect( mAddButton, SIGNAL(clicked()), SLOT(slotAdd()) );
64  connect( mEditButton, SIGNAL(clicked()), SLOT(slotEdit()) );
65  connect( mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()) );
66  connect( mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()) );
67 
68  mModel = new IMModel( this );
69 
70  mView->setModel( mModel );
71  mView->setItemDelegate( new IMDelegate( this ) );
72 
73  connect( mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
74  this, SLOT(slotUpdateButtons()) );
75  connect( mView, SIGNAL(doubleClicked(QModelIndex)),
76  this, SLOT(slotEdit()) );
77  slotUpdateButtons();
78 }
79 
80 void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
81 {
82  mModel->setAddresses( addresses );
83 }
84 
85 IMAddress::List IMEditorDialog::addresses() const
86 {
87  return mModel->addresses();
88 }
89 
90 void IMEditorDialog::slotAdd()
91 {
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  }
122 }
123 
124 void IMEditorDialog::slotRemove()
125 {
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 );
142 }
143 
144 void IMEditorDialog::slotSetStandard()
145 {
146  const int currentRow = mView->currentIndex().row();
147  if ( currentRow < 0 ) {
148  return;
149  }
150 
151  // set current index as preferred and all other as non-preferred
152  for ( int i = 0; i < mModel->rowCount(); ++i ) {
153  const QModelIndex index = mModel->index( i, 0 );
154  mModel->setData( index, ( index.row() == currentRow ), IMModel::IsPreferredRole );
155  }
156 }
157 
158 void IMEditorDialog::slotUpdateButtons()
159 {
160  const QModelIndex currentIndex = mView->currentIndex();
161 
162  mRemoveButton->setEnabled( currentIndex.isValid() );
163  mEditButton->setEnabled( currentIndex.isValid() );
164 
165  mStandardButton->setEnabled( currentIndex.isValid() &&
166  !mModel->data( currentIndex, IMModel::IsPreferredRole ).toBool() );
167 }
168 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:37 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal