korganizer Library API Documentation

kotodoeditor.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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <qtooltip.h> 00027 #include <qframe.h> 00028 #include <qpixmap.h> 00029 #include <qlayout.h> 00030 #include <qdatetime.h> 00031 00032 #include <kiconloader.h> 00033 #include <klocale.h> 00034 #include <kmessagebox.h> 00035 00036 #include <libkdepim/categoryselectdialog.h> 00037 #include <libkcal/calendarlocal.h> 00038 #include <libkcal/calendarresources.h> 00039 #include <libkcal/resourcecalendar.h> 00040 00041 #include "koprefs.h" 00042 #include "koeditorattachments.h" 00043 #include "kodialogmanager.h" 00044 00045 #include "kotodoeditor.h" 00046 00047 KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 00048 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 00049 { 00050 mTodo = 0; 00051 mRelatedTodo = 0; 00052 } 00053 00054 KOTodoEditor::~KOTodoEditor() 00055 { 00056 emit dialogClose( mTodo ); 00057 } 00058 00059 void KOTodoEditor::init() 00060 { 00061 setupGeneral(); 00062 setupAttendeesTab(); 00063 setupAttachmentsTab(); 00064 } 00065 00066 void KOTodoEditor::reload() 00067 { 00068 if ( mTodo ) readTodo( mTodo ); 00069 } 00070 00071 void KOTodoEditor::setupGeneral() 00072 { 00073 mGeneral = new KOEditorGeneralTodo(this); 00074 00075 connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 00076 connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 00077 mGeneral,SLOT(setCategories(const QString &))); 00078 00079 if (KOPrefs::instance()->mCompactDialogs) { 00080 QFrame *topFrame = addPage(i18n("General")); 00081 00082 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 00083 topLayout->setMargin(marginHint()); 00084 topLayout->setSpacing(spacingHint()); 00085 00086 mGeneral->initHeader(topFrame,topLayout); 00087 mGeneral->initTime(topFrame,topLayout); 00088 QHBoxLayout *priorityLayout = new QHBoxLayout( topLayout ); 00089 mGeneral->initPriority(topFrame,priorityLayout); 00090 mGeneral->initCategories( topFrame, topLayout ); 00091 topLayout->addStretch(1); 00092 00093 QFrame *topFrame2 = addPage(i18n("Details")); 00094 00095 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 00096 topLayout2->setMargin(marginHint()); 00097 topLayout2->setSpacing(spacingHint()); 00098 00099 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 00100 mGeneral->initCompletion(topFrame2,completionLayout); 00101 00102 mGeneral->initAlarm(topFrame,topLayout); 00103 mGeneral->enableAlarm( false ); 00104 00105 mGeneral->initSecrecy( topFrame2, topLayout2 ); 00106 mGeneral->initDescription(topFrame2,topLayout2); 00107 } else { 00108 QFrame *topFrame = addPage(i18n("&General")); 00109 00110 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 00111 topLayout->setSpacing(spacingHint()); 00112 00113 mGeneral->initHeader(topFrame,topLayout); 00114 mGeneral->initTime(topFrame,topLayout); 00115 mGeneral->initStatus(topFrame,topLayout); 00116 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 00117 mGeneral->initAlarm(topFrame,alarmLineLayout); 00118 mGeneral->initDescription(topFrame,topLayout); 00119 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 00120 mGeneral->initCategories( topFrame, detailsLayout ); 00121 mGeneral->initSecrecy( topFrame, detailsLayout ); 00122 } 00123 00124 mGeneral->finishSetup(); 00125 } 00126 00127 void KOTodoEditor::editTodo(Todo *todo) 00128 { 00129 init(); 00130 00131 mTodo = todo; 00132 readTodo(mTodo); 00133 } 00134 00135 void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 00136 { 00137 init(); 00138 00139 mTodo = 0; 00140 setDefaults(due,relatedTodo,allDay); 00141 } 00142 00143 void KOTodoEditor::newTodo( const QString &text ) 00144 { 00145 init(); 00146 00147 mTodo = 0; 00148 00149 loadDefaults(); 00150 00151 mGeneral->setDescription( text ); 00152 00153 int pos = text.find( "\n" ); 00154 if ( pos > 0 ) { 00155 mGeneral->setSummary( text.left( pos ) ); 00156 mGeneral->setDescription( text ); 00157 } else { 00158 mGeneral->setSummary( text ); 00159 } 00160 } 00161 00162 void KOTodoEditor::newTodo( const QString &summary, 00163 const QString &description, 00164 const QString &attachment ) 00165 { 00166 init(); 00167 00168 mTodo = 0; 00169 00170 loadDefaults(); 00171 00172 mGeneral->setSummary( summary ); 00173 mGeneral->setDescription( description ); 00174 00175 if ( !attachment.isEmpty() ) { 00176 mAttachments->addAttachment( attachment ); 00177 } 00178 } 00179 00180 void KOTodoEditor::loadDefaults() 00181 { 00182 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 00183 } 00184 00185 bool KOTodoEditor::processInput() 00186 { 00187 if ( !validateInput() ) return false; 00188 00189 if ( mTodo ) { 00190 Todo *oldTodo = mTodo->clone(); 00191 00192 writeTodo( mTodo ); 00193 00194 mTodo->setRevision( mTodo->revision() + 1 ); 00195 00196 emit todoChanged( oldTodo, mTodo ); 00197 00198 delete oldTodo; 00199 } else { 00200 mTodo = new Todo; 00201 mTodo->setOrganizer( KOPrefs::instance()->email() ); 00202 00203 writeTodo( mTodo ); 00204 00205 if ( !mCalendar->addTodo( mTodo ) ) { 00206 KODialogManager::errorSaveTodo( this ); 00207 delete mTodo; 00208 mTodo = 0; 00209 return false; 00210 } 00211 00212 emit todoAdded( mTodo ); 00213 } 00214 00215 return true; 00216 } 00217 00218 void KOTodoEditor::processCancel() 00219 { 00220 if ( mTodo ) { 00221 emit editCanceled( mTodo ); 00222 } 00223 } 00224 00225 void KOTodoEditor::deleteTodo() 00226 { 00227 if (mTodo) { 00228 if (KOPrefs::instance()->mConfirm) { 00229 switch (msgItemDelete()) { 00230 case KMessageBox::Continue: // OK 00231 emit todoToBeDeleted(mTodo); 00232 emit dialogClose(mTodo); 00233 mCalendar->deleteTodo(mTodo); 00234 emit todoDeleted(); 00235 reject(); 00236 break; 00237 } 00238 } 00239 else { 00240 emit todoToBeDeleted(mTodo); 00241 emit dialogClose(mTodo); 00242 mCalendar->deleteTodo(mTodo); 00243 emit todoDeleted(); 00244 reject(); 00245 } 00246 } else { 00247 reject(); 00248 } 00249 } 00250 00251 void KOTodoEditor::setDefaults( QDateTime due, Todo *relatedEvent, bool allDay ) 00252 { 00253 mRelatedTodo = relatedEvent; 00254 00255 mGeneral->setDefaults( due, allDay ); 00256 mDetails->setDefaults(); 00257 mAttachments->setDefaults(); 00258 } 00259 00260 void KOTodoEditor::readTodo( Todo *todo ) 00261 { 00262 mGeneral->readTodo( todo ); 00263 mDetails->readEvent( todo ); 00264 mAttachments->readIncidence( todo ); 00265 00266 // categories 00267 mCategoryDialog->setSelected( todo->categories() ); 00268 00269 // TODO: We should handle read-only events here. 00270 } 00271 00272 void KOTodoEditor::writeTodo( Todo *todo ) 00273 { 00274 mGeneral->writeTodo( todo ); 00275 mDetails->writeEvent( todo ); 00276 mAttachments->writeIncidence( todo ); 00277 00278 // set related event, i.e. parent to-do in this case. 00279 if ( mRelatedTodo ) { 00280 todo->setRelatedTo( mRelatedTodo ); 00281 } 00282 } 00283 00284 bool KOTodoEditor::validateInput() 00285 { 00286 if ( !mGeneral->validateInput() ) return false; 00287 if ( !mDetails->validateInput() ) return false; 00288 return true; 00289 } 00290 00291 int KOTodoEditor::msgItemDelete() 00292 { 00293 return KMessageBox::warningContinueCancel(this, 00294 i18n("This item will be permanently deleted."), 00295 i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete")); 00296 } 00297 00298 void KOTodoEditor::modified (int modification) 00299 { 00300 if (modification == KOGlobals::CATEGORY_MODIFIED || 00301 KOGlobals::UNKNOWN_MODIFIED == modification ) 00302 mCategoryDialog->setSelected (mTodo->categories ()); 00303 mGeneral->modified (mTodo, modification); 00304 00305 } 00306 00307 void KOTodoEditor::slotLoadTemplate() 00308 { 00309 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId ); 00310 Todo *todo = new Todo; 00311 QString templateName = loadTemplate( &cal, todo->type(), 00312 KOPrefs::instance()->mTodoTemplates ); 00313 delete todo; 00314 if ( templateName.isEmpty() ) { 00315 return; 00316 } 00317 00318 Todo::List todos = cal.todos(); 00319 if ( todos.count() == 0 ) { 00320 KMessageBox::error( this, 00321 i18n("Template '%1' does not contain a valid todo.") 00322 .arg( templateName ) ); 00323 } else { 00324 readTodo( todos.first() ); 00325 } 00326 } 00327 00328 void KOTodoEditor::saveTemplate( const QString &templateName ) 00329 { 00330 Todo *todo = new Todo; 00331 writeTodo( todo ); 00332 saveAsTemplate( todo, templateName ); 00333 } 00334 00335 #include "kotodoeditor.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003