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

akonadi/contact

contacteditordialog.cpp
00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2007-2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "contacteditordialog.h"
00023 
00024 #include "contacteditor.h"
00025 
00026 #include <akonadi/collectioncombobox.h>
00027 #include <akonadi/item.h>
00028 
00029 #include <kabc/addressee.h>
00030 
00031 #include <klocale.h>
00032 
00033 #include <QtGui/QGridLayout>
00034 #include <QtGui/QLabel>
00035 
00036 using namespace Akonadi;
00037 
00038 class ContactEditorDialog::Private
00039 {
00040   public:
00041     Private( ContactEditorDialog::Mode mode, AbstractContactEditorWidget *editorWidget,
00042              ContactEditorDialog *parent )
00043       : q( parent ), mAddressBookBox( 0 ), mMode( mode )
00044     {
00045       KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
00046       q->setCaption( mode == ContactEditorDialog::CreateMode ? i18n( "New Contact" ) : i18n( "Edit Contact" ) );
00047       q->setButtons( ContactEditorDialog::Ok | ContactEditorDialog::Cancel );
00048 
00049       QWidget *mainWidget = new QWidget( q );
00050       q->setMainWidget( mainWidget );
00051 
00052       QGridLayout *layout = new QGridLayout( mainWidget );
00053 
00054       if ( editorWidget )
00055         mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, editorWidget, q );
00056       else
00057         mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, q );
00058 
00059       if ( mode == ContactEditorDialog::CreateMode ) {
00060         QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
00061 
00062         mAddressBookBox = new CollectionComboBox( mainWidget );
00063         mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
00064         mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
00065 
00066         layout->addWidget( label, 0, 0 );
00067         layout->addWidget( mAddressBookBox, 0, 1 );
00068       }
00069 
00070       layout->addWidget( mEditor, 1, 0, 1, 2 );
00071       layout->setColumnStretch( 1, 1 );
00072 
00073       connect( mEditor, SIGNAL(contactStored(Akonadi::Item)),
00074                q, SIGNAL(contactStored(Akonadi::Item)) );
00075 
00076       connect( q, SIGNAL(okClicked()), q, SLOT(slotOkClicked()) );
00077       connect( q, SIGNAL(cancelClicked()), q, SLOT(slotCancelClicked()) );
00078 
00079       q->setInitialSize( QSize( 800, 500 ) );
00080     }
00081 
00082     void slotOkClicked()
00083     {
00084       if ( mAddressBookBox )
00085         mEditor->setDefaultAddressBook( mAddressBookBox->currentCollection() );
00086 
00087       if ( mEditor->saveContact() )
00088         q->accept();
00089     }
00090 
00091     void slotCancelClicked()
00092     {
00093       q->reject();
00094     }
00095 
00096     ContactEditorDialog *q;
00097     CollectionComboBox *mAddressBookBox;
00098     ContactEditorDialog::Mode mMode;
00099     ContactEditor *mEditor;
00100 };
00101 
00102 ContactEditorDialog::ContactEditorDialog( Mode mode, QWidget *parent )
00103   : KDialog( parent ), d( new Private( mode, 0, this ) )
00104 {
00105 }
00106 
00107 ContactEditorDialog::ContactEditorDialog( Mode mode, AbstractContactEditorWidget *editorWidget, QWidget *parent )
00108   : KDialog( parent ), d( new Private( mode, editorWidget, this ) )
00109 {
00110 }
00111 
00112 ContactEditorDialog::~ContactEditorDialog()
00113 {
00114   delete d;
00115 }
00116 
00117 void ContactEditorDialog::setContact( const Akonadi::Item &contact )
00118 {
00119   d->mEditor->loadContact( contact );
00120 }
00121 
00122 void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
00123 {
00124   if ( d->mMode == EditMode )
00125     return;
00126 
00127   d->mAddressBookBox->setDefaultCollection( addressbook );
00128 }
00129 
00130 ContactEditor* ContactEditorDialog::editor() const
00131 {
00132   return d->mEditor;
00133 }
00134 
00135 #include "contacteditordialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:01:43 by doxygen 1.7.5 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