Diffstat (limited to 'libopie2/opiepim/core/opimnotifymanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.cpp | 240 |
1 files changed, 148 insertions, 92 deletions
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index 1771fad..a54d597 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp | |||
@@ -26,77 +26,117 @@ | |||
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <opie2/opimnotifymanager.h> | ||
30 | 29 | ||
30 | #include "opimnotifymanager.h" | ||
31 | |||
32 | /* OPIE */ | ||
31 | #include <opie2/oconversion.h> | 33 | #include <opie2/oconversion.h> |
32 | 34 | ||
35 | /* QT */ | ||
33 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
34 | 37 | ||
35 | namespace Opie { | 38 | namespace Opie |
39 | { | ||
36 | 40 | ||
37 | OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) | 41 | OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al ) |
38 | : m_rem( rem ), m_al( al ) | 42 | : m_rem( rem ), m_al( al ) |
39 | {} | 43 | {} |
40 | OPimNotifyManager::~OPimNotifyManager() { | 44 | |
41 | } | 45 | |
46 | OPimNotifyManager::~OPimNotifyManager() | ||
47 | {} | ||
48 | |||
49 | |||
42 | /* use static_cast and type instead of dynamic... */ | 50 | /* use static_cast and type instead of dynamic... */ |
43 | void OPimNotifyManager::add( const OPimNotify& noti) { | 51 | void OPimNotifyManager::add( const OPimNotify& noti ) |
44 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 52 | { |
45 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 53 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) |
54 | { | ||
55 | const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); | ||
46 | m_rem.append( rem ); | 56 | m_rem.append( rem ); |
47 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 57 | } |
48 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 58 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) |
59 | { | ||
60 | const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); | ||
49 | m_al.append( al ); | 61 | m_al.append( al ); |
50 | } | 62 | } |
51 | } | 63 | } |
52 | void OPimNotifyManager::remove( const OPimNotify& noti) { | 64 | |
53 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 65 | |
54 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 66 | void OPimNotifyManager::remove( const OPimNotify& noti ) |
67 | { | ||
68 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) | ||
69 | { | ||
70 | const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); | ||
55 | m_rem.remove( rem ); | 71 | m_rem.remove( rem ); |
56 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 72 | } |
57 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 73 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) |
74 | { | ||
75 | const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); | ||
58 | m_al.remove( al ); | 76 | m_al.remove( al ); |
59 | } | 77 | } |
60 | } | 78 | } |
61 | void OPimNotifyManager::replace( const OPimNotify& noti) { | 79 | |
62 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 80 | |
63 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 81 | void OPimNotifyManager::replace( const OPimNotify& noti ) |
82 | { | ||
83 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) | ||
84 | { | ||
85 | const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); | ||
64 | m_rem.remove( rem ); | 86 | m_rem.remove( rem ); |
65 | m_rem.append( rem ); | 87 | m_rem.append( rem ); |
66 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 88 | } |
67 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 89 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) |
90 | { | ||
91 | const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); | ||
68 | m_al.remove( al ); | 92 | m_al.remove( al ); |
69 | m_al.append( al ); | 93 | m_al.append( al ); |
70 | } | 94 | } |
71 | } | 95 | } |
72 | OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { | 96 | |
97 | |||
98 | OPimNotifyManager::Reminders OPimNotifyManager::reminders() const | ||
99 | { | ||
73 | return m_rem; | 100 | return m_rem; |
74 | } | 101 | } |
75 | OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { | 102 | |
103 | |||
104 | OPimNotifyManager::Alarms OPimNotifyManager::alarms() const | ||
105 | { | ||
76 | return m_al; | 106 | return m_al; |
77 | } | 107 | } |
78 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { | ||
79 | Alarms::ConstIterator it; | ||
80 | found = true; | ||
81 | 108 | ||
82 | for ( it = m_al.begin(); it != m_al.end(); ++it ){ | ||
83 | if ( (*it).dateTime() == when ) | ||
84 | return (*it); | ||
85 | } | ||
86 | 109 | ||
87 | // Fall through if nothing could be found | 110 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const |
88 | found = false; | 111 | { |
89 | OPimAlarm empty; | 112 | Alarms::ConstIterator it; |
90 | return empty; | 113 | found = true; |
114 | |||
115 | for ( it = m_al.begin(); it != m_al.end(); ++it ) | ||
116 | { | ||
117 | if ( ( *it ).dateTime() == when ) | ||
118 | return ( *it ); | ||
119 | } | ||
120 | |||
121 | // Fall through if nothing could be found | ||
122 | found = false; | ||
123 | OPimAlarm empty; | ||
124 | return empty; | ||
91 | } | 125 | } |
92 | 126 | ||
93 | 127 | ||
94 | void OPimNotifyManager::setAlarms( const Alarms& al) { | 128 | void OPimNotifyManager::setAlarms( const Alarms& al ) |
129 | { | ||
95 | m_al = al; | 130 | m_al = al; |
96 | } | 131 | } |
97 | void OPimNotifyManager::setReminders( const Reminders& rem) { | 132 | |
133 | |||
134 | void OPimNotifyManager::setReminders( const Reminders& rem ) | ||
135 | { | ||
98 | m_rem = rem; | 136 | m_rem = rem; |
99 | } | 137 | } |
138 | |||
139 | |||
100 | /* FIXME!!! */ | 140 | /* FIXME!!! */ |
101 | /** | 141 | /** |
102 | * The idea is to check if the provider for our service | 142 | * The idea is to check if the provider for our service |
@@ -105,89 +145,105 @@ void OPimNotifyManager::setReminders( const Reminders& rem) { | |||
105 | * if not the Factory to get the backend... | 145 | * if not the Factory to get the backend... |
106 | * Qtopia1.6 services would be kewl to have here.... | 146 | * Qtopia1.6 services would be kewl to have here.... |
107 | */ | 147 | */ |
108 | void OPimNotifyManager::registerNotify( const OPimNotify& ) { | 148 | void OPimNotifyManager::registerNotify( const OPimNotify& ) |
109 | 149 | { | |
110 | } | 150 | } |
151 | |||
152 | |||
111 | /* FIXME!!! */ | 153 | /* FIXME!!! */ |
112 | /** | 154 | /** |
113 | * same as above... | 155 | * same as above... |
114 | * Also implement Url model | 156 | * Also implement Url model |
115 | * have a MainWindow.... | 157 | * have a MainWindow.... |
116 | */ | 158 | */ |
117 | void OPimNotifyManager::deregister( const OPimNotify& ) { | 159 | void OPimNotifyManager::deregister( const OPimNotify& ) |
118 | 160 | { | |
119 | } | 161 | } |
120 | 162 | ||
121 | bool OPimNotifyManager::isEmpty()const { | 163 | |
122 | qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); | 164 | bool OPimNotifyManager::isEmpty() const |
165 | { | ||
166 | qWarning( "is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); | ||
123 | if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; | 167 | if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; |
124 | else return false; | 168 | else return false; |
125 | } | 169 | } |
126 | 170 | ||
127 | // Taken from otodoaccessxml.. | 171 | |
172 | // Taken from otodoaccessxml.. code duplication bad. any alternative? | ||
128 | QString OPimNotifyManager::alarmsToString() const | 173 | QString OPimNotifyManager::alarmsToString() const |
129 | { | 174 | { |
130 | QString str; | 175 | QString str; |
131 | 176 | ||
132 | OPimNotifyManager::Alarms alarms = m_al; | 177 | OPimNotifyManager::Alarms alarms = m_al; |
133 | if ( !alarms.isEmpty() ) { | 178 | if ( !alarms.isEmpty() ) |
134 | QStringList als; | 179 | { |
135 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 180 | QStringList als; |
136 | for ( ; it != alarms.end(); ++it ) { | 181 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
137 | /* only if time is valid */ | 182 | for ( ; it != alarms.end(); ++it ) |
138 | if ( (*it).dateTime().isValid() ) { | 183 | { |
139 | als << OConversion::dateTimeToString( (*it).dateTime() ) | 184 | /* only if time is valid */ |
140 | + ":" + QString::number( (*it).duration() ) | 185 | if ( ( *it ).dateTime().isValid() ) |
141 | + ":" + QString::number( (*it).sound() ) | 186 | { |
142 | + ":"; | 187 | als << OConversion::dateTimeToString( ( *it ).dateTime() ) |
143 | } | 188 | + ":" + QString::number( ( *it ).duration() ) |
144 | } | 189 | + ":" + QString::number( ( *it ).sound() ) |
145 | // now write the list | 190 | + ":"; |
146 | qWarning("als: %s", als.join("____________").latin1() ); | 191 | } |
147 | str = als.join(";"); | 192 | } |
148 | } | 193 | // now write the list |
149 | 194 | qWarning( "als: %s", als.join( "____________" ).latin1() ); | |
150 | return str; | 195 | str = als.join( ";" ); |
196 | } | ||
197 | |||
198 | return str; | ||
151 | } | 199 | } |
200 | |||
201 | |||
152 | QString OPimNotifyManager::remindersToString() const | 202 | QString OPimNotifyManager::remindersToString() const |
153 | { | 203 | { |
154 | QString str; | 204 | QString str; |
155 | 205 | ||
156 | OPimNotifyManager::Reminders reminders = m_rem; | 206 | OPimNotifyManager::Reminders reminders = m_rem; |
157 | if (!reminders.isEmpty() ) { | 207 | if ( !reminders.isEmpty() ) |
158 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 208 | { |
159 | QStringList records; | 209 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
160 | for ( ; it != reminders.end(); ++it ) { | 210 | QStringList records; |
161 | records << QString::number( (*it).recordUid() ); | 211 | for ( ; it != reminders.end(); ++it ) |
162 | } | 212 | { |
163 | str = records.join(";"); | 213 | records << QString::number( ( *it ).recordUid() ); |
164 | } | 214 | } |
215 | str = records.join( ";" ); | ||
216 | } | ||
165 | 217 | ||
166 | return str; | 218 | return str; |
167 | } | 219 | } |
168 | 220 | ||
221 | |||
169 | void OPimNotifyManager::alarmsFromString( const QString& str ) | 222 | void OPimNotifyManager::alarmsFromString( const QString& str ) |
170 | { | 223 | { |
171 | QStringList als = QStringList::split(";", str ); | 224 | QStringList als = QStringList::split( ";", str ); |
172 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | 225 | for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) |
173 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 226 | { |
174 | qWarning("alarm: %s", alarm.join("___").latin1() ); | 227 | QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty |
175 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), | 228 | qWarning( "alarm: %s", alarm.join( "___" ).latin1() ); |
176 | OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); | 229 | qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(), |
177 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), | 230 | OConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() ); |
178 | alarm[1].toInt() ); | 231 | OPimAlarm al( alarm[ 2 ].toInt(), OConversion::dateTimeFromString( alarm[ 0 ] ), |
179 | add( al ); | 232 | alarm[ 1 ].toInt() ); |
180 | } | 233 | add( al ); |
234 | } | ||
181 | } | 235 | } |
182 | 236 | ||
237 | |||
183 | void OPimNotifyManager::remindersFromString( const QString& str ) | 238 | void OPimNotifyManager::remindersFromString( const QString& str ) |
184 | { | 239 | { |
185 | 240 | ||
186 | QStringList rems = QStringList::split(";", str ); | 241 | QStringList rems = QStringList::split( ";", str ); |
187 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | 242 | for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) |
188 | OPimReminder rem( (*it).toInt() ); | 243 | { |
189 | add( rem ); | 244 | OPimReminder rem( ( *it ).toInt() ); |
190 | } | 245 | add( rem ); |
191 | 246 | } | |
247 | |||
192 | } | 248 | } |
193 | } | 249 | } |