Commit fcd9a2e9 authored by Sergio Martins's avatar Sergio Martins
Browse files

The editors now use the same undo/redo stack as the application.

Undo/Redo wasn't working when changing incidences through the
editors because we had two IncidenceChanger instances instead of
one.
parent da2cb862
......@@ -57,7 +57,7 @@ class ItemEditorPrivate
Akonadi::IncidenceChanger *mChanger;
public:
ItemEditorPrivate( EditorItemManager *qq );
ItemEditorPrivate( Akonadi::IncidenceChanger *changer, EditorItemManager *qq );
void itemChanged( const Akonadi::Item &, const QSet<QByteArray> & );
void itemFetchResult( KJob *job );
void itemMoveResult( KJob *job );
......@@ -74,12 +74,14 @@ class ItemEditorPrivate
void moveJobFinished( KJob *job );
};
ItemEditorPrivate::ItemEditorPrivate( EditorItemManager *qq )
ItemEditorPrivate::ItemEditorPrivate( Akonadi::IncidenceChanger *changer, EditorItemManager *qq )
: q_ptr( qq ), mItemMonitor( 0 ), mIsCounterProposal( false )
{
mFetchScope.fetchFullPayload();
mFetchScope.setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
mChanger = new Akonadi::IncidenceChanger( qq );
mChanger = changer ? changer : new Akonadi::IncidenceChanger( qq );
qq->connect( mChanger,
SIGNAL(modifyFinished(int,Akonadi::Item,Akonadi::IncidenceChanger::ResultCode,QString)),
qq, SLOT(onModifyFinished(int,Akonadi::Item,Akonadi::IncidenceChanger::ResultCode,QString)) );
......@@ -245,8 +247,8 @@ void ItemEditorPrivate::itemChanged( const Akonadi::Item &item,
/// ItemEditor
EditorItemManager::EditorItemManager( ItemEditorUi *ui )
: d_ptr( new ItemEditorPrivate( this ) )
EditorItemManager::EditorItemManager( ItemEditorUi *ui, Akonadi::IncidenceChanger *changer )
: d_ptr( new ItemEditorPrivate( changer, this ) )
{
Q_D( ItemEditor );
d->mItemUi = ui;
......
......@@ -53,8 +53,10 @@ class INCIDENCEEDITORS_NG_EXPORT EditorItemManager : public QObject
public:
/**
* Creates an ItemEditor for a new Item.
* Receives an option IncidenceChanger, so you can share the undo/redo stack with your
* application.
*/
EditorItemManager( ItemEditorUi *ui );
EditorItemManager( ItemEditorUi *ui, Akonadi::IncidenceChanger *changer = 0 );
/**
* Destructs the ItemEditor. Unsaved changes will get lost at this point.
......
......@@ -81,7 +81,7 @@ class EventOrTodoDialogPrivate : public ItemEditorUi
QString typeToString( const int type ) const;
public:
EventOrTodoDialogPrivate( EventOrTodoDialog *qq );
EventOrTodoDialogPrivate( Akonadi::IncidenceChanger *changer, EventOrTodoDialog *qq );
~EventOrTodoDialogPrivate();
/// General methods
......@@ -112,12 +112,13 @@ class EventOrTodoDialogPrivate : public ItemEditorUi
}
EventOrTodoDialogPrivate::EventOrTodoDialogPrivate( EventOrTodoDialog *qq )
EventOrTodoDialogPrivate::EventOrTodoDialogPrivate( Akonadi::IncidenceChanger *changer,
EventOrTodoDialog *qq )
: q_ptr( qq ),
mUi( new Ui::EventOrTodoDesktop ),
mCalSelector( new Akonadi::CollectionComboBox ),
mCloseOnSave( false ),
mItemManager( new EditorItemManager( this ) ),
mItemManager( new EditorItemManager( this, changer ) ),
mEditor( new CombinedIncidenceEditor ),
mInitiallyDirty( false )
{
......@@ -590,8 +591,9 @@ void EventOrTodoDialogPrivate::reject( RejectReason reason, const QString &error
/// EventOrTodoDialog
EventOrTodoDialog::EventOrTodoDialog( QWidget *parent, Qt::WFlags flags )
: IncidenceDialog( parent, flags ), d_ptr( new EventOrTodoDialogPrivate( this ) )
EventOrTodoDialog::EventOrTodoDialog( Akonadi::IncidenceChanger *changer,
QWidget *parent, Qt::WFlags flags )
: IncidenceDialog( parent, flags ), d_ptr( new EventOrTodoDialogPrivate( changer, this ) )
{
Q_D( EventOrTodoDialog );
......@@ -666,7 +668,7 @@ void EventOrTodoDialog::selectCollection( const Akonadi::Collection &collection
void EventOrTodoDialog::setIsCounterProposal( bool isCounterProposal )
{
Q_D( EventOrTodoDialog );
//Q_D( EventOrTodoDialog );
//d->mInvitationDispatcher->setIsCounterProposal( isCounterProposal ); TODO_SERGIO
}
......
......@@ -25,6 +25,10 @@
#include "editoritemmanager.h"
#include "incidencedialog.h"
namespace Akonadi {
class IncidenceChanger;
}
namespace IncidenceEditorNG {
class EventOrTodoDialogPrivate;
......@@ -33,7 +37,8 @@ class INCIDENCEEDITORS_NG_EXPORT EventOrTodoDialog : public IncidenceDialog
{
Q_OBJECT
public:
explicit EventOrTodoDialog( QWidget *parent = 0, Qt::WFlags flags = 0 );
explicit EventOrTodoDialog( Akonadi::IncidenceChanger *changer = 0,
QWidget *parent = 0, Qt::WFlags flags = 0 );
~EventOrTodoDialog();
/**
......
......@@ -63,7 +63,7 @@ class GroupwareUiDelegate : public QObject, public CalendarSupport::GroupwareUiD
IncidenceEditorNG::IncidenceDialog *dialog =
IncidenceEditorNG::IncidenceDialogFactory::create( false/*needs initial saving?*/,
incidence->type() );
incidence->type(), 0 );
dialog->setIsCounterProposal( true );
dialog->load( item, QDate::currentDate() );
#else
......
......@@ -26,12 +26,14 @@
#include <KCalCore/Event>
#include <KCalCore/Todo>
#include <Akonadi/Item>
#include <Akonadi/Calendar/IncidenceChanger>
using namespace IncidenceEditorNG;
using namespace KCalCore;
IncidenceDialog *IncidenceDialogFactory::create( bool needsSaving,
KCalCore::IncidenceBase::IncidenceType type,
Akonadi::IncidenceChanger *changer,
QWidget *parent, Qt::WFlags flags )
{
switch ( type ) {
......@@ -40,7 +42,7 @@ IncidenceDialog *IncidenceDialogFactory::create( bool needsSaving,
case KCalCore::IncidenceBase::TypeJournal:
{
// TODO: rename EventOrTodoDialog to IncidenceDialog
EventOrTodoDialog *dialog = new EventOrTodoDialog( parent, flags );
EventOrTodoDialog *dialog = new EventOrTodoDialog( changer, parent, flags );
// needs to be save to akonadi?, apply button should be turned on if so.
dialog->setInitiallyDirty( needsSaving/* mInitiallyDirty */ );
......@@ -87,6 +89,7 @@ IncidenceDialog * IncidenceDialogFactory::createTodoEditor( const QString &summa
IncidenceDialog *dialog = create( true, /* no need for, we're not editing an existing to-do */
KCalCore::Incidence::TypeTodo,
0,
parent, flags );
dialog->selectCollection( defaultCollection );
dialog->load( item );
......@@ -129,6 +132,7 @@ IncidenceDialog * IncidenceDialogFactory::createEventEditor( const QString &summ
IncidenceDialog *dialog =
create( false, // not needed for saving, as we're not editing an existing incidence
KCalCore::Incidence::TypeEvent,
0,
parent, flags );
dialog->selectCollection( defaultCollection );
......
......@@ -26,6 +26,10 @@
#include <KCalCore/IncidenceBase>
#include <Akonadi/Collection>
namespace Akonadi {
class IncidenceChanger;
}
namespace IncidenceEditorNG {
class IncidenceDialog;
......@@ -49,6 +53,7 @@ namespace IncidenceDialogFactory
INCIDENCEEDITORS_NG_EXPORT IncidenceDialog *create(
bool needsSaving,
KCalCore::IncidenceBase::IncidenceType type,
Akonadi::IncidenceChanger *changer,
QWidget *parent = 0, Qt::WFlags flags = 0 );
INCIDENCEEDITORS_NG_EXPORT IncidenceDialog *createTodoEditor(
......
......@@ -1071,8 +1071,7 @@ void CalendarView::dateTimesForNewEvent( QDateTime &startDt, QDateTime &endDt,
}
}
IncidenceEditorNG::IncidenceDialog *CalendarView::newEventEditor(
const KCalCore::Event::Ptr &event )
IncidenceEditorNG::IncidenceDialog *CalendarView::newEventEditor( const KCalCore::Event::Ptr &event )
{
Akonadi::Item item;
item.setPayload( event );
......@@ -1080,9 +1079,8 @@ IncidenceEditorNG::IncidenceDialog *CalendarView::newEventEditor(
IncidenceEditorNG::IncidenceDialog *dialog = mDialogManager->createDialog( item );
dialog->load( item );
// connectIncidenceEditor( dialog );
mDialogManager->connectTypeAhead(
dialog, dynamic_cast<KOEventView*>( viewManager()->currentView() ) );
dialog, qobject_cast<KOEventView*>( viewManager()->currentView() ) );
return dialog;
}
......
......@@ -175,8 +175,8 @@ IncidenceEditorNG::IncidenceDialog *KODialogManager::createDialog( const Akonadi
IncidenceEditorNG::IncidenceDialog *dialog =
IncidenceEditorNG::IncidenceDialogFactory::create(
false/*needs initial saving?*/,
incidence->type(), mMainView );
/*needs initial saving=*/false,
incidence->type(), mMainView->incidenceChanger(), mMainView );
return dialog;
}
......
......@@ -940,7 +940,7 @@ bool AlarmDialog::openIncidenceEditorNG( const Akonadi::Item &item )
IncidenceEditorNG::IncidenceDialog *dialog =
IncidenceEditorNG::IncidenceDialogFactory::create(
false, /*doesn't need initial saving*/
incidence->type(), this );
incidence->type(), 0, this );
dialog->load( item );
return true;
}
......
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