Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 4a5cb33..2d50ecd 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,116 +1,147 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <errno.h> | 29 | #include <errno.h> |
2 | #include <fcntl.h> | 30 | #include <fcntl.h> |
3 | 31 | ||
4 | #include <sys/mman.h> | 32 | #include <sys/mman.h> |
5 | #include <sys/stat.h> | 33 | #include <sys/stat.h> |
6 | #include <sys/types.h> | 34 | #include <sys/types.h> |
7 | 35 | ||
8 | #include <unistd.h> | 36 | #include <unistd.h> |
9 | 37 | ||
10 | 38 | ||
11 | #include <qfile.h> | 39 | #include <qfile.h> |
12 | #include <qvector.h> | 40 | #include <qvector.h> |
13 | 41 | ||
14 | #include <qpe/global.h> | 42 | #include <qpe/global.h> |
15 | #include <qpe/stringutil.h> | 43 | #include <qpe/stringutil.h> |
16 | #include <qpe/timeconversion.h> | 44 | #include <qpe/timeconversion.h> |
17 | 45 | ||
18 | #include "oconversion.h" | 46 | #include <opie2/oconversion.h> |
19 | #include "opimstate.h" | 47 | #include <opie2/opimstate.h> |
20 | #include "otimezone.h" | 48 | #include <opie2/otimezone.h> |
21 | #include "opimnotifymanager.h" | 49 | #include <opie2/opimnotifymanager.h> |
22 | #include "orecur.h" | 50 | #include <opie2/orecur.h> |
23 | #include "otodoaccessxml.h" | 51 | #include <opie2/otodoaccessxml.h> |
52 | |||
53 | using namespace Opie; | ||
24 | 54 | ||
25 | namespace { | 55 | namespace { |
26 | time_t rp_end; | 56 | time_t rp_end; |
27 | ORecur* rec; | 57 | ORecur* rec; |
28 | ORecur *recur() { | 58 | ORecur *recur() { |
29 | if (!rec ) rec = new ORecur; | 59 | if (!rec ) rec = new ORecur; |
30 | return rec; | 60 | return rec; |
31 | } | 61 | } |
32 | int snd; | 62 | int snd; |
33 | enum MoreAttributes { | 63 | enum MoreAttributes { |
34 | FRType = OTodo::CompletedDate + 2, | 64 | FRType = OTodo::CompletedDate + 2, |
35 | FRWeekdays, | 65 | FRWeekdays, |
36 | FRPosition, | 66 | FRPosition, |
37 | FRFreq, | 67 | FRFreq, |
38 | FRHasEndDate, | 68 | FRHasEndDate, |
39 | FREndDate, | 69 | FREndDate, |
40 | FRStart, | 70 | FRStart, |
41 | FREnd | 71 | FREnd |
42 | }; | 72 | }; |
43 | // FROM TT again | 73 | // FROM TT again |
44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 74 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
45 | { | 75 | { |
46 | char needleChar; | 76 | char needleChar; |
47 | char haystackChar; | 77 | char haystackChar; |
48 | if (!needle || !haystack || !hLen || !nLen) | 78 | if (!needle || !haystack || !hLen || !nLen) |
49 | return 0; | 79 | return 0; |
50 | 80 | ||
51 | const char* hsearch = haystack; | 81 | const char* hsearch = haystack; |
52 | 82 | ||
53 | if ((needleChar = *needle++) != 0) { | 83 | if ((needleChar = *needle++) != 0) { |
54 | nLen--; //(to make up for needle++) | 84 | nLen--; //(to make up for needle++) |
55 | do { | 85 | do { |
56 | do { | 86 | do { |
57 | if ((haystackChar = *hsearch++) == 0) | 87 | if ((haystackChar = *hsearch++) == 0) |
58 | return (0); | 88 | return (0); |
59 | if (hsearch >= haystack + hLen) | 89 | if (hsearch >= haystack + hLen) |
60 | return (0); | 90 | return (0); |
61 | } while (haystackChar != needleChar); | 91 | } while (haystackChar != needleChar); |
62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 92 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
63 | hsearch--; | 93 | hsearch--; |
64 | } | 94 | } |
65 | return ((char *)hsearch); | 95 | return ((char *)hsearch); |
66 | } | 96 | } |
67 | } | 97 | } |
68 | 98 | ||
99 | namespace Opie { | ||
69 | 100 | ||
70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 101 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
71 | const QString& fileName ) | 102 | const QString& fileName ) |
72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 103 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
73 | { | 104 | { |
74 | if (!fileName.isEmpty() ) | 105 | if (!fileName.isEmpty() ) |
75 | m_file = fileName; | 106 | m_file = fileName; |
76 | else | 107 | else |
77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 108 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
78 | } | 109 | } |
79 | OTodoAccessXML::~OTodoAccessXML() { | 110 | OTodoAccessXML::~OTodoAccessXML() { |
80 | 111 | ||
81 | } | 112 | } |
82 | bool OTodoAccessXML::load() { | 113 | bool OTodoAccessXML::load() { |
83 | rec = 0; | 114 | rec = 0; |
84 | m_opened = true; | 115 | m_opened = true; |
85 | m_changed = false; | 116 | m_changed = false; |
86 | /* initialize dict */ | 117 | /* initialize dict */ |
87 | /* | 118 | /* |
88 | * UPDATE dict if you change anything!!! | 119 | * UPDATE dict if you change anything!!! |
89 | */ | 120 | */ |
90 | QAsciiDict<int> dict(26); | 121 | QAsciiDict<int> dict(26); |
91 | dict.setAutoDelete( TRUE ); | 122 | dict.setAutoDelete( TRUE ); |
92 | dict.insert("Categories" , new int(OTodo::Category) ); | 123 | dict.insert("Categories" , new int(OTodo::Category) ); |
93 | dict.insert("Uid" , new int(OTodo::Uid) ); | 124 | dict.insert("Uid" , new int(OTodo::Uid) ); |
94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 125 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
95 | dict.insert("Completed" , new int(OTodo::Completed) ); | 126 | dict.insert("Completed" , new int(OTodo::Completed) ); |
96 | dict.insert("Description" , new int(OTodo::Description) ); | 127 | dict.insert("Description" , new int(OTodo::Description) ); |
97 | dict.insert("Summary" , new int(OTodo::Summary) ); | 128 | dict.insert("Summary" , new int(OTodo::Summary) ); |
98 | dict.insert("Priority" , new int(OTodo::Priority) ); | 129 | dict.insert("Priority" , new int(OTodo::Priority) ); |
99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 130 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 131 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 132 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
102 | dict.insert("Progress" , new int(OTodo::Progress) ); | 133 | dict.insert("Progress" , new int(OTodo::Progress) ); |
103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); | 134 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); |
104 | dict.insert("StartDate", new int(OTodo::StartDate) ); | 135 | dict.insert("StartDate", new int(OTodo::StartDate) ); |
105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 136 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
106 | dict.insert("State", new int(OTodo::State) ); | 137 | dict.insert("State", new int(OTodo::State) ); |
107 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 138 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
108 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 139 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 140 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 141 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
111 | dict.insert("rtype", new int(FRType) ); | 142 | dict.insert("rtype", new int(FRType) ); |
112 | dict.insert("rweekdays", new int(FRWeekdays) ); | 143 | dict.insert("rweekdays", new int(FRWeekdays) ); |
113 | dict.insert("rposition", new int(FRPosition) ); | 144 | dict.insert("rposition", new int(FRPosition) ); |
114 | dict.insert("rfreq", new int(FRFreq) ); | 145 | dict.insert("rfreq", new int(FRFreq) ); |
115 | dict.insert("start", new int(FRStart) ); | 146 | dict.insert("start", new int(FRStart) ); |
116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 147 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
@@ -829,48 +860,50 @@ QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | |||
829 | /* sort it now */ | 860 | /* sort it now */ |
830 | vector.sort(); | 861 | vector.sort(); |
831 | /* now get the uids */ | 862 | /* now get the uids */ |
832 | QArray<int> array( vector.count() ); | 863 | QArray<int> array( vector.count() ); |
833 | for (uint i= 0; i < vector.count(); i++ ) { | 864 | for (uint i= 0; i < vector.count(); i++ ) { |
834 | array[i] = ( vector.at(i) )->todo.uid(); | 865 | array[i] = ( vector.at(i) )->todo.uid(); |
835 | } | 866 | } |
836 | return array; | 867 | return array; |
837 | }; | 868 | }; |
838 | void OTodoAccessXML::removeAllCompleted() { | 869 | void OTodoAccessXML::removeAllCompleted() { |
839 | QMap<int, OTodo> events = m_events; | 870 | QMap<int, OTodo> events = m_events; |
840 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 871 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
841 | if ( (*it).isCompleted() ) | 872 | if ( (*it).isCompleted() ) |
842 | events.remove( it.key() ); | 873 | events.remove( it.key() ); |
843 | } | 874 | } |
844 | m_events = events; | 875 | m_events = events; |
845 | } | 876 | } |
846 | QBitArray OTodoAccessXML::supports()const { | 877 | QBitArray OTodoAccessXML::supports()const { |
847 | static QBitArray ar = sup(); | 878 | static QBitArray ar = sup(); |
848 | return ar; | 879 | return ar; |
849 | } | 880 | } |
850 | QBitArray OTodoAccessXML::sup() { | 881 | QBitArray OTodoAccessXML::sup() { |
851 | QBitArray ar( OTodo::CompletedDate +1 ); | 882 | QBitArray ar( OTodo::CompletedDate +1 ); |
852 | ar.fill( true ); | 883 | ar.fill( true ); |
853 | ar[OTodo::CrossReference] = false; | 884 | ar[OTodo::CrossReference] = false; |
854 | ar[OTodo::State ] = false; | 885 | ar[OTodo::State ] = false; |
855 | ar[OTodo::Reminders] = false; | 886 | ar[OTodo::Reminders] = false; |
856 | ar[OTodo::Notifiers] = false; | 887 | ar[OTodo::Notifiers] = false; |
857 | ar[OTodo::Maintainer] = false; | 888 | ar[OTodo::Maintainer] = false; |
858 | 889 | ||
859 | return ar; | 890 | return ar; |
860 | } | 891 | } |
861 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const | 892 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const |
862 | { | 893 | { |
863 | QArray<int> m_currentQuery( m_events.count() ); | 894 | QArray<int> m_currentQuery( m_events.count() ); |
864 | uint arraycounter = 0; | 895 | uint arraycounter = 0; |
865 | 896 | ||
866 | QMap<int, OTodo>::ConstIterator it; | 897 | QMap<int, OTodo>::ConstIterator it; |
867 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 898 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
868 | if ( it.data().match( r ) ) | 899 | if ( it.data().match( r ) ) |
869 | m_currentQuery[arraycounter++] = it.data().uid(); | 900 | m_currentQuery[arraycounter++] = it.data().uid(); |
870 | 901 | ||
871 | } | 902 | } |
872 | // Shrink to fit.. | 903 | // Shrink to fit.. |
873 | m_currentQuery.resize(arraycounter); | 904 | m_currentQuery.resize(arraycounter); |
874 | 905 | ||
875 | return m_currentQuery; | 906 | return m_currentQuery; |
876 | } | 907 | } |
908 | |||
909 | } | ||