summaryrefslogtreecommitdiff
authoreilers <eilers>2004-01-16 13:37:03 (UTC)
committer eilers <eilers>2004-01-16 13:37:03 (UTC)
commit839775ea257f2c9be752a77c41a09416469df591 (patch) (side-by-side diff)
treed856530aad005f66adae3634bd384d3d02bb6c95
parentf7936b488e81f8706c4ea900979f2ea70734cfe9 (diff)
downloadopie-839775ea257f2c9be752a77c41a09416469df591.zip
opie-839775ea257f2c9be752a77c41a09416469df591.tar.gz
opie-839775ea257f2c9be752a77c41a09416469df591.tar.bz2
Some changes to handle alarms for datebook-sql db..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimnotifymanager.cpp16
-rw-r--r--libopie/pim/opimnotifymanager.h15
-rw-r--r--libopie/pim/orecur.h5
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp16
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.h15
-rw-r--r--libopie2/opiepim/core/orecur.h5
6 files changed, 72 insertions, 0 deletions
diff --git a/libopie/pim/opimnotifymanager.cpp b/libopie/pim/opimnotifymanager.cpp
index 53ad4c3..d6f0ead 100644
--- a/libopie/pim/opimnotifymanager.cpp
+++ b/libopie/pim/opimnotifymanager.cpp
@@ -1,146 +1,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 );
}
}
diff --git a/libopie/pim/opimnotifymanager.h b/libopie/pim/opimnotifymanager.h
index 48410e7..f3c22f9 100644
--- a/libopie/pim/opimnotifymanager.h
+++ b/libopie/pim/opimnotifymanager.h
@@ -1,76 +1,91 @@
#ifndef OPIE_PIM_NOTIFY_MANAGER_H
#define OPIE_PIM_NOTIFY_MANAGER_H
#include <qvaluelist.h>
#include <opie/opimnotify.h>
/**
* The notify manager keeps track of the Notifiers....
*/
class OPimNotifyManager {
public:
typedef QValueList<OPimReminder> Reminders;
typedef QValueList<OPimAlarm> Alarms;
OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() );
~OPimNotifyManager();
/* we will cast it for you ;) */
void add( const OPimNotify& );
void remove( const OPimNotify& );
/* replaces all with this one! */
void replace( const OPimNotify& );
Reminders reminders()const;
+
+ /**
+ * Return
+ */
Alarms alarms()const;
+ /**
+ * Return alarm at DateTime "when". If more than one is registered at this
+ * DateTime, the first one is returned.
+ * If none was found, an empty Alarm is returned.
+ * @param when The date and time of the returned alarm
+ * @param found Returns true if anything was found.
+ * @return Returns the found alarm at given DateTime. It is empty if found is false
+ * (nothing could be found at given date and time)
+ */
+ OPimAlarm alarmAtDateTime( const QDateTime& when, bool& found ) const;
+
void setAlarms( const Alarms& );
void setReminders( const Reminders& );
/* register is a Ansi C keyword... */
/**
* This function will register the Notify to the Alarm Server
* or datebook depending on the type of the notify
*/
void registerNotify( const OPimNotify& );
/**
* this will do the opposite..
*/
void deregister( const OPimNotify& );
bool isEmpty()const;
/**
* Return all alarms as string
*/
QString alarmsToString() const;
/**
* Return all notifiers as string
*/
QString remindersToString() const;
/**
* Convert string to alarms
* @param str String created by alarmsToString()
*/
void alarmsFromString( const QString& str );
/**
* Convert string to reminders
* @param str String created by remindersToString()
*/
void remindersFromString( const QString& str );
private:
Reminders m_rem;
Alarms m_al;
class Private;
Private *d;
};
#endif
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h
index 7750c12..d7ecd90 100644
--- a/libopie/pim/orecur.h
+++ b/libopie/pim/orecur.h
@@ -1,102 +1,107 @@
/*
* GPL from TT
*/
#ifndef OPIE_RECUR_H
#define OPIE_RECUR_H
#include <sys/types.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qmap.h>
+
+/**
+ * Class to handle Recurrencies..
+ */
+
class ORecur {
public:
typedef QValueList<QDate> ExceptionList;
enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
MonthlyDate, Yearly };
enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
FRI = 0x10, SAT = 0x20, SUN = 0x40 };
enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate,
EndDate, Created, Exceptions };
ORecur();
ORecur( const QMap<int, QString>& map );
ORecur( const ORecur& );
~ORecur();
ORecur &operator=( const ORecur& );
bool operator==(const ORecur& )const;
bool doesRecur()const;
/* if it recurrs on that day */
bool doesRecur( const QDate& );
RepeatType type()const;
int frequency()const;
int position()const;
char days()const;
bool hasEndDate()const;
QDate start()const;
QDate endDate()const;
QDateTime createdDateTime()const;
/**
* starting on monday=0, sunday=6
* for convience
*/
bool repeatOnWeekDay( int day )const;
/**
* FromWhereToStart is not included!!!
*/
bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate );
/**
* The module this ORecur belongs to
*/
QString service()const;
/*
* reference to the exception list
*/
ExceptionList &exceptions();
/**
* the current repetition
*/
int repetition()const;
void setType( const RepeatType& );
void setFrequency( int freq );
void setPosition( int pos );
void setDays( char c);
void setEndDate( const QDate& dt );
void setStart( const QDate& dt );
void setCreatedDateTime( const QDateTime& );
void setHasEndDate( bool b );
void setRepitition(int );
void setService( const QString& ser );
QMap<int, QString> toMap() const;
void fromMap( const QMap<int, QString>& map );
/* almost internal */
QString toString()const;
private:
bool p_nextOccurrence( const QDate& from, QDate& next );
void deref();
inline void checkOrModify();
/* Converts rType to String */
QString rTypeString() const;
/* Returns a map to convert Stringname for RType to RepeatType */
QMap<QString, RepeatType> rTypeValueConvertMap() const;
class Data;
Data* data;
class ORecurPrivate;
ORecurPrivate *d;
};
#endif
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 53ad4c3..d6f0ead 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -1,146 +1,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 );
}
}
diff --git a/libopie2/opiepim/core/opimnotifymanager.h b/libopie2/opiepim/core/opimnotifymanager.h
index 48410e7..f3c22f9 100644
--- a/libopie2/opiepim/core/opimnotifymanager.h
+++ b/libopie2/opiepim/core/opimnotifymanager.h
@@ -1,76 +1,91 @@
#ifndef OPIE_PIM_NOTIFY_MANAGER_H
#define OPIE_PIM_NOTIFY_MANAGER_H
#include <qvaluelist.h>
#include <opie/opimnotify.h>
/**
* The notify manager keeps track of the Notifiers....
*/
class OPimNotifyManager {
public:
typedef QValueList<OPimReminder> Reminders;
typedef QValueList<OPimAlarm> Alarms;
OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() );
~OPimNotifyManager();
/* we will cast it for you ;) */
void add( const OPimNotify& );
void remove( const OPimNotify& );
/* replaces all with this one! */
void replace( const OPimNotify& );
Reminders reminders()const;
+
+ /**
+ * Return
+ */
Alarms alarms()const;
+ /**
+ * Return alarm at DateTime "when". If more than one is registered at this
+ * DateTime, the first one is returned.
+ * If none was found, an empty Alarm is returned.
+ * @param when The date and time of the returned alarm
+ * @param found Returns true if anything was found.
+ * @return Returns the found alarm at given DateTime. It is empty if found is false
+ * (nothing could be found at given date and time)
+ */
+ OPimAlarm alarmAtDateTime( const QDateTime& when, bool& found ) const;
+
void setAlarms( const Alarms& );
void setReminders( const Reminders& );
/* register is a Ansi C keyword... */
/**
* This function will register the Notify to the Alarm Server
* or datebook depending on the type of the notify
*/
void registerNotify( const OPimNotify& );
/**
* this will do the opposite..
*/
void deregister( const OPimNotify& );
bool isEmpty()const;
/**
* Return all alarms as string
*/
QString alarmsToString() const;
/**
* Return all notifiers as string
*/
QString remindersToString() const;
/**
* Convert string to alarms
* @param str String created by alarmsToString()
*/
void alarmsFromString( const QString& str );
/**
* Convert string to reminders
* @param str String created by remindersToString()
*/
void remindersFromString( const QString& str );
private:
Reminders m_rem;
Alarms m_al;
class Private;
Private *d;
};
#endif
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h
index 7750c12..d7ecd90 100644
--- a/libopie2/opiepim/core/orecur.h
+++ b/libopie2/opiepim/core/orecur.h
@@ -1,102 +1,107 @@
/*
* GPL from TT
*/
#ifndef OPIE_RECUR_H
#define OPIE_RECUR_H
#include <sys/types.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qmap.h>
+
+/**
+ * Class to handle Recurrencies..
+ */
+
class ORecur {
public:
typedef QValueList<QDate> ExceptionList;
enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
MonthlyDate, Yearly };
enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
FRI = 0x10, SAT = 0x20, SUN = 0x40 };
enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate,
EndDate, Created, Exceptions };
ORecur();
ORecur( const QMap<int, QString>& map );
ORecur( const ORecur& );
~ORecur();
ORecur &operator=( const ORecur& );
bool operator==(const ORecur& )const;
bool doesRecur()const;
/* if it recurrs on that day */
bool doesRecur( const QDate& );
RepeatType type()const;
int frequency()const;
int position()const;
char days()const;
bool hasEndDate()const;
QDate start()const;
QDate endDate()const;
QDateTime createdDateTime()const;
/**
* starting on monday=0, sunday=6
* for convience
*/
bool repeatOnWeekDay( int day )const;
/**
* FromWhereToStart is not included!!!
*/
bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate );
/**
* The module this ORecur belongs to
*/
QString service()const;
/*
* reference to the exception list
*/
ExceptionList &exceptions();
/**
* the current repetition
*/
int repetition()const;
void setType( const RepeatType& );
void setFrequency( int freq );
void setPosition( int pos );
void setDays( char c);
void setEndDate( const QDate& dt );
void setStart( const QDate& dt );
void setCreatedDateTime( const QDateTime& );
void setHasEndDate( bool b );
void setRepitition(int );
void setService( const QString& ser );
QMap<int, QString> toMap() const;
void fromMap( const QMap<int, QString>& map );
/* almost internal */
QString toString()const;
private:
bool p_nextOccurrence( const QDate& from, QDate& next );
void deref();
inline void checkOrModify();
/* Converts rType to String */
QString rTypeString() const;
/* Returns a map to convert Stringname for RType to RepeatType */
QMap<QString, RepeatType> rTypeValueConvertMap() const;
class Data;
Data* data;
class ORecurPrivate;
ORecurPrivate *d;
};
#endif