summaryrefslogtreecommitdiffstats
path: root/korganizer/actionmanager.h
blob: ebfed515560f4af121edb31d371258b920add1e7 (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
/*
    This file is part of KOrganizer.

    Copyright (c) 2002 Mike Pilone <[email protected]>
    Copyright (c) 2002 Don Sanders <[email protected]>
    Copyright (c) 2003,2004 Cornelius Schumacher <[email protected]>
    Copyright (C) 2003-2004 Reinhold Kainhofer <[email protected]>

    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 TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/
#ifndef KORG_ACTIONMANAGER_H
#define KORG_ACTIONMANAGER_H

#include <tqobject.h>
#include <kurl.h>
#include <korganizer/part.h>
#include <kdemacros.h>

#include "kcalendariface.h"

namespace KCal
{
  class Calendar;
  class CalendarResources;
  class Incidence;
  class ResourceCalendar;
}
namespace KOrg {
  class MainWindow;
}

class TDEAction;
class TDEActionCollection;
class TDERecentFilesAction;
class TDESelectAction;
class TDEToggleAction;
class TDEConfig;
class TDEProcess;
class KTempFile;
class KXMLGUIClient;
class CalendarView;
class KOrganizer;
class KONewStuff;
class KOWindowList;
class PreviewDialog;
class ResourceView;
class HTMLExportSettings;

using namespace KCal;

/**
  The ActionManager creates all the actions in KOrganizer. This class
  is shared between the main application and the part so all common
  actions are in one location.
  It also provides DCOP interface[s].
*/
class KDE_EXPORT ActionManager : public TQObject, public KCalendarIface
{
    Q_OBJECT
  
  public:
    ActionManager( KXMLGUIClient *client, CalendarView *widget,
                   TQObject *parent, KOrg::MainWindow *mainWindow,
                   bool isPart );
    virtual ~ActionManager();

    /** Peform initialization that requires this* to be full constructed */
    void init();

    CalendarView *view() const { return mCalendarView; }

    /**
      Create Calendar object based on local file and set it on the view.
    */
    void createCalendarLocal();
    /**
      Create Calendar object based on the resource framework and set it on the
      view.
    */
    void createCalendarResources();

    /**
      Save calendar to disk.
    */
    void saveCalendar();

    /**
      Save the resource based calendar. Return false if an error occured and the
      user decidec to not ignore the error. Otherwise it returns true.
    */
    bool saveResourceCalendar();

    /**
      Load the resource based calendar.
    */
    void loadResourceCalendar();

  public slots:
    /** Add a new resource */
    bool addResource( const KURL &mUrl );
    /**
      Open calendar file from URL. Merge into current calendar, if \a merge is
      true.
    */
    bool openURL( const KURL &url, bool merge = false );
    /** Save calendar file to URL of current calendar */
    bool saveURL();
    /** Save calendar file to URL */
    bool saveAsURL( const KURL &kurl );
    /** Save calendar if it is modified by the user. Ask user what to do. */
    bool saveModifiedURL();

    void exportHTML();
    void exportHTML( HTMLExportSettings * );
  public:
    /** Get current URL */
    KURL url() const { return mURL; }

    /** Is there a instance with this URL? */
    static KOrg::MainWindow* findInstance( const KURL &url );
    /** Open calendar file from URL */
    bool openURL( const TQString &url );
    /** Open calendar file from URL */
    bool mergeURL( const TQString &url );
    /** Save calendar file to URL */
    bool saveAsURL( const TQString &url );
    /** Close calendar file opened from URL */
    void closeURL();
    /** Get current URL as TQString */
    TQString getCurrentURLasString() const;
    /**
      Delete the incidence with the given unique id from current calendar.
      @param uid UID of the incidence to delete.
      @param force If true, all recurrences and sub-todos (if applicable) will be
                         deleted without prompting for confirmation.
    */
    virtual bool deleteIncidence( const TQString& uid, bool force = false );

    bool editIncidence( const TQString &uid );
    bool editIncidence( const TQString &uid, const TQDate &date );

    /**
      Add an incidence to the active calendar.
      @param ical A calendar in iCalendar format containing the incidence.
    */

    bool addIncidence( const TQString& ical );

    //// Implementation of the DCOP interface
    virtual ResourceRequestReply resourceRequest( const TQValueList<TQPair<TQDateTime, TQDateTime> >& busy,
                                                  const TQCString& resource,
                                                  const TQString& vCalIn );

    void openEventEditor( const TQString& );
    void openEventEditor( const TQString& summary,
                          const TQString& description,
                          const TQString& attachment );
    void openEventEditor( const TQString& summary,
                          const TQString& description,
                          const TQString& attachment,
                          const TQStringList& attendees );
    void openEventEditor( const TQString& summary,
                          const TQString& description,
                          const TQString& uri,
                          const TQString& file,
                          const TQStringList& attendees,
                          const TQString& attachmentMimetype );

    void openTodoEditor( const TQString& );
    void openTodoEditor( const TQString& summary,
                         const TQString& description,
                         const TQString& attachment );
    void openTodoEditor( const TQString& summary,
                         const TQString& description,
                         const TQString& attachment,
                         const TQStringList& attendees );
    void openTodoEditor( const TQString& summary,
                         const TQString& description,
                         const TQString& uri,
                         const TQString& file,
                         const TQStringList& attendees,
                         const TQString& attachmentMimetype,
                         bool isTask );

    void openJournalEditor( const TQDate& date );
    void openJournalEditor( const TQString& text, const TQDate& date );
    void openJournalEditor( const TQString& text );
   //TODO:
   // void openJournalEditor( const TQString& summary,
   //                         const TQString& description,
   //                         const TQString& attachment );

    void showJournalView();
    void showTodoView();
    void showEventView();

    void goDate( const TQDate& );
    void goDate( const TQString& );
    void showDate( const TQDate &date );

    TQString localFileName();

    bool queryClose();

    void loadProfile( const TQString & path );

    void saveToProfile( const TQString & path ) const;

    bool handleCommandLine();

  signals:
    /**
      Emitted when the "New" action is activated.
    */
    void actionNew( const KURL &url = KURL() );

    /**
      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 topwidget is closing down, so that any attached
      child windows can also close.
    */
    void closingDown();

    /** Indicates that a new resource was added */
    void resourceAdded( ResourceCalendar * );

  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();

    void setDestinationPolicy();

    void processIncidenceSelection( Incidence *incidence, const TQDate &date );
    void keyBindings();

    /**
      Using the TDEConfig associated with the kapp variable, read in the
      settings from the config file.
    */
    void readSettings();

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

    /* Session management */
    void saveProperties( TDEConfig * );
    void readProperties( TDEConfig * );

    void loadParts();

    void importCalendar( const KURL &url );

  protected slots:

    /** open new window */
    void file_new();

    /** open a file, load it into the calendar. */
    void file_open();

    /** open a file from the list of recent files. Also called from file_open()
        after the URL is obtained from the user. */
    void file_open( const KURL &url );

    /** import a calendar from another program like ical. */
    void file_icalimport();

    /** open a calendar and add the contents to the current calendar. */
    void file_merge();

    /** revert to saved */
    void file_revert();

    /** delete or archive old entries in your calendar for speed/space. */
    void file_archive();

    /** save a file with the current fileName. */
    void file_save();

    /** save a file under a (possibly) different filename. */
    void file_saveas();

    /** close a file, prompt for save if changes made. */
    void file_close();

    /** Open kcontrol module for configuring date and time formats */
    void configureDateTime();

    /** Show tip of the day */
    void showTip();

    /** Show tip of the day */
    void showTipOnStart();

    void downloadNewStuff();
    void uploadNewStuff();

    void toggleResourceButtons();

    void toggleDateNavigator();
    void toggleTodoView();
    void toggleEventViewer();
    void toggleResourceView();

    /** called by the autoSaveTimer to automatically save the calendar */
    void checkAutoSave();

    /** connected to CalendarView's signal which comes from the ArchiveDialog */
    void slotAutoArchivingSettingsModified();

    /** called by the auto archive timer to automatically delete/archive events */
    void slotAutoArchive();

    void configureDateTimeFinished(TDEProcess *);

    void setTitle();

    void updateUndoAction( const TQString & );

    void updateRedoAction( const TQString & );

    void slotPreviewDialogFinished( PreviewDialog * );

  protected:
    /** Get URL for saving. Opens FileDialog. */
    KURL getSaveURL();

    void showStatusMessageOpen( const KURL &url, bool merge );

    void initCalendar( Calendar *cal );

    /**
      Return widget used as parent for dialogs and message boxes.
    */
    TQWidget *dialogParent();

  private slots:
    void dumpText( const TQString & );  // only for debugging purposes

  private:
    class ActionStringsVisitor;

    /** Create all the actions. */
    void initActions();
    void enableIncidenceActions( bool enable );

    TQPair<ResourceCalendar *, TQString> viewSubResourceCalendar();
    bool isWritable( ResourceCalendar *res, const TQString &subRes, const TQString &contentsType );

    KOrg::Part::List mParts; // List of parts loaded
    KURL mURL;      // URL of calendar file
    TQString mFile;  // Local name of calendar file
    TQString mLastUrl;  // URL of last loaded calendar.

    KTempFile *mTempFile;
    TQTimer *mAutoSaveTimer;   // used if calendar is to be autosaved
    TQTimer *mAutoArchiveTimer; // used for the auto-archiving feature

    // list of all existing KOrganizer instances
    static KOWindowList *mWindowList;

    // Actions
    TDERecentFilesAction *mRecent;
    TDEToggleAction *mResourceButtonsAction;

    TDEToggleAction *mDateNavigatorShowAction;
    TDEToggleAction *mTodoViewShowAction;
    TDEToggleAction *mResourceViewShowAction;
    TDEToggleAction *mEventViewerShowAction;
//     TDEToggleAction *mToggleAlarmAction;

    TDEAction *mShowIncidenceAction;
    TDEAction *mEditIncidenceAction;
    TDEAction *mDeleteIncidenceAction;
//     TDEAction *mAssignResourceAction;

    TDEAction *mCutAction;
    TDEAction *mCopyAction;
    TDEAction *mDeleteAction;
    TDEAction *mNextXDays;
    TDEAction *mPublishEvent;
    TDEAction *mForwardEvent;

    TDEAction *mSendInvitation;
    TDEAction *mSendCancel;
    TDEAction *mSendStatusUpdate;

    TDEAction *mRequestChange;
    TDEAction *mRequestUpdate;

    TDEAction *mUndoAction;
    TDEAction *mRedoAction;

    TDESelectAction *mFilterAction;

    KXMLGUIClient *mGUIClient;
    TDEActionCollection *mACollection;
    CalendarView *mCalendarView;
    KOrg::MainWindow *mMainWindow;
    bool mIsPart;

    KONewStuff *mNewStuff;
    bool mHtmlExportSync;

    // Either mCalendar *or* mCalendarResources is set.
    Calendar *mCalendar;
    CalendarResources *mCalendarResources;

    ResourceView *mResourceView;

    bool mIsClosing;
};

#endif