summaryrefslogtreecommitdiff
authoreilers <eilers>2004-07-18 14:37:20 (UTC)
committer eilers <eilers>2004-07-18 14:37:20 (UTC)
commit30775961a5c33d4721395eb07d11c4fcc142ce96 (patch) (side-by-side diff)
tree99858db337e64689f31b0099c48a26a41e1fc136
parentf37561246bc7d8bf4cf791ce156afdf098552dca (diff)
downloadopie-30775961a5c33d4721395eb07d11c4fcc142ce96.zip
opie-30775961a5c33d4721395eb07d11c4fcc142ce96.tar.gz
opie-30775961a5c33d4721395eb07d11c4fcc142ce96.tar.bz2
Fixed bugreport #1370 and
added check, whether source and destdatabase is the same..
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/pimconverter/converter.cpp34
-rwxr-xr-xnoncore/tools/pimconverter/converter.h3
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,207 +1,239 @@
#include "converter.h"
/* OPIE */
#include <qpe/qpeapplication.h>
#include <opie2/odebug.h>
#include <opie2/opimglobal.h>
// Include SQL related header files
#define __USE_SQL
#include <opie2/opimaccessfactory.h>
/* QT */
#include <qdatetime.h>
#include <qprogressbar.h>
#include <qcombobox.h>
#include <qcheckbox.h>
+#include <qmessagebox.h>
using namespace Opie;
using namespace Pim;
Converter::Converter():
m_selectedDatabase( ADDRESSBOOK ),
m_selectedSourceFormat( XML ),
- m_selectedDestFormat( SQL )
+ m_selectedDestFormat( SQL ),
+ m_criticalState( false )
{
m_dataBaseSelector -> setCurrentItem( m_selectedDatabase );
m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat );
m_destFormatSelector -> setCurrentItem( m_selectedDestFormat );
m_eraseDB -> setChecked( true ); // Default erase on copy
}
void Converter::selectedDatabase( int num )
{
m_selectedDatabase = num;
}
void Converter::selectedDestFormat( int num )
{
m_selectedDestFormat = num;
}
void Converter::selectedSourceFormat( int num )
{
m_selectedSourceFormat = num;
}
void Converter::start_conversion(){
// Creating backends to the requested databases..
OPimBase* sourceDB;
OPimBase* destDB;
+ odebug << "SourceFormat: " << m_selectedSourceFormat << oendl;
+ odebug << "DestFormat: " << m_selectedDestFormat << oendl;
+ if ( m_selectedSourceFormat == m_selectedDestFormat ){
+
+ QMessageBox::warning( this, "PimConverter",
+ tr( "It is not a good idea to use\n" )
+ +tr( "the same source and destformat !" ),
+ tr( "Ok" ) );
+ return;
+ }
+
switch( m_selectedSourceFormat ){
case XML:
odebug << "XMLSourceDB = " << m_selectedDatabase << "" << oendl;
switch( m_selectedDatabase ){
case ADDRESSBOOK:{
sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" );
}
break;
case TODOLIST:{
sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" );
}break;
case DATEBOOK:{
sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" );
}
break;
default:
owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
return;
}
break;
case SQL:
odebug << "SQLSourceDB = " << m_selectedDatabase << "" << oendl;
switch( m_selectedDatabase ){
case ADDRESSBOOK:{
sourceDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::SQL, "converter" );
}
break;
case TODOLIST:{
sourceDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::SQL, "converter" );
}break;
case DATEBOOK:{
sourceDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" );
}
break;
default:
owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
return;
}
break;
default:
owarn << "Unknown source format selected (" << m_selectedSourceFormat << ") !!" << oendl;
return;
}
switch ( m_selectedDestFormat ){
case XML:
odebug << "XMLDestDB = " << m_selectedDatabase << "" << oendl;
switch( m_selectedDatabase ){
case ADDRESSBOOK:{
destDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::XML, "converter" );
}
break;
case TODOLIST:{
destDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "converter" );
}break;
case DATEBOOK:{
destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::XML, "converter" );
}
break;
default:
owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
return;
}
break;
case SQL:
odebug << "SQLDestDB = " << m_selectedDatabase << "" << oendl;
switch( m_selectedDatabase ){
case ADDRESSBOOK:{
destDB = OPimAccessFactory<OPimContactAccess>::create( OPimGlobal::CONTACTLIST, OPimGlobal::SQL, "converter" );
}
break;
case TODOLIST:{
destDB = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::SQL, "converter" );
}break;
case DATEBOOK:{
destDB = OPimAccessFactory<ODateBookAccess>::create( OPimGlobal::DATEBOOK, OPimGlobal::SQL, "converter" );
}
break;
default:
owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
return;
}
break;
default:
owarn << "Unknown destination format selected (" << m_selectedDestFormat << ")!!" << oendl;
return;
}
if ( !sourceDB || !destDB )
return;
+ m_criticalState = true;
+
sourceDB -> load();
destDB -> load();
QTime t;
t.start();
// Clean the dest-database if requested (isChecked)
if ( m_eraseDB -> isChecked() ){
odebug << "Clearing destination database!" << oendl;
destDB -> clear();
}
// Now transmit every pim-item from the source database to the destination -database
QArray<int> uidList = sourceDB->records();
odebug << "Try to move data for addressbook.. (" << uidList.count() << " items) " << oendl;
m_progressBar->setTotalSteps( uidList.count() );
int count = 0;
for ( uint i = 0; i < uidList.count(); ++i ){
odebug << "Adding uid: " << uidList[i] << "" << oendl;
OPimRecord* rec = sourceDB -> record( uidList[i] );
destDB -> add( rec );
m_progressBar->setProgress( ++count );
}
// Now commit data..
destDB -> save();
+ m_criticalState = false;
+
// Delete the frontends. Backends will be deleted automatically, too !
// We have to cast them back to delete them properly !
switch( m_selectedDatabase ){
case ADDRESSBOOK:
delete static_cast<OPimContactAccess*> (sourceDB);
delete static_cast<OPimContactAccess*> (destDB);
break;
case TODOLIST:
delete static_cast<OPimTodoAccess*> (sourceDB);
delete static_cast<OPimTodoAccess*> (destDB);
break;
case DATEBOOK:
delete static_cast<ODateBookAccess*> (sourceDB);
delete static_cast<ODateBookAccess*> (destDB);
break;
default:
owarn << "Unknown database selected (" << m_selectedDatabase << ")" << oendl;
return;
}
owarn << "Conversion is finished and needed " << t.elapsed() << " ms !" << oendl;
}
+void Converter::closeEvent( QCloseEvent *e )
+{
+
+ /* Due to the fact that we don't have multitasking here, this
+ * critical handling don't make sense, but the future..
+ */
+ if ( m_criticalState ){
+ e->ignore();
+ return;
+ }
+ e->accept();
+}
+
+
+
int main( int argc, char** argv ) {
QPEApplication a( argc, argv );
Converter dlg;
a.showMainWidget( &dlg );
// dlg. showMaximized ( );
return a.exec();
}
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 @@
#ifndef _CONVERTER_H_
#define _CONVERTER_H_
#include "converter_base.h"
class Converter: public converter_base {
public:
Converter();
// Slots defined in the ui-description file
void start_conversion();
void selectedDatabase( int num );
void selectedDestFormat( int num );
void selectedSourceFormat( int num );
+ void closeEvent( QCloseEvent *e );
+
private:
// Caution:
// The order and value of the following enums must be regarding
// the predefinition in the UI-File !!
enum DataBases{
ADDRESSBOOK = 0,
TODOLIST = 1,
DATEBOOK = 2,
};
enum DbFormats{
XML = 0,
SQL = 1,
};
int m_selectedDatabase;
int m_selectedSourceFormat;
int m_selectedDestFormat;
+ bool m_criticalState;
};
#endif