kpilot

todoRecord.cc

Go to the documentation of this file.
00001 /* vcalRecord.cc                       KPilot
00002 **
00003 ** Copyright (C) 2006 by Adriaan de Groot <groot@kde.org>
00004 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00005 ** Copyright (C) 2001 by Dan Pilone
00006 **
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 #include <libkcal/calendar.h>
00033 #include <libkcal/calendarlocal.h>
00034 #include <libkcal/recurrence.h>
00035 #include <libkcal/vcalformat.h>
00036 
00037 #include "pilot.h"
00038 #include "pilotTodoEntry.h"
00039 
00040 #include "kcalRecord.h"
00041 #include "todoRecord.h"
00042 
00043 bool KCalSync::setTodoEntry(PilotTodoEntry *de,
00044     const KCal::Todo *todo,
00045     const CategoryAppInfo &info)
00046 {
00047     FUNCTIONSETUP;
00048     if (!de || !todo) {
00049         DEBUGKPILOT << fname << ": NULL todo given... Skipping it" << endl;
00050         return false;
00051     }
00052 
00053     // set secrecy, start/end times, alarms, recurrence, exceptions, summary and description:
00054     if (todo->secrecy()!=KCal::Todo::SecrecyPublic)
00055     {
00056         de->setSecret( true );
00057     }
00058 
00059     // update it from the iCalendar Todo.
00060 
00061     if (todo->hasDueDate()) {
00062         struct tm t = writeTm(todo->dtDue());
00063         de->setDueDate(t);
00064         de->setIndefinite(0);
00065     } else {
00066         de->setIndefinite(1);
00067     }
00068 
00069     // TODO: take recurrence (code in VCAlConduit) from ActionNames
00070 
00071     setCategory(de, todo, info);
00072 
00073     // TODO: sync the alarm from ActionNames. Need to extend PilotTodoEntry
00074     de->setPriority(todo->priority());
00075 
00076     de->setComplete(todo->isCompleted());
00077 
00078     // what we call summary pilot calls description.
00079     de->setDescription(todo->summary());
00080 
00081     // what we call description pilot puts as a separate note
00082     de->setNote(todo->description());
00083 
00084     DEBUGKPILOT << "-------- " << todo->summary() << endl;
00085     return de->pack();
00086 }
00087 
00088 bool KCalSync::setTodo(KCal::Todo *e,
00089     const PilotTodoEntry *de,
00090     const CategoryAppInfo &info)
00091 {
00092     FUNCTIONSETUP;
00093 
00094     if (!e)
00095     {
00096         DEBUGKPILOT << fname
00097             << ": null todo entry given. skipping..." << endl;
00098         return false;
00099     }
00100     if (!de)
00101     {
00102         DEBUGKPILOT << fname
00103             << "! NULL todo entry given... Skipping it" << endl;
00104         return false;
00105     }
00106 
00107 
00108     e->setPilotId(de->id());
00109     DEBUGKPILOT<<fname<<": set KCal item to pilotId: [" << e->pilotId() << "] ..."<<endl;
00110 
00111     e->setSecrecy(de->isSecret() ? KCal::Todo::SecrecyPrivate : KCal::Todo::SecrecyPublic);
00112 
00113     if (de->getIndefinite()) {
00114         e->setHasDueDate(false);
00115     } else {
00116         e->setDtDue(readTm(de->getDueDate()));
00117         e->setHasDueDate(true);
00118     }
00119 
00120     // Categories
00121     setCategory(e, de, info);
00122 
00123     // PRIORITY //
00124     e->setPriority(de->getPriority());
00125 
00126     // COMPLETED? //
00127     e->setCompleted(de->getComplete());
00128     if ( de->getComplete() && !e->hasCompletedDate() ) {
00129         e->setCompleted( QDateTime::currentDateTime() );
00130     }
00131 
00132     e->setSummary(de->getDescription());
00133     e->setDescription(de->getNote());
00134 
00135     // NOTE: This MUST be done last, since every other set* call
00136     // calls updated(), which will trigger an
00137     // setSyncStatus(SYNCMOD)!!!
00138     e->setSyncStatus(KCal::Incidence::SYNCNONE);
00139 
00140     return true;
00141 }