Diffstat (limited to 'kaddressbook/xxport/vcard_xxport.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/xxport/vcard_xxport.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp index dd49a9c..c017f5b 100644 --- a/kaddressbook/xxport/vcard_xxport.cpp +++ b/kaddressbook/xxport/vcard_xxport.cpp | |||
@@ -11,106 +11,110 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 <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 "xxportmanager.h" | 45 | #include "xxportmanager.h" |
46 | 46 | ||
47 | #include "vcard_xxport.h" | 47 | #include "vcard_xxport.h" |
48 | 48 | ||
49 | #ifndef KAB_EMBEDDED | 49 | #ifndef KAB_EMBEDDED |
50 | 50 | ||
51 | class VCardXXPortFactory : public XXPortFactory | 51 | class VCardXXPortFactory : 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 VCardXXPort( ab, parent, name ); | 56 | return new VCardXXPort( ab, parent, name ); |
57 | } | 57 | } |
58 | }; | 58 | }; |
59 | #endif //KAB_EMBEDDED | ||
59 | 60 | ||
60 | 61 | ||
61 | extern "C" | 62 | extern "C" |
62 | { | 63 | { |
64 | #ifndef KAB_EMBEDDED | ||
63 | void *init_libkaddrbk_vcard_xxport() | 65 | void *init_libkaddrbk_vcard_xxport() |
66 | #else //KAB_EMBEDDED | ||
67 | void *init_kaddrbk_vcard_xxport() | ||
68 | #endif //KAB_EMBEDDED | ||
64 | { | 69 | { |
65 | return ( new VCardXXPortFactory() ); | 70 | return ( new VCardXXPortFactory() ); |
66 | } | 71 | } |
67 | } | 72 | } |
68 | #endif //KAB_EMBEDDED | ||
69 | 73 | ||
70 | 74 | ||
71 | VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 75 | VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
72 | : XXPortObject( ab, parent, name ) | 76 | : XXPortObject( ab, parent, name ) |
73 | { | 77 | { |
74 | createImportAction( i18n( "Import vCard..." ) ); | 78 | createImportAction( i18n( "Import vCard..." ) ); |
75 | createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); | 79 | createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); |
76 | createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); | 80 | createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); |
77 | } | 81 | } |
78 | 82 | ||
79 | bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 83 | bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) |
80 | { | 84 | { |
81 | QString name; | 85 | QString name; |
82 | 86 | ||
83 | if ( list.count() == 1 ) | 87 | if ( list.count() == 1 ) |
84 | name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; | 88 | name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; |
85 | else | 89 | else |
86 | name = "addressbook.vcf"; | 90 | name = "addressbook.vcf"; |
87 | 91 | ||
88 | #ifndef KAB_EMBEDDED | 92 | #ifndef KAB_EMBEDDED |
89 | QString fileName = KFileDialog::getSaveFileName( name ); | 93 | QString fileName = KFileDialog::getSaveFileName( name ); |
90 | #else //KAB_EMBEDDED | 94 | #else //KAB_EMBEDDED |
91 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); | 95 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); |
92 | #endif //KAB_EMBEDDED | 96 | #endif //KAB_EMBEDDED |
93 | 97 | ||
94 | if ( fileName.isEmpty() ) | 98 | if ( fileName.isEmpty() ) |
95 | return true; | 99 | return true; |
96 | 100 | ||
97 | QFile outFile( fileName ); | 101 | QFile outFile( fileName ); |
98 | if ( !outFile.open( IO_WriteOnly ) ) { | 102 | if ( !outFile.open( IO_WriteOnly ) ) { |
99 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 103 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
100 | KMessageBox::error( parentWidget(), text.arg( fileName ) ); | 104 | KMessageBox::error( parentWidget(), text.arg( fileName ) ); |
101 | return false; | 105 | return false; |
102 | } | 106 | } |
103 | 107 | ||
104 | QTextStream t( &outFile ); | 108 | QTextStream t( &outFile ); |
105 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 109 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
106 | 110 | ||
107 | KABC::Addressee::List::ConstIterator it; | 111 | KABC::Addressee::List::ConstIterator it; |
108 | for ( it = list.begin(); it != list.end(); ++it ) { | 112 | for ( it = list.begin(); it != list.end(); ++it ) { |
109 | KABC::VCardConverter converter; | 113 | KABC::VCardConverter converter; |
110 | QString vcard; | 114 | QString vcard; |
111 | 115 | ||
112 | KABC::VCardConverter::Version version; | 116 | KABC::VCardConverter::Version version; |
113 | if ( data == "v21" ) | 117 | if ( data == "v21" ) |
114 | version = KABC::VCardConverter::v2_1; | 118 | version = KABC::VCardConverter::v2_1; |
115 | else | 119 | else |
116 | version = KABC::VCardConverter::v3_0; | 120 | version = KABC::VCardConverter::v3_0; |