summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp11
-rw-r--r--kaddressbook/xxport/qtopia/qtopia_xxport.cpp12
2 files changed, 21 insertions, 2 deletions
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
index 12c83af..db30d34 100644
--- a/kaddressbook/xxport/opie/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -59,154 +59,163 @@ $Id$
59#include "opie_xxport.h" 59#include "opie_xxport.h"
60 60
61 61
62class OpieXXPortFactory : public XXPortFactory 62class OpieXXPortFactory : public XXPortFactory
63{ 63{
64 public: 64 public:
65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 65 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
66 { 66 {
67 return new OpieXXPort( ab, parent, name ); 67 return new OpieXXPort( ab, parent, name );
68 } 68 }
69}; 69};
70 70
71 71
72extern "C" 72extern "C"
73{ 73{
74 void *init_microkaddrbk_opie_xxport() 74 void *init_microkaddrbk_opie_xxport()
75 { 75 {
76 return ( new OpieXXPortFactory() ); 76 return ( new OpieXXPortFactory() );
77 } 77 }
78} 78}
79 79
80 80
81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 81OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortObject( ab, parent, name ) 82 : XXPortObject( ab, parent, name )
83{ 83{
84 createImportAction( i18n( "Import Opie..." ) ); 84 createImportAction( i18n( "Import Opie..." ) );
85 createExportAction( i18n( "Export Opie..." ) ); 85 createExportAction( i18n( "Export Opie..." ) );
86} 86}
87 87
88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 88bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
89{ 89{
90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92#ifndef KAB_EMBEDDED 92#ifndef KAB_EMBEDDED
93 QString fileName = KFileDialog::getSaveFileName( name ); 93 QString fileName = KFileDialog::getSaveFileName( name );
94#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 95 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
96#endif //KAB_EMBEDDED 96#endif //KAB_EMBEDDED
97 97
98 if ( fileName.isEmpty() ) 98 if ( fileName.isEmpty() )
99 return true; 99 return true;
100 100
101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 101 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 102 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
103 103
104 if ( !access ) { 104 if ( !access ) {
105 qDebug("Unable to access file() %s", fileName.latin1()); 105 qDebug("Unable to access file() %s", fileName.latin1());
106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 106 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
107 return false; 107 return false;
108 } 108 }
109 109
110 KABC::OpieConverter mConverter; 110 KABC::OpieConverter mConverter;
111 111
112 bool res = mConverter.init(); 112 bool res = mConverter.init();
113 if (!res) 113 if (!res)
114 { 114 {
115 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); 115 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
116 qDebug(text); 116 qDebug(text);
117 KMessageBox::error( parentWidget(), text ); 117 KMessageBox::error( parentWidget(), text );
118 delete access; 118 delete access;
119 return false; 119 return false;
120 } 120 }
121 121
122 //Now check if the file has already entries, and ask the user if he wants to delete them first. 122 //Now check if the file has already entries, and ask the user if he wants to delete them first.
123 OContactAccess::List contactList = access->allRecords(); 123 OContactAccess::List contactList = access->allRecords();
124 if (contactList.count() > 0) 124 if (contactList.count() > 0)
125 { 125 {
126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
128 // Clean the database.. 128 // Clean the database..
129 access->clear(); 129 access->clear();
130 } 130 }
131 } 131 }
132 132
133 133
134 KABC::Addressee::List::ConstIterator it; 134 KABC::Addressee::List::ConstIterator it;
135 for ( it = list.begin(); it != list.end(); ++it ) { 135 for ( it = list.begin(); it != list.end(); ++it ) {
136 OContact c; 136 OContact c;
137 KABC::Addressee addressee = (*it); 137 KABC::Addressee addressee = (*it);
138 138
139 res = mConverter.addresseeToOpie( *it, c ); 139 res = mConverter.addresseeToOpie( *it, c );
140 if (res == true) 140 if (res == true)
141 { 141 {
142 res = access->add(c); 142 res = access->add(c);
143 if (res == false) 143 if (res == false)
144 qDebug("Unable to append Contact %s", c.fullName().latin1()); 144 qDebug("Unable to append Contact %s", c.fullName().latin1());
145 } 145 }
146 else 146 else
147 { 147 {
148 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 148 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
149 } 149 }
150 } 150 }
151 151
152 access->save(); 152 access->save();
153 153
154 delete access; 154 delete access;
155//US the deletion of the access object deletes the backend object as well. 155//US the deletion of the access object deletes the backend object as well.
156 156
157 return true; 157 return true;
158} 158}
159 159
160KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const 160KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
161{ 161{
162 KABC::AddresseeList adrlst; 162 KABC::AddresseeList adrlst;
163 163
164 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 164 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
165 165
166#ifndef KAB_EMBEDDED 166#ifndef KAB_EMBEDDED
167 QString fileName = KFileDialog::getOpenFileName( name ); 167 QString fileName = KFileDialog::getOpenFileName( name );
168#else //KAB_EMBEDDED 168#else //KAB_EMBEDDED
169 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); 169 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() );
170#endif //KAB_EMBEDDED 170#endif //KAB_EMBEDDED
171 171
172 if ( fileName.isEmpty() ) 172 if ( fileName.isEmpty() )
173 return KABC::AddresseeList(); 173 return KABC::AddresseeList();
174 174
175 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); 175 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
176 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); 176 OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
177 177
178 if ( !access ) { 178 if ( !access ) {
179 qDebug("Unable to access file() %s", fileName.latin1()); 179 qDebug("Unable to access file() %s", fileName.latin1());
180 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 180 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
181 return KABC::AddresseeList(); 181 return KABC::AddresseeList();
182 } 182 }
183 183
184 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available 184 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
185 185
186 KABC::OpieConverter mConverter; 186 KABC::OpieConverter mConverter;
187 bool res = false;
188 187
188 bool res = mConverter.init();
189 if (!res)
190 {
191 QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
192 qDebug(text);
193 KMessageBox::error( parentWidget(), text );
194 delete access;
195 return KABC::AddresseeList();
196 }
197
189 198
190 OContactAccess::List::Iterator it; 199 OContactAccess::List::Iterator it;
191 OContactAccess::List allList = access->allRecords(); 200 OContactAccess::List allList = access->allRecords();
192 for ( it = allList.begin(); it != allList.end(); ++it ) 201 for ( it = allList.begin(); it != allList.end(); ++it )
193 { 202 {
194 OContact c = (*it); 203 OContact c = (*it);
195 204
196 KABC::Addressee addressee; 205 KABC::Addressee addressee;
197 206
198 res = mConverter.opieToAddressee( c, addressee ); 207 res = mConverter.opieToAddressee( c, addressee );
199 208
200 if ( !addressee.isEmpty() && res ) { 209 if ( !addressee.isEmpty() && res ) {
201 adrlst.append( addressee ); 210 adrlst.append( addressee );
202 } 211 }
203 212
204// qDebug("found %s", c.fullName().latin1()); 213// qDebug("found %s", c.fullName().latin1());
205 } 214 }
206 215
207 delete access; 216 delete access;
208//US the deletion of the access object deletes the backend object as well. 217//US the deletion of the access object deletes the backend object as well.
209 218
210 return adrlst; 219 return adrlst;
211 220
212} 221}
diff --git a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
index 3d830df..bf39fdb 100644
--- a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
@@ -38,154 +38,164 @@ $Id$
38#include "stdaddressbook.h" 38#include "stdaddressbook.h"
39 39
40/*US 40/*US
41#include <qfile.h> 41#include <qfile.h>
42#include <qtextstream.h> 42#include <qtextstream.h>
43 43
44#include <kabc/vcardconverter.h> 44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h> 46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED 47#endif //KAB_EMBEDDED
48 48
49#include <klocale.h> 49#include <klocale.h>
50#include <kmessagebox.h> 50#include <kmessagebox.h>
51#include <ktempfile.h> 51#include <ktempfile.h>
52#include <kurl.h> 52#include <kurl.h>
53*/ 53*/
54 54
55#include "xxportmanager.h" 55#include "xxportmanager.h"
56#include "qtopiaconverter.h" 56#include "qtopiaconverter.h"
57 57
58#include "qtopia_xxport.h" 58#include "qtopia_xxport.h"
59 59
60 60
61class QtopiaXXPortFactory : public XXPortFactory 61class QtopiaXXPortFactory : public XXPortFactory
62{ 62{
63 public: 63 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 { 65 {
66 return new QtopiaXXPort( ab, parent, name ); 66 return new QtopiaXXPort( ab, parent, name );
67 } 67 }
68}; 68};
69 69
70 70
71extern "C" 71extern "C"
72{ 72{
73 void *init_microkaddrbk_qtopia_xxport() 73 void *init_microkaddrbk_qtopia_xxport()
74 { 74 {
75 return ( new QtopiaXXPortFactory() ); 75 return ( new QtopiaXXPortFactory() );
76 } 76 }
77} 77}
78 78
79 79
80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
81 : XXPortObject( ab, parent, name ) 81 : XXPortObject( ab, parent, name )
82{ 82{
83 createImportAction( i18n( "Import Qtopia..." ) ); 83 createImportAction( i18n( "Import Qtopia..." ) );
84 createExportAction( i18n( "Export Qtopia..." ) ); 84 createExportAction( i18n( "Export Qtopia..." ) );
85} 85}
86 86
87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
88{ 88{
89 // we can not choose the filename. Therefore use the default to display 89 // we can not choose the filename. Therefore use the default to display
90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92 AddressBookAccess* access = new AddressBookAccess(); 92 AddressBookAccess* access = new AddressBookAccess();
93 93
94 if ( !access ) { 94 if ( !access ) {
95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
96 qDebug(text.latin1()); 96 qDebug(text.latin1());
97 KMessageBox::error( parentWidget(), text ); 97 KMessageBox::error( parentWidget(), text );
98 addressBook()->error( text ); 98 addressBook()->error( text );
99 return false; 99 return false;
100 } 100 }
101 101
102 KABC::QtopiaConverter mConverter; 102 KABC::QtopiaConverter mConverter;
103 103
104 bool res = mConverter.init(); 104 bool res = mConverter.init();
105 if (!res) 105 if (!res)
106 { 106 {
107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); 107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
108 qDebug(text); 108 qDebug(text);
109 KMessageBox::error( parentWidget(), text ); 109 KMessageBox::error( parentWidget(), text );
110 delete access; 110 delete access;
111 return false; 111 return false;
112 } 112 }
113 113
114 //Now check if the file has already entries, and ask the user if he wants to delete them first. 114 //Now check if the file has already entries, and ask the user if he wants to delete them first.
115 { //create a new scope 115 { //create a new scope
116 AddressBookIterator it(*access); 116 AddressBookIterator it(*access);
117 const PimContact* firstcontact = it.toFirst(); 117 const PimContact* firstcontact = it.toFirst();
118 if (firstcontact) 118 if (firstcontact)
119 { 119 {
120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
122 // Clean the database.. 122 // Clean the database..
123 123
124 AddressBookIterator it2(*access); 124 AddressBookIterator it2(*access);
125 for (it2.toFirst(); it2.current(); ++it2) { 125 for (it2.toFirst(); it2.current(); ++it2) {
126 access->removeContact(*it2.current()); 126 access->removeContact(*it2.current());
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 KABC::Addressee::List::ConstIterator it; 132 KABC::Addressee::List::ConstIterator it;
133 for ( it = list.begin(); it != list.end(); ++it ) { 133 for ( it = list.begin(); it != list.end(); ++it ) {
134 PimContact c; 134 PimContact c;
135 KABC::Addressee addressee = (*it); 135 KABC::Addressee addressee = (*it);
136 136
137 res = mConverter.addresseeToQtopia( *it, c ); 137 res = mConverter.addresseeToQtopia( *it, c );
138 if (res == true) 138 if (res == true)
139 { 139 {
140 access->addContact(c); 140 access->addContact(c);
141 } 141 }
142 } 142 }
143 143
144 delete access; 144 delete access;
145 145
146 return true; 146 return true;
147} 147}
148 148
149KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const 149KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const
150{ 150{
151 KABC::AddresseeList adrlst; 151 KABC::AddresseeList adrlst;
152 152
153 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 153 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
154 154
155 AddressBookAccess* access = new AddressBookAccess(); 155 AddressBookAccess* access = new AddressBookAccess();
156 156
157 if ( !access ) { 157 if ( !access ) {
158 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 158 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
159 qDebug(text.latin1()); 159 qDebug(text.latin1());
160 addressBook()->error( text ); 160 addressBook()->error( text );
161 KMessageBox::error( parentWidget(), text ); 161 KMessageBox::error( parentWidget(), text );
162 return KABC::AddresseeList(); 162 return KABC::AddresseeList();
163 } 163 }
164 164
165 KABC::QtopiaConverter mConverter; 165 KABC::QtopiaConverter mConverter;
166 bool res = false;
167 166
167 bool res = mConverter.init();
168 if (!res)
169 {
170 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
171 qDebug(text);
172 KMessageBox::error( parentWidget(), text );
173 delete access;
174 return KABC::AddresseeList();
175 }
176
177
168 178
169 { //create a new scope 179 { //create a new scope
170 AddressBookIterator it(*access); 180 AddressBookIterator it(*access);
171 181
172 for (it.toFirst(); it.current(); ++it) { 182 for (it.toFirst(); it.current(); ++it) {
173 const PimContact*contact = it.current(); 183 const PimContact*contact = it.current();
174 184
175 KABC::Addressee addressee; 185 KABC::Addressee addressee;
176 186
177 res = mConverter.qtopiaToAddressee( (*contact), addressee ); 187 res = mConverter.qtopiaToAddressee( (*contact), addressee );
178 188
179 if ( !addressee.isEmpty() && res ) 189 if ( !addressee.isEmpty() && res )
180 { 190 {
181 adrlst.append( addressee ); 191 adrlst.append( addressee );
182 } 192 }
183 } 193 }
184 } 194 }
185 195
186 delete access; 196 delete access;
187//US the deletion of the access object deletes the backend object as well. 197//US the deletion of the access object deletes the backend object as well.
188 198
189 return adrlst; 199 return adrlst;
190 200
191} 201}