2 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
3 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
4 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
6 Copyright (c) 2008 Thomas Thrainer <tom_t@gmx.at>
7 Copyright (c) 2010 Laurent Montel <montel@kde.org>
9 Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
10 Author: Sergio Martins <sergio@kdab.com>
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.
27 #include "dndfactory.h"
30 #include <KCalCore/MemoryCalendar>
32 #include <KCalUtils/VCalDrag>
33 #include <KCalUtils/ICalDrag>
35 using namespace CalendarSupport
;
38 Private class that helps to provide binary compatibility between releases.
42 class CalendarSupport::DndFactory::Private
45 Private( const CalendarSupport::CalendarAdaptor::Ptr
&cal
, bool deleteCalendar
)
46 : mDeleteCalendar( deleteCalendar
), mCalendar( cal
),
47 mDndFactory( new KCalUtils::DndFactory( cal
) )
55 CalendarAdaptor::Ptr mCalendar
;
56 KCalUtils::DndFactory
*mDndFactory
;
60 namespace CalendarSupport
{
61 DndFactory::DndFactory( const CalendarSupport::CalendarAdaptor::Ptr
&cal
, bool deleteCalendarHere
)
62 : d( new CalendarSupport::DndFactory::Private ( cal
, deleteCalendarHere
) )
66 DndFactory::~DndFactory()
71 QMimeData
*DndFactory::createMimeData()
73 return d
->mDndFactory
->createMimeData();
76 QDrag
*DndFactory::createDrag( QWidget
*owner
)
78 return d
->mDndFactory
->createDrag( owner
);
81 QMimeData
*DndFactory::createMimeData( const KCalCore::Incidence::Ptr
&incidence
)
83 return d
->mDndFactory
->createMimeData( incidence
);
86 QDrag
*DndFactory::createDrag( const KCalCore::Incidence::Ptr
&incidence
, QWidget
*owner
)
88 return d
->mDndFactory
->createDrag( incidence
, owner
);
91 KCalCore::MemoryCalendar::Ptr
DndFactory::createDropCalendar( const QMimeData
*md
)
93 return d
->mDndFactory
->createDropCalendar( md
);
97 KCalCore::MemoryCalendar::Ptr
DndFactory::createDropCalendar( const QMimeData
*md
,
98 const KDateTime::Spec
&timeSpec
)
100 KCalCore::MemoryCalendar::Ptr
cal( new KCalCore::MemoryCalendar( timeSpec
) );
102 if ( KCalUtils::ICalDrag::fromMimeData( md
, cal
) ||
103 KCalUtils::VCalDrag::fromMimeData( md
, cal
) ) {
107 return KCalCore::MemoryCalendar::Ptr();
110 KCalCore::MemoryCalendar::Ptr
DndFactory::createDropCalendar( QDropEvent
*de
)
112 return d
->mDndFactory
->createDropCalendar( de
);
115 KCalCore::Event::Ptr
DndFactory::createDropEvent( const QMimeData
*md
)
117 return d
->mDndFactory
->createDropEvent( md
);
120 KCalCore::Event::Ptr
DndFactory::createDropEvent( QDropEvent
*de
)
122 return d
->mDndFactory
->createDropEvent( de
);
125 KCalCore::Todo::Ptr
DndFactory::createDropTodo( const QMimeData
*md
)
127 return d
->mDndFactory
->createDropTodo( md
);
130 KCalCore::Todo::Ptr
DndFactory::createDropTodo( QDropEvent
*de
)
132 return d
->mDndFactory
->createDropTodo( de
);
135 void DndFactory::cutIncidence( const Akonadi::Item
&selectedInc
)
137 if ( copyIncidence( selectedInc
) ) {
138 // Don't call the kcal's version, call deleteIncidence( Item, )
139 // which creates a ItemDeleteJob.
140 d
->mCalendar
->deleteIncidence( selectedInc
, d
->mDeleteCalendar
);
144 bool DndFactory::copyIncidence( const Akonadi::Item
&item
)
146 if ( CalendarSupport::hasIncidence( item
) ) {
147 return d
->mDndFactory
->copyIncidence( CalendarSupport::incidence( item
) );
153 KCalCore::Incidence::Ptr
DndFactory::pasteIncidence(
154 const KDateTime
&newDateTime
, const KCalUtils::DndFactory::PasteFlags
&pasteFlags
)
156 return d
->mDndFactory
->pasteIncidence( newDateTime
, pasteFlags
);
159 bool DndFactory::copyIncidences( const Akonadi::Item::List
&items
)
161 KCalCore::Incidence::List incList
;
162 Q_FOREACH ( const Akonadi::Item
&item
, items
) {
163 if ( CalendarSupport::hasIncidence( item
) ) {
164 incList
.append( CalendarSupport::incidence( item
) );
168 return d
->mDndFactory
->copyIncidences( incList
);
171 bool DndFactory::cutIncidences( const Akonadi::Item::List
&items
)
173 if ( copyIncidences( items
) ) {
174 Akonadi::Item::List::ConstIterator it
;
175 Akonadi::Item::List::ConstIterator
end( items
.constEnd() );
176 for ( it
= items
.constBegin(); it
!= end
; ++it
) {
177 // Don't call the kcal's version, call deleteIncidence( Item, )
178 // which creates a Akonadi::ItemDeleteJob.
179 d
->mCalendar
->deleteIncidence( *it
);
187 KCalCore::Incidence::List
DndFactory::pasteIncidences(
188 const KDateTime
&newDateTime
, const KCalUtils::DndFactory::PasteFlags
&pasteFlags
)
190 return d
->mDndFactory
->pasteIncidences( newDateTime
, pasteFlags
);