• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.11.3 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 #include <klocalizedstring.h>
33 #include <kglobal.h>
34 
35 #include <QGridLayout>
36 #include <QLabel>
37 
38 using namespace Akonadi;
39 
40 class ContactEditorDialog::Private
41 {
42  public:
43  Private( ContactEditorDialog::Mode mode, ContactEditorDialog::DisplayMode displaymode, AbstractContactEditorWidget *editorWidget,
44  ContactEditorDialog *parent )
45  : q( parent ), mAddressBookBox( 0 ), mMode( mode )
46  {
47  KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
48  q->setCaption( mode == ContactEditorDialog::CreateMode ? i18n( "New Contact" ) : i18n( "Edit Contact" ) );
49  q->setButtons( ContactEditorDialog::Ok | ContactEditorDialog::Cancel );
50 
51  QWidget *mainWidget = new QWidget( q );
52  q->setMainWidget( mainWidget );
53 
54  QGridLayout *layout = new QGridLayout( mainWidget );
55 
56  if ( editorWidget ) {
57  mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, editorWidget, q );
58  } else {
59  mEditor = new ContactEditor( mode == ContactEditorDialog::CreateMode ? ContactEditor::CreateMode : ContactEditor::EditMode, displaymode == ContactEditorDialog::FullMode ? ContactEditor::FullMode : ContactEditor::VCardMode, q );
60  }
61 
62  if ( mode == ContactEditorDialog::CreateMode ) {
63  QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
64 
65  mAddressBookBox = new CollectionComboBox( mainWidget );
66  mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
67  mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
68 
69  layout->addWidget( label, 0, 0 );
70  layout->addWidget( mAddressBookBox, 0, 1 );
71  }
72 
73  layout->addWidget( mEditor, 1, 0, 1, 2 );
74  layout->setColumnStretch( 1, 1 );
75 
76  connect( mEditor, SIGNAL(contactStored(Akonadi::Item)),
77  q, SIGNAL(contactStored(Akonadi::Item)) );
78 
79  connect( mEditor, SIGNAL(error(QString)),
80  q, SIGNAL(error(QString)) );
81 
82  connect( q, SIGNAL(okClicked()), q, SLOT(slotOkClicked()) );
83  connect( q, SIGNAL(cancelClicked()), q, SLOT(slotCancelClicked()) );
84  connect( mEditor, SIGNAL(finished()), q, SLOT(slotFinish()) );
85 
86  readConfig();
87  }
88 
89  void slotOkClicked()
90  {
91  if ( mAddressBookBox ) {
92  mEditor->setDefaultAddressBook( mAddressBookBox->currentCollection() );
93  }
94  mEditor->saveContactInAddressBook();
95  }
96 
97  void slotFinish()
98  {
99  q->KDialog::accept();
100  }
101 
102  void slotCancelClicked()
103  {
104  q->reject();
105  }
106 
107  void readConfig()
108  {
109  KConfig config( QLatin1String( "akonadi_contactrc" ) );
110  KConfigGroup group( &config, QLatin1String( "ContactEditor" ) );
111  const QSize size = group.readEntry( "Size", QSize() );
112  if ( size.isValid() ) {
113  q->resize( size );
114  } else {
115  q->resize( 800, 500 );
116  }
117  }
118 
119  void writeConfig()
120  {
121  KConfig config( QLatin1String( "akonadi_contactrc" ) );
122  KConfigGroup group( &config, QLatin1String( "ContactEditor" ) );
123  group.writeEntry( "Size", q->size() );
124  group.sync();
125  }
126 
127  ContactEditorDialog *q;
128  CollectionComboBox *mAddressBookBox;
129  ContactEditorDialog::Mode mMode;
130  ContactEditor *mEditor;
131 };
132 
133 ContactEditorDialog::ContactEditorDialog( Mode mode, QWidget *parent )
134  : KDialog( parent ), d( new Private( mode, FullMode, 0, this ) )
135 {
136 }
137 
138 ContactEditorDialog::ContactEditorDialog( Mode mode, AbstractContactEditorWidget *editorWidget, QWidget *parent )
139  : KDialog( parent ), d( new Private( mode, FullMode, editorWidget, this ) )
140 {
141 }
142 
143 ContactEditorDialog::ContactEditorDialog( Mode mode, DisplayMode displayMode, QWidget *parent )
144  : KDialog( parent ), d( new Private( mode, displayMode, 0, this ) )
145 {
146 }
147 
148 ContactEditorDialog::~ContactEditorDialog()
149 {
150  d->writeConfig();
151  delete d;
152 }
153 
154 void ContactEditorDialog::setContact( const Akonadi::Item &contact )
155 {
156  d->mEditor->loadContact( contact );
157 }
158 
159 void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
160 {
161  if ( d->mMode == EditMode ) {
162  return;
163  }
164 
165  d->mAddressBookBox->setDefaultCollection( addressbook );
166 }
167 
168 ContactEditor* ContactEditorDialog::editor() const
169 {
170  return d->mEditor;
171 }
172 
173 
174 void ContactEditorDialog::accept()
175 {
176  //Nothing
177 }
178 
179 #include "moc_contacteditordialog.cpp"
Akonadi::ContactEditorDialog::~ContactEditorDialog
~ContactEditorDialog()
Destroys the contact editor dialog.
Definition: contacteditordialog.cpp:148
Akonadi::ContactEditorDialog
A dialog for creating or editing a contact in Akonadi.
Definition: contacteditordialog.h:77
Akonadi::ContactEditor::EditMode
Edits an existing contact.
Definition: contacteditor.h:90
Akonadi::ContactEditorDialog::ContactEditorDialog
ContactEditorDialog(Mode mode, QWidget *parent=0)
Creates a new contact editor dialog with the standard editor widget.
Definition: contacteditordialog.cpp:133
Akonadi::ContactEditor::CreateMode
Creates a new contact.
Definition: contacteditor.h:89
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::ContactEditorDialog::EditMode
Edits an existing contact.
Definition: contacteditordialog.h:87
Akonadi::ContactEditorDialog::contactStored
void contactStored(const Akonadi::Item &contact)
This signal is emitted whenever a contact was updated or stored.
Akonadi::ContactEditor::FullMode
Show all pages.
Definition: contacteditor.h:94
Akonadi::CollectionComboBox
A combobox for selecting an Akonadi collection.
Definition: collectioncombobox.h:62
Akonadi::ContactEditorDialog::Mode
Mode
Describes the mode of the editor dialog.
Definition: contacteditordialog.h:85
Akonadi::ContactEditorDialog::setContact
void setContact(const Akonadi::Item &contact)
Sets the contact to edit when in EditMode.
Definition: contacteditordialog.cpp:154
Akonadi::ContactEditor
An widget to edit contacts in Akonadi.
Definition: contacteditor.h:80
Akonadi::ContactEditorDialog::error
void error(const QString &errMsg)
This signal is emitted whenever a contact is not updated or stored.
Akonadi::Collection::CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::ContactEditorDialog::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressbook)
Sets the addressbook that shall be selected as default in create mode.
Definition: contacteditordialog.cpp:159
Akonadi::ContactEditor::VCardMode
Show just pages with elements stored in vcard.
Definition: contacteditor.h:95
Akonadi::ContactEditorDialog::CreateMode
Creates a new contact.
Definition: contacteditordialog.h:86
Akonadi::ContactEditorDialog::editor
ContactEditor * editor() const
Returns the ContactEditor that is used by this dialog.
Definition: contacteditordialog.cpp:168
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:16 by doxygen 1.8.5 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.11.3 API Reference

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