Diffstat (limited to 'kaddressbook/xxport/opie_xxport.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/xxport/opie_xxport.cpp | 120 |
1 files changed, 8 insertions, 112 deletions
diff --git a/kaddressbook/xxport/opie_xxport.cpp b/kaddressbook/xxport/opie_xxport.cpp index 192b803..7b29b0a 100644 --- a/kaddressbook/xxport/opie_xxport.cpp +++ b/kaddressbook/xxport/opie_xxport.cpp | |||
@@ -22,53 +22,27 @@ | |||
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 <qdir.h> | 31 | #include <qdir.h> |
32 | 32 | ||
33 | #include <kfiledialog.h> | 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 | 34 | ||
35 | #include "addressee.h" | ||
61 | #include "xxportmanager.h" | 36 | #include "xxportmanager.h" |
62 | |||
63 | #include "opie_xxport.h" | 37 | #include "opie_xxport.h" |
64 | 38 | ||
65 | /*US | 39 | /*US |
66 | class OpieXXPortFactory : public XXPortFactory | 40 | class OpieXXPortFactory : public XXPortFactory |
67 | { | 41 | { |
68 | public: | 42 | public: |
69 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 43 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
70 | { | 44 | { |
71 | return new OpieXXPort( ab, parent, name ); | 45 | return new OpieXXPort( ab, parent, name ); |
72 | } | 46 | } |
73 | }; | 47 | }; |
74 | */ | 48 | */ |
@@ -79,117 +53,39 @@ extern "C" | |||
79 | void *init_microkaddrbk_opie_xxport() | 53 | void *init_microkaddrbk_opie_xxport() |
80 | { | 54 | { |
81 | return ( new OpieXXPortFactory() ); | 55 | return ( new OpieXXPortFactory() ); |
82 | } | 56 | } |
83 | } | 57 | } |
84 | 58 | ||
85 | 59 | ||
86 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 60 | OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
87 | : XXPortResourceObject( ab, parent, name ) | 61 | : XXPortResourceObject( ab, parent, name ) |
88 | { | 62 | { |
89 | defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 63 | defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
90 | 64 | ||
91 | KRES::Factory* mFactory = KRES::Factory::self( "contact" ); | 65 | if ( mFactory && !mFactory->typeName( "opie" ).isEmpty() ) |
92 | |||
93 | if ( mFactory ) | ||
94 | { | 66 | { |
95 | mResource = (KABC::Resource*)(mFactory->resource( "opie", 0, false )); | 67 | createImportAction( i18n( "Import Opie..." ) ); |
96 | 68 | createExportAction( i18n( "Export Opie..." ) ); | |
97 | if ( mResource ) | ||
98 | { | ||
99 | createImportAction( i18n( "Import Opie..." ) ); | ||
100 | createExportAction( i18n( "Export Opie..." ) ); | ||
101 | } | ||
102 | } | 69 | } |
103 | } | 70 | } |
104 | 71 | ||
105 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 72 | bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier ) |
106 | { | 73 | { |
107 | if (mResource == 0) | ||
108 | return false; | ||
109 | |||
110 | QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() ); | 74 | QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() ); |
111 | 75 | ||
112 | if ( fileName.isEmpty() ) | 76 | if ( fileName.isEmpty() ) |
113 | return false; | 77 | return false; |
114 | 78 | ||
115 | mResource->setFileName( fileName ); | 79 | return _exportContacts( list, identifier, 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 | } | 80 | } |
166 | 81 | ||
167 | 82 | ||
168 | KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const | 83 | KABC::AddresseeList OpieXXPort::importContacts( const QString &identifier ) const |
169 | { | 84 | { |
170 | if (mResource == 0) | ||
171 | return KABC::AddresseeList(); | ||
172 | |||
173 | KABC::AddresseeList adrlst; | ||
174 | |||
175 | QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() ); | 85 | QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() ); |
176 | 86 | ||
177 | if ( fileName.isEmpty() ) | 87 | if ( fileName.isEmpty() ) |
178 | return KABC::AddresseeList(); | 88 | return KABC::AddresseeList(); |
179 | 89 | ||
180 | mResource->setFileName( fileName ); | 90 | return _importContacts( identifier, 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 | } | 91 | } |