Diffstat (limited to 'noncore/unsupported/libopie/pim/opimnotifymanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/libopie/pim/opimnotifymanager.cpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/opimnotifymanager.cpp b/noncore/unsupported/libopie/pim/opimnotifymanager.cpp new file mode 100644 index 0000000..d6f0ead --- a/dev/null +++ b/noncore/unsupported/libopie/pim/opimnotifymanager.cpp | |||
@@ -0,0 +1,162 @@ | |||
1 | #include "opimnotifymanager.h" | ||
2 | |||
3 | #include "oconversion.h" | ||
4 | |||
5 | #include <qstringlist.h> | ||
6 | |||
7 | OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) | ||
8 | : m_rem( rem ), m_al( al ) | ||
9 | {} | ||
10 | OPimNotifyManager::~OPimNotifyManager() { | ||
11 | } | ||
12 | /* use static_cast and type instead of dynamic... */ | ||
13 | void OPimNotifyManager::add( const OPimNotify& noti) { | ||
14 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | ||
15 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | ||
16 | m_rem.append( rem ); | ||
17 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | ||
18 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | ||
19 | m_al.append( al ); | ||
20 | } | ||
21 | } | ||
22 | void OPimNotifyManager::remove( const OPimNotify& noti) { | ||
23 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | ||
24 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | ||
25 | m_rem.remove( rem ); | ||
26 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | ||
27 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | ||
28 | m_al.remove( al ); | ||
29 | } | ||
30 | } | ||
31 | void OPimNotifyManager::replace( const OPimNotify& noti) { | ||
32 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | ||
33 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | ||
34 | m_rem.remove( rem ); | ||
35 | m_rem.append( rem ); | ||
36 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | ||
37 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | ||
38 | m_al.remove( al ); | ||
39 | m_al.append( al ); | ||
40 | } | ||
41 | } | ||
42 | OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { | ||
43 | return m_rem; | ||
44 | } | ||
45 | OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { | ||
46 | return m_al; | ||
47 | } | ||
48 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { | ||
49 | Alarms::ConstIterator it; | ||
50 | found = true; | ||
51 | |||
52 | for ( it = m_al.begin(); it != m_al.end(); ++it ){ | ||
53 | if ( (*it).dateTime() == when ) | ||
54 | return (*it); | ||
55 | } | ||
56 | |||
57 | // Fall through if nothing could be found | ||
58 | found = false; | ||
59 | OPimAlarm empty; | ||
60 | return empty; | ||
61 | } | ||
62 | |||
63 | |||
64 | void OPimNotifyManager::setAlarms( const Alarms& al) { | ||
65 | m_al = al; | ||
66 | } | ||
67 | void OPimNotifyManager::setReminders( const Reminders& rem) { | ||
68 | m_rem = rem; | ||
69 | } | ||
70 | /* FIXME!!! */ | ||
71 | /** | ||
72 | * The idea is to check if the provider for our service | ||
73 | * is online | ||
74 | * if it is we will use QCOP | ||
75 | * if not the Factory to get the backend... | ||
76 | * Qtopia1.6 services would be kewl to have here.... | ||
77 | */ | ||
78 | void OPimNotifyManager::registerNotify( const OPimNotify& ) { | ||
79 | |||
80 | } | ||
81 | /* FIXME!!! */ | ||
82 | /** | ||
83 | * same as above... | ||
84 | * Also implement Url model | ||
85 | * have a MainWindow.... | ||
86 | */ | ||
87 | void OPimNotifyManager::deregister( const OPimNotify& ) { | ||
88 | |||
89 | } | ||
90 | |||
91 | bool OPimNotifyManager::isEmpty()const { | ||
92 | qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); | ||
93 | if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; | ||
94 | else return false; | ||
95 | } | ||
96 | |||
97 | // Taken from otodoaccessxml.. | ||
98 | QString OPimNotifyManager::alarmsToString() const | ||
99 | { | ||
100 | QString str; | ||
101 | |||
102 | OPimNotifyManager::Alarms alarms = m_al; | ||
103 | if ( !alarms.isEmpty() ) { | ||
104 | QStringList als; | ||
105 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | ||
106 | for ( ; it != alarms.end(); ++it ) { | ||
107 | /* only if time is valid */ | ||
108 | if ( (*it).dateTime().isValid() ) { | ||
109 | als << OConversion::dateTimeToString( (*it).dateTime() ) | ||
110 | + ":" + QString::number( (*it).duration() ) | ||
111 | + ":" + QString::number( (*it).sound() ) | ||
112 | + ":"; | ||
113 | } | ||
114 | } | ||
115 | // now write the list | ||
116 | qWarning("als: %s", als.join("____________").latin1() ); | ||
117 | str = als.join(";"); | ||
118 | } | ||
119 | |||
120 | return str; | ||
121 | } | ||
122 | QString OPimNotifyManager::remindersToString() const | ||
123 | { | ||
124 | QString str; | ||
125 | |||
126 | OPimNotifyManager::Reminders reminders = m_rem; | ||
127 | if (!reminders.isEmpty() ) { | ||
128 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | ||
129 | QStringList records; | ||
130 | for ( ; it != reminders.end(); ++it ) { | ||
131 | records << QString::number( (*it).recordUid() ); | ||
132 | } | ||
133 | str = records.join(";"); | ||
134 | } | ||
135 | |||
136 | return str; | ||
137 | } | ||
138 | |||
139 | void OPimNotifyManager::alarmsFromString( const QString& str ) | ||
140 | { | ||
141 | QStringList als = QStringList::split(";", str ); | ||
142 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | ||
143 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | ||
144 | qWarning("alarm: %s", alarm.join("___").latin1() ); | ||
145 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), | ||
146 | OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); | ||
147 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), | ||
148 | alarm[1].toInt() ); | ||
149 | add( al ); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | void OPimNotifyManager::remindersFromString( const QString& str ) | ||
154 | { | ||
155 | |||
156 | QStringList rems = QStringList::split(";", str ); | ||
157 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | ||
158 | OPimReminder rem( (*it).toInt() ); | ||
159 | add( rem ); | ||
160 | } | ||
161 | |||
162 | } | ||