summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authorzecke <zecke>2004-11-18 21:45:49 (UTC)
committer zecke <zecke>2004-11-18 21:45:49 (UTC)
commit7484344ff5be1f7c54e51715776d0e3cadeb1ed0 (patch) (unidiff)
tree96f427f7a1fb1c8ca0a6efbd72b51e916cb1651d /libopie2/opiepim
parent3302eb30390e6053637929316670da3e8fbe279e (diff)
downloadopie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.zip
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.gz
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.bz2
Big PIM API Update Core Part (1/2 of what should be implemented):
OPimRecords: -Add a so called safeCast using the rtti value OPimTodo: -Fix memleak with OPimState OPimOccurrence: -New class. Every 'Access' can give occurrences for a period of time Move Documentation
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/core.pro3
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp7
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h57
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp35
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h11
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h351
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp24
-rw-r--r--libopie2/opiepim/core/opimcontact.h4
-rw-r--r--libopie2/opiepim/core/opimevent.cpp19
-rw-r--r--libopie2/opiepim/core/opimevent.h24
-rw-r--r--libopie2/opiepim/core/opimglobal.h18
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp5
-rw-r--r--libopie2/opiepim/core/opimoccurrence.cpp319
-rw-r--r--libopie2/opiepim/core/opimoccurrence.h142
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp23
-rw-r--r--libopie2/opiepim/core/opimrecord.h11
-rw-r--r--libopie2/opiepim/core/opimrecordlist.h17
-rw-r--r--libopie2/opiepim/core/opimresolver.h2
-rw-r--r--libopie2/opiepim/core/opimstate.h6
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.cpp112
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h139
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp44
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp127
-rw-r--r--libopie2/opiepim/core/opimtodo.h13
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp23
-rw-r--r--libopie2/opiepim/core/otodoaccess.h36
26 files changed, 1244 insertions, 328 deletions
diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro
index b1b5655..f943318 100644
--- a/libopie2/opiepim/core/core.pro
+++ b/libopie2/opiepim/core/core.pro
@@ -1,48 +1,51 @@
1HEADERS += \ 1HEADERS += \
2 core/ocontactaccess.h \ 2 core/ocontactaccess.h \
3 core/odatebookaccess.h \ 3 core/odatebookaccess.h \
4 core/opimaccessfactory.h \ 4 core/opimaccessfactory.h \
5 core/opimaccesstemplate.h \ 5 core/opimaccesstemplate.h \
6 core/opimcache.h \ 6 core/opimcache.h \
7 core/opimcontactfields.h \ 7 core/opimcontactfields.h \
8 core/opimcontact.h \ 8 core/opimcontact.h \
9 core/opimdateconversion.h \ 9 core/opimdateconversion.h \
10 core/opimevent.h \ 10 core/opimevent.h \
11 core/opimglobal.h \ 11 core/opimglobal.h \
12 core/opimmaintainer.h \ 12 core/opimmaintainer.h \
13 core/opimnotify.h \ 13 core/opimnotify.h \
14 core/opimnotifymanager.h \ 14 core/opimnotifymanager.h \
15 core/opimoccurrence.h \
15 core/opimrecord.h \ 16 core/opimrecord.h \
16 core/opimrecordlist.h \ 17 core/opimrecordlist.h \
17 core/opimrecurrence.h \ 18 core/opimrecurrence.h \
18 core/opimresolver.h \ 19 core/opimresolver.h \
19 core/opimstate.h \ 20 core/opimstate.h \
20 core/opimtemplatebase.h \ 21 core/opimtemplatebase.h \
21 core/opimtimezone.h \ 22 core/opimtimezone.h \
22 core/opimtodo.h \ 23 core/opimtodo.h \
23 core/opimxref.h \ 24 core/opimxref.h \
24 core/opimxrefmanager.h \ 25 core/opimxrefmanager.h \
25 core/opimxrefpartner.h \ 26 core/opimxrefpartner.h \
26 core/otodoaccess.h 27 core/otodoaccess.h
27 28
28SOURCES += \ 29SOURCES += \
29 core/ocontactaccess.cpp \ 30 core/ocontactaccess.cpp \
30 core/odatebookaccess.cpp \ 31 core/odatebookaccess.cpp \
31 core/opimcontactfields.cpp \ 32 core/opimcontactfields.cpp \
32 core/opimcontact.cpp \ 33 core/opimcontact.cpp \
33 core/opimdateconversion.cpp \ 34 core/opimdateconversion.cpp \
34 core/opimevent.cpp \ 35 core/opimevent.cpp \
35 core/opimmaintainer.cpp \ 36 core/opimmaintainer.cpp \
36 core/opimnotify.cpp \ 37 core/opimnotify.cpp \
37 core/opimnotifymanager.cpp \ 38 core/opimnotifymanager.cpp \
39 core/opimoccurrence.cpp \
38 core/opimrecord.cpp \ 40 core/opimrecord.cpp \
39 core/opimrecurrence.cpp \ 41 core/opimrecurrence.cpp \
40 core/opimresolver.cpp \ 42 core/opimresolver.cpp \
41 core/opimstate.cpp \ 43 core/opimstate.cpp \
44 core/opimtemplatebase.cpp \
42 core/opimtimezone.cpp \ 45 core/opimtimezone.cpp \
43 core/opimtodo.cpp \ 46 core/opimtodo.cpp \
44 core/opimxref.cpp \ 47 core/opimxref.cpp \
45 core/opimxrefmanager.cpp \ 48 core/opimxrefmanager.cpp \
46 core/opimxrefpartner.cpp \ 49 core/opimxrefpartner.cpp \
47 core/otodoaccess.cpp 50 core/otodoaccess.cpp
48 51
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 771d855..9bbc820 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,164 +1,163 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: XML-Backend: Automatic reload if something was changed... 31 * ToDo: XML-Backend: Automatic reload if something was changed...
32 * 32 *
33 * 33 *
34 */ 34 */
35 35
36#include <opie2/ocontactaccess.h> 36#include <opie2/ocontactaccess.h>
37#include <opie2/obackendfactory.h> 37#include <opie2/obackendfactory.h>
38 38
39/* OPIE */ 39/* OPIE */
40#include <opie2/ocontactaccessbackend_xml.h> 40#include <opie2/ocontactaccessbackend_xml.h>
41#include <opie2/opimresolver.h> 41#include <opie2/opimresolver.h>
42#include <opie2/opimglobal.h> 42#include <opie2/opimglobal.h>
43#include <opie2/odebug.h> 43#include <opie2/odebug.h>
44 44
45//#include <qpe/qcopenvelope_qws.h> 45//#include <qpe/qcopenvelope_qws.h>
46#include <qpe/global.h> 46#include <qpe/global.h>
47 47
48/* QT */ 48/* QT */
49#include <qasciidict.h> 49#include <qasciidict.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qfile.h> 51#include <qfile.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qlist.h> 53#include <qlist.h>
54#include <qcopchannel_qws.h> 54#include <qcopchannel_qws.h>
55 55
56/* STD */ 56/* STD */
57#include <errno.h> 57#include <errno.h>
58#include <fcntl.h> 58#include <fcntl.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62 62
63namespace Opie { 63namespace Opie {
64 64
65OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 65OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
66 OPimContactAccessBackend* end, bool autosync ): 66 OPimContactAccessBackend* end, bool autosync ):
67 OPimAccessTemplate<OPimContact>( end ) 67 OPimAccessTemplate<OPimContact>( end )
68{ 68{
69 /* take care of the backend. If there is no one defined, we 69 /* take care of the backend. If there is no one defined, we
70 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 70 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
71 */ 71 */
72 if( end == 0 ) { 72 if( end == 0 ) {
73 owarn << "Using BackendFactory !" << oendl;
74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); 73 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
75 } 74 }
76 // Set backend locally and in template 75 // Set backend locally and in template
77 m_backEnd = end; 76 m_backEnd = end;
78 OPimAccessTemplate<OPimContact>::setBackEnd (end); 77 OPimAccessTemplate<OPimContact>::setBackEnd (end);
79 78
80 79
81 /* Connect signal of external db change to function */ 80 /* Connect signal of external db change to function */
82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 81 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), 82 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
84 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 83 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
85 if ( autosync ){ 84 if ( autosync ){
86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 85 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), 86 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
88 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 87 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
89 } 88 }
90 89
91 90
92} 91}
93OPimContactAccess::~OPimContactAccess () 92OPimContactAccess::~OPimContactAccess ()
94{ 93{
95 /* The user may forget to save the changed database, therefore try to 94 /* The user may forget to save the changed database, therefore try to
96 * do it for him.. 95 * do it for him..
97 */ 96 */
98 save(); 97 save();
99 // delete m_backEnd; is done by template.. 98 // delete m_backEnd; is done by template..
100} 99}
101 100
102 101
103bool OPimContactAccess::save () 102bool OPimContactAccess::save ()
104{ 103{
105 /* If the database was changed externally, we could not save the 104 /* If the database was changed externally, we could not save the
106 * Data. This will remove added items which is unacceptable ! 105 * Data. This will remove added items which is unacceptable !
107 * Therefore: Reload database and merge the data... 106 * Therefore: Reload database and merge the data...
108 */ 107 */
109 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) 108 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
110 reload(); 109 reload();
111 110
112 bool status = OPimAccessTemplate<OPimContact>::save(); 111 bool status = OPimAccessTemplate<OPimContact>::save();
113 if ( !status ) return false; 112 if ( !status ) return false;
114 113
115 /* Now tell everyone that new data is available. 114 /* Now tell everyone that new data is available.
116 */ 115 */
117 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 116 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
118 117
119 return true; 118 return true;
120} 119}
121 120
122const uint OPimContactAccess::querySettings() 121const uint OPimContactAccess::querySettings()
123{ 122{
124 return ( m_backEnd->querySettings() ); 123 return ( m_backEnd->querySettings() );
125} 124}
126 125
127bool OPimContactAccess::hasQuerySettings ( int querySettings ) const 126bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
128{ 127{
129 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 128 return ( m_backEnd->hasQuerySettings ( querySettings ) );
130} 129}
130
131#if 0
131OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 132OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
132{ 133{
133 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 134 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
134 return ( OPimRecordList<OPimContact>(matchingContacts, this) ); 135 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
135} 136}
137#endif
136 138
137 139
138bool OPimContactAccess::wasChangedExternally()const 140bool OPimContactAccess::wasChangedExternally()const
139{ 141{
140 return ( m_backEnd->wasChangedExternally() ); 142 return ( m_backEnd->wasChangedExternally() );
141} 143}
142 144
143 145
144void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 146void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
145{ 147{
146 if ( msg == "addressbookUpdated()" ){ 148 if ( msg == "addressbookUpdated()" ){
147 owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl;
148 emit signalChanged ( this ); 149 emit signalChanged ( this );
149 } else if ( msg == "flush()" ) { 150 } else if ( msg == "flush()" ) {
150 owarn << "OPimContactAccess: Received flush()" << oendl;
151 save (); 151 save ();
152 } else if ( msg == "reload()" ) { 152 } else if ( msg == "reload()" ) {
153 owarn << "OPimContactAccess: Received reload()" << oendl;
154 reload (); 153 reload ();
155 emit signalChanged ( this ); 154 emit signalChanged ( this );
156 } 155 }
157} 156}
158 157
159int OPimContactAccess::rtti() const 158int OPimContactAccess::rtti() const
160{ 159{
161 return OPimResolver::AddressBook; 160 return OPimResolver::AddressBook;
162} 161}
163 162
164} 163}
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 4429b6f..691ece2 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,163 +1,156 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: Define enum for query settings 31 * ToDo: Define enum for query settings
32 * ===================================================================== 32 * =====================================================================
33 */ 33 */
34#ifndef _OCONTACTACCESS_H 34#ifndef _OCONTACTACCESS_H
35#define _OCONTACTACCESS_H 35#define _OCONTACTACCESS_H
36 36
37#include <qobject.h> 37#include <qobject.h>
38 38
39#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40 40
41#include <qvaluelist.h> 41#include <qvaluelist.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43 43
44#include <opie2/opimcontact.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
48namespace Opie { 48namespace Opie {
49/** 49/**
50 * Class to access the contacts database. 50 * Class to access the contacts database.
51 * This is just a frontend for the real database handling which is 51 * This is just a frontend for the real database handling which is
52 * done by the backend. 52 * done by the backend.
53 * This class is used to access the Contacts on a system. This class as any OPIE PIM 53 * This class is used to access the Contacts on a system. This class as any OPIE PIM
54 * class is backend independent. 54 * class is backend independent.
55 * @author Stefan Eilers, Holger Freyther 55 * @author Stefan Eilers, Holger Freyther
56 * @see OPimAccessTemplate 56 * @see OPimAccessTemplate
57 */ 57 */
58class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> 58class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61 61
62 public: 62 public:
63 enum SortFilter {
64 DoNotShowNoneChildren = FilterCustom<<1,
65 DoNotShowNoneAnniversary = FilterCustom<<2,
66 DoNotShowNoneBirthday = FilterCustom<<3,
67 DoNotShowNoHomeAddress = FilterCustom<<4,
68 DoNotShowNoBusinessAddress = FilterCustom<<5
69 };
70
71 enum SortOrder {
72 SortTitle = SortCustom,
73 SortFirstName,
74 SortMiddleName,
75 SortSuffix,
76 SortEmail,
77 SortNickname,
78 SortAnniversary,
79 SortBirthday,
80 SortGender
81 };
82
63 /** 83 /**
64 * Create Database with contacts (addressbook). 84 * Create Database with contacts (addressbook).
65 * @param appname Name of application which wants access to the database 85 * @param appname Name of application which wants access to the database
66 * (i.e. "todolist") 86 * (i.e. "todolist")
67 * @param filename The name of the database file. If not set, the default one 87 * @param filename The name of the database file. If not set, the default one
68 * is used. 88 * is used.
69 * @param backend Pointer to an alternative Backend. If not set, we will use 89 * @param backend Pointer to an alternative Backend. If not set, we will use
70 * the default backend. 90 * the default backend.
71 * @param handlesync If <b>true</b> the database stores the current state 91 * @param handlesync If <b>true</b> the database stores the current state
72 * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> 92 * 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 93 * 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> 94 * to react itself, it should be disabled by setting it to <b>false</b>
75 * @see OPimContactAccessBackend 95 * @see OPimContactAccessBackend
76 */ 96 */
77 OPimContactAccess (const QString appname, const QString filename = 0l, 97 OPimContactAccess (const QString appname, const QString filename = 0l,
78 OPimContactAccessBackend* backend = 0l, bool handlesync = true); 98 OPimContactAccessBackend* backend = 0l, bool handlesync = true);
79 ~OPimContactAccess (); 99 ~OPimContactAccess ();
80 100
81 /** Constants for query.
82 * Use this constants to set the query parameters.
83 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
84 * @see queryByExample()
85 */
86 enum QuerySettings {
87 WildCards = 0x0001,
88 IgnoreCase = 0x0002,
89 RegExp = 0x0004,
90 ExactMatch = 0x0008,
91 MatchOne = 0x0010, // Only one Entry must match
92 DateDiff = 0x0020, // Find all entries from today until given date
93 DateYear = 0x0040, // The year matches
94 DateMonth = 0x0080, // The month matches
95 DateDay = 0x0100, // The day matches
96 };
97
98
99 /** Return all Contacts in a sorted manner.
100 * @param ascending true: Sorted in acending order.
101 * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
102 * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
103 * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
104 */
105 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const;
106 101
107 /** Return all possible settings. 102 /** Return all possible settings.
108 * @return All settings provided by the current backend 103 * @return All settings provided by the current backend
109 * (i.e.: query_WildCards & query_IgnoreCase) 104 * (i.e.: query_WildCards & query_IgnoreCase)
110 */ 105 */
111 const uint querySettings(); 106 const uint querySettings();
112 107
113 /** Check whether settings are correct. 108 /** Check whether settings are correct.
114 * @return <i>true</i> if the given settings are correct and possible. 109 * @return <i>true</i> if the given settings are correct and possible.
115 */ 110 */
116 bool hasQuerySettings ( int querySettings ) const; 111 bool hasQuerySettings ( int querySettings ) const;
117 112
118 /** 113 /**
119 * if the resource was changed externally. 114 * if the resource was changed externally.
120 * You should use the signal instead of polling possible changes ! 115 * You should use the signal instead of polling possible changes !
121 */ 116 */
122 bool wasChangedExternally()const; 117 bool wasChangedExternally()const;
123 118
124 119
125 /** Save contacts database. 120 /** Save contacts database.
126 * Save is more a "commit". After calling this function, all changes are public available. 121 * Save is more a "commit". After calling this function, all changes are public available.
127 * @return true if successful 122 * @return true if successful
128 */ 123 */
129 bool save(); 124 bool save();
130 125
131 /** 126 /**
132 * Return identification of used records 127 * Return identification of used records
133 */ 128 */
134 int rtti() const; 129 int rtti() const;
135 130
136 signals: 131 signals:
137 /* Signal is emitted if the database was changed. Therefore 132 /* Signal is emitted if the database was changed. Therefore
138 * we may need to reload to stay consistent. 133 * we may need to reload to stay consistent.
139 * @param which Pointer to the database who created this event. This pointer 134 * @param which Pointer to the database who created this event. This pointer
140 * 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.
141 * @see reload() 136 * @see reload()
142 */ 137 */
143 void signalChanged ( const OPimContactAccess *which ); 138 void signalChanged ( const OPimContactAccess *which );
144 139
145 140
146 private: 141 private:
147 // class OPimContactAccessPrivate;
148 // OPimContactAccessPrivate* d;
149 OPimContactAccessBackend *m_backEnd; 142 OPimContactAccessBackend *m_backEnd;
150 bool m_loading:1; 143 bool m_loading:1;
151 144
152 private slots: 145 private slots:
153 void copMessage( const QCString &msg, const QByteArray &data ); 146 void copMessage( const QCString &msg, const QByteArray &data );
154 147
155 private: 148 private:
156 class Private; 149 class Private;
157 Private *d; 150 Private *d;
158 151
159}; 152};
160 153
161} 154}
162 155
163#endif 156#endif
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index 440ee0a..32fbb7d 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -1,118 +1,95 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#include <opie2/obackendfactory.h> 29#include <opie2/obackendfactory.h>
30#include <opie2/odatebookaccess.h> 30#include <opie2/odatebookaccess.h>
31#include <opie2/opimresolver.h> 31#include <opie2/opimresolver.h>
32#include <opie2/opimglobal.h> 32#include <opie2/opimglobal.h>
33 33
34namespace Opie { 34namespace Opie {
35/** 35/**
36 * Simple constructor 36 * Simple constructor
37 * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation 37 * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation
38 * will be used! 38 * will be used!
39 * @param back The backend to be used or 0 for the default backend 39 * @param back The backend to be used or 0 for the default backend
40 * @param ac What kind of access is intended 40 * @param ac What kind of access is intended
41 */ 41 */
42ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 42ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access )
43 : OPimAccessTemplate<OPimEvent>( back ) 43 : OPimAccessTemplate<OPimEvent>( back )
44{ 44{
45 if (!back ) 45 if (!back )
46 back = OBackendFactory<ODateBookAccessBackend>::defaultBackend( OPimGlobal::DATEBOOK, QString::null ); 46 back = OBackendFactory<ODateBookAccessBackend>::defaultBackend( OPimGlobal::DATEBOOK, QString::null );
47 47
48 m_backEnd = back; 48 m_backEnd = back;
49 setBackEnd( m_backEnd ); 49 setBackEnd( m_backEnd );
50} 50}
51ODateBookAccess::~ODateBookAccess() { 51ODateBookAccess::~ODateBookAccess() {
52} 52}
53 53
54/**
55 * @return all events available
56 */
57ODateBookAccess::List ODateBookAccess::rawEvents()const {
58 QArray<int> ints = m_backEnd->rawEvents();
59
60 List lis( ints, this );
61 return lis;
62}
63 54
64/** 55/**
65 * @return all repeating events 56 * @return all repeating events
66 */ 57 */
67ODateBookAccess::List ODateBookAccess::rawRepeats()const { 58ODateBookAccess::List ODateBookAccess::rawRepeats()const {
68 QArray<int> ints = m_backEnd->rawRepeats(); 59 QArray<int> ints = m_backEnd->rawRepeats();
69 60
70 List lis( ints, this ); 61 List lis( ints, this );
71 return lis; 62 return lis;
72} 63}
73 64
74/** 65/**
75 * @return all non repeating events 66 * @return all non repeating events
76 */ 67 */
77ODateBookAccess::List ODateBookAccess::nonRepeats()const { 68ODateBookAccess::List ODateBookAccess::nonRepeats()const {
78 QArray<int> ints = m_backEnd->nonRepeats(); 69 QArray<int> ints = m_backEnd->nonRepeats();
79 70
80 List lis( ints, this ); 71 List lis( ints, this );
81 return lis; 72 return lis;
82} 73}
83 74
84/** 75/**
85 * @return dates in the time span between from and to
86 * @param from Include all events from...
87 * @param to Include all events to...
88 */
89OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const {
90 return m_backEnd->effectiveEvents( from, to );
91}
92/**
93 * @return all events at a given datetime
94 */
95OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const {
96 return m_backEnd->effectiveEvents( start );
97}
98
99/**
100 * @return non repeating dates in the time span between from and to 76 * @return non repeating dates in the time span between from and to
101 * @param from Include all events from... 77 * @param from Include all events from...
102 * @param to Include all events to... 78 * @param to Include all events to...
103 */ 79 */
104OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { 80OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const {
105 return m_backEnd->effectiveNonRepeatingEvents( from, to ); 81 return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( from, to ) );
106} 82}
107/** 83/**
108 * @return all non repeating events at a given datetime 84 * @return all non repeating events at a given datetime
109 */ 85 */
110OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { 86OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
111 return m_backEnd->effectiveNonRepeatingEvents( start ); 87 return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( start ) );
112} 88}
89
113int ODateBookAccess::rtti() const 90int ODateBookAccess::rtti() const
114{ 91{
115 return OPimResolver::DateBook; 92 return OPimResolver::DateBook;
116} 93}
117 94
118} 95}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index c6c3598..0be8606 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -1,81 +1,76 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_DATE_BOOK_ACCESS_H 29#ifndef OPIE_DATE_BOOK_ACCESS_H
30#define OPIE_DATE_BOOK_ACCESS_H 30#define OPIE_DATE_BOOK_ACCESS_H
31 31
32#include "odatebookaccessbackend.h" 32#include "odatebookaccessbackend.h"
33#include "opimaccesstemplate.h" 33#include "opimaccesstemplate.h"
34 34
35#include <opie2/opimevent.h> 35#include <opie2/opimevent.h>
36 36
37namespace Opie { 37namespace Opie {
38/** 38/**
39 * This is the object orientated datebook database. It'll use OBackendFactory 39 * This is the object orientated datebook database. It'll use OBackendFactory
40 * to query for a backend. 40 * to query for a backend.
41 * All access to the datebook should be done via this class. 41 * All access to the datebook should be done via this class.
42 * Make sure to load and save the datebook this is not part of 42 * Make sure to load and save the datebook this is not part of
43 * destructing and creating the object 43 * destructing and creating the object
44 * 44 *
45 * @author Holger Freyther, Stefan Eilers 45 * @author Holger Freyther, Stefan Eilers
46 */ 46 */
47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { 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();
51 51
52 /* return all events */
53 List rawEvents()const;
54
55 /* return repeating events */ 52 /* return repeating events */
56 List rawRepeats()const; 53 List rawRepeats()const;
57 54
58 /* return non repeating events */ 55 /* return non repeating events */
59 List nonRepeats()const; 56 List nonRepeats()const;
60 57
61 /* return non repeating events (from,to) */ 58 /* return non repeating events (from,to) */
62 OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; 59 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
63 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; 60 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const;
64 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
65 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const;
66 61
67 /** 62 /**
68 * Return identification of used records 63 * Return identification of used records
69 */ 64 */
70 int rtti() const; 65 int rtti() const;
71 66
72 67
73private: 68private:
74 ODateBookAccessBackend* m_backEnd; 69 ODateBookAccessBackend* m_backEnd;
75 class Private; 70 class Private;
76 Private* d; 71 Private* d;
77}; 72};
78 73
79} 74}
80 75
81#endif 76#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f936d4e..2deb92a 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,373 +1,522 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
6 .=l. 6 .=l.
7 .>+-= 7 .>+-=
8 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14 .%`+i> _;_. 14 .%`+i> _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++= -. .` .: details. 21++= -. .` .: details.
22 : = ...= . :.=- 22 : = ...= . :.=-
23 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
31#define OPIE_PIM_ACCESS_TEMPLATE_H 31#define OPIE_PIM_ACCESS_TEMPLATE_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
35#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
36#include <opie2/opimrecordlist.h> 36#include <opie2/opimrecordlist.h>
37 37
38#include <opie2/opimtemplatebase.h> 38#include <opie2/opimtemplatebase.h>
39#include <opie2/odebug.h> 39#include <opie2/odebug.h>
40 40
41/* QT */ 41/* QT */
42#include <qarray.h> 42#include <qarray.h>
43#include <qdatetime.h>
43 44
44namespace Opie { 45namespace Opie {
45 46
46class OPimAccessTemplatePrivate; 47class OPimAccessTemplatePrivate;
47/** 48/**
48 * Thats the frontend to our OPIE PIM 49 * Thats the frontend to our OPIE PIM
49 * Library. Either you want to use it's 50 * Library. Either you want to use it's
50 * interface or you want to implement 51 * interface or you want to implement
51 * your own Access lib 52 * your own Access lib
52 * Just create a OPimRecord and inherit from 53 * Just create a OPimRecord and inherit from
53 * the templates 54 * the templates
54 */ 55 */
55 56
56template <class T = OPimRecord > 57template <class T = OPimRecord >
57class OPimAccessTemplate : public OTemplateBase<T> { 58class OPimAccessTemplate : public OTemplateBase<T> {
58public: 59public:
60 /**
61 *
62 */
59 enum Access { 63 enum Access {
60 Random = 0, 64 Random = 0,
61 SortedAccess 65 SortedAccess
62 }; 66 };
63 typedef OPimRecordList<T> List; 67 typedef OPimRecordList<T> List;
64 typedef OPimAccessBackend<T> BackEnd; 68 typedef OPimAccessBackend<T> BackEnd;
65 typedef OPimCache<T> Cache; 69 typedef OPimCache<T> Cache;
66 70
67 /** 71 //@{
68 * c'tor BackEnd
69 * enum Access a small hint on how to handle the backend
70 */
71 OPimAccessTemplate( BackEnd* end); 72 OPimAccessTemplate( BackEnd* end);
72
73 virtual ~OPimAccessTemplate(); 73 virtual ~OPimAccessTemplate();
74 //@}
74 75
75 /** 76 //@{
76 * load from the backend
77 */
78 bool load(); 77 bool load();
79
80 /** Reload database.
81 * You should execute this function if the external database
82 * was changed.
83 * This function will load the external database and afterwards
84 * rejoin the local changes. Therefore the local database will be set consistent.
85 */
86 virtual bool reload(); 78 virtual bool reload();
87
88 /** Save contacts database.
89 * Save is more a "commit". After calling this function, all changes are public available.
90 * @return true if successful
91 */
92 bool save(); 79 bool save();
80 void clear() ;
81 //@}
82
93 83
94 /**
95 * if the resource was changed externally
96 * You should use the signal handling instead of polling possible changes !
97 * zecke: Do you implement a signal for otodoaccess ?
98 */
99 bool wasChangedExternally()const; 84 bool wasChangedExternally()const;
100 85
101 /** 86 //@{
102 * return a List of records
103 * you can iterate over them
104 */
105 virtual List allRecords()const; 87 virtual List allRecords()const;
106
107 /**
108 * return a List of records
109 * that match the regex
110 */
111 virtual List matchRegexp( const QRegExp &r ) const; 88 virtual List matchRegexp( const QRegExp &r ) const;
112
113 /**
114 * queryByExample.
115 * @see otodoaccess, ocontactaccess
116 */
117 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 89 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
90 virtual T find( UID uid )const;
91 virtual T find( UID uid, const QArray<int>&,
92 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
93 virtual List sorted( const List&, bool ascending, int sortOrder,
94 int sortFilter, int cat )const;
95 virtual List sorted( const List&, bool ascending, int sortOrder,
96 int sortFilter, const QArray<UID>& cats )const;
97 virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const;
98 virtual List sorted( bool ascending, int sortOrder, int sortOrder,
99 const QArray<UID>& cats )const;
100 //@}
118 101
119 /** 102 /**
120 * find the OPimRecord uid 103 * (Re)Implementation
121 */
122 T find( int uid )const;
123
124 /**
125 * read ahead cache find method ;)
126 */
127 T find( int uid, const QArray<int>&,
128 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
129
130
131 /* invalidate cache here */
132 /**
133 * clears the backend and invalidates the backend
134 */ 104 */
135 void clear() ; 105 //@{
136 106 UIDArray matchRegexpSimple( const QRegExp& r )const;
137 /** 107 UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const;
138 * add T to the backend 108 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
139 * @param t The item to add. 109 int sortFilter, int cat )const;
140 * @return <i>true</i> if added successfully. 110 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
141 */ 111 int sortFilter, const QArray<int>& )const;
142 virtual bool add( const T& t ) ; 112 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
143 113 int cat )const;
114 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
115 const QArray<int>& )const;
116 OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const;
117 OPimOccurrence::List occurrences( const QDateTime& dt )const;
118 //@}
119
120 //@{
121 virtual bool add( const T& t ) ;
144 bool add( const OPimRecord& ); 122 bool add( const OPimRecord& );
145 /**
146 * Add an Opie PimRecord.
147 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
148 * But take care that the accessing database is compatible to the real type of OPimRecord !!
149 * Otherwise this access will be rejected !
150 */
151 bool add( const OPimRecord* ); 123 bool add( const OPimRecord* );
152
153
154 /* only the uid matters */
155 /**
156 * remove T from the backend
157 * @param t The item to remove
158 * @return <i>true</i> if successful.
159 */
160 virtual bool remove( const T& t ); 124 virtual bool remove( const T& t );
161 125 bool remove( UID uid );
162 /**
163 * remove the OPimRecord with uid
164 * @param uid The ID of the item to remove
165 * @return <i>true</i> if successful.
166 */
167 bool remove( int uid );
168 bool remove( const OPimRecord& ); 126 bool remove( const OPimRecord& );
169
170 /**
171 * replace T from backend
172 * @param t The item to replace
173 * @return <i>true</i> if successful.
174 */
175 virtual bool replace( const T& t) ; 127 virtual bool replace( const T& t) ;
176 128
129 //@}
130
177 void setReadAhead( uint count ); 131 void setReadAhead( uint count );
178 /** 132 virtual T cacheFind( int uid )const;
179 * @internal
180 */
181 void cache( const T& )const; 133 void cache( const T& )const;
182 void setSaneCacheSize( int ); 134 void setSaneCacheSize( int );
183 135
184 QArray<int> records()const; 136 QArray<UID> records()const;
185protected: 137protected:
186 /** 138 /**
187 * invalidate the cache 139 * invalidate the cache
188 */ 140 */
189 void invalidateCache(); 141 void invalidateCache();
190 142
191 void setBackEnd( BackEnd* end ); 143 void setBackEnd( BackEnd* end );
192 /** 144 /**
193 * returns the backend 145 * returns the backend
194 */ 146 */
195 BackEnd* backEnd(); 147 BackEnd* backEnd();
196 BackEnd* m_backEnd; 148 BackEnd* m_backEnd;
197 149
198 Cache m_cache; 150 Cache m_cache;
199 151
200private: 152private:
201 OPimAccessTemplatePrivate *d; 153 OPimAccessTemplatePrivate *d;
202 154
203}; 155};
204 156
157/**
158 * c'tor BackEnd
159 * enum Access a small hint on how to handle the backend
160 */
205template <class T> 161template <class T>
206OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 162OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
207 : OTemplateBase<T>(), m_backEnd( end ) 163 : OTemplateBase<T>(), m_backEnd( end )
208{ 164{
209 if (end ) 165 if (end )
210 end->setFrontend( this ); 166 end->setFrontend( this );
211} 167}
212template <class T> 168template <class T>
213OPimAccessTemplate<T>::~OPimAccessTemplate() { 169OPimAccessTemplate<T>::~OPimAccessTemplate() {
214 owarn << "~OPimAccessTemplate<T>" << oendl;
215 delete m_backEnd; 170 delete m_backEnd;
216} 171}
172
173/**
174 * load from the backend
175 */
217template <class T> 176template <class T>
218bool OPimAccessTemplate<T>::load() { 177bool OPimAccessTemplate<T>::load() {
219 invalidateCache(); 178 invalidateCache();
220 return m_backEnd->load(); 179 return m_backEnd->load();
221} 180}
181
182/** Reload database.
183 * You should execute this function if the external database
184 * was changed.
185 * This function will load the external database and afterwards
186 * rejoin the local changes. Therefore the local database will be set consistent.
187 */
222template <class T> 188template <class T>
223bool OPimAccessTemplate<T>::reload() { 189bool OPimAccessTemplate<T>::reload() {
224 invalidateCache(); 190 invalidateCache();
225 return m_backEnd->reload(); 191 return m_backEnd->reload();
226} 192}
193
194/**
195 * Save contacts database.
196 * Save is more a "commit". After calling this function, all changes are public available.
197 * @return true if successful
198 */
227template <class T> 199template <class T>
228bool OPimAccessTemplate<T>::save() { 200bool OPimAccessTemplate<T>::save() {
229 return m_backEnd->save(); 201 return m_backEnd->save();
230} 202}
203
204
205/**
206 * return a List of records
207 * you can iterate over them
208 */
231template <class T> 209template <class T>
232typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 210typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
233 QArray<int> ints = m_backEnd->allRecords(); 211 QArray<int> ints = m_backEnd->allRecords();
234 List lis(ints, this ); 212 List lis(ints, this );
235 return lis; 213 return lis;
236} 214}
215
216/**
217 * return a List of records
218 * that match the regex
219 */
237template <class T> 220template <class T>
238typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 221typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
239 QArray<int> ints = m_backEnd->matchRegexp( r ); 222 QArray<int> ints = m_backEnd->matchRegexp( r );
240 List lis(ints, this ); 223 List lis(ints, this );
241 return lis; 224 return lis;
242} 225}
226
227/**
228 * find the OPimRecord uid
229 */
243template <class T> 230template <class T>
244QArray<int> OPimAccessTemplate<T>::records()const { 231QArray<int> OPimAccessTemplate<T>::records()const {
245 return m_backEnd->allRecords(); 232 return m_backEnd->allRecords();
246} 233}
234
235
236/**
237 * queryByExample.
238 * @see otodoaccess, ocontactaccess
239 */
247template <class T> 240template <class T>
248typename OPimAccessTemplate<T>::List 241typename OPimAccessTemplate<T>::List
249OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 242OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
250 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 243 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
251 244
252 List lis(ints, this ); 245 List lis(ints, this );
253 return lis; 246 return lis;
254} 247}
248
255template <class T> 249template <class T>
256T OPimAccessTemplate<T>::find( int uid ) const{ 250T OPimAccessTemplate<T>::find( UID uid ) const{
257 // First search in cache.. 251 // First search in cache..
258 if ( m_cache.contains( uid ) ) 252 if ( m_cache.contains( uid ) )
259 return m_cache.find( uid ); 253 return m_cache.find( uid );
260 254
261 T t = m_backEnd->find( uid ); 255 T t = m_backEnd->find( uid );
262 cache( t ); 256 cache( t );
263 257
264 return t; 258 return t;
265} 259}
266 260
267template <class T> 261template <class T>
268T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 262T OPimAccessTemplate<T>::cacheFind( int uid ) const
263{
264 return m_cache.find( uid );
265}
266
267/**
268 * read ahead cache find method ;)
269 */
270template <class T>
271T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar,
269 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 272 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
270 /* 273 /*
271 * better do T.isEmpty() 274 * better do T.isEmpty()
272 * after a find this way we would 275 * after a find this way we would
273 * avoid two finds in QCache... 276 * avoid two finds in QCache...
274 */ 277 */
275 // owarn << "find it now " << uid << oendl; 278 if (m_cache.contains( uid ) )
276 if ( m_cache.contains( uid ) ) {
277 return m_cache.find( uid ); 279 return m_cache.find( uid );
278 } 280
279 281
280 T t = m_backEnd->find( uid, ar, current, dir ); 282 T t = m_backEnd->find( uid, ar, current, dir );
281 cache( t ); 283 cache( t );
282 return t; 284 return t;
283} 285}
286
287/**
288 * clears the backend and invalidates the backend
289 */
284template <class T> 290template <class T>
285void OPimAccessTemplate<T>::clear() { 291void OPimAccessTemplate<T>::clear() {
286 invalidateCache(); 292 invalidateCache();
287 m_backEnd->clear(); 293 m_backEnd->clear();
288} 294}
295
296
297/**
298 * add T to the backend
299 * @param t The item to add.
300 * @return <i>true</i> if added successfully.
301 */
289template <class T> 302template <class T>
290bool OPimAccessTemplate<T>::add( const T& t ) { 303bool OPimAccessTemplate<T>::add( const T& t ) {
291 cache( t ); 304 cache( t );
292 return m_backEnd->add( t ); 305 return m_backEnd->add( t );
293} 306}
294 307
295template <class T> 308template <class T>
296bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { 309bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
297 /* same type */ 310 /* same type */
298 T tempInstance; 311 T tempInstance;
299 if ( rec.rtti() == tempInstance.rtti() ) { 312 if ( rec.rtti() == tempInstance.rtti() ) {
300 const T& t = static_cast<const T&>(rec); 313 const T& t = static_cast<const T&>(rec);
301 return add(t); 314 return add(t);
302 } else { 315 } else {
303 owarn << "Adding not possible: Objecttype mismatch" << oendl; 316 owarn << "Adding not possible: Objecttype mismatch" << oendl;
304 } 317 }
305 return false; 318 return false;
306} 319}
307 320
321/**
322 * Add an Opie PimRecord.
323 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
324 * But take care that the accessing database is compatible to the real type of OPimRecord !!
325 * Otherwise this access will be rejected !
326 */
308template <class T> 327template <class T>
309bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 328bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
310 /* same type, but pointer */ 329 /* same type, but pointer */
311 T tempInstance; 330 T tempInstance;
312 if ( rec -> rtti() == tempInstance.rtti() ) { 331 if ( rec -> rtti() == tempInstance.rtti() ) {
313 const T* t = static_cast<const T*>(rec); 332 const T* t = static_cast<const T*>(rec);
314 return add( *t ); 333 return add( *t );
315 } else { 334 } else {
316 owarn << "Adding not possible: Objecttype mismatch" << oendl; 335 owarn << "Adding not possible: Objecttype mismatch" << oendl;
317 } 336 }
318 return false; 337 return false;
319} 338}
320 339
340/**
341 * remove T from the backend
342 * @param t The item to remove
343 * @return <i>true</i> if successful.
344 */
321template <class T> 345template <class T>
322bool OPimAccessTemplate<T>::remove( const T& t ) { 346bool OPimAccessTemplate<T>::remove( const T& t ) {
323 return remove( t.uid() ); 347 return remove( t.uid() );
324} 348}
349
350/**
351 * remove the OPimRecord with uid
352 * @param uid The ID of the item to remove
353 * @return <i>true</i> if successful.
354 */
325template <class T> 355template <class T>
326bool OPimAccessTemplate<T>::remove( int uid ) { 356bool OPimAccessTemplate<T>::remove( UID uid ) {
327 m_cache.remove( uid ); 357 m_cache.remove( uid );
328 return m_backEnd->remove( uid ); 358 return m_backEnd->remove( uid );
329} 359}
330template <class T> 360template <class T>
331bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 361bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
332 return remove( rec.uid() ); 362 return remove( rec.uid() );
333} 363}
364
365/**
366 * replace T from backend
367 * @param t The item to replace
368 * @return <i>true</i> if successful.
369 */
334template <class T> 370template <class T>
335bool OPimAccessTemplate<T>::replace( const T& t ) { 371bool OPimAccessTemplate<T>::replace( const T& t ) {
336 m_cache.replace( t ); 372 m_cache.replace( t );
337 return m_backEnd->replace( t ); 373 return m_backEnd->replace( t );
338} 374}
375
376/**
377 * @internal
378 */
339template <class T> 379template <class T>
340void OPimAccessTemplate<T>::invalidateCache() { 380void OPimAccessTemplate<T>::invalidateCache() {
341 m_cache.invalidate(); 381 m_cache.invalidate();
342} 382}
343template <class T> 383template <class T>
344typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 384typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
345 return m_backEnd; 385 return m_backEnd;
346} 386}
387
388/**
389 * if the resource was changed externally
390 * You should use the signal handling instead of polling possible changes !
391 * zecke: Do you implement a signal for otodoaccess ?
392 */
347template <class T> 393template <class T>
348bool OPimAccessTemplate<T>::wasChangedExternally()const { 394bool OPimAccessTemplate<T>::wasChangedExternally()const {
349 return false; 395 return false;
350} 396}
351template <class T> 397template <class T>
352void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 398void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
353 m_backEnd = end; 399 m_backEnd = end;
354 if (m_backEnd ) 400 if (m_backEnd )
355 m_backEnd->setFrontend( this ); 401 m_backEnd->setFrontend( this );
356} 402}
357template <class T> 403template <class T>
358void OPimAccessTemplate<T>::cache( const T& t ) const{ 404void OPimAccessTemplate<T>::cache( const T& t ) const{
359 /* hacky we need to work around the const*/ 405 /* hacky we need to work around the const*/
360 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 406 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
361} 407}
362template <class T> 408template <class T>
363void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 409void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
364 m_cache.setSize( size ); 410 m_cache.setSize( size );
365} 411}
366template <class T> 412template <class T>
367void OPimAccessTemplate<T>::setReadAhead( uint count ) { 413void OPimAccessTemplate<T>::setReadAhead( uint count ) {
368 m_backEnd->setReadAhead( count ); 414 m_backEnd->setReadAhead( count );
369} 415}
370 416
417
418template <class T>
419typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
420 bool ascending, int sortOrder,
421 int sortFilter, int cat )const {
422 QArray<int> cats( 1 );
423 cats[0] = cat;
424 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
425 sortFilter, cats );
426 return List(ints, this);
427}
428
429template<class T>
430typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
431 bool ascending, int sortOrder,
432 int sortFilter, const QArray<UID>& cats )const {
433 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
434 sortFilter, cats );
435 return List(ints, this);
436}
437
438template<class T>
439typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
440 int sortFilter, int cat )const {
441 QArray<int> cats( 1 );
442 cats[0] = cat;
443 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
444 sortFilter, cats );
445 return List(ints, this);
446}
447
448template<class T>
449typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
450 int sortFilter, const QArray<UID>& cats )const {
451 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
452 sortFilter, cats );
453 return List(ints, this);
454}
455
456template <class T>
457OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start,
458 const QDate& end ) const {
459 /*
460 * Some magic involved to go from single OPimBackendOccurrence
461 * to multiple OPimOccurrence's
462 */
463 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) );
464}
465
466template<class T>
467OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const {
468 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) );
469}
470
471/*
472 *Implementations!!
473 */
474template <class T>
475UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const {
476 return m_backEnd->matchRegexp( r );
477}
478
479template <class T>
480UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec,
481 int settings,
482 const QDateTime& d )const {
483 return m_backEnd->queryByExample( rec, settings, d );
484}
485
486template <class T>
487UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
488 bool ascending,
489 int sortOrder, int sortFilter,
490 int cat ) const{
491 QArray<int> cats( 1 );
492 cats[0] = cat;
493 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
494}
495
496template <class T>
497UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
498 bool ascending,
499 int sortOrder, int sortFilter,
500 const QArray<int>& cats ) const{
501 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
502}
503
504template <class T>
505UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
506 int sortOrder, int sortFilter,
507 int cat ) const{
508 QArray<int> cats( 1 );
509 cats[0] = cat;
510
511 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
512}
513
514template <class T>
515UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
516 int sortOrder, int sortFilter,
517 const QArray<int>& cats ) const{
518 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
519}
371} 520}
372 521
373#endif 522#endif
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index 36e9a93..64f195b 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -1,180 +1,179 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#define QTOPIA_INTERNAL_CONTACT_MRE 30#define QTOPIA_INTERNAL_CONTACT_MRE
31 31
32#include "opimcontact.h" 32#include "opimcontact.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimresolver.h> 35#include <opie2/opimresolver.h>
36#include <opie2/opimdateconversion.h> 36#include <opie2/opimdateconversion.h>
37#include <opie2/odebug.h> 37#include <opie2/odebug.h>
38 38
39#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
40#include <qpe/timestring.h> 40#include <qpe/timestring.h>
41#include <qpe/config.h> 41#include <qpe/config.h>
42 42
43/* QT */ 43/* QT */
44#include <qstylesheet.h> 44#include <qstylesheet.h>
45 45
46/* STD */ 46/* STD */
47#include <stdio.h> 47#include <stdio.h>
48 48
49/*! 49/*!
50 \class Contact contact.h 50 \class Contact contact.h
51 \brief The Contact class holds the data of an address book entry. 51 \brief The Contact class holds the data of an address book entry.
52 52
53 This data includes information the name of the person, contact 53 This data includes information the name of the person, contact
54 information, and business information such as deparment and job title. 54 information, and business information such as deparment and job title.
55 55
56 \ingroup qtopiaemb 56 \ingroup qtopiaemb
57 \ingroup qtopiadesktop 57 \ingroup qtopiadesktop
58*/ 58*/
59 59
60 60
61namespace Opie 61namespace Opie
62{ 62{
63/*! 63/*!
64 Creates a new, empty contact. 64 Creates a new, empty contact.
65*/ 65*/
66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) 66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
67{} 67{}
68 68
69/*! 69/*!
70 \internal 70 \internal
71 Creates a new contact. The properties of the contact are 71 Creates a new contact. The properties of the contact are
72 set from \a fromMap. 72 set from \a fromMap.
73*/ 73*/
74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) 74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
75{ 75{
76 QString cats = mMap[ Qtopia::AddressCategory ]; 76 QString cats = mMap[ Qtopia::AddressCategory ];
77 if ( !cats.isEmpty() ) 77 if ( !cats.isEmpty() )
78 setCategories( idsFromString( cats ) ); 78 setCategories( idsFromString( cats ) );
79 79
80 QString uidStr = find( Qtopia::AddressUid ); 80 QString uidStr = find( Qtopia::AddressUid );
81 81
82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
83 { 83 {
84 owarn << "Invalid UID found. Generate new one.." << oendl;
85 setUid( uidGen().generate() ); 84 setUid( uidGen().generate() );
86 } 85 }
87 else 86 else
88 setUid( uidStr.toInt() ); 87 setUid( uidStr.toInt() );
89 88
90 // if ( !uidStr.isEmpty() ) 89 // if ( !uidStr.isEmpty() )
91 // setUid( uidStr.toInt() ); 90 // setUid( uidStr.toInt() );
92} 91}
93 92
94/*! 93/*!
95 Destroys a contact. 94 Destroys a contact.
96*/ 95*/
97OPimContact::~OPimContact() 96OPimContact::~OPimContact()
98{} 97{}
99 98
100/*! \fn void OPimContact::setTitle( const QString &str ) 99/*! \fn void OPimContact::setTitle( const QString &str )
101 Sets the title of the contact to \a str. 100 Sets the title of the contact to \a str.
102*/ 101*/
103 102
104/*! \fn void OPimContact::setFirstName( const QString &str ) 103/*! \fn void OPimContact::setFirstName( const QString &str )
105 Sets the first name of the contact to \a str. 104 Sets the first name of the contact to \a str.
106*/ 105*/
107 106
108/*! \fn void OPimContact::setMiddleName( const QString &str ) 107/*! \fn void OPimContact::setMiddleName( const QString &str )
109 Sets the middle name of the contact to \a str. 108 Sets the middle name of the contact to \a str.
110*/ 109*/
111 110
112/*! \fn void OPimContact::setLastName( const QString &str ) 111/*! \fn void OPimContact::setLastName( const QString &str )
113 Sets the last name of the contact to \a str. 112 Sets the last name of the contact to \a str.
114*/ 113*/
115 114
116/*! \fn void OPimContact::setSuffix( const QString &str ) 115/*! \fn void OPimContact::setSuffix( const QString &str )
117 Sets the suffix of the contact to \a str. 116 Sets the suffix of the contact to \a str.
118*/ 117*/
119 118
120/*! \fn void OPimContact::setFileAs( const QString &str ) 119/*! \fn void OPimContact::setFileAs( const QString &str )
121 Sets the contact to filed as \a str. 120 Sets the contact to filed as \a str.
122*/ 121*/
123 122
124/*! \fn void OPimContact::setDefaultEmail( const QString &str ) 123/*! \fn void OPimContact::setDefaultEmail( const QString &str )
125 Sets the default email of the contact to \a str. 124 Sets the default email of the contact to \a str.
126*/ 125*/
127 126
128/*! \fn void OPimContact::setHomeStreet( const QString &str ) 127/*! \fn void OPimContact::setHomeStreet( const QString &str )
129 Sets the home street address of the contact to \a str. 128 Sets the home street address of the contact to \a str.
130*/ 129*/
131 130
132/*! \fn void OPimContact::setHomeCity( const QString &str ) 131/*! \fn void OPimContact::setHomeCity( const QString &str )
133 Sets the home city of the contact to \a str. 132 Sets the home city of the contact to \a str.
134*/ 133*/
135 134
136/*! \fn void OPimContact::setHomeState( const QString &str ) 135/*! \fn void OPimContact::setHomeState( const QString &str )
137 Sets the home state of the contact to \a str. 136 Sets the home state of the contact to \a str.
138*/ 137*/
139 138
140/*! \fn void OPimContact::setHomeZip( const QString &str ) 139/*! \fn void OPimContact::setHomeZip( const QString &str )
141 Sets the home zip code of the contact to \a str. 140 Sets the home zip code of the contact to \a str.
142*/ 141*/
143 142
144/*! \fn void OPimContact::setHomeCountry( const QString &str ) 143/*! \fn void OPimContact::setHomeCountry( const QString &str )
145 Sets the home country of the contact to \a str. 144 Sets the home country of the contact to \a str.
146*/ 145*/
147 146
148/*! \fn void OPimContact::setHomePhone( const QString &str ) 147/*! \fn void OPimContact::setHomePhone( const QString &str )
149 Sets the home phone number of the contact to \a str. 148 Sets the home phone number of the contact to \a str.
150*/ 149*/
151 150
152/*! \fn void OPimContact::setHomeFax( const QString &str ) 151/*! \fn void OPimContact::setHomeFax( const QString &str )
153 Sets the home fax number of the contact to \a str. 152 Sets the home fax number of the contact to \a str.
154*/ 153*/
155 154
156/*! \fn void OPimContact::setHomeMobile( const QString &str ) 155/*! \fn void OPimContact::setHomeMobile( const QString &str )
157 Sets the home mobile phone number of the contact to \a str. 156 Sets the home mobile phone number of the contact to \a str.
158*/ 157*/
159 158
160/*! \fn void OPimContact::setHomeWebpage( const QString &str ) 159/*! \fn void OPimContact::setHomeWebpage( const QString &str )
161 Sets the home webpage of the contact to \a str. 160 Sets the home webpage of the contact to \a str.
162*/ 161*/
163 162
164/*! \fn void OPimContact::setCompany( const QString &str ) 163/*! \fn void OPimContact::setCompany( const QString &str )
165 Sets the company for contact to \a str. 164 Sets the company for contact to \a str.
166*/ 165*/
167 166
168/*! \fn void OPimContact::setJobTitle( const QString &str ) 167/*! \fn void OPimContact::setJobTitle( const QString &str )
169 Sets the job title of the contact to \a str. 168 Sets the job title of the contact to \a str.
170*/ 169*/
171 170
172/*! \fn void OPimContact::setDepartment( const QString &str ) 171/*! \fn void OPimContact::setDepartment( const QString &str )
173 Sets the department for contact to \a str. 172 Sets the department for contact to \a str.
174*/ 173*/
175 174
176/*! \fn void OPimContact::setOffice( const QString &str ) 175/*! \fn void OPimContact::setOffice( const QString &str )
177 Sets the office for contact to \a str. 176 Sets the office for contact to \a str.
178*/ 177*/
179 178
180/*! \fn void OPimContact::setBusinessStreet( const QString &str ) 179/*! \fn void OPimContact::setBusinessStreet( const QString &str )
@@ -1045,247 +1044,262 @@ QStringList OPimContact::fields()
1045 list.append( "Manager" ); 1044 list.append( "Manager" );
1046 1045
1047 list.append( "HomeStreet" ); 1046 list.append( "HomeStreet" );
1048 list.append( "HomeCity" ); 1047 list.append( "HomeCity" );
1049 list.append( "HomeState" ); 1048 list.append( "HomeState" );
1050 list.append( "HomeZip" ); 1049 list.append( "HomeZip" );
1051 list.append( "HomeCountry" ); 1050 list.append( "HomeCountry" );
1052 list.append( "HomeWebPage" ); 1051 list.append( "HomeWebPage" );
1053 1052
1054 list.append( "Spouse" ); 1053 list.append( "Spouse" );
1055 list.append( "Gender" ); 1054 list.append( "Gender" );
1056 list.append( "Birthday" ); 1055 list.append( "Birthday" );
1057 list.append( "Anniversary" ); 1056 list.append( "Anniversary" );
1058 list.append( "Nickname" ); 1057 list.append( "Nickname" );
1059 list.append( "Children" ); 1058 list.append( "Children" );
1060 1059
1061 list.append( "Notes" ); 1060 list.append( "Notes" );
1062 list.append( "Groups" ); 1061 list.append( "Groups" );
1063 1062
1064 return list; 1063 return list;
1065} 1064}
1066 1065
1067 1066
1068/*! 1067/*!
1069 Sets the list of email address for contact to those contained in \a str. 1068 Sets the list of email address for contact to those contained in \a str.
1070 Email address should be separated by ';'s. 1069 Email address should be separated by ';'s.
1071*/ 1070*/
1072void OPimContact::setEmails( const QString &str ) 1071void OPimContact::setEmails( const QString &str )
1073{ 1072{
1074 replace( Qtopia::Emails, str ); 1073 replace( Qtopia::Emails, str );
1075 if ( str.isEmpty() ) 1074 if ( str.isEmpty() )
1076 setDefaultEmail( QString::null ); 1075 setDefaultEmail( QString::null );
1077} 1076}
1078 1077
1079/*! 1078/*!
1080 Sets the list of children for the contact to those contained in \a str. 1079 Sets the list of children for the contact to those contained in \a str.
1081*/ 1080*/
1082void OPimContact::setChildren( const QString &str ) 1081void OPimContact::setChildren( const QString &str )
1083{ 1082{
1084 replace( Qtopia::Children, str ); 1083 replace( Qtopia::Children, str );
1085} 1084}
1086 1085
1087/*! 1086/*!
1088 \overload 1087 \overload
1089 Returns TRUE if the contact matches the regular expression \a regexp. 1088 Returns TRUE if the contact matches the regular expression \a regexp.
1090 Otherwise returns FALSE. 1089 Otherwise returns FALSE.
1091*/ 1090*/
1092bool OPimContact::match( const QRegExp &r ) const 1091bool OPimContact::match( const QRegExp &r ) const
1093{ 1092{
1094 setLastHitField( -1 ); 1093 setLastHitField( -1 );
1095 bool match; 1094 bool match;
1096 match = false; 1095 match = false;
1097 QMap<int, QString>::ConstIterator it; 1096 QMap<int, QString>::ConstIterator it;
1098 for ( it = mMap.begin(); it != mMap.end(); ++it ) 1097 for ( it = mMap.begin(); it != mMap.end(); ++it )
1099 { 1098 {
1100 if ( ( *it ).find( r ) > -1 ) 1099 if ( ( *it ).find( r ) > -1 )
1101 { 1100 {
1102 setLastHitField( it.key() ); 1101 setLastHitField( it.key() );
1103 match = true; 1102 match = true;
1104 break; 1103 break;
1105 } 1104 }
1106 } 1105 }
1107 return match; 1106 return match;
1108} 1107}
1109 1108
1110 1109
1111QString OPimContact::toShortText() const 1110QString OPimContact::toShortText() const
1112{ 1111{
1113 return ( fullName() ); 1112 return ( fullName() );
1114} 1113}
1115 1114
1116 1115
1117QString OPimContact::type() const 1116QString OPimContact::type() const
1118{ 1117{
1119 return QString::fromLatin1( "OPimContact" ); 1118 return QString::fromLatin1( "OPimContact" );
1120} 1119}
1121 1120
1122 1121
1123class QString OPimContact::recordField( int pos ) const 1122class QString OPimContact::recordField( int pos ) const
1124{ 1123{
1125 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1124 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1126 return SLFIELDS[ pos ]; 1125 return SLFIELDS[ pos ];
1127} 1126}
1128 1127
1129// In future releases, we should store birthday and anniversary 1128// In future releases, we should store birthday and anniversary
1130// internally as QDate instead of QString ! 1129// internally as QDate instead of QString !
1131// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1130// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1132 1131
1133/*! \fn void OPimContact::setBirthday( const QDate& date ) 1132/*! \fn void OPimContact::setBirthday( const QDate& date )
1134 Sets the birthday for the contact to \a date. If date is null 1133 Sets the birthday for the contact to \a date. If date is null
1135 the current stored date will be removed. 1134 the current stored date will be removed.
1136*/ 1135*/
1137void OPimContact::setBirthday( const QDate &v ) 1136void OPimContact::setBirthday( const QDate &v )
1138{ 1137{
1139 if ( v.isNull() ) 1138 if ( v.isNull() )
1140 { 1139 {
1141 owarn << "Remove Birthday" << oendl;
1142 replace( Qtopia::Birthday, QString::null ); 1140 replace( Qtopia::Birthday, QString::null );
1143 return ; 1141 return ;
1144 } 1142 }
1145 1143
1146 if ( v.isValid() ) 1144 if ( v.isValid() )
1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1145 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1148 1146
1149} 1147}
1150 1148
1151 1149
1152/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1150/*! \fn void OPimContact::setAnniversary( const QDate &date )
1153 Sets the anniversary of the contact to \a date. If date is 1151 Sets the anniversary of the contact to \a date. If date is
1154 null, the current stored date will be removed. 1152 null, the current stored date will be removed.
1155*/ 1153*/
1156void OPimContact::setAnniversary( const QDate &v ) 1154void OPimContact::setAnniversary( const QDate &v )
1157{ 1155{
1158 if ( v.isNull() ) 1156 if ( v.isNull() )
1159 { 1157 {
1160 owarn << "Remove Anniversary" << oendl;
1161 replace( Qtopia::Anniversary, QString::null ); 1158 replace( Qtopia::Anniversary, QString::null );
1162 return ; 1159 return ;
1163 } 1160 }
1164 1161
1165 if ( v.isValid() ) 1162 if ( v.isValid() )
1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1163 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1167} 1164}
1168 1165
1169 1166
1170/*! \fn QDate OPimContact::birthday() const 1167/*! \fn QDate OPimContact::birthday() const
1171 Returns the birthday of the contact. 1168 Returns the birthday of the contact.
1172*/ 1169*/
1173QDate OPimContact::birthday() const 1170QDate OPimContact::birthday() const
1174{ 1171{
1175 QString str = find( Qtopia::Birthday ); 1172 QString str = find( Qtopia::Birthday );
1176 // owarn << "Birthday " << str << oendl;
1177 if ( !str.isEmpty() ) 1173 if ( !str.isEmpty() )
1178 return OPimDateConversion::dateFromString ( str ); 1174 return OPimDateConversion::dateFromString ( str );
1179 else 1175 else
1180 return QDate(); 1176 return QDate();
1181} 1177}
1182 1178
1183 1179
1184/*! \fn QDate OPimContact::anniversary() const 1180/*! \fn QDate OPimContact::anniversary() const
1185 Returns the anniversary of the contact. 1181 Returns the anniversary of the contact.
1186*/ 1182*/
1187QDate OPimContact::anniversary() const 1183QDate OPimContact::anniversary() const
1188{ 1184{
1189 QDate empty; 1185 QDate empty;
1190 QString str = find( Qtopia::Anniversary ); 1186 QString str = find( Qtopia::Anniversary );
1191 // owarn << "Anniversary " << str << oendl;
1192 if ( !str.isEmpty() ) 1187 if ( !str.isEmpty() )
1193 return OPimDateConversion::dateFromString ( str ); 1188 return OPimDateConversion::dateFromString ( str );
1194 else 1189 else
1195 return empty; 1190 return empty;
1196} 1191}
1197 1192
1198 1193
1199void OPimContact::insertEmail( const QString &v ) 1194void OPimContact::insertEmail( const QString &v )
1200{ 1195{
1201 //odebug << "insertEmail " << v << "" << oendl; 1196 //odebug << "insertEmail " << v << "" << oendl;
1202 QString e = v.simplifyWhiteSpace(); 1197 QString e = v.simplifyWhiteSpace();
1203 QString def = defaultEmail(); 1198 QString def = defaultEmail();
1204 1199
1205 // if no default, set it as the default email and don't insert 1200 // if no default, set it as the default email and don't insert
1206 if ( def.isEmpty() ) 1201 if ( def.isEmpty() )
1207 { 1202 {
1208 setDefaultEmail( e ); // will insert into the list for us 1203 setDefaultEmail( e ); // will insert into the list for us
1209 return ; 1204 return ;
1210 } 1205 }
1211 1206
1212 // otherwise, insert assuming doesn't already exist 1207 // otherwise, insert assuming doesn't already exist
1213 QString emailsStr = find( Qtopia::Emails ); 1208 QString emailsStr = find( Qtopia::Emails );
1214 if ( emailsStr.contains( e ) ) 1209 if ( emailsStr.contains( e ) )
1215 return ; 1210 return ;
1216 if ( !emailsStr.isEmpty() ) 1211 if ( !emailsStr.isEmpty() )
1217 emailsStr += emailSeparator(); 1212 emailsStr += emailSeparator();
1218 emailsStr += e; 1213 emailsStr += e;
1219 replace( Qtopia::Emails, emailsStr ); 1214 replace( Qtopia::Emails, emailsStr );
1220} 1215}
1221 1216
1222 1217
1223 void OPimContact::removeEmail( const QString &v ) 1218 void OPimContact::removeEmail( const QString &v )
1224{ 1219{
1225 QString e = v.simplifyWhiteSpace(); 1220 QString e = v.simplifyWhiteSpace();
1226 QString def = defaultEmail(); 1221 QString def = defaultEmail();
1227 QString emailsStr = find( Qtopia::Emails ); 1222 QString emailsStr = find( Qtopia::Emails );
1228 QStringList emails = emailList(); 1223 QStringList emails = emailList();
1229 1224
1230 // otherwise, must first contain it 1225 // otherwise, must first contain it
1231 if ( !emailsStr.contains( e ) ) 1226 if ( !emailsStr.contains( e ) )
1232 return ; 1227 return ;
1233 1228
1234 // remove it 1229 // remove it
1235 //odebug << " removing email from list " << e << "" << oendl; 1230 //odebug << " removing email from list " << e << "" << oendl;
1236 emails.remove( e ); 1231 emails.remove( e );
1237 // reset the string 1232 // reset the string
1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1233 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1239 replace( Qtopia::Emails, emailsStr ); 1234 replace( Qtopia::Emails, emailsStr );
1240 1235
1241 // if default, then replace the default email with the first one 1236 // if default, then replace the default email with the first one
1242 if ( def == e ) 1237 if ( def == e )
1243 { 1238 {
1244 //odebug << "removeEmail is default; setting new default" << oendl; 1239 //odebug << "removeEmail is default; setting new default" << oendl;
1245 if ( !emails.count() ) 1240 if ( !emails.count() )
1246 clearEmails(); 1241 clearEmails();
1247 else // setDefaultEmail will remove e from the list 1242 else // setDefaultEmail will remove e from the list
1248 setDefaultEmail( emails.first() ); 1243 setDefaultEmail( emails.first() );
1249 } 1244 }
1250} 1245}
1251 1246
1252 1247
1253void OPimContact::clearEmails() 1248void OPimContact::clearEmails()
1254{ 1249{
1255 mMap.remove( Qtopia::DefaultEmail ); 1250 mMap.remove( Qtopia::DefaultEmail );
1256 mMap.remove( Qtopia::Emails ); 1251 mMap.remove( Qtopia::Emails );
1257} 1252}
1258 1253
1259 1254
1260void OPimContact::setDefaultEmail( const QString &v ) 1255void OPimContact::setDefaultEmail( const QString &v )
1261{ 1256{
1262 QString e = v.simplifyWhiteSpace(); 1257 QString e = v.simplifyWhiteSpace();
1263 1258
1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl; 1259 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
1265 replace( Qtopia::DefaultEmail, e ); 1260 replace( Qtopia::DefaultEmail, e );
1266 1261
1267 if ( !e.isEmpty() ) 1262 if ( !e.isEmpty() )
1268 insertEmail( e ); 1263 insertEmail( e );
1269 1264
1270} 1265}
1271 1266
1272 1267
1273void OPimContact::insertEmails( const QStringList &v ) 1268void OPimContact::insertEmails( const QStringList &v )
1274{ 1269{
1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1270 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1276 insertEmail( *it ); 1271 insertEmail( *it );
1277} 1272}
1278 1273
1279 1274
1280int OPimContact::rtti() const 1275int OPimContact::rtti() const
1281{ 1276{
1282 return OPimResolver::AddressBook; 1277 return OPimResolver::AddressBook;
1283} 1278}
1284 1279
1280/**
1281 * \brief Cast to OPimContact or on failure return 0l
1282 *
1283 * This method tries to cast from a OPimRecord to a
1284 * OPimContact it uses. If the OPimRecord is from type
1285 * OPimContact the case will suceed and a pointer to
1286 * OPimContact is returned otherwise a Null Pointer is returned.
1287 *
1288 *
1289 * @see OPimTodo::safeCast()
1290 * @see OPimEvent::safeCast()
1291 * @return Return a OPimContact or a Null Pointer
1292 */
1293OPimContact* OPimContact::safeCast( const OPimRecord* rec ) {
1294 return( rec && rec->rtti() == OPimResolver::AddressBook ) ?
1295 static_cast<OPimContact*>( const_cast<OPimRecord*>(rec) ) :
1296 0l;
1297}
1298
1285 1299
1286void OPimContact::setUid( int i ) 1300void OPimContact::setUid( int i )
1287{ 1301{
1288 OPimRecord::setUid( i ); 1302 OPimRecord::setUid( i );
1289 replace( Qtopia::AddressUid , QString::number( i ) ); 1303 replace( Qtopia::AddressUid , QString::number( i ) );
1290} 1304}
1291} 1305}
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
index 6891dd6..6fa2c4b 100644
--- a/libopie2/opiepim/core/opimcontact.h
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -135,122 +135,126 @@ class QPC_EXPORT OPimContact : public OPimRecord
135 135
136 // // custom 136 // // custom
137 // void setCustomField( const QString &key, const QString &v ) 137 // void setCustomField( const QString &key, const QString &v )
138 // { replace(Custom- + key, v ); } 138 // { replace(Custom- + key, v ); }
139 139
140 // name 140 // name
141 QString fullName() const; 141 QString fullName() const;
142 QString title() const { return find( Qtopia::Title ); } 142 QString title() const { return find( Qtopia::Title ); }
143 QString firstName() const { return find( Qtopia::FirstName ); } 143 QString firstName() const { return find( Qtopia::FirstName ); }
144 QString middleName() const { return find( Qtopia::MiddleName ); } 144 QString middleName() const { return find( Qtopia::MiddleName ); }
145 QString lastName() const { return find( Qtopia::LastName ); } 145 QString lastName() const { return find( Qtopia::LastName ); }
146 QString suffix() const { return find( Qtopia::Suffix ); } 146 QString suffix() const { return find( Qtopia::Suffix ); }
147 QString fileAs() const { return find( Qtopia::FileAs ); } 147 QString fileAs() const { return find( Qtopia::FileAs ); }
148 148
149 // email 149 // email
150 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } 150 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
151 QStringList emailList() const; 151 QStringList emailList() const;
152 152
153 // home 153 // home
154 /* 154 /*
155 * OPimAddress address(enum Location)const; 155 * OPimAddress address(enum Location)const;
156 * would be some how nicer... 156 * would be some how nicer...
157 * -zecke 157 * -zecke
158 */ 158 */
159 QString homeStreet() const { return find( Qtopia::HomeStreet ); } 159 QString homeStreet() const { return find( Qtopia::HomeStreet ); }
160 QString homeCity() const { return find( Qtopia::HomeCity ); } 160 QString homeCity() const { return find( Qtopia::HomeCity ); }
161 QString homeState() const { return find( Qtopia::HomeState ); } 161 QString homeState() const { return find( Qtopia::HomeState ); }
162 QString homeZip() const { return find( Qtopia::HomeZip ); } 162 QString homeZip() const { return find( Qtopia::HomeZip ); }
163 QString homeCountry() const { return find( Qtopia::HomeCountry ); } 163 QString homeCountry() const { return find( Qtopia::HomeCountry ); }
164 QString homePhone() const { return find( Qtopia::HomePhone ); } 164 QString homePhone() const { return find( Qtopia::HomePhone ); }
165 QString homeFax() const { return find( Qtopia::HomeFax ); } 165 QString homeFax() const { return find( Qtopia::HomeFax ); }
166 QString homeMobile() const { return find( Qtopia::HomeMobile ); } 166 QString homeMobile() const { return find( Qtopia::HomeMobile ); }
167 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } 167 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
168 /** Multi line string containing all non-empty address info in the form 168 /** Multi line string containing all non-empty address info in the form
169 * Street 169 * Street
170 * City, State Zip 170 * City, State Zip
171 * Country 171 * Country
172 */ 172 */
173 QString displayHomeAddress() const; 173 QString displayHomeAddress() const;
174 174
175 // business 175 // business
176 QString company() const { return find( Qtopia::Company ); } 176 QString company() const { return find( Qtopia::Company ); }
177 QString businessStreet() const { return find( Qtopia::BusinessStreet ); } 177 QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
178 QString businessCity() const { return find( Qtopia::BusinessCity ); } 178 QString businessCity() const { return find( Qtopia::BusinessCity ); }
179 QString businessState() const { return find( Qtopia::BusinessState ); } 179 QString businessState() const { return find( Qtopia::BusinessState ); }
180 QString businessZip() const { return find( Qtopia::BusinessZip ); } 180 QString businessZip() const { return find( Qtopia::BusinessZip ); }
181 QString businessCountry() const { return find( Qtopia::BusinessCountry ); } 181 QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
182 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } 182 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
183 QString jobTitle() const { return find( Qtopia::JobTitle ); } 183 QString jobTitle() const { return find( Qtopia::JobTitle ); }
184 QString department() const { return find( Qtopia::Department ); } 184 QString department() const { return find( Qtopia::Department ); }
185 QString office() const { return find( Qtopia::Office ); } 185 QString office() const { return find( Qtopia::Office ); }
186 QString businessPhone() const { return find( Qtopia::BusinessPhone ); } 186 QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
187 QString businessFax() const { return find( Qtopia::BusinessFax ); } 187 QString businessFax() const { return find( Qtopia::BusinessFax ); }
188 QString businessMobile() const { return find( Qtopia::BusinessMobile ); } 188 QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
189 QString businessPager() const { return find( Qtopia::BusinessPager ); } 189 QString businessPager() const { return find( Qtopia::BusinessPager ); }
190 QString profession() const { return find( Qtopia::Profession ); } 190 QString profession() const { return find( Qtopia::Profession ); }
191 QString assistant() const { return find( Qtopia::Assistant ); } 191 QString assistant() const { return find( Qtopia::Assistant ); }
192 QString manager() const { return find( Qtopia::Manager ); } 192 QString manager() const { return find( Qtopia::Manager ); }
193 /** Multi line string containing all non-empty address info in the form 193 /** Multi line string containing all non-empty address info in the form
194 * Street 194 * Street
195 * City, State Zip 195 * City, State Zip
196 * Country 196 * Country
197 */ 197 */
198 QString displayBusinessAddress() const; 198 QString displayBusinessAddress() const;
199 199
200 //personal 200 //personal
201 QString spouse() const { return find( Qtopia::Spouse ); } 201 QString spouse() const { return find( Qtopia::Spouse ); }
202 QString gender() const { return find( Qtopia::Gender ); } 202 QString gender() const { return find( Qtopia::Gender ); }
203 QDate birthday() const; 203 QDate birthday() const;
204 QDate anniversary() const; 204 QDate anniversary() const;
205 QString nickname() const { return find( Qtopia::Nickname ); } 205 QString nickname() const { return find( Qtopia::Nickname ); }
206 QString children() const { return find( Qtopia::Children ); } 206 QString children() const { return find( Qtopia::Children ); }
207 QStringList childrenList() const; 207 QStringList childrenList() const;
208 208
209 // other 209 // other
210 QString notes() const { return find( Qtopia::Notes ); } 210 QString notes() const { return find( Qtopia::Notes ); }
211 QString groups() const { return find( Qtopia::Groups ); } 211 QString groups() const { return find( Qtopia::Groups ); }
212 QStringList groupList() const; 212 QStringList groupList() const;
213 213
214 QString toRichText() const; 214 QString toRichText() const;
215 QMap<int, QString> toMap() const; 215 QMap<int, QString> toMap() const;
216 QString field( int key ) const { return find( key ); } 216 QString field( int key ) const { return find( key ); }
217 217
218 218
219 void setUid( int i ); 219 void setUid( int i );
220 220
221 QString toShortText() const; 221 QString toShortText() const;
222 QString type() const; 222 QString type() const;
223 class QString recordField( int ) const; 223 class QString recordField( int ) const;
224 224
225 // Why private ? (eilers,se) 225 // Why private ? (eilers,se)
226 QString emailSeparator() const { return " "; } 226 QString emailSeparator() const { return " "; }
227 227
228 // the emails should be seperated by a comma 228 // the emails should be seperated by a comma
229 void setEmails( const QString &v ); 229 void setEmails( const QString &v );
230 QString emails() const { return find( Qtopia::Emails ); } 230 QString emails() const { return find( Qtopia::Emails ); }
231
232 //@{
231 int rtti() const; 233 int rtti() const;
234 static OPimContact* safeCast( const OPimRecord* );
235 //@}
232 236
233 private: 237 private:
234 // The XML Backend needs some access to the private functions 238 // The XML Backend needs some access to the private functions
235 friend class OPimContactAccessBackend_XML; 239 friend class OPimContactAccessBackend_XML;
236 240
237 void insert( int key, const QString &value ); 241 void insert( int key, const QString &value );
238 void replace( int key, const QString &value ); 242 void replace( int key, const QString &value );
239 QString find( int key ) const; 243 QString find( int key ) const;
240 static QStringList fields(); 244 static QStringList fields();
241 245
242 void save( QString &buf ) const; 246 void save( QString &buf ) const;
243 247
244 QString displayAddress( const QString &street, 248 QString displayAddress( const QString &street,
245 const QString &city, 249 const QString &city,
246 const QString &state, 250 const QString &state,
247 const QString &zip, 251 const QString &zip,
248 const QString &country ) const; 252 const QString &country ) const;
249 253
250 QMap<int, QString> mMap; 254 QMap<int, QString> mMap;
251 OPimContactPrivate *d; 255 OPimContactPrivate *d;
252}; 256};
253 257
254} 258}
255 259
256#endif 260#endif
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 7bc6c32..1b553d8 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -396,192 +396,211 @@ QString OPimEvent::toRichText() const
396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); 396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
397 } 397 }
398 text += "</h3></b><br><hr><br>"; 398 text += "</h3></b><br><hr><br>";
399 399
400 // location 400 // location
401 if ( !( value = location() ).isEmpty() ) 401 if ( !( value = location() ).isEmpty() )
402 { 402 {
403 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 403 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
404 text += Qtopia::escapeString( value ) + "<br>"; 404 text += Qtopia::escapeString( value ) + "<br>";
405 } 405 }
406 406
407 // all day event 407 // all day event
408 if ( isAllDay() ) 408 if ( isAllDay() )
409 { 409 {
410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
411 } 411 }
412 // multiple day event 412 // multiple day event
413 else if ( isMultipleDay () ) 413 else if ( isMultipleDay () )
414 { 414 {
415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
416 } 416 }
417 // start & end times 417 // start & end times
418 else 418 else
419 { 419 {
420 // start time 420 // start time
421 if ( startDateTime().isValid() ) 421 if ( startDateTime().isValid() )
422 { 422 {
423 text += "<b>" + QObject::tr( "Start:" ) + "</b> "; 423 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
424 text += Qtopia::escapeString( startDateTime().toString() ). 424 text += Qtopia::escapeString( startDateTime().toString() ).
425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
426 } 426 }
427 427
428 // end time 428 // end time
429 if ( endDateTime().isValid() ) 429 if ( endDateTime().isValid() )
430 { 430 {
431 text += "<b>" + QObject::tr( "End:" ) + "</b> "; 431 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
432 text += Qtopia::escapeString( endDateTime().toString() ). 432 text += Qtopia::escapeString( endDateTime().toString() ).
433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
434 } 434 }
435 } 435 }
436 436
437 // categories 437 // categories
438 if ( categoryNames( "Calendar" ).count() ) 438 if ( categoryNames( "Calendar" ).count() )
439 { 439 {
440 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 440 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
441 text += categoryNames( "Calendar" ).join( ", " ); 441 text += categoryNames( "Calendar" ).join( ", " );
442 text += "<br>"; 442 text += "<br>";
443 } 443 }
444 444
445 //notes 445 //notes
446 if ( !note().isEmpty() ) 446 if ( !note().isEmpty() )
447 { 447 {
448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>"; 448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
449 text += note(); 449 text += note();
450 // text += Qtopia::escapeString(note() ). 450 // text += Qtopia::escapeString(note() ).
451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
452 } 452 }
453 return text; 453 return text;
454} 454}
455 455
456 456
457QString OPimEvent::toShortText() const 457QString OPimEvent::toShortText() const
458{ 458{
459 QString text; 459 QString text;
460 text += QString::number( startDateTime().date().day() ); 460 text += QString::number( startDateTime().date().day() );
461 text += "."; 461 text += ".";
462 text += QString::number( startDateTime().date().month() ); 462 text += QString::number( startDateTime().date().month() );
463 text += "."; 463 text += ".";
464 text += QString::number( startDateTime().date().year() ); 464 text += QString::number( startDateTime().date().year() );
465 text += " "; 465 text += " ";
466 text += QString::number( startDateTime().time().hour() ); 466 text += QString::number( startDateTime().time().hour() );
467 text += ":"; 467 text += ":";
468 text += QString::number( startDateTime().time().minute() ); 468 text += QString::number( startDateTime().time().minute() );
469 text += " - "; 469 text += " - ";
470 text += description(); 470 text += description();
471 return text; 471 return text;
472} 472}
473 473
474 474
475QString OPimEvent::type() const 475QString OPimEvent::type() const
476{ 476{
477 return QString::fromLatin1( "OPimEvent" ); 477 return QString::fromLatin1( "OPimEvent" );
478} 478}
479 479
480 480
481QString OPimEvent::recordField( int /*id */ ) const 481QString OPimEvent::recordField( int /*id */ ) const
482{ 482{
483 return QString::null; 483 return QString::null;
484} 484}
485 485
486 486
487int OPimEvent::rtti() const 487int OPimEvent::rtti() const
488{ 488{
489 return OPimResolver::DateBook; 489 return OPimResolver::DateBook;
490} 490}
491 491
492/**
493 * \brief Cast safely to OPimEvent from OPimRecord
494 *
495 * Safely cast from OPimRecord to OPimEvent. If the
496 * OPimRecord is not of type OPimEvent Null will be
497 * returned.
498 *
499 * @param rec The OPimRecord to be casted to OPimEvent
500 *
501 * @see OPimTodo::safeCast
502 * @return OPimEvent or Null Pointer
503 */
504OPimEvent* OPimEvent::safeCast( const OPimRecord* rec) {
505 return ( rec && rec->rtti() == OPimResolver::DateBook ) ?
506 static_cast<OPimEvent*>( const_cast<OPimRecord*>(rec) ) :
507 0l;
508}
509
510
492 511
493bool OPimEvent::loadFromStream( QDataStream& ) 512bool OPimEvent::loadFromStream( QDataStream& )
494{ 513{
495 return true; 514 return true;
496} 515}
497 516
498 517
499bool OPimEvent::saveToStream( QDataStream& ) const 518bool OPimEvent::saveToStream( QDataStream& ) const
500{ 519{
501 return true; 520 return true;
502} 521}
503 522
504 523
505void OPimEvent::changeOrModify() 524void OPimEvent::changeOrModify()
506{ 525{
507 if ( data->count != 1 ) 526 if ( data->count != 1 )
508 { 527 {
509 data->deref(); 528 data->deref();
510 Data* d2 = new Data; 529 Data* d2 = new Data;
511 d2->description = data->description; 530 d2->description = data->description;
512 d2->location = data->location; 531 d2->location = data->location;
513 532
514 if ( data->manager ) 533 if ( data->manager )
515 d2->manager = new OPimNotifyManager( *data->manager ); 534 d2->manager = new OPimNotifyManager( *data->manager );
516 535
517 if ( data->recur ) 536 if ( data->recur )
518 d2->recur = new OPimRecurrence( *data->recur ); 537 d2->recur = new OPimRecurrence( *data->recur );
519 538
520 d2->note = data->note; 539 d2->note = data->note;
521 d2->created = data->created; 540 d2->created = data->created;
522 d2->start = data->start; 541 d2->start = data->start;
523 d2->end = data->end; 542 d2->end = data->end;
524 d2->isAllDay = data->isAllDay; 543 d2->isAllDay = data->isAllDay;
525 d2->timezone = data->timezone; 544 d2->timezone = data->timezone;
526 d2->parent = data->parent; 545 d2->parent = data->parent;
527 546
528 if ( data->child ) 547 if ( data->child )
529 { 548 {
530 d2->child = new QArray<int>( *data->child ); 549 d2->child = new QArray<int>( *data->child );
531 d2->child->detach(); 550 d2->child->detach();
532 } 551 }
533 552
534 data = d2; 553 data = d2;
535 } 554 }
536} 555}
537 556
538 557
539void OPimEvent::deref() 558void OPimEvent::deref()
540{ 559{
541 if ( data->deref() ) 560 if ( data->deref() )
542 { 561 {
543 delete data; 562 delete data;
544 data = 0; 563 data = 0;
545 } 564 }
546} 565}
547// Exporting Event data to map. Using the same 566// Exporting Event data to map. Using the same
548// encoding as ODateBookAccessBackend_xml does.. 567// encoding as ODateBookAccessBackend_xml does..
549// Thus, we could remove the stuff there and use this 568// Thus, we could remove the stuff there and use this
550// for it and for all other places.. 569// for it and for all other places..
551// Encoding should happen at one place, only ! (eilers) 570// Encoding should happen at one place, only ! (eilers)
552QMap<int, QString> OPimEvent::toMap() const 571QMap<int, QString> OPimEvent::toMap() const
553{ 572{
554 QMap<int, QString> retMap; 573 QMap<int, QString> retMap;
555 574
556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 575 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 576 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 577 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 578 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 579 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
561 if ( notifiers().alarms().count() ){ 580 if ( notifiers().alarms().count() ){
562 // Currently we just support one alarm.. (eilers) 581 // Currently we just support one alarm.. (eilers)
563 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 582 OPimAlarm alarm = notifiers().alarms() [ 0 ];
564 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 583 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
565 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 584 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
566 } 585 }
567 586
568 /* either use UTC timeZone or current() if there is was a timezone set */ 587 /* either use UTC timeZone or current() if there is was a timezone set */
569 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); 588 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
570 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime()))); 589 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
571 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() ))); 590 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
572 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 591 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
573 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 592 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
574 if ( parent() ) 593 if ( parent() )
575 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 594 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
576 if ( children().count() ) 595 if ( children().count() )
577 { 596 {
578 QArray<int> childr = children(); 597 QArray<int> childr = children();
579 QString buf; 598 QString buf;
580 for ( uint i = 0; i < childr.count(); i++ ) 599 for ( uint i = 0; i < childr.count(); i++ )
581 { 600 {
582 if ( i != 0 ) buf += " "; 601 if ( i != 0 ) buf += " ";
583 buf += QString::number( childr[ i ] ); 602 buf += QString::number( childr[ i ] );
584 } 603 }
585 retMap.insert( OPimEvent::FRecChildren, buf ); 604 retMap.insert( OPimEvent::FRecChildren, buf );
586 } 605 }
587 606
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h
index 5553cac..32f648f 100644
--- a/libopie2/opiepim/core/opimevent.h
+++ b/libopie2/opiepim/core/opimevent.h
@@ -25,251 +25,265 @@
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29// CONTAINS GPLed code of TT 29// CONTAINS GPLed code of TT
30 30
31#ifndef OEVENT_H 31#ifndef OEVENT_H
32#define OEVENT_H 32#define OEVENT_H
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimtimezone.h> 35#include <opie2/opimtimezone.h>
36#include <opie2/opimrecord.h> 36#include <opie2/opimrecord.h>
37#include <qpe/recordfields.h> 37#include <qpe/recordfields.h>
38#include <qpe/palmtopuidgen.h> 38#include <qpe/palmtopuidgen.h>
39 39
40/* QT */ 40/* QT */
41#include <qstring.h> 41#include <qstring.h>
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qvaluelist.h> 43#include <qvaluelist.h>
44 44
45namespace Opie 45namespace Opie
46{ 46{
47struct OCalendarHelper 47struct OCalendarHelper
48{ 48{
49 /** calculate the week number of the date */ 49 /** calculate the week number of the date */
50 static int week( const QDate& ); 50 static int week( const QDate& );
51 /** calculate the occurence of week days since the start of the month */ 51 /** calculate the occurence of week days since the start of the month */
52 static int ocurrence( const QDate& ); 52 static int ocurrence( const QDate& );
53 53
54 // returns the dayOfWeek for the *first* day it finds (ignores 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 55 // any further days!). Returns 1 (Monday) if there isn't any day found
56 static int dayOfWeek( char day ); 56 static int dayOfWeek( char day );
57 57
58 /** returns the diff of month */ 58 /** returns the diff of month */
59 static int monthDiff( const QDate& first, const QDate& second ); 59 static int monthDiff( const QDate& first, const QDate& second );
60 60
61}; 61};
62 62
63class OPimNotifyManager; 63class OPimNotifyManager;
64class OPimRecurrence; 64class OPimRecurrence;
65 65
66/** 66/**
67 * This is the container for all Events. It encapsules all 67 * This is the container for all Events. It encapsules all
68 * available information for a single Event 68 * available information for a single Event
69 * @short container for events. 69 * @short container for events.
70 */ 70 */
71class OPimEvent : public OPimRecord 71class OPimEvent : public OPimRecord
72{ 72{
73 public: 73 public:
74 typedef QValueList<OPimEvent> ValueList; 74 typedef QValueList<OPimEvent> ValueList;
75 /** 75 /**
76 * RecordFields contain possible attributes 76 * RecordFields contain possible attributes
77 * used in the Results of toMap().. 77 * used in the Results of toMap()..
78 */ 78 */
79 enum RecordFields { 79 enum RecordFields {
80 FUid = Qtopia::UID_ID, 80 FUid = Qtopia::UID_ID,
81 FCategories = Qtopia::CATEGORY_ID, 81 FCategories = Qtopia::CATEGORY_ID,
82 FDescription /* = 0 Why this ? (eilers) */, 82 FDescription /* = 0 Why this ? (eilers) */,
83 FLocation, 83 FLocation,
84 FType, 84 FType,
85 FAlarm, 85 FAlarm,
86 FSound, 86 FSound,
87 FRType, 87 FRType,
88 FRWeekdays, 88 FRWeekdays,
89 FRPosition, 89 FRPosition,
90 FRFreq, 90 FRFreq,
91 FRHasEndDate, 91 FRHasEndDate,
92 FREndDate, 92 FREndDate,
93 FRCreated, 93 FRCreated,
94 FRExceptions, 94 FRExceptions,
95 FStart, 95 FStart,
96 FEnd, 96 FEnd,
97 FNote, 97 FNote,
98 FTimeZone, 98 FTimeZone,
99 FRecParent, 99 FRecParent,
100 FRecChildren, 100 FRecChildren,
101 }; 101 };
102 102
103 /** 103 /**
104 * Start with an Empty OPimEvent. UID == 0 means that it is empty 104 * Start with an Empty OPimEvent. UID == 0 means that it is empty
105 */ 105 */
106 OPimEvent( int uid = 0 ); 106 OPimEvent( int uid = 0 );
107 107
108 /** 108 /**
109 * copy c'tor 109 * copy c'tor
110 */ 110 */
111 OPimEvent( const OPimEvent& ); 111 OPimEvent( const OPimEvent& );
112 112
113 /** 113 /**
114 * Create OPimEvent, initialized by map 114 * Create OPimEvent, initialized by map
115 * @see enum RecordFields 115 * @see enum RecordFields
116 */ 116 */
117 OPimEvent( const QMap<int, QString> map ); 117 OPimEvent( const QMap<int, QString> map );
118 ~OPimEvent(); 118 ~OPimEvent();
119 OPimEvent &operator=( const OPimEvent& ); 119 OPimEvent &operator=( const OPimEvent& );
120 120
121 //@{
121 QString description() const; 122 QString description() const;
122 void setDescription( const QString& description ); 123 void setDescription( const QString& description );
123 124
124 QString location() const; 125 QString location() const;
125 void setLocation( const QString& loc ); 126 void setLocation( const QString& loc );
127 //@}
126 128
129 //@{
127 bool hasNotifiers() const; 130 bool hasNotifiers() const;
128 OPimNotifyManager &notifiers() const; 131 OPimNotifyManager &notifiers() const;
132 //@}
129 133
134 //@{
130 OPimRecurrence recurrence() const; 135 OPimRecurrence recurrence() const;
131 void setRecurrence( const OPimRecurrence& ); 136 void setRecurrence( const OPimRecurrence& );
132 bool hasRecurrence() const; 137 bool hasRecurrence() const;
138 //@}
133 139
140 //@{
134 QString note() const; 141 QString note() const;
135 void setNote( const QString& note ); 142 void setNote( const QString& note );
143 //@}
136 144
137 145
138 QDateTime createdDateTime() const; 146 QDateTime createdDateTime() const;
139 void setCreatedDateTime( const QDateTime& dt ); 147 void setCreatedDateTime( const QDateTime& dt );
140 148
141 /** set the date to dt. dt is the QDateTime in localtime */ 149 /** set the date to dt. dt is the QDateTime in localtime */
142 void setStartDateTime( const QDateTime& ); 150 void setStartDateTime( const QDateTime& );
143 /** returns the datetime in the local timeZone */ 151 /** returns the datetime in the local timeZone */
144 QDateTime startDateTime() const; 152 QDateTime startDateTime() const;
145 153
146 /** returns the start datetime in the current zone */ 154 /** returns the start datetime in the current zone */
147 QDateTime startDateTimeInZone() const; 155 QDateTime startDateTimeInZone() const;
148 156
149 /** in current timezone */ 157 /** in current timezone */
150 void setEndDateTime( const QDateTime& ); 158 void setEndDateTime( const QDateTime& );
151 /** in current timezone */ 159 /** in current timezone */
152 QDateTime endDateTime() const; 160 QDateTime endDateTime() const;
153 QDateTime endDateTimeInZone() const; 161 QDateTime endDateTimeInZone() const;
154 162
155 bool isMultipleDay() const; 163 bool isMultipleDay() const;
156 bool isAllDay() const; 164 bool isAllDay() const;
157 void setAllDay( bool isAllDay ); 165 void setAllDay( bool isAllDay );
158 166
159 /* pin this event to a timezone! FIXME */ 167 /* pin this event to a timezone! FIXME */
160 void setTimeZone( const QString& timeZone ); 168 void setTimeZone( const QString& timeZone );
161 QString timeZone() const; 169 QString timeZone() const;
162 170
163 171
164 virtual bool match( const QRegExp& ) const; 172 //@{
165
166 /** For exception to recurrence here is a list of children... */ 173 /** For exception to recurrence here is a list of children... */
167 QArray<int> children() const; 174 QArray<int> children() const;
168 void setChildren( const QArray<int>& ); 175 void setChildren( const QArray<int>& );
169 void addChild( int uid ); 176 void addChild( int uid );
170 void removeChild( int uid ); 177 void removeChild( int uid );
178 //@}
171 179
172 /** return the parent OPimEvent */ 180 /** return the parent OPimEvent */
173 int parent() const; 181 int parent() const;
174 void setParent( int uid ); 182 void setParent( int uid );
175 183
176 184
177 /* needed reimp */ 185 /* needed reimp */
186 //@{ Reimplementations
187 virtual bool match( const QRegExp& ) const;
178 QString toRichText() const; 188 QString toRichText() const;
179 QString toShortText() const; 189 QString toShortText() const;
180 QString type() const; 190 QString type() const;
181 191
182 QMap<int, QString> toMap() const; 192 QMap<int, QString> toMap() const;
183 void fromMap( const QMap<int, QString>& map ); 193 void fromMap( const QMap<int, QString>& map );
184 QString recordField( int ) const; 194 QString recordField( int ) const;
185 195
186 int rtti() const;
187
188 bool loadFromStream( QDataStream& ); 196 bool loadFromStream( QDataStream& );
189 bool saveToStream( QDataStream& ) const; 197 bool saveToStream( QDataStream& ) const;
198 //@}
199
200 //@{
201 int rtti() const;
202 static OPimEvent* safeCast( const OPimRecord* );
203 //@}
190 204
191 /* bool operator==( const OPimEvent& ); 205 /* bool operator==( const OPimEvent& );
192 bool operator!=( const OPimEvent& ); 206 bool operator!=( const OPimEvent& );
193 bool operator<( const OPimEvent& ); 207 bool operator<( const OPimEvent& );
194 bool operator<=( const OPimEvent& ); 208 bool operator<=( const OPimEvent& );
195 bool operator>( const OPimEvent& ); 209 bool operator>( const OPimEvent& );
196 bool operator>=(const OPimEvent& ); 210 bool operator>=(const OPimEvent& );
197 */ 211 */
198 212
199 private: 213 private:
200 inline void changeOrModify(); 214 inline void changeOrModify();
201 void deref(); 215 void deref();
202 struct Data; 216 struct Data;
203 Data* data; 217 Data* data;
204 class Private; 218 class Private;
205 Private* priv; 219 Private* priv;
206 220
207}; 221};
208 222
209/** 223/**
210 * AN Event can span through multiple days. We split up a multiday eve 224 * AN Event can span through multiple days. We split up a multiday eve
211 */ 225 */
212class OEffectiveEvent 226class OEffectiveEvent
213{ 227{
214 228
215 public: 229 public:
216 typedef QValueList<OEffectiveEvent> ValueList; 230 typedef QValueList<OEffectiveEvent> ValueList;
217 enum Position { MidWay, Start, End, StartEnd }; 231 enum Position { MidWay, Start, End, StartEnd };
218 // If we calculate the effective event of a multi-day event 232 // If we calculate the effective event of a multi-day event
219 // we have to figure out whether we are at the first day, 233 // we have to figure out whether we are at the first day,
220 // at the end, or anywhere else ("middle"). This is important 234 // at the end, or anywhere else ("middle"). This is important
221 // for the start/end times (00:00/23:59) 235 // for the start/end times (00:00/23:59)
222 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- 236 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
223 // day event 237 // day event
224 // Start: start time -> 23:59 238 // Start: start time -> 23:59
225 // End: 00:00 -> end time 239 // End: 00:00 -> end time
226 // Start | End == StartEnd: for single-day events (default) 240 // Start | End == StartEnd: for single-day events (default)
227 // here we draw start time -> end time 241 // here we draw start time -> end time
228 OEffectiveEvent(); 242 OEffectiveEvent();
229 OEffectiveEvent( const OPimEvent& event, const QDate& startDate, Position pos = StartEnd ); 243 OEffectiveEvent( const OPimEvent& event, const QDate& startDate, Position pos = StartEnd );
230 OEffectiveEvent( const OEffectiveEvent& ); 244 OEffectiveEvent( const OEffectiveEvent& );
231 OEffectiveEvent &operator=( const OEffectiveEvent& ); 245 OEffectiveEvent &operator=( const OEffectiveEvent& );
232 ~OEffectiveEvent(); 246 ~OEffectiveEvent();
233 247
234 void setStartTime( const QTime& ); 248 void setStartTime( const QTime& );
235 void setEndTime( const QTime& ); 249 void setEndTime( const QTime& );
236 void setEvent( const OPimEvent& ); 250 void setEvent( const OPimEvent& );
237 void setDate( const QDate& ); 251 void setDate( const QDate& );
238 252
239 void setEffectiveDates( const QDate& from, const QDate& to ); 253 void setEffectiveDates( const QDate& from, const QDate& to );
240 254
241 QString description() const; 255 QString description() const;
242 QString location() const; 256 QString location() const;
243 QString note() const; 257 QString note() const;
244 OPimEvent event() const; 258 OPimEvent event() const;
245 QTime startTime() const; 259 QTime startTime() const;
246 QTime endTime() const; 260 QTime endTime() const;
247 QDate date() const; 261 QDate date() const;
248 262
249 /* return the length in hours */ 263 /* return the length in hours */
250 int length() const; 264 int length() const;
251 int size() const; 265 int size() const;
252 266
253 QDate startDate() const; 267 QDate startDate() const;
254 QDate endDate() const; 268 QDate endDate() const;
255 269
256 bool operator<( const OEffectiveEvent &e ) const; 270 bool operator<( const OEffectiveEvent &e ) const;
257 bool operator<=( const OEffectiveEvent &e ) const; 271 bool operator<=( const OEffectiveEvent &e ) const;
258 bool operator==( const OEffectiveEvent &e ) const; 272 bool operator==( const OEffectiveEvent &e ) const;
259 bool operator!=( const OEffectiveEvent &e ) const; 273 bool operator!=( const OEffectiveEvent &e ) const;
260 bool operator>( const OEffectiveEvent &e ) const; 274 bool operator>( const OEffectiveEvent &e ) const;
261 bool operator>= ( const OEffectiveEvent &e ) const; 275 bool operator>= ( const OEffectiveEvent &e ) const;
262 276
263 private: 277 private:
264 void deref(); 278 void deref();
265 inline void changeOrModify(); 279 inline void changeOrModify();
266 class Private; 280 class Private;
267 Private* priv; 281 Private* priv;
268 struct Data; 282 struct Data;
269 Data* data; 283 Data* data;
270 284
271}; 285};
272 286
273} 287}
274 288
275#endif 289#endif
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h
index 3925c89..9d319a1 100644
--- a/libopie2/opiepim/core/opimglobal.h
+++ b/libopie2/opiepim/core/opimglobal.h
@@ -1,64 +1,76 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef __OPIMGLOBAL_H_ 29#ifndef __OPIMGLOBAL_H_
30#define __OPIMGLOBAL_H_ 30#define __OPIMGLOBAL_H_
31 31
32#include <qarray.h>
33
32namespace Opie{ 34namespace Opie{
35
36/**
37 * The unique identifier for every
38 * PIM record. For now it is a negative
39 * int but we could change it to long or QUuid
40 * in the future
41 */
42typedef int UID;
43typedef QArray<UID> UIDArray;
44
33namespace Pim{ 45namespace Pim{
34 46
35 47
36 /** 48 /**
37 * Contains global types and enums for the PIM-API 49 * Contains global types and enums for the PIM-API
38 */ 50 */
39class OPimGlobal{ 51class OPimGlobal{
40 public: 52 public:
41 enum PimType { 53 enum PimType {
42 TODOLIST, 54 TODOLIST,
43 CONTACTLIST, 55 CONTACTLIST,
44 DATEBOOK, 56 DATEBOOK,
45 _END_PimType 57 _END_PimType
46 }; 58 };
47 59
48 enum DatabaseStyle { 60 enum DatabaseStyle {
49 DEFAULT, // Use default Database 61 DEFAULT, // Use default Database
50 UNKNOWN, // Unknown database style 62 UNKNOWN, // Unknown database style
51 XML, 63 XML,
52 SQL, 64 SQL,
53 VCARD, // Also used for VCAL ! 65 VCARD, // Also used for VCAL !
54 _END_DatabaseStyle 66 _END_DatabaseStyle
55 }; 67 };
56 68
57 69
58}; 70};
59 71
60} 72}
61} 73}
62 74
63 75
64#endif 76#endif
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 516dc79..77cd922 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -71,180 +71,175 @@ void OPimNotifyManager::remove( const OPimNotify& noti )
71 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 71 const OPimReminder & rem = static_cast<const OPimReminder&>( noti );
72 m_rem.remove( rem ); 72 m_rem.remove( rem );
73 } 73 }
74 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 74 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) )
75 { 75 {
76 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 76 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
77 m_al.remove( al ); 77 m_al.remove( al );
78 } 78 }
79} 79}
80 80
81 81
82void OPimNotifyManager::replace( const OPimNotify& noti ) 82void OPimNotifyManager::replace( const OPimNotify& noti )
83{ 83{
84 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 84 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) )
85 { 85 {
86 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 86 const OPimReminder & rem = static_cast<const OPimReminder&>( noti );
87 m_rem.remove( rem ); 87 m_rem.remove( rem );
88 m_rem.append( rem ); 88 m_rem.append( rem );
89 } 89 }
90 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 90 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) )
91 { 91 {
92 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 92 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
93 m_al.remove( al ); 93 m_al.remove( al );
94 m_al.append( al ); 94 m_al.append( al );
95 } 95 }
96} 96}
97 97
98 98
99OPimNotifyManager::Reminders OPimNotifyManager::reminders() const 99OPimNotifyManager::Reminders OPimNotifyManager::reminders() const
100{ 100{
101 return m_rem; 101 return m_rem;
102} 102}
103 103
104 104
105OPimNotifyManager::Alarms OPimNotifyManager::alarms() const 105OPimNotifyManager::Alarms OPimNotifyManager::alarms() const
106{ 106{
107 return m_al; 107 return m_al;
108} 108}
109 109
110 110
111OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const 111OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const
112{ 112{
113 Alarms::ConstIterator it; 113 Alarms::ConstIterator it;
114 found = true; 114 found = true;
115 115
116 for ( it = m_al.begin(); it != m_al.end(); ++it ) 116 for ( it = m_al.begin(); it != m_al.end(); ++it )
117 { 117 {
118 if ( ( *it ).dateTime() == when ) 118 if ( ( *it ).dateTime() == when )
119 return ( *it ); 119 return ( *it );
120 } 120 }
121 121
122 // Fall through if nothing could be found 122 // Fall through if nothing could be found
123 found = false; 123 found = false;
124 OPimAlarm empty; 124 OPimAlarm empty;
125 return empty; 125 return empty;
126} 126}
127 127
128 128
129void OPimNotifyManager::setAlarms( const Alarms& al ) 129void OPimNotifyManager::setAlarms( const Alarms& al )
130{ 130{
131 m_al = al; 131 m_al = al;
132} 132}
133 133
134 134
135void OPimNotifyManager::setReminders( const Reminders& rem ) 135void OPimNotifyManager::setReminders( const Reminders& rem )
136{ 136{
137 m_rem = rem; 137 m_rem = rem;
138} 138}
139 139
140 140
141/* FIXME!!! */ 141/* FIXME!!! */
142/** 142/**
143 * The idea is to check if the provider for our service 143 * The idea is to check if the provider for our service
144 * is online 144 * is online
145 * if it is we will use QCOP 145 * if it is we will use QCOP
146 * if not the Factory to get the backend... 146 * if not the Factory to get the backend...
147 * Qtopia1.6 services would be kewl to have here.... 147 * Qtopia1.6 services would be kewl to have here....
148 */ 148 */
149void OPimNotifyManager::registerNotify( const OPimNotify& ) 149void OPimNotifyManager::registerNotify( const OPimNotify& )
150{ 150{
151} 151}
152 152
153 153
154/* FIXME!!! */ 154/* FIXME!!! */
155/** 155/**
156 * same as above... 156 * same as above...
157 * Also implement Url model 157 * Also implement Url model
158 * have a MainWindow.... 158 * have a MainWindow....
159 */ 159 */
160void OPimNotifyManager::deregister( const OPimNotify& ) 160void OPimNotifyManager::deregister( const OPimNotify& )
161{ 161{
162} 162}
163 163
164 164
165bool OPimNotifyManager::isEmpty() const 165bool OPimNotifyManager::isEmpty() const
166{ 166{
167 owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl;
168 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 167 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
169 else return false; 168 else return false;
170} 169}
171 170
172 171
173// Taken from otodoaccessxml.. code duplication bad. any alternative? 172// Taken from otodoaccessxml.. code duplication bad. any alternative?
174QString OPimNotifyManager::alarmsToString() const 173QString OPimNotifyManager::alarmsToString() const
175{ 174{
176 QString str; 175 QString str;
177 176
178 OPimNotifyManager::Alarms alarms = m_al; 177 OPimNotifyManager::Alarms alarms = m_al;
179 if ( !alarms.isEmpty() ) 178 if ( !alarms.isEmpty() )
180 { 179 {
181 QStringList als; 180 QStringList als;
182 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 181 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
183 for ( ; it != alarms.end(); ++it ) 182 for ( ; it != alarms.end(); ++it )
184 { 183 {
185 /* only if time is valid */ 184 /* only if time is valid */
186 if ( ( *it ).dateTime().isValid() ) 185 if ( ( *it ).dateTime().isValid() )
187 { 186 {
188 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() ) 187 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() )
189 + ":" + QString::number( ( *it ).duration() ) 188 + ":" + QString::number( ( *it ).duration() )
190 + ":" + QString::number( ( *it ).sound() ) 189 + ":" + QString::number( ( *it ).sound() )
191 + ":"; 190 + ":";
192 } 191 }
193 } 192 }
194 // now write the list 193 // now write the list
195 owarn << "als: " << als.join( "____________" ) << "" << oendl;
196 str = als.join( ";" ); 194 str = als.join( ";" );
197 } 195 }
198 196
199 return str; 197 return str;
200} 198}
201 199
202 200
203QString OPimNotifyManager::remindersToString() const 201QString OPimNotifyManager::remindersToString() const
204{ 202{
205 QString str; 203 QString str;
206 204
207 OPimNotifyManager::Reminders reminders = m_rem; 205 OPimNotifyManager::Reminders reminders = m_rem;
208 if ( !reminders.isEmpty() ) 206 if ( !reminders.isEmpty() )
209 { 207 {
210 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 208 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
211 QStringList records; 209 QStringList records;
212 for ( ; it != reminders.end(); ++it ) 210 for ( ; it != reminders.end(); ++it )
213 { 211 {
214 records << QString::number( ( *it ).recordUid() ); 212 records << QString::number( ( *it ).recordUid() );
215 } 213 }
216 str = records.join( ";" ); 214 str = records.join( ";" );
217 } 215 }
218 216
219 return str; 217 return str;
220} 218}
221 219
222 220
223void OPimNotifyManager::alarmsFromString( const QString& str ) 221void OPimNotifyManager::alarmsFromString( const QString& str )
224{ 222{
225 QStringList als = QStringList::split( ";", str ); 223 QStringList als = QStringList::split( ";", str );
226 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) 224 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it )
227 { 225 {
228 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 226 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
229 owarn << "alarm: " << alarm.join( "___" ) << "" << oendl;
230 owarn << "alarm[0]: " << alarm[ 0 ] << " "
231 << OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString() << oendl;
232 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), 227 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
233 alarm[ 1 ].toInt() ); 228 alarm[ 1 ].toInt() );
234 add( al ); 229 add( al );
235 } 230 }
236} 231}
237 232
238 233
239void OPimNotifyManager::remindersFromString( const QString& str ) 234void OPimNotifyManager::remindersFromString( const QString& str )
240{ 235{
241 236
242 QStringList rems = QStringList::split( ";", str ); 237 QStringList rems = QStringList::split( ";", str );
243 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) 238 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it )
244 { 239 {
245 OPimReminder rem( ( *it ).toInt() ); 240 OPimReminder rem( ( *it ).toInt() );
246 add( rem ); 241 add( rem );
247 } 242 }
248 243
249} 244}
250} 245}
diff --git a/libopie2/opiepim/core/opimoccurrence.cpp b/libopie2/opiepim/core/opimoccurrence.cpp
new file mode 100644
index 0000000..14ab5cf
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.cpp
@@ -0,0 +1,319 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.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 "opimoccurrence.h"
31#include <opie2/opimtemplatebase.h>
32#include <opie2/private/opimoccurrence_p.h>
33
34
35/* QT */
36#include <qshared.h>
37
38
39namespace Opie {
40
41OPimOccurrence::OPimOccurrence( OPimOccurrence::Data* _data,
42 enum OPimOccurrence::Position pos )
43 : m_pos( pos ), data( _data )
44{}
45
46/**
47 * \brief Copy constructor
48 */
49OPimOccurrence::OPimOccurrence( const OPimOccurrence& oc )
50 : data( oc.data )
51{
52 /*
53 * Increment the reference count
54 */
55 data->ref();
56
57 /*
58 * copy the other information
59 */
60 m_start = oc.m_start;
61 m_end = oc.m_end;
62 m_occurrence = oc.m_occurrence;
63 m_isAllDay = oc.m_isAllDay;
64 m_pos = oc.m_pos;
65}
66
67OPimOccurrence::OPimOccurrence()
68 : m_isAllDay( false ), m_pos( StartEnd )
69{
70 /* simple convient c'tor */
71 data = new OPimOccurrence::Data();
72}
73
74OPimOccurrence::~OPimOccurrence() {
75 deref();
76}
77
78/**
79 * \brief Copy Operator
80 */
81OPimOccurrence& OPimOccurrence::operator=( const OPimOccurrence& oc ) {
82 /* guard against self assignment */
83 if ( this == &oc ) return *this;
84
85 oc.data->ref();
86 deref();
87 data = oc.data;
88
89
90 /*
91 * copy the other information
92 */
93 m_start = oc.m_start;
94 m_end = oc.m_end;
95 m_occurrence = oc.m_occurrence;
96 m_isAllDay = oc.m_isAllDay;
97 m_pos = oc.m_pos;
98
99 return *this;
100}
101
102
103/**
104 * @internal
105 */
106void OPimOccurrence::deref() {
107 if ( data->deref() ) {
108 delete data;
109 data = 0;
110 }
111}
112
113/**
114 * \brief Set the Occurrence to be All Day on a specified QDate
115 *
116 * If no QTime is associated to a OPimOccurrence use this Method
117 * to set the Period of this Occurrence. When using this Method
118 * later calls to \sa isAllDay() will return true.
119 * The Occurrence will be set to occurr on \par from.
120 *
121 * @param from The Day this OPimOccurrence occurs
122 *
123 */
124void OPimOccurrence::setPeriod( const QDate& from ) {
125 m_occurrence = from;
126 m_start = m_end = QTime(); // assign invalid value just in case
127 m_isAllDay = true;
128}
129
130/**
131 * \brief Set the period of this Occurrence with a QTime associated (overloaded)
132 *
133 * Set the period of time for this Occurrence. Each Ocurrence is limited
134 * to one day. Using this Method will make \sa isAllDay() return false.
135 * If \par from and \par to are on two different days the QDate of the
136 * \par from QDateTime will be used.
137 *
138 * @param from The Start Date Time of the Occurrence
139 * @param to The End Date Time of the Occurrence
140 */
141void OPimOccurrence::setPeriod( const QDateTime& from, const QDateTime& to ) {
142 m_occurrence = from.date();
143 m_start = from.time();
144 m_end = to.time();
145 m_isAllDay = false;
146}
147
148/**
149 * \brief Set the period of this Occurrence with a QTime associated
150 *
151 * @param from The QDate of the Occurrence
152 * @param start The Start QTime of the Occurrence
153 * @param end The End QTime of the Occurrence
154 */
155void OPimOccurrence::setPeriod( const QDate& from, const QTime& start,
156 const QTime& end ) {
157 m_occurrence = from;
158 m_start = start;
159 m_end = end;
160 m_isAllDay = false;
161}
162
163
164/**
165 * \brief Is a QTime associated to the OPimOccurrence
166 *
167 * @return Return true if no QTime is associated
168 */
169bool OPimOccurrence::isAllDay()const {
170 return m_isAllDay;
171}
172
173
174/**
175 * \brief Return the QDate where this OPimOccurrence takes place
176 * @return the QDate where this OPimOccurrence occurrs.
177 */
178QDate OPimOccurrence::date()const {
179 return m_occurrence;
180}
181
182
183/**
184 * \brief Return the start time of the OPimOccurrence
185 *
186 * @return Return the Start Time of the OPimOccurrence. It is
187 * invalid if \sa isAllDay() returns true.
188 */
189QTime OPimOccurrence::startTime()const {
190 return m_start;
191}
192
193QTime OPimOccurrence::endTime()const {
194 return m_end;
195}
196
197QDateTime OPimOccurrence::startDateTime()const {
198 return QDateTime( m_occurrence, m_start );
199}
200
201QDateTime OPimOccurrence::endDateTime()const {
202 return QDateTime( m_occurrence, m_end );
203}
204
205
206QString OPimOccurrence::summary()const {
207 return data->summary;
208}
209
210QString OPimOccurrence::location()const {
211 return data->location;
212}
213
214QString OPimOccurrence::note()const {
215 return data->note;
216}
217
218
219/**
220 * -1 if no time is associated
221 * otherwise the length of the occurrence in hours
222 */
223int OPimOccurrence::length()const {
224 if ( m_isAllDay )
225 return -1;
226 else
227 return ( m_end.hour() * 60 - m_start.hour() * 60 )
228 + QABS( m_start.minute() - m_end.minute() );
229}
230
231enum OPimOccurrence::Position OPimOccurrence::position()const {
232 return m_pos;
233}
234
235void OPimOccurrence::setPosition( enum OPimOccurrence::Position& pos ) {
236 m_pos = pos;
237}
238
239
240Opie::Core::OSharedPointer<OPimRecord> OPimOccurrence::record()const {
241 if ( !data->record && data->backend )
242 data->record = data->backend->record( data->uid );
243 return data->record;
244}
245
246template<class Record> Record OPimOccurrence::internalToRecord()const {
247 Record target;
248
249 /* If it is not loaded, try to load it using OPimBase */
250 if ( !data->record && data->backend )
251 data->record = data->backend->record( data->uid );
252
253 Record *ta = Record::safeCast( data->record );
254 if ( ta )
255 target = *ta;
256
257
258 return target;
259}
260
261OPimEvent OPimOccurrence::toEvent()const {
262 return internalToRecord<OPimEvent>();
263}
264
265OPimTodo OPimOccurrence::toTodo()const {
266 return internalToRecord<OPimTodo>();
267}
268
269OPimContact OPimOccurrence::toContact()const {
270 return internalToRecord<OPimContact>();
271}
272
273bool OPimOccurrence::operator<( const OPimOccurrence& oc )const {
274 if ( m_occurrence < oc.m_occurrence )
275 return true;
276 if ( m_occurrence == oc.m_occurrence )
277 return m_start < oc.m_start;
278 else
279 return false;
280}
281
282bool OPimOccurrence::operator<=( const OPimOccurrence& oc )const {
283 return ( m_occurrence <= oc.m_occurrence );
284}
285
286bool OPimOccurrence::operator==( const OPimOccurrence& oc )const {
287 if ( data->uid != oc.data->uid )
288 return false;
289 if ( m_occurrence != oc.m_occurrence )
290 return false;
291 if ( m_isAllDay != oc.m_isAllDay )
292 return false;
293 if ( m_isAllDay && oc.m_isAllDay )
294 if ( m_start != oc.m_start ||
295 m_end != oc.m_end )
296 return false;
297 if ( data->summary != oc.data->summary )
298 return false;
299 if ( data->note != oc.data->note )
300 return false;
301 if ( data->location != oc.data->location )
302 return false;
303
304 return true;
305}
306
307bool OPimOccurrence::operator!=( const OPimOccurrence& oc )const {
308 return !( *this == oc );
309}
310
311bool OPimOccurrence::operator>( const OPimOccurrence& oc )const {
312 return !( *this <= oc );
313}
314
315bool OPimOccurrence::operator>=( const OPimOccurrence& oc )const {
316 return !( *this < oc );
317}
318
319}
diff --git a/libopie2/opiepim/core/opimoccurrence.h b/libopie2/opiepim/core/opimoccurrence.h
new file mode 100644
index 0000000..902638b
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.h
@@ -0,0 +1,142 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.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 OPIE_PIM_OCCURRENCE_H
31#define OPIE_PIM_OCCURRENCE_H
32
33#include <opie2/osharedpointer.h>
34#include <opie2/opimrecord.h>
35#include <opie2/opimevent.h>
36#include <opie2/opimtodo.h>
37#include <opie2/opimcontact.h>
38
39#include <qdatetime.h>
40#include <qstringlist.h>
41
42namespace Opie {
43
44template<class T> class OPimAccessTemplate;
45/**
46 * \brief An OPimOccurrence represents a occurence for one day of a OPimRecord
47 *
48 * An OPimOccurrence represents the occurrence of one OPimRecord
49 * for a period of Time for one day. An occurrence can spawn
50 * more then one day and then is splitted into multiple OPimOccurrence.
51 * By attributes you can find if a OPimOccurrence is the beginning and
52 * end, begin, end or is midway of a multiday occurrence.
53 *
54 */
55class OPimOccurrence {
56 friend class OPimBase;
57public:
58 typedef QValueList<OPimOccurrence> List;
59 /**
60 * The position of the OPimOccurrence in a possible
61 * MultiDay Occurrence.
62 */
63 enum Position {
64 MidWay, /* This OPimOccurrence is somewhere in between Start and End */
65 Start, /* This OPimOccurrence is the Start of a multi day Occurrence */
66 End, /* This OPimOccurrence is the End of a multi day Occurrence */
67 StartEnd /* This OPimOccurrence only spans one day */
68 };
69
70 //@{
71 OPimOccurrence();
72 OPimOccurrence( const OPimOccurrence& );
73 ~OPimOccurrence();
74 //@}
75
76 //@{
77 void setPeriod( const QDate& from );
78 void setPeriod( const QDateTime& from, const QDateTime& to );
79 void setPeriod( const QDate& from, const QTime& start, const QTime& end );
80 //@}
81
82 //@{
83 bool isAllDay()const;
84 QDate date()const;
85 QTime startTime()const;
86 QTime endTime()const;
87 QDateTime startDateTime()const;
88 QDateTime endDateTime()const;
89 //@}
90
91 //@{
92 QString summary()const;
93 QString location()const;
94 QString note()const;
95 //@}
96
97 //@{
98 int length()const;
99 Position position()const;
100 void setPosition( enum Position& );
101 //@}
102
103 //@{
104 Opie::Core::OSharedPointer<OPimRecord> record()const;
105 OPimEvent toEvent()const;
106 OPimTodo toTodo()const;
107 OPimContact toContact()const;
108 //@}
109
110
111 //@{
112 bool operator< ( const OPimOccurrence& )const;
113 bool operator<=( const OPimOccurrence& )const;
114 bool operator==( const OPimOccurrence& )const;
115 bool operator!=( const OPimOccurrence& )const;
116 bool operator> ( const OPimOccurrence& )const;
117 bool operator>=( const OPimOccurrence& )const;
118 OPimOccurrence &operator=( const OPimOccurrence& );
119 //@}
120
121private:
122 QDate m_occurrence;
123 QTime m_start, m_end;
124 bool m_isAllDay : 1;
125 enum Position m_pos;
126
127 void deref();
128 inline void changeOrModify();
129
130 struct Private;
131 struct Data;
132
133 Data *data;
134 Private *d;
135
136private: // ctor
137 OPimOccurrence( OPimOccurrence::Data *, enum Position );
138 template<class T> T internalToRecord()const;
139};
140}
141
142#endif
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 6546d99..60946e0 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -7,267 +7,258 @@
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimrecord.h" 30#include "opimrecord.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <qpe/categories.h> 33#include <qpe/categories.h>
34#include <qpe/categoryselect.h> 34#include <qpe/categoryselect.h>
35 35
36/* QT */ 36/* QT */
37 37
38namespace Opie 38namespace Opie
39{ 39{
40Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 40Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
41 41
42 42
43OPimRecord::OPimRecord( int uid ) 43OPimRecord::OPimRecord( int uid )
44 : Qtopia::Record() 44 : Qtopia::Record()
45{ 45{
46 46
47 m_lastHit = -1; 47 m_lastHit = -1;
48 setUid( uid ); 48 setUid( uid );
49} 49}
50 50
51 51
52OPimRecord::~OPimRecord() 52OPimRecord::~OPimRecord()
53{} 53{}
54 54
55 55
56OPimRecord::OPimRecord( const OPimRecord& rec ) 56OPimRecord::OPimRecord( const OPimRecord& rec )
57 : Qtopia::Record( rec ) 57 : Qtopia::Record( rec )
58{ 58{
59 ( *this ) = rec; 59 ( *this ) = rec;
60} 60}
61 61
62 62
63OPimRecord &OPimRecord::operator=( const OPimRecord& rec ) 63OPimRecord &OPimRecord::operator=( const OPimRecord& rec )
64{ 64{
65 if ( this == &rec ) return * this; 65 if ( this == &rec ) return * this;
66 66
67 Qtopia::Record::operator=( rec ); 67 Qtopia::Record::operator=( rec );
68 m_xrefman = rec.m_xrefman; 68 m_xrefman = rec.m_xrefman;
69 m_lastHit = rec.m_lastHit; 69 m_lastHit = rec.m_lastHit;
70 70
71 return *this; 71 return *this;
72} 72}
73 73
74 74
75/* 75/*
76 * category names 76 * category names
77 */ 77 */
78QStringList OPimRecord::categoryNames( const QString& appname ) const 78QStringList OPimRecord::categoryNames( const QString& appname ) const
79{ 79{
80 QStringList list; 80 QStringList list;
81 QArray<int> cats = categories(); 81 QArray<int> cats = categories();
82 Categories catDB; 82 Categories catDB;
83 catDB.load( categoryFileName() ); 83 catDB.load( categoryFileName() );
84 84
85 for ( uint i = 0; i < cats.count(); i++ ) 85 for ( uint i = 0; i < cats.count(); i++ )
86 { 86 {
87 list << catDB.label( appname, cats[ i ] ); 87 list << catDB.label( appname, cats[ i ] );
88 } 88 }
89 89
90 return list; 90 return list;
91} 91}
92 92
93 93
94void OPimRecord::setCategoryNames( const QStringList& ) 94void OPimRecord::setCategoryNames( const QStringList& )
95{ 95{
96} 96}
97 97
98 98
99void OPimRecord::addCategoryName( const QString& ) 99void OPimRecord::addCategoryName( const QString& )
100{ 100{
101 Categories catDB; 101 Categories catDB;
102 catDB.load( categoryFileName() ); 102 catDB.load( categoryFileName() );
103
104
105} 103}
106 104
107 105
108bool OPimRecord::isEmpty() const 106bool OPimRecord::isEmpty() const
109{ 107{
110 return ( uid() == 0 ); 108 return ( uid() == 0 );
111} 109}
112 110
113 111
114/*QString OPimRecord::crossToString()const {
115 QString str;
116 QMap<QString, QArray<int> >::ConstIterator it;
117 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
118 QArray<int> id = it.data();
119 for ( uint i = 0; i < id.size(); ++i ) {
120 str += it.key() + "," + QString::number( i ) + ";";
121 }
122 }
123 str = str.remove( str.length()-1, 1); // strip the ;
124 //owarn << "IDS " + str << oendl;
125
126 return str;
127 }*/
128/* if uid = 1 assign a new one */ 112/* if uid = 1 assign a new one */
129void OPimRecord::setUid( int uid ) 113void OPimRecord::setUid( int uid )
130{ 114{
131 if ( uid == 1 ) 115 if ( uid == 1 )
132 uid = uidGen().generate(); 116 uid = uidGen().generate();
133 117
134 Qtopia::Record::setUid( uid ); 118 Qtopia::Record::setUid( uid );
135}; 119};
136 120
137 121
138Qtopia::UidGen &OPimRecord::uidGen() 122Qtopia::UidGen &OPimRecord::uidGen()
139{ 123{
140 return m_uidGen; 124 return m_uidGen;
141} 125}
142 126
143 127
144OPimXRefManager &OPimRecord::xrefmanager() 128OPimXRefManager &OPimRecord::xrefmanager()
145{ 129{
146 return m_xrefman; 130 return m_xrefman;
147} 131}
148 132
149 133
150int OPimRecord::rtti() const 134int OPimRecord::rtti() const
151{ 135{
152 return 0; 136 return 0;
153} 137}
154 138
155/** 139/**
156 * now let's put our data into the stream 140 * now let's put our data into the stream
157 */ 141 */
158/* 142/*
159 * First read UID 143 * First read UID
160 * Categories 144 * Categories
161 * XRef 145 * XRef
162 */ 146 */
163bool OPimRecord::loadFromStream( QDataStream& stream ) 147bool OPimRecord::loadFromStream( QDataStream& stream )
164{ 148{
165 int Int; 149 int Int;
166 uint UInt; 150 uint UInt;
167 stream >> Int; 151 stream >> Int;
168 setUid( Int ); 152 setUid( Int );
169 153
170 /** Categories */ 154 /** Categories */
171 stream >> UInt; 155 stream >> UInt;
172 QArray<int> array( UInt ); 156 QArray<int> array( UInt );
173 for ( uint i = 0; i < UInt; i++ ) 157 for ( uint i = 0; i < UInt; i++ )
174 { 158 {
175 stream >> array[ i ]; 159 stream >> array[ i ];
176 } 160 }
177 setCategories( array ); 161 setCategories( array );
178 162
179 /* 163 /*
180 * now we do the X-Ref stuff 164 * now we do the X-Ref stuff
181 */ 165 */
182 OPimXRef xref; 166 OPimXRef xref;
183 stream >> UInt; 167 stream >> UInt;
184 for ( uint i = 0; i < UInt; i++ ) 168 for ( uint i = 0; i < UInt; i++ )
185 { 169 {
186 xref.setPartner( OPimXRef::One, partner( stream ) ); 170 xref.setPartner( OPimXRef::One, partner( stream ) );
187 xref.setPartner( OPimXRef::Two, partner( stream ) ); 171 xref.setPartner( OPimXRef::Two, partner( stream ) );
188 m_xrefman.add( xref ); 172 m_xrefman.add( xref );
189 } 173 }
190 174
191 return true; 175 return true;
192} 176}
193 177
194 178
195bool OPimRecord::saveToStream( QDataStream& stream ) const 179bool OPimRecord::saveToStream( QDataStream& stream ) const
196{ 180{
197 /** UIDs */ 181 /** UIDs */
198 182
199 stream << uid(); 183 stream << uid();
200 184
201 /** Categories */ 185 /** Categories */
202 stream << categories().count(); 186 stream << categories().count();
203 for ( uint i = 0; i < categories().count(); i++ ) 187 for ( uint i = 0; i < categories().count(); i++ )
204 { 188 {
205 stream << categories() [ i ]; 189 stream << categories() [ i ];
206 } 190 }
207 191
208 /* 192 /*
209 * first the XRef count 193 * first the XRef count
210 * then the xrefs 194 * then the xrefs
211 */ 195 */
212 stream << m_xrefman.list().count(); 196 stream << m_xrefman.list().count();
213 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); 197 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
214 it != m_xrefman.list().end(); ++it ) 198 it != m_xrefman.list().end(); ++it )
215 { 199 {
216 flush( ( *it ).partner( OPimXRef::One ), stream ); 200 flush( ( *it ).partner( OPimXRef::One ), stream );
217 flush( ( *it ).partner( OPimXRef::Two ), stream ); 201 flush( ( *it ).partner( OPimXRef::Two ), stream );
218 } 202 }
219 return true; 203 return true;
220} 204}
221 205
222 206
223void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const 207void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const
224{ 208{
225 str << par.service(); 209 str << par.service();
226 str << par.uid(); 210 str << par.uid();
227 str << par.field(); 211 str << par.field();
228} 212}
229 213
230 214
231OPimXRefPartner OPimRecord::partner( QDataStream& stream ) 215OPimXRefPartner OPimRecord::partner( QDataStream& stream )
232{ 216{
233 OPimXRefPartner par; 217 OPimXRefPartner par;
234 QString str; 218 QString str;
235 int i; 219 int i;
236 220
237 stream >> str; 221 stream >> str;
238 par.setService( str ); 222 par.setService( str );
239 223
240 stream >> i; 224 stream >> i;
241 par.setUid( i ); 225 par.setUid( i );
242 226
243 stream >> i ; 227 stream >> i ;
244 par.setField( i ); 228 par.setField( i );
245 229
246 return par; 230 return par;
247} 231}
248 232
249 233
250void OPimRecord::setLastHitField( int lastHit ) const 234void OPimRecord::setLastHitField( int lastHit ) const
251{ 235{
252 m_lastHit = lastHit; 236 m_lastHit = lastHit;
253} 237}
254 238
255 239
256int OPimRecord::lastHitField() const 240int OPimRecord::lastHitField() const
257{ 241{
258 return m_lastHit; 242 return m_lastHit;
259} 243}
260 244
261 245
262QMap<QString, QString> OPimRecord::toExtraMap() const 246QMap<QString, QString> OPimRecord::toExtraMap() const
263{ 247{
264 return customMap; 248 return customMap;
265} 249}
266 250
267 251
268void OPimRecord::setExtraMap( const QMap<QString, QString>& map ) 252void OPimRecord::setExtraMap( const QMap<QString, QString>& map )
269{ 253{
270 customMap = map; 254 customMap = map;
271} 255}
272 256
257#if 0
258QString OPimRecord::recordAttributeTranslated( int field )const
259{
260 return recordAttributeTranslated()[field];
261}
262#endif
263
273} 264}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 127439a..363cc78 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,193 +1,200 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OPIMRECORD_H 30#ifndef OPIMRECORD_H
31#define OPIMRECORD_H 31#define OPIMRECORD_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimxrefmanager.h> 34#include <opie2/opimxrefmanager.h>
35#include <opie2/opimglobal.h>
36
35/* 37/*
36 * we need to get customMap which is private... 38 * we need to get customMap which is private...
37 */ 39 */
38#define private protected 40#define private protected
39#include <qpe/palmtoprecord.h> 41#include <qpe/palmtoprecord.h>
40#undef private 42#undef private
41 43
42/* QT */ 44/* QT */
43#include <qdatastream.h> 45#include <qdatastream.h>
44#include <qmap.h> 46#include <qmap.h>
45#include <qstring.h> 47#include <qstring.h>
46#include <qstringlist.h> 48#include <qstringlist.h>
47 49
48namespace Opie 50namespace Opie
49{ 51{
50/** 52/**
51 * This is the base class for 53 * This is the base class for
52 * all PIM Records 54 * all PIM Records
53 * 55 *
54 */ 56 */
55class OPimRecord : public Qtopia::Record 57class OPimRecord : public Qtopia::Record
56{ 58{
57 public: 59 public:
58 /** 60 /**
59 * c'tor 61 * c'tor
60 * uid of 0 isEmpty 62 * uid of 0 isEmpty
61 * uid of 1 will be assigned a new one 63 * uid of 1 will be assigned a new one
62 */ 64 */
63 OPimRecord( int uid = 0 ); 65 OPimRecord( UID uid = 0 );
64 ~OPimRecord(); 66 ~OPimRecord();
65 67
66 /** 68 /**
67 * copy c'tor 69 * copy c'tor
68 */ 70 */
69 OPimRecord( const OPimRecord& rec ); 71 OPimRecord( const OPimRecord& rec );
70 72
71 /** 73 /**
72 * copy operator 74 * copy operator
73 */ 75 */
74 OPimRecord &operator=( const OPimRecord& ); 76 OPimRecord &operator=( const OPimRecord& );
75 77
76 /** 78 /**
77 * category names resolved 79 * category names resolved
78 */ 80 */
79 QStringList categoryNames( const QString& appname ) const; 81 QStringList categoryNames( const QString& appname ) const;
80 82
81 /** 83 /**
82 * set category names they will be resolved 84 * set category names they will be resolved
83 */ 85 */
84 void setCategoryNames( const QStringList& ); 86 void setCategoryNames( const QStringList& );
85 87
86 /** 88 /**
87 * addCategoryName adds a name 89 * addCategoryName adds a name
88 * to the internal category list 90 * to the internal category list
89 */ 91 */
90 void addCategoryName( const QString& ); 92 void addCategoryName( const QString& );
91 93
92 /** 94 /**
93 * if a Record isEmpty 95 * if a Record isEmpty
94 * it's empty if it's 0 96 * it's empty if it's 0
95 */ 97 */
96 virtual bool isEmpty() const; 98 virtual bool isEmpty() const;
97 99
98 /** 100 /**
99 * toRichText summary 101 * toRichText summary
100 */ 102 */
101 virtual QString toRichText() const = 0; 103 virtual QString toRichText() const = 0;
102 104
103 /** 105 /**
104 * a small one line summary 106 * a small one line summary
105 */ 107 */
106 virtual QString toShortText() const = 0; 108 virtual QString toShortText() const = 0;
107 109
108 /** 110 /**
109 * the name of the Record 111 * the name of the Record
110 */ 112 */
111 virtual QString type() const = 0; 113 virtual QString type() const = 0;
112 114
113 /** 115 /**
114 * matches the Records the regular expression? 116 * matches the Records the regular expression?
115 */ 117 */
116 virtual bool match( const QString &regexp ) const 118 virtual bool match( const QString &regexp ) const
117 { 119 {
118 setLastHitField( -1 ); 120 setLastHitField( -1 );
119 return Qtopia::Record::match( QRegExp( regexp ) ); 121 return Qtopia::Record::match( QRegExp( regexp ) );
120 }; 122 };
121 123
122 /** 124 /**
123 * if implemented this function returns which item has been 125 * if implemented this function returns which item has been
124 * last hit by the match() function. 126 * last hit by the match() function.
125 * or -1 if not implemented or no hit has occured 127 * or -1 if not implemented or no hit has occured
126 */ 128 */
127 int lastHitField() const; 129 int lastHitField() const;
128 130
129 /** 131 /**
130 * converts the internal structure to a map 132 * converts the internal structure to a map
131 */ 133 */
132 virtual QMap<int, QString> toMap() const = 0; 134 virtual QMap<int, QString> toMap() const = 0;
133 // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers) 135 // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers)
134 136
135 /** 137 /**
136 * key value representation of extra items 138 * key value representation of extra items
137 */ 139 */
138 QMap<QString, QString> toExtraMap() const; 140 QMap<QString, QString> toExtraMap() const;
139 void setExtraMap( const QMap<QString, QString>& ); 141 void setExtraMap( const QMap<QString, QString>& );
140 142
143//@{
141 /** 144 /**
142 * the name for a recordField 145 * the name for a recordField
143 */ 146 */
144 virtual QString recordField( int ) const = 0; 147 virtual QString recordField( int ) const = 0;
148// virtual QArray<int> recordAttributes()const = 0;
149// virtual QMap<int,QString> recordAttributesTranslated() const = 0;
150// QString recordAttributeTranslated(int field)const;
151//@}
145 152
146 /** 153 /**
147 * returns a reference of the 154 * returns a reference of the
148 * Cross Reference Manager 155 * Cross Reference Manager
149 * Partner 'One' is THIS PIM RECORD! 156 * Partner 'One' is THIS PIM RECORD!
150 * 'Two' is the Partner where we link to 157 * 'Two' is the Partner where we link to
151 */ 158 */
152 OPimXRefManager& xrefmanager(); 159 OPimXRefManager& xrefmanager();
153 160
154 /** 161 /**
155 * set the uid 162 * set the uid
156 */ 163 */
157 virtual void setUid( int uid ); 164 virtual void setUid( int uid );
158 165
159 /* 166 /*
160 * used inside the Templates for casting 167 * used inside the Templates for casting
161 * REIMPLEMENT in your .... 168 * REIMPLEMENT in your ....
162 */ 169 */
163 virtual int rtti() const; 170 virtual int rtti() const;
164 171
165 /** 172 /**
166 * some marshalling and de marshalling code 173 * some marshalling and de marshalling code
167 * saves the OPimRecord 174 * saves the OPimRecord
168 * to and from a DataStream 175 * to and from a DataStream
169 */ 176 */
170 virtual bool loadFromStream( QDataStream& ); 177 virtual bool loadFromStream( QDataStream& );
171 virtual bool saveToStream( QDataStream& stream ) const; 178 virtual bool saveToStream( QDataStream& stream ) const;
172 179
173 protected: 180 protected:
174 // need to be const cause it is called from const methods 181 // need to be const cause it is called from const methods
175 mutable int m_lastHit; 182 mutable int m_lastHit;
176 void setLastHitField( int lastHit ) const; 183 void setLastHitField( int lastHit ) const;
177 Qtopia::UidGen &uidGen(); 184 Qtopia::UidGen &uidGen();
178 // QString crossToString()const; 185 // QString crossToString()const;
179 186
180 private: 187 private:
181 class OPimRecordPrivate; 188 class OPimRecordPrivate;
182 OPimRecordPrivate *d; 189 OPimRecordPrivate *d;
183 OPimXRefManager m_xrefman; 190 OPimXRefManager m_xrefman;
184 static Qtopia::UidGen m_uidGen; 191 static Qtopia::UidGen m_uidGen;
185 192
186 private: 193 private:
187 void flush( const OPimXRefPartner&, QDataStream& stream ) const; 194 void flush( const OPimXRefPartner&, QDataStream& stream ) const;
188 OPimXRefPartner partner( QDataStream& ); 195 OPimXRefPartner partner( QDataStream& );
189}; 196};
190 197
191} 198}
192 199
193#endif 200#endif
diff --git a/libopie2/opiepim/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h
index 1d5027f..0459f41 100644
--- a/libopie2/opiepim/core/opimrecordlist.h
+++ b/libopie2/opiepim/core/opimrecordlist.h
@@ -1,403 +1,410 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef ORECORDLIST_H 30#ifndef ORECORDLIST_H
31#define ORECORDLIST_H 31#define ORECORDLIST_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimtemplatebase.h> 34#include <opie2/opimtemplatebase.h>
35#include <opie2/opimrecord.h> 35#include <opie2/opimrecord.h>
36//#include <opie2/odebug.h> 36//#include <opie2/odebug.h>
37 37
38/* QT */ 38/* QT */
39#include <qarray.h> 39#include <qarray.h>
40 40
41namespace Opie 41namespace Opie
42{ 42{
43 43
44template<class T> class OPimAccessTemplate;
44class OPimRecordListIteratorPrivate; 45class OPimRecordListIteratorPrivate;
45/** 46/**
46 * Our List Iterator 47 * Our List Iterator
47 * it behaves like STL or Qt 48 * it behaves like STL or Qt
48 * 49 *
49 * for(it = list.begin(); it != list.end(); ++it ) 50 * for(it = list.begin(); it != list.end(); ++it )
50 * doSomeCoolStuff( (*it) ); 51 * doSomeCoolStuff( (*it) );
51 */ 52 */
52template <class T> class OPimRecordList; 53template <class T> class OPimRecordList;
53template <class T = OPimRecord> 54template <class T = OPimRecord>
54class OPimRecordListIterator 55class OPimRecordListIterator
55{ 56{
56 friend class OPimRecordList<T>; 57 friend class OPimRecordList<T>;
57 58
58 public: 59 public:
59 typedef OTemplateBase<T> Base; 60 typedef OTemplateBase<T> Base;
60 61
61 /** 62 /**
62 * The c'tor used internally from 63 * The c'tor used internally from
63 * OPimRecordList 64 * OPimRecordList
64 */ 65 */
65 OPimRecordListIterator( const QArray<int>, const Base* ); 66 OPimRecordListIterator( const QArray<int>, const Base* );
66 67
67 /** 68 /**
68 * The standard c'tor 69 * The standard c'tor
69 */ 70 */
70 OPimRecordListIterator(); 71 OPimRecordListIterator();
71 ~OPimRecordListIterator(); 72 ~OPimRecordListIterator();
72 73
73 OPimRecordListIterator( const OPimRecordListIterator& ); 74 OPimRecordListIterator( const OPimRecordListIterator& );
74 OPimRecordListIterator &operator=( const OPimRecordListIterator& ); 75 OPimRecordListIterator &operator=( const OPimRecordListIterator& );
75 76
76 /** 77 /**
77 * a * operator ;) 78 * a * operator ;)
78 * use it like this T = (*it); 79 * use it like this T = (*it);
79 */ 80 */
80 T operator*(); 81 T operator*();
81 OPimRecordListIterator &operator++(); 82 OPimRecordListIterator &operator++();
82 OPimRecordListIterator &operator--(); 83 OPimRecordListIterator &operator--();
83 84
84 bool operator==( const OPimRecordListIterator& it ); 85 bool operator==( const OPimRecordListIterator& it );
85 bool operator!=( const OPimRecordListIterator& it ); 86 bool operator!=( const OPimRecordListIterator& it );
86 87
87 /** 88 /**
88 * the current item 89 * the current item
89 */ 90 */
90 uint current() const; 91 uint current() const;
91 92
92 /** 93 /**
93 * the number of items 94 * the number of items
94 */ 95 */
95 uint count() const; 96 uint count() const;
96 97
97 /** 98 /**
98 * sets the current item 99 * sets the current item
99 */ 100 */
100 void setCurrent( uint cur ); 101 void setCurrent( uint cur );
101 102
102 private: 103 private:
103 QArray<int> m_uids; 104 QArray<int> m_uids;
104 uint m_current; 105 uint m_current;
105 const Base* m_temp; 106 const Base* m_temp;
106 bool m_end : 1; 107 bool m_end : 1;
107 T m_record; 108 T m_record;
108 bool m_direction : 1; 109 bool m_direction : 1;
109 110
110 /* d pointer for future versions */ 111 /* d pointer for future versions */
111 OPimRecordListIteratorPrivate *d; 112 OPimRecordListIteratorPrivate *d;
112}; 113};
113 114
114 115
115class OPimRecordListPrivate; 116class OPimRecordListPrivate;
116/** 117/**
117 * The recordlist used as a return type 118 * The recordlist used as a return type
118 * from OPimAccessTemplate 119 * from OPimAccessTemplate
119 */ 120 */
120template <class T = OPimRecord > 121template <class T = OPimRecord >
121class OPimRecordList 122class OPimRecordList
122{ 123{
124 template<class> friend class OPimAccessTemplate;
123 public: 125 public:
124 typedef OTemplateBase<T> Base; 126 typedef OTemplateBase<T> Base;
125 typedef OPimRecordListIterator<T> Iterator; 127 typedef OPimRecordListIterator<T> Iterator;
126 128
127 /** 129 /**
128 * c'tor 130 * c'tor
129 */ 131 */
130 OPimRecordList () 132 OPimRecordList (){}
131 {}
132 OPimRecordList( const QArray<int>& ids, 133 OPimRecordList( const QArray<int>& ids,
133 const Base* ); 134 const Base* );
134 ~OPimRecordList(); 135 ~OPimRecordList();
135 136
136 /** 137 /**
137 * the first iterator 138 * the first iterator
138 */ 139 */
139 Iterator begin(); 140 Iterator begin();
140 141
141 /** 142 /**
142 * the end 143 * the end
143 */ 144 */
144 Iterator end(); 145 Iterator end();
145 146
146 /** 147 /**
147 * the number of items in the list 148 * the number of items in the list
148 */ 149 */
149 uint count() const; 150 uint count() const;
150 151
151 T operator[] ( uint i ); 152 T operator[] ( uint i );
152 int uidAt( uint i ); 153 int uidAt( uint i );
153 154
154 /** 155 /**
155 * Remove the contact with given uid 156 * Remove the contact with given uid
156 */ 157 */
157 bool remove( int uid ); 158 bool remove( int uid );
158 159
159 /* 160 /*
160 ConstIterator begin()const; 161 ConstIterator begin()const;
161 ConstIterator end()const; 162 ConstIterator end()const;
162 */ 163 */
164 protected:
165 UIDArray uids()const;
166
163 private: 167 private:
164 QArray<int> m_ids; 168 QArray<int> m_ids;
165 const Base* m_acc; 169 const Base* m_acc;
166 OPimRecordListPrivate *d; 170 OPimRecordListPrivate *d;
167}; 171};
168 172
169 173
170/* ok now implement it */ 174/* ok now implement it */
171template <class T> 175template <class T>
172OPimRecordListIterator<T>::OPimRecordListIterator() 176OPimRecordListIterator<T>::OPimRecordListIterator()
173{ 177{
174 m_current = 0; 178 m_current = 0;
175 m_temp = 0l; 179 m_temp = 0l;
176 m_end = true; 180 m_end = true;
177 m_record = T(); 181 m_record = T();
178 /* forward */ 182 /* forward */
179 m_direction = TRUE; 183 m_direction = TRUE;
180} 184}
181 185
182 186
183template <class T> 187template <class T>
184OPimRecordListIterator<T>::~OPimRecordListIterator() 188OPimRecordListIterator<T>::~OPimRecordListIterator()
185{ 189{
186 /* nothing to delete */ 190 /* nothing to delete */
187} 191}
188 192
189 193
190template <class T> 194template <class T>
191OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it ) 195OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it )
192{ 196{
193 //owarn << "OPimRecordListIterator copy c'tor" << oendl;
194 m_uids = it.m_uids; 197 m_uids = it.m_uids;
195 m_current = it.m_current; 198 m_current = it.m_current;
196 m_temp = it.m_temp; 199 m_temp = it.m_temp;
197 m_end = it.m_end; 200 m_end = it.m_end;
198 m_record = it.m_record; 201 m_record = it.m_record;
199 m_direction = it.m_direction; 202 m_direction = it.m_direction;
200} 203}
201 204
202 205
203template <class T> 206template <class T>
204OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it ) 207OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it )
205{ 208{
206 m_uids = it.m_uids; 209 m_uids = it.m_uids;
207 m_current = it.m_current; 210 m_current = it.m_current;
208 m_temp = it.m_temp; 211 m_temp = it.m_temp;
209 m_end = it.m_end; 212 m_end = it.m_end;
210 m_record = it.m_record; 213 m_record = it.m_record;
211 214
212 return *this; 215 return *this;
213} 216}
214 217
215 218
216template <class T> 219template <class T>
217T OPimRecordListIterator<T>::operator*() 220T OPimRecordListIterator<T>::operator*()
218{ 221{
219 //owarn << "operator* " << m_current << " " << m_uids[m_current] << oendl;
220 if ( !m_end ) 222 if ( !m_end )
221 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, 223 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current,
222 m_direction ? Base::Forward : 224 m_direction ? Base::Forward :
223 Base::Reverse ); 225 Base::Reverse );
224 else 226 else
225 m_record = T(); 227 m_record = T();
226 228
227 return m_record; 229 return m_record;
228} 230}
229 231
230 232
231template <class T> 233template <class T>
232OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++() 234OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++()
233{ 235{
234 m_direction = true; 236 m_direction = true;
235 if ( m_current < m_uids.count() ) 237 if ( m_current < m_uids.count() )
236 { 238 {
237 m_end = false; 239 m_end = false;
238 ++m_current; 240 ++m_current;
239 } 241 }
240 else 242 else
241 m_end = true; 243 m_end = true;
242 244
243 return *this; 245 return *this;
244} 246}
245 247
246 248
247template <class T> 249template <class T>
248OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--() 250OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--()
249{ 251{
250 m_direction = false; 252 m_direction = false;
251 if ( m_current > 0 ) 253 if ( m_current > 0 )
252 { 254 {
253 --m_current; 255 --m_current;
254 m_end = false; 256 m_end = false;
255 } 257 }
256 else 258 else
257 m_end = true; 259 m_end = true;
258 260
259 return *this; 261 return *this;
260} 262}
261 263
262 264
263template <class T> 265template <class T>
264bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it ) 266bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it )
265{ 267{
266 268
267 /* if both are at we're the same.... */ 269 /* if both are at we're the same.... */
268 if ( m_end == it.m_end ) return true; 270 if ( m_end == it.m_end ) return true;
269 271
270 if ( m_uids != it.m_uids ) return false; 272 if ( m_uids != it.m_uids ) return false;
271 if ( m_current != it.m_current ) return false; 273 if ( m_current != it.m_current ) return false;
272 if ( m_temp != it.m_temp ) return false; 274 if ( m_temp != it.m_temp ) return false;
273 275
274 return true; 276 return true;
275} 277}
276 278
277 279
278template <class T> 280template <class T>
279bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it ) 281bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it )
280{ 282{
281 return !( *this == it ); 283 return !( *this == it );
282} 284}
283 285
284 286
285template <class T> 287template <class T>
286OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids, 288OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids,
287 const Base* t ) 289 const Base* t )
288 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), 290 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
289 m_direction( false ) 291 m_direction( false )
290{ 292{
291 /* if the list is empty we're already at the end of the list */ 293 /* if the list is empty we're already at the end of the list */
292 if ( uids.count() == 0 ) 294 if ( uids.count() == 0 )
293 m_end = true; 295 m_end = true;
294} 296}
295 297
296 298
297template <class T> 299template <class T>
298uint OPimRecordListIterator<T>::current() const 300uint OPimRecordListIterator<T>::current() const
299{ 301{
300 return m_current; 302 return m_current;
301} 303}
302 304
303 305
304template <class T> 306template <class T>
305void OPimRecordListIterator<T>::setCurrent( uint cur ) 307void OPimRecordListIterator<T>::setCurrent( uint cur )
306{ 308{
307 if ( cur < m_uids.count() ) 309 if ( cur < m_uids.count() )
308 { 310 {
309 m_end = false; 311 m_end = false;
310 m_current = cur; 312 m_current = cur;
311 } 313 }
312} 314}
313template <class T> 315template <class T>
314uint OPimRecordListIterator<T>::count() const 316uint OPimRecordListIterator<T>::count() const
315{ 317{
316 return m_uids.count(); 318 return m_uids.count();
317} 319}
318 320
319 321
320template <class T> 322template <class T>
321OPimRecordList<T>::OPimRecordList( const QArray<int>& ids, 323OPimRecordList<T>::OPimRecordList( const QArray<int>& ids,
322 const Base* acc ) 324 const Base* acc )
323 : m_ids( ids ), m_acc( acc ) 325 : m_ids( ids ), m_acc( acc )
324{} 326{}
325 327
326 328
327template <class T> 329template <class T>
328OPimRecordList<T>::~OPimRecordList() 330OPimRecordList<T>::~OPimRecordList()
329{ 331{
330 /* nothing to do here */ 332 /* nothing to do here */
331} 333}
332 334
333 335
334template <class T> 336template <class T>
335typename OPimRecordList<T>::Iterator OPimRecordList<T>::begin() 337typename OPimRecordList<T>::Iterator OPimRecordList<T>::begin()
336{ 338{
337 Iterator it( m_ids, m_acc ); 339 Iterator it( m_ids, m_acc );
338 return it; 340 return it;
339} 341}
340 342
341 343
342template <class T> 344template <class T>
343typename OPimRecordList<T>::Iterator OPimRecordList<T>::end() 345typename OPimRecordList<T>::Iterator OPimRecordList<T>::end()
344{ 346{
345 Iterator it( m_ids, m_acc ); 347 Iterator it( m_ids, m_acc );
346 it.m_end = true; 348 it.m_end = true;
347 it.m_current = m_ids.count(); 349 it.m_current = m_ids.count();
348 350
349 return it; 351 return it;
350} 352}
351 353
352 354
353template <class T> 355template <class T>
354uint OPimRecordList<T>::count() const 356uint OPimRecordList<T>::count() const
355{ 357{
356 return m_ids.count(); 358 return m_ids.count();
357} 359}
358 360
359 361
360template <class T> 362template <class T>
361T OPimRecordList<T>::operator[] ( uint i ) 363T OPimRecordList<T>::operator[] ( uint i )
362{ 364{
363 if ( i >= m_ids.count() ) 365 if ( i >= m_ids.count() )
364 return T(); 366 return T();
365 /* forward */ 367 /* forward */
366 return m_acc->find( m_ids[ i ], m_ids, i ); 368 return m_acc->find( m_ids[ i ], m_ids, i );
367} 369}
368 370
369 371
370template <class T> 372template <class T>
371int OPimRecordList<T>::uidAt( uint i ) 373int OPimRecordList<T>::uidAt( uint i )
372{ 374{
373 return m_ids[ i ]; 375 return m_ids[ i ];
374} 376}
375 377
376 378
377template <class T> 379template <class T>
378bool OPimRecordList<T>::remove( int uid ) 380bool OPimRecordList<T>::remove( int uid )
379{ 381{
380 QArray<int> copy( m_ids.count() ); 382 QArray<int> copy( m_ids.count() );
381 int counter = 0; 383 int counter = 0;
382 bool ret_val = false; 384 bool ret_val = false;
383 385
384 for ( uint i = 0; i < m_ids.count(); i++ ) 386 for ( uint i = 0; i < m_ids.count(); i++ )
385 { 387 {
386 if ( m_ids[ i ] != uid ) 388 if ( m_ids[ i ] != uid )
387 { 389 {
388 copy[ counter++ ] = m_ids[ i ]; 390 copy[ counter++ ] = m_ids[ i ];
389 391
390 } 392 }
391 else 393 else
392 ret_val = true; 394 ret_val = true;
393 } 395 }
394 396
395 copy.resize( counter ); 397 copy.resize( counter );
396 m_ids = copy; 398 m_ids = copy;
397 399
398 400
399 return ret_val; 401 return ret_val;
400} 402}
401 403
404template<class T>
405UIDArray OPimRecordList<T>::uids()const {
406 return m_ids;
407}
408
402} 409}
403#endif 410#endif
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h
index 0a6dddf..088474b 100644
--- a/libopie2/opiepim/core/opimresolver.h
+++ b/libopie2/opiepim/core/opimresolver.h
@@ -1,125 +1,123 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIMRESOLVER_H 29#ifndef OPIMRESOLVER_H
30#define OPIMRESOLVER_H 30#define OPIMRESOLVER_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimtemplatebase.h> 33#include <opie2/opimtemplatebase.h>
34 34
35/* QT */ 35/* QT */
36#include <qstring.h> 36#include <qstring.h>
37#include <qvaluelist.h> 37#include <qvaluelist.h>
38 38
39namespace Opie { 39namespace Opie {
40/** 40/**
41 * OPimResolver is a MetaClass to access 41 * OPimResolver is a MetaClass to access
42 * available backends read only. 42 * available backends read only.
43 * It will be used to resolve uids + app names 43 * It will be used to resolve uids + app names
44 * to full informations 44 * to full informations
45 * to traverse through a list of alarms, reminders 45 * to traverse through a list of alarms, reminders
46 * to get access to built in PIM functionality 46 * to get access to built in PIM functionality
47 * and to more stuff 47 * and to more stuff
48 * THE PERFORMANCE will depend on THE BACKEND
49 * USING XML is a waste of memory!!!!!
50 */ 48 */
51class OPimResolver { 49class OPimResolver {
52 50
53 public: 51 public:
54 enum BuiltIn { TodoList = 0, 52 enum BuiltIn { TodoList = 0,
55 DateBook, 53 DateBook,
56 AddressBook 54 AddressBook
57 }; 55 };
58 static OPimResolver* self(); 56 static OPimResolver* self();
59 57
60 58
61 /** 59 /**
62 * return a record for a uid 60 * return a record for a uid
63 * and an service 61 * and an service
64 * You've THE OWNERSHIP NOW! 62 * You've THE OWNERSHIP NOW!
65 */ 63 */
66 OPimRecord *record( const QString& service, int uid ); 64 OPimRecord *record( const QString& service, int uid );
67 65
68 /** 66 /**
69 * return the QCopChannel for service 67 * return the QCopChannel for service
70 * When we will use Qtopia Services it will be used here 68 * When we will use Qtopia Services it will be used here
71 */ 69 */
72 QCString qcopChannel( enum BuiltIn& )const; 70 QCString qcopChannel( enum BuiltIn& )const;
73 QCString qcopChannel( const QString& service )const; 71 QCString qcopChannel( const QString& service )const;
74 72
75 /** 73 /**
76 * The Application channel (QPE/Application/name) 74 * The Application channel (QPE/Application/name)
77 */ 75 */
78 QCString applicationChannel( enum BuiltIn& )const; 76 QCString applicationChannel( enum BuiltIn& )const;
79 QCString applicationChannel( const QString& service )const; 77 QCString applicationChannel( const QString& service )const;
80 78
81 /** 79 /**
82 * return a list of available services 80 * return a list of available services
83 */ 81 */
84 QStringList services()const; 82 QStringList services()const;
85 inline QString serviceName(int rrti )const; 83 inline QString serviceName(int rrti )const;
86 int serviceId( const QString& Service); 84 int serviceId( const QString& Service);
87 /** 85 /**
88 * add a record to a service... ;) 86 * add a record to a service... ;)
89 */ 87 */
90 bool add( const QString& service, const OPimRecord& ); 88 bool add( const QString& service, const OPimRecord& );
91 89
92 90
93 /** 91 /**
94 * record returns an empty record for a given service. 92 * record returns an empty record for a given service.
95 * Be sure to delete it!!! 93 * Be sure to delete it!!!
96 * 94 *
97 */ 95 */
98 OPimRecord* record( const QString& service ); 96 OPimRecord* record( const QString& service );
99 OPimRecord* record( int rtti ); 97 OPimRecord* record( int rtti );
100 98
101 /** 99 /**
102 * you can cast to your 100 * you can cast to your
103 */ 101 */
104 OPimBase* backend( const QString& service ); 102 OPimBase* backend( const QString& service );
105 OPimBase* backend( int rtti ); 103 OPimBase* backend( int rtti );
106 104
107 private: 105 private:
108 OPimResolver(); 106 OPimResolver();
109 void loadData(); 107 void loadData();
110 inline bool isBuiltIn( const QString& )const; 108 inline bool isBuiltIn( const QString& )const;
111 OPimRecord* recordExtern( const QString&, int ); 109 OPimRecord* recordExtern( const QString&, int );
112 OPimRecord* recordExtern( const QString& ); 110 OPimRecord* recordExtern( const QString& );
113 111
114 static OPimResolver* m_self; 112 static OPimResolver* m_self;
115 struct Data; 113 struct Data;
116 class Private; 114 class Private;
117 115
118 Data* data; 116 Data* data;
119 Private* d; 117 Private* d;
120 QStringList m_builtIns; 118 QStringList m_builtIns;
121}; 119};
122 120
123} 121}
124 122
125#endif 123#endif
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h
index 8336b3e..ae1e0d2 100644
--- a/libopie2/opiepim/core/opimstate.h
+++ b/libopie2/opiepim/core/opimstate.h
@@ -1,78 +1,72 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIMSTATE_H 29#ifndef OPIMSTATE_H
30#define OPIMSTATE_H 30#define OPIMSTATE_H
31 31
32/* QT */ 32/* QT */
33#include <qstring.h> 33#include <qstring.h>
34 34
35namespace Opie { 35namespace Opie {
36/** 36/**
37 * The State of a Task 37 * The State of a Task
38 * This class encapsules the state of a todo 38 * This class encapsules the state of a todo
39 * and it's shared too 39 * and it's shared too
40 */ 40 */
41/*
42 * in c a simple struct would be enough ;)
43 * g_new_state();
44 * g_do_some_thing( state_t* );
45 * ;)
46 */
47class OPimState { 41class OPimState {
48 42
49 public: 43 public:
50 enum State { 44 enum State {
51 Started = 0, 45 Started = 0,
52 Postponed, 46 Postponed,
53 Finished, 47 Finished,
54 NotStarted, 48 NotStarted,
55 Undefined 49 Undefined
56 }; 50 };
57 OPimState( int state = Undefined ); 51 OPimState( int state = Undefined );
58 OPimState( const OPimState& ); 52 OPimState( const OPimState& );
59 ~OPimState(); 53 ~OPimState();
60 54
61 bool operator==( const OPimState& ); 55 bool operator==( const OPimState& );
62 OPimState &operator=( const OPimState& ); 56 OPimState &operator=( const OPimState& );
63 void setState( int state); 57 void setState( int state);
64 int state()const; 58 int state()const;
65 59
66 private: 60 private:
67 void deref(); 61 void deref();
68 inline void copyInternally(); 62 inline void copyInternally();
69 63
70 struct Data; 64 struct Data;
71 Data* data; 65 Data* data;
72 66
73 class Private; 67 class Private;
74 Private *d; 68 Private *d;
75}; 69};
76 70
77} 71}
78#endif 72#endif
diff --git a/libopie2/opiepim/core/opimtemplatebase.cpp b/libopie2/opiepim/core/opimtemplatebase.cpp
new file mode 100644
index 0000000..0a07320
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtemplatebase.cpp
@@ -0,0 +1,112 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <zecke@handhelds.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 "opimtemplatebase.h"
31
32#include <opie2/opimoccurrence.h>
33#include <opie2/private/opimoccurrence_p.h>
34
35namespace Opie {
36
37static void setPeriod( OPimOccurrence& oc, bool period, const QDate& d,
38 const QTime& s, const QTime& t ) {
39 if ( period )
40 oc.setPeriod( d );
41 else
42 oc.setPeriod( d, s, t );
43}
44
45// namespace Opie {
46OPimBase::OPimBase() {}
47OPimBase::~OPimBase() {}
48
49/**
50 * @internal Convert internal Occurrence representation
51 * to the external
52 */
53OPimOccurrence::List OPimBase::convertOccurrenceFromBackend( const OPimBackendOccurrence::List& lst )const {
54 OPimOccurrence::List oc_lst;
55
56 /*
57 * Split multiday events up. Create the internal data structure
58 * and then iterate over the days and create the OPimOccurrecne.
59 */
60 for ( OPimBackendOccurrence::List::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
61 OPimBackendOccurrence boc = *it;
62
63 /*
64 * Create the Shared Data Structure
65 */
66 OPimOccurrence::Data *data = new OPimOccurrence::Data();
67 data->summary = boc.summary();
68 data->location = boc.location();
69 data->note = boc.note();
70 data->uid = boc.uid();
71 data->backend = const_cast<OPimBase*>(this);
72
73 QDateTime start = boc.startDateTime();
74 QDateTime end = boc.endDateTime();
75
76 /*
77 * Start and End are on the same day
78 * Start and End are on two different ways.
79 * - Add Start and End and the days inbetween
80 */
81 int dto = start.daysTo( end );
82 bool allDay = boc.isAllDay();
83
84 if ( dto == 0 ) {
85 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::StartEnd );
86 setPeriod( oc, allDay, start.date(), start.time(), end.time() );
87 oc_lst.append( oc );
88 }else {
89
90 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::Start );
91 setPeriod( oc, allDay, start.date(), start.time(), QTime(23,59,59));
92 oc_lst.append( oc );
93
94 QDate next = start.addDays( 1 ).date();
95 while ( next != end.date() ) {
96 oc = OPimOccurrence( data, OPimOccurrence::MidWay );
97 setPeriod( oc, allDay, next, QTime(0, 0, 0), QTime(23, 59, 59));
98 oc_lst.append( oc );
99 next = next.addDays( 1 );
100 }
101
102 oc = OPimOccurrence( data, OPimOccurrence::End );
103 setPeriod( oc, allDay, end.date(), QTime(0, 0, 0 ), end.time() );
104 oc_lst.append( oc );
105 }
106 }
107
108 return oc_lst;
109}
110// }
111
112}
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index 787486c..b238a68 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -1,130 +1,223 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OTEMPLATEBASE_H 29#ifndef OTEMPLATEBASE_H
30#define OTEMPLATEBASE_H 30#define OTEMPLATEBASE_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecord.h> 33#include <opie2/opimrecord.h>
34#include <opie2/opimcache.h> 34#include <opie2/opimcache.h>
35#include <opie2/opimoccurrence.h>
36#include <opie2/opimbackendoccurrence.h>
35 37
36/* QT */ 38/* QT */
37#include <qarray.h> 39#include <qarray.h>
40#include <qdatetime.h>
38 41
39namespace Opie { 42namespace Opie {
43
44class OPimBasePrivate;
45
40/** 46/**
41 * Templates do not have a base class, This is why 47 * This is the base class for all our Interfaces to the
42 * we've this class 48 * PIM Records. It is pointer based and can be used
43 * this is here to give us the possibility 49 * generically for all types of Records.
44 * to have a common base class 50 *
45 * You may not want to use that interface internaly
46 * POOR mans interface
47 */ 51 */
48class OPimBasePrivate;
49struct OPimBase { 52struct OPimBase {
53 //@{
54 OPimBase();
55 virtual ~OPimBase();
56 //@}
57
58 //@{
50 /** 59 /**
51 * return the rtti 60 * return the rtti
52 */ 61 */
53 virtual int rtti() const = 0; 62 virtual int rtti() const = 0;
54 virtual OPimRecord* record()const = 0; 63 virtual OPimRecord* record()const = 0;
55 virtual OPimRecord* record(int uid)const = 0; 64 virtual OPimRecord* record(int uid)const = 0;
65 //@}
66
67 //@{
56 virtual bool add( const OPimRecord& ) = 0; 68 virtual bool add( const OPimRecord& ) = 0;
57 virtual bool add( const OPimRecord* ) = 0; 69 virtual bool add( const OPimRecord* ) = 0;
70
58 virtual bool remove( int uid ) = 0; 71 virtual bool remove( int uid ) = 0;
59 virtual bool remove( const OPimRecord& ) = 0; 72 virtual bool remove( const OPimRecord& ) = 0;
73 //@}
74
75 //@{
60 virtual void clear() = 0; 76 virtual void clear() = 0;
61 virtual bool load() = 0; 77 virtual bool load() = 0;
62 virtual bool save() = 0; 78 virtual bool save() = 0;
63 virtual QArray<int> records()const = 0; 79 //@}
64 /* 80
65 * ADD editing here? 81 //@{
66 * -zecke 82 virtual QArray<UID> records()const = 0;
83
84 /** Constants for query.
85 * Use this constants to set the query parameters.
86 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
87 * @see queryByExample()
67 */ 88 */
68private: 89 enum QuerySettings {
69 OPimBasePrivate* d; 90 WildCards = 0x0001, /** Use Wildcards */
91 IgnoreCase = 0x0002, /** Ignore the Case */
92 RegExp = 0x0004, /** Do a Regular Expression match */
93 ExactMatch = 0x0008, /** It needs to exactly match */
94 MatchOne = 0x0010, /** Only one Entry must match */
95 DateDiff = 0x0020, /** Find all entries from today until given date */
96 DateYear = 0x0040, /** The year matches */
97 DateMonth = 0x0080, /** The month matches */
98 DateDay = 0x0100, /** The day matches */
99 LastItem = 0xffff /** the last possible name */
100 };
70 101
102 /**
103 * Common Attributes for the Sort Order
104 */
105 enum SortOrderBase {
106 SortSummary = 0, /** Sort by a Summary of the records */
107 SortByCategory = 1, /** Sort by Category */
108 SortByDate = 2, /** Sort by Date */
109 SortCustom = 10, /** The First available sort number for the OPimAccessTemplates */
110 LastSortOrderBase = 0xffff /** make this enum 16bit large */
111 };
112
113 /**
114 * Sort with the help of the \sa sorted function
115 * a list of Items.
116 * The Item you provide in SortOrder will be used
117 * for sorting.
118 *
119 * @see sorted
120 */
121 enum SortFilterBase {
122 FilterCategory = 1,
123 FilterCustom = 1024,
124 LastSortFilterBase = 0xffffffff
125 };
126
127 virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0;
128 virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings,
129 const QDateTime& d = QDateTime() )const = 0;
130 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
131 int sortOrder, int sortFilter, int cat)const = 0;
132 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
133 int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
134 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0;
135 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
136 virtual OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const = 0;
137 virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0;
138 //@}
139
140
141protected:
142 OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const;
143
144private:
145 OPimBasePrivate* d;
71}; 146};
147
148
72/** 149/**
73 * internal template base 150 * internal template base
74 * Attention: T needs to implement the copy c'tor!!! 151 * Attention: T needs to implement the copy c'tor!!!
75 */ 152 */
76class OTemplateBasePrivate; 153class OTemplateBasePrivate;
77template <class T = OPimRecord> 154template <class T = OPimRecord>
78class OTemplateBase : public OPimBase { 155class OTemplateBase : public OPimBase {
79public: 156public:
80 /** Look ahead direction of cache */ 157 /**
81 enum CacheDirection { Forward=0, Reverse }; 158 * The Direction for ReadAhead/ReadBehind which will
82 159 * be used by the backends to Cache Items in
83 OTemplateBase() { 160 * advance.
161 * For example if you know that you will access the
162 * next ten items you can give the backend a hint
163 * to read ahead or read before.
164 */
165 enum CacheDirection {
166 Forward=0, /** Go forward when caching (++ to the index) */
167 Reverse /** Go backward when caching (-- to the index) */
84 }; 168 };
85 virtual ~OTemplateBase() { 169
86 } 170
171 //@{
172 OTemplateBase() {};
173 virtual ~OTemplateBase() {}
174 //@}
175
176
177 //@{
87 virtual T find( int uid )const = 0; 178 virtual T find( int uid )const = 0;
88 179
89 /** 180 /**
90 * read ahead find 181 * read ahead find
91 */ 182 */
92 virtual T find( int uid, const QArray<int>& items, 183 virtual T find( int uid, const QArray<int>& items,
93 uint current, CacheDirection dir = Forward )const = 0; 184 uint current, CacheDirection dir = Forward )const = 0;
185 //@}
94 186
187 //@{
95 /** 188 /**
96 * Put element into Cache 189 * Put element into Cache
97 */ 190 */
98 virtual void cache( const T& )const = 0; 191 virtual void cache( const T& )const = 0;
99 virtual void setSaneCacheSize( int ) = 0; 192 virtual void setSaneCacheSize( int ) = 0;
100 193
101 OPimRecord* record()const; 194 OPimRecord* record()const;
102 OPimRecord* record(int uid )const; 195 OPimRecord* record(int uid )const;
103 static T* rec(); 196 static T* rec();
197 //@}
104 198
105
106private: 199private:
107 OTemplateBasePrivate *d; 200 OTemplateBasePrivate *d;
108}; 201};
109 202
110 203
111template <class T> 204template <class T>
112OPimRecord* OTemplateBase<T>::record()const { 205OPimRecord* OTemplateBase<T>::record()const {
113 T* t = new T; 206 T* t = new T;
114 return t; 207 return t;
115} 208}
116template <class T> 209template <class T>
117OPimRecord* OTemplateBase<T>::record(int uid )const { 210OPimRecord* OTemplateBase<T>::record(int uid )const {
118 T t2 = find(uid ); 211 T t2 = find(uid );
119 T* t1 = new T(t2); 212 T* t1 = new T(t2);
120 213
121 return t1; 214 return t1;
122}; 215}
216
123template <class T> 217template <class T>
124T* OTemplateBase<T>::rec() { 218T* OTemplateBase<T>::rec() {
125 return new T; 219 return new T;
126} 220}
127
128} 221}
129 222
130#endif 223#endif
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index 5b32b1f..1dc36b4 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -1,192 +1,206 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimtimezone.h" 30#include "opimtimezone.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35/* STD */ 35/* STD */
36#include <stdio.h> 36#include <stdio.h>
37#include <stdlib.h> 37#include <stdlib.h>
38#include <sys/types.h> 38#include <sys/types.h>
39 39
40namespace Opie 40namespace Opie
41{ 41{
42 42
43QDateTime utcTime( time_t t ) 43/*
44 * Save the old timeZone in a secure way (NULL Pointer check),
45 * set the new timeZone from the parameter, call tzset
46 * and then return the old timezone
47 */
48static QString setTimeZone( const QString& zone) {
49 QString old;
50 char *org = ::getenv( "TZ" );
51 if( org )
52 old = QString::fromLocal8Bit( org );
53
54 ::setenv( "TZ", zone.local8Bit(), true );
55 ::tzset();
56
57 return old;
58}
59
60static void resetTimeZone( const QString& zone ) {
61 ::setenv( "TZ", zone.local8Bit(), true );
62}
63
64static QDateTime utcTime( time_t t )
44{ 65{
45 tm * broken = ::gmtime( &t ); 66 tm * broken = ::gmtime( &t );
46 QDateTime ret; 67 QDateTime ret;
47 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); 68 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
48 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); 69 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
49 return ret; 70 return ret;
50} 71}
51 72
52QDateTime utcTime( time_t t, const QString& zone ) 73static QDateTime utcTime( time_t t, const QString& zone )
53{ 74{
54 QCString org = ::getenv( "TZ" );
55#ifndef Q_OS_MACX // Following line causes bus errors on Mac
56
57 ::setenv( "TZ", zone.latin1(), true );
58 ::tzset();
59 75
76#ifndef Q_OS_MACX // Following line causes bus errors on Mac
77 QString old = setTimeZone( zone );
60 tm* broken = ::localtime( &t ); 78 tm* broken = ::localtime( &t );
61 ::setenv( "TZ", org, true ); 79 resetTimeZone( old );
62#else 80#else
63#warning "Need a replacement for MacOSX!!" 81#warning "Need a replacement for MacOSX!!"
64 82
65 tm* broken = ::localtime( &t ); 83 tm* broken = ::localtime( &t );
66#endif 84#endif
67 85
68 QDateTime ret; 86 QDateTime ret;
69 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); 87 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
70 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); 88 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
71 89
72 return ret; 90 return ret;
73} 91}
74 92
75 93
76time_t to_Time_t( const QDateTime& utc, const QString& str ) 94static time_t to_Time_t( const QDateTime& utc, const QString& str )
77{ 95{
78 QDate d = utc.date(); 96 QDate d = utc.date();
79 QTime t = utc.time(); 97 QTime t = utc.time();
80 98
81 tm broken; 99 tm broken;
82 broken.tm_year = d.year() - 1900; 100 broken.tm_year = d.year() - 1900;
83 broken.tm_mon = d.month() - 1; 101 broken.tm_mon = d.month() - 1;
84 broken.tm_mday = d.day(); 102 broken.tm_mday = d.day();
85 broken.tm_hour = t.hour(); 103 broken.tm_hour = t.hour();
86 broken.tm_min = t.minute(); 104 broken.tm_min = t.minute();
87 broken.tm_sec = t.second(); 105 broken.tm_sec = t.second();
88 106
89 QCString org = ::getenv( "TZ" );
90#ifndef Q_OS_MACX // Following line causes bus errors on Mac 107#ifndef Q_OS_MACX // Following line causes bus errors on Mac
91 108 QString old = setTimeZone( str );
92 ::setenv( "TZ", str.latin1(), true );
93 ::tzset();
94
95 time_t ti = ::mktime( &broken ); 109 time_t ti = ::mktime( &broken );
96 ::setenv( "TZ", org, true ); 110 resetTimeZone( old );
97#else 111#else
98#warning "Need a replacement for MacOSX!!" 112#warning "Need a replacement for MacOSX!!"
99 113
100 time_t ti = ::mktime( &broken ); 114 time_t ti = ::mktime( &broken );
101#endif 115#endif
102 116
103 return ti; 117 return ti;
104} 118}
105} 119}
106 120
107namespace Opie 121namespace Opie
108{ 122{
109OPimTimeZone::OPimTimeZone( const ZoneName& zone ) 123OPimTimeZone::OPimTimeZone( const ZoneName& zone )
110 : m_name( zone ) 124 : m_name( zone )
111{} 125{}
112 126
113 127
114OPimTimeZone::~OPimTimeZone() 128OPimTimeZone::~OPimTimeZone()
115{} 129{}
116 130
117 131
118bool OPimTimeZone::isValid() const 132bool OPimTimeZone::isValid() const
119{ 133{
120 return !m_name.isEmpty(); 134 return !m_name.isEmpty();
121} 135}
122 136
123/* 137/*
124 * we will get the current timezone 138 * we will get the current timezone
125 * and ask it to convert to the timezone date 139 * and ask it to convert to the timezone date
126 */ 140 */
127QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt ) 141QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt )
128{ 142{
129 return OPimTimeZone::current().toDateTime( dt, *this ); 143 return OPimTimeZone::current().toDateTime( dt, *this );
130} 144}
131 145
132 146
133QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt ) 147QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt )
134{ 148{
135 return OPimTimeZone::utc().toDateTime( dt, *this ); 149 return OPimTimeZone::utc().toDateTime( dt, *this );
136} 150}
137 151
138 152
139QDateTime OPimTimeZone::fromUTCDateTime( time_t t ) 153QDateTime OPimTimeZone::fromUTCDateTime( time_t t )
140{ 154{
141 return utcTime( t ); 155 return utcTime( t );
142} 156}
143 157
144 158
145QDateTime OPimTimeZone::toDateTime( time_t t ) 159QDateTime OPimTimeZone::toDateTime( time_t t )
146{ 160{
147 return utcTime( t, m_name ); 161 return utcTime( t, m_name );
148} 162}
149 163
150 164
151/* 165/*
152 * convert dt to utc using zone.m_name 166 * convert dt to utc using zone.m_name
153 * convert utc -> timeZoneDT using this->m_name 167 * convert utc -> timeZoneDT using this->m_name
154 */ 168 */
155QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) 169QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
156{ 170{
157 time_t utc = to_Time_t( dt, m_name ); 171 time_t utc = to_Time_t( dt, m_name );
158 return utcTime( utc, zone.m_name ); 172 return utcTime( utc, zone.m_name );
159} 173}
160 174
161 175
162time_t OPimTimeZone::fromDateTime( const QDateTime& time ) 176time_t OPimTimeZone::fromDateTime( const QDateTime& time )
163{ 177{
164 return to_Time_t( time, m_name ); 178 return to_Time_t( time, m_name );
165} 179}
166 180
167 181
168time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) 182time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
169{ 183{
170 return to_Time_t( time, "Europe/London" ); 184 return to_Time_t( time, "Europe/London" );
171} 185}
172 186
173 187
174OPimTimeZone OPimTimeZone::current() 188OPimTimeZone OPimTimeZone::current()
175{ 189{
176 QCString str = ::getenv( "TZ" ); 190 QCString str = ::getenv( "TZ" );
177 OPimTimeZone zone( str ); 191 OPimTimeZone zone( str );
178 return zone; 192 return zone;
179} 193}
180 194
181 195
182OPimTimeZone OPimTimeZone::utc() 196OPimTimeZone OPimTimeZone::utc()
183{ 197{
184 return OPimTimeZone( "Europe/London" ); 198 return OPimTimeZone( "Europe/London" );
185} 199}
186 200
187 201
188QString OPimTimeZone::timeZone() const 202QString OPimTimeZone::timeZone() const
189{ 203{
190 return m_name; 204 return m_name;
191} 205}
192 206
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 27b36a6..16ca987 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -1,479 +1,494 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimtodo.h" 30#include "opimtodo.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimstate.h> 33#include <opie2/opimstate.h>
34#include <opie2/opimrecurrence.h> 34#include <opie2/opimrecurrence.h>
35#include <opie2/opimmaintainer.h> 35#include <opie2/opimmaintainer.h>
36#include <opie2/opimnotifymanager.h> 36#include <opie2/opimnotifymanager.h>
37#include <opie2/opimresolver.h> 37#include <opie2/opimresolver.h>
38#include <opie2/odebug.h> 38#include <opie2/odebug.h>
39 39
40#include <qpe/palmtopuidgen.h> 40#include <qpe/palmtopuidgen.h>
41#include <qpe/palmtoprecord.h> 41#include <qpe/palmtoprecord.h>
42#include <qpe/categories.h> 42#include <qpe/categories.h>
43#include <qpe/categoryselect.h> 43#include <qpe/categoryselect.h>
44#include <qpe/stringutil.h> 44#include <qpe/stringutil.h>
45 45
46/* QT */ 46/* QT */
47#include <qobject.h> 47#include <qobject.h>
48#include <qshared.h> 48#include <qshared.h>
49 49
50namespace Opie 50namespace Opie
51{ 51{
52 52
53struct OPimTodo::OPimTodoData : public QShared 53struct OPimTodo::OPimTodoData : public QShared
54{ 54{
55 OPimTodoData() : QShared() 55 OPimTodoData() : QShared()
56 { 56 {
57 recur = 0; 57 recur = 0;
58 state = 0; 58 state = 0;
59 maintainer = 0; 59 maintainer = 0;
60 notifiers = 0; 60 notifiers = 0;
61 }; 61 };
62 ~OPimTodoData() 62 ~OPimTodoData()
63 { 63 {
64 delete recur; 64 delete recur;
65 delete maintainer; 65 delete maintainer;
66 delete notifiers; 66 delete notifiers;
67 delete state;
67 } 68 }
68 69
69 QDate date; 70 QDate date;
70 bool isCompleted: 1; 71 bool isCompleted: 1;
71 bool hasDate: 1; 72 bool hasDate: 1;
72 int priority; 73 int priority;
73 QString desc; 74 QString desc;
74 QString sum; 75 QString sum;
75 QMap<QString, QString> extra; 76 QMap<QString, QString> extra;
76 ushort prog; 77 ushort prog;
77 OPimState *state; 78 OPimState *state;
78 OPimRecurrence *recur; 79 OPimRecurrence *recur;
79 OPimMaintainer *maintainer; 80 OPimMaintainer *maintainer;
80 QDate start; 81 QDate start;
81 QDate completed; 82 QDate completed;
82 OPimNotifyManager *notifiers; 83 OPimNotifyManager *notifiers;
83}; 84};
84 85
85 86
86OPimTodo::OPimTodo( const OPimTodo &event ) 87OPimTodo::OPimTodo( const OPimTodo &event )
87 : OPimRecord( event ), data( event.data ) 88 : OPimRecord( event ), data( event.data )
88{ 89{
89 data->ref(); 90 data->ref();
90 // owarn << "ref up" << oendl;
91} 91}
92 92
93 93
94OPimTodo::~OPimTodo() 94OPimTodo::~OPimTodo()
95{ 95{
96 96
97 // owarn << "~OPimTodo " << oendl;
98 if ( data->deref() ) 97 if ( data->deref() )
99 { 98 {
100 // owarn << "OPimTodo::dereffing" << oendl;
101 delete data; 99 delete data;
102 data = 0l; 100 data = 0l;
103 } 101 }
104} 102}
105 103
106 104
107OPimTodo::OPimTodo( bool completed, int priority, 105OPimTodo::OPimTodo( bool completed, int priority,
108 const QArray<int> &category, 106 const QArray<int> &category,
109 const QString& summary, 107 const QString& summary,
110 const QString &description, 108 const QString &description,
111 ushort progress, 109 ushort progress,
112 bool hasDate, QDate date, int uid ) 110 bool hasDate, QDate date, int uid )
113 : OPimRecord( uid ) 111 : OPimRecord( uid )
114{ 112{
115 // owarn << "OPimTodoData " + summary << oendl;
116 setCategories( category ); 113 setCategories( category );
117 114
118 data = new OPimTodoData; 115 data = new OPimTodoData;
119 116
120 data->date = date; 117 data->date = date;
121 data->isCompleted = completed; 118 data->isCompleted = completed;
122 data->hasDate = hasDate; 119 data->hasDate = hasDate;
123 data->priority = priority; 120 data->priority = priority;
124 data->sum = summary; 121 data->sum = summary;
125 data->prog = progress; 122 data->prog = progress;
126 data->desc = Qtopia::simplifyMultiLineSpace( description ); 123 data->desc = Qtopia::simplifyMultiLineSpace( description );
127} 124}
128 125
129 126
130OPimTodo::OPimTodo( bool completed, int priority, 127OPimTodo::OPimTodo( bool completed, int priority,
131 const QStringList &category, 128 const QStringList &category,
132 const QString& summary, 129 const QString& summary,
133 const QString &description, 130 const QString &description,
134 ushort progress, 131 ushort progress,
135 bool hasDate, QDate date, int uid ) 132 bool hasDate, QDate date, int uid )
136 : OPimRecord( uid ) 133 : OPimRecord( uid )
137{ 134{
138 // owarn << "OPimTodoData" + summary << oendl;
139 setCategories( idsFromString( category.join( ";" ) ) ); 135 setCategories( idsFromString( category.join( ";" ) ) );
140 136
141 data = new OPimTodoData; 137 data = new OPimTodoData;
142 138
143 data->date = date; 139 data->date = date;
144 data->isCompleted = completed; 140 data->isCompleted = completed;
145 data->hasDate = hasDate; 141 data->hasDate = hasDate;
146 data->priority = priority; 142 data->priority = priority;
147 data->sum = summary; 143 data->sum = summary;
148 data->prog = progress; 144 data->prog = progress;
149 data->desc = Qtopia::simplifyMultiLineSpace( description ); 145 data->desc = Qtopia::simplifyMultiLineSpace( description );
150} 146}
151 147
152 148
153bool OPimTodo::match( const QRegExp &regExp ) const 149bool OPimTodo::match( const QRegExp &regExp ) const
154{ 150{
155 if ( QString::number( data->priority ).find( regExp ) != -1 ) 151 if ( QString::number( data->priority ).find( regExp ) != -1 )
156 { 152 {
157 setLastHitField( Priority ); 153 setLastHitField( Priority );
158 return true; 154 return true;
159 } 155 }
160 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) 156 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
161 { 157 {
162 setLastHitField( HasDate ); 158 setLastHitField( HasDate );
163 return true; 159 return true;
164 } 160 }
165 else if ( data->desc.find( regExp ) != -1 ) 161 else if ( data->desc.find( regExp ) != -1 )
166 { 162 {
167 setLastHitField( Description ); 163 setLastHitField( Description );
168 return true; 164 return true;
169 } 165 }
170 else if ( data->sum.find( regExp ) != -1 ) 166 else if ( data->sum.find( regExp ) != -1 )
171 { 167 {
172 setLastHitField( Summary ); 168 setLastHitField( Summary );
173 return true; 169 return true;
174 } 170 }
175 return false; 171 return false;
176} 172}
177 173
178 174
179bool OPimTodo::isCompleted() const 175bool OPimTodo::isCompleted() const
180{ 176{
181 return data->isCompleted; 177 return data->isCompleted;
182} 178}
183 179
184 180
185bool OPimTodo::hasDueDate() const 181bool OPimTodo::hasDueDate() const
186{ 182{
187 return data->hasDate; 183 return data->hasDate;
188} 184}
189 185
190 186/**
187 * \brief Does this Todo have a start date
188 *
189 * Does this Todo have a start date. The decision
190 * is based on if the internal startDate isValid
191 * in the sense of QDate::isValid.
192 *
193 * @return True if the startDate isValid
194 * @see startDate
195 * @see setStartDate
196 * @see QDate::isValid()
197 */
191bool OPimTodo::hasStartDate() const 198bool OPimTodo::hasStartDate() const
192{ 199{
193 return data->start.isValid(); 200 return data->start.isValid();
194} 201}
195 202
196 203/**
204 * \brief Does this Todo have a Date when it was completed
205 *
206 * As in \sa hasStartDate() it is determined if there
207 * is a completed date by looking if the internal date
208 * isValid \sa QDate::isValid.
209 *
210 * @see hasStartDate
211 * @return True if the completedDate is set and valid.
212 */
197bool OPimTodo::hasCompletedDate() const 213bool OPimTodo::hasCompletedDate() const
198{ 214{
199 return data->completed.isValid(); 215 return data->completed.isValid();
200} 216}
201 217
202 218
203int OPimTodo::priority() const 219int OPimTodo::priority() const
204{ 220{
205 return data->priority; 221 return data->priority;
206} 222}
207 223
208 224
209QString OPimTodo::summary() const 225QString OPimTodo::summary() const
210{ 226{
211 return data->sum; 227 return data->sum;
212} 228}
213 229
214 230
215ushort OPimTodo::progress() const 231ushort OPimTodo::progress() const
216{ 232{
217 return data->prog; 233 return data->prog;
218} 234}
219 235
220 236
221QDate OPimTodo::dueDate() const 237QDate OPimTodo::dueDate() const
222{ 238{
223 return data->date; 239 return data->date;
224} 240}
225 241
226 242
227QDate OPimTodo::startDate() const 243QDate OPimTodo::startDate() const
228{ 244{
229 return data->start; 245 return data->start;
230} 246}
231 247
232 248
233QDate OPimTodo::completedDate() const 249QDate OPimTodo::completedDate() const
234{ 250{
235 return data->completed; 251 return data->completed;
236} 252}
237 253
238 254
239QString OPimTodo::description() const 255QString OPimTodo::description() const
240{ 256{
241 return data->desc; 257 return data->desc;
242} 258}
243 259
244 260
245bool OPimTodo::hasState() const 261bool OPimTodo::hasState() const
246{ 262{
247 if ( !data->state ) return false; 263 if ( !data->state ) return false;
248 return ( data->state->state() != OPimState::Undefined ); 264 return ( data->state->state() != OPimState::Undefined );
249} 265}
250 266
251 267
252OPimState OPimTodo::state() const 268OPimState OPimTodo::state() const
253{ 269{
254 if ( !data->state ) 270 if ( !data->state )
255 { 271 {
256 OPimState state; 272 OPimState state;
257 return state; 273 return state;
258 } 274 }
259 275
260 return ( *data->state ); 276 return ( *data->state );
261} 277}
262 278
263 279
264bool OPimTodo::hasRecurrence() const 280bool OPimTodo::hasRecurrence() const
265{ 281{
266 if ( !data->recur ) return false; 282 if ( !data->recur ) return false;
267 return data->recur->doesRecur(); 283 return data->recur->doesRecur();
268} 284}
269 285
270 286
271OPimRecurrence OPimTodo::recurrence() const 287OPimRecurrence OPimTodo::recurrence() const
272{ 288{
273 if ( !data->recur ) return OPimRecurrence(); 289 if ( !data->recur ) return OPimRecurrence();
274 290
275 return ( *data->recur ); 291 return ( *data->recur );
276} 292}
277 293
278 294
279bool OPimTodo::hasMaintainer() const 295bool OPimTodo::hasMaintainer() const
280{ 296{
281 if ( !data->maintainer ) return false; 297 if ( !data->maintainer ) return false;
282 298
283 return ( data->maintainer->mode() != OPimMaintainer::Undefined ); 299 return ( data->maintainer->mode() != OPimMaintainer::Undefined );
284} 300}
285 301
286 302
287OPimMaintainer OPimTodo::maintainer() const 303OPimMaintainer OPimTodo::maintainer() const
288{ 304{
289 if ( !data->maintainer ) return OPimMaintainer(); 305 if ( !data->maintainer ) return OPimMaintainer();
290 306
291 return ( *data->maintainer ); 307 return ( *data->maintainer );
292} 308}
293 309
294 310
295void OPimTodo::setCompleted( bool completed ) 311void OPimTodo::setCompleted( bool completed )
296{ 312{
297 changeOrModify(); 313 changeOrModify();
298 data->isCompleted = completed; 314 data->isCompleted = completed;
299} 315}
300 316
301 317
302void OPimTodo::setHasDueDate( bool hasDate ) 318void OPimTodo::setHasDueDate( bool hasDate )
303{ 319{
304 changeOrModify(); 320 changeOrModify();
305 data->hasDate = hasDate; 321 data->hasDate = hasDate;
306} 322}
307 323
308 324
309void OPimTodo::setDescription( const QString &desc ) 325void OPimTodo::setDescription( const QString &desc )
310{ 326{
311 // owarn << "desc " + desc << oendl;
312 changeOrModify(); 327 changeOrModify();
313 data->desc = Qtopia::simplifyMultiLineSpace( desc ); 328 data->desc = Qtopia::simplifyMultiLineSpace( desc );
314} 329}
315 330
316 331
317void OPimTodo::setSummary( const QString& sum ) 332void OPimTodo::setSummary( const QString& sum )
318{ 333{
319 changeOrModify(); 334 changeOrModify();
320 data->sum = sum; 335 data->sum = sum;
321} 336}
322 337
323 338
324void OPimTodo::setPriority( int prio ) 339void OPimTodo::setPriority( int prio )
325{ 340{
326 changeOrModify(); 341 changeOrModify();
327 data->priority = prio; 342 data->priority = prio;
328} 343}
329 344
330 345
331void OPimTodo::setDueDate( const QDate& date ) 346void OPimTodo::setDueDate( const QDate& date )
332{ 347{
333 changeOrModify(); 348 changeOrModify();
334 data->date = date; 349 data->date = date;
335} 350}
336 351
337 352
338void OPimTodo::setStartDate( const QDate& date ) 353void OPimTodo::setStartDate( const QDate& date )
339{ 354{
340 changeOrModify(); 355 changeOrModify();
341 data->start = date; 356 data->start = date;
342} 357}
343 358
344 359
345void OPimTodo::setCompletedDate( const QDate& date ) 360void OPimTodo::setCompletedDate( const QDate& date )
346{ 361{
347 changeOrModify(); 362 changeOrModify();
348 data->completed = date; 363 data->completed = date;
349} 364}
350 365
351 366
352void OPimTodo::setState( const OPimState& state ) 367void OPimTodo::setState( const OPimState& state )
353{ 368{
354 changeOrModify(); 369 changeOrModify();
355 if ( data->state ) 370 if ( data->state )
356 ( *data->state ) = state; 371 ( *data->state ) = state;
357 else 372 else
358 data->state = new OPimState( state ); 373 data->state = new OPimState( state );
359} 374}
360 375
361 376
362void OPimTodo::setRecurrence( const OPimRecurrence& rec ) 377void OPimTodo::setRecurrence( const OPimRecurrence& rec )
363{ 378{
364 changeOrModify(); 379 changeOrModify();
365 if ( data->recur ) 380 if ( data->recur )
366 ( *data->recur ) = rec; 381 ( *data->recur ) = rec;
367 else 382 else
368 data->recur = new OPimRecurrence( rec ); 383 data->recur = new OPimRecurrence( rec );
369} 384}
370 385
371 386
372void OPimTodo::setMaintainer( const OPimMaintainer& pim ) 387void OPimTodo::setMaintainer( const OPimMaintainer& pim )
373{ 388{
374 changeOrModify(); 389 changeOrModify();
375 390
376 if ( data->maintainer ) 391 if ( data->maintainer )
377 ( *data->maintainer ) = pim; 392 ( *data->maintainer ) = pim;
378 else 393 else
379 data->maintainer = new OPimMaintainer( pim ); 394 data->maintainer = new OPimMaintainer( pim );
380} 395}
381 396
382 397
383bool OPimTodo::isOverdue( ) 398bool OPimTodo::isOverdue( )const
384{ 399{
385 if ( data->hasDate && !data->isCompleted ) 400 if ( data->hasDate && !data->isCompleted )
386 return QDate::currentDate() > data->date; 401 return QDate::currentDate() > data->date;
387 return false; 402 return false;
388} 403}
389 404
390 405
391void OPimTodo::setProgress( ushort progress ) 406void OPimTodo::setProgress( ushort progress )
392{ 407{
393 changeOrModify(); 408 changeOrModify();
394 data->prog = progress; 409 data->prog = progress;
395} 410}
396 411
397 412
398QString OPimTodo::toShortText() const 413QString OPimTodo::toShortText() const
399{ 414{
400 return summary(); 415 return summary();
401} 416}
402 417
403 418
404/*! 419/*!
405 Returns a richt text string 420 Returns a richt text string
406*/ 421*/
407QString OPimTodo::toRichText() const 422QString OPimTodo::toRichText() const
408{ 423{
409 QString text; 424 QString text;
410 QStringList catlist; 425 QStringList catlist;
411 426
412 // summary 427 // summary
413 text += "<b><h3><img src=\"todo/TodoList\"> "; 428 text += "<b><h3><img src=\"todo/TodoList\"> ";
414 if ( !summary().isEmpty() ) 429 if ( !summary().isEmpty() )
415 { 430 {
416 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); 431 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
417 } 432 }
418 text += "</h3></b><br><hr><br>"; 433 text += "</h3></b><br><hr><br>";
419 434
420 // description 435 // description
421 if ( !description().isEmpty() ) 436 if ( !description().isEmpty() )
422 { 437 {
423 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 438 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
424 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 439 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
425 } 440 }
426 441
427 // priority 442 // priority
428 int priorityval = priority(); 443 int priorityval = priority();
429 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + 444 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
430 QString::number( priorityval ) + "\"> "; 445 QString::number( priorityval ) + "\"> ";
431 446
432 switch ( priorityval ) 447 switch ( priorityval )
433 { 448 {
434 case 1 : text += QObject::tr( "Very high" ); 449 case 1 : text += QObject::tr( "Very high" );
435 break; 450 break;
436 case 2 : text += QObject::tr( "High" ); 451 case 2 : text += QObject::tr( "High" );
437 break; 452 break;
438 case 3 : text += QObject::tr( "Normal" ); 453 case 3 : text += QObject::tr( "Normal" );
439 break; 454 break;
440 case 4 : text += QObject::tr( "Low" ); 455 case 4 : text += QObject::tr( "Low" );
441 break; 456 break;
442 case 5 : text += QObject::tr( "Very low" ); 457 case 5 : text += QObject::tr( "Very low" );
443 break; 458 break;
444 }; 459 };
445 text += "<br>"; 460 text += "<br>";
446 461
447 // progress 462 // progress
448 text += "<b>" + QObject::tr( "Progress:" ) + " </b>" 463 text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
449 + QString::number( progress() ) + " %<br>"; 464 + QString::number( progress() ) + " %<br>";
450 465
451 // due date 466 // due date
452 if ( hasDueDate() ) 467 if ( hasDueDate() )
453 { 468 {
454 QDate dd = dueDate(); 469 QDate dd = dueDate();
455 int off = QDate::currentDate().daysTo( dd ); 470 int off = QDate::currentDate().daysTo( dd );
456 471
457 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 472 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
458 if ( off < 0 ) 473 if ( off < 0 )
459 text += "#FF0000"; 474 text += "#FF0000";
460 else if ( off == 0 ) 475 else if ( off == 0 )
461 text += "#FFFF00"; 476 text += "#FFFF00";
462 else if ( off > 0 ) 477 else if ( off > 0 )
463 text += "#00FF00"; 478 text += "#00FF00";
464 479
465 text += "\">" + dd.toString() + "</font><br>"; 480 text += "\">" + dd.toString() + "</font><br>";
466 } 481 }
467 482
468 // categories 483 // categories
469 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 484 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
470 text += categoryNames( "Todo List" ).join( ", " ); 485 text += categoryNames( "Todo List" ).join( ", " );
471 text += "<br>"; 486 text += "<br>";
472 487
473 return text; 488 return text;
474} 489}
475 490
476 491
477bool OPimTodo::hasNotifiers() const 492bool OPimTodo::hasNotifiers() const
478{ 493{
479 if ( !data->notifiers ) return false; 494 if ( !data->notifiers ) return false;
@@ -500,214 +515,296 @@ const OPimNotifyManager& OPimTodo::notifiers() const
500 515
501bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const 516bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
502{ 517{
503 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 518 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
504 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 519 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
505 if ( hasDueDate() && toDoEvent.hasDueDate() ) 520 if ( hasDueDate() && toDoEvent.hasDueDate() )
506 { 521 {
507 if ( dueDate() == toDoEvent.dueDate() ) 522 if ( dueDate() == toDoEvent.dueDate() )
508 { // let's the priority decide 523 { // let's the priority decide
509 return priority() < toDoEvent.priority(); 524 return priority() < toDoEvent.priority();
510 } 525 }
511 else 526 else
512 { 527 {
513 return dueDate() < toDoEvent.dueDate(); 528 return dueDate() < toDoEvent.dueDate();
514 } 529 }
515 } 530 }
516 return false; 531 return false;
517} 532}
518 533
519 534
520bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const 535bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
521{ 536{
522 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 537 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
523 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 538 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
524 if ( hasDueDate() && toDoEvent.hasDueDate() ) 539 if ( hasDueDate() && toDoEvent.hasDueDate() )
525 { 540 {
526 if ( dueDate() == toDoEvent.dueDate() ) 541 if ( dueDate() == toDoEvent.dueDate() )
527 { // let's the priority decide 542 { // let's the priority decide
528 return priority() <= toDoEvent.priority(); 543 return priority() <= toDoEvent.priority();
529 } 544 }
530 else 545 else
531 { 546 {
532 return dueDate() <= toDoEvent.dueDate(); 547 return dueDate() <= toDoEvent.dueDate();
533 } 548 }
534 } 549 }
535 return true; 550 return true;
536} 551}
537 552
538 553
539bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const 554bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
540{ 555{
541 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 556 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
542 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 557 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
543 if ( hasDueDate() && toDoEvent.hasDueDate() ) 558 if ( hasDueDate() && toDoEvent.hasDueDate() )
544 { 559 {
545 if ( dueDate() == toDoEvent.dueDate() ) 560 if ( dueDate() == toDoEvent.dueDate() )
546 { // let's the priority decide 561 { // let's the priority decide
547 return priority() > toDoEvent.priority(); 562 return priority() > toDoEvent.priority();
548 } 563 }
549 else 564 else
550 { 565 {
551 return dueDate() > toDoEvent.dueDate(); 566 return dueDate() > toDoEvent.dueDate();
552 } 567 }
553 } 568 }
554 return false; 569 return false;
555} 570}
556 571
557 572
558bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const 573bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
559{ 574{
560 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 575 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
561 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 576 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
562 if ( hasDueDate() && toDoEvent.hasDueDate() ) 577 if ( hasDueDate() && toDoEvent.hasDueDate() )
563 { 578 {
564 if ( dueDate() == toDoEvent.dueDate() ) 579 if ( dueDate() == toDoEvent.dueDate() )
565 { // let's the priority decide 580 { // let's the priority decide
566 return priority() > toDoEvent.priority(); 581 return priority() > toDoEvent.priority();
567 } 582 }
568 else 583 else
569 { 584 {
570 return dueDate() > toDoEvent.dueDate(); 585 return dueDate() > toDoEvent.dueDate();
571 } 586 }
572 } 587 }
573 return true; 588 return true;
574} 589}
575 590
576 591
577bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const 592bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
578{ 593{
579 if ( data->priority != toDoEvent.data->priority ) return false; 594 if ( data->priority != toDoEvent.data->priority ) return false;
580 if ( data->priority != toDoEvent.data->prog ) return false; 595 if ( data->priority != toDoEvent.data->prog ) return false;
581 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 596 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
582 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 597 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
583 if ( data->date != toDoEvent.data->date ) return false; 598 if ( data->date != toDoEvent.data->date ) return false;
584 if ( data->sum != toDoEvent.data->sum ) return false; 599 if ( data->sum != toDoEvent.data->sum ) return false;
585 if ( data->desc != toDoEvent.data->desc ) return false; 600 if ( data->desc != toDoEvent.data->desc ) return false;
586 if ( data->maintainer != toDoEvent.data->maintainer ) 601 if ( data->maintainer != toDoEvent.data->maintainer )
587 return false; 602 return false;
588 603
589 return OPimRecord::operator==( toDoEvent ); 604 return OPimRecord::operator==( toDoEvent );
590} 605}
591 606
592 607
593void OPimTodo::deref() 608void OPimTodo::deref()
594{ 609{
595 610
596 // owarn << "deref in ToDoEvent" << oendl;
597 if ( data->deref() ) 611 if ( data->deref() )
598 { 612 {
599 // owarn << "deleting" << oendl;
600 delete data; 613 delete data;
601 data = 0; 614 data = 0;
602 } 615 }
603} 616}
604 617
605 618
606OPimTodo &OPimTodo::operator=( const OPimTodo &item ) 619OPimTodo &OPimTodo::operator=( const OPimTodo &item )
607{ 620{
608 if ( this == &item ) return * this; 621 if ( this == &item ) return * this;
609 622
610 OPimRecord::operator=( item ); 623 OPimRecord::operator=( item );
611 //owarn << "operator= ref " << oendl;
612 item.data->ref(); 624 item.data->ref();
613 deref(); 625 deref();
614 data = item.data; 626 data = item.data;
615 627
616 return *this; 628 return *this;
617} 629}
618 630
619 631
620QMap<int, QString> OPimTodo::toMap() const 632QMap<int, QString> OPimTodo::toMap() const
621{ 633{
622 QMap<int, QString> map; 634 QMap<int, QString> map;
623 635
624 map.insert( Uid, QString::number( uid() ) ); 636 map.insert( Uid, QString::number( uid() ) );
625 map.insert( Category, idsToString( categories() ) ); 637 map.insert( Category, idsToString( categories() ) );
626 map.insert( HasDate, QString::number( data->hasDate ) ); 638 map.insert( HasDate, QString::number( data->hasDate ) );
627 map.insert( Completed, QString::number( data->isCompleted ) ); 639 map.insert( Completed, QString::number( data->isCompleted ) );
628 map.insert( Description, data->desc ); 640 map.insert( Description, data->desc );
629 map.insert( Summary, data->sum ); 641 map.insert( Summary, data->sum );
630 map.insert( Priority, QString::number( data->priority ) ); 642 map.insert( Priority, QString::number( data->priority ) );
631 map.insert( DateDay, QString::number( data->date.day() ) ); 643 map.insert( DateDay, QString::number( data->date.day() ) );
632 map.insert( DateMonth, QString::number( data->date.month() ) ); 644 map.insert( DateMonth, QString::number( data->date.month() ) );
633 map.insert( DateYear, QString::number( data->date.year() ) ); 645 map.insert( DateYear, QString::number( data->date.year() ) );
634 map.insert( Progress, QString::number( data->prog ) ); 646 map.insert( Progress, QString::number( data->prog ) );
635 // map.insert( CrossReference, crossToString() ); 647 // map.insert( CrossReference, crossToString() );
636 /* FIXME!!! map.insert( State, ); 648 /* FIXME!!! map.insert( State, );
637 map.insert( Recurrence, ); 649 map.insert( Recurrence, );
638 map.insert( Reminders, ); 650 map.insert( Reminders, );
639 map. 651 map.
640 */ 652 */
641 return map; 653 return map;
642} 654}
643 655
644 656
645/** 657/**
646 * change or modify looks at the ref count and either 658 * change or modify looks at the ref count and either
647 * creates a new QShared Object or it can modify it 659 * creates a new QShared Object or it can modify it
648 * right in place 660 * right in place
649 */ 661 */
650void OPimTodo::changeOrModify() 662void OPimTodo::changeOrModify()
651{ 663{
652 if ( data->count != 1 ) 664 if ( data->count != 1 )
653 { 665 {
654 owarn << "changeOrModify" << oendl;
655 data->deref(); 666 data->deref();
656 OPimTodoData* d2 = new OPimTodoData(); 667 OPimTodoData* d2 = new OPimTodoData();
657 copy( data, d2 ); 668 copy( data, d2 );
658 data = d2; 669 data = d2;
659 } 670 }
660} 671}
661 672
662 673
663// WATCHOUT 674// WATCHOUT
664/* 675/*
665 * if you add something to the Data struct 676 * if you add something to the Data struct
666 * be sure to copy it here 677 * be sure to copy it here
667 */ 678 */
668void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) 679void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
669{ 680{
670 dest->date = src->date; 681 dest->date = src->date;
671 dest->isCompleted = src->isCompleted; 682 dest->isCompleted = src->isCompleted;
672 dest->hasDate = src->hasDate; 683 dest->hasDate = src->hasDate;
673 dest->priority = src->priority; 684 dest->priority = src->priority;
674 dest->desc = src->desc; 685 dest->desc = src->desc;
675 dest->sum = src->sum; 686 dest->sum = src->sum;
676 dest->extra = src->extra; 687 dest->extra = src->extra;
677 dest->prog = src->prog; 688 dest->prog = src->prog;
678 689
679 if ( src->state ) 690 if ( src->state )
680 dest->state = new OPimState( *src->state ); 691 dest->state = new OPimState( *src->state );
681 692
682 if ( src->recur ) 693 if ( src->recur )
683 dest->recur = new OPimRecurrence( *src->recur ); 694 dest->recur = new OPimRecurrence( *src->recur );
684 695
685 if ( src->maintainer ) 696 if ( src->maintainer )
686 dest->maintainer = new OPimMaintainer( *src->maintainer ) 697 dest->maintainer = new OPimMaintainer( *src->maintainer )
687 ; 698 ;
688 dest->start = src->start; 699 dest->start = src->start;
689 dest->completed = src->completed; 700 dest->completed = src->completed;
690 701
691 if ( src->notifiers ) 702 if ( src->notifiers )
692 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 703 dest->notifiers = new OPimNotifyManager( *src->notifiers );
693} 704}
694 705
695 706
696QString OPimTodo::type() const 707QString OPimTodo::type() const
697{ 708{
698 return QString::fromLatin1( "OPimTodo" ); 709 return QString::fromLatin1( "OPimTodo" );
699} 710}
700 711
701 712
702QString OPimTodo::recordField( int /*id*/ ) const 713QString OPimTodo::recordField( int id) const
703{ 714{
704 return QString::null; 715 QString res;
716 Q_UNUSED( id )
717#if 0
718 switch( id ) {
719 case HasDate:
720 res = (hasDueDate() ?
721 QObject::tr( "Has a due-date" )
722 : QObject::tr( "No due-date" ));
723 break;
724 case Completed:
725 res = ( isCompleted() ?
726 QObject::tr( "Completed" ) :
727 QObject::tr( "Not completed" ));
728 break;
729 case Description:
730 res = description();
731 break;
732 case Summary:
733 res = summary();
734 break;
735 case Priority:
736 res = QString::number( priority() );
737 break;
738 case DateDay:
739 res = QString::number( dueDate().day() );
740 break;
741 case DateMonth:
742 res = QString::number( dueDate().month() );
743 break;
744 case DateYear:
745 res = QString::number( dueDate().year() );
746 break;
747 case Progress:
748 res = QString::number( progress() );
749 break;
750 case State:
751 res = QString::number( state().state() );
752 break;
753 case Recurrence:
754 res = ( hasRecurrence() ?
755 QString::null /*recurrence().summary()*/ :
756 QObject::tr("No reccurrence"));
757 break;
758 case Alarms:
759 break;
760 case Reminders:
761 break;
762 case Maintainer:
763 break;
764 case StartDate:
765 res = ( hasStartDate() ?
766 /*TimeString::()*/ QString::null :
767 QObject::tr( "No start-date" ) );
768 break;
769 case CompletedDate:
770 res = ( hasCompletedDate() ?
771 /*TimeString::()*/ QString::null :
772 QObject::tr( "No completed-date" ) );
773 break;
774 case DueDate:
775 res = ( hasDueDate() ?
776 /*TimeString::()*/ QString::null :
777 QObject::tr( "No due-date" );
778 break;
779 default:
780 res = OPimRecord::recordField( id );
781 }
782
783#endif
784 return res;
705} 785}
706 786
707 787
708int OPimTodo::rtti() const 788int OPimTodo::rtti() const
709{ 789{
710 return OPimResolver::TodoList; 790 return OPimResolver::TodoList;
711} 791}
712 792
793/**
794 * \brief Provide a SafeCast to OPimTodo from a OPimRecord
795 *
796 * Provide a safe cast that will return 0 if the record
797 * type is not OPimTodo. In the other case it will
798 * be casted to OPimTodo and returned
799 *
800 * @param rec The OPimRecord to be casted
801 *
802 * @return a pointer to OPimTodo or 0l
803 */
804OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) {
805 return (rec && rec->rtti() == OPimResolver::TodoList ) ?
806 static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) :
807 0l;
808}
809
713} 810}
diff --git a/libopie2/opiepim/core/opimtodo.h b/libopie2/opiepim/core/opimtodo.h
index e17fe6a..f4f9926 100644
--- a/libopie2/opiepim/core/opimtodo.h
+++ b/libopie2/opiepim/core/opimtodo.h
@@ -1,173 +1,174 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7_;:, .> :=|. This program is free software; you can 7_;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License, 11- . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21: = ...= . :.=- 21: = ...= . :.=-
22-. .:....=;==+<; You should have received a copy of the GNU 22-. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OTODOEVENT_H 30#ifndef OTODOEVENT_H
31#define OTODOEVENT_H 31#define OTODOEVENT_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
35#include <qpe/recordfields.h> 35#include <qpe/recordfields.h>
36#include <qpe/palmtopuidgen.h> 36#include <qpe/palmtopuidgen.h>
37 37
38/* QT */ 38/* QT */
39#include <qarray.h> 39#include <qarray.h>
40#include <qmap.h> 40#include <qmap.h>
41#include <qregexp.h> 41#include <qregexp.h>
42#include <qstringlist.h> 42#include <qstringlist.h>
43#include <qdatetime.h> 43#include <qdatetime.h>
44#include <qvaluelist.h> 44#include <qvaluelist.h>
45 45
46namespace Opie 46namespace Opie
47{ 47{
48 48
49class OPimState; 49class OPimState;
50class OPimRecurrence; 50class OPimRecurrence;
51class OPimMaintainer; 51class OPimMaintainer;
52class OPimNotifyManager; 52class OPimNotifyManager;
53class OPimTodo : public OPimRecord 53class OPimTodo : public OPimRecord
54{ 54{
55 public: 55 public:
56 typedef QValueList<OPimTodo> ValueList; 56 typedef QValueList<OPimTodo> ValueList;
57 enum RecordFields { 57 enum RecordFields {
58 Uid = Qtopia::UID_ID, 58 Uid = Qtopia::UID_ID,
59 Category = Qtopia::CATEGORY_ID, 59 Category = Qtopia::CATEGORY_ID,
60 HasDate, 60 HasDate,
61 Completed, 61 Completed,
62 Description, 62 Description,
63 Summary, 63 Summary,
64 Priority, 64 Priority,
65 DateDay, 65 DateDay,
66 DateMonth, 66 DateMonth,
67 DateYear, 67 DateYear,
68 Progress, 68 Progress,
69 CrossReference, 69 CrossReference,
70 State, 70 State,
71 Recurrence, 71 Recurrence,
72 Alarms, 72 Alarms,
73 Reminders, 73 Reminders,
74 Notifiers,
75 Maintainer, 74 Maintainer,
76 StartDate, 75 StartDate,
77 CompletedDate 76 CompletedDate,
77//ADDITIONAL FOR RECORDFIELD
78 DueDate,
78 }; 79 };
79 public: 80 public:
80 // priorities from Very low to very high 81 // priorities from Very low to very high
81 enum TaskPriority { VeryHigh = 1, High, Normal, Low, VeryLow }; 82 enum TaskPriority { VeryHigh = 1, High, Normal, Low, VeryLow };
82 83
83 /* Constructs a new ToDoEvent 84 /* Constructs a new ToDoEvent
84 @param completed Is the TodoEvent completed 85 @param completed Is the TodoEvent completed
85 @param priority What is the priority of this ToDoEvent 86 @param priority What is the priority of this ToDoEvent
86 @param category Which category does it belong( uid ) 87 @param category Which category does it belong( uid )
87 @param summary A small summary of the todo 88 @param summary A small summary of the todo
88 @param description What is this ToDoEvent about 89 @param description What is this ToDoEvent about
89 @param hasDate Does this Event got a deadline 90 @param hasDate Does this Event got a deadline
90 @param date what is the deadline? 91 @param date what is the deadline?
91 @param uid what is the UUID of this Event 92 @param uid what is the UUID of this Event
92 **/ 93 **/
93 OPimTodo( bool completed = false, int priority = Normal, 94 OPimTodo( bool completed = false, int priority = Normal,
94 const QStringList &category = QStringList(), 95 const QStringList &category = QStringList(),
95 const QString &summary = QString::null , 96 const QString &summary = QString::null ,
96 const QString &description = QString::null, 97 const QString &description = QString::null,
97 ushort progress = 0, 98 ushort progress = 0,
98 bool hasDate = false, QDate date = QDate::currentDate(), 99 bool hasDate = false, QDate date = QDate::currentDate(),
99 int uid = 0 /*empty*/ ); 100 int uid = 0 /*empty*/ );
100 101
101 OPimTodo( bool completed, int priority, 102 OPimTodo( bool completed, int priority,
102 const QArray<int>& category, 103 const QArray<int>& category,
103 const QString& summary = QString::null, 104 const QString& summary = QString::null,
104 const QString& description = QString::null, 105 const QString& description = QString::null,
105 ushort progress = 0, 106 ushort progress = 0,
106 bool hasDate = false, QDate date = QDate::currentDate(), 107 bool hasDate = false, QDate date = QDate::currentDate(),
107 int uid = 0 /* empty */ ); 108 int uid = 0 /* empty */ );
108 109
109 /** Copy c'tor 110 /** Copy c'tor
110 * 111 *
111 */ 112 */
112 OPimTodo( const OPimTodo & ); 113 OPimTodo( const OPimTodo & );
113 114
114 /** 115 /**
115 *destructor 116 *destructor
116 */ 117 */
117 ~OPimTodo(); 118 ~OPimTodo();
118 119
119 /** 120 /**
120 * Is this event completed? 121 * Is this event completed?
121 */ 122 */
122 bool isCompleted() const; 123 bool isCompleted() const;
123 124
124 /** 125 /**
125 * Does this Event have a deadline 126 * Does this Event have a deadline
126 */ 127 */
127 bool hasDueDate() const; 128 bool hasDueDate() const;
128 bool hasStartDate() const; 129 bool hasStartDate() const;
129 bool hasCompletedDate() const; 130 bool hasCompletedDate() const;
130 131
131 /** 132 /**
132 * What is the priority? 133 * What is the priority?
133 */ 134 */
134 int priority() const ; 135 int priority() const ;
135 136
136 /** 137 /**
137 * progress as ushort 0, 20, 40, 60, 80 or 100% 138 * progress as ushort 0, 20, 40, 60, 80 or 100%
138 */ 139 */
139 ushort progress() const; 140 ushort progress() const;
140 141
141 /** 142 /**
142 * The due Date 143 * The due Date
143 */ 144 */
144 QDate dueDate() const; 145 QDate dueDate() const;
145 146
146 /** 147 /**
147 * When did it start? 148 * When did it start?
148 */ 149 */
149 QDate startDate() const; 150 QDate startDate() const;
150 151
151 /** 152 /**
152 * When was it completed? 153 * When was it completed?
153 */ 154 */
154 QDate completedDate() const; 155 QDate completedDate() const;
155 156
156 /** 157 /**
157 * does it have a state? 158 * does it have a state?
158 */ 159 */
159 bool hasState() const; 160 bool hasState() const;
160 161
161 /** 162 /**
162 * What is the state of this OPimTodo? 163 * What is the state of this OPimTodo?
163 */ 164 */
164 OPimState state() const; 165 OPimState state() const;
165 166
166 /** 167 /**
167 * has recurrence? 168 * has recurrence?
168 */ 169 */
169 bool hasRecurrence() const; 170 bool hasRecurrence() const;
170 171
171 /** 172 /**
172 * the recurrance of this 173 * the recurrance of this
173 */ 174 */
@@ -189,132 +190,136 @@ class OPimTodo : public OPimRecord
189 QString description() const; 190 QString description() const;
190 191
191 /** 192 /**
192 * A small summary of the todo 193 * A small summary of the todo
193 */ 194 */
194 QString summary() const; 195 QString summary() const;
195 196
196 /** 197 /**
197 * @reimplemented 198 * @reimplemented
198 * Return this todoevent in a RichText formatted QString 199 * Return this todoevent in a RichText formatted QString
199 */ 200 */
200 QString toRichText() const; 201 QString toRichText() const;
201 202
202 bool hasNotifiers() const; 203 bool hasNotifiers() const;
203 /* 204 /*
204 * FIXME check if the sharing is still fine!! -zecke 205 * FIXME check if the sharing is still fine!! -zecke
205 * ### CHECK If API is fine 206 * ### CHECK If API is fine
206 */ 207 */
207 /** 208 /**
208 * return a reference to our notifiers... 209 * return a reference to our notifiers...
209 */ 210 */
210 OPimNotifyManager &notifiers(); 211 OPimNotifyManager &notifiers();
211 212
212 /** 213 /**
213 * 214 *
214 */ 215 */
215 const OPimNotifyManager &notifiers() const; 216 const OPimNotifyManager &notifiers() const;
216 217
217 /** 218 /**
218 * reimplementations 219 * reimplementations
219 */ 220 */
220 QString type() const; 221 QString type() const;
221 QString toShortText() const; 222 QString toShortText() const;
222 QString recordField( int id ) const; 223 QString recordField( int id ) const;
223 224
224 /** 225 /**
225 * toMap puts all data into the map. int relates 226 * toMap puts all data into the map. int relates
226 * to ToDoEvent RecordFields enum 227 * to ToDoEvent RecordFields enum
227 */ 228 */
228 QMap<int, QString> toMap() const; 229 QMap<int, QString> toMap() const;
229 230
230 /** 231 /**
231 * Set if this Todo is completed 232 * Set if this Todo is completed
232 */ 233 */
233 void setCompleted( bool completed ); 234 void setCompleted( bool completed );
234 235
235 /** 236 /**
236 * set if this todo got an end data 237 * set if this todo got an end data
237 */ 238 */
238 void setHasDueDate( bool hasDate ); 239 void setHasDueDate( bool hasDate );
239 // FIXME we do not have these for start, completed 240 // FIXME we do not have these for start, completed
240 // cause we'll use the isNull() of QDate for figuring 241 // cause we'll use the isNull() of QDate for figuring
241 // out if it's has a date... 242 // out if it's has a date...
242 // decide what to do here? -zecke 243 // decide what to do here? -zecke
243 244
244 /** 245 /**
245 * Set the priority of the Todo 246 * Set the priority of the Todo
246 */ 247 */
247 void setPriority( int priority ); 248 void setPriority( int priority );
248 249
249 /** 250 /**
250 * Set the progress. 251 * Set the progress.
251 */ 252 */
252 void setProgress( ushort progress ); 253 void setProgress( ushort progress );
253 254
254 /** 255 /**
255 * set the end date 256 * set the end date
256 */ 257 */
257 void setDueDate( const QDate& date ); 258 void setDueDate( const QDate& date );
258 259
259 /** 260 /**
260 * set the start date 261 * set the start date
261 */ 262 */
262 void setStartDate( const QDate& date ); 263 void setStartDate( const QDate& date );
263 264
264 /** 265 /**
265 * set the completed date 266 * set the completed date
266 */ 267 */
267 void setCompletedDate( const QDate& date ); 268 void setCompletedDate( const QDate& date );
268 269
269 void setRecurrence( const OPimRecurrence& ); 270 void setRecurrence( const OPimRecurrence& );
270 271
271 void setDescription( const QString& ); 272 void setDescription( const QString& );
272 void setSummary( const QString& ); 273 void setSummary( const QString& );
273 274
274 /** 275 /**
275 * set the state of a Todo 276 * set the state of a Todo
276 * @param state State what the todo should take 277 * @param state State what the todo should take
277 */ 278 */
278 void setState( const OPimState& state ); 279 void setState( const OPimState& state );
279 280
280 /** 281 /**
281 * set the Maintainer Mode 282 * set the Maintainer Mode
282 */ 283 */
283 void setMaintainer( const OPimMaintainer& ); 284 void setMaintainer( const OPimMaintainer& );
284 285
285 bool isOverdue(); 286 bool isOverdue()const;
286 287
287 288
288 virtual bool match( const QRegExp &r ) const; 289 virtual bool match( const QRegExp &r ) const;
289 290
290 bool operator<( const OPimTodo &toDoEvent ) const; 291 bool operator<( const OPimTodo &toDoEvent ) const;
291 bool operator<=( const OPimTodo &toDoEvent ) const; 292 bool operator<=( const OPimTodo &toDoEvent ) const;
292 bool operator!=( const OPimTodo &toDoEvent ) const; 293 bool operator!=( const OPimTodo &toDoEvent ) const;
293 bool operator>( const OPimTodo &toDoEvent ) const; 294 bool operator>( const OPimTodo &toDoEvent ) const;
294 bool operator>=( const OPimTodo &toDoEvent ) const; 295 bool operator>=( const OPimTodo &toDoEvent ) const;
295 bool operator==( const OPimTodo &toDoEvent ) const; 296 bool operator==( const OPimTodo &toDoEvent ) const;
296 OPimTodo &operator=( const OPimTodo &toDoEvent ); 297 OPimTodo &operator=( const OPimTodo &toDoEvent );
297 298
299 //@{
298 int rtti() const; 300 int rtti() const;
301 static OPimTodo* safeCast( const OPimRecord* );
302 //@}
303
299 304
300 private: 305 private:
301 class OPimTodoPrivate; 306 class OPimTodoPrivate;
302 struct OPimTodoData; 307 struct OPimTodoData;
303 308
304 void deref(); 309 void deref();
305 inline void changeOrModify(); 310 inline void changeOrModify();
306 void copy( OPimTodoData* src, OPimTodoData* dest ); 311 void copy( OPimTodoData* src, OPimTodoData* dest );
307 OPimTodoPrivate *d; 312 OPimTodoPrivate *d;
308 OPimTodoData *data; 313 OPimTodoData *data;
309 314
310}; 315};
311 316
312 317
313inline bool OPimTodo::operator!=( const OPimTodo &toDoEvent ) const 318inline bool OPimTodo::operator!=( const OPimTodo &toDoEvent ) const
314{ 319{
315 return !( *this == toDoEvent ); 320 return !( *this == toDoEvent );
316} 321}
317 322
318} 323}
319 324
320#endif 325#endif
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index 26a68a0..4ad5950 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -1,101 +1,88 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#include <qdatetime.h> 29#include <qdatetime.h>
30 30
31#include <qpe/alarmserver.h> 31#include <qpe/alarmserver.h>
32 32
33// #include "otodoaccesssql.h" 33// #include "otodoaccesssql.h"
34#include <opie2/otodoaccess.h> 34#include <opie2/otodoaccess.h>
35#include <opie2/obackendfactory.h> 35#include <opie2/obackendfactory.h>
36#include <opie2/opimresolver.h> 36#include <opie2/opimresolver.h>
37#include <opie2/opimglobal.h> 37#include <opie2/opimglobal.h>
38 38
39namespace Opie { 39namespace Opie {
40OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) 40OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
41 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) 41 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
42{ 42{
43// if (end == 0l ) 43// if (end == 0l )
44// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); 44// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null);
45 45
46 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! 46 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben !
47 if (end == 0l ) 47 if (end == 0l )
48 m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null); 48 m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null);
49 49
50 setBackEnd( m_todoBackEnd ); 50 setBackEnd( m_todoBackEnd );
51} 51}
52OPimTodoAccess::~OPimTodoAccess() { 52OPimTodoAccess::~OPimTodoAccess() {
53// owarn << "~OPimTodoAccess" << oendl;
54} 53}
54
55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { 55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
56 QValueList<OPimTodo>::ConstIterator it; 56 QValueList<OPimTodo>::ConstIterator it;
57 for ( it = list.begin(); it != list.end(); ++it ) { 57 for ( it = list.begin(); it != list.end(); ++it ) {
58 replace( (*it) ); 58 replace( (*it) );
59 } 59 }
60} 60}
61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
62 const QDate& end, 62 const QDate& end,
63 bool includeNoDates ) { 63 bool includeNoDates )const {
64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
65 65
66 List lis( ints, this ); 66 List lis( ints, this );
67 return lis; 67 return lis;
68} 68}
69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
70 bool includeNoDates ) { 70 bool includeNoDates )const {
71 return effectiveToDos( start, QDate::currentDate(), 71 return effectiveToDos( start, QDate::currentDate(),
72 includeNoDates ); 72 includeNoDates );
73} 73}
74OPimTodoAccess::List OPimTodoAccess::overDue() { 74OPimTodoAccess::List OPimTodoAccess::overDue()const {
75 List lis( m_todoBackEnd->overDue(), this ); 75 List lis( m_todoBackEnd->overDue(), this );
76 return lis; 76 return lis;
77} 77}
78/* sort order */ 78
79OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
80 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
81 filter, cat );
82 OPimTodoAccess::List list( ints, this );
83 return list;
84}
85void OPimTodoAccess::removeAllCompleted() { 79void OPimTodoAccess::removeAllCompleted() {
86 m_todoBackEnd->removeAllCompleted(); 80 m_todoBackEnd->removeAllCompleted();
87} 81}
88QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
89 return m_todoBackEnd->supports();
90}
91bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
92 return backendSupport(ar).testBit( attr );
93}
94
95 82
96int OPimTodoAccess::rtti() const 83int OPimTodoAccess::rtti() const
97{ 84{
98 return OPimResolver::TodoList; 85 return OPimResolver::TodoList;
99} 86}
100 87
101} 88}
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index 3f5af30..8338586 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -1,142 +1,118 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_TODO_ACCESS_H 29#ifndef OPIE_TODO_ACCESS_H
30#define OPIE_TODO_ACCESS_H 30#define OPIE_TODO_ACCESS_H
31 31
32#include <qobject.h> 32#include <qobject.h>
33#include <qvaluelist.h> 33#include <qvaluelist.h>
34 34
35#include <opie2/opimtodo.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 * OPimTodoAccess 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 OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { 46class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> {
47 Q_OBJECT 47 Q_OBJECT
48public: 48public:
49 enum SortOrder { Completed = 0, 49 enum SortOrder { Completed = SortCustom,
50 Priority, 50 Priority,
51 Description,
52 Deadline }; 51 Deadline };
53 enum SortFilter{ Category =1, 52 enum SortFilter{ OnlyOverDue= FilterCustom,
54 OnlyOverDue= 2, 53 DoNotShowCompleted = FilterCustom<<1 };
55 DoNotShowCompleted =4 };
56 /** 54 /**
57 * if you use 0l 55 * if you use 0l
58 * the default resource will be 56 * the default resource will be
59 * picked up 57 * picked up
60 */ 58 */
61 OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); 59 OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random );
62 ~OPimTodoAccess(); 60 ~OPimTodoAccess();
63 61
64 62
65 /* our functions here */ 63 /* our functions here */
66 /** 64 /**
67 * include todos from start to end 65 * include todos from start to end
68 * includeNoDates whether or not to include 66 * includeNoDates whether or not to include
69 * events with no dates 67 * events with no dates
70 */ 68 */
71 List effectiveToDos( const QDate& start, 69 List effectiveToDos( const QDate& start,
72 const QDate& end, 70 const QDate& end,
73 bool includeNoDates = true ); 71 bool includeNoDates = true )const;
74 72
75 /** 73 /**
76 * start 74 * start
77 * end date taken from the currentDate() 75 * end date taken from the currentDate()
78 */ 76 */
79 List effectiveToDos( const QDate& start, 77 List effectiveToDos( const QDate& start,
80 bool includeNoDates = true ); 78 bool includeNoDates = true )const;
81 79
82 80
83 /** 81 /**
84 * return overdue OPimTodos 82 * return overdue OPimTodos
85 */ 83 */
86 List overDue(); 84 List overDue()const;
87
88 /**
89 *
90 */
91 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
92 85
93 /** 86 /**
94 * merge a list of OPimTodos into 87 * merge a list of OPimTodos into
95 * the resource 88 * the resource
96 */ 89 */
97 void mergeWith( const QValueList<OPimTodo>& ); 90 void mergeWith( const QValueList<OPimTodo>& );
98 91
99 /** 92 /**
100 * delete all already completed items 93 * delete all already completed items
101 */ 94 */
102 void removeAllCompleted(); 95 void removeAllCompleted();
103 96
104 /** 97 /**
105 * request information about what a backend supports.
106 * Supports in the sense of beeing able to store.
107 * This is related to the enum in OPimTodo
108 *
109 * @param backend Will be used in the future when we support multiple backend
110 */
111 QBitArray backendSupport( const QString& backend = QString::null )const;
112
113 /**
114 * see above but for a specefic attribute. This method was added for convience
115 * @param attr The attribute to be queried for
116 * @param backend Will be used in the future when we support multiple backends
117 */
118 bool backendSupports( int attr, const QString& backend = QString::null )const;
119
120
121 /**
122 * Return identification of used records 98 * Return identification of used records
123 */ 99 */
124 int rtti() const; 100 int rtti() const;
125signals: 101signals:
126 /** 102 /**
127 * if the OPimTodoAccess was changed 103 * if the OPimTodoAccess was changed
128 */ 104 */
129 void changed( const OPimTodoAccess* ); 105 void changed( const OPimTodoAccess* );
130 void changed( const OPimTodoAccess*, int uid ); 106 void changed( const OPimTodoAccess*, int uid );
131 void added( const OPimTodoAccess*, int uid ); 107 void added( const OPimTodoAccess*, int uid );
132 void removed( const OPimTodoAccess*, int uid ); 108 void removed( const OPimTodoAccess*, int uid );
133private: 109private:
134 int m_cat; 110 int m_cat;
135 OPimTodoAccessBackend* m_todoBackEnd; 111 OPimTodoAccessBackend* m_todoBackEnd;
136 class OPimTodoAccessPrivate; 112 class OPimTodoAccessPrivate;
137 OPimTodoAccessPrivate* d; 113 OPimTodoAccessPrivate* d;
138}; 114};
139 115
140} 116}
141 117
142#endif 118#endif