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

akonadi/contact

  • akonadi
  • contact
contactgroupeditordialog.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 "contactgroupeditordialog.h"
23
24#include "contactgroupeditor.h"
25#include "contactgroupeditor_p.h"
26
27#include <akonadi/collectioncombobox.h>
28#include <akonadi/item.h>
29#include <kabc/contactgroup.h>
30#include <klocale.h>
31#include <klocalizedstring.h>
32#include <kglobal.h>
33#include <kpushbutton.h>
34#include <klineedit.h>
35
36#include <QGridLayout>
37#include <QLabel>
38
39using namespace Akonadi;
40
41class ContactGroupEditorDialog::Private
42{
43 public:
44 Private( ContactGroupEditorDialog *qq, ContactGroupEditorDialog::Mode mode )
45 : q( qq ), mAddressBookBox( 0 ), mEditor( 0 ), mMode( mode )
46 {
47 }
48
49 void slotGroupNameChanged( const QString& name )
50 {
51 bool isValid = !( name.contains( QLatin1Char( '@' ) ) || name.contains( QLatin1Char( '.' ) ) );
52 q->button( Ok )->setEnabled( !name.trimmed().isEmpty() && isValid );
53 mEditor->groupNameIsValid( isValid );
54 }
55
56 void readConfig()
57 {
58 KConfig config( QLatin1String( "akonadi_contactrc" ) );
59 KConfigGroup group( &config, QLatin1String( "ContactGroupEditorDialog" ) );
60 const QSize size = group.readEntry( "Size", QSize(470, 400) );
61 if ( size.isValid() ) {
62 q->resize( size );
63 }
64 }
65 void writeConfig()
66 {
67 KConfig config( QLatin1String( "akonadi_contactrc" ) );
68 KConfigGroup group( &config, QLatin1String( "ContactGroupEditorDialog" ) );
69 group.writeEntry( "Size", q->size() );
70 group.sync();
71 }
72 ContactGroupEditorDialog *q;
73 CollectionComboBox *mAddressBookBox;
74 ContactGroupEditor *mEditor;
75 ContactGroupEditorDialog::Mode mMode;
76};
77
78ContactGroupEditorDialog::ContactGroupEditorDialog( Mode mode, QWidget *parent )
79 : KDialog( parent ), d( new Private( this, mode ) )
80{
81 KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
82 setCaption( mode == CreateMode ? i18n( "New Contact Group" ) : i18n( "Edit Contact Group" ) );
83 setButtons( Ok | Cancel );
84
85 // Disable default button, so that finish editing of
86 // a member with the Enter key does not close the dialog
87 button( Ok )->setAutoDefault( false );
88 button( Cancel )->setAutoDefault( false );
89
90 QWidget *mainWidget = new QWidget( this );
91 setMainWidget( mainWidget );
92
93 QGridLayout *layout = new QGridLayout( mainWidget );
94
95 d->mEditor = new Akonadi::ContactGroupEditor( mode == CreateMode ?
96 Akonadi::ContactGroupEditor::CreateMode : Akonadi::ContactGroupEditor::EditMode,
97 this );
98
99 if ( mode == CreateMode ) {
100 QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
101
102 d->mAddressBookBox = new CollectionComboBox( mainWidget );
103 d->mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::ContactGroup::mimeType() );
104 d->mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
105
106 layout->addWidget( label, 0, 0 );
107 layout->addWidget( d->mAddressBookBox, 0, 1 );
108 }
109
110 layout->addWidget( d->mEditor, 1, 0, 1, 2 );
111 layout->setColumnStretch( 1, 1 );
112
113 connect( d->mEditor, SIGNAL(contactGroupStored(Akonadi::Item)),
114 this, SIGNAL(contactGroupStored(Akonadi::Item)) );
115 connect( d->mEditor->d->mGui.groupName, SIGNAL(textChanged(QString)),
116 this, SLOT(slotGroupNameChanged(QString)) );
117
118 button( Ok )->setEnabled( !d->mEditor->d->mGui.groupName->text().trimmed().isEmpty() );
119
120 d->readConfig();
121}
122
123ContactGroupEditorDialog::~ContactGroupEditorDialog()
124{
125 d->writeConfig();
126 delete d;
127}
128
129void ContactGroupEditorDialog::setContactGroup( const Akonadi::Item &group )
130{
131 d->mEditor->loadContactGroup( group );
132}
133
134void ContactGroupEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
135{
136 if ( d->mMode == EditMode ) {
137 return;
138 }
139
140 d->mAddressBookBox->setDefaultCollection( addressbook );
141}
142
143ContactGroupEditor* ContactGroupEditorDialog::editor() const
144{
145 return d->mEditor;
146}
147
148void ContactGroupEditorDialog::slotButtonClicked( int button )
149{
150 if ( button == KDialog::Ok ) {
151 if ( d->mAddressBookBox ) {
152 d->mEditor->setDefaultAddressBook( d->mAddressBookBox->currentCollection() );
153 }
154
155 if ( d->mEditor->saveContactGroup() ) {
156 accept();
157 }
158 } else if ( button == KDialog::Cancel ) {
159 reject();
160 }
161}
162
163#include "moc_contactgroupeditordialog.cpp"
Akonadi::ContactGroupEditorDialog
A dialog for creating or editing a contact group in Akonadi.
Definition: contactgroupeditordialog.h:76
Akonadi::ContactGroupEditorDialog::contactGroupStored
void contactGroupStored(const Akonadi::Item &group)
This signal is emitted whenever a contact group was updated or stored.
Akonadi::ContactGroupEditorDialog::~ContactGroupEditorDialog
~ContactGroupEditorDialog()
Destroys the contact group editor dialog.
Definition: contactgroupeditordialog.cpp:123
Akonadi::ContactGroupEditorDialog::setContactGroup
void setContactGroup(const Akonadi::Item &group)
Sets the contact group to edit when in EditMode.
Definition: contactgroupeditordialog.cpp:129
Akonadi::ContactGroupEditorDialog::editor
ContactGroupEditor * editor() const
Returns the ContactGroupEditor that is used by the dialog.
Definition: contactgroupeditordialog.cpp:143
Akonadi::ContactGroupEditorDialog::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressbook)
Sets the addressbook that shall be selected as default for storage in create mode.
Definition: contactgroupeditordialog.cpp:134
Akonadi::ContactGroupEditorDialog::Mode
Mode
Describes the mode of the contact group editor.
Definition: contactgroupeditordialog.h:83
Akonadi::ContactGroupEditorDialog::CreateMode
@ CreateMode
Creates a new contact group.
Definition: contactgroupeditordialog.h:84
Akonadi::ContactGroupEditorDialog::EditMode
@ EditMode
Edits an existing contact group.
Definition: contactgroupeditordialog.h:85
Akonadi::ContactGroupEditorDialog::ContactGroupEditorDialog
ContactGroupEditorDialog(Mode mode, QWidget *parent=0)
Creates a new contact group editor dialog.
Definition: contactgroupeditordialog.cpp:78
Akonadi::ContactGroupEditor
An widget to edit contact groups in Akonadi.
Definition: contactgroupeditor.h:83
Akonadi::ContactGroupEditor::CreateMode
@ CreateMode
Creates a new contact group.
Definition: contactgroupeditor.h:91
Akonadi::ContactGroupEditor::EditMode
@ EditMode
Edits an existing contact group.
Definition: contactgroupeditor.h:92
Akonadi::ContactGroupEditor::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressbook)
Sets the addressbook which shall be used to store new contact groups.
Definition: contactgroupeditor.cpp:313
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/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • 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