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 | |||
@@ -9,6 +9,12 @@ | |||
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 | ||
@@ -16,6 +22,8 @@ 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 | ||
@@ -26,14 +34,30 @@ void Converter::start_conversion(){ | |||
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() ); |
@@ -45,7 +69,22 @@ void Converter::start_conversion(){ | |||
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 | ||