-rw-r--r-- | noncore/tools/pimconverter/config.in | 8 | ||||
-rw-r--r-- | noncore/tools/pimconverter/converter.cpp | 224 | ||||
-rwxr-xr-x | noncore/tools/pimconverter/converter.h | 40 | ||||
-rw-r--r-- | noncore/tools/pimconverter/converter.pro | 11 | ||||
-rw-r--r-- | noncore/tools/pimconverter/converter_base.ui | 291 |
5 files changed, 574 insertions, 0 deletions
diff --git a/noncore/tools/pimconverter/config.in b/noncore/tools/pimconverter/config.in new file mode 100644 index 0000000..f797d4f --- a/dev/null +++ b/noncore/tools/pimconverter/config.in @@ -0,0 +1,8 @@ + config PIMCONVERTER + boolean "opie- Pim Converter (converts pim data between different databases)" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2PIM && LIBOPIE2DB + + comment "The pim converter needs libqpe, libopie2core, libopie2pim and libopie2db" + depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2PIM && LIBOPIE2DB ) + diff --git a/noncore/tools/pimconverter/converter.cpp b/noncore/tools/pimconverter/converter.cpp new file mode 100644 index 0000000..1091f4a --- a/dev/null +++ b/noncore/tools/pimconverter/converter.cpp @@ -0,0 +1,224 @@ +#include "converter.h" + +#include <qdatetime.h> +#include <qprogressbar.h> +#include <qcombobox.h> +#include <qcheckbox.h> + +#include <qpe/qpeapplication.h> + +#include <opie2/ocontactaccess.h> +#include <opie2/ocontactaccessbackend_xml.h> +#include <opie2/ocontactaccessbackend_sql.h> + +#include <opie2/otodoaccess.h> +#include <opie2/otodoaccessxml.h> +#include <opie2/otodoaccesssql.h> + +#include <opie2/odatebookaccess.h> +#include <opie2/odatebookaccessbackend_xml.h> +#include <opie2/odatebookaccessbackend_sql.h> + +// #define _ADDRESSBOOK_ACCESS + +using namespace Opie; + +Converter::Converter(): + m_selectedDatabase( ADDRESSBOOK ), + m_selectedSourceFormat( XML ), + m_selectedDestFormat( SQL ) +{ + 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; + + switch( m_selectedSourceFormat ){ + case XML: + qDebug("XMLSourceDB = %d", m_selectedDatabase); + switch( m_selectedDatabase ){ + case ADDRESSBOOK:{ + OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_XML( "Converter", QString::null ); + sourceDB = new OPimContactAccess ( "addressbook_xml", QString::null , sourceBackend, true ); + } + break; + case TODOLIST:{ + OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessXML( "Converter" ); + sourceDB = new OPimTodoAccess( sourceBackend ); + }break; + case DATEBOOK:{ + ODateBookAccessBackend_XML* sourceBackend = new ODateBookAccessBackend_XML( "Converter", QString::null ); + sourceDB = new ODateBookAccess ( sourceBackend ); + } + break; + default: + qWarning( "Unknown database selected (%d)", m_selectedDatabase ); + return; + } + break; + case SQL: + qDebug("SQLSourceDB = %d", m_selectedDatabase); + switch( m_selectedDatabase ){ + case ADDRESSBOOK:{ + qDebug("SQLSourceDB = %d", m_selectedDatabase); + OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null ); + sourceDB = new OPimContactAccess ( "Converter", QString::null, sourceBackend, true ); + } + break; + case TODOLIST:{ + OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessBackendSQL( QString::null ); + sourceDB = new OPimTodoAccess( sourceBackend ); + }break; + case DATEBOOK: { + ODateBookAccessBackend_SQL* sourceBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null ); + sourceDB = new ODateBookAccess ( sourceBackend ); + } + break; + default: + qWarning( "Unknown database selected (%d)", m_selectedDatabase ); + return; + } + break; + default: + qWarning( "Unknown source format selected (%d) !!", m_selectedSourceFormat ); + return; + } + + switch ( m_selectedDestFormat ){ + case XML: + qDebug("XMLDestDB = %d", m_selectedDatabase); + switch( m_selectedDatabase ){ + case ADDRESSBOOK:{ + OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_XML( "Converter", QString::null ); + destDB = new OPimContactAccess ( "Converter", QString::null , destBackend, true ); + } + break; + case TODOLIST:{ + OPimTodoAccessBackend* destBackend = new OPimTodoAccessXML( "Converter" ); + destDB = new OPimTodoAccess( destBackend ); + }break; + case DATEBOOK:{ + ODateBookAccessBackend_XML* destBackend = new ODateBookAccessBackend_XML( "Converter", QString::null ); + destDB = new ODateBookAccess ( destBackend ); + } + break; + default: + qWarning( "Unknown database selected (%d)", m_selectedDatabase ); + return; + } + break; + case SQL: + qDebug("SQLDestDB = %d", m_selectedDatabase); + switch( m_selectedDatabase ){ + case ADDRESSBOOK:{ + OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null ); + destDB = new OPimContactAccess ( "addressbook_xml", QString::null , destBackend, true ); + } + break; + case TODOLIST:{ + OPimTodoAccessBackend* destBackend = new OPimTodoAccessBackendSQL( QString::null ); + destDB = new OPimTodoAccess( destBackend ); + }break; + case DATEBOOK:{ + ODateBookAccessBackend_SQL* destBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null ); + destDB = new ODateBookAccess ( destBackend ); + } + break; + default: + qWarning( "Unknown database selected (%d)", m_selectedDatabase ); + return; + } + break; + default: + qWarning( "Unknown destination format selected (%d)!!", m_selectedDestFormat ); + return; + } + + if ( !sourceDB || !destDB ) + return; + + sourceDB -> load(); + destDB -> load(); + + QTime t; + t.start(); + + // Clean the dest-database if requested (isChecked) + if ( m_eraseDB -> isChecked() ){ + qDebug( "Clearing destination database!" ); + destDB -> clear(); + } + + // Now transmit every pim-item from the source database to the destination -database + QArray<int> uidList = sourceDB->records(); + qDebug( "Try to move data for addressbook.. (%d items) ", uidList.count() ); + m_progressBar->setTotalSteps( uidList.count() ); + int count = 0; + for ( uint i = 0; i < uidList.count(); ++i ){ + qDebug( "Adding uid: %d", uidList[i] ); + OPimRecord* rec = sourceDB -> record( uidList[i] ); + destDB -> add( rec ); + m_progressBar->setProgress( ++count ); + } + + // Now commit data.. + destDB -> save(); + + // 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: + qWarning( "Unknown database selected (%d)", m_selectedDatabase ); + return; + } + + + qWarning("Conversion is finished and needed %d ms !", t.elapsed()); +} + +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 new file mode 100755 index 0000000..27d7fb2 --- a/dev/null +++ b/noncore/tools/pimconverter/converter.h @@ -0,0 +1,40 @@ +#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 ); + +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; + +}; + + +#endif diff --git a/noncore/tools/pimconverter/converter.pro b/noncore/tools/pimconverter/converter.pro new file mode 100644 index 0000000..0504a55 --- a/dev/null +++ b/noncore/tools/pimconverter/converter.pro @@ -0,0 +1,11 @@ +CONFIG = qt warn_on debug +# CONFIG = qt warn_on release quick-app +HEADERS = converter.h +SOURCES = converter.cpp +INTERFACES = converter_base.ui +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe -lopiecore2 -lopiepim2 -lopiedb2 +TARGET = $(OPIEDIR)/bin/opimconverter + +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/tools/pimconverter/converter_base.ui b/noncore/tools/pimconverter/converter_base.ui new file mode 100644 index 0000000..c7a2fb5 --- a/dev/null +++ b/noncore/tools/pimconverter/converter_base.ui @@ -0,0 +1,291 @@ +<!DOCTYPE UI><UI> +<class>converter_base</class> +<widget> + <class>QDialog</class> + <property stdset="1"> + <name>name</name> + <cstring>converter_base</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>269</width> + <height>324</height> + </rect> + </property> + <property stdset="1"> + <name>caption</name> + <string>PIM-Database Converter</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" > + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox6</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Converter</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox1</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Select Database:</string> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>Addressbook</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>TodoList</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>Datebook</string> + </property> + </item> + <property stdset="1"> + <name>name</name> + <cstring>m_dataBaseSelector</cstring> + </property> + </widget> + </grid> + </widget> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox2</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Source/Destination:</string> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>to</string> + </property> + </widget> + <widget row="1" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>XML</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>SQL (SQLite)</string> + </property> + </item> + <property stdset="1"> + <name>name</name> + <cstring>m_destFormatSelector</cstring> + </property> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Convert from</string> + </property> + </widget> + <widget row="0" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>XML</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>SQL (SQLite)</string> + </property> + </item> + <property stdset="1"> + <name>name</name> + <cstring>m_sourceFormatSelector</cstring> + </property> + </widget> + </grid> + </widget> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox5</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Config:</string> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" > + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>m_eraseDB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Erase before copy</string> + </property> + </widget> + </grid> + </widget> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox4</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Progress:</string> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>m_progressBar</cstring> + </property> + </widget> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>PushButton1</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Go!</string> + </property> + </widget> + </vbox> + </widget> + </vbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>PushButton1</sender> + <signal>clicked()</signal> + <receiver>converter_base</receiver> + <slot>start_conversion()</slot> + </connection> + <connection> + <sender>m_sourceFormatSelector</sender> + <signal>activated(int)</signal> + <receiver>converter_base</receiver> + <slot>selectedSourceFormat(int)</slot> + </connection> + <connection> + <sender>m_dataBaseSelector</sender> + <signal>activated(int)</signal> + <receiver>converter_base</receiver> + <slot>selectedDatabase(int)</slot> + </connection> + <connection> + <sender>m_destFormatSelector</sender> + <signal>activated(int)</signal> + <receiver>converter_base</receiver> + <slot>selectedDestFormat(int)</slot> + </connection> + <slot access="public">selectedDatabase(int)</slot> + <slot access="public">selectedDestFormat(int)</slot> + <slot access="public">selectedSourceFormat(int)</slot> + <slot access="public">start_conversion()</slot> +</connections> +</UI> |