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 
00029 #include <libkdepim/categoryeditdialog.h>
00030 
00031 #include "calendarview.h"
00032 #include "koprefsdialog.h"
00033 #include "koprefs.h"
00034 #include "koeventeditor.h"
00035 #include "kotodoeditor.h"
00036 #include "kojournaleditor.h"
00037 #include "searchdialog.h"
00038 #include "filtereditdialog.h"
00039 #ifndef KORG_NOARCHIVE
00040 #include "archivedialog.h"
00041 #endif
00042 #include "koviewmanager.h"
00043 #include "koagendaview.h"
00044 #include "koglobals.h"
00045 
00046 #include "kodialogmanager.h"
00047 #include "kodialogmanager.moc"
00048 
00049 
00050 // FIXME: Handle KOEventViewerDialogs in dialog manager. Pass
00051 // KOPrefs::mCompactDialog.
00052 
00053 class KODialogManager::DialogManagerVisitor : public IncidenceBase::Visitor
00054 {
00055   public:
00056     DialogManagerVisitor() : mDialogManager( 0 ) {}
00057 
00058     bool act( IncidenceBase *incidence, KODialogManager *manager )
00059     {
00060       mDialogManager = manager;
00061       return incidence->accept( *this );
00062     }
00063 
00064   protected:
00065     KODialogManager *mDialogManager;
00066 };
00067 
00068 class KODialogManager::EditorDialogVisitor : 
00069       public KODialogManager::DialogManagerVisitor
00070 {
00071   public:
00072     EditorDialogVisitor() : DialogManagerVisitor(), mEditor( 0 ) {}
00073     KOIncidenceEditor *editor() const { return mEditor; }
00074   protected:
00075     bool visit( Event * ) { mEditor = mDialogManager->getEventEditor(); return mEditor; }
00076     bool visit( Todo * ) { mEditor = mDialogManager->getTodoEditor(); return mEditor; }
00077     bool visit( Journal * ) { mEditor = mDialogManager->getJournalEditor(); return mEditor; }
00078   protected:
00079     KOIncidenceEditor *mEditor;
00080 };
00081 
00082 
00083 KODialogManager::KODialogManager( CalendarView *mainView ) :
00084   QObject(), mMainView( mainView )
00085 {
00086   mOptionsDialog = 0;
00087   mSearchDialog = 0;
00088   mArchiveDialog = 0;
00089   mFilterEditDialog = 0;
00090 
00091   mCategoryEditDialog = new KPIM::CategoryEditDialog( KOPrefs::instance(), mMainView );
00092   connect( mainView, SIGNAL( categoriesChanged() ),
00093            mCategoryEditDialog, SLOT( reload() ) );
00094   KOGlobals::fitDialogToScreen( mCategoryEditDialog );
00095 }
00096 
00097 KODialogManager::~KODialogManager()
00098 {
00099   delete mOptionsDialog;
00100   delete mSearchDialog;
00101 #ifndef KORG_NOARCHIVE
00102   delete mArchiveDialog;
00103 #endif
00104   delete mFilterEditDialog;
00105 }
00106 
00107 void KODialogManager::errorSaveIncidence( QWidget *parent, Incidence *incidence )
00108 {
00109   KMessageBox::sorry( parent, i18n("Unable to save %1 \"%2\".")
00110                       .arg( i18n( incidence->type() ) )
00111                       .arg( incidence->summary() ) );
00112 }
00113 
00114 void KODialogManager::showOptionsDialog()
00115 {
00116   if (!mOptionsDialog) {
00117 #if 0
00118     mOptionsDialog = new KConfigureDialog();
00119 //    mOptionsDialog = new KConfigureDialog( KConfigureDialog::Configurable );
00120 //    mOptionsDialog = new KConfigureDialog( mMainView );
00121     connect( mOptionsDialog->dialog(),
00122              SIGNAL( configCommitted( const QCString & ) ),
00123              mMainView, SLOT( updateConfig() ) );
00124 #else
00125     mOptionsDialog = new KCMultiDialog( mMainView, "KorganizerPreferences" );
00126     connect( mOptionsDialog, SIGNAL( configCommitted( const QCString & ) ),
00127              mMainView, SLOT( updateConfig( const QCString& ) ) );
00128 #if 0
00129     connect( mOptionsDialog, SIGNAL( applyClicked() ),
00130              mMainView, SLOT( updateConfig() ) );
00131     connect( mOptionsDialog, SIGNAL( okClicked() ),
00132              mMainView, SLOT( updateConfig() ) );
00133     // @TODO Find a way to do this with KCMultiDialog
00134     connect(mCategoryEditDialog,SIGNAL(categoryConfigChanged()),
00135             mOptionsDialog,SLOT(updateCategories()));
00136 #endif
00137 
00138     QStringList modules;
00139 
00140     modules.append( "korganizer_configmain.desktop" );
00141     modules.append( "korganizer_configtime.desktop" );
00142     modules.append( "korganizer_configviews.desktop" );
00143     modules.append( "korganizer_configfonts.desktop" );
00144     modules.append( "korganizer_configcolors.desktop" );
00145     modules.append( "korganizer_configgroupscheduling.desktop" );
00146     modules.append( "korganizer_configgroupautomation.desktop" );
00147     modules.append( "korganizer_configfreebusy.desktop" );
00148     modules.append( "korganizer_configplugins.desktop" );
00149     modules.append( "korganizer_configdesignerfields.desktop" );
00150 
00151     // add them all
00152     QStringList::iterator mit;
00153     for ( mit = modules.begin(); mit != modules.end(); ++mit )
00154       mOptionsDialog->addModule( *mit );
00155 #endif
00156   }
00157 
00158   mOptionsDialog->show();
00159   mOptionsDialog->raise();
00160 }
00161 
00162 void KODialogManager::showCategoryEditDialog()
00163 {
00164   mCategoryEditDialog->show();
00165 }
00166 
00167 void KODialogManager::showSearchDialog()
00168 {
00169   if (!mSearchDialog) {
00170     mSearchDialog = new SearchDialog(mMainView->calendar(),mMainView);
00171     connect(mSearchDialog,SIGNAL(showIncidenceSignal(Incidence *)),
00172             mMainView,SLOT(showIncidence(Incidence *)));
00173     connect(mSearchDialog,SIGNAL(editIncidenceSignal(Incidence *)),
00174             mMainView,SLOT(editIncidence(Incidence *)));
00175     connect(mSearchDialog,SIGNAL(deleteIncidenceSignal(Incidence *)),
00176             mMainView, SLOT(deleteIncidence(Incidence *)));
00177     connect(mMainView,SIGNAL(closingDown()),mSearchDialog,SLOT(reject()));
00178   }
00179   // make sure the widget is on top again
00180   mSearchDialog->show();
00181   mSearchDialog->raise();
00182 }
00183 
00184 void KODialogManager::showArchiveDialog()
00185 {
00186 #ifndef KORG_NOARCHIVE
00187   if (!mArchiveDialog) {
00188     mArchiveDialog = new ArchiveDialog(mMainView->calendar(),mMainView);
00189     connect(mArchiveDialog,SIGNAL(eventsDeleted()),
00190             mMainView,SLOT(updateView()));
00191     connect(mArchiveDialog,SIGNAL(autoArchivingSettingsModified()),
00192             mMainView,SLOT(slotAutoArchivingSettingsModified()));
00193   }
00194   mArchiveDialog->show();
00195   mArchiveDialog->raise();
00196 
00197   // Workaround.
00198   QApplication::restoreOverrideCursor();
00199 #endif
00200 }
00201 
00202 void KODialogManager::showFilterEditDialog( QPtrList<CalFilter> *filters )
00203 {
00204   if ( !mFilterEditDialog ) {
00205     mFilterEditDialog = new FilterEditDialog( filters, mMainView );
00206     connect( mFilterEditDialog, SIGNAL( filterChanged() ),
00207              mMainView, SLOT( updateFilter() ) );
00208     connect( mFilterEditDialog, SIGNAL( editCategories() ),
00209              mCategoryEditDialog, SLOT( show() ) );
00210     connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00211              mFilterEditDialog, SLOT( updateCategoryConfig() ) );
00212   }
00213   mFilterEditDialog->show();
00214   mFilterEditDialog->raise();
00215 }
00216 
00217 KOIncidenceEditor *KODialogManager::getEditor( Incidence *incidence )
00218 {
00219   if ( !incidence ) return 0;
00220   EditorDialogVisitor v;
00221   if ( v.act( incidence, this ) ) {
00222     return v.editor();
00223   } else
00224     return 0;
00225 }
00226 
00227 KOEventEditor *KODialogManager::getEventEditor()
00228 {
00229   KOEventEditor *eventEditor = new KOEventEditor( mMainView->calendar(),
00230                                                   mMainView );
00231   connectEditor( eventEditor );
00232   return eventEditor;
00233 }
00234 
00235 void KODialogManager::connectTypeAhead( KOEventEditor *editor,
00236                                         KOAgendaView *agenda )
00237 {
00238   if ( editor && agenda ) {
00239     agenda->setTypeAheadReceiver( editor->typeAheadReceiver() );
00240     connect( editor, SIGNAL( focusReceivedSignal() ),
00241              agenda, SLOT( finishTypeAhead() ) );
00242   }
00243 }
00244 
00245 void KODialogManager::connectEditor( KOIncidenceEditor*editor )
00246 {
00247 /*  connect( editor, SIGNAL( deleteIncidenceSignal( Incidence * ) ),
00248            mMainView, SLOT( deleteIncidence( Incidence * ) ) );*/
00249 
00250   connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
00251            editor, SLOT( updateCategoryConfig() ) );
00252   connect( editor, SIGNAL( editCategories() ),
00253            mCategoryEditDialog, SLOT( show() ) );
00254 
00255   connect( editor, SIGNAL( dialogClose( Incidence * ) ),
00256            mMainView, SLOT( dialogClosing( Incidence * ) ) );
00257   connect( editor, SIGNAL( editCanceled( Incidence * ) ),
00258            mMainView, SLOT( editCanceled( Incidence * ) ) );
00259   connect( mMainView, SIGNAL( closingDown() ), editor, SLOT( reject() ) );
00260 
00261   connect( editor, SIGNAL( deleteAttendee( Incidence * ) ),
00262            mMainView, SIGNAL( cancelAttendees( Incidence * ) ) );
00263 }
00264 
00265 KOTodoEditor *KODialogManager::getTodoEditor()
00266 {
00267   KOTodoEditor *todoEditor = new KOTodoEditor( mMainView->calendar(), mMainView );
00268   connectEditor( todoEditor );
00269   return todoEditor;
00270 }
00271 
00272 KOJournalEditor *KODialogManager::getJournalEditor()
00273 {
00274   KOJournalEditor *journalEditor = new KOJournalEditor( mMainView->calendar(), mMainView );
00275   connectEditor( journalEditor );
00276   return journalEditor;
00277 }
00278 
00279 void KODialogManager::updateSearchDialog()
00280 {
00281   if (mSearchDialog) mSearchDialog->updateView();
00282 }
00283 
KDE Home | KDE Accessibility Home | Description of Access Keys