summaryrefslogtreecommitdiff
path: root/libopie/pim/otodoaccessxml.cpp
Side-by-side diff
Diffstat (limited to 'libopie/pim/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodoaccessxml.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index b2dfe80..21f93a0 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,6 +1,16 @@
+#include <errno.h>
+#include <fcntl.h>
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <unistd.h>
+
+
#include <qfile.h>
#include <qvector.h>
#include <qpe/global.h>
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
@@ -49,26 +59,42 @@ bool OTodoAccessXML::load() {
dict.insert("Reminders", new int(OTodo::Reminders) );
dict.insert("Notifiers", new int(OTodo::Notifiers) );
dict.insert("Maintainer", new int(OTodo::Maintainer) );
// here the custom XML parser from TT it's GPL
// but we want to push OpiePIM... to TT.....
- QFile f(m_file );
- if (!f.open(IO_ReadOnly) )
+ // mmap part from zecke :)
+ int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
+ struct stat attribut;
+ if ( fd < 0 ) return false;
+
+ if ( fstat(fd, &attribut ) == -1 ) {
+ ::close( fd );
return false;
+ }
+ void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
+ if ( map_addr == ( (caddr_t)-1) ) {
+ ::close(fd );
+ return false;
+ }
+ /* advise the kernel who we want to read it */
+ ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
+ /* we do not the file any more */
+ ::close( fd );
- QByteArray ba = f.readAll();
- f.close();
- char* dt = ba.data();
- int len = ba.size();
+ char* dt = (char*)map_addr;
+ int len = attribut.st_size;
int i = 0;
char *point;
const char* collectionString = "<Task ";
+ int strLen = strlen(collectionString);
while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
i = point -dt;
- i+= strlen(collectionString);
+ i+= strLen;
+ qWarning("Found a start at %d %d", i, (point-dt) );
+
OTodo ev;
m_year = m_month = m_day = 0;
while ( TRUE ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
@@ -117,23 +143,26 @@ bool OTodoAccessXML::load() {
todo( &dict, ev, attr, str );
}
/*
* now add it
*/
+ qWarning("End at %d", i );
if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
ev.setUid( 1 );
m_changed = true;
}
if ( ev.hasDueDate() ) {
ev.setDueDate( QDate(m_year, m_month, m_day) );
}
m_events.insert(ev.uid(), ev );
m_year = m_month = m_day = -1;
}
+ munmap(map_addr, attribut.st_size );
+
qWarning("counts %d records loaded!", m_events.count() );
return true;
}
bool OTodoAccessXML::reload() {
return load();
}