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

akonadi

  • akonadi
  • contact
contacteditordialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2007-2009 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "contacteditordialog.h"
23 
24 #include "contacteditor.h"
25 
26 #include <akonadi/collectioncombobox.h>
27 #include <akonadi/item.h>
28 
29 #include <kabc/addressee.h>
30 
31 #include <klocale.h>
32 
33 #include <QtGui/QGridLayout>
34 #include <QtGui/QLabel>
35 
36 using namespace Akonadi;
37 
38 class ContactEditorDialog::Private
39 {
40  public:
41  Private( ContactEditorDialog::Mode mode, AbstractContactEditorWidget *editorWidget,
42  ContactEditorDialog *parent )
43  : q( parent ), mAddressBookBox( 0 ), mMode( mode )
44  {
45  KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
46  q->setCaption( mode == ContactEditorDialog::CreateMode ? i18n( "New Contact" ) : i18n( "Edit Contact" ) );
47  q->setButtons( ContactEditorDialog::Ok | ContactEditorDialog::Cancel );
48 
49  QWidget *mainWidget = new QWidget( q );
50  q->setMainWidget( mainWidget );
51 
52  QGridLayout *layout = new QGridLayout( mainWidget );
53 
54  if ( editorWidget )
55  mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, editorWidget, q );
56  else
57  mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, q );
58 
59  if ( mode == ContactEditorDialog::CreateMode ) {
60  QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
61 
62  mAddressBookBox = new CollectionComboBox( mainWidget );
63  mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
64  mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
65 
66  layout->addWidget( label, 0, 0 );
67  layout->addWidget( mAddressBookBox, 0, 1 );
68  }
69 
70  layout->addWidget( mEditor, 1, 0, 1, 2 );
71  layout->setColumnStretch( 1, 1 );
72 
73  connect( mEditor, SIGNAL(contactStored(Akonadi::Item)),
74  q, SIGNAL(contactStored(Akonadi::Item)) );
75 
76  connect( q, SIGNAL(okClicked()), q, SLOT(slotOkClicked()) );
77  connect( q, SIGNAL(cancelClicked()), q, SLOT(slotCancelClicked()) );
78 
79  q->setInitialSize( QSize( 800, 500 ) );
80  }
81 
82  void slotOkClicked()
83  {
84  if ( mAddressBookBox )
85  mEditor->setDefaultAddressBook( mAddressBookBox->currentCollection() );
86 
87  if ( mEditor->saveContact() )
88  q->accept();
89  }
90 
91  void slotCancelClicked()
92  {
93  q->reject();
94  }
95 
96  ContactEditorDialog *q;
97  CollectionComboBox *mAddressBookBox;
98  ContactEditorDialog::Mode mMode;
99  ContactEditor *mEditor;
100 };
101 
102 ContactEditorDialog::ContactEditorDialog( Mode mode, QWidget *parent )
103  : KDialog( parent ), d( new Private( mode, 0, this ) )
104 {
105 }
106 
107 ContactEditorDialog::ContactEditorDialog( Mode mode, AbstractContactEditorWidget *editorWidget, QWidget *parent )
108  : KDialog( parent ), d( new Private( mode, editorWidget, this ) )
109 {
110 }
111 
112 ContactEditorDialog::~ContactEditorDialog()
113 {
114  delete d;
115 }
116 
117 void ContactEditorDialog::setContact( const Akonadi::Item &contact )
118 {
119  d->mEditor->loadContact( contact );
120 }
121 
122 void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
123 {
124  if ( d->mMode == EditMode )
125  return;
126 
127  d->mAddressBookBox->setDefaultCollection( addressbook );
128 }
129 
130 ContactEditor* ContactEditorDialog::editor() const
131 {
132  return d->mEditor;
133 }
134 
135 #include "contacteditordialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:46:02 by doxygen 1.8.1.2 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.9.5 API Reference

Skip menu "kdepimlibs-4.9.5 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