summaryrefslogtreecommitdiffabout
path: root/korganizer/kotodoeditor.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/kotodoeditor.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'korganizer/kotodoeditor.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoeditor.cpp373
1 files changed, 373 insertions, 0 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
new file mode 100644
index 0000000..1c44f2b
--- a/dev/null
+++ b/korganizer/kotodoeditor.cpp
@@ -0,0 +1,373 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
23*/
24
25#include <qtooltip.h>
26#include <qframe.h>
27#include <qpixmap.h>
28#include <qlayout.h>
29#include <qhbox.h>
30#include <qdir.h>
31#include <qdatetime.h>
32#include <qapplication.h>
33
34#include <kiconloader.h>
35#include <klocale.h>
36#include <kfiledialog.h>
37#include <kstandarddirs.h>
38#include <kmessagebox.h>
39
40#include <libkdepim/categoryselectdialog.h>
41#include <libkcal/calendarlocal.h>
42#include <libkcal/calendarresources.h>
43#include <libkcal/resourcecalendar.h>
44#include <libkcal/icalformat.h>
45#include <kresources/resourceselectdialog.h>
46
47#include "koprefs.h"
48
49#include "kotodoeditor.h"
50#include "kotodoeditor.moc"
51extern int globalFlagBlockAgenda;
52
53KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
54 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
55{
56 mTodo = 0;
57 mRelatedTodo = 0;
58 findButton(User1)->hide();
59 init();
60}
61
62KOTodoEditor::~KOTodoEditor()
63{
64 emit dialogClose( mTodo );
65}
66
67void KOTodoEditor::init()
68{
69 setupGeneral();
70 setupAttendeesTab();
71}
72void KOTodoEditor::setCategories( QString s )
73{
74 mGeneral->setCategories(s);
75}
76void KOTodoEditor::setSecrecy( int sec )
77{
78 mGeneral->setSecrecy( sec );
79}
80void KOTodoEditor::reload()
81{
82 if ( mTodo ) readTodo( mTodo );
83}
84
85void KOTodoEditor::setupGeneral()
86{
87 mGeneral = new KOEditorGeneralTodo(this);
88 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
89
90 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
91 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
92 // mGeneral,SLOT(setCategories(const QString &)));
93
94 if (KOPrefs::instance()->mCompactDialogs) {
95 QFrame *topFrame = addPage(i18n("General"));
96
97 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
98 if ( QApplication::desktop()->width() < 480 ) {
99 topLayout->setMargin(1);
100 topLayout->setSpacing(1);
101 } else {
102 topLayout->setMargin(marginHint()-1);
103 topLayout->setSpacing(spacingHint()-1);
104 }
105 mGeneral->initHeader(topFrame,topLayout);
106 mGeneral->initTime(topFrame,topLayout);
107 mGeneral->initAlarm(topFrame,topLayout);
108 mGeneral->enableAlarm( false );
109
110
111 QBoxLayout *priorityLayout;
112 if ( QApplication::desktop()->width() < 500 )
113 priorityLayout = new QVBoxLayout( topLayout );
114 else
115 priorityLayout = new QHBoxLayout( topLayout );
116 QWidget* prioWidget = new QWidget (topFrame);
117 priorityLayout->addWidget( prioWidget );
118 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget);
119
120
121 QIconSet icon;
122 if ( QApplication::desktop()->width() < 321 )
123 icon = SmallIcon("fileexport16");
124 else
125 icon = SmallIcon("fileexport");
126 QPushButton * saveTemplate = new QPushButton( prioWidget);
127 saveTemplate->setIconSet (icon ) ;
128 int size = saveTemplate->sizeHint().height();
129 saveTemplate->setFixedSize( size, size );
130 if ( QApplication::desktop()->width() < 321 )
131 icon = SmallIcon("fileimport16");
132 else
133 icon = SmallIcon("fileimport");
134 QPushButton * loadTemplate = new QPushButton( prioWidget);
135 loadTemplate->setIconSet (icon ) ;
136 loadTemplate->setFixedSize( size, size );
137
138 priorityLayout2->addWidget(loadTemplate);
139 priorityLayout2->addWidget(saveTemplate);
140 mGeneral->initPriority(prioWidget,priorityLayout2);
141 mGeneral->initCategories( topFrame, priorityLayout );
142 topLayout->addStretch(1);
143
144 QFrame *topFrame2 = addPage(i18n("Details"));
145
146 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
147 topLayout2->setMargin(marginHint());
148 topLayout2->setSpacing(spacingHint());
149
150 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
151 mGeneral->initCompletion(topFrame2,completionLayout);
152
153
154 mGeneral->initSecrecy( topFrame2, topLayout2 );
155 mGeneral->initDescription(topFrame2,topLayout2);
156
157 // QHBox * hb = new QHBox ( topFrame2 );
158 // topLayout2->addWidget(hb);
159 // hb->setSpacing( 3 );
160
161 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
162 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
163
164 } else {
165 QFrame *topFrame = addPage(i18n("General"));
166
167 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
168 topLayout->setSpacing(spacingHint());
169
170 mGeneral->initHeader(topFrame,topLayout);
171 mGeneral->initTime(topFrame,topLayout);
172 mGeneral->initStatus(topFrame,topLayout);
173 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
174 mGeneral->initAlarm(topFrame,alarmLineLayout);
175 mGeneral->initDescription(topFrame,topLayout);
176 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
177 mGeneral->initCategories( topFrame, detailsLayout );
178 mGeneral->initSecrecy( topFrame, detailsLayout );
179 }
180 mGeneral->finishSetup();
181
182}
183
184void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
185{
186 //init();
187
188 mTodo = todo;
189 readTodo(mTodo);
190 if ( editDescription ) {
191 showPage( 1 );
192 mGeneral->setFocusOn( 1 );
193 } else {
194 showPage( 0 );
195 mGeneral->setFocusOn( 2 );
196 }
197}
198
199void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
200{
201 //init();
202
203 mTodo = 0;
204 setDefaults(due,relatedTodo,allDay);
205}
206
207void KOTodoEditor::loadDefaults()
208{
209 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
210}
211
212bool KOTodoEditor::processInput( bool emitTime )
213{
214 if (!validateInput()) return false;
215
216 Todo *todo = 0;
217
218 if (mTodo) todo = mTodo;
219 else {
220 todo = new Todo;
221 todo->setOrganizer(KOPrefs::instance()->email());
222 }
223
224 writeTodo(todo);
225 if ( emitTime ) {
226 globalFlagBlockAgenda = 1;
227 emit showAgendaView( false );
228 if ( todo->hasDueDate() )
229 emit jumpToTime( todo->dtDue().date() );
230 globalFlagBlockAgenda = 2;
231 }
232 if (mTodo) {
233 todo->setRevision(todo->revision()+1);
234 emit todoChanged(todo);
235 } else {
236 mCalendar->addTodo(todo);
237 mTodo = todo;
238 emit todoAdded(todo);
239 }
240
241 return true;
242}
243
244void KOTodoEditor::deleteTodo()
245{
246 if (mTodo) {
247 if (KOPrefs::instance()->mConfirm) {
248 switch (msgItemDelete()) {
249 case KMessageBox::Continue: // OK
250 emit todoToBeDeleted(mTodo);
251 emit dialogClose(mTodo);
252 mCalendar->deleteTodo(mTodo);
253 emit todoDeleted();
254 reject();
255 break;
256 }
257 }
258 else {
259 emit todoToBeDeleted(mTodo);
260 emit dialogClose(mTodo);
261 mCalendar->deleteTodo(mTodo);
262 emit todoDeleted();
263 reject();
264 }
265 } else {
266 reject();
267 }
268}
269
270void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
271{
272 mRelatedTodo = relatedEvent;
273
274 mGeneral->setDefaults(due,allDay);
275 mDetails->setDefaults();
276 showPage( 0 );
277 if ( mRelatedTodo )
278 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
279 mGeneral->setFocusOn( 2 );
280}
281
282void KOTodoEditor::readTodo(Todo *todo)
283{
284 mGeneral->readTodo(todo);
285 mDetails->readEvent(todo);
286 mRelatedTodo = 0;//todo->relatedTo();
287 // categories
288 // mCategoryDialog->setSelected(todo->categories());
289
290 // We should handle read-only events here.
291}
292
293void KOTodoEditor::writeTodo(Todo *event)
294{
295 mGeneral->writeTodo(event);
296 mDetails->writeEvent(event);
297
298 // set related event, i.e. parent to-do in this case.
299 if (mRelatedTodo) {
300 event->setRelatedTo(mRelatedTodo);
301 }
302}
303
304bool KOTodoEditor::validateInput()
305{
306 if (!mGeneral->validateInput()) return false;
307 if (!mDetails->validateInput()) return false;
308 return true;
309}
310
311int KOTodoEditor::msgItemDelete()
312{
313 return KMessageBox::warningContinueCancel(this,
314 i18n("This item will be permanently deleted."),
315 i18n("KOrganizer Confirmation"),i18n("Delete"));
316}
317
318void KOTodoEditor::modified (int modification)
319{
320 if (modification == KOGlobals::CATEGORY_MODIFIED ||
321 KOGlobals::UNKNOWN_MODIFIED == modification )
322 // mCategoryDialog->setSelected (mTodo->categories ());
323 mGeneral->modified (mTodo, modification);
324
325}
326
327void KOTodoEditor::slotLoadTemplate()
328{
329
330 QString fileName =locateLocal( "templates", "todos" );
331 QDir t_dir;
332 if ( !t_dir.exists(fileName) )
333 t_dir.mkdir ( fileName );
334 fileName += "/todo";
335 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
336 if ( fileName.length() == 0 )
337 return;
338 CalendarLocal cal;
339 ICalFormat format;
340 if ( !format.load( &cal, fileName ) ) {
341 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
342 .arg( fileName ) );
343 return ;
344 }
345 QPtrList<Todo> todos = cal.todos();
346 Todo * todo = todos.first();
347 if ( !todo ) {
348 KMessageBox::error( this,
349 i18n("Template does not\ncontain a valid Todo."));
350 } else {
351 readTodo( todo );
352 }
353
354}
355
356void KOTodoEditor::slotSaveTemplate()
357{
358 QString fileName =locateLocal( "templates", "todos" );
359 QDir t_dir;
360 if ( !t_dir.exists(fileName) )
361 t_dir.mkdir ( fileName );
362 fileName += "/todo";
363 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
364 if ( fileName.length() > 0 )
365 saveTemplate( fileName );
366}
367
368void KOTodoEditor::saveTemplate( const QString &templateName )
369{
370 Todo *todo = new Todo;
371 writeTodo( todo );
372 saveAsTemplate( todo, templateName );
373}