• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

akonadi/contact

contactgroupeditordialog.cpp
00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2007-2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "contactgroupeditordialog.h"
00023 
00024 #include "contactgroupeditor.h"
00025 #include "contactgroupeditor_p.h"
00026 
00027 #include <akonadi/collectioncombobox.h>
00028 #include <akonadi/item.h>
00029 #include <kabc/contactgroup.h>
00030 #include <klocale.h>
00031 #include <kpushbutton.h>
00032 #include <klineedit.h>
00033 
00034 #include <QtGui/QGridLayout>
00035 #include <QtGui/QLabel>
00036 
00037 using namespace Akonadi;
00038 
00039 class ContactGroupEditorDialog::Private
00040 {
00041   public:
00042     Private( ContactGroupEditorDialog *qq, ContactGroupEditorDialog::Mode mode )
00043       : q( qq ), mAddressBookBox( 0 ), mMode( mode )
00044     {
00045     }
00046 
00047     void slotGroupNameChanged( const QString& name )
00048     {
00049       q->button( Ok )->setEnabled( !name.isEmpty() );
00050     }
00051 
00052     ContactGroupEditorDialog *q;
00053     CollectionComboBox *mAddressBookBox;
00054     ContactGroupEditor *mEditor;
00055     ContactGroupEditorDialog::Mode mMode;
00056 };
00057 
00058 ContactGroupEditorDialog::ContactGroupEditorDialog( Mode mode, QWidget *parent )
00059   : KDialog( parent ), d( new Private( this, mode ) )
00060 {
00061   KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) );
00062   setCaption( mode == CreateMode ? i18n( "New Contact Group" ) : i18n( "Edit Contact Group" ) );
00063   setButtons( Ok | Cancel );
00064 
00065   // Disable default button, so that finish editing of
00066   // a member with the Enter key does not close the dialog
00067   button( Ok )->setAutoDefault( false );
00068   button( Cancel )->setAutoDefault( false );
00069 
00070   QWidget *mainWidget = new QWidget( this );
00071   setMainWidget( mainWidget );
00072 
00073   QGridLayout *layout = new QGridLayout( mainWidget );
00074 
00075   d->mEditor = new Akonadi::ContactGroupEditor( mode == CreateMode ?
00076                                                 Akonadi::ContactGroupEditor::CreateMode : Akonadi::ContactGroupEditor::EditMode,
00077                                                 this );
00078 
00079   if ( mode == CreateMode ) {
00080     QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget );
00081 
00082     d->mAddressBookBox = new CollectionComboBox( mainWidget );
00083     d->mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::ContactGroup::mimeType() );
00084     d->mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem );
00085 
00086     layout->addWidget( label, 0, 0 );
00087     layout->addWidget( d->mAddressBookBox, 0, 1 );
00088   }
00089 
00090   layout->addWidget( d->mEditor, 1, 0, 1, 2 );
00091   layout->setColumnStretch( 1, 1 );
00092 
00093   connect( d->mEditor, SIGNAL(contactGroupStored(Akonadi::Item)),
00094            this, SIGNAL(contactGroupStored(Akonadi::Item)) );
00095   connect( d->mEditor->d->mGui.groupName, SIGNAL(textChanged(QString)),
00096            this, SLOT(slotGroupNameChanged(QString)) );
00097 
00098   button( Ok )->setEnabled( !d->mEditor->d->mGui.groupName->text().isEmpty() );
00099 
00100   setInitialSize( QSize( 470, 400 ) );
00101 }
00102 
00103 ContactGroupEditorDialog::~ContactGroupEditorDialog()
00104 {
00105   delete d;
00106 }
00107 
00108 void ContactGroupEditorDialog::setContactGroup( const Akonadi::Item &group )
00109 {
00110   d->mEditor->loadContactGroup( group );
00111 }
00112 
00113 void ContactGroupEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook )
00114 {
00115   if ( d->mMode == EditMode )
00116     return;
00117 
00118   d->mAddressBookBox->setDefaultCollection( addressbook );
00119 }
00120 
00121 ContactGroupEditor* ContactGroupEditorDialog::editor() const
00122 {
00123   return d->mEditor;
00124 }
00125 
00126 void ContactGroupEditorDialog::slotButtonClicked( int button )
00127 {
00128   if ( button == KDialog::Ok ) {
00129     if ( d->mAddressBookBox )
00130       d->mEditor->setDefaultAddressBook( d->mAddressBookBox->currentCollection() );
00131 
00132     if ( d->mEditor->saveContactGroup() )
00133       accept();
00134   } else if ( button == KDialog::Cancel ) {
00135     reject();
00136   }
00137 }
00138 
00139 #include "contactgroupeditordialog.moc"

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal