author | ulf69 <ulf69> | 2004-06-30 22:12:32 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-06-30 22:12:32 (UTC) |
commit | 34c8059a5400d4a13456a5b4cb90328369999f20 (patch) (unidiff) | |
tree | 694e9a6b7814522ddec59b52cbaad3fe5690afea /kaddressbook/xxport/opie/opie_xxport.cpp | |
parent | bd79f5a89b0d1071ef9ad749fe3a8096bbc25b0b (diff) | |
download | kdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.zip kdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.tar.gz kdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'kaddressbook/xxport/opie/opie_xxport.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/xxport/opie/opie_xxport.cpp | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp new file mode 100644 index 0000000..616eec1 --- a/dev/null +++ b/kaddressbook/xxport/opie/opie_xxport.cpp | |||
@@ -0,0 +1,196 @@ | |||
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 "stdaddressbook.h" | ||
38 | |||
39 | /*US | ||
40 | #include <qfile.h> | ||
41 | #include <qtextstream.h> | ||
42 | |||
43 | #include <kabc/vcardconverter.h> | ||
44 | #ifndef KAB_EMBEDDED | ||
45 | #include <kio/netaccess.h> | ||
46 | #endif //KAB_EMBEDDED | ||
47 | |||
48 | #include <klocale.h> | ||
49 | #include <kmessagebox.h> | ||
50 | #include <ktempfile.h> | ||
51 | #include <kurl.h> | ||
52 | */ | ||
53 | |||
54 | #include "xxportmanager.h" | ||
55 | #include "opieconverter.h" | ||
56 | |||
57 | #include "opie_xxport.h" | ||
58 | |||
59 | |||
60 | class OpieXXPortFactory : public XXPortFactory | ||
61 | { | ||
62 | public: | ||
63 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | ||
64 | { | ||
65 | return new OpieXXPort( ab, parent, name ); | ||
66 | } | ||
67 | }; | ||
68 | |||
69 | |||
70 | extern "C" | ||
71 | { | ||
72 | void *init_kaddrbk_opie_xxport() | ||
73 | { | ||
74 | return ( new OpieXXPortFactory() ); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | |||
79 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | ||
80 | : XXPortObject( ab, parent, name ) | ||
81 | { | ||
82 | createImportAction( i18n( "Import Opie..." ) ); | ||
83 | createExportAction( i18n( "Export Opie..." ) ); | ||
84 | } | ||
85 | |||
86 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | ||
87 | { | ||
88 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | ||
89 | |||
90 | #ifndef KAB_EMBEDDED | ||
91 | QString fileName = KFileDialog::getSaveFileName( name ); | ||
92 | #else //KAB_EMBEDDED | ||
93 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); | ||
94 | #endif //KAB_EMBEDDED | ||
95 | |||
96 | if ( fileName.isEmpty() ) | ||
97 | return true; | ||
98 | |||
99 | OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); | ||
100 | |||
101 | if ( !access ) { | ||
102 | qDebug("Unable to access file() %s", fileName.latin1()); | ||
103 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | ||
104 | return false; | ||
105 | } | ||
106 | |||
107 | //Now check if the file has already entries, and ask the user if he wants to delete them first. | ||
108 | OContactAccess::List contactList = access->allRecords(); | ||
109 | if (contactList.count() > 0) | ||
110 | { | ||
111 | QString text( i18n( "<qt>Do you want to remove all existing entries from <b>%1</b> before exporting.?</qt>" ) ); | ||
112 | if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { | ||
113 | // Clean the database.. | ||
114 | access->clear(); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | KABC::OpieConverter mConverter; | ||
119 | bool res; | ||
120 | |||
121 | KABC::Addressee::List::ConstIterator it; | ||
122 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
123 | OContact c; | ||
124 | KABC::Addressee addressee = (*it); | ||
125 | |||
126 | res = mConverter.addresseeToOpie( *it, c ); | ||
127 | if (res == true) | ||
128 | { | ||
129 | res = access->add(c); | ||
130 | if (res == false) | ||
131 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | access->save(); | ||
140 | |||
141 | delete access; | ||
142 | |||
143 | return true; | ||
144 | } | ||
145 | |||
146 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const | ||
147 | { | ||
148 | KABC::AddresseeList adrlst; | ||
149 | |||
150 | QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | ||
151 | |||
152 | #ifndef KAB_EMBEDDED | ||
153 | QString fileName = KFileDialog::getOpenFileName( name ); | ||
154 | #else //KAB_EMBEDDED | ||
155 | QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); | ||
156 | #endif //KAB_EMBEDDED | ||
157 | |||
158 | if ( fileName.isEmpty() ) | ||
159 | return KABC::AddresseeList(); | ||
160 | |||
161 | OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); | ||
162 | |||
163 | if ( !access ) { | ||
164 | qDebug("Unable to access file() %s", fileName.latin1()); | ||
165 | addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); | ||
166 | return KABC::AddresseeList(); | ||
167 | } | ||
168 | |||
169 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | ||
170 | |||
171 | KABC::OpieConverter mConverter; | ||
172 | bool res = false; | ||
173 | |||
174 | |||
175 | OContactAccess::List::Iterator it; | ||
176 | OContactAccess::List allList = access->allRecords(); | ||
177 | for ( it = allList.begin(); it != allList.end(); ++it ) | ||
178 | { | ||
179 | OContact c = (*it); | ||
180 | |||
181 | KABC::Addressee addressee; | ||
182 | |||
183 | res = mConverter.opieToAddressee( c, addressee ); | ||
184 | |||
185 | if ( !addressee.isEmpty() && res ) { | ||
186 | adrlst.append( addressee ); | ||
187 | } | ||
188 | |||
189 | // qDebug("found %s", c.fullName().latin1()); | ||
190 | } | ||
191 | |||
192 | delete access; | ||
193 | |||
194 | return adrlst; | ||
195 | |||
196 | } | ||