summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authorzecke <zecke>2004-03-13 19:51:45 (UTC)
committer zecke <zecke>2004-03-13 19:51:45 (UTC)
commit6d08277737e22b7a1527124623f3571969073ddf (patch) (unidiff)
tree4129e674e21df767b31299e873dd44e33a308e1b /libopie2/opiepim
parent8e28911f7199f4450ac5eef09482069f9b9caea2 (diff)
downloadopie-6d08277737e22b7a1527124623f3571969073ddf.zip
opie-6d08277737e22b7a1527124623f3571969073ddf.tar.gz
opie-6d08277737e22b7a1527124623f3571969073ddf.tar.bz2
Move XML class to internal PIM
Add namespaces!!! Opie::Core and Opie::Core::Private Opie::Net and Opie::Net::Private Opie::Ui and Opie::Ui::Private Opie::MM and Opie::MM::Private Opie::DB and Opie::DB::Private PIM classes are not yet converted because we will do other work on it as well
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/backends.pro6
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp2
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h8
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp3
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp2
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h8
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp2
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h12
-rw-r--r--libopie2/opiepim/core/backends/private/xmltree.cc323
-rw-r--r--libopie2/opiepim/core/backends/private/xmltree.h122
10 files changed, 476 insertions, 12 deletions
diff --git a/libopie2/opiepim/backend/backends.pro b/libopie2/opiepim/backend/backends.pro
index 4231a00..d4867ba 100644
--- a/libopie2/opiepim/backend/backends.pro
+++ b/libopie2/opiepim/backend/backends.pro
@@ -1,31 +1,33 @@
1SOURCES += core/backends/ocontactaccessbackend_sql.cpp \ 1SOURCES += core/backends/ocontactaccessbackend_sql.cpp \
2 core/backends/ocontactaccessbackend_vcard.cpp \ 2 core/backends/ocontactaccessbackend_vcard.cpp \
3 core/backends/ocontactaccessbackend_xml.cpp \ 3 core/backends/ocontactaccessbackend_xml.cpp \
4 core/backends/ocontactaccess.cpp \ 4 core/backends/ocontactaccess.cpp \
5 core/backends/odatebookaccessbackend.cpp \ 5 core/backends/odatebookaccessbackend.cpp \
6 core/backends/odatebookaccessbackend_xml.cpp \ 6 core/backends/odatebookaccessbackend_xml.cpp \
7 core/backends/otodoaccessbackend.cpp \ 7 core/backends/otodoaccessbackend.cpp \
8 core/backends/otodoaccess.cpp \ 8 core/backends/otodoaccess.cpp \
9 core/backends/otodoaccesssql.cpp \ 9 core/backends/otodoaccesssql.cpp \
10 core/backends/otodoaccessvcal.cpp \ 10 core/backends/otodoaccessvcal.cpp \
11 core/backends/otodoaccessxml.cpp \ 11 core/backends/otodoaccessxml.cpp \
12 core/backends/odatebookaccess.cpp \ 12 core/backends/odatebookaccess.cpp \
13 core/backends/odatebookaccessbackend_sql.cpp 13 core/backends/odatebookaccessbackend_sql.cpp \
14 core/backends/private/xmltree.cc
14 15
15HEADERS += core/backends/obackendfactory.h \ 16HEADERS += core/backends/obackendfactory.h \
16 core/backends/ocontactaccessbackend.h \ 17 core/backends/ocontactaccessbackend.h \
17 core/backends/ocontactaccessbackend_sql.h \ 18 core/backends/ocontactaccessbackend_sql.h \
18 core/backends/ocontactaccessbackend_vcard.h \ 19 core/backends/ocontactaccessbackend_vcard.h \
19 core/backends/ocontactaccessbackend_xml.h \ 20 core/backends/ocontactaccessbackend_xml.h \
20 core/backends/ocontactaccess.h \ 21 core/backends/ocontactaccess.h \
21 core/backends/odatebookaccessbackend.h \ 22 core/backends/odatebookaccessbackend.h \
22 core/backends/odatebookaccessbackend_sql.h \ 23 core/backends/odatebookaccessbackend_sql.h \
23 core/backends/odatebookaccessbackend_xml.h \ 24 core/backends/odatebookaccessbackend_xml.h \
24 core/backends/opimaccessbackend.h \ 25 core/backends/opimaccessbackend.h \
25 core/backends/opimaccesstemplate.h \ 26 core/backends/opimaccesstemplate.h \
26 core/backends/otodoaccessbackend.h \ 27 core/backends/otodoaccessbackend.h \
27 core/backends/otodoaccess.h \ 28 core/backends/otodoaccess.h \
28 core/backends/otodoaccesssql.h \ 29 core/backends/otodoaccesssql.h \
29 core/backends/otodoaccessvcal.h \ 30 core/backends/otodoaccessvcal.h \
30 core/backends/otodoaccessxml.h \ 31 core/backends/otodoaccessxml.h \
31 core/backends/odatebookaccess.h 32 core/backends/odatebookaccess.h \
33 core/backends/private/xmltree.h
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index f121cc2..d16d692 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -1,97 +1,97 @@
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 * 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#include <qarray.h> 35#include <qarray.h>
36#include <qdatetime.h> 36#include <qdatetime.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38 38
39#include <qpe/global.h> 39#include <qpe/global.h>
40#include <qpe/recordfields.h> 40#include <qpe/recordfields.h>
41 41
42#include <opie2/opimcontactfields.h> 42#include <opie2/opimcontactfields.h>
43#include <opie2/opimdateconversion.h> 43#include <opie2/opimdateconversion.h>
44#include <opie2/osqldriver.h> 44#include <opie2/osqldriver.h>
45#include <opie2/osqlresult.h> 45#include <opie2/osqlresult.h>
46#include <opie2/osqlmanager.h> 46#include <opie2/osqlmanager.h>
47#include <opie2/osqlquery.h> 47#include <opie2/osqlquery.h>
48 48
49 49using namespace Opie::DB;
50 50
51 51
52// If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead 52// If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead
53// vertical like "uid, type, value". 53// vertical like "uid, type, value".
54// DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !! 54// DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !!
55#define __STORE_HORIZONTAL_ 55#define __STORE_HORIZONTAL_
56 56
57// Distinct loading is not very fast. If I expect that every person has just 57// Distinct loading is not very fast. If I expect that every person has just
58// one (and always one) 'Last Name', I can request all uid's for existing lastnames, 58// one (and always one) 'Last Name', I can request all uid's for existing lastnames,
59// which is faster.. 59// which is faster..
60// But this may not be true for all entries, like company contacts.. 60// But this may not be true for all entries, like company contacts..
61// The current AddressBook application handles this problem, but other may not.. (eilers) 61// The current AddressBook application handles this problem, but other may not.. (eilers)
62#define __USE_SUPERFAST_LOADQUERY 62#define __USE_SUPERFAST_LOADQUERY
63 63
64 64
65/* 65/*
66 * Implementation of used query types 66 * Implementation of used query types
67 * CREATE query 67 * CREATE query
68 * LOAD query 68 * LOAD query
69 * INSERT 69 * INSERT
70 * REMOVE 70 * REMOVE
71 * CLEAR 71 * CLEAR
72 */ 72 */
73namespace Opie { 73namespace Opie {
74 /** 74 /**
75 * CreateQuery for the Todolist Table 75 * CreateQuery for the Todolist Table
76 */ 76 */
77 class CreateQuery : public OSQLQuery { 77 class CreateQuery : public OSQLQuery {
78 public: 78 public:
79 CreateQuery(); 79 CreateQuery();
80 ~CreateQuery(); 80 ~CreateQuery();
81 QString query()const; 81 QString query()const;
82 }; 82 };
83 83
84 /** 84 /**
85 * Clears (delete) a Table 85 * Clears (delete) a Table
86 */ 86 */
87 class ClearQuery : public OSQLQuery { 87 class ClearQuery : public OSQLQuery {
88 public: 88 public:
89 ClearQuery(); 89 ClearQuery();
90 ~ClearQuery(); 90 ~ClearQuery();
91 QString query()const; 91 QString query()const;
92 92
93 }; 93 };
94 94
95 95
96 /** 96 /**
97 * LoadQuery 97 * LoadQuery
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
index 58ae2ae..ba122ec 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
@@ -1,109 +1,113 @@
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 */
43namespace Opie {
44namespace DB {
43class OSQLDriver; 45class OSQLDriver;
44class OSQLResult; 46class OSQLResult;
45class OSQLResultItem; 47class OSQLResultItem;
48}
49}
46 50
47namespace Opie { 51namespace Opie {
48 52
49/* the default xml implementation */ 53/* the default xml implementation */
50/** 54/**
51 * This class is the SQL implementation of a Contact backend 55 * This class is the SQL implementation of a Contact backend
52 * it does implement everything available for OPimContact. 56 * it does implement everything available for OPimContact.
53 * @see OPimAccessBackend for more information of available methods 57 * @see OPimAccessBackend for more information of available methods
54 */ 58 */
55class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { 59class OPimContactAccessBackend_SQL : public OPimContactAccessBackend {
56 public: 60 public:
57 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); 61 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null );
58 62
59 ~OPimContactAccessBackend_SQL (); 63 ~OPimContactAccessBackend_SQL ();
60 64
61 bool save(); 65 bool save();
62 66
63 bool load (); 67 bool load ();
64 68
65 void clear (); 69 void clear ();
66 70
67 bool wasChangedExternally(); 71 bool wasChangedExternally();
68 72
69 QArray<int> allRecords() const; 73 QArray<int> allRecords() const;
70 74
71 OPimContact find ( int uid ) const; 75 OPimContact find ( int uid ) const;
72 // FIXME: Add lookahead-cache support ! 76 // FIXME: Add lookahead-cache support !
73 //OPimContact find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; 77 //OPimContact find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
74 78
75 QArray<int> queryByExample ( const OPimContact &query, int settings, 79 QArray<int> queryByExample ( const OPimContact &query, int settings,
76 const QDateTime& d ); 80 const QDateTime& d );
77 81
78 QArray<int> matchRegexp( const QRegExp &r ) const; 82 QArray<int> matchRegexp( const QRegExp &r ) const;
79 83
80 const uint querySettings(); 84 const uint querySettings();
81 85
82 bool hasQuerySettings (uint querySettings) const; 86 bool hasQuerySettings (uint querySettings) const;
83 87
84 // Currently only asc implemented.. 88 // Currently only asc implemented..
85 QArray<int> sorted( bool asc, int , int , int ); 89 QArray<int> sorted( bool asc, int , int , int );
86 bool add ( const OPimContact &newcontact ); 90 bool add ( const OPimContact &newcontact );
87 91
88 bool replace ( const OPimContact &contact ); 92 bool replace ( const OPimContact &contact );
89 93
90 bool remove ( int uid ); 94 bool remove ( int uid );
91 bool reload(); 95 bool reload();
92 96
93 private: 97 private:
94 QArray<int> extractUids( OSQLResult& res ) const; 98 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
95 QMap<int, QString> requestNonCustom( int uid ) const; 99 QMap<int, QString> requestNonCustom( int uid ) const;
96 QMap<QString, QString> requestCustom( int uid ) const; 100 QMap<QString, QString> requestCustom( int uid ) const;
97 void update(); 101 void update();
98 102
99 protected: 103 protected:
100 bool m_changed; 104 bool m_changed;
101 QString m_fileName; 105 QString m_fileName;
102 QArray<int> m_uids; 106 QArray<int> m_uids;
103 107
104 OSQLDriver* m_driver; 108 Opie::DB::OSQLDriver* m_driver;
105}; 109};
106 110
107} 111}
108 112
109#endif 113#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 5d92b8f..f5e76d5 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -1,99 +1,100 @@
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 * XML Backend for the OPIE-Contact Database. 30 * XML Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#include <opie2/ocontactaccessbackend_xml.h> 33#include <opie2/ocontactaccessbackend_xml.h>
34 34
35#include <qasciidict.h> 35#include <qasciidict.h>
36#include <qfile.h> 36#include <qfile.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qarray.h> 39#include <qarray.h>
40#include <qmap.h> 40#include <qmap.h>
41 41
42#include <qpe/global.h> 42#include <qpe/global.h>
43 43
44#include <opie2/xmltree.h> 44#include "private/xmltree.h"
45#include <opie2/ocontactaccessbackend.h> 45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/ocontactaccess.h> 46#include <opie2/ocontactaccess.h>
47 47
48#include <stdlib.h> 48#include <stdlib.h>
49#include <errno.h> 49#include <errno.h>
50 50
51using namespace Opie; 51using namespace Opie;
52using namespace Opie::Pim::Private;
52 53
53 54
54namespace Opie { 55namespace Opie {
55OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 56OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
56 m_changed( false ) 57 m_changed( false )
57{ 58{
58 // Just m_contactlist should call delete if an entry 59 // Just m_contactlist should call delete if an entry
59 // is removed. 60 // is removed.
60 m_contactList.setAutoDelete( true ); 61 m_contactList.setAutoDelete( true );
61 m_uidToContact.setAutoDelete( false ); 62 m_uidToContact.setAutoDelete( false );
62 63
63 m_appName = appname; 64 m_appName = appname;
64 65
65 /* Set journalfile name ... */ 66 /* Set journalfile name ... */
66 m_journalName = getenv("HOME"); 67 m_journalName = getenv("HOME");
67 m_journalName +="/.abjournal" + appname; 68 m_journalName +="/.abjournal" + appname;
68 69
69 /* Expecting to access the default filename if nothing else is set */ 70 /* Expecting to access the default filename if nothing else is set */
70 if ( filename.isEmpty() ){ 71 if ( filename.isEmpty() ){
71 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 72 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
72 } else 73 } else
73 m_fileName = filename; 74 m_fileName = filename;
74 75
75 /* Load Database now */ 76 /* Load Database now */
76 load (); 77 load ();
77} 78}
78 79
79bool OPimContactAccessBackend_XML::save() 80bool OPimContactAccessBackend_XML::save()
80{ 81{
81 82
82 if ( !m_changed ) 83 if ( !m_changed )
83 return true; 84 return true;
84 85
85 QString strNewFile = m_fileName + ".new"; 86 QString strNewFile = m_fileName + ".new";
86 QFile f( strNewFile ); 87 QFile f( strNewFile );
87 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 88 if ( !f.open( IO_WriteOnly|IO_Raw ) )
88 return false; 89 return false;
89 90
90 int total_written; 91 int total_written;
91 int idx_offset = 0; 92 int idx_offset = 0;
92 QString out; 93 QString out;
93 94
94 // Write Header 95 // Write Header
95 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 96 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
96 " <Groups>\n" 97 " <Groups>\n"
97 " </Groups>\n" 98 " </Groups>\n"
98 " <Contacts>\n"; 99 " <Contacts>\n";
99 QCString cstr = out.utf8(); 100 QCString cstr = out.utf8();
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 2ee76cc..a779dc1 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -1,96 +1,98 @@
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-Calender Database. 30 * SQL Backend for the OPIE-Calender Database.
31 * 31 *
32 */ 32 */
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include <qarray.h> 37#include <qarray.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39 39
40#include <qpe/global.h> 40#include <qpe/global.h>
41 41
42#include <opie2/osqldriver.h> 42#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 43#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 44#include <opie2/osqlquery.h>
45 45
46#include <opie2/opimrecurrence.h> 46#include <opie2/opimrecurrence.h>
47#include <opie2/odatebookaccessbackend_sql.h> 47#include <opie2/odatebookaccessbackend_sql.h>
48 48
49using namespace Opie::DB;
50
49namespace Opie { 51namespace Opie {
50 52
51 53
52ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 54ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
53 const QString& fileName ) 55 const QString& fileName )
54 : ODateBookAccessBackend(), m_driver( NULL ) 56 : ODateBookAccessBackend(), m_driver( NULL )
55{ 57{
56 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 58 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
57 59
58 // Get the standart sql-driver from the OSQLManager.. 60 // Get the standart sql-driver from the OSQLManager..
59 OSQLManager man; 61 OSQLManager man;
60 m_driver = man.standard(); 62 m_driver = man.standard();
61 m_driver->setUrl( m_fileName ); 63 m_driver->setUrl( m_fileName );
62 64
63 initFields(); 65 initFields();
64 66
65 load(); 67 load();
66} 68}
67 69
68ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 70ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
69 if( m_driver ) 71 if( m_driver )
70 delete m_driver; 72 delete m_driver;
71} 73}
72 74
73void ODateBookAccessBackend_SQL::initFields() 75void ODateBookAccessBackend_SQL::initFields()
74{ 76{
75 77
76 // This map contains the translation of the fieldtype id's to 78 // This map contains the translation of the fieldtype id's to
77 // the names of the table columns 79 // the names of the table columns
78 m_fieldMap.insert( OPimEvent::FUid, "uid" ); 80 m_fieldMap.insert( OPimEvent::FUid, "uid" );
79 m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); 81 m_fieldMap.insert( OPimEvent::FCategories, "Categories" );
80 m_fieldMap.insert( OPimEvent::FDescription, "Description" ); 82 m_fieldMap.insert( OPimEvent::FDescription, "Description" );
81 m_fieldMap.insert( OPimEvent::FLocation, "Location" ); 83 m_fieldMap.insert( OPimEvent::FLocation, "Location" );
82 m_fieldMap.insert( OPimEvent::FType, "Type" ); 84 m_fieldMap.insert( OPimEvent::FType, "Type" );
83 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); 85 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" );
84 m_fieldMap.insert( OPimEvent::FSound, "Sound" ); 86 m_fieldMap.insert( OPimEvent::FSound, "Sound" );
85 m_fieldMap.insert( OPimEvent::FRType, "RType" ); 87 m_fieldMap.insert( OPimEvent::FRType, "RType" );
86 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); 88 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" );
87 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); 89 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" );
88 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); 90 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" );
89 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); 91 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" );
90 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); 92 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" );
91 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); 93 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" );
92 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); 94 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" );
93 m_fieldMap.insert( OPimEvent::FStart, "Start" ); 95 m_fieldMap.insert( OPimEvent::FStart, "Start" );
94 m_fieldMap.insert( OPimEvent::FEnd, "End" ); 96 m_fieldMap.insert( OPimEvent::FEnd, "End" );
95 m_fieldMap.insert( OPimEvent::FNote, "Note" ); 97 m_fieldMap.insert( OPimEvent::FNote, "Note" );
96 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); 98 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" );
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index cbfeb97..60d7f21 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -1,93 +1,97 @@
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_SQL__H 29#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H
30#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H 30#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H
31 31
32#include <qmap.h> 32#include <qmap.h>
33#include <opie2/osqlresult.h> 33#include <opie2/osqlresult.h>
34 34
35#include <opie2/odatebookaccessbackend.h> 35#include <opie2/odatebookaccessbackend.h>
36 36
37namespace Opie {
38namespace DB {
37class OSQLDriver; 39class OSQLDriver;
40}
41}
38 42
39namespace Opie { 43namespace Opie {
40/** 44/**
41 * This is the default SQL implementation for DateBoook SQL storage 45 * This is the default SQL implementation for DateBoook SQL storage
42 * It fully implements the interface 46 * It fully implements the interface
43 * @see ODateBookAccessBackend 47 * @see ODateBookAccessBackend
44 * @see OPimAccessBackend 48 * @see OPimAccessBackend
45 */ 49 */
46class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { 50class ODateBookAccessBackend_SQL : public ODateBookAccessBackend {
47public: 51public:
48 ODateBookAccessBackend_SQL( const QString& appName, 52 ODateBookAccessBackend_SQL( const QString& appName,
49 const QString& fileName = QString::null); 53 const QString& fileName = QString::null);
50 ~ODateBookAccessBackend_SQL(); 54 ~ODateBookAccessBackend_SQL();
51 55
52 bool load(); 56 bool load();
53 bool reload(); 57 bool reload();
54 bool save(); 58 bool save();
55 59
56 QArray<int> allRecords()const; 60 QArray<int> allRecords()const;
57 QArray<int> matchRegexp(const QRegExp &r) const; 61 QArray<int> matchRegexp(const QRegExp &r) const;
58 QArray<int> queryByExample( const OPimEvent&, int, const QDateTime& d = QDateTime() ); 62 QArray<int> queryByExample( const OPimEvent&, int, const QDateTime& d = QDateTime() );
59 OPimEvent find( int uid )const; 63 OPimEvent find( int uid )const;
60 void clear(); 64 void clear();
61 bool add( const OPimEvent& ev ); 65 bool add( const OPimEvent& ev );
62 bool remove( int uid ); 66 bool remove( int uid );
63 bool replace( const OPimEvent& ev ); 67 bool replace( const OPimEvent& ev );
64 68
65 QArray<UID> rawEvents()const; 69 QArray<UID> rawEvents()const;
66 QArray<UID> rawRepeats()const; 70 QArray<UID> rawRepeats()const;
67 QArray<UID> nonRepeats()const; 71 QArray<UID> nonRepeats()const;
68 72
69 OPimEvent::ValueList directNonRepeats(); 73 OPimEvent::ValueList directNonRepeats();
70 OPimEvent::ValueList directRawRepeats(); 74 OPimEvent::ValueList directRawRepeats();
71 75
72private: 76private:
73 bool loadFile(); 77 bool loadFile();
74 QString m_fileName; 78 QString m_fileName;
75 QArray<int> m_uids; 79 QArray<int> m_uids;
76 80
77 QMap<int, QString> m_fieldMap; 81 QMap<int, QString> m_fieldMap;
78 QMap<QString, int> m_reverseFieldMap; 82 QMap<QString, int> m_reverseFieldMap;
79 83
80 OSQLDriver* m_driver; 84 Opie::DB::OSQLDriver* m_driver;
81 85
82 class Private; 86 class Private;
83 Private *d; 87 Private *d;
84 88
85 void initFields(); 89 void initFields();
86 void update(); 90 void update();
87 QArray<int> extractUids( OSQLResult& res ) const; 91 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
88 92
89}; 93};
90 94
91} 95}
92 96
93#endif 97#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 72232e5..d218090 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -1,91 +1,93 @@
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#include <qdatetime.h> 30#include <qdatetime.h>
31 31
32#include <qpe/global.h> 32#include <qpe/global.h>
33 33
34#include <opie2/osqldriver.h> 34#include <opie2/osqldriver.h>
35#include <opie2/osqlresult.h> 35#include <opie2/osqlresult.h>
36#include <opie2/osqlmanager.h> 36#include <opie2/osqlmanager.h>
37#include <opie2/osqlquery.h> 37#include <opie2/osqlquery.h>
38 38
39#include <opie2/otodoaccesssql.h> 39#include <opie2/otodoaccesssql.h>
40#include <opie2/opimstate.h> 40#include <opie2/opimstate.h>
41#include <opie2/opimnotifymanager.h> 41#include <opie2/opimnotifymanager.h>
42#include <opie2/opimrecurrence.h> 42#include <opie2/opimrecurrence.h>
43 43
44using namespace Opie::DB;
45
44using namespace Opie; 46using namespace Opie;
45/* 47/*
46 * first some query 48 * first some query
47 * CREATE query 49 * CREATE query
48 * LOAD query 50 * LOAD query
49 * INSERT 51 * INSERT
50 * REMOVE 52 * REMOVE
51 * CLEAR 53 * CLEAR
52 */ 54 */
53namespace { 55namespace {
54 /** 56 /**
55 * CreateQuery for the Todolist Table 57 * CreateQuery for the Todolist Table
56 */ 58 */
57 class CreateQuery : public OSQLQuery { 59 class CreateQuery : public OSQLQuery {
58 public: 60 public:
59 CreateQuery(); 61 CreateQuery();
60 ~CreateQuery(); 62 ~CreateQuery();
61 QString query()const; 63 QString query()const;
62 }; 64 };
63 65
64 /** 66 /**
65 * LoadQuery 67 * LoadQuery
66 * this one queries for all uids 68 * this one queries for all uids
67 */ 69 */
68 class LoadQuery : public OSQLQuery { 70 class LoadQuery : public OSQLQuery {
69 public: 71 public:
70 LoadQuery(); 72 LoadQuery();
71 ~LoadQuery(); 73 ~LoadQuery();
72 QString query()const; 74 QString query()const;
73 }; 75 };
74 76
75 /** 77 /**
76 * inserts/adds a OPimTodo to the table 78 * inserts/adds a OPimTodo to the table
77 */ 79 */
78 class InsertQuery : public OSQLQuery { 80 class InsertQuery : public OSQLQuery {
79 public: 81 public:
80 InsertQuery(const OPimTodo& ); 82 InsertQuery(const OPimTodo& );
81 ~InsertQuery(); 83 ~InsertQuery();
82 QString query()const; 84 QString query()const;
83 private: 85 private:
84 OPimTodo m_todo; 86 OPimTodo m_todo;
85 }; 87 };
86 88
87 /** 89 /**
88 * removes one from the table 90 * removes one from the table
89 */ 91 */
90 class RemoveQuery : public OSQLQuery { 92 class RemoveQuery : public OSQLQuery {
91 public: 93 public:
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index e945863..0ae2591 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -1,88 +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) 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
36namespace Opie {
37namespace DB {
36class OSQLDriver; 38class OSQLDriver;
37class OSQLResult; 39class OSQLResult;
38class OSQLResultItem; 40class OSQLResultItem;
41}
42}
39 43
40namespace Opie { 44namespace Opie {
41 45
42class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend { 46class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend {
43public: 47public:
44 OPimTodoAccessBackendSQL( const QString& file ); 48 OPimTodoAccessBackendSQL( const QString& file );
45 ~OPimTodoAccessBackendSQL(); 49 ~OPimTodoAccessBackendSQL();
46 50
47 bool load(); 51 bool load();
48 bool reload(); 52 bool reload();
49 bool save(); 53 bool save();
50 QArray<int> allRecords()const; 54 QArray<int> allRecords()const;
51 55
52 QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); 56 QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
53 OPimTodo find(int uid)const; 57 OPimTodo find(int uid)const;
54 OPimTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; 58 OPimTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
55 void clear(); 59 void clear();
56 bool add( const OPimTodo& t ); 60 bool add( const OPimTodo& t );
57 bool remove( int uid ); 61 bool remove( int uid );
58 bool replace( const OPimTodo& t ); 62 bool replace( const OPimTodo& t );
59 63
60 QArray<int> overDue(); 64 QArray<int> overDue();
61 QArray<int> effectiveToDos( const QDate& start, 65 QArray<int> effectiveToDos( const QDate& start,
62 const QDate& end, bool includeNoDates ); 66 const QDate& end, bool includeNoDates );
63 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 67 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
64 68
65 QBitArray supports()const; 69 QBitArray supports()const;
66 QArray<int> matchRegexp( const QRegExp &r ) const; 70 QArray<int> matchRegexp( const QRegExp &r ) const;
67 void removeAllCompleted(); 71 void removeAllCompleted();
68 72
69 73
70private: 74private:
71 void update()const; 75 void update()const;
72 void fillDict(); 76 void fillDict();
73 inline bool date( QDate& date, const QString& )const; 77 inline bool date( QDate& date, const QString& )const;
74 inline OPimTodo todo( const OSQLResult& )const; 78 inline OPimTodo todo( const Opie::DB::OSQLResult& )const;
75 inline OPimTodo todo( OSQLResultItem& )const; 79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const;
76 inline QArray<int> uids( const OSQLResult& )const; 80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const;
77 OPimTodo todo( int uid )const; 81 OPimTodo todo( int uid )const;
78 QBitArray sup() const; 82 QBitArray sup() const;
79 83
80 QAsciiDict<int> m_dict; 84 QAsciiDict<int> m_dict;
81 OSQLDriver* m_driver; 85 Opie::DB::OSQLDriver* m_driver;
82 QArray<int> m_uids; 86 QArray<int> m_uids;
83 bool m_dirty : 1; 87 bool m_dirty : 1;
84}; 88};
85 89
86} 90}
87 91
88#endif 92#endif
diff --git a/libopie2/opiepim/core/backends/private/xmltree.cc b/libopie2/opiepim/core/backends/private/xmltree.cc
new file mode 100644
index 0000000..40749ca
--- a/dev/null
+++ b/libopie2/opiepim/core/backends/private/xmltree.cc
@@ -0,0 +1,323 @@
1/* This file is part of the KDE project
2 Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20#include "xmltree.h"
21
22#include <qpe/stringutil.h>
23
24#include <qxml.h>
25
26#include <assert.h>
27
28using namespace Opie::Pim::Private;
29
30XMLElement::XMLElement()
31 : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 )
32{
33}
34
35XMLElement::~XMLElement()
36{
37 XMLElement *n = m_first;
38
39 while ( n )
40 {
41 XMLElement *tmp = n;
42 n = n->m_next;
43 delete tmp;
44 }
45}
46
47void XMLElement::appendChild( XMLElement *child )
48{
49 if ( child->m_parent )
50 child->m_parent->removeChild( child );
51
52 child->m_parent = this;
53
54 if ( m_last )
55 m_last->m_next = child;
56
57 child->m_prev = m_last;
58
59 if ( !m_first )
60 m_first = child;
61
62 m_last = child;
63}
64
65void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild )
66{
67 assert( newChild != refChild );
68
69 if ( refChild == m_last )
70 {
71 appendChild( newChild );
72 return;
73 }
74
75 assert( refChild );
76 assert( refChild->m_parent );
77 assert( refChild->m_parent == this );
78
79 if ( newChild->m_parent && newChild != refChild )
80 newChild->m_parent->removeChild( newChild );
81
82 newChild->m_parent = this;
83
84 XMLElement *next = refChild->m_next;
85
86 refChild->m_next = newChild;
87
88 newChild->m_prev = refChild;
89 newChild->m_next = next;
90
91 if ( next )
92 next->m_prev = newChild;
93}
94
95QString XMLElement::attribute( const QString &attr ) const
96{
97 AttributeMap::ConstIterator it = m_attributes.find( attr );
98 if ( it == m_attributes.end() )
99 return QString::null;
100 return it.data();
101}
102
103void XMLElement::setAttribute( const QString &attr, const QString &value )
104{
105 m_attributes.replace( attr, value );
106}
107
108void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild )
109{
110 assert( refChild );
111 assert( refChild->m_parent );
112 assert( refChild->m_parent == this );
113 assert( newChild != refChild );
114
115 if ( newChild->m_parent && newChild != refChild )
116 newChild->m_parent->removeChild( newChild );
117
118 newChild->m_parent = this;
119
120 XMLElement *prev = refChild->m_prev;
121
122 refChild->m_prev = newChild;
123
124 newChild->m_prev = prev;
125 newChild->m_next = refChild;
126
127 if ( prev )
128 prev->m_next = newChild;
129
130 if ( refChild == m_first )
131 m_first = newChild;
132}
133
134void XMLElement::removeChild( XMLElement *child )
135{
136 if ( child->m_parent != this )
137 return;
138
139 if ( m_first == child )
140 m_first = child->m_next;
141
142 if ( m_last == child )
143 m_last = child->m_prev;
144
145 if ( child->m_prev )
146 child->m_prev->m_next = child->m_next;
147
148 if ( child->m_next )
149 child->m_next->m_prev = child->m_prev;
150
151 child->m_parent = 0;
152 child->m_prev = 0;
153 child->m_next = 0;
154}
155
156void XMLElement::save( QTextStream &s, uint indent )
157{
158 if ( !m_value.isEmpty() )
159 {
160 s << Qtopia::escapeString( m_value );
161 return;
162 }
163
164 for ( uint i = 0; i < indent; ++i )
165 s << " ";
166
167 s << "<" << m_tag;
168
169 if ( !m_attributes.isEmpty() )
170 {
171 s << " ";
172 AttributeMap::ConstIterator it = m_attributes.begin();
173 AttributeMap::ConstIterator end = m_attributes.end();
174 for (; it != end; ++it )
175 {
176 s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\"";
177 s << " ";
178 }
179 }
180
181 if ( m_last )
182 {
183 if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent )
184 s << ">";
185 else
186 s << ">" << endl;
187
188 int newIndent = indent;
189 if ( m_parent )
190 newIndent++;
191
192 XMLElement *n = m_first;
193 while ( n )
194 {
195 n->save( s, newIndent );
196 n = n->nextChild();
197 }
198
199 if ( m_last && m_last->value().isEmpty() && m_parent )
200 for ( uint i = 0; i < indent; ++i )
201 s << " ";
202
203 if ( m_parent )
204 s << "</" << m_tag << ">" << endl;
205 }
206 else
207 s << "/>" << endl;
208}
209
210class Handler : public QXmlDefaultHandler
211{
212public:
213 Handler() : m_node( 0 ), m_root( 0 ) {}
214
215 XMLElement *root() const { return m_root; }
216
217 virtual bool startDocument();
218 virtual bool endDocument();
219 virtual bool startElement( const QString &ns, const QString &ln, const QString &qName,
220 const QXmlAttributes &attr );
221 virtual bool endElement( const QString &ns, const QString &ln, const QString &qName );
222 virtual bool characters( const QString &ch );
223
224private:
225 XMLElement *m_node;
226 XMLElement *m_root;
227};
228
229bool Handler::startDocument()
230{
231 m_root = m_node = new XMLElement;
232
233 return true;
234}
235
236bool Handler::endDocument()
237{
238 return m_root == m_node;
239}
240
241bool Handler::startElement( const QString &, const QString &, const QString &qName,
242 const QXmlAttributes &attr )
243{
244 XMLElement *bm = new XMLElement;
245
246 XMLElement::AttributeMap attributes;
247 for ( int i = 0; i < attr.length(); ++i )
248 attributes[ attr.qName( i ) ] = attr.value( i );
249
250 bm->setAttributes( attributes );
251
252 bm->setTagName( qName );
253
254 m_node->appendChild( bm );
255 m_node = bm;
256
257 return true;
258}
259
260bool Handler::endElement( const QString &, const QString &, const QString & )
261{
262 if ( m_node == m_root )
263 return false;
264
265 m_node = m_node->parent();
266 return true;
267}
268
269bool Handler::characters( const QString &ch )
270{
271 XMLElement *textNode = new XMLElement;
272 textNode->setValue( ch );
273 m_node->appendChild( textNode );
274 return true;
275}
276
277XMLElement *XMLElement::namedItem( const QString &name )
278{
279 XMLElement *e = m_first;
280
281 for (; e; e = e->nextChild() )
282 if ( e->tagName() == name )
283 return e;
284
285 return 0;
286}
287
288XMLElement *XMLElement::clone() const
289{
290 XMLElement *res = new XMLElement;
291
292 res->setTagName( m_tag );
293 res->setValue( m_value );
294 res->setAttributes( m_attributes );
295
296 XMLElement *e = m_first;
297 for (; e; e = e->m_next )
298 res->appendChild( e->clone() );
299
300 return res;
301}
302
303XMLElement *XMLElement::load( const QString &fileName )
304{
305 QFile f( fileName );
306 if ( !f.open( IO_ReadOnly ) )
307 return 0;
308
309 QTextStream stream( &f );
310 stream.setEncoding( QTextStream::UnicodeUTF8 );
311 QXmlInputSource src( stream );
312 QXmlSimpleReader reader;
313 Handler handler;
314
315 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false );
316 reader.setContentHandler( &handler );
317 reader.parse( src );
318
319 return handler.root();;
320}
321
322/* vim: et sw=4
323 */
diff --git a/libopie2/opiepim/core/backends/private/xmltree.h b/libopie2/opiepim/core/backends/private/xmltree.h
new file mode 100644
index 0000000..9817a02
--- a/dev/null
+++ b/libopie2/opiepim/core/backends/private/xmltree.h
@@ -0,0 +1,122 @@
1/* This file is part of the KDE project
2 Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20
21#ifndef __bookmarks_h__
22#define __bookmarks_h__
23
24#include <qstring.h>
25#include <qmap.h>
26#include <qtextstream.h>
27
28namespace Opie {
29namespace Pim {
30namespace Private{
31
32/**
33 * A small xml lib written by Simon Hausmann.
34 */
35class XMLElement
36{
37public:
38 typedef QMap<QString, QString> AttributeMap;
39
40 /**
41 * The constructor of XMLElement
42 */
43 XMLElement();
44 ~XMLElement();
45
46 /** appendChild appends a child to the XMLElement behind the last element.
47 * The ownership of the child get's transfered to the
48 * this XMLElement.
49 * If child is already the child of another parent
50 * it's get removed from the other parent first.
51 */
52 void appendChild( XMLElement *child );
53
54 /** inserts newChild after refChild. If newChild is the child
55 * of another parent the child will get removed.
56 * The ownership of child gets transfered.
57 *
58 */
59 void insertAfter( XMLElement *newChild, XMLElement *refChild );
60
61 /** same as insertAfter but the element get's inserted before refChild.
62 *
63 */
64 void insertBefore( XMLElement *newChild, XMLElement *refChild );
65
66 /** removeChild removes the child from the XMLElement.
67 * The ownership gets dropped. You need to delete the
68 * child yourself.
69 */
70 void removeChild( XMLElement *child );
71
72 /** parent() returns the parent of this XMLElement
73 * If there is no parent 0l gets returned
74 */
75 XMLElement *parent() const { return m_parent; }
76 XMLElement *firstChild() const { return m_first; }
77 XMLElement *nextChild() const { return m_next; }
78 XMLElement *prevChild() const { return m_prev; }
79 XMLElement *lastChild() const { return m_last; }
80
81 void setTagName( const QString &tag ) { m_tag = tag; }
82 QString tagName() const { return m_tag; }
83
84 void setValue( const QString &val ) { m_value = val; }
85 QString value() const { return m_value; }
86
87 void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; }
88 AttributeMap attributes() const { return m_attributes; }
89 AttributeMap &attributes() { return m_attributes; }
90
91 QString attribute( const QString & ) const;
92 void setAttribute( const QString &attr, const QString &value );
93 void save( QTextStream &stream, uint indent = 0 );
94
95 XMLElement *namedItem( const QString &name );
96
97 XMLElement *clone() const;
98
99 static XMLElement *load( const QString &fileName );
100
101private:
102 QString m_tag;
103 QString m_value;
104 AttributeMap m_attributes;
105
106 XMLElement *m_parent;
107 XMLElement *m_next;
108 XMLElement *m_prev;
109 XMLElement *m_first;
110 XMLElement *m_last;
111
112 XMLElement( const XMLElement &rhs );
113 XMLElement &operator=( const XMLElement &rhs );
114 class Private;
115 Private* d;
116};
117
118}
119}
120} // namespace Opie
121
122#endif