korganizer

kodialogmanager.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <kcmultidialog.h>
00027 #include <ksettings/dialog.h>
00028 #include <kwin.h>
00029 
00030 #include <libkdepim/categoryeditdialog.h>
00031 
00032 #include "calendarview.h"
00033 #include "koprefsdialog.h"
00034 #include "koprefs.h"
00035 #include "koeventeditor.h"
00036 #include "kotodoeditor.h"
00037 #include "kojournaleditor.h"
00038 #include "searchdialog.h"
00039 #include "filtereditdialog.h"
00040 #ifndef KORG_NOARCHIVE
00041 #include "archivedialog.h"
00042 #endif
00043 #include "koviewmanager.h"
00044 #include "koagendaview.h"
00045 #include "koglobals.h"
00046 
00047 #include "kodialogmanager.h"
00048 #include "kodialogmanager.moc"
00049 
00050 
00051 // FIXME: Handle KOEventViewerDialogs in dialog manager. Pass
00052 // KOPrefs::mCompactDialog.
00053 
00054 class KODialogManager::DialogManagerVisitor : public IncidenceBase::Visitor
00055 {
00056   public:
00057     DialogManagerVisitor() : mDialogManager( 0 ) {}
00058 
00059     bool act( IncidenceBase *incidence, KODialogManager *manager )
00060     {
00061       mDialogManager = manager;
00062       return incidence->accept( *this );
00063     }
00064 
00065   protected:
00066     KODialogManager *mDialogManager;
00067 };
00068 
00069 class KODialogManager::EditorDialogVisitor : 
00070       public KODialogManager::DialogManagerVisitor
00071 {
00072   public:
00073     EditorDialogVisitor() : DialogManagerVisitor(), mEditor( 0 ) {}
00074     KOIncidenceEditor *editor() const { return mEditor; }
00075   protected:
00076     bool visit( Event * ) { mEditor = mDialogManager->getEventEditor(); return mEditor; }
00077     bool visit( Todo * ) { mEditor = mDialogManager->getTodoEditor(); return mEditor; }
00078     bool visit( Journal * ) { mEditor = mDialogManager->getJournalEditor(); return mEditor; }
00079   protected:
00080     KOIncidenceEditor *mEditor;
00081 };
00082 
00083 
00084 KODialogManager::KODialogManager( CalendarView *mainView ) :
00085   QObject(), mMainView( mainView )
00086 {
00087   mOptionsDialog = 0;
00088   mSearchDialog = 0;
00089   mArchiveDialog = 0;
00090   mFilterEditDialog = 0;
00091 
00092   mCategoryEditDialog = new KPIM::CategoryEditDialog( KOPrefs::instance(), mMainView );
00093   // don't set any specific parent for the dialog, as its kept around and reused
00094   // in different cases where it should have different parents
00095   KWin::setMainWindow( mCategoryEditDialog, 0 );
00096   connect( mainView, SIGNAL( categoriesChanged() ),
00097            mCategoryEditDialog, SLOT( reload() ) );
00098   KOGlobals::fitDialogToScreen( mCategoryEditDialog );
00099 }
00100 
00101 KODialogManager::~KODialogManager()
00102 {
00103   delete mOptionsDialog;
00104   delete mSearchDialog;
00105 #ifndef KORG_NOARCHIVE
00106   delete mArchiveDialog;
00107 #endif
00108   delete mFilterEditDialog;
00109 }
00110 
00111 void KODialogManager::errorSaveIncidence( QWidget *parent, Incidence *incidence )
00112 {
00113   KMessageBox::sorry( parent, i18n("Unable to save %1 \"%2\".")
00114                       .arg( i18n( incidence->type() ) )
00115                       .arg( incidence->summary() ) );
00116 }
00117 
00118 void KODialogManager::showOptionsDialog()
00119 {
00120   if (!mOptionsDialog) {
00121 #if 0
00122     mOptionsDialog = new KConfigureDialog();
00123 //    mOptionsDialog = new KConfigureDialog( KConfigureDialog::Configurable );
00124 //    mOptionsDialog = new KConfigureDialog( mMainView );
00125     connect( mOptionsDialog->dialog(),
00126              SIGNAL( configCommitted( const QCString & ) ),
00127              mMainView, SLOT( updateConfig() ) );
00128 #else
00129     mOptionsDialog = new KCMultiDialog( mMainView, "KorganizerPreferences" );
00130     connect( mOptionsDialog, SIGNAL( configCommitted( const QCString & ) ),
00131              mMainView, SLOT( updateConfig( const QCString& ) ) );
00132 #if 0
00133     connect( mOptionsDialog, SIGNAL( applyClicked() ),
00134              mMainView, SLOT( updateConfig() ) );
00135     connect( mOptionsDialog, SIGNAL( okClicked() ),
00136              mMainView, SLOT( updateConfig() ) );
00137     // @TODO Find a way to do this with KCMultiDialog
00138     connect(mCategoryEditDialog,SIGNAL(categoryConfigChanged()),
00139             mOptionsDialog,SLOT(updateCategories()));
00140 #endif
00141 
00142     QStringList modules;
00143 
00144     modules.append( "korganizer_configmain.desktop" );
00145     modules.append( "korganizer_configtime.desktop" );
00146     modules.append( "korganizer_configviews.desktop" );
00147     modules.append( "korganizer_configfonts.desktop" );
00148     modules.append( "korganizer_configcolors.desktop" );
00149     modules.append( "korganizer_configgroupscheduling.desktop" );
00150     modules.append( "korganizer_configgroupautomation.desktop" );
00151     modules.append( "korganizer_configfreebusy.desktop" );
00152     modules.append( "korganizer_configplugins.desktop" );
00153     modules.append( "korganizer_configdesignerfields.desktop" );
00154 
00155     // add them all
00156     QStringList::iterator mit;
00157     for ( mit = modules.begin(); mit != modules.end(); ++mit )
00158       mOptionsDialog->addModule( *mit );
00159 #endif
00160   }
00161 
00162   mOptionsDialog->show();
00163   mOptionsDialog->raise();
00164 }
00165 
00166 void KODialogManager::showCategoryEditDialog()
00167 {
00168   mCategoryEditDialog->show();
00169 }
00170 
00171 void KODialogManager::showSearchDialog()
00172 {
00173   if (!mSearchDialog) {
00174     mSearchDialog = new SearchDialog(mMainView->calendar(),mMainView);
00175     connect(mSearchDialog,SIGNAL(showIncidenceSignal(Incidence *)),
00176             mMainView,SLOT(showIncidence(Incidence *)));
00177     connect(mSearchDialog,SIGNAL(editIncidenceSignal(Incidence *)),
00178             mMainView,SLOT(editIncidence(Incidence *)));
00179     connect(mSearchDialog,SIGNAL(deleteIncidenceSignal(Incidence *)),
00180             mMainView, SLOT(deleteIncidence(Incidence *)));
00181     connect(mMainView,SIGNAL(closingDown()),mSearchDialog,SLOT(reject()));
00182   }
00183   // make sure the widget is on top again
00184   mSearchDialog->show();
00185   mSearchDialog->raise();
00186 }
00187 
00188 void KODialogManager::showArchiveDialog()
00189 {
00190 #ifndef KORG_NOARCHIVE
00191   if (!mArchiveDialog) {
00192     mArchiveDialog = new ArchiveDialog(mMainView->calendar(),mMainView);
00193     connect(mArchiveDialog,SIGNAL(eventsDeleted()),
00194             mMainView,SLOT(updateView()));
00195     connect(mArchiveDialog,SIGNAL(autoArchivingSettingsModified()),
00196             mMainView,SLOT(slotAutoArchivingSettingsModified()));
00197   }
00198   mArchiveDialog->show();
00199   mArchiveDialog->raise();
00200 
00201   // Workaround.
00202   QApplication::restoreOverrideCursor();
00203 #endif
00204 }
00205 
00206 void KODialogManager::showFilterEditDialog( QPtrList<CalFilter> *filters )
00207 {
00208   if ( !mFilterEditDialog ) {
00209     mFilterEditDialog = new FilterEditDialog( filters, mMainView );
00210     connect( mFilterEditDialog, SIGNAL( filterChanged() ),
00211              mMainView, SLOT( updateFilter() ) );
00212     connect( mFilterEditDialog, SIGNAL( editCategories() ),
00213              mCategoryEditDialog, SLOT( show() ) );
00214     connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00215              mFilterEditDialog, SLOT( updateCategoryConfig() ) );
00216   }
00217   mFilterEditDialog->show();
00218   mFilterEditDialog->raise();
00219 }
00220 
00221 KOIncidenceEditor *KODialogManager::getEditor( Incidence *incidence )
00222 {
00223   if ( !incidence ) return 0;
00224   EditorDialogVisitor v;
00225   if ( v.act( incidence, this ) ) {
00226     return v.editor();
00227   } else
00228     return 0;
00229 }
00230 
00231 KOEventEditor *KODialogManager::getEventEditor()
00232 {
00233   KOEventEditor *eventEditor = new KOEventEditor( mMainView->calendar(),
00234                                                   mMainView );
00235   connectEditor( eventEditor );
00236   return eventEditor;
00237 }
00238 
00239 void KODialogManager::connectTypeAhead( KOEventEditor *editor,
00240                                         KOAgendaView *agenda )
00241 {
00242   if ( editor && agenda ) {
00243     agenda->setTypeAheadReceiver( editor->typeAheadReceiver() );
00244     connect( editor, SIGNAL( focusReceivedSignal() ),
00245              agenda, SLOT( finishTypeAhead() ) );
00246   }
00247 }
00248 
00249 void KODialogManager::connectEditor( KOIncidenceEditor*editor )
00250 {
00251 /*  connect( editor, SIGNAL( deleteIncidenceSignal( Incidence * ) ),
00252            mMainView, SLOT( deleteIncidence( Incidence * ) ) );*/
00253 
00254   connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00255            editor, SLOT( updateCategoryConfig() ) );
00256   connect( editor, SIGNAL( editCategories() ),
00257            mCategoryEditDialog, SLOT( show() ) );
00258 
00259   connect( editor, SIGNAL( dialogClose( Incidence * ) ),
00260            mMainView, SLOT( dialogClosing( Incidence * ) ) );
00261   connect( editor, SIGNAL( editCanceled( Incidence * ) ),
00262            mMainView, SLOT( editCanceled( Incidence * ) ) );
00263   connect( mMainView, SIGNAL( closingDown() ), editor, SLOT( reject() ) );
00264 
00265   connect( editor, SIGNAL( deleteAttendee( Incidence * ) ),
00266            mMainView, SIGNAL( cancelAttendees( Incidence * ) ) );
00267 }
00268 
00269 KOTodoEditor *KODialogManager::getTodoEditor()
00270 {
00271   KOTodoEditor *todoEditor = new KOTodoEditor( mMainView->calendar(), mMainView );
00272   connectEditor( todoEditor );
00273   return todoEditor;
00274 }
00275 
00276 KOJournalEditor *KODialogManager::getJournalEditor()
00277 {
00278   KOJournalEditor *journalEditor = new KOJournalEditor( mMainView->calendar(), mMainView );
00279   connectEditor( journalEditor );
00280   return journalEditor;
00281 }
00282 
00283 void KODialogManager::updateSearchDialog()
00284 {
00285   if (mSearchDialog) mSearchDialog->updateView();
00286 }
00287 
KDE Home | KDE Accessibility Home | Description of Access Keys