summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
authormickeyl <mickeyl>2004-02-24 12:46:23 (UTC)
committer mickeyl <mickeyl>2004-02-24 12:46:23 (UTC)
commit911473db35a9fce5f3589f03c27210456faaba86 (patch) (unidiff)
tree7d55b6117b24de6ab18747b00a4641d38001c0ed /libopie2/opiepim/core
parenta2ead23c3614fe581261455cb4c3f31cee2098f3 (diff)
downloadopie-911473db35a9fce5f3589f03c27210456faaba86.zip
opie-911473db35a9fce5f3589f03c27210456faaba86.tar.gz
opie-911473db35a9fce5f3589f03c27210456faaba86.tar.bz2
*phew* here is the class and file rename patch. not converted yet: backend,
but that will be not visible to application classes so we can change it later.
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/core.pro16
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp36
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h20
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp2
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h4
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h6
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp1293
-rw-r--r--libopie2/opiepim/core/opimcontact.h256
-rw-r--r--libopie2/opiepim/core/opimcontactfields.cpp518
-rw-r--r--libopie2/opiepim/core/opimcontactfields.h102
-rw-r--r--libopie2/opiepim/core/opimdateconversion.cpp (renamed from libopie2/opiepim/core/oconversion.cpp)10
-rw-r--r--libopie2/opiepim/core/opimdateconversion.h (renamed from libopie2/opiepim/core/oconversion.h)2
-rw-r--r--libopie2/opiepim/core/opimevent.cpp1025
-rw-r--r--libopie2/opiepim/core/opimevent.h275
-rw-r--r--libopie2/opiepim/core/opimnotify.h2
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp8
-rw-r--r--libopie2/opiepim/core/opimrecordlist.h402
-rw-r--r--libopie2/opiepim/core/opimrecurrence.cpp (renamed from libopie2/opiepim/core/orecur.cpp)160
-rw-r--r--libopie2/opiepim/core/opimrecurrence.h (renamed from libopie2/opiepim/core/orecur.h)20
-rw-r--r--libopie2/opiepim/core/opimresolver.cpp8
-rw-r--r--libopie2/opiepim/core/opimresolver.h2
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h (renamed from libopie2/opiepim/core/otemplatebase.h)0
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp (renamed from libopie2/opiepim/core/otimezone.cpp)36
-rw-r--r--libopie2/opiepim/core/opimtimezone.h (renamed from libopie2/opiepim/core/otimezone.h)12
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp712
-rw-r--r--libopie2/opiepim/core/opimtodo.h320
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp32
-rw-r--r--libopie2/opiepim/core/otodoaccess.h34
28 files changed, 5109 insertions, 204 deletions
diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro
index 0473622..597b1e8 100644
--- a/libopie2/opiepim/core/core.pro
+++ b/libopie2/opiepim/core/core.pro
@@ -1,4 +1,5 @@
1HEADERS += core/oconversion.h \ 1HEADERS += \
2 core/opimdateconversion.h \
2 core/opimcache.h \ 3 core/opimcache.h \
3 core/opimmaintainer.h \ 4 core/opimmaintainer.h \
4 core/opimresolver.h \ 5 core/opimresolver.h \
@@ -6,16 +7,17 @@ HEADERS += core/oconversion.h \
6 core/opimxref.h \ 7 core/opimxref.h \
7 core/opimxrefmanager.h \ 8 core/opimxrefmanager.h \
8 core/opimxrefpartner.h \ 9 core/opimxrefpartner.h \
9 core/orecur.h \ 10 core/opimrecurrence.h \
10 core/otemplatebase.h \ 11 core/opimtemplatebase.h \
11 core/otimezone.h 12 core/opimtimezone.h
12 13
13SOURCES += core/oconversion.cpp \ 14SOURCES += \
15 core/opimdateconversion.cpp \
14 core/opimmaintainer.cpp \ 16 core/opimmaintainer.cpp \
15 core/opimresolver.cpp \ 17 core/opimresolver.cpp \
16 core/opimstate.cpp \ 18 core/opimstate.cpp \
17 core/opimxref.cpp \ 19 core/opimxref.cpp \
18 core/opimxrefmanager.cpp \ 20 core/opimxrefmanager.cpp \
19 core/opimxrefpartner.cpp \ 21 core/opimxrefpartner.cpp \
20 core/orecur.cpp \ 22 core/opimrecurrence.cpp \
21 core/otimezone.cpp 23 core/opimtimezone.cpp
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index f67a40c..c12e138 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -55,20 +55,20 @@
55 55
56namespace Opie { 56namespace Opie {
57 57
58OContactAccess::OContactAccess ( const QString appname, const QString , 58OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
59 OContactAccessBackend* end, bool autosync ): 59 OPimContactAccessBackend* end, bool autosync ):
60 OPimAccessTemplate<OContact>( end ) 60 OPimAccessTemplate<OPimContact>( end )
61{ 61{
62 /* take care of the backend. If there is no one defined, we 62 /* take care of the backend. If there is no one defined, we
63 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 63 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
64 */ 64 */
65 if( end == 0 ) { 65 if( end == 0 ) {
66 qWarning ("Using BackendFactory !"); 66 qWarning ("Using BackendFactory !");
67 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); 67 end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname );
68 } 68 }
69 // Set backend locally and in template 69 // Set backend locally and in template
70 m_backEnd = end; 70 m_backEnd = end;
71 OPimAccessTemplate<OContact>::setBackEnd (end); 71 OPimAccessTemplate<OPimContact>::setBackEnd (end);
72 72
73 73
74 /* Connect signal of external db change to function */ 74 /* Connect signal of external db change to function */
@@ -83,7 +83,7 @@ OContactAccess::OContactAccess ( const QString appname, const QString ,
83 83
84 84
85} 85}
86OContactAccess::~OContactAccess () 86OPimContactAccess::~OPimContactAccess ()
87{ 87{
88 /* The user may forget to save the changed database, therefore try to 88 /* The user may forget to save the changed database, therefore try to
89 * do it for him.. 89 * do it for him..
@@ -93,16 +93,16 @@ OContactAccess::~OContactAccess ()
93} 93}
94 94
95 95
96bool OContactAccess::save () 96bool OPimContactAccess::save ()
97{ 97{
98 /* If the database was changed externally, we could not save the 98 /* If the database was changed externally, we could not save the
99 * Data. This will remove added items which is unacceptable ! 99 * Data. This will remove added items which is unacceptable !
100 * Therefore: Reload database and merge the data... 100 * Therefore: Reload database and merge the data...
101 */ 101 */
102 if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) 102 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
103 reload(); 103 reload();
104 104
105 bool status = OPimAccessTemplate<OContact>::save(); 105 bool status = OPimAccessTemplate<OPimContact>::save();
106 if ( !status ) return false; 106 if ( !status ) return false;
107 107
108 /* Now tell everyone that new data is available. 108 /* Now tell everyone that new data is available.
@@ -112,38 +112,38 @@ bool OContactAccess::save ()
112 return true; 112 return true;
113} 113}
114 114
115const uint OContactAccess::querySettings() 115const uint OPimContactAccess::querySettings()
116{ 116{
117 return ( m_backEnd->querySettings() ); 117 return ( m_backEnd->querySettings() );
118} 118}
119 119
120bool OContactAccess::hasQuerySettings ( int querySettings ) const 120bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
121{ 121{
122 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 122 return ( m_backEnd->hasQuerySettings ( querySettings ) );
123} 123}
124ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 124OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
125{ 125{
126 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 126 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
127 return ( ORecordList<OContact>(matchingContacts, this) ); 127 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
128} 128}
129 129
130 130
131bool OContactAccess::wasChangedExternally()const 131bool OPimContactAccess::wasChangedExternally()const
132{ 132{
133 return ( m_backEnd->wasChangedExternally() ); 133 return ( m_backEnd->wasChangedExternally() );
134} 134}
135 135
136 136
137void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) 137void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
138{ 138{
139 if ( msg == "addressbookUpdated()" ){ 139 if ( msg == "addressbookUpdated()" ){
140 qWarning ("OContactAccess: Received addressbokUpdated()"); 140 qWarning ("OPimContactAccess: Received addressbokUpdated()");
141 emit signalChanged ( this ); 141 emit signalChanged ( this );
142 } else if ( msg == "flush()" ) { 142 } else if ( msg == "flush()" ) {
143 qWarning ("OContactAccess: Received flush()"); 143 qWarning ("OPimContactAccess: Received flush()");
144 save (); 144 save ();
145 } else if ( msg == "reload()" ) { 145 } else if ( msg == "reload()" ) {
146 qWarning ("OContactAccess: Received reload()"); 146 qWarning ("OPimContactAccess: Received reload()");
147 reload (); 147 reload ();
148 emit signalChanged ( this ); 148 emit signalChanged ( this );
149 } 149 }
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 505c87b..cf5333a 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -41,7 +41,7 @@
41#include <qvaluelist.h> 41#include <qvaluelist.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43 43
44#include <opie2/ocontact.h> 44#include <opie2/opimcontact.h>
45#include <opie2/ocontactaccessbackend.h> 45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/opimaccesstemplate.h> 46#include <opie2/opimaccesstemplate.h>
47 47
@@ -55,7 +55,7 @@ namespace Opie {
55 * @author Stefan Eilers, Holger Freyther 55 * @author Stefan Eilers, Holger Freyther
56 * @see OPimAccessTemplate 56 * @see OPimAccessTemplate
57 */ 57 */
58class OContactAccess: public QObject, public OPimAccessTemplate<OContact> 58class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61 61
@@ -72,11 +72,11 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
72 * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> 72 * automatically if it receives the signals <i>flush()</i> and <i>reload()</i>
73 * which are used before and after synchronisation. If the application wants 73 * which are used before and after synchronisation. If the application wants
74 * to react itself, it should be disabled by setting it to <b>false</b> 74 * to react itself, it should be disabled by setting it to <b>false</b>
75 * @see OContactAccessBackend 75 * @see OPimContactAccessBackend
76 */ 76 */
77 OContactAccess (const QString appname, const QString filename = 0l, 77 OPimContactAccess (const QString appname, const QString filename = 0l,
78 OContactAccessBackend* backend = 0l, bool handlesync = true); 78 OPimContactAccessBackend* backend = 0l, bool handlesync = true);
79 ~OContactAccess (); 79 ~OPimContactAccess ();
80 80
81 /** Constants for query. 81 /** Constants for query.
82 * Use this constants to set the query parameters. 82 * Use this constants to set the query parameters.
@@ -135,13 +135,13 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
135 * is useful if an application has to handle multiple databases at the same time. 135 * is useful if an application has to handle multiple databases at the same time.
136 * @see reload() 136 * @see reload()
137 */ 137 */
138 void signalChanged ( const OContactAccess *which ); 138 void signalChanged ( const OPimContactAccess *which );
139 139
140 140
141 private: 141 private:
142 // class OContactAccessPrivate; 142 // class OPimContactAccessPrivate;
143 // OContactAccessPrivate* d; 143 // OPimContactAccessPrivate* d;
144 OContactAccessBackend *m_backEnd; 144 OPimContactAccessBackend *m_backEnd;
145 bool m_loading:1; 145 bool m_loading:1;
146 146
147 private slots: 147 private slots:
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index 8c527f6..ac310c1 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -38,7 +38,7 @@ namespace Opie {
38 * @param ac What kind of access is intended 38 * @param ac What kind of access is intended
39 */ 39 */
40ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 40ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
41 : OPimAccessTemplate<OEvent>( back ) 41 : OPimAccessTemplate<OPimEvent>( back )
42{ 42{
43 if (!back ) 43 if (!back )
44 back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); 44 back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null );
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index 38dc754..6c9290f 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -32,7 +32,7 @@
32#include "odatebookaccessbackend.h" 32#include "odatebookaccessbackend.h"
33#include "opimaccesstemplate.h" 33#include "opimaccesstemplate.h"
34 34
35#include <opie2/oevent.h> 35#include <opie2/opimevent.h>
36 36
37namespace Opie { 37namespace Opie {
38/** 38/**
@@ -44,7 +44,7 @@ namespace Opie {
44 * 44 *
45 * @author Holger Freyther, Stefan Eilers 45 * @author Holger Freyther, Stefan Eilers
46 */ 46 */
47class ODateBookAccess : public OPimAccessTemplate<OEvent> { 47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> {
48public: 48public:
49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); 49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
50 ~ODateBookAccess(); 50 ~ODateBookAccess();
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 5826cbc..f1bcc44 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -33,10 +33,10 @@
33 33
34#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
35#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
36#include <opie2/orecordlist.h> 36#include <opie2/opimrecordlist.h>
37 37
38#include <opie2/opimcache.h> 38#include <opie2/opimcache.h>
39#include <opie2/otemplatebase.h> 39#include <opie2/opimtemplatebase.h>
40 40
41namespace Opie { 41namespace Opie {
42 42
@@ -57,7 +57,7 @@ public:
57 Random = 0, 57 Random = 0,
58 SortedAccess 58 SortedAccess
59 }; 59 };
60 typedef ORecordList<T> List; 60 typedef OPimRecordList<T> List;
61 typedef OPimAccessBackend<T> BackEnd; 61 typedef OPimAccessBackend<T> BackEnd;
62 typedef OPimCache<T> Cache; 62 typedef OPimCache<T> Cache;
63 63
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
new file mode 100644
index 0000000..a5df597
--- a/dev/null
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -0,0 +1,1293 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#define QTOPIA_INTERNAL_CONTACT_MRE
31
32#include "opimcontact.h"
33
34/* OPIE */
35#include <opie2/opimresolver.h>
36#include <opie2/opimdateconversion.h>
37#include <qpe/stringutil.h>
38#include <qpe/timestring.h>
39#include <qpe/config.h>
40
41/* QT */
42#include <qobject.h>
43#include <qregexp.h>
44#include <qstylesheet.h>
45#include <qfileinfo.h>
46#include <qmap.h>
47
48/* STD */
49#include <stdio.h>
50
51/*!
52 \class Contact contact.h
53 \brief The Contact class holds the data of an address book entry.
54
55 This data includes information the name of the person, contact
56 information, and business information such as deparment and job title.
57
58 \ingroup qtopiaemb
59 \ingroup qtopiadesktop
60*/
61
62
63namespace Opie
64{
65/*!
66 Creates a new, empty contact.
67*/
68OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
69{}
70
71/*!
72 \internal
73 Creates a new contact. The properties of the contact are
74 set from \a fromMap.
75*/
76OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
77{
78 QString cats = mMap[ Qtopia::AddressCategory ];
79 if ( !cats.isEmpty() )
80 setCategories( idsFromString( cats ) );
81
82 QString uidStr = find( Qtopia::AddressUid );
83
84 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
85 {
86 qWarning( "Invalid UID found. Generate new one.." );
87 setUid( uidGen().generate() );
88 }
89 else
90 setUid( uidStr.toInt() );
91
92 // if ( !uidStr.isEmpty() )
93 // setUid( uidStr.toInt() );
94}
95
96/*!
97 Destroys a contact.
98*/
99OPimContact::~OPimContact()
100{}
101
102/*! \fn void OPimContact::setTitle( const QString &str )
103 Sets the title of the contact to \a str.
104*/
105
106/*! \fn void OPimContact::setFirstName( const QString &str )
107 Sets the first name of the contact to \a str.
108*/
109
110/*! \fn void OPimContact::setMiddleName( const QString &str )
111 Sets the middle name of the contact to \a str.
112*/
113
114/*! \fn void OPimContact::setLastName( const QString &str )
115 Sets the last name of the contact to \a str.
116*/
117
118/*! \fn void OPimContact::setSuffix( const QString &str )
119 Sets the suffix of the contact to \a str.
120*/
121
122/*! \fn void OPimContact::setFileAs( const QString &str )
123 Sets the contact to filed as \a str.
124*/
125
126/*! \fn void OPimContact::setDefaultEmail( const QString &str )
127 Sets the default email of the contact to \a str.
128*/
129
130/*! \fn void OPimContact::setHomeStreet( const QString &str )
131 Sets the home street address of the contact to \a str.
132*/
133
134/*! \fn void OPimContact::setHomeCity( const QString &str )
135 Sets the home city of the contact to \a str.
136*/
137
138/*! \fn void OPimContact::setHomeState( const QString &str )
139 Sets the home state of the contact to \a str.
140*/
141
142/*! \fn void OPimContact::setHomeZip( const QString &str )
143 Sets the home zip code of the contact to \a str.
144*/
145
146/*! \fn void OPimContact::setHomeCountry( const QString &str )
147 Sets the home country of the contact to \a str.
148*/
149
150/*! \fn void OPimContact::setHomePhone( const QString &str )
151 Sets the home phone number of the contact to \a str.
152*/
153
154/*! \fn void OPimContact::setHomeFax( const QString &str )
155 Sets the home fax number of the contact to \a str.
156*/
157
158/*! \fn void OPimContact::setHomeMobile( const QString &str )
159 Sets the home mobile phone number of the contact to \a str.
160*/
161
162/*! \fn void OPimContact::setHomeWebpage( const QString &str )
163 Sets the home webpage of the contact to \a str.
164*/
165
166/*! \fn void OPimContact::setCompany( const QString &str )
167 Sets the company for contact to \a str.
168*/
169
170/*! \fn void OPimContact::setJobTitle( const QString &str )
171 Sets the job title of the contact to \a str.
172*/
173
174/*! \fn void OPimContact::setDepartment( const QString &str )
175 Sets the department for contact to \a str.
176*/
177
178/*! \fn void OPimContact::setOffice( const QString &str )
179 Sets the office for contact to \a str.
180*/
181
182/*! \fn void OPimContact::setBusinessStreet( const QString &str )
183 Sets the business street address of the contact to \a str.
184*/
185
186/*! \fn void OPimContact::setBusinessCity( const QString &str )
187 Sets the business city of the contact to \a str.
188*/
189
190/*! \fn void OPimContact::setBusinessState( const QString &str )
191 Sets the business state of the contact to \a str.
192*/
193
194/*! \fn void OPimContact::setBusinessZip( const QString &str )
195 Sets the business zip code of the contact to \a str.
196*/
197
198/*! \fn void OPimContact::setBusinessCountry( const QString &str )
199 Sets the business country of the contact to \a str.
200*/
201
202/*! \fn void OPimContact::setBusinessPhone( const QString &str )
203 Sets the business phone number of the contact to \a str.
204*/
205
206/*! \fn void OPimContact::setBusinessFax( const QString &str )
207 Sets the business fax number of the contact to \a str.
208*/
209
210/*! \fn void OPimContact::setBusinessMobile( const QString &str )
211 Sets the business mobile phone number of the contact to \a str.
212*/
213
214/*! \fn void OPimContact::setBusinessPager( const QString &str )
215 Sets the business pager number of the contact to \a str.
216*/
217
218/*! \fn void OPimContact::setBusinessWebpage( const QString &str )
219 Sets the business webpage of the contact to \a str.
220*/
221
222/*! \fn void OPimContact::setProfession( const QString &str )
223 Sets the profession of the contact to \a str.
224*/
225
226/*! \fn void OPimContact::setAssistant( const QString &str )
227 Sets the assistant of the contact to \a str.
228*/
229
230/*! \fn void OPimContact::setManager( const QString &str )
231 Sets the manager of the contact to \a str.
232*/
233
234/*! \fn void OPimContact::setSpouse( const QString &str )
235 Sets the spouse of the contact to \a str.
236*/
237
238/*! \fn void OPimContact::setGender( const QString &str )
239 Sets the gender of the contact to \a str.
240*/
241
242/*! \fn void OPimContact::setNickname( const QString &str )
243 Sets the nickname of the contact to \a str.
244*/
245
246/*! \fn void OPimContact::setNotes( const QString &str )
247 Sets the notes about the contact to \a str.
248*/
249
250/*! \fn QString OPimContact::title() const
251 Returns the title of the contact.
252*/
253
254/*! \fn QString OPimContact::firstName() const
255 Returns the first name of the contact.
256*/
257
258/*! \fn QString OPimContact::middleName() const
259 Returns the middle name of the contact.
260*/
261
262/*! \fn QString OPimContact::lastName() const
263 Returns the last name of the contact.
264*/
265
266/*! \fn QString OPimContact::suffix() const
267 Returns the suffix of the contact.
268*/
269
270/*! \fn QString OPimContact::fileAs() const
271 Returns the string the contact is filed as.
272*/
273
274/*! \fn QString OPimContact::defaultEmail() const
275 Returns the default email address of the contact.
276*/
277
278/*! \fn QString OPimContact::emails() const
279 Returns the list of email address for a contact separated by ';'s in a single
280 string.
281*/
282
283/*! \fn QString OPimContact::homeStreet() const
284 Returns the home street address of the contact.
285*/
286
287/*! \fn QString OPimContact::homeCity() const
288 Returns the home city of the contact.
289*/
290
291/*! \fn QString OPimContact::homeState() const
292 Returns the home state of the contact.
293*/
294
295/*! \fn QString OPimContact::homeZip() const
296 Returns the home zip of the contact.
297*/
298
299/*! \fn QString OPimContact::homeCountry() const
300 Returns the home country of the contact.
301*/
302
303/*! \fn QString OPimContact::homePhone() const
304 Returns the home phone number of the contact.
305*/
306
307/*! \fn QString OPimContact::homeFax() const
308 Returns the home fax number of the contact.
309*/
310
311/*! \fn QString OPimContact::homeMobile() const
312 Returns the home mobile number of the contact.
313*/
314
315/*! \fn QString OPimContact::homeWebpage() const
316 Returns the home webpage of the contact.
317*/
318
319/*! \fn QString OPimContact::company() const
320 Returns the company for the contact.
321*/
322
323/*! \fn QString OPimContact::department() const
324 Returns the department for the contact.
325*/
326
327/*! \fn QString OPimContact::office() const
328 Returns the office for the contact.
329*/
330
331/*! \fn QString OPimContact::jobTitle() const
332 Returns the job title of the contact.
333*/
334
335/*! \fn QString OPimContact::profession() const
336 Returns the profession of the contact.
337*/
338
339/*! \fn QString OPimContact::assistant() const
340 Returns the assistant of the contact.
341*/
342
343/*! \fn QString OPimContact::manager() const
344 Returns the manager of the contact.
345*/
346
347/*! \fn QString OPimContact::businessStreet() const
348 Returns the business street address of the contact.
349*/
350
351/*! \fn QString OPimContact::businessCity() const
352 Returns the business city of the contact.
353*/
354
355/*! \fn QString OPimContact::businessState() const
356 Returns the business state of the contact.
357*/
358
359/*! \fn QString OPimContact::businessZip() const
360 Returns the business zip of the contact.
361*/
362
363/*! \fn QString OPimContact::businessCountry() const
364 Returns the business country of the contact.
365*/
366
367/*! \fn QString OPimContact::businessPhone() const
368 Returns the business phone number of the contact.
369*/
370
371/*! \fn QString OPimContact::businessFax() const
372 Returns the business fax number of the contact.
373*/
374
375/*! \fn QString OPimContact::businessMobile() const
376 Returns the business mobile number of the contact.
377*/
378
379/*! \fn QString OPimContact::businessPager() const
380 Returns the business pager number of the contact.
381*/
382
383/*! \fn QString OPimContact::businessWebpage() const
384 Returns the business webpage of the contact.
385*/
386
387/*! \fn QString OPimContact::spouse() const
388 Returns the spouse of the contact.
389*/
390
391/*! \fn QString OPimContact::gender() const
392 Returns the gender of the contact.
393*/
394
395/*! \fn QString OPimContact::nickname() const
396 Returns the nickname of the contact.
397*/
398
399/*! \fn QString OPimContact::children() const
400 Returns the children of the contact.
401*/
402
403/*! \fn QString OPimContact::notes() const
404 Returns the notes relating to the the contact.
405*/
406
407/*! \fn QString OPimContact::groups() const
408 \internal
409 Returns the groups for the contact.
410*/
411
412/*! \fn QStringList OPimContact::groupList() const
413 \internal
414*/
415
416/*! \fn QString OPimContact::field(int) const
417 \internal
418*/
419
420/*! \fn void OPimContact::saveJournal( journal_action, const QString & = QString::null )
421 \internal
422*/
423
424/*! \fn void OPimContact::setUid( int id )
425 \internal
426 Sets the uid for this record to \a id.
427*/
428
429/*! \enum OPimContact::journal_action
430 \internal
431*/
432
433/*!
434 \internal
435*/
436QMap<int, QString> OPimContact::toMap() const
437{
438 QMap<int, QString> map = mMap;
439 QString cats = idsToString( categories() );
440 if ( !cats.isEmpty() )
441 map.insert( Qtopia::AddressCategory, cats );
442 return map;
443}
444
445/*!
446 Returns a rich text formatted QString representing the contents the contact.
447*/
448QString OPimContact::toRichText() const
449{
450 QString text;
451 QString value, comp, state;
452 QString str;
453 bool marker = false;
454
455 Config cfg( "qpe" );
456 cfg.setGroup( "Appearance" );
457 int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
458
459 // name, jobtitle and company
460 if ( !( value = fullName() ).isEmpty() )
461 text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>";
462
463 if ( !( value = jobTitle() ).isEmpty() )
464 text += Qtopia::escapeString( value ) + " ";
465
466 comp = company();
467 if ( !( value = department() ).isEmpty() )
468 {
469 text += Qtopia::escapeString( value );
470 if ( comp )
471 text += ", " + Qtopia::escapeString( comp );
472 }
473 else if ( comp )
474 text += "<br>" + Qtopia::escapeString( comp );
475 text += "<br><hr>";
476
477 // defailt email
478 QString defEmail = defaultEmail();
479 if ( !defEmail.isEmpty() )
480 {
481 text += "<b><img src=\"addressbook/email\"> " + QObject::tr( "Default Email: " ) + "</b>"
482 + Qtopia::escapeString( defEmail );
483 marker = true;
484 }
485
486 // business address
487 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
488 !businessZip().isEmpty() || !businessCountry().isEmpty() )
489 {
490 text += QObject::tr( "<br><b>Work Address:</b>" );
491 marker = true;
492 }
493
494 if ( !( value = businessStreet() ).isEmpty() )
495 {
496 text += "<br>" + Qtopia::escapeString( value );
497 marker = true;
498 }
499
500 switch ( addressformat )
501 {
502 case Zip_City_State:
503 { // Zip_Code City, State
504 state = businessState();
505 if ( !( value = businessZip() ).isEmpty() )
506 {
507 text += "<br>" + Qtopia::escapeString( value ) + " ";
508 marker = true;
509
510 }
511 if ( !( value = businessCity() ).isEmpty() )
512 {
513 marker = true;
514 if ( businessZip().isEmpty() && !businessStreet().isEmpty() )
515 text += "<br>";
516 text += Qtopia::escapeString( value );
517 if ( state )
518 text += ", " + Qtopia::escapeString( state );
519 }
520 else if ( !state.isEmpty() )
521 {
522 text += "<br>" + Qtopia::escapeString( state );
523 marker = true;
524 }
525 break;
526 }
527 case City_State_Zip:
528 { // City, State Zip_Code
529 state = businessState();
530 if ( !( value = businessCity() ).isEmpty() )
531 {
532 marker = true;
533 text += "<br>" + Qtopia::escapeString( value );
534 if ( state )
535 text += ", " + Qtopia::escapeString( state );
536 }
537 else if ( !state.isEmpty() )
538 {
539 text += "<br>" + Qtopia::escapeString( state );
540 marker = true;
541 }
542 if ( !( value = businessZip() ).isEmpty() )
543 {
544 text += " " + Qtopia::escapeString( value );
545 marker = true;
546 }
547 break;
548 }
549 }
550
551 if ( !( value = businessCountry() ).isEmpty() )
552 {
553 text += "<br>" + Qtopia::escapeString( value );
554 marker = true;
555 }
556
557 // rest of Business data
558 str = office();
559 if ( !str.isEmpty() )
560 {
561 text += "<br><b>" + QObject::tr( "Office: " ) + "</b>"
562 + Qtopia::escapeString( str );
563 marker = true;
564 }
565 str = businessWebpage();
566 if ( !str.isEmpty() )
567 {
568 text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr( "Business Web Page: " ) + "</b>"
569 + Qtopia::escapeString( str );
570 marker = true;
571 }
572 str = businessPhone();
573 if ( !str.isEmpty() )
574 {
575 text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>"
576 + Qtopia::escapeString( str );
577 marker = true;
578 }
579 str = businessFax();
580 if ( !str.isEmpty() )
581 {
582 text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr( "Business Fax: " ) + "</b>"
583 + Qtopia::escapeString( str );
584 marker = true;
585 }
586 str = businessMobile();
587 if ( !str.isEmpty() )
588 {
589 text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>"
590 + Qtopia::escapeString( str );
591 marker = true;
592 }
593 str = businessPager();
594 if ( !str.isEmpty() )
595 {
596 text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>"
597 + Qtopia::escapeString( str );
598 marker = true;
599 }
600
601 // text += "<br>";
602
603 // home address
604 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
605 !homeZip().isEmpty() || !homeCountry().isEmpty() )
606 {
607 text += QObject::tr( "<br><b>Home Address:</b>" );
608 marker = true;
609 }
610
611 if ( !( value = homeStreet() ).isEmpty() )
612 {
613 text += "<br>" + Qtopia::escapeString( value );
614 marker = true;
615 }
616
617 switch ( addressformat )
618 {
619 case Zip_City_State:
620 { // Zip_Code City, State
621 state = homeState();
622 if ( !( value = homeZip() ).isEmpty() )
623 {
624 text += "<br>" + Qtopia::escapeString( value ) + " ";
625 marker = true;
626 }
627 if ( !( value = homeCity() ).isEmpty() )
628 {
629 marker = true;
630 if ( homeZip().isEmpty() && !homeStreet().isEmpty() )
631 text += "<br>";
632 text += Qtopia::escapeString( value );
633 if ( !state.isEmpty() )
634 text += ", " + Qtopia::escapeString( state );
635 }
636 else if ( !state.isEmpty() )
637 {
638 text += "<br>" + Qtopia::escapeString( state );
639 marker = true;
640 }
641 break;
642 }
643 case City_State_Zip:
644 { // City, State Zip_Code
645 state = homeState();
646 if ( !( value = homeCity() ).isEmpty() )
647 {
648 marker = true;
649 text += "<br>" + Qtopia::escapeString( value );
650 if ( state )
651 text += ", " + Qtopia::escapeString( state );
652 }
653 else if ( !state.isEmpty() )
654 {
655 text += "<br>" + Qtopia::escapeString( state );
656 marker = true;
657 }
658 if ( !( value = homeZip() ).isEmpty() )
659 {
660 text += " " + Qtopia::escapeString( value );
661 marker = true;
662 }
663 break;
664 }
665 }
666
667 if ( !( value = homeCountry() ).isEmpty() )
668 {
669 text += "<br>" + Qtopia::escapeString( value );
670 marker = true;
671 }
672
673 // rest of Home data
674 str = homeWebpage();
675 if ( !str.isEmpty() )
676 {
677 text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr( "Home Web Page: " ) + "</b>"
678 + Qtopia::escapeString( str );
679 marker = true;
680 }
681 str = homePhone();
682 if ( !str.isEmpty() )
683 {
684 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>"
685 + Qtopia::escapeString( str );
686 marker = true;
687 }
688 str = homeFax();
689 if ( !str.isEmpty() )
690 {
691 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>"
692 + Qtopia::escapeString( str );
693 marker = true;
694 }
695 str = homeMobile();
696 if ( !str.isEmpty() )
697 {
698 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>"
699 + Qtopia::escapeString( str );
700 marker = true;
701 }
702
703 if ( marker )
704 text += "<br><hr>";
705
706 // the rest...
707 str = emails();
708 if ( !str.isEmpty() && ( str != defEmail ) )
709 text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>"
710 + Qtopia::escapeString( str );
711 str = profession();
712 if ( !str.isEmpty() )
713 text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>"
714 + Qtopia::escapeString( str );
715 str = assistant();
716 if ( !str.isEmpty() )
717 text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>"
718 + Qtopia::escapeString( str );
719 str = manager();
720 if ( !str.isEmpty() )
721 text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>"
722 + Qtopia::escapeString( str );
723 str = gender();
724 if ( !str.isEmpty() && str.toInt() != 0 )
725 {
726 text += "<br>";
727 if ( str.toInt() == 1 )
728 str = QObject::tr( "Male" );
729 else if ( str.toInt() == 2 )
730 str = QObject::tr( "Female" );
731 text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str;
732 }
733 str = spouse();
734 if ( !str.isEmpty() )
735 text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>"
736 + Qtopia::escapeString( str );
737 if ( birthday().isValid() )
738 {
739 str = TimeString::numberDateString( birthday() );
740 text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>"
741 + Qtopia::escapeString( str );
742 }
743 if ( anniversary().isValid() )
744 {
745 str = TimeString::numberDateString( anniversary() );
746 text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>"
747 + Qtopia::escapeString( str );
748 }
749 str = children();
750 if ( !str.isEmpty() )
751 text += "<br><b>" + QObject::tr( "Children: " ) + "</b>"
752 + Qtopia::escapeString( str );
753
754 str = nickname();
755 if ( !str.isEmpty() )
756 text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>"
757 + Qtopia::escapeString( str );
758
759 // categories
760 if ( categoryNames( "Contacts" ).count() )
761 {
762 text += "<br><b>" + QObject::tr( "Category:" ) + "</b> ";
763 text += categoryNames( "Contacts" ).join( ", " );
764 }
765
766 // notes last
767 if ( !( value = notes() ).isEmpty() )
768 {
769 text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> ";
770 QRegExp reg( "\n" );
771
772 //QString tmp = Qtopia::escapeString(value);
773 QString tmp = QStyleSheet::convertFromPlainText( value );
774 //tmp.replace( reg, "<br>" );
775 text += "<br>" + tmp + "<br>";
776 }
777 return text;
778}
779
780/*!
781 \internal
782*/
783void OPimContact::insert( int key, const QString &v )
784{
785 QString value = v.stripWhiteSpace();
786 if ( value.isEmpty() )
787 mMap.remove( key );
788 else
789 mMap.insert( key, value );
790}
791
792/*!
793 \internal
794*/
795void OPimContact::replace( int key, const QString & v )
796{
797 QString value = v.stripWhiteSpace();
798 if ( value.isEmpty() )
799 mMap.remove( key );
800 else
801 mMap.replace( key, value );
802}
803
804/*!
805 \internal
806*/
807QString OPimContact::find( int key ) const
808{
809 return mMap[ key ];
810}
811
812/*!
813 \internal
814*/
815QString OPimContact::displayAddress( const QString &street,
816 const QString &city,
817 const QString &state,
818 const QString &zip,
819 const QString &country ) const
820{
821 QString s = street;
822 if ( !street.isEmpty() )
823 s += "\n";
824 s += city;
825 if ( !city.isEmpty() && !state.isEmpty() )
826 s += ", ";
827 s += state;
828 if ( !state.isEmpty() && !zip.isEmpty() )
829 s += " ";
830 s += zip;
831 if ( !country.isEmpty() && !s.isEmpty() )
832 s += "\n";
833 s += country;
834 return s;
835}
836
837/*!
838 \internal
839*/
840QString OPimContact::displayBusinessAddress() const
841{
842 return displayAddress( businessStreet(), businessCity(),
843 businessState(), businessZip(),
844 businessCountry() );
845}
846
847/*!
848 \internal
849*/
850QString OPimContact::displayHomeAddress() const
851{
852 return displayAddress( homeStreet(), homeCity(),
853 homeState(), homeZip(),
854 homeCountry() );
855}
856
857/*!
858 Returns the full name of the contact
859*/
860QString OPimContact::fullName() const
861{
862 QString title = find( Qtopia::Title );
863 QString firstName = find( Qtopia::FirstName );
864 QString middleName = find( Qtopia::MiddleName );
865 QString lastName = find( Qtopia::LastName );
866 QString suffix = find( Qtopia::Suffix );
867
868 QString name = title;
869 if ( !firstName.isEmpty() )
870 {
871 if ( !name.isEmpty() )
872 name += " ";
873 name += firstName;
874 }
875 if ( !middleName.isEmpty() )
876 {
877 if ( !name.isEmpty() )
878 name += " ";
879 name += middleName;
880 }
881 if ( !lastName.isEmpty() )
882 {
883 if ( !name.isEmpty() )
884 name += " ";
885 name += lastName;
886 }
887 if ( !suffix.isEmpty() )
888 {
889 if ( !name.isEmpty() )
890 name += " ";
891 name += suffix;
892 }
893 return name.simplifyWhiteSpace();
894}
895
896/*!
897 Returns a list of the names of the children of the contact.
898*/
899QStringList OPimContact::childrenList() const
900{
901 return QStringList::split( " ", find( Qtopia::Children ) );
902}
903
904/*! \fn void OPimContact::insertEmail( const QString &email )
905
906 Insert \a email into the email list. Ensures \a email can only be added
907 once. If there is no default email address set, it sets it to the \a email.
908*/
909
910/*! \fn void OPimContact::removeEmail( const QString &email )
911
912 Removes the \a email from the email list. If the default email was \a email,
913 then the default email address is assigned to the first email in the
914 email list
915*/
916
917/*! \fn void OPimContact::clearEmails()
918
919 Clears the email list.
920 */
921
922/*! \fn void OPimContact::insertEmails( const QStringList &emailList )
923
924 Appends the \a emailList to the exiting email list
925 */
926
927/*!
928 Returns a list of email addresses belonging to the contact, including
929 the default email address.
930*/
931QStringList OPimContact::emailList() const
932{
933 QString emailStr = emails();
934
935 QStringList r;
936 if ( !emailStr.isEmpty() )
937 {
938 qDebug( " emailstr " );
939 QStringList l = QStringList::split( emailSeparator(), emailStr );
940 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
941 r += ( *it ).simplifyWhiteSpace();
942 }
943
944 return r;
945}
946
947/*!
948 \overload
949
950 Generates the string for the contact to be filed as from the first,
951 middle and last name of the contact.
952*/
953void OPimContact::setFileAs()
954{
955 QString lastName, firstName, middleName, fileas;
956
957 lastName = find( Qtopia::LastName );
958 firstName = find( Qtopia::FirstName );
959 middleName = find( Qtopia::MiddleName );
960 if ( !lastName.isEmpty() && !firstName.isEmpty()
961 && !middleName.isEmpty() )
962 fileas = lastName + ", " + firstName + " " + middleName;
963 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
964 fileas = lastName + ", " + firstName;
965 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
966 !middleName.isEmpty() )
967 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
968 + middleName + ( middleName.isEmpty() ? "" : " " )
969 + lastName;
970
971 replace( Qtopia::FileAs, fileas );
972}
973
974/*!
975 \internal
976 Appends the contact information to \a buf.
977*/
978void OPimContact::save( QString &buf ) const
979{
980 static const QStringList SLFIELDS = fields();
981 // I'm expecting "<Contact " in front of this...
982 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
983 it != mMap.end(); ++it )
984 {
985 const QString &value = it.data();
986 int key = it.key();
987 if ( !value.isEmpty() )
988 {
989 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid )
990 continue;
991
992 key -= Qtopia::AddressCategory + 1;
993 buf += SLFIELDS[ key ];
994 buf += "=\"" + Qtopia::escapeString( value ) + "\" ";
995 }
996 }
997 buf += customToXml();
998 if ( categories().count() > 0 )
999 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
1000 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
1001 // You need to close this yourself
1002}
1003
1004
1005/*!
1006 \internal
1007 Returns the list of fields belonging to a contact
1008 Never change order of this list ! It has to be regarding
1009 enum AddressBookFields !!
1010*/
1011QStringList OPimContact::fields()
1012{
1013 QStringList list;
1014
1015 list.append( "Title" ); // Not Used!
1016 list.append( "FirstName" );
1017 list.append( "MiddleName" );
1018 list.append( "LastName" );
1019 list.append( "Suffix" );
1020 list.append( "FileAs" );
1021
1022 list.append( "JobTitle" );
1023 list.append( "Department" );
1024 list.append( "Company" );
1025 list.append( "BusinessPhone" );
1026 list.append( "BusinessFax" );
1027 list.append( "BusinessMobile" );
1028
1029 list.append( "DefaultEmail" );
1030 list.append( "Emails" );
1031
1032 list.append( "HomePhone" );
1033 list.append( "HomeFax" );
1034 list.append( "HomeMobile" );
1035
1036 list.append( "BusinessStreet" );
1037 list.append( "BusinessCity" );
1038 list.append( "BusinessState" );
1039 list.append( "BusinessZip" );
1040 list.append( "BusinessCountry" );
1041 list.append( "BusinessPager" );
1042 list.append( "BusinessWebPage" );
1043
1044 list.append( "Office" );
1045 list.append( "Profession" );
1046 list.append( "Assistant" );
1047 list.append( "Manager" );
1048
1049 list.append( "HomeStreet" );
1050 list.append( "HomeCity" );
1051 list.append( "HomeState" );
1052 list.append( "HomeZip" );
1053 list.append( "HomeCountry" );
1054 list.append( "HomeWebPage" );
1055
1056 list.append( "Spouse" );
1057 list.append( "Gender" );
1058 list.append( "Birthday" );
1059 list.append( "Anniversary" );
1060 list.append( "Nickname" );
1061 list.append( "Children" );
1062
1063 list.append( "Notes" );
1064 list.append( "Groups" );
1065
1066 return list;
1067}
1068
1069
1070/*!
1071 Sets the list of email address for contact to those contained in \a str.
1072 Email address should be separated by ';'s.
1073*/
1074void OPimContact::setEmails( const QString &str )
1075{
1076 replace( Qtopia::Emails, str );
1077 if ( str.isEmpty() )
1078 setDefaultEmail( QString::null );
1079}
1080
1081/*!
1082 Sets the list of children for the contact to those contained in \a str.
1083*/
1084void OPimContact::setChildren( const QString &str )
1085{
1086 replace( Qtopia::Children, str );
1087}
1088
1089/*!
1090 \overload
1091 Returns TRUE if the contact matches the regular expression \a regexp.
1092 Otherwise returns FALSE.
1093*/
1094bool OPimContact::match( const QRegExp &r ) const
1095{
1096 setLastHitField( -1 );
1097 bool match;
1098 match = false;
1099 QMap<int, QString>::ConstIterator it;
1100 for ( it = mMap.begin(); it != mMap.end(); ++it )
1101 {
1102 if ( ( *it ).find( r ) > -1 )
1103 {
1104 setLastHitField( it.key() );
1105 match = true;
1106 break;
1107 }
1108 }
1109 return match;
1110}
1111
1112
1113QString OPimContact::toShortText() const
1114{
1115 return ( fullName() );
1116}
1117
1118
1119QString OPimContact::type() const
1120{
1121 return QString::fromLatin1( "OPimContact" );
1122}
1123
1124
1125class QString OPimContact::recordField( int pos ) const
1126{
1127 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1128 return SLFIELDS[ pos ];
1129}
1130
1131// In future releases, we should store birthday and anniversary
1132// internally as QDate instead of QString !
1133// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1134
1135/*! \fn void OPimContact::setBirthday( const QDate& date )
1136 Sets the birthday for the contact to \a date. If date is null
1137 the current stored date will be removed.
1138*/
1139void OPimContact::setBirthday( const QDate &v )
1140{
1141 if ( v.isNull() )
1142 {
1143 qWarning( "Remove Birthday" );
1144 replace( Qtopia::Birthday, QString::null );
1145 return ;
1146 }
1147
1148 if ( v.isValid() )
1149 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1150
1151}
1152
1153
1154/*! \fn void OPimContact::setAnniversary( const QDate &date )
1155 Sets the anniversary of the contact to \a date. If date is
1156 null, the current stored date will be removed.
1157*/
1158void OPimContact::setAnniversary( const QDate &v )
1159{
1160 if ( v.isNull() )
1161 {
1162 qWarning( "Remove Anniversary" );
1163 replace( Qtopia::Anniversary, QString::null );
1164 return ;
1165 }
1166
1167 if ( v.isValid() )
1168 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1169}
1170
1171
1172/*! \fn QDate OPimContact::birthday() const
1173 Returns the birthday of the contact.
1174*/
1175QDate OPimContact::birthday() const
1176{
1177 QString str = find( Qtopia::Birthday );
1178 // qWarning ("Birthday %s", str.latin1() );
1179 if ( !str.isEmpty() )
1180 return OPimDateConversion::dateFromString ( str );
1181 else
1182 return QDate();
1183}
1184
1185
1186/*! \fn QDate OPimContact::anniversary() const
1187 Returns the anniversary of the contact.
1188*/
1189QDate OPimContact::anniversary() const
1190{
1191 QDate empty;
1192 QString str = find( Qtopia::Anniversary );
1193 // qWarning ("Anniversary %s", str.latin1() );
1194 if ( !str.isEmpty() )
1195 return OPimDateConversion::dateFromString ( str );
1196 else
1197 return empty;
1198}
1199
1200
1201void OPimContact::insertEmail( const QString &v )
1202{
1203 //qDebug("insertEmail %s", v.latin1());
1204 QString e = v.simplifyWhiteSpace();
1205 QString def = defaultEmail();
1206
1207 // if no default, set it as the default email and don't insert
1208 if ( def.isEmpty() )
1209 {
1210 setDefaultEmail( e ); // will insert into the list for us
1211 return ;
1212 }
1213
1214 // otherwise, insert assuming doesn't already exist
1215 QString emailsStr = find( Qtopia::Emails );
1216 if ( emailsStr.contains( e ) )
1217 return ;
1218 if ( !emailsStr.isEmpty() )
1219 emailsStr += emailSeparator();
1220 emailsStr += e;
1221 replace( Qtopia::Emails, emailsStr );
1222}
1223
1224
1225 void OPimContact::removeEmail( const QString &v )
1226{
1227 QString e = v.simplifyWhiteSpace();
1228 QString def = defaultEmail();
1229 QString emailsStr = find( Qtopia::Emails );
1230 QStringList emails = emailList();
1231
1232 // otherwise, must first contain it
1233 if ( !emailsStr.contains( e ) )
1234 return ;
1235
1236 // remove it
1237 //qDebug(" removing email from list %s", e.latin1());
1238 emails.remove( e );
1239 // reset the string
1240 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1241 replace( Qtopia::Emails, emailsStr );
1242
1243 // if default, then replace the default email with the first one
1244 if ( def == e )
1245 {
1246 //qDebug("removeEmail is default; setting new default");
1247 if ( !emails.count() )
1248 clearEmails();
1249 else // setDefaultEmail will remove e from the list
1250 setDefaultEmail( emails.first() );
1251 }
1252}
1253
1254
1255void OPimContact::clearEmails()
1256{
1257 mMap.remove( Qtopia::DefaultEmail );
1258 mMap.remove( Qtopia::Emails );
1259}
1260
1261
1262void OPimContact::setDefaultEmail( const QString &v )
1263{
1264 QString e = v.simplifyWhiteSpace();
1265
1266 //qDebug("OPimContact::setDefaultEmail %s", e.latin1());
1267 replace( Qtopia::DefaultEmail, e );
1268
1269 if ( !e.isEmpty() )
1270 insertEmail( e );
1271
1272}
1273
1274
1275void OPimContact::insertEmails( const QStringList &v )
1276{
1277 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1278 insertEmail( *it );
1279}
1280
1281
1282int OPimContact::rtti()
1283{
1284 return OPimResolver::AddressBook;
1285}
1286
1287
1288void OPimContact::setUid( int i )
1289{
1290 OPimRecord::setUid( i );
1291 replace( Qtopia::AddressUid , QString::number( i ) );
1292}
1293}
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
new file mode 100644
index 0000000..c08f7ed
--- a/dev/null
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -0,0 +1,256 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCONTACT_H
31#define OCONTACT_H
32
33/* OPIE */
34#include <opie2/opimrecord.h>
35#include <qpe/recordfields.h>
36
37/* QT */
38#include <qdatetime.h>
39#include <qstringlist.h>
40
41#if defined(QPC_TEMPLATEDLL)
42// MOC_SKIP_BEGIN
43QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
44// MOC_SKIP_END
45#endif
46
47namespace Opie
48{
49class OPimContactPrivate;
50
51/**
52 * OPimContact class represents a specialised PIM Record for contacts.
53 * It does store all kind of persopn related information.
54 *
55 * @short Contact Container
56 * @author TT, Stefan Eiler, Holger Freyther
57 */
58class QPC_EXPORT OPimContact : public OPimRecord
59{
60 friend class DataSet;
61
62 public:
63 OPimContact();
64 OPimContact( const QMap<int, QString> &fromMap );
65 virtual ~OPimContact();
66
67 enum DateFormat{
68 Zip_City_State = 0,
69 City_State_Zip
70 };
71
72 /*
73 * do we need to inline them
74 * if yes do we need to inline them this way?
75 * -zecke
76 */
77 void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
78 void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
79 void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
80 void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
81 void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
82 void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
83 void setFileAs();
84
85 // default email address
86 void setDefaultEmail( const QString &v );
87 // inserts email to list and ensure's doesn't already exist
88 void insertEmail( const QString &v );
89 void removeEmail( const QString &v );
90 void clearEmails();
91 void insertEmails( const QStringList &v );
92
93 // home
94 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
95 void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
96 void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
97 void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
98 void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
99 void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
100 void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
101 void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
102 void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
103
104 // business
105 void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
106 void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
107 void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
108 void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
109 void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
110 void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
111 void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
112 void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
113 void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
114 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
115 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
116 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
117 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
118 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
119 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
120 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
121 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
122
123 // personal
124 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
125 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
126 void setBirthday( const QDate &v );
127 void setAnniversary( const QDate &v );
128 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
129 void setChildren( const QString &v );
130
131 // other
132 void setNotes( const QString &v ) { replace( Qtopia::Notes, v ); }
133
134 virtual bool match( const QRegExp &regexp ) const;
135
136 // // custom
137 // void setCustomField( const QString &key, const QString &v )
138 // { replace(Custom- + key, v ); }
139
140 // name
141 QString fullName() const;
142 QString title() const { return find( Qtopia::Title ); }
143 QString firstName() const { return find( Qtopia::FirstName ); }
144 QString middleName() const { return find( Qtopia::MiddleName ); }
145 QString lastName() const { return find( Qtopia::LastName ); }
146 QString suffix() const { return find( Qtopia::Suffix ); }
147 QString fileAs() const { return find( Qtopia::FileAs ); }
148
149 // email
150 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
151 QStringList emailList() const;
152
153 // home
154 /*
155 * OPimAddress address(enum Location)const;
156 * would be some how nicer...
157 * -zecke
158 */
159 QString homeStreet() const { return find( Qtopia::HomeStreet ); }
160 QString homeCity() const { return find( Qtopia::HomeCity ); }
161 QString homeState() const { return find( Qtopia::HomeState ); }
162 QString homeZip() const { return find( Qtopia::HomeZip ); }
163 QString homeCountry() const { return find( Qtopia::HomeCountry ); }
164 QString homePhone() const { return find( Qtopia::HomePhone ); }
165 QString homeFax() const { return find( Qtopia::HomeFax ); }
166 QString homeMobile() const { return find( Qtopia::HomeMobile ); }
167 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
168 /** Multi line string containing all non-empty address info in the form
169 * Street
170 * City, State Zip
171 * Country
172 */
173 QString displayHomeAddress() const;
174
175 // business
176 QString company() const { return find( Qtopia::Company ); }
177 QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
178 QString businessCity() const { return find( Qtopia::BusinessCity ); }
179 QString businessState() const { return find( Qtopia::BusinessState ); }
180 QString businessZip() const { return find( Qtopia::BusinessZip ); }
181 QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
182 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
183 QString jobTitle() const { return find( Qtopia::JobTitle ); }
184 QString department() const { return find( Qtopia::Department ); }
185 QString office() const { return find( Qtopia::Office ); }
186 QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
187 QString businessFax() const { return find( Qtopia::BusinessFax ); }
188 QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
189 QString businessPager() const { return find( Qtopia::BusinessPager ); }
190 QString profession() const { return find( Qtopia::Profession ); }
191 QString assistant() const { return find( Qtopia::Assistant ); }
192 QString manager() const { return find( Qtopia::Manager ); }
193 /** Multi line string containing all non-empty address info in the form
194 * Street
195 * City, State Zip
196 * Country
197 */
198 QString displayBusinessAddress() const;
199
200 //personal
201 QString spouse() const { return find( Qtopia::Spouse ); }
202 QString gender() const { return find( Qtopia::Gender ); }
203 QDate birthday() const;
204 QDate anniversary() const;
205 QString nickname() const { return find( Qtopia::Nickname ); }
206 QString children() const { return find( Qtopia::Children ); }
207 QStringList childrenList() const;
208
209 // other
210 QString notes() const { return find( Qtopia::Notes ); }
211 QString groups() const { return find( Qtopia::Groups ); }
212 QStringList groupList() const;
213
214 QString toRichText() const;
215 QMap<int, QString> toMap() const;
216 QString field( int key ) const { return find( key ); }
217
218
219 void setUid( int i );
220
221 QString toShortText() const;
222 QString type() const;
223 class QString recordField( int ) const;
224
225 // Why private ? (eilers,se)
226 QString emailSeparator() const { return " "; }
227
228 // the emails should be seperated by a comma
229 void setEmails( const QString &v );
230 QString emails() const { return find( Qtopia::Emails ); }
231 static int rtti();
232
233 private:
234 // The XML Backend needs some access to the private functions
235 friend class OPimContactAccessBackend_XML;
236
237 void insert( int key, const QString &value );
238 void replace( int key, const QString &value );
239 QString find( int key ) const;
240 static QStringList fields();
241
242 void save( QString &buf ) const;
243
244 QString displayAddress( const QString &street,
245 const QString &city,
246 const QString &state,
247 const QString &zip,
248 const QString &country ) const;
249
250 QMap<int, QString> mMap;
251 OPimContactPrivate *d;
252};
253
254}
255
256#endif
diff --git a/libopie2/opiepim/core/opimcontactfields.cpp b/libopie2/opiepim/core/opimcontactfields.cpp
new file mode 100644
index 0000000..4b0ba3b
--- a/dev/null
+++ b/libopie2/opiepim/core/opimcontactfields.cpp
@@ -0,0 +1,518 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimcontactfields.h"
31
32/* OPIE */
33#include <opie2/opimcontact.h>
34#include <qpe/recordfields.h> // We should use our own enum in the future ..
35#include <qpe/config.h>
36
37/* QT */
38#include <qobject.h>
39#include <qstringlist.h>
40
41
42namespace Opie
43{
44/*!
45 \internal
46 Returns a list of personal field names for a contact.
47*/
48QStringList OPimContactFields::personalfields( bool sorted, bool translated )
49{
50 QStringList list;
51 QMap<int, QString> mapIdToStr;
52 if ( translated )
53 mapIdToStr = idToTrFields();
54 else
55 mapIdToStr = idToUntrFields();
56
57 list.append( mapIdToStr[ Qtopia::AddressUid ] );
58 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
59
60 list.append( mapIdToStr[ Qtopia::Title ] );
61 list.append( mapIdToStr[ Qtopia::FirstName ] );
62 list.append( mapIdToStr[ Qtopia::MiddleName ] );
63 list.append( mapIdToStr[ Qtopia::LastName ] );
64 list.append( mapIdToStr[ Qtopia::Suffix ] );
65 list.append( mapIdToStr[ Qtopia::FileAs ] );
66
67 list.append( mapIdToStr[ Qtopia::JobTitle ] );
68 list.append( mapIdToStr[ Qtopia::Department ] );
69 list.append( mapIdToStr[ Qtopia::Company ] );
70
71 list.append( mapIdToStr[ Qtopia::Notes ] );
72 list.append( mapIdToStr[ Qtopia::Groups ] );
73
74 if ( sorted ) list.sort();
75 return list;
76}
77
78/*!
79 \internal
80 Returns a list of details field names for a contact.
81*/
82QStringList OPimContactFields::detailsfields( bool sorted, bool translated )
83{
84 QStringList list;
85 QMap<int, QString> mapIdToStr;
86 if ( translated )
87 mapIdToStr = idToTrFields();
88 else
89 mapIdToStr = idToUntrFields();
90
91 list.append( mapIdToStr[ Qtopia::Office ] );
92 list.append( mapIdToStr[ Qtopia::Profession ] );
93 list.append( mapIdToStr[ Qtopia::Assistant ] );
94 list.append( mapIdToStr[ Qtopia::Manager ] );
95
96 list.append( mapIdToStr[ Qtopia::Spouse ] );
97 list.append( mapIdToStr[ Qtopia::Gender ] );
98 list.append( mapIdToStr[ Qtopia::Birthday ] );
99 list.append( mapIdToStr[ Qtopia::Anniversary ] );
100 list.append( mapIdToStr[ Qtopia::Nickname ] );
101 list.append( mapIdToStr[ Qtopia::Children ] );
102
103 if ( sorted ) list.sort();
104 return list;
105}
106
107/*!
108 \internal
109 Returns a list of phone field names for a contact.
110*/
111QStringList OPimContactFields::phonefields( bool sorted, bool translated )
112{
113 QStringList list;
114 QMap<int, QString> mapIdToStr;
115 if ( translated )
116 mapIdToStr = idToTrFields();
117 else
118 mapIdToStr = idToUntrFields();
119
120 list.append( mapIdToStr[ Qtopia::BusinessPhone ] );
121 list.append( mapIdToStr[ Qtopia::BusinessFax ] );
122 list.append( mapIdToStr[ Qtopia::BusinessMobile ] );
123 list.append( mapIdToStr[ Qtopia::BusinessPager ] );
124 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] );
125
126 list.append( mapIdToStr[ Qtopia::DefaultEmail ] );
127 list.append( mapIdToStr[ Qtopia::Emails ] );
128
129 list.append( mapIdToStr[ Qtopia::HomePhone ] );
130 list.append( mapIdToStr[ Qtopia::HomeFax ] );
131 list.append( mapIdToStr[ Qtopia::HomeMobile ] );
132 // list.append( mapIdToStr[Qtopia::HomePager] );
133 list.append( mapIdToStr[ Qtopia::HomeWebPage ] );
134
135 if ( sorted ) list.sort();
136
137 return list;
138}
139
140/*!
141 \internal
142 Returns a list of field names for a contact.
143*/
144QStringList OPimContactFields::fields( bool sorted, bool translated )
145{
146 QStringList list;
147 QMap<int, QString> mapIdToStr;
148 if ( translated )
149 mapIdToStr = idToTrFields();
150 else
151 mapIdToStr = idToUntrFields();
152
153 list += personalfields( sorted, translated );
154
155 list += phonefields( sorted, translated );
156
157 list.append( mapIdToStr[ Qtopia::BusinessStreet ] );
158 list.append( mapIdToStr[ Qtopia::BusinessCity ] );
159 list.append( mapIdToStr[ Qtopia::BusinessState ] );
160 list.append( mapIdToStr[ Qtopia::BusinessZip ] );
161 list.append( mapIdToStr[ Qtopia::BusinessCountry ] );
162
163 list.append( mapIdToStr[ Qtopia::HomeStreet ] );
164 list.append( mapIdToStr[ Qtopia::HomeCity ] );
165 list.append( mapIdToStr[ Qtopia::HomeState ] );
166 list.append( mapIdToStr[ Qtopia::HomeZip ] );
167 list.append( mapIdToStr[ Qtopia::HomeCountry ] );
168
169 list += detailsfields( sorted, translated );
170
171 if ( sorted ) list.sort();
172
173 return list;
174}
175
176
177/*!
178 \internal
179 Returns an untranslated list of personal field names for a contact.
180*/
181QStringList OPimContactFields::untrpersonalfields( bool sorted )
182{
183 return personalfields( sorted, false );
184}
185
186
187/*!
188 \internal
189 Returns a translated list of personal field names for a contact.
190*/
191QStringList OPimContactFields::trpersonalfields( bool sorted )
192{
193 return personalfields( sorted, true );
194}
195
196
197/*!
198 \internal
199 Returns an untranslated list of details field names for a contact.
200*/
201QStringList OPimContactFields::untrdetailsfields( bool sorted )
202{
203 return detailsfields( sorted, false );
204}
205
206
207/*!
208 \internal
209 Returns a translated list of details field names for a contact.
210*/
211QStringList OPimContactFields::trdetailsfields( bool sorted )
212{
213 return detailsfields( sorted, true );
214}
215
216
217/*!
218 \internal
219 Returns a translated list of phone field names for a contact.
220*/
221QStringList OPimContactFields::trphonefields( bool sorted )
222{
223 return phonefields( sorted, true );
224}
225
226/*!
227 \internal
228 Returns an untranslated list of phone field names for a contact.
229*/
230QStringList OPimContactFields::untrphonefields( bool sorted )
231{
232 return phonefields( sorted, false );
233}
234
235
236/*!
237 \internal
238 Returns a translated list of field names for a contact.
239*/
240QStringList OPimContactFields::trfields( bool sorted )
241{
242 return fields( sorted, true );
243}
244
245/*!
246 \internal
247 Returns an untranslated list of field names for a contact.
248*/
249QStringList OPimContactFields::untrfields( bool sorted )
250{
251 return fields( sorted, false );
252}
253
254QMap<int, QString> OPimContactFields::idToTrFields()
255{
256 QMap<int, QString> ret_map;
257
258 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
259 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
260
261 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) );
262 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
263 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
264 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
265 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) );
266 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
267
268 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
269 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
270 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
271 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
272 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
273 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) );
274
275 // email
276 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
277 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
278
279 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
280 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
281 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
282
283 // business
284 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
285 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
286 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
287 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
288 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
289 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
290 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
291
292 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
293 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
294 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
295 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
296
297 // home
298 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
299 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
300 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
301 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
302 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
303 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
304
305 //personal
306 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
307 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
308 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
309 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
310 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
311 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
312
313 // other
314 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
315
316
317 return ret_map;
318}
319
320QMap<int, QString> OPimContactFields::idToUntrFields()
321{
322 QMap<int, QString> ret_map;
323
324 ret_map.insert( Qtopia::AddressUid, "User Id" );
325 ret_map.insert( Qtopia::AddressCategory, "Categories" );
326
327 ret_map.insert( Qtopia::Title, "Name Title" );
328 ret_map.insert( Qtopia::FirstName, "First Name" );
329 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
330 ret_map.insert( Qtopia::LastName, "Last Name" );
331 ret_map.insert( Qtopia::Suffix, "Suffix" );
332 ret_map.insert( Qtopia::FileAs, "File As" );
333
334 ret_map.insert( Qtopia::JobTitle, "Job Title" );
335 ret_map.insert( Qtopia::Department, "Department" );
336 ret_map.insert( Qtopia::Company, "Company" );
337 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
338 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
339 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
340
341 // email
342 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
343 ret_map.insert( Qtopia::Emails, "Emails" );
344
345 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
346 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
347 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
348
349 // business
350 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
351 ret_map.insert( Qtopia::BusinessCity, "Business City" );
352 ret_map.insert( Qtopia::BusinessState, "Business State" );
353 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
354 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
355 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
356 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
357
358 ret_map.insert( Qtopia::Office, "Office" );
359 ret_map.insert( Qtopia::Profession, "Profession" );
360 ret_map.insert( Qtopia::Assistant, "Assistant" );
361 ret_map.insert( Qtopia::Manager, "Manager" );
362
363 // home
364 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
365 ret_map.insert( Qtopia::HomeCity, "Home City" );
366 ret_map.insert( Qtopia::HomeState, "Home State" );
367 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
368 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
369 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
370
371 //personal
372 ret_map.insert( Qtopia::Spouse, "Spouse" );
373 ret_map.insert( Qtopia::Gender, "Gender" );
374 ret_map.insert( Qtopia::Birthday, "Birthday" );
375 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
376 ret_map.insert( Qtopia::Nickname, "Nickname" );
377 ret_map.insert( Qtopia::Children, "Children" );
378
379 // other
380 ret_map.insert( Qtopia::Notes, "Notes" );
381 ret_map.insert( Qtopia::Groups, "Groups" );
382
383
384 return ret_map;
385}
386
387QMap<QString, int> OPimContactFields::trFieldsToId()
388{
389 QMap<int, QString> idtostr = idToTrFields();
390 QMap<QString, int> ret_map;
391
392
393 QMap<int, QString>::Iterator it;
394 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
395 ret_map.insert( *it, it.key() );
396
397
398 return ret_map;
399}
400
401/* ======================================================================= */
402
403QMap<QString, int> OPimContactFields::untrFieldsToId()
404{
405 QMap<int, QString> idtostr = idToUntrFields();
406 QMap<QString, int> ret_map;
407
408
409 QMap<int, QString>::Iterator it;
410 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
411 ret_map.insert( *it, it.key() );
412
413
414 return ret_map;
415}
416
417
418OPimContactFields::OPimContactFields() :
419 fieldOrder( DEFAULT_FIELD_ORDER ),
420 changedFieldOrder( false )
421{
422 // Get the global field order from the config file and
423 // use it as a start pattern
424 Config cfg ( "AddressBook" );
425 cfg.setGroup( "ContactFieldOrder" );
426 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
427}
428
429OPimContactFields::~OPimContactFields()
430{
431
432 // We will store the fieldorder into the config file
433 // to reuse it for the future..
434 if ( changedFieldOrder )
435 {
436 Config cfg ( "AddressBook" );
437 cfg.setGroup( "ContactFieldOrder" );
438 cfg.writeEntry( "General", globalFieldOrder );
439 }
440}
441
442
443
444void OPimContactFields::saveToRecord( OPimContact &cnt )
445{
446
447 qDebug( "ocontactfields saveToRecord: >%s<", fieldOrder.latin1() );
448
449 // Store fieldorder into this contact.
450 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
451
452 globalFieldOrder = fieldOrder;
453 changedFieldOrder = true;
454
455}
456
457void OPimContactFields::loadFromRecord( const OPimContact &cnt )
458{
459 qDebug( "ocontactfields loadFromRecord" );
460 qDebug( "loading >%s<", cnt.fullName().latin1() );
461
462 // Get fieldorder for this contact. If none is defined,
463 // we will use the global one from the config file..
464
465 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
466
467 qDebug( "fieldOrder from contact>%s<", fieldOrder.latin1() );
468
469 if ( fieldOrder.isEmpty() )
470 {
471 fieldOrder = globalFieldOrder;
472 }
473
474
475 qDebug( "effective fieldOrder in loadFromRecord >%s<", fieldOrder.latin1() );
476}
477
478void OPimContactFields::setFieldOrder( int num, int index )
479{
480 qDebug( "qcontactfields setfieldorder pos %i -> %i", num, index );
481
482 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ];
483
484 // We will store this new fieldorder globally to
485 // remember it for contacts which have none
486 globalFieldOrder = fieldOrder;
487 changedFieldOrder = true;
488
489 qDebug( "fieldOrder >%s<", fieldOrder.latin1() );
490}
491
492int OPimContactFields::getFieldOrder( int num, int defIndex )
493{
494 qDebug( "ocontactfields getFieldOrder" );
495 qDebug( "fieldOrder >%s<", fieldOrder.latin1() );
496
497 // Get index of combo as char..
498 QChar poschar = fieldOrder[ num ];
499
500 bool ok;
501 int ret = 0;
502 // Convert char to number..
503 if ( !( poschar == QChar::null ) )
504 ret = QString( poschar ).toInt( &ok, 16 );
505 else
506 ok = false;
507
508 // Return default value if index for
509 // num was not set or if anything else happened..
510 if ( !ok ) ret = defIndex;
511
512 qDebug( "returning >%i<", ret );
513
514 return ret;
515
516}
517
518}
diff --git a/libopie2/opiepim/core/opimcontactfields.h b/libopie2/opiepim/core/opimcontactfields.h
new file mode 100644
index 0000000..3aa3894
--- a/dev/null
+++ b/libopie2/opiepim/core/opimcontactfields.h
@@ -0,0 +1,102 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCONTACTFIELDS_H
31#define OCONTACTFIELDS_H
32
33class QStringList;
34
35/* OPIE */
36#include <opie2/opimcontact.h>
37
38/* QT */
39#include <qmap.h>
40#include <qstring.h>
41
42#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order"
43#define DEFAULT_FIELD_ORDER "__________"
44
45namespace Opie
46{
47class OPimContactFields
48{
49
50 public:
51 OPimContactFields();
52 ~OPimContactFields();
53 /** Set the index for combo boxes.
54 * Sets the <b>index</b> of combo <b>num</b>.
55 * @param num selects the number of the combo
56 * @param index sets the index in the combo
57 */
58 void setFieldOrder( int num, int index );
59
60 /** Get the index for combo boxes.
61 * Returns the index of combo <b>num</b> or defindex
62 * if none was defined..
63 * @param num Selects the number of the combo
64 * @param defIndex will be returned if none was defined (either
65 * globally in the config file, nor by the contact which was used
66 * by loadFromRecord() )
67 */
68 int getFieldOrder( int num, int defIndex );
69
70 /** Store fieldorder to contact. */
71 void saveToRecord( OPimContact& );
72 /** Get Fieldorder from contact. */
73 void loadFromRecord( const OPimContact& );
74
75 private:
76 QString fieldOrder;
77 QString globalFieldOrder;
78 bool changedFieldOrder;
79
80 public:
81 static QStringList personalfields( bool sorted = true, bool translated = false );
82 static QStringList phonefields( bool sorted = true, bool translated = false );
83 static QStringList detailsfields( bool sorted = true, bool translated = false );
84 static QStringList fields( bool sorted = true, bool translated = false );
85
86 static QStringList trpersonalfields( bool sorted = true );
87 static QStringList untrpersonalfields( bool sorted = true );
88 static QStringList trphonefields( bool sorted = true );
89 static QStringList untrphonefields( bool sorted = true );
90 static QStringList trdetailsfields( bool sorted = true );
91 static QStringList untrdetailsfields( bool sorted = true );
92 static QStringList trfields( bool sorted = true );
93 static QStringList untrfields( bool sorted = true );
94
95 static QMap<int, QString> idToTrFields();
96 static QMap<QString, int> trFieldsToId();
97 static QMap<int, QString> idToUntrFields();
98 static QMap<QString, int> untrFieldsToId();
99
100};
101}
102#endif
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/opimdateconversion.cpp
index 160c2c6..8bf891b 100644
--- a/libopie2/opiepim/core/oconversion.cpp
+++ b/libopie2/opiepim/core/opimdateconversion.cpp
@@ -27,13 +27,13 @@ _;:, .> :=|. This program is free software; you can
27*/ 27*/
28 28
29/* OPIE */ 29/* OPIE */
30#include <opie2/oconversion.h> 30#include <opie2/opimdateconversion.h>
31#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
32 32
33namespace Opie 33namespace Opie
34{ 34{
35 35
36QString OConversion::dateToString( const QDate &d ) 36QString OPimDateConversion::dateToString( const QDate &d )
37{ 37{
38 if ( d.isNull() || !d.isValid() ) 38 if ( d.isNull() || !d.isValid() )
39 return QString::null; 39 return QString::null;
@@ -52,7 +52,7 @@ QString OConversion::dateToString( const QDate &d )
52} 52}
53 53
54 54
55QDate OConversion::dateFromString( const QString& s ) 55QDate OPimDateConversion::dateFromString( const QString& s )
56{ 56{
57 QDate date; 57 QDate date;
58 58
@@ -99,7 +99,7 @@ QDate OConversion::dateFromString( const QString& s )
99} 99}
100 100
101 101
102QString OConversion::dateTimeToString( const QDateTime& dt ) 102QString OPimDateConversion::dateTimeToString( const QDateTime& dt )
103{ 103{
104 if ( !dt.isValid() || dt.isNull() ) 104 if ( !dt.isValid() || dt.isNull() )
105 return QString::null; 105 return QString::null;
@@ -122,7 +122,7 @@ QString OConversion::dateTimeToString( const QDateTime& dt )
122} 122}
123 123
124 124
125QDateTime OConversion::dateTimeFromString( const QString& str ) 125QDateTime OPimDateConversion::dateTimeFromString( const QString& str )
126{ 126{
127 127
128 if ( str.isEmpty() ) 128 if ( str.isEmpty() )
diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/opimdateconversion.h
index eeb97e5..45536da 100644
--- a/libopie2/opiepim/core/oconversion.h
+++ b/libopie2/opiepim/core/opimdateconversion.h
@@ -35,7 +35,7 @@
35 35
36namespace Opie { 36namespace Opie {
37 37
38class OConversion 38class OPimDateConversion
39{ 39{
40public: 40public:
41 static QString dateToString( const QDate &d ); 41 static QString dateToString( const QDate &d );
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
new file mode 100644
index 0000000..3ddbf85
--- a/dev/null
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -0,0 +1,1025 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimevent.h"
31
32/* OPIE */
33#include <opie2/opimrecurrence.h>
34#include <opie2/opimresolver.h>
35#include <opie2/opimnotifymanager.h>
36#include <qpe/categories.h>
37#include <qpe/palmtopuidgen.h>
38#include <qpe/stringutil.h>
39
40/* QT */
41#include <qshared.h>
42#include <qarray.h>
43
44namespace Opie
45{
46
47int OCalendarHelper::week( const QDate& date )
48{
49 // Calculates the week this date is in within that
50 // month. Equals the "row" is is in in the month view
51 int week = 1;
52 QDate tmp( date.year(), date.month(), 1 );
53 if ( date.dayOfWeek() < tmp.dayOfWeek() )
54 ++week;
55
56 week += ( date.day() - 1 ) / 7;
57
58 return week;
59}
60
61
62int OCalendarHelper::ocurrence( const QDate& date )
63{
64 // calculates the number of occurrances of this day of the
65 // week till the given date (e.g 3rd Wednesday of the month)
66 return ( date.day() - 1 ) / 7 + 1;
67}
68
69
70int OCalendarHelper::dayOfWeek( char day )
71{
72 int dayOfWeek = 1;
73 char i = OPimRecurrence::MON;
74 while ( !( i & day ) && i <= OPimRecurrence::SUN )
75 {
76 i <<= 1;
77 ++dayOfWeek;
78 }
79 return dayOfWeek;
80}
81
82
83int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
84{
85 return ( second.year() - first.year() ) * 12 +
86 second.month() - first.month();
87}
88
89
90struct OPimEvent::Data : public QShared
91{
92 Data() : QShared()
93 {
94 child = 0;
95 recur = 0;
96 manager = 0;
97 isAllDay = false;
98 parent = 0;
99 }
100 ~Data()
101 {
102 delete manager;
103 delete recur;
104 }
105 QString description;
106 QString location;
107 OPimNotifyManager* manager;
108 OPimRecurrence* recur;
109 QString note;
110 QDateTime created;
111 QDateTime start;
112 QDateTime end;
113bool isAllDay : 1;
114 QString timezone;
115 QArray<int>* child;
116 int parent;
117};
118
119
120OPimEvent::OPimEvent( int uid )
121 : OPimRecord( uid )
122{
123 data = new Data;
124}
125
126
127OPimEvent::OPimEvent( const OPimEvent& ev )
128 : OPimRecord( ev ), data( ev.data )
129{
130 data->ref();
131}
132
133
134OPimEvent::OPimEvent( const QMap<int, QString> map )
135 : OPimRecord( 0 )
136{
137 data = new Data;
138
139 fromMap( map );
140}
141
142
143OPimEvent::~OPimEvent()
144{
145 if ( data->deref() )
146 {
147 delete data;
148 data = 0;
149 }
150}
151
152
153OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
154{
155 if ( this == &ev ) return * this;
156
157 OPimRecord::operator=( ev );
158 ev.data->ref();
159 deref();
160 data = ev.data;
161
162
163 return *this;
164}
165
166
167QString OPimEvent::description() const
168{
169 return data->description;
170}
171
172
173void OPimEvent::setDescription( const QString& description )
174{
175 changeOrModify();
176 data->description = description;
177}
178
179
180void OPimEvent::setLocation( const QString& loc )
181{
182 changeOrModify();
183 data->location = loc;
184}
185
186
187QString OPimEvent::location() const
188{
189 return data->location;
190}
191
192
193OPimNotifyManager &OPimEvent::notifiers() const
194{
195 // I hope we can skip the changeOrModify here
196 // the notifier should take care of it
197 // and OPimNotify is shared too
198 if ( !data->manager )
199 data->manager = new OPimNotifyManager;
200
201 return *data->manager;
202}
203
204
205bool OPimEvent::hasNotifiers() const
206{
207 if ( !data->manager )
208 return false;
209 if ( data->manager->reminders().isEmpty() &&
210 data->manager->alarms().isEmpty() )
211 return false;
212
213 return true;
214}
215
216
217OPimRecurrence OPimEvent::recurrence() const
218{
219 if ( !data->recur )
220 data->recur = new OPimRecurrence;
221
222 return *data->recur;
223}
224
225
226void OPimEvent::setRecurrence( const OPimRecurrence& rec )
227{
228 changeOrModify();
229 if ( data->recur )
230 ( *data->recur ) = rec;
231 else
232 data->recur = new OPimRecurrence( rec );
233}
234
235
236bool OPimEvent::hasRecurrence() const
237{
238 if ( !data->recur ) return false;
239 return data->recur->doesRecur();
240}
241
242
243QString OPimEvent::note() const
244{
245 return data->note;
246}
247
248
249void OPimEvent::setNote( const QString& note )
250{
251 changeOrModify();
252 data->note = note;
253}
254
255
256QDateTime OPimEvent::createdDateTime() const
257{
258 return data->created;
259}
260
261
262void OPimEvent::setCreatedDateTime( const QDateTime& time )
263{
264 changeOrModify();
265 data->created = time;
266}
267
268
269QDateTime OPimEvent::startDateTime() const
270{
271 if ( data->isAllDay )
272 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
273 return data->start;
274}
275
276
277QDateTime OPimEvent::startDateTimeInZone() const
278{
279 /* if no timezone, or all day event or if the current and this timeZone match... */
280 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
281
282 OPimTimeZone zone( data->timezone );
283 return zone.toDateTime( data->start, OPimTimeZone::current() );
284}
285
286
287void OPimEvent::setStartDateTime( const QDateTime& dt )
288{
289 changeOrModify();
290 data->start = dt;
291}
292
293
294QDateTime OPimEvent::endDateTime() const
295{
296 /*
297 * if all Day event the end time needs
298 * to be on the same day as the start
299 */
300 if ( data->isAllDay )
301 return QDateTime( data->start.date(), QTime( 23, 59, 59 ) );
302 return data->end;
303}
304
305
306QDateTime OPimEvent::endDateTimeInZone() const
307{
308 /* if no timezone, or all day event or if the current and this timeZone match... */
309 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
310
311 OPimTimeZone zone( data->timezone );
312 return zone.toDateTime( data->end, OPimTimeZone::current() );
313}
314
315
316void OPimEvent::setEndDateTime( const QDateTime& dt )
317{
318 changeOrModify();
319 data->end = dt;
320}
321
322
323bool OPimEvent::isMultipleDay() const
324{
325 return data->end.date().day() - data->start.date().day();
326}
327
328
329bool OPimEvent::isAllDay() const
330{
331 return data->isAllDay;
332}
333
334
335void OPimEvent::setAllDay( bool allDay )
336{
337 changeOrModify();
338 data->isAllDay = allDay;
339 if ( allDay ) data->timezone = "UTC";
340}
341
342
343void OPimEvent::setTimeZone( const QString& tz )
344{
345 changeOrModify();
346 data->timezone = tz;
347}
348
349
350QString OPimEvent::timeZone() const
351{
352 if ( data->isAllDay ) return QString::fromLatin1( "UTC" );
353 return data->timezone;
354}
355
356
357bool OPimEvent::match( const QRegExp& re ) const
358{
359 if ( re.match( data->description ) != -1 )
360 {
361 setLastHitField( Qtopia::DatebookDescription );
362 return true;
363 }
364 if ( re.match( data->note ) != -1 )
365 {
366 setLastHitField( Qtopia::Note );
367 return true;
368 }
369 if ( re.match( data->location ) != -1 )
370 {
371 setLastHitField( Qtopia::Location );
372 return true;
373 }
374 if ( re.match( data->start.toString() ) != -1 )
375 {
376 setLastHitField( Qtopia::StartDateTime );
377 return true;
378 }
379 if ( re.match( data->end.toString() ) != -1 )
380 {
381 setLastHitField( Qtopia::EndDateTime );
382 return true;
383 }
384 return false;
385}
386
387
388QString OPimEvent::toRichText() const
389{
390 QString text, value;
391
392 // description
393 text += "<b><h3><img src=\"datebook/DateBook\">";
394 if ( !description().isEmpty() )
395 {
396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
397 }
398 text += "</h3></b><br><hr><br>";
399
400 // location
401 if ( !( value = location() ).isEmpty() )
402 {
403 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
404 text += Qtopia::escapeString( value ) + "<br>";
405 }
406
407 // all day event
408 if ( isAllDay() )
409 {
410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
411 }
412 // multiple day event
413 else if ( isMultipleDay () )
414 {
415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
416 }
417 // start & end times
418 else
419 {
420 // start time
421 if ( startDateTime().isValid() )
422 {
423 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
424 text += Qtopia::escapeString( startDateTime().toString() ).
425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
426 }
427
428 // end time
429 if ( endDateTime().isValid() )
430 {
431 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
432 text += Qtopia::escapeString( endDateTime().toString() ).
433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
434 }
435 }
436
437 // categories
438 if ( categoryNames( "Calendar" ).count() )
439 {
440 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
441 text += categoryNames( "Calendar" ).join( ", " );
442 text += "<br>";
443 }
444
445 //notes
446 if ( !note().isEmpty() )
447 {
448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
449 text += note();
450 // text += Qtopia::escapeString(note() ).
451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
452 }
453 return text;
454}
455
456
457QString OPimEvent::toShortText() const
458{
459 QString text;
460 text += QString::number( startDateTime().date().day() );
461 text += ".";
462 text += QString::number( startDateTime().date().month() );
463 text += ".";
464 text += QString::number( startDateTime().date().year() );
465 text += " ";
466 text += QString::number( startDateTime().time().hour() );
467 text += ":";
468 text += QString::number( startDateTime().time().minute() );
469 text += " - ";
470 text += description();
471 return text;
472}
473
474
475QString OPimEvent::type() const
476{
477 return QString::fromLatin1( "OPimEvent" );
478}
479
480
481QString OPimEvent::recordField( int /*id */ ) const
482{
483 return QString::null;
484}
485
486
487int OPimEvent::rtti()
488{
489 return OPimResolver::DateBook;
490}
491
492
493bool OPimEvent::loadFromStream( QDataStream& )
494{
495 return true;
496}
497
498
499bool OPimEvent::saveToStream( QDataStream& ) const
500{
501 return true;
502}
503
504
505void OPimEvent::changeOrModify()
506{
507 if ( data->count != 1 )
508 {
509 data->deref();
510 Data* d2 = new Data;
511 d2->description = data->description;
512 d2->location = data->location;
513
514 if ( data->manager )
515 d2->manager = new OPimNotifyManager( *data->manager );
516
517 if ( data->recur )
518 d2->recur = new OPimRecurrence( *data->recur );
519
520 d2->note = data->note;
521 d2->created = data->created;
522 d2->start = data->start;
523 d2->end = data->end;
524 d2->isAllDay = data->isAllDay;
525 d2->timezone = data->timezone;
526 d2->parent = data->parent;
527
528 if ( data->child )
529 {
530 d2->child = new QArray<int>( *data->child );
531 d2->child->detach();
532 }
533
534 data = d2;
535 }
536}
537
538
539void OPimEvent::deref()
540{
541 if ( data->deref() )
542 {
543 delete data;
544 data = 0;
545 }
546}
547// Exporting Event data to map. Using the same
548// encoding as ODateBookAccessBackend_xml does..
549// Thus, we could remove the stuff there and use this
550// for it and for all other places..
551// Encoding should happen at one place, only ! (eilers)
552QMap<int, QString> OPimEvent::toMap() const
553{
554 QMap<int, QString> retMap;
555
556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
561 OPimAlarm alarm = notifiers().alarms() [ 0 ];
562 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
563 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
564
565 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
566 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
567 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
568 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
569 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
570 if ( parent() )
571 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
572 if ( children().count() )
573 {
574 QArray<int> childr = children();
575 QString buf;
576 for ( uint i = 0; i < childr.count(); i++ )
577 {
578 if ( i != 0 ) buf += " ";
579 buf += QString::number( childr[ i ] );
580 }
581 retMap.insert( OPimEvent::FRecChildren, buf );
582 }
583
584 // Add recurrence stuff
585 if ( hasRecurrence() )
586 {
587 OPimRecurrence recur = recurrence();
588 QMap<int, QString> recFields = recur.toMap();
589 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
590 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
591 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
592 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
593 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
594 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
595 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
596 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
597 }
598 else
599 {
600 OPimRecurrence recur = recurrence();
601 QMap<int, QString> recFields = recur.toMap();
602 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
603 }
604
605 return retMap;
606}
607
608
609void OPimEvent::fromMap( const QMap<int, QString>& map )
610{
611
612 // We just want to set the UID if it is really stored.
613 if ( !map[ OPimEvent::FUid ].isEmpty() )
614 setUid( map[ OPimEvent::FUid ].toInt() );
615
616 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
617 setDescription( map[ OPimEvent::FDescription ] );
618 setLocation( map[ OPimEvent::FLocation ] );
619
620 if ( map[ OPimEvent::FType ] == "AllDay" )
621 setAllDay( true );
622 else
623 setAllDay( false );
624
625 int alarmTime = -1;
626 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
627 alarmTime = map[ OPimEvent::FAlarm ].toInt();
628
629 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
630 if ( ( alarmTime != -1 ) )
631 {
632 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
633 OPimAlarm al( sound , dt );
634 notifiers().add( al );
635 }
636 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
637 {
638 setTimeZone( map[ OPimEvent::FTimeZone ] );
639 }
640
641 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
642 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
643
644 /* AllDay is always in UTC */
645 if ( isAllDay() )
646 {
647 OPimTimeZone utc = OPimTimeZone::utc();
648 setStartDateTime( utc.fromUTCDateTime( start ) );
649 setEndDateTime ( utc.fromUTCDateTime( end ) );
650 setTimeZone( "UTC" ); // make sure it is really utc
651 }
652 else
653 {
654 /* to current date time */
655 // qWarning(" Start is %d", start );
656 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
657 QDateTime date = zone.toDateTime( start );
658 qWarning( " Start is %s", date.toString().latin1() );
659 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
660
661 date = zone.toDateTime( end );
662 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
663 }
664
665 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
666 setParent( map[ OPimEvent::FRecParent ].toInt() );
667
668 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
669 {
670 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
671 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
672 {
673 addChild( ( *it ).toInt() );
674 }
675 }
676
677 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
678 if ( !map[ OPimEvent::FRType ].isEmpty() )
679 {
680 QMap<int, QString> recFields;
681 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
682 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
683 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
684 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
685 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
686 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
687 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
688 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
689 OPimRecurrence recur( recFields );
690 setRecurrence( recur );
691 }
692
693}
694
695
696int OPimEvent::parent() const
697{
698 return data->parent;
699}
700
701
702void OPimEvent::setParent( int uid )
703{
704 changeOrModify();
705 data->parent = uid;
706}
707
708
709QArray<int> OPimEvent::children() const
710{
711 if ( !data->child ) return QArray<int>();
712 else
713 return data->child->copy();
714}
715
716
717void OPimEvent::setChildren( const QArray<int>& arr )
718{
719 changeOrModify();
720 if ( data->child ) delete data->child;
721
722 data->child = new QArray<int>( arr );
723 data->child->detach();
724}
725
726
727void OPimEvent::addChild( int uid )
728{
729 changeOrModify();
730 if ( !data->child )
731 {
732 data->child = new QArray<int>( 1 );
733 ( *data->child ) [ 0 ] = uid;
734 }
735 else
736 {
737 int count = data->child->count();
738 data->child->resize( count + 1 );
739 ( *data->child ) [ count ] = uid;
740 }
741}
742
743
744void OPimEvent::removeChild( int uid )
745{
746 if ( !data->child || !data->child->contains( uid ) ) return ;
747 changeOrModify();
748 QArray<int> newAr( data->child->count() - 1 );
749 int j = 0;
750 uint count = data->child->count();
751 for ( uint i = 0; i < count; i++ )
752 {
753 if ( ( *data->child ) [ i ] != uid )
754 {
755 newAr[ j ] = ( *data->child ) [ i ];
756 j++;
757 }
758 }
759 ( *data->child ) = newAr;
760}
761
762
763struct OEffectiveEvent::Data : public QShared
764{
765 Data() : QShared()
766 {}
767 OPimEvent event;
768 QDate date;
769 QTime start, end;
770 QDate startDate, endDate;
771bool dates : 1;
772};
773
774
775OEffectiveEvent::OEffectiveEvent()
776{
777 data = new Data;
778 data->date = QDate::currentDate();
779 data->start = data->end = QTime::currentTime();
780 data->dates = false;
781}
782
783
784OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
785 Position pos )
786{
787 data = new Data;
788 data->event = ev;
789 data->date = startDate;
790 if ( pos & Start )
791 data->start = ev.startDateTime().time();
792 else
793 data->start = QTime( 0, 0, 0 );
794
795 if ( pos & End )
796 data->end = ev.endDateTime().time();
797 else
798 data->end = QTime( 23, 59, 59 );
799
800 data->dates = false;
801}
802
803
804OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
805{
806 data = ev.data;
807 data->ref();
808}
809
810
811OEffectiveEvent::~OEffectiveEvent()
812{
813 if ( data->deref() )
814 {
815 delete data;
816 data = 0;
817 }
818}
819
820
821OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
822{
823 if ( *this == ev ) return * this;
824
825 ev.data->ref();
826 deref();
827 data = ev.data;
828
829 return *this;
830}
831
832
833void OEffectiveEvent::setStartTime( const QTime& ti )
834{
835 changeOrModify();
836 data->start = ti;
837}
838
839
840void OEffectiveEvent::setEndTime( const QTime& en )
841{
842 changeOrModify();
843 data->end = en;
844}
845
846
847void OEffectiveEvent::setEvent( const OPimEvent& ev )
848{
849 changeOrModify();
850 data->event = ev;
851}
852
853
854void OEffectiveEvent::setDate( const QDate& da )
855{
856 changeOrModify();
857 data->date = da;
858}
859
860
861void OEffectiveEvent::setEffectiveDates( const QDate& from,
862 const QDate& to )
863{
864 if ( !from.isValid() )
865 {
866 data->dates = false;
867 return ;
868 }
869
870 data->startDate = from;
871 data->endDate = to;
872}
873
874
875QString OEffectiveEvent::description() const
876{
877 return data->event.description();
878}
879
880
881QString OEffectiveEvent::location() const
882{
883 return data->event.location();
884}
885
886
887QString OEffectiveEvent::note() const
888{
889 return data->event.note();
890}
891
892
893OPimEvent OEffectiveEvent::event() const
894{
895 return data->event;
896}
897
898
899QTime OEffectiveEvent::startTime() const
900{
901 return data->start;
902}
903
904
905QTime OEffectiveEvent::endTime() const
906{
907 return data->end;
908}
909
910
911QDate OEffectiveEvent::date() const
912{
913 return data->date;
914}
915
916
917int OEffectiveEvent::length() const
918{
919 return ( data->end.hour() * 60 - data->start.hour() * 60 )
920 + QABS( data->start.minute() - data->end.minute() );
921}
922
923
924int OEffectiveEvent::size() const
925{
926 return ( data->end.hour() - data->start.hour() ) * 3600
927 + ( data->end.minute() - data->start.minute() * 60
928 + data->end.second() - data->start.second() );
929}
930
931
932QDate OEffectiveEvent::startDate() const
933{
934 if ( data->dates )
935 return data->startDate;
936 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
937 return data->date;
938 else
939 return data->event.startDateTime().date();
940}
941
942
943QDate OEffectiveEvent::endDate() const
944{
945 if ( data->dates )
946 return data->endDate;
947 else if ( data->event.hasRecurrence() )
948 return data->date;
949 else
950 return data->event.endDateTime().date();
951}
952
953
954void OEffectiveEvent::deref()
955{
956 if ( data->deref() )
957 {
958 delete data;
959 data = 0;
960 }
961}
962
963
964void OEffectiveEvent::changeOrModify()
965{
966 if ( data->count != 1 )
967 {
968 data->deref();
969 Data* d2 = new Data;
970 d2->event = data->event;
971 d2->date = data->date;
972 d2->start = data->start;
973 d2->end = data->end;
974 d2->startDate = data->startDate;
975 d2->endDate = data->endDate;
976 d2->dates = data->dates;
977 data = d2;
978 }
979}
980
981
982bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const
983{
984 if ( data->date < e.date() )
985 return TRUE;
986 if ( data->date == e.date() )
987 return ( startTime() < e.startTime() );
988 else
989 return FALSE;
990}
991
992
993bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const
994{
995 return ( data->date <= e.date() );
996}
997
998
999bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const
1000{
1001 return ( date() == e.date()
1002 && startTime() == e.startTime()
1003 && endTime() == e.endTime()
1004 && event() == e.event() );
1005}
1006
1007
1008bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const
1009{
1010 return !( *this == e );
1011}
1012
1013
1014bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const
1015{
1016 return !( *this <= e );
1017}
1018
1019
1020bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const
1021{
1022 return !( *this < e );
1023}
1024
1025}
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h
new file mode 100644
index 0000000..949f263
--- a/dev/null
+++ b/libopie2/opiepim/core/opimevent.h
@@ -0,0 +1,275 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29// CONTAINS GPLed code of TT
30
31#ifndef OEVENT_H
32#define OEVENT_H
33
34/* OPIE */
35#include <opie2/opimtimezone.h>
36#include <opie2/opimrecord.h>
37#include <qpe/recordfields.h>
38#include <qpe/palmtopuidgen.h>
39
40/* QT */
41#include <qstring.h>
42#include <qdatetime.h>
43#include <qvaluelist.h>
44
45namespace Opie
46{
47struct OCalendarHelper
48{
49 /** calculate the week number of the date */
50 static int week( const QDate& );
51 /** calculate the occurence of week days since the start of the month */
52 static int ocurrence( const QDate& );
53
54 // returns the dayOfWeek for the *first* day it finds (ignores
55 // any further days!). Returns 1 (Monday) if there isn't any day found
56 static int dayOfWeek( char day );
57
58 /** returns the diff of month */
59 static int monthDiff( const QDate& first, const QDate& second );
60
61};
62
63class OPimNotifyManager;
64class OPimRecurrence;
65
66/**
67 * This is the container for all Events. It encapsules all
68 * available information for a single Event
69 * @short container for events.
70 */
71class OPimEvent : public OPimRecord
72{
73 public:
74 typedef QValueList<OPimEvent> ValueList;
75 /**
76 * RecordFields contain possible attributes
77 * used in the Results of toMap()..
78 */
79 enum RecordFields {
80 FUid = Qtopia::UID_ID,
81 FCategories = Qtopia::CATEGORY_ID,
82 FDescription = 0,
83 FLocation,
84 FType,
85 FAlarm,
86 FSound,
87 FRType,
88 FRWeekdays,
89 FRPosition,
90 FRFreq,
91 FRHasEndDate,
92 FREndDate,
93 FRCreated,
94 FRExceptions,
95 FStart,
96 FEnd,
97 FNote,
98 FTimeZone,
99 FRecParent,
100 FRecChildren,
101 };
102
103 /**
104 * Start with an Empty OPimEvent. UID == 0 means that it is empty
105 */
106 OPimEvent( int uid = 0 );
107
108 /**
109 * copy c'tor
110 */
111 OPimEvent( const OPimEvent& );
112
113 /**
114 * Create OPimEvent, initialized by map
115 * @see enum RecordFields
116 */
117 OPimEvent( const QMap<int, QString> map );
118 ~OPimEvent();
119 OPimEvent &operator=( const OPimEvent& );
120
121 QString description() const;
122 void setDescription( const QString& description );
123
124 QString location() const;
125 void setLocation( const QString& loc );
126
127 bool hasNotifiers() const;
128 OPimNotifyManager &notifiers() const;
129
130 OPimRecurrence recurrence() const;
131 void setRecurrence( const OPimRecurrence& );
132 bool hasRecurrence() const;
133
134 QString note() const;
135 void setNote( const QString& note );
136
137
138 QDateTime createdDateTime() const;
139 void setCreatedDateTime( const QDateTime& dt );
140
141 /** set the date to dt. dt is the QDateTime in localtime */
142 void setStartDateTime( const QDateTime& );
143 /** returns the datetime in the local timeZone */
144 QDateTime startDateTime() const;
145
146 /** returns the start datetime in the current zone */
147 QDateTime startDateTimeInZone() const;
148
149 /** in current timezone */
150 void setEndDateTime( const QDateTime& );
151 /** in current timezone */
152 QDateTime endDateTime() const;
153 QDateTime endDateTimeInZone() const;
154
155 bool isMultipleDay() const;
156 bool isAllDay() const;
157 void setAllDay( bool isAllDay );
158
159 /* pin this event to a timezone! FIXME */
160 void setTimeZone( const QString& timeZone );
161 QString timeZone() const;
162
163
164 virtual bool match( const QRegExp& ) const;
165
166 /** For exception to recurrence here is a list of children... */
167 QArray<int> children() const;
168 void setChildren( const QArray<int>& );
169 void addChild( int uid );
170 void removeChild( int uid );
171
172 /** return the parent OPimEvent */
173 int parent() const;
174 void setParent( int uid );
175
176
177 /* needed reimp */
178 QString toRichText() const;
179 QString toShortText() const;
180 QString type() const;
181
182 QMap<int, QString> toMap() const;
183 void fromMap( const QMap<int, QString>& map );
184 QString recordField( int ) const;
185
186 static int rtti();
187
188 bool loadFromStream( QDataStream& );
189 bool saveToStream( QDataStream& ) const;
190
191 /* bool operator==( const OPimEvent& );
192 bool operator!=( const OPimEvent& );
193 bool operator<( const OPimEvent& );
194 bool operator<=( const OPimEvent& );
195 bool operator>( const OPimEvent& );
196 bool operator>=(const OPimEvent& );
197 */
198
199 private:
200 inline void changeOrModify();
201 void deref();
202 struct Data;
203 Data* data;
204 class Private;
205 Private* priv;
206
207};
208
209/**
210 * AN Event can span through multiple days. We split up a multiday eve
211 */
212class OEffectiveEvent
213{
214
215 public:
216 typedef QValueList<OEffectiveEvent> ValueList;
217 enum Position { MidWay, Start, End, StartEnd };
218 // If we calculate the effective event of a multi-day event
219 // we have to figure out whether we are at the first day,
220 // at the end, or anywhere else ("middle"). This is important
221 // for the start/end times (00:00/23:59)
222 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
223 // day event
224 // Start: start time -> 23:59
225 // End: 00:00 -> end time
226 // Start | End == StartEnd: for single-day events (default)
227 // here we draw start time -> end time
228 OEffectiveEvent();
229 OEffectiveEvent( const OPimEvent& event, const QDate& startDate, Position pos = StartEnd );
230 OEffectiveEvent( const OEffectiveEvent& );
231 OEffectiveEvent &operator=( const OEffectiveEvent& );
232 ~OEffectiveEvent();
233
234 void setStartTime( const QTime& );
235 void setEndTime( const QTime& );
236 void setEvent( const OPimEvent& );
237 void setDate( const QDate& );
238
239 void setEffectiveDates( const QDate& from, const QDate& to );
240
241 QString description() const;
242 QString location() const;
243 QString note() const;
244 OPimEvent event() const;
245 QTime startTime() const;
246 QTime endTime() const;
247 QDate date() const;
248
249 /* return the length in hours */
250 int length() const;
251 int size() const;
252
253 QDate startDate() const;
254 QDate endDate() const;
255
256 bool operator<( const OEffectiveEvent &e ) const;
257 bool operator<=( const OEffectiveEvent &e ) const;
258 bool operator==( const OEffectiveEvent &e ) const;
259 bool operator!=( const OEffectiveEvent &e ) const;
260 bool operator>( const OEffectiveEvent &e ) const;
261 bool operator>= ( const OEffectiveEvent &e ) const;
262
263 private:
264 void deref();
265 inline void changeOrModify();
266 class Private;
267 Private* priv;
268 struct Data;
269 Data* data;
270
271};
272
273}
274
275#endif
diff --git a/libopie2/opiepim/core/opimnotify.h b/libopie2/opiepim/core/opimnotify.h
index d0e40ca..4f74d2e 100644
--- a/libopie2/opiepim/core/opimnotify.h
+++ b/libopie2/opiepim/core/opimnotify.h
@@ -138,7 +138,7 @@ class OPimAlarm : public OPimNotify
138 * A Reminder will be put into the 138 * A Reminder will be put into the
139 * datebook 139 * datebook
140 * Note that the returned dateTime() may be not valid. 140 * Note that the returned dateTime() may be not valid.
141 * In these cases one must resolve the uid and get the OEvent 141 * In these cases one must resolve the uid and get the OPimEvent
142 */ 142 */
143class OPimReminder : public OPimNotify 143class OPimReminder : public OPimNotify
144{ 144{
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index a54d597..573340a 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -30,7 +30,7 @@
30#include "opimnotifymanager.h" 30#include "opimnotifymanager.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/oconversion.h> 33#include <opie2/opimdateconversion.h>
34 34
35/* QT */ 35/* QT */
36#include <qstringlist.h> 36#include <qstringlist.h>
@@ -184,7 +184,7 @@ QString OPimNotifyManager::alarmsToString() const
184 /* only if time is valid */ 184 /* only if time is valid */
185 if ( ( *it ).dateTime().isValid() ) 185 if ( ( *it ).dateTime().isValid() )
186 { 186 {
187 als << OConversion::dateTimeToString( ( *it ).dateTime() ) 187 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() )
188 + ":" + QString::number( ( *it ).duration() ) 188 + ":" + QString::number( ( *it ).duration() )
189 + ":" + QString::number( ( *it ).sound() ) 189 + ":" + QString::number( ( *it ).sound() )
190 + ":"; 190 + ":";
@@ -227,8 +227,8 @@ void OPimNotifyManager::alarmsFromString( const QString& str )
227 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 227 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
228 qWarning( "alarm: %s", alarm.join( "___" ).latin1() ); 228 qWarning( "alarm: %s", alarm.join( "___" ).latin1() );
229 qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(), 229 qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(),
230 OConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() ); 230 OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() );
231 OPimAlarm al( alarm[ 2 ].toInt(), OConversion::dateTimeFromString( alarm[ 0 ] ), 231 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
232 alarm[ 1 ].toInt() ); 232 alarm[ 1 ].toInt() );
233 add( al ); 233 add( al );
234 } 234 }
diff --git a/libopie2/opiepim/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h
new file mode 100644
index 0000000..b23138d
--- a/dev/null
+++ b/libopie2/opiepim/core/opimrecordlist.h
@@ -0,0 +1,402 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef ORECORDLIST_H
31#define ORECORDLIST_H
32
33/* OPIE */
34#include <opie2/opimtemplatebase.h>
35#include <opie2/opimrecord.h>
36
37/* QT */
38#include <qarray.h>
39
40namespace Opie
41{
42
43class OPimRecordListIteratorPrivate;
44/**
45 * Our List Iterator
46 * it behaves like STL or Qt
47 *
48 * for(it = list.begin(); it != list.end(); ++it )
49 * doSomeCoolStuff( (*it) );
50 */
51template <class T> class OPimRecordList;
52template <class T = OPimRecord>
53class OPimRecordListIterator
54{
55 friend class OPimRecordList<T>;
56
57 public:
58 typedef OTemplateBase<T> Base;
59
60 /**
61 * The c'tor used internally from
62 * OPimRecordList
63 */
64 OPimRecordListIterator( const QArray<int>, const Base* );
65
66 /**
67 * The standard c'tor
68 */
69 OPimRecordListIterator();
70 ~OPimRecordListIterator();
71
72 OPimRecordListIterator( const OPimRecordListIterator& );
73 OPimRecordListIterator &operator=( const OPimRecordListIterator& );
74
75 /**
76 * a * operator ;)
77 * use it like this T = (*it);
78 */
79 T operator*();
80 OPimRecordListIterator &operator++();
81 OPimRecordListIterator &operator--();
82
83 bool operator==( const OPimRecordListIterator& it );
84 bool operator!=( const OPimRecordListIterator& it );
85
86 /**
87 * the current item
88 */
89 uint current() const;
90
91 /**
92 * the number of items
93 */
94 uint count() const;
95
96 /**
97 * sets the current item
98 */
99 void setCurrent( uint cur );
100
101 private:
102 QArray<int> m_uids;
103 uint m_current;
104 const Base* m_temp;
105 bool m_end : 1;
106 T m_record;
107 bool m_direction : 1;
108
109 /* d pointer for future versions */
110 OPimRecordListIteratorPrivate *d;
111};
112
113
114class OPimRecordListPrivate;
115/**
116 * The recordlist used as a return type
117 * from OPimAccessTemplate
118 */
119template <class T = OPimRecord >
120class OPimRecordList
121{
122 public:
123 typedef OTemplateBase<T> Base;
124 typedef OPimRecordListIterator<T> Iterator;
125
126 /**
127 * c'tor
128 */
129 OPimRecordList ()
130 {}
131 OPimRecordList( const QArray<int>& ids,
132 const Base* );
133 ~OPimRecordList();
134
135 /**
136 * the first iterator
137 */
138 Iterator begin();
139
140 /**
141 * the end
142 */
143 Iterator end();
144
145 /**
146 * the number of items in the list
147 */
148 uint count() const;
149
150 T operator[] ( uint i );
151 int uidAt( uint i );
152
153 /**
154 * Remove the contact with given uid
155 */
156 bool remove( int uid );
157
158 /*
159 ConstIterator begin()const;
160 ConstIterator end()const;
161 */
162 private:
163 QArray<int> m_ids;
164 const Base* m_acc;
165 OPimRecordListPrivate *d;
166};
167
168
169/* ok now implement it */
170template <class T>
171OPimRecordListIterator<T>::OPimRecordListIterator()
172{
173 m_current = 0;
174 m_temp = 0l;
175 m_end = true;
176 m_record = T();
177 /* forward */
178 m_direction = TRUE;
179}
180
181
182template <class T>
183OPimRecordListIterator<T>::~OPimRecordListIterator()
184{
185 /* nothing to delete */
186}
187
188
189template <class T>
190OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it )
191{
192 // qWarning("OPimRecordListIterator copy c'tor");
193 m_uids = it.m_uids;
194 m_current = it.m_current;
195 m_temp = it.m_temp;
196 m_end = it.m_end;
197 m_record = it.m_record;
198 m_direction = it.m_direction;
199}
200
201
202template <class T>
203OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it )
204{
205 m_uids = it.m_uids;
206 m_current = it.m_current;
207 m_temp = it.m_temp;
208 m_end = it.m_end;
209 m_record = it.m_record;
210
211 return *this;
212}
213
214
215template <class T>
216T OPimRecordListIterator<T>::operator*()
217{
218 //qWarning("operator* %d %d", m_current, m_uids[m_current] );
219 if ( !m_end )
220 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current,
221 m_direction ? Base::Forward :
222 Base::Reverse );
223 else
224 m_record = T();
225
226 return m_record;
227}
228
229
230template <class T>
231OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++()
232{
233 m_direction = true;
234 if ( m_current < m_uids.count() )
235 {
236 m_end = false;
237 ++m_current;
238 }
239 else
240 m_end = true;
241
242 return *this;
243}
244
245
246template <class T>
247OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--()
248{
249 m_direction = false;
250 if ( m_current > 0 )
251 {
252 --m_current;
253 m_end = false;
254 }
255 else
256 m_end = true;
257
258 return *this;
259}
260
261
262template <class T>
263bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it )
264{
265
266 /* if both are at we're the same.... */
267 if ( m_end == it.m_end ) return true;
268
269 if ( m_uids != it.m_uids ) return false;
270 if ( m_current != it.m_current ) return false;
271 if ( m_temp != it.m_temp ) return false;
272
273 return true;
274}
275
276
277template <class T>
278bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it )
279{
280 return !( *this == it );
281}
282
283
284template <class T>
285OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids,
286 const Base* t )
287 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
288 m_direction( false )
289{
290 /* if the list is empty we're already at the end of the list */
291 if ( uids.count() == 0 )
292 m_end = true;
293}
294
295
296template <class T>
297uint OPimRecordListIterator<T>::current() const
298{
299 return m_current;
300}
301
302
303template <class T>
304void OPimRecordListIterator<T>::setCurrent( uint cur )
305{
306 if ( cur < m_uids.count() )
307 {
308 m_end = false;
309 m_current = cur;
310 }
311}
312template <class T>
313uint OPimRecordListIterator<T>::count() const
314{
315 return m_uids.count();
316}
317
318
319template <class T>
320OPimRecordList<T>::OPimRecordList( const QArray<int>& ids,
321 const Base* acc )
322 : m_ids( ids ), m_acc( acc )
323{}
324
325
326template <class T>
327OPimRecordList<T>::~OPimRecordList()
328{
329 /* nothing to do here */
330}
331
332
333template <class T>
334typename OPimRecordList<T>::Iterator OPimRecordList<T>::begin()
335{
336 Iterator it( m_ids, m_acc );
337 return it;
338}
339
340
341template <class T>
342typename OPimRecordList<T>::Iterator OPimRecordList<T>::end()
343{
344 Iterator it( m_ids, m_acc );
345 it.m_end = true;
346 it.m_current = m_ids.count();
347
348 return it;
349}
350
351
352template <class T>
353uint OPimRecordList<T>::count() const
354{
355 return m_ids.count();
356}
357
358
359template <class T>
360T OPimRecordList<T>::operator[] ( uint i )
361{
362 if ( i >= m_ids.count() )
363 return T();
364 /* forward */
365 return m_acc->find( m_ids[ i ], m_ids, i );
366}
367
368
369template <class T>
370int OPimRecordList<T>::uidAt( uint i )
371{
372 return m_ids[ i ];
373}
374
375
376template <class T>
377bool OPimRecordList<T>::remove( int uid )
378{
379 QArray<int> copy( m_ids.count() );
380 int counter = 0;
381 bool ret_val = false;
382
383 for ( uint i = 0; i < m_ids.count(); i++ )
384 {
385 if ( m_ids[ i ] != uid )
386 {
387 copy[ counter++ ] = m_ids[ i ];
388
389 }
390 else
391 ret_val = true;
392 }
393
394 copy.resize( counter );
395 m_ids = copy;
396
397
398 return ret_val;
399}
400
401}
402#endif
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/opimrecurrence.cpp
index 5e2da25..98bd647 100644
--- a/libopie2/opiepim/core/orecur.cpp
+++ b/libopie2/opiepim/core/opimrecurrence.cpp
@@ -27,10 +27,10 @@
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "orecur.h" 30#include "opimrecurrence.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/otimezone.h> 33#include <opie2/opimtimezone.h>
34#include <qpe/timeconversion.h> 34#include <qpe/timeconversion.h>
35 35
36/* QT */ 36/* QT */
@@ -41,9 +41,9 @@
41 41
42namespace Opie { 42namespace Opie {
43 43
44struct ORecur::Data : public QShared { 44struct OPimRecurrence::Data : public QShared {
45 Data() : QShared() { 45 Data() : QShared() {
46 type = ORecur::NoRepeat; 46 type = OPimRecurrence::NoRepeat;
47 freq = -1; 47 freq = -1;
48 days = 0; 48 days = 0;
49 pos = 0; 49 pos = 0;
@@ -52,7 +52,7 @@ struct ORecur::Data : public QShared {
52 end = QDate::currentDate(); 52 end = QDate::currentDate();
53 } 53 }
54 char days; // Q_UINT8 for 8 seven days;) 54 char days; // Q_UINT8 for 8 seven days;)
55 ORecur::RepeatType type; 55 OPimRecurrence::RepeatType type;
56 int freq; 56 int freq;
57 int pos; 57 int pos;
58 bool hasEnd : 1; 58 bool hasEnd : 1;
@@ -65,25 +65,25 @@ struct ORecur::Data : public QShared {
65}; 65};
66 66
67 67
68ORecur::ORecur() { 68OPimRecurrence::OPimRecurrence() {
69 data = new Data; 69 data = new Data;
70} 70}
71 71
72ORecur::ORecur( const QMap<int, QString>& map ) 72OPimRecurrence::OPimRecurrence( const QMap<int, QString>& map )
73{ 73{
74 ORecur(); 74 OPimRecurrence();
75 fromMap( map ); 75 fromMap( map );
76} 76}
77 77
78 78
79ORecur::ORecur( const ORecur& rec) 79OPimRecurrence::OPimRecurrence( const OPimRecurrence& rec)
80 : data( rec.data ) 80 : data( rec.data )
81{ 81{
82 data->ref(); 82 data->ref();
83} 83}
84 84
85 85
86ORecur::~ORecur() { 86OPimRecurrence::~OPimRecurrence() {
87 if ( data->deref() ) { 87 if ( data->deref() ) {
88 delete data; 88 delete data;
89 data = 0l; 89 data = 0l;
@@ -91,7 +91,7 @@ ORecur::~ORecur() {
91} 91}
92 92
93 93
94void ORecur::deref() { 94void OPimRecurrence::deref() {
95 if ( data->deref() ) { 95 if ( data->deref() ) {
96 delete data; 96 delete data;
97 data = 0l; 97 data = 0l;
@@ -99,12 +99,12 @@ void ORecur::deref() {
99} 99}
100 100
101 101
102bool ORecur::operator==( const ORecur& )const { 102bool OPimRecurrence::operator==( const OPimRecurrence& )const {
103 return false; 103 return false;
104} 104}
105 105
106 106
107ORecur &ORecur::operator=( const ORecur& re) { 107OPimRecurrence &OPimRecurrence::operator=( const OPimRecurrence& re) {
108 if ( *this == re ) return *this; 108 if ( *this == re ) return *this;
109 109
110 re.data->ref(); 110 re.data->ref();
@@ -115,7 +115,7 @@ ORecur &ORecur::operator=( const ORecur& re) {
115} 115}
116 116
117 117
118bool ORecur::doesRecur()const { 118bool OPimRecurrence::doesRecur()const {
119 return !( type() == NoRepeat ); 119 return !( type() == NoRepeat );
120} 120}
121 121
@@ -124,7 +124,7 @@ bool ORecur::doesRecur()const {
124 * we try to be smart here 124 * we try to be smart here
125 * 125 *
126 */ 126 */
127bool ORecur::doesRecur( const QDate& date ) { 127bool OPimRecurrence::doesRecur( const QDate& date ) {
128 /* the day before the recurrance */ 128 /* the day before the recurrance */
129 QDate da = date.addDays(-1); 129 QDate da = date.addDays(-1);
130 130
@@ -139,7 +139,7 @@ bool ORecur::doesRecur( const QDate& date ) {
139// FIXME unuglify! 139// FIXME unuglify!
140// GPL from Datebookdb.cpp 140// GPL from Datebookdb.cpp
141// FIXME exception list! 141// FIXME exception list!
142bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { 142bool OPimRecurrence::nextOcurrence( const QDate& from, QDate& next ) {
143 bool stillLooking; 143 bool stillLooking;
144 stillLooking = p_nextOccurrence( from, next ); 144 stillLooking = p_nextOccurrence( from, next );
145 while ( stillLooking && data->list.contains(next) ) 145 while ( stillLooking && data->list.contains(next) )
@@ -149,7 +149,7 @@ bool ORecur::nextOcurrence( const QDate& from, QDate& next ) {
149} 149}
150 150
151 151
152bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { 152bool OPimRecurrence::p_nextOccurrence( const QDate& from, QDate& next ) {
153 153
154 // easy checks, first are we too far in the future or too far in the past? 154 // easy checks, first are we too far in the future or too far in the past?
155 QDate tmpDate; 155 QDate tmpDate;
@@ -423,122 +423,122 @@ bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) {
423} 423}
424 424
425 425
426ORecur::RepeatType ORecur::type()const{ 426OPimRecurrence::RepeatType OPimRecurrence::type()const{
427 return data->type; 427 return data->type;
428} 428}
429 429
430 430
431int ORecur::frequency()const { 431int OPimRecurrence::frequency()const {
432 return data->freq; 432 return data->freq;
433} 433}
434 434
435 435
436int ORecur::position()const { 436int OPimRecurrence::position()const {
437 return data->pos; 437 return data->pos;
438} 438}
439 439
440 440
441char ORecur::days() const{ 441char OPimRecurrence::days() const{
442 return data->days; 442 return data->days;
443} 443}
444 444
445 445
446bool ORecur::hasEndDate()const { 446bool OPimRecurrence::hasEndDate()const {
447 return data->hasEnd; 447 return data->hasEnd;
448} 448}
449 449
450 450
451QDate ORecur::endDate()const { 451QDate OPimRecurrence::endDate()const {
452 return data->end; 452 return data->end;
453} 453}
454 454
455 455
456QDate ORecur::start()const{ 456QDate OPimRecurrence::start()const{
457 return data->start; 457 return data->start;
458} 458}
459 459
460 460
461QDateTime ORecur::createdDateTime()const { 461QDateTime OPimRecurrence::createdDateTime()const {
462 return data->create; 462 return data->create;
463} 463}
464 464
465 465
466int ORecur::repetition()const { 466int OPimRecurrence::repetition()const {
467 return data->rep; 467 return data->rep;
468} 468}
469 469
470 470
471QString ORecur::service()const { 471QString OPimRecurrence::service()const {
472 return data->app; 472 return data->app;
473} 473}
474 474
475 475
476ORecur::ExceptionList& ORecur::exceptions() { 476OPimRecurrence::ExceptionList& OPimRecurrence::exceptions() {
477 return data->list; 477 return data->list;
478} 478}
479 479
480 480
481void ORecur::setType( const RepeatType& z) { 481void OPimRecurrence::setType( const RepeatType& z) {
482 checkOrModify(); 482 checkOrModify();
483 data->type = z; 483 data->type = z;
484} 484}
485 485
486 486
487void ORecur::setFrequency( int freq ) { 487void OPimRecurrence::setFrequency( int freq ) {
488 checkOrModify(); 488 checkOrModify();
489 data->freq = freq; 489 data->freq = freq;
490} 490}
491 491
492 492
493void ORecur::setPosition( int pos ) { 493void OPimRecurrence::setPosition( int pos ) {
494 checkOrModify(); 494 checkOrModify();
495 data->pos = pos; 495 data->pos = pos;
496} 496}
497 497
498 498
499void ORecur::setDays( char c ) { 499void OPimRecurrence::setDays( char c ) {
500 checkOrModify(); 500 checkOrModify();
501 data->days = c; 501 data->days = c;
502} 502}
503 503
504 504
505void ORecur::setEndDate( const QDate& dt) { 505void OPimRecurrence::setEndDate( const QDate& dt) {
506 checkOrModify(); 506 checkOrModify();
507 data->end = dt; 507 data->end = dt;
508} 508}
509 509
510 510
511void ORecur::setCreatedDateTime( const QDateTime& t) { 511void OPimRecurrence::setCreatedDateTime( const QDateTime& t) {
512 checkOrModify(); 512 checkOrModify();
513 data->create = t; 513 data->create = t;
514} 514}
515 515
516 516
517void ORecur::setHasEndDate( bool b) { 517void OPimRecurrence::setHasEndDate( bool b) {
518 checkOrModify(); 518 checkOrModify();
519 data->hasEnd = b; 519 data->hasEnd = b;
520} 520}
521 521
522 522
523void ORecur::setRepitition( int rep ) { 523void OPimRecurrence::setRepitition( int rep ) {
524 checkOrModify(); 524 checkOrModify();
525 data->rep = rep; 525 data->rep = rep;
526} 526}
527 527
528 528
529void ORecur::setService( const QString& app ) { 529void OPimRecurrence::setService( const QString& app ) {
530 checkOrModify(); 530 checkOrModify();
531 data->app = app; 531 data->app = app;
532} 532}
533 533
534 534
535void ORecur::setStart( const QDate& dt ) { 535void OPimRecurrence::setStart( const QDate& dt ) {
536 checkOrModify(); 536 checkOrModify();
537 data->start = dt; 537 data->start = dt;
538} 538}
539 539
540 540
541void ORecur::checkOrModify() { 541void OPimRecurrence::checkOrModify() {
542 if ( data->count != 1 ) { 542 if ( data->count != 1 ) {
543 data->deref(); 543 data->deref();
544 Data* d2 = new Data; 544 Data* d2 = new Data;
@@ -558,51 +558,51 @@ void ORecur::checkOrModify() {
558} 558}
559 559
560 560
561QString ORecur::toString()const { 561QString OPimRecurrence::toString()const {
562 QString buf; 562 QString buf;
563 QMap<int, QString> recMap = toMap(); 563 QMap<int, QString> recMap = toMap();
564 564
565 buf += " rtype=\""; 565 buf += " rtype=\"";
566 buf += recMap[ORecur::RType]; 566 buf += recMap[OPimRecurrence::RType];
567 buf += "\""; 567 buf += "\"";
568 if (data->days > 0 ) 568 if (data->days > 0 )
569 buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; 569 buf += " rweekdays=\"" + recMap[OPimRecurrence::RWeekdays] + "\"";
570 if ( data->pos != 0 ) 570 if ( data->pos != 0 )
571 buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; 571 buf += " rposition=\"" + recMap[OPimRecurrence::RPosition] + "\"";
572 572
573 buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; 573 buf += " rfreq=\"" + recMap[OPimRecurrence::RFreq] + "\"";
574 buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; 574 buf += " rhasenddate=\"" + recMap[OPimRecurrence::RHasEndDate]+ "\"";
575 if ( data->hasEnd ) 575 if ( data->hasEnd )
576 buf += " enddt=\"" 576 buf += " enddt=\""
577 + recMap[ORecur::EndDate] 577 + recMap[OPimRecurrence::EndDate]
578 + "\""; 578 + "\"";
579 buf += " created=\"" + recMap[ORecur::Created] + "\""; 579 buf += " created=\"" + recMap[OPimRecurrence::Created] + "\"";
580 580
581 if ( data->list.isEmpty() ) return buf; 581 if ( data->list.isEmpty() ) return buf;
582 buf += " exceptions=\""; 582 buf += " exceptions=\"";
583 buf += recMap[ORecur::Exceptions]; 583 buf += recMap[OPimRecurrence::Exceptions];
584 buf += "\" "; 584 buf += "\" ";
585 585
586 return buf; 586 return buf;
587} 587}
588 588
589QString ORecur::rTypeString() const 589QString OPimRecurrence::rTypeString() const
590{ 590{
591 QString retString; 591 QString retString;
592 switch ( data->type ) { 592 switch ( data->type ) {
593 case ORecur::Daily: 593 case OPimRecurrence::Daily:
594 retString = "Daily"; 594 retString = "Daily";
595 break; 595 break;
596 case ORecur::Weekly: 596 case OPimRecurrence::Weekly:
597 retString = "Weekly"; 597 retString = "Weekly";
598 break; 598 break;
599 case ORecur::MonthlyDay: 599 case OPimRecurrence::MonthlyDay:
600 retString = "MonthlyDay"; 600 retString = "MonthlyDay";
601 break; 601 break;
602 case ORecur::MonthlyDate: 602 case OPimRecurrence::MonthlyDate:
603 retString = "MonthlyDate"; 603 retString = "MonthlyDate";
604 break; 604 break;
605 case ORecur::Yearly: 605 case OPimRecurrence::Yearly:
606 retString = "Yearly"; 606 retString = "Yearly";
607 break; 607 break;
608 default: 608 default:
@@ -614,33 +614,33 @@ QString ORecur::rTypeString() const
614 return retString; 614 return retString;
615} 615}
616 616
617QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const 617QMap<QString, OPimRecurrence::RepeatType> OPimRecurrence::rTypeValueConvertMap() const
618{ 618{
619 QMap<QString, RepeatType> convertMap; 619 QMap<QString, RepeatType> convertMap;
620 620
621 convertMap.insert( QString( "Daily" ), ORecur::Daily ); 621 convertMap.insert( QString( "Daily" ), OPimRecurrence::Daily );
622 convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); 622 convertMap.insert( QString( "Weekly" ), OPimRecurrence::Weekly );
623 convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); 623 convertMap.insert( QString( "MonthlyDay" ), OPimRecurrence::MonthlyDay );
624 convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); 624 convertMap.insert( QString( "MonthlyDate" ), OPimRecurrence::MonthlyDate );
625 convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); 625 convertMap.insert( QString( "Yearly" ), OPimRecurrence::Yearly );
626 convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); 626 convertMap.insert( QString( "NoRepeat" ), OPimRecurrence::NoRepeat );
627 627
628 return convertMap; 628 return convertMap;
629} 629}
630 630
631 631
632QMap<int, QString> ORecur::toMap() const 632QMap<int, QString> OPimRecurrence::toMap() const
633{ 633{
634 QMap<int, QString> retMap; 634 QMap<int, QString> retMap;
635 635
636 retMap.insert( ORecur::RType, rTypeString() ); 636 retMap.insert( OPimRecurrence::RType, rTypeString() );
637 retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); 637 retMap.insert( OPimRecurrence::RWeekdays, QString::number( static_cast<int>( data->days ) ) );
638 retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); 638 retMap.insert( OPimRecurrence::RPosition, QString::number(data->pos ) );
639 retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); 639 retMap.insert( OPimRecurrence::RFreq, QString::number( data->freq ) );
640 retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); 640 retMap.insert( OPimRecurrence::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) );
641 if( data -> hasEnd ) 641 if( data -> hasEnd )
642 retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); 642 retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) );
643 retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); 643 retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::utc().fromUTCDateTime( data->create ) ) );
644 644
645 if ( data->list.isEmpty() ) return retMap; 645 if ( data->list.isEmpty() ) return retMap;
646 646
@@ -656,31 +656,31 @@ QMap<int, QString> ORecur::toMap() const
656 exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); 656 exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() );
657 } 657 }
658 658
659 retMap.insert( ORecur::Exceptions, exceptBuf ); 659 retMap.insert( OPimRecurrence::Exceptions, exceptBuf );
660 660
661 return retMap; 661 return retMap;
662} 662}
663 663
664void ORecur::fromMap( const QMap<int, QString>& map ) 664void OPimRecurrence::fromMap( const QMap<int, QString>& map )
665{ 665{
666 QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); 666 QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap();
667 667
668 data -> type = repTypeMap[ map [ORecur::RType] ]; 668 data -> type = repTypeMap[ map [OPimRecurrence::RType] ];
669 data -> days = (char) map[ ORecur::RWeekdays ].toInt(); 669 data -> days = (char) map[ OPimRecurrence::RWeekdays ].toInt();
670 data -> pos = map[ ORecur::RPosition ].toInt(); 670 data -> pos = map[ OPimRecurrence::RPosition ].toInt();
671 data -> freq = map[ ORecur::RFreq ].toInt(); 671 data -> freq = map[ OPimRecurrence::RFreq ].toInt();
672 data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; 672 data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false;
673 OTimeZone utc = OTimeZone::utc(); 673 OPimTimeZone utc = OPimTimeZone::utc();
674 if ( data -> hasEnd ){ 674 if ( data -> hasEnd ){
675 data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); 675 data -> end = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date();
676 } 676 }
677 data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); 677 data -> create = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date();
678 678
679#if 0 679#if 0
680 // FIXME: Exceptions currently not supported... 680 // FIXME: Exceptions currently not supported...
681 // Convert the list of exceptions from QString into ExceptionList 681 // Convert the list of exceptions from QString into ExceptionList
682 data -> list.clear(); 682 data -> list.clear();
683 QString exceptStr = map[ ORecur::Exceptions ]; 683 QString exceptStr = map[ OPimRecurrence::Exceptions ];
684 QStringList exceptList = QStringList::split( " ", exceptStr ); 684 QStringList exceptList = QStringList::split( " ", exceptStr );
685 ... 685 ...
686#endif 686#endif
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/opimrecurrence.h
index 7808897..f186cfe 100644
--- a/libopie2/opiepim/core/orecur.h
+++ b/libopie2/opiepim/core/opimrecurrence.h
@@ -43,7 +43,7 @@ namespace Opie {
43 * Class to handle Recurrencies.. 43 * Class to handle Recurrencies..
44 */ 44 */
45 45
46class ORecur { 46class OPimRecurrence {
47 47
48 public: 48 public:
49 typedef QValueList<QDate> ExceptionList; 49 typedef QValueList<QDate> ExceptionList;
@@ -54,13 +54,13 @@ class ORecur {
54 enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate, 54 enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate,
55 EndDate, Created, Exceptions }; 55 EndDate, Created, Exceptions };
56 56
57 ORecur(); 57 OPimRecurrence();
58 ORecur( const QMap<int, QString>& map ); 58 OPimRecurrence( const QMap<int, QString>& map );
59 ORecur( const ORecur& ); 59 OPimRecurrence( const OPimRecurrence& );
60 ~ORecur(); 60 ~OPimRecurrence();
61 61
62 ORecur &operator=( const ORecur& ); 62 OPimRecurrence &operator=( const OPimRecurrence& );
63 bool operator==(const ORecur& )const; 63 bool operator==(const OPimRecurrence& )const;
64 64
65 bool doesRecur()const; 65 bool doesRecur()const;
66 /* if it recurrs on that day */ 66 /* if it recurrs on that day */
@@ -85,7 +85,7 @@ class ORecur {
85 bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate ); 85 bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate );
86 86
87 /** 87 /**
88 * The module this ORecur belongs to 88 * The module this OPimRecurrence belongs to
89 */ 89 */
90 QString service()const; 90 QString service()const;
91 91
@@ -129,8 +129,8 @@ class ORecur {
129 129
130 class Data; 130 class Data;
131 Data* data; 131 Data* data;
132 class ORecurPrivate; 132 class OPimRecurrencePrivate;
133 ORecurPrivate *d; 133 OPimRecurrencePrivate *d;
134}; 134};
135 135
136} 136}
diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp
index 73d7de1..eb6661a 100644
--- a/libopie2/opiepim/core/opimresolver.cpp
+++ b/libopie2/opiepim/core/opimresolver.cpp
@@ -72,9 +72,9 @@ OPimRecord* OPimResolver::record( int rtti ) {
72 OPimRecord* rec = 0l; 72 OPimRecord* rec = 0l;
73 switch( rtti ) { 73 switch( rtti ) {
74 case 1: /* todolist */ 74 case 1: /* todolist */
75 rec = new OTodo(); 75 rec = new OPimTodo();
76 case 2: /* contact */ 76 case 2: /* contact */
77 rec = new OContact(); 77 rec = new OPimContact();
78 default: 78 default:
79 break; 79 break;
80 } 80 }
@@ -211,12 +211,12 @@ OPimBase* OPimResolver::backend( int rtti ) {
211 OPimBase* base = 0l; 211 OPimBase* base = 0l;
212 switch( rtti ) { 212 switch( rtti ) {
213 case TodoList: 213 case TodoList:
214 base = new OTodoAccess(); 214 base = new OPimTodoAccess();
215 break; 215 break;
216 case DateBook: 216 case DateBook:
217 break; 217 break;
218 case AddressBook: 218 case AddressBook:
219 base = new OContactAccess("Resolver"); 219 base = new OPimContactAccess("Resolver");
220 break; 220 break;
221 default: 221 default:
222 break; 222 break;
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h
index dd6f07f..0a6dddf 100644
--- a/libopie2/opiepim/core/opimresolver.h
+++ b/libopie2/opiepim/core/opimresolver.h
@@ -30,7 +30,7 @@
30#define OPIMRESOLVER_H 30#define OPIMRESOLVER_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/otemplatebase.h> 33#include <opie2/opimtemplatebase.h>
34 34
35/* QT */ 35/* QT */
36#include <qstring.h> 36#include <qstring.h>
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index 58cbfeb..58cbfeb 100644
--- a/libopie2/opiepim/core/otemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index e67715f..be21b1b 100644
--- a/libopie2/opiepim/core/otimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -27,7 +27,7 @@
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "otimezone.h" 30#include "opimtimezone.h"
31 31
32/* STD */ 32/* STD */
33#include <stdio.h> 33#include <stdio.h>
@@ -100,16 +100,16 @@ time_t to_Time_t( const QDateTime& utc, const QString& str )
100 100
101namespace Opie 101namespace Opie
102{ 102{
103OTimeZone::OTimeZone( const ZoneName& zone ) 103OPimTimeZone::OPimTimeZone( const ZoneName& zone )
104 : m_name( zone ) 104 : m_name( zone )
105{} 105{}
106 106
107 107
108OTimeZone::~OTimeZone() 108OPimTimeZone::~OPimTimeZone()
109{} 109{}
110 110
111 111
112bool OTimeZone::isValid() const 112bool OPimTimeZone::isValid() const
113{ 113{
114 return !m_name.isEmpty(); 114 return !m_name.isEmpty();
115} 115}
@@ -118,25 +118,25 @@ bool OTimeZone::isValid() const
118 * we will get the current timezone 118 * we will get the current timezone
119 * and ask it to convert to the timezone date 119 * and ask it to convert to the timezone date
120 */ 120 */
121QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt ) 121QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt )
122{ 122{
123 return OTimeZone::current().toDateTime( dt, *this ); 123 return OPimTimeZone::current().toDateTime( dt, *this );
124} 124}
125 125
126 126
127QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) 127QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt )
128{ 128{
129 return OTimeZone::utc().toDateTime( dt, *this ); 129 return OPimTimeZone::utc().toDateTime( dt, *this );
130} 130}
131 131
132 132
133QDateTime OTimeZone::fromUTCDateTime( time_t t ) 133QDateTime OPimTimeZone::fromUTCDateTime( time_t t )
134{ 134{
135 return utcTime( t ); 135 return utcTime( t );
136} 136}
137 137
138 138
139QDateTime OTimeZone::toDateTime( time_t t ) 139QDateTime OPimTimeZone::toDateTime( time_t t )
140{ 140{
141 return utcTime( t, m_name ); 141 return utcTime( t, m_name );
142} 142}
@@ -146,7 +146,7 @@ QDateTime OTimeZone::toDateTime( time_t t )
146 * convert dt to utc using zone.m_name 146 * convert dt to utc using zone.m_name
147 * convert utc -> timeZoneDT using this->m_name 147 * convert utc -> timeZoneDT using this->m_name
148 */ 148 */
149QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) 149QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
150{ 150{
151 time_t utc = to_Time_t( dt, zone.m_name ); 151 time_t utc = to_Time_t( dt, zone.m_name );
152 qWarning( "%d %s", utc, zone.m_name.latin1() ); 152 qWarning( "%d %s", utc, zone.m_name.latin1() );
@@ -154,33 +154,33 @@ QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone )
154} 154}
155 155
156 156
157time_t OTimeZone::fromDateTime( const QDateTime& time ) 157time_t OPimTimeZone::fromDateTime( const QDateTime& time )
158{ 158{
159 return to_Time_t( time, m_name ); 159 return to_Time_t( time, m_name );
160} 160}
161 161
162 162
163time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) 163time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
164{ 164{
165 return to_Time_t( time, "UTC" ); 165 return to_Time_t( time, "UTC" );
166} 166}
167 167
168 168
169OTimeZone OTimeZone::current() 169OPimTimeZone OPimTimeZone::current()
170{ 170{
171 QCString str = ::getenv( "TZ" ); 171 QCString str = ::getenv( "TZ" );
172 OTimeZone zone( str ); 172 OPimTimeZone zone( str );
173 return zone; 173 return zone;
174} 174}
175 175
176 176
177OTimeZone OTimeZone::utc() 177OPimTimeZone OPimTimeZone::utc()
178{ 178{
179 return OTimeZone( "UTC" ); 179 return OPimTimeZone( "UTC" );
180} 180}
181 181
182 182
183QString OTimeZone::timeZone() const 183QString OPimTimeZone::timeZone() const
184{ 184{
185 return m_name; 185 return m_name;
186} 186}
diff --git a/libopie2/opiepim/core/otimezone.h b/libopie2/opiepim/core/opimtimezone.h
index f0b4022..284e80f 100644
--- a/libopie2/opiepim/core/otimezone.h
+++ b/libopie2/opiepim/core/opimtimezone.h
@@ -44,12 +44,12 @@ namespace Opie
44 * and to localtime 44 * and to localtime
45 * and time_t 45 * and time_t
46 */ 46 */
47class OTimeZone { 47class OPimTimeZone {
48 48
49 public: 49 public:
50 typedef QString ZoneName; 50 typedef QString ZoneName;
51 OTimeZone( const ZoneName& = ZoneName::null ); 51 OPimTimeZone( const ZoneName& = ZoneName::null );
52 virtual ~OTimeZone(); // just in case. 52 virtual ~OPimTimeZone(); // just in case.
53 53
54 bool isValid()const; 54 bool isValid()const;
55 55
@@ -80,7 +80,7 @@ class OTimeZone {
80 /** 80 /**
81 * converts the QDateTime from one timezone to this timeZone 81 * converts the QDateTime from one timezone to this timeZone
82 */ 82 */
83 QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); 83 QDateTime toDateTime( const QDateTime&, const OPimTimeZone& timeZone );
84 84
85 /** 85 /**
86 * converts the date time into a time_t. It takes the timezone into account 86 * converts the date time into a time_t. It takes the timezone into account
@@ -92,8 +92,8 @@ class OTimeZone {
92 */ 92 */
93 time_t fromUTCDateTime( const QDateTime& ); 93 time_t fromUTCDateTime( const QDateTime& );
94 94
95 static OTimeZone current(); 95 static OPimTimeZone current();
96 static OTimeZone utc(); 96 static OPimTimeZone utc();
97 97
98 QString timeZone() const; 98 QString timeZone() const;
99 99
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
new file mode 100644
index 0000000..34df807
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -0,0 +1,712 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimtodo.h"
31
32/* OPIE */
33#include <opie2/opimstate.h>
34#include <opie2/opimrecurrence.h>
35#include <opie2/opimmaintainer.h>
36#include <opie2/opimnotifymanager.h>
37#include <opie2/opimresolver.h>
38#include <qpe/palmtopuidgen.h>
39#include <qpe/stringutil.h>
40#include <qpe/palmtoprecord.h>
41#include <qpe/stringutil.h>
42#include <qpe/categories.h>
43#include <qpe/categoryselect.h>
44
45/* QT */
46#include <qobject.h>
47#include <qshared.h>
48
49namespace Opie
50{
51
52struct OPimTodo::OPimTodoData : public QShared
53{
54 OPimTodoData() : QShared()
55 {
56 recur = 0;
57 state = 0;
58 maintainer = 0;
59 notifiers = 0;
60 };
61 ~OPimTodoData()
62 {
63 delete recur;
64 delete maintainer;
65 delete notifiers;
66 }
67
68 QDate date;
69 bool isCompleted: 1;
70 bool hasDate: 1;
71 int priority;
72 QString desc;
73 QString sum;
74 QMap<QString, QString> extra;
75 ushort prog;
76 OPimState *state;
77 OPimRecurrence *recur;
78 OPimMaintainer *maintainer;
79 QDate start;
80 QDate completed;
81 OPimNotifyManager *notifiers;
82};
83
84
85OPimTodo::OPimTodo( const OPimTodo &event )
86 : OPimRecord( event ), data( event.data )
87{
88 data->ref();
89 // qWarning("ref up");
90}
91
92
93OPimTodo::~OPimTodo()
94{
95
96 // qWarning("~OPimTodo " );
97 if ( data->deref() )
98 {
99 // qWarning("OPimTodo::dereffing");
100 delete data;
101 data = 0l;
102 }
103}
104
105
106OPimTodo::OPimTodo( bool completed, int priority,
107 const QArray<int> &category,
108 const QString& summary,
109 const QString &description,
110 ushort progress,
111 bool hasDate, QDate date, int uid )
112 : OPimRecord( uid )
113{
114 // qWarning("OPimTodoData " + summary);
115 setCategories( category );
116
117 data = new OPimTodoData;
118
119 data->date = date;
120 data->isCompleted = completed;
121 data->hasDate = hasDate;
122 data->priority = priority;
123 data->sum = summary;
124 data->prog = progress;
125 data->desc = Qtopia::simplifyMultiLineSpace( description );
126}
127
128
129OPimTodo::OPimTodo( bool completed, int priority,
130 const QStringList &category,
131 const QString& summary,
132 const QString &description,
133 ushort progress,
134 bool hasDate, QDate date, int uid )
135 : OPimRecord( uid )
136{
137 // qWarning("OPimTodoData" + summary);
138 setCategories( idsFromString( category.join( ";" ) ) );
139
140 data = new OPimTodoData;
141
142 data->date = date;
143 data->isCompleted = completed;
144 data->hasDate = hasDate;
145 data->priority = priority;
146 data->sum = summary;
147 data->prog = progress;
148 data->desc = Qtopia::simplifyMultiLineSpace( description );
149}
150
151
152bool OPimTodo::match( const QRegExp &regExp ) const
153{
154 if ( QString::number( data->priority ).find( regExp ) != -1 )
155 {
156 setLastHitField( Priority );
157 return true;
158 }
159 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
160 {
161 setLastHitField( HasDate );
162 return true;
163 }
164 else if ( data->desc.find( regExp ) != -1 )
165 {
166 setLastHitField( Description );
167 return true;
168 }
169 else if ( data->sum.find( regExp ) != -1 )
170 {
171 setLastHitField( Summary );
172 return true;
173 }
174 return false;
175}
176
177
178bool OPimTodo::isCompleted() const
179{
180 return data->isCompleted;
181}
182
183
184bool OPimTodo::hasDueDate() const
185{
186 return data->hasDate;
187}
188
189
190bool OPimTodo::hasStartDate() const
191{
192 return data->start.isValid();
193}
194
195
196bool OPimTodo::hasCompletedDate() const
197{
198 return data->completed.isValid();
199}
200
201
202int OPimTodo::priority() const
203{
204 return data->priority;
205}
206
207
208QString OPimTodo::summary() const
209{
210 return data->sum;
211}
212
213
214ushort OPimTodo::progress() const
215{
216 return data->prog;
217}
218
219
220QDate OPimTodo::dueDate() const
221{
222 return data->date;
223}
224
225
226QDate OPimTodo::startDate() const
227{
228 return data->start;
229}
230
231
232QDate OPimTodo::completedDate() const
233{
234 return data->completed;
235}
236
237
238QString OPimTodo::description() const
239{
240 return data->desc;
241}
242
243
244bool OPimTodo::hasState() const
245{
246 if ( !data->state ) return false;
247 return ( data->state->state() != OPimState::Undefined );
248}
249
250
251OPimState OPimTodo::state() const
252{
253 if ( !data->state )
254 {
255 OPimState state;
256 return state;
257 }
258
259 return ( *data->state );
260}
261
262
263bool OPimTodo::hasRecurrence() const
264{
265 if ( !data->recur ) return false;
266 return data->recur->doesRecur();
267}
268
269
270OPimRecurrence OPimTodo::recurrence() const
271{
272 if ( !data->recur ) return OPimRecurrence();
273
274 return ( *data->recur );
275}
276
277
278bool OPimTodo::hasMaintainer() const
279{
280 if ( !data->maintainer ) return false;
281
282 return ( data->maintainer->mode() != OPimMaintainer::Undefined );
283}
284
285
286OPimMaintainer OPimTodo::maintainer() const
287{
288 if ( !data->maintainer ) return OPimMaintainer();
289
290 return ( *data->maintainer );
291}
292
293
294void OPimTodo::setCompleted( bool completed )
295{
296 changeOrModify();
297 data->isCompleted = completed;
298}
299
300
301void OPimTodo::setHasDueDate( bool hasDate )
302{
303 changeOrModify();
304 data->hasDate = hasDate;
305}
306
307
308void OPimTodo::setDescription( const QString &desc )
309{
310 // qWarning( "desc " + desc );
311 changeOrModify();
312 data->desc = Qtopia::simplifyMultiLineSpace( desc );
313}
314
315
316void OPimTodo::setSummary( const QString& sum )
317{
318 changeOrModify();
319 data->sum = sum;
320}
321
322
323void OPimTodo::setPriority( int prio )
324{
325 changeOrModify();
326 data->priority = prio;
327}
328
329
330void OPimTodo::setDueDate( const QDate& date )
331{
332 changeOrModify();
333 data->date = date;
334}
335
336
337void OPimTodo::setStartDate( const QDate& date )
338{
339 changeOrModify();
340 data->start = date;
341}
342
343
344void OPimTodo::setCompletedDate( const QDate& date )
345{
346 changeOrModify();
347 data->completed = date;
348}
349
350
351void OPimTodo::setState( const OPimState& state )
352{
353 changeOrModify();
354 if ( data->state )
355 ( *data->state ) = state;
356 else
357 data->state = new OPimState( state );
358}
359
360
361void OPimTodo::setRecurrence( const OPimRecurrence& rec )
362{
363 changeOrModify();
364 if ( data->recur )
365 ( *data->recur ) = rec;
366 else
367 data->recur = new OPimRecurrence( rec );
368}
369
370
371void OPimTodo::setMaintainer( const OPimMaintainer& pim )
372{
373 changeOrModify();
374
375 if ( data->maintainer )
376 ( *data->maintainer ) = pim;
377 else
378 data->maintainer = new OPimMaintainer( pim );
379}
380
381
382bool OPimTodo::isOverdue( )
383{
384 if ( data->hasDate && !data->isCompleted )
385 return QDate::currentDate() > data->date;
386 return false;
387}
388
389
390void OPimTodo::setProgress( ushort progress )
391{
392 changeOrModify();
393 data->prog = progress;
394}
395
396
397QString OPimTodo::toShortText() const
398{
399 return summary();
400}
401
402
403/*!
404 Returns a richt text string
405*/
406QString OPimTodo::toRichText() const
407{
408 QString text;
409 QStringList catlist;
410
411 // summary
412 text += "<b><h3><img src=\"todo/TodoList\"> ";
413 if ( !summary().isEmpty() )
414 {
415 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
416 }
417 text += "</h3></b><br><hr><br>";
418
419 // description
420 if ( !description().isEmpty() )
421 {
422 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
423 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
424 }
425
426 // priority
427 int priorityval = priority();
428 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
429 QString::number( priorityval ) + "\"> ";
430
431 switch ( priorityval )
432 {
433 case 1 : text += QObject::tr( "Very high" );
434 break;
435 case 2 : text += QObject::tr( "High" );
436 break;
437 case 3 : text += QObject::tr( "Normal" );
438 break;
439 case 4 : text += QObject::tr( "Low" );
440 break;
441 case 5 : text += QObject::tr( "Very low" );
442 break;
443 };
444 text += "<br>";
445
446 // progress
447 text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
448 + QString::number( progress() ) + " %<br>";
449
450 // due date
451 if ( hasDueDate() )
452 {
453 QDate dd = dueDate();
454 int off = QDate::currentDate().daysTo( dd );
455
456 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
457 if ( off < 0 )
458 text += "#FF0000";
459 else if ( off == 0 )
460 text += "#FFFF00";
461 else if ( off > 0 )
462 text += "#00FF00";
463
464 text += "\">" + dd.toString() + "</font><br>";
465 }
466
467 // categories
468 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
469 text += categoryNames( "Todo List" ).join( ", " );
470 text += "<br>";
471
472 return text;
473}
474
475
476bool OPimTodo::hasNotifiers() const
477{
478 if ( !data->notifiers ) return false;
479 return !data->notifiers->isEmpty();
480}
481
482
483OPimNotifyManager& OPimTodo::notifiers()
484{
485 if ( !data->notifiers )
486 data->notifiers = new OPimNotifyManager;
487 return ( *data->notifiers );
488}
489
490
491const OPimNotifyManager& OPimTodo::notifiers() const
492{
493 if ( !data->notifiers )
494 data->notifiers = new OPimNotifyManager;
495
496 return ( *data->notifiers );
497}
498
499
500bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
501{
502 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
503 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
504 if ( hasDueDate() && toDoEvent.hasDueDate() )
505 {
506 if ( dueDate() == toDoEvent.dueDate() )
507 { // let's the priority decide
508 return priority() < toDoEvent.priority();
509 }
510 else
511 {
512 return dueDate() < toDoEvent.dueDate();
513 }
514 }
515 return false;
516}
517
518
519bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
520{
521 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
522 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
523 if ( hasDueDate() && toDoEvent.hasDueDate() )
524 {
525 if ( dueDate() == toDoEvent.dueDate() )
526 { // let's the priority decide
527 return priority() <= toDoEvent.priority();
528 }
529 else
530 {
531 return dueDate() <= toDoEvent.dueDate();
532 }
533 }
534 return true;
535}
536
537
538bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
539{
540 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
541 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
542 if ( hasDueDate() && toDoEvent.hasDueDate() )
543 {
544 if ( dueDate() == toDoEvent.dueDate() )
545 { // let's the priority decide
546 return priority() > toDoEvent.priority();
547 }
548 else
549 {
550 return dueDate() > toDoEvent.dueDate();
551 }
552 }
553 return false;
554}
555
556
557bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
558{
559 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
560 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
561 if ( hasDueDate() && toDoEvent.hasDueDate() )
562 {
563 if ( dueDate() == toDoEvent.dueDate() )
564 { // let's the priority decide
565 return priority() > toDoEvent.priority();
566 }
567 else
568 {
569 return dueDate() > toDoEvent.dueDate();
570 }
571 }
572 return true;
573}
574
575
576bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
577{
578 if ( data->priority != toDoEvent.data->priority ) return false;
579 if ( data->priority != toDoEvent.data->prog ) return false;
580 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
581 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
582 if ( data->date != toDoEvent.data->date ) return false;
583 if ( data->sum != toDoEvent.data->sum ) return false;
584 if ( data->desc != toDoEvent.data->desc ) return false;
585 if ( data->maintainer != toDoEvent.data->maintainer )
586 return false;
587
588 return OPimRecord::operator==( toDoEvent );
589}
590
591
592void OPimTodo::deref()
593{
594
595 // qWarning("deref in ToDoEvent");
596 if ( data->deref() )
597 {
598 // qWarning("deleting");
599 delete data;
600 data = 0;
601 }
602}
603
604
605OPimTodo &OPimTodo::operator=( const OPimTodo &item )
606{
607 if ( this == &item ) return * this;
608
609 OPimRecord::operator=( item );
610 //qWarning("operator= ref ");
611 item.data->ref();
612 deref();
613 data = item.data;
614
615 return *this;
616}
617
618
619QMap<int, QString> OPimTodo::toMap() const
620{
621 QMap<int, QString> map;
622
623 map.insert( Uid, QString::number( uid() ) );
624 map.insert( Category, idsToString( categories() ) );
625 map.insert( HasDate, QString::number( data->hasDate ) );
626 map.insert( Completed, QString::number( data->isCompleted ) );
627 map.insert( Description, data->desc );
628 map.insert( Summary, data->sum );
629 map.insert( Priority, QString::number( data->priority ) );
630 map.insert( DateDay, QString::number( data->date.day() ) );
631 map.insert( DateMonth, QString::number( data->date.month() ) );
632 map.insert( DateYear, QString::number( data->date.year() ) );
633 map.insert( Progress, QString::number( data->prog ) );
634 // map.insert( CrossReference, crossToString() );
635 /* FIXME!!! map.insert( State, );
636 map.insert( Recurrence, );
637 map.insert( Reminders, );
638 map.
639 */
640 return map;
641}
642
643
644/**
645 * change or modify looks at the ref count and either
646 * creates a new QShared Object or it can modify it
647 * right in place
648 */
649void OPimTodo::changeOrModify()
650{
651 if ( data->count != 1 )
652 {
653 qWarning( "changeOrModify" );
654 data->deref();
655 OPimTodoData* d2 = new OPimTodoData();
656 copy( data, d2 );
657 data = d2;
658 }
659}
660
661
662// WATCHOUT
663/*
664 * if you add something to the Data struct
665 * be sure to copy it here
666 */
667void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
668{
669 dest->date = src->date;
670 dest->isCompleted = src->isCompleted;
671 dest->hasDate = src->hasDate;
672 dest->priority = src->priority;
673 dest->desc = src->desc;
674 dest->sum = src->sum;
675 dest->extra = src->extra;
676 dest->prog = src->prog;
677
678 if ( src->state )
679 dest->state = new OPimState( *src->state );
680
681 if ( src->recur )
682 dest->recur = new OPimRecurrence( *src->recur );
683
684 if ( src->maintainer )
685 dest->maintainer = new OPimMaintainer( *src->maintainer )
686 ;
687 dest->start = src->start;
688 dest->completed = src->completed;
689
690 if ( src->notifiers )
691 dest->notifiers = new OPimNotifyManager( *src->notifiers );
692}
693
694
695QString OPimTodo::type() const
696{
697 return QString::fromLatin1( "OPimTodo" );
698}
699
700
701QString OPimTodo::recordField( int /*id*/ ) const
702{
703 return QString::null;
704}
705
706
707int OPimTodo::rtti()
708{
709 return OPimResolver::TodoList;
710}
711
712}
diff --git a/libopie2/opiepim/core/opimtodo.h b/libopie2/opiepim/core/opimtodo.h
new file mode 100644
index 0000000..5304180
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtodo.h
@@ -0,0 +1,320 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7_;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21: = ...= . :.=-
22-. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OTODOEVENT_H
31#define OTODOEVENT_H
32
33/* OPIE */
34#include <opie2/opimrecord.h>
35#include <qpe/recordfields.h>
36#include <qpe/palmtopuidgen.h>
37
38/* QT */
39#include <qarray.h>
40#include <qmap.h>
41#include <qregexp.h>
42#include <qstringlist.h>
43#include <qdatetime.h>
44#include <qvaluelist.h>
45
46namespace Opie
47{
48
49class OPimState;
50class OPimRecurrence;
51class OPimMaintainer;
52class OPimNotifyManager;
53class OPimTodo : public OPimRecord
54{
55 public:
56 typedef QValueList<OPimTodo> ValueList;
57 enum RecordFields {
58 Uid = Qtopia::UID_ID,
59 Category = Qtopia::CATEGORY_ID,
60 HasDate,
61 Completed,
62 Description,
63 Summary,
64 Priority,
65 DateDay,
66 DateMonth,
67 DateYear,
68 Progress,
69 CrossReference,
70 State,
71 Recurrence,
72 Alarms,
73 Reminders,
74 Notifiers,
75 Maintainer,
76 StartDate,
77 CompletedDate
78 };
79 public:
80 // priorities from Very low to very high
81 enum TaskPriority { VeryHigh = 1, High, Normal, Low, VeryLow };
82
83 /* Constructs a new ToDoEvent
84 @param completed Is the TodoEvent completed
85 @param priority What is the priority of this ToDoEvent
86 @param category Which category does it belong( uid )
87 @param summary A small summary of the todo
88 @param description What is this ToDoEvent about
89 @param hasDate Does this Event got a deadline
90 @param date what is the deadline?
91 @param uid what is the UUID of this Event
92 **/
93 OPimTodo( bool completed = false, int priority = Normal,
94 const QStringList &category = QStringList(),
95 const QString &summary = QString::null ,
96 const QString &description = QString::null,
97 ushort progress = 0,
98 bool hasDate = false, QDate date = QDate::currentDate(),
99 int uid = 0 /*empty*/ );
100
101 OPimTodo( bool completed, int priority,
102 const QArray<int>& category,
103 const QString& summary = QString::null,
104 const QString& description = QString::null,
105 ushort progress = 0,
106 bool hasDate = false, QDate date = QDate::currentDate(),
107 int uid = 0 /* empty */ );
108
109 /** Copy c'tor
110 *
111 */
112 OPimTodo( const OPimTodo & );
113
114 /**
115 *destructor
116 */
117 ~OPimTodo();
118
119 /**
120 * Is this event completed?
121 */
122 bool isCompleted() const;
123
124 /**
125 * Does this Event have a deadline
126 */
127 bool hasDueDate() const;
128 bool hasStartDate() const;
129 bool hasCompletedDate() const;
130
131 /**
132 * What is the priority?
133 */
134 int priority() const ;
135
136 /**
137 * progress as ushort 0, 20, 40, 60, 80 or 100%
138 */
139 ushort progress() const;
140
141 /**
142 * The due Date
143 */
144 QDate dueDate() const;
145
146 /**
147 * When did it start?
148 */
149 QDate startDate() const;
150
151 /**
152 * When was it completed?
153 */
154 QDate completedDate() const;
155
156 /**
157 * does it have a state?
158 */
159 bool hasState() const;
160
161 /**
162 * What is the state of this OPimTodo?
163 */
164 OPimState state() const;
165
166 /**
167 * has recurrence?
168 */
169 bool hasRecurrence() const;
170
171 /**
172 * the recurrance of this
173 */
174 OPimRecurrence recurrence() const;
175
176 /**
177 * does this OPimTodo have a maintainer?
178 */
179 bool hasMaintainer() const;
180
181 /**
182 * the Maintainer of this OPimTodo
183 */
184 OPimMaintainer maintainer() const;
185
186 /**
187 * The description of the todo
188 */
189 QString description() const;
190
191 /**
192 * A small summary of the todo
193 */
194 QString summary() const;
195
196 /**
197 * @reimplemented
198 * Return this todoevent in a RichText formatted QString
199 */
200 QString toRichText() const;
201
202 bool hasNotifiers() const;
203 /*
204 * FIXME check if the sharing is still fine!! -zecke
205 * ### CHECK If API is fine
206 */
207 /**
208 * return a reference to our notifiers...
209 */
210 OPimNotifyManager &notifiers();
211
212 /**
213 *
214 */
215 const OPimNotifyManager &notifiers() const;
216
217 /**
218 * reimplementations
219 */
220 QString type() const;
221 QString toShortText() const;
222 QString recordField( int id ) const;
223
224 /**
225 * toMap puts all data into the map. int relates
226 * to ToDoEvent RecordFields enum
227 */
228 QMap<int, QString> toMap() const;
229
230 /**
231 * Set if this Todo is completed
232 */
233 void setCompleted( bool completed );
234
235 /**
236 * set if this todo got an end data
237 */
238 void setHasDueDate( bool hasDate );
239 // FIXME we do not have these for start, completed
240 // cause we'll use the isNull() of QDate for figuring
241 // out if it's has a date...
242 // decide what to do here? -zecke
243
244 /**
245 * Set the priority of the Todo
246 */
247 void setPriority( int priority );
248
249 /**
250 * Set the progress.
251 */
252 void setProgress( ushort progress );
253
254 /**
255 * set the end date
256 */
257 void setDueDate( const QDate& date );
258
259 /**
260 * set the start date
261 */
262 void setStartDate( const QDate& date );
263
264 /**
265 * set the completed date
266 */
267 void setCompletedDate( const QDate& date );
268
269 void setRecurrence( const OPimRecurrence& );
270
271 void setDescription( const QString& );
272 void setSummary( const QString& );
273
274 /**
275 * set the state of a Todo
276 * @param state State what the todo should take
277 */
278 void setState( const OPimState& state );
279
280 /**
281 * set the Maintainer Mode
282 */
283 void setMaintainer( const OPimMaintainer& );
284
285 bool isOverdue();
286
287
288 virtual bool match( const QRegExp &r ) const;
289
290 bool operator<( const OPimTodo &toDoEvent ) const;
291 bool operator<=( const OPimTodo &toDoEvent ) const;
292 bool operator!=( const OPimTodo &toDoEvent ) const;
293 bool operator>( const OPimTodo &toDoEvent ) const;
294 bool operator>=( const OPimTodo &toDoEvent ) const;
295 bool operator==( const OPimTodo &toDoEvent ) const;
296 OPimTodo &operator=( const OPimTodo &toDoEvent );
297
298 static int rtti();
299
300 private:
301 class OPimTodoPrivate;
302 struct OPimTodoData;
303
304 void deref();
305 inline void changeOrModify();
306 void copy( OPimTodoData* src, OPimTodoData* dest );
307 OPimTodoPrivate *d;
308 OPimTodoData *data;
309
310};
311
312
313inline bool OPimTodo::operator!=( const OPimTodo &toDoEvent ) const
314{
315 return !( *this == toDoEvent );
316}
317
318}
319
320#endif
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index 2a3695d..83750d5 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -35,28 +35,28 @@
35#include <opie2/obackendfactory.h> 35#include <opie2/obackendfactory.h>
36 36
37namespace Opie { 37namespace Opie {
38OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) 38OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
39 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) 39 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
40{ 40{
41// if (end == 0l ) 41// if (end == 0l )
42// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); 42// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null);
43 43
44 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! 44 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben !
45 if (end == 0l ) 45 if (end == 0l )
46 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); 46 m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::Default ("todo", QString::null);
47 47
48 setBackEnd( m_todoBackEnd ); 48 setBackEnd( m_todoBackEnd );
49} 49}
50OTodoAccess::~OTodoAccess() { 50OPimTodoAccess::~OPimTodoAccess() {
51// qWarning("~OTodoAccess"); 51// qWarning("~OPimTodoAccess");
52} 52}
53void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 53void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
54 QValueList<OTodo>::ConstIterator it; 54 QValueList<OPimTodo>::ConstIterator it;
55 for ( it = list.begin(); it != list.end(); ++it ) { 55 for ( it = list.begin(); it != list.end(); ++it ) {
56 replace( (*it) ); 56 replace( (*it) );
57 } 57 }
58} 58}
59OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 59OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
60 const QDate& end, 60 const QDate& end,
61 bool includeNoDates ) { 61 bool includeNoDates ) {
62 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 62 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
@@ -64,29 +64,29 @@ OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
64 List lis( ints, this ); 64 List lis( ints, this );
65 return lis; 65 return lis;
66} 66}
67OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 67OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
68 bool includeNoDates ) { 68 bool includeNoDates ) {
69 return effectiveToDos( start, QDate::currentDate(), 69 return effectiveToDos( start, QDate::currentDate(),
70 includeNoDates ); 70 includeNoDates );
71} 71}
72OTodoAccess::List OTodoAccess::overDue() { 72OPimTodoAccess::List OPimTodoAccess::overDue() {
73 List lis( m_todoBackEnd->overDue(), this ); 73 List lis( m_todoBackEnd->overDue(), this );
74 return lis; 74 return lis;
75} 75}
76/* sort order */ 76/* sort order */
77OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 77OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
78 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 78 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
79 filter, cat ); 79 filter, cat );
80 OTodoAccess::List list( ints, this ); 80 OPimTodoAccess::List list( ints, this );
81 return list; 81 return list;
82} 82}
83void OTodoAccess::removeAllCompleted() { 83void OPimTodoAccess::removeAllCompleted() {
84 m_todoBackEnd->removeAllCompleted(); 84 m_todoBackEnd->removeAllCompleted();
85} 85}
86QBitArray OTodoAccess::backendSupport( const QString& ) const{ 86QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
87 return m_todoBackEnd->supports(); 87 return m_todoBackEnd->supports();
88} 88}
89bool OTodoAccess::backendSupports( int attr, const QString& ar) const{ 89bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
90 return backendSupport(ar).testBit( attr ); 90 return backendSupport(ar).testBit( attr );
91} 91}
92 92
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index e13d277..51f3793 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -32,18 +32,18 @@
32#include <qobject.h> 32#include <qobject.h>
33#include <qvaluelist.h> 33#include <qvaluelist.h>
34 34
35#include <opie2/otodo.h> 35#include <opie2/opimtodo.h>
36#include <opie2/otodoaccessbackend.h> 36#include <opie2/otodoaccessbackend.h>
37#include <opie2/opimaccesstemplate.h> 37#include <opie2/opimaccesstemplate.h>
38 38
39namespace Opie { 39namespace Opie {
40 40
41/** 41/**
42 * OTodoAccess 42 * OPimTodoAccess
43 * the class to get access to 43 * the class to get access to
44 * the todolist 44 * the todolist
45 */ 45 */
46class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 46class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> {
47 Q_OBJECT 47 Q_OBJECT
48public: 48public:
49 enum SortOrder { Completed = 0, 49 enum SortOrder { Completed = 0,
@@ -58,8 +58,8 @@ public:
58 * the default resource will be 58 * the default resource will be
59 * picked up 59 * picked up
60 */ 60 */
61 OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random ); 61 OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random );
62 ~OTodoAccess(); 62 ~OPimTodoAccess();
63 63
64 64
65 /* our functions here */ 65 /* our functions here */
@@ -81,7 +81,7 @@ public:
81 81
82 82
83 /** 83 /**
84 * return overdue OTodos 84 * return overdue OPimTodos
85 */ 85 */
86 List overDue(); 86 List overDue();
87 87
@@ -91,10 +91,10 @@ public:
91 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); 91 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
92 92
93 /** 93 /**
94 * merge a list of OTodos into 94 * merge a list of OPimTodos into
95 * the resource 95 * the resource
96 */ 96 */
97 void mergeWith( const QValueList<OTodo>& ); 97 void mergeWith( const QValueList<OPimTodo>& );
98 98
99 /** 99 /**
100 * delete all already completed items 100 * delete all already completed items
@@ -104,7 +104,7 @@ public:
104 /** 104 /**
105 * request information about what a backend supports. 105 * request information about what a backend supports.
106 * Supports in the sense of beeing able to store. 106 * Supports in the sense of beeing able to store.
107 * This is related to the enum in OTodo 107 * This is related to the enum in OPimTodo
108 * 108 *
109 * @param backend Will be used in the future when we support multiple backend 109 * @param backend Will be used in the future when we support multiple backend
110 */ 110 */
@@ -118,17 +118,17 @@ public:
118 bool backendSupports( int attr, const QString& backend = QString::null )const; 118 bool backendSupports( int attr, const QString& backend = QString::null )const;
119signals: 119signals:
120 /** 120 /**
121 * if the OTodoAccess was changed 121 * if the OPimTodoAccess was changed
122 */ 122 */
123 void changed( const OTodoAccess* ); 123 void changed( const OPimTodoAccess* );
124 void changed( const OTodoAccess*, int uid ); 124 void changed( const OPimTodoAccess*, int uid );
125 void added( const OTodoAccess*, int uid ); 125 void added( const OPimTodoAccess*, int uid );
126 void removed( const OTodoAccess*, int uid ); 126 void removed( const OPimTodoAccess*, int uid );
127private: 127private:
128 int m_cat; 128 int m_cat;
129 OTodoAccessBackend* m_todoBackEnd; 129 OPimTodoAccessBackend* m_todoBackEnd;
130 class OTodoAccessPrivate; 130 class OPimTodoAccessPrivate;
131 OTodoAccessPrivate* d; 131 OPimTodoAccessPrivate* d;
132}; 132};
133 133
134} 134}