summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-17 00:37:00 (UTC)
committer ulf69 <ulf69>2004-07-17 00:37:00 (UTC)
commit2439711b1ac7ee38269baff704293eb37a27f6c9 (patch) (unidiff)
tree706d4a329b557b28db14442b41229d11fede854b
parentb306ee8c93dd563f42a32a1ee2c63eacc6050604 (diff)
downloadkdepimpi-2439711b1ac7ee38269baff704293eb37a27f6c9.zip
kdepimpi-2439711b1ac7ee38269baff704293eb37a27f6c9.tar.gz
kdepimpi-2439711b1ac7ee38269baff704293eb37a27f6c9.tar.bz2
implementation of sharp import and export
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/sharpdtm/sharpdtmE.pro2
-rw-r--r--kaddressbook/xxport/sharpdtm/sharpdtm_xxport.cpp103
2 files changed, 49 insertions, 56 deletions
diff --git a/kaddressbook/xxport/sharpdtm/sharpdtmE.pro b/kaddressbook/xxport/sharpdtm/sharpdtmE.pro
index 6e83853..0425c42 100644
--- a/kaddressbook/xxport/sharpdtm/sharpdtmE.pro
+++ b/kaddressbook/xxport/sharpdtm/sharpdtmE.pro
@@ -1,27 +1,27 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3TARGET = microkaddrbk_sharpdtm_xxport 3TARGET = microkaddrbk_sharpdtm_xxport
4 4
5OBJECTS_DIR = obj/$(PLATFORM) 5OBJECTS_DIR = obj/$(PLATFORM)
6MOC_DIR = moc/$(PLATFORM) 6MOC_DIR = moc/$(PLATFORM)
7DESTDIR = $(QPEDIR)/lib 7DESTDIR = $(QPEDIR)/lib
8 8
9DEFINES += KAB_EMBEDDED 9DEFINES += KAB_EMBEDDED
10 10
11INCLUDEPATH += ../.. ../../../external/sharpdtm/include ../../.. ../../../kabc ../../../kabc/converter/qtopia ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include 11INCLUDEPATH += ../.. ../../../external/sharpdtm/include ../../.. ../../../kabc ../../../kabc/converter/sharpdtm ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include
12LIBS += -L$(QPEDIR)/lib 12LIBS += -L$(QPEDIR)/lib
13LIBS += -lmicrokde 13LIBS += -lmicrokde
14LIBS += -lmicrokabc 14LIBS += -lmicrokabc
15LIBS += -lqpe 15LIBS += -lqpe
16LIBS += -lqte 16LIBS += -lqte
17LIBS += -lzdtm 17LIBS += -lzdtm
18LIBS += -lmicrokabc_sharpdtmconverter 18LIBS += -lmicrokabc_sharpdtmconverter
19 19
20INTERFACES = \ 20INTERFACES = \
21 21
22HEADERS = \ 22HEADERS = \
23 sharpdtm_xxport.h \ 23 sharpdtm_xxport.h \
24 24
25SOURCES = \ 25SOURCES = \
26 sharpdtm_xxport.cpp \ 26 sharpdtm_xxport.cpp \
27 27
diff --git a/kaddressbook/xxport/sharpdtm/sharpdtm_xxport.cpp b/kaddressbook/xxport/sharpdtm/sharpdtm_xxport.cpp
index 4e6a504..8593814 100644
--- a/kaddressbook/xxport/sharpdtm/sharpdtm_xxport.cpp
+++ b/kaddressbook/xxport/sharpdtm/sharpdtm_xxport.cpp
@@ -1,206 +1,199 @@
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 <sl/slzdb.h> 36#include <sl/slzdb.h>
37 37
38#include "stdaddressbook.h" 38#include "stdaddressbook.h"
39 39
40/*US 40/*US
41#include <qfile.h> 41#include <qfile.h>
42#include <qtextstream.h> 42#include <qtextstream.h>
43 43
44#include <kabc/vcardconverter.h> 44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h> 46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED 47#endif //KAB_EMBEDDED
48 48
49#include <klocale.h> 49#include <klocale.h>
50#include <kmessagebox.h> 50#include <kmessagebox.h>
51#include <ktempfile.h> 51#include <ktempfile.h>
52#include <kurl.h> 52#include <kurl.h>
53*/ 53*/
54 54
55#include "xxportmanager.h" 55#include "xxportmanager.h"
56//#include "qtopiaconverter.h" 56#include "sharpdtmconverter.h"
57 57
58#include "sharpdtm_xxport.h" 58#include "sharpdtm_xxport.h"
59 59
60 60
61class SharpDTMXXPortFactory : public XXPortFactory 61class SharpDTMXXPortFactory : public XXPortFactory
62{ 62{
63 public: 63 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 { 65 {
66 return new SharpDTMXXPort( ab, parent, name ); 66 return new SharpDTMXXPort( ab, parent, name );
67 } 67 }
68}; 68};
69 69
70 70
71extern "C" 71extern "C"
72{ 72{
73 void *init_microkaddrbk_sharpdtm_xxport() 73 void *init_microkaddrbk_sharpdtm_xxport()
74 { 74 {
75 return ( new SharpDTMXXPortFactory() ); 75 return ( new SharpDTMXXPortFactory() );
76 } 76 }
77} 77}
78 78
79 79
80SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 80SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
81 : XXPortObject( ab, parent, name ) 81 : XXPortObject( ab, parent, name )
82{ 82{
83 createImportAction( i18n( "Import Sharp..." ) ); 83 createImportAction( i18n( "Import Sharp..." ) );
84 createExportAction( i18n( "Export Sharp..." ) ); 84 createExportAction( i18n( "Export Sharp..." ) );
85} 85}
86 86
87bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 87bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
88{ 88{
89 // we can not choose the filename. Therefore use the default to display 89 // we can not choose the filename. Therefore use the default to display
90 QString fileName = SlZDataBase::addressbookFileName(); 90 QString fileName = SlZDataBase::addressbookFileName();
91 91
92 SlZDataBase* access = new SlZDataBase(fileName, 92 SlZDataBase* access = new SlZDataBase(fileName,
93 SlZDataBase::addressbookItems()); 93 SlZDataBase::addressbookItems());
94 94
95 if ( !access ) { 95 if ( !access ) {
96 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 96 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
97 qDebug(text.latin1()); 97 qDebug(text.latin1());
98 KMessageBox::error( parentWidget(), text ); 98 KMessageBox::error( parentWidget(), text );
99 addressBook()->error( text ); 99 addressBook()->error( text );
100 return false; 100 return false;
101 } 101 }
102 102
103// KABC::QtopiaConverter mConverter; 103 KABC::SharpDTMConverter mConverter;
104 104
105// bool res = mConverter.init(); 105 bool res = mConverter.init();
106 bool res = true;
107 if (!res) 106 if (!res)
108 { 107 {
109 QString text( i18n( "Unable to initialize sharpdtm converter.<br>Most likely a problem with the category file." ) ); 108 QString text( i18n( "Unable to initialize sharpdtm converter.<br>Most likely a problem with the category file." ) );
110 qDebug(text); 109 qDebug(text);
111 KMessageBox::error( parentWidget(), text ); 110 KMessageBox::error( parentWidget(), text );
112 delete access; 111 delete access;
113 return false; 112 return false;
114 } 113 }
115 114
116 //Now check if the file has already entries, and ask the user if he wants to delete them first. 115 //Now check if the file has already entries, and ask the user if he wants to delete them first.
117/*US 116 if (access->count() > 0)
118 { //create a new scope 117 {
119 AddressBookIterator it(*access); 118 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
120 const PimContact* firstcontact = it.toFirst(); 119 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
121 if (firstcontact) 120 // Clean the database..
122 { 121 access->deleteCard(0, SlZDataBase::AllCard );
123 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
124 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
125 // Clean the database..
126
127 AddressBookIterator it2(*access);
128 for (it2.toFirst(); it2.current(); ++it2) {
129 access->removeContact(*it2.current());
130 }
131 }
132 } 122 }
133 } 123 }
134 124
135 KABC::Addressee::List::ConstIterator it; 125 KABC::Addressee::List::ConstIterator it;
136 for ( it = list.begin(); it != list.end(); ++it ) { 126 for ( it = list.begin(); it != list.end(); ++it ) {
137 PimContact c; 127 CardId c;
138 KABC::Addressee addressee = (*it); 128 res = access->editNewCard();
139 129
140 res = mConverter.addresseeToQtopia( *it, c );
141 if (res == true) 130 if (res == true)
142 { 131 {
143 access->addContact(c); 132 res = mConverter.addresseeToSharp( *it, access, c );
144 } 133
134 if (res == true)
135 access->finishEditCard(&c);
136 else
137 access->cancelEditCard();
138 }
145 } 139 }
146*/ 140
147 delete access; 141 delete access;
148 142
149 return true; 143 return true;
150} 144}
151 145
152KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const 146KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const
153{ 147{
154 KABC::AddresseeList adrlst; 148 KABC::AddresseeList adrlst;
155 149
156 QString fileName = SlZDataBase::addressbookFileName(); 150 QString fileName = SlZDataBase::addressbookFileName();
157 151
152 // the last parameter in the SlZDataBase constructor means "readonly"
158 SlZDataBase* access = new SlZDataBase(fileName, 153 SlZDataBase* access = new SlZDataBase(fileName,
159 SlZDataBase::addressbookItems()); 154 SlZDataBase::addressbookItems(), NULL, true);
155
160 156
161
162 if ( !access ) { 157 if ( !access ) {
163 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 158 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
164 qDebug(text.latin1()); 159 qDebug(text.latin1());
165 addressBook()->error( text ); 160 addressBook()->error( text );
166 KMessageBox::error( parentWidget(), text ); 161 KMessageBox::error( parentWidget(), text );
167 return KABC::AddresseeList(); 162 return KABC::AddresseeList();
168 } 163 }
169/*US 164
170 KABC::QtopiaConverter mConverter; 165 KABC::SharpDTMConverter mConverter;
171 166
172 bool res = mConverter.init(); 167 bool res = mConverter.init();
173 if (!res) 168 if (!res)
174 { 169 {
175 QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) ); 170 QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) );
176 qDebug(text); 171 qDebug(text);
177 KMessageBox::error( parentWidget(), text ); 172 KMessageBox::error( parentWidget(), text );
178 delete access; 173 delete access;
179 return KABC::AddresseeList(); 174 return KABC::AddresseeList();
180 } 175 }
181 176
182 177
183 178 { //create a new scope
184 { //create a new scope 179 CardId id;
185 AddressBookIterator it(*access); 180
186 181 for (bool res=access->first(); res == true; res=access->next()) {
187 for (it.toFirst(); it.current(); ++it) { 182 id = access->cardId();
188 const PimContact*contact = it.current(); 183
189
190 KABC::Addressee addressee; 184 KABC::Addressee addressee;
191 185
192 res = mConverter.qtopiaToAddressee( (*contact), addressee ); 186 res = mConverter.sharpToAddressee( id, access, addressee );
193 187
194 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
195 { 189 {
196 adrlst.append( addressee ); 190 adrlst.append( addressee );
197 } 191 }
198 } 192 }
199 } 193 }
200*/ 194
201
202 delete access; 195 delete access;
203 196
204 return adrlst; 197 return adrlst;
205 198
206} 199}