libopie PIM API Documentation

opimnotifymanager.cpp

Go to the documentation of this file.
00001 #include "opimnotifymanager.h"
00002 
00003 #include "oconversion.h"
00004 
00005 #include <qstringlist.h>
00006 
00007 OPimNotifyManager::OPimNotifyManager( const Reminders& rem,  const Alarms& al)
00008     : m_rem( rem ), m_al( al )
00009 {}
00010 OPimNotifyManager::~OPimNotifyManager() {
00011 }
00012 /* use static_cast and type instead of dynamic... */
00013 void OPimNotifyManager::add( const OPimNotify& noti) {
00014     if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
00015         const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
00016         m_rem.append( rem );
00017     }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
00018         const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
00019         m_al.append( al );
00020     }
00021 }
00022 void OPimNotifyManager::remove( const OPimNotify& noti) {
00023     if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
00024         const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
00025         m_rem.remove( rem );
00026     }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
00027         const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
00028         m_al.remove( al );
00029     }
00030 }
00031 void OPimNotifyManager::replace( const OPimNotify& noti) {
00032     if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
00033         const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
00034         m_rem.remove( rem );
00035         m_rem.append( rem );
00036     }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
00037         const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
00038         m_al.remove( al );
00039         m_al.append( al );
00040     }
00041 }
00042 OPimNotifyManager::Reminders OPimNotifyManager::reminders()const {
00043     return m_rem;
00044 }
00045 OPimNotifyManager::Alarms    OPimNotifyManager::alarms()const {
00046     return m_al;
00047 }
00048 OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const {
00049     Alarms::ConstIterator it;
00050     found = true;
00051 
00052     for ( it = m_al.begin(); it != m_al.end(); ++it ){
00053         if ( (*it).dateTime() == when )
00054             return (*it);
00055     }
00056 
00057     // Fall through if nothing could be found
00058     found = false;
00059     OPimAlarm empty;
00060     return empty;
00061 }
00062 
00063 
00064 void OPimNotifyManager::setAlarms( const Alarms& al) {
00065     m_al = al;
00066 }
00067 void OPimNotifyManager::setReminders( const Reminders& rem) {
00068     m_rem = rem;
00069 }
00070 /* FIXME!!! */
00078 void OPimNotifyManager::registerNotify( const OPimNotify& ) {
00079 
00080 }
00081 /* FIXME!!! */
00087 void OPimNotifyManager::deregister( const OPimNotify& ) {
00088 
00089 }
00090 
00091 bool OPimNotifyManager::isEmpty()const {
00092     qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() );
00093     if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
00094     else return false;
00095 }
00096 
00097 // Taken from otodoaccessxml..
00098 QString OPimNotifyManager::alarmsToString() const
00099 {
00100     QString str;
00101 
00102     OPimNotifyManager::Alarms alarms = m_al;
00103     if ( !alarms.isEmpty() ) {
00104         QStringList als;
00105         OPimNotifyManager::Alarms::Iterator it = alarms.begin();
00106         for ( ; it != alarms.end(); ++it ) {
00107             /* only if time is valid */
00108             if ( (*it).dateTime().isValid() ) {
00109                 als << OConversion::dateTimeToString( (*it).dateTime() )
00110                     + ":" + QString::number( (*it).duration() )
00111                     + ":" + QString::number( (*it).sound() )
00112                     + ":";
00113             }
00114         }
00115         // now write the list
00116         qWarning("als: %s", als.join("____________").latin1() );
00117         str = als.join(";");
00118     }
00119 
00120     return str;
00121 }
00122 QString OPimNotifyManager::remindersToString() const
00123 {
00124     QString str;
00125 
00126     OPimNotifyManager::Reminders reminders = m_rem;
00127     if (!reminders.isEmpty() ) {
00128         OPimNotifyManager::Reminders::Iterator it = reminders.begin();
00129         QStringList records;
00130         for ( ; it != reminders.end(); ++it ) {
00131             records << QString::number( (*it).recordUid() );
00132         }
00133         str = records.join(";");
00134     }
00135 
00136     return str;
00137 }
00138 
00139 void OPimNotifyManager::alarmsFromString( const QString& str )
00140 {
00141         QStringList als = QStringList::split(";", str );
00142         for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
00143         QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
00144         qWarning("alarm: %s", alarm.join("___").latin1() );
00145         qWarning("alarm[0]: %s %s", alarm[0].latin1(), 
00146              OConversion::dateTimeFromString( alarm[0] ).toString().latin1() );
00147         OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), 
00148                   alarm[1].toInt() );
00149         add( al );
00150         }
00151 }
00152 
00153 void OPimNotifyManager::remindersFromString( const QString& str )
00154 {
00155 
00156         QStringList rems = QStringList::split(";", str );
00157         for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) {
00158         OPimReminder rem( (*it).toInt() );
00159         add( rem );
00160         }
00161     
00162 }
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:21 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001