-rw-r--r-- | libopie/pim/test/converter.cpp | 45 | ||||
-rwxr-xr-x | libopie/pim/test/converter.h | 18 | ||||
-rw-r--r-- | libopie/pim/test/converter.pro | 2 |
3 files changed, 61 insertions, 4 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 | |||
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; |
diff --git a/libopie/pim/test/converter.h b/libopie/pim/test/converter.h new file mode 100755 index 0000000..1cc2a7c --- a/dev/null +++ b/libopie/pim/test/converter.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef _CONVERTER_H_ | ||
2 | #define _CONVERTER_H_ | ||
3 | |||
4 | |||
5 | #include "converter_base.h" | ||
6 | |||
7 | |||
8 | class Converter: public converter_base { | ||
9 | public: | ||
10 | Converter(); | ||
11 | |||
12 | void start_conversion(); | ||
13 | private: | ||
14 | |||
15 | }; | ||
16 | |||
17 | |||
18 | #endif | ||
diff --git a/libopie/pim/test/converter.pro b/libopie/pim/test/converter.pro index aa74bff..bd9c7a3 100644 --- a/libopie/pim/test/converter.pro +++ b/libopie/pim/test/converter.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE= app | 1 | # TEMPLATE= app |
2 | CONFIG = qt warn_on debug | 2 | CONFIG = qt warn_on debug |
3 | # CONFIG = qt warn_on release | 3 | # CONFIG = qt warn_on release |
4 | #HEADERS = | 4 | #HEADERS = |
5 | SOURCES = converter.cpp | 5 | SOURCES = converter.cpp |
6 | INTERFACES = converter_base.ui | 6 | INTERFACES = converter_base.ui |
7 | INCLUDEPATH+= $(OPIEDIR)/include | 7 | INCLUDEPATH+= $(OPIEDIR)/include |