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

otodoaccessvcal.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
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 <opie2/private/vobject_p.h>
00031 
00032 /* OPIE */
00033 #include <opie2/otodoaccessvcal.h>
00034 #include <opie2/odebug.h>
00035 
00036 #include <qpe/timeconversion.h>
00037 
00038 /* QT */
00039 //FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
00040 #define protected public
00041 #include <qfile.h>
00042 #undef protected
00043 
00044 using namespace Opie;
00045 
00046 namespace {
00047     static OPimTodo eventByVObj( VObject *obj ){
00048         OPimTodo event;
00049         VObject *ob;
00050         QCString name;
00051         // no uid, attendees, ... and no fun
00052         // description
00053         if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
00054             name = vObjectStringZValue( ob );
00055 #if 0
00056             event.setDescription( name );
00057 #else
00058             event.setSummary( name );
00059 #endif
00060         }
00061         // summary
00062         if ( ( ob = isAPropertyOf( obj,  VCSummaryProp ) ) != 0 ) {
00063             name = vObjectStringZValue( ob );
00064 #if 0
00065             event.setSummary( name );
00066 #else
00067             event.setDescription( name );
00068 #endif
00069         }
00070         // completed
00071         if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
00072             name = vObjectStringZValue( ob );
00073             if( name == "COMPLETED" ){
00074                 event.setCompleted( true );
00075             }else{
00076                 event.setCompleted( false );
00077             }
00078         }else
00079             event.setCompleted( false );
00080         // priority
00081         if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
00082             name = vObjectStringZValue( ob );
00083             bool ok;
00084             event.setPriority(name.toInt(&ok) );
00085         }
00086         //due date
00087         if((ob = isAPropertyOf(obj, VCDueProp)) ){
00088             event.setHasDueDate( true );
00089             name = vObjectStringZValue( ob );
00090             event.setDueDate( TimeConversion::fromISO8601( name).date() );
00091         }
00092         // categories
00093         if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
00094             name = vObjectStringZValue( ob );
00095         }
00096 
00097         event.setUid( 1 );
00098         return event;
00099     };
00100     static VObject *vobjByEvent( const OPimTodo &event )  {
00101         VObject *task = newVObject( VCTodoProp );
00102         if( task == 0 )
00103             return 0l;
00104 
00105         if( event.hasDueDate() ) {
00106             QTime time(0, 0, 0);
00107             QDateTime date(event.dueDate(), time );
00108             addPropValue( task, VCDueProp,
00109                           TimeConversion::toISO8601( date ) );
00110         }
00111 
00112         if( event.isCompleted() )
00113             addPropValue( task, VCStatusProp, "COMPLETED");
00114 
00115         QString string = QString::number(event.priority() );
00116         addPropValue( task, VCPriorityProp, string.local8Bit() );
00117 
00118         addPropValue( task, VCCategoriesProp,
00119                       event.idsToString( event.categories() ).local8Bit() );
00120 
00121 #if 0
00122 
00123     // There seems a misrepresentation between summary in otodoevent
00124     // and summary in vcard.
00125     // The same with description..
00126     // Description is summary and vice versa.. Argh.. (eilers)
00127 
00128 
00129         addPropValue( task, VCDescriptionProp,
00130                       event.description().local8Bit() );
00131 
00132         addPropValue( task, VCSummaryProp,
00133                       event.summary().local8Bit() );
00134 
00135 #else
00136         addPropValue( task, VCDescriptionProp,
00137                       event.summary().local8Bit() );
00138 
00139         addPropValue( task, VCSummaryProp,
00140                       event.description().local8Bit() );
00141 #endif
00142   return task;
00143 };
00144 }
00145 
00146 namespace Opie {
00147 OPimTodoAccessVCal::OPimTodoAccessVCal( const QString& path )
00148     : m_dirty(false), m_file( path )
00149 {
00150 }
00151 OPimTodoAccessVCal::~OPimTodoAccessVCal() {
00152 }
00153 bool OPimTodoAccessVCal::load() {
00154     m_map.clear();
00155     m_dirty = false;
00156 
00157     VObject* vcal = 0l;
00158     vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
00159     if (!vcal )
00160         return false;
00161 
00162     // Iterate over the list
00163     VObjectIterator it;
00164     VObject* vobj;
00165 
00166     initPropIterator(&it, vcal);
00167 
00168     while( moreIteration( &it ) ) {
00169         vobj = ::nextVObject( &it );
00170         QCString name = ::vObjectName( vobj );
00171         if( name == VCTodoProp ){
00172             OPimTodo to = eventByVObj( vobj );
00173             m_map.insert( to.uid(), to );
00174         }
00175     }
00176 
00177     // Should I do a delete vcal?
00178 
00179     return true;
00180 }
00181 bool OPimTodoAccessVCal::reload() {
00182     return load();
00183 }
00184 bool OPimTodoAccessVCal::save() {
00185     if (!m_dirty )
00186         return true;
00187 
00188     QFile file( m_file );
00189     if (!file.open(IO_WriteOnly ) )
00190         return false;
00191 
00192     VObject *obj;
00193     obj = newVObject( VCCalProp );
00194     addPropValue( obj, VCVersionProp, "1.0" );
00195     VObject *vo;
00196     for(QMap<int, OPimTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
00197         vo = vobjByEvent( it.data() );
00198         addVObjectProp(obj, vo );
00199     }
00200     writeVObject( file.fh, obj ); //FIXME: HACK!!!
00201     cleanVObject( obj );
00202     cleanStrTbl();
00203 
00204     m_dirty = false;
00205     return true;
00206 }
00207 void OPimTodoAccessVCal::clear() {
00208     m_map.clear();
00209     m_dirty = true;
00210 }
00211 bool OPimTodoAccessVCal::add( const OPimTodo& to ) {
00212     m_map.insert( to.uid(), to );
00213     m_dirty = true;
00214     return true;
00215 }
00216 bool OPimTodoAccessVCal::remove( int uid ) {
00217     m_map.remove( uid );
00218     m_dirty = true;
00219     return true;
00220 }
00221 void OPimTodoAccessVCal::removeAllCompleted() {
00222     for ( QMap<int, OPimTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
00223         if ( (*it).isCompleted() )
00224             m_map.remove( it );
00225     }
00226 }
00227 bool OPimTodoAccessVCal::replace( const OPimTodo& to ) {
00228     m_map.replace( to.uid(), to );
00229     m_dirty = true;
00230     return true;
00231 }
00232 OPimTodo OPimTodoAccessVCal::find(int uid )const {
00233     return m_map[uid];
00234 }
00235 
00236 QArray<int> OPimTodoAccessVCal::allRecords()const {
00237     QArray<int> ar( m_map.count() );
00238     QMap<int, OPimTodo>::ConstIterator it;
00239     int i = 0;
00240     for ( it = m_map.begin(); it != m_map.end(); ++it ) {
00241         ar[i] = it.key();
00242         i++;
00243     }
00244     return ar;
00245 }
00246 
00247 QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& ,
00248                                              const QDate& ,
00249                                              bool  )const {
00250     QArray<int> ar(0);
00251     return ar;
00252 }
00253 
00254 QArray<int> OPimTodoAccessVCal::overDue()const {
00255     QArray<int> ar(0);
00256     return ar;
00257 }
00258 
00259 }

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