summaryrefslogtreecommitdiff
path: root/noncore/tools/pimconverter
Unidiff
Diffstat (limited to 'noncore/tools/pimconverter') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/pimconverter/converter.cpp147
-rwxr-xr-xnoncore/tools/pimconverter/converter.h3
2 files changed, 87 insertions, 63 deletions
diff --git a/noncore/tools/pimconverter/converter.cpp b/noncore/tools/pimconverter/converter.cpp
index 2cd6969..fa3e714 100644
--- a/noncore/tools/pimconverter/converter.cpp
+++ b/noncore/tools/pimconverter/converter.cpp
@@ -1,32 +1,33 @@
1#include "converter.h" 1#include "converter.h"
2 2
3#include <stdlib.h> // For "system()" command 3#include <stdlib.h> // For "system()" command
4 4
5/* OPIE */ 5/* OPIE */
6#include <opie2/oapplicationfactory.h> 6#include <opie2/oapplicationfactory.h>
7#include <opie2/odebug.h> 7#include <opie2/odebug.h>
8#include <opie2/opimglobal.h> 8#include <opie2/opimglobal.h>
9#include <qpe/global.h>
9// Include SQL related header files 10// Include SQL related header files
10#define __USE_SQL 11#define __USE_SQL
11#include <opie2/opimaccessfactory.h> 12#include <opie2/opimaccessfactory.h>
12 13
13/* QT */ 14/* QT */
14#include <qdatetime.h> 15#include <qdatetime.h>
15#include <qprogressbar.h> 16#include <qprogressbar.h>
16#include <qcombobox.h> 17#include <qcombobox.h>
17#include <qcheckbox.h> 18#include <qcheckbox.h>
18#include <qmessagebox.h> 19#include <qmessagebox.h>
19 20
20 21
21OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<Converter> ) 22OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<Converter> )
22 23
23using namespace Opie; 24using namespace Opie;
24using namespace Pim; 25using namespace Pim;
25 26
26Converter::Converter(QWidget *p, const char* n, WFlags fl): 27Converter::Converter(QWidget *p, const char* n, WFlags fl):
27 converter_base( p, n, fl ), 28 converter_base( p, n, fl ),
28 m_selectedDatabase( ADDRESSBOOK ), 29 m_selectedDatabase( ADDRESSBOOK ),
29 m_selectedSourceFormat( XML ), 30 m_selectedSourceFormat( XML ),
30 m_selectedDestFormat( SQL ), 31 m_selectedDestFormat( SQL ),
31 m_criticalState( false ) 32 m_criticalState( false )
32{ 33{
@@ -40,52 +41,51 @@ void Converter::selectedDatabase( int num )
40{ 41{
41 m_selectedDatabase = num; 42 m_selectedDatabase = num;
42} 43}
43 44
44void Converter::selectedDestFormat( int num ) 45void Converter::selectedDestFormat( int num )
45{ 46{
46 m_selectedDestFormat = num; 47 m_selectedDestFormat = num;
47} 48}
48 49
49void Converter::selectedSourceFormat( int num ) 50void Converter::selectedSourceFormat( int num )
50{ 51{
51 m_selectedSourceFormat = num; 52 m_selectedSourceFormat = num;
52} 53}
53 54
54void Converter::start_conversion(){ 55void Converter::start_conversion(){
55 56
56 // Creating backends to the requested databases.. 57 // Creating backends to the requested databases..
57 OPimBase* sourceDB; 58 OPimBase* sourceDB;
58 OPimBase* destDB; 59 OPimBase* destDB;
59 60
60 odebug << "SourceFormat: " << m_selectedSourceFormat << oendl; 61 odebug << "SourceFormat: " << m_selectedSourceFormat << oendl;
61 odebug << "DestFormat: " << m_selectedDestFormat << oendl; 62 odebug << "DestFormat: " << m_selectedDestFormat << oendl;
62 if ( m_selectedSourceFormat == m_selectedDestFormat ){ 63 if ( m_selectedSourceFormat == m_selectedDestFormat ){
63 64
64 QMessageBox::warning( this, "PimConverter", 65 QMessageBox::warning( this, tr("PimConverter"),
65 tr( "It is not a good idea to use\n" ) 66 tr( "<qt>It is not a good idea to use"
66 +tr( "the same source and destformat !" ), 67 "the same source and destformat !</qt>"));
67 tr( "Ok" ) );
68 return; 68 return;
69 } 69 }
70 70
71 switch( m_selectedSourceFormat ){ 71 switch( m_selectedSourceFormat ){
72 case XML: 72 case XML:
73 odebug << "XMLSourceDB = " << m_selectedDatabase << "" << oendl; 73 odebug << "XMLSourceDB = " << m_selectedDatabase << "" << oendl;
74 switch( m_selectedDatabase ){ 74 switch( m_selectedDatabase ){
75 case ADDRESSBOOK:{ 75 case ADDRESSBOOK:{
76 sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" ); 76 sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" );
77 } 77 }
78 break; 78 break;
79 case TODOLIST:{ 79 case TODOLIST:{
80 sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" ); 80 sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" );
81 }break; 81 }break;
82 case DATEBOOK:{ 82 case DATEBOOK:{
83 sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" ); 83 sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" );
84 } 84 }
85 break; 85 break;
86 default: 86 default:
87 owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; 87 owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
88 return; 88 return;
89 } 89 }
90 break; 90 break;
91 case SQL: 91 case SQL:
@@ -206,108 +206,129 @@ void Converter::start_conversion(){
206 delete static_cast<ODateBookAccess*> (destDB); 206 delete static_cast<ODateBookAccess*> (destDB);
207 break; 207 break;
208 default: 208 default:
209 owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl; 209 owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
210 return; 210 return;
211 } 211 }
212 212
213 213
214 owarn << "Conversion is finished and needed " << t.elapsed() << " ms !" << oendl; 214 owarn << "Conversion is finished and needed " << t.elapsed() << " ms !" << oendl;
215} 215}
216 216
217void Converter::closeEvent( QCloseEvent *e ) 217void Converter::closeEvent( QCloseEvent *e )
218{ 218{
219 219
220 /* Due to the fact that we don't have multitasking here, this 220 /* Due to the fact that we don't have multitasking here, this
221 * critical handling don't make sense, but the future.. 221 * critical handling don't make sense, but the future..
222 */ 222 */
223 if ( m_criticalState ){ 223 if ( m_criticalState ){
224 e->ignore(); 224 e->ignore();
225 return; 225 return;
226 } 226 }
227 e->accept(); 227 e->accept();
228} 228}
229 229
230bool Converter::sqliteCopyAndConvert(const QString& src, const QString &dest, QString &cmd)
231{
232 if (!QFile::exists( src ) ) {
233 cmd = tr("No SQLite2 database exists");
234 return false;
235 }
236
237 if( QFile::exists( dest ) ) {
238 cmd = tr("A copy of the SQLite2 exists");
239 return false;
240 }
241
242 /*
243 * Copy it over
244 */
245 cmd = "cp " + Global::shellQuote(src) + " " + Global::shellQuote(dest);
246 if( ::system( cmd ) != 0 )
247 return false;
248
249 /*
250 * Delete it to make place for the new file
251 */
252 cmd = "rm " + Global::shellQuote(src);
253 if( ::system( cmd ) != 0 )
254 return false;
255
256 /*
257 * Convert it
258 */
259 cmd = "sqlite " + Global::shellQuote(dest) + " .dump | sqlite3 " + Global::shellQuote(src);
260 return ::system( cmd ) == 0;
261}
262
230 263
231 264
232void Converter::start_upgrade() 265void Converter::start_upgrade()
233{ 266{
234 odebug << "Start upgrading" << oendl; 267 odebug << "Start upgrading" << oendl;
235 switch( QMessageBox::warning( this, "Pim-Converter", 268 switch( QMessageBox::warning( this, tr("Pim-Converter"),
236 "Are you really sure that you\n" 269 tr("<qt>Are you really sure that you "
237 "want to convert your database from\n" 270 "want to convert your database from "
238 "sqlite V2 to sqlite V3?", 271 "sqlite V2 to sqlite V3?</qt>"),
239 QMessageBox::Ok | QMessageBox::Default, 272 QMessageBox::Ok | QMessageBox::Default,
240 QMessageBox::Abort | QMessageBox::Escape )) { 273 QMessageBox::Abort | QMessageBox::Escape )) {
241 274
242 case QMessageBox::Abort: // Abort clicked or Escape pressed 275 case QMessageBox::Abort: // Abort clicked or Escape pressed
243 // abort 276 // abort
244 return; 277 return;
245 break; 278 break;
246 } 279 }
247 odebug << "Checking whether sqlite is installed" << oendl; 280 odebug << "Checking whether sqlite is installed" << oendl;
248 if ( system( "which sqlite" ) != 0 ){ 281 if ( system( "which sqlite" ) != 0 ){
249 QMessageBox::critical( this, "Pim-Converter", 282 QMessageBox::critical( this, tr("Pim-Converter"),
250 QString("An internal error occurred:\n") + 283 tr("<qt>An internal error occurred: "
251 "sqlite was not accessible!\n"+ 284 "sqlite was not accessible! "
252 "Please correct the PATH or install \n" + 285 "Please correct the PATH or install "
253 "this packages!" ); 286 "this packages!</qt>") );
254 return; 287 return;
255 } 288 }
256 if ( system( "which sqlite3" ) != 0 ){ 289 if ( system( "which sqlite3" ) != 0 ){
257 QMessageBox::critical( this, "Pim-Converter", 290 QMessageBox::critical( this, tr("Pim-Converter"),
258 QString("An internal error occurred:\n") + 291 tr("<qt>An internal error occurred: "
259 "sqlite3 was not accessible!\n"+ 292 "sqlite3 was not accessible! "
260 "Please correct the PATH or install \n" + 293 "Please correct the PATH or install "
261 "this packages!" ); 294 "this packages!</qt>") );
295 return;
296 }
297
298 QString src, dest, cmd;
299 src = Global::applicationFileName("addressbook", "addressbook.db" );
300 dest = Global::applicationFileName("addressbook", "addressbook.db_v2" );
301
302 if(!sqliteCopyAndConvert(src, dest, cmd)) {
303 QMessageBox::critical( this, tr("Pim-Converter"),
304 tr("<qt>An internal error occurred: "
305 "Converting the addressbook command was impossible! "
306 "Executed the following command: %1</qt>").arg(cmd) );
262 return; 307 return;
263 } 308 }
264 if ( QFile::exists( "~/Applications/addressbook/addressbook.db" ) 309
265 && !QFile::exists( "~/Applications/addressbook/addressbook.db_v2" ) ){ 310 src = Global::applicationFileName("datebook", "datebook.db" );
266 odebug << "Executing conversion commands" << oendl; 311 dest = Global::applicationFileName("datebook", "datebook.db_v2" );
267 QString addr_convert_string = "cd ~/Applications/addressbook/;cp addressbook.db addressbook.db_v2;sqlite addressbook.db_v2 .dump | sqlite3 addressbook.db"; 312 if(!sqliteCopyAndConvert(src, dest, cmd)) {
268 odebug << "1. Addressbook Command:" << addr_convert_string << oendl; 313 QMessageBox::critical( this, tr("Pim-Converter"),
269 if ( system( addr_convert_string ) != 0 ){ 314 tr("<qt>An internal error occurred: "
270 QMessageBox::critical( this, "Pim-Converter", 315 "Converting the datebook command was impossible! "
271 QString("An internal error occurred:\n") + 316 "Executed the following command: '%1' </qt>").arg(cmd)
272 "Converting the addressbook command was impossible!\n"+ 317 );
273 "Executed the following command:\n" + 318 return;
274 addr_convert_string );
275 return;
276 }
277 }
278 if ( QFile::exists( "~/Applications/datebook/datebook.db" )
279 && !QFile::exists( "~/Applications/datebook/datebook.db_v2" ) ){
280 QString dateb_convert_string = "cd ~/Applications/datebook/;cp datebook.db datebook.db_v2;sqlite datebook.db_v2 .dump | sqlite3 datebook.db";
281 odebug << "2. Datebook Command" << dateb_convert_string << oendl;
282 if ( system( dateb_convert_string ) != 0 ){
283 QMessageBox::critical( this, "Pim-Converter",
284 QString("An internal error occurred:\n") +
285 "Converting the datebook command was impossible!\n"+
286 "Executed the following command:\n" +
287 dateb_convert_string );
288 return;
289 }
290 } 319 }
291 320
292 if ( QFile::exists( "~/Applications/todolist/todolist.db" ) 321 src = Global::applicationFileName("todolist", "todolist.db" );
293 && !QFile::exists( "~/Applications/todolist/todolist.db_v2" ) ){ 322 dest = Global::applicationFileName("todolist", "todolist.db_v2" );
294 QString todo_convert_string = "cd ~/Applications/todolist/;cp todolist.db todolist.db_v2;sqlite todolist.db_v2 .dump | sqlite3 todolist.db"; 323 if(!sqliteCopyAndConvert(src, dest, cmd)) {
295 odebug << "3. Todolist Command:" << todo_convert_string << oendl; 324 QMessageBox::critical( this, tr("Pim-Converter"),
296 if ( system( todo_convert_string ) != 0 ){ 325 tr("<qt>An internal error occurred: "
297 QMessageBox::critical( this, "Pim-Converter", 326 "Converting the todolist command was impossible! "
298 QString("An internal error occurred:\n") + 327 "Executed the following command: '%1' </qt>").arg(cmd) );
299 "Converting the todolist command was impossible!\n"+ 328 return;
300 "Executed the following command:\n" +
301 todo_convert_string );
302 return;
303 }
304 } 329 }
305 330
306 QMessageBox::information( this, "Pim-Converter", 331 QMessageBox::information( this, tr("Pim-Converter"),
307 "Conversion is finished!", 332 tr("Conversion is finished!"),
308 "&OK", NULL, NULL, 333 QMessageBox::Ok );
309 0, // Enter == button 0
310 0 );
311
312
313} 334}
diff --git a/noncore/tools/pimconverter/converter.h b/noncore/tools/pimconverter/converter.h
index 9d75d79..e9035e7 100755
--- a/noncore/tools/pimconverter/converter.h
+++ b/noncore/tools/pimconverter/converter.h
@@ -19,28 +19,31 @@ public:
19 19
20 void closeEvent( QCloseEvent *e ); 20 void closeEvent( QCloseEvent *e );
21 21
22private: 22private:
23 // Caution: 23 // Caution:
24 // The order and value of the following enums must be regarding 24 // The order and value of the following enums must be regarding
25 // the predefinition in the UI-File !! 25 // the predefinition in the UI-File !!
26 // If you don't understand what I am talking about: Keep your fingers away!! 26 // If you don't understand what I am talking about: Keep your fingers away!!
27 enum DataBases{ 27 enum DataBases{
28 ADDRESSBOOK = 0, 28 ADDRESSBOOK = 0,
29 TODOLIST = 1, 29 TODOLIST = 1,
30 DATEBOOK = 2, 30 DATEBOOK = 2,
31 }; 31 };
32 32
33 enum DbFormats{ 33 enum DbFormats{
34 XML = 0, 34 XML = 0,
35 SQL = 1, 35 SQL = 1,
36 }; 36 };
37 37
38 int m_selectedDatabase; 38 int m_selectedDatabase;
39 int m_selectedSourceFormat; 39 int m_selectedSourceFormat;
40 int m_selectedDestFormat; 40 int m_selectedDestFormat;
41 bool m_criticalState; 41 bool m_criticalState;
42 42
43
44private:
45 static bool sqliteCopyAndConvert( const QString &src, const QString &destination, QString &lastCommand );
43}; 46};
44 47
45 48
46#endif 49#endif