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

akonadi

  • 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 <kpushbutton.h>
32 #include <klineedit.h>
33 
34 #include <QGridLayout>
35 #include <QLabel>
36 
37 using namespace Akonadi;
38 
39 class ContactGroupEditorDialog::Private
40 {
41  public:
42  Private( ContactGroupEditorDialog *qq, ContactGroupEditorDialog::Mode mode )
43  : q( qq ), mAddressBookBox( 0 ), mEditor( 0 ), mMode( mode )
44  {
45  }
46 
47  void slotGroupNameChanged( const QString& name )
48  {
49  bool isValid = !( name.contains( QLatin1Char( '@' ) ) || name.contains( QLatin1Char( '.' ) ) );
50  q->button( Ok )->setEnabled( !name.isEmpty() && isValid );
51  mEditor->groupNameIsValid( isValid );
52  }
53 
54  ContactGroupEditorDialog *q;
55  CollectionComboBox *mAddressBookBox;
56  ContactGroupEditor *mEditor;
57  ContactGroupEditorDialog::Mode mMode;
58 };
59 
60 ContactGroupEditorDialog::ContactGroupEditorDialog( Mode mode, QWidget *parent )
61  : KDialog( parent ), d( new Private( this, mode ) )
62 {
63  KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
64  setCaption( mode == CreateMode ? i18n( "New Contact Group" ) : i18n( "Edit Contact Group" ) );
65  setButtons( Ok | Cancel );
66 
67  // Disable default button, so that finish editing of
68  // a member with the Enter key does not close the dialog
69  button( Ok )->setAutoDefault( false );
70  button( Cancel )->setAutoDefault( false );
71 
72  QWidget *mainWidget = new QWidget( this );
73  setMainWidget( mainWidget );
74 
75  QGridLayout *layout = new QGridLayout( mainWidget );
76 
77  d->mEditor = new Akonadi::ContactGroupEditor( mode == CreateMode ?
78  Akonadi::ContactGroupEditor::CreateMode : Akonadi::ContactGroupEditor::EditMode,
79  this );
80 
81  if ( mode == CreateMode ) {
82  QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
83 
84  d->mAddressBookBox = new CollectionComboBox( mainWidget );
85  d->mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::ContactGroup::mimeType() );
86  d->mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
87 
88  layout->addWidget( label, 0, 0 );
89  layout->addWidget( d->mAddressBookBox, 0, 1 );
90  }
91 
92  layout->addWidget( d->mEditor, 1, 0, 1, 2 );
93  layout->setColumnStretch( 1, 1 );
94 
95  connect( d->mEditor, SIGNAL(contactGroupStored(Akonadi::Item)),
96  this, SIGNAL(contactGroupStored(Akonadi::Item)) );
97  connect( d->mEditor->d->mGui.groupName, SIGNAL(textChanged(QString)),
98  this, SLOT(slotGroupNameChanged(QString)) );
99 
100  button( Ok )->setEnabled( !d->mEditor->d->mGui.groupName->text().isEmpty() );
101 
102  setInitialSize( QSize( 470, 400 ) );
103 }
104 
105 ContactGroupEditorDialog::~ContactGroupEditorDialog()
106 {
107  delete d;
108 }
109 
110 void ContactGroupEditorDialog::setContactGroup( const Akonadi::Item &group )
111 {
112  d->mEditor->loadContactGroup( group );
113 }
114 
115 void ContactGroupEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
116 {
117  if ( d->mMode == EditMode ) {
118  return;
119  }
120 
121  d->mAddressBookBox->setDefaultCollection( addressbook );
122 }
123 
124 ContactGroupEditor* ContactGroupEditorDialog::editor() const
125 {
126  return d->mEditor;
127 }
128 
129 void ContactGroupEditorDialog::slotButtonClicked( int button )
130 {
131  if ( button == KDialog::Ok ) {
132  if ( d->mAddressBookBox ) {
133  d->mEditor->setDefaultAddressBook( d->mAddressBookBox->currentCollection() );
134  }
135 
136  if ( d->mEditor->saveContactGroup() ) {
137  accept();
138  }
139  } else if ( button == KDialog::Cancel ) {
140  reject();
141  }
142 }
143 
144 #include "moc_contactgroupeditordialog.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