kpilot

todoEditor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* KPilot
00003 **
00004 ** Copyright (C) 2000 by Dan Pilone
00005 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 **
00007 ** This is a dialog window that edits one single todo record.
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 
00031 
00032 #include "options.h"
00033 
00034 #include <qcombobox.h>
00035 #include <qlayout.h>
00036 #include <qlabel.h>
00037 #include <qtextedit.h>
00038 #include <qcheckbox.h>
00039 
00040 #include <kdatewidget.h>
00041 
00042 #include "pilotTodoEntry.h"
00043 #include "todoEditor_base.h"
00044 #include "todoEditor.moc"
00045 
00046 
00047 TodoEditor::TodoEditor(PilotTodoEntry * p, struct ToDoAppInfo *appInfo,
00048     QWidget * parent, const char *name) :
00049     KDialogBase(parent, name, false, i18n("To-do Editor"), Ok|Cancel),
00050     fDeleteOnCancel(p == 0L),
00051     fTodo(p),
00052     fAppInfo(appInfo)
00053 {
00054     FUNCTIONSETUP;
00055 
00056     fWidget=new TodoEditorBase(this);
00057     setMainWidget(fWidget);
00058     fillFields();
00059 
00060     connect(parent, SIGNAL(recordChanged(PilotTodoEntry *)),
00061         this, SLOT(updateRecord(PilotTodoEntry *)));
00062 
00063 }
00064 
00065 TodoEditor::~TodoEditor()
00066 {
00067     FUNCTIONSETUP;
00068 
00069     if (fDeleteOnCancel && fTodo)
00070     {
00071 #ifdef DEBUG
00072         DEBUGKPILOT << fname
00073             << ": Deleting private todo record." << endl;
00074 #endif
00075         delete fTodo;
00076         fTodo = 0L;
00077     }
00078 
00079 #ifdef DEBUG
00080     DEBUGKPILOT << fname << ": Help! I'm deleting!" << endl;
00081 #endif
00082 }
00083 
00084 
00085 
00086 void TodoEditor::fillFields()
00087 {
00088     FUNCTIONSETUP;
00089 
00090     if (fTodo == 0L)
00091     {
00092         fTodo = new PilotTodoEntry();
00093         fDeleteOnCancel = true;
00094     }
00095 
00096     fWidget->fDescription->setText(fTodo->getDescription());
00097     fWidget->fCompleted->setChecked(fTodo->getComplete());
00098     if (fTodo->getIndefinite())
00099     {
00100         fWidget->fHasEndDate->setChecked(false);
00101     }
00102     else
00103     {
00104         fWidget->fHasEndDate->setChecked(true);
00105         fWidget->fEndDate->setDate(readTm(fTodo->getDueDate()).date());
00106     }
00107     fWidget->fPriority->setCurrentItem(fTodo->getPriority());
00108 //  fCategory->setCurrentItem(fTodo->getCategory()));
00109     fWidget->fNote->setText(fTodo->getNote());
00110 }
00111 
00112 
00113 
00114 /* slot */ void TodoEditor::slotCancel()
00115 {
00116     FUNCTIONSETUP;
00117 
00118     if (fDeleteOnCancel && fTodo)
00119     {
00120         delete fTodo;
00121 
00122         fTodo = 0L;
00123     }
00124     KDialogBase::slotCancel();
00125 }
00126 
00127 /* slot */ void TodoEditor::slotOk()
00128 {
00129     FUNCTIONSETUP;
00130 
00131     // Commit changes here
00132     fTodo->setDescription(fWidget->fDescription->text());
00133     fTodo->setComplete(fWidget->fCompleted->isChecked());
00134     if (fWidget->fHasEndDate->isChecked())
00135     {
00136         fTodo->setIndefinite(false);
00137         struct tm duedate=writeTm(fWidget->fEndDate->date());
00138         fTodo->setDueDate(duedate);
00139     }
00140     else
00141     {
00142         fTodo->setIndefinite(true);
00143     }
00144     fTodo->setPriority(fWidget->fPriority->currentItem());
00145 //  fTodo->setCategory(fWidget->fCategory->currentItem());
00146     fTodo->setNote(fWidget->fNote->text());
00147 
00148     emit(recordChangeComplete(fTodo));
00149     KDialogBase::slotOk();
00150 }
00151 
00152 /* slot */ void TodoEditor::updateRecord(PilotTodoEntry * p)
00153 {
00154     FUNCTIONSETUP;
00155     if (p != fTodo)
00156     {
00157         // Not meant for me
00158         //
00159         //
00160         return;
00161     }
00162 
00163     if (p->isDeleted())
00164     {
00165         delayedDestruct();
00166         return;
00167     }
00168     else
00169     {
00170         fillFields();
00171     }
00172 }
00173