korganizer

kodialogmanager.cpp
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program 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
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 As a special exception, permission is given to link this program
22 with any edition of TQt, and distribute the resulting executable,
23 without including the source code for TQt in the source distribution.
24*/
25
26#include <kcmultidialog.h>
27#include <ksettings/dialog.h>
28#include <twin.h>
29
30#include <libtdepim/categoryeditdialog.h>
31
32#include "calendarview.h"
33#include "koprefsdialog.h"
34#include "koprefs.h"
35#include "koeventeditor.h"
36#include "kotodoeditor.h"
37#include "kojournaleditor.h"
38#include "searchdialog.h"
39#include "filtereditdialog.h"
40#ifndef KORG_NOARCHIVE
41#include "archivedialog.h"
42#endif
43#include "koviewmanager.h"
44#include "koagendaview.h"
45#include "koglobals.h"
46
47#include "kodialogmanager.h"
48#include "kodialogmanager.moc"
49
50
51// FIXME: Handle KOEventViewerDialogs in dialog manager. Pass
52// KOPrefs::mCompactDialog.
53
54class KODialogManager::DialogManagerVisitor : public IncidenceBase::Visitor
55{
56 public:
57 DialogManagerVisitor() : mDialogManager( 0 ) {}
58
59 bool act( IncidenceBase *incidence, KODialogManager *manager )
60 {
61 mDialogManager = manager;
62 return incidence->accept( *this );
63 }
64
65 protected:
66 KODialogManager *mDialogManager;
67};
68
69class KODialogManager::EditorDialogVisitor :
70 public KODialogManager::DialogManagerVisitor
71{
72 public:
73 EditorDialogVisitor() : DialogManagerVisitor(), mEditor( 0 ) {}
74 KOIncidenceEditor *editor() const { return mEditor; }
75 protected:
76 bool visit( Event * ) { mEditor = mDialogManager->getEventEditor(); return mEditor; }
77 bool visit( Todo * ) { mEditor = mDialogManager->getTodoEditor(); return mEditor; }
78 bool visit( Journal * ) { mEditor = mDialogManager->getJournalEditor(); return mEditor; }
79 protected:
80 KOIncidenceEditor *mEditor;
81};
82
83
84KODialogManager::KODialogManager( CalendarView *mainView ) :
85 TQObject(), mMainView( mainView )
86{
87 mOptionsDialog = 0;
88 mSearchDialog = 0;
89 mArchiveDialog = 0;
90 mFilterEditDialog = 0;
91
92 mCategoryEditDialog = new KPIM::CategoryEditDialog( KOPrefs::instance(), mMainView );
93 // don't set any specific parent for the dialog, as its kept around and reused
94 // in different cases where it should have different parents
95 KWin::setMainWindow( mCategoryEditDialog, 0 );
96 connect( mainView, TQ_SIGNAL( categoriesChanged() ),
97 mCategoryEditDialog, TQ_SLOT( reload() ) );
98 KOGlobals::fitDialogToScreen( mCategoryEditDialog );
99}
100
101KODialogManager::~KODialogManager()
102{
103 delete mOptionsDialog;
104 delete mSearchDialog;
105#ifndef KORG_NOARCHIVE
106 delete mArchiveDialog;
107#endif
108 delete mFilterEditDialog;
109}
110
111void KODialogManager::errorSaveIncidence( TQWidget *parent, Incidence *incidence )
112{
113 KMessageBox::sorry( parent, i18n("Unable to save %1 \"%2\".")
114 .arg( i18n( incidence->type() ) )
115 .arg( incidence->summary() ) );
116}
117
118void KODialogManager::showOptionsDialog()
119{
120 if (!mOptionsDialog) {
121#if 0
122 mOptionsDialog = new TDEConfigureDialog();
123// mOptionsDialog = new TDEConfigureDialog( TDEConfigureDialog::Configurable );
124// mOptionsDialog = new TDEConfigureDialog( mMainView );
125 connect( mOptionsDialog->dialog(),
126 TQ_SIGNAL( configCommitted( const TQCString & ) ),
127 mMainView, TQ_SLOT( updateConfig() ) );
128#else
129 mOptionsDialog = new KCMultiDialog( mMainView, "KorganizerPreferences" );
130 connect( mOptionsDialog, TQ_SIGNAL( configCommitted( const TQCString & ) ),
131 mMainView, TQ_SLOT( updateConfig( const TQCString& ) ) );
132#if 0
133 connect( mOptionsDialog, TQ_SIGNAL( applyClicked() ),
134 mMainView, TQ_SLOT( updateConfig() ) );
135 connect( mOptionsDialog, TQ_SIGNAL( okClicked() ),
136 mMainView, TQ_SLOT( updateConfig() ) );
137 // @TODO Find a way to do this with KCMultiDialog
138 connect(mCategoryEditDialog,TQ_SIGNAL(categoryConfigChanged()),
139 mOptionsDialog,TQ_SLOT(updateCategories()));
140#endif
141
142 TQStringList modules;
143
144 modules.append( "korganizer_configmain.desktop" );
145 modules.append( "korganizer_configtime.desktop" );
146 modules.append( "korganizer_configviews.desktop" );
147 modules.append( "korganizer_configfonts.desktop" );
148 modules.append( "korganizer_configcolors.desktop" );
149 modules.append( "korganizer_configgroupscheduling.desktop" );
150 modules.append( "korganizer_configgroupautomation.desktop" );
151 modules.append( "korganizer_configfreebusy.desktop" );
152 modules.append( "korganizer_configplugins.desktop" );
153 modules.append( "korganizer_configdesignerfields.desktop" );
154
155 // add them all
156 TQStringList::iterator mit;
157 for ( mit = modules.begin(); mit != modules.end(); ++mit )
158 mOptionsDialog->addModule( *mit );
159#endif
160 }
161
162 mOptionsDialog->show();
163 mOptionsDialog->raise();
164}
165
166void KODialogManager::showCategoryEditDialog()
167{
168 mCategoryEditDialog->show();
169}
170
171void KODialogManager::showSearchDialog()
172{
173 if ( !mSearchDialog ) {
174 mSearchDialog = new SearchDialog( mMainView->calendar(), mMainView );
175 connect( mSearchDialog, TQ_SIGNAL(showIncidenceSignal(Incidence *,const TQDate &)),
176 mMainView, TQ_SLOT(showIncidence(Incidence *,const TQDate &)) );
177 connect( mSearchDialog, TQ_SIGNAL(editIncidenceSignal(Incidence *,const TQDate &)),
178 mMainView, TQ_SLOT(editIncidence(Incidence *,const TQDate &)) );
179 connect( mSearchDialog, TQ_SIGNAL(deleteIncidenceSignal(Incidence *)),
180 mMainView, TQ_SLOT(deleteIncidence(Incidence *)) );
181 connect( mMainView, TQ_SIGNAL(closingDown()),mSearchDialog,TQ_SLOT(reject()) );
182 }
183 // make sure the widget is on top again
184 mSearchDialog->show();
185 mSearchDialog->raise();
186}
187
188void KODialogManager::showArchiveDialog()
189{
190#ifndef KORG_NOARCHIVE
191 if (!mArchiveDialog) {
192 mArchiveDialog = new ArchiveDialog(mMainView->calendar(),mMainView);
193 connect(mArchiveDialog,TQ_SIGNAL(eventsDeleted()),
194 mMainView,TQ_SLOT(updateView()));
195 connect(mArchiveDialog,TQ_SIGNAL(autoArchivingSettingsModified()),
196 mMainView,TQ_SLOT(slotAutoArchivingSettingsModified()));
197 }
198 mArchiveDialog->show();
199 mArchiveDialog->raise();
200
201 // Workaround.
202 TQApplication::restoreOverrideCursor();
203#endif
204}
205
206void KODialogManager::showFilterEditDialog( TQPtrList<CalFilter> *filters )
207{
208 if ( !mFilterEditDialog ) {
209 mFilterEditDialog = new FilterEditDialog( filters, mMainView );
210 connect( mFilterEditDialog, TQ_SIGNAL( filterChanged() ),
211 mMainView, TQ_SLOT( updateFilter() ) );
212 connect( mFilterEditDialog, TQ_SIGNAL( editCategories() ),
213 mCategoryEditDialog, TQ_SLOT( show() ) );
214 connect( mCategoryEditDialog, TQ_SIGNAL( categoryConfigChanged() ),
215 mFilterEditDialog, TQ_SLOT( updateCategoryConfig() ) );
216 }
217 mFilterEditDialog->show();
218 mFilterEditDialog->raise();
219}
220
222{
223 if ( !incidence ) return 0;
224 EditorDialogVisitor v;
225 if ( v.act( incidence, this ) ) {
226 return v.editor();
227 } else
228 return 0;
229}
230
232{
233 KOEventEditor *eventEditor = new KOEventEditor( mMainView->calendar(),
234 mMainView );
235 connectEditor( eventEditor );
236 return eventEditor;
237}
238
239void KODialogManager::connectTypeAhead( KOEventEditor *editor,
240 KOrg::AgendaView *agenda )
241{
242 if ( editor && agenda ) {
243 agenda->setTypeAheadReceiver( editor->typeAheadReceiver() );
244 connect( editor, TQ_SIGNAL( focusReceivedSignal() ),
245 agenda, TQ_SLOT( finishTypeAhead() ) );
246 }
247}
248
249void KODialogManager::connectEditor( KOIncidenceEditor*editor )
250{
251 connect( editor, TQ_SIGNAL( deleteIncidenceSignal( Incidence * ) ),
252 mMainView, TQ_SLOT( deleteIncidence( Incidence * ) ) );
253
254 connect( mCategoryEditDialog, TQ_SIGNAL( categoryConfigChanged() ),
255 editor, TQ_SIGNAL( updateCategoryConfig() ) );
256 connect( editor, TQ_SIGNAL( editCategories() ),
257 mCategoryEditDialog, TQ_SLOT( show() ) );
258
259 connect( editor, TQ_SIGNAL( dialogClose( Incidence * ) ),
260 mMainView, TQ_SLOT( dialogClosing( Incidence * ) ) );
261 connect( editor, TQ_SIGNAL( editCanceled( Incidence * ) ),
262 mMainView, TQ_SLOT( editCanceled( Incidence * ) ) );
263 connect( mMainView, TQ_SIGNAL( closingDown() ), editor, TQ_SLOT( reject() ) );
264
265 connect( editor, TQ_SIGNAL( deleteAttendee( Incidence * ) ),
266 mMainView, TQ_SIGNAL( cancelAttendees( Incidence * ) ) );
267}
268
270{
271 kdDebug(5850) << k_funcinfo << endl;
272 KOTodoEditor *todoEditor = new KOTodoEditor( mMainView->calendar(), mMainView );
273 connectEditor( todoEditor );
274 return todoEditor;
275}
276
278{
279 KOJournalEditor *journalEditor = new KOJournalEditor( mMainView->calendar(), mMainView );
280 connectEditor( journalEditor );
281 return journalEditor;
282}
283
284void KODialogManager::updateSearchDialog()
285{
286 if (mSearchDialog) mSearchDialog->updateView();
287}
288
This is the main calendar widget.
Definition: calendarview.h:82
This is the class to add/edit a calendar filter.
virtual bool visit(FreeBusy *)
virtual bool accept(Visitor &)
TQString summary() const
This class manages the dialogs used by the calendar view.
KOJournalEditor * getJournalEditor()
Get an editor dialog for a Journal.
KOIncidenceEditor * getEditor(Incidence *)
Get the appropriate editor for the given incidence.
KOEventEditor * getEventEditor()
Get an editor dialog for an Event.
KOTodoEditor * getTodoEditor()
Get an editor dialog for a Todo.
This class provides a dialog for editing an event.
Definition: koeventeditor.h:49
This is the base class for the calendar component editors.
This class provides a dialog for editing a Journal.
This class provides a dialog for editing a Todo.
Definition: kotodoeditor.h:38
Base class for single/multi agenda views.
Definition: agendaview.h:28