Diffstat (limited to 'libopie2/opiepim/core/opimnotifymanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.cpp | 120 |
1 files changed, 88 insertions, 32 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 | |||
@@ -27,42 +27,66 @@ | |||
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 | { |
53 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) | ||
54 | { | ||
45 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 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 | } |
58 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) | ||
59 | { | ||
48 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 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 | |
66 | void OPimNotifyManager::remove( const OPimNotify& noti ) | ||
67 | { | ||
68 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) | ||
69 | { | ||
54 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 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 | } |
73 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) | ||
74 | { | ||
57 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 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 | |
81 | void OPimNotifyManager::replace( const OPimNotify& noti ) | ||
82 | { | ||
83 | if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) | ||
84 | { | ||
63 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 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 | } |
89 | else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) | ||
90 | { | ||
67 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 91 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); |
68 | m_al.remove( al ); | 92 | m_al.remove( al ); |
@@ -70,15 +94,25 @@ void OPimNotifyManager::replace( const OPimNotify& noti) { | |||
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 { | 108 | |
109 | |||
110 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const | ||
111 | { | ||
79 | Alarms::ConstIterator it; | 112 | Alarms::ConstIterator it; |
80 | found = true; | 113 | found = true; |
81 | 114 | ||
82 | for ( it = m_al.begin(); it != m_al.end(); ++it ){ | 115 | for ( it = m_al.begin(); it != m_al.end(); ++it ) |
116 | { | ||
83 | if ( (*it).dateTime() == when ) | 117 | if ( (*it).dateTime() == when ) |
84 | return (*it); | 118 | return (*it); |
@@ -92,10 +126,16 @@ OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found | |||
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 | /** |
@@ -106,7 +146,9 @@ void OPimNotifyManager::setReminders( const Reminders& rem) { | |||
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 | /** |
@@ -115,9 +157,11 @@ void OPimNotifyManager::registerNotify( const OPimNotify& ) { | |||
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 | |
164 | bool OPimNotifyManager::isEmpty() const | ||
165 | { | ||
122 | qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); | 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; |
@@ -125,5 +169,6 @@ bool OPimNotifyManager::isEmpty()const { | |||
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 | { |
@@ -131,10 +176,13 @@ QString OPimNotifyManager::alarmsToString() const | |||
131 | 176 | ||
132 | OPimNotifyManager::Alarms alarms = m_al; | 177 | OPimNotifyManager::Alarms alarms = m_al; |
133 | if ( !alarms.isEmpty() ) { | 178 | if ( !alarms.isEmpty() ) |
179 | { | ||
134 | QStringList als; | 180 | QStringList als; |
135 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 181 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
136 | for ( ; it != alarms.end(); ++it ) { | 182 | for ( ; it != alarms.end(); ++it ) |
183 | { | ||
137 | /* only if time is valid */ | 184 | /* only if time is valid */ |
138 | if ( (*it).dateTime().isValid() ) { | 185 | if ( ( *it ).dateTime().isValid() ) |
186 | { | ||
139 | als << OConversion::dateTimeToString( (*it).dateTime() ) | 187 | als << OConversion::dateTimeToString( (*it).dateTime() ) |
140 | + ":" + QString::number( (*it).duration() ) | 188 | + ":" + QString::number( (*it).duration() ) |
@@ -150,4 +198,6 @@ QString OPimNotifyManager::alarmsToString() const | |||
150 | return str; | 198 | return str; |
151 | } | 199 | } |
200 | |||
201 | |||
152 | QString OPimNotifyManager::remindersToString() const | 202 | QString OPimNotifyManager::remindersToString() const |
153 | { | 203 | { |
@@ -155,8 +205,10 @@ QString OPimNotifyManager::remindersToString() const | |||
155 | 205 | ||
156 | OPimNotifyManager::Reminders reminders = m_rem; | 206 | OPimNotifyManager::Reminders reminders = m_rem; |
157 | if (!reminders.isEmpty() ) { | 207 | if ( !reminders.isEmpty() ) |
208 | { | ||
158 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 209 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
159 | QStringList records; | 210 | QStringList records; |
160 | for ( ; it != reminders.end(); ++it ) { | 211 | for ( ; it != reminders.end(); ++it ) |
212 | { | ||
161 | records << QString::number( (*it).recordUid() ); | 213 | records << QString::number( (*it).recordUid() ); |
162 | } | 214 | } |
@@ -167,8 +219,10 @@ QString OPimNotifyManager::remindersToString() const | |||
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 ) |
226 | { | ||
173 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 227 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty |
174 | qWarning("alarm: %s", alarm.join("___").latin1() ); | 228 | qWarning("alarm: %s", alarm.join("___").latin1() ); |
@@ -181,9 +235,11 @@ void OPimNotifyManager::alarmsFromString( const QString& str ) | |||
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 ) |
243 | { | ||
188 | OPimReminder rem( (*it).toInt() ); | 244 | OPimReminder rem( (*it).toInt() ); |
189 | add( rem ); | 245 | add( rem ); |