author | mickeyl <mickeyl> | 2004-02-21 12:25:50 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-21 12:25:50 (UTC) |
commit | 6155f1be5c19fc51a4929c9e173f9e5a24d193e6 (patch) (side-by-side diff) | |
tree | c18ca863f82a559c60728f922519ac696387ec53 /libopie2/opiepim | |
parent | a570c2824fcecaf1c278e1b5a592fa14cc0647f8 (diff) | |
download | opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.zip opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.tar.gz opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.tar.bz2 |
the usual cosmetics
-rw-r--r-- | libopie2/opiepim/core/oconversion.cpp | 213 | ||||
-rw-r--r-- | libopie2/opiepim/core/oconversion.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcache.h | 10 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimmaintainer.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimmaintainer.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimresolver.cpp | 11 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimresolver.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimstate.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimstate.h | 11 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxref.cpp | 14 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxref.h | 22 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefmanager.cpp | 22 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefmanager.h | 9 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefpartner.cpp | 12 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefpartner.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 754 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 17 | ||||
-rw-r--r-- | libopie2/opiepim/core/otemplatebase.h | 9 | ||||
-rw-r--r-- | libopie2/opiepim/core/otimezone.cpp | 168 | ||||
-rw-r--r-- | libopie2/opiepim/core/otimezone.h | 13 |
20 files changed, 751 insertions, 576 deletions
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/oconversion.cpp index b7eebef..160c2c6 100644 --- a/libopie2/opiepim/core/oconversion.cpp +++ b/libopie2/opiepim/core/oconversion.cpp @@ -1,132 +1,143 @@ /*
- This file is part of the Opie Project
- Copyright (C) The Main Author <main-author@whereever.org>
- =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
- .=l.
- .>+-=
- _;:, .> :=|. This program is free software; you can
-.> <`_, > . <= redistribute it and/or modify it under
-:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
-.="- .-=="i, .._ License as published by the Free Software
- - . .-<_> .<> Foundation; either version 2 of the License,
- ._= =} : or (at your option) any later version.
- .%`+i> _;_.
- .i_,=:_. -<s. This program is distributed in the hope that
- + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
- : .. .:, . . . without even the implied warranty of
- =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
- _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
-..}^=.= = ; Library General Public License for more
-++= -. .` .: details.
- : = ...= . :.=-
- -. .:....=;==+<; You should have received a copy of the GNU
- -_. . . )=. = Library General Public License along with
- -- :-=` this library; see the file COPYING.LIB.
- If not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ This file is part of the Opie Project
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+_;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+- . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+: = ...= . :.=-
+-. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
*/
+/* OPIE */
#include <opie2/oconversion.h>
#include <qpe/timeconversion.h>
-
-namespace Opie {
+namespace Opie
+{
QString OConversion::dateToString( const QDate &d )
{
- if ( d.isNull() || !d.isValid() )
- return QString::null;
+ if ( d.isNull() || !d.isValid() )
+ return QString::null;
- // ISO format in year, month, day (YYYYMMDD); e.g. 20021231
- QString year = QString::number( d.year() );
- QString month = QString::number( d.month() );
- month = month.rightJustify( 2, '0' );
- QString day = QString::number( d.day() );
- day = day.rightJustify( 2, '0' );
+ // ISO format in year, month, day (YYYYMMDD); e.g. 20021231
+ QString year = QString::number( d.year() );
+ QString month = QString::number( d.month() );
+ month = month.rightJustify( 2, '0' );
+ QString day = QString::number( d.day() );
+ day = day.rightJustify( 2, '0' );
- QString str = year + month + day;
- //qDebug( "\tPimContact dateToStr = %s", str.latin1() );
+ QString str = year + month + day;
+ //qDebug( "\tPimContact dateToStr = %s", str.latin1() );
- return str;
+ return str;
}
+
QDate OConversion::dateFromString( const QString& s )
{
- QDate date;
-
- if ( s.isEmpty() )
- return date;
-
- // Be backward compatible to old Opie format:
- // Try to load old format. If it fails, try new ISO-Format!
- date = TimeConversion::fromString ( s );
- if ( date.isValid() )
- return date;
-
- // Read ISO-Format (YYYYMMDD)
- int year = s.mid(0, 4).toInt();
- int month = s.mid(4,2).toInt();
- int day = s.mid(6,2).toInt();
-
- // do some quick sanity checking -eilers
- // but we isValid() again? -zecke
- if ( year < 1900 || year > 3000 ) {
- qWarning( "PimContact year is not in range");
- return date;
- }
- if ( month < 0 || month > 12 ) {
- qWarning( "PimContact month is not in range");
- return date;
- }
- if ( day < 0 || day > 31 ) {
- qWarning( "PimContact day is not in range");
- return date;
- }
-
- date.setYMD( year, month, day );
- if ( !date.isValid() ) {
- qWarning( "PimContact date is not valid");
- return date;
- }
-
- return date;
+ QDate date;
+
+ if ( s.isEmpty() )
+ return date;
+
+ // Be backward compatible to old Opie format:
+ // Try to load old format. If it fails, try new ISO-Format!
+ date = TimeConversion::fromString ( s );
+ if ( date.isValid() )
+ return date;
+
+ // Read ISO-Format (YYYYMMDD)
+ int year = s.mid( 0, 4 ).toInt();
+ int month = s.mid( 4, 2 ).toInt();
+ int day = s.mid( 6, 2 ).toInt();
+
+ // do some quick sanity checking -eilers
+ // but we isValid() again? -zecke
+ if ( year < 1900 || year > 3000 )
+ {
+ qWarning( "PimContact year is not in range" );
+ return date;
+ }
+ if ( month < 0 || month > 12 )
+ {
+ qWarning( "PimContact month is not in range" );
+ return date;
+ }
+ if ( day < 0 || day > 31 )
+ {
+ qWarning( "PimContact day is not in range" );
+ return date;
+ }
+
+ date.setYMD( year, month, day );
+ if ( !date.isValid() )
+ {
+ qWarning( "PimContact date is not valid" );
+ return date;
+ }
+
+ return date;
}
-QString OConversion::dateTimeToString( const QDateTime& dt ) {
- if (!dt.isValid() || dt.isNull() ) return QString::null;
- QString year = QString::number( dt.date().year() );
- QString month = QString::number( dt.date().month() );
- QString day = QString::number( dt.date().day() );
- QString hour = QString::number( dt.time().hour() );
- QString min = QString::number( dt.time().minute() );
- QString sec = QString::number( dt.time().second() );
+QString OConversion::dateTimeToString( const QDateTime& dt )
+{
+ if ( !dt.isValid() || dt.isNull() )
+ return QString::null;
- month = month.rightJustify( 2, '0' );
- day = day. rightJustify( 2, '0' );
- hour = hour. rightJustify( 2, '0' );
- min = min. rightJustify( 2, '0' );
- sec = sec. rightJustify( 2, '0' );
+ QString year = QString::number( dt.date().year() );
+ QString month = QString::number( dt.date().month() );
+ QString day = QString::number( dt.date().day() );
- QString str = day + month + year + hour + min + sec;
+ QString hour = QString::number( dt.time().hour() );
+ QString min = QString::number( dt.time().minute() );
+ QString sec = QString::number( dt.time().second() );
- return str;
+ month = month.rightJustify( 2, '0' );
+ day = day. rightJustify( 2, '0' );
+ hour = hour. rightJustify( 2, '0' );
+ min = min. rightJustify( 2, '0' );
+ sec = sec. rightJustify( 2, '0' );
+
+ return day + month + year + hour + min + sec;
}
-QDateTime OConversion::dateTimeFromString( const QString& str) {
- if ( str.isEmpty() ) return QDateTime();
- int day = str.mid(0, 2).toInt();
- int month = str.mid(2, 2).toInt();
- int year = str.mid(4, 4).toInt();
- int hour = str.mid(8, 2).toInt();
- int min = str.mid(10, 2).toInt();
- int sec = str.mid(12, 2).toInt();
+
+QDateTime OConversion::dateTimeFromString( const QString& str )
+{
+
+ if ( str.isEmpty() )
+ return QDateTime();
+ int day = str.mid( 0, 2 ).toInt();
+ int month = str.mid( 2, 2 ).toInt();
+ int year = str.mid( 4, 4 ).toInt();
+ int hour = str.mid( 8, 2 ).toInt();
+ int min = str.mid( 10, 2 ).toInt();
+ int sec = str.mid( 12, 2 ).toInt();
QDate date( year, month, day );
QTime time( hour, min, sec );
QDateTime dt( date, time );
return dt;
}
-}
\ No newline at end of file +}
diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/oconversion.h index 3c4fdf3..eeb97e5 100644 --- a/libopie2/opiepim/core/oconversion.h +++ b/libopie2/opiepim/core/oconversion.h @@ -1,62 +1,61 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __oconversion_h__ -#define __oconversion_h__ +#ifndef OCONVERSION_H +#define OCONVERSION_H -/* #include <time.h> */ -/* #include <sys/types.h> */ +/* QT */ #include <qdatetime.h> namespace Opie { class OConversion { public: static QString dateToString( const QDate &d ); static QDate dateFromString( const QString &datestr ); /** * simple function to store DateTime as string and read from string * no timezone changing is done * DDMMYYYYHHMMSS is the simple format */ static QString dateTimeToString( const QDateTime& ); static QDateTime dateTimeFromString( const QString& ); private: class Private; Private* d; }; } #endif // __oconversion_h__ diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index e70a910..a033574 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h @@ -1,131 +1,133 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_CACHE_H -#define OPIE_PIM_CACHE_H - -#include <qintcache.h> +#ifndef OPIMCACHE_H +#define OPIMCACHE_H +/* OPIE */ #include <opie2/opimrecord.h> +/* QT */ +#include <qintcache.h> + namespace Opie { class OPimCacheItemPrivate; template <class T = OPimRecord> class OPimCacheItem { public: OPimCacheItem( const T& t = T() ); OPimCacheItem( const OPimCacheItem& ); ~OPimCacheItem(); OPimCacheItem &operator=( const OPimCacheItem& ); T record()const; void setRecord( const T& ); private: T m_t; OPimCacheItemPrivate *d; }; class OPimCachePrivate; /** * OPimCache for caching the items * We support adding, removing * and finding */ template <class T = OPimRecord> class OPimCache { public: typedef OPimCacheItem<T> Item; OPimCache(); OPimCache( const OPimCache& ); ~OPimCache(); OPimCache &operator=( const OPimCache& ); bool contains(int uid)const; void invalidate(); void setSize( int size ); T find(int uid )const; void add( const T& ); void remove( int uid ); void replace( const T& ); private: QIntCache<Item> m_cache; OPimCachePrivate* d; }; // Implementation template <class T> OPimCacheItem<T>::OPimCacheItem( const T& t ) : m_t(t) { } template <class T> OPimCacheItem<T>::~OPimCacheItem() { } template <class T> T OPimCacheItem<T>::record()const { return m_t; } template <class T> void OPimCacheItem<T>::setRecord( const T& t ) { m_t = t; } // Cache template <class T> OPimCache<T>::OPimCache() : m_cache(100, 53 ) { m_cache.setAutoDelete( TRUE ); } template <class T> OPimCache<T>::~OPimCache() { } template <class T> bool OPimCache<T>::contains(int uid )const { Item* it = m_cache.find( uid, FALSE ); if (!it) return false; return true; } template <class T> void OPimCache<T>::invalidate() { m_cache.clear(); } template <class T> void OPimCache<T>::setSize( int size ) { m_cache.setMaxCost( size ); } template <class T> T OPimCache<T>::find(int uid )const { Item *it = m_cache.find( uid ); diff --git a/libopie2/opiepim/core/opimmaintainer.cpp b/libopie2/opiepim/core/opimmaintainer.cpp index b2eff12..b8d829a 100644 --- a/libopie2/opiepim/core/opimmaintainer.cpp +++ b/libopie2/opiepim/core/opimmaintainer.cpp @@ -1,69 +1,69 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/opimmaintainer.h> +#include "opimmaintainer.h" namespace Opie { OPimMaintainer::OPimMaintainer( int mode, int uid ) : m_mode(mode), m_uid(uid ) {} OPimMaintainer::~OPimMaintainer() { } OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) { *this = main; } OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) { m_mode = main.m_mode; m_uid = main.m_uid; return *this; } bool OPimMaintainer::operator==( const OPimMaintainer& main ) { if (m_mode != main.m_mode ) return false; if (m_uid != main.m_uid ) return false; return true; } bool OPimMaintainer::operator!=( const OPimMaintainer& main ) { return !(*this == main ); } int OPimMaintainer::mode()const { return m_mode; } int OPimMaintainer::uid()const { return m_uid; } void OPimMaintainer::setMode( int mo) { m_mode = mo; } void OPimMaintainer::setUid( int uid ) { m_uid = uid; } } diff --git a/libopie2/opiepim/core/opimmaintainer.h b/libopie2/opiepim/core/opimmaintainer.h index 46bc9d2..e7e7eeb 100644 --- a/libopie2/opiepim/core/opimmaintainer.h +++ b/libopie2/opiepim/core/opimmaintainer.h @@ -1,71 +1,72 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_MAINTAINER_H -#define OPIE_PIM_MAINTAINER_H +#ifndef OPIMMAINTAINER_H +#define OPIMMAINTAINER_H +/* QT */ #include <qstring.h> namespace Opie { /** * Who maintains what? */ class OPimMaintainer { public: enum Mode { Undefined = -1, Nothing = 0, Responsible, DoneBy, Coordinating, }; OPimMaintainer( int mode = Undefined, int uid = 0); OPimMaintainer( const OPimMaintainer& ); ~OPimMaintainer(); OPimMaintainer &operator=( const OPimMaintainer& ); bool operator==( const OPimMaintainer& ); bool operator!=( const OPimMaintainer& ); int mode()const; int uid()const; void setMode( int mode ); void setUid( int uid ); private: int m_mode; int m_uid; class Private; Private *d; }; } #endif diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp index eceabcb..73d7de1 100644 --- a/libopie2/opiepim/core/opimresolver.cpp +++ b/libopie2/opiepim/core/opimresolver.cpp @@ -1,133 +1,134 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qcopchannel_qws.h> -#include <qpe/qcopenvelope_qws.h> +#include "opimresolver.h" -#include <opie2/otodoaccess.h> +/* OPIE */ #include <opie2/ocontactaccess.h> +#include <opie2/otodoaccess.h> +#include <qpe/qcopenvelope_qws.h> -//#include "opimfactory.h" -#include <opie2/opimresolver.h> +/* QT */ +#include <qcopchannel_qws.h> namespace Opie { OPimResolver* OPimResolver::m_self = 0l; OPimResolver::OPimResolver() { /* the built in channels */ m_builtIns << "Todolist" << "Addressbook" << "Datebook"; } OPimResolver* OPimResolver::self() { if (!m_self) m_self = new OPimResolver(); return m_self; } /* * FIXME use a cache here too */ OPimRecord* OPimResolver::record( const QString& service, int uid ) { OPimRecord* rec = 0l; OPimBase* base = backend( service ); if ( base ) rec = base->record( uid ); delete base; return rec; } OPimRecord* OPimResolver::record( const QString& service ) { return record( serviceId( service ) ); } OPimRecord* OPimResolver::record( int rtti ) { OPimRecord* rec = 0l; switch( rtti ) { case 1: /* todolist */ rec = new OTodo(); case 2: /* contact */ rec = new OContact(); default: break; } /* * FIXME resolve externally */ if (!rec ) { ; } return 0l; } bool OPimResolver::isBuiltIn( const QString& str) const{ return m_builtIns.contains( str ); } QCString OPimResolver::qcopChannel( enum BuiltIn& built)const { QCString str("QPE/"); switch( built ) { case TodoList: str += "Todolist"; break; case DateBook: str += "Datebook"; break; case AddressBook: str += "Addressbook"; break; default: break; } return str; } QCString OPimResolver::qcopChannel( const QString& service )const { QCString str("QPE/"); str += service.latin1(); return str; } /* * Implement services!! * FIXME */ QCString OPimResolver::applicationChannel( enum BuiltIn& built)const { QCString str("QPE/Application/"); switch( built ) { case TodoList: str += "todolist"; break; case DateBook: str += "datebook"; break; case AddressBook: str += "addressbook"; break; } return str; } diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h index adc7c16..dd6f07f 100644 --- a/libopie2/opiepim/core/opimresolver.h +++ b/libopie2/opiepim/core/opimresolver.h @@ -1,121 +1,125 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_RESOLVER -#define OPIE_PIM_RESOLVER +#ifndef OPIMRESOLVER_H +#define OPIMRESOLVER_H +/* OPIE */ +#include <opie2/otemplatebase.h> + +/* QT */ #include <qstring.h> #include <qvaluelist.h> -#include <opie2/otemplatebase.h> - namespace Opie { /** * OPimResolver is a MetaClass to access * available backends read only. * It will be used to resolve uids + app names * to full informations * to traverse through a list of alarms, reminders * to get access to built in PIM functionality * and to more stuff * THE PERFORMANCE will depend on THE BACKEND * USING XML is a waste of memory!!!!! */ class OPimResolver { -public: + + public: enum BuiltIn { TodoList = 0, DateBook, AddressBook }; static OPimResolver* self(); /** * return a record for a uid * and an service * You've THE OWNERSHIP NOW! */ OPimRecord *record( const QString& service, int uid ); /** * return the QCopChannel for service * When we will use Qtopia Services it will be used here */ QCString qcopChannel( enum BuiltIn& )const; QCString qcopChannel( const QString& service )const; /** * The Application channel (QPE/Application/name) */ QCString applicationChannel( enum BuiltIn& )const; QCString applicationChannel( const QString& service )const; /** * return a list of available services */ QStringList services()const; inline QString serviceName(int rrti )const; int serviceId( const QString& Service); /** * add a record to a service... ;) */ bool add( const QString& service, const OPimRecord& ); /** * record returns an empty record for a given service. * Be sure to delete it!!! * */ OPimRecord* record( const QString& service ); OPimRecord* record( int rtti ); /** * you can cast to your */ OPimBase* backend( const QString& service ); OPimBase* backend( int rtti ); -private: + + private: OPimResolver(); void loadData(); inline bool isBuiltIn( const QString& )const; OPimRecord* recordExtern( const QString&, int ); OPimRecord* recordExtern( const QString& ); static OPimResolver* m_self; struct Data; class Private; Data* data; Private* d; QStringList m_builtIns; }; } #endif diff --git a/libopie2/opiepim/core/opimstate.cpp b/libopie2/opiepim/core/opimstate.cpp index 1013a1c..8aff558 100644 --- a/libopie2/opiepim/core/opimstate.cpp +++ b/libopie2/opiepim/core/opimstate.cpp @@ -1,95 +1,96 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qshared.h> - #include "opimstate.h" +/* QT */ +#include <qshared.h> + namespace Opie { /* * for one int this does not make * much sense but never the less * we will do it for the future */ struct OPimState::Data : public QShared { Data() : QShared(),state(Undefined) { } int state; }; OPimState::OPimState( int state ) { data = new Data; data->state = state; } OPimState::OPimState( const OPimState& st) : data( st.data ) { /* ref up */ data->ref(); } OPimState::~OPimState() { if ( data->deref() ) { delete data ; data = 0; } } bool OPimState::operator==( const OPimState& st) { if ( data->state == st.data->state ) return true; return false; } OPimState &OPimState::operator=( const OPimState& st) { st.data->ref(); deref(); data = st.data; return *this; } void OPimState::setState( int st) { copyInternally(); data->state = st; } int OPimState::state()const { return data->state; } void OPimState::deref() { if ( data->deref() ) { delete data; data = 0l; } } void OPimState::copyInternally() { /* we need to change it */ if ( data->count != 1 ) { data->deref(); Data* d2 = new Data; d2->state = data->state; data = d2; } } } diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h index 78e8cd0..8336b3e 100644 --- a/libopie2/opiepim/core/opimstate.h +++ b/libopie2/opiepim/core/opimstate.h @@ -1,75 +1,78 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_STATE_H -#define OPIE_PIM_STATE_H +#ifndef OPIMSTATE_H +#define OPIMSTATE_H +/* QT */ #include <qstring.h> namespace Opie { /** * The State of a Task * This class encapsules the state of a todo * and it's shared too */ /* * in c a simple struct would be enough ;) * g_new_state(); * g_do_some_thing( state_t* ); * ;) */ class OPimState { -public: + + public: enum State { Started = 0, Postponed, Finished, NotStarted, Undefined }; OPimState( int state = Undefined ); OPimState( const OPimState& ); ~OPimState(); bool operator==( const OPimState& ); OPimState &operator=( const OPimState& ); void setState( int state); int state()const; -private: + + private: void deref(); inline void copyInternally(); struct Data; Data* data; class Private; Private *d; }; } #endif diff --git a/libopie2/opiepim/core/opimxref.cpp b/libopie2/opiepim/core/opimxref.cpp index 85d3345..f58ebb5 100644 --- a/libopie2/opiepim/core/opimxref.cpp +++ b/libopie2/opiepim/core/opimxref.cpp @@ -1,79 +1,85 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/opimxref.h> +#include "opimxref.h" namespace Opie { OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) : m_partners(2) { m_partners[0] = one; m_partners[1] = two; } -OPimXRef::OPimXRef() - : m_partners(2) +OPimXRef::OPimXRef():m_partners(2) { } + OPimXRef::OPimXRef( const OPimXRef& ref) { *this = ref; } + OPimXRef::~OPimXRef() { } + OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { m_partners = ref.m_partners; m_partners.detach(); - return* this; + return *this; } + bool OPimXRef::operator==( const OPimXRef& oper ) { if ( m_partners == oper.m_partners ) return true; return false; } OPimXRefPartner OPimXRef::partner( enum Partners par) const{ return m_partners[par]; } + void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { m_partners[par] = part; } + bool OPimXRef::containsString( const QString& string ) const{ if ( m_partners[One].service() == string || m_partners[Two].service() == string ) return true; return false; } + bool OPimXRef::containsUid( int uid ) const{ if ( m_partners[One].uid() == uid || m_partners[Two].uid() == uid ) return true; return false; } } diff --git a/libopie2/opiepim/core/opimxref.h b/libopie2/opiepim/core/opimxref.h index 820c9c4..f3e814e 100644 --- a/libopie2/opiepim/core/opimxref.h +++ b/libopie2/opiepim/core/opimxref.h @@ -1,71 +1,73 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIM_XREF_H -#define OPIM_XREF_H +#ifndef OPIMXREF_H +#define OPIMXREF_H +/* OPIE */ +#include <opie2/opimxrefpartner.h> + +/* QT */ #include <qarray.h> #include <qvaluelist.h> -#include <opie2/opimxrefpartner.h> - namespace Opie { /** * this is a Cross Referecne between * two Cross Reference Partners */ class OPimXRef { -public: + public: typedef QValueList<OPimXRef> ValueList; enum Partners { One, Two }; OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); OPimXRef(); OPimXRef( const OPimXRef& ); ~OPimXRef(); OPimXRef &operator=( const OPimXRef& ); bool operator==( const OPimXRef& ); - OPimXRefPartner partner( enum Partners )const; + OPimXRefPartner partner( enum Partners ) const; - void setPartner( enum Partners, const OPimXRefPartner& ); + void setPartner( enum Partners, const OPimXRefPartner& ); - bool containsString( const QString& service)const; - bool containsUid( int uid )const; + bool containsString( const QString& service) const; + bool containsUid( int uid ) const; -private: + private: QArray<OPimXRefPartner> m_partners; class Private; Private *d; }; } #endif diff --git a/libopie2/opiepim/core/opimxrefmanager.cpp b/libopie2/opiepim/core/opimxrefmanager.cpp index bf6fed6..e7c6c5a 100644 --- a/libopie2/opiepim/core/opimxrefmanager.cpp +++ b/libopie2/opiepim/core/opimxrefmanager.cpp @@ -1,102 +1,114 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/opimxrefmanager.h> +#include "opimxrefmanager.h" namespace Opie { OPimXRefManager::OPimXRefManager() { } + OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { m_list = ref.m_list; } + OPimXRefManager::~OPimXRefManager() { } + OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { m_list = ref.m_list; return *this; } + bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { // if ( m_list == ref.m_list ) return true; return false; } + void OPimXRefManager::add( const OPimXRef& ref) { m_list.append( ref ); } + void OPimXRefManager::remove( const OPimXRef& ref) { m_list.remove( ref ); } + void OPimXRefManager::replace( const OPimXRef& ref) { m_list.remove( ref ); m_list.append( ref ); } + void OPimXRefManager::clear() { m_list.clear(); } -QStringList OPimXRefManager::apps()const { + +QStringList OPimXRefManager::apps() const { OPimXRef::ValueList::ConstIterator it; QStringList list; QString str; for ( it = m_list.begin(); it != m_list.end(); ++it ) { str = (*it).partner( OPimXRef::One ).service(); if ( !list.contains( str ) ) list << str; str = (*it).partner( OPimXRef::Two ).service(); if ( !list.contains( str ) ) list << str; } return list; } -OPimXRef::ValueList OPimXRefManager::list()const { + +OPimXRef::ValueList OPimXRefManager::list() const { return m_list; } -OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ + +OPimXRef::ValueList OPimXRefManager::list( const QString& appName ) const{ OPimXRef::ValueList list; OPimXRef::ValueList::ConstIterator it; for ( it = m_list.begin(); it != m_list.end(); ++it ) { if ( (*it).containsString( appName ) ) list.append( (*it) ); } return list; } -OPimXRef::ValueList OPimXRefManager::list( int uid )const { + +OPimXRef::ValueList OPimXRefManager::list( int uid ) const { OPimXRef::ValueList list; OPimXRef::ValueList::ConstIterator it; for ( it = m_list.begin(); it != m_list.end(); ++it ) { if ( (*it).containsUid( uid ) ) list.append( (*it) ); } return list; } } diff --git a/libopie2/opiepim/core/opimxrefmanager.h b/libopie2/opiepim/core/opimxrefmanager.h index fa2d7f4..b80a645 100644 --- a/libopie2/opiepim/core/opimxrefmanager.h +++ b/libopie2/opiepim/core/opimxrefmanager.h @@ -1,74 +1,77 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIM_XREF_MANAGER_H -#define OPIM_XREF_MANAGER_H -#include <qstringlist.h> +#ifndef OPIMXREFMANAGER_H +#define OPIMXREFMANAGER_H +/* OPIE */ #include <opie2/opimxref.h> +/* QT */ +#include <qstringlist.h> + namespace Opie { /** * This is a simple manager for * OPimXRefs. * It allows addition, removing, replacing * clearing and 'querying' the XRef... */ class OPimXRefManager { public: OPimXRefManager(); OPimXRefManager( const OPimXRefManager& ); ~OPimXRefManager(); OPimXRefManager& operator=( const OPimXRefManager& ); bool operator==( const OPimXRefManager& ); void add( const OPimXRef& ); void remove( const OPimXRef& ); void replace( const OPimXRef& ); void clear(); /** * apps participating */ QStringList apps()const; OPimXRef::ValueList list()const; OPimXRef::ValueList list( const QString& service )const; OPimXRef::ValueList list( int uid )const; private: OPimXRef::ValueList m_list; class Private; Private *d; }; } #endif diff --git a/libopie2/opiepim/core/opimxrefpartner.cpp b/libopie2/opiepim/core/opimxrefpartner.cpp index f6ccc7f..3741bc3 100644 --- a/libopie2/opiepim/core/opimxrefpartner.cpp +++ b/libopie2/opiepim/core/opimxrefpartner.cpp @@ -1,75 +1,85 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/opimxrefpartner.h> +#include "opimxrefpartner.h" namespace Opie { OPimXRefPartner::OPimXRefPartner( const QString& appName, int uid, int field ) : m_app(appName), m_uid(uid), m_field( field ) { } + OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { *this = ref; } + OPimXRefPartner::~OPimXRefPartner() { } + OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { m_app = par.m_app; m_uid = par.m_uid; m_field = par.m_field; return *this; } + bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { if ( m_app != par.m_app ) return false; if ( m_uid != par.m_uid ) return false; if ( m_field != par.m_field ) return false; return true; } + QString OPimXRefPartner::service()const { return m_app; } + int OPimXRefPartner::uid()const { return m_uid; } + int OPimXRefPartner::field()const { return m_field; } + void OPimXRefPartner::setService( const QString& appName ) { m_app = appName; } + void OPimXRefPartner::setUid( int uid ) { m_uid = uid; } + void OPimXRefPartner::setField( int field ) { m_field = field; } } diff --git a/libopie2/opiepim/core/opimxrefpartner.h b/libopie2/opiepim/core/opimxrefpartner.h index 6853d5b..005dbc0 100644 --- a/libopie2/opiepim/core/opimxrefpartner.h +++ b/libopie2/opiepim/core/opimxrefpartner.h @@ -1,70 +1,73 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OPIM_XREF_PARTNER_H #define OPIM_XREF_PARTNER_H +/* QT */ #include <qstring.h> namespace Opie { /** * This class represents one partner * of a Cross Reference. * In Opie one application * can link one uid * with one tableId( fieldId ) to another. */ class OPimXRefPartner { -public: + + public: OPimXRefPartner( const QString& service = QString::null, int uid = 0, int field = -1 ); OPimXRefPartner( const OPimXRefPartner& ); OPimXRefPartner& operator=( const OPimXRefPartner& ); ~OPimXRefPartner(); bool operator==(const OPimXRefPartner& ); QString service()const; int uid()const; int field()const; void setService( const QString& service ); void setUid( int uid ); void setField( int field ); -private: + + private: QString m_app; int m_uid; int m_field; class Private; Private* d; }; } #endif diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index 033f264..5e2da25 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp @@ -1,625 +1,691 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <time.h> +#include "orecur.h" -#include <qshared.h> +/* OPIE */ +#include <opie2/otimezone.h> +#include <qpe/timeconversion.h> -#include <qtopia/timeconversion.h> +/* QT */ +#include <qshared.h> -#include <opie2/otimezone.h> -#include <opie2/orecur.h> +/* STD */ +#include <time.h> namespace Opie { + struct ORecur::Data : public QShared { Data() : QShared() { type = ORecur::NoRepeat; freq = -1; days = 0; pos = 0; create = QDateTime::currentDateTime(); hasEnd = FALSE; end = QDate::currentDate(); } char days; // Q_UINT8 for 8 seven days;) ORecur::RepeatType type; int freq; int pos; bool hasEnd : 1; QDate end; QDateTime create; int rep; QString app; ExceptionList list; QDate start; }; ORecur::ORecur() { data = new Data; } ORecur::ORecur( const QMap<int, QString>& map ) { - ORecur(); - fromMap( map ); + ORecur(); + fromMap( map ); } ORecur::ORecur( const ORecur& rec) : data( rec.data ) { data->ref(); } + + ORecur::~ORecur() { if ( data->deref() ) { delete data; data = 0l; } } + + void ORecur::deref() { if ( data->deref() ) { delete data; data = 0l; } } + + bool ORecur::operator==( const ORecur& )const { return false; } + + ORecur &ORecur::operator=( const ORecur& re) { if ( *this == re ) return *this; re.data->ref(); deref(); data = re.data; return *this; } + + bool ORecur::doesRecur()const { return !( type() == NoRepeat ); } + + /* * we try to be smart here * */ bool ORecur::doesRecur( const QDate& date ) { /* the day before the recurrance */ QDate da = date.addDays(-1); QDate recur; if (!nextOcurrence( da, recur ) ) return false; return (recur == date); } + + // FIXME unuglify! // GPL from Datebookdb.cpp // FIXME exception list! bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { bool stillLooking; stillLooking = p_nextOccurrence( from, next ); while ( stillLooking && data->list.contains(next) ) stillLooking = p_nextOccurrence( next.addDays(1), next ); return stillLooking; } + + bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { // easy checks, first are we too far in the future or too far in the past? QDate tmpDate; int freq = frequency(); int diff, diff2, a; int iday, imonth, iyear; int dayOfWeek = 0; int firstOfWeek = 0; int weekOfMonth; if (hasEndDate() && endDate() < from) - return FALSE; + return FALSE; if (start() >= from ) { - next = start(); - return TRUE; + next = start(); + return TRUE; } switch ( type() ) { - case Weekly: - /* weekly is just daily by 7 */ - /* first convert the repeatPattern.Days() mask to the next - day of week valid after from */ + case Weekly: + /* weekly is just daily by 7 */ + /* first convert the repeatPattern.Days() mask to the next + day of week valid after from */ dayOfWeek = from.dayOfWeek(); - dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ - - /* this is done in case freq > 1 and from in week not - for this round */ - // firstOfWeek = 0; this is already done at decl. - while(!((1 << firstOfWeek) & days() )) - firstOfWeek++; - - /* there is at least one 'day', or there would be no event */ - while(!((1 << (dayOfWeek % 7)) & days() )) - dayOfWeek++; - - dayOfWeek = dayOfWeek % 7; /* the actual day of week */ - dayOfWeek -= start().dayOfWeek() -1; - - firstOfWeek = firstOfWeek % 7; /* the actual first of week */ - firstOfWeek -= start().dayOfWeek() -1; - - // dayOfWeek may be negitive now - // day of week is number of days to add to start day - - freq *= 7; - // FALL-THROUGH !!!!! - case Daily: - // the add is for the possible fall through from weekly */ - if(start().addDays(dayOfWeek) > from) { - /* first week exception */ - next = QDate(start().addDays(dayOfWeek) ); - if ((next > endDate()) - && hasEndDate() ) - return FALSE; - return TRUE; - } - /* if from is middle of a non-week */ - - diff = start().addDays(dayOfWeek).daysTo(from) % freq; - diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; - - if(diff != 0) - diff = freq - diff; - if(diff2 != 0) - diff2 = freq - diff2; - diff = QMIN(diff, diff2); - - next = QDate(from.addDays(diff)); - if ( (next > endDate()) - && hasEndDate() ) - return FALSE; - return TRUE; - case MonthlyDay: - iday = from.day(); - iyear = from.year(); - imonth = from.month(); - /* find equivelent day of month for this month */ - dayOfWeek = start().dayOfWeek(); - weekOfMonth = (start().day() - 1) / 7; - - /* work out when the next valid month is */ - a = from.year() - start().year(); - a *= 12; - a = a + (imonth - start().month()); - /* a is e.start()monthsFrom(from); */ - if(a % freq) { - a = freq - (a % freq); - imonth = from.month() + a; - if (imonth > 12) { - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - } - } - /* imonth is now the first month after or on - from that matches the frequency given */ - - /* find for this month */ - tmpDate = QDate( iyear, imonth, 1 ); - - iday = 1; - iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; - iday += 7 * weekOfMonth; - while (iday > tmpDate.daysInMonth()) { - imonth += freq; - if (imonth > 12) { - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - } - tmpDate = QDate( iyear, imonth, 1 ); - /* these loops could go for a while, check end case now */ - if ((tmpDate > endDate()) && hasEndDate() ) - return FALSE; - iday = 1; - iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; - iday += 7 * weekOfMonth; - } - tmpDate = QDate(iyear, imonth, iday); - - if (tmpDate >= from) { - next = tmpDate; - if ((next > endDate() ) && hasEndDate() ) - return FALSE; - return TRUE; - } - - /* need to find the next iteration */ - do { - imonth += freq; - if (imonth > 12) { - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - } - tmpDate = QDate( iyear, imonth, 1 ); - /* these loops could go for a while, check end case now */ - if ((tmpDate > endDate()) && hasEndDate() ) - return FALSE; - iday = 1; - iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; - iday += 7 * weekOfMonth; - } while (iday > tmpDate.daysInMonth()); - tmpDate = QDate(iyear, imonth, iday); - - next = tmpDate; - if ((next > endDate()) && hasEndDate() ) - return FALSE; - return TRUE; - case MonthlyDate: - iday = start().day(); - iyear = from.year(); - imonth = from.month(); - - a = from.year() - start().year(); - a *= 12; - a = a + (imonth - start().month()); - /* a is e.start()monthsFrom(from); */ - if(a % freq) { - a = freq - (a % freq); - imonth = from.month() + a; - if (imonth > 12) { - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - } - } - /* imonth is now the first month after or on - from that matches the frequencey given */ - - /* this could go for a while, worse case, 4*12 iterations, probably */ - while(!QDate::isValid(iyear, imonth, iday) ) { - imonth += freq; - if (imonth > 12) { - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - } - /* these loops could go for a while, check end case now */ - if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) - return FALSE; - } - - if(QDate(iyear, imonth, iday) >= from) { - /* done */ - next = QDate(iyear, imonth, iday); - if ((next > endDate()) && hasEndDate() ) - return FALSE; - return TRUE; - } - - /* ok, need to cycle */ - imonth += freq; - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - - while(!QDate::isValid(iyear, imonth, iday) ) { - imonth += freq; - imonth--; - iyear += imonth / 12; - imonth = imonth % 12; - imonth++; - if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) - return FALSE; - } - - next = QDate(iyear, imonth, iday); - if ((next > endDate()) && hasEndDate() ) - return FALSE; - return TRUE; - case Yearly: - iday = start().day(); - imonth = start().month(); - iyear = from.year(); // after all, we want to start in this year - - diff = 1; - if(imonth == 2 && iday > 28) { - /* leap year, and it counts, calculate actual frequency */ - if(freq % 4) - if (freq % 2) - freq = freq * 4; - else - freq = freq * 2; - /* else divides by 4 already, leave freq alone */ - diff = 4; - } - - a = from.year() - start().year(); - if(a % freq) { - a = freq - (a % freq); - iyear = iyear + a; - } - - /* under the assumption we won't hit one of the special not-leap years twice */ - if(!QDate::isValid(iyear, imonth, iday)) { - /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ - iyear += freq; - } - - if(QDate(iyear, imonth, iday) >= from) { - next = QDate(iyear, imonth, iday); - - if ((next > endDate()) && hasEndDate() ) - return FALSE; - return TRUE; - } - /* iyear == from.year(), need to advance again */ - iyear += freq; - /* under the assumption we won't hit one of the special not-leap years twice */ - if(!QDate::isValid(iyear, imonth, iday)) { - /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ - iyear += freq; - } - - next = QDate(iyear, imonth, iday); - if ((next > endDate()) && hasEndDate() ) - return FALSE; - return TRUE; - default: - return FALSE; + dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ + + /* this is done in case freq > 1 and from in week not + for this round */ + // firstOfWeek = 0; this is already done at decl. + while(!((1 << firstOfWeek) & days() )) + firstOfWeek++; + + /* there is at least one 'day', or there would be no event */ + while(!((1 << (dayOfWeek % 7)) & days() )) + dayOfWeek++; + + dayOfWeek = dayOfWeek % 7; /* the actual day of week */ + dayOfWeek -= start().dayOfWeek() -1; + + firstOfWeek = firstOfWeek % 7; /* the actual first of week */ + firstOfWeek -= start().dayOfWeek() -1; + + // dayOfWeek may be negitive now + // day of week is number of days to add to start day + + freq *= 7; + // FALL-THROUGH !!!!! + case Daily: + // the add is for the possible fall through from weekly */ + if(start().addDays(dayOfWeek) > from) { + /* first week exception */ + next = QDate(start().addDays(dayOfWeek) ); + if ((next > endDate()) + && hasEndDate() ) + return FALSE; + return TRUE; + } + /* if from is middle of a non-week */ + + diff = start().addDays(dayOfWeek).daysTo(from) % freq; + diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; + + if(diff != 0) + diff = freq - diff; + if(diff2 != 0) + diff2 = freq - diff2; + diff = QMIN(diff, diff2); + + next = QDate(from.addDays(diff)); + if ( (next > endDate()) + && hasEndDate() ) + return FALSE; + return TRUE; + case MonthlyDay: + iday = from.day(); + iyear = from.year(); + imonth = from.month(); + /* find equivelent day of month for this month */ + dayOfWeek = start().dayOfWeek(); + weekOfMonth = (start().day() - 1) / 7; + + /* work out when the next valid month is */ + a = from.year() - start().year(); + a *= 12; + a = a + (imonth - start().month()); + /* a is e.start()monthsFrom(from); */ + if(a % freq) { + a = freq - (a % freq); + imonth = from.month() + a; + if (imonth > 12) { + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + } + } + /* imonth is now the first month after or on + from that matches the frequency given */ + + /* find for this month */ + tmpDate = QDate( iyear, imonth, 1 ); + + iday = 1; + iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; + iday += 7 * weekOfMonth; + while (iday > tmpDate.daysInMonth()) { + imonth += freq; + if (imonth > 12) { + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + } + tmpDate = QDate( iyear, imonth, 1 ); + /* these loops could go for a while, check end case now */ + if ((tmpDate > endDate()) && hasEndDate() ) + return FALSE; + iday = 1; + iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; + iday += 7 * weekOfMonth; + } + tmpDate = QDate(iyear, imonth, iday); + + if (tmpDate >= from) { + next = tmpDate; + if ((next > endDate() ) && hasEndDate() ) + return FALSE; + return TRUE; + } + + /* need to find the next iteration */ + do { + imonth += freq; + if (imonth > 12) { + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + } + tmpDate = QDate( iyear, imonth, 1 ); + /* these loops could go for a while, check end case now */ + if ((tmpDate > endDate()) && hasEndDate() ) + return FALSE; + iday = 1; + iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; + iday += 7 * weekOfMonth; + } while (iday > tmpDate.daysInMonth()); + tmpDate = QDate(iyear, imonth, iday); + + next = tmpDate; + if ((next > endDate()) && hasEndDate() ) + return FALSE; + return TRUE; + case MonthlyDate: + iday = start().day(); + iyear = from.year(); + imonth = from.month(); + + a = from.year() - start().year(); + a *= 12; + a = a + (imonth - start().month()); + /* a is e.start()monthsFrom(from); */ + if(a % freq) { + a = freq - (a % freq); + imonth = from.month() + a; + if (imonth > 12) { + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + } + } + /* imonth is now the first month after or on + from that matches the frequencey given */ + + /* this could go for a while, worse case, 4*12 iterations, probably */ + while(!QDate::isValid(iyear, imonth, iday) ) { + imonth += freq; + if (imonth > 12) { + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + } + /* these loops could go for a while, check end case now */ + if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) + return FALSE; + } + + if(QDate(iyear, imonth, iday) >= from) { + /* done */ + next = QDate(iyear, imonth, iday); + if ((next > endDate()) && hasEndDate() ) + return FALSE; + return TRUE; + } + + /* ok, need to cycle */ + imonth += freq; + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + + while(!QDate::isValid(iyear, imonth, iday) ) { + imonth += freq; + imonth--; + iyear += imonth / 12; + imonth = imonth % 12; + imonth++; + if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) + return FALSE; + } + + next = QDate(iyear, imonth, iday); + if ((next > endDate()) && hasEndDate() ) + return FALSE; + return TRUE; + case Yearly: + iday = start().day(); + imonth = start().month(); + iyear = from.year(); // after all, we want to start in this year + + diff = 1; + if(imonth == 2 && iday > 28) { + /* leap year, and it counts, calculate actual frequency */ + if(freq % 4) + if (freq % 2) + freq = freq * 4; + else + freq = freq * 2; + /* else divides by 4 already, leave freq alone */ + diff = 4; + } + + a = from.year() - start().year(); + if(a % freq) { + a = freq - (a % freq); + iyear = iyear + a; + } + + /* under the assumption we won't hit one of the special not-leap years twice */ + if(!QDate::isValid(iyear, imonth, iday)) { + /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ + iyear += freq; + } + + if(QDate(iyear, imonth, iday) >= from) { + next = QDate(iyear, imonth, iday); + + if ((next > endDate()) && hasEndDate() ) + return FALSE; + return TRUE; + } + /* iyear == from.year(), need to advance again */ + iyear += freq; + /* under the assumption we won't hit one of the special not-leap years twice */ + if(!QDate::isValid(iyear, imonth, iday)) { + /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ + iyear += freq; + } + + next = QDate(iyear, imonth, iday); + if ((next > endDate()) && hasEndDate() ) + return FALSE; + return TRUE; + default: + return FALSE; } } + + ORecur::RepeatType ORecur::type()const{ return data->type; } + + int ORecur::frequency()const { return data->freq; } + + int ORecur::position()const { return data->pos; } + + char ORecur::days() const{ return data->days; } + + bool ORecur::hasEndDate()const { return data->hasEnd; } + + QDate ORecur::endDate()const { return data->end; } + + QDate ORecur::start()const{ return data->start; } + + QDateTime ORecur::createdDateTime()const { return data->create; } + + int ORecur::repetition()const { return data->rep; } + + QString ORecur::service()const { return data->app; } + + ORecur::ExceptionList& ORecur::exceptions() { return data->list; } + + void ORecur::setType( const RepeatType& z) { checkOrModify(); data->type = z; } + + void ORecur::setFrequency( int freq ) { checkOrModify(); data->freq = freq; } + + void ORecur::setPosition( int pos ) { checkOrModify(); data->pos = pos; } + + void ORecur::setDays( char c ) { checkOrModify(); data->days = c; } + + void ORecur::setEndDate( const QDate& dt) { checkOrModify(); data->end = dt; } + + void ORecur::setCreatedDateTime( const QDateTime& t) { checkOrModify(); data->create = t; } + + void ORecur::setHasEndDate( bool b) { checkOrModify(); data->hasEnd = b; } + + void ORecur::setRepitition( int rep ) { checkOrModify(); data->rep = rep; } + + void ORecur::setService( const QString& app ) { checkOrModify(); data->app = app; } + + void ORecur::setStart( const QDate& dt ) { checkOrModify(); data->start = dt; } + + void ORecur::checkOrModify() { if ( data->count != 1 ) { data->deref(); Data* d2 = new Data; d2->days = data->days; d2->type = data->type; d2->freq = data->freq; d2->pos = data->pos; d2->hasEnd = data->hasEnd; d2->end = data->end; d2->create = data->create; d2->rep = data->rep; d2->app = data->app; d2->list = data->list; d2->start = data->start; data = d2; } } + + QString ORecur::toString()const { QString buf; QMap<int, QString> recMap = toMap(); buf += " rtype=\""; buf += recMap[ORecur::RType]; buf += "\""; if (data->days > 0 ) - buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; + buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; if ( data->pos != 0 ) - buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; + buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; if ( data->hasEnd ) - buf += " enddt=\"" - + recMap[ORecur::EndDate] - + "\""; + buf += " enddt=\"" + + recMap[ORecur::EndDate] + + "\""; buf += " created=\"" + recMap[ORecur::Created] + "\""; if ( data->list.isEmpty() ) return buf; buf += " exceptions=\""; buf += recMap[ORecur::Exceptions]; buf += "\" "; return buf; } QString ORecur::rTypeString() const { - QString retString; - switch ( data->type ) { - case ORecur::Daily: - retString = "Daily"; - break; - case ORecur::Weekly: - retString = "Weekly"; - break; - case ORecur::MonthlyDay: - retString = "MonthlyDay"; - break; - case ORecur::MonthlyDate: - retString = "MonthlyDate"; - break; - case ORecur::Yearly: - retString = "Yearly"; - break; - default: - retString = "NoRepeat"; - break; - - } - - return retString; + QString retString; + switch ( data->type ) { + case ORecur::Daily: + retString = "Daily"; + break; + case ORecur::Weekly: + retString = "Weekly"; + break; + case ORecur::MonthlyDay: + retString = "MonthlyDay"; + break; + case ORecur::MonthlyDate: + retString = "MonthlyDate"; + break; + case ORecur::Yearly: + retString = "Yearly"; + break; + default: + retString = "NoRepeat"; + break; + + } + + return retString; } QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const { - QMap<QString, RepeatType> convertMap; + QMap<QString, RepeatType> convertMap; - convertMap.insert( QString( "Daily" ), ORecur::Daily ); - convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); - convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); - convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); - convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); - convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); + convertMap.insert( QString( "Daily" ), ORecur::Daily ); + convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); + convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); + convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); + convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); + convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); - return convertMap; + return convertMap; } QMap<int, QString> ORecur::toMap() const { - QMap<int, QString> retMap; - - retMap.insert( ORecur::RType, rTypeString() ); - retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); - retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); - retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); - retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); - if( data -> hasEnd ) - retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); - retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); - - if ( data->list.isEmpty() ) return retMap; - - // save exceptions list here!! - ExceptionList::ConstIterator it; - ExceptionList list = data->list; - QString exceptBuf; - QDate date; - for ( it = list.begin(); it != list.end(); ++it ) { - date = (*it); - if ( it != list.begin() ) exceptBuf += " "; - - exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); - } - - retMap.insert( ORecur::Exceptions, exceptBuf ); - - return retMap; + QMap<int, QString> retMap; + + retMap.insert( ORecur::RType, rTypeString() ); + retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); + retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); + retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); + retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); + if( data -> hasEnd ) + retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); + retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); + + if ( data->list.isEmpty() ) return retMap; + + // save exceptions list here!! + ExceptionList::ConstIterator it; + ExceptionList list = data->list; + QString exceptBuf; + QDate date; + for ( it = list.begin(); it != list.end(); ++it ) { + date = (*it); + if ( it != list.begin() ) exceptBuf += " "; + + exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); + } + + retMap.insert( ORecur::Exceptions, exceptBuf ); + + return retMap; } void ORecur::fromMap( const QMap<int, QString>& map ) { - QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); - - data -> type = repTypeMap[ map [ORecur::RType] ]; - data -> days = (char) map[ ORecur::RWeekdays ].toInt(); - data -> pos = map[ ORecur::RPosition ].toInt(); - data -> freq = map[ ORecur::RFreq ].toInt(); - data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; - OTimeZone utc = OTimeZone::utc(); - if ( data -> hasEnd ){ - data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); - } - data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); + QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); + + data -> type = repTypeMap[ map [ORecur::RType] ]; + data -> days = (char) map[ ORecur::RWeekdays ].toInt(); + data -> pos = map[ ORecur::RPosition ].toInt(); + data -> freq = map[ ORecur::RFreq ].toInt(); + data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; + OTimeZone utc = OTimeZone::utc(); + if ( data -> hasEnd ){ + data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); + } + data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); #if 0 - // FIXME: Exceptions currently not supported... - // Convert the list of exceptions from QString into ExceptionList - data -> list.clear(); - QString exceptStr = map[ ORecur::Exceptions ]; - QStringList exceptList = QStringList::split( " ", exceptStr ); - ... + // FIXME: Exceptions currently not supported... + // Convert the list of exceptions from QString into ExceptionList + data -> list.clear(); + QString exceptStr = map[ ORecur::Exceptions ]; + QStringList exceptList = QStringList::split( " ", exceptStr ); + ... #endif - - + + } -}
\ No newline at end of file +} diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index 60508f5..7808897 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h @@ -1,134 +1,137 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_RECUR_H -#define OPIE_RECUR_H - -#include <sys/types.h> +#ifndef ORECUR_H +#define ORECUR_H +/* QT */ #include <qdatetime.h> #include <qvaluelist.h> #include <qmap.h> +/* STD */ +#include <sys/types.h> namespace Opie { /** * Class to handle Recurrencies.. */ class ORecur { -public: + + 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 }; + 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: + + 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/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h index 17d9961..58cbfeb 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/otemplatebase.h @@ -1,129 +1,130 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_TEMPLATE_BASE_H -#define OPIE_TEMPLATE_BASE_H - -#include <qarray.h> +#ifndef OTEMPLATEBASE_H +#define OTEMPLATEBASE_H +/* OPIE */ #include <opie2/opimrecord.h> +/* QT */ +#include <qarray.h> namespace Opie { /** * Templates do not have a base class, This is why * we've this class * this is here to give us the possibility * to have a common base class * You may not want to use that interface internaly * POOR mans interface */ class OPimBasePrivate; struct OPimBase { /** * return the rtti */ virtual int rtti()= 0; virtual OPimRecord* record()const = 0; virtual OPimRecord* record(int uid)const = 0; virtual bool add( const OPimRecord& ) = 0; virtual bool remove( int uid ) = 0; virtual bool remove( const OPimRecord& ) = 0; virtual void clear() = 0; virtual bool load() = 0; virtual bool save() = 0; virtual QArray<int> records()const = 0; /* * ADD editing here? * -zecke */ private: OPimBasePrivate* d; }; /** * internal template base * T needs to implement the copy c'tor!!! */ class OTemplateBasePrivate; template <class T = OPimRecord> class OTemplateBase : public OPimBase { public: enum CacheDirection { Forward=0, Reverse }; OTemplateBase() { }; virtual ~OTemplateBase() { } virtual T find( int uid )const = 0; /** * read ahead find */ virtual T find( int uid, const QArray<int>& items, uint current, CacheDirection dir = Forward )const = 0; virtual void cache( const T& )const = 0; virtual void setSaneCacheSize( int ) = 0; /* reimplement of OPimBase */ int rtti(); OPimRecord* record()const; OPimRecord* record(int uid )const; static T* rec(); private: OTemplateBasePrivate *d; }; /* * implementation */ template <class T> int OTemplateBase<T>::rtti() { return T::rtti(); } template <class T> OPimRecord* OTemplateBase<T>::record()const { T* t = new T; return t; } template <class T> OPimRecord* OTemplateBase<T>::record(int uid )const { T t2 = find(uid ); T* t1 = new T(t2); return t1; }; template <class T> T* OTemplateBase<T>::rec() { return new T; } } #endif diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp index dab68af..e67715f 100644 --- a/libopie2/opiepim/core/otimezone.cpp +++ b/libopie2/opiepim/core/otimezone.cpp @@ -1,146 +1,188 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "otimezone.h" + +/* STD */ #include <stdio.h> #include <stdlib.h> - #include <sys/types.h> -#include <opie2/otimezone.h> - -namespace Opie { +namespace Opie +{ - QDateTime utcTime( time_t t) { - tm* broken = ::gmtime( &t ); - QDateTime ret; - ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); - ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); - return ret; - } - QDateTime utcTime( time_t t, const QString& zone) { - QCString org = ::getenv( "TZ" ); +QDateTime utcTime( time_t t ) +{ + tm * broken = ::gmtime( &t ); + QDateTime ret; + ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); + ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); + return ret; +} +QDateTime utcTime( time_t t, const QString& zone ) +{ + QCString org = ::getenv( "TZ" ); #ifndef Q_OS_MACX // Following line causes bus errors on Mac - ::setenv( "TZ", zone.latin1(), true ); - ::tzset(); - tm* broken = ::localtime( &t ); - ::setenv( "TZ", org, true ); + ::setenv( "TZ", zone.latin1(), true ); + ::tzset(); + + tm* broken = ::localtime( &t ); + ::setenv( "TZ", org, true ); #else #warning "Need a replacement for MacOSX!!" - tm* broken = ::localtime( &t ); + + tm* broken = ::localtime( &t ); #endif - QDateTime ret; - ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); - ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); - - return ret; - } - time_t to_Time_t( const QDateTime& utc, const QString& str ) { - QDate d = utc.date(); - QTime t = utc.time(); - - tm broken; - broken.tm_year = d.year() - 1900; - broken.tm_mon = d.month() - 1; - broken.tm_mday = d.day(); - broken.tm_hour = t.hour(); - broken.tm_min = t.minute(); - broken.tm_sec = t.second(); - - QCString org = ::getenv( "TZ" ); + QDateTime ret; + ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); + ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); + + return ret; +} +time_t to_Time_t( const QDateTime& utc, const QString& str ) +{ + QDate d = utc.date(); + QTime t = utc.time(); + + tm broken; + broken.tm_year = d.year() - 1900; + broken.tm_mon = d.month() - 1; + broken.tm_mday = d.day(); + broken.tm_hour = t.hour(); + broken.tm_min = t.minute(); + broken.tm_sec = t.second(); + + QCString org = ::getenv( "TZ" ); #ifndef Q_OS_MACX // Following line causes bus errors on Mac - ::setenv( "TZ", str.latin1(), true ); - ::tzset(); - time_t ti = ::mktime( &broken ); - ::setenv( "TZ", org, true ); + ::setenv( "TZ", str.latin1(), true ); + ::tzset(); + + time_t ti = ::mktime( &broken ); + ::setenv( "TZ", org, true ); #else #warning "Need a replacement for MacOSX!!" - time_t ti = ::mktime( &broken ); + + time_t ti = ::mktime( &broken ); #endif - return ti; - } -} -namespace Opie { -OTimeZone::OTimeZone( const ZoneName& zone ) - : m_name(zone) { + return ti; } -OTimeZone::~OTimeZone() { } -bool OTimeZone::isValid()const { +namespace Opie +{ +OTimeZone::OTimeZone( const ZoneName& zone ) + : m_name( zone ) +{} + + +OTimeZone::~OTimeZone() +{} + + +bool OTimeZone::isValid() const +{ return !m_name.isEmpty(); } /* * we will get the current timezone * and ask it to convert to the timezone date */ -QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { +QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt ) +{ return OTimeZone::current().toDateTime( dt, *this ); } -QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { + + +QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) +{ return OTimeZone::utc().toDateTime( dt, *this ); } -QDateTime OTimeZone::fromUTCDateTime( time_t t) { + + +QDateTime OTimeZone::fromUTCDateTime( time_t t ) +{ return utcTime( t ); } -QDateTime OTimeZone::toDateTime( time_t t) { + + +QDateTime OTimeZone::toDateTime( time_t t ) +{ return utcTime( t, m_name ); } + + /* * convert dt to utc using zone.m_name * convert utc -> timeZoneDT using this->m_name */ -QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { +QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) +{ time_t utc = to_Time_t( dt, zone.m_name ); - qWarning("%d %s", utc, zone.m_name.latin1() ); + qWarning( "%d %s", utc, zone.m_name.latin1() ); return utcTime( utc, m_name ); } -time_t OTimeZone::fromDateTime( const QDateTime& time ) { + + +time_t OTimeZone::fromDateTime( const QDateTime& time ) +{ return to_Time_t( time, m_name ); } -time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { + + +time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) +{ return to_Time_t( time, "UTC" ); } -OTimeZone OTimeZone::current() { - QCString str = ::getenv("TZ"); + + +OTimeZone OTimeZone::current() +{ + QCString str = ::getenv( "TZ" ); OTimeZone zone( str ); return zone; } -OTimeZone OTimeZone::utc() { - return OTimeZone("UTC"); + + +OTimeZone OTimeZone::utc() +{ + return OTimeZone( "UTC" ); } -QString OTimeZone::timeZone()const { + + +QString OTimeZone::timeZone() const +{ return m_name; } } diff --git a/libopie2/opiepim/core/otimezone.h b/libopie2/opiepim/core/otimezone.h index 28ae6cb..f0b4022 100644 --- a/libopie2/opiepim/core/otimezone.h +++ b/libopie2/opiepim/core/otimezone.h @@ -1,102 +1,107 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_TIME_ZONE_H -#define OPIE_TIME_ZONE_H +#ifndef OTIMEZONE_H +#define OTIMEZONE_H -#include <time.h> +/* QT */ #include <qdatetime.h> +/* STD */ +#include <time.h> + namespace Opie { /** * A very primitive class to convert time * from one timezone to another * and to localtime * and time_t */ class OTimeZone { + public: typedef QString ZoneName; OTimeZone( const ZoneName& = ZoneName::null ); virtual ~OTimeZone(); // just in case. bool isValid()const; /** * converts the QDateTime to a DateTime * in the local timezone * if QDateTime is 25th Jan and takes place in Europe/Berlin at 12h * and the current timezone is Europe/London the returned * time will be 11h. */ QDateTime toLocalDateTime( const QDateTime& dt ); /** * converts the QDateTime to UTC time */ QDateTime toUTCDateTime( const QDateTime& dt ); /** * reads the time_t into a QDateTime using UTC as timezone! */ QDateTime fromUTCDateTime( time_t ); /** * converts the time_t to the time in the timezone */ QDateTime toDateTime( time_t ); /** * converts the QDateTime from one timezone to this timeZone */ QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); /** * converts the date time into a time_t. It takes the timezone into account */ time_t fromDateTime( const QDateTime& ); /** * converts the datetime with timezone UTC */ time_t fromUTCDateTime( const QDateTime& ); static OTimeZone current(); static OTimeZone utc(); - QString timeZone()const; + QString timeZone() const; + private: ZoneName m_name; class Private; Private* d; }; }; #endif |