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 "opimnotifymanager.h" 00031 00032 /* OPIE */ 00033 #include <opie2/opimdateconversion.h> 00034 #include <opie2/odebug.h> 00035 00036 /* QT */ 00037 #include <qstringlist.h> 00038 00039 namespace Opie 00040 { 00041 00042 OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al ) 00043 : m_rem( rem ), m_al( al ) 00044 {} 00045 00046 00047 OPimNotifyManager::~OPimNotifyManager() 00048 {} 00049 00050 00051 /* use static_cast and type instead of dynamic... */ 00052 void OPimNotifyManager::add( const OPimNotify& noti ) 00053 { 00054 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 00055 { 00056 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 00057 m_rem.append( rem ); 00058 } 00059 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 00060 { 00061 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 00062 m_al.append( al ); 00063 } 00064 } 00065 00066 00067 void OPimNotifyManager::remove( const OPimNotify& noti ) 00068 { 00069 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 00070 { 00071 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 00072 m_rem.remove( rem ); 00073 } 00074 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 00075 { 00076 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 00077 m_al.remove( al ); 00078 } 00079 } 00080 00081 00082 void OPimNotifyManager::replace( const OPimNotify& noti ) 00083 { 00084 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 00085 { 00086 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 00087 m_rem.remove( rem ); 00088 m_rem.append( rem ); 00089 } 00090 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 00091 { 00092 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 00093 m_al.remove( al ); 00094 m_al.append( al ); 00095 } 00096 } 00097 00098 00099 OPimNotifyManager::Reminders OPimNotifyManager::reminders() const 00100 { 00101 return m_rem; 00102 } 00103 00104 00105 OPimNotifyManager::Alarms OPimNotifyManager::alarms() const 00106 { 00107 return m_al; 00108 } 00109 00110 00111 OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const 00112 { 00113 Alarms::ConstIterator it; 00114 found = true; 00115 00116 for ( it = m_al.begin(); it != m_al.end(); ++it ) 00117 { 00118 if ( ( *it ).dateTime() == when ) 00119 return ( *it ); 00120 } 00121 00122 // Fall through if nothing could be found 00123 found = false; 00124 OPimAlarm empty; 00125 return empty; 00126 } 00127 00128 00129 void OPimNotifyManager::setAlarms( const Alarms& al ) 00130 { 00131 m_al = al; 00132 } 00133 00134 00135 void OPimNotifyManager::setReminders( const Reminders& rem ) 00136 { 00137 m_rem = rem; 00138 } 00139 00140 00141 /* FIXME!!! */ 00149 void OPimNotifyManager::registerNotify( const OPimNotify& ) 00150 { 00151 } 00152 00153 00154 /* FIXME!!! */ 00160 void OPimNotifyManager::deregister( const OPimNotify& ) 00161 { 00162 } 00163 00164 00165 bool OPimNotifyManager::isEmpty() const 00166 { 00167 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 00168 else return false; 00169 } 00170 00171 00172 // Taken from otodoaccessxml.. code duplication bad. any alternative? 00173 QString OPimNotifyManager::alarmsToString() const 00174 { 00175 QString str; 00176 00177 OPimNotifyManager::Alarms alarms = m_al; 00178 if ( !alarms.isEmpty() ) 00179 { 00180 QStringList als; 00181 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 00182 for ( ; it != alarms.end(); ++it ) 00183 { 00184 /* only if time is valid */ 00185 if ( ( *it ).dateTime().isValid() ) 00186 { 00187 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() ) 00188 + ":" + QString::number( ( *it ).duration() ) 00189 + ":" + QString::number( ( *it ).sound() ) 00190 + ":"; 00191 } 00192 } 00193 // now write the list 00194 str = als.join( ";" ); 00195 } 00196 00197 return str; 00198 } 00199 00200 00201 QString OPimNotifyManager::remindersToString() const 00202 { 00203 QString str; 00204 00205 OPimNotifyManager::Reminders reminders = m_rem; 00206 if ( !reminders.isEmpty() ) 00207 { 00208 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 00209 QStringList records; 00210 for ( ; it != reminders.end(); ++it ) 00211 { 00212 records << QString::number( ( *it ).recordUid() ); 00213 } 00214 str = records.join( ";" ); 00215 } 00216 00217 return str; 00218 } 00219 00220 00221 void OPimNotifyManager::alarmsFromString( const QString& str ) 00222 { 00223 QStringList als = QStringList::split( ";", str ); 00224 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) 00225 { 00226 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 00227 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), 00228 alarm[ 1 ].toInt() ); 00229 add( al ); 00230 } 00231 } 00232 00233 00234 void OPimNotifyManager::remindersFromString( const QString& str ) 00235 { 00236 00237 QStringList rems = QStringList::split( ";", str ); 00238 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) 00239 { 00240 OPimReminder rem( ( *it ).toInt() ); 00241 add( rem ); 00242 } 00243 00244 } 00245 }
1.4.2