summaryrefslogtreecommitdiff
path: root/noncore
authoreilers <eilers>2004-04-28 10:40:10 (UTC)
committer eilers <eilers>2004-04-28 10:40:10 (UTC)
commit0c9020f9016ec7058b6aef3fda36865f293f4f4a (patch) (unidiff)
tree1aa0de19d395ebf5ff5a7339bb4f24d37a91b6fa /noncore
parent7784d05b07dc65eab1754497e71fbf56d714b048 (diff)
downloadopie-0c9020f9016ec7058b6aef3fda36865f293f4f4a.zip
opie-0c9020f9016ec7058b6aef3fda36865f293f4f4a.tar.gz
opie-0c9020f9016ec7058b6aef3fda36865f293f4f4a.tar.bz2
First demo release of the PIM database conversion tool..
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/pimconverter/config.in8
-rw-r--r--noncore/tools/pimconverter/converter.cpp224
-rwxr-xr-xnoncore/tools/pimconverter/converter.h40
-rw-r--r--noncore/tools/pimconverter/converter.pro11
-rw-r--r--noncore/tools/pimconverter/converter_base.ui291
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 @@
1 config PIMCONVERTER
2 boolean "opie- Pim Converter (converts pim data between different databases)"
3 default "n"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2PIM && LIBOPIE2DB
5
6 comment "The pim converter needs libqpe, libopie2core, libopie2pim and libopie2db"
7 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2PIM && LIBOPIE2DB )
8
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 @@
1#include "converter.h"
2
3#include <qdatetime.h>
4#include <qprogressbar.h>
5#include <qcombobox.h>
6#include <qcheckbox.h>
7
8#include <qpe/qpeapplication.h>
9
10#include <opie2/ocontactaccess.h>
11#include <opie2/ocontactaccessbackend_xml.h>
12#include <opie2/ocontactaccessbackend_sql.h>
13
14#include <opie2/otodoaccess.h>
15#include <opie2/otodoaccessxml.h>
16#include <opie2/otodoaccesssql.h>
17
18#include <opie2/odatebookaccess.h>
19#include <opie2/odatebookaccessbackend_xml.h>
20#include <opie2/odatebookaccessbackend_sql.h>
21
22// #define _ADDRESSBOOK_ACCESS
23
24using namespace Opie;
25
26Converter::Converter():
27 m_selectedDatabase( ADDRESSBOOK ),
28 m_selectedSourceFormat( XML ),
29 m_selectedDestFormat( SQL )
30{
31 m_dataBaseSelector -> setCurrentItem( m_selectedDatabase );
32 m_sourceFormatSelector -> setCurrentItem( m_selectedSourceFormat );
33 m_destFormatSelector -> setCurrentItem( m_selectedDestFormat );
34 m_eraseDB -> setChecked( true ); // Default erase on copy
35}
36
37void Converter::selectedDatabase( int num )
38{
39 m_selectedDatabase = num;
40}
41
42void Converter::selectedDestFormat( int num )
43{
44 m_selectedDestFormat = num;
45}
46
47void Converter::selectedSourceFormat( int num )
48{
49 m_selectedSourceFormat = num;
50}
51
52void Converter::start_conversion(){
53
54 // Creating backends to the requested databases..
55 OPimBase* sourceDB;
56 OPimBase* destDB;
57
58 switch( m_selectedSourceFormat ){
59 case XML:
60 qDebug("XMLSourceDB = %d", m_selectedDatabase);
61 switch( m_selectedDatabase ){
62 case ADDRESSBOOK:{
63 OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_XML( "Converter", QString::null );
64 sourceDB = new OPimContactAccess ( "addressbook_xml", QString::null , sourceBackend, true );
65 }
66 break;
67 case TODOLIST:{
68 OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessXML( "Converter" );
69 sourceDB = new OPimTodoAccess( sourceBackend );
70 }break;
71 case DATEBOOK:{
72 ODateBookAccessBackend_XML* sourceBackend = new ODateBookAccessBackend_XML( "Converter", QString::null );
73 sourceDB = new ODateBookAccess ( sourceBackend );
74 }
75 break;
76 default:
77 qWarning( "Unknown database selected (%d)", m_selectedDatabase );
78 return;
79 }
80 break;
81 case SQL:
82 qDebug("SQLSourceDB = %d", m_selectedDatabase);
83 switch( m_selectedDatabase ){
84 case ADDRESSBOOK:{
85 qDebug("SQLSourceDB = %d", m_selectedDatabase);
86 OPimContactAccessBackend* sourceBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null );
87 sourceDB = new OPimContactAccess ( "Converter", QString::null, sourceBackend, true );
88 }
89 break;
90 case TODOLIST:{
91 OPimTodoAccessBackend* sourceBackend = new OPimTodoAccessBackendSQL( QString::null );
92 sourceDB = new OPimTodoAccess( sourceBackend );
93 }break;
94 case DATEBOOK: {
95 ODateBookAccessBackend_SQL* sourceBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null );
96 sourceDB = new ODateBookAccess ( sourceBackend );
97 }
98 break;
99 default:
100 qWarning( "Unknown database selected (%d)", m_selectedDatabase );
101 return;
102 }
103 break;
104 default:
105 qWarning( "Unknown source format selected (%d) !!", m_selectedSourceFormat );
106 return;
107 }
108
109 switch ( m_selectedDestFormat ){
110 case XML:
111 qDebug("XMLDestDB = %d", m_selectedDatabase);
112 switch( m_selectedDatabase ){
113 case ADDRESSBOOK:{
114 OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_XML( "Converter", QString::null );
115 destDB = new OPimContactAccess ( "Converter", QString::null , destBackend, true );
116 }
117 break;
118 case TODOLIST:{
119 OPimTodoAccessBackend* destBackend = new OPimTodoAccessXML( "Converter" );
120 destDB = new OPimTodoAccess( destBackend );
121 }break;
122 case DATEBOOK:{
123 ODateBookAccessBackend_XML* destBackend = new ODateBookAccessBackend_XML( "Converter", QString::null );
124 destDB = new ODateBookAccess ( destBackend );
125 }
126 break;
127 default:
128 qWarning( "Unknown database selected (%d)", m_selectedDatabase );
129 return;
130 }
131 break;
132 case SQL:
133 qDebug("SQLDestDB = %d", m_selectedDatabase);
134 switch( m_selectedDatabase ){
135 case ADDRESSBOOK:{
136 OPimContactAccessBackend* destBackend = new OPimContactAccessBackend_SQL( QString::null, QString::null );
137 destDB = new OPimContactAccess ( "addressbook_xml", QString::null , destBackend, true );
138 }
139 break;
140 case TODOLIST:{
141 OPimTodoAccessBackend* destBackend = new OPimTodoAccessBackendSQL( QString::null );
142 destDB = new OPimTodoAccess( destBackend );
143 }break;
144 case DATEBOOK:{
145 ODateBookAccessBackend_SQL* destBackend = new ODateBookAccessBackend_SQL( "Converter", QString::null );
146 destDB = new ODateBookAccess ( destBackend );
147 }
148 break;
149 default:
150 qWarning( "Unknown database selected (%d)", m_selectedDatabase );
151 return;
152 }
153 break;
154 default:
155 qWarning( "Unknown destination format selected (%d)!!", m_selectedDestFormat );
156 return;
157 }
158
159 if ( !sourceDB || !destDB )
160 return;
161
162 sourceDB -> load();
163 destDB -> load();
164
165 QTime t;
166 t.start();
167
168 // Clean the dest-database if requested (isChecked)
169 if ( m_eraseDB -> isChecked() ){
170 qDebug( "Clearing destination database!" );
171 destDB -> clear();
172 }
173
174 // Now transmit every pim-item from the source database to the destination -database
175 QArray<int> uidList = sourceDB->records();
176 qDebug( "Try to move data for addressbook.. (%d items) ", uidList.count() );
177 m_progressBar->setTotalSteps( uidList.count() );
178 int count = 0;
179 for ( uint i = 0; i < uidList.count(); ++i ){
180 qDebug( "Adding uid: %d", uidList[i] );
181 OPimRecord* rec = sourceDB -> record( uidList[i] );
182 destDB -> add( rec );
183 m_progressBar->setProgress( ++count );
184 }
185
186 // Now commit data..
187 destDB -> save();
188
189 // Delete the frontends. Backends will be deleted automatically, too !
190 // We have to cast them back to delete them properly !
191 switch( m_selectedDatabase ){
192 case ADDRESSBOOK:
193 delete static_cast<OPimContactAccess*> (sourceDB);
194 delete static_cast<OPimContactAccess*> (destDB);
195 break;
196 case TODOLIST:
197 delete static_cast<OPimTodoAccess*> (sourceDB);
198 delete static_cast<OPimTodoAccess*> (destDB);
199 break;
200 case DATEBOOK:
201 delete static_cast<ODateBookAccess*> (sourceDB);
202 delete static_cast<ODateBookAccess*> (destDB);
203 break;
204 default:
205 qWarning( "Unknown database selected (%d)", m_selectedDatabase );
206 return;
207 }
208
209
210 qWarning("Conversion is finished and needed %d ms !", t.elapsed());
211}
212
213int main( int argc, char** argv ) {
214
215 QPEApplication a( argc, argv );
216
217 Converter dlg;
218
219 a.showMainWidget( &dlg );
220 // dlg. showMaximized ( );
221
222 return a.exec();
223
224}
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 @@
1#ifndef _CONVERTER_H_
2#define _CONVERTER_H_
3
4
5#include "converter_base.h"
6
7
8class Converter: public converter_base {
9public:
10 Converter();
11
12 // Slots defined in the ui-description file
13 void start_conversion();
14 void selectedDatabase( int num );
15 void selectedDestFormat( int num );
16 void selectedSourceFormat( int num );
17
18private:
19 // Caution:
20 // The order and value of the following enums must be regarding
21 // the predefinition in the UI-File !!
22 enum DataBases{
23 ADDRESSBOOK = 0,
24 TODOLIST = 1,
25 DATEBOOK = 2,
26 };
27
28 enum DbFormats{
29 XML = 0,
30 SQL = 1,
31 };
32
33 int m_selectedDatabase;
34 int m_selectedSourceFormat;
35 int m_selectedDestFormat;
36
37};
38
39
40#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 @@
1 CONFIG = qt warn_on debug
2 # CONFIG = qt warn_on release quick-app
3HEADERS = converter.h
4 SOURCES = converter.cpp
5INTERFACES = converter_base.ui
6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lopiecore2 -lopiepim2 -lopiedb2
9 TARGET = $(OPIEDIR)/bin/opimconverter
10
11include ( $(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 @@
1<!DOCTYPE UI><UI>
2<class>converter_base</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>converter_base</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>269</width>
15 <height>324</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>PIM-Database Converter</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <grid>
26 <property stdset="1">
27 <name>margin</name>
28 <number>4</number>
29 </property>
30 <property stdset="1">
31 <name>spacing</name>
32 <number>6</number>
33 </property>
34 <widget row="0" column="0" >
35 <class>QGroupBox</class>
36 <property stdset="1">
37 <name>name</name>
38 <cstring>GroupBox6</cstring>
39 </property>
40 <property stdset="1">
41 <name>title</name>
42 <string>Converter</string>
43 </property>
44 <property>
45 <name>layoutMargin</name>
46 </property>
47 <property>
48 <name>layoutSpacing</name>
49 </property>
50 <vbox>
51 <property stdset="1">
52 <name>margin</name>
53 <number>4</number>
54 </property>
55 <property stdset="1">
56 <name>spacing</name>
57 <number>2</number>
58 </property>
59 <widget>
60 <class>QGroupBox</class>
61 <property stdset="1">
62 <name>name</name>
63 <cstring>GroupBox1</cstring>
64 </property>
65 <property stdset="1">
66 <name>title</name>
67 <string>Select Database:</string>
68 </property>
69 <grid>
70 <property stdset="1">
71 <name>margin</name>
72 <number>11</number>
73 </property>
74 <property stdset="1">
75 <name>spacing</name>
76 <number>6</number>
77 </property>
78 <widget row="0" column="1" >
79 <class>QComboBox</class>
80 <item>
81 <property>
82 <name>text</name>
83 <string>Addressbook</string>
84 </property>
85 </item>
86 <item>
87 <property>
88 <name>text</name>
89 <string>TodoList</string>
90 </property>
91 </item>
92 <item>
93 <property>
94 <name>text</name>
95 <string>Datebook</string>
96 </property>
97 </item>
98 <property stdset="1">
99 <name>name</name>
100 <cstring>m_dataBaseSelector</cstring>
101 </property>
102 </widget>
103 </grid>
104 </widget>
105 <widget>
106 <class>QGroupBox</class>
107 <property stdset="1">
108 <name>name</name>
109 <cstring>GroupBox2</cstring>
110 </property>
111 <property stdset="1">
112 <name>title</name>
113 <string>Source/Destination:</string>
114 </property>
115 <grid>
116 <property stdset="1">
117 <name>margin</name>
118 <number>11</number>
119 </property>
120 <property stdset="1">
121 <name>spacing</name>
122 <number>6</number>
123 </property>
124 <widget row="1" column="0" >
125 <class>QLabel</class>
126 <property stdset="1">
127 <name>name</name>
128 <cstring>TextLabel3_2</cstring>
129 </property>
130 <property stdset="1">
131 <name>text</name>
132 <string>to</string>
133 </property>
134 </widget>
135 <widget row="1" column="1" >
136 <class>QComboBox</class>
137 <item>
138 <property>
139 <name>text</name>
140 <string>XML</string>
141 </property>
142 </item>
143 <item>
144 <property>
145 <name>text</name>
146 <string>SQL (SQLite)</string>
147 </property>
148 </item>
149 <property stdset="1">
150 <name>name</name>
151 <cstring>m_destFormatSelector</cstring>
152 </property>
153 </widget>
154 <widget row="0" column="0" >
155 <class>QLabel</class>
156 <property stdset="1">
157 <name>name</name>
158 <cstring>TextLabel2_2</cstring>
159 </property>
160 <property stdset="1">
161 <name>text</name>
162 <string>Convert from</string>
163 </property>
164 </widget>
165 <widget row="0" column="1" >
166 <class>QComboBox</class>
167 <item>
168 <property>
169 <name>text</name>
170 <string>XML</string>
171 </property>
172 </item>
173 <item>
174 <property>
175 <name>text</name>
176 <string>SQL (SQLite)</string>
177 </property>
178 </item>
179 <property stdset="1">
180 <name>name</name>
181 <cstring>m_sourceFormatSelector</cstring>
182 </property>
183 </widget>
184 </grid>
185 </widget>
186 <widget>
187 <class>QGroupBox</class>
188 <property stdset="1">
189 <name>name</name>
190 <cstring>GroupBox5</cstring>
191 </property>
192 <property stdset="1">
193 <name>title</name>
194 <string>Config:</string>
195 </property>
196 <grid>
197 <property stdset="1">
198 <name>margin</name>
199 <number>11</number>
200 </property>
201 <property stdset="1">
202 <name>spacing</name>
203 <number>6</number>
204 </property>
205 <widget row="0" column="0" >
206 <class>QCheckBox</class>
207 <property stdset="1">
208 <name>name</name>
209 <cstring>m_eraseDB</cstring>
210 </property>
211 <property stdset="1">
212 <name>text</name>
213 <string>Erase before copy</string>
214 </property>
215 </widget>
216 </grid>
217 </widget>
218 <widget>
219 <class>QGroupBox</class>
220 <property stdset="1">
221 <name>name</name>
222 <cstring>GroupBox4</cstring>
223 </property>
224 <property stdset="1">
225 <name>title</name>
226 <string>Progress:</string>
227 </property>
228 <vbox>
229 <property stdset="1">
230 <name>margin</name>
231 <number>11</number>
232 </property>
233 <property stdset="1">
234 <name>spacing</name>
235 <number>6</number>
236 </property>
237 <widget>
238 <class>QProgressBar</class>
239 <property stdset="1">
240 <name>name</name>
241 <cstring>m_progressBar</cstring>
242 </property>
243 </widget>
244 <widget>
245 <class>QPushButton</class>
246 <property stdset="1">
247 <name>name</name>
248 <cstring>PushButton1</cstring>
249 </property>
250 <property stdset="1">
251 <name>text</name>
252 <string>Go!</string>
253 </property>
254 </widget>
255 </vbox>
256 </widget>
257 </vbox>
258 </widget>
259 </grid>
260</widget>
261<connections>
262 <connection>
263 <sender>PushButton1</sender>
264 <signal>clicked()</signal>
265 <receiver>converter_base</receiver>
266 <slot>start_conversion()</slot>
267 </connection>
268 <connection>
269 <sender>m_sourceFormatSelector</sender>
270 <signal>activated(int)</signal>
271 <receiver>converter_base</receiver>
272 <slot>selectedSourceFormat(int)</slot>
273 </connection>
274 <connection>
275 <sender>m_dataBaseSelector</sender>
276 <signal>activated(int)</signal>
277 <receiver>converter_base</receiver>
278 <slot>selectedDatabase(int)</slot>
279 </connection>
280 <connection>
281 <sender>m_destFormatSelector</sender>
282 <signal>activated(int)</signal>
283 <receiver>converter_base</receiver>
284 <slot>selectedDestFormat(int)</slot>
285 </connection>
286 <slot access="public">selectedDatabase(int)</slot>
287 <slot access="public">selectedDestFormat(int)</slot>
288 <slot access="public">selectedSourceFormat(int)</slot>
289 <slot access="public">start_conversion()</slot>
290</connections>
291</UI>