kotodoeditor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qtooltip.h>
00026 #include <qframe.h>
00027 #include <qpixmap.h>
00028 #include <qlayout.h>
00029 #include <qdatetime.h>
00030
00031 #include <kiconloader.h>
00032 #include <klocale.h>
00033 #include <kmessagebox.h>
00034
00035 #include <libkdepim/categoryselectdialog.h>
00036 #include <libkcal/calendarlocal.h>
00037
00038 #include "koprefs.h"
00039
00040 #include "kotodoeditor.h"
00041 #include "kotodoeditor.moc"
00042
00043 KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
00044 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
00045 {
00046 mTodo = 0;
00047 mRelatedTodo = 0;
00048 }
00049
00050 KOTodoEditor::~KOTodoEditor()
00051 {
00052 emit dialogClose( mTodo );
00053 }
00054
00055 void KOTodoEditor::init()
00056 {
00057 setupGeneral();
00058 setupAttendeesTab();
00059 }
00060
00061 void KOTodoEditor::reload()
00062 {
00063 if ( mTodo ) readTodo( mTodo );
00064 }
00065
00066 void KOTodoEditor::setupGeneral()
00067 {
00068 mGeneral = new KOEditorGeneralTodo(this);
00069
00070 connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
00071 connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
00072 mGeneral,SLOT(setCategories(const QString &)));
00073
00074 if (KOPrefs::instance()->mCompactDialogs) {
00075 QFrame *topFrame = addPage(i18n("General"));
00076
00077 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00078 topLayout->setMargin(marginHint());
00079 topLayout->setSpacing(spacingHint());
00080
00081 mGeneral->initHeader(topFrame,topLayout);
00082 mGeneral->initTime(topFrame,topLayout);
00083 QHBoxLayout *priorityLayout = new QHBoxLayout( topLayout );
00084 mGeneral->initPriority(topFrame,priorityLayout);
00085 mGeneral->initCategories( topFrame, topLayout );
00086 topLayout->addStretch(1);
00087
00088 QFrame *topFrame2 = addPage(i18n("Details"));
00089
00090 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
00091 topLayout2->setMargin(marginHint());
00092 topLayout2->setSpacing(spacingHint());
00093
00094 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
00095 mGeneral->initCompletion(topFrame2,completionLayout);
00096
00097 mGeneral->initAlarm(topFrame,topLayout);
00098 mGeneral->enableAlarm( false );
00099
00100 mGeneral->initSecrecy( topFrame2, topLayout2 );
00101 mGeneral->initDescription(topFrame2,topLayout2);
00102 } else {
00103 QFrame *topFrame = addPage(i18n("General"));
00104
00105 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00106 topLayout->setSpacing(spacingHint());
00107
00108 mGeneral->initHeader(topFrame,topLayout);
00109 mGeneral->initTime(topFrame,topLayout);
00110 mGeneral->initStatus(topFrame,topLayout);
00111 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
00112 mGeneral->initAlarm(topFrame,alarmLineLayout);
00113 mGeneral->initDescription(topFrame,topLayout);
00114 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
00115 mGeneral->initCategories( topFrame, detailsLayout );
00116 mGeneral->initSecrecy( topFrame, detailsLayout );
00117 }
00118
00119 mGeneral->finishSetup();
00120 }
00121
00122 void KOTodoEditor::editTodo(Todo *todo)
00123 {
00124 init();
00125
00126 mTodo = todo;
00127 readTodo(mTodo);
00128 }
00129
00130 void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
00131 {
00132 init();
00133
00134 mTodo = 0;
00135 setDefaults(due,relatedTodo,allDay);
00136 }
00137
00138 void KOTodoEditor::loadDefaults()
00139 {
00140 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
00141 }
00142
00143 bool KOTodoEditor::processInput()
00144 {
00145 if (!validateInput()) return false;
00146
00147 Todo *todo = 0;
00148
00149 if (mTodo) todo = mTodo;
00150 else {
00151 todo = new Todo;
00152 todo->setOrganizer(KOPrefs::instance()->email());
00153 }
00154
00155 writeTodo(todo);
00156
00157 if (mTodo) {
00158 todo->setRevision(todo->revision()+1);
00159 emit todoChanged(todo);
00160 } else {
00161 mCalendar->addTodo(todo);
00162 mTodo = todo;
00163 emit todoAdded(todo);
00164 }
00165
00166 return true;
00167 }
00168
00169 void KOTodoEditor::deleteTodo()
00170 {
00171 if (mTodo) {
00172 if (KOPrefs::instance()->mConfirm) {
00173 switch (msgItemDelete()) {
00174 case KMessageBox::Continue:
00175 emit todoToBeDeleted(mTodo);
00176 emit dialogClose(mTodo);
00177 mCalendar->deleteTodo(mTodo);
00178 emit todoDeleted();
00179 reject();
00180 break;
00181 }
00182 }
00183 else {
00184 emit todoToBeDeleted(mTodo);
00185 emit dialogClose(mTodo);
00186 mCalendar->deleteTodo(mTodo);
00187 emit todoDeleted();
00188 reject();
00189 }
00190 } else {
00191 reject();
00192 }
00193 }
00194
00195 void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
00196 {
00197 mRelatedTodo = relatedEvent;
00198
00199 mGeneral->setDefaults(due,allDay);
00200 mDetails->setDefaults();
00201 }
00202
00203 void KOTodoEditor::readTodo(Todo *todo)
00204 {
00205 mGeneral->readTodo(todo);
00206 mDetails->readEvent(todo);
00207
00208
00209 mCategoryDialog->setSelected(todo->categories());
00210
00211
00212 }
00213
00214 void KOTodoEditor::writeTodo(Todo *event)
00215 {
00216 mGeneral->writeTodo(event);
00217 mDetails->writeEvent(event);
00218
00219
00220 if (mRelatedTodo) {
00221 event->setRelatedTo(mRelatedTodo);
00222 }
00223 }
00224
00225 bool KOTodoEditor::validateInput()
00226 {
00227 if (!mGeneral->validateInput()) return false;
00228 if (!mDetails->validateInput()) return false;
00229 return true;
00230 }
00231
00232 int KOTodoEditor::msgItemDelete()
00233 {
00234 return KMessageBox::warningContinueCancel(this,
00235 i18n("This item will be permanently deleted."),
00236 i18n("KOrganizer Confirmation"),i18n("Delete"));
00237 }
00238
00239 void KOTodoEditor::modified (int modification)
00240 {
00241 if (modification == KOGlobals::CATEGORY_MODIFIED ||
00242 KOGlobals::UNKNOWN_MODIFIED == modification )
00243 mCategoryDialog->setSelected (mTodo->categories ());
00244 mGeneral->modified (mTodo, modification);
00245
00246 }
00247
00248 void KOTodoEditor::slotLoadTemplate()
00249 {
00250 CalendarLocal cal;
00251 Todo *todo = new Todo;
00252 QString templateName = loadTemplate( &cal, todo->type(),
00253 KOPrefs::instance()->mTodoTemplates );
00254 delete todo;
00255 if ( templateName.isEmpty() ) {
00256 return;
00257 }
00258
00259 QPtrList<Todo> todos = cal.todos();
00260 todo = todos.first();
00261 if ( !todo ) {
00262 KMessageBox::error( this,
00263 i18n("Template '%1' does not contain a valid Todo.")
00264 .arg( templateName ) );
00265 } else {
00266 readTodo( todo );
00267 }
00268 }
00269
00270 void KOTodoEditor::slotSaveTemplate()
00271 {
00272 createSaveTemplateDialog( SaveTemplateDialog::TodoType );
00273 }
00274
00275 void KOTodoEditor::saveTemplate( const QString &templateName )
00276 {
00277 Todo *todo = new Todo;
00278 writeTodo( todo );
00279 saveAsTemplate( todo, templateName );
00280 }
This file is part of the documentation for kdelibs Version 3.1.5.