summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-02 18:22:39 (UTC)
committer ulf69 <ulf69>2004-08-02 18:22:39 (UTC)
commit9f89ce524f3dc9bb820e32f235a03d0a167b9f89 (patch) (unidiff)
tree140294ee8ce336999d45c5823a3e09a7ffa22fdd
parente084a79b8aa0174e7587893f9b87d88670ed9f2c (diff)
downloadkdepimpi-9f89ce524f3dc9bb820e32f235a03d0a167b9f89.zip
kdepimpi-9f89ce524f3dc9bb820e32f235a03d0a167b9f89.tar.gz
kdepimpi-9f89ce524f3dc9bb820e32f235a03d0a167b9f89.tar.bz2
overhaul of the export/import interface to use dynamically loaded
resources as base for export and import
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp2
-rw-r--r--kaddressbook/xxport/kde2_xxport.cpp2
-rw-r--r--kaddressbook/xxport/opie_xxport.cpp195
-rw-r--r--kaddressbook/xxport/opie_xxport.h68
-rw-r--r--kaddressbook/xxport/qtopia_xxport.cpp287
-rw-r--r--kaddressbook/xxport/qtopia_xxport.h64
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.cpp284
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.h60
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp3
9 files changed, 962 insertions, 3 deletions
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
index d4d5475..81148d9 100644
--- a/kaddressbook/xxport/csv_xxport.cpp
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -1,192 +1,192 @@
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 <qfile.h> 31#include <qfile.h>
32#include <qregexp.h> 32#include <qregexp.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34 34
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#ifndef KAB_EMBEDDED 36#ifndef KAB_EMBEDDED
37#include <kio/netaccess.h> 37#include <kio/netaccess.h>
38#endif //KAB_EMBEDDED 38#endif //KAB_EMBEDDED
39 39
40#include <klocale.h> 40#include <klocale.h>
41#include <kmessagebox.h> 41#include <kmessagebox.h>
42#include <ktempfile.h> 42#include <ktempfile.h>
43#include <kurl.h> 43#include <kurl.h>
44 44
45#include "csvimportdialog.h" 45#include "csvimportdialog.h"
46 46
47#include "csv_xxport.h" 47#include "csv_xxport.h"
48 48
49 49
50#ifndef KAB_EMBEDDED 50#ifndef KAB_EMBEDDED
51 51
52class CSVXXPortFactory : public XXPortFactory 52class CSVXXPortFactory : public XXPortFactory
53{ 53{
54 public: 54 public:
55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
56 { 56 {
57 return new CSVXXPort( ab, parent, name ); 57 return new CSVXXPort( ab, parent, name );
58 } 58 }
59}; 59};
60 60
61#endif //KAB_EMBEDDED 61#endif //KAB_EMBEDDED
62 62
63 63
64extern "C" 64extern "C"
65{ 65{
66#ifndef KAB_EMBEDDED 66#ifndef KAB_EMBEDDED
67 void *init_libkaddrbk_csv_xxport() 67 void *init_libkaddrbk_csv_xxport()
68#else //KAB_EMBEDDED 68#else //KAB_EMBEDDED
69 void *init_kaddrbk_csv_xxport() 69 void *init_microkaddrbk_csv_xxport()
70#endif //KAB_EMBEDDED 70#endif //KAB_EMBEDDED
71 { 71 {
72 return ( new CSVXXPortFactory() ); 72 return ( new CSVXXPortFactory() );
73 } 73 }
74} 74}
75 75
76 76
77CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 77CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
78 : XXPortObject( ab, parent, name ) 78 : XXPortObject( ab, parent, name )
79{ 79{
80 createImportAction( i18n( "Import CSV List..." ) ); 80 createImportAction( i18n( "Import CSV List..." ) );
81 createExportAction( i18n( "Export CSV List..." ) ); 81 createExportAction( i18n( "Export CSV List..." ) );
82} 82}
83 83
84bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& ) 84bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
85{ 85{
86#ifndef KAB_EMBEDDED 86#ifndef KAB_EMBEDDED
87 KURL url = KFileDialog::getSaveURL( "addressbook.csv" ); 87 KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
88 if ( url.isEmpty() ) 88 if ( url.isEmpty() )
89 return true; 89 return true;
90 90
91 if ( !url.isLocalFile() ) { 91 if ( !url.isLocalFile() ) {
92 KTempFile tmpFile; 92 KTempFile tmpFile;
93 if ( tmpFile.status() != 0 ) { 93 if ( tmpFile.status() != 0 ) {
94 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" ); 94 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
95 KMessageBox::error( parentWidget(), txt.arg( url.url() ) 95 KMessageBox::error( parentWidget(), txt.arg( url.url() )
96 .arg( strerror( tmpFile.status() ) ) ); 96 .arg( strerror( tmpFile.status() ) ) );
97 return false; 97 return false;
98 } 98 }
99 99
100 doExport( tmpFile.file(), list ); 100 doExport( tmpFile.file(), list );
101 tmpFile.close(); 101 tmpFile.close();
102 102
103 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() ); 103 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
104 } else { 104 } else {
105 QFile file( url.path() ); 105 QFile file( url.path() );
106 if ( !file.open( IO_WriteOnly ) ) { 106 if ( !file.open( IO_WriteOnly ) ) {
107 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 107 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
108 KMessageBox::error( parentWidget(), txt.arg( url.path() ) ); 108 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
109 return false; 109 return false;
110 } 110 }
111 111
112 doExport( &file, list ); 112 doExport( &file, list );
113 file.close(); 113 file.close();
114 114
115 return true; 115 return true;
116 } 116 }
117 117
118#else //KAB_EMBEDDED 118#else //KAB_EMBEDDED
119 119
120 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() ); 120 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
121 121
122 if ( fileName.isEmpty() ) 122 if ( fileName.isEmpty() )
123 return false; 123 return false;
124 124
125 QFile file( fileName ); 125 QFile file( fileName );
126 if ( !file.open( IO_WriteOnly ) ) { 126 if ( !file.open( IO_WriteOnly ) ) {
127 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ); 127 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
128 KMessageBox::error( parentWidget(), txt.arg( fileName ) ); 128 KMessageBox::error( parentWidget(), txt.arg( fileName ) );
129 return false; 129 return false;
130 } 130 }
131 131
132 doExport( &file, list ); 132 doExport( &file, list );
133 file.close(); 133 file.close();
134 134
135 return true; 135 return true;
136 136
137 137
138#endif //KAB_EMBEDDED 138#endif //KAB_EMBEDDED
139 139
140} 140}
141 141
142KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const 142KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
143{ 143{
144 CSVImportDialog dlg( addressBook(), parentWidget() ); 144 CSVImportDialog dlg( addressBook(), parentWidget() );
145 if ( dlg.exec() ) 145 if ( dlg.exec() )
146 return dlg.contacts(); 146 return dlg.contacts();
147 else 147 else
148 return KABC::AddresseeList(); 148 return KABC::AddresseeList();
149} 149}
150 150
151void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list ) 151void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
152{ 152{
153 QTextStream t( fp ); 153 QTextStream t( fp );
154 154
155 KABC::AddresseeList::ConstIterator iter; 155 KABC::AddresseeList::ConstIterator iter;
156 KABC::Field::List fields = addressBook()->fields(); 156 KABC::Field::List fields = addressBook()->fields();
157 KABC::Field::List::Iterator fieldIter; 157 KABC::Field::List::Iterator fieldIter;
158 bool first = true; 158 bool first = true;
159 159
160 // First output the column headings 160 // First output the column headings
161 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 161 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
162 if ( !first ) 162 if ( !first )
163 t << ","; 163 t << ",";
164 164
165 t << "\"" << (*fieldIter)->label() << "\""; 165 t << "\"" << (*fieldIter)->label() << "\"";
166 first = false; 166 first = false;
167 } 167 }
168 t << "\n"; 168 t << "\n";
169 169
170 // Then all the addressee objects 170 // Then all the addressee objects
171 KABC::Addressee addr; 171 KABC::Addressee addr;
172 for ( iter = list.begin(); iter != list.end(); ++iter ) { 172 for ( iter = list.begin(); iter != list.end(); ++iter ) {
173 addr = *iter; 173 addr = *iter;
174 first = true; 174 first = true;
175 175
176 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) { 176 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
177 if ( !first ) 177 if ( !first )
178 t << ","; 178 t << ",";
179 179
180 t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\""; 180 t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\"";
181 first = false; 181 first = false;
182 } 182 }
183 183
184 t << "\n"; 184 t << "\n";
185 } 185 }
186} 186}
187 187
188#ifndef KAB_EMBEDDED 188#ifndef KAB_EMBEDDED
189#include "csv_xxport.moc" 189#include "csv_xxport.moc"
190#endif //KAB_EMBEDDED 190#endif //KAB_EMBEDDED
191 191
192 192
diff --git a/kaddressbook/xxport/kde2_xxport.cpp b/kaddressbook/xxport/kde2_xxport.cpp
index 3fdb36d..03efc1b 100644
--- a/kaddressbook/xxport/kde2_xxport.cpp
+++ b/kaddressbook/xxport/kde2_xxport.cpp
@@ -1,121 +1,121 @@
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 <qfile.h> 31#include <qfile.h>
32 32
33#include <kdebug.h> 33#include <kdebug.h>
34#include <kfiledialog.h> 34#include <kfiledialog.h>
35#ifndef KAB_EMBEDDED 35#ifndef KAB_EMBEDDED
36#include <kio/netaccess.h> 36#include <kio/netaccess.h>
37#endif //KAB_EMBEDDED 37#endif //KAB_EMBEDDED
38#include <klocale.h> 38#include <klocale.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40#include <kprocess.h> 40#include <kprocess.h>
41#include <kstandarddirs.h> 41#include <kstandarddirs.h>
42#include <ktempfile.h> 42#include <ktempfile.h>
43#include <kurl.h> 43#include <kurl.h>
44 44
45#include "xxportmanager.h" 45#include "xxportmanager.h"
46 46
47#include "kde2_xxport.h" 47#include "kde2_xxport.h"
48 48
49#ifndef KAB_EMBEDDED 49#ifndef KAB_EMBEDDED
50 50
51class KDE2XXPortFactory : public XXPortFactory 51class KDE2XXPortFactory : public XXPortFactory
52{ 52{
53 public: 53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 { 55 {
56 return new KDE2XXPort( ab, parent, name ); 56 return new KDE2XXPort( ab, parent, name );
57 } 57 }
58}; 58};
59 59
60#endif //KAB_EMBEDDED 60#endif //KAB_EMBEDDED
61 61
62 62
63extern "C" 63extern "C"
64{ 64{
65#ifndef KAB_EMBEDDED 65#ifndef KAB_EMBEDDED
66 void *init_libkaddrbk_kde2_xxport() 66 void *init_libkaddrbk_kde2_xxport()
67#else //KAB_EMBEDDED 67#else //KAB_EMBEDDED
68 void *init_kaddrbk_kde2_xxport() 68 void *init_microkaddrbk_kde2_xxport()
69#endif //KAB_EMBEDDED 69#endif //KAB_EMBEDDED
70 { 70 {
71 return ( new KDE2XXPortFactory() ); 71 return ( new KDE2XXPortFactory() );
72 } 72 }
73} 73}
74 74
75 75
76KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 76KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
77 : XXPortObject( ab, parent, name ) 77 : XXPortObject( ab, parent, name )
78{ 78{
79 createImportAction( i18n( "Import KDE 2 Addressbook..." ) ); 79 createImportAction( i18n( "Import KDE 2 Addressbook..." ) );
80} 80}
81 81
82KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const 82KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const
83{ 83{
84 QString fileName = locateLocal( "data", "kabc/std.vcf" ); 84 QString fileName = locateLocal( "data", "kabc/std.vcf" );
85 if ( !QFile::exists( fileName ) ) { 85 if ( !QFile::exists( fileName ) ) {
86 KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) ); 86 KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) );
87 return KABC::AddresseeList(); 87 return KABC::AddresseeList();
88 } 88 }
89 89
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 int result = KMessageBox::questionYesNoCancel( parentWidget(), 91 int result = KMessageBox::questionYesNoCancel( parentWidget(),
92 i18n( "Override previously imported entries?" ), 92 i18n( "Override previously imported entries?" ),
93 i18n( "Import KDE 2 Addressbook" ) ); 93 i18n( "Import KDE 2 Addressbook" ) );
94#else //KAB_EMBEDDED 94#else //KAB_EMBEDDED
95 int result = KMessageBox::warningYesNoCancel( parentWidget(), 95 int result = KMessageBox::warningYesNoCancel( parentWidget(),
96 i18n( "Override previously imported entries?" ), 96 i18n( "Override previously imported entries?" ),
97 i18n( "Import KDE 2 Addressbook" ) ); 97 i18n( "Import KDE 2 Addressbook" ) );
98#endif //KAB_EMBEDDED 98#endif //KAB_EMBEDDED
99 99
100 if ( !result ) return KABC::AddresseeList(); 100 if ( !result ) return KABC::AddresseeList();
101 101
102 KProcess proc; 102 KProcess proc;
103 103
104 if ( result == KMessageBox::Yes ) { 104 if ( result == KMessageBox::Yes ) {
105 proc << "kab2kabc"; 105 proc << "kab2kabc";
106 proc << "--override"; 106 proc << "--override";
107 } else if ( result == KMessageBox::No ) 107 } else if ( result == KMessageBox::No )
108 proc << "kab2kabc"; 108 proc << "kab2kabc";
109 else 109 else
110 kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl; 110 kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl;
111 111
112 proc.start( KProcess::Block ); 112 proc.start( KProcess::Block );
113 113
114 addressBook()->load(); 114 addressBook()->load();
115 115
116 return KABC::AddresseeList(); 116 return KABC::AddresseeList();
117} 117}
118 118
119#ifndef KAB_EMBEDDED 119#ifndef KAB_EMBEDDED
120#include "kde2_xxport.moc" 120#include "kde2_xxport.moc"
121#endif //KAB_EMBEDDED 121#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/opie_xxport.cpp b/kaddressbook/xxport/opie_xxport.cpp
new file mode 100644
index 0000000..192b803
--- a/dev/null
+++ b/kaddressbook/xxport/opie_xxport.cpp
@@ -0,0 +1,195 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qdir.h>
32
33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <opie/ocontactaccess.h>
37//US #include <opie/ocontactaccessbackend_xml.h>
38
39//US #include "stdaddressbook.h"
40#include "resource.h"
41#include "tmpaddressbook.h"
42
43/*US
44#include <qfile.h>
45#include <qtextstream.h>
46
47#include <kabc/vcardconverter.h>
48#ifndef KAB_EMBEDDED
49#include <kio/netaccess.h>
50#endif //KAB_EMBEDDED
51
52#include <klocale.h>
53#include <kmessagebox.h>
54#include <ktempfile.h>
55#include <kurl.h>
56*/
57
58#include <factory.h>
59
60
61#include "xxportmanager.h"
62
63#include "opie_xxport.h"
64
65/*US
66class OpieXXPortFactory : public XXPortFactory
67{
68 public:
69 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
70 {
71 return new OpieXXPort( ab, parent, name );
72 }
73};
74*/
75
76
77extern "C"
78{
79 void *init_microkaddrbk_opie_xxport()
80 {
81 return ( new OpieXXPortFactory() );
82 }
83}
84
85
86OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
87 : XXPortResourceObject( ab, parent, name )
88{
89 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
90
91 KRES::Factory* mFactory = KRES::Factory::self( "contact" );
92
93 if ( mFactory )
94 {
95 mResource = (KABC::Resource*)(mFactory->resource( "opie", 0, false ));
96
97 if ( mResource )
98 {
99 createImportAction( i18n( "Import Opie..." ) );
100 createExportAction( i18n( "Export Opie..." ) );
101 }
102 }
103}
104
105bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
106{
107 if (mResource == 0)
108 return false;
109
110 QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() );
111
112 if ( fileName.isEmpty() )
113 return false;
114
115 mResource->setFileName( fileName );
116
117
118 KABC::TmpAddressBook tmpAB;
119
120 tmpAB.addResource( mResource );
121
122 qDebug("11111");
123
124 //Now check if the file has already entries, and ask the user if he wants to delete them first.
125 KABC::AddressBook::Iterator it2 = tmpAB.begin();
126 for ( it2 = tmpAB.begin(); it2 != tmpAB.end(); ++it2 ) {
127 KABC::Addressee addressee = (*it2);
128 qDebug("found %s", addressee.formattedName().latin1());
129 }
130
131 if (it2 != tmpAB.end())
132 {
133 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
134 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
135 // Clean the database..
136 tmpAB.clear();
137 }
138 }
139 qDebug("22222");
140
141//US debug
142 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
143 QPtrListIterator<KABC::Resource> resIt( kabcResources );
144 KABC::Resource *resource;
145 while ( ( resource = resIt.current() ) != 0 ) {
146 ++resIt;
147 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
148 }
149
150
151 KABC::Addressee::List::ConstIterator it;
152 for ( it = list.begin(); it != list.end(); ++it ) {
153 tmpAB.insertAddressee(*it);
154 }
155
156 bool res = false;
157 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
158
159 if (ticket != 0)
160 res = tmpAB.save( ticket );
161
162 tmpAB.removeResource( mResource );
163
164 return res;
165}
166
167
168KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
169{
170 if (mResource == 0)
171 return KABC::AddresseeList();
172
173 KABC::AddresseeList adrlst;
174
175 QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() );
176
177 if ( fileName.isEmpty() )
178 return KABC::AddresseeList();
179
180 mResource->setFileName( fileName );
181
182
183 KABC::TmpAddressBook tmpAB;
184
185 tmpAB.addResource( mResource );
186
187 bool res = tmpAB.load();
188
189 adrlst = tmpAB.allAddressees();
190
191 tmpAB.removeResource( mResource );
192
193 return adrlst;
194
195}
diff --git a/kaddressbook/xxport/opie_xxport.h b/kaddressbook/xxport/opie_xxport.h
new file mode 100644
index 0000000..106f38b
--- a/dev/null
+++ b/kaddressbook/xxport/opie_xxport.h
@@ -0,0 +1,68 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef OPIE_XXPORT_H
32#define OPIE_XXPORT_H
33
34#include <xxportobject.h>
35
36
37class KABC::Resource;
38
39class OpieXXPort : public XXPortResourceObject
40{
41 Q_OBJECT
42
43 public:
44 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
45
46 QString identifier() const { return "opie"; }
47
48 public slots:
49 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
50 KABC::AddresseeList importContacts( const QString &data ) const;
51
52 private:
53 QString defaultFileName;
54
55};
56
57
58class OpieXXPortFactory : public XXPortFactory
59{
60 public:
61 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
62 {
63 return new OpieXXPort( ab, parent, name );
64 }
65};
66
67
68#endif
diff --git a/kaddressbook/xxport/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia_xxport.cpp
new file mode 100644
index 0000000..8377cd5
--- a/dev/null
+++ b/kaddressbook/xxport/qtopia_xxport.cpp
@@ -0,0 +1,287 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qdir.h>
32
33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <qpe/pim/addressbookaccess.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h"
56//US #include "qtopiaconverter.h"
57
58#include "qtopia_xxport.h"
59
60/*US
61class QtopiaXXPortFactory : public XXPortFactory
62{
63 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 {
66 return new QtopiaXXPort( ab, parent, name );
67 }
68};
69*/
70
71extern "C"
72{
73 void *init_microkaddrbk_qtopia_xxport()
74 {
75 return ( new QtopiaXXPortFactory() );
76 }
77}
78
79
80
81QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortResourceObject( ab, parent, name )
83{
84 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
85
86 KRES::Factory* mFactory = KRES::Factory::self( "contact" );
87
88 if ( mFactory )
89 {
90 mResource = (KABC::Resource*)(mFactory->resource( "qtopia", 0, false ));
91
92 if ( mResource )
93 {
94 createImportAction( i18n( "Import Qtopia..." ) );
95 createExportAction( i18n( "Export Qtopia..." ) );
96 }
97 }
98}
99
100bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
101{
102/*US
103 // we can not choose the filename. Therefore use the default to display
104 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
105
106 AddressBookAccess* access = new AddressBookAccess();
107
108 if ( !access ) {
109 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
110 qDebug(text.latin1());
111 KMessageBox::error( parentWidget(), text );
112 addressBook()->error( text );
113 return false;
114 }
115
116 KABC::QtopiaConverter mConverter;
117
118 bool res = mConverter.init();
119 if (!res)
120 {
121 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
122 qDebug(text);
123 KMessageBox::error( parentWidget(), text );
124 delete access;
125 return false;
126 }
127
128 //Now check if the file has already entries, and ask the user if he wants to delete them first.
129 { //create a new scope
130 AddressBookIterator it(*access);
131 const PimContact* firstcontact = it.toFirst();
132 if (firstcontact)
133 {
134 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
135 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
136 // Clean the database..
137
138 AddressBookIterator it2(*access);
139 for (it2.toFirst(); it2.current(); ++it2) {
140 access->removeContact(*it2.current());
141 }
142 }
143 }
144 }
145
146 KABC::Addressee::List::ConstIterator it;
147 for ( it = list.begin(); it != list.end(); ++it ) {
148 PimContact c;
149
150 res = mConverter.addresseeToQtopia( *it, c );
151 if (res == true)
152 {
153 access->addContact(c);
154 }
155 }
156
157 delete access;
158
159 return true;
160*/
161
162 if (mResource == 0)
163 return false;
164
165 QString fileName = defaultFileName;
166
167
168 mResource->setFileName( fileName );
169
170 //Now check if the file has already entries, and ask the user if he wants to delete them first.
171 if (mResource->count() > 0)
172 {
173 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
174 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
175 // Clean the database.
176 mResource->clear();
177 }
178 }
179
180 KABC::AddressBook tmpAB;
181
182 tmpAB.addResource( mResource );
183
184//US debug
185 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
186 QPtrListIterator<KABC::Resource> resIt( kabcResources );
187 KABC::Resource *resource;
188 while ( ( resource = resIt.current() ) != 0 ) {
189 ++resIt;
190 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
191 }
192
193
194 KABC::Addressee::List::ConstIterator it;
195 for ( it = list.begin(); it != list.end(); ++it ) {
196 tmpAB.insertAddressee(*it);
197 }
198
199 KABC::Ticket * ticket = mResource->requestSaveTicket();
200 return tmpAB.save( ticket );
201
202
203
204}
205
206KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const
207{
208/*US
209 KABC::AddresseeList adrlst;
210
211 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
212
213 AddressBookAccess* access = new AddressBookAccess();
214
215 if ( !access ) {
216 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
217 qDebug(text.latin1());
218 addressBook()->error( text );
219 KMessageBox::error( parentWidget(), text );
220 return KABC::AddresseeList();
221 }
222
223 KABC::QtopiaConverter mConverter;
224
225 bool res = mConverter.init();
226 if (!res)
227 {
228 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
229 qDebug(text);
230 KMessageBox::error( parentWidget(), text );
231 delete access;
232 return KABC::AddresseeList();
233 }
234
235
236
237 { //create a new scope
238 AddressBookIterator it(*access);
239
240 for (it.toFirst(); it.current(); ++it) {
241 const PimContact*contact = it.current();
242
243 KABC::Addressee addressee;
244
245 res = mConverter.qtopiaToAddressee( (*contact), addressee );
246
247 if ( !addressee.isEmpty() && res )
248 {
249 adrlst.append( addressee );
250 }
251 }
252 }
253
254 delete access;
255//US the deletion of the access object deletes the backend object as well.
256
257 return adrlst;
258*/
259
260 if (mResource == 0)
261 return KABC::AddresseeList();
262
263 KABC::AddresseeList adrlst;
264
265 QString fileName = defaultFileName;
266
267 mResource->setFileName( fileName );
268
269
270 KABC::AddressBook tmpAB;
271
272 tmpAB.addResource( mResource );
273
274//US debug
275 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
276 QPtrListIterator<KABC::Resource> resIt( kabcResources );
277 KABC::Resource *resource;
278 while ( ( resource = resIt.current() ) != 0 ) {
279 ++resIt;
280 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
281 }
282
283 bool res = tmpAB.load();
284
285 return tmpAB.allAddressees();
286
287}
diff --git a/kaddressbook/xxport/qtopia_xxport.h b/kaddressbook/xxport/qtopia_xxport.h
new file mode 100644
index 0000000..c7c89de
--- a/dev/null
+++ b/kaddressbook/xxport/qtopia_xxport.h
@@ -0,0 +1,64 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef QTOPIA_XXPORT_H
32#define QTOPIA_XXPORT_H
33
34#include <xxportobject.h>
35
36class QtopiaXXPort : public XXPortResourceObject
37{
38 Q_OBJECT
39
40 public:
41 QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42
43 QString identifier() const { return "qtopia"; }
44
45 public slots:
46 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
47 KABC::AddresseeList importContacts( const QString &data ) const;
48
49 private:
50 QString defaultFileName;
51
52};
53
54
55class QtopiaXXPortFactory : public XXPortFactory
56{
57 public:
58 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
59 {
60 return new QtopiaXXPort( ab, parent, name );
61 }
62};
63
64#endif
diff --git a/kaddressbook/xxport/sharpdtm_xxport.cpp b/kaddressbook/xxport/sharpdtm_xxport.cpp
new file mode 100644
index 0000000..8c2e07a
--- a/dev/null
+++ b/kaddressbook/xxport/sharpdtm_xxport.cpp
@@ -0,0 +1,284 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2004 Ulf Schenk
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qdir.h>
32
33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <sl/slzdb.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h"
56
57#include "sharpdtm_xxport.h"
58
59/*US
60class SharpDTMXXPortFactory : public XXPortFactory
61{
62 public:
63 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
64 {
65 return new SharpDTMXXPort( ab, parent, name );
66 }
67};
68*/
69
70extern "C"
71{
72 void *init_microkaddrbk_sharpdtm_xxport()
73 {
74 return ( new SharpDTMXXPortFactory() );
75 }
76}
77
78SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
79 : XXPortResourceObject( ab, parent, name )
80{
81 KRES::Factory* mFactory = KRES::Factory::self( "contact" );
82
83 if ( mFactory )
84 {
85 mResource = (KABC::Resource*)(mFactory->resource( "sharpdtm", 0, false ));
86 if ( mResource )
87 {
88 createImportAction( i18n( "Import Sharp..." ) );
89 createExportAction( i18n( "Export Sharp..." ) );
90 }
91 }
92}
93
94bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
95{
96/*US
97 // we can not choose the filename. Therefore use the default to display
98 QString fileName = SlZDataBase::addressbookFileName();
99
100 SlZDataBase* access = new SlZDataBase(fileName,
101 SlZDataBase::addressbookItems());
102
103 if ( !access ) {
104 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
105 qDebug(text.latin1());
106 KMessageBox::error( parentWidget(), text );
107 addressBook()->error( text );
108 return false;
109 }
110
111 KABC::SharpDTMConverter mConverter;
112
113 bool res = mConverter.init();
114 if (!res)
115 {
116 QString text( i18n( "Unable to initialize sharpdtm converter.<br>Most likely a problem with the category file." ) );
117 qDebug(text);
118 KMessageBox::error( parentWidget(), text );
119 delete access;
120 return false;
121 }
122
123 //Now check if the file has already entries, and ask the user if he wants to delete them first.
124 if (access->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->deleteCard(0, SlZDataBase::AllCard );
130 }
131 }
132
133 KABC::Addressee::List::ConstIterator it;
134 for ( it = list.begin(); it != list.end(); ++it ) {
135 CardId c;
136 res = access->editNewCard();
137
138 if (res == true)
139 {
140 res = mConverter.addresseeToSharp( *it, access, c );
141
142 if (res == true)
143 access->finishEditCard(&c);
144 else
145 access->cancelEditCard();
146 }
147 }
148
149 delete access;
150
151 return true;
152*/
153
154 if (mResource == 0)
155 return false;
156
157 // we can not choose the filename. Therefore use the default to display
158 QString fileName = mResource->fileName();
159
160 if ( fileName.isEmpty() )
161 return false;
162
163 //Now check if the file has already entries, and ask the user if he wants to delete them first.
164 if (mResource->count() > 0)
165 {
166 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
167 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
168 // Clean the database..
169 mResource->clear();
170 }
171 }
172
173 KABC::AddressBook tmpAB;
174
175 tmpAB.addResource( mResource );
176
177//US debug
178 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
179 QPtrListIterator<KABC::Resource> resIt( kabcResources );
180 KABC::Resource *resource;
181 while ( ( resource = resIt.current() ) != 0 ) {
182 ++resIt;
183 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
184 }
185
186
187 KABC::Addressee::List::ConstIterator it;
188 for ( it = list.begin(); it != list.end(); ++it ) {
189 tmpAB.insertAddressee(*it);
190 }
191
192 KABC::Ticket * ticket = mResource->requestSaveTicket();
193 return tmpAB.save( ticket );
194
195
196}
197
198KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const
199{
200/*US
201 KABC::AddresseeList adrlst;
202
203 QString fileName = SlZDataBase::addressbookFileName();
204
205 // the last parameter in the SlZDataBase constructor means "readonly"
206 SlZDataBase* access = new SlZDataBase(fileName,
207 SlZDataBase::addressbookItems(), NULL, true);
208
209
210 if ( !access ) {
211 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
212 qDebug(text.latin1());
213 addressBook()->error( text );
214 KMessageBox::error( parentWidget(), text );
215 return KABC::AddresseeList();
216 }
217
218 KABC::SharpDTMConverter mConverter;
219
220 bool res = mConverter.init();
221 if (!res)
222 {
223 QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) );
224 qDebug(text);
225 KMessageBox::error( parentWidget(), text );
226 delete access;
227 return KABC::AddresseeList();
228 }
229
230
231 { //create a new scope
232 CardId id;
233
234 for (bool res=access->first(); res == true; res=access->next()) {
235 id = access->cardId();
236
237 KABC::Addressee addressee;
238
239 res = mConverter.sharpToAddressee( id, access, addressee );
240
241 if ( !addressee.isEmpty() && res )
242 {
243 adrlst.append( addressee );
244 }
245 }
246 }
247
248 delete access;
249
250 return adrlst;
251*/
252
253 if (mResource == 0)
254 return KABC::AddresseeList();
255
256 KABC::AddresseeList adrlst;
257
258 QString fileName = mResource->fileName();
259
260 if ( fileName.isEmpty() )
261 return KABC::AddresseeList();
262
263 mResource->setFileName( fileName );
264
265
266 KABC::AddressBook tmpAB;
267
268 tmpAB.addResource( mResource );
269
270//US debug
271 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
272 QPtrListIterator<KABC::Resource> resIt( kabcResources );
273 KABC::Resource *resource;
274 while ( ( resource = resIt.current() ) != 0 ) {
275 ++resIt;
276 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
277 }
278
279 bool res = tmpAB.load();
280
281 return tmpAB.allAddressees();
282
283
284}
diff --git a/kaddressbook/xxport/sharpdtm_xxport.h b/kaddressbook/xxport/sharpdtm_xxport.h
new file mode 100644
index 0000000..43fd434
--- a/dev/null
+++ b/kaddressbook/xxport/sharpdtm_xxport.h
@@ -0,0 +1,60 @@
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef SHARPDTM_XXPORT_H
32#define SHARPDTM_XXPORT_H
33
34#include <xxportobject.h>
35
36class SharpDTMXXPort : public XXPortResourceObject
37{
38 Q_OBJECT
39
40 public:
41 SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42
43 QString identifier() const { return "qtopia"; }
44
45 public slots:
46 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
47 KABC::AddresseeList importContacts( const QString &data ) const;
48
49};
50
51class SharpDTMXXPortFactory : public XXPortFactory
52{
53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 {
56 return new SharpDTMXXPort( ab, parent, name );
57 }
58};
59
60#endif
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index 4819341..acf6419 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -1,255 +1,256 @@
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 <qfile.h> 31#include <qfile.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33 33
34#include <kabc/vcardconverter.h> 34#include <kabc/vcardconverter.h>
35#include <kabc/vcardparser/vcardtool.h> 35#include <kabc/vcardparser/vcardtool.h>
36#include <kfiledialog.h> 36#include <kfiledialog.h>
37#ifndef KAB_EMBEDDED 37#ifndef KAB_EMBEDDED
38#include <kio/netaccess.h> 38#include <kio/netaccess.h>
39#endif //KAB_EMBEDDED 39#endif //KAB_EMBEDDED
40 40
41#include <klocale.h> 41#include <klocale.h>
42#include <kmessagebox.h> 42#include <kmessagebox.h>
43#include <ktempfile.h> 43#include <ktempfile.h>
44#include <kurl.h> 44#include <kurl.h>
45 45
46#include "xxportmanager.h" 46#include "xxportmanager.h"
47 47
48#include "vcard_xxport.h" 48#include "vcard_xxport.h"
49 49
50#ifndef KAB_EMBEDDED 50#ifndef KAB_EMBEDDED
51 51
52class VCardXXPortFactory : public XXPortFactory 52class VCardXXPortFactory : public XXPortFactory
53{ 53{
54 public: 54 public:
55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
56 { 56 {
57 return new VCardXXPort( ab, parent, name ); 57 return new VCardXXPort( ab, parent, name );
58 } 58 }
59}; 59};
60#endif //KAB_EMBEDDED 60#endif //KAB_EMBEDDED
61 61
62 62
63extern "C" 63extern "C"
64{ 64{
65#ifndef KAB_EMBEDDED 65#ifndef KAB_EMBEDDED
66 void *init_libkaddrbk_vcard_xxport() 66 void *init_libkaddrbk_vcard_xxport()
67#else //KAB_EMBEDDED 67#else //KAB_EMBEDDED
68 void *init_kaddrbk_vcard_xxport() 68 void *init_microkaddrbk_vcard_xxport()
69#endif //KAB_EMBEDDED 69#endif //KAB_EMBEDDED
70 { 70 {
71 return ( new VCardXXPortFactory() ); 71 return ( new VCardXXPortFactory() );
72 } 72 }
73} 73}
74 74
75 75
76VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 76VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
77 : XXPortObject( ab, parent, name ) 77 : XXPortObject( ab, parent, name )
78{ 78{
79 createImportAction( i18n( "Import vCard..." ) ); 79 createImportAction( i18n( "Import vCard..." ) );
80//US KABC::VCardConverter does not support the export of 2.1 addressbooks. 80//US KABC::VCardConverter does not support the export of 2.1 addressbooks.
81//US createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); 81//US createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
82 createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); 82 createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
83} 83}
84 84
85bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 85bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
86{ 86{
87 QString name; 87 QString name;
88 88
89 if ( list.count() == 1 ) 89 if ( list.count() == 1 )
90 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; 90 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
91 else 91 else
92 name = "addressbook.vcf"; 92 name = "addressbook.vcf";
93 93
94#ifndef KAB_EMBEDDED 94#ifndef KAB_EMBEDDED
95 QString fileName = KFileDialog::getSaveFileName( name ); 95 QString fileName = KFileDialog::getSaveFileName( name );
96#else //KAB_EMBEDDED 96#else //KAB_EMBEDDED
97 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); 97 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
98#endif //KAB_EMBEDDED 98#endif //KAB_EMBEDDED
99 99
100 if ( fileName.isEmpty() ) 100 if ( fileName.isEmpty() )
101 return false; 101 return false;
102 102
103 QFile outFile( fileName ); 103 QFile outFile( fileName );
104 if ( !outFile.open( IO_WriteOnly ) ) { 104 if ( !outFile.open( IO_WriteOnly ) ) {
105 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 105 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
106 KMessageBox::error( parentWidget(), text.arg( fileName ) ); 106 KMessageBox::error( parentWidget(), text.arg( fileName ) );
107 return false; 107 return false;
108 } 108 }
109 109
110 QTextStream t( &outFile ); 110 QTextStream t( &outFile );
111 t.setEncoding( QTextStream::UnicodeUTF8 ); 111 t.setEncoding( QTextStream::UnicodeUTF8 );
112 112
113 KABC::Addressee::List::ConstIterator it; 113 KABC::Addressee::List::ConstIterator it;
114 for ( it = list.begin(); it != list.end(); ++it ) { 114 for ( it = list.begin(); it != list.end(); ++it ) {
115 KABC::VCardConverter converter; 115 KABC::VCardConverter converter;
116 QString vcard; 116 QString vcard;
117 117
118 KABC::VCardConverter::Version version; 118 KABC::VCardConverter::Version version;
119 if ( data == "v21" ) 119 if ( data == "v21" )
120 version = KABC::VCardConverter::v2_1; 120 version = KABC::VCardConverter::v2_1;
121 else 121 else
122 version = KABC::VCardConverter::v3_0; 122 version = KABC::VCardConverter::v3_0;
123 123
124 converter.addresseeToVCard( *it, vcard, version ); 124 converter.addresseeToVCard( *it, vcard, version );
125 t << vcard << "\r\n\r\n"; 125 t << vcard << "\r\n\r\n";
126 } 126 }
127 127
128 outFile.close(); 128 outFile.close();
129 129
130 return true; 130 return true;
131} 131}
132 132
133KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const 133KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
134{ 134{
135 QString fileName; 135 QString fileName;
136 KABC::AddresseeList addrList; 136 KABC::AddresseeList addrList;
137 KURL url; 137 KURL url;
138 138
139#ifndef KAB_EMBEDDED 139#ifndef KAB_EMBEDDED
140 if ( !XXPortManager::importData.isEmpty() ) 140 if ( !XXPortManager::importData.isEmpty() )
141 addrList = parseVCard( XXPortManager::importData ); 141 addrList = parseVCard( XXPortManager::importData );
142 else { 142 else {
143 if ( XXPortManager::importURL.isEmpty() ) 143 if ( XXPortManager::importURL.isEmpty() )
144 { 144 {
145 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 145 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
146 } 146 }
147 else 147 else
148 url = XXPortManager::importURL; 148 url = XXPortManager::importURL;
149 149
150 if ( url.isEmpty() ) 150 if ( url.isEmpty() )
151 return addrList; 151 return addrList;
152 152
153 QString caption( i18n( "vCard Import Failed" ) ); 153 QString caption( i18n( "vCard Import Failed" ) );
154 if ( KIO::NetAccess::download( url, fileName ) ) { 154 if ( KIO::NetAccess::download( url, fileName ) ) {
155 QFile file( fileName ); 155 QFile file( fileName );
156 156
157 file.open( IO_ReadOnly ); 157 file.open( IO_ReadOnly );
158 QByteArray rawData = file.readAll(); 158 QByteArray rawData = file.readAll();
159 file.close(); 159 file.close();
160 160
161 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 161 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
162 addrList = parseVCard( data ); 162 addrList = parseVCard( data );
163 163
164 if ( !url.isLocalFile() ) 164 if ( !url.isLocalFile() )
165 KIO::NetAccess::removeTempFile( fileName ); 165 KIO::NetAccess::removeTempFile( fileName );
166 166
167 } else { 167 } else {
168 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); 168 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
169 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); 169 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
170 } 170 }
171 171
172 } 172 }
173 173
174 174
175#else //KAB_EMBEDDED 175#else //KAB_EMBEDDED
176 176
177 177
178 if ( !XXPortManager::importData.isEmpty() ) 178 if ( !XXPortManager::importData.isEmpty() )
179 addrList = parseVCard( XXPortManager::importData ); 179 addrList = parseVCard( XXPortManager::importData );
180 else { 180 else {
181 if ( XXPortManager::importURL.isEmpty() ) 181 if ( XXPortManager::importURL.isEmpty() )
182 { 182 {
183 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); 183 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
184 if ( fileName.isEmpty() ) 184 if ( fileName.isEmpty() )
185 return addrList; 185 return addrList;
186 186
187 } 187 }
188 else 188 else
189 { 189 {
190//US url = XXPortManager::importURL; 190//US url = XXPortManager::importURL;
191 qDebug("VCardXXPort::importContacts Urls at the moment not supported"); 191 qDebug("VCardXXPort::importContacts Urls at the moment not supported");
192 if ( url.isEmpty() ) 192 if ( url.isEmpty() )
193 return addrList; 193 return addrList;
194 194
195 } 195 }
196 196
197 197
198 QFile file( fileName ); 198 QFile file( fileName );
199 199
200 file.open( IO_ReadOnly ); 200 file.open( IO_ReadOnly );
201 QByteArray rawData = file.readAll(); 201 QByteArray rawData = file.readAll();
202 file.close(); 202 file.close();
203 203
204 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 204 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
205 addrList = parseVCard( data ); 205 addrList = parseVCard( data );
206 206
207 } 207 }
208#endif //KAB_EMBEDDED 208#endif //KAB_EMBEDDED
209 209
210 return addrList; 210 return addrList;
211} 211}
212 212
213KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const 213KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
214{ 214{
215 215
216 KABC::VCardTool tool; 216 KABC::VCardTool tool;
217 KABC::AddresseeList addrList; 217 KABC::AddresseeList addrList;
218 addrList = tool.parseVCards( data ); 218 addrList = tool.parseVCards( data );
219 // LR : I switched to the code, which is in current cvs HEAD 219 // LR : I switched to the code, which is in current cvs HEAD
220 /* 220 /*
221 uint numVCards = data.contains( "BEGIN:VCARD", false ); 221 uint numVCards = data.contains( "BEGIN:VCARD", false );
222 QStringList dataList = QStringList::split( "\r\n\r\n", data ); 222 QStringList dataList = QStringList::split( "\r\n\r\n", data );
223 223
224 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) { 224 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
225 KABC::Addressee addr; 225 KABC::Addressee addr;
226 bool ok = false; 226 bool ok = false;
227 227
228 if ( dataList[ i ].contains( "VERSION:3.0" ) ) 228 if ( dataList[ i ].contains( "VERSION:3.0" ) )
229 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 ); 229 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 );
230 else if ( dataList[ i ].contains( "VERSION:2.1" ) ) 230 else if ( dataList[ i ].contains( "VERSION:2.1" ) )
231 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 ); 231 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 );
232 else { 232 else {
233 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) ); 233 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) );
234 continue; 234 continue;
235 } 235 }
236 236
237 if ( !addr.isEmpty() && ok ) 237 if ( !addr.isEmpty() && ok )
238 addrList.append( addr ); 238 addrList.append( addr );
239 else { 239 else {
240 QString text = i18n( "The selected file does not include a valid vCard. " 240 QString text = i18n( "The selected file does not include a valid vCard. "
241 "Please check the file and try again." ); 241 "Please check the file and try again." );
242 KMessageBox::sorry( parentWidget(), text ); 242 KMessageBox::sorry( parentWidget(), text );
243 } 243 }
244 } 244 }
245 */ 245 */
246 if ( addrList.isEmpty() ) { 246 if ( addrList.isEmpty() ) {
247 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" ); 247 QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" );
248 KMessageBox::sorry( parentWidget(), text ); 248 KMessageBox::sorry( parentWidget(), text );
249 } 249 }
250 return addrList; 250 return addrList;
251} 251}
252 252
253
253#ifndef KAB_EMBEDDED 254#ifndef KAB_EMBEDDED
254#include "vcard_xxport.moc" 255#include "vcard_xxport.moc"
255#endif //KAB_EMBEDDED 256#endif //KAB_EMBEDDED