author | eilers <eilers> | 2004-12-28 14:19:26 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-12-28 14:19:26 (UTC) |
commit | 47c87c92a46f56bc9190025e7a653fa48718431e (patch) (unidiff) | |
tree | 2c8d87f8a8132d6b59d56cdb35762a479515b1d1 | |
parent | 521e3eed02205bca9baca9000ac7ff095a15abde (diff) | |
download | opie-47c87c92a46f56bc9190025e7a653fa48718431e.zip opie-47c87c92a46f56bc9190025e7a653fa48718431e.tar.gz opie-47c87c92a46f56bc9190025e7a653fa48718431e.tar.bz2 |
Fixing bug #1501 and preparing for implementation of generic QueryByExample and
sorted for datebook and todo..
-rw-r--r-- | libopie2/opiepim/ChangeLog | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 29 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend.cpp | 27 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend.h | 15 | ||||
-rw-r--r-- | libopie2/opiepim/backend/opimaccessbackend.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.cpp | 32 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.h | 15 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 34 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.h | 1 |
13 files changed, 134 insertions, 42 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog index 564e92a..2007744 100644 --- a/libopie2/opiepim/ChangeLog +++ b/libopie2/opiepim/ChangeLog | |||
@@ -1,21 +1,23 @@ | |||
1 | 2004-12-28 Stefan Eilers <stefan@eilers-online.net> | 1 | 2004-12-28 Stefan Eilers <stefan@eilers-online.net> |
2 | * Make improved query by example accessable via frontend | 2 | * Make improved query by example accessable via frontend |
3 | * Some API improvement | 3 | * Some API documentation improvement |
4 | * Cleanup of backend api.. | ||
5 | * Fixing bug #1501 | ||
4 | 2004-11-23 Stefan Eilers <stefan@eilers-online.net> | 6 | 2004-11-23 Stefan Eilers <stefan@eilers-online.net> |
5 | * Implement fast and full featured version of sorted() for addressbook | 7 | * Implement fast and full featured version of sorted() for addressbook |
6 | * Implement generic queryByExample for all Addressboook backends. It allows incremental search. | 8 | * Implement generic queryByExample for all Addressboook backends. It allows incremental search. |
7 | * Update of API Documentation | 9 | * Update of API Documentation |
8 | 2004-11-18 Holger Freyther <freyther@handhelds.org> | 10 | 2004-11-18 Holger Freyther <freyther@handhelds.org> |
9 | * Every Access can give a set of Occurrences for a period or a datetime | 11 | * Every Access can give a set of Occurrences for a period or a datetime |
10 | * QueryByExample, Find, Sort can be generically accessed by OPimBase | 12 | * QueryByExample, Find, Sort can be generically accessed by OPimBase |
11 | pointer interface | 13 | pointer interface |
12 | * OPimBackendOccurrence gets split up to OPimOccurrences by | 14 | * OPimBackendOccurrence gets split up to OPimOccurrences by |
13 | OPimTemplateBase | 15 | OPimTemplateBase |
14 | * Add safeCast to various OPimRecords | 16 | * Add safeCast to various OPimRecords |
15 | * Kill memleak in OPimTodo | 17 | * Kill memleak in OPimTodo |
16 | * Add SortVector implementations for OPimTodo and OPimContact | 18 | * Add SortVector implementations for OPimTodo and OPimContact |
17 | 19 | ||
18 | 2004-??-??The Opie Team <opie@handhelds.org> | 20 | 2004-??-??The Opie Team <opie@handhelds.org> |
19 | * Implemented some important modifications to allow to use OPimRecords as it is, without | 21 | * Implemented some important modifications to allow to use OPimRecords as it is, without |
20 | have to cast them. This makes it possible to write applications which handling pim | 22 | have to cast them. This makes it possible to write applications which handling pim |
21 | data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file | 23 | data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index ee6dbc2..27d70ab 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,111 +1,111 @@ | |||
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 | * The class responsible for managing a backend. | 30 | * The class responsible for managing a backend. |
31 | * The implementation of this abstract class contains | 31 | * The implementation of this abstract class contains |
32 | * the complete database handling. | 32 | * the complete database handling. |
33 | * | 33 | * |
34 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 34 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
35 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 35 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
36 | * | 36 | * |
37 | */ | 37 | */ |
38 | 38 | ||
39 | #ifndef _OCONTACTACCESSBACKEND_H_ | 39 | #ifndef _OCONTACTACCESSBACKEND_H_ |
40 | #define _OCONTACTACCESSBACKEND_H_ | 40 | #define _OCONTACTACCESSBACKEND_H_ |
41 | 41 | ||
42 | #include <opie2/opimcontact.h> | 42 | #include <opie2/opimcontact.h> |
43 | #include <opie2/opimaccessbackend.h> | 43 | #include <opie2/opimaccessbackend.h> |
44 | 44 | ||
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | 46 | ||
47 | namespace Opie { | 47 | namespace Opie { |
48 | /** | 48 | /** |
49 | * This class represents the interface of all Contact Backends. | 49 | * This class represents the interface of all Contact Backends. |
50 | * Derivates of this class will be used to access the contacts. | 50 | * Derivates of this class will be used to access the contacts. |
51 | * As implementation currently XML and vCard exist. This class needs to be implemented | 51 | * As implementation currently XML and vCard exist. This class needs to be implemented |
52 | * if you want to provide your own storage. | 52 | * if you want to provide your own storage. |
53 | * In all queries a list of uids is passed on instead of loading the actual record! | 53 | * In all queries a list of uids is passed on instead of loading the actual record! |
54 | * | 54 | * |
55 | * @see OPimContactAccessBackend_VCard | 55 | * @see OPimContactAccessBackend_VCard |
56 | * @see OPimContactAccessBackend_XML | 56 | * @see OPimContactAccessBackend_XML |
57 | */ | 57 | */ |
58 | class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> { | 58 | class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> { |
59 | public: | 59 | public: |
60 | OPimContactAccessBackend(); | 60 | OPimContactAccessBackend(); |
61 | 61 | ||
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Return if database was changed externally. | 64 | * Return if database was changed externally. |
65 | * This may just make sense on file based databases like a XML-File. | 65 | * This may just make sense on file based databases like a XML-File. |
66 | * It is used to prevent to overwrite the current database content | 66 | * It is used to prevent to overwrite the current database content |
67 | * if the file was already changed by something else ! | 67 | * if the file was already changed by something else ! |
68 | * If this happens, we have to reload before save our data. | 68 | * If this happens, we have to reload before save our data. |
69 | * If we use real databases, this should be handled by the database | 69 | * If we use real databases, this should be handled by the database |
70 | * management system themselve, therefore this function should always return false in | 70 | * management system themselve, therefore this function should always return false in |
71 | * this case. It is not our problem to handle this conflict ... | 71 | * this case. It is not our problem to handle this conflict ... |
72 | * @return <i>true</i> if the database was changed and if save without reload will | 72 | * @return <i>true</i> if the database was changed and if save without reload will |
73 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 73 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
74 | * in this situation. | 74 | * in this situation. |
75 | */ | 75 | */ |
76 | virtual bool wasChangedExternally() = 0; | 76 | virtual bool wasChangedExternally() = 0; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Return all possible settings. | 79 | * Return all possible settings. |
80 | * @return All settings provided by the current backend | 80 | * @return All settings provided by the current backend |
81 | * (i.e.: query_WildCards & query_IgnoreCase) | 81 | * (i.e.: query_WildCards & query_IgnoreCase) |
82 | */ | 82 | */ |
83 | virtual const uint querySettings() const; | 83 | const uint querySettings() const; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Check whether settings are correct. | 86 | * Check whether settings are correct. |
87 | * @return <i>true</i> if the given settings are correct and possible. | 87 | * @return <i>true</i> if the given settings are correct and possible. |
88 | */ | 88 | */ |
89 | virtual bool hasQuerySettings (uint querySettings) const; | 89 | bool hasQuerySettings (uint querySettings) const; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Advanced search mechanism. | 92 | * Advanced search mechanism. |
93 | */ | 93 | */ |
94 | UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const; | 94 | UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const; |
95 | /** | 95 | /** |
96 | * Slow and inefficent default implementation | 96 | * Slow and inefficent default implementation |
97 | */ | 97 | */ |
98 | //@{ | 98 | //@{ |
99 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; | 99 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; |
100 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; | 100 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; |
101 | //@} | 101 | //@} |
102 | 102 | ||
103 | 103 | ||
104 | private: | 104 | private: |
105 | class Private; | 105 | class Private; |
106 | Private *d; | 106 | Private *d; |
107 | }; | 107 | }; |
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | #endif | 111 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 9375f43..2368865 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -1,1051 +1,1066 @@ | |||
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 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include "ocontactaccessbackend_sql.h" | 33 | #include "ocontactaccessbackend_sql.h" |
34 | 34 | ||
35 | /* OPIE */ | 35 | /* OPIE */ |
36 | #include <opie2/opimcontact.h> | 36 | #include <opie2/opimcontact.h> |
37 | #include <opie2/opimcontactfields.h> | 37 | #include <opie2/opimcontactfields.h> |
38 | #include <opie2/opimdateconversion.h> | 38 | #include <opie2/opimdateconversion.h> |
39 | #include <opie2/osqldriver.h> | 39 | #include <opie2/osqldriver.h> |
40 | #include <opie2/osqlresult.h> | 40 | #include <opie2/osqlresult.h> |
41 | #include <opie2/osqlmanager.h> | 41 | #include <opie2/osqlmanager.h> |
42 | #include <opie2/osqlquery.h> | 42 | #include <opie2/osqlquery.h> |
43 | #include <opie2/odebug.h> | 43 | #include <opie2/odebug.h> |
44 | 44 | ||
45 | #include <qpe/global.h> | 45 | #include <qpe/global.h> |
46 | #include <qpe/recordfields.h> | 46 | #include <qpe/recordfields.h> |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qarray.h> | 49 | #include <qarray.h> |
50 | #include <qdatetime.h> | 50 | #include <qdatetime.h> |
51 | #include <qstringlist.h> | 51 | #include <qstringlist.h> |
52 | 52 | ||
53 | 53 | ||
54 | using namespace Opie; | 54 | using namespace Opie; |
55 | using namespace Opie::DB; | 55 | using namespace Opie::DB; |
56 | 56 | ||
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Implementation of used query types * CREATE query | 59 | * Implementation of used query types * CREATE query |
60 | * LOAD query | 60 | * LOAD query |
61 | * INSERT | 61 | * INSERT |
62 | * REMOVE | 62 | * REMOVE |
63 | * CLEAR | 63 | * CLEAR |
64 | */ | 64 | */ |
65 | namespace { | 65 | namespace { |
66 | /** | 66 | /** |
67 | * CreateQuery for the Todolist Table | 67 | * CreateQuery for the Todolist Table |
68 | */ | 68 | */ |
69 | class CreateQuery : public OSQLQuery { | 69 | class CreateQuery : public OSQLQuery { |
70 | public: | 70 | public: |
71 | CreateQuery(); | 71 | CreateQuery(); |
72 | ~CreateQuery(); | 72 | ~CreateQuery(); |
73 | QString query()const; | 73 | QString query()const; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Clears (delete) a Table | 77 | * Clears (delete) a Table |
78 | */ | 78 | */ |
79 | class ClearQuery : public OSQLQuery { | 79 | class ClearQuery : public OSQLQuery { |
80 | public: | 80 | public: |
81 | ClearQuery(); | 81 | ClearQuery(); |
82 | ~ClearQuery(); | 82 | ~ClearQuery(); |
83 | QString query()const; | 83 | QString query()const; |
84 | 84 | ||
85 | }; | 85 | }; |
86 | 86 | ||
87 | 87 | ||
88 | /** | 88 | /** |
89 | * LoadQuery | 89 | * LoadQuery |
90 | * this one queries for all uids | 90 | * this one queries for all uids |
91 | */ | 91 | */ |
92 | class LoadQuery : public OSQLQuery { | 92 | class LoadQuery : public OSQLQuery { |
93 | public: | 93 | public: |
94 | LoadQuery(); | 94 | LoadQuery(); |
95 | ~LoadQuery(); | 95 | ~LoadQuery(); |
96 | QString query()const; | 96 | QString query()const; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * inserts/adds a OPimContact to the table | 100 | * inserts/adds a OPimContact to the table |
101 | */ | 101 | */ |
102 | class InsertQuery : public OSQLQuery { | 102 | class InsertQuery : public OSQLQuery { |
103 | public: | 103 | public: |
104 | InsertQuery(const OPimContact& ); | 104 | InsertQuery(const OPimContact& ); |
105 | ~InsertQuery(); | 105 | ~InsertQuery(); |
106 | QString query()const; | 106 | QString query()const; |
107 | private: | 107 | private: |
108 | OPimContact m_contact; | 108 | OPimContact m_contact; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | /** | 112 | /** |
113 | * removes one from the table | 113 | * removes one from the table |
114 | */ | 114 | */ |
115 | class RemoveQuery : public OSQLQuery { | 115 | class RemoveQuery : public OSQLQuery { |
116 | public: | 116 | public: |
117 | RemoveQuery(int uid ); | 117 | RemoveQuery(int uid ); |
118 | ~RemoveQuery(); | 118 | ~RemoveQuery(); |
119 | QString query()const; | 119 | QString query()const; |
120 | private: | 120 | private: |
121 | int m_uid; | 121 | int m_uid; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | /** | 124 | /** |
125 | * a find query for noncustom elements | 125 | * a find query for noncustom elements |
126 | */ | 126 | */ |
127 | class FindQuery : public OSQLQuery { | 127 | class FindQuery : public OSQLQuery { |
128 | public: | 128 | public: |
129 | FindQuery(int uid); | 129 | FindQuery(int uid); |
130 | FindQuery(const UIDArray& ); | 130 | FindQuery(const UIDArray& ); |
131 | ~FindQuery(); | 131 | ~FindQuery(); |
132 | QString query()const; | 132 | QString query()const; |
133 | private: | 133 | private: |
134 | QString single()const; | 134 | QString single()const; |
135 | QString multi()const; | 135 | QString multi()const; |
136 | UIDArray m_uids; | 136 | UIDArray m_uids; |
137 | int m_uid; | 137 | int m_uid; |
138 | }; | 138 | }; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * a find query for custom elements | 141 | * a find query for custom elements |
142 | */ | 142 | */ |
143 | class FindCustomQuery : public OSQLQuery { | 143 | class FindCustomQuery : public OSQLQuery { |
144 | public: | 144 | public: |
145 | FindCustomQuery(int uid); | 145 | FindCustomQuery(int uid); |
146 | FindCustomQuery(const UIDArray& ); | 146 | FindCustomQuery(const UIDArray& ); |
147 | ~FindCustomQuery(); | 147 | ~FindCustomQuery(); |
148 | QString query()const; | 148 | QString query()const; |
149 | private: | 149 | private: |
150 | QString single()const; | 150 | QString single()const; |
151 | QString multi()const; | 151 | QString multi()const; |
152 | UIDArray m_uids; | 152 | UIDArray m_uids; |
153 | int m_uid; | 153 | int m_uid; |
154 | }; | 154 | }; |
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | // We using two tables to store the information: | 158 | // We using two tables to store the information: |
159 | // 1. addressbook : It contains General information about the contact (non custom) | 159 | // 1. addressbook : It contains General information about the contact (non custom) |
160 | // 2. custom_data : Not official supported entries | 160 | // 2. custom_data : Not official supported entries |
161 | // All tables are connected by the uid of the contact. | 161 | // All tables are connected by the uid of the contact. |
162 | // Maybe I should add a table for meta-information ? | 162 | // Maybe I should add a table for meta-information ? |
163 | CreateQuery::CreateQuery() : OSQLQuery() {} | 163 | CreateQuery::CreateQuery() : OSQLQuery() {} |
164 | CreateQuery::~CreateQuery() {} | 164 | CreateQuery::~CreateQuery() {} |
165 | QString CreateQuery::query()const { | 165 | QString CreateQuery::query()const { |
166 | QString qu; | 166 | QString qu; |
167 | 167 | ||
168 | qu += "create table addressbook( uid PRIMARY KEY "; | 168 | qu += "create table addressbook( uid PRIMARY KEY "; |
169 | 169 | ||
170 | QStringList fieldList = OPimContactFields::untrfields( false ); | 170 | QStringList fieldList = OPimContactFields::untrfields( false ); |
171 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 171 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
172 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); | 172 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); |
173 | } | 173 | } |
174 | qu += " );"; | 174 | qu += " );"; |
175 | 175 | ||
176 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 176 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
177 | 177 | ||
178 | return qu; | 178 | return qu; |
179 | } | 179 | } |
180 | 180 | ||
181 | ClearQuery::ClearQuery() | 181 | ClearQuery::ClearQuery() |
182 | : OSQLQuery() {} | 182 | : OSQLQuery() {} |
183 | ClearQuery::~ClearQuery() {} | 183 | ClearQuery::~ClearQuery() {} |
184 | QString ClearQuery::query()const { | 184 | QString ClearQuery::query()const { |
185 | QString qu = "drop table addressbook;"; | 185 | QString qu = "drop table addressbook;"; |
186 | qu += "drop table custom_data;"; | 186 | qu += "drop table custom_data;"; |
187 | // qu += "drop table dates;"; | 187 | // qu += "drop table dates;"; |
188 | return qu; | 188 | return qu; |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | LoadQuery::LoadQuery() : OSQLQuery() {} | 192 | LoadQuery::LoadQuery() : OSQLQuery() {} |
193 | LoadQuery::~LoadQuery() {} | 193 | LoadQuery::~LoadQuery() {} |
194 | QString LoadQuery::query()const { | 194 | QString LoadQuery::query()const { |
195 | QString qu; | 195 | QString qu; |
196 | qu += "select uid from addressbook"; | 196 | qu += "select uid from addressbook"; |
197 | 197 | ||
198 | return qu; | 198 | return qu; |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | InsertQuery::InsertQuery( const OPimContact& contact ) | 202 | InsertQuery::InsertQuery( const OPimContact& contact ) |
203 | : OSQLQuery(), m_contact( contact ) { | 203 | : OSQLQuery(), m_contact( contact ) { |
204 | } | 204 | } |
205 | 205 | ||
206 | InsertQuery::~InsertQuery() { | 206 | InsertQuery::~InsertQuery() { |
207 | } | 207 | } |
208 | 208 | ||
209 | /* | 209 | /* |
210 | * converts from a OPimContact to a query | 210 | * converts from a OPimContact to a query |
211 | */ | 211 | */ |
212 | QString InsertQuery::query()const{ | 212 | QString InsertQuery::query()const{ |
213 | 213 | ||
214 | QString qu; | 214 | QString qu; |
215 | qu += "insert into addressbook VALUES( " + | 215 | qu += "insert into addressbook VALUES( " + |
216 | QString::number( m_contact.uid() ); | 216 | QString::number( m_contact.uid() ); |
217 | 217 | ||
218 | // Get all information out of the contact-class | 218 | // Get all information out of the contact-class |
219 | // Remember: The category is stored in contactMap, too ! | 219 | // Remember: The category is stored in contactMap, too ! |
220 | QMap<int, QString> contactMap = m_contact.toMap(); | 220 | QMap<int, QString> contactMap = m_contact.toMap(); |
221 | 221 | ||
222 | QStringList fieldList = OPimContactFields::untrfields( false ); | 222 | QStringList fieldList = OPimContactFields::untrfields( false ); |
223 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 223 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
224 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 224 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
225 | // Convert Column-String to Id and get value for this id.. | 225 | // Convert Column-String to Id and get value for this id.. |
226 | // Hmmm.. Maybe not very cute solution.. | 226 | // Hmmm.. Maybe not very cute solution.. |
227 | int id = translate[*it]; | 227 | int id = translate[*it]; |
228 | switch ( id ){ | 228 | switch ( id ){ |
229 | case Qtopia::Birthday: | 229 | case Qtopia::Birthday: |
230 | case Qtopia::Anniversary:{ | 230 | case Qtopia::Anniversary:{ |
231 | QDate day; | 231 | QDate day; |
232 | if ( id == Qtopia::Birthday ){ | 232 | if ( id == Qtopia::Birthday ){ |
233 | day = m_contact.birthday(); | 233 | day = m_contact.birthday(); |
234 | } else { | 234 | } else { |
235 | day = m_contact.anniversary(); | 235 | day = m_contact.anniversary(); |
236 | } | 236 | } |
237 | // These entries should stored in a special format | 237 | // These entries should stored in a special format |
238 | // year-month-day | 238 | // year-month-day |
239 | if ( day.isValid() ){ | 239 | if ( day.isValid() ){ |
240 | qu += QString(",\"%1-%2-%3\"") | 240 | qu += QString(",\"%1-%2-%3\"") |
241 | .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) | 241 | .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) |
242 | .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) | 242 | .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) |
243 | .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); | 243 | .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); |
244 | } else { | 244 | } else { |
245 | qu += ",\"\""; | 245 | qu += ",\"\""; |
246 | } | 246 | } |
247 | } | 247 | } |
248 | break; | 248 | break; |
249 | default: | 249 | default: |
250 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); | 250 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | qu += " );"; | 253 | qu += " );"; |
254 | 254 | ||
255 | 255 | ||
256 | // Now add custom data.. | 256 | // Now add custom data.. |
257 | int id = 0; | 257 | int id = 0; |
258 | id = 0; | 258 | id = 0; |
259 | QMap<QString, QString> customMap = m_contact.toExtraMap(); | 259 | QMap<QString, QString> customMap = m_contact.toExtraMap(); |
260 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 260 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
261 | it != customMap.end(); ++it ){ | 261 | it != customMap.end(); ++it ){ |
262 | qu += "insert into custom_data VALUES(" | 262 | qu += "insert into custom_data VALUES(" |
263 | + QString::number( m_contact.uid() ) | 263 | + QString::number( m_contact.uid() ) |
264 | + "," | 264 | + "," |
265 | + QString::number( id++ ) | 265 | + QString::number( id++ ) |
266 | + ",'" | 266 | + ",'" |
267 | + it.key() | 267 | + it.key() |
268 | + "'," | 268 | + "'," |
269 | + "0" // Priority for future enhancements | 269 | + "0" // Priority for future enhancements |
270 | + ",'" | 270 | + ",'" |
271 | + it.data() | 271 | + it.data() |
272 | + "');"; | 272 | + "');"; |
273 | } | 273 | } |
274 | // qu += "commit;"; | 274 | // qu += "commit;"; |
275 | odebug << "add " << qu << "" << oendl; | 275 | odebug << "add " << qu << "" << oendl; |
276 | return qu; | 276 | return qu; |
277 | } | 277 | } |
278 | 278 | ||
279 | 279 | ||
280 | RemoveQuery::RemoveQuery(int uid ) | 280 | RemoveQuery::RemoveQuery(int uid ) |
281 | : OSQLQuery(), m_uid( uid ) {} | 281 | : OSQLQuery(), m_uid( uid ) {} |
282 | |||
282 | RemoveQuery::~RemoveQuery() {} | 283 | RemoveQuery::~RemoveQuery() {} |
284 | |||
283 | QString RemoveQuery::query()const { | 285 | QString RemoveQuery::query()const { |
284 | QString qu = "DELETE from addressbook where uid = " | 286 | QString qu = "DELETE from addressbook where uid = " |
285 | + QString::number(m_uid) + ";"; | 287 | + QString::number(m_uid) + ";"; |
286 | qu += "DELETE from custom_data where uid = " | 288 | qu += "DELETE from custom_data where uid = " |
287 | + QString::number(m_uid) + ";"; | 289 | + QString::number(m_uid) + ";"; |
288 | return qu; | 290 | return qu; |
289 | } | 291 | } |
290 | 292 | ||
291 | 293 | ||
292 | |||
293 | |||
294 | FindQuery::FindQuery(int uid) | 294 | FindQuery::FindQuery(int uid) |
295 | : OSQLQuery(), m_uid( uid ) { | 295 | : OSQLQuery(), m_uid( uid ) { |
296 | } | 296 | } |
297 | FindQuery::FindQuery(const UIDArray& ints) | 297 | FindQuery::FindQuery(const UIDArray& ints) |
298 | : OSQLQuery(), m_uids( ints ){ | 298 | : OSQLQuery(), m_uids( ints ){ |
299 | } | 299 | } |
300 | FindQuery::~FindQuery() { | 300 | FindQuery::~FindQuery() { |
301 | } | 301 | } |
302 | QString FindQuery::query()const{ | 302 | QString FindQuery::query()const{ |
303 | if ( m_uids.count() == 0 ) | 303 | if ( m_uids.count() == 0 ) |
304 | return single(); | 304 | return single(); |
305 | else | 305 | else |
306 | return multi(); | 306 | return multi(); |
307 | } | 307 | } |
308 | 308 | ||
309 | |||
310 | |||
309 | QString FindQuery::multi()const { | 311 | QString FindQuery::multi()const { |
310 | QString qu = "select * from addressbook where"; | 312 | QString qu = "select * from addressbook where"; |
311 | for (uint i = 0; i < m_uids.count(); i++ ) { | 313 | for (uint i = 0; i < m_uids.count(); i++ ) { |
312 | qu += " uid = " + QString::number( m_uids[i] ) + " OR"; | 314 | qu += " uid = " + QString::number( m_uids[i] ) + " OR"; |
313 | } | 315 | } |
314 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | 316 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. |
315 | 317 | ||
316 | odebug << "find query: " << qu << "" << oendl; | 318 | odebug << "find query: " << qu << "" << oendl; |
317 | return qu; | 319 | return qu; |
318 | } | 320 | } |
319 | 321 | ||
320 | QString FindQuery::single()const{ | 322 | QString FindQuery::single()const{ |
321 | QString qu = "select *"; | 323 | QString qu = "select *"; |
322 | qu += " from addressbook where uid = " + QString::number(m_uid); | 324 | qu += " from addressbook where uid = " + QString::number(m_uid); |
323 | 325 | ||
324 | // owarn << "find query: " << qu << "" << oendl; | 326 | // owarn << "find query: " << qu << "" << oendl; |
325 | return qu; | 327 | return qu; |
326 | } | 328 | } |
327 | 329 | ||
328 | 330 | ||
329 | FindCustomQuery::FindCustomQuery(int uid) | 331 | FindCustomQuery::FindCustomQuery(int uid) |
330 | : OSQLQuery(), m_uid( uid ) { | 332 | : OSQLQuery(), m_uid( uid ) { |
331 | } | 333 | } |
332 | FindCustomQuery::FindCustomQuery(const UIDArray& ints) | 334 | FindCustomQuery::FindCustomQuery(const UIDArray& ints) |
333 | : OSQLQuery(), m_uids( ints ){ | 335 | : OSQLQuery(), m_uids( ints ){ |
334 | } | 336 | } |
335 | FindCustomQuery::~FindCustomQuery() { | 337 | FindCustomQuery::~FindCustomQuery() { |
336 | } | 338 | } |
337 | QString FindCustomQuery::query()const{ | 339 | QString FindCustomQuery::query()const{ |
338 | // if ( m_uids.count() == 0 ) | 340 | // if ( m_uids.count() == 0 ) |
339 | return single(); | 341 | return single(); |
340 | } | 342 | } |
341 | QString FindCustomQuery::single()const{ | 343 | QString FindCustomQuery::single()const{ |
342 | QString qu = "select uid, type, value from custom_data where uid = "; | 344 | QString qu = "select uid, type, value from custom_data where uid = "; |
343 | qu += QString::number(m_uid); | 345 | qu += QString::number(m_uid); |
344 | return qu; | 346 | return qu; |
345 | } | 347 | } |
346 | 348 | ||
347 | }; | 349 | }; |
348 | 350 | ||
349 | 351 | ||
350 | /* --------------------------------------------------------------------------- */ | 352 | /* --------------------------------------------------------------------------- */ |
351 | 353 | ||
352 | namespace Opie { | 354 | namespace Opie { |
353 | 355 | ||
354 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, | 356 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, |
355 | const QString& filename ): | 357 | const QString& filename ): |
356 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) | 358 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) |
357 | { | 359 | { |
358 | odebug << "C'tor OPimContactAccessBackend_SQL starts" << oendl; | 360 | odebug << "C'tor OPimContactAccessBackend_SQL starts" << oendl; |
359 | QTime t; | 361 | QTime t; |
360 | t.start(); | 362 | t.start(); |
361 | 363 | ||
362 | /* Expecting to access the default filename if nothing else is set */ | 364 | /* Expecting to access the default filename if nothing else is set */ |
363 | if ( filename.isEmpty() ){ | 365 | if ( filename.isEmpty() ){ |
364 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 366 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
365 | } else | 367 | } else |
366 | m_fileName = filename; | 368 | m_fileName = filename; |
367 | 369 | ||
368 | // Get the standart sql-driver from the OSQLManager.. | 370 | // Get the standart sql-driver from the OSQLManager.. |
369 | OSQLManager man; | 371 | OSQLManager man; |
370 | m_driver = man.standard(); | 372 | m_driver = man.standard(); |
371 | m_driver->setUrl( m_fileName ); | 373 | m_driver->setUrl( m_fileName ); |
372 | 374 | ||
373 | load(); | 375 | load(); |
374 | 376 | ||
375 | odebug << "C'tor OPimContactAccessBackend_SQL ends: " << t.elapsed() << " ms" << oendl; | 377 | odebug << "C'tor OPimContactAccessBackend_SQL ends: " << t.elapsed() << " ms" << oendl; |
376 | } | 378 | } |
377 | 379 | ||
378 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () | 380 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () |
379 | { | 381 | { |
380 | if( m_driver ) | 382 | if( m_driver ) |
381 | delete m_driver; | 383 | delete m_driver; |
382 | } | 384 | } |
383 | 385 | ||
384 | bool OPimContactAccessBackend_SQL::load () | 386 | bool OPimContactAccessBackend_SQL::load () |
385 | { | 387 | { |
386 | if (!m_driver->open() ) | 388 | if (!m_driver->open() ) |
387 | return false; | 389 | return false; |
388 | 390 | ||
389 | // Don't expect that the database exists. | 391 | // Don't expect that the database exists. |
390 | // It is save here to create the table, even if it | 392 | // It is save here to create the table, even if it |
391 | // do exist. ( Is that correct for all databases ?? ) | 393 | // do exist. ( Is that correct for all databases ?? ) |
392 | CreateQuery creat; | 394 | CreateQuery creat; |
393 | OSQLResult res = m_driver->query( &creat ); | 395 | OSQLResult res = m_driver->query( &creat ); |
394 | 396 | ||
395 | update(); | 397 | update(); |
396 | 398 | ||
397 | return true; | 399 | return true; |
398 | 400 | ||
399 | } | 401 | } |
400 | 402 | ||
401 | bool OPimContactAccessBackend_SQL::reload() | 403 | bool OPimContactAccessBackend_SQL::reload() |
402 | { | 404 | { |
403 | return load(); | 405 | return load(); |
404 | } | 406 | } |
405 | 407 | ||
406 | bool OPimContactAccessBackend_SQL::save() | 408 | bool OPimContactAccessBackend_SQL::save() |
407 | { | 409 | { |
408 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 410 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
409 | } | 411 | } |
410 | 412 | ||
411 | 413 | ||
412 | void OPimContactAccessBackend_SQL::clear () | 414 | void OPimContactAccessBackend_SQL::clear () |
413 | { | 415 | { |
414 | ClearQuery cle; | 416 | ClearQuery cle; |
415 | OSQLResult res = m_driver->query( &cle ); | 417 | OSQLResult res = m_driver->query( &cle ); |
416 | 418 | ||
417 | reload(); | 419 | reload(); |
418 | } | 420 | } |
419 | 421 | ||
420 | bool OPimContactAccessBackend_SQL::wasChangedExternally() | 422 | bool OPimContactAccessBackend_SQL::wasChangedExternally() |
421 | { | 423 | { |
422 | return false; | 424 | return false; |
423 | } | 425 | } |
424 | 426 | ||
425 | UIDArray OPimContactAccessBackend_SQL::allRecords() const | 427 | UIDArray OPimContactAccessBackend_SQL::allRecords() const |
426 | { | 428 | { |
427 | 429 | ||
428 | // FIXME: Think about cute handling of changed tables.. | 430 | // FIXME: Think about cute handling of changed tables.. |
429 | // Thus, we don't have to call update here... | 431 | // Thus, we don't have to call update here... |
430 | if ( m_changed ) | 432 | if ( m_changed ) |
431 | ((OPimContactAccessBackend_SQL*)this)->update(); | 433 | ((OPimContactAccessBackend_SQL*)this)->update(); |
432 | 434 | ||
433 | return m_uids; | 435 | return m_uids; |
434 | } | 436 | } |
435 | 437 | ||
436 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) | 438 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) |
437 | { | 439 | { |
438 | odebug << "add in contact SQL-Backend" << oendl; | 440 | odebug << "add in contact SQL-Backend" << oendl; |
439 | InsertQuery ins( newcontact ); | 441 | InsertQuery ins( newcontact ); |
440 | OSQLResult res = m_driver->query( &ins ); | 442 | OSQLResult res = m_driver->query( &ins ); |
441 | 443 | ||
442 | if ( res.state() == OSQLResult::Failure ) | 444 | if ( res.state() == OSQLResult::Failure ) |
443 | return false; | 445 | return false; |
444 | 446 | ||
445 | int c = m_uids.count(); | 447 | int c = m_uids.count(); |
446 | m_uids.resize( c+1 ); | 448 | m_uids.resize( c+1 ); |
447 | m_uids[c] = newcontact.uid(); | 449 | m_uids[c] = newcontact.uid(); |
448 | 450 | ||
449 | return true; | 451 | return true; |
450 | } | 452 | } |
451 | 453 | ||
452 | 454 | ||
453 | bool OPimContactAccessBackend_SQL::remove ( int uid ) | 455 | bool OPimContactAccessBackend_SQL::remove ( int uid ) |
454 | { | 456 | { |
455 | RemoveQuery rem( uid ); | 457 | RemoveQuery rem( uid ); |
456 | OSQLResult res = m_driver->query(&rem ); | 458 | OSQLResult res = m_driver->query(&rem ); |
457 | 459 | ||
458 | if ( res.state() == OSQLResult::Failure ) | 460 | if ( res.state() == OSQLResult::Failure ) |
459 | return false; | 461 | return false; |
460 | 462 | ||
461 | m_changed = true; | 463 | m_changed = true; |
462 | 464 | ||
463 | return true; | 465 | return true; |
464 | } | 466 | } |
465 | 467 | ||
466 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) | 468 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) |
467 | { | 469 | { |
468 | if ( !remove( contact.uid() ) ) | 470 | if ( !remove( contact.uid() ) ) |
469 | return false; | 471 | return false; |
470 | 472 | ||
471 | return add( contact ); | 473 | return add( contact ); |
472 | } | 474 | } |
473 | 475 | ||
474 | 476 | ||
475 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | 477 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const |
476 | { | 478 | { |
477 | odebug << "OPimContactAccessBackend_SQL::find(" << uid << ")" << oendl; | 479 | odebug << "OPimContactAccessBackend_SQL::find(" << uid << ")" << oendl; |
478 | QTime t; | 480 | QTime t; |
479 | t.start(); | 481 | t.start(); |
480 | 482 | ||
481 | OPimContact retContact( requestNonCustom( uid ) ); | 483 | OPimContact retContact( requestNonCustom( uid ) ); |
482 | retContact.setExtraMap( requestCustom( uid ) ); | 484 | retContact.setExtraMap( requestCustom( uid ) ); |
483 | 485 | ||
484 | odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; | 486 | odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; |
485 | return retContact; | 487 | return retContact; |
486 | } | 488 | } |
487 | 489 | ||
488 | OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUids, uint current, Frontend::CacheDirection direction ) const | 490 | OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUids, uint current, Frontend::CacheDirection direction ) const |
489 | { | 491 | { |
490 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl; | 492 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl; |
491 | odebug << "searching for " << uid << "" << oendl; | 493 | odebug << "searching for " << uid << "" << oendl; |
492 | 494 | ||
493 | QTime t; | 495 | QTime t; |
494 | t.start(); | 496 | t.start(); |
495 | 497 | ||
496 | uint numReadAhead = readAhead(); | 498 | uint numReadAhead = readAhead(); |
497 | QArray<int> searchList( numReadAhead ); | 499 | QArray<int> searchList( numReadAhead ); |
498 | 500 | ||
499 | uint size =0; | 501 | uint size =0; |
500 | 502 | ||
501 | // Build an array with all elements which should be requested and cached | 503 | // Build an array with all elements which should be requested and cached |
502 | // We will just request "numReadAhead" elements, starting from "current" position in | 504 | // We will just request "numReadAhead" elements, starting from "current" position in |
503 | // the list of many uids ! | 505 | // the list of many uids ! |
504 | switch( direction ) { | 506 | switch( direction ) { |
505 | /* forward */ | 507 | /* forward */ |
506 | case Frontend::Forward: | 508 | case Frontend::Forward: |
507 | for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) { | 509 | for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) { |
508 | searchList[size] = queryUids[i]; | 510 | searchList[size] = queryUids[i]; |
509 | size++; | 511 | size++; |
510 | } | 512 | } |
511 | break; | 513 | break; |
512 | /* reverse */ | 514 | /* reverse */ |
513 | case Frontend::Reverse: | 515 | case Frontend::Reverse: |
514 | for ( uint i = current; i != 0 && size < numReadAhead; i-- ) { | 516 | for ( uint i = current; i != 0 && size < numReadAhead; i-- ) { |
515 | searchList[size] = queryUids[i]; | 517 | searchList[size] = queryUids[i]; |
516 | size++; | 518 | size++; |
517 | } | 519 | } |
518 | break; | 520 | break; |
519 | } | 521 | } |
520 | 522 | ||
521 | //Shrink to real size.. | 523 | //Shrink to real size.. |
522 | searchList.resize( size ); | 524 | searchList.resize( size ); |
523 | 525 | ||
524 | OPimContact retContact( requestContactsAndCache( uid, searchList ) ); | 526 | OPimContact retContact( requestContactsAndCache( uid, searchList ) ); |
525 | 527 | ||
526 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl; | 528 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl; |
527 | return retContact; | 529 | return retContact; |
528 | } | 530 | } |
529 | 531 | ||
530 | 532 | ||
531 | UIDArray OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, | 533 | UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings, |
532 | const QDateTime& qd ) const | 534 | const QDateTime& qd ) const |
533 | { | 535 | { |
534 | QString qu = "SELECT uid FROM addressbook WHERE"; | 536 | QString qu = "SELECT uid FROM addressbook WHERE"; |
537 | |||
538 | // Just add uid's selection if we really try to search in a subset of all uids! Otherwise this would | ||
539 | // just take time and memory! | ||
540 | if ( uidlist.count() != m_uids.count() ) { | ||
541 | qu += " ("; | ||
542 | |||
543 | for ( uint i = 0; i < uidlist.count(); i++ ) { | ||
544 | qu += " uid = " + QString::number( uidlist[i] ) + " OR"; | ||
545 | } | ||
546 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | ||
547 | qu += " ) AND "; | ||
548 | } | ||
549 | |||
535 | QString searchQuery =""; | 550 | QString searchQuery =""; |
536 | 551 | ||
537 | QDate startDate; | 552 | QDate startDate; |
538 | 553 | ||
539 | if ( qd.isValid() ) | 554 | if ( qd.isValid() ) |
540 | startDate = qd.date(); | 555 | startDate = qd.date(); |
541 | else | 556 | else |
542 | startDate = QDate::currentDate(); | 557 | startDate = QDate::currentDate(); |
543 | 558 | ||
544 | 559 | ||
545 | QMap<int, QString> queryFields = query.toMap(); | 560 | QMap<int, QString> queryFields = query.toMap(); |
546 | QStringList fieldList = OPimContactFields::untrfields( false ); | 561 | QStringList fieldList = OPimContactFields::untrfields( false ); |
547 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 562 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
548 | 563 | ||
549 | // Convert every filled field to a SQL-Query | 564 | // Convert every filled field to a SQL-Query |
550 | // bool isAnyFieldSelected = false; | 565 | // bool isAnyFieldSelected = false; |
551 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 566 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
552 | 567 | ||
553 | int id = translate[*it]; | 568 | int id = translate[*it]; |
554 | QString queryStr = queryFields[id]; | 569 | QString queryStr = queryFields[id]; |
555 | QDate* endDate = 0l; | 570 | QDate* endDate = 0l; |
556 | 571 | ||
557 | if ( !queryStr.isEmpty() ){ | 572 | if ( !queryStr.isEmpty() ){ |
558 | // If something is alredy stored in the query, add an "AND" | 573 | // If something is alredy stored in the query, add an "AND" |
559 | // to the end of the string to prepare for the next .. | 574 | // to the end of the string to prepare for the next .. |
560 | if ( !searchQuery.isEmpty() ) | 575 | if ( !searchQuery.isEmpty() ) |
561 | searchQuery += " AND"; | 576 | searchQuery += " AND"; |
562 | 577 | ||
563 | // isAnyFieldSelected = true; | 578 | // isAnyFieldSelected = true; |
564 | switch( id ){ | 579 | switch( id ){ |
565 | case Qtopia::Birthday: | 580 | case Qtopia::Birthday: |
566 | endDate = new QDate( query.birthday() ); | 581 | endDate = new QDate( query.birthday() ); |
567 | // Fall through ! | 582 | // Fall through ! |
568 | case Qtopia::Anniversary: | 583 | case Qtopia::Anniversary: |
569 | if ( endDate == 0l ) | 584 | if ( endDate == 0l ) |
570 | endDate = new QDate( query.anniversary() ); | 585 | endDate = new QDate( query.anniversary() ); |
571 | 586 | ||
572 | if ( settings & OPimContactAccess::DateDiff ) { | 587 | if ( settings & OPimContactAccess::DateDiff ) { |
573 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) | 588 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) |
574 | .arg( *it ) | 589 | .arg( *it ) |
575 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | 590 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) |
576 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | 591 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) |
577 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) | 592 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) |
578 | .arg( *it ) | 593 | .arg( *it ) |
579 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) | 594 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) |
580 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) | 595 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) |
581 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; | 596 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; |
582 | } | 597 | } |
583 | 598 | ||
584 | if ( settings & OPimContactAccess::DateYear ){ | 599 | if ( settings & OPimContactAccess::DateYear ){ |
585 | if ( settings & OPimContactAccess::DateDiff ) | 600 | if ( settings & OPimContactAccess::DateDiff ) |
586 | searchQuery += " AND"; | 601 | searchQuery += " AND"; |
587 | 602 | ||
588 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) | 603 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) |
589 | .arg( *it ) | 604 | .arg( *it ) |
590 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); | 605 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); |
591 | } | 606 | } |
592 | 607 | ||
593 | if ( settings & OPimContactAccess::DateMonth ){ | 608 | if ( settings & OPimContactAccess::DateMonth ){ |
594 | if ( ( settings & OPimContactAccess::DateDiff ) | 609 | if ( ( settings & OPimContactAccess::DateDiff ) |
595 | || ( settings & OPimContactAccess::DateYear ) ) | 610 | || ( settings & OPimContactAccess::DateYear ) ) |
596 | searchQuery += " AND"; | 611 | searchQuery += " AND"; |
597 | 612 | ||
598 | searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) | 613 | searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) |
599 | .arg( *it ) | 614 | .arg( *it ) |
600 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); | 615 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); |
601 | } | 616 | } |
602 | 617 | ||
603 | if ( settings & OPimContactAccess::DateDay ){ | 618 | if ( settings & OPimContactAccess::DateDay ){ |
604 | if ( ( settings & OPimContactAccess::DateDiff ) | 619 | if ( ( settings & OPimContactAccess::DateDiff ) |
605 | || ( settings & OPimContactAccess::DateYear ) | 620 | || ( settings & OPimContactAccess::DateYear ) |
606 | || ( settings & OPimContactAccess::DateMonth ) ) | 621 | || ( settings & OPimContactAccess::DateMonth ) ) |
607 | searchQuery += " AND"; | 622 | searchQuery += " AND"; |
608 | 623 | ||
609 | searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) | 624 | searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) |
610 | .arg( *it ) | 625 | .arg( *it ) |
611 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); | 626 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); |
612 | } | 627 | } |
613 | 628 | ||
614 | break; | 629 | break; |
615 | default: | 630 | default: |
616 | // Switching between case sensitive and insensitive... | 631 | // Switching between case sensitive and insensitive... |
617 | // LIKE is not case sensitive, GLOB is case sensitive | 632 | // LIKE is not case sensitive, GLOB is case sensitive |
618 | // Do exist a better solution to switch this ? | 633 | // Do exist a better solution to switch this ? |
619 | if ( settings & OPimContactAccess::IgnoreCase ) | 634 | if ( settings & OPimContactAccess::IgnoreCase ) |
620 | searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" | 635 | searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" |
621 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; | 636 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; |
622 | else | 637 | else |
623 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" | 638 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" |
624 | + queryStr + "'" + ")"; | 639 | + queryStr + "'" + ")"; |
625 | 640 | ||
626 | } | 641 | } |
627 | } | 642 | } |
628 | 643 | ||
629 | delete endDate; | 644 | delete endDate; |
630 | } | 645 | } |
631 | // Skip trailing "AND" | 646 | // Skip trailing "AND" |
632 | // if ( isAnyFieldSelected ) | 647 | // if ( isAnyFieldSelected ) |
633 | // qu = qu.left( qu.length() - 4 ); | 648 | // qu = qu.left( qu.length() - 4 ); |
634 | 649 | ||
635 | qu += searchQuery; | 650 | qu += searchQuery; |
636 | 651 | ||
637 | odebug << "queryByExample query: " << qu << "" << oendl; | 652 | odebug << "queryByExample query: " << qu << "" << oendl; |
638 | 653 | ||
639 | // Execute query and return the received uid's | 654 | // Execute query and return the received uid's |
640 | OSQLRawQuery raw( qu ); | 655 | OSQLRawQuery raw( qu ); |
641 | OSQLResult res = m_driver->query( &raw ); | 656 | OSQLResult res = m_driver->query( &raw ); |
642 | if ( res.state() != OSQLResult::Success ){ | 657 | if ( res.state() != OSQLResult::Success ){ |
643 | UIDArray empty; | 658 | UIDArray empty; |
644 | return empty; | 659 | return empty; |
645 | } | 660 | } |
646 | 661 | ||
647 | UIDArray list = extractUids( res ); | 662 | UIDArray list = extractUids( res ); |
648 | 663 | ||
649 | return list; | 664 | return list; |
650 | } | 665 | } |
651 | 666 | ||
652 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 667 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
653 | { | 668 | { |
654 | #if 0 | 669 | #if 0 |
655 | QArray<int> nix(0); | 670 | QArray<int> nix(0); |
656 | return nix; | 671 | return nix; |
657 | 672 | ||
658 | #else | 673 | #else |
659 | QString qu = "SELECT uid FROM addressbook WHERE ("; | 674 | QString qu = "SELECT uid FROM addressbook WHERE ("; |
660 | QString searchlist; | 675 | QString searchlist; |
661 | 676 | ||
662 | QStringList fieldList = OPimContactFields::untrfields( false ); | 677 | QStringList fieldList = OPimContactFields::untrfields( false ); |
663 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 678 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
664 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 679 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
665 | if ( !searchlist.isEmpty() ) | 680 | if ( !searchlist.isEmpty() ) |
666 | searchlist += " OR "; | 681 | searchlist += " OR "; |
667 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; | 682 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; |
668 | } | 683 | } |
669 | 684 | ||
670 | qu = qu + searchlist + ")"; | 685 | qu = qu + searchlist + ")"; |
671 | 686 | ||
672 | odebug << "query: " << qu << "" << oendl; | 687 | odebug << "query: " << qu << "" << oendl; |
673 | 688 | ||
674 | OSQLRawQuery raw( qu ); | 689 | OSQLRawQuery raw( qu ); |
675 | OSQLResult res = m_driver->query( &raw ); | 690 | OSQLResult res = m_driver->query( &raw ); |
676 | 691 | ||
677 | return extractUids( res ); | 692 | return extractUids( res ); |
678 | 693 | ||
679 | 694 | ||
680 | #endif | 695 | #endif |
681 | } | 696 | } |
682 | 697 | ||
683 | const uint OPimContactAccessBackend_SQL::querySettings() const | 698 | const uint OPimContactAccessBackend_SQL::querySettings() const |
684 | { | 699 | { |
685 | return OPimContactAccess::IgnoreCase | 700 | return OPimContactAccess::IgnoreCase |
686 | | OPimContactAccess::WildCards | 701 | | OPimContactAccess::WildCards |
687 | | OPimContactAccess::DateDiff | 702 | | OPimContactAccess::DateDiff |
688 | | OPimContactAccess::DateYear | 703 | | OPimContactAccess::DateYear |
689 | | OPimContactAccess::DateMonth | 704 | | OPimContactAccess::DateMonth |
690 | | OPimContactAccess::DateDay | 705 | | OPimContactAccess::DateDay |
691 | ; | 706 | ; |
692 | } | 707 | } |
693 | 708 | ||
694 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 709 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
695 | { | 710 | { |
696 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 711 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
697 | * may be added with any of the other settings. IgnoreCase should never used alone. | 712 | * may be added with any of the other settings. IgnoreCase should never used alone. |
698 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 713 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
699 | */ | 714 | */ |
700 | 715 | ||
701 | // Step 1: Check whether the given settings are supported by this backend | 716 | // Step 1: Check whether the given settings are supported by this backend |
702 | if ( ( querySettings & ( | 717 | if ( ( querySettings & ( |
703 | OPimContactAccess::IgnoreCase | 718 | OPimContactAccess::IgnoreCase |
704 | | OPimContactAccess::WildCards | 719 | | OPimContactAccess::WildCards |
705 | | OPimContactAccess::DateDiff | 720 | | OPimContactAccess::DateDiff |
706 | | OPimContactAccess::DateYear | 721 | | OPimContactAccess::DateYear |
707 | | OPimContactAccess::DateMonth | 722 | | OPimContactAccess::DateMonth |
708 | | OPimContactAccess::DateDay | 723 | | OPimContactAccess::DateDay |
709 | // | OPimContactAccess::RegExp | 724 | // | OPimContactAccess::RegExp |
710 | // | OPimContactAccess::ExactMatch | 725 | // | OPimContactAccess::ExactMatch |
711 | ) ) != querySettings ) | 726 | ) ) != querySettings ) |
712 | return false; | 727 | return false; |
713 | 728 | ||
714 | // Step 2: Check whether the given combinations are ok.. | 729 | // Step 2: Check whether the given combinations are ok.. |
715 | 730 | ||
716 | // IngoreCase alone is invalid | 731 | // IngoreCase alone is invalid |
717 | if ( querySettings == OPimContactAccess::IgnoreCase ) | 732 | if ( querySettings == OPimContactAccess::IgnoreCase ) |
718 | return false; | 733 | return false; |
719 | 734 | ||
720 | // WildCards, RegExp and ExactMatch should never used at the same time | 735 | // WildCards, RegExp and ExactMatch should never used at the same time |
721 | switch ( querySettings & ~( OPimContactAccess::IgnoreCase | 736 | switch ( querySettings & ~( OPimContactAccess::IgnoreCase |
722 | | OPimContactAccess::DateDiff | 737 | | OPimContactAccess::DateDiff |
723 | | OPimContactAccess::DateYear | 738 | | OPimContactAccess::DateYear |
724 | | OPimContactAccess::DateMonth | 739 | | OPimContactAccess::DateMonth |
725 | | OPimContactAccess::DateDay | 740 | | OPimContactAccess::DateDay |
726 | ) | 741 | ) |
727 | ){ | 742 | ){ |
728 | case OPimContactAccess::RegExp: | 743 | case OPimContactAccess::RegExp: |
729 | return ( true ); | 744 | return ( true ); |
730 | case OPimContactAccess::WildCards: | 745 | case OPimContactAccess::WildCards: |
731 | return ( true ); | 746 | return ( true ); |
732 | case OPimContactAccess::ExactMatch: | 747 | case OPimContactAccess::ExactMatch: |
733 | return ( true ); | 748 | return ( true ); |
734 | case 0: // one of the upper removed bits were set.. | 749 | case 0: // one of the upper removed bits were set.. |
735 | return ( true ); | 750 | return ( true ); |
736 | default: | 751 | default: |
737 | return ( false ); | 752 | return ( false ); |
738 | } | 753 | } |
739 | 754 | ||
740 | } | 755 | } |
741 | 756 | ||
742 | UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int sortOrder, | 757 | UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int sortOrder, |
743 | int filter, const QArray<int>& categories )const | 758 | int filter, const QArray<int>& categories )const |
744 | { | 759 | { |
745 | QTime t; | 760 | QTime t; |
746 | t.start(); | 761 | t.start(); |
747 | 762 | ||
748 | QString query = "SELECT uid FROM addressbook"; | 763 | QString query = "SELECT uid FROM addressbook"; |
749 | 764 | ||
750 | query += " WHERE ("; | 765 | query += " WHERE ("; |
751 | for ( uint i = 0; i < ar.count(); i++ ) { | 766 | for ( uint i = 0; i < ar.count(); i++ ) { |
752 | query += " uid = " + QString::number( ar[i] ) + " OR"; | 767 | query += " uid = " + QString::number( ar[i] ) + " OR"; |
753 | } | 768 | } |
754 | query.remove( query.length()-2, 2 ); // Hmmmm.. | 769 | query.remove( query.length()-2, 2 ); // Hmmmm.. |
755 | query += ")"; | 770 | query += ")"; |
756 | 771 | ||
757 | 772 | ||
758 | if ( filter != OPimBase::FilterOff ){ | 773 | if ( filter != OPimBase::FilterOff ){ |
759 | if ( filter & OPimContactAccess::DoNotShowWithCategory ){ | 774 | if ( filter & OPimContactAccess::DoNotShowWithCategory ){ |
760 | query += " AND ( \"Categories\" == '' )"; | 775 | query += " AND ( \"Categories\" == '' )"; |
761 | } else if ( filter & OPimBase::FilterCategory ){ | 776 | } else if ( filter & OPimBase::FilterCategory ){ |
762 | query += " AND ("; | 777 | query += " AND ("; |
763 | for ( uint i = 0; i < categories.count(); i++ ){ | 778 | for ( uint i = 0; i < categories.count(); i++ ){ |
764 | query += "\"Categories\" LIKE"; | 779 | query += "\"Categories\" LIKE"; |
765 | query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; | 780 | query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; |
766 | } | 781 | } |
767 | query.remove( query.length()-2, 2 ); // Hmmmm.. | 782 | query.remove( query.length()-2, 2 ); // Hmmmm.. |
768 | query += ")"; | 783 | query += ")"; |
769 | } | 784 | } |
770 | 785 | ||
771 | if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ | 786 | if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ |
772 | query += " AND ( \"Children\" != '' )"; | 787 | query += " AND ( \"Children\" != '' )"; |
773 | } | 788 | } |
774 | 789 | ||
775 | if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ | 790 | if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ |
776 | query += " AND ( \"Anniversary\" != '' )"; | 791 | query += " AND ( \"Anniversary\" != '' )"; |
777 | } | 792 | } |
778 | 793 | ||
779 | if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ | 794 | if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ |
780 | query += " AND ( \"Birthday\" != '' )"; | 795 | query += " AND ( \"Birthday\" != '' )"; |
781 | } | 796 | } |
782 | 797 | ||
783 | if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ | 798 | if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ |
784 | // Expect that no Street means no Address, too! (eilers) | 799 | // Expect that no Street means no Address, too! (eilers) |
785 | query += " AND ( \"Home Street\" != '' )"; | 800 | query += " AND ( \"Home Street\" != '' )"; |
786 | } | 801 | } |
787 | 802 | ||
788 | if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ | 803 | if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ |
789 | // Expect that no Street means no Address, too! (eilers) | 804 | // Expect that no Street means no Address, too! (eilers) |
790 | query += " AND ( \"Business Street\" != '' )"; | 805 | query += " AND ( \"Business Street\" != '' )"; |
791 | } | 806 | } |
792 | 807 | ||
793 | } | 808 | } |
794 | 809 | ||
795 | query += " ORDER BY"; | 810 | query += " ORDER BY"; |
796 | 811 | ||
797 | switch ( sortOrder ) { | 812 | switch ( sortOrder ) { |
798 | case OPimContactAccess::SortSummary: | 813 | case OPimContactAccess::SortSummary: |
799 | query += " \"Notes\""; | 814 | query += " \"Notes\""; |
800 | break; | 815 | break; |
801 | case OPimContactAccess::SortByCategory: | 816 | case OPimContactAccess::SortByCategory: |
802 | query += " \"Categories\""; | 817 | query += " \"Categories\""; |
803 | break; | 818 | break; |
804 | case OPimContactAccess::SortByDate: | 819 | case OPimContactAccess::SortByDate: |
805 | query += " \"\""; | 820 | query += " \"\""; |
806 | break; | 821 | break; |
807 | case OPimContactAccess::SortTitle: | 822 | case OPimContactAccess::SortTitle: |
808 | query += " \"Name Title\""; | 823 | query += " \"Name Title\""; |
809 | break; | 824 | break; |
810 | case OPimContactAccess::SortFirstName: | 825 | case OPimContactAccess::SortFirstName: |
811 | query += " \"First Name\""; | 826 | query += " \"First Name\""; |
812 | break; | 827 | break; |
813 | case OPimContactAccess::SortMiddleName: | 828 | case OPimContactAccess::SortMiddleName: |
814 | query += " \"Middle Name\""; | 829 | query += " \"Middle Name\""; |
815 | break; | 830 | break; |
816 | case OPimContactAccess::SortLastName: | 831 | case OPimContactAccess::SortLastName: |
817 | query += " \"Last Name\""; | 832 | query += " \"Last Name\""; |
818 | break; | 833 | break; |
819 | case OPimContactAccess::SortFileAsName: | 834 | case OPimContactAccess::SortFileAsName: |
820 | query += " \"File As\""; | 835 | query += " \"File As\""; |
821 | break; | 836 | break; |
822 | case OPimContactAccess::SortSuffix: | 837 | case OPimContactAccess::SortSuffix: |
823 | query += " \"Suffix\""; | 838 | query += " \"Suffix\""; |
824 | break; | 839 | break; |
825 | case OPimContactAccess::SortEmail: | 840 | case OPimContactAccess::SortEmail: |
826 | query += " \"Default Email\""; | 841 | query += " \"Default Email\""; |
827 | break; | 842 | break; |
828 | case OPimContactAccess::SortNickname: | 843 | case OPimContactAccess::SortNickname: |
829 | query += " \"Nickname\""; | 844 | query += " \"Nickname\""; |
830 | break; | 845 | break; |
831 | case OPimContactAccess::SortAnniversary: | 846 | case OPimContactAccess::SortAnniversary: |
832 | query += " \"Anniversary\""; | 847 | query += " \"Anniversary\""; |
833 | break; | 848 | break; |
834 | case OPimContactAccess::SortBirthday: | 849 | case OPimContactAccess::SortBirthday: |
835 | query += " \"Birthday\""; | 850 | query += " \"Birthday\""; |
836 | break; | 851 | break; |
837 | case OPimContactAccess::SortGender: | 852 | case OPimContactAccess::SortGender: |
838 | query += " \"Gender\""; | 853 | query += " \"Gender\""; |
839 | break; | 854 | break; |
840 | default: | 855 | default: |
841 | query += " \"Last Name\""; | 856 | query += " \"Last Name\""; |
842 | } | 857 | } |
843 | 858 | ||
844 | if ( !asc ) | 859 | if ( !asc ) |
845 | query += " DESC"; | 860 | query += " DESC"; |
846 | 861 | ||
847 | 862 | ||
848 | odebug << "sorted query is: " << query << "" << oendl; | 863 | odebug << "sorted query is: " << query << "" << oendl; |
849 | 864 | ||
850 | OSQLRawQuery raw( query ); | 865 | OSQLRawQuery raw( query ); |
851 | OSQLResult res = m_driver->query( &raw ); | 866 | OSQLResult res = m_driver->query( &raw ); |
852 | if ( res.state() != OSQLResult::Success ){ | 867 | if ( res.state() != OSQLResult::Success ){ |
853 | UIDArray empty; | 868 | UIDArray empty; |
854 | return empty; | 869 | return empty; |
855 | } | 870 | } |
856 | 871 | ||
857 | UIDArray list = extractUids( res ); | 872 | UIDArray list = extractUids( res ); |
858 | 873 | ||
859 | odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; | 874 | odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; |
860 | return list; | 875 | return list; |
861 | } | 876 | } |
862 | 877 | ||
863 | 878 | ||
864 | void OPimContactAccessBackend_SQL::update() | 879 | void OPimContactAccessBackend_SQL::update() |
865 | { | 880 | { |
866 | odebug << "Update starts" << oendl; | 881 | odebug << "Update starts" << oendl; |
867 | QTime t; | 882 | QTime t; |
868 | t.start(); | 883 | t.start(); |
869 | 884 | ||
870 | // Now load the database set and extract the uid's | 885 | // Now load the database set and extract the uid's |
871 | // which will be held locally | 886 | // which will be held locally |
872 | 887 | ||
873 | LoadQuery lo; | 888 | LoadQuery lo; |
874 | OSQLResult res = m_driver->query(&lo); | 889 | OSQLResult res = m_driver->query(&lo); |
875 | if ( res.state() != OSQLResult::Success ) | 890 | if ( res.state() != OSQLResult::Success ) |
876 | return; | 891 | return; |
877 | 892 | ||
878 | m_uids = extractUids( res ); | 893 | m_uids = extractUids( res ); |
879 | 894 | ||
880 | m_changed = false; | 895 | m_changed = false; |
881 | 896 | ||
882 | odebug << "Update ends " << t.elapsed() << " ms" << oendl; | 897 | odebug << "Update ends " << t.elapsed() << " ms" << oendl; |
883 | } | 898 | } |
884 | 899 | ||
885 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 900 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
886 | { | 901 | { |
887 | odebug << "extractUids" << oendl; | 902 | odebug << "extractUids" << oendl; |
888 | QTime t; | 903 | QTime t; |
889 | t.start(); | 904 | t.start(); |
890 | OSQLResultItem::ValueList list = res.results(); | 905 | OSQLResultItem::ValueList list = res.results(); |
891 | OSQLResultItem::ValueList::Iterator it; | 906 | OSQLResultItem::ValueList::Iterator it; |
892 | UIDArray ints(list.count() ); | 907 | UIDArray ints(list.count() ); |
893 | odebug << " count = " << list.count() << "" << oendl; | 908 | odebug << " count = " << list.count() << "" << oendl; |
894 | 909 | ||
895 | int i = 0; | 910 | int i = 0; |
896 | for (it = list.begin(); it != list.end(); ++it ) { | 911 | for (it = list.begin(); it != list.end(); ++it ) { |
897 | ints[i] = (*it).data("uid").toInt(); | 912 | ints[i] = (*it).data("uid").toInt(); |
898 | i++; | 913 | i++; |
899 | } | 914 | } |
900 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; | 915 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; |
901 | 916 | ||
902 | return ints; | 917 | return ints; |
903 | 918 | ||
904 | } | 919 | } |
905 | 920 | ||
906 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const | 921 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const |
907 | { | 922 | { |
908 | QTime t; | 923 | QTime t; |
909 | t.start(); | 924 | t.start(); |
910 | 925 | ||
911 | int t2needed = 0; | 926 | int t2needed = 0; |
912 | int t3needed = 0; | 927 | int t3needed = 0; |
913 | QTime t2; | 928 | QTime t2; |
914 | t2.start(); | 929 | t2.start(); |
915 | FindQuery query( uid ); | 930 | FindQuery query( uid ); |
916 | OSQLResult res_noncustom = m_driver->query( &query ); | 931 | OSQLResult res_noncustom = m_driver->query( &query ); |
917 | t2needed = t2.elapsed(); | 932 | t2needed = t2.elapsed(); |
918 | 933 | ||
919 | OSQLResultItem resItem = res_noncustom.first(); | 934 | OSQLResultItem resItem = res_noncustom.first(); |
920 | 935 | ||
921 | QMap<int, QString> nonCustomMap; | 936 | QMap<int, QString> nonCustomMap; |
922 | QTime t3; | 937 | QTime t3; |
923 | t3.start(); | 938 | t3.start(); |
924 | nonCustomMap = fillNonCustomMap( resItem ); | 939 | nonCustomMap = fillNonCustomMap( resItem ); |
925 | t3needed = t3.elapsed(); | 940 | t3needed = t3.elapsed(); |
926 | 941 | ||
927 | 942 | ||
928 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; | 943 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; |
929 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed | 944 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
930 | << " ms, mapping: " << t3needed << " ms" << oendl; | 945 | << " ms, mapping: " << t3needed << " ms" << oendl; |
931 | 946 | ||
932 | return nonCustomMap; | 947 | return nonCustomMap; |
933 | } | 948 | } |
934 | 949 | ||
935 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ | 950 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ |
936 | OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const UIDArray& uidlist )const | 951 | OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const UIDArray& uidlist )const |
937 | { | 952 | { |
938 | // We want to get all contacts with one query. | 953 | // We want to get all contacts with one query. |
939 | // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). | 954 | // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). |
940 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned | 955 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned |
941 | // by using the cache.. | 956 | // by using the cache.. |
942 | UIDArray cachelist = uidlist; | 957 | UIDArray cachelist = uidlist; |
943 | OPimContact retContact; | 958 | OPimContact retContact; |
944 | 959 | ||
945 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; | 960 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; |
946 | 961 | ||
947 | QTime t; | 962 | QTime t; |
948 | t.start(); | 963 | t.start(); |
949 | 964 | ||
950 | int t2needed = 0; | 965 | int t2needed = 0; |
951 | int t3needed = 0; | 966 | int t3needed = 0; |
952 | QTime t2; | 967 | QTime t2; |
953 | t2.start(); | 968 | t2.start(); |
954 | FindQuery query( cachelist ); | 969 | FindQuery query( cachelist ); |
955 | OSQLResult res_noncustom = m_driver->query( &query ); | 970 | OSQLResult res_noncustom = m_driver->query( &query ); |
956 | t2needed = t2.elapsed(); | 971 | t2needed = t2.elapsed(); |
957 | 972 | ||
958 | QMap<int, QString> nonCustomMap; | 973 | QMap<int, QString> nonCustomMap; |
959 | QTime t3; | 974 | QTime t3; |
960 | t3.start(); | 975 | t3.start(); |
961 | OSQLResultItem resItem = res_noncustom.first(); | 976 | OSQLResultItem resItem = res_noncustom.first(); |
962 | do { | 977 | do { |
963 | OPimContact contact( fillNonCustomMap( resItem ) ); | 978 | OPimContact contact( fillNonCustomMap( resItem ) ); |
964 | contact.setExtraMap( requestCustom( contact.uid() ) ); | 979 | contact.setExtraMap( requestCustom( contact.uid() ) ); |
965 | odebug << "Caching uid: " << contact.uid() << oendl; | 980 | odebug << "Caching uid: " << contact.uid() << oendl; |
966 | cache( contact ); | 981 | cache( contact ); |
967 | if ( contact.uid() == uid ) | 982 | if ( contact.uid() == uid ) |
968 | retContact = contact; | 983 | retContact = contact; |
969 | resItem = res_noncustom.next(); | 984 | resItem = res_noncustom.next(); |
970 | } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! | 985 | } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! |
971 | t3needed = t3.elapsed(); | 986 | t3needed = t3.elapsed(); |
972 | 987 | ||
973 | 988 | ||
974 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; | 989 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; |
975 | odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed | 990 | odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
976 | << " ms, mapping: " << t3needed << " ms" << oendl; | 991 | << " ms, mapping: " << t3needed << " ms" << oendl; |
977 | 992 | ||
978 | return retContact; | 993 | return retContact; |
979 | } | 994 | } |
980 | 995 | ||
981 | QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const | 996 | QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const |
982 | { | 997 | { |
983 | QMap<int, QString> nonCustomMap; | 998 | QMap<int, QString> nonCustomMap; |
984 | 999 | ||
985 | // Now loop through all columns | 1000 | // Now loop through all columns |
986 | QStringList fieldList = OPimContactFields::untrfields( false ); | 1001 | QStringList fieldList = OPimContactFields::untrfields( false ); |
987 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 1002 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
988 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 1003 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
989 | // Get data for the selected column and store it with the | 1004 | // Get data for the selected column and store it with the |
990 | // corresponding id into the map.. | 1005 | // corresponding id into the map.. |
991 | 1006 | ||
992 | int id = translate[*it]; | 1007 | int id = translate[*it]; |
993 | QString value = resultItem.data( (*it) ); | 1008 | QString value = resultItem.data( (*it) ); |
994 | 1009 | ||
995 | // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl; | 1010 | // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl; |
996 | 1011 | ||
997 | switch( id ){ | 1012 | switch( id ){ |
998 | case Qtopia::Birthday: | 1013 | case Qtopia::Birthday: |
999 | case Qtopia::Anniversary:{ | 1014 | case Qtopia::Anniversary:{ |
1000 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 1015 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
1001 | QStringList list = QStringList::split( '-', value ); | 1016 | QStringList list = QStringList::split( '-', value ); |
1002 | QStringList::Iterator lit = list.begin(); | 1017 | QStringList::Iterator lit = list.begin(); |
1003 | int year = (*lit).toInt(); | 1018 | int year = (*lit).toInt(); |
1004 | int month = (*(++lit)).toInt(); | 1019 | int month = (*(++lit)).toInt(); |
1005 | int day = (*(++lit)).toInt(); | 1020 | int day = (*(++lit)).toInt(); |
1006 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ | 1021 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ |
1007 | QDate date( year, month, day ); | 1022 | QDate date( year, month, day ); |
1008 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); | 1023 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); |
1009 | } | 1024 | } |
1010 | } | 1025 | } |
1011 | break; | 1026 | break; |
1012 | case Qtopia::AddressCategory: | 1027 | case Qtopia::AddressCategory: |
1013 | odebug << "Category is: " << value << "" << oendl; | 1028 | odebug << "Category is: " << value << "" << oendl; |
1014 | default: | 1029 | default: |
1015 | nonCustomMap.insert( id, value ); | 1030 | nonCustomMap.insert( id, value ); |
1016 | } | 1031 | } |
1017 | } | 1032 | } |
1018 | 1033 | ||
1019 | nonCustomMap.insert( Qtopia::AddressUid, resultItem.data( "uid" ) ); | 1034 | nonCustomMap.insert( Qtopia::AddressUid, resultItem.data( "uid" ) ); |
1020 | 1035 | ||
1021 | return nonCustomMap; | 1036 | return nonCustomMap; |
1022 | } | 1037 | } |
1023 | 1038 | ||
1024 | 1039 | ||
1025 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const | 1040 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const |
1026 | { | 1041 | { |
1027 | QTime t; | 1042 | QTime t; |
1028 | t.start(); | 1043 | t.start(); |
1029 | 1044 | ||
1030 | QMap<QString, QString> customMap; | 1045 | QMap<QString, QString> customMap; |
1031 | 1046 | ||
1032 | FindCustomQuery query( uid ); | 1047 | FindCustomQuery query( uid ); |
1033 | OSQLResult res_custom = m_driver->query( &query ); | 1048 | OSQLResult res_custom = m_driver->query( &query ); |
1034 | 1049 | ||
1035 | if ( res_custom.state() == OSQLResult::Failure ) { | 1050 | if ( res_custom.state() == OSQLResult::Failure ) { |
1036 | owarn << "OSQLResult::Failure in find query !!" << oendl; | 1051 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
1037 | QMap<QString, QString> empty; | 1052 | QMap<QString, QString> empty; |
1038 | return empty; | 1053 | return empty; |
1039 | } | 1054 | } |
1040 | 1055 | ||
1041 | OSQLResultItem::ValueList list = res_custom.results(); | 1056 | OSQLResultItem::ValueList list = res_custom.results(); |
1042 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 1057 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
1043 | for ( ; it != list.end(); ++it ) { | 1058 | for ( ; it != list.end(); ++it ) { |
1044 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 1059 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
1045 | } | 1060 | } |
1046 | 1061 | ||
1047 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; | 1062 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; |
1048 | return customMap; | 1063 | return customMap; |
1049 | } | 1064 | } |
1050 | 1065 | ||
1051 | } | 1066 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h index 299c175..1cf1185 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h | |||
@@ -1,115 +1,115 @@ | |||
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 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #ifndef _OPimContactAccessBackend_SQL_ | 33 | #ifndef _OPimContactAccessBackend_SQL_ |
34 | #define _OPimContactAccessBackend_SQL_ | 34 | #define _OPimContactAccessBackend_SQL_ |
35 | 35 | ||
36 | #include <opie2/ocontactaccessbackend.h> | 36 | #include <opie2/ocontactaccessbackend.h> |
37 | #include <opie2/ocontactaccess.h> | 37 | #include <opie2/ocontactaccess.h> |
38 | 38 | ||
39 | #include <qlist.h> | 39 | #include <qlist.h> |
40 | #include <qdict.h> | 40 | #include <qdict.h> |
41 | 41 | ||
42 | /* aren't in namespace Opie yet - alwin */ | 42 | /* aren't in namespace Opie yet - alwin */ |
43 | namespace Opie { | 43 | namespace Opie { |
44 | namespace DB { | 44 | namespace DB { |
45 | class OSQLDriver; | 45 | class OSQLDriver; |
46 | class OSQLResult; | 46 | class OSQLResult; |
47 | class OSQLResultItem; | 47 | class OSQLResultItem; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | namespace Opie { | 51 | namespace Opie { |
52 | 52 | ||
53 | /* the default xml implementation */ | 53 | /* the default xml implementation */ |
54 | /** | 54 | /** |
55 | * This class is the SQL implementation of a Contact backend | 55 | * This class is the SQL implementation of a Contact backend |
56 | * it does implement everything available for OPimContact. | 56 | * it does implement everything available for OPimContact. |
57 | * @see OPimAccessBackend for more information of available methods | 57 | * @see OPimAccessBackend for more information of available methods |
58 | */ | 58 | */ |
59 | class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { | 59 | class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { |
60 | public: | 60 | public: |
61 | OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); | 61 | OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); |
62 | 62 | ||
63 | ~OPimContactAccessBackend_SQL (); | 63 | ~OPimContactAccessBackend_SQL (); |
64 | 64 | ||
65 | bool save(); | 65 | bool save(); |
66 | 66 | ||
67 | bool load (); | 67 | bool load (); |
68 | 68 | ||
69 | void clear (); | 69 | void clear (); |
70 | 70 | ||
71 | bool wasChangedExternally(); | 71 | bool wasChangedExternally(); |
72 | 72 | ||
73 | UIDArray allRecords() const; | 73 | UIDArray allRecords() const; |
74 | 74 | ||
75 | OPimContact find( int uid ) const; | 75 | OPimContact find( int uid ) const; |
76 | OPimContact find( int uid, const UIDArray& items, uint cur, Frontend::CacheDirection ) const; | 76 | OPimContact find( int uid, const UIDArray& items, uint cur, Frontend::CacheDirection ) const; |
77 | 77 | ||
78 | UIDArray queryByExample ( const OPimContact &query, int settings, | 78 | UIDArray queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings, |
79 | const QDateTime& d ) const; | 79 | const QDateTime& d ) const; |
80 | 80 | ||
81 | UIDArray matchRegexp( const QRegExp &r ) const; | 81 | UIDArray matchRegexp( const QRegExp &r ) const; |
82 | 82 | ||
83 | const uint querySettings() const; | 83 | const uint querySettings() const; |
84 | 84 | ||
85 | bool hasQuerySettings (uint querySettings) const; | 85 | bool hasQuerySettings (uint querySettings) const; |
86 | 86 | ||
87 | UIDArray sorted( const UIDArray& ar, bool asc, int sortOrder, | 87 | UIDArray sorted( const UIDArray& ar, bool asc, int sortOrder, |
88 | int filter, const QArray<int>& categories)const; | 88 | int filter, const QArray<int>& categories)const; |
89 | 89 | ||
90 | bool add ( const OPimContact &newcontact ); | 90 | bool add ( const OPimContact &newcontact ); |
91 | 91 | ||
92 | bool replace ( const OPimContact &contact ); | 92 | bool replace ( const OPimContact &contact ); |
93 | 93 | ||
94 | bool remove ( int uid ); | 94 | bool remove ( int uid ); |
95 | bool reload(); | 95 | bool reload(); |
96 | 96 | ||
97 | private: | 97 | private: |
98 | UIDArray extractUids( Opie::DB::OSQLResult& res ) const; | 98 | UIDArray extractUids( Opie::DB::OSQLResult& res ) const; |
99 | QMap<int, QString> requestNonCustom( int uid ) const; | 99 | QMap<int, QString> requestNonCustom( int uid ) const; |
100 | QMap<QString, QString> requestCustom( int uid ) const; | 100 | QMap<QString, QString> requestCustom( int uid ) const; |
101 | QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const; | 101 | QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const; |
102 | OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const; | 102 | OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const; |
103 | void update(); | 103 | void update(); |
104 | 104 | ||
105 | protected: | 105 | protected: |
106 | bool m_changed; | 106 | bool m_changed; |
107 | QString m_fileName; | 107 | QString m_fileName; |
108 | UIDArray m_uids; | 108 | UIDArray m_uids; |
109 | 109 | ||
110 | Opie::DB::OSQLDriver* m_driver; | 110 | Opie::DB::OSQLDriver* m_driver; |
111 | }; | 111 | }; |
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | #endif | 115 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp index 73c7059..e44912a 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp | |||
@@ -1,164 +1,181 @@ | |||
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 <qtl.h> | 29 | #include <qtl.h> |
30 | 30 | ||
31 | #include <opie2/opimrecurrence.h> | 31 | #include <opie2/opimrecurrence.h> |
32 | 32 | ||
33 | #include <opie2/odatebookaccessbackend.h> | 33 | #include <opie2/odatebookaccessbackend.h> |
34 | 34 | ||
35 | using namespace Opie; | 35 | using namespace Opie; |
36 | 36 | ||
37 | namespace { | 37 | namespace { |
38 | /* a small helper to get all NonRepeating events for a range of time */ | 38 | /* a small helper to get all NonRepeating events for a range of time */ |
39 | void events( OPimBackendOccurrence::List& tmpList, | 39 | void events( OPimBackendOccurrence::List& tmpList, |
40 | const OPimEvent::ValueList& events, | 40 | const OPimEvent::ValueList& events, |
41 | const QDate& from, const QDate& to ) { | 41 | const QDate& from, const QDate& to ) { |
42 | QDateTime dtStart, dtEnd; | 42 | QDateTime dtStart, dtEnd; |
43 | 43 | ||
44 | for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { | 44 | for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { |
45 | dtStart = (*it).startDateTime(); | 45 | dtStart = (*it).startDateTime(); |
46 | dtEnd = (*it).endDateTime(); | 46 | dtEnd = (*it).endDateTime(); |
47 | 47 | ||
48 | /* | 48 | /* |
49 | * If in range | 49 | * If in range |
50 | */ | 50 | */ |
51 | if (dtStart.date() >= from && dtEnd.date() <= to ) { | 51 | if (dtStart.date() >= from && dtEnd.date() <= to ) { |
52 | OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );; | 52 | OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );; |
53 | tmpList.append( eff ); | 53 | tmpList.append( eff ); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list, | 58 | void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list, |
59 | const QDate& from, const QDate& to ) { | 59 | const QDate& from, const QDate& to ) { |
60 | QDate repeat; | 60 | QDate repeat; |
61 | for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { | 61 | for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { |
62 | int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); | 62 | int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); |
63 | QDate itDate = from.addDays(-dur ); | 63 | QDate itDate = from.addDays(-dur ); |
64 | OPimRecurrence rec = (*it).recurrence(); | 64 | OPimRecurrence rec = (*it).recurrence(); |
65 | if ( !rec.hasEndDate() || rec.endDate() > to ) { | 65 | if ( !rec.hasEndDate() || rec.endDate() > to ) { |
66 | rec.setEndDate( to ); | 66 | rec.setEndDate( to ); |
67 | rec.setHasEndDate( true ); | 67 | rec.setHasEndDate( true ); |
68 | } | 68 | } |
69 | 69 | ||
70 | QDateTime start, end; | 70 | QDateTime start, end; |
71 | while (rec.nextOcurrence(itDate, repeat ) ) { | 71 | while (rec.nextOcurrence(itDate, repeat ) ) { |
72 | if (repeat > to ) break; | 72 | if (repeat > to ) break; |
73 | 73 | ||
74 | OPimEvent event = *it; | 74 | OPimEvent event = *it; |
75 | start = QDateTime( repeat, event.startDateTime().time() ); | 75 | start = QDateTime( repeat, event.startDateTime().time() ); |
76 | end = QDateTime( repeat.addDays(dur), event.endDateTime().time() ); | 76 | end = QDateTime( repeat.addDays(dur), event.endDateTime().time() ); |
77 | OPimBackendOccurrence eff(start, end, event.uid() ); | 77 | OPimBackendOccurrence eff(start, end, event.uid() ); |
78 | tmpList.append( eff ); | 78 | tmpList.append( eff ); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | namespace Opie { | 84 | namespace Opie { |
85 | 85 | ||
86 | ODateBookAccessBackend::ODateBookAccessBackend() | 86 | ODateBookAccessBackend::ODateBookAccessBackend() |
87 | : OPimAccessBackend<OPimEvent>() | 87 | : OPimAccessBackend<OPimEvent>() |
88 | { | 88 | { |
89 | 89 | ||
90 | } | 90 | } |
91 | ODateBookAccessBackend::~ODateBookAccessBackend() { | 91 | ODateBookAccessBackend::~ODateBookAccessBackend() { |
92 | 92 | ||
93 | } | 93 | } |
94 | OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from, | 94 | OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from, |
95 | const QDate& to )const { | 95 | const QDate& to )const { |
96 | OPimBackendOccurrence::List tmpList; | 96 | OPimBackendOccurrence::List tmpList; |
97 | 97 | ||
98 | events( tmpList, directNonRepeats(), from, to ); | 98 | events( tmpList, directNonRepeats(), from, to ); |
99 | repeat( tmpList, directRawRepeats(),from,to ); | 99 | repeat( tmpList, directRawRepeats(),from,to ); |
100 | 100 | ||
101 | return tmpList; | 101 | return tmpList; |
102 | } | 102 | } |
103 | OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const { | 103 | |
104 | OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const | ||
105 | { | ||
104 | OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() ); | 106 | OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() ); |
105 | 107 | ||
106 | return filterOccurrences( day, dt ); | 108 | return filterOccurrences( day, dt ); |
107 | } | 109 | } |
108 | 110 | ||
109 | OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, | 111 | OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, |
110 | const QDate& to )const { | 112 | const QDate& to )const |
113 | { | ||
111 | OPimBackendOccurrence::List tmpList; | 114 | OPimBackendOccurrence::List tmpList; |
112 | OPimEvent::ValueList list = directNonRepeats(); | 115 | OPimEvent::ValueList list = directNonRepeats(); |
113 | 116 | ||
114 | events( tmpList, list, from, to ); | 117 | events( tmpList, list, from, to ); |
115 | 118 | ||
116 | return tmpList; | 119 | return tmpList; |
117 | } | 120 | } |
118 | 121 | ||
119 | OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const { | 122 | OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const |
123 | { | ||
120 | OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); | 124 | OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); |
121 | return filterOccurrences( day,dt ); | 125 | return filterOccurrences( day,dt ); |
122 | } | 126 | } |
123 | 127 | ||
128 | const uint ODateBookAccessBackend::querySettings() const | ||
129 | { | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const | ||
134 | { | ||
135 | return false; | ||
136 | } | ||
137 | |||
138 | |||
124 | 139 | ||
125 | UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings, | 140 | UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, |
126 | const QDateTime& d )const { | 141 | const QDateTime& d )const |
142 | { | ||
143 | qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" ); | ||
127 | return UIDArray(); | 144 | return UIDArray(); |
128 | } | 145 | } |
129 | 146 | ||
130 | UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { | 147 | UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { |
131 | return UIDArray(); | 148 | return UIDArray(); |
132 | } | 149 | } |
133 | 150 | ||
134 | OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, | 151 | OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, |
135 | const QDateTime& dt ) { | 152 | const QDateTime& dt ) { |
136 | OPimBackendOccurrence::List tmpList; | 153 | OPimBackendOccurrence::List tmpList; |
137 | OPimBackendOccurrence::List::ConstIterator it; | 154 | OPimBackendOccurrence::List::ConstIterator it; |
138 | 155 | ||
139 | for ( it = dayList.begin(); it != dayList.end(); ++it ) { | 156 | for ( it = dayList.begin(); it != dayList.end(); ++it ) { |
140 | OPimBackendOccurrence occ = *it; | 157 | OPimBackendOccurrence occ = *it; |
141 | 158 | ||
142 | /* | 159 | /* |
143 | * Let us find occurrences that are 'now'! | 160 | * Let us find occurrences that are 'now'! |
144 | * If the dt.date() is on the same day as start or end of the Occurrence | 161 | * If the dt.date() is on the same day as start or end of the Occurrence |
145 | * check how near start/end are. | 162 | * check how near start/end are. |
146 | * If it is in the middle of a multiday occurrence list it. | 163 | * If it is in the middle of a multiday occurrence list it. |
147 | * | 164 | * |
148 | * We might want to 'lose' the sixty second offset and list | 165 | * We might want to 'lose' the sixty second offset and list |
149 | * all Events which are active at that time. | 166 | * all Events which are active at that time. |
150 | */ | 167 | */ |
151 | if ( dt.date() == occ.startDateTime().date() ) { | 168 | if ( dt.date() == occ.startDateTime().date() ) { |
152 | if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 ) | 169 | if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 ) |
153 | tmpList.append( occ ); | 170 | tmpList.append( occ ); |
154 | }else if ( dt.date() == occ.endDateTime().date() ) { | 171 | }else if ( dt.date() == occ.endDateTime().date() ) { |
155 | if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 ) | 172 | if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 ) |
156 | tmpList.append( occ ); | 173 | tmpList.append( occ ); |
157 | }else if ( dt.date() >= occ.startDateTime().date() && | 174 | }else if ( dt.date() >= occ.startDateTime().date() && |
158 | dt.date() >= occ.endDateTime().date() ) | 175 | dt.date() >= occ.endDateTime().date() ) |
159 | tmpList.append( occ ); | 176 | tmpList.append( occ ); |
160 | } | 177 | } |
161 | 178 | ||
162 | return tmpList; | 179 | return tmpList; |
163 | } | 180 | } |
164 | } | 181 | } |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index 8927ca1..91f63aa 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h | |||
@@ -1,114 +1,127 @@ | |||
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_BACKEND_H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
30 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 30 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
31 | 31 | ||
32 | #include <qarray.h> | 32 | #include <qarray.h> |
33 | 33 | ||
34 | #include <opie2/opimaccessbackend.h> | 34 | #include <opie2/opimaccessbackend.h> |
35 | #include <opie2/opimevent.h> | 35 | #include <opie2/opimevent.h> |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | /** | 38 | /** |
39 | * This class is the interface to the storage of Events. | 39 | * This class is the interface to the storage of Events. |
40 | * @see OPimAccessBackend | 40 | * @see OPimAccessBackend |
41 | * | 41 | * |
42 | */ | 42 | */ |
43 | class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> { | 43 | class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> { |
44 | public: | 44 | public: |
45 | /** | 45 | /** |
46 | * c'tor without parameter | 46 | * c'tor without parameter |
47 | */ | 47 | */ |
48 | ODateBookAccessBackend(); | 48 | ODateBookAccessBackend(); |
49 | ~ODateBookAccessBackend(); | 49 | ~ODateBookAccessBackend(); |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * This method should return a list of UIDs containing | 52 | * This method should return a list of UIDs containing |
53 | * all repeating events. No filter should be applied | 53 | * all repeating events. No filter should be applied |
54 | * @return list of repeating events | 54 | * @return list of repeating events |
55 | */ | 55 | */ |
56 | virtual UIDArray rawRepeats()const = 0; | 56 | virtual UIDArray rawRepeats()const = 0; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * This mthod should return a list of UIDs containing all non | 59 | * This mthod should return a list of UIDs containing all non |
60 | * repeating events. No filter should be applied | 60 | * repeating events. No filter should be applied |
61 | * @return list of nonrepeating events | 61 | * @return list of nonrepeating events |
62 | */ | 62 | */ |
63 | virtual UIDArray nonRepeats() const = 0; | 63 | virtual UIDArray nonRepeats() const = 0; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * If you do not want to implement the effectiveEvents methods below | 66 | * If you do not want to implement the effectiveEvents methods below |
67 | * you need to supply it with directNonRepeats. | 67 | * you need to supply it with directNonRepeats. |
68 | * This method can return empty lists if effectiveEvents is implememted | 68 | * This method can return empty lists if effectiveEvents is implememted |
69 | */ | 69 | */ |
70 | virtual OPimEvent::ValueList directNonRepeats()const = 0; | 70 | virtual OPimEvent::ValueList directNonRepeats()const = 0; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Same as above but return raw repeats! | 73 | * Same as above but return raw repeats! |
74 | */ | 74 | */ |
75 | virtual OPimEvent::ValueList directRawRepeats()const = 0; | 75 | virtual OPimEvent::ValueList directRawRepeats()const = 0; |
76 | 76 | ||
77 | /* is implemented by default but you can reimplement it*/ | 77 | /* is implemented by default but you can reimplement it*/ |
78 | /** | 78 | /** |
79 | * Effective Events are special event occuring during a time frame. This method does calcualte | 79 | * Effective Events are special event occuring during a time frame. This method does calcualte |
80 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method | 80 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method |
81 | * yourself | 81 | * yourself |
82 | */ | 82 | */ |
83 | virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const; | 83 | virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * this is an overloaded member function | 86 | * this is an overloaded member function |
87 | * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) | 87 | * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) |
88 | */ | 88 | */ |
89 | virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const; | 89 | virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Common and probably inefficent implementation | 92 | * Common and probably inefficent implementation |
93 | * for queryByExample, sorted | 93 | * for queryByExample, sorted |
94 | * and occurrences | 94 | * and occurrences |
95 | */ | 95 | */ |
96 | //@{ | 96 | //@{ |
97 | UIDArray queryByExample( const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const; | 97 | /** |
98 | * Return all possible settings. | ||
99 | * @return All settings provided by the current backend | ||
100 | * (i.e.: query_WildCards & query_IgnoreCase) | ||
101 | */ | ||
102 | const uint querySettings() const; | ||
103 | |||
104 | /** | ||
105 | * Check whether settings are correct. | ||
106 | * @return <i>true</i> if the given settings are correct and possible. | ||
107 | */ | ||
108 | bool hasQuerySettings (uint querySettings) const; | ||
109 | |||
110 | UIDArray queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const; | ||
98 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; | 111 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; |
99 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const; | 112 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const; |
100 | OPimBackendOccurrence::List occurrences( const QDateTime& )const; | 113 | OPimBackendOccurrence::List occurrences( const QDateTime& )const; |
101 | //@} | 114 | //@} |
102 | 115 | ||
103 | protected: | 116 | protected: |
104 | static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List, | 117 | static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List, |
105 | const QDateTime& time ); | 118 | const QDateTime& time ); |
106 | private: | 119 | private: |
107 | class Private; | 120 | class Private; |
108 | Private *d; | 121 | Private *d; |
109 | 122 | ||
110 | }; | 123 | }; |
111 | 124 | ||
112 | } | 125 | } |
113 | 126 | ||
114 | #endif | 127 | #endif |
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index 7321758..6666fd6 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h | |||
@@ -1,445 +1,445 @@ | |||
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_PIM_ACCESS_BACKEND | 29 | #ifndef OPIE_PIM_ACCESS_BACKEND |
30 | #define OPIE_PIM_ACCESS_BACKEND | 30 | #define OPIE_PIM_ACCESS_BACKEND |
31 | 31 | ||
32 | #include <qarray.h> | 32 | #include <qarray.h> |
33 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
34 | 34 | ||
35 | #include <opie2/opimtemplatebase.h> | 35 | #include <opie2/opimtemplatebase.h> |
36 | #include <opie2/opimrecord.h> | 36 | #include <opie2/opimrecord.h> |
37 | #include <opie2/opimbackendoccurrence.h> | 37 | #include <opie2/opimbackendoccurrence.h> |
38 | 38 | ||
39 | namespace Opie { | 39 | namespace Opie { |
40 | class OPimAccessBackendPrivate; | 40 | class OPimAccessBackendPrivate; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * OPimAccessBackend is the Backend Interface to be used | 43 | * OPimAccessBackend is the Backend Interface to be used |
44 | * by OTemplateBase based Frontends. | 44 | * by OTemplateBase based Frontends. |
45 | * For efficency reasons and to support delayed loading | 45 | * For efficency reasons and to support delayed loading |
46 | * most of the Frontend functions can be implemented | 46 | * most of the Frontend functions can be implemented |
47 | * by this backend. | 47 | * by this backend. |
48 | * This allows to utilise the best method on each backend. | 48 | * This allows to utilise the best method on each backend. |
49 | * For example we can use SQL queries instead of self made | 49 | * For example we can use SQL queries instead of self made |
50 | * query which is first more efficent and also uses less memory. | 50 | * query which is first more efficent and also uses less memory. |
51 | */ | 51 | */ |
52 | template <class T = OPimRecord> | 52 | template <class T = OPimRecord> |
53 | class OPimAccessBackend { | 53 | class OPimAccessBackend { |
54 | public: | 54 | public: |
55 | typedef OTemplateBase<T> Frontend; | 55 | typedef OTemplateBase<T> Frontend; |
56 | 56 | ||
57 | //@{ | 57 | //@{ |
58 | OPimAccessBackend(int access = 0); | 58 | OPimAccessBackend(int access = 0); |
59 | virtual ~OPimAccessBackend(); | 59 | virtual ~OPimAccessBackend(); |
60 | //@} | 60 | //@} |
61 | 61 | ||
62 | //@{ | 62 | //@{ |
63 | virtual bool load() = 0; | 63 | virtual bool load() = 0; |
64 | virtual bool reload() = 0; | 64 | virtual bool reload() = 0; |
65 | virtual bool save() = 0; | 65 | virtual bool save() = 0; |
66 | virtual void clear() = 0; | 66 | virtual void clear() = 0; |
67 | //@} | 67 | //@} |
68 | 68 | ||
69 | //@{ | 69 | //@{ |
70 | // FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in | 70 | // FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in |
71 | // all typespecifc backenends (eilers) | 71 | // all typespecifc backenends (eilers) |
72 | /** | 72 | /** |
73 | * Return all possible settings for queryByExample() | 73 | * Return all possible settings for queryByExample() |
74 | * @return All settings provided by the current backend | 74 | * @return All settings provided by the current backend |
75 | * (i.e.: query_WildCards & query_IgnoreCase) | 75 | * (i.e.: query_WildCards & query_IgnoreCase) |
76 | * See implementation in the specific backends for contacts, todo and dates. | 76 | * See implementation in the specific backends for contacts, todo and dates. |
77 | */ | 77 | */ |
78 | virtual const uint querySettings() const { return 0; } /* FIXME: Make Abstrakt !! = 0; */ | 78 | virtual const uint querySettings() const = 0; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Check whether settings are correct for queryByExample() | 81 | * Check whether settings are correct for queryByExample() |
82 | * See implementation in the specific backends for OPimContactAccess, OPimTodoAccess and ODateBookAccess. | 82 | * See implementation in the specific backends for OPimContactAccess, OPimTodoAccess and ODateBookAccess. |
83 | * @return <i>true</i> if the given settings are correct and possible. | 83 | * @return <i>true</i> if the given settings are correct and possible. |
84 | */ | 84 | */ |
85 | virtual bool hasQuerySettings (uint querySettings) const { return false; } /* FIXME: Make Abstrakt !! = 0; */ | 85 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
86 | //@} | 86 | //@} |
87 | 87 | ||
88 | 88 | ||
89 | //@{ | 89 | //@{ |
90 | virtual UIDArray allRecords()const = 0; | 90 | virtual UIDArray allRecords()const = 0; |
91 | virtual UIDArray matchRegexp(const QRegExp &r) const; | 91 | virtual UIDArray matchRegexp(const QRegExp &r) const; |
92 | virtual UIDArray queryByExample( const UIDArray&, const T& t, | 92 | virtual UIDArray queryByExample( const UIDArray&, const T& t, |
93 | int settings, const QDateTime& d = QDateTime() )const { return UIDArray(); } /* FIXME: Make Abstrakt !! = 0; */ | 93 | int settings, const QDateTime& d = QDateTime() )const = 0; |
94 | virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const; | 94 | virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const; |
95 | virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const; | 95 | virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const; |
96 | virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const = 0; | 96 | virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const = 0; |
97 | virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const; | 97 | virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const; |
98 | virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const; | 98 | virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const; |
99 | virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const; | 99 | virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const; |
100 | //@} | 100 | //@} |
101 | 101 | ||
102 | 102 | ||
103 | //@{ | 103 | //@{ |
104 | virtual T find(UID uid )const = 0; | 104 | virtual T find(UID uid )const = 0; |
105 | virtual T find(UID uid, const QArray<UID>& items, | 105 | virtual T find(UID uid, const QArray<UID>& items, |
106 | uint current, typename Frontend::CacheDirection )const ; | 106 | uint current, typename Frontend::CacheDirection )const ; |
107 | //@} | 107 | //@} |
108 | 108 | ||
109 | 109 | ||
110 | //@{ | 110 | //@{ |
111 | virtual bool add( const T& t ) = 0; | 111 | virtual bool add( const T& t ) = 0; |
112 | virtual bool remove( UID uid ) = 0; | 112 | virtual bool remove( UID uid ) = 0; |
113 | virtual bool replace( const T& t ) = 0; | 113 | virtual bool replace( const T& t ) = 0; |
114 | //@} | 114 | //@} |
115 | 115 | ||
116 | 116 | ||
117 | 117 | ||
118 | void setFrontend( Frontend* front ); | 118 | void setFrontend( Frontend* front ); |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * set the read ahead count | 121 | * set the read ahead count |
122 | */ | 122 | */ |
123 | void setReadAhead( uint count ); | 123 | void setReadAhead( uint count ); |
124 | protected: | 124 | protected: |
125 | //@{ | 125 | //@{ |
126 | int access()const; | 126 | int access()const; |
127 | void cache( const T& t )const; | 127 | void cache( const T& t )const; |
128 | void setSaneCacheSize( int ); | 128 | void setSaneCacheSize( int ); |
129 | uint readAhead()const; | 129 | uint readAhead()const; |
130 | //@} | 130 | //@} |
131 | 131 | ||
132 | private: | 132 | private: |
133 | OPimAccessBackendPrivate *d; | 133 | OPimAccessBackendPrivate *d; |
134 | Frontend* m_front; | 134 | Frontend* m_front; |
135 | uint m_read; | 135 | uint m_read; |
136 | int m_acc; | 136 | int m_acc; |
137 | 137 | ||
138 | }; | 138 | }; |
139 | 139 | ||
140 | template <class T> | 140 | template <class T> |
141 | OPimAccessBackend<T>::OPimAccessBackend(int acc) | 141 | OPimAccessBackend<T>::OPimAccessBackend(int acc) |
142 | : m_acc( acc ) | 142 | : m_acc( acc ) |
143 | { | 143 | { |
144 | m_front = 0l; | 144 | m_front = 0l; |
145 | } | 145 | } |
146 | template <class T> | 146 | template <class T> |
147 | OPimAccessBackend<T>::~OPimAccessBackend() { | 147 | OPimAccessBackend<T>::~OPimAccessBackend() { |
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * Slow but default matchRegexp Implementation | 152 | * Slow but default matchRegexp Implementation |
153 | * Create a Big Enough QArray and then iterate | 153 | * Create a Big Enough QArray and then iterate |
154 | * over all Records and matchRegexp them. | 154 | * over all Records and matchRegexp them. |
155 | * At the end we will resize the array to the actual | 155 | * At the end we will resize the array to the actual |
156 | * number of items | 156 | * number of items |
157 | */ | 157 | */ |
158 | template <class T> | 158 | template <class T> |
159 | UIDArray OPimAccessBackend<T>::matchRegexp( const QRegExp& reg )const { | 159 | UIDArray OPimAccessBackend<T>::matchRegexp( const QRegExp& reg )const { |
160 | UIDArray all_rec = allRecords(); | 160 | UIDArray all_rec = allRecords(); |
161 | UIDArray result( all_rec.count() ); | 161 | UIDArray result( all_rec.count() ); |
162 | uint used_records = 0, all_rec_count = all_rec.count(); | 162 | uint used_records = 0, all_rec_count = all_rec.count(); |
163 | 163 | ||
164 | for ( uint i = 0; i < all_rec_count; ++i ) | 164 | for ( uint i = 0; i < all_rec_count; ++i ) |
165 | if (find( all_rec[i], all_rec, i, Frontend::Forward ).match( reg ) ) | 165 | if (find( all_rec[i], all_rec, i, Frontend::Forward ).match( reg ) ) |
166 | result[used_records++] = all_rec[i]; | 166 | result[used_records++] = all_rec[i]; |
167 | 167 | ||
168 | /* shrink to fit */ | 168 | /* shrink to fit */ |
169 | result.resize( used_records ); | 169 | result.resize( used_records ); |
170 | return result; | 170 | return result; |
171 | } | 171 | } |
172 | 172 | ||
173 | template <class T> | 173 | template <class T> |
174 | UIDArray OPimAccessBackend<T>::queryByExample( const T& rec, int settings, | 174 | UIDArray OPimAccessBackend<T>::queryByExample( const T& rec, int settings, |
175 | const QDateTime& datetime )const { | 175 | const QDateTime& datetime )const { |
176 | 176 | ||
177 | return queryByExample( allRecords(), rec, settings, datetime ); | 177 | return queryByExample( allRecords(), rec, settings, datetime ); |
178 | } | 178 | } |
179 | 179 | ||
180 | template <class T> | 180 | template <class T> |
181 | UIDArray OPimAccessBackend<T>::queryByExample( const OPimRecord* rec, int settings, | 181 | UIDArray OPimAccessBackend<T>::queryByExample( const OPimRecord* rec, int settings, |
182 | const QDateTime& datetime )const { | 182 | const QDateTime& datetime )const { |
183 | T* tmp_rec = T::safeCast( rec ); | 183 | T* tmp_rec = T::safeCast( rec ); |
184 | UIDArray ar; | 184 | UIDArray ar; |
185 | if ( tmp_rec ) | 185 | if ( tmp_rec ) |
186 | ar = queryByExample( *tmp_rec, settings, datetime ); | 186 | ar = queryByExample( *tmp_rec, settings, datetime ); |
187 | 187 | ||
188 | return ar; | 188 | return ar; |
189 | } | 189 | } |
190 | 190 | ||
191 | template <class T> | 191 | template <class T> |
192 | UIDArray OPimAccessBackend<T>::sorted( bool asc, int order, int filter, | 192 | UIDArray OPimAccessBackend<T>::sorted( bool asc, int order, int filter, |
193 | const QArray<int>& cats )const { | 193 | const QArray<int>& cats )const { |
194 | return sorted( allRecords(), asc, order, filter, cats ); | 194 | return sorted( allRecords(), asc, order, filter, cats ); |
195 | } | 195 | } |
196 | 196 | ||
197 | template<class T> | 197 | template<class T> |
198 | OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDate&, | 198 | OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDate&, |
199 | const QDate& )const { | 199 | const QDate& )const { |
200 | return OPimBackendOccurrence::List(); | 200 | return OPimBackendOccurrence::List(); |
201 | } | 201 | } |
202 | 202 | ||
203 | template<class T> | 203 | template<class T> |
204 | OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDateTime& dt )const { | 204 | OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDateTime& dt )const { |
205 | QDate date = dt.date(); | 205 | QDate date = dt.date(); |
206 | return occurrences( date, date ); | 206 | return occurrences( date, date ); |
207 | } | 207 | } |
208 | 208 | ||
209 | template <class T> | 209 | template <class T> |
210 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 210 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
211 | m_front = fr; | 211 | m_front = fr; |
212 | } | 212 | } |
213 | template <class T> | 213 | template <class T> |
214 | void OPimAccessBackend<T>::cache( const T& t )const { | 214 | void OPimAccessBackend<T>::cache( const T& t )const { |
215 | if ( m_front ) | 215 | if ( m_front ) |
216 | m_front->cache( t ); | 216 | m_front->cache( t ); |
217 | } | 217 | } |
218 | 218 | ||
219 | template <class T> | 219 | template <class T> |
220 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 220 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
221 | if ( m_front ) | 221 | if ( m_front ) |
222 | m_front->setSaneCacheSize( size ); | 222 | m_front->setSaneCacheSize( size ); |
223 | } | 223 | } |
224 | template <class T> | 224 | template <class T> |
225 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 225 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
226 | uint, typename Frontend::CacheDirection ) const{ | 226 | uint, typename Frontend::CacheDirection ) const{ |
227 | qDebug( "*** Lookahead feature not supported. Fallback to default find!!" ); | 227 | qDebug( "*** Lookahead feature not supported. Fallback to default find!!" ); |
228 | return find( uid ); | 228 | return find( uid ); |
229 | } | 229 | } |
230 | template <class T> | 230 | template <class T> |
231 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | 231 | void OPimAccessBackend<T>::setReadAhead( uint count ) { |
232 | m_read = count; | 232 | m_read = count; |
233 | } | 233 | } |
234 | template <class T> | 234 | template <class T> |
235 | uint OPimAccessBackend<T>::readAhead()const { | 235 | uint OPimAccessBackend<T>::readAhead()const { |
236 | return m_read; | 236 | return m_read; |
237 | } | 237 | } |
238 | template <class T> | 238 | template <class T> |
239 | int OPimAccessBackend<T>::access()const { | 239 | int OPimAccessBackend<T>::access()const { |
240 | return m_acc; | 240 | return m_acc; |
241 | } | 241 | } |
242 | 242 | ||
243 | } | 243 | } |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * \fn template <class T> OPimAccessBackend<T>::OPimAccessBackend(int hint ) | 246 | * \fn template <class T> OPimAccessBackend<T>::OPimAccessBackend(int hint ) |
247 | * @param hint The access hint from the frontend | 247 | * @param hint The access hint from the frontend |
248 | */ | 248 | */ |
249 | 249 | ||
250 | /** | 250 | /** |
251 | * \fn template <class T> bool OPimAccessBackend<T>::load() | 251 | * \fn template <class T> bool OPimAccessBackend<T>::load() |
252 | * Opens the DataBase and does necessary | 252 | * Opens the DataBase and does necessary |
253 | * initialisation of internal structures. | 253 | * initialisation of internal structures. |
254 | * | 254 | * |
255 | * @return true If the DataBase could be opened and | 255 | * @return true If the DataBase could be opened and |
256 | * Information was successfully loaded | 256 | * Information was successfully loaded |
257 | */ | 257 | */ |
258 | 258 | ||
259 | /** | 259 | /** |
260 | * \fn template <class T> bool OPimAccessBackend<T>::reload() | 260 | * \fn template <class T> bool OPimAccessBackend<T>::reload() |
261 | * Reinitialise the DataBase and merges the external changes | 261 | * Reinitialise the DataBase and merges the external changes |
262 | * with your local changes. | 262 | * with your local changes. |
263 | * | 263 | * |
264 | * @return True if the DataBase was reloaded. | 264 | * @return True if the DataBase was reloaded. |
265 | * | 265 | * |
266 | */ | 266 | */ |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * \fn template <class T> bool OPimAccessBackend<T>::save() | 269 | * \fn template <class T> bool OPimAccessBackend<T>::save() |
270 | * | 270 | * |
271 | * Save the changes to storage. In case of memory or | 271 | * Save the changes to storage. In case of memory or |
272 | * disk shortage, return false. | 272 | * disk shortage, return false. |
273 | * | 273 | * |
274 | * | 274 | * |
275 | * @return True if the DataBase could be saved to storage. | 275 | * @return True if the DataBase could be saved to storage. |
276 | */ | 276 | */ |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * \fn template <class T> bool OPimAccessBackend<T>::clear() | 279 | * \fn template <class T> bool OPimAccessBackend<T>::clear() |
280 | * Until a \sa save() changes shouldn't be comitted | 280 | * Until a \sa save() changes shouldn't be comitted |
281 | * | 281 | * |
282 | * | 282 | * |
283 | * @return True if the DataBase could be cleared | 283 | * @return True if the DataBase could be cleared |
284 | * @todo Introduce a 'Commit' | 284 | * @todo Introduce a 'Commit' |
285 | */ | 285 | */ |
286 | 286 | ||
287 | /** | 287 | /** |
288 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::allRecords()const | 288 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::allRecords()const |
289 | * Return an array of all available uids in the loaded | 289 | * Return an array of all available uids in the loaded |
290 | * DataBase. | 290 | * DataBase. |
291 | * @see load | 291 | * @see load |
292 | */ | 292 | */ |
293 | 293 | ||
294 | /** | 294 | /** |
295 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::matchRegexp(const QRegExp& r)const | 295 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::matchRegexp(const QRegExp& r)const |
296 | * Return a List of records that match the regex \par r. | 296 | * Return a List of records that match the regex \par r. |
297 | * | 297 | * |
298 | * @param r The QRegExp to match. | 298 | * @param r The QRegExp to match. |
299 | */ | 299 | */ |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::queryByExample(const T& t, int settings, const QDateTime& d = QDateTime() ) | 302 | * \fn template <class T> QArray<UID> OPimAccessBackend<T>::queryByExample(const T& t, int settings, const QDateTime& d = QDateTime() ) |
303 | * | 303 | * |
304 | * Implement QueryByExample. An Example record is filled and with the | 304 | * Implement QueryByExample. An Example record is filled and with the |
305 | * settings and QDateTime it is determined how the query should be executed. | 305 | * settings and QDateTime it is determined how the query should be executed. |
306 | * Return a list of UIDs that match the Example | 306 | * Return a list of UIDs that match the Example |
307 | * | 307 | * |
308 | * @param t The Example record | 308 | * @param t The Example record |
309 | * @param settings Gives | 309 | * @param settings Gives |
310 | * | 310 | * |
311 | */ | 311 | */ |
312 | 312 | ||
313 | /** | 313 | /** |
314 | * \fn template<class T> QArray<UID> OPimAccessBackend<T>::sorted(const QArray<UID>& ids, bool asc, int sortOrder, int sortFilter, int cat) | 314 | * \fn template<class T> QArray<UID> OPimAccessBackend<T>::sorted(const QArray<UID>& ids, bool asc, int sortOrder, int sortFilter, int cat) |
315 | * \brief Sort the List of records according to the preference | 315 | * \brief Sort the List of records according to the preference |
316 | * | 316 | * |
317 | * Implement sorting in your backend. The default implementation is | 317 | * Implement sorting in your backend. The default implementation is |
318 | * to return the list as it was passed. | 318 | * to return the list as it was passed. |
319 | * The default Backend Implementation should do unaccelerated filtering | 319 | * The default Backend Implementation should do unaccelerated filtering |
320 | * | 320 | * |
321 | * | 321 | * |
322 | * @param ids The Records to sort | 322 | * @param ids The Records to sort |
323 | * @param asc Sort ascending or descending | 323 | * @param asc Sort ascending or descending |
324 | * @param sortOrder | 324 | * @param sortOrder |
325 | * @param sortFilter Sort filter | 325 | * @param sortFilter Sort filter |
326 | * @param cat The Category to include | 326 | * @param cat The Category to include |
327 | */ | 327 | */ |
328 | 328 | ||
329 | /** | 329 | /** |
330 | * \fn template <class T> T OPimAccessBackend<T>::find(UID uid)const | 330 | * \fn template <class T> T OPimAccessBackend<T>::find(UID uid)const |
331 | * \brief Find the Record with the UID | 331 | * \brief Find the Record with the UID |
332 | * | 332 | * |
333 | * Find the UID in the database and return the record. | 333 | * Find the UID in the database and return the record. |
334 | * @param uid The uid to be searched for | 334 | * @param uid The uid to be searched for |
335 | * @return The record or an empty record (T.isEmpty()) | 335 | * @return The record or an empty record (T.isEmpty()) |
336 | * | 336 | * |
337 | */ | 337 | */ |
338 | 338 | ||
339 | /** | 339 | /** |
340 | * \fn template <class T> T OPimAccessBackend<T>::find( UID uid, const QArray<UID>& items, uint current, typename Frontend::CacheDirection d)const | 340 | * \fn template <class T> T OPimAccessBackend<T>::find( UID uid, const QArray<UID>& items, uint current, typename Frontend::CacheDirection d)const |
341 | * \brief find a Record and do a read ahead or read behind | 341 | * \brief find a Record and do a read ahead or read behind |
342 | * | 342 | * |
343 | * @param uid The UID to search for | 343 | * @param uid The UID to search for |
344 | * @param items The list of items from where your search | 344 | * @param items The list of items from where your search |
345 | * @param current The index of \param uid | 345 | * @param current The index of \param uid |
346 | * @param d The direction to search for | 346 | * @param d The direction to search for |
347 | * | 347 | * |
348 | * @see find | 348 | * @see find |
349 | */ | 349 | */ |
350 | 350 | ||
351 | 351 | ||
352 | /** | 352 | /** |
353 | * \fn template<class T> bool OPimAccessBackend<T>::add(const T& t) | 353 | * \fn template<class T> bool OPimAccessBackend<T>::add(const T& t) |
354 | * | 354 | * |
355 | * \brief Add the record to the internal database | 355 | * \brief Add the record to the internal database |
356 | * | 356 | * |
357 | * If an record with the same t.uid() is already present internally | 357 | * If an record with the same t.uid() is already present internally |
358 | * the behaviour is undefined but the state of the database | 358 | * the behaviour is undefined but the state of the database |
359 | * needs to be stable. | 359 | * needs to be stable. |
360 | * For modifying a record use \sa replace. | 360 | * For modifying a record use \sa replace. |
361 | * | 361 | * |
362 | * | 362 | * |
363 | * @return true if the record could be added or false if not | 363 | * @return true if the record could be added or false if not |
364 | * @todo Eilers your opinion on readd/replace | 364 | * @todo Eilers your opinion on readd/replace |
365 | */ | 365 | */ |
366 | 366 | ||
367 | /** | 367 | /** |
368 | * \fn template<class T> bool OPimAccessBackend<T>::remove(UID uid) | 368 | * \fn template<class T> bool OPimAccessBackend<T>::remove(UID uid) |
369 | * \brief Remove a record by its UID | 369 | * \brief Remove a record by its UID |
370 | * | 370 | * |
371 | * Remove the records with UID from the internal Database. | 371 | * Remove the records with UID from the internal Database. |
372 | * | 372 | * |
373 | * @return True if the record could be removed. | 373 | * @return True if the record could be removed. |
374 | * | 374 | * |
375 | */ | 375 | */ |
376 | 376 | ||
377 | /** | 377 | /** |
378 | * \fn template<class T> bool OPimAccessBackend<T>::replace(const T& t) | 378 | * \fn template<class T> bool OPimAccessBackend<T>::replace(const T& t) |
379 | * \brief Take this Record and replace the old version. | 379 | * \brief Take this Record and replace the old version. |
380 | * | 380 | * |
381 | * Take \param t as the new record for t.uid(). It is not described | 381 | * Take \param t as the new record for t.uid(). It is not described |
382 | * what happens if the record is not present in the database. | 382 | * what happens if the record is not present in the database. |
383 | * Normally the record is determined by the UID. | 383 | * Normally the record is determined by the UID. |
384 | * | 384 | * |
385 | * @param t The record to use internally. | 385 | * @param t The record to use internally. |
386 | */ | 386 | */ |
387 | 387 | ||
388 | /** | 388 | /** |
389 | * \fn template<class T> void OPimAccessBackend<T>::setFrontend( Frontend* fron) | 389 | * \fn template<class T> void OPimAccessBackend<T>::setFrontend( Frontend* fron) |
390 | * \@aram fron The Frontend that uses this backend | 390 | * \@aram fron The Frontend that uses this backend |
391 | * | 391 | * |
392 | * This function is called by the frontend and is used | 392 | * This function is called by the frontend and is used |
393 | */ | 393 | */ |
394 | 394 | ||
395 | /** | 395 | /** |
396 | * \fn template<class T> void OPimAccessBackend<T>::setReadAhead(uint count) | 396 | * \fn template<class T> void OPimAccessBackend<T>::setReadAhead(uint count) |
397 | * \brief Set the number of items to Read-Ahead/Read-Behind | 397 | * \brief Set the number of items to Read-Ahead/Read-Behind |
398 | * | 398 | * |
399 | * @param count The number of records to read ahead | 399 | * @param count The number of records to read ahead |
400 | */ | 400 | */ |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * \fn template<class T> void OPimAccessBackend<T>::cache( const T& t)const | 403 | * \fn template<class T> void OPimAccessBackend<T>::cache( const T& t)const |
404 | * \brief Add the Record to the PIM Cache | 404 | * \brief Add the Record to the PIM Cache |
405 | * | 405 | * |
406 | * This will add the Record to the PIM cache, which is owned | 406 | * This will add the Record to the PIM cache, which is owned |
407 | * by the FrontEnd. If no FrontEnd is available the item will | 407 | * by the FrontEnd. If no FrontEnd is available the item will |
408 | * not be cached. | 408 | * not be cached. |
409 | * | 409 | * |
410 | * | 410 | * |
411 | * @param t The Item to be added to the Cache | 411 | * @param t The Item to be added to the Cache |
412 | */ | 412 | */ |
413 | 413 | ||
414 | /** | 414 | /** |
415 | * \fn template<class T> void OPimAccessBackend<T>::setSaneCacheSize(int items) | 415 | * \fn template<class T> void OPimAccessBackend<T>::setSaneCacheSize(int items) |
416 | * \brief Give a hint on the number of too cached items | 416 | * \brief Give a hint on the number of too cached items |
417 | * | 417 | * |
418 | * Give the Frontend a hint on the number of items to be cached. Use | 418 | * Give the Frontend a hint on the number of items to be cached. Use |
419 | * a prime number for best performance. | 419 | * a prime number for best performance. |
420 | * | 420 | * |
421 | * @param items The number of items to be cached | 421 | * @param items The number of items to be cached |
422 | */ | 422 | */ |
423 | 423 | ||
424 | /** | 424 | /** |
425 | * \fn template<class T> uint OPimAccessBackend<T>::readAhead()const | 425 | * \fn template<class T> uint OPimAccessBackend<T>::readAhead()const |
426 | * \brief Return the number of Items to be ReadAhead | 426 | * \brief Return the number of Items to be ReadAhead |
427 | * | 427 | * |
428 | * @return The number of Items to read ahead/read behind | 428 | * @return The number of Items to read ahead/read behind |
429 | */ | 429 | */ |
430 | 430 | ||
431 | /** | 431 | /** |
432 | * \fn template<class T> QArray<OPimBackendOccurence> OPimAccessBackend<T>::occurrences(const QDateTime& start,const QDateTime& end) | 432 | * \fn template<class T> QArray<OPimBackendOccurence> OPimAccessBackend<T>::occurrences(const QDateTime& start,const QDateTime& end) |
433 | * \brief Get a List of Occurrences for a period of time | 433 | * \brief Get a List of Occurrences for a period of time |
434 | * | 434 | * |
435 | * Return an Array of OPimBackendOccurence for a period of time. If start == end date | 435 | * Return an Array of OPimBackendOccurence for a period of time. If start == end date |
436 | * return only occurrences for the start date. If end is smaller the start date | 436 | * return only occurrences for the start date. If end is smaller the start date |
437 | * the result is not defined. You could switch dates or return an empty list. | 437 | * the result is not defined. You could switch dates or return an empty list. |
438 | * | 438 | * |
439 | * @return Return an array of OPimBackendOccurence for the period specified by the parameters | 439 | * @return Return an array of OPimBackendOccurence for the period specified by the parameters |
440 | * @param start The start of the period. | 440 | * @param start The start of the period. |
441 | * @param end The end of the period. | 441 | * @param end The end of the period. |
442 | * | 442 | * |
443 | */ | 443 | */ |
444 | 444 | ||
445 | #endif | 445 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp index 5f86be9..f979976 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.cpp +++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp | |||
@@ -1,155 +1,181 @@ | |||
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 <opie2/otodoaccessbackend.h> | 30 | #include <opie2/otodoaccessbackend.h> |
31 | #include <opie2/private/opimtodosortvector.h> | 31 | #include <opie2/private/opimtodosortvector.h> |
32 | #include <opie2/otodoaccess.h> | 32 | #include <opie2/otodoaccess.h> |
33 | 33 | ||
34 | #include <qintdict.h> | 34 | #include <qintdict.h> |
35 | 35 | ||
36 | namespace Opie { | 36 | namespace Opie { |
37 | OPimTodoAccessBackend::OPimTodoAccessBackend() | 37 | OPimTodoAccessBackend::OPimTodoAccessBackend() |
38 | : OPimAccessBackend<OPimTodo>() | 38 | : OPimAccessBackend<OPimTodo>() |
39 | { | 39 | { |
40 | } | 40 | } |
41 | OPimTodoAccessBackend::~OPimTodoAccessBackend() { | 41 | OPimTodoAccessBackend::~OPimTodoAccessBackend() { |
42 | 42 | ||
43 | } | 43 | } |
44 | 44 | ||
45 | UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings, | 45 | const uint OPimTodoAccessBackend::querySettings() const |
46 | const QDateTime& d)const { | 46 | { |
47 | return UIDArray(); | 47 | return 0; |
48 | } | ||
49 | |||
50 | bool OPimTodoAccessBackend::hasQuerySettings (uint querySettings) const | ||
51 | { | ||
52 | return false; | ||
53 | } | ||
54 | |||
55 | |||
56 | UIDArray OPimTodoAccessBackend::queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, | ||
57 | const QDateTime& endperiod )const | ||
58 | { | ||
59 | qDebug( "Accessing OPimTodoAccessBackend::queryByExample() which is not implemented!" ); | ||
60 | return UIDArray(); | ||
61 | |||
62 | // odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl; | ||
63 | |||
64 | // UIDArray m_currentQuery( uid_array.count() ); | ||
65 | // uint arraycounter = 0; | ||
66 | |||
67 | // for( uint it = 0; it < uid_array.count(); ++it ){ | ||
68 | // /* Search all fields and compare them with query object. Store them into list | ||
69 | // * if all fields matches. | ||
70 | // */ | ||
71 | // } | ||
72 | |||
73 | |||
48 | } | 74 | } |
49 | 75 | ||
50 | UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc, | 76 | UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc, |
51 | int sortOrder, int sortFilter, | 77 | int sortOrder, int sortFilter, |
52 | const QArray<int>& categories )const { | 78 | const QArray<int>& categories )const { |
53 | odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl; | 79 | odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl; |
54 | Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); | 80 | Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); |
55 | int item = 0; | 81 | int item = 0; |
56 | 82 | ||
57 | bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; | 83 | bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; |
58 | bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; | 84 | bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; |
59 | bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; | 85 | bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; |
60 | bool catPassed = false; | 86 | bool catPassed = false; |
61 | int cat; | 87 | int cat; |
62 | 88 | ||
63 | for ( uint i = 0; i < events.count(); ++i ) { | 89 | for ( uint i = 0; i < events.count(); ++i ) { |
64 | OPimTodo todo = find( events[i], events, i, Frontend::Forward ); | 90 | OPimTodo todo = find( events[i], events, i, Frontend::Forward ); |
65 | if ( todo.isEmpty() ) | 91 | if ( todo.isEmpty() ) |
66 | continue; | 92 | continue; |
67 | 93 | ||
68 | /* show category */ | 94 | /* show category */ |
69 | /* -1 == unfiled */ | 95 | /* -1 == unfiled */ |
70 | catPassed = false; | 96 | catPassed = false; |
71 | for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { | 97 | for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { |
72 | cat = categories[cat_nu]; | 98 | cat = categories[cat_nu]; |
73 | if ( bCat && cat == -1 ) { | 99 | if ( bCat && cat == -1 ) { |
74 | if(!todo.categories().isEmpty() ) | 100 | if(!todo.categories().isEmpty() ) |
75 | continue; | 101 | continue; |
76 | } else if ( bCat && cat != 0) | 102 | } else if ( bCat && cat != 0) |
77 | if (!todo.categories().contains( cat ) ) | 103 | if (!todo.categories().contains( cat ) ) |
78 | continue; | 104 | continue; |
79 | catPassed = true; | 105 | catPassed = true; |
80 | break; | 106 | break; |
81 | } | 107 | } |
82 | 108 | ||
83 | /* | 109 | /* |
84 | * If none of the Categories matched | 110 | * If none of the Categories matched |
85 | * continue | 111 | * continue |
86 | */ | 112 | */ |
87 | if ( !catPassed ) | 113 | if ( !catPassed ) |
88 | continue; | 114 | continue; |
89 | if ( !todo.isOverdue() && bOnly ) | 115 | if ( !todo.isOverdue() && bOnly ) |
90 | continue; | 116 | continue; |
91 | if (todo.isCompleted() && comp ) | 117 | if (todo.isCompleted() && comp ) |
92 | continue; | 118 | continue; |
93 | 119 | ||
94 | vector.insert(item++, todo ); | 120 | vector.insert(item++, todo ); |
95 | } | 121 | } |
96 | 122 | ||
97 | vector.resize( item ); | 123 | vector.resize( item ); |
98 | /* sort it now */ | 124 | /* sort it now */ |
99 | vector.sort(); | 125 | vector.sort(); |
100 | /* now get the uids */ | 126 | /* now get the uids */ |
101 | UIDArray array( vector.count() ); | 127 | UIDArray array( vector.count() ); |
102 | for (uint i= 0; i < vector.count(); i++ ) | 128 | for (uint i= 0; i < vector.count(); i++ ) |
103 | array[i] = vector.uidAt( i ); | 129 | array[i] = vector.uidAt( i ); |
104 | 130 | ||
105 | return array; | 131 | return array; |
106 | } | 132 | } |
107 | 133 | ||
108 | OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start, | 134 | OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start, |
109 | const QDate& end )const { | 135 | const QDate& end )const { |
110 | OPimBackendOccurrence::List lst; | 136 | OPimBackendOccurrence::List lst; |
111 | UIDArray effective = effectiveToDos( start, end, false ); | 137 | UIDArray effective = effectiveToDos( start, end, false ); |
112 | UIDArray overdue = overDue(); | 138 | UIDArray overdue = overDue(); |
113 | uint count = effective.count(); | 139 | uint count = effective.count(); |
114 | int uid; | 140 | int uid; |
115 | QIntDict<int> hash; | 141 | QIntDict<int> hash; |
116 | hash.setAutoDelete( true ); | 142 | hash.setAutoDelete( true ); |
117 | OPimTodo todo; | 143 | OPimTodo todo; |
118 | 144 | ||
119 | for ( uint i = 0; i < count; ++i ) { | 145 | for ( uint i = 0; i < count; ++i ) { |
120 | uid = effective[i]; | 146 | uid = effective[i]; |
121 | todo = find( uid, effective, i, Frontend::Forward ); | 147 | todo = find( uid, effective, i, Frontend::Forward ); |
122 | /* | 148 | /* |
123 | * If isOverdue but in the 'normal' range we will fill | 149 | * If isOverdue but in the 'normal' range we will fill |
124 | * the hash so we won't have duplicates in OPimBackendOccurrence | 150 | * the hash so we won't have duplicates in OPimBackendOccurrence |
125 | */ | 151 | */ |
126 | if ( todo.isOverdue() ) | 152 | if ( todo.isOverdue() ) |
127 | hash.insert( uid, new int(6) ); | 153 | hash.insert( uid, new int(6) ); |
128 | OPimBackendOccurrence oc = todo.hasStartDate() ? | 154 | OPimBackendOccurrence oc = todo.hasStartDate() ? |
129 | OPimBackendOccurrence( todo.startDate(), | 155 | OPimBackendOccurrence( todo.startDate(), |
130 | todo.dueDate(), uid ) : | 156 | todo.dueDate(), uid ) : |
131 | OPimBackendOccurrence( todo.dueDate(), uid, QString::null ); | 157 | OPimBackendOccurrence( todo.dueDate(), uid, QString::null ); |
132 | oc.setSummary( todo.summary() ); | 158 | oc.setSummary( todo.summary() ); |
133 | lst.append( oc ); | 159 | lst.append( oc ); |
134 | } | 160 | } |
135 | 161 | ||
136 | /* | 162 | /* |
137 | * Create the OverDue items but skip | 163 | * Create the OverDue items but skip |
138 | * the already handled Records | 164 | * the already handled Records |
139 | */ | 165 | */ |
140 | if ( !overdue.isEmpty() ) { | 166 | if ( !overdue.isEmpty() ) { |
141 | QDate today = QDate::currentDate(); | 167 | QDate today = QDate::currentDate(); |
142 | QDate dueDate = (start >= today && today <= end ) ? today : start; | 168 | QDate dueDate = (start >= today && today <= end ) ? today : start; |
143 | count = overdue.count(); | 169 | count = overdue.count(); |
144 | for ( uint i = 0; i < count; ++i ) { | 170 | for ( uint i = 0; i < count; ++i ) { |
145 | uid = overdue[i]; | 171 | uid = overdue[i]; |
146 | if (!hash.find( uid ) ) | 172 | if (!hash.find( uid ) ) |
147 | continue; | 173 | continue; |
148 | todo = find( uid, overdue, i, Frontend::Forward ); | 174 | todo = find( uid, overdue, i, Frontend::Forward ); |
149 | lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) ); | 175 | lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) ); |
150 | } | 176 | } |
151 | } | 177 | } |
152 | 178 | ||
153 | return lst; | 179 | return lst; |
154 | } | 180 | } |
155 | } | 181 | } |
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h index 66297bb..870ee57 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.h +++ b/libopie2/opiepim/backend/otodoaccessbackend.h | |||
@@ -1,79 +1,92 @@ | |||
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_BACKEND_H | 29 | #ifndef OPIE_TODO_ACCESS_BACKEND_H |
30 | #define OPIE_TODO_ACCESS_BACKEND_H | 30 | #define OPIE_TODO_ACCESS_BACKEND_H |
31 | 31 | ||
32 | #include <qbitarray.h> | 32 | #include <qbitarray.h> |
33 | 33 | ||
34 | #include <opie2/opimtodo.h> | 34 | #include <opie2/opimtodo.h> |
35 | #include <opie2/opimaccessbackend.h> | 35 | #include <opie2/opimaccessbackend.h> |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> { | 38 | class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> { |
39 | public: | 39 | public: |
40 | OPimTodoAccessBackend(); | 40 | OPimTodoAccessBackend(); |
41 | ~OPimTodoAccessBackend(); | 41 | ~OPimTodoAccessBackend(); |
42 | virtual UIDArray effectiveToDos( const QDate& start, | 42 | virtual UIDArray effectiveToDos( const QDate& start, |
43 | const QDate& end, | 43 | const QDate& end, |
44 | bool includeNoDates )const = 0; | 44 | bool includeNoDates )const = 0; |
45 | virtual UIDArray overDue()const = 0; | 45 | virtual UIDArray overDue()const = 0; |
46 | virtual void removeAllCompleted() = 0; | 46 | virtual void removeAllCompleted() = 0; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Common and probably inefficent implementation | 49 | * Common and probably inefficent implementation |
50 | * for queryByExample, matchRegexp, sorted | 50 | * for queryByExample, matchRegexp, sorted |
51 | * and occurrences | 51 | * and occurrences |
52 | */ | 52 | */ |
53 | //@{ | 53 | //@{ |
54 | UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const; | 54 | /** |
55 | * Return all possible settings. | ||
56 | * @return All settings provided by the current backend | ||
57 | * (i.e.: query_WildCards & query_IgnoreCase) | ||
58 | */ | ||
59 | const uint querySettings() const; | ||
60 | |||
61 | /** | ||
62 | * Check whether settings are correct. | ||
63 | * @return <i>true</i> if the given settings are correct and possible. | ||
64 | */ | ||
65 | bool hasQuerySettings (uint querySettings) const; | ||
66 | |||
67 | UIDArray queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, const QDateTime& endperiod = QDateTime() )const; | ||
55 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; | 68 | UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; |
56 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; | 69 | OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; |
57 | //@} | 70 | //@} |
58 | 71 | ||
59 | private: | 72 | private: |
60 | class Private; | 73 | class Private; |
61 | Private *d; | 74 | Private *d; |
62 | 75 | ||
63 | }; | 76 | }; |
64 | } | 77 | } |
65 | 78 | ||
66 | 79 | ||
67 | /** | 80 | /** |
68 | * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const | 81 | * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const |
69 | * \brief Return occurrences for a period of time | 82 | * \brief Return occurrences for a period of time |
70 | * | 83 | * |
71 | * This method will return the 'effective' Todos and also | 84 | * This method will return the 'effective' Todos and also |
72 | * 'Overdue' Todos. Overdues will be shown on the 'current' | 85 | * 'Overdue' Todos. Overdues will be shown on the 'current' |
73 | * day if it is in the range or on \par start. If the overdue | 86 | * day if it is in the range or on \par start. If the overdue |
74 | * is inside the 'Effective Todos' we will skip the | 87 | * is inside the 'Effective Todos' we will skip the |
75 | * special overdue handling. | 88 | * special overdue handling. |
76 | * | 89 | * |
77 | * | 90 | * |
78 | */ | 91 | */ |
79 | #endif | 92 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 2bcab29..70e40e4 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -1,830 +1,840 @@ | |||
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) Holger Freyther (zecke@handhelds.org) | 4 | Copyright (C) Holger Freyther (zecke@handhelds.org) |
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 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/osqldriver.h> | 32 | #include <opie2/osqldriver.h> |
33 | #include <opie2/osqlresult.h> | 33 | #include <opie2/osqlresult.h> |
34 | #include <opie2/osqlmanager.h> | 34 | #include <opie2/osqlmanager.h> |
35 | #include <opie2/osqlquery.h> | 35 | #include <opie2/osqlquery.h> |
36 | 36 | ||
37 | #include <opie2/otodoaccesssql.h> | 37 | #include <opie2/otodoaccesssql.h> |
38 | #include <opie2/opimstate.h> | 38 | #include <opie2/opimstate.h> |
39 | #include <opie2/opimnotifymanager.h> | 39 | #include <opie2/opimnotifymanager.h> |
40 | #include <opie2/opimrecurrence.h> | 40 | #include <opie2/opimrecurrence.h> |
41 | #include <opie2/odebug.h> | 41 | #include <opie2/odebug.h> |
42 | 42 | ||
43 | #include <qpe/global.h> | 43 | #include <qpe/global.h> |
44 | 44 | ||
45 | /* QT */ | 45 | /* QT */ |
46 | #include <qdatetime.h> | 46 | #include <qdatetime.h> |
47 | #include <qmap.h> | 47 | #include <qmap.h> |
48 | #include <qstring.h> | 48 | #include <qstring.h> |
49 | 49 | ||
50 | 50 | ||
51 | using namespace Opie::DB; | 51 | using namespace Opie::DB; |
52 | 52 | ||
53 | using namespace Opie; | 53 | using namespace Opie; |
54 | /* | 54 | /* |
55 | * first some query | 55 | * first some query |
56 | * CREATE query | 56 | * CREATE query |
57 | * LOAD query | 57 | * LOAD query |
58 | * INSERT | 58 | * INSERT |
59 | * REMOVE | 59 | * REMOVE |
60 | * CLEAR | 60 | * CLEAR |
61 | */ | 61 | */ |
62 | namespace { | 62 | namespace { |
63 | /** | 63 | /** |
64 | * CreateQuery for the Todolist Table | 64 | * CreateQuery for the Todolist Table |
65 | */ | 65 | */ |
66 | class CreateQuery : public OSQLQuery { | 66 | class CreateQuery : public OSQLQuery { |
67 | public: | 67 | public: |
68 | CreateQuery(); | 68 | CreateQuery(); |
69 | ~CreateQuery(); | 69 | ~CreateQuery(); |
70 | QString query()const; | 70 | QString query()const; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * LoadQuery | 74 | * LoadQuery |
75 | * this one queries for all uids | 75 | * this one queries for all uids |
76 | */ | 76 | */ |
77 | class LoadQuery : public OSQLQuery { | 77 | class LoadQuery : public OSQLQuery { |
78 | public: | 78 | public: |
79 | LoadQuery(); | 79 | LoadQuery(); |
80 | ~LoadQuery(); | 80 | ~LoadQuery(); |
81 | QString query()const; | 81 | QString query()const; |
82 | }; | 82 | }; |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * inserts/adds a OPimTodo to the table | 85 | * inserts/adds a OPimTodo to the table |
86 | */ | 86 | */ |
87 | class InsertQuery : public OSQLQuery { | 87 | class InsertQuery : public OSQLQuery { |
88 | public: | 88 | public: |
89 | InsertQuery(const OPimTodo& ); | 89 | InsertQuery(const OPimTodo& ); |
90 | ~InsertQuery(); | 90 | ~InsertQuery(); |
91 | QString query()const; | 91 | QString query()const; |
92 | private: | 92 | private: |
93 | OPimTodo m_todo; | 93 | OPimTodo m_todo; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * removes one from the table | 97 | * removes one from the table |
98 | */ | 98 | */ |
99 | class RemoveQuery : public OSQLQuery { | 99 | class RemoveQuery : public OSQLQuery { |
100 | public: | 100 | public: |
101 | RemoveQuery(int uid ); | 101 | RemoveQuery(int uid ); |
102 | ~RemoveQuery(); | 102 | ~RemoveQuery(); |
103 | QString query()const; | 103 | QString query()const; |
104 | private: | 104 | private: |
105 | int m_uid; | 105 | int m_uid; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Clears (delete) a Table | 109 | * Clears (delete) a Table |
110 | */ | 110 | */ |
111 | class ClearQuery : public OSQLQuery { | 111 | class ClearQuery : public OSQLQuery { |
112 | public: | 112 | public: |
113 | ClearQuery(); | 113 | ClearQuery(); |
114 | ~ClearQuery(); | 114 | ~ClearQuery(); |
115 | QString query()const; | 115 | QString query()const; |
116 | 116 | ||
117 | }; | 117 | }; |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * a find query | 120 | * a find query |
121 | */ | 121 | */ |
122 | class FindQuery : public OSQLQuery { | 122 | class FindQuery : public OSQLQuery { |
123 | public: | 123 | public: |
124 | FindQuery(int uid); | 124 | FindQuery(int uid); |
125 | FindQuery(const QArray<int>& ); | 125 | FindQuery(const QArray<int>& ); |
126 | ~FindQuery(); | 126 | ~FindQuery(); |
127 | QString query()const; | 127 | QString query()const; |
128 | private: | 128 | private: |
129 | QString single()const; | 129 | QString single()const; |
130 | QString multi()const; | 130 | QString multi()const; |
131 | QArray<int> m_uids; | 131 | QArray<int> m_uids; |
132 | int m_uid; | 132 | int m_uid; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * overdue query | 136 | * overdue query |
137 | */ | 137 | */ |
138 | class OverDueQuery : public OSQLQuery { | 138 | class OverDueQuery : public OSQLQuery { |
139 | public: | 139 | public: |
140 | OverDueQuery(); | 140 | OverDueQuery(); |
141 | ~OverDueQuery(); | 141 | ~OverDueQuery(); |
142 | QString query()const; | 142 | QString query()const; |
143 | }; | 143 | }; |
144 | class EffQuery : public OSQLQuery { | 144 | class EffQuery : public OSQLQuery { |
145 | public: | 145 | public: |
146 | EffQuery( const QDate&, const QDate&, bool inc ); | 146 | EffQuery( const QDate&, const QDate&, bool inc ); |
147 | ~EffQuery(); | 147 | ~EffQuery(); |
148 | QString query()const; | 148 | QString query()const; |
149 | private: | 149 | private: |
150 | QString with()const; | 150 | QString with()const; |
151 | QString out()const; | 151 | QString out()const; |
152 | QDate m_start; | 152 | QDate m_start; |
153 | QDate m_end; | 153 | QDate m_end; |
154 | bool m_inc :1; | 154 | bool m_inc :1; |
155 | }; | 155 | }; |
156 | 156 | ||
157 | 157 | ||
158 | /** | 158 | /** |
159 | * a find query for custom elements | 159 | * a find query for custom elements |
160 | */ | 160 | */ |
161 | class FindCustomQuery : public OSQLQuery { | 161 | class FindCustomQuery : public OSQLQuery { |
162 | public: | 162 | public: |
163 | FindCustomQuery(int uid); | 163 | FindCustomQuery(int uid); |
164 | FindCustomQuery(const QArray<int>& ); | 164 | FindCustomQuery(const QArray<int>& ); |
165 | ~FindCustomQuery(); | 165 | ~FindCustomQuery(); |
166 | QString query()const; | 166 | QString query()const; |
167 | private: | 167 | private: |
168 | QString single()const; | 168 | QString single()const; |
169 | QString multi()const; | 169 | QString multi()const; |
170 | QArray<int> m_uids; | 170 | QArray<int> m_uids; |
171 | int m_uid; | 171 | int m_uid; |
172 | }; | 172 | }; |
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | CreateQuery::CreateQuery() : OSQLQuery() {} | 176 | CreateQuery::CreateQuery() : OSQLQuery() {} |
177 | CreateQuery::~CreateQuery() {} | 177 | CreateQuery::~CreateQuery() {} |
178 | QString CreateQuery::query()const { | 178 | QString CreateQuery::query()const { |
179 | QString qu; | 179 | QString qu; |
180 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 180 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
181 | qu += "description, summary, priority, DueDate, progress , state, "; | 181 | qu += "description, summary, priority, DueDate, progress , state, "; |
182 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) | 182 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
183 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 183 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
184 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 184 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
186 | return qu; | 186 | return qu; |
187 | } | 187 | } |
188 | 188 | ||
189 | LoadQuery::LoadQuery() : OSQLQuery() {} | 189 | LoadQuery::LoadQuery() : OSQLQuery() {} |
190 | LoadQuery::~LoadQuery() {} | 190 | LoadQuery::~LoadQuery() {} |
191 | QString LoadQuery::query()const { | 191 | QString LoadQuery::query()const { |
192 | QString qu; | 192 | QString qu; |
193 | // We do not need "distinct" here. The primary key is always unique.. | 193 | // We do not need "distinct" here. The primary key is always unique.. |
194 | //qu += "select distinct uid from todolist"; | 194 | //qu += "select distinct uid from todolist"; |
195 | qu += "select uid from todolist"; | 195 | qu += "select uid from todolist"; |
196 | 196 | ||
197 | return qu; | 197 | return qu; |
198 | } | 198 | } |
199 | 199 | ||
200 | InsertQuery::InsertQuery( const OPimTodo& todo ) | 200 | InsertQuery::InsertQuery( const OPimTodo& todo ) |
201 | : OSQLQuery(), m_todo( todo ) { | 201 | : OSQLQuery(), m_todo( todo ) { |
202 | } | 202 | } |
203 | InsertQuery::~InsertQuery() { | 203 | InsertQuery::~InsertQuery() { |
204 | } | 204 | } |
205 | /* | 205 | /* |
206 | * converts from a OPimTodo to a query | 206 | * converts from a OPimTodo to a query |
207 | * we leave out X-Ref + Maintainer | 207 | * we leave out X-Ref + Maintainer |
208 | * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding | 208 | * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding |
209 | * decoding stuff there.. (eilers) | 209 | * decoding stuff there.. (eilers) |
210 | */ | 210 | */ |
211 | QString InsertQuery::query()const{ | 211 | QString InsertQuery::query()const{ |
212 | 212 | ||
213 | int year, month, day; | 213 | int year, month, day; |
214 | year = month = day = 0; | 214 | year = month = day = 0; |
215 | if (m_todo.hasDueDate() ) { | 215 | if (m_todo.hasDueDate() ) { |
216 | QDate date = m_todo.dueDate(); | 216 | QDate date = m_todo.dueDate(); |
217 | year = date.year(); | 217 | year = date.year(); |
218 | month = date.month(); | 218 | month = date.month(); |
219 | day = date.day(); | 219 | day = date.day(); |
220 | } | 220 | } |
221 | int sYear = 0, sMonth = 0, sDay = 0; | 221 | int sYear = 0, sMonth = 0, sDay = 0; |
222 | if( m_todo.hasStartDate() ){ | 222 | if( m_todo.hasStartDate() ){ |
223 | QDate sDate = m_todo.startDate(); | 223 | QDate sDate = m_todo.startDate(); |
224 | sYear = sDate.year(); | 224 | sYear = sDate.year(); |
225 | sMonth= sDate.month(); | 225 | sMonth= sDate.month(); |
226 | sDay = sDate.day(); | 226 | sDay = sDate.day(); |
227 | } | 227 | } |
228 | 228 | ||
229 | int eYear = 0, eMonth = 0, eDay = 0; | 229 | int eYear = 0, eMonth = 0, eDay = 0; |
230 | if( m_todo.hasCompletedDate() ){ | 230 | if( m_todo.hasCompletedDate() ){ |
231 | QDate eDate = m_todo.completedDate(); | 231 | QDate eDate = m_todo.completedDate(); |
232 | eYear = eDate.year(); | 232 | eYear = eDate.year(); |
233 | eMonth= eDate.month(); | 233 | eMonth= eDate.month(); |
234 | eDay = eDate.day(); | 234 | eDay = eDate.day(); |
235 | } | 235 | } |
236 | QString qu; | 236 | QString qu; |
237 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); | 237 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); |
238 | qu = "insert into todolist VALUES(" | 238 | qu = "insert into todolist VALUES(" |
239 | + QString::number( m_todo.uid() ) + "," | 239 | + QString::number( m_todo.uid() ) + "," |
240 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 240 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
241 | + QString::number( m_todo.isCompleted() ) + "," | 241 | + QString::number( m_todo.isCompleted() ) + "," |
242 | + "'" + m_todo.description() + "'" + "," | 242 | + "'" + m_todo.description() + "'" + "," |
243 | + "'" + m_todo.summary() + "'" + "," | 243 | + "'" + m_todo.summary() + "'" + "," |
244 | + QString::number(m_todo.priority() ) + "," | 244 | + QString::number(m_todo.priority() ) + "," |
245 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" | 245 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" |
246 | + QString::number(month).rightJustify( 2, '0' ) | 246 | + QString::number(month).rightJustify( 2, '0' ) |
247 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," | 247 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," |
248 | + QString::number( m_todo.progress() ) + "," | 248 | + QString::number( m_todo.progress() ) + "," |
249 | + QString::number( m_todo.state().state() ) + "," | 249 | + QString::number( m_todo.state().state() ) + "," |
250 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," | 250 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
251 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," | 251 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
252 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," | 252 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
253 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," | 253 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
254 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," | 254 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," |
255 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," | 255 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," |
256 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," | 256 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," |
257 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; | 257 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; |
258 | 258 | ||
259 | if ( m_todo.hasNotifiers() ) { | 259 | if ( m_todo.hasNotifiers() ) { |
260 | OPimNotifyManager manager = m_todo.notifiers(); | 260 | OPimNotifyManager manager = m_todo.notifiers(); |
261 | qu += "'" + manager.remindersToString() + "'" + "," | 261 | qu += "'" + manager.remindersToString() + "'" + "," |
262 | + "'" + manager.alarmsToString() + "'" + ","; | 262 | + "'" + manager.alarmsToString() + "'" + ","; |
263 | } | 263 | } |
264 | else{ | 264 | else{ |
265 | qu += QString( "''" ) + "," | 265 | qu += QString( "''" ) + "," |
266 | + "''" + ","; | 266 | + "''" + ","; |
267 | } | 267 | } |
268 | 268 | ||
269 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 269 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
270 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" | 270 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" |
271 | + QString::number(sMonth).rightJustify( 2, '0' ) | 271 | + QString::number(sMonth).rightJustify( 2, '0' ) |
272 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," | 272 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," |
273 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" | 273 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" |
274 | + QString::number(eMonth).rightJustify( 2, '0' ) | 274 | + QString::number(eMonth).rightJustify( 2, '0' ) |
275 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" | 275 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" |
276 | + "); "; | 276 | + "); "; |
277 | 277 | ||
278 | // Save custom Entries: | 278 | // Save custom Entries: |
279 | int id = 0; | 279 | int id = 0; |
280 | id = 0; | 280 | id = 0; |
281 | QMap<QString, QString> customMap = m_todo.toExtraMap(); | 281 | QMap<QString, QString> customMap = m_todo.toExtraMap(); |
282 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 282 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
283 | it != customMap.end(); ++it ){ | 283 | it != customMap.end(); ++it ){ |
284 | qu += "insert into custom_data VALUES(" | 284 | qu += "insert into custom_data VALUES(" |
285 | + QString::number( m_todo.uid() ) | 285 | + QString::number( m_todo.uid() ) |
286 | + "," | 286 | + "," |
287 | + QString::number( id++ ) | 287 | + QString::number( id++ ) |
288 | + ",'" | 288 | + ",'" |
289 | + it.key() | 289 | + it.key() |
290 | + "'," | 290 | + "'," |
291 | + "0" // Priority for future enhancements | 291 | + "0" // Priority for future enhancements |
292 | + ",'" | 292 | + ",'" |
293 | + it.data() | 293 | + it.data() |
294 | + "');"; | 294 | + "');"; |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | odebug << "add " << qu << "" << oendl; | 298 | odebug << "add " << qu << "" << oendl; |
299 | return qu; | 299 | return qu; |
300 | } | 300 | } |
301 | 301 | ||
302 | RemoveQuery::RemoveQuery(int uid ) | 302 | RemoveQuery::RemoveQuery(int uid ) |
303 | : OSQLQuery(), m_uid( uid ) {} | 303 | : OSQLQuery(), m_uid( uid ) {} |
304 | |||
304 | RemoveQuery::~RemoveQuery() {} | 305 | RemoveQuery::~RemoveQuery() {} |
306 | |||
305 | QString RemoveQuery::query()const { | 307 | QString RemoveQuery::query()const { |
306 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; | 308 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; |
307 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); | 309 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); |
308 | return qu; | 310 | return qu; |
309 | } | 311 | } |
310 | 312 | ||
311 | 313 | ||
312 | ClearQuery::ClearQuery() | 314 | ClearQuery::ClearQuery() |
313 | : OSQLQuery() {} | 315 | : OSQLQuery() {} |
314 | ClearQuery::~ClearQuery() {} | 316 | ClearQuery::~ClearQuery() {} |
315 | QString ClearQuery::query()const { | 317 | QString ClearQuery::query()const |
316 | QString qu = "drop table todolist"; | 318 | { |
317 | return qu; | 319 | QString qu = "drop table todolist"; |
320 | return qu; | ||
318 | } | 321 | } |
322 | |||
319 | FindQuery::FindQuery(int uid) | 323 | FindQuery::FindQuery(int uid) |
320 | : OSQLQuery(), m_uid(uid ) { | 324 | : OSQLQuery(), m_uid(uid ) |
325 | { | ||
321 | } | 326 | } |
327 | |||
322 | FindQuery::FindQuery(const QArray<int>& ints) | 328 | FindQuery::FindQuery(const QArray<int>& ints) |
323 | : OSQLQuery(), m_uids(ints){ | 329 | : OSQLQuery(), m_uids(ints) |
330 | { | ||
324 | } | 331 | } |
325 | FindQuery::~FindQuery() { | 332 | |
333 | FindQuery::~FindQuery() | ||
334 | { | ||
326 | } | 335 | } |
336 | |||
327 | QString FindQuery::query()const{ | 337 | QString FindQuery::query()const{ |
328 | if (m_uids.count() == 0 ) | 338 | if (m_uids.count() == 0 ) |
329 | return single(); | 339 | return single(); |
330 | else | 340 | else |
331 | return multi(); | 341 | return multi(); |
332 | } | 342 | } |
333 | QString FindQuery::single()const{ | 343 | QString FindQuery::single()const{ |
334 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); | 344 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); |
335 | return qu; | 345 | return qu; |
336 | } | 346 | } |
337 | QString FindQuery::multi()const { | 347 | QString FindQuery::multi()const { |
338 | QString qu = "select * from todolist where "; | 348 | QString qu = "select * from todolist where "; |
339 | for (uint i = 0; i < m_uids.count(); i++ ) { | 349 | for (uint i = 0; i < m_uids.count(); i++ ) { |
340 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 350 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
341 | } | 351 | } |
342 | qu.remove( qu.length()-2, 2 ); | 352 | qu.remove( qu.length()-2, 2 ); |
343 | return qu; | 353 | return qu; |
344 | } | 354 | } |
345 | 355 | ||
346 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 356 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
347 | OverDueQuery::~OverDueQuery() {} | 357 | OverDueQuery::~OverDueQuery() {} |
348 | QString OverDueQuery::query()const { | 358 | QString OverDueQuery::query()const { |
349 | QDate date = QDate::currentDate(); | 359 | QDate date = QDate::currentDate(); |
350 | QString str; | 360 | QString str; |
351 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") | 361 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") |
352 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 362 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
353 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 363 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
354 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); | 364 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); |
355 | 365 | ||
356 | return str; | 366 | return str; |
357 | } | 367 | } |
358 | 368 | ||
359 | 369 | ||
360 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 370 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
361 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 371 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
362 | EffQuery::~EffQuery() {} | 372 | EffQuery::~EffQuery() {} |
363 | QString EffQuery::query()const { | 373 | QString EffQuery::query()const { |
364 | return m_inc ? with() : out(); | 374 | return m_inc ? with() : out(); |
365 | } | 375 | } |
366 | QString EffQuery::with()const { | 376 | QString EffQuery::with()const { |
367 | QString str; | 377 | QString str; |
368 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 378 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
369 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 379 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
370 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 380 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
371 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 381 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
372 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 382 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
373 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 383 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
374 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 384 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
375 | return str; | 385 | return str; |
376 | } | 386 | } |
377 | QString EffQuery::out()const { | 387 | QString EffQuery::out()const { |
378 | QString str; | 388 | QString str; |
379 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 389 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
380 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 390 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
381 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 391 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
382 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 392 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
383 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 393 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
384 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 394 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
385 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 395 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
386 | 396 | ||
387 | return str; | 397 | return str; |
388 | } | 398 | } |
389 | 399 | ||
390 | FindCustomQuery::FindCustomQuery(int uid) | 400 | FindCustomQuery::FindCustomQuery(int uid) |
391 | : OSQLQuery(), m_uid( uid ) { | 401 | : OSQLQuery(), m_uid( uid ) { |
392 | } | 402 | } |
393 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 403 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
394 | : OSQLQuery(), m_uids( ints ){ | 404 | : OSQLQuery(), m_uids( ints ){ |
395 | } | 405 | } |
396 | FindCustomQuery::~FindCustomQuery() { | 406 | FindCustomQuery::~FindCustomQuery() { |
397 | } | 407 | } |
398 | QString FindCustomQuery::query()const{ | 408 | QString FindCustomQuery::query()const{ |
399 | return single(); // Multiple requests not supported ! | 409 | return single(); // Multiple requests not supported ! |
400 | } | 410 | } |
401 | QString FindCustomQuery::single()const{ | 411 | QString FindCustomQuery::single()const{ |
402 | QString qu = "select uid, type, value from custom_data where uid = "; | 412 | QString qu = "select uid, type, value from custom_data where uid = "; |
403 | qu += QString::number(m_uid); | 413 | qu += QString::number(m_uid); |
404 | return qu; | 414 | return qu; |
405 | } | 415 | } |
406 | 416 | ||
407 | }; | 417 | }; |
408 | 418 | ||
409 | 419 | ||
410 | namespace Opie { | 420 | namespace Opie { |
411 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) | 421 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) |
412 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) | 422 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) |
413 | { | 423 | { |
414 | QString fi = file; | 424 | QString fi = file; |
415 | if ( fi.isEmpty() ) | 425 | if ( fi.isEmpty() ) |
416 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 426 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
417 | OSQLManager man; | 427 | OSQLManager man; |
418 | m_driver = man.standard(); | 428 | m_driver = man.standard(); |
419 | m_driver->setUrl(fi); | 429 | m_driver->setUrl(fi); |
420 | // fillDict(); | 430 | // fillDict(); |
421 | } | 431 | } |
422 | 432 | ||
423 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ | 433 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ |
424 | if( m_driver ) | 434 | if( m_driver ) |
425 | delete m_driver; | 435 | delete m_driver; |
426 | } | 436 | } |
427 | 437 | ||
428 | bool OPimTodoAccessBackendSQL::load(){ | 438 | bool OPimTodoAccessBackendSQL::load(){ |
429 | if (!m_driver->open() ) | 439 | if (!m_driver->open() ) |
430 | return false; | 440 | return false; |
431 | 441 | ||
432 | CreateQuery creat; | 442 | CreateQuery creat; |
433 | OSQLResult res = m_driver->query(&creat ); | 443 | OSQLResult res = m_driver->query(&creat ); |
434 | 444 | ||
435 | m_dirty = true; | 445 | m_dirty = true; |
436 | return true; | 446 | return true; |
437 | } | 447 | } |
438 | bool OPimTodoAccessBackendSQL::reload(){ | 448 | bool OPimTodoAccessBackendSQL::reload(){ |
439 | return load(); | 449 | return load(); |
440 | } | 450 | } |
441 | 451 | ||
442 | bool OPimTodoAccessBackendSQL::save(){ | 452 | bool OPimTodoAccessBackendSQL::save(){ |
443 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 453 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
444 | } | 454 | } |
445 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { | 455 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { |
446 | if (m_dirty ) | 456 | if (m_dirty ) |
447 | update(); | 457 | update(); |
448 | 458 | ||
449 | return m_uids; | 459 | return m_uids; |
450 | } | 460 | } |
451 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ | 461 | // QArray<int> OPimTodoAccessBackendSQL::queryByExample( const UIDArray& uidlist, const OPimTodo& , int, const QDateTime& ){ |
452 | QArray<int> ints(0); | 462 | // QArray<int> ints(0); |
453 | return ints; | 463 | // return ints; |
454 | } | 464 | // } |
455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | 465 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ |
456 | FindQuery query( uid ); | 466 | FindQuery query( uid ); |
457 | return parseResultAndCache( uid, m_driver->query(&query) ); | 467 | return parseResultAndCache( uid, m_driver->query(&query) ); |
458 | } | 468 | } |
459 | 469 | ||
460 | // Remember: uid is already in the list of uids, called ints ! | 470 | // Remember: uid is already in the list of uids, called ints ! |
461 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 471 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
462 | uint cur, Frontend::CacheDirection dir ) const{ | 472 | uint cur, Frontend::CacheDirection dir ) const{ |
463 | uint CACHE = readAhead(); | 473 | uint CACHE = readAhead(); |
464 | odebug << "searching for " << uid << "" << oendl; | 474 | odebug << "searching for " << uid << "" << oendl; |
465 | QArray<int> search( CACHE ); | 475 | QArray<int> search( CACHE ); |
466 | uint size =0; | 476 | uint size =0; |
467 | 477 | ||
468 | // we try to cache CACHE items | 478 | // we try to cache CACHE items |
469 | switch( dir ) { | 479 | switch( dir ) { |
470 | /* forward */ | 480 | /* forward */ |
471 | case Frontend::Forward: | 481 | case Frontend::Forward: |
472 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 482 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
473 | search[size] = ints[i]; | 483 | search[size] = ints[i]; |
474 | size++; | 484 | size++; |
475 | } | 485 | } |
476 | break; | 486 | break; |
477 | /* reverse */ | 487 | /* reverse */ |
478 | case Frontend::Reverse: | 488 | case Frontend::Reverse: |
479 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 489 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
480 | search[size] = ints[i]; | 490 | search[size] = ints[i]; |
481 | size++; | 491 | size++; |
482 | } | 492 | } |
483 | break; | 493 | break; |
484 | } | 494 | } |
485 | 495 | ||
486 | search.resize( size ); | 496 | search.resize( size ); |
487 | FindQuery query( search ); | 497 | FindQuery query( search ); |
488 | OSQLResult res = m_driver->query( &query ); | 498 | OSQLResult res = m_driver->query( &query ); |
489 | if ( res.state() != OSQLResult::Success ) | 499 | if ( res.state() != OSQLResult::Success ) |
490 | return OPimTodo(); | 500 | return OPimTodo(); |
491 | 501 | ||
492 | return parseResultAndCache( uid, res ); | 502 | return parseResultAndCache( uid, res ); |
493 | } | 503 | } |
494 | 504 | ||
495 | void OPimTodoAccessBackendSQL::clear() { | 505 | void OPimTodoAccessBackendSQL::clear() { |
496 | ClearQuery cle; | 506 | ClearQuery cle; |
497 | OSQLResult res = m_driver->query( &cle ); | 507 | OSQLResult res = m_driver->query( &cle ); |
498 | CreateQuery qu; | 508 | CreateQuery qu; |
499 | res = m_driver->query(&qu); | 509 | res = m_driver->query(&qu); |
500 | } | 510 | } |
501 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { | 511 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
502 | InsertQuery ins( t ); | 512 | InsertQuery ins( t ); |
503 | OSQLResult res = m_driver->query( &ins ); | 513 | OSQLResult res = m_driver->query( &ins ); |
504 | 514 | ||
505 | if ( res.state() == OSQLResult::Failure ) | 515 | if ( res.state() == OSQLResult::Failure ) |
506 | return false; | 516 | return false; |
507 | 517 | ||
508 | int c = m_uids.count(); | 518 | int c = m_uids.count(); |
509 | m_uids.resize( c+1 ); | 519 | m_uids.resize( c+1 ); |
510 | m_uids[c] = t.uid(); | 520 | m_uids[c] = t.uid(); |
511 | 521 | ||
512 | return true; | 522 | return true; |
513 | } | 523 | } |
514 | bool OPimTodoAccessBackendSQL::remove( int uid ) { | 524 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
515 | RemoveQuery rem( uid ); | 525 | RemoveQuery rem( uid ); |
516 | OSQLResult res = m_driver->query(&rem ); | 526 | OSQLResult res = m_driver->query(&rem ); |
517 | 527 | ||
518 | if ( res.state() == OSQLResult::Failure ) | 528 | if ( res.state() == OSQLResult::Failure ) |
519 | return false; | 529 | return false; |
520 | 530 | ||
521 | m_dirty = true; | 531 | m_dirty = true; |
522 | return true; | 532 | return true; |
523 | } | 533 | } |
524 | /* | 534 | /* |
525 | * FIXME better set query | 535 | * FIXME better set query |
526 | * but we need the cache for that | 536 | * but we need the cache for that |
527 | * now we remove | 537 | * now we remove |
528 | */ | 538 | */ |
529 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { | 539 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { |
530 | remove( t.uid() ); | 540 | remove( t.uid() ); |
531 | bool b= add(t); | 541 | bool b= add(t); |
532 | m_dirty = false; // we changed some stuff but the UID stayed the same | 542 | m_dirty = false; // we changed some stuff but the UID stayed the same |
533 | return b; | 543 | return b; |
534 | } | 544 | } |
535 | QArray<int> OPimTodoAccessBackendSQL::overDue()const { | 545 | QArray<int> OPimTodoAccessBackendSQL::overDue()const { |
536 | OverDueQuery qu; | 546 | OverDueQuery qu; |
537 | return uids( m_driver->query(&qu ) ); | 547 | return uids( m_driver->query(&qu ) ); |
538 | } | 548 | } |
539 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 549 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
540 | const QDate& t, | 550 | const QDate& t, |
541 | bool u)const { | 551 | bool u)const { |
542 | EffQuery ef(s, t, u ); | 552 | EffQuery ef(s, t, u ); |
543 | return uids (m_driver->query(&ef) ); | 553 | return uids (m_driver->query(&ef) ); |
544 | } | 554 | } |
545 | 555 | ||
546 | #if 0 | 556 | #if 0 |
547 | /* | 557 | /* |
548 | * | 558 | * |
549 | */ | 559 | */ |
550 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 560 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
551 | int sortFilter, int cat ) { | 561 | int sortFilter, int cat ) { |
552 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; | 562 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; |
553 | QString query; | 563 | QString query; |
554 | query = "select uid from todolist WHERE "; | 564 | query = "select uid from todolist WHERE "; |
555 | 565 | ||
556 | /* | 566 | /* |
557 | * Sort Filter stuff | 567 | * Sort Filter stuff |
558 | * not that straight forward | 568 | * not that straight forward |
559 | * FIXME: Replace magic numbers | 569 | * FIXME: Replace magic numbers |
560 | * | 570 | * |
561 | */ | 571 | */ |
562 | /* Category */ | 572 | /* Category */ |
563 | if ( sortFilter & OPimTodoAccess::FilterCategory ) { | 573 | if ( sortFilter & OPimTodoAccess::FilterCategory ) { |
564 | QString str; | 574 | QString str; |
565 | if (cat != 0 ) str = QString::number( cat ); | 575 | if (cat != 0 ) str = QString::number( cat ); |
566 | query += " categories like '%" +str+"%' AND"; | 576 | query += " categories like '%" +str+"%' AND"; |
567 | } | 577 | } |
568 | /* Show only overdue */ | 578 | /* Show only overdue */ |
569 | if ( sortFilter & OPimTodoAccess::OnlyOverDue ) { | 579 | if ( sortFilter & OPimTodoAccess::OnlyOverDue ) { |
570 | QDate date = QDate::currentDate(); | 580 | QDate date = QDate::currentDate(); |
571 | QString due; | 581 | QString due; |
572 | QString base; | 582 | QString base; |
573 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") | 583 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") |
574 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 584 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
575 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 585 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
576 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); | 586 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); |
577 | query += " " + base + " AND"; | 587 | query += " " + base + " AND"; |
578 | } | 588 | } |
579 | /* not show completed */ | 589 | /* not show completed */ |
580 | if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) { | 590 | if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) { |
581 | query += " completed = 0 AND"; | 591 | query += " completed = 0 AND"; |
582 | }else{ | 592 | }else{ |
583 | query += " ( completed = 1 OR completed = 0) AND"; | 593 | query += " ( completed = 1 OR completed = 0) AND"; |
584 | } | 594 | } |
585 | /* strip the end */ | 595 | /* strip the end */ |
586 | query = query.remove( query.length()-3, 3 ); | 596 | query = query.remove( query.length()-3, 3 ); |
587 | 597 | ||
588 | 598 | ||
589 | /* | 599 | /* |
590 | * sort order stuff | 600 | * sort order stuff |
591 | * quite straight forward | 601 | * quite straight forward |
592 | */ | 602 | */ |
593 | query += "ORDER BY "; | 603 | query += "ORDER BY "; |
594 | switch( sortOrder ) { | 604 | switch( sortOrder ) { |
595 | /* completed */ | 605 | /* completed */ |
596 | case OPimTodoAccess::Completed: | 606 | case OPimTodoAccess::Completed: |
597 | query += "completed"; | 607 | query += "completed"; |
598 | break; | 608 | break; |
599 | case OPimTodoAccess::Priority: | 609 | case OPimTodoAccess::Priority: |
600 | query += "priority"; | 610 | query += "priority"; |
601 | break; | 611 | break; |
602 | case OPimTodoAccess::SortSummary: | 612 | case OPimTodoAccess::SortSummary: |
603 | query += "summary"; | 613 | query += "summary"; |
604 | break; | 614 | break; |
605 | case OPimTodoAccess::Deadline: | 615 | case OPimTodoAccess::Deadline: |
606 | query += "DueDate"; | 616 | query += "DueDate"; |
607 | break; | 617 | break; |
608 | } | 618 | } |
609 | 619 | ||
610 | if ( !asc ) | 620 | if ( !asc ) |
611 | query += " DESC"; | 621 | query += " DESC"; |
612 | 622 | ||
613 | 623 | ||
614 | odebug << query << oendl; | 624 | odebug << query << oendl; |
615 | OSQLRawQuery raw(query ); | 625 | OSQLRawQuery raw(query ); |
616 | return uids( m_driver->query(&raw) ); | 626 | return uids( m_driver->query(&raw) ); |
617 | } | 627 | } |
618 | #endif | 628 | #endif |
619 | 629 | ||
620 | 630 | ||
621 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 631 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
622 | if ( str == "0-0-0" ) | 632 | if ( str == "0000-00-00" ) |
623 | return false; | 633 | return false; |
624 | else{ | 634 | else{ |
625 | int day, year, month; | 635 | int day, year, month; |
626 | QStringList list = QStringList::split("-", str ); | 636 | QStringList list = QStringList::split("-", str ); |
627 | year = list[0].toInt(); | 637 | year = list[0].toInt(); |
628 | month = list[1].toInt(); | 638 | month = list[1].toInt(); |
629 | day = list[2].toInt(); | 639 | day = list[2].toInt(); |
630 | da.setYMD( year, month, day ); | 640 | da.setYMD( year, month, day ); |
631 | return true; | 641 | return true; |
632 | } | 642 | } |
633 | } | 643 | } |
634 | 644 | ||
635 | 645 | ||
636 | OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ | 646 | OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ |
637 | if ( res.state() == OSQLResult::Failure ) { | 647 | if ( res.state() == OSQLResult::Failure ) { |
638 | OPimTodo to; | 648 | OPimTodo to; |
639 | return to; | 649 | return to; |
640 | } | 650 | } |
641 | 651 | ||
642 | OPimTodo retTodo; | 652 | OPimTodo retTodo; |
643 | 653 | ||
644 | OSQLResultItem::ValueList list = res.results(); | 654 | OSQLResultItem::ValueList list = res.results(); |
645 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 655 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
646 | OPimTodo to, tmp; | 656 | OPimTodo to, tmp; |
647 | 657 | ||
648 | for ( ; it != list.end(); ++it ) { | 658 | for ( ; it != list.end(); ++it ) { |
649 | OPimTodo newTodo = parse( (*it) ); | 659 | OPimTodo newTodo = parse( (*it) ); |
650 | cache( newTodo ); | 660 | cache( newTodo ); |
651 | if ( newTodo.uid() == uid ) | 661 | if ( newTodo.uid() == uid ) |
652 | retTodo = newTodo; | 662 | retTodo = newTodo; |
653 | } | 663 | } |
654 | return retTodo; | 664 | return retTodo; |
655 | } | 665 | } |
656 | OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const { | 666 | OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const { |
657 | 667 | ||
658 | // Request information from addressbook table and create the OPimTodo-object. | 668 | // Request information from addressbook table and create the OPimTodo-object. |
659 | 669 | ||
660 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 670 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
661 | hasDueDate = date( dueDate, item.data("DueDate") ); | 671 | hasDueDate = date( dueDate, item.data("DueDate") ); |
662 | QStringList cats = QStringList::split(";", item.data("categories") ); | 672 | QStringList cats = QStringList::split(";", item.data("categories") ); |
663 | 673 | ||
664 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 674 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
665 | cats, item.data("summary"), item.data("description"), | 675 | cats, item.data("summary"), item.data("description"), |
666 | item.data("progress").toUShort(), hasDueDate, dueDate, | 676 | item.data("progress").toUShort(), hasDueDate, dueDate, |
667 | item.data("uid").toInt() ); | 677 | item.data("uid").toInt() ); |
668 | 678 | ||
669 | bool isOk; | 679 | bool isOk; |
670 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 680 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
671 | if ( isOk ) | 681 | if ( isOk ) |
672 | to.setPriority( prioInt ); | 682 | to.setPriority( prioInt ); |
673 | 683 | ||
674 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 684 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
675 | hasStartDate = date( startDate, item.data("startdate") ); | 685 | hasStartDate = date( startDate, item.data("startdate") ); |
676 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); | 686 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); |
677 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | 687 | hasCompletedDate = date( completedDate, item.data("completeddate") ); |
678 | 688 | ||
679 | if ( hasStartDate ) | 689 | if ( hasStartDate ) |
680 | to.setStartDate( startDate ); | 690 | to.setStartDate( startDate ); |
681 | if ( hasCompletedDate ) | 691 | if ( hasCompletedDate ) |
682 | to.setCompletedDate( completedDate ); | 692 | to.setCompletedDate( completedDate ); |
683 | 693 | ||
684 | OPimNotifyManager& manager = to.notifiers(); | 694 | OPimNotifyManager& manager = to.notifiers(); |
685 | manager.alarmsFromString( item.data("alarms") ); | 695 | manager.alarmsFromString( item.data("alarms") ); |
686 | manager.remindersFromString( item.data("reminders") ); | 696 | manager.remindersFromString( item.data("reminders") ); |
687 | 697 | ||
688 | OPimState pimState; | 698 | OPimState pimState; |
689 | pimState.setState( QString( item.data("state") ).toInt() ); | 699 | pimState.setState( QString( item.data("state") ).toInt() ); |
690 | to.setState( pimState ); | 700 | to.setState( pimState ); |
691 | 701 | ||
692 | QMap<int, QString> recMap; | 702 | QMap<int, QString> recMap; |
693 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); | 703 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); |
694 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); | 704 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); |
695 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); | 705 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); |
696 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); | 706 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); |
697 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); | 707 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); |
698 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); | 708 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); |
699 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); | 709 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); |
700 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); | 710 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
701 | 711 | ||
702 | OPimRecurrence recur; | 712 | OPimRecurrence recur; |
703 | recur.fromMap( recMap ); | 713 | recur.fromMap( recMap ); |
704 | to.setRecurrence( recur ); | 714 | to.setRecurrence( recur ); |
705 | 715 | ||
706 | // Finally load the custom-entries for this UID and put it into the created object | 716 | // Finally load the custom-entries for this UID and put it into the created object |
707 | to.setExtraMap( requestCustom( to.uid() ) ); | 717 | to.setExtraMap( requestCustom( to.uid() ) ); |
708 | 718 | ||
709 | return to; | 719 | return to; |
710 | } | 720 | } |
711 | 721 | ||
712 | // FIXME: Where is the difference to "find" ? (eilers) | 722 | // FIXME: Where is the difference to "find" ? (eilers) |
713 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 723 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
714 | FindQuery find( uid ); | 724 | FindQuery find( uid ); |
715 | return parseResultAndCache( uid, m_driver->query(&find) ); | 725 | return parseResultAndCache( uid, m_driver->query(&find) ); |
716 | } | 726 | } |
717 | 727 | ||
718 | 728 | ||
719 | /* | 729 | /* |
720 | * need to be const so let's fool the | 730 | * need to be const so let's fool the |
721 | * compiler :( | 731 | * compiler :( |
722 | */ | 732 | */ |
723 | void OPimTodoAccessBackendSQL::update()const { | 733 | void OPimTodoAccessBackendSQL::update()const { |
724 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; | 734 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; |
725 | LoadQuery lo; | 735 | LoadQuery lo; |
726 | OSQLResult res = m_driver->query(&lo); | 736 | OSQLResult res = m_driver->query(&lo); |
727 | if ( res.state() != OSQLResult::Success ) | 737 | if ( res.state() != OSQLResult::Success ) |
728 | return; | 738 | return; |
729 | 739 | ||
730 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 740 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
731 | } | 741 | } |
732 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 742 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
733 | 743 | ||
734 | OSQLResultItem::ValueList list = res.results(); | 744 | OSQLResultItem::ValueList list = res.results(); |
735 | OSQLResultItem::ValueList::Iterator it; | 745 | OSQLResultItem::ValueList::Iterator it; |
736 | QArray<int> ints(list.count() ); | 746 | QArray<int> ints(list.count() ); |
737 | 747 | ||
738 | int i = 0; | 748 | int i = 0; |
739 | for (it = list.begin(); it != list.end(); ++it ) { | 749 | for (it = list.begin(); it != list.end(); ++it ) { |
740 | ints[i] = (*it).data("uid").toInt(); | 750 | ints[i] = (*it).data("uid").toInt(); |
741 | i++; | 751 | i++; |
742 | } | 752 | } |
743 | return ints; | 753 | return ints; |
744 | } | 754 | } |
745 | 755 | ||
746 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 756 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const |
747 | { | 757 | { |
748 | QString qu = "SELECT uid FROM todolist WHERE ("; | 758 | QString qu = "SELECT uid FROM todolist WHERE ("; |
749 | 759 | ||
750 | // Does it make sense to search other fields, too ? | 760 | // Does it make sense to search other fields, too ? |
751 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; | 761 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
752 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | 762 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; |
753 | 763 | ||
754 | qu += ")"; | 764 | qu += ")"; |
755 | 765 | ||
756 | OSQLRawQuery raw( qu ); | 766 | OSQLRawQuery raw( qu ); |
757 | OSQLResult res = m_driver->query( &raw ); | 767 | OSQLResult res = m_driver->query( &raw ); |
758 | 768 | ||
759 | return uids( res ); | 769 | return uids( res ); |
760 | } | 770 | } |
761 | 771 | ||
762 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 772 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
763 | // First we need the uids from all entries which are | 773 | // First we need the uids from all entries which are |
764 | // completed. Then, we just have to remove them... | 774 | // completed. Then, we just have to remove them... |
765 | 775 | ||
766 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | 776 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; |
767 | 777 | ||
768 | OSQLRawQuery raw( qu ); | 778 | OSQLRawQuery raw( qu ); |
769 | OSQLResult res = m_driver->query( &raw ); | 779 | OSQLResult res = m_driver->query( &raw ); |
770 | 780 | ||
771 | QArray<int> completed_uids = uids( res ); | 781 | QArray<int> completed_uids = uids( res ); |
772 | 782 | ||
773 | if ( completed_uids.size() == 0 ) | 783 | if ( completed_uids.size() == 0 ) |
774 | return; | 784 | return; |
775 | 785 | ||
776 | qu = "DELETE FROM todolist WHERE ("; | 786 | qu = "DELETE FROM todolist WHERE ("; |
777 | QString query; | 787 | QString query; |
778 | 788 | ||
779 | for ( uint i = 0; i < completed_uids.size(); i++ ){ | 789 | for ( uint i = 0; i < completed_uids.size(); i++ ){ |
780 | if ( !query.isEmpty() ) | 790 | if ( !query.isEmpty() ) |
781 | query += " OR "; | 791 | query += " OR "; |
782 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 792 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
783 | } | 793 | } |
784 | qu += query + " );"; | 794 | qu += query + " );"; |
785 | 795 | ||
786 | // Put remove of custom entries in this query to speed up.. | 796 | // Put remove of custom entries in this query to speed up.. |
787 | qu += "DELETE FORM custom_data WHERE ("; | 797 | qu += "DELETE FORM custom_data WHERE ("; |
788 | query = ""; | 798 | query = ""; |
789 | 799 | ||
790 | for ( uint i = 0; i < completed_uids.size(); i++ ){ | 800 | for ( uint i = 0; i < completed_uids.size(); i++ ){ |
791 | if ( !query.isEmpty() ) | 801 | if ( !query.isEmpty() ) |
792 | query += " OR "; | 802 | query += " OR "; |
793 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 803 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
794 | } | 804 | } |
795 | qu += query + " );"; | 805 | qu += query + " );"; |
796 | 806 | ||
797 | OSQLRawQuery raw2( qu ); | 807 | OSQLRawQuery raw2( qu ); |
798 | res = m_driver->query( &raw2 ); | 808 | res = m_driver->query( &raw2 ); |
799 | 809 | ||
800 | if ( res.state() == OSQLResult::Failure ) | 810 | if ( res.state() == OSQLResult::Failure ) |
801 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; | 811 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; |
802 | 812 | ||
803 | } | 813 | } |
804 | 814 | ||
805 | 815 | ||
806 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 816 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
807 | { | 817 | { |
808 | QMap<QString, QString> customMap; | 818 | QMap<QString, QString> customMap; |
809 | 819 | ||
810 | FindCustomQuery query( uid ); | 820 | FindCustomQuery query( uid ); |
811 | OSQLResult res_custom = m_driver->query( &query ); | 821 | OSQLResult res_custom = m_driver->query( &query ); |
812 | 822 | ||
813 | if ( res_custom.state() == OSQLResult::Failure ) { | 823 | if ( res_custom.state() == OSQLResult::Failure ) { |
814 | owarn << "OSQLResult::Failure in find query !!" << oendl; | 824 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
815 | return QMap<QString, QString>(); | 825 | return QMap<QString, QString>(); |
816 | } | 826 | } |
817 | 827 | ||
818 | OSQLResultItem::ValueList list = res_custom.results(); | 828 | OSQLResultItem::ValueList list = res_custom.results(); |
819 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 829 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
820 | for ( ; it != list.end(); ++it ) | 830 | for ( ; it != list.end(); ++it ) |
821 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 831 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
822 | 832 | ||
823 | 833 | ||
824 | return customMap; | 834 | return customMap; |
825 | } | 835 | } |
826 | 836 | ||
827 | 837 | ||
828 | 838 | ||
829 | 839 | ||
830 | } | 840 | } |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 0ba8f3a..ac3476a 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h | |||
@@ -1,88 +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) 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_PIM_ACCESS_SQL_H | 29 | #ifndef OPIE_PIM_ACCESS_SQL_H |
30 | #define OPIE_PIM_ACCESS_SQL_H | 30 | #define OPIE_PIM_ACCESS_SQL_H |
31 | 31 | ||
32 | /* #include <qasciidict.h> */ | 32 | /* #include <qasciidict.h> */ |
33 | 33 | ||
34 | #include <opie2/otodoaccessbackend.h> | 34 | #include <opie2/otodoaccessbackend.h> |
35 | 35 | ||
36 | namespace Opie { | 36 | namespace Opie { |
37 | namespace DB { | 37 | namespace DB { |
38 | class OSQLDriver; | 38 | class OSQLDriver; |
39 | class OSQLResult; | 39 | class OSQLResult; |
40 | class OSQLResultItem; | 40 | class OSQLResultItem; |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | namespace Opie { | 44 | namespace Opie { |
45 | 45 | ||
46 | class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend { | 46 | class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend { |
47 | public: | 47 | public: |
48 | OPimTodoAccessBackendSQL( const QString& file ); | 48 | OPimTodoAccessBackendSQL( const QString& file ); |
49 | ~OPimTodoAccessBackendSQL(); | 49 | ~OPimTodoAccessBackendSQL(); |
50 | 50 | ||
51 | bool load(); | 51 | bool load(); |
52 | bool reload(); | 52 | bool reload(); |
53 | bool save(); | 53 | bool save(); |
54 | QArray<UID> allRecords()const; | 54 | QArray<UID> allRecords()const; |
55 | 55 | ||
56 | QArray<UID> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); | 56 | /* QArray<UID> queryByExample( const UIDArray& uidlist, const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); */ |
57 | OPimTodo find(UID uid)const; | 57 | OPimTodo find(UID uid)const; |
58 | OPimTodo find(UID uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | 58 | OPimTodo find(UID uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; |
59 | void clear(); | 59 | void clear(); |
60 | bool add( const OPimTodo& t ); | 60 | bool add( const OPimTodo& t ); |
61 | bool remove( UID uid ); | 61 | bool remove( UID uid ); |
62 | bool replace( const OPimTodo& t ); | 62 | bool replace( const OPimTodo& t ); |
63 | 63 | ||
64 | QArray<UID> overDue()const; | 64 | QArray<UID> overDue()const; |
65 | QArray<UID> effectiveToDos( const QDate& start, | 65 | QArray<UID> effectiveToDos( const QDate& start, |
66 | const QDate& end, bool includeNoDates )const; | 66 | const QDate& end, bool includeNoDates )const; |
67 | QArray<UID> matchRegexp( const QRegExp &r ) const; | 67 | QArray<UID> matchRegexp( const QRegExp &r ) const; |
68 | void removeAllCompleted(); | 68 | void removeAllCompleted(); |
69 | 69 | ||
70 | 70 | ||
71 | private: | 71 | private: |
72 | void update()const; | 72 | void update()const; |
73 | inline bool date( QDate& date, const QString& )const; | 73 | inline bool date( QDate& date, const QString& )const; |
74 | inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const; | 74 | inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const; |
75 | inline OPimTodo parse( Opie::DB::OSQLResultItem& )const; | 75 | inline OPimTodo parse( Opie::DB::OSQLResultItem& )const; |
76 | inline QArray<UID> uids( const Opie::DB::OSQLResult& )const; | 76 | inline QArray<UID> uids( const Opie::DB::OSQLResult& )const; |
77 | OPimTodo todo( UID uid )const; | 77 | OPimTodo todo( UID uid )const; |
78 | QMap<QString, QString> requestCustom( UID uid ) const; | 78 | QMap<QString, QString> requestCustom( UID uid ) const; |
79 | 79 | ||
80 | // QAsciiDict<int> m_dict; | 80 | // QAsciiDict<int> m_dict; |
81 | Opie::DB::OSQLDriver* m_driver; | 81 | Opie::DB::OSQLDriver* m_driver; |
82 | QArray<UID> m_uids; | 82 | QArray<UID> m_uids; |
83 | bool m_dirty : 1; | 83 | bool m_dirty : 1; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | } | 86 | } |
87 | 87 | ||
88 | #endif | 88 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 273f91a..ab50604 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,720 +1,717 @@ | |||
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 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <opie2/opimdateconversion.h> | 31 | #include <opie2/opimdateconversion.h> |
32 | #include <opie2/opimstate.h> | 32 | #include <opie2/opimstate.h> |
33 | #include <opie2/opimtimezone.h> | 33 | #include <opie2/opimtimezone.h> |
34 | #include <opie2/opimnotifymanager.h> | 34 | #include <opie2/opimnotifymanager.h> |
35 | #include <opie2/opimrecurrence.h> | 35 | #include <opie2/opimrecurrence.h> |
36 | #include <opie2/otodoaccessxml.h> | 36 | #include <opie2/otodoaccessxml.h> |
37 | #include <opie2/otodoaccess.h> | 37 | #include <opie2/otodoaccess.h> |
38 | #include <opie2/odebug.h> | 38 | #include <opie2/odebug.h> |
39 | 39 | ||
40 | #include <opie2/private/opimtodosortvector.h> | 40 | #include <opie2/private/opimtodosortvector.h> |
41 | 41 | ||
42 | #include <qpe/global.h> | 42 | #include <qpe/global.h> |
43 | #include <qpe/stringutil.h> | 43 | #include <qpe/stringutil.h> |
44 | #include <qpe/timeconversion.h> | 44 | #include <qpe/timeconversion.h> |
45 | 45 | ||
46 | /* QT */ | 46 | /* QT */ |
47 | #include <qfile.h> | 47 | #include <qfile.h> |
48 | #include <qvector.h> | 48 | #include <qvector.h> |
49 | 49 | ||
50 | /* STD */ | 50 | /* STD */ |
51 | #include <errno.h> | 51 | #include <errno.h> |
52 | #include <fcntl.h> | 52 | #include <fcntl.h> |
53 | 53 | ||
54 | #include <sys/mman.h> | 54 | #include <sys/mman.h> |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> |
57 | 57 | ||
58 | #include <unistd.h> | 58 | #include <unistd.h> |
59 | 59 | ||
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | 62 | ||
63 | namespace { | 63 | namespace { |
64 | time_t rp_end; | 64 | time_t rp_end; |
65 | OPimRecurrence* rec; | 65 | OPimRecurrence* rec; |
66 | OPimRecurrence *recur() { | 66 | OPimRecurrence *recur() { |
67 | if (!rec ) rec = new OPimRecurrence; | 67 | if (!rec ) rec = new OPimRecurrence; |
68 | return rec; | 68 | return rec; |
69 | } | 69 | } |
70 | int snd; | 70 | int snd; |
71 | enum MoreAttributes { | 71 | enum MoreAttributes { |
72 | FRType = OPimTodo::CompletedDate + 2, | 72 | FRType = OPimTodo::CompletedDate + 2, |
73 | FRWeekdays, | 73 | FRWeekdays, |
74 | FRPosition, | 74 | FRPosition, |
75 | FRFreq, | 75 | FRFreq, |
76 | FRHasEndDate, | 76 | FRHasEndDate, |
77 | FREndDate, | 77 | FREndDate, |
78 | FRStart, | 78 | FRStart, |
79 | FREnd | 79 | FREnd |
80 | }; | 80 | }; |
81 | // FROM TT again | 81 | // FROM TT again |
82 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 82 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
83 | { | 83 | { |
84 | char needleChar; | 84 | char needleChar; |
85 | char haystackChar; | 85 | char haystackChar; |
86 | if (!needle || !haystack || !hLen || !nLen) | 86 | if (!needle || !haystack || !hLen || !nLen) |
87 | return 0; | 87 | return 0; |
88 | 88 | ||
89 | const char* hsearch = haystack; | 89 | const char* hsearch = haystack; |
90 | 90 | ||
91 | if ((needleChar = *needle++) != 0) { | 91 | if ((needleChar = *needle++) != 0) { |
92 | nLen--; //(to make up for needle++) | 92 | nLen--; //(to make up for needle++) |
93 | do { | 93 | do { |
94 | do { | 94 | do { |
95 | if ((haystackChar = *hsearch++) == 0) | 95 | if ((haystackChar = *hsearch++) == 0) |
96 | return (0); | 96 | return (0); |
97 | if (hsearch >= haystack + hLen) | 97 | if (hsearch >= haystack + hLen) |
98 | return (0); | 98 | return (0); |
99 | } while (haystackChar != needleChar); | 99 | } while (haystackChar != needleChar); |
100 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 100 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
101 | hsearch--; | 101 | hsearch--; |
102 | } | 102 | } |
103 | return ((char *)hsearch); | 103 | return ((char *)hsearch); |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | namespace Opie { | 107 | namespace Opie { |
108 | 108 | ||
109 | OPimTodoAccessXML::OPimTodoAccessXML( const QString& appName, | 109 | OPimTodoAccessXML::OPimTodoAccessXML( const QString& appName, |
110 | const QString& fileName ) | 110 | const QString& fileName ) |
111 | : OPimTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 111 | : OPimTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
112 | { | 112 | { |
113 | if (!fileName.isEmpty() ) | 113 | if (!fileName.isEmpty() ) |
114 | m_file = fileName; | 114 | m_file = fileName; |
115 | else | 115 | else |
116 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 116 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
117 | } | 117 | } |
118 | OPimTodoAccessXML::~OPimTodoAccessXML() { | 118 | OPimTodoAccessXML::~OPimTodoAccessXML() { |
119 | 119 | ||
120 | } | 120 | } |
121 | bool OPimTodoAccessXML::load() { | 121 | bool OPimTodoAccessXML::load() { |
122 | rec = 0; | 122 | rec = 0; |
123 | m_opened = true; | 123 | m_opened = true; |
124 | m_changed = false; | 124 | m_changed = false; |
125 | /* initialize dict */ | 125 | /* initialize dict */ |
126 | /* | 126 | /* |
127 | * UPDATE dict if you change anything!!! | 127 | * UPDATE dict if you change anything!!! |
128 | */ | 128 | */ |
129 | QAsciiDict<int> dict(26); | 129 | QAsciiDict<int> dict(26); |
130 | dict.setAutoDelete( TRUE ); | 130 | dict.setAutoDelete( TRUE ); |
131 | dict.insert("Categories" , new int(OPimTodo::Category) ); | 131 | dict.insert("Categories" , new int(OPimTodo::Category) ); |
132 | dict.insert("Uid" , new int(OPimTodo::Uid) ); | 132 | dict.insert("Uid" , new int(OPimTodo::Uid) ); |
133 | dict.insert("HasDate" , new int(OPimTodo::HasDate) ); | 133 | dict.insert("HasDate" , new int(OPimTodo::HasDate) ); |
134 | dict.insert("Completed" , new int(OPimTodo::Completed) ); | 134 | dict.insert("Completed" , new int(OPimTodo::Completed) ); |
135 | dict.insert("Description" , new int(OPimTodo::Description) ); | 135 | dict.insert("Description" , new int(OPimTodo::Description) ); |
136 | dict.insert("Summary" , new int(OPimTodo::Summary) ); | 136 | dict.insert("Summary" , new int(OPimTodo::Summary) ); |
137 | dict.insert("Priority" , new int(OPimTodo::Priority) ); | 137 | dict.insert("Priority" , new int(OPimTodo::Priority) ); |
138 | dict.insert("DateDay" , new int(OPimTodo::DateDay) ); | 138 | dict.insert("DateDay" , new int(OPimTodo::DateDay) ); |
139 | dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); | 139 | dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); |
140 | dict.insert("DateYear" , new int(OPimTodo::DateYear) ); | 140 | dict.insert("DateYear" , new int(OPimTodo::DateYear) ); |
141 | dict.insert("Progress" , new int(OPimTodo::Progress) ); | 141 | dict.insert("Progress" , new int(OPimTodo::Progress) ); |
142 | dict.insert("CompletedDate", new int(OPimTodo::CompletedDate) ); | 142 | dict.insert("CompletedDate", new int(OPimTodo::CompletedDate) ); |
143 | dict.insert("StartDate", new int(OPimTodo::StartDate) ); | 143 | dict.insert("StartDate", new int(OPimTodo::StartDate) ); |
144 | dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); | 144 | dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); |
145 | dict.insert("State", new int(OPimTodo::State) ); | 145 | dict.insert("State", new int(OPimTodo::State) ); |
146 | dict.insert("Alarms", new int(OPimTodo::Alarms) ); | 146 | dict.insert("Alarms", new int(OPimTodo::Alarms) ); |
147 | dict.insert("Reminders", new int(OPimTodo::Reminders) ); | 147 | dict.insert("Reminders", new int(OPimTodo::Reminders) ); |
148 | dict.insert("Maintainer", new int(OPimTodo::Maintainer) ); | 148 | dict.insert("Maintainer", new int(OPimTodo::Maintainer) ); |
149 | dict.insert("rtype", new int(FRType) ); | 149 | dict.insert("rtype", new int(FRType) ); |
150 | dict.insert("rweekdays", new int(FRWeekdays) ); | 150 | dict.insert("rweekdays", new int(FRWeekdays) ); |
151 | dict.insert("rposition", new int(FRPosition) ); | 151 | dict.insert("rposition", new int(FRPosition) ); |
152 | dict.insert("rfreq", new int(FRFreq) ); | 152 | dict.insert("rfreq", new int(FRFreq) ); |
153 | dict.insert("start", new int(FRStart) ); | 153 | dict.insert("start", new int(FRStart) ); |
154 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 154 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
155 | dict.insert("enddt", new int(FREndDate) ); | 155 | dict.insert("enddt", new int(FREndDate) ); |
156 | 156 | ||
157 | // here the custom XML parser from TT it's GPL | 157 | // here the custom XML parser from TT it's GPL |
158 | // but we want to push OpiePIM... to TT..... | 158 | // but we want to push OpiePIM... to TT..... |
159 | // mmap part from zecke :) | 159 | // mmap part from zecke :) |
160 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); | 160 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
161 | struct stat attribut; | 161 | struct stat attribut; |
162 | if ( fd < 0 ) return false; | 162 | if ( fd < 0 ) return false; |
163 | 163 | ||
164 | if ( fstat(fd, &attribut ) == -1 ) { | 164 | if ( fstat(fd, &attribut ) == -1 ) { |
165 | ::close( fd ); | 165 | ::close( fd ); |
166 | return false; | 166 | return false; |
167 | } | 167 | } |
168 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 168 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
169 | if ( map_addr == ( (caddr_t)-1) ) { | 169 | if ( map_addr == ( (caddr_t)-1) ) { |
170 | ::close(fd ); | 170 | ::close(fd ); |
171 | return false; | 171 | return false; |
172 | } | 172 | } |
173 | /* advise the kernel who we want to read it */ | 173 | /* advise the kernel who we want to read it */ |
174 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | 174 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); |
175 | /* we do not the file any more */ | 175 | /* we do not the file any more */ |
176 | ::close( fd ); | 176 | ::close( fd ); |
177 | 177 | ||
178 | char* dt = (char*)map_addr; | 178 | char* dt = (char*)map_addr; |
179 | int len = attribut.st_size; | 179 | int len = attribut.st_size; |
180 | int i = 0; | 180 | int i = 0; |
181 | char *point; | 181 | char *point; |
182 | const char* collectionString = "<Task "; | 182 | const char* collectionString = "<Task "; |
183 | int strLen = strlen(collectionString); | 183 | int strLen = strlen(collectionString); |
184 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { | 184 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { |
185 | i = point -dt; | 185 | i = point -dt; |
186 | i+= strLen; | 186 | i+= strLen; |
187 | 187 | ||
188 | OPimTodo ev; | 188 | OPimTodo ev; |
189 | m_year = m_month = m_day = 0; | 189 | m_year = m_month = m_day = 0; |
190 | 190 | ||
191 | while ( TRUE ) { | 191 | while ( TRUE ) { |
192 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 192 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
193 | ++i; | 193 | ++i; |
194 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 194 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
195 | break; | 195 | break; |
196 | 196 | ||
197 | // we have another attribute, read it. | 197 | // we have another attribute, read it. |
198 | int j = i; | 198 | int j = i; |
199 | while ( j < len && dt[j] != '=' ) | 199 | while ( j < len && dt[j] != '=' ) |
200 | ++j; | 200 | ++j; |
201 | QCString attr( dt+i, j-i+1); | 201 | QCString attr( dt+i, j-i+1); |
202 | 202 | ||
203 | i = ++j; // skip = | 203 | i = ++j; // skip = |
204 | 204 | ||
205 | // find the start of quotes | 205 | // find the start of quotes |
206 | while ( i < len && dt[i] != '"' ) | 206 | while ( i < len && dt[i] != '"' ) |
207 | ++i; | 207 | ++i; |
208 | j = ++i; | 208 | j = ++i; |
209 | 209 | ||
210 | bool haveUtf = FALSE; | 210 | bool haveUtf = FALSE; |
211 | bool haveEnt = FALSE; | 211 | bool haveEnt = FALSE; |
212 | while ( j < len && dt[j] != '"' ) { | 212 | while ( j < len && dt[j] != '"' ) { |
213 | if ( ((unsigned char)dt[j]) > 0x7f ) | 213 | if ( ((unsigned char)dt[j]) > 0x7f ) |
214 | haveUtf = TRUE; | 214 | haveUtf = TRUE; |
215 | if ( dt[j] == '&' ) | 215 | if ( dt[j] == '&' ) |
216 | haveEnt = TRUE; | 216 | haveEnt = TRUE; |
217 | ++j; | 217 | ++j; |
218 | } | 218 | } |
219 | if ( i == j ) { | 219 | if ( i == j ) { |
220 | // empty value | 220 | // empty value |
221 | i = j + 1; | 221 | i = j + 1; |
222 | continue; | 222 | continue; |
223 | } | 223 | } |
224 | 224 | ||
225 | QCString value( dt+i, j-i+1 ); | 225 | QCString value( dt+i, j-i+1 ); |
226 | i = j + 1; | 226 | i = j + 1; |
227 | 227 | ||
228 | QString str = (haveUtf ? QString::fromUtf8( value ) | 228 | QString str = (haveUtf ? QString::fromUtf8( value ) |
229 | : QString::fromLatin1( value ) ); | 229 | : QString::fromLatin1( value ) ); |
230 | if ( haveEnt ) | 230 | if ( haveEnt ) |
231 | str = Qtopia::plainString( str ); | 231 | str = Qtopia::plainString( str ); |
232 | 232 | ||
233 | /* | 233 | /* |
234 | * add key + value | 234 | * add key + value |
235 | */ | 235 | */ |
236 | todo( &dict, ev, attr, str ); | 236 | todo( &dict, ev, attr, str ); |
237 | 237 | ||
238 | } | 238 | } |
239 | /* | 239 | /* |
240 | * now add it | 240 | * now add it |
241 | */ | 241 | */ |
242 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 242 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
243 | ev.setUid( 1 ); | 243 | ev.setUid( 1 ); |
244 | m_changed = true; | 244 | m_changed = true; |
245 | } | 245 | } |
246 | if ( ev.hasDueDate() ) { | 246 | if ( ev.hasDueDate() ) { |
247 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 247 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
248 | } | 248 | } |
249 | if ( rec && rec->doesRecur() ) { | 249 | if ( rec && rec->doesRecur() ) { |
250 | OPimTimeZone utc = OPimTimeZone::utc(); | 250 | OPimTimeZone utc = OPimTimeZone::utc(); |
251 | OPimRecurrence recu( *rec ); // call copy c'tor | 251 | OPimRecurrence recu( *rec ); // call copy c'tor |
252 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); | 252 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); |
253 | recu.setStart( ev.dueDate() ); | 253 | recu.setStart( ev.dueDate() ); |
254 | ev.setRecurrence( recu ); | 254 | ev.setRecurrence( recu ); |
255 | } | 255 | } |
256 | m_events.insert(ev.uid(), ev ); | 256 | m_events.insert(ev.uid(), ev ); |
257 | m_year = m_month = m_day = -1; | 257 | m_year = m_month = m_day = -1; |
258 | delete rec; | 258 | delete rec; |
259 | rec = 0; | 259 | rec = 0; |
260 | } | 260 | } |
261 | 261 | ||
262 | munmap(map_addr, attribut.st_size ); | 262 | munmap(map_addr, attribut.st_size ); |
263 | 263 | ||
264 | return true; | 264 | return true; |
265 | } | 265 | } |
266 | bool OPimTodoAccessXML::reload() { | 266 | bool OPimTodoAccessXML::reload() { |
267 | m_events.clear(); | 267 | m_events.clear(); |
268 | return load(); | 268 | return load(); |
269 | } | 269 | } |
270 | bool OPimTodoAccessXML::save() { | 270 | bool OPimTodoAccessXML::save() { |
271 | if (!m_opened || !m_changed ) { | 271 | if (!m_opened || !m_changed ) { |
272 | return true; | 272 | return true; |
273 | } | 273 | } |
274 | QString strNewFile = m_file + ".new"; | 274 | QString strNewFile = m_file + ".new"; |
275 | QFile f( strNewFile ); | 275 | QFile f( strNewFile ); |
276 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 276 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
277 | return false; | 277 | return false; |
278 | 278 | ||
279 | int written; | 279 | int written; |
280 | QString out; | 280 | QString out; |
281 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 281 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
282 | 282 | ||
283 | // for all todos | 283 | // for all todos |
284 | QMap<int, OPimTodo>::Iterator it; | 284 | QMap<int, OPimTodo>::Iterator it; |
285 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 285 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
286 | out+= "<Task " + toString( (*it) ) + " />\n"; | 286 | out+= "<Task " + toString( (*it) ) + " />\n"; |
287 | QCString cstr = out.utf8(); | 287 | QCString cstr = out.utf8(); |
288 | written = f.writeBlock( cstr.data(), cstr.length() ); | 288 | written = f.writeBlock( cstr.data(), cstr.length() ); |
289 | 289 | ||
290 | /* less written then we wanted */ | 290 | /* less written then we wanted */ |
291 | if ( written != (int)cstr.length() ) { | 291 | if ( written != (int)cstr.length() ) { |
292 | f.close(); | 292 | f.close(); |
293 | QFile::remove( strNewFile ); | 293 | QFile::remove( strNewFile ); |
294 | return false; | 294 | return false; |
295 | } | 295 | } |
296 | out = QString::null; | 296 | out = QString::null; |
297 | } | 297 | } |
298 | 298 | ||
299 | out += "</Tasks>"; | 299 | out += "</Tasks>"; |
300 | QCString cstr = out.utf8(); | 300 | QCString cstr = out.utf8(); |
301 | written = f.writeBlock( cstr.data(), cstr.length() ); | 301 | written = f.writeBlock( cstr.data(), cstr.length() ); |
302 | 302 | ||
303 | if ( written != (int)cstr.length() ) { | 303 | if ( written != (int)cstr.length() ) { |
304 | f.close(); | 304 | f.close(); |
305 | QFile::remove( strNewFile ); | 305 | QFile::remove( strNewFile ); |
306 | return false; | 306 | return false; |
307 | } | 307 | } |
308 | /* flush before renaming */ | 308 | /* flush before renaming */ |
309 | f.close(); | 309 | f.close(); |
310 | 310 | ||
311 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 311 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
312 | QFile::remove( strNewFile ); | 312 | QFile::remove( strNewFile ); |
313 | } | 313 | } |
314 | 314 | ||
315 | m_changed = false; | 315 | m_changed = false; |
316 | return true; | 316 | return true; |
317 | } | 317 | } |
318 | QArray<int> OPimTodoAccessXML::allRecords()const { | 318 | QArray<int> OPimTodoAccessXML::allRecords()const { |
319 | QArray<int> ids( m_events.count() ); | 319 | QArray<int> ids( m_events.count() ); |
320 | QMap<int, OPimTodo>::ConstIterator it; | 320 | QMap<int, OPimTodo>::ConstIterator it; |
321 | int i = 0; | 321 | int i = 0; |
322 | 322 | ||
323 | for ( it = m_events.begin(); it != m_events.end(); ++it ) | 323 | for ( it = m_events.begin(); it != m_events.end(); ++it ) |
324 | ids[i++] = it.key(); | 324 | ids[i++] = it.key(); |
325 | 325 | ||
326 | 326 | ||
327 | return ids; | 327 | return ids; |
328 | } | 328 | } |
329 | QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) { | 329 | |
330 | QArray<int> ids(0); | ||
331 | return ids; | ||
332 | } | ||
333 | OPimTodo OPimTodoAccessXML::find( int uid )const { | 330 | OPimTodo OPimTodoAccessXML::find( int uid )const { |
334 | OPimTodo todo; | 331 | OPimTodo todo; |
335 | todo.setUid( 0 ); // isEmpty() | 332 | todo.setUid( 0 ); // isEmpty() |
336 | QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid ); | 333 | QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid ); |
337 | if ( it != m_events.end() ) | 334 | if ( it != m_events.end() ) |
338 | todo = it.data(); | 335 | todo = it.data(); |
339 | 336 | ||
340 | return todo; | 337 | return todo; |
341 | } | 338 | } |
342 | void OPimTodoAccessXML::clear() { | 339 | void OPimTodoAccessXML::clear() { |
343 | if (m_opened ) | 340 | if (m_opened ) |
344 | m_changed = true; | 341 | m_changed = true; |
345 | 342 | ||
346 | m_events.clear(); | 343 | m_events.clear(); |
347 | } | 344 | } |
348 | bool OPimTodoAccessXML::add( const OPimTodo& todo ) { | 345 | bool OPimTodoAccessXML::add( const OPimTodo& todo ) { |
349 | m_changed = true; | 346 | m_changed = true; |
350 | m_events.insert( todo.uid(), todo ); | 347 | m_events.insert( todo.uid(), todo ); |
351 | 348 | ||
352 | return true; | 349 | return true; |
353 | } | 350 | } |
354 | bool OPimTodoAccessXML::remove( int uid ) { | 351 | bool OPimTodoAccessXML::remove( int uid ) { |
355 | m_changed = true; | 352 | m_changed = true; |
356 | m_events.remove( uid ); | 353 | m_events.remove( uid ); |
357 | 354 | ||
358 | return true; | 355 | return true; |
359 | } | 356 | } |
360 | bool OPimTodoAccessXML::replace( const OPimTodo& todo) { | 357 | bool OPimTodoAccessXML::replace( const OPimTodo& todo) { |
361 | m_changed = true; | 358 | m_changed = true; |
362 | m_events.replace( todo.uid(), todo ); | 359 | m_events.replace( todo.uid(), todo ); |
363 | 360 | ||
364 | return true; | 361 | return true; |
365 | } | 362 | } |
366 | QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start, | 363 | QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start, |
367 | const QDate& end, | 364 | const QDate& end, |
368 | bool includeNoDates )const { | 365 | bool includeNoDates )const { |
369 | QArray<int> ids( m_events.count() ); | 366 | QArray<int> ids( m_events.count() ); |
370 | QMap<int, OPimTodo>::ConstIterator it; | 367 | QMap<int, OPimTodo>::ConstIterator it; |
371 | 368 | ||
372 | int i = 0; | 369 | int i = 0; |
373 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 370 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
374 | if ( !it.data().hasDueDate() && includeNoDates) { | 371 | if ( !it.data().hasDueDate() && includeNoDates) { |
375 | ids[i++] = it.key(); | 372 | ids[i++] = it.key(); |
376 | }else if ( it.data().dueDate() >= start && | 373 | }else if ( it.data().dueDate() >= start && |
377 | it.data().dueDate() <= end ) { | 374 | it.data().dueDate() <= end ) { |
378 | ids[i++] = it.key(); | 375 | ids[i++] = it.key(); |
379 | } | 376 | } |
380 | } | 377 | } |
381 | ids.resize( i ); | 378 | ids.resize( i ); |
382 | return ids; | 379 | return ids; |
383 | } | 380 | } |
384 | QArray<int> OPimTodoAccessXML::overDue()const { | 381 | QArray<int> OPimTodoAccessXML::overDue()const { |
385 | QArray<int> ids( m_events.count() ); | 382 | QArray<int> ids( m_events.count() ); |
386 | int i = 0; | 383 | int i = 0; |
387 | 384 | ||
388 | QMap<int, OPimTodo>::ConstIterator it; | 385 | QMap<int, OPimTodo>::ConstIterator it; |
389 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 386 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
390 | if ( it.data().isOverdue() ) { | 387 | if ( it.data().isOverdue() ) { |
391 | ids[i] = it.key(); | 388 | ids[i] = it.key(); |
392 | i++; | 389 | i++; |
393 | } | 390 | } |
394 | } | 391 | } |
395 | ids.resize( i ); | 392 | ids.resize( i ); |
396 | return ids; | 393 | return ids; |
397 | } | 394 | } |
398 | 395 | ||
399 | 396 | ||
400 | /* private */ | 397 | /* private */ |
401 | void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev, | 398 | void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev, |
402 | const QCString& attr, const QString& val) { | 399 | const QCString& attr, const QString& val) { |
403 | 400 | ||
404 | int *find=0; | 401 | int *find=0; |
405 | 402 | ||
406 | find = (*dict)[ attr.data() ]; | 403 | find = (*dict)[ attr.data() ]; |
407 | if (!find ) { | 404 | if (!find ) { |
408 | ev.setCustomField( attr, val ); | 405 | ev.setCustomField( attr, val ); |
409 | return; | 406 | return; |
410 | } | 407 | } |
411 | 408 | ||
412 | switch( *find ) { | 409 | switch( *find ) { |
413 | case OPimTodo::Uid: | 410 | case OPimTodo::Uid: |
414 | ev.setUid( val.toInt() ); | 411 | ev.setUid( val.toInt() ); |
415 | break; | 412 | break; |
416 | case OPimTodo::Category: | 413 | case OPimTodo::Category: |
417 | ev.setCategories( ev.idsFromString( val ) ); | 414 | ev.setCategories( ev.idsFromString( val ) ); |
418 | break; | 415 | break; |
419 | case OPimTodo::HasDate: | 416 | case OPimTodo::HasDate: |
420 | ev.setHasDueDate( val.toInt() ); | 417 | ev.setHasDueDate( val.toInt() ); |
421 | break; | 418 | break; |
422 | case OPimTodo::Completed: | 419 | case OPimTodo::Completed: |
423 | ev.setCompleted( val.toInt() ); | 420 | ev.setCompleted( val.toInt() ); |
424 | break; | 421 | break; |
425 | case OPimTodo::Description: | 422 | case OPimTodo::Description: |
426 | ev.setDescription( val ); | 423 | ev.setDescription( val ); |
427 | break; | 424 | break; |
428 | case OPimTodo::Summary: | 425 | case OPimTodo::Summary: |
429 | ev.setSummary( val ); | 426 | ev.setSummary( val ); |
430 | break; | 427 | break; |
431 | case OPimTodo::Priority: | 428 | case OPimTodo::Priority: |
432 | ev.setPriority( val.toInt() ); | 429 | ev.setPriority( val.toInt() ); |
433 | break; | 430 | break; |
434 | case OPimTodo::DateDay: | 431 | case OPimTodo::DateDay: |
435 | m_day = val.toInt(); | 432 | m_day = val.toInt(); |
436 | break; | 433 | break; |
437 | case OPimTodo::DateMonth: | 434 | case OPimTodo::DateMonth: |
438 | m_month = val.toInt(); | 435 | m_month = val.toInt(); |
439 | break; | 436 | break; |
440 | case OPimTodo::DateYear: | 437 | case OPimTodo::DateYear: |
441 | m_year = val.toInt(); | 438 | m_year = val.toInt(); |
442 | break; | 439 | break; |
443 | case OPimTodo::Progress: | 440 | case OPimTodo::Progress: |
444 | ev.setProgress( val.toInt() ); | 441 | ev.setProgress( val.toInt() ); |
445 | break; | 442 | break; |
446 | case OPimTodo::CompletedDate: | 443 | case OPimTodo::CompletedDate: |
447 | ev.setCompletedDate( OPimDateConversion::dateFromString( val ) ); | 444 | ev.setCompletedDate( OPimDateConversion::dateFromString( val ) ); |
448 | break; | 445 | break; |
449 | case OPimTodo::StartDate: | 446 | case OPimTodo::StartDate: |
450 | ev.setStartDate( OPimDateConversion::dateFromString( val ) ); | 447 | ev.setStartDate( OPimDateConversion::dateFromString( val ) ); |
451 | break; | 448 | break; |
452 | case OPimTodo::State: | 449 | case OPimTodo::State: |
453 | ev.setState( val.toInt() ); | 450 | ev.setState( val.toInt() ); |
454 | break; | 451 | break; |
455 | case OPimTodo::Alarms:{ | 452 | case OPimTodo::Alarms:{ |
456 | OPimNotifyManager &manager = ev.notifiers(); | 453 | OPimNotifyManager &manager = ev.notifiers(); |
457 | QStringList als = QStringList::split(";", val ); | 454 | QStringList als = QStringList::split(";", val ); |
458 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | 455 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { |
459 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 456 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty |
460 | OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); | 457 | OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); |
461 | manager.add( al ); | 458 | manager.add( al ); |
462 | } | 459 | } |
463 | } | 460 | } |
464 | break; | 461 | break; |
465 | case OPimTodo::Reminders:{ | 462 | case OPimTodo::Reminders:{ |
466 | OPimNotifyManager &manager = ev.notifiers(); | 463 | OPimNotifyManager &manager = ev.notifiers(); |
467 | QStringList rems = QStringList::split(";", val ); | 464 | QStringList rems = QStringList::split(";", val ); |
468 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | 465 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { |
469 | OPimReminder rem( (*it).toInt() ); | 466 | OPimReminder rem( (*it).toInt() ); |
470 | manager.add( rem ); | 467 | manager.add( rem ); |
471 | } | 468 | } |
472 | } | 469 | } |
473 | break; | 470 | break; |
474 | case OPimTodo::CrossReference: | 471 | case OPimTodo::CrossReference: |
475 | { | 472 | { |
476 | /* | 473 | /* |
477 | * A cross refernce looks like | 474 | * A cross refernce looks like |
478 | * appname,id;appname,id | 475 | * appname,id;appname,id |
479 | * we need to split it up | 476 | * we need to split it up |
480 | */ | 477 | */ |
481 | QStringList refs = QStringList::split(';', val ); | 478 | QStringList refs = QStringList::split(';', val ); |
482 | QStringList::Iterator strIt; | 479 | QStringList::Iterator strIt; |
483 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 480 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
484 | int pos = (*strIt).find(','); | 481 | int pos = (*strIt).find(','); |
485 | if ( pos > -1 ) | 482 | if ( pos > -1 ) |
486 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 483 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
487 | 484 | ||
488 | } | 485 | } |
489 | break; | 486 | break; |
490 | } | 487 | } |
491 | /* Recurrence stuff below + post processing later */ | 488 | /* Recurrence stuff below + post processing later */ |
492 | case FRType: | 489 | case FRType: |
493 | if ( val == "Daily" ) | 490 | if ( val == "Daily" ) |
494 | recur()->setType( OPimRecurrence::Daily ); | 491 | recur()->setType( OPimRecurrence::Daily ); |
495 | else if ( val == "Weekly" ) | 492 | else if ( val == "Weekly" ) |
496 | recur()->setType( OPimRecurrence::Weekly); | 493 | recur()->setType( OPimRecurrence::Weekly); |
497 | else if ( val == "MonthlyDay" ) | 494 | else if ( val == "MonthlyDay" ) |
498 | recur()->setType( OPimRecurrence::MonthlyDay ); | 495 | recur()->setType( OPimRecurrence::MonthlyDay ); |
499 | else if ( val == "MonthlyDate" ) | 496 | else if ( val == "MonthlyDate" ) |
500 | recur()->setType( OPimRecurrence::MonthlyDate ); | 497 | recur()->setType( OPimRecurrence::MonthlyDate ); |
501 | else if ( val == "Yearly" ) | 498 | else if ( val == "Yearly" ) |
502 | recur()->setType( OPimRecurrence::Yearly ); | 499 | recur()->setType( OPimRecurrence::Yearly ); |
503 | else | 500 | else |
504 | recur()->setType( OPimRecurrence::NoRepeat ); | 501 | recur()->setType( OPimRecurrence::NoRepeat ); |
505 | break; | 502 | break; |
506 | case FRWeekdays: | 503 | case FRWeekdays: |
507 | recur()->setDays( val.toInt() ); | 504 | recur()->setDays( val.toInt() ); |
508 | break; | 505 | break; |
509 | case FRPosition: | 506 | case FRPosition: |
510 | recur()->setPosition( val.toInt() ); | 507 | recur()->setPosition( val.toInt() ); |
511 | break; | 508 | break; |
512 | case FRFreq: | 509 | case FRFreq: |
513 | recur()->setFrequency( val.toInt() ); | 510 | recur()->setFrequency( val.toInt() ); |
514 | break; | 511 | break; |
515 | case FRHasEndDate: | 512 | case FRHasEndDate: |
516 | recur()->setHasEndDate( val.toInt() ); | 513 | recur()->setHasEndDate( val.toInt() ); |
517 | break; | 514 | break; |
518 | case FREndDate: { | 515 | case FREndDate: { |
519 | rp_end = (time_t) val.toLong(); | 516 | rp_end = (time_t) val.toLong(); |
520 | break; | 517 | break; |
521 | } | 518 | } |
522 | default: | 519 | default: |
523 | ev.setCustomField( attr, val ); | 520 | ev.setCustomField( attr, val ); |
524 | break; | 521 | break; |
525 | } | 522 | } |
526 | } | 523 | } |
527 | 524 | ||
528 | // from PalmtopRecord... GPL ### FIXME | 525 | // from PalmtopRecord... GPL ### FIXME |
529 | namespace { | 526 | namespace { |
530 | QString customToXml(const QMap<QString, QString>& customMap ) | 527 | QString customToXml(const QMap<QString, QString>& customMap ) |
531 | { | 528 | { |
532 | QString buf(" "); | 529 | QString buf(" "); |
533 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); | 530 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); |
534 | cit != customMap.end(); ++cit) { | 531 | cit != customMap.end(); ++cit) { |
535 | buf += cit.key(); | 532 | buf += cit.key(); |
536 | buf += "=\""; | 533 | buf += "=\""; |
537 | buf += Qtopia::escapeString(cit.data()); | 534 | buf += Qtopia::escapeString(cit.data()); |
538 | buf += "\" "; | 535 | buf += "\" "; |
539 | } | 536 | } |
540 | return buf; | 537 | return buf; |
541 | } | 538 | } |
542 | 539 | ||
543 | 540 | ||
544 | } | 541 | } |
545 | 542 | ||
546 | QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { | 543 | QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { |
547 | QString str; | 544 | QString str; |
548 | 545 | ||
549 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 546 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
550 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 547 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
551 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 548 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
552 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 549 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
553 | 550 | ||
554 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 551 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
555 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 552 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
556 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 553 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
557 | 554 | ||
558 | if ( ev.hasDueDate() ) { | 555 | if ( ev.hasDueDate() ) { |
559 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 556 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
560 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 557 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
561 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 558 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
562 | } | 559 | } |
563 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 560 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
564 | 561 | ||
565 | // append the extra options | 562 | // append the extra options |
566 | /* FIXME Qtopia::Record this is currently not | 563 | /* FIXME Qtopia::Record this is currently not |
567 | * possible you can set custom fields | 564 | * possible you can set custom fields |
568 | * but don' iterate over the list | 565 | * but don' iterate over the list |
569 | * I may do #define private protected | 566 | * I may do #define private protected |
570 | * for this case - cough --zecke | 567 | * for this case - cough --zecke |
571 | */ | 568 | */ |
572 | /* | 569 | /* |
573 | QMap<QString, QString> extras = ev.extras(); | 570 | QMap<QString, QString> extras = ev.extras(); |
574 | QMap<QString, QString>::Iterator extIt; | 571 | QMap<QString, QString>::Iterator extIt; |
575 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 572 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
576 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 573 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
577 | */ | 574 | */ |
578 | // cross refernce | 575 | // cross refernce |
579 | if ( ev.hasRecurrence() ) { | 576 | if ( ev.hasRecurrence() ) { |
580 | str += ev.recurrence().toString(); | 577 | str += ev.recurrence().toString(); |
581 | } | 578 | } |
582 | if ( ev.hasStartDate() ) | 579 | if ( ev.hasStartDate() ) |
583 | str += "StartDate=\""+ OPimDateConversion::dateToString( ev.startDate() ) +"\" "; | 580 | str += "StartDate=\""+ OPimDateConversion::dateToString( ev.startDate() ) +"\" "; |
584 | if ( ev.hasCompletedDate() ) | 581 | if ( ev.hasCompletedDate() ) |
585 | str += "CompletedDate=\""+ OPimDateConversion::dateToString( ev.completedDate() ) +"\" "; | 582 | str += "CompletedDate=\""+ OPimDateConversion::dateToString( ev.completedDate() ) +"\" "; |
586 | if ( ev.hasState() ) | 583 | if ( ev.hasState() ) |
587 | str += "State=\""+QString::number( ev.state().state() )+"\" "; | 584 | str += "State=\""+QString::number( ev.state().state() )+"\" "; |
588 | 585 | ||
589 | /* | 586 | /* |
590 | * save reminders and notifiers! | 587 | * save reminders and notifiers! |
591 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... | 588 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... |
592 | */ | 589 | */ |
593 | if ( ev.hasNotifiers() ) { | 590 | if ( ev.hasNotifiers() ) { |
594 | OPimNotifyManager manager = ev.notifiers(); | 591 | OPimNotifyManager manager = ev.notifiers(); |
595 | OPimNotifyManager::Alarms alarms = manager.alarms(); | 592 | OPimNotifyManager::Alarms alarms = manager.alarms(); |
596 | if (!alarms.isEmpty() ) { | 593 | if (!alarms.isEmpty() ) { |
597 | QStringList als; | 594 | QStringList als; |
598 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 595 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
599 | for ( ; it != alarms.end(); ++it ) { | 596 | for ( ; it != alarms.end(); ++it ) { |
600 | /* only if time is valid */ | 597 | /* only if time is valid */ |
601 | if ( (*it).dateTime().isValid() ) { | 598 | if ( (*it).dateTime().isValid() ) { |
602 | als << OPimDateConversion::dateTimeToString( (*it).dateTime() ) | 599 | als << OPimDateConversion::dateTimeToString( (*it).dateTime() ) |
603 | + ":" + QString::number( (*it).duration() ) | 600 | + ":" + QString::number( (*it).duration() ) |
604 | + ":" + QString::number( (*it).sound() ) | 601 | + ":" + QString::number( (*it).sound() ) |
605 | + ":"; | 602 | + ":"; |
606 | } | 603 | } |
607 | } | 604 | } |
608 | // now write the list | 605 | // now write the list |
609 | str += "Alarms=\""+als.join(";") +"\" "; | 606 | str += "Alarms=\""+als.join(";") +"\" "; |
610 | } | 607 | } |
611 | 608 | ||
612 | /* | 609 | /* |
613 | * now the same for reminders but more easy. We just save the uid of the OPimEvent. | 610 | * now the same for reminders but more easy. We just save the uid of the OPimEvent. |
614 | */ | 611 | */ |
615 | OPimNotifyManager::Reminders reminders = manager.reminders(); | 612 | OPimNotifyManager::Reminders reminders = manager.reminders(); |
616 | if (!reminders.isEmpty() ) { | 613 | if (!reminders.isEmpty() ) { |
617 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 614 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
618 | QStringList records; | 615 | QStringList records; |
619 | for ( ; it != reminders.end(); ++it ) { | 616 | for ( ; it != reminders.end(); ++it ) { |
620 | records << QString::number( (*it).recordUid() ); | 617 | records << QString::number( (*it).recordUid() ); |
621 | } | 618 | } |
622 | str += "Reminders=\""+ records.join(";") +"\" "; | 619 | str += "Reminders=\""+ records.join(";") +"\" "; |
623 | } | 620 | } |
624 | } | 621 | } |
625 | str += customToXml( ev.toExtraMap() ); | 622 | str += customToXml( ev.toExtraMap() ); |
626 | 623 | ||
627 | 624 | ||
628 | return str; | 625 | return str; |
629 | } | 626 | } |
630 | QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const { | 627 | QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const { |
631 | return Qtopia::Record::idsToString( ints ); | 628 | return Qtopia::Record::idsToString( ints ); |
632 | } | 629 | } |
633 | 630 | ||
634 | 631 | ||
635 | QArray<int> OPimTodoAccessXML::sorted( const UIDArray& events, bool asc, | 632 | QArray<int> OPimTodoAccessXML::sorted( const UIDArray& events, bool asc, |
636 | int sortOrder,int sortFilter, | 633 | int sortOrder,int sortFilter, |
637 | const QArray<int>& categories )const { | 634 | const QArray<int>& categories )const { |
638 | Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); | 635 | Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); |
639 | int item = 0; | 636 | int item = 0; |
640 | 637 | ||
641 | bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; | 638 | bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; |
642 | bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; | 639 | bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; |
643 | bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; | 640 | bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; |
644 | bool catPassed = false; | 641 | bool catPassed = false; |
645 | int cat; | 642 | int cat; |
646 | 643 | ||
647 | for ( uint i = 0; i < events.count(); ++i ) { | 644 | for ( uint i = 0; i < events.count(); ++i ) { |
648 | /* Guard against creating a new item... */ | 645 | /* Guard against creating a new item... */ |
649 | if ( !m_events.contains( events[i] ) ) | 646 | if ( !m_events.contains( events[i] ) ) |
650 | continue; | 647 | continue; |
651 | 648 | ||
652 | OPimTodo todo = m_events[events[i]]; | 649 | OPimTodo todo = m_events[events[i]]; |
653 | 650 | ||
654 | /* show category */ | 651 | /* show category */ |
655 | /* -1 == unfiled */ | 652 | /* -1 == unfiled */ |
656 | catPassed = false; | 653 | catPassed = false; |
657 | for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { | 654 | for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { |
658 | cat = categories[cat_nu]; | 655 | cat = categories[cat_nu]; |
659 | if ( bCat && cat == -1 ) { | 656 | if ( bCat && cat == -1 ) { |
660 | if(!todo.categories().isEmpty() ) | 657 | if(!todo.categories().isEmpty() ) |
661 | continue; | 658 | continue; |
662 | } else if ( bCat && cat != 0) | 659 | } else if ( bCat && cat != 0) |
663 | if (!todo.categories().contains( cat ) ) | 660 | if (!todo.categories().contains( cat ) ) |
664 | continue; | 661 | continue; |
665 | catPassed = true; | 662 | catPassed = true; |
666 | break; | 663 | break; |
667 | } | 664 | } |
668 | 665 | ||
669 | /* | 666 | /* |
670 | * If none of the Categories matched | 667 | * If none of the Categories matched |
671 | * continue | 668 | * continue |
672 | */ | 669 | */ |
673 | if ( !catPassed ) | 670 | if ( !catPassed ) |
674 | continue; | 671 | continue; |
675 | if ( !todo.isOverdue() && bOnly ) | 672 | if ( !todo.isOverdue() && bOnly ) |
676 | continue; | 673 | continue; |
677 | if (todo.isCompleted() && comp ) | 674 | if (todo.isCompleted() && comp ) |
678 | continue; | 675 | continue; |
679 | 676 | ||
680 | vector.insert(item++, todo ); | 677 | vector.insert(item++, todo ); |
681 | } | 678 | } |
682 | 679 | ||
683 | vector.resize( item ); | 680 | vector.resize( item ); |
684 | /* sort it now */ | 681 | /* sort it now */ |
685 | vector.sort(); | 682 | vector.sort(); |
686 | /* now get the uids */ | 683 | /* now get the uids */ |
687 | UIDArray array( vector.count() ); | 684 | UIDArray array( vector.count() ); |
688 | for (uint i= 0; i < vector.count(); i++ ) | 685 | for (uint i= 0; i < vector.count(); i++ ) |
689 | array[i] = vector.uidAt( i ); | 686 | array[i] = vector.uidAt( i ); |
690 | 687 | ||
691 | return array; | 688 | return array; |
692 | } | 689 | } |
693 | 690 | ||
694 | void OPimTodoAccessXML::removeAllCompleted() { | 691 | void OPimTodoAccessXML::removeAllCompleted() { |
695 | QMap<int, OPimTodo> events = m_events; | 692 | QMap<int, OPimTodo> events = m_events; |
696 | for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 693 | for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
697 | if ( (*it).isCompleted() ) | 694 | if ( (*it).isCompleted() ) |
698 | events.remove( it.key() ); | 695 | events.remove( it.key() ); |
699 | } | 696 | } |
700 | m_events = events; | 697 | m_events = events; |
701 | } | 698 | } |
702 | 699 | ||
703 | QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const | 700 | QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const |
704 | { | 701 | { |
705 | QArray<int> currentQuery( m_events.count() ); | 702 | QArray<int> currentQuery( m_events.count() ); |
706 | uint arraycounter = 0; | 703 | uint arraycounter = 0; |
707 | 704 | ||
708 | QMap<int, OPimTodo>::ConstIterator it; | 705 | QMap<int, OPimTodo>::ConstIterator it; |
709 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 706 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
710 | if ( it.data().match( r ) ) | 707 | if ( it.data().match( r ) ) |
711 | currentQuery[arraycounter++] = it.data().uid(); | 708 | currentQuery[arraycounter++] = it.data().uid(); |
712 | 709 | ||
713 | } | 710 | } |
714 | // Shrink to fit.. | 711 | // Shrink to fit.. |
715 | currentQuery.resize(arraycounter); | 712 | currentQuery.resize(arraycounter); |
716 | 713 | ||
717 | return currentQuery; | 714 | return currentQuery; |
718 | } | 715 | } |
719 | 716 | ||
720 | } | 717 | } |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h index 134a21a..8a71bb7 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.h +++ b/libopie2/opiepim/backend/otodoaccessxml.h | |||
@@ -1,88 +1,87 @@ | |||
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_TODO_ACCESS_XML_H | 29 | #ifndef OPIE_TODO_ACCESS_XML_H |
30 | #define OPIE_TODO_ACCESS_XML_H | 30 | #define OPIE_TODO_ACCESS_XML_H |
31 | 31 | ||
32 | #include <qasciidict.h> | 32 | #include <qasciidict.h> |
33 | #include <qmap.h> | 33 | #include <qmap.h> |
34 | 34 | ||
35 | #include <opie2/otodoaccessbackend.h> | 35 | #include <opie2/otodoaccessbackend.h> |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | class XMLElement; | 38 | class XMLElement; |
39 | 39 | ||
40 | class OPimTodoAccessXML : public OPimTodoAccessBackend { | 40 | class OPimTodoAccessXML : public OPimTodoAccessBackend { |
41 | public: | 41 | public: |
42 | /** | 42 | /** |
43 | * fileName if Empty we will use the default path | 43 | * fileName if Empty we will use the default path |
44 | */ | 44 | */ |
45 | OPimTodoAccessXML( const QString& appName, | 45 | OPimTodoAccessXML( const QString& appName, |
46 | const QString& fileName = QString::null ); | 46 | const QString& fileName = QString::null ); |
47 | ~OPimTodoAccessXML(); | 47 | ~OPimTodoAccessXML(); |
48 | 48 | ||
49 | bool load(); | 49 | bool load(); |
50 | bool reload(); | 50 | bool reload(); |
51 | bool save(); | 51 | bool save(); |
52 | 52 | ||
53 | QArray<int> allRecords()const; | 53 | QArray<int> allRecords()const; |
54 | QArray<int> matchRegexp(const QRegExp &r) const; | 54 | QArray<int> matchRegexp(const QRegExp &r) const; |
55 | QArray<int> queryByExample( const OPimTodo&, int querysettings, const QDateTime& d = QDateTime() ); | ||
56 | OPimTodo find( int uid )const; | 55 | OPimTodo find( int uid )const; |
57 | void clear(); | 56 | void clear(); |
58 | bool add( const OPimTodo& ); | 57 | bool add( const OPimTodo& ); |
59 | bool remove( int uid ); | 58 | bool remove( int uid ); |
60 | void removeAllCompleted(); | 59 | void removeAllCompleted(); |
61 | bool replace( const OPimTodo& ); | 60 | bool replace( const OPimTodo& ); |
62 | 61 | ||
63 | /* our functions */ | 62 | /* our functions */ |
64 | QArray<int> effectiveToDos( const QDate& start, | 63 | QArray<int> effectiveToDos( const QDate& start, |
65 | const QDate& end, | 64 | const QDate& end, |
66 | bool includeNoDates )const; | 65 | bool includeNoDates )const; |
67 | QArray<int> overDue()const; | 66 | QArray<int> overDue()const; |
68 | 67 | ||
69 | //@{ | 68 | //@{ |
70 | UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const; | 69 | UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const; |
71 | //@} | 70 | //@} |
72 | private: | 71 | private: |
73 | void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& ); | 72 | void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& ); |
74 | QString toString( const OPimTodo& )const; | 73 | QString toString( const OPimTodo& )const; |
75 | QString toString( const QArray<int>& ints ) const; | 74 | QString toString( const QArray<int>& ints ) const; |
76 | QMap<int, OPimTodo> m_events; | 75 | QMap<int, OPimTodo> m_events; |
77 | QString m_file; | 76 | QString m_file; |
78 | QString m_app; | 77 | QString m_app; |
79 | bool m_opened : 1; | 78 | bool m_opened : 1; |
80 | bool m_changed : 1; | 79 | bool m_changed : 1; |
81 | class OPimTodoAccessXMLPrivate; | 80 | class OPimTodoAccessXMLPrivate; |
82 | OPimTodoAccessXMLPrivate* d; | 81 | OPimTodoAccessXMLPrivate* d; |
83 | int m_year, m_month, m_day; | 82 | int m_year, m_month, m_day; |
84 | }; | 83 | }; |
85 | 84 | ||
86 | }; | 85 | }; |
87 | 86 | ||
88 | #endif | 87 | #endif |