Diffstat (limited to 'kaddressbook/xxport/opie/opie_xxport.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/xxport/opie/opie_xxport.cpp | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp deleted file mode 100644 index c9b0163..0000000 --- a/kaddressbook/xxport/opie/opie_xxport.cpp +++ b/dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of KAddressbook. | ||
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | Enhanced Version of the file for platform independent KDE tools. | ||
26 | Copyright (c) 2004 Ulf Schenk | ||
27 | |||
28 | $Id$ | ||
29 | */ | ||
30 | |||
31 | #include <qdir.h> | ||
32 | |||
33 | #include <kfiledialog.h> | ||
34 | #include <kmessagebox.h> | ||
35 | |||
36 | #include <opie/ocontactaccess.h> | ||
37 | #include <opie/ocontactaccessbackend_xml.h> | ||
38 | |||
39 | #include "stdaddressbook.h" | ||
40 | |||
41 | /*US | ||
42 | #include <qfile.h> | ||
43 | #include <qtextstream.h> | ||
44 | |||
45 | #include <kabc/vcardconverter.h> | ||
46 | #ifndef KAB_EMBEDDED | ||
47 | #include <kio/netaccess.h> | ||
48 | #endif //KAB_EMBEDDED | ||
49 | |||
50 | #include <klocale.h> | ||
51 | #include <kmessagebox.h> | ||
52 | #include <ktempfile.h> | ||
53 | #include <kurl.h> | ||
54 | */ | ||
55 | |||
56 | #include "xxportmanager.h" | ||
57 | #include "opieconverter.h" | ||
58 | |||
59 | #include "opie_xxport.h" | ||
60 | |||
61 | |||
62 | class OpieXXPortFactory : public XXPortFactory | ||
63 | { | ||
64 | public: | ||
65 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | ||
66 | { | ||
67 | return new OpieXXPort( ab, parent, name ); | ||
68 | } | ||
69 | }; | ||
70 | |||
71 | |||
72 | extern "C" | ||
73 | { | ||
74 | void *init_microkaddrbk_opie_xxport() | ||
75 | { | ||
76 | return ( new OpieXXPortFactory() ); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | |||
81 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | ||
82 | : XXPortObject( ab, parent, name ) | ||
83 | { | ||
84 | createImportAction( i18n( "Import Opie..." ) ); | ||
85 | createExportAction( i18n( "Export Opie..." ) ); | ||
86 | } | ||
87 | |||
88 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | ||
89 | { | ||
90 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | ||
91 | |||
92 | #ifndef KAB_EMBEDDED | ||
93 | QString fileName = KFileDialog::getSaveFileName( name ); | ||
94 | #else //KAB_EMBEDDED | ||
95 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); | ||
96 | #endif //KAB_EMBEDDED | ||
97 | |||
98 | if ( fileName.isEmpty() ) | ||
99 | return false; | ||
100 | |||
101 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); | ||
102 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); | ||
103 | |||
104 | if ( !access ) { | ||
105 | qDebug("Unable to access file() %s", fileName.latin1()); | ||
106 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | ||
107 | return false; | ||
108 | } | ||
109 | |||
110 | KABC::OpieConverter mConverter; | ||
111 | |||
112 | bool res = mConverter.init(); | ||
113 | if (!res) | ||
114 | { | ||
115 | QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) ); | ||
116 | qDebug(text); | ||
117 | KMessageBox::error( parentWidget(), text ); | ||
118 | delete access; | ||
119 | return false; | ||
120 | } | ||
121 | |||
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(); | ||
124 | if (contactList.count() > 0) | ||
125 | { | ||
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 ) { | ||
128 | // Clean the database.. | ||
129 | access->clear(); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | |||
134 | KABC::Addressee::List::ConstIterator it; | ||
135 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
136 | OContact c; | ||
137 | KABC::Addressee addressee = (*it); | ||
138 | |||
139 | res = mConverter.addresseeToOpie( *it, c ); | ||
140 | if (res == true) | ||
141 | { | ||
142 | res = access->add(c); | ||
143 | if (res == false) | ||
144 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | access->save(); | ||
153 | |||
154 | delete access; | ||
155 | //US the deletion of the access object deletes the backend object as well. | ||
156 | |||
157 | return true; | ||
158 | } | ||
159 | |||
160 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const | ||
161 | { | ||
162 | KABC::AddresseeList adrlst; | ||
163 | |||
164 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | ||
165 | |||
166 | #ifndef KAB_EMBEDDED | ||
167 | QString fileName = KFileDialog::getOpenFileName( name ); | ||
168 | #else //KAB_EMBEDDED | ||
169 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); | ||
170 | #endif //KAB_EMBEDDED | ||
171 | |||
172 | if ( fileName.isEmpty() ) | ||
173 | return KABC::AddresseeList(); | ||
174 | |||
175 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); | ||
176 | OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); | ||
177 | |||
178 | if ( !access ) { | ||
179 | qDebug("Unable to access file() %s", fileName.latin1()); | ||
180 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | ||
181 | return KABC::AddresseeList(); | ||
182 | } | ||
183 | |||
184 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | ||
185 | |||
186 | KABC::OpieConverter mConverter; | ||
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 | |||
198 | |||
199 | OContactAccess::List::Iterator it; | ||
200 | OContactAccess::List allList = access->allRecords(); | ||
201 | for ( it = allList.begin(); it != allList.end(); ++it ) | ||
202 | { | ||
203 | OContact c = (*it); | ||
204 | |||
205 | KABC::Addressee addressee; | ||
206 | |||
207 | res = mConverter.opieToAddressee( c, addressee ); | ||
208 | |||
209 | if ( !addressee.isEmpty() && res ) { | ||
210 | adrlst.append( addressee ); | ||
211 | } | ||
212 | |||
213 | // qDebug("found %s", c.fullName().latin1()); | ||
214 | } | ||
215 | |||
216 | delete access; | ||
217 | //US the deletion of the access object deletes the backend object as well. | ||
218 | |||
219 | return adrlst; | ||
220 | |||
221 | } | ||