kpilot/kpilot

todoEditor.cc

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 static const char *todoEditor_id =
00047     "$Id: todoEditor.cc 529452 2006-04-13 14:05:00Z mueller $";
00048 
00049 TodoEditor::TodoEditor(PilotTodoEntry * p, struct ToDoAppInfo *appInfo,
00050     QWidget * parent, const char *name) :
00051     KDialogBase(parent, name, false, i18n("To-do Editor"), Ok|Cancel),
00052     fDeleteOnCancel(p == 0L),
00053     fTodo(p),
00054     fAppInfo(appInfo)
00055 {
00056     FUNCTIONSETUP;
00057 
00058     fWidget=new TodoEditorBase(this);
00059     setMainWidget(fWidget);
00060     fillFields();
00061 
00062     connect(parent, SIGNAL(recordChanged(PilotTodoEntry *)),
00063         this, SLOT(updateRecord(PilotTodoEntry *)));
00064 
00065     (void) todoEditor_id;
00066 }
00067 
00068 TodoEditor::~TodoEditor()
00069 {
00070     FUNCTIONSETUP;
00071 
00072     if (fDeleteOnCancel && fTodo)
00073     {
00074 #ifdef DEBUG
00075         DEBUGKPILOT << fname
00076             << ": Deleting private todo record." << endl;
00077 #endif
00078         delete fTodo;
00079         fTodo = 0L;
00080     }
00081 
00082 #ifdef DEBUG
00083     DEBUGKPILOT << fname << ": Help! I'm deleting!" << endl;
00084 #endif
00085 }
00086 
00087 
00088 
00089 void TodoEditor::fillFields()
00090 {
00091     FUNCTIONSETUP;
00092 
00093     if (fTodo == 0L)
00094     {
00095         fTodo = new PilotTodoEntry(*fAppInfo);
00096         fDeleteOnCancel = true;
00097     }
00098 
00099     fWidget->fDescription->setText(fTodo->getDescription());
00100     fWidget->fCompleted->setChecked(fTodo->getComplete());
00101     if (fTodo->getIndefinite())
00102     {
00103         fWidget->fHasEndDate->setChecked(false);
00104     }
00105     else
00106     {
00107         fWidget->fHasEndDate->setChecked(true);
00108         fWidget->fEndDate->setDate(readTm(fTodo->getDueDate()).date());
00109     }
00110     fWidget->fPriority->setCurrentItem(fTodo->getPriority());
00111 //  fCategory->setCurrentItem(fTodo->getCategory()));
00112     fWidget->fNote->setText(fTodo->getNote());
00113 }
00114 
00115 
00116 
00117 /* slot */ void TodoEditor::slotCancel()
00118 {
00119     FUNCTIONSETUP;
00120 
00121     if (fDeleteOnCancel && fTodo)
00122     {
00123         delete fTodo;
00124 
00125         fTodo = 0L;
00126     }
00127     KDialogBase::slotCancel();
00128 }
00129 
00130 /* slot */ void TodoEditor::slotOk()
00131 {
00132     FUNCTIONSETUP;
00133 
00134     // Commit changes here
00135     fTodo->setDescription(fWidget->fDescription->text());
00136     fTodo->setComplete(fWidget->fCompleted->isChecked());
00137     if (fWidget->fHasEndDate->isChecked())
00138     {
00139         fTodo->setIndefinite(false);
00140         struct tm duedate=writeTm(fWidget->fEndDate->date());
00141         fTodo->setDueDate(duedate);
00142     }
00143     else
00144     {
00145         fTodo->setIndefinite(true);
00146     }
00147     fTodo->setPriority(fWidget->fPriority->currentItem());
00148 //  fTodo->setCategory(fWidget->fCategory->currentItem());
00149     fTodo->setNote(fWidget->fNote->text());
00150 
00151     emit(recordChangeComplete(fTodo));
00152     fDeleteOnCancel = false;
00153     KDialogBase::slotOk();
00154 }
00155 
00156 /* slot */ void TodoEditor::updateRecord(PilotTodoEntry * p)
00157 {
00158     FUNCTIONSETUP;
00159     if (p != fTodo)
00160     {
00161         // Not meant for me
00162         //
00163         //
00164         return;
00165     }
00166 
00167     if (p->isDeleted())
00168     {
00169         delayedDestruct();
00170         return;
00171     }
00172     else
00173     {
00174         fillFields();
00175     }
00176 }
00177 
KDE Home | KDE Accessibility Home | Description of Access Keys