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