summaryrefslogtreecommitdiffstats
path: root/korganizer/calendarview.h
blob: a3e9a9ab36596a76ecd86924b5f8f1300f000074 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*
    This file is part of KOrganizer.

    Copyright (c) 2000,2001,2003,2004 Cornelius Schumacher <schumacher@kde.org>
    Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/
#ifndef CALENDARVIEW_H
#define CALENDARVIEW_H

#include <tqwidget.h>
#include <tqptrlist.h>
#include <tqmap.h>
#include <kfile.h>
#include <korganizer/koeventviewer.h>
#include <libkcal/scheduler.h>
#include <kdepimmacros.h>

#include <korganizer/calendarviewbase.h>

class QWidgetStack;
class QSplitter;

class KOViewManager;
class KODialogManager;
class KOTodoView;
class KOEventEditor;
class DateNavigatorContainer;
class DateNavigator;
class KOIncidenceEditor;
class ResourceView;
class NavigatorBar;
class DateChecker;

namespace KOrg { class History; class IncidenceChangerBase; }
class HTMLExportSettings;

using namespace KOrg;
using namespace KCal;

class CalendarViewExtension : public QWidget
{
  public:
    CalendarViewExtension( TQWidget *parent, const char *name = 0 )
      : TQWidget( parent, name ) {}

    class Factory
    {
      public:
        virtual CalendarViewExtension *create( TQWidget *parent ) = 0;
    };
};

/**
  This is the main calendar widget. It provides the different views on the
  calendar data as well as the date navigator. It also handles synchronization
  of the different views and controls the different dialogs like preferences,
  event editor, search dialog etc.

  @short main calendar view widget
  @author Cornelius Schumacher
*/
class KDE_EXPORT CalendarView : public KOrg::CalendarViewBase, public Calendar::Observer
{
    Q_OBJECT
  public:
    /**
      Constructs a new calendar view widget.

      @param parent   parent window
      @param name     Qt internal widget object name
    */
    CalendarView( TQWidget *parent = 0, const char *name = 0 );
    virtual ~CalendarView();


    class CalendarViewVisitor : public IncidenceBase::Visitor
    {
      public:
        CalendarViewVisitor() : mView( 0 ) {}
        bool act( IncidenceBase *incidence, CalendarView *view )
        {
          mView = view;
          return incidence->accept( *this );
        }
      protected:
        CalendarView *mView;
    };

    class CanDeleteIncidenceVisitor : public CalendarViewVisitor
    {
      protected:
        bool visit( Event *event ) { return mView->deleteEvent( event ); }
        bool visit( Todo *todo ) { return mView->deleteTodo( todo ); }
        bool visit( Journal *journal ) { return mView->deleteJournal( journal ); }
    };


    void setCalendar( Calendar * );
    Calendar *calendar();

    KOrg::History *history() const { return mHistory; }

    KOViewManager *viewManager() const { return mViewManager; }
    KODialogManager *dialogManager() const { return mDialogManager; }

    TQWidgetStack *viewStack() const { return mRightFrame; }
    TQWidget *leftFrame() const { return mLeftFrame; }
    NavigatorBar *navigatorBar() const { return mNavigatorBar; }
    DateNavigator *dateNavigator() const { return mNavigator; }

    KOIncidenceEditor *editorDialog( Incidence* ) const;
    IncidenceChangerBase *incidenceChanger() const { return mChanger; }

    TQDate startDate();
    TQDate endDate();


    void addView( KOrg::BaseView * );
    void showView( KOrg::BaseView * );

    /**
      Add calendar view extension widget. CalendarView takes ownership of the
      objects created by the factory.
    */
    void addExtension( CalendarViewExtension::Factory * );

    /** currentSelection() returns a pointer to the incidence selected in the current view */
    Incidence *currentSelection();
    /** Return a pointer to the incidence selected in the current view. If there
        is no selection, return the selected todo from the todo list on the left */
    Incidence *selectedIncidence();
    /** Returns the name of the current filter */
    TQString currentFilterName() const;

  signals:
    /** when change is made to options dialog, the topwidget will catch this
     *  and emit this signal which notifies all widgets which have registered
     *  for notification to update their settings. */
    void configChanged();
    /** Emitted when the categories were updated, and thus the categories editor
     *  dialog needs to reload the list of categories */
    void categoriesChanged();
    /** emitted when the topwidget is closing down, so that any attached
        child windows can also close. */
    void closingDown();
    /** emitted right before we die */
    void closed( TQWidget * );

    /** Emitted when state of modified flag changes */
    void modifiedChanged( bool );

    /** Emitted when state of read-only flag changes */
    void readOnlyChanged( bool );

    /** Emitted when the unit of navigation changes */
    void changeNavStringPrev( const TQString & );
    void changeNavStringNext( const TQString & );

    /** Emitted when state of events selection has changed and user is organizer*/
    void organizerEventsSelected( bool );
    /** Emitted when state of events selection has changed and user is attendee*/
    void groupEventsSelected( bool );
    /**
      Emitted when an incidence gets selected. If the selection is cleared the
      signal is emitted with 0 as argument.
    */
    void incidenceSelected( Incidence * );
    /** Emitted, when a todoitem is selected or deselected.
        the connected slots enables/disables the corresponding menu items */
    void todoSelected( bool );
    void subtodoSelected( bool );

    /** Emitted, when a day changed (i.e. korganizer was running at midnight).
        The argument is the new date */
    void dayPassed( const TQDate & );
    /**
      Attendees were removed from this incidence. Only the removed attendees
      are present in the incidence, so we just need to send a cancel messages
      to all attendees groupware messages are enabled at all.
    */
    void cancelAttendees( Incidence * );


    /**
      Emitted, when clipboard content changes. Parameter indicates if paste
      is possible or not.
    */
    void pasteEnabled( bool );
    /** Send status message, which can e.g. be displayed in the status bar. */
    void statusMessage( const TQString & );

    void calendarViewExpanded( bool );

    /** Emitted when auto-archiving options were modified */
    void autoArchivingSettingsModified();

    void newIncidenceChanger( IncidenceChangerBase* );
    void exportHTML( HTMLExportSettings* );

    void newFilterListSignal( const TQStringList & );
    void selectFilterSignal( int );
    void filterChanged();

  public slots:
    /** options dialog made a changed to the configuration. we catch this
     *  and notify all widgets which need to update their configuration. */
    void updateConfig( const TQCString& );
    /** Calendar configuration was changed, so refresh categories list
    */
    void updateCategories();


    /**
      Load calendar from file \a filename. If \a merge is true, load
      calendar into existing one, if it is false, clear calendar, before
      loading. Return true, if calendar could be successfully loaded.
    */
    bool openCalendar( const TQString &filename, bool merge = false );

    /**
      Save calendar data to file. Return true if calendar could be
      successfully saved.
    */
    bool saveCalendar( const TQString &filename );

    /**
      Close calendar. Clear calendar data and reset views to display an empty
      calendar.
    */
    void closeCalendar();

    /** Archive old events of calendar */
    void archiveCalendar();

    void showIncidence();
    void editIncidence();
    bool editIncidence( const TQString& uid );
    void deleteIncidence();

    /**
      Add an incidence to the active calendar.
      @param ical A calendar in iCalendar format containing the incidence. The
                  calendar must consist of a VCALENDAR component which contains
                  the incidence (VEVENT, VTODO, VJOURNAL or VFREEBUSY) and
                  optionally a VTIMEZONE component. If there is more than one
                  incidence, only the first is added to KOrganizer's calendar.
    */
    bool addIncidence( const TQString &ical );

    void connectIncidenceEditor( KOIncidenceEditor * );

    /** create new event without having a date hint. Takes current date as
     default hint. */
    void newEvent();
    /** create an editeventwin with supplied date/time, and if bool is true,
     * make the event take all day. */
    void newEvent( const TQDate &startDt );
    void newEvent( const TQDateTime &startDt );
    void newEvent( const TQDateTime &startDt, const TQDateTime &EndDt, bool allDay = false );
    /**
      Create new Event from given summary, description, attachment list and
      attendees list
    */
    void newEvent( const TQString &summary, const TQString &description = TQString::null,
                   const TQStringList &attachment = TQStringList(), const TQStringList &attendees = TQStringList(),
                   const TQStringList &attachmentMimetypes = TQStringList(), bool inlineAttachment = false );
    void newFloatingEvent();

    /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
    void showIncidence( Incidence * );
    /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
    bool editIncidence( Incidence *incidence, bool isCounter = false );
    /**
      Delete the supplied incidence. It calls the correct deleteXXX method
      @param force If true, all recurrences and sub-todos (if applicable) will be
                   deleted without prompting for confirmation.
    */
    void deleteIncidence( Incidence *, bool force = false );
    /**
      Cuts the selected incidence using the edit_cut() method
    */
    void cutIncidence( Incidence * );
    /**
      Copies the selected incidence using the edit_copy() method
    */
    void copyIncidence( Incidence *);
    /**
      Pastes the curren incidence using the edit_paste() method
    */
    void pasteIncidence();

    /** Delete the supplied todo and all sub-todos */
    void deleteSubTodosIncidence ( Todo *todo );
    /**
      Delete the todo incidence, and its sub-to-dos.
      @param todo The todo to delete.
      @param force If true, all sub-todos will be deleted without prompting for confirmation.
    */
    void deleteTodoIncidence ( Todo *todo, bool force = false );
    /** Check if deleting the supplied event is allowed. */
    bool deleteEvent( Event * ) { return true; }
    /** Check if deleting the todo is allowed */
    bool deleteTodo( Todo * ) {return true; }
    /** Check if deleting the supplied journal is allowed. */
    bool deleteJournal( Journal * ) { return true; }
    /**
      Delete the incidence with the given unique ID. Returns false, if event wasn't found.
      @param uid The UID of the incidence to delete.
      @param force If true, all recurrences and sub-todos (if applicable) will be
                   deleted without prompting for confirmation.
    */
    bool deleteIncidence( const TQString &uid, bool force = false );

    /** create new todo */
    void newTodo();
    /** create new todo, due on date */
    void newTodo( const TQDate &date );
    /** create new todo with a parent todo */
    void newSubTodo();
    /** create new todo with a parent todo */
    void newSubTodo( Todo * );

    void newTodo( const TQString &summary, const TQString &description = TQString::null,
                  const TQStringList &attachments = TQStringList(), const TQStringList &attendees = TQStringList(),
                  const TQStringList &attachmentMimetypes = TQStringList(), bool inlineAttachment = false );

    void newJournal();
    void newJournal( const TQDate &date );
    void newJournal( const TQString &text, const TQDate &date = TQDate() );

    void toggleAlarm( Incidence * );
    void dissociateOccurrence( Incidence *, const TQDate & );
    void dissociateFutureOccurrence( Incidence *, const TQDate & );


    /**
      Check if clipboard contains vCalendar event. The signal pasteEnabled() is
      emitted as result.
    */
    void checkClipboard();

    /**
      Using the KConfig associated with the kapp variable, read in the
      settings from the config file.

      You have to call setCalendar before calling readSettings.
    */
    void readSettings();

    /** write current state to config file. */
    void writeSettings();

    /** read settings for calendar filters */
    void readFilterSettings( KConfig *config );

    /** write settings for calendar filters */
    void writeFilterSettings( KConfig *config );

    /** passes on the message that an event has changed to the currently
     * activated view so that it can make appropriate display changes. */
    void changeIncidenceDisplay( Incidence *, int );

    void incidenceAdded( Incidence * );
    void incidenceChanged( Incidence *oldEvent, Incidence *newEvent );
    void incidenceChanged( Incidence *oldEvent, Incidence *newEvent, int what );
    void incidenceToBeDeleted( Incidence *incidence );
    void incidenceDeleted( Incidence * );
    void startMultiModify( const TQString &text );
    void endMultiModify();

    void editCanceled( Incidence * );

    void updateView( const TQDate &start, const TQDate &end );
    void updateView();

    void updateUnmanagedViews();

    /** cut the current appointment to the clipboard */
    void edit_cut();

    /** copy the current appointment(s) to the clipboard */
    void edit_copy();

    /** paste the current vobject(s) in the clipboard buffer into calendar */
    void edit_paste();

    /** edit viewing and configuration options. */
    void edit_options();

    /**
      Functions for printing, previewing a print, and setting up printing
      parameters.
    */
    void print();

    /** Export as HTML file */
    void exportWeb();

    /** Export as iCalendar file */
    void exportICalendar();

    /** Export as vCalendar file */
    void exportVCalendar();

    /** pop up a dialog to show an existing appointment. */
    void appointment_show();
    /**
     * pop up an Appointment Dialog to edit an existing appointment. Get
     * information on the appointment from the list of unique IDs that is
     * currently in the View, called currIds.
     */
    void appointment_edit();
    /**
     * pop up dialog confirming deletion of currently selected event in the
     * View.
     */
    void appointment_delete();

    /* frees a subtodo from it's relation, update the view */
    void todo_unsub();
    /* Free a subtodo from it's relation, without update the view */
    bool todo_unsub( Todo *todo );
    /** Make all sub-to-dos of todo independents, update the view*/
    bool makeSubTodosIndependents ( );
    /** Make all sub-to-dos of todo independents, not update the view*/
    bool makeSubTodosIndependents ( Todo *todo );

    /** Take ownership of selected event. */
    void takeOverEvent();

    /** Take ownership of all events in calendar. */
    void takeOverCalendar();

    /** query whether or not the calendar is "dirty". */
    bool isModified();
    /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
    void setModified( bool modified = true );

    /** query if the calendar is read-only. */
    bool isReadOnly();
    /** set state of calendar to read-only */
    void setReadOnly( bool readOnly = true );

    void eventUpdated( Incidence * );

    /* iTIP scheduling actions */
    void schedule_publish( Incidence *incidence = 0 );
    void schedule_request( Incidence *incidence = 0 );
    void schedule_refresh( Incidence *incidence = 0 );
    void schedule_cancel( Incidence *incidence = 0 );
    void schedule_add( Incidence *incidence = 0 );
    void schedule_reply( Incidence *incidence = 0 );
    void schedule_counter( Incidence *incidence = 0 );
    void schedule_declinecounter( Incidence *incidence = 0 );
    void schedule_forward( Incidence *incidence = 0 );
    void mailFreeBusy( int daysToPublish = 30 );
    void uploadFreeBusy();

    void openAddressbook();

    void editFilters();

    void updateFilter();

    void showIntro();

    void showDateNavigator( bool );
    void showTodoView( bool );
    void showEventViewer( bool );

    /** Move the current view date to the specified date */
    void goDate( const TQDate& date );

    /** Show the given date without changing date selection length. */
    void showDate( const TQDate &date );

    /** Move the current view date to today */
    void goToday();

    /** Move to the next date(s) in the current view */
    void goNext();

    /** Move to the previous date(s) in the current view */
    void goPrevious();

    void toggleExpand();
    void showLeftFrame( bool show = true );

    void dialogClosing( Incidence * );

    void processMainViewSelection( Incidence * );
    void processTodoListSelection( Incidence * );

    void processIncidenceSelection( Incidence * );

    void purgeCompleted();

    void slotCalendarChanged();

    void slotAutoArchivingSettingsModified() { emit autoArchivingSettingsModified(); }

    void showErrorMessage( const TQString & );
    void schedule( Scheduler::Method, Incidence *incidence );
    void addIncidenceOn( Incidence *, const TQDate & );
    void moveIncidenceTo( Incidence *, const TQDate & );
    void filterActivated( int filterNum );

    void resourcesChanged();

  protected slots:
    /** Select a view or adapt the current view to display the specified dates. */
    void showDates( const KCal::DateList & );

  public:
    // show a standard warning
    // returns KMsgBox::yesNoCancel()
    int msgCalModified();

    /** Adapt navigation units corresponding to step size of navigation of the
     * current view.
     */
    void adaptNavigationUnits();

    //Attendee* getYourAttendee( Event *event );

  protected:
    void setIncidenceChanger( IncidenceChangerBase *changer );

//     // returns KMsgBox::OKCancel()
    int msgItemDelete( Incidence *incidence );

    Todo *selectedTodo();

    void warningChangeFailed( Incidence * );
    void checkForFilteredChange( Incidence *incidence );
    /** Adjust the given date/times by valid defaults (selection or configured
        defaults, if invalid values are given) and allow the view to adjust the
        type. */
    void dateTimesForNewEvent( TQDateTime &startDt, TQDateTime &endDt, bool &allDay );
    KOEventEditor *newEventEditor( const TQDateTime &startDtParam = TQDateTime(),
         const TQDateTime &endDtParam = TQDateTime() , bool allDayParam = false );

  private:
    void init();

    void calendarModified( bool, Calendar * );
    // Helper function for purgeCompleted that recursively purges a todo and
    // its subitems. If it cannot delete a completed todo (because it has
    // uncompleted subitems), notAllPurged is set to true.
    bool purgeCompletedSubTodos( Todo* todo, bool &notAllPurged );

    KOrg::History *mHistory;

    TQSplitter    *mPanner;
    TQSplitter    *mLeftSplitter;
    TQWidget      *mLeftFrame;
    TQWidgetStack *mRightFrame;

    NavigatorBar *mNavigatorBar;

    DateNavigatorContainer *mDateNavigator;


    TQPtrList<CalendarViewExtension> mExtensions;

    Calendar *mCalendar;

    DateNavigator *mNavigator;
    DateChecker *mDateChecker;

    KOEventViewer *mEventViewer;
    KOViewManager *mViewManager;
    KODialogManager *mDialogManager;

    // Calendar filters
    TQPtrList<CalFilter> mFilters;
    CalFilter *mCurrentFilter;

    // various housekeeping variables.
    bool            mModified; // flag indicating if calendar is modified
    bool            mReadOnly; // flag indicating if calendar is read-only
    TQDate mSaveSingleDate;

    Incidence *mSelectedIncidence;

    KOTodoView *mTodoList;
    TQMap<Incidence*,KOIncidenceEditor*> mDialogList;

    KOrg::IncidenceChangerBase *mChanger;
};




#endif