korganizer Library API Documentation

kojournaleditor.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 1997, 1998 Preston Brown 00005 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 00022 As a special exception, permission is given to link this program 00023 with any edition of Qt, and distribute the resulting executable, 00024 without including the source code for Qt in the source distribution. 00025 */ 00026 00027 #include "kojournaleditor.h" 00028 00029 #include "koeditorgeneraljournal.h" 00030 #include "kodialogmanager.h" 00031 #include "koprefs.h" 00032 00033 #include <libkcal/journal.h> 00034 #include <libkcal/calendarlocal.h> 00035 00036 #include <kmessagebox.h> 00037 #include <klocale.h> 00038 #include <kdebug.h> 00039 00040 #include <qlayout.h> 00041 00042 using namespace KCal; 00043 00044 KOJournalEditor::KOJournalEditor( Calendar *calendar, QWidget *parent ) : 00045 KOIncidenceEditor( i18n("Edit Journal"), calendar, parent ) 00046 { 00047 mJournal = 0; 00048 } 00049 00050 KOJournalEditor::~KOJournalEditor() 00051 { 00052 emit dialogClose( mJournal ); 00053 } 00054 00055 void KOJournalEditor::init() 00056 { 00057 setupGeneral(); 00058 } 00059 00060 void KOJournalEditor::reload() 00061 { 00062 kdDebug(5851)<<"reloading Journal"<<endl; 00063 if ( mJournal ) readJournal( mJournal ); 00064 } 00065 00066 void KOJournalEditor::setupGeneral() 00067 { 00068 mGeneral = new KOEditorGeneralJournal(this); 00069 00070 if (KOPrefs::instance()->mCompactDialogs) { 00071 QFrame *topFrame = addPage(i18n("General")); 00072 00073 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00074 topLayout->setMargin( marginHint() ); 00075 topLayout->setSpacing( spacingHint() ); 00076 00077 mGeneral->initDate( topFrame, topLayout ); 00078 mGeneral->initDescription( topFrame, topLayout ); 00079 } else { 00080 QFrame *topFrame = addPage(i18n("&General")); 00081 00082 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 00083 topLayout->setSpacing(spacingHint()); 00084 00085 mGeneral->initDate( topFrame, topLayout ); 00086 mGeneral->initDescription( topFrame, topLayout ); 00087 } 00088 00089 mGeneral->finishSetup(); 00090 } 00091 00092 void KOJournalEditor::editIncidence( Incidence *incidence ) 00093 { 00094 Journal *journal=dynamic_cast<Journal*>(incidence); 00095 if (journal) 00096 { 00097 init(); 00098 00099 mJournal = journal; 00100 readJournal(mJournal); 00101 } 00102 } 00103 00104 void KOJournalEditor::newJournal( QDate date ) 00105 { 00106 init(); 00107 00108 mJournal = 0; 00109 setDefaults( date ); 00110 } 00111 00112 void KOJournalEditor::newJournal( const QString &text ) 00113 { 00114 init(); 00115 00116 mJournal = 0; 00117 00118 loadDefaults(); 00119 00120 mGeneral->setDescription( text ); 00121 } 00122 00123 void KOJournalEditor::newJournal( const QString &text, QDate date ) 00124 { 00125 init(); 00126 00127 mJournal = 0; 00128 00129 loadDefaults(); 00130 00131 mGeneral->setDescription( text ); 00132 mGeneral->setDate( date ); 00133 } 00134 00135 void KOJournalEditor::loadDefaults() 00136 { 00137 setDefaults( QDate::currentDate() ); 00138 } 00139 00140 // TODO_RK: make sure calendar()->endChange is called somewhere! 00141 bool KOJournalEditor::processInput() 00142 { 00143 if ( !validateInput() ) return false; 00144 00145 if ( mJournal ) { 00146 Journal *oldJournal = mJournal->clone(); 00147 00148 writeJournal( mJournal ); 00149 00150 mJournal->setRevision( mJournal->revision() + 1 ); 00151 00152 emit incidenceChanged( oldJournal, mJournal ); 00153 00154 delete oldJournal; 00155 } else { 00156 mJournal = new Journal; 00157 // mJournal->setOrganizer( KOPrefs::instance()->email() ); 00158 00159 writeJournal( mJournal ); 00160 00161 if ( !mCalendar->addJournal( mJournal ) ) { 00162 KODialogManager::errorSaveJournal( this ); 00163 delete mJournal; 00164 mJournal = 0; 00165 return false; 00166 } 00167 00168 emit incidenceAdded( mJournal ); 00169 } 00170 00171 return true; 00172 } 00173 00174 void KOJournalEditor::processCancel() 00175 { 00176 if ( mJournal ) { 00177 emit editCanceled( mJournal ); 00178 } 00179 } 00180 00181 void KOJournalEditor::deleteJournal() 00182 { 00183 if ( mJournal ) { 00184 if ( KOPrefs::instance()->mConfirm ) { 00185 switch ( msgItemDelete() ) { 00186 case KMessageBox::Continue: // OK 00187 emit incidenceToBeDeleted( mJournal ); 00188 emit dialogClose( mJournal ); 00189 mCalendar->deleteJournal( mJournal ); 00190 emit incidenceDeleted( mJournal ); 00191 reject(); 00192 break; 00193 } 00194 } 00195 else { 00196 emit incidenceToBeDeleted( mJournal ); 00197 emit dialogClose( mJournal ); 00198 mCalendar->deleteJournal( mJournal ); 00199 emit incidenceDeleted( mJournal ); 00200 reject(); 00201 } 00202 } else { 00203 reject(); 00204 } 00205 } 00206 00207 void KOJournalEditor::setDefaults( QDate date ) 00208 { 00209 mGeneral->setDefaults( date ); 00210 } 00211 00212 void KOJournalEditor::readJournal( Journal *journal ) 00213 { 00214 kdDebug(5851)<<"read Journal"<<endl; 00215 mGeneral->readJournal( journal ); 00216 } 00217 00218 void KOJournalEditor::writeJournal( Journal *journal ) 00219 { 00220 mGeneral->writeJournal( journal ); 00221 } 00222 00223 bool KOJournalEditor::validateInput() 00224 { 00225 return mGeneral->validateInput(); 00226 } 00227 00228 int KOJournalEditor::msgItemDelete() 00229 { 00230 return KMessageBox::warningContinueCancel( this, 00231 i18n("This journal entry will be permanently deleted."), 00232 i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" )); 00233 } 00234 00235 void KOJournalEditor::modified( int /*modification*/) 00236 { 00237 // Play dump, just reload the Journal. This dialog has become so complicated that 00238 // there is no point in trying to be smart here... 00239 reload(); 00240 } 00241 00242 void KOJournalEditor::slotLoadTemplate() 00243 { 00244 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId ); 00245 Journal *journal = new Journal; 00246 QString templateName = loadTemplate( &cal, journal->type(), 00247 KOPrefs::instance()->mJournalTemplates ); 00248 delete journal; 00249 if ( templateName.isEmpty() ) { 00250 return; 00251 } 00252 00253 Journal::List journals = cal.journals(); 00254 if ( journals.count() == 0 ) { 00255 KMessageBox::error( this, 00256 i18n("Template '%1' does not contain a valid journal.") 00257 .arg( templateName ) ); 00258 } else { 00259 readJournal( journals.first() ); 00260 } 00261 } 00262 00263 void KOJournalEditor::saveTemplate( const QString &templateName ) 00264 { 00265 Journal *journal = new Journal; 00266 writeJournal( journal ); 00267 saveAsTemplate( journal, templateName ); 00268 } 00269 00270 #include "kojournaleditor.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:25 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003