summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index 929d004..0ebda98 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -1,47 +1,77 @@
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 <stdio.h> 32#include <stdio.h>
5#include <stdlib.h> 33#include <stdlib.h>
6 34
7#include <sys/types.h> 35#include <sys/types.h>
8#include <sys/mman.h> 36#include <sys/mman.h>
9#include <sys/stat.h> 37#include <sys/stat.h>
10 38
11#include <unistd.h> 39#include <unistd.h>
12 40
13#include <qasciidict.h> 41#include <qasciidict.h>
14#include <qfile.h> 42#include <qfile.h>
15 43
16#include <qtopia/global.h> 44#include <qtopia/global.h>
17#include <qtopia/stringutil.h> 45#include <qtopia/stringutil.h>
18#include <qtopia/timeconversion.h> 46#include <qtopia/timeconversion.h>
19 47
20#include "opimnotifymanager.h" 48#include <opie2/opimnotifymanager.h>
21#include "orecur.h" 49#include <opie2/orecur.h>
22#include "otimezone.h" 50#include <opie2/otimezone.h>
23#include "odatebookaccessbackend_xml.h" 51#include <opie2/odatebookaccessbackend_xml.h>
52
53using namespace Opie;
24 54
25namespace { 55namespace {
26 // FROM TT again 56 // FROM TT again
27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 57char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
28{ 58{
29 char needleChar; 59 char needleChar;
30 char haystackChar; 60 char haystackChar;
31 if (!needle || !haystack || !hLen || !nLen) 61 if (!needle || !haystack || !hLen || !nLen)
32 return 0; 62 return 0;
33 63
34 const char* hsearch = haystack; 64 const char* hsearch = haystack;
35 65
36 if ((needleChar = *needle++) != 0) { 66 if ((needleChar = *needle++) != 0) {
37 nLen--; //(to make up for needle++) 67 nLen--; //(to make up for needle++)
38 do { 68 do {
39 do { 69 do {
40 if ((haystackChar = *hsearch++) == 0) 70 if ((haystackChar = *hsearch++) == 0)
41 return (0); 71 return (0);
42 if (hsearch >= haystack + hLen) 72 if (hsearch >= haystack + hLen)
43 return (0); 73 return (0);
44 } while (haystackChar != needleChar); 74 } while (haystackChar != needleChar);
45 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 75 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
46 hsearch--; 76 hsearch--;
47 } 77 }
@@ -145,48 +175,49 @@ namespace {
145 } 175 }
146 176
147 // skip custom writing 177 // skip custom writing
148 } 178 }
149 179
150 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { 180 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) {
151 QMap<int, OEvent>::ConstIterator it; 181 QMap<int, OEvent>::ConstIterator it;
152 QString buf; 182 QString buf;
153 QCString str; 183 QCString str;
154 int total_written; 184 int total_written;
155 for ( it = list.begin(); it != list.end(); ++it ) { 185 for ( it = list.begin(); it != list.end(); ++it ) {
156 buf = "<event"; 186 buf = "<event";
157 save( it.data(), buf ); 187 save( it.data(), buf );
158 buf += " />\n"; 188 buf += " />\n";
159 str = buf.utf8(); 189 str = buf.utf8();
160 190
161 total_written = file.writeBlock(str.data(), str.length() ); 191 total_written = file.writeBlock(str.data(), str.length() );
162 if ( total_written != int(str.length() ) ) 192 if ( total_written != int(str.length() ) )
163 return false; 193 return false;
164 } 194 }
165 return true; 195 return true;
166 } 196 }
167} 197}
168 198
199namespace Opie {
169ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 200ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
170 const QString& fileName ) 201 const QString& fileName )
171 : ODateBookAccessBackend() { 202 : ODateBookAccessBackend() {
172 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; 203 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
173 m_changed = false; 204 m_changed = false;
174} 205}
175ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 206ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
176} 207}
177bool ODateBookAccessBackend_XML::load() { 208bool ODateBookAccessBackend_XML::load() {
178 return loadFile(); 209 return loadFile();
179} 210}
180bool ODateBookAccessBackend_XML::reload() { 211bool ODateBookAccessBackend_XML::reload() {
181 clear(); 212 clear();
182 return load(); 213 return load();
183} 214}
184bool ODateBookAccessBackend_XML::save() { 215bool ODateBookAccessBackend_XML::save() {
185 if (!m_changed) return true; 216 if (!m_changed) return true;
186 217
187 int total_written; 218 int total_written;
188 QString strFileNew = m_name + ".new"; 219 QString strFileNew = m_name + ".new";
189 220
190 QFile f( strFileNew ); 221 QFile f( strFileNew );
191 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; 222 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
192 223
@@ -589,24 +620,26 @@ void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& val
589 e.setTimeZone( value ); 620 e.setTimeZone( value );
590 break; 621 break;
591 default: 622 default:
592 break; 623 break;
593 } 624 }
594} 625}
595QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const 626QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const
596{ 627{
597 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); 628 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() );
598 uint arraycounter = 0; 629 uint arraycounter = 0;
599 QMap<int, OEvent>::ConstIterator it; 630 QMap<int, OEvent>::ConstIterator it;
600 631
601 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) 632 for ( it = m_raw.begin(); it != m_raw.end(); ++it )
602 if ( it.data().match( r ) ) 633 if ( it.data().match( r ) )
603 m_currentQuery[arraycounter++] = it.data().uid(); 634 m_currentQuery[arraycounter++] = it.data().uid();
604 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) 635 for ( it = m_rep.begin(); it != m_rep.end(); ++it )
605 if ( it.data().match( r ) ) 636 if ( it.data().match( r ) )
606 m_currentQuery[arraycounter++] = it.data().uid(); 637 m_currentQuery[arraycounter++] = it.data().uid();
607 638
608 // Shrink to fit.. 639 // Shrink to fit..
609 m_currentQuery.resize(arraycounter); 640 m_currentQuery.resize(arraycounter);
610 641
611 return m_currentQuery; 642 return m_currentQuery;
612} 643}
644
645}