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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 <QGridLayout>
29 #include <QPointer>
30 #include <QPushButton>
31 #include <QTreeView>
32 
33 #include <klocalizedstring.h>
34 #include <kmessagebox.h>
35 #include <KSharedConfig>
36 
37 IMEditorDialog::IMEditorDialog( QWidget *parent )
38  : KDialog( parent )
39 {
40  setCaption( i18nc( "@title:window", "Edit Instant Messaging Addresses" ) );
41  setButtons( Ok | Cancel );
42  setDefaultButton( Ok );
43 
44  QWidget *widget = new QWidget( this );
45  setMainWidget( widget );
46 
47  QGridLayout *layout = new QGridLayout( widget );
48 
49  mAddButton = new QPushButton( i18nc( "@action:button", "Add..." ) );
50  mEditButton = new QPushButton( i18nc( "@action:button", "Edit..." ) );
51  mRemoveButton = new QPushButton( i18nc( "@action:button", "Remove" ) );
52  mStandardButton = new QPushButton( i18nc( "@action:button", "Set as Standard" ) );
53 
54  mView = new QTreeView;
55  mView->setRootIsDecorated( false );
56 
57  layout->addWidget( mView, 0, 0, 5, 1 );
58  layout->addWidget( mAddButton, 0, 1 );
59  layout->addWidget( mEditButton, 1, 1 );
60  layout->addWidget( mRemoveButton, 2, 1 );
61  layout->addWidget( mStandardButton, 3, 1 );
62  layout->setRowStretch( 4, 1 );
63 
64  connect( mAddButton, SIGNAL(clicked()), SLOT(slotAdd()) );
65  connect( mEditButton, SIGNAL(clicked()), SLOT(slotEdit()) );
66  connect( mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()) );
67  connect( mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()) );
68 
69  mModel = new IMModel( this );
70 
71  mView->setModel( mModel );
72  mView->setItemDelegate( new IMDelegate( this ) );
73 
74  connect( mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
75  this, SLOT(slotUpdateButtons()) );
76  connect( mView, SIGNAL(doubleClicked(QModelIndex)),
77  this, SLOT(slotEdit()) );
78  slotUpdateButtons();
79  readConfig();
80 }
81 
82 IMEditorDialog::~IMEditorDialog()
83 {
84  writeConfig();
85 }
86 
87 void IMEditorDialog::readConfig()
88 {
89  KConfigGroup group( KGlobal::config(), "IMEditorDialog" );
90  const QSize sizeDialog = group.readEntry( "Size", QSize(400,200) );
91  if ( sizeDialog.isValid() ) {
92  resize( sizeDialog );
93  }
94 }
95 
96 void IMEditorDialog::writeConfig()
97 {
98  KConfigGroup group( KGlobal::config(), "IMEditorDialog" );
99  group.writeEntry( "Size", size() );
100 }
101 
102 void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
103 {
104  mModel->setAddresses( addresses );
105 }
106 
107 IMAddress::List IMEditorDialog::addresses() const
108 {
109  return mModel->addresses();
110 }
111 
112 void IMEditorDialog::slotAdd()
113 {
114  QPointer<IMItemDialog> d( new IMItemDialog( this ) );
115  d->setCaption( i18nc( "@title:window", "Add IM Address" ) );
116  if ( d->exec() == QDialog::Accepted && d != 0 ) {
117  IMAddress newAddress = d->address();
118  int addedRow = mModel->rowCount();
119  mModel->insertRow( addedRow );
120 
121  mModel->setData( mModel->index( addedRow, 0 ), newAddress.protocol(), IMModel::ProtocolRole );
122  mModel->setData( mModel->index( addedRow, 1 ), newAddress.name(), Qt::EditRole );
123  }
124  delete d;
125 }
126 
127 void IMEditorDialog::slotEdit()
128 {
129  const int currentRow = mView->currentIndex().row();
130  if ( currentRow < 0 ) {
131  return;
132  }
133 
134  QPointer<IMItemDialog> d( new IMItemDialog( this ) );
135  d->setCaption( i18nc( "@title:window", "Edit IM Address" ) );
136  d->setAddress( mModel->addresses().at( currentRow ) );
137 
138  if ( d->exec() == QDialog::Accepted && d != 0 ) {
139  IMAddress editedAddress = d->address();
140  mModel->setData( mModel->index( currentRow, 0 ), editedAddress.protocol(),
141  IMModel::ProtocolRole );
142  mModel->setData( mModel->index( currentRow, 1 ), editedAddress.name(),
143  Qt::EditRole );
144  }
145  delete d;
146 }
147 
148 void IMEditorDialog::slotRemove()
149 {
150  const int currentRow = mView->currentIndex().row();
151  if ( currentRow < 0 ) {
152  return;
153  }
154 
155  if ( KMessageBox::warningContinueCancel(
156  this,
157  i18nc( "@info Instant messaging",
158  "Do you really want to delete the selected <resource>%1</resource> address?",
159  mModel->data( mModel->index( currentRow, 0 ), Qt::DisplayRole ).toString() ),
160  i18nc( "@title:window", "Confirm Delete Resource" ),
161  KStandardGuiItem::del() ) != KMessageBox::Continue ) {
162  return;
163  }
164 
165  mModel->removeRow( currentRow );
166 }
167 
168 void IMEditorDialog::slotSetStandard()
169 {
170  const int currentRow = mView->currentIndex().row();
171  if ( currentRow < 0 ) {
172  return;
173  }
174 
175  // set current index as preferred and all other as non-preferred
176  for ( int i = 0; i < mModel->rowCount(); ++i ) {
177  const QModelIndex index = mModel->index( i, 0 );
178  mModel->setData( index, ( index.row() == currentRow ), IMModel::IsPreferredRole );
179  }
180 }
181 
182 void IMEditorDialog::slotUpdateButtons()
183 {
184  const QModelIndex currentIndex = mView->currentIndex();
185 
186  mRemoveButton->setEnabled( currentIndex.isValid() );
187  mEditButton->setEnabled( currentIndex.isValid() );
188 
189  mStandardButton->setEnabled( currentIndex.isValid() &&
190  !mModel->data( currentIndex, IMModel::IsPreferredRole ).toBool() );
191 }
192 
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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