• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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/QList>
00028 #include <QtCore/QStringList>
00029 #include <QtGui/QGridLayout>
00030 #include <QtGui/QPushButton>
00031 #include <QtGui/QTreeView>
00032 
00033 #include <klocale.h>
00034 #include <kmessagebox.h>
00035 
00036 IMEditorDialog::IMEditorDialog( QWidget *parent )
00037   : KDialog( parent )
00038 {
00039   setCaption( i18n( "Edit Instant Messaging Address" ) );
00040   setButtons( Ok | Cancel );
00041   setDefaultButton( Ok );
00042 
00043   QWidget *widget = new QWidget( this );
00044   setMainWidget( widget );
00045 
00046   QGridLayout *layout = new QGridLayout( widget );
00047 
00048   mAddButton = new QPushButton( i18n( "Add" ) );
00049   mRemoveButton = new QPushButton( i18n( "Remove" ) );
00050   mStandardButton = new QPushButton( i18n( "Set as Standard" ) );
00051 
00052   mView = new QTreeView;
00053   mView->setRootIsDecorated( false );
00054 
00055   layout->addWidget( mView, 0, 0, 4, 1 );
00056   layout->addWidget( mAddButton, 0, 1 );
00057   layout->addWidget( mRemoveButton, 1, 1 );
00058   layout->addWidget( mStandardButton, 2, 1 );
00059 
00060   connect( mAddButton, SIGNAL( clicked() ), SLOT( slotAdd() ) );
00061   connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) );
00062   connect( mStandardButton, SIGNAL( clicked()), SLOT( slotSetStandard() ) );
00063 
00064   mRemoveButton->setEnabled( false );
00065   mStandardButton->setEnabled( false );
00066 
00067   mModel = new IMModel( this );
00068 
00069   mView->setModel( mModel );
00070   mView->setItemDelegate( new IMDelegate( this ) );
00071 
00072   connect( mView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
00073            this, SLOT( slotUpdateButtons() ) );
00074 }
00075 
00076 void IMEditorDialog::setAddresses( const IMAddress::List &addresses )
00077 {
00078   mModel->setAddresses( addresses );
00079 }
00080 
00081 IMAddress::List IMEditorDialog::addresses() const
00082 {
00083   return mModel->addresses();
00084 }
00085 
00086 void IMEditorDialog::slotAdd()
00087 {
00088   mModel->insertRow( mModel->rowCount() );
00089 }
00090 
00091 void IMEditorDialog::slotRemove()
00092 {
00093   const QModelIndex currentIndex = mView->currentIndex();
00094   if ( !currentIndex.isValid() )
00095     return;
00096 
00097   if ( KMessageBox::warningContinueCancel( this,
00098                                            i18nc( "Instant messaging", "Do you really want to delete the selected address?" ),
00099                                            i18n( "Confirm Delete" ), KStandardGuiItem::del() ) != KMessageBox::Continue ) {
00100     return;
00101   }
00102 
00103   mModel->removeRow( currentIndex.row() );
00104 }
00105 
00106 void IMEditorDialog::slotSetStandard()
00107 {
00108   const QModelIndex currentIndex = mView->currentIndex();
00109   if ( !currentIndex.isValid() )
00110     return;
00111 
00112   // set current index as preferred and all other as non-preferred
00113   for ( int i = 0; i < mModel->rowCount(); ++i ) {
00114     const QModelIndex index = mModel->index( i, 0 );
00115     mModel->setData( index, (index.row() == currentIndex.row()), IMModel::IsPreferredRole );
00116   }
00117 }
00118 
00119 void IMEditorDialog::slotUpdateButtons()
00120 {
00121   const QModelIndex currentIndex = mView->currentIndex();
00122 
00123   mRemoveButton->setEnabled( currentIndex.isValid() );
00124   mStandardButton->setEnabled( currentIndex.isValid() );
00125 }
00126 
00127 #include "imeditordialog.moc"

akonadi/contact

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal