-rw-r--r-- | noncore/tools/pimconverter/converter.cpp | 34 | ||||
-rwxr-xr-x | noncore/tools/pimconverter/converter.h | 3 |
2 files changed, 36 insertions, 1 deletions
diff --git a/noncore/tools/pimconverter/converter.cpp b/noncore/tools/pimconverter/converter.cpp index 7d34b24..ded59b6 100644 --- a/noncore/tools/pimconverter/converter.cpp +++ b/noncore/tools/pimconverter/converter.cpp | |||
@@ -1,69 +1,82 @@ | |||
1 | #include "converter.h" | 1 | #include "converter.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
5 | 5 | ||
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | #include <opie2/opimglobal.h> | 7 | #include <opie2/opimglobal.h> |
8 | // Include SQL related header files | 8 | // Include SQL related header files |
9 | #define __USE_SQL | 9 | #define __USE_SQL |
10 | #include <opie2/opimaccessfactory.h> | 10 | #include <opie2/opimaccessfactory.h> |
11 | 11 | ||
12 | /* QT */ | 12 | /* QT */ |
13 | #include <qdatetime.h> | 13 | #include <qdatetime.h> |
14 | #include <qprogressbar.h> | 14 | #include <qprogressbar.h> |
15 | #include <qcombobox.h> | 15 | #include <qcombobox.h> |
16 | #include <qcheckbox.h> | 16 | #include <qcheckbox.h> |
17 | #include <qmessagebox.h> | ||
17 | 18 | ||
18 | 19 | ||
19 | using namespace Opie; | 20 | using namespace Opie; |
20 | using namespace Pim; | 21 | using namespace Pim; |
21 | 22 | ||
22 | Converter::Converter(): | 23 | Converter::Converter(): |
23 | m_selectedDatabase( ADDRESSBOOK ), | 24 | m_selectedDatabase( ADDRESSBOOK ), |
24 | m_selectedSourceFormat( XML ), | 25 | m_selectedSourceFormat( XML ), |
25 | m_selectedDestFormat( SQL ) | 26 | m_selectedDestFormat( SQL ), |
27 | m_criticalState( false ) | ||
26 | { | 28 | { |
27 | m_dataBaseSelector -> setCurrentItem( m_selectedDatabase ); | 29 | m_dataBaseSelector -> setCurrentItem( m_selectedDatabase ); |
28 | m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat ); | 30 | m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat ); |
29 | m_destFormatSelector -> setCurrentItem( m_selectedDestFormat ); | 31 | m_destFormatSelector -> setCurrentItem( m_selectedDestFormat ); |
30 | m_eraseDB -> setChecked( true ); // Default erase on copy | 32 | m_eraseDB -> setChecked( true ); // Default erase on copy |
31 | } | 33 | } |
32 | 34 | ||
33 | void Converter::selectedDatabase( int num ) | 35 | void Converter::selectedDatabase( int num ) |
34 | { | 36 | { |
35 | m_selectedDatabase = num; | 37 | m_selectedDatabase = num; |
36 | } | 38 | } |
37 | 39 | ||
38 | void Converter::selectedDestFormat( int num ) | 40 | void Converter::selectedDestFormat( int num ) |
39 | { | 41 | { |
40 | m_selectedDestFormat = num; | 42 | m_selectedDestFormat = num; |
41 | } | 43 | } |
42 | 44 | ||
43 | void Converter::selectedSourceFormat( int num ) | 45 | void Converter::selectedSourceFormat( int num ) |
44 | { | 46 | { |
45 | m_selectedSourceFormat = num; | 47 | m_selectedSourceFormat = num; |
46 | } | 48 | } |
47 | 49 | ||
48 | void Converter::start_conversion(){ | 50 | void Converter::start_conversion(){ |
49 | 51 | ||
50 | // Creating backends to the requested databases.. | 52 | // Creating backends to the requested databases.. |
51 | OPimBase* sourceDB; | 53 | OPimBase* sourceDB; |
52 | OPimBase* destDB; | 54 | OPimBase* destDB; |
53 | 55 | ||
56 | odebug << "SourceFormat: " << m_selectedSourceFormat << oendl; | ||
57 | odebug << "DestFormat: " << m_selectedDestFormat << oendl; | ||
58 | if ( m_selectedSourceFormat == m_selectedDestFormat ){ | ||
59 | |||
60 | QMessageBox::warning( this, "PimConverter", | ||
61 | tr( "It is not a good idea to use\n" ) | ||
62 | +tr( "the same source and destformat !" ), | ||
63 | tr( "Ok" ) ); | ||
64 | return; | ||
65 | } | ||
66 | |||
54 | switch( m_selectedSourceFormat ){ | 67 | switch( m_selectedSourceFormat ){ |
55 | case XML: | 68 | case XML: |
56 | odebug << "XMLSourceDB = " << m_selectedDatabase << "" << oendl; | 69 | odebug << "XMLSourceDB = " << m_selectedDatabase << "" << oendl; |
57 | switch( m_selectedDatabase ){ | 70 | switch( m_selectedDatabase ){ |
58 | case ADDRESSBOOK:{ | 71 | case ADDRESSBOOK:{ |
59 | sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" ); | 72 | sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" ); |
60 | } | 73 | } |
61 | break; | 74 | break; |
62 | case TODOLIST:{ | 75 | case TODOLIST:{ |
63 | sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" ); | 76 | sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" ); |
64 | }break; | 77 | }break; |
65 | case DATEBOOK:{ | 78 | case DATEBOOK:{ |
66 | sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" ); | 79 | sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" ); |
67 | } | 80 | } |
68 | break; | 81 | break; |
69 | default: | 82 | default: |
@@ -129,79 +142,98 @@ void Converter::start_conversion(){ | |||
129 | destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" ); | 142 | destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" ); |
130 | } | 143 | } |
131 | break; | 144 | break; |
132 | default: | 145 | default: |
133 | owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; | 146 | owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; |
134 | return; | 147 | return; |
135 | } | 148 | } |
136 | break; | 149 | break; |
137 | default: | 150 | default: |
138 | owarn << "Unknown destination format selected (" << m_selectedDestFormat << ")!!" << oendl; | 151 | owarn << "Unknown destination format selected (" << m_selectedDestFormat << ")!!" << oendl; |
139 | return; | 152 | return; |
140 | } | 153 | } |
141 | 154 | ||
142 | if ( !sourceDB || !destDB ) | 155 | if ( !sourceDB || !destDB ) |
143 | return; | 156 | return; |
144 | 157 | ||
158 | m_criticalState = true; | ||
159 | |||
145 | sourceDB -> load(); | 160 | sourceDB -> load(); |
146 | destDB -> load(); | 161 | destDB -> load(); |
147 | 162 | ||
148 | QTime t; | 163 | QTime t; |
149 | t.start(); | 164 | t.start(); |
150 | 165 | ||
151 | // Clean the dest-database if requested (isChecked) | 166 | // Clean the dest-database if requested (isChecked) |
152 | if ( m_eraseDB -> isChecked() ){ | 167 | if ( m_eraseDB -> isChecked() ){ |
153 | odebug << "Clearing destination database!" << oendl; | 168 | odebug << "Clearing destination database!" << oendl; |
154 | destDB -> clear(); | 169 | destDB -> clear(); |
155 | } | 170 | } |
156 | 171 | ||
157 | // Now transmit every pim-item from the source database to the destination -database | 172 | // Now transmit every pim-item from the source database to the destination -database |
158 | QArray<int> uidList = sourceDB->records(); | 173 | QArray<int> uidList = sourceDB->records(); |
159 | odebug << "Try to move data for addressbook.. (" << uidList.count() << " items) " << oendl; | 174 | odebug << "Try to move data for addressbook.. (" << uidList.count() << " items) " << oendl; |
160 | m_progressBar->setTotalSteps( uidList.count() ); | 175 | m_progressBar->setTotalSteps( uidList.count() ); |
161 | int count = 0; | 176 | int count = 0; |
162 | for ( uint i = 0; i < uidList.count(); ++i ){ | 177 | for ( uint i = 0; i < uidList.count(); ++i ){ |
163 | odebug << "Adding uid: " << uidList[i] << "" << oendl; | 178 | odebug << "Adding uid: " << uidList[i] << "" << oendl; |
164 | OPimRecord* rec = sourceDB -> record( uidList[i] ); | 179 | OPimRecord* rec = sourceDB -> record( uidList[i] ); |
165 | destDB -> add( rec ); | 180 | destDB -> add( rec ); |
166 | m_progressBar->setProgress( ++count ); | 181 | m_progressBar->setProgress( ++count ); |
167 | } | 182 | } |
168 | 183 | ||
169 | // Now commit data.. | 184 | // Now commit data.. |
170 | destDB -> save(); | 185 | destDB -> save(); |
171 | 186 | ||
187 | m_criticalState = false; | ||
188 | |||
172 | // Delete the frontends. Backends will be deleted automatically, too ! | 189 | // Delete the frontends. Backends will be deleted automatically, too ! |
173 | // We have to cast them back to delete them properly ! | 190 | // We have to cast them back to delete them properly ! |
174 | switch( m_selectedDatabase ){ | 191 | switch( m_selectedDatabase ){ |
175 | case ADDRESSBOOK: | 192 | case ADDRESSBOOK: |
176 | delete static_cast<OPimContactAccess*> (sourceDB); | 193 | delete static_cast<OPimContactAccess*> (sourceDB); |
177 | delete static_cast<OPimContactAccess*> (destDB); | 194 | delete static_cast<OPimContactAccess*> (destDB); |
178 | break; | 195 | break; |
179 | case TODOLIST: | 196 | case TODOLIST: |
180 | delete static_cast<OPimTodoAccess*> (sourceDB); | 197 | delete static_cast<OPimTodoAccess*> (sourceDB); |
181 | delete static_cast<OPimTodoAccess*> (destDB); | 198 | delete static_cast<OPimTodoAccess*> (destDB); |
182 | break; | 199 | break; |
183 | case DATEBOOK: | 200 | case DATEBOOK: |
184 | delete static_cast<ODateBookAccess*> (sourceDB); | 201 | delete static_cast<ODateBookAccess*> (sourceDB); |
185 | delete static_cast<ODateBookAccess*> (destDB); | 202 | delete static_cast<ODateBookAccess*> (destDB); |
186 | break; | 203 | break; |
187 | default: | 204 | default: |
188 | owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; | 205 | owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; |
189 | return; | 206 | return; |
190 | } | 207 | } |
191 | 208 | ||
192 | 209 | ||
193 | owarn << "Conversion is finished and needed " << t.elapsed() << " ms !" << oendl; | 210 | owarn << "Conversion is finished and needed " << t.elapsed() << " ms !" << oendl; |
194 | } | 211 | } |
195 | 212 | ||
213 | void Converter::closeEvent( QCloseEvent *e ) | ||
214 | { | ||
215 | |||
216 | /* Due to the fact that we don't have multitasking here, this | ||
217 | * critical handling don't make sense, but the future.. | ||
218 | */ | ||
219 | if ( m_criticalState ){ | ||
220 | e->ignore(); | ||
221 | return; | ||
222 | } | ||
223 | e->accept(); | ||
224 | } | ||
225 | |||
226 | |||
227 | |||
196 | int main( int argc, char** argv ) { | 228 | int main( int argc, char** argv ) { |
197 | 229 | ||
198 | QPEApplication a( argc, argv ); | 230 | QPEApplication a( argc, argv ); |
199 | 231 | ||
200 | Converter dlg; | 232 | Converter dlg; |
201 | 233 | ||
202 | a.showMainWidget( &dlg ); | 234 | a.showMainWidget( &dlg ); |
203 | // dlg. showMaximized ( ); | 235 | // dlg. showMaximized ( ); |
204 | 236 | ||
205 | return a.exec(); | 237 | return a.exec(); |
206 | 238 | ||
207 | } | 239 | } |
diff --git a/noncore/tools/pimconverter/converter.h b/noncore/tools/pimconverter/converter.h index 27d7fb2..a78c6bc 100755 --- a/noncore/tools/pimconverter/converter.h +++ b/noncore/tools/pimconverter/converter.h | |||
@@ -1,40 +1,43 @@ | |||
1 | #ifndef _CONVERTER_H_ | 1 | #ifndef _CONVERTER_H_ |
2 | #define _CONVERTER_H_ | 2 | #define _CONVERTER_H_ |
3 | 3 | ||
4 | 4 | ||
5 | #include "converter_base.h" | 5 | #include "converter_base.h" |
6 | 6 | ||
7 | 7 | ||
8 | class Converter: public converter_base { | 8 | class Converter: public converter_base { |
9 | public: | 9 | public: |
10 | Converter(); | 10 | Converter(); |
11 | 11 | ||
12 | // Slots defined in the ui-description file | 12 | // Slots defined in the ui-description file |
13 | void start_conversion(); | 13 | void start_conversion(); |
14 | void selectedDatabase( int num ); | 14 | void selectedDatabase( int num ); |
15 | void selectedDestFormat( int num ); | 15 | void selectedDestFormat( int num ); |
16 | void selectedSourceFormat( int num ); | 16 | void selectedSourceFormat( int num ); |
17 | |||
18 | void closeEvent( QCloseEvent *e ); | ||
17 | 19 | ||
18 | private: | 20 | private: |
19 | // Caution: | 21 | // Caution: |
20 | // The order and value of the following enums must be regarding | 22 | // The order and value of the following enums must be regarding |
21 | // the predefinition in the UI-File !! | 23 | // the predefinition in the UI-File !! |
22 | enum DataBases{ | 24 | enum DataBases{ |
23 | ADDRESSBOOK = 0, | 25 | ADDRESSBOOK = 0, |
24 | TODOLIST = 1, | 26 | TODOLIST = 1, |
25 | DATEBOOK = 2, | 27 | DATEBOOK = 2, |
26 | }; | 28 | }; |
27 | 29 | ||
28 | enum DbFormats{ | 30 | enum DbFormats{ |
29 | XML = 0, | 31 | XML = 0, |
30 | SQL = 1, | 32 | SQL = 1, |
31 | }; | 33 | }; |
32 | 34 | ||
33 | int m_selectedDatabase; | 35 | int m_selectedDatabase; |
34 | int m_selectedSourceFormat; | 36 | int m_selectedSourceFormat; |
35 | int m_selectedDestFormat; | 37 | int m_selectedDestFormat; |
38 | bool m_criticalState; | ||
36 | 39 | ||
37 | }; | 40 | }; |
38 | 41 | ||
39 | 42 | ||
40 | #endif | 43 | #endif |