author | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
commit | ae70312b1613e26b4ef89a2c9821d9531b82e987 (patch) (unidiff) | |
tree | 7eb70bc45ee29e94da27a18b0136eb4a14e59fa6 /libopie/pim/test/converter.cpp | |
parent | 9e7aafdb7c76d29fee742d53131a73dd60aded2b (diff) | |
download | opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.zip opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.gz opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.bz2 |
Finishing implementation of sql-backend for datebook. But I have to
port the PIM datebook application to use it, before I could debug the
whole stuff.
Thus, PIM-Database backend is finished, but highly experimental. And some
parts are still generic. For instance, the "queryByExample()" methods are
not (or not fully) implemented. Todo: custom-entries not stored.
The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
expression search in the database, which is not supported by sqlite !
Therefore we need either an extended sqlite or a workaround which would
be very slow and memory consuming..
Diffstat (limited to 'libopie/pim/test/converter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/test/converter.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/libopie/pim/test/converter.cpp b/libopie/pim/test/converter.cpp index 650d119..bfdb605 100644 --- a/libopie/pim/test/converter.cpp +++ b/libopie/pim/test/converter.cpp | |||
@@ -1,60 +1,99 @@ | |||
1 | #include "converter.h" | 1 | #include "converter.h" |
2 | 2 | ||
3 | #include <qdatetime.h> | 3 | #include <qdatetime.h> |
4 | #include <qprogressbar.h> | 4 | #include <qprogressbar.h> |
5 | 5 | ||
6 | #include <qpe/qpeapplication.h> | 6 | #include <qpe/qpeapplication.h> |
7 | 7 | ||
8 | #include <opie/ocontactaccess.h> | 8 | #include <opie/ocontactaccess.h> |
9 | #include <opie/ocontactaccessbackend_xml.h> | 9 | #include <opie/ocontactaccessbackend_xml.h> |
10 | #include <opie/ocontactaccessbackend_sql.h> | 10 | #include <opie/ocontactaccessbackend_sql.h> |
11 | 11 | ||
12 | #include <opie/odatebookaccess.h> | ||
13 | #include <opie/odatebookaccessbackend_xml.h> | ||
14 | #include <opie/odatebookaccessbackend_sql.h> | ||
15 | |||
16 | // #define _ADDRESSBOOK_ACCESS | ||
17 | |||
12 | Converter::Converter(){ | 18 | Converter::Converter(){ |
13 | } | 19 | } |
14 | 20 | ||
15 | void Converter::start_conversion(){ | 21 | void Converter::start_conversion(){ |
16 | qWarning("Converting Contacts from XML to SQL.."); | 22 | qWarning("Converting Contacts from XML to SQL.."); |
17 | 23 | ||
18 | // Creating backends to the requested databases.. | 24 | // Creating backends to the requested databases.. |
25 | |||
26 | #ifdef _ADDRESSBOOK_ACCESS | ||
19 | OContactAccessBackend* xmlBackend = new OContactAccessBackend_XML( "Converter", | 27 | OContactAccessBackend* xmlBackend = new OContactAccessBackend_XML( "Converter", |
20 | QString::null ); | 28 | QString::null ); |
21 | 29 | ||
22 | OContactAccessBackend* sqlBackend = new OContactAccessBackend_SQL( QString::null, | 30 | OContactAccessBackend* sqlBackend = new OContactAccessBackend_SQL( QString::null, |
23 | QString::null ); | 31 | QString::null ); |
24 | // Put the created backends into frontends to access them | 32 | // Put the created backends into frontends to access them |
25 | OContactAccess* xmlAccess = new OContactAccess ( "addressbook_xml", | 33 | OContactAccess* xmlAccess = new OContactAccess ( "addressbook_xml", |
26 | QString::null , xmlBackend, true ); | 34 | QString::null , xmlBackend, true ); |
27 | 35 | ||
28 | OContactAccess* sqlAccess = new OContactAccess ( "addressbook_sql", | 36 | OContactAccess* sqlAccess = new OContactAccess ( "addressbook_sql", |
29 | QString::null , sqlBackend, true ); | 37 | QString::null ); |
30 | 38 | ||
39 | #else | ||
40 | ODateBookAccessBackend* xmlBackend = new ODateBookAccessBackend_XML( "Converter", | ||
41 | QString::null ); | ||
42 | |||
43 | ODateBookAccessBackend* sqlBackend = new ODateBookAccessBackend_SQL( QString::null, | ||
44 | QString::null ); | ||
45 | // Put the created backends into frontends to access them | ||
46 | ODateBookAccess* xmlAccess = new ODateBookAccess ( xmlBackend ); | ||
47 | |||
48 | ODateBookAccess* sqlAccess = new ODateBookAccess ( sqlBackend ); | ||
49 | |||
50 | xmlAccess->load(); | ||
51 | |||
52 | #endif | ||
53 | |||
31 | QTime t; | 54 | QTime t; |
32 | t.start(); | 55 | t.start(); |
33 | 56 | ||
34 | // Clean the sql-database.. | 57 | // Clean the sql-database.. |
35 | sqlAccess->clear(); | 58 | sqlAccess->clear(); |
36 | 59 | ||
60 | #ifdef _ADDRESSBOOK_ACCESS | ||
37 | // Now trasmit every contact from the xml database to the sql-database | 61 | // Now trasmit every contact from the xml database to the sql-database |
38 | OContactAccess::List contactList = xmlAccess->allRecords(); | 62 | OContactAccess::List contactList = xmlAccess->allRecords(); |
39 | m_progressBar->setTotalSteps( contactList.count() ); | 63 | m_progressBar->setTotalSteps( contactList.count() ); |
40 | int count = 0; | 64 | int count = 0; |
41 | if ( sqlAccess && xmlAccess ){ | 65 | if ( sqlAccess && xmlAccess ){ |
42 | OContactAccess::List::Iterator it; | 66 | OContactAccess::List::Iterator it; |
43 | for ( it = contactList.begin(); it != contactList.end(); ++it ){ | 67 | for ( it = contactList.begin(); it != contactList.end(); ++it ){ |
44 | sqlAccess->add( *it ); | 68 | sqlAccess->add( *it ); |
45 | m_progressBar->setProgress( ++count ); | 69 | m_progressBar->setProgress( ++count ); |
46 | } | 70 | } |
47 | } | 71 | } |
48 | 72 | #else | |
73 | // Now transmit every contact from the xml database to the sql-database | ||
74 | ODateBookAccess::List dateList = xmlAccess->allRecords(); | ||
75 | m_progressBar->setTotalSteps( dateList.count() ); | ||
76 | qWarning( "Number of elements to copy: %d", dateList.count() ); | ||
77 | |||
78 | int count = 0; | ||
79 | if ( sqlAccess && xmlAccess ){ | ||
80 | ODateBookAccess::List::Iterator it; | ||
81 | for ( it = dateList.begin(); it != dateList.end(); ++it ){ | ||
82 | sqlAccess->add( *it ); | ||
83 | m_progressBar->setProgress( ++count ); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | #endif | ||
49 | // Delete the frontends. Backends will be deleted automatically, too ! | 88 | // Delete the frontends. Backends will be deleted automatically, too ! |
50 | delete sqlAccess; | 89 | delete sqlAccess; |
51 | 90 | ||
52 | qWarning("Conversion is finished and needed %d ms !", t.elapsed()); | 91 | qWarning("Conversion is finished and needed %d ms !", t.elapsed()); |
53 | 92 | ||
54 | delete xmlAccess; | 93 | delete xmlAccess; |
55 | } | 94 | } |
56 | 95 | ||
57 | int main( int argc, char** argv ) { | 96 | int main( int argc, char** argv ) { |
58 | 97 | ||
59 | QPEApplication a( argc, argv ); | 98 | QPEApplication a( argc, argv ); |
60 | 99 | ||