-rw-r--r-- | noncore/tools/pimconverter/converter.cpp | 69 |
1 files changed, 24 insertions, 45 deletions
diff --git a/noncore/tools/pimconverter/converter.cpp b/noncore/tools/pimconverter/converter.cpp index 1091f4a..2bd47a4 100644 --- a/noncore/tools/pimconverter/converter.cpp +++ b/noncore/tools/pimconverter/converter.cpp | |||
@@ -1,195 +1,174 @@ | |||
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 | #include <qcombobox.h> | 5 | #include <qcombobox.h> |
6 | #include <qcheckbox.h> | 6 | #include <qcheckbox.h> |
7 | 7 | ||
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | 9 | ||
10 | #include <opie2/ocontactaccess.h> | 10 | #include <opie2/opimglobal.h> |
11 | #include <opie2/ocontactaccessbackend_xml.h> | 11 | // Include SQL related header files |
12 | #include <opie2/ocontactaccessbackend_sql.h> | 12 | #define __USE_SQL |
13 | 13 | #include <opie2/opimaccessfactory.h> | |
14 | #include <opie2/otodoaccess.h> | ||
15 | #include <opie2/otodoaccessxml.h> | ||
16 | #include <opie2/otodoaccesssql.h> | ||
17 | |||
18 | #include <opie2/odatebookaccess.h> | ||
19 | #include <opie2/odatebookaccessbackend_xml.h> | ||
20 | #include <opie2/odatebookaccessbackend_sql.h> | ||
21 | |||
22 | // #define _ADDRESSBOOK_ACCESS | ||
23 | 14 | ||
24 | using namespace Opie; | 15 | using namespace Opie; |
16 | using namespace Pim; | ||
25 | 17 | ||
26 | Converter::Converter(): | 18 | Converter::Converter(): |
27 | m_selectedDatabase( ADDRESSBOOK ), | 19 | m_selectedDatabase( ADDRESSBOOK ), |
28 | m_selectedSourceFormat( XML ), | 20 | m_selectedSourceFormat( XML ), |
29 | m_selectedDestFormat( SQL ) | 21 | m_selectedDestFormat( SQL ) |
30 | { | 22 | { |
31 | m_dataBaseSelector -> setCurrentItem( m_selectedDatabase ); | 23 | m_dataBaseSelector -> setCurrentItem( m_selectedDatabase ); |
32 | m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat ); | 24 | m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat ); |
33 | m_destFormatSelector -> setCurrentItem( m_selectedDestFormat ); | 25 | m_destFormatSelector -> setCurrentItem( m_selectedDestFormat ); |
34 | m_eraseDB -> setChecked( true ); // Default erase on copy | 26 | m_eraseDB -> setChecked( true ); // Default erase on copy |
35 | } | 27 | } |
36 | 28 | ||
37 | void Converter::selectedDatabase( int num ) | 29 | void Converter::selectedDatabase( int num ) |
38 | { | 30 | { |
39 | m_selectedDatabase = num; | 31 | m_selectedDatabase = num; |
40 | } | 32 | } |
41 | 33 | ||
42 | void Converter::selectedDestFormat( int num ) | 34 | void Converter::selectedDestFormat( int num ) |
43 | { | 35 | { |
44 | m_selectedDestFormat = num; | 36 | m_selectedDestFormat = num; |
45 | } | 37 | } |
46 | 38 | ||
47 | void Converter::selectedSourceFormat( int num ) | 39 | void Converter::selectedSourceFormat( int num ) |
48 | { | 40 | { |
49 | m_selectedSourceFormat = num; | 41 | m_selectedSourceFormat = num; |
50 | } | 42 | } |
51 | 43 | ||
52 | void Converter::start_conversion(){ | 44 | void Converter::start_conversion(){ |
53 | 45 | ||
54 | // Creating backends to the requested databases.. | 46 | // Creating backends to the requested databases.. |
55 | OPimBase* sourceDB; | 47 | OPimBase* sourceDB; |
56 | OPimBase* destDB; | 48 | OPimBase* destDB; |
57 | 49 | ||
58 | switch( m_selectedSourceFormat ){ | 50 | switch( m_selectedSourceFormat ){ |
59 | case XML: | 51 | case XML: |
60 | qDebug("XMLSourceDB = %d", m_selectedDatabase); | 52 | qDebug("XMLSourceDB = %d", m_selectedDatabase); |
61 | switch( m_selectedDatabase ){ | 53 | switch( m_selectedDatabase ){ |
62 | case ADDRESSBOOK:{ | 54 | case ADDRESSBOOK:{ |
63 | OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_XML( "Converter", QString::null ); | 55 | sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" ); |
64 | sourceDB = new OPimContactAccess ( "addressbook_xml", QString::null , sourceBackend, true ); | ||
65 | } | 56 | } |
66 | break; | 57 | break; |
67 | case TODOLIST:{ | 58 | case TODOLIST:{ |
68 | OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessXML( "Converter" ); | 59 | sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" ); |
69 | sourceDB = new OPimTodoAccess( sourceBackend ); | ||
70 | }break; | 60 | }break; |
71 | case DATEBOOK:{ | 61 | case DATEBOOK:{ |
72 | ODateBookAccessBackend_XML* sourceBackend = new ODateBookAccessBackend_XML( "Converter", QString::null ); | 62 | sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" ); |
73 | sourceDB = new ODateBookAccess ( sourceBackend ); | ||
74 | } | 63 | } |
75 | break; | 64 | break; |
76 | default: | 65 | default: |
77 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); | 66 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); |
78 | return; | 67 | return; |
79 | } | 68 | } |
80 | break; | 69 | break; |
81 | case SQL: | 70 | case SQL: |
82 | qDebug("SQLSourceDB = %d", m_selectedDatabase); | 71 | qDebug("SQLSourceDB = %d", m_selectedDatabase); |
83 | switch( m_selectedDatabase ){ | 72 | switch( m_selectedDatabase ){ |
84 | case ADDRESSBOOK:{ | 73 | case ADDRESSBOOK:{ |
85 | qDebug("SQLSourceDB = %d", m_selectedDatabase); | 74 | sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::SQL, "converter" ); |
86 | OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null ); | 75 | } |
87 | sourceDB = new OPimContactAccess ( "Converter", QString::null, sourceBackend, true ); | ||
88 | } | ||
89 | break; | 76 | break; |
90 | case TODOLIST:{ | 77 | case TODOLIST:{ |
91 | OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessBackendSQL( QString::null ); | 78 | sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::SQL, "converter" ); |
92 | sourceDB = new OPimTodoAccess( sourceBackend ); | ||
93 | }break; | 79 | }break; |
94 | case DATEBOOK: { | 80 | case DATEBOOK:{ |
95 | ODateBookAccessBackend_SQL* sourceBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null ); | 81 | sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" ); |
96 | sourceDB = new ODateBookAccess ( sourceBackend ); | 82 | } |
97 | } | ||
98 | break; | 83 | break; |
99 | default: | 84 | default: |
100 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); | 85 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); |
101 | return; | 86 | return; |
102 | } | 87 | } |
103 | break; | 88 | break; |
104 | default: | 89 | default: |
105 | qWarning( "Unknown source format selected (%d) !!", m_selectedSourceFormat ); | 90 | qWarning( "Unknown source format selected (%d) !!", m_selectedSourceFormat ); |
106 | return; | 91 | return; |
107 | } | 92 | } |
108 | 93 | ||
109 | switch ( m_selectedDestFormat ){ | 94 | switch ( m_selectedDestFormat ){ |
110 | case XML: | 95 | case XML: |
111 | qDebug("XMLDestDB = %d", m_selectedDatabase); | 96 | qDebug("XMLDestDB = %d", m_selectedDatabase); |
112 | switch( m_selectedDatabase ){ | 97 | switch( m_selectedDatabase ){ |
113 | case ADDRESSBOOK:{ | 98 | case ADDRESSBOOK:{ |
114 | OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_XML( "Converter", QString::null ); | 99 | destDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" ); |
115 | destDB = new OPimContactAccess ( "Converter", QString::null , destBackend, true ); | 100 | } |
116 | } | ||
117 | break; | 101 | break; |
118 | case TODOLIST:{ | 102 | case TODOLIST:{ |
119 | OPimTodoAccessBackend* destBackend = new OPimTodoAccessXML( "Converter" ); | 103 | destDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" ); |
120 | destDB = new OPimTodoAccess( destBackend ); | ||
121 | }break; | 104 | }break; |
122 | case DATEBOOK:{ | 105 | case DATEBOOK:{ |
123 | ODateBookAccessBackend_XML* destBackend = new ODateBookAccessBackend_XML( "Converter", QString::null ); | 106 | destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" ); |
124 | destDB = new ODateBookAccess ( destBackend ); | 107 | } |
125 | } | ||
126 | break; | 108 | break; |
127 | default: | 109 | default: |
128 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); | 110 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); |
129 | return; | 111 | return; |
130 | } | 112 | } |
131 | break; | 113 | break; |
132 | case SQL: | 114 | case SQL: |
133 | qDebug("SQLDestDB = %d", m_selectedDatabase); | 115 | qDebug("SQLDestDB = %d", m_selectedDatabase); |
134 | switch( m_selectedDatabase ){ | 116 | switch( m_selectedDatabase ){ |
135 | case ADDRESSBOOK:{ | 117 | case ADDRESSBOOK:{ |
136 | OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null ); | 118 | destDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::SQL, "converter" ); |
137 | destDB = new OPimContactAccess ( "addressbook_xml", QString::null , destBackend, true ); | 119 | } |
138 | } | ||
139 | break; | 120 | break; |
140 | case TODOLIST:{ | 121 | case TODOLIST:{ |
141 | OPimTodoAccessBackend* destBackend = new OPimTodoAccessBackendSQL( QString::null ); | 122 | destDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::SQL, "converter" ); |
142 | destDB = new OPimTodoAccess( destBackend ); | ||
143 | }break; | 123 | }break; |
144 | case DATEBOOK:{ | 124 | case DATEBOOK:{ |
145 | ODateBookAccessBackend_SQL* destBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null ); | 125 | destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" ); |
146 | destDB = new ODateBookAccess ( destBackend ); | 126 | } |
147 | } | ||
148 | break; | 127 | break; |
149 | default: | 128 | default: |
150 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); | 129 | qWarning( "Unknown database selected (%d)", m_selectedDatabase ); |
151 | return; | 130 | return; |
152 | } | 131 | } |
153 | break; | 132 | break; |
154 | default: | 133 | default: |
155 | qWarning( "Unknown destination format selected (%d)!!", m_selectedDestFormat ); | 134 | qWarning( "Unknown destination format selected (%d)!!", m_selectedDestFormat ); |
156 | return; | 135 | return; |
157 | } | 136 | } |
158 | 137 | ||
159 | if ( !sourceDB || !destDB ) | 138 | if ( !sourceDB || !destDB ) |
160 | return; | 139 | return; |
161 | 140 | ||
162 | sourceDB -> load(); | 141 | sourceDB -> load(); |
163 | destDB -> load(); | 142 | destDB -> load(); |
164 | 143 | ||
165 | QTime t; | 144 | QTime t; |
166 | t.start(); | 145 | t.start(); |
167 | 146 | ||
168 | // Clean the dest-database if requested (isChecked) | 147 | // Clean the dest-database if requested (isChecked) |
169 | if ( m_eraseDB -> isChecked() ){ | 148 | if ( m_eraseDB -> isChecked() ){ |
170 | qDebug( "Clearing destination database!" ); | 149 | qDebug( "Clearing destination database!" ); |
171 | destDB -> clear(); | 150 | destDB -> clear(); |
172 | } | 151 | } |
173 | 152 | ||
174 | // Now transmit every pim-item from the source database to the destination -database | 153 | // Now transmit every pim-item from the source database to the destination -database |
175 | QArray<int> uidList = sourceDB->records(); | 154 | QArray<int> uidList = sourceDB->records(); |
176 | qDebug( "Try to move data for addressbook.. (%d items) ", uidList.count() ); | 155 | qDebug( "Try to move data for addressbook.. (%d items) ", uidList.count() ); |
177 | m_progressBar->setTotalSteps( uidList.count() ); | 156 | m_progressBar->setTotalSteps( uidList.count() ); |
178 | int count = 0; | 157 | int count = 0; |
179 | for ( uint i = 0; i < uidList.count(); ++i ){ | 158 | for ( uint i = 0; i < uidList.count(); ++i ){ |
180 | qDebug( "Adding uid: %d", uidList[i] ); | 159 | qDebug( "Adding uid: %d", uidList[i] ); |
181 | OPimRecord* rec = sourceDB -> record( uidList[i] ); | 160 | OPimRecord* rec = sourceDB -> record( uidList[i] ); |
182 | destDB -> add( rec ); | 161 | destDB -> add( rec ); |
183 | m_progressBar->setProgress( ++count ); | 162 | m_progressBar->setProgress( ++count ); |
184 | } | 163 | } |
185 | 164 | ||
186 | // Now commit data.. | 165 | // Now commit data.. |
187 | destDB -> save(); | 166 | destDB -> save(); |
188 | 167 | ||
189 | // Delete the frontends. Backends will be deleted automatically, too ! | 168 | // Delete the frontends. Backends will be deleted automatically, too ! |
190 | // We have to cast them back to delete them properly ! | 169 | // We have to cast them back to delete them properly ! |
191 | switch( m_selectedDatabase ){ | 170 | switch( m_selectedDatabase ){ |
192 | case ADDRESSBOOK: | 171 | case ADDRESSBOOK: |
193 | delete static_cast<OPimContactAccess*> (sourceDB); | 172 | delete static_cast<OPimContactAccess*> (sourceDB); |
194 | delete static_cast<OPimContactAccess*> (destDB); | 173 | delete static_cast<OPimContactAccess*> (destDB); |
195 | break; | 174 | break; |