Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opimtemplatebase.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2004 Holger Freyther <zecke@handhelds.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include "opimtemplatebase.h"
00031 
00032 #include <opie2/opimoccurrence.h>
00033 #include <opie2/private/opimoccurrence_p.h>
00034 
00035 namespace Opie {
00036 
00037 static void setPeriod( OPimOccurrence& oc, bool period, const QDate& d,
00038                        const QTime& s, const QTime& t ) {
00039     if ( period )
00040         oc.setPeriod( d );
00041     else
00042         oc.setPeriod( d, s, t );
00043 }
00044 
00045 // namespace Opie {
00046 OPimBase::OPimBase() {}
00047 OPimBase::~OPimBase() {}
00048 
00053 OPimOccurrence::List OPimBase::convertOccurrenceFromBackend( const OPimBackendOccurrence::List& lst )const {
00054     OPimOccurrence::List oc_lst;
00055 
00056     /*
00057      * Split multiday events up. Create the internal data structure
00058      * and then iterate over the days and create the OPimOccurrecne.
00059      */
00060     for ( OPimBackendOccurrence::List::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
00061         OPimBackendOccurrence boc = *it;
00062 
00063         /*
00064          * Create the Shared Data Structure
00065          */
00066         OPimOccurrence::Data *data = new OPimOccurrence::Data();
00067         data->summary = boc.summary();
00068         data->location = boc.location();
00069         data->note = boc.note();
00070         data->uid = boc.uid();
00071         data->backend = const_cast<OPimBase*>(this);
00072 
00073         QDateTime start = boc.startDateTime();
00074         QDateTime end = boc.endDateTime();
00075 
00076         /*
00077          * Start and End are on the same day
00078          * Start and End are on two different ways.
00079          *      - Add Start and End and the days inbetween
00080          */
00081         int dto = start.daysTo( end );
00082         bool allDay = boc.isAllDay();
00083 
00084         if ( dto == 0 ) {
00085             OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::StartEnd );
00086             setPeriod( oc, allDay, start.date(), start.time(), end.time() );
00087             oc_lst.append( oc );
00088         }else {
00089 
00090             OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::Start );
00091             setPeriod( oc, allDay, start.date(), start.time(), QTime(23,59,59));
00092             oc_lst.append( oc );
00093 
00094             QDate next = start.addDays( 1 ).date();
00095             while ( next != end.date() ) {
00096                 oc = OPimOccurrence( data, OPimOccurrence::MidWay );
00097                 setPeriod( oc, allDay, next, QTime(0, 0, 0), QTime(23, 59, 59));
00098                 oc_lst.append( oc );
00099                 next = next.addDays( 1 );
00100             }
00101 
00102             oc = OPimOccurrence( data, OPimOccurrence::End );
00103             setPeriod( oc, allDay, end.date(), QTime(0, 0, 0 ), end.time() );
00104             oc_lst.append( oc );
00105         }
00106     }
00107 
00108     return oc_lst;
00109 }
00110 // }
00111 
00112 }

Generated on Sat Nov 5 16:16:22 2005 for OPIE by  doxygen 1.4.2