00001 /* 00002 This file is part of the Opie Project 00003 Copyright (C) 2003, 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 "opimoccurrence.h" 00031 #include <opie2/opimtemplatebase.h> 00032 #include <opie2/private/opimoccurrence_p.h> 00033 00034 00035 /* QT */ 00036 #include <qshared.h> 00037 00038 00039 namespace Opie { 00040 00041 OPimOccurrence::OPimOccurrence( OPimOccurrence::Data* _data, 00042 enum OPimOccurrence::Position pos ) 00043 : m_pos( pos ), data( _data ) 00044 {} 00045 00049 OPimOccurrence::OPimOccurrence( const OPimOccurrence& oc ) 00050 : data( oc.data ) 00051 { 00052 /* 00053 * Increment the reference count 00054 */ 00055 data->ref(); 00056 00057 /* 00058 * copy the other information 00059 */ 00060 m_start = oc.m_start; 00061 m_end = oc.m_end; 00062 m_occurrence = oc.m_occurrence; 00063 m_isAllDay = oc.m_isAllDay; 00064 m_pos = oc.m_pos; 00065 } 00066 00067 OPimOccurrence::OPimOccurrence() 00068 : m_isAllDay( false ), m_pos( StartEnd ) 00069 { 00070 /* simple convient c'tor */ 00071 data = new OPimOccurrence::Data(); 00072 } 00073 00074 OPimOccurrence::~OPimOccurrence() { 00075 deref(); 00076 } 00077 00081 OPimOccurrence& OPimOccurrence::operator=( const OPimOccurrence& oc ) { 00082 /* guard against self assignment */ 00083 if ( this == &oc ) return *this; 00084 00085 oc.data->ref(); 00086 deref(); 00087 data = oc.data; 00088 00089 00090 /* 00091 * copy the other information 00092 */ 00093 m_start = oc.m_start; 00094 m_end = oc.m_end; 00095 m_occurrence = oc.m_occurrence; 00096 m_isAllDay = oc.m_isAllDay; 00097 m_pos = oc.m_pos; 00098 00099 return *this; 00100 } 00101 00102 00106 void OPimOccurrence::deref() { 00107 if ( data->deref() ) { 00108 delete data; 00109 data = 0; 00110 } 00111 } 00112 00124 void OPimOccurrence::setPeriod( const QDate& from ) { 00125 m_occurrence = from; 00126 m_start = m_end = QTime(); // assign invalid value just in case 00127 m_isAllDay = true; 00128 } 00129 00141 void OPimOccurrence::setPeriod( const QDateTime& from, const QDateTime& to ) { 00142 m_occurrence = from.date(); 00143 m_start = from.time(); 00144 m_end = to.time(); 00145 m_isAllDay = false; 00146 } 00147 00155 void OPimOccurrence::setPeriod( const QDate& from, const QTime& start, 00156 const QTime& end ) { 00157 m_occurrence = from; 00158 m_start = start; 00159 m_end = end; 00160 m_isAllDay = false; 00161 } 00162 00163 00169 bool OPimOccurrence::isAllDay()const { 00170 return m_isAllDay; 00171 } 00172 00173 00178 QDate OPimOccurrence::date()const { 00179 return m_occurrence; 00180 } 00181 00182 00189 QTime OPimOccurrence::startTime()const { 00190 return m_start; 00191 } 00192 00193 QTime OPimOccurrence::endTime()const { 00194 return m_end; 00195 } 00196 00197 QDateTime OPimOccurrence::startDateTime()const { 00198 return QDateTime( m_occurrence, m_start ); 00199 } 00200 00201 QDateTime OPimOccurrence::endDateTime()const { 00202 return QDateTime( m_occurrence, m_end ); 00203 } 00204 00205 00206 QString OPimOccurrence::summary()const { 00207 return data->summary; 00208 } 00209 00210 QString OPimOccurrence::location()const { 00211 return data->location; 00212 } 00213 00214 QString OPimOccurrence::note()const { 00215 return data->note; 00216 } 00217 00218 00223 int OPimOccurrence::length()const { 00224 if ( m_isAllDay ) 00225 return -1; 00226 else 00227 return ( m_end.hour() * 60 - m_start.hour() * 60 ) 00228 + QABS( m_start.minute() - m_end.minute() ); 00229 } 00230 00231 enum OPimOccurrence::Position OPimOccurrence::position()const { 00232 return m_pos; 00233 } 00234 00235 void OPimOccurrence::setPosition( enum OPimOccurrence::Position& pos ) { 00236 m_pos = pos; 00237 } 00238 00239 00240 Opie::Core::OSharedPointer<OPimRecord> OPimOccurrence::record()const { 00241 if ( !data->record && data->backend ) 00242 data->record = data->backend->record( data->uid ); 00243 return data->record; 00244 } 00245 00246 template<class Record> Record OPimOccurrence::internalToRecord()const { 00247 Record target; 00248 00249 /* If it is not loaded, try to load it using OPimBase */ 00250 if ( !data->record && data->backend ) 00251 data->record = data->backend->record( data->uid ); 00252 00253 Record *ta = Record::safeCast( data->record ); 00254 if ( ta ) 00255 target = *ta; 00256 00257 00258 return target; 00259 } 00260 00261 OPimEvent OPimOccurrence::toEvent()const { 00262 return internalToRecord<OPimEvent>(); 00263 } 00264 00265 OPimTodo OPimOccurrence::toTodo()const { 00266 return internalToRecord<OPimTodo>(); 00267 } 00268 00269 OPimContact OPimOccurrence::toContact()const { 00270 return internalToRecord<OPimContact>(); 00271 } 00272 00273 bool OPimOccurrence::operator<( const OPimOccurrence& oc )const { 00274 if ( m_occurrence < oc.m_occurrence ) 00275 return true; 00276 if ( m_occurrence == oc.m_occurrence ) 00277 return m_start < oc.m_start; 00278 else 00279 return false; 00280 } 00281 00282 bool OPimOccurrence::operator<=( const OPimOccurrence& oc )const { 00283 return ( m_occurrence <= oc.m_occurrence ); 00284 } 00285 00286 bool OPimOccurrence::operator==( const OPimOccurrence& oc )const { 00287 if ( data->uid != oc.data->uid ) 00288 return false; 00289 if ( m_occurrence != oc.m_occurrence ) 00290 return false; 00291 if ( m_isAllDay != oc.m_isAllDay ) 00292 return false; 00293 if ( m_isAllDay && oc.m_isAllDay ) 00294 if ( m_start != oc.m_start || 00295 m_end != oc.m_end ) 00296 return false; 00297 if ( data->summary != oc.data->summary ) 00298 return false; 00299 if ( data->note != oc.data->note ) 00300 return false; 00301 if ( data->location != oc.data->location ) 00302 return false; 00303 00304 return true; 00305 } 00306 00307 bool OPimOccurrence::operator!=( const OPimOccurrence& oc )const { 00308 return !( *this == oc ); 00309 } 00310 00311 bool OPimOccurrence::operator>( const OPimOccurrence& oc )const { 00312 return !( *this <= oc ); 00313 } 00314 00315 bool OPimOccurrence::operator>=( const OPimOccurrence& oc )const { 00316 return !( *this < oc ); 00317 } 00318 00319 }
1.4.2