summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-30 22:12:32 (UTC)
committer ulf69 <ulf69>2004-06-30 22:12:32 (UTC)
commit34c8059a5400d4a13456a5b4cb90328369999f20 (patch) (unidiff)
tree694e9a6b7814522ddec59b52cbaad3fe5690afea
parentbd79f5a89b0d1071ef9ad749fe3a8096bbc25b0b (diff)
downloadkdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.zip
kdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.tar.gz
kdepimpi-34c8059a5400d4a13456a5b4cb90328369999f20.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/converter.pro4
-rw-r--r--kabc/converter/opie/opieconverter.cpp196
-rw-r--r--kabc/converter/opie/opieconverter.h74
-rw-r--r--kabc/converter/opie/opieconverterE.pro31
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp196
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.h51
-rw-r--r--kaddressbook/xxport/opie/opie_xxportE.pro27
7 files changed, 579 insertions, 0 deletions
diff --git a/kabc/converter/converter.pro b/kabc/converter/converter.pro
new file mode 100644
index 0000000..0f44d2e
--- a/dev/null
+++ b/kabc/converter/converter.pro
@@ -0,0 +1,4 @@
1
2
3TEMPLATE = subdirs
4SUBDIRS = opie
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp
new file mode 100644
index 0000000..fbb5817
--- a/dev/null
+++ b/kabc/converter/opie/opieconverter.cpp
@@ -0,0 +1,196 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28//US
29#include "kglobal.h"
30
31
32#include "opieconverter.h"
33
34using namespace KABC;
35
36OpieConverter::OpieConverter()
37{
38}
39
40OpieConverter::~OpieConverter()
41{
42}
43
44bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
45{
46 // name
47//US QString fileAs() const { return find( Qtopia::FileAs ); }
48
49 addr.setFamilyName( contact.lastName() );
50 addr.setGivenName( contact.firstName() );
51 addr.setAdditionalName( contact.middleName() );
52 addr.setPrefix( contact.title() );
53 addr.setSuffix( contact.suffix() );
54
55
56 // email
57 QStringList emails = contact.emailList();
58 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
59 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
60 }
61
62 // home
63 Address homeaddress;
64 homeaddress.setType(Address::Home);
65//US homeaddress.setPostOfficeBox( "" );
66//US homeaddress.setExtended( "" );
67 homeaddress.setStreet( contact.homeStreet() );
68 homeaddress.setLocality( contact.homeCity() );
69 homeaddress.setRegion( contact.homeState() );
70 homeaddress.setPostalCode( contact.homeZip() );
71 homeaddress.setCountry( contact.homeCountry() );
72
73 addr.insertAddress( homeaddress );
74
75 if (!contact.homePhone().isEmpty())
76 {
77 PhoneNumber homephone;
78 homephone.setType( PhoneNumber::Home );
79 homephone.setNumber( contact.homePhone() );
80 addr.insertPhoneNumber( homephone );
81 }
82
83 if (!contact.homeFax().isEmpty())
84 {
85 PhoneNumber homefax;
86 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
87 homefax.setNumber( contact.homeFax() );
88 addr.insertPhoneNumber( homefax );
89 }
90
91 if (!contact.homeMobile().isEmpty())
92 {
93 PhoneNumber homemobile;
94 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
95 homemobile.setNumber( contact.homeMobile() );
96 addr.insertPhoneNumber( homemobile );
97 }
98
99 addr.setUrl( contact.homeWebpage() );
100
101
102 // business
103 Address businessaddress;
104 businessaddress.setType(Address::Work);
105//US businessaddress.setPostOfficeBox( "" );
106//US businessaddress.setExtended( "" );
107 businessaddress.setStreet( contact.businessStreet() );
108 businessaddress.setLocality( contact.businessCity() );
109 businessaddress.setRegion( contact.businessState() );
110 businessaddress.setPostalCode( contact.businessZip() );
111 businessaddress.setCountry( contact.businessCountry() );
112
113 addr.insertAddress( businessaddress );
114
115 if (!contact.businessPhone().isEmpty())
116 {
117 PhoneNumber businessphone;
118 businessphone.setType( PhoneNumber::Work );
119 businessphone.setNumber( contact.businessPhone() );
120 addr.insertPhoneNumber( businessphone );
121 }
122
123 if (!contact.businessFax().isEmpty())
124 {
125 PhoneNumber businessfax;
126 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
127 businessfax.setNumber( contact.businessFax() );
128 addr.insertPhoneNumber( businessfax );
129 }
130
131 if (!contact.businessMobile().isEmpty())
132 {
133 PhoneNumber businessmobile;
134 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
135 businessmobile.setNumber( contact.businessMobile() );
136 addr.insertPhoneNumber( businessmobile );
137 }
138
139 if (!contact.businessPager().isEmpty())
140 {
141 PhoneNumber businesspager;
142 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
143 businesspager.setNumber( contact.businessPager() );
144 addr.insertPhoneNumber( businesspager );
145 }
146
147 addr.setRole( contact.jobTitle() ); //?
148 addr.setOrganization( contact.company() );
149 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
150 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
151 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
152 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
153 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
154
155//???
156//US QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
157
158 //personal
159 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
160 addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() );
161 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dateToAddresseeString(contact.anniversary()) );
162 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
163 addr.setBirthday( contact.birthday() );
164 addr.setNickName( contact.nickname() );
165
166 // other
167 addr.setNote( contact.notes() );
168
169//US QString groups() const { return find( Qtopia::Groups ); }
170//US QStringList groupList() const;
171
172/*US
173 QStringList cats = contact.categoryNames("Contacts");
174 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
175 qDebug("Cat: %s", (*it).latin1());
176 }
177*/
178 addr.setCategories( contact.categoryNames("Contacts") );
179// qDebug("Groups: %s", contact.groups().latin1());
180// addr.setCategories( contact.groupList() );
181
182
183 return true;
184}
185
186bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact )
187{
188 return false;
189}
190
191QString OpieConverter::dateToAddresseeString( const QDate &date )
192{
193 return KGlobal::locale()->formatDate(date, true);
194//US return date.toString("yyyyMMdd");
195}
196
diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h
new file mode 100644
index 0000000..55a869a
--- a/dev/null
+++ b/kabc/converter/opie/opieconverter.h
@@ -0,0 +1,74 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_OPIECONVERTER_H
29#define KABC_OPIECONVERTER_H
30
31#include <qstring.h>
32
33#include "addressee.h"
34#include <opie/ocontact.h>
35
36namespace KABC {
37
38class OpieConverter
39{
40public:
41
42 /**
43 * Constructor.
44 */
45 OpieConverter();
46
47 /**
48 * Destructor.
49 */
50 ~OpieConverter();
51
52 /**
53 * Converts a vcard string to an addressee.
54 *
55 * @param contact The opie contact.
56 * @param addr The addressee.
57 */
58 bool opieToAddressee( OContact &contact, Addressee &addr );
59
60 /**
61 * Converts an addressee to a vcard string.
62 *
63 * @param addr The addressee.
64 * @param contact The opie contact.
65 */
66 bool addresseeToOpie( const Addressee &addr, OContact &contact );
67
68 private:
69 QString dateToAddresseeString( const QDate &date );
70
71};
72
73}
74#endif
diff --git a/kabc/converter/opie/opieconverterE.pro b/kabc/converter/opie/opieconverterE.pro
new file mode 100644
index 0000000..314bb1e
--- a/dev/null
+++ b/kabc/converter/opie/opieconverterE.pro
@@ -0,0 +1,31 @@
1TEMPLATE = lib
2INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(QPEDIR)/include
3#CONFIG += staticlib
4OBJECTS_DIR = obj/$(PLATFORM)
5MOC_DIR = moc/$(PLATFORM)
6
7#for static linkage, put it here
8#DESTDIR=../../lib/$(PLATFORM)
9
10#for dynamic linkage, put it here
11DESTDIR=$(QPEDIR)/lib
12
13LIBS += -lmicrokde
14LIBS += -lmicrokabc
15LIBS += -L$(QPEDIR)/lib
16LIBS += -lopie
17LIBS += -lqpe
18LIBS += -lqte
19
20
21TARGET = microkabc_opieconverter
22
23# Input
24
25HEADERS += \
26 opieconverter.h \
27
28
29SOURCES += \
30 opieconverter.cpp \
31
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
new file mode 100644
index 0000000..616eec1
--- a/dev/null
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -0,0 +1,196 @@
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#include <opie/ocontactaccess.h>
37#include "stdaddressbook.h"
38
39/*US
40#include <qfile.h>
41#include <qtextstream.h>
42
43#include <kabc/vcardconverter.h>
44#ifndef KAB_EMBEDDED
45#include <kio/netaccess.h>
46#endif //KAB_EMBEDDED
47
48#include <klocale.h>
49#include <kmessagebox.h>
50#include <ktempfile.h>
51#include <kurl.h>
52*/
53
54#include "xxportmanager.h"
55#include "opieconverter.h"
56
57#include "opie_xxport.h"
58
59
60class OpieXXPortFactory : public XXPortFactory
61{
62 public:
63 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
64 {
65 return new OpieXXPort( ab, parent, name );
66 }
67};
68
69
70extern "C"
71{
72 void *init_kaddrbk_opie_xxport()
73 {
74 return ( new OpieXXPortFactory() );
75 }
76}
77
78
79OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
80 : XXPortObject( ab, parent, name )
81{
82 createImportAction( i18n( "Import Opie..." ) );
83 createExportAction( i18n( "Export Opie..." ) );
84}
85
86bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
87{
88 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
89
90#ifndef KAB_EMBEDDED
91 QString fileName = KFileDialog::getSaveFileName( name );
92#else //KAB_EMBEDDED
93 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
94#endif //KAB_EMBEDDED
95
96 if ( fileName.isEmpty() )
97 return true;
98
99 OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false);
100
101 if ( !access ) {
102 qDebug("Unable to access file() %s", fileName.latin1());
103 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
104 return false;
105 }
106
107 //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();
109 if (contactList.count() > 0)
110 {
111 QString text( i18n( "<qt>Do you want to remove all existing entries from <b>%1</b> before exporting.?</qt>" ) );
112 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
113 // Clean the database..
114 access->clear();
115 }
116 }
117
118 KABC::OpieConverter mConverter;
119 bool res;
120
121 KABC::Addressee::List::ConstIterator it;
122 for ( it = list.begin(); it != list.end(); ++it ) {
123 OContact c;
124 KABC::Addressee addressee = (*it);
125
126 res = mConverter.addresseeToOpie( *it, c );
127 if (res == true)
128 {
129 res = access->add(c);
130 if (res == false)
131 qDebug("Unable to append Contact %s", c.fullName().latin1());
132 }
133 else
134 {
135 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
136 }
137 }
138
139 access->save();
140
141 delete access;
142
143 return true;
144}
145
146KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
147{
148 KABC::AddresseeList adrlst;
149
150 QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
151
152#ifndef KAB_EMBEDDED
153 QString fileName = KFileDialog::getOpenFileName( name );
154#else //KAB_EMBEDDED
155 QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() );
156#endif //KAB_EMBEDDED
157
158 if ( fileName.isEmpty() )
159 return KABC::AddresseeList();
160
161 OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false);
162
163 if ( !access ) {
164 qDebug("Unable to access file() %s", fileName.latin1());
165 addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
166 return KABC::AddresseeList();
167 }
168
169 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
170
171 KABC::OpieConverter mConverter;
172 bool res = false;
173
174
175 OContactAccess::List::Iterator it;
176 OContactAccess::List allList = access->allRecords();
177 for ( it = allList.begin(); it != allList.end(); ++it )
178 {
179 OContact c = (*it);
180
181 KABC::Addressee addressee;
182
183 res = mConverter.opieToAddressee( c, addressee );
184
185 if ( !addressee.isEmpty() && res ) {
186 adrlst.append( addressee );
187 }
188
189// qDebug("found %s", c.fullName().latin1());
190 }
191
192 delete access;
193
194 return adrlst;
195
196}
diff --git a/kaddressbook/xxport/opie/opie_xxport.h b/kaddressbook/xxport/opie/opie_xxport.h
new file mode 100644
index 0000000..d6aa776
--- a/dev/null
+++ b/kaddressbook/xxport/opie/opie_xxport.h
@@ -0,0 +1,51 @@
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
36class OpieXXPort : public XXPortObject
37{
38 Q_OBJECT
39
40 public:
41 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42
43 QString identifier() const { return "opie"; }
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
51#endif
diff --git a/kaddressbook/xxport/opie/opie_xxportE.pro b/kaddressbook/xxport/opie/opie_xxportE.pro
new file mode 100644
index 0000000..a660a48
--- a/dev/null
+++ b/kaddressbook/xxport/opie/opie_xxportE.pro
@@ -0,0 +1,27 @@
1TEMPLATE = lib
2CONFIG += qt warn_on
3TARGET = kaddrbk_opie_xxport
4
5OBJECTS_DIR = obj/$(PLATFORM)
6MOC_DIR = moc/$(PLATFORM)
7DESTDIR = $(QPEDIR)/lib
8
9DEFINES += KAB_EMBEDDED
10
11INCLUDEPATH += ../.. ../../.. ../../../kabc ../../../kabc/converter/opie ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include
12LIBS += -L$(QPEDIR)/lib
13LIBS += -lmicrokde
14LIBS += -lmicrokabc
15LIBS += -lopie
16LIBS += -lqpe
17LIBS += -lqte
18LIBS += -lmicrokabc_opieconverter
19
20INTERFACES = \
21
22HEADERS = \
23 opie_xxport.h \
24
25SOURCES = \
26 opie_xxport.cpp \
27