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

akonadi/contact

imeditordialog.cpp
00001 /*
00002 IM address editor widget for KDE PIM
00003 
00004 Copyright 2004,2010 Will Stephenson <wstephenson@kde.org>
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) version 3, or any
00010 later version accepted by the membership of KDE e.V. (or its
00011 successor approved by the membership of KDE e.V.), which shall
00012 act as a proxy defined in Section 6 of version 3 of the license.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #include "imeditordialog.h"
00024 
00025 #include "imdelegate.h"
00026 
00027 #include <QtCore/QStringList>
00028 #include <QtGui/QGridLayout>
00029 #include <QtGui/QPushButton>
00030 #include <QtGui/QTreeView>
00031 
00032 #include <klocale.h>
00033 #include <kmessagebox.h>
00034 
00035 IMEditorDialog::IMEditorDialog( QWidget *parent )
00036   : KDialog( parent )
00037 {
00038   setCaption( i18n( "Edit Instant Messaging Addresses" ) );
00039   setButtons( Ok | Cancel );
00040   setDefaultButton( Ok );
00041 
00042   QWidget *widget = new QWidget( this );
00043   setMainWidget( widget );
00044 
00045   QGridLayout *layout = new QGridLayout( widget );
00046 
00047   mAddButton = new QPushButton( i18n( "Add" ) );
00048   mRemoveButton = new QPushButton( i18n( "Remove" ) );
00049   mStandardButton = new QPushButton( i18n( "Set as Standard" ) );
00050 
00051   mView = new QTreeView;
00052   mView->setRootIsDecorated( false );
00053 
00054   layout->addWidget( mView, 0, 0, 4, 1 );
00055   layout->addWidget( mAddButton, 0, 1 );
00056   layout->addWidget( mRemoveButton, 1, 1 );
00057   layout->addWidget( mStandardButton, 2, 1 );
00058 
00059   connect( mAddButton, SIGNAL(clicked()), SLOT(slotAdd()) );
00060   connect( mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()) );
00061   connect( mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()) );
00062 
00063   mRemoveButton->setEnabled( false );
00064   mStandardButton->setEnabled( false );
00065 
00066   mModel = new IMModel( this );
00067 
00068   mView->setModel( mModel );
00069   mView->setItemDelegate( new IMDelegate( this ) );
00070 
00071   connect( mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
00072            this, SLOT(slotUpdateButtons()) );
00073 }
00074 
00075 void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
00076 {
00077   mModel->setAddresses( addresses );
00078 }
00079 
00080 IMAddress::List IMEditorDialog::addresses() const
00081 {
00082   return mModel->addresses();
00083 }
00084 
00085 void IMEditorDialog::slotAdd()
00086 {
00087   mModel->insertRow( mModel->rowCount() );
00088 }
00089 
00090 void IMEditorDialog::slotRemove()
00091 {
00092   const QModelIndex currentIndex = mView->currentIndex();
00093   if ( !currentIndex.isValid() )
00094     return;
00095 
00096   if ( KMessageBox::warningContinueCancel( this,
00097                                            i18nc( "Instant messaging", "Do you really want to delete the selected address?" ),
00098                                            i18n( "Confirm Delete" ), KStandardGuiItem::del() ) != KMessageBox::Continue ) {
00099     return;
00100   }
00101 
00102   mModel->removeRow( currentIndex.row() );
00103 }
00104 
00105 void IMEditorDialog::slotSetStandard()
00106 {
00107   const QModelIndex currentIndex = mView->currentIndex();
00108   if ( !currentIndex.isValid() )
00109     return;
00110 
00111   // set current index as preferred and all other as non-preferred
00112   for ( int i = 0; i < mModel->rowCount(); ++i ) {
00113     const QModelIndex index = mModel->index( i, 0 );
00114     mModel->setData( index, (index.row() == currentIndex.row()), IMModel::IsPreferredRole );
00115   }
00116 }
00117 
00118 void IMEditorDialog::slotUpdateButtons()
00119 {
00120   const QModelIndex currentIndex = mView->currentIndex();
00121 
00122   mRemoveButton->setEnabled( currentIndex.isValid() );
00123   mStandardButton->setEnabled( currentIndex.isValid() );
00124 }
00125 
00126 #include "imeditordialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:02:51 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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