summaryrefslogtreecommitdiffabout
path: root/korganizer/koeventeditor.cpp
Unidiff
Diffstat (limited to 'korganizer/koeventeditor.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeventeditor.cpp378
1 files changed, 378 insertions, 0 deletions
diff --git a/korganizer/koeventeditor.cpp b/korganizer/koeventeditor.cpp
new file mode 100644
index 0000000..b3edec6
--- a/dev/null
+++ b/korganizer/koeventeditor.cpp
@@ -0,0 +1,378 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qtooltip.h>
25#include <qframe.h>
26#include <qpixmap.h>
27#include <qhbox.h>
28#include <qdir.h>
29#include <qlayout.h>
30#include <qwidgetstack.h>
31#include <qapplication.h>
32
33#include <kiconloader.h>
34#include <kstandarddirs.h>
35#include <kdebug.h>
36#include <klocale.h>
37#include <kfiledialog.h>
38#include <kmessagebox.h>
39#include <libkcal/calendarresources.h>
40#include <libkcal/resourcecalendar.h>
41#include <kresources/resourceselectdialog.h>
42
43#include <libkdepim/categoryselectdialog.h>
44#include <libkcal/calendarlocal.h>
45#include <libkcal/icalformat.h>
46
47#include "koprefs.h"
48
49#include "koeventeditor.h"
50#include "koeventeditor.moc"
51extern int globalFlagBlockAgenda;
52
53KOEventEditor::KOEventEditor( Calendar *calendar, QWidget *parent ) :
54 KOIncidenceEditor( i18n("Edit Event"), calendar, parent )
55{
56 mEvent = 0;
57 init();
58}
59
60KOEventEditor::~KOEventEditor()
61{
62 //emit dialogClose( mEvent );
63}
64
65void KOEventEditor::init()
66{
67
68 setupGeneral();
69 setupAttendeesTab();
70 setupRecurrence();
71
72 // Propagate date time settings to recurrence tab
73 connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)),
74 mRecurrence,SLOT(setDateTimes(QDateTime,QDateTime)));
75 connect(mGeneral,SIGNAL(dateTimeStrChanged(const QString &)),
76 mRecurrence,SLOT(setDateTimeStr(const QString &)));
77
78 // Category dialog
79 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
80 //connect(mCategoryDialog,SIGNAL(categoriesSelected(const QString &)),
81 // mGeneral,SLOT(setCategories(const QString &)));
82
83
84}
85
86void KOEventEditor::reload()
87{
88 if ( mEvent ) readEvent( mEvent );
89}
90
91void KOEventEditor::setSecrecy( int sec )
92{
93 mGeneral->setSecrecy( sec );
94}
95void KOEventEditor::setCategories( QString s )
96{
97 mGeneral->setCategories(s);
98
99}
100void KOEventEditor::setupGeneral()
101{
102 mGeneral = new KOEditorGeneralEvent( this, "KOEditorGeneralEvent" );
103 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
104
105 if( KOPrefs::instance()->mCompactDialogs ) {
106 QFrame *topFrame = addPage(i18n("General"));
107 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
108 topLayout->setSpacing(spacingHint()-1);
109 topLayout->setMargin(marginHint()-1);
110 mGeneral->initHeader(topFrame,topLayout);
111 mGeneral->initTime(topFrame,topLayout);
112// QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
113 mGeneral->initAlarm(topFrame,topLayout);
114 mGeneral->enableAlarm( false );
115
116 QBoxLayout *buttonLayout;
117 if ( QApplication::desktop()->width() < 500 )
118 buttonLayout = new QVBoxLayout( topLayout );
119 else
120 buttonLayout = new QHBoxLayout( topLayout );
121 QHBox* buttonWidget = new QHBox (topFrame);
122 QIconSet icon;
123 if ( QApplication::desktop()->width() < 321 )
124 icon = SmallIcon("fileexport16");
125 else
126 icon = SmallIcon("fileexport");
127 QPushButton * loadTemplate = new QPushButton( buttonWidget);
128 QPushButton * saveTemplate = new QPushButton( buttonWidget);
129 saveTemplate->setIconSet (icon ) ;
130 int size = saveTemplate->sizeHint().height();
131 saveTemplate->setFixedSize( size, size );
132 if ( QApplication::desktop()->width() < 321 )
133 icon = SmallIcon("fileimport16");
134 else
135 icon = SmallIcon("fileimport");
136 loadTemplate->setIconSet (icon ) ;
137 loadTemplate->setFixedSize( size, size );
138 buttonLayout->addWidget( buttonWidget );
139 mGeneral->initCategories( topFrame, buttonLayout );
140
141 topLayout->addStretch( 1 );
142
143 QFrame *topFrame2 = addPage(i18n("Details"));
144
145 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
146 topLayout2->setSpacing(spacingHint());
147
148 mGeneral->initClass(topFrame2,topLayout2);
149 mGeneral->initSecrecy( topFrame2, topLayout2 );
150 mGeneral->initDescription(topFrame2,topLayout2);
151
152 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
153 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
154 } else {
155 QFrame *topFrame = addPage(i18n("General"));
156
157 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
158 topLayout->setSpacing(spacingHint());
159
160 mGeneral->initHeader(topFrame,topLayout);
161 mGeneral->initTime(topFrame,topLayout);
162 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
163 mGeneral->initAlarm(topFrame,alarmLineLayout);
164 mGeneral->initClass(topFrame,alarmLineLayout);
165 mGeneral->initDescription(topFrame,topLayout);
166 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
167 mGeneral->initCategories( topFrame, detailsLayout );
168 mGeneral->initSecrecy( topFrame, detailsLayout );
169 }
170
171 mGeneral->finishSetup();
172
173}
174
175void KOEventEditor::setupRecurrence()
176{
177 QFrame *topFrame = addPage( i18n("Recurrence") );
178 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
179
180 mRecurrence = new KOEditorRecurrence( topFrame );
181 topLayout->addWidget( mRecurrence );
182}
183
184void KOEventEditor::editEvent(Event *event, bool showDescription)
185{
186 // init();
187
188 mEvent = event;
189 readEvent(mEvent);
190 qApp->processEvents();
191 if ( showDescription ) {
192 showPage( 1 );
193 mGeneral->setFocusOn( 1 );
194 } else {
195 showPage( 0 );
196 mGeneral->setFocusOn( 2 );
197 }
198}
199
200void KOEventEditor::newEvent( QDateTime from, QDateTime to, bool allDay )
201{
202 // init();
203
204 mEvent = 0;
205 setDefaults(from,to,allDay);
206}
207
208void KOEventEditor::loadDefaults()
209{
210 int fmt = KOPrefs::instance()->mStartTime;
211
212 QDateTime from(QDate::currentDate(), QTime(fmt,0,0));
213 QDateTime to(QDate::currentDate(),
214 QTime(fmt+KOPrefs::instance()->mDefaultDuration,0,0));
215
216 setDefaults(from,to,false);
217}
218
219bool KOEventEditor::processInput( bool emitTime )
220{
221 if (!validateInput()) return false;
222
223 Event *event = 0;
224
225 if (mEvent) event = mEvent;
226 else {
227 event = new Event;
228 event->setOrganizer(KOPrefs::instance()->email());
229 }
230
231 writeEvent(event);
232 if ( emitTime ) {
233 globalFlagBlockAgenda = 1;
234 emit showAgendaView( false );
235 emit jumpToTime( event->dtStart().date() );
236 globalFlagBlockAgenda = 2;
237
238 }
239 if (mEvent) {
240 event->setRevision(event->revision()+1);
241 emit eventChanged(event);
242 } else {
243 mCalendar->addEvent(event);
244 mEvent = event;
245 emit eventAdded(event);
246 }
247
248 return true;
249}
250
251void KOEventEditor::deleteEvent()
252{
253 kdDebug() << "Delete event" << endl;
254
255 if (mEvent) {
256 if (KOPrefs::instance()->mConfirm) {
257 switch (msgItemDelete()) {
258 case KMessageBox::Continue: // OK
259 emit eventToBeDeleted(mEvent);
260 emit dialogClose(mEvent);
261 mCalendar->deleteEvent(mEvent);
262 emit eventDeleted();
263 reject();
264 break;
265 }
266 }
267 else {
268 emit eventToBeDeleted(mEvent);
269 emit dialogClose(mEvent);
270 mCalendar->deleteEvent(mEvent);
271 emit eventDeleted();
272 reject();
273 }
274 } else {
275 reject();
276 }
277}
278
279void KOEventEditor::setDefaults(QDateTime from, QDateTime to, bool allDay)
280{
281 mGeneral->setDefaults(from,to,allDay);
282 mDetails->setDefaults();
283 mRecurrence->setDefaults(from,to,allDay);
284 showPage( 0 );
285 mGeneral->setFocusOn( 2 );
286}
287
288void KOEventEditor::readEvent( Event *event, bool tmpl )
289{
290 mGeneral->readEvent( event, tmpl );
291 mDetails->readEvent( event );
292 mRecurrence->readEvent( event );
293
294 // categories
295 //mCategoryDialog->setSelected( event->categories() );
296}
297
298void KOEventEditor::writeEvent(Event *event)
299{
300 mGeneral->writeEvent( event );
301 mDetails->writeEvent( event );
302
303 if ( event->organizer() == KOPrefs::instance()->email() ) {
304 Event *ev = new Event( *event );
305 ev->registerObserver(0);
306 mDetails->cancelAttendeeEvent( ev );
307 if ( ev->attendeeCount() > 0 ) {
308 emit deleteAttendee( ev );
309 }
310 delete(ev);
311 }
312
313 mRecurrence->writeEvent(event);
314}
315
316bool KOEventEditor::validateInput()
317{
318 if (!mGeneral->validateInput()) return false;
319 if (!mDetails->validateInput()) return false;
320 if (!mRecurrence->validateInput()) return false;
321 return true;
322}
323
324int KOEventEditor::msgItemDelete()
325{
326 return KMessageBox::warningContinueCancel(this,
327 i18n("This item will be permanently deleted."),
328 i18n("KOrganizer Confirmation"),i18n("Delete"));
329}
330
331void KOEventEditor::slotLoadTemplate()
332{
333
334 QString fileName =locateLocal( "templates", "events" );
335 QDir t_dir;
336 if ( !t_dir.exists(fileName) )
337 t_dir.mkdir ( fileName );
338 fileName += "/event";
339 fileName = KFileDialog::getSaveFileName( fileName , "Load Event template", this );
340 if ( fileName.length() == 0 )
341 return;
342 CalendarLocal cal;
343 ICalFormat format;
344 if ( !format.load( &cal, fileName ) ) {
345 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
346 .arg( fileName ) );
347 return ;
348 }
349 QPtrList<Event> events = cal.events();
350 Event* event = events.first();
351 if ( !event ) {
352 KMessageBox::error( this,
353 i18n("Template does not contain\na valid Event."));
354 } else {
355 kdDebug() << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
356 readEvent( event, true );
357 }
358}
359
360
361void KOEventEditor::slotSaveTemplate()
362{
363 QString fileName =locateLocal( "templates", "events" );
364 QDir t_dir;
365 if ( !t_dir.exists(fileName) )
366 t_dir.mkdir ( fileName );
367 fileName += "/event";
368 fileName = KFileDialog::getSaveFileName( fileName , "Save as Event template", this );
369 if ( fileName.length() > 0 )
370 saveTemplate( fileName );
371}
372
373void KOEventEditor::saveTemplate( const QString &templateName )
374{
375 Event *event = new Event;
376 writeEvent( event );
377 saveAsTemplate( event, templateName );
378}