libopie PIM API Documentation

opimnotify.cpp

Go to the documentation of this file.
00001 #include <qshared.h>
00002 
00003 #include "opimnotify.h"
00004 
00005 struct OPimNotify::Data : public QShared {
00006     Data() : QShared(),dur(-1),parent(0) {
00007 
00008     }
00009     QDateTime start;
00010     int dur;
00011     QString application;
00012     int parent;
00013 };
00014 
00015 OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) {
00016     data = new Data;
00017     data->start = start;
00018     data->dur = duration;
00019     data->parent = parent;
00020 }
00021 OPimNotify::OPimNotify( const OPimNotify& noti)
00022     : data( noti.data )
00023 {
00024     data->ref();
00025 }
00026 OPimNotify::~OPimNotify() {
00027     if ( data->deref() ) {
00028         delete data;
00029         data = 0l;
00030     }
00031 }
00032 
00033 OPimNotify &OPimNotify::operator=( const OPimNotify& noti) {
00034     noti.data->ref();
00035     deref();
00036     data = noti.data;
00037 
00038     return *this;
00039 }
00040 bool OPimNotify::operator==( const OPimNotify& noti ) {
00041     if ( data == noti.data ) return true;
00042     if ( data->dur != noti.data->dur ) return false;
00043     if ( data->parent != noti.data->parent ) return false;
00044     if ( data->application != noti.data->application ) return false;
00045     if ( data->start != noti.data->start ) return false;
00046 
00047     return true;
00048 }
00049 QDateTime OPimNotify::dateTime()const {
00050     return data->start;
00051 }
00052 QString OPimNotify::service()const {
00053     return data->application;
00054 }
00055 int OPimNotify::parent()const {
00056     return data->parent;
00057 }
00058 int OPimNotify::duration()const {
00059     return data->dur;
00060 }
00061 QDateTime OPimNotify::endTime()const {
00062     return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) );
00063 }
00064 void OPimNotify::setDateTime( const QDateTime& time ) {
00065     copyIntern();
00066     data->start = time;
00067 }
00068 void OPimNotify::setDuration( int dur ) {
00069     copyIntern();
00070     data->dur = dur;
00071 }
00072 void OPimNotify::setParent( int uid ) {
00073     copyIntern();
00074     data->parent = uid;
00075 }
00076 void OPimNotify::setService( const QString& str ) {
00077     copyIntern();
00078     data->application = str;
00079 }
00080 void OPimNotify::copyIntern() {
00081     if ( data->count != 1 ) {
00082         data->deref();
00083         Data* dat = new Data;
00084         dat->start = data->start;
00085         dat->dur   = data->dur;
00086         dat->application = data->application;
00087         dat->parent = data->parent;
00088         data = dat;
00089     }
00090 }
00091 void OPimNotify::deref() {
00092     if ( data->deref() ) {
00093         delete data;
00094         data = 0;
00095     }
00096 }
00097 
00098 /***********************************************************/
00099 struct OPimAlarm::Data : public QShared {
00100     Data() : QShared() {
00101         sound = 1;
00102     }
00103     int sound;
00104     QString file;
00105 };
00106 OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent )
00107     : OPimNotify( start, duration, parent )
00108 {
00109     data = new Data;
00110     data->sound = sound;
00111 }
00112 OPimAlarm::OPimAlarm( const OPimAlarm& al)
00113     : OPimNotify(al), data( al.data )
00114 {
00115     data->ref();
00116 }
00117 OPimAlarm::~OPimAlarm() {
00118     if ( data->deref() ) {
00119         delete data;
00120         data = 0l;
00121     }
00122 }
00123 OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al)
00124 {
00125     OPimNotify::operator=( al );
00126     deref();
00127     al.data->ref();
00128 
00129     data = al.data;
00130 
00131 
00132     return *this;
00133 }
00134 bool OPimAlarm::operator==( const OPimAlarm& al) {
00135     if ( data->sound != al.data->sound ) return false;
00136     else if ( data->sound == Custom && data->file != al.data->file )
00137         return false;
00138 
00139     return OPimNotify::operator==( al );
00140 }
00141 QString OPimAlarm::type()const {
00142     return QString::fromLatin1("OPimAlarm");
00143 }
00144 int OPimAlarm::sound()const {
00145     return data->sound;
00146 }
00147 QString OPimAlarm::file()const {
00148     return data->file;
00149 }
00150 void OPimAlarm::setSound( int snd) {
00151     copyIntern();
00152     data->sound = snd;
00153 }
00154 void OPimAlarm::setFile( const QString& sound ) {
00155     copyIntern();
00156     data->file = sound;
00157 }
00158 void OPimAlarm::deref() {
00159     if ( data->deref() ) {
00160         delete data;
00161         data = 0l;
00162     }
00163 }
00164 void OPimAlarm::copyIntern() {
00165     if ( data->count != 1 ) {
00166         data->deref();
00167         Data *newDat = new Data;
00168         newDat->sound = data->sound;
00169         newDat->file  = data->file;
00170         data = newDat;
00171     }
00172 }
00173 /************************/
00174 struct OPimReminder::Data : public QShared {
00175     Data() : QShared(), record( 0) {
00176     }
00177     int record;
00178 
00179 };
00180 OPimReminder::OPimReminder( int uid, const QDateTime& start,  int dur, int parent )
00181     : OPimNotify( start, dur, parent )
00182 {
00183     data = new Data;
00184     data->record = uid;
00185 }
00186 OPimReminder::OPimReminder( const OPimReminder& rem )
00187     :  OPimNotify( rem ), data( rem.data )
00188 {
00189     data->ref();
00190 }
00191 OPimReminder& OPimReminder::operator=( const OPimReminder& rem) {
00192     OPimNotify::operator=(rem );
00193 
00194     deref();
00195     rem.data->ref();
00196     data = rem.data;
00197 
00198     return *this;
00199 }
00200 bool OPimReminder::operator==( const OPimReminder& rem) {
00201     if ( data->record != rem.data->record ) return false;
00202 
00203     return OPimNotify::operator==( rem );
00204 }
00205 QString OPimReminder::type()const {
00206     return QString::fromLatin1("OPimReminder");
00207 }
00208 int OPimReminder::recordUid()const {
00209     return data->record;
00210 }
00211 void OPimReminder::setRecordUid( int uid ) {
00212     copyIntern();
00213     data->record = uid;
00214 }
00215 void OPimReminder::deref() {
00216     if ( data->deref() ) {
00217         delete data;
00218         data = 0l;
00219     }
00220 }
00221 void OPimReminder::copyIntern() {
00222     if ( data->count != 1 ) {
00223         Data* da = new Data;
00224         da->record = data->record;
00225         data = da;
00226     }
00227 }
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:20 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001