Commit c30760bf authored by Tobias Koenig's avatar Tobias Koenig

Handle missing default collections properly by not closing the dialog

svn path=/trunk/KDE/kdepim/akonadi/contact/; revision=1015899
parent 741d5524
......@@ -22,10 +22,10 @@
#include "contacteditor.h"
#include "abstractcontacteditorwidget.h"
#include "contactmetadata_p.h"
#include "contactmetadataattribute_p.h"
#include "addressbookselectiondialog.h"
#include "autoqpointer.h"
#include "contactmetadata_p.h"
#include "contactmetadataattribute_p.h"
#include <akonadi/itemcreatejob.h>
#include <akonadi/itemfetchjob.h>
......@@ -186,14 +186,14 @@ void ContactEditor::loadContact( const Akonadi::Item &item )
d->mMonitor->setItemMonitored( item );
}
void ContactEditor::saveContact()
bool ContactEditor::saveContact()
{
if ( d->mMode == EditMode ) {
if ( !d->mItem.isValid() )
return;
return true;
if ( d->mReadOnly )
return;
return true;
KABC::Addressee addr = d->mItem.payload<KABC::Addressee>();
......@@ -211,7 +211,7 @@ void ContactEditor::saveContact()
if ( dlg->exec() == KDialog::Accepted )
setDefaultCollection( dlg->selectedAddressBook() );
else
return; // FIXME: should go back to the editor instead of aborting
return false;
}
KABC::Addressee addr;
......@@ -226,6 +226,8 @@ void ContactEditor::saveContact()
Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, d->mDefaultCollection );
connect( job, SIGNAL( result( KJob* ) ), SLOT( storeDone( KJob* ) ) );
}
return true;
}
void ContactEditor::setDefaultCollection( const Akonadi::Collection &collection )
......
......@@ -83,7 +83,7 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
/**
* Saves the contact from the editor back to the storage.
*/
void saveContact();
bool saveContact();
/**
* Sets the @p collection which shall be used to store new
......
......@@ -79,9 +79,8 @@ class ContactEditorDialog::Private
if ( mAddressBookBox )
mEditor->setDefaultCollection( mAddressBookBox->selectedAddressBook() );
mEditor->saveContact();
q->accept();
if ( mEditor->saveContact() )
q->accept();
}
void slotCancelClicked()
......
......@@ -19,25 +19,27 @@
#include "contactgroupeditor.h"
#include <QtGui/QGridLayout>
#include <QtGui/QMessageBox>
#include "addressbookselectiondialog.h"
#include "autoqpointer.h"
#include "contactcompletionmodel_p.h"
#include "contactgrouplineedit_p.h"
#include "ui_contactgroupeditor.h"
#include "waitingoverlay_p.h"
#include <kabc/addressee.h>
#include <kabc/contactgroup.h>
#include <klocale.h>
#include <klineedit.h>
#include <kmessagebox.h>
#include <akonadi/itemcreatejob.h>
#include <akonadi/itemfetchjob.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/itemmodifyjob.h>
#include <akonadi/monitor.h>
#include <akonadi/session.h>
#include <kabc/addressee.h>
#include <kabc/contactgroup.h>
#include <klocale.h>
#include <klineedit.h>
#include <kmessagebox.h>
#include "contactcompletionmodel_p.h"
#include "contactgrouplineedit_p.h"
#include "ui_contactgroupeditor.h"
#include "waitingoverlay_p.h"
#include <QtGui/QGridLayout>
#include <QtGui/QMessageBox>
namespace Akonadi
{
......@@ -327,7 +329,13 @@ bool ContactGroupEditor::saveContactGroup()
ItemModifyJob *job = new ItemModifyJob( d->mItem );
connect( job, SIGNAL( result( KJob* ) ), SLOT( storeDone( KJob* ) ) );
} else if ( d->mMode == CreateMode ) {
Q_ASSERT_X( d->mDefaultCollection.isValid(), "ContactGroupEditor::saveContactGroup", "Using invalid default collection for saving!" );
if ( !d->mDefaultCollection.isValid() ) {
AutoQPointer<AddressBookSelectionDialog> dlg = new AddressBookSelectionDialog( AddressBookSelectionDialog::ContactsOnly, this );
if ( dlg->exec() == KDialog::Accepted )
setDefaultCollection( dlg->selectedAddressBook() );
else
return false;
}
KABC::ContactGroup group;
if ( !d->storeContactGroup( group ) )
......
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