author | zecke <zecke> | 2004-10-23 21:51:16 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-10-23 21:51:16 (UTC) |
commit | 9c5964f8d2be467aa53d3d8255b499890556e320 (patch) (unidiff) | |
tree | 91507b2507cbfda0896541dde082e065444126df | |
parent | cbcdbc9d68e493a4229b24a57075d617ae99ca70 (diff) | |
download | opie-9c5964f8d2be467aa53d3d8255b499890556e320.zip opie-9c5964f8d2be467aa53d3d8255b499890556e320.tar.gz opie-9c5964f8d2be467aa53d3d8255b499890556e320.tar.bz2 |
-Move code for converting sqlite2 to sqlite3 to a method on its own
-Use Global::applicationFileName to get the filenames for the data
-Use tr around messages
-Do not use custom labels for "Ok" but use Qts QMessageBox ones to get
its translation for free
TODO: Test on ARM
-rw-r--r-- | noncore/tools/pimconverter/converter.cpp | 139 | ||||
-rwxr-xr-x | noncore/tools/pimconverter/converter.h | 3 |
2 files changed, 83 insertions, 59 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 | |||
@@ -6,6 +6,7 @@ | |||
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> |
@@ -61,10 +62,9 @@ void Converter::start_conversion(){ | |||
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 | ||
@@ -227,15 +227,48 @@ void Converter::closeEvent( QCloseEvent *e ) | |||
227 | e->accept(); | 227 | e->accept(); |
228 | } | 228 | } |
229 | 229 | ||
230 | bool 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 | ||
232 | void Converter::start_upgrade() | 265 | void 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 | ||
@@ -246,68 +279,56 @@ void Converter::start_upgrade() | |||
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>") ); |
262 | return; | 295 | return; |
263 | } | 296 | } |
264 | if ( QFile::exists( "~/Applications/addressbook/addressbook.db" ) | 297 | |
265 | && !QFile::exists( "~/Applications/addressbook/addressbook.db_v2" ) ){ | 298 | QString src, dest, cmd; |
266 | odebug << "Executing conversion commands" << oendl; | 299 | src = Global::applicationFileName("addressbook", "addressbook.db" ); |
267 | QString addr_convert_string = "cd ~/Applications/addressbook/;cp addressbook.db addressbook.db_v2;sqlite addressbook.db_v2 .dump | sqlite3 addressbook.db"; | 300 | dest = Global::applicationFileName("addressbook", "addressbook.db_v2" ); |
268 | odebug << "1. Addressbook Command:" << addr_convert_string << oendl; | 301 | |
269 | if ( system( addr_convert_string ) != 0 ){ | 302 | if(!sqliteCopyAndConvert(src, dest, cmd)) { |
270 | QMessageBox::critical( this, "Pim-Converter", | 303 | QMessageBox::critical( this, tr("Pim-Converter"), |
271 | QString("An internal error occurred:\n") + | 304 | tr("<qt>An internal error occurred: " |
272 | "Converting the addressbook command was impossible!\n"+ | 305 | "Converting the addressbook command was impossible! " |
273 | "Executed the following command:\n" + | 306 | "Executed the following command: %1</qt>").arg(cmd) ); |
274 | addr_convert_string ); | ||
275 | return; | 307 | return; |
276 | } | 308 | } |
277 | } | 309 | |
278 | if ( QFile::exists( "~/Applications/datebook/datebook.db" ) | 310 | src = Global::applicationFileName("datebook", "datebook.db" ); |
279 | && !QFile::exists( "~/Applications/datebook/datebook.db_v2" ) ){ | 311 | dest = Global::applicationFileName("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"; | 312 | if(!sqliteCopyAndConvert(src, dest, cmd)) { |
281 | odebug << "2. Datebook Command" << dateb_convert_string << oendl; | 313 | QMessageBox::critical( this, tr("Pim-Converter"), |
282 | if ( system( dateb_convert_string ) != 0 ){ | 314 | tr("<qt>An internal error occurred: " |
283 | QMessageBox::critical( this, "Pim-Converter", | 315 | "Converting the datebook command was impossible! " |
284 | QString("An internal error occurred:\n") + | 316 | "Executed the following command: '%1' </qt>").arg(cmd) |
285 | "Converting the datebook command was impossible!\n"+ | 317 | ); |
286 | "Executed the following command:\n" + | ||
287 | dateb_convert_string ); | ||
288 | return; | 318 | return; |
289 | } | 319 | } |
290 | } | ||
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"+ | ||
300 | "Executed the following command:\n" + | ||
301 | todo_convert_string ); | ||
302 | return; | 328 | return; |
303 | } | 329 | } |
304 | } | ||
305 | |||
306 | QMessageBox::information( this, "Pim-Converter", | ||
307 | "Conversion is finished!", | ||
308 | "&OK", NULL, NULL, | ||
309 | 0, // Enter == button 0 | ||
310 | 0 ); | ||
311 | |||
312 | 330 | ||
331 | QMessageBox::information( this, tr("Pim-Converter"), | ||
332 | tr("Conversion is finished!"), | ||
333 | QMessageBox::Ok ); | ||
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 | |||
@@ -40,6 +40,9 @@ private: | |||
40 | int m_selectedDestFormat; | 40 | int m_selectedDestFormat; |
41 | bool m_criticalState; | 41 | bool m_criticalState; |
42 | 42 | ||
43 | |||
44 | private: | ||
45 | static bool sqliteCopyAndConvert( const QString &src, const QString &destination, QString &lastCommand ); | ||
43 | }; | 46 | }; |
44 | 47 | ||
45 | 48 | ||