libopie PIM API Documentation

otodoaccessvcal.cpp

Go to the documentation of this file.
00001 #include <qfile.h>
00002 
00003 #include <qtopia/private/vobject_p.h>
00004 #include <qtopia/timeconversion.h>
00005 #include <qtopia/private/qfiledirect_p.h>
00006 
00007 #include "otodoaccessvcal.h"
00008 
00009 namespace {
00010     static OTodo eventByVObj( VObject *obj ){
00011         OTodo event;
00012         VObject *ob;
00013         QCString name;
00014         // no uid, attendees, ... and no fun
00015         // description
00016         if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
00017             name = vObjectStringZValue( ob );
00018 #if 0
00019             event.setDescription( name );
00020 #else
00021             event.setSummary( name );
00022 #endif
00023         }
00024         // summary
00025         if ( ( ob = isAPropertyOf( obj,  VCSummaryProp ) ) != 0 ) {
00026             name = vObjectStringZValue( ob );
00027 #if 0
00028             event.setSummary( name );
00029 #else
00030             event.setDescription( name );
00031 #endif
00032         }
00033         // completed
00034         if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
00035             name = vObjectStringZValue( ob );
00036             if( name == "COMPLETED" ){
00037                 event.setCompleted( true );
00038             }else{
00039                 event.setCompleted( false );
00040             }
00041         }else
00042             event.setCompleted( false );
00043         // priority
00044         if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
00045             name = vObjectStringZValue( ob );
00046             bool ok;
00047             event.setPriority(name.toInt(&ok) );
00048         }
00049         //due date
00050         if((ob = isAPropertyOf(obj, VCDueProp)) ){
00051             event.setHasDueDate( true );
00052             name = vObjectStringZValue( ob );
00053             event.setDueDate( TimeConversion::fromISO8601( name).date() );
00054         }
00055         // categories
00056         if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
00057             name = vObjectStringZValue( ob );
00058             qWarning("Categories:%s", name.data() );
00059         }
00060 
00061         event.setUid( 1 );
00062         return event;
00063     };
00064     static VObject *vobjByEvent( const OTodo &event )  {
00065         VObject *task = newVObject( VCTodoProp );
00066         if( task == 0 )
00067             return 0l;
00068 
00069         if( event.hasDueDate() ) {
00070             QTime time(0, 0, 0);
00071             QDateTime date(event.dueDate(), time );
00072             addPropValue( task, VCDueProp,
00073                           TimeConversion::toISO8601( date ) );
00074         }
00075 
00076         if( event.isCompleted() )
00077             addPropValue( task, VCStatusProp, "COMPLETED");
00078 
00079         QString string = QString::number(event.priority() );
00080         addPropValue( task, VCPriorityProp, string.local8Bit() );
00081 
00082         addPropValue( task, VCCategoriesProp,
00083                       event.idsToString( event.categories() ).local8Bit() );
00084 
00085 #if 0
00086 
00087     // There seems a misrepresentation between summary in otodoevent
00088     // and summary in vcard. 
00089     // The same with description..
00090     // Description is summary and vice versa.. Argh.. (eilers)
00091 
00092 
00093         addPropValue( task, VCDescriptionProp,
00094                       event.description().local8Bit() );
00095 
00096         addPropValue( task, VCSummaryProp,
00097                       event.summary().local8Bit() );
00098 
00099 #else
00100         addPropValue( task, VCDescriptionProp,
00101                       event.summary().local8Bit() );
00102 
00103         addPropValue( task, VCSummaryProp,
00104                       event.description().local8Bit() );
00105 #endif 
00106   return task;
00107 };
00108 }
00109 
00110 OTodoAccessVCal::OTodoAccessVCal( const QString& path )
00111     : m_dirty(false), m_file( path )
00112 {
00113 }
00114 OTodoAccessVCal::~OTodoAccessVCal() {
00115 }
00116 bool OTodoAccessVCal::load() {
00117     m_map.clear();
00118     m_dirty = false;
00119 
00120     VObject* vcal = 0l;
00121     vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
00122     if (!vcal )
00123         return false;
00124 
00125     // Iterate over the list
00126     VObjectIterator it;
00127     VObject* vobj;
00128 
00129     initPropIterator(&it, vcal);
00130 
00131     while( moreIteration( &it ) ) {
00132         vobj = ::nextVObject( &it );
00133         QCString name = ::vObjectName( vobj );
00134         if( name == VCTodoProp ){
00135             OTodo to = eventByVObj( vobj );
00136             m_map.insert( to.uid(), to );
00137         }
00138     }
00139 
00140     // Should I do a delete vcal?
00141 
00142     return true;
00143 }
00144 bool OTodoAccessVCal::reload() {
00145     return load();
00146 }
00147 bool OTodoAccessVCal::save() {
00148     if (!m_dirty )
00149         return true;
00150 
00151     QFileDirect file( m_file );
00152     if (!file.open(IO_WriteOnly ) )
00153         return false;
00154 
00155     VObject *obj;
00156     obj = newVObject( VCCalProp );
00157     addPropValue( obj, VCVersionProp, "1.0" );
00158     VObject *vo;
00159     for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
00160         vo = vobjByEvent( it.data() );
00161         addVObjectProp(obj, vo );
00162     }
00163     writeVObject( file.directHandle(), obj );
00164     cleanVObject( obj );
00165     cleanStrTbl();
00166 
00167     m_dirty = false;
00168     return true;
00169 }
00170 void OTodoAccessVCal::clear() {
00171     m_map.clear();
00172     m_dirty = true;
00173 }
00174 bool OTodoAccessVCal::add( const OTodo& to ) {
00175     m_map.insert( to.uid(), to );
00176     m_dirty = true;
00177     return true;
00178 }
00179 bool OTodoAccessVCal::remove( int uid ) {
00180     m_map.remove( uid );
00181     m_dirty = true;
00182     return true;
00183 }
00184 void OTodoAccessVCal::removeAllCompleted() {
00185     for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
00186         if ( (*it).isCompleted() )
00187             m_map.remove( it );
00188     }
00189 }
00190 bool OTodoAccessVCal::replace( const OTodo& to ) {
00191     m_map.replace( to.uid(), to );
00192     m_dirty = true;
00193     return true;
00194 }
00195 OTodo OTodoAccessVCal::find(int uid )const {
00196     return m_map[uid];
00197 }
00198 QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
00199     QArray<int> ar(0);
00200     return ar;
00201 }
00202 QArray<int> OTodoAccessVCal::allRecords()const {
00203     QArray<int> ar( m_map.count() );
00204     QMap<int, OTodo>::ConstIterator it;
00205     int i = 0;
00206     for ( it = m_map.begin(); it != m_map.end(); ++it ) {
00207         ar[i] = it.key();
00208         i++;
00209     }
00210     return ar;
00211 }
00212 QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const {
00213     QArray<int> ar(0);
00214     return ar;
00215 }
00216 QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) {
00217     QArray<int> ar(0);
00218     return ar;
00219 }
00220 QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& ,
00221                                              const QDate& ,
00222                                              bool  ) {
00223     QArray<int> ar(0);
00224     return ar;
00225 }
00226 QArray<int> OTodoAccessVCal::overDue() {
00227     QArray<int> ar(0);
00228     return ar;
00229 }
00230 QBitArray OTodoAccessVCal::supports()const {
00231     static QBitArray ar = sup();
00232 
00233     return ar;
00234 }
00235 QBitArray OTodoAccessVCal::sup() {
00236     QBitArray ar ( OTodo::CompletedDate +1 );
00237     ar.fill( true );
00238 
00239     ar[OTodo::CrossReference] = false;
00240     ar[OTodo::State ] = false;
00241     ar[OTodo::Reminders] = false;
00242     ar[OTodo::Notifiers] = false;
00243     ar[OTodo::Maintainer] = false;
00244     ar[OTodo::Progress] = false;
00245     ar[OTodo::Alarms ] = false;
00246     ar[OTodo::Recurrence] = false;
00247 
00248     return ar;
00249 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:22 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001