summaryrefslogtreecommitdiff
path: root/libopie/pim/opimnotifymanager.cpp
blob: d6f0ead6378bac08214d40242ba01b9844d3c06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "opimnotifymanager.h"

#include "oconversion.h"

#include <qstringlist.h>

OPimNotifyManager::OPimNotifyManager( const Reminders& rem,  const Alarms& al)
    : m_rem( rem ), m_al( al )
{}
OPimNotifyManager::~OPimNotifyManager() {
}
/* use static_cast and type instead of dynamic... */
void OPimNotifyManager::add( const OPimNotify& noti) {
    if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
        const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
        m_rem.append( rem );
    }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
        const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
        m_al.append( al );
    }
}
void OPimNotifyManager::remove( const OPimNotify& noti) {
    if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
        const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
        m_rem.remove( rem );
    }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
        const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
        m_al.remove( al );
    }
}
void OPimNotifyManager::replace( const OPimNotify& noti) {
    if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
        const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
        m_rem.remove( rem );
        m_rem.append( rem );
    }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
        const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
        m_al.remove( al );
        m_al.append( al );
    }
}
OPimNotifyManager::Reminders OPimNotifyManager::reminders()const {
    return m_rem;
}
OPimNotifyManager::Alarms    OPimNotifyManager::alarms()const {
    return m_al;
}
OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const {
	Alarms::ConstIterator it;
	found = true;

	for ( it = m_al.begin(); it != m_al.end(); ++it ){
		if ( (*it).dateTime() == when )
			return (*it);
	}

	// Fall through if nothing could be found
	found = false;
	OPimAlarm empty;
	return empty;
}


void OPimNotifyManager::setAlarms( const Alarms& al) {
    m_al = al;
}
void OPimNotifyManager::setReminders( const Reminders& rem) {
    m_rem = rem;
}
/* FIXME!!! */
/**
 * The idea is to check if the provider for our service
 * is online
 * if it is we will use QCOP
 * if not the Factory to get the backend...
 * Qtopia1.6 services would be kewl to have here....
 */
void OPimNotifyManager::registerNotify( const OPimNotify& ) {

}
/* FIXME!!! */
/**
 * same as above...
 * Also implement Url model
 * have a MainWindow....
 */
void OPimNotifyManager::deregister( const OPimNotify& ) {

}

bool OPimNotifyManager::isEmpty()const {
    qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() );
    if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
    else return false;
}

// Taken from otodoaccessxml..
QString OPimNotifyManager::alarmsToString() const
{
	QString str;

	OPimNotifyManager::Alarms alarms = m_al;
	if ( !alarms.isEmpty() ) {
		QStringList als;
		OPimNotifyManager::Alarms::Iterator it = alarms.begin();
		for ( ; it != alarms.end(); ++it ) {
			/* only if time is valid */
			if ( (*it).dateTime().isValid() ) {
				als << OConversion::dateTimeToString( (*it).dateTime() )
					+ ":" + QString::number( (*it).duration() )
					+ ":" + QString::number( (*it).sound() )
					+ ":";
			}
		}
		// now write the list
		qWarning("als: %s", als.join("____________").latin1() );
		str = als.join(";");
	}

	return str;
}
QString OPimNotifyManager::remindersToString() const
{
	QString str;

	OPimNotifyManager::Reminders reminders = m_rem;
	if (!reminders.isEmpty() ) {
		OPimNotifyManager::Reminders::Iterator it = reminders.begin();
		QStringList records;
		for ( ; it != reminders.end(); ++it ) {
			records << QString::number( (*it).recordUid() );
		}
		str = records.join(";");
	}

	return str;
}

void OPimNotifyManager::alarmsFromString( const QString& str )
{
        QStringList als = QStringList::split(";", str );
        for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
		QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
		qWarning("alarm: %s", alarm.join("___").latin1() );
		qWarning("alarm[0]: %s %s", alarm[0].latin1(), 
			 OConversion::dateTimeFromString( alarm[0] ).toString().latin1() );
		OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), 
			      alarm[1].toInt() );
		add( al );
        }
}

void OPimNotifyManager::remindersFromString( const QString& str )
{

        QStringList rems = QStringList::split(";", str );
        for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) {
		OPimReminder rem( (*it).toInt() );
		add( rem );
        }
	
}