• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
38using namespace Akonadi;
39
40class 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(800, 500) );
112 if ( size.isValid() ) {
113 q->resize( size );
114 }
115 }
116
117 void writeConfig()
118 {
119 KConfig config( QLatin1String( "akonadi_contactrc" ) );
120 KConfigGroup group( &config, QLatin1String( "ContactEditor" ) );
121 group.writeEntry( "Size", q->size() );
122 group.sync();
123 }
124
125 ContactEditorDialog *q;
126 CollectionComboBox *mAddressBookBox;
127 ContactEditorDialog::Mode mMode;
128 ContactEditor *mEditor;
129};
130
131ContactEditorDialog::ContactEditorDialog( Mode mode, QWidget *parent )
132 : KDialog( parent ), d( new Private( mode, FullMode, 0, this ) )
133{
134}
135
136ContactEditorDialog::ContactEditorDialog( Mode mode, AbstractContactEditorWidget *editorWidget, QWidget *parent )
137 : KDialog( parent ), d( new Private( mode, FullMode, editorWidget, this ) )
138{
139}
140
141ContactEditorDialog::ContactEditorDialog( Mode mode, DisplayMode displayMode, QWidget *parent )
142 : KDialog( parent ), d( new Private( mode, displayMode, 0, this ) )
143{
144}
145
146ContactEditorDialog::~ContactEditorDialog()
147{
148 d->writeConfig();
149 delete d;
150}
151
152void ContactEditorDialog::setContact( const Akonadi::Item &contact )
153{
154 d->mEditor->loadContact( contact );
155}
156
157void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
158{
159 if ( d->mMode == EditMode ) {
160 return;
161 }
162
163 d->mAddressBookBox->setDefaultCollection( addressbook );
164}
165
166ContactEditor* ContactEditorDialog::editor() const
167{
168 return d->mEditor;
169}
170
171void ContactEditorDialog::accept()
172{
173 //Nothing
174}
175
176#include "moc_contacteditordialog.cpp"
Akonadi::CollectionComboBox
A combobox for selecting an Akonadi collection.
Definition: collectioncombobox.h:63
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::CanCreateItem
@ CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::ContactEditorDialog
A dialog for creating or editing a contact in Akonadi.
Definition: contacteditordialog.h:78
Akonadi::ContactEditorDialog::Mode
Mode
Describes the mode of the editor dialog.
Definition: contacteditordialog.h:85
Akonadi::ContactEditorDialog::EditMode
@ EditMode
Edits an existing contact.
Definition: contacteditordialog.h:87
Akonadi::ContactEditorDialog::CreateMode
@ CreateMode
Creates a new contact.
Definition: contacteditordialog.h:86
Akonadi::ContactEditorDialog::setContact
void setContact(const Akonadi::Item &contact)
Sets the contact to edit when in EditMode.
Definition: contacteditordialog.cpp:152
Akonadi::ContactEditorDialog::ContactEditorDialog
ContactEditorDialog(Mode mode, QWidget *parent=0)
Creates a new contact editor dialog with the standard editor widget.
Definition: contacteditordialog.cpp:131
Akonadi::ContactEditorDialog::editor
ContactEditor * editor() const
Returns the ContactEditor that is used by this dialog.
Definition: contacteditordialog.cpp:166
Akonadi::ContactEditorDialog::error
void error(const QString &errMsg)
This signal is emitted whenever a contact is not updated or stored.
Akonadi::ContactEditorDialog::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressbook)
Sets the addressbook that shall be selected as default in create mode.
Definition: contacteditordialog.cpp:157
Akonadi::ContactEditorDialog::contactStored
void contactStored(const Akonadi::Item &contact)
This signal is emitted whenever a contact was updated or stored.
Akonadi::ContactEditorDialog::~ContactEditorDialog
~ContactEditorDialog()
Destroys the contact editor dialog.
Definition: contacteditordialog.cpp:146
Akonadi::ContactEditor
An widget to edit contacts in Akonadi.
Definition: contacteditor.h:81
Akonadi::ContactEditor::FullMode
@ FullMode
Show all pages.
Definition: contacteditor.h:94
Akonadi::ContactEditor::VCardMode
@ VCardMode
Show just pages with elements stored in vcard.
Definition: contacteditor.h:95
Akonadi::ContactEditor::CreateMode
@ CreateMode
Creates a new contact.
Definition: contacteditor.h:89
Akonadi::ContactEditor::EditMode
@ EditMode
Edits an existing contact.
Definition: contacteditor.h:90
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.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.14.10 API Reference

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