-rw-r--r-- | libkcal/dndfactory.cpp | 186 | ||||
-rw-r--r-- | libkcal/dndfactory.h | 56 | ||||
-rw-r--r-- | libkcal/dndfactory_dummy.h | 62 | ||||
-rw-r--r-- | libkcal/libkcal.pro | 2 |
4 files changed, 284 insertions, 22 deletions
diff --git a/libkcal/dndfactory.cpp b/libkcal/dndfactory.cpp new file mode 100644 index 0000000..cdcfae4 --- a/dev/null +++ b/libkcal/dndfactory.cpp | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | This file is part of libkcal. | ||
3 | Copyright (c) 1998 Preston Brwon | ||
4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | ||
5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> | ||
6 | |||
7 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Library General Public License | ||
18 | along with this library; see the file COPYING.LIB. If not, write to | ||
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
20 | Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
23 | #include <qapplication.h> | ||
24 | #include <qclipboard.h> | ||
25 | |||
26 | #include <kiconloader.h> | ||
27 | #include <kdebug.h> | ||
28 | #include <kmessagebox.h> | ||
29 | #include <klocale.h> | ||
30 | |||
31 | #include "vcaldrag.h" | ||
32 | #include "icaldrag.h" | ||
33 | #include "calendar.h" | ||
34 | #include "vcalformat.h" | ||
35 | #include "icalformat.h" | ||
36 | #include "calendarlocal.h" | ||
37 | |||
38 | #include "dndfactory.h" | ||
39 | |||
40 | using namespace KCal; | ||
41 | |||
42 | DndFactory::DndFactory( Calendar *cal ) : | ||
43 | mCalendar( cal ) | ||
44 | { | ||
45 | } | ||
46 | |||
47 | ICalDrag *DndFactory::createDrag( Incidence *incidence, QWidget *owner ) | ||
48 | { | ||
49 | CalendarLocal cal( mCalendar->timeZoneId() ); | ||
50 | Incidence *i = incidence->clone(); | ||
51 | cal.addIncidence( i ); | ||
52 | |||
53 | ICalDrag *icd = new ICalDrag( &cal, owner ); | ||
54 | if ( i->type() == "Event" ) | ||
55 | icd->setPixmap( BarIcon( "appointment" ) ); | ||
56 | else if ( i->type() == "Todo" ) | ||
57 | icd->setPixmap( BarIcon( "todo" ) ); | ||
58 | |||
59 | return icd; | ||
60 | } | ||
61 | |||
62 | Event *DndFactory::createDrop(QDropEvent *de) | ||
63 | { | ||
64 | kdDebug(5800) << "DndFactory::createDrop()" << endl; | ||
65 | |||
66 | CalendarLocal cal( mCalendar->timeZoneId() ); | ||
67 | |||
68 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { | ||
69 | de->accept(); | ||
70 | |||
71 | QPtrList<Event> events = cal.events(); | ||
72 | if ( !events.isEmpty() ) { | ||
73 | Event *event = new Event( *events.first() ); | ||
74 | return event; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | Todo *DndFactory::createDropTodo(QDropEvent *de) | ||
82 | { | ||
83 | kdDebug(5800) << "VCalFormat::createDropTodo()" << endl; | ||
84 | |||
85 | CalendarLocal cal( mCalendar->timeZoneId() ); | ||
86 | |||
87 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { | ||
88 | de->accept(); | ||
89 | |||
90 | QPtrList<Todo> todos = cal.todos(); | ||
91 | if ( !todos.isEmpty() ) { | ||
92 | Todo *todo = new Todo( *todos.first() ); | ||
93 | return todo; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | |||
101 | void DndFactory::cutIncidence( Incidence *selectedInc ) | ||
102 | { | ||
103 | if ( copyIncidence( selectedInc ) ) { | ||
104 | mCalendar->deleteIncidence( selectedInc ); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | bool DndFactory::copyIncidence( Incidence *selectedInc ) | ||
109 | { | ||
110 | if ( !selectedInc ) | ||
111 | return false; | ||
112 | QClipboard *cb = QApplication::clipboard(); | ||
113 | |||
114 | CalendarLocal cal( mCalendar->timeZoneId() ); | ||
115 | Incidence *inc = selectedInc->clone(); | ||
116 | cal.addIncidence( inc ); | ||
117 | cb->setData( new ICalDrag( &cal ) ); | ||
118 | |||
119 | return true; | ||
120 | } | ||
121 | |||
122 | Incidence *DndFactory::pasteIncidence(const QDate &newDate, const QTime *newTime) | ||
123 | { | ||
124 | // kdDebug(5800) << "DnDFactory::pasteEvent()" << endl; | ||
125 | |||
126 | CalendarLocal cal( mCalendar->timeZoneId() ); | ||
127 | |||
128 | QClipboard *cb = QApplication::clipboard(); | ||
129 | |||
130 | if ( !ICalDrag::decode( cb->data(), &cal ) && | ||
131 | !VCalDrag::decode( cb->data(), &cal ) ) { | ||
132 | kdDebug(5800) << "Can't parse clipboard" << endl; | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | QPtrList<Incidence> incList = cal.incidences(); | ||
137 | Incidence *inc = incList.first(); | ||
138 | |||
139 | if ( !incList.isEmpty() && inc ) { | ||
140 | inc = inc->clone(); | ||
141 | |||
142 | inc->recreate(); | ||
143 | |||
144 | if ( inc->type() == "Event" ) { | ||
145 | |||
146 | Event *anEvent = static_cast<Event*>( inc ); | ||
147 | // Calculate length of event | ||
148 | int daysOffset = anEvent->dtStart().date().daysTo( | ||
149 | anEvent->dtEnd().date() ); | ||
150 | // new end date if event starts at the same time on the new day | ||
151 | QDateTime endDate( newDate.addDays(daysOffset), anEvent->dtEnd().time() ); | ||
152 | |||
153 | if ( newTime ) { | ||
154 | // additional offset for new time of day | ||
155 | int addSecsOffset( anEvent->dtStart().time().secsTo( *newTime )); | ||
156 | endDate=endDate.addSecs( addSecsOffset ); | ||
157 | anEvent->setDtStart( QDateTime( newDate, *newTime ) ); | ||
158 | } else { | ||
159 | anEvent->setDtStart( QDateTime( newDate, anEvent->dtStart().time() ) ); | ||
160 | } | ||
161 | anEvent->setDtEnd( endDate ); | ||
162 | |||
163 | } else if ( inc->type() == "Todo" ) { | ||
164 | Todo *anTodo = static_cast<Todo*>( inc ); | ||
165 | if ( newTime ) { | ||
166 | anTodo->setDtDue( QDateTime( newDate, *newTime ) ); | ||
167 | } else { | ||
168 | anTodo->setDtDue( QDateTime( newDate, anTodo->dtDue().time() ) ); | ||
169 | } | ||
170 | } else if ( inc->type() == "Journal" ) { | ||
171 | Journal *anJournal = static_cast<Journal*>( inc ); | ||
172 | if ( newTime ) { | ||
173 | anJournal->setDtStart( QDateTime( newDate, *newTime ) ); | ||
174 | } else { | ||
175 | anJournal->setDtStart( QDateTime( newDate ) ); | ||
176 | } | ||
177 | } else { | ||
178 | kdDebug(5850) << "Trying to paste unknown incidence of type " << inc->type() << endl; | ||
179 | } | ||
180 | |||
181 | return inc; | ||
182 | |||
183 | } | ||
184 | |||
185 | return 0; | ||
186 | } | ||
diff --git a/libkcal/dndfactory.h b/libkcal/dndfactory.h index 6b73f34..7e2ca04 100644 --- a/libkcal/dndfactory.h +++ b/libkcal/dndfactory.h | |||
@@ -1,10 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | |||
3 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> | ||
5 | 7 | ||
6 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 10 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 11 | version 2 of the License, or (at your option) any later version. |
10 | 12 | ||
@@ -16,47 +18,57 @@ | |||
16 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
20 | */ | 22 | */ |
21 | 23 | ||
22 | // $Id$ | ||
23 | |||
24 | #ifndef KCAL_DNDFACTORY_H | 24 | #ifndef KCAL_DNDFACTORY_H |
25 | #define KCAL_DNDFACTORY_H | 25 | #define KCAL_DNDFACTORY_H |
26 | 26 | ||
27 | #include "vcalformat.h" | 27 | //#include "libkcal_export.h" |
28 | |||
29 | class QDropEvent; | ||
30 | 28 | ||
31 | namespace KCal { | 29 | namespace KCal { |
32 | 30 | ||
31 | class ICalDrag; | ||
32 | class Event; | ||
33 | class Todo; | ||
34 | class Calendar; | ||
35 | #define LIBKCAL_EXPORT | ||
36 | |||
33 | /** | 37 | /** |
34 | This class implements functions to create Drag and Drop objects used for | 38 | This class implements functions to create Drag and Drop objects used for |
35 | Drag-and-Drop and Copy-and-Paste. | 39 | Drag-and-Drop and Copy-and-Paste. |
36 | 40 | ||
37 | @short vCalendar Drag-and-Drop object factory. | 41 | @short vCalendar/iCalendar Drag-and-Drop object factory. |
38 | */ | 42 | */ |
39 | class DndFactory { | 43 | class LIBKCAL_EXPORT DndFactory |
44 | { | ||
40 | public: | 45 | public: |
41 | DndFactory( Calendar * ) {} | 46 | DndFactory( Calendar * ); |
47 | |||
48 | /** | ||
49 | Create a drag object. | ||
50 | */ | ||
51 | ICalDrag *createDrag( Incidence *incidence, QWidget *owner ); | ||
42 | 52 | ||
43 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | ||
44 | ICalDrag *createDrag(Event *, QWidget *) { return 0; } | ||
45 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | ||
46 | ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; } | ||
47 | /** Create Todo object from drop event */ | 53 | /** Create Todo object from drop event */ |
48 | Todo *createDropTodo(QDropEvent *) { return 0; } | 54 | Todo *createDropTodo(QDropEvent *de); |
49 | /** Create Event object from drop event */ | 55 | /** Create Event object from drop event */ |
50 | Event *createDrop(QDropEvent *) { return 0; } | 56 | Event *createDrop(QDropEvent *de); |
51 | 57 | ||
52 | /** cut event to clipboard */ | 58 | /** cut incidence to clipboard */ |
53 | void cutEvent(Event *) {} | 59 | void cutIncidence( Incidence * ); |
54 | /** cut, copy, and paste operations follow. */ | 60 | /** copy the incidence to clipboard */ |
55 | bool copyEvent(Event *) { return false; } | 61 | bool copyIncidence( Incidence * ); |
56 | /** pastes the event and returns a pointer to the new event pasted. */ | 62 | /** pastes the event or todo and returns a pointer to the new incidence pasted. */ |
57 | Event *pasteEvent(const QDate &, const QTime *newTime = 0) { return 0; } | 63 | Incidence *pasteIncidence( const QDate &, const QTime *newTime = 0 ); |
64 | |||
65 | private: | ||
66 | Calendar *mCalendar; | ||
67 | |||
68 | class Private; | ||
69 | Private *d; | ||
58 | }; | 70 | }; |
59 | 71 | ||
60 | } | 72 | } |
61 | 73 | ||
62 | #endif | 74 | #endif |
diff --git a/libkcal/dndfactory_dummy.h b/libkcal/dndfactory_dummy.h new file mode 100644 index 0000000..6b73f34 --- a/dev/null +++ b/libkcal/dndfactory_dummy.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | This file is part of libkcal. | ||
3 | Copyright (c) 1998 Preston Brown | ||
4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public License | ||
17 | along with this library; see the file COPYING.LIB. If not, write to | ||
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
19 | Boston, MA 02111-1307, USA. | ||
20 | */ | ||
21 | |||
22 | // $Id$ | ||
23 | |||
24 | #ifndef KCAL_DNDFACTORY_H | ||
25 | #define KCAL_DNDFACTORY_H | ||
26 | |||
27 | #include "vcalformat.h" | ||
28 | |||
29 | class QDropEvent; | ||
30 | |||
31 | namespace KCal { | ||
32 | |||
33 | /** | ||
34 | This class implements functions to create Drag and Drop objects used for | ||
35 | Drag-and-Drop and Copy-and-Paste. | ||
36 | |||
37 | @short vCalendar Drag-and-Drop object factory. | ||
38 | */ | ||
39 | class DndFactory { | ||
40 | public: | ||
41 | DndFactory( Calendar * ) {} | ||
42 | |||
43 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | ||
44 | ICalDrag *createDrag(Event *, QWidget *) { return 0; } | ||
45 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | ||
46 | ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; } | ||
47 | /** Create Todo object from drop event */ | ||
48 | Todo *createDropTodo(QDropEvent *) { return 0; } | ||
49 | /** Create Event object from drop event */ | ||
50 | Event *createDrop(QDropEvent *) { return 0; } | ||
51 | |||
52 | /** cut event to clipboard */ | ||
53 | void cutEvent(Event *) {} | ||
54 | /** cut, copy, and paste operations follow. */ | ||
55 | bool copyEvent(Event *) { return false; } | ||
56 | /** pastes the event and returns a pointer to the new event pasted. */ | ||
57 | Event *pasteEvent(const QDate &, const QTime *newTime = 0) { return 0; } | ||
58 | }; | ||
59 | |||
60 | } | ||
61 | |||
62 | #endif | ||
diff --git a/libkcal/libkcal.pro b/libkcal/libkcal.pro index 171c726..33c63c3 100644 --- a/libkcal/libkcal.pro +++ b/libkcal/libkcal.pro | |||
@@ -56,12 +56,13 @@ kincidenceformatter.h \ | |||
56 | period.h \ | 56 | period.h \ |
57 | person.h \ | 57 | person.h \ |
58 | qtopiaformat.h \ | 58 | qtopiaformat.h \ |
59 | recurrence.h \ | 59 | recurrence.h \ |
60 | scheduler.h \ | 60 | scheduler.h \ |
61 | todo.h \ | 61 | todo.h \ |
62 | dndfactory.h \ | ||
62 | vcaldrag.h \ | 63 | vcaldrag.h \ |
63 | vcalformat.h \ | 64 | vcalformat.h \ |
64 | versit/port.h \ | 65 | versit/port.h \ |
65 | versit/vcc.h \ | 66 | versit/vcc.h \ |
66 | versit/vobject.h \ | 67 | versit/vobject.h \ |
67 | phoneformat.h \ | 68 | phoneformat.h \ |
@@ -95,12 +96,13 @@ SOURCES = \ | |||
95 | period.cpp \ | 96 | period.cpp \ |
96 | person.cpp \ | 97 | person.cpp \ |
97 | qtopiaformat.cpp \ | 98 | qtopiaformat.cpp \ |
98 | recurrence.cpp \ | 99 | recurrence.cpp \ |
99 | scheduler.cpp \ | 100 | scheduler.cpp \ |
100 | todo.cpp \ | 101 | todo.cpp \ |
102 | dndfactory.cpp \ | ||
101 | vcaldrag.cpp \ | 103 | vcaldrag.cpp \ |
102 | vcalformat.cpp \ | 104 | vcalformat.cpp \ |
103 | versit/vcc.c \ | 105 | versit/vcc.c \ |
104 | versit/vobject.c \ | 106 | versit/vobject.c \ |
105 | phoneformat.cpp \ | 107 | phoneformat.cpp \ |
106 | 108 | ||