• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.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 <QGridLayout>
34 #include <QLabel>
35 
36 using namespace Akonadi;
37 
38 class ContactEditorDialog::Private
39 {
40  public:
41  Private( ContactEditorDialog::Mode mode, ContactEditorDialog::DisplayMode displaymode, 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, displaymode == ContactEditorDialog::FullMode ? ContactEditor::FullMode : ContactEditor::VCardMode, q );
58  }
59 
60  if ( mode == ContactEditorDialog::CreateMode ) {
61  QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
62 
63  mAddressBookBox = new CollectionComboBox( mainWidget );
64  mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
65  mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
66 
67  layout->addWidget( label, 0, 0 );
68  layout->addWidget( mAddressBookBox, 0, 1 );
69  }
70 
71  layout->addWidget( mEditor, 1, 0, 1, 2 );
72  layout->setColumnStretch( 1, 1 );
73 
74  connect( mEditor, SIGNAL(contactStored(Akonadi::Item)),
75  q, SIGNAL(contactStored(Akonadi::Item)) );
76 
77  connect( q, SIGNAL(okClicked()), q, SLOT(slotOkClicked()) );
78  connect( q, SIGNAL(cancelClicked()), q, SLOT(slotCancelClicked()) );
79 
80  q->setInitialSize( QSize( 800, 500 ) );
81  }
82 
83  void slotOkClicked()
84  {
85  if ( mAddressBookBox ) {
86  mEditor->setDefaultAddressBook( mAddressBookBox->currentCollection() );
87  }
88 
89  if ( mEditor->saveContact() ) {
90  q->accept();
91  }
92  }
93 
94  void slotCancelClicked()
95  {
96  q->reject();
97  }
98 
99  ContactEditorDialog *q;
100  CollectionComboBox *mAddressBookBox;
101  ContactEditorDialog::Mode mMode;
102  ContactEditor *mEditor;
103 };
104 
105 ContactEditorDialog::ContactEditorDialog( Mode mode, QWidget *parent )
106  : KDialog( parent ), d( new Private( mode, FullMode, 0, this ) )
107 {
108 }
109 
110 ContactEditorDialog::ContactEditorDialog( Mode mode, AbstractContactEditorWidget *editorWidget, QWidget *parent )
111  : KDialog( parent ), d( new Private( mode, FullMode, editorWidget, this ) )
112 {
113 }
114 
115 ContactEditorDialog::ContactEditorDialog( Mode mode, DisplayMode displayMode, QWidget *parent )
116  : KDialog( parent ), d( new Private( mode, displayMode, 0, this ) )
117 {
118 }
119 
120 ContactEditorDialog::~ContactEditorDialog()
121 {
122  delete d;
123 }
124 
125 void ContactEditorDialog::setContact( const Akonadi::Item &contact )
126 {
127  d->mEditor->loadContact( contact );
128 }
129 
130 void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
131 {
132  if ( d->mMode == EditMode ) {
133  return;
134  }
135 
136  d->mAddressBookBox->setDefaultCollection( addressbook );
137 }
138 
139 ContactEditor* ContactEditorDialog::editor() const
140 {
141  return d->mEditor;
142 }
143 
144 #include "moc_contacteditordialog.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:34 by doxygen 1.8.3.1 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.10.5 API Reference

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