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

opimnotify.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) The Main Author <main-author@whereever.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 "opimnotify.h"
00031 
00032 /* QT */
00033 
00034 namespace Opie
00035 {
00036 
00037 struct OPimNotify::Data : public QShared
00038 {
00039     Data() : QShared(), dur( -1 ), parent( 0 )
00040     {
00041     }
00042     QDateTime start;
00043     int dur;
00044     QString application;
00045     int parent;
00046 };
00047 
00048 OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent )
00049 {
00050     data = new Data;
00051     data->start = start;
00052     data->dur = duration;
00053     data->parent = parent;
00054 }
00055 
00056 
00057 OPimNotify::OPimNotify( const OPimNotify& noti )
00058         : data( noti.data )
00059 {
00060     data->ref();
00061 }
00062 
00063 
00064 OPimNotify::~OPimNotify()
00065 {
00066     if ( data->deref() )
00067     {
00068         delete data;
00069         data = 0l;
00070     }
00071 }
00072 
00073 
00074 OPimNotify &OPimNotify::operator=( const OPimNotify& noti )
00075 {
00076     noti.data->ref();
00077     deref();
00078     data = noti.data;
00079 
00080     return *this;
00081 }
00082 
00083 
00084 bool OPimNotify::operator==( const OPimNotify& noti )
00085 {
00086     if ( data == noti.data ) return true;
00087     if ( data->dur != noti.data->dur ) return false;
00088     if ( data->parent != noti.data->parent ) return false;
00089     if ( data->application != noti.data->application ) return false;
00090     if ( data->start != noti.data->start ) return false;
00091 
00092     return true;
00093 }
00094 
00095 
00096 QDateTime OPimNotify::dateTime() const
00097 {
00098     return data->start;
00099 }
00100 
00101 
00102 QString OPimNotify::service() const
00103 {
00104     return data->application;
00105 }
00106 
00107 
00108 int OPimNotify::parent() const
00109 {
00110     return data->parent;
00111 }
00112 
00113 
00114 int OPimNotify::duration() const
00115 {
00116     return data->dur;
00117 }
00118 
00119 
00120 QDateTime OPimNotify::endTime() const
00121 {
00122     return QDateTime( data->start.date(), data->start.time().addSecs( data->dur ) );
00123 }
00124 
00125 
00126 void OPimNotify::setDateTime( const QDateTime& time )
00127 {
00128     copyIntern();
00129     data->start = time;
00130 }
00131 
00132 
00133 void OPimNotify::setDuration( int dur )
00134 {
00135     copyIntern();
00136     data->dur = dur;
00137 }
00138 
00139 
00140 void OPimNotify::setParent( int uid )
00141 {
00142     copyIntern();
00143     data->parent = uid;
00144 }
00145 
00146 
00147 void OPimNotify::setService( const QString& str )
00148 {
00149     copyIntern();
00150     data->application = str;
00151 }
00152 
00153 
00154 void OPimNotify::copyIntern()
00155 {
00156     if ( data->count != 1 )
00157     {
00158         data->deref();
00159         Data* dat = new Data;
00160         dat->start = data->start;
00161         dat->dur = data->dur;
00162         dat->application = data->application;
00163         dat->parent = data->parent;
00164         data = dat;
00165     }
00166 }
00167 
00168 
00169 void OPimNotify::deref()
00170 {
00171     if ( data->deref() )
00172     {
00173         delete data;
00174         data = 0;
00175     }
00176 }
00177 
00178 
00179 /***********************************************************/
00180 struct OPimAlarm::Data : public QShared
00181 {
00182     Data() : QShared()
00183     {
00184         sound = 1;
00185     }
00186     int sound;
00187     QString file;
00188 };
00189 
00190 
00191 OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent )
00192         : OPimNotify( start, duration, parent )
00193 {
00194     data = new Data;
00195     data->sound = sound;
00196 }
00197 
00198 
00199 OPimAlarm::OPimAlarm( const OPimAlarm& al )
00200         : OPimNotify( al ), data( al.data )
00201 {
00202     data->ref();
00203 }
00204 
00205 
00206 OPimAlarm::~OPimAlarm()
00207 {
00208     if ( data->deref() )
00209     {
00210         delete data;
00211         data = 0l;
00212     }
00213 }
00214 
00215 
00216 OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al )
00217 {
00218     OPimNotify::operator=( al );
00219     deref();
00220     al.data->ref();
00221 
00222     data = al.data;
00223 
00224 
00225     return *this;
00226 }
00227 
00228 
00229 bool OPimAlarm::operator==( const OPimAlarm& al )
00230 {
00231     if ( data->sound != al.data->sound ) return false;
00232     else if ( data->sound == Custom && data->file != al.data->file )
00233         return false;
00234 
00235     return OPimNotify::operator==( al );
00236 }
00237 
00238 
00239 QString OPimAlarm::type() const
00240 {
00241     return QString::fromLatin1( "OPimAlarm" );
00242 }
00243 
00244 
00245 int OPimAlarm::sound() const
00246 {
00247     return data->sound;
00248 }
00249 
00250 
00251 QString OPimAlarm::file() const
00252 {
00253     return data->file;
00254 }
00255 
00256 
00257 void OPimAlarm::setSound( int snd )
00258 {
00259     copyIntern();
00260     data->sound = snd;
00261 }
00262 
00263 
00264 void OPimAlarm::setFile( const QString& sound )
00265 {
00266     copyIntern();
00267     data->file = sound;
00268 }
00269 
00270 
00271 void OPimAlarm::deref()
00272 {
00273     if ( data->deref() )
00274     {
00275         delete data;
00276         data = 0l;
00277     }
00278 }
00279 
00280 
00281 void OPimAlarm::copyIntern()
00282 {
00283     if ( data->count != 1 )
00284     {
00285         data->deref();
00286         Data *newDat = new Data;
00287         newDat->sound = data->sound;
00288         newDat->file = data->file;
00289         data = newDat;
00290     }
00291 }
00292 
00293 
00294 /************************/
00295 struct OPimReminder::Data : public QShared
00296 {
00297     Data() : QShared(), record( 0 )
00298     {}
00299     int record;
00300 
00301 };
00302 
00303 
00304 OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent )
00305         : OPimNotify( start, dur, parent )
00306 {
00307     data = new Data;
00308     data->record = uid;
00309 }
00310 
00311 
00312 OPimReminder::OPimReminder( const OPimReminder& rem )
00313         : OPimNotify( rem ), data( rem.data )
00314 {
00315     data->ref();
00316 }
00317 
00318 
00319 OPimReminder& OPimReminder::operator=( const OPimReminder& rem )
00320 {
00321     OPimNotify::operator=( rem );
00322 
00323     deref();
00324     rem.data->ref();
00325     data = rem.data;
00326 
00327     return *this;
00328 }
00329 
00330 
00331 bool OPimReminder::operator==( const OPimReminder& rem )
00332 {
00333     if ( data->record != rem.data->record ) return false;
00334 
00335     return OPimNotify::operator==( rem );
00336 }
00337 
00338 
00339 QString OPimReminder::type() const
00340 {
00341     return QString::fromLatin1( "OPimReminder" );
00342 }
00343 
00344 
00345 int OPimReminder::recordUid() const
00346 {
00347     return data->record;
00348 }
00349 
00350 
00351 void OPimReminder::setRecordUid( int uid )
00352 {
00353     copyIntern();
00354     data->record = uid;
00355 }
00356 
00357 
00358 void OPimReminder::deref()
00359 {
00360     if ( data->deref() )
00361     {
00362         delete data;
00363         data = 0l;
00364     }
00365 }
00366 
00367 
00368 void OPimReminder::copyIntern()
00369 {
00370     if ( data->count != 1 )
00371     {
00372         Data * da = new Data;
00373         da->record = data->record;
00374         data = da;
00375     }
00376 }
00377 
00378 }

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