summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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
@@ -9,25 +9,27 @@
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
19using namespace Opie; 20using namespace Opie;
20using namespace Pim; 21using namespace Pim;
21 22
22Converter::Converter(): 23Converter::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
33void Converter::selectedDatabase( int num ) 35void Converter::selectedDatabase( int num )
@@ -46,16 +48,27 @@ void Converter::selectedSourceFormat( int num )
46} 48}
47 49
48void Converter::start_conversion(){ 50void 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;
@@ -137,16 +150,18 @@ void Converter::start_conversion(){
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() ){
@@ -164,16 +179,18 @@ void Converter::start_conversion(){
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:
@@ -188,16 +205,31 @@ void Converter::start_conversion(){
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
213void 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
196int main( int argc, char** argv ) { 228int 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 ( );
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
@@ -9,16 +9,18 @@ class Converter: public converter_base {
9public: 9public:
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
18private: 20private:
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,
@@ -28,13 +30,14 @@ private:
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