summaryrefslogtreecommitdiff
path: root/libopie/pim/test/converter.cpp
Unidiff
Diffstat (limited to 'libopie/pim/test/converter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/test/converter.cpp45
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
@@ -6,49 +6,88 @@
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
12Converter::Converter(){ 18Converter::Converter(){
13} 19}
14 20
15void Converter::start_conversion(){ 21void 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;