Commit d5989086 authored by Tobias Koenig's avatar Tobias Koenig

Rework the API of the Contact(Group)Editor/Dialog

Add support for templates

svn path=/trunk/KDE/kdepimlibs/; revision=1036738
parent a3ecd485
......@@ -241,7 +241,7 @@ bool ContactEditor::saveContact()
if ( !d->mDefaultCollection.isValid() ) {
AutoQPointer<AddressBookSelectionDialog> dlg = new AddressBookSelectionDialog( AddressBookSelectionDialog::ContactsOnly, this );
if ( dlg->exec() == KDialog::Accepted )
setDefaultCollection( dlg->selectedAddressBook() );
setDefaultAddressBook( dlg->selectedAddressBook() );
else
return false;
}
......@@ -262,7 +262,12 @@ bool ContactEditor::saveContact()
return true;
}
void ContactEditor::setDefaultCollection( const Akonadi::Collection &collection )
void ContactEditor::setContactTemplate( const KABC::Addressee &contact )
{
d->loadContact( contact, d->mContactMetaData );
}
void ContactEditor::setDefaultAddressBook( const Akonadi::Collection &collection )
{
d->mDefaultCollection = collection;
}
......
......@@ -26,6 +26,10 @@
#include <QtGui/QWidget>
namespace KABC {
class Addressee;
}
namespace Akonadi {
class AbstractContactEditorWidget;
......@@ -113,6 +117,20 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
*/
virtual ~ContactEditor();
/**
* Sets a @p contact that is used as template in create mode.
*
* The fields of the editor will be prefilled with the content
* of the contact.
*/
void setContactTemplate( const KABC::Addressee &contact );
/**
* Sets the @p addressbook which shall be used to store new
* contacts.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressbook );
public Q_SLOTS:
/**
* Loads the @p contact into the editor.
......@@ -124,12 +142,6 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
*/
bool saveContact();
/**
* Sets the @p collection which shall be used to store new
* contacts.
*/
void setDefaultCollection( const Akonadi::Collection &collection );
Q_SIGNALS:
/**
* This signal is emitted when the @p contact has been saved back
......@@ -153,7 +165,7 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
Q_PRIVATE_SLOT( d, void parentCollectionFetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void storeDone( KJob* ) )
Q_PRIVATE_SLOT( d, void itemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) )
//@endcond PRIVATE
//@endcond
};
}
......
......@@ -80,7 +80,7 @@ class ContactEditorDialog::Private
void slotOkClicked()
{
if ( mAddressBookBox )
mEditor->setDefaultCollection( mAddressBookBox->selectedAddressBook() );
mEditor->setDefaultAddressBook( mAddressBookBox->selectedAddressBook() );
if ( mEditor->saveContact() )
q->accept();
......@@ -125,4 +125,9 @@ void ContactEditorDialog::setDefaultAddressBook( const Akonadi::Collection &addr
d->mAddressBookBox->setDefaultAddressBook( addressbook );
}
ContactEditor* ContactEditorDialog::editor() const
{
return d->mEditor;
}
#include "contacteditordialog.moc"
......@@ -31,6 +31,7 @@ class QAbstractItemModel;
namespace Akonadi {
class AbstractContactEditorWidget;
class ContactEditor;
class Collection;
class Item;
......@@ -44,13 +45,13 @@ class Item;
*
* @code
*
* Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::CreateMode, this );
* using namespace Akonadi;
*
* ContactEditorDialog *dlg = new ContactEditorDialog( ContactEditorDialog::CreateMode, this );
* connect( dlg, SIGNAL( contactStored( const Akonadi::Item& ) ),
* this, SLOT( contactStored( const Akonadi::Item& ) ) );
* dlg->show();
*
* if ( dlg.exec() ) {
* qDebug() << "New contact has been added to the address book";
* } else {
* qDebug() << "User has canceled operation";
* }
*
* @endcode
*
......@@ -58,16 +59,15 @@ class Item;
*
* @code
*
* const Akonadi::Item contact = ...;
* using namespace Akonadi;
*
* Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::EditMode, this );
* dlg.setContact( contact );
* const Item contact = ...;
*
* if ( dlg.exec() ) {
* qDebug() << "Contact has been edited";
* } else {
* qDebug() << "User has canceled operation";
* }
* ContactEditorDialog *dlg = new ContactEditorDialog( ContactEditorDialog::EditMode, this );
* connect( dlg, SIGNAL( contactStored( const Akonadi::Item& ) ),
* this, SLOT( contactStored( const Akonadi::Item& ) ) );
* dlg->setContact( contact );
* dlg->show();
*
* @endcode
*
......@@ -127,6 +127,11 @@ class AKONADI_CONTACT_EXPORT ContactEditorDialog : public KDialog
*/
void setDefaultAddressBook( const Akonadi::Collection &addressbook );
/**
* Returns the ContactEditor that is used by this dialog.
*/
ContactEditor* editor() const;
Q_SIGNALS:
/**
* This signal is emitted whenever a contact was updated or stored.
......@@ -142,7 +147,7 @@ class AKONADI_CONTACT_EXPORT ContactEditorDialog : public KDialog
Q_PRIVATE_SLOT( d, void slotOkClicked() )
Q_PRIVATE_SLOT( d, void slotCancelClicked() )
//@endcond PRIVATE
//@endcond
};
}
......
......@@ -281,7 +281,7 @@ bool ContactGroupEditor::saveContactGroup()
if ( !d->mDefaultCollection.isValid() ) {
AutoQPointer<AddressBookSelectionDialog> dlg = new AddressBookSelectionDialog( AddressBookSelectionDialog::ContactsOnly, this );
if ( dlg->exec() == KDialog::Accepted )
setDefaultCollection( dlg->selectedAddressBook() );
setDefaultAddressBook( dlg->selectedAddressBook() );
else
return false;
}
......@@ -301,7 +301,14 @@ bool ContactGroupEditor::saveContactGroup()
return true;
}
void ContactGroupEditor::setDefaultCollection( const Akonadi::Collection &collection )
void ContactGroupEditor::setContactGroupTemplate( const KABC::ContactGroup &group )
{
d->mGroupModel->loadContactGroup( group );
d->mGui.membersView->header()->setDefaultSectionSize( d->mGui.membersView->header()->width() / 2 );
d->mGui.membersView->header()->resizeSections( QHeaderView::Interactive );
}
void ContactGroupEditor::setDefaultAddressBook( const Akonadi::Collection &collection )
{
d->mDefaultCollection = collection;
}
......
......@@ -26,6 +26,10 @@
#include <QtGui/QWidget>
namespace KABC {
class ContactGroup;
}
namespace Akonadi {
class Collection;
......@@ -102,6 +106,20 @@ class AKONADI_CONTACT_EXPORT ContactGroupEditor : public QWidget
*/
virtual ~ContactGroupEditor();
/**
* Sets a contact @p group that is used as template in create mode.
*
* The fields of the editor will be prefilled with the content
* of the group.
*/
void setContactGroupTemplate( const KABC::ContactGroup &group );
/**
* Sets the @p addressbook which shall be used to store new
* contact groups.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressbook );
public Q_SLOTS:
/**
* Loads the contact @p group into the editor.
......@@ -115,12 +133,6 @@ class AKONADI_CONTACT_EXPORT ContactGroupEditor : public QWidget
*/
bool saveContactGroup();
/**
* Sets the @p collection which shall be used to store new
* contact groups.
*/
void setDefaultCollection( const Akonadi::Collection &collection );
Q_SIGNALS:
/**
* This signal is emitted when the contact @p group has been saved back
......
......@@ -98,11 +98,16 @@ void ContactGroupEditorDialog::setDefaultAddressBook( const Akonadi::Collection
d->mAddressBookBox->setDefaultAddressBook( addressbook );
}
ContactGroupEditor* ContactGroupEditorDialog::editor() const
{
return d->mEditor;
}
void ContactGroupEditorDialog::slotButtonClicked( int button )
{
if ( button == KDialog::Ok ) {
if ( d->mAddressBookBox )
d->mEditor->setDefaultCollection( d->mAddressBookBox->selectedAddressBook() );
d->mEditor->setDefaultAddressBook( d->mAddressBookBox->selectedAddressBook() );
if ( d->mEditor->saveContactGroup() )
accept();
......
......@@ -44,13 +44,12 @@ class ContactGroupEditor;
*
* @code
*
* Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::CreateMode, this );
* using namespace Akonadi;
*
* if ( dlg.exec() ) {
* qDebug() << "New contact group has been added to the address book";
* } else {
* qDebug() << "User has canceled operation";
* }
* ContactGroupEditorDialog *dlg = new ContactGroupEditorDialog( ContactGroupEditorDialog::CreateMode, this );
* connect( dlg, SIGNAL( contactGroupStored( const Akonadi::Item& ) ),
* this, SLOT( contactGroupStored( const Akonadi::Item& ) ) );
* dlg->show();
*
* @endcode
*
......@@ -58,16 +57,15 @@ class ContactGroupEditor;
*
* @code
*
* const Akonadi::Item contactGroup = ...;
* using namespace Akonadi;
*
* Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::EditMode, this );
* dlg.setContactGroup( contactGroup );
* const Item contactGroup = ...;
*
* if ( dlg.exec() ) {
* qDebug() << "Contact group has been edited";
* } else {
* qDebug() << "User has canceled operation";
* }
* ContactGroupEditorDialog *dlg = new ContactGroupEditorDialog( ContactGroupEditorDialog::EditMode, this );
* connect( dlg, SIGNAL( contactGroupStored( const Akonadi::Item& ) ),
* this, SLOT( contactGroupStored( const Akonadi::Item& ) ) );
* dlg->setContactGroup( contactGroup );
* dlg->show();
*
* @endcode
*
......@@ -106,13 +104,17 @@ class AKONADI_CONTACT_EXPORT ContactGroupEditorDialog : public KDialog
*/
void setContactGroup( const Akonadi::Item &group );
//TODO_AKONADI_REVIEW: add setContactGroupTemplate()
/**
* Sets the @p addressbook that shall be selected as default in create mode.
* Sets the @p addressbook that shall be selected as default
* for storage in create mode.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressbook );
/**
* Returns the ContactGroupEditor that is used by the dialog.
*/
ContactGroupEditor* editor() const;
Q_SIGNALS:
/**
* This signal is emitted whenever a contact group was updated or stored.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment