Commit b96f004a authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 309324 - No error message when ItemCreateJob or ItemModifyJob fails

FIXED-IN: 4.11
BUG: 309324
parent 374fee39
......@@ -149,6 +149,7 @@ void ContactEditor::Private::storeDone( KJob *job )
{
if ( job->error() != KJob::NoError ) {
emit mParent->error( job->errorString() );
emit mParent->finished();
return;
}
......@@ -157,6 +158,7 @@ void ContactEditor::Private::storeDone( KJob *job )
} else if ( mMode == CreateMode ) {
emit mParent->contactStored( static_cast<Akonadi::ItemCreateJob*>( job )->item() );
}
emit mParent->finished();
}
void ContactEditor::Private::itemChanged( const Akonadi::Item&, const QSet<QByteArray>& )
......@@ -245,6 +247,54 @@ KABC::Addressee ContactEditor::contact()
return addr;
}
void ContactEditor::saveContactInAddressBook()
{
if ( d->mMode == EditMode ) {
if ( !d->mItem.isValid() || d->mReadOnly ) {
emit finished();
return;
}
KABC::Addressee addr = d->mItem.payload<KABC::Addressee>();
d->storeContact( addr, d->mContactMetaData );
d->mContactMetaData.store( d->mItem );
d->mItem.setPayload<KABC::Addressee>( addr );
Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob( d->mItem );
connect( job, SIGNAL(result(KJob*)), SLOT(storeDone(KJob*)) );
} else if ( d->mMode == CreateMode ) {
if ( !d->mDefaultCollection.isValid() ) {
const QStringList mimeTypeFilter( KABC::Addressee::mimeType() );
AutoQPointer<CollectionDialog> dlg = new CollectionDialog( this );
dlg->setMimeTypeFilter( mimeTypeFilter );
dlg->setAccessRightsFilter( Collection::CanCreateItem );
dlg->setCaption( i18n( "Select Address Book" ) );
dlg->setDescription( i18n( "Select the address book the new contact shall be saved in:" ) );
if ( dlg->exec() == KDialog::Accepted ) {
setDefaultAddressBook( dlg->selectedCollection() );
} else {
return;
}
}
KABC::Addressee addr;
d->storeContact( addr, d->mContactMetaData );
Akonadi::Item item;
item.setPayload<KABC::Addressee>( addr );
item.setMimeType( KABC::Addressee::mimeType() );
d->mContactMetaData.store( item );
Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, d->mDefaultCollection );
connect( job, SIGNAL(result(KJob*)), SLOT(storeDone(KJob*)) );
}
}
bool ContactEditor::saveContact()
{
if ( d->mMode == EditMode ) {
......
......@@ -70,10 +70,7 @@ class Item;
*
* ...
*
* if ( !editor->saveContact() ) {
* qDebug() << "Unable to save changed contact to storage";
* return;
* }
* editor->saveContactInAddressBook();
*
* @endcode
*
......@@ -158,8 +155,17 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
/**
* Saves the contact from the editor back to the storage.
* @deprecated use saveContactInAddressBook. We can't get contactStored and error infos.
* Remove it for KDE SC5
*/
KDE_DEPRECATED bool saveContact();
/**
* Save the contact from the editor back to the storage. And return error.
* Need to connect to finished() signal, to keep time to emit signal.
* @since 4.11
*/
bool saveContact();
void saveContactInAddressBook();
Q_SIGNALS:
/**
......@@ -171,9 +177,15 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
/**
* This signal is emitted when an error occurred during the save.
* @param errorMsg The error message.
* @since 4.11
*/
void error( const QString &errorMsg );
/**
* @brief finished
* @since 4.11
*/
void finished();
private:
//@cond PRIVATE
class Private;
......
......@@ -76,8 +76,12 @@ class ContactEditorDialog::Private
connect( mEditor, SIGNAL(contactStored(Akonadi::Item)),
q, SIGNAL(contactStored(Akonadi::Item)) );
connect( mEditor, SIGNAL(error(QString)),
q, SIGNAL(error(QString)) );
connect( q, SIGNAL(okClicked()), q, SLOT(slotOkClicked()) );
connect( q, SIGNAL(cancelClicked()), q, SLOT(slotCancelClicked()) );
connect( mEditor, SIGNAL(finished()), q, SLOT(slotFinish()) );
q->setInitialSize( QSize( 800, 500 ) );
}
......@@ -87,10 +91,12 @@ class ContactEditorDialog::Private
if ( mAddressBookBox ) {
mEditor->setDefaultAddressBook( mAddressBookBox->currentCollection() );
}
mEditor->saveContactInAddressBook();
}
if ( mEditor->saveContact() ) {
q->accept();
}
void slotFinish()
{
q->KDialog::accept();
}
void slotCancelClicked()
......@@ -143,4 +149,10 @@ ContactEditor* ContactEditorDialog::editor() const
return d->mEditor;
}
void ContactEditorDialog::accept()
{
//Nothing
}
#include "moc_contacteditordialog.cpp"
......@@ -150,6 +150,16 @@ class AKONADI_CONTACT_EXPORT ContactEditorDialog : public KDialog
*/
void contactStored( const Akonadi::Item &contact );
/**
* This signal is emitted whenever a contact is not updated or stored.
*
* @param errMsg The error during updating or storing contact.
*/
void error(const QString& errMsg);
public Q_SLOTS:
void accept();
private:
//@cond PRIVATE
class Private;
......@@ -157,6 +167,7 @@ class AKONADI_CONTACT_EXPORT ContactEditorDialog : public KDialog
Q_PRIVATE_SLOT( d, void slotOkClicked() )
Q_PRIVATE_SLOT( d, void slotCancelClicked() )
Q_PRIVATE_SLOT( d, void slotFinish() )
//@endcond
};
......
......@@ -491,6 +491,8 @@ class StandardContactActionManager::Private
QPointer<Akonadi::ContactEditorDialog> dlg =
new Akonadi::ContactEditorDialog(
Akonadi::ContactEditorDialog::EditMode, mParentWidget );
connect( dlg, SIGNAL(error(QString)),
mParent, SLOT(slotContactEditorError(QString)) );
dlg->setContact( item );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->show();
......@@ -504,6 +506,11 @@ class StandardContactActionManager::Private
}
}
void slotContactEditorError(const QString& error)
{
KMessageBox::error(mParentWidget, i18n("Contact can not stored: %1", error), i18n("Failed to store contact"));
}
KActionCollection *mActionCollection;
QWidget *mParentWidget;
StandardActionManager *mGenericManager;
......
......@@ -186,6 +186,7 @@ class AKONADI_CONTACT_EXPORT StandardContactActionManager : public QObject
Q_PRIVATE_SLOT( d, void slotCreateContact() )
Q_PRIVATE_SLOT( d, void slotCreateContactGroup() )
Q_PRIVATE_SLOT( d, void slotEditItem() )
Q_PRIVATE_SLOT( d, void slotContactEditorError(const QString&) )
//@endcond
};
......
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