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 bool isValid = !(name.contains(QLatin1Char('@')) || name.contains(QLatin1Char('.'))); 00050 q->button( Ok )->setEnabled( !name.isEmpty() && isValid ); 00051 mEditor->groupNameIsValid(isValid); 00052 } 00053 00054 ContactGroupEditorDialog *q; 00055 CollectionComboBox *mAddressBookBox; 00056 ContactGroupEditor *mEditor; 00057 ContactGroupEditorDialog::Mode mMode; 00058 }; 00059 00060 ContactGroupEditorDialog::ContactGroupEditorDialog( Mode mode, QWidget *parent ) 00061 : KDialog( parent ), d( new Private( this, mode ) ) 00062 { 00063 KGlobal::locale()->insertCatalog( QLatin1String( "akonadicontact" ) ); 00064 setCaption( mode == CreateMode ? i18n( "New Contact Group" ) : i18n( "Edit Contact Group" ) ); 00065 setButtons( Ok | Cancel ); 00066 00067 // Disable default button, so that finish editing of 00068 // a member with the Enter key does not close the dialog 00069 button( Ok )->setAutoDefault( false ); 00070 button( Cancel )->setAutoDefault( false ); 00071 00072 QWidget *mainWidget = new QWidget( this ); 00073 setMainWidget( mainWidget ); 00074 00075 QGridLayout *layout = new QGridLayout( mainWidget ); 00076 00077 d->mEditor = new Akonadi::ContactGroupEditor( mode == CreateMode ? 00078 Akonadi::ContactGroupEditor::CreateMode : Akonadi::ContactGroupEditor::EditMode, 00079 this ); 00080 00081 if ( mode == CreateMode ) { 00082 QLabel *label = new QLabel( i18n( "Add to:" ), mainWidget ); 00083 00084 d->mAddressBookBox = new CollectionComboBox( mainWidget ); 00085 d->mAddressBookBox->setMimeTypeFilter( QStringList() << KABC::ContactGroup::mimeType() ); 00086 d->mAddressBookBox->setAccessRightsFilter( Collection::CanCreateItem ); 00087 00088 layout->addWidget( label, 0, 0 ); 00089 layout->addWidget( d->mAddressBookBox, 0, 1 ); 00090 } 00091 00092 layout->addWidget( d->mEditor, 1, 0, 1, 2 ); 00093 layout->setColumnStretch( 1, 1 ); 00094 00095 connect( d->mEditor, SIGNAL(contactGroupStored(Akonadi::Item)), 00096 this, SIGNAL(contactGroupStored(Akonadi::Item)) ); 00097 connect( d->mEditor->d->mGui.groupName, SIGNAL(textChanged(QString)), 00098 this, SLOT(slotGroupNameChanged(QString)) ); 00099 00100 button( Ok )->setEnabled( !d->mEditor->d->mGui.groupName->text().isEmpty() ); 00101 00102 setInitialSize( QSize( 470, 400 ) ); 00103 } 00104 00105 ContactGroupEditorDialog::~ContactGroupEditorDialog() 00106 { 00107 delete d; 00108 } 00109 00110 void ContactGroupEditorDialog::setContactGroup( const Akonadi::Item &group ) 00111 { 00112 d->mEditor->loadContactGroup( group ); 00113 } 00114 00115 void ContactGroupEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addressbook ) 00116 { 00117 if ( d->mMode == EditMode ) 00118 return; 00119 00120 d->mAddressBookBox->setDefaultCollection( addressbook ); 00121 } 00122 00123 ContactGroupEditor* ContactGroupEditorDialog::editor() const 00124 { 00125 return d->mEditor; 00126 } 00127 00128 void ContactGroupEditorDialog::slotButtonClicked( int button ) 00129 { 00130 if ( button == KDialog::Ok ) { 00131 if ( d->mAddressBookBox ) 00132 d->mEditor->setDefaultAddressBook( d->mAddressBookBox->currentCollection() ); 00133 00134 if ( d->mEditor->saveContactGroup() ) 00135 accept(); 00136 } else if ( button == KDialog::Cancel ) { 00137 reject(); 00138 } 00139 } 00140 00141 #include "contactgroupeditordialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:43 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:43 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.