summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-07-09 08:05:25 (UTC)
committer ulf69 <ulf69>2004-07-09 08:05:25 (UTC)
commit259a7a50e4f8138cedfc2004fbde3b37cedcc49f (patch) (side-by-side diff)
treedfd2e89f169ba65ffd250f9b52f8f4efcd62d8b3
parentd91c533ffc42d7bf48fa1326754894b2c30b6831 (diff)
downloadkdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.zip
kdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.tar.gz
kdepimpi-259a7a50e4f8138cedfc2004fbde3b37cedcc49f.tar.bz2
support for export of categories und supression of empty fields
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/opie/opieconverter.cpp105
-rw-r--r--kabc/converter/opie/opieconverter.h11
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp16
-rw-r--r--kaddressbook/xxport/opie/opie_xxportE.pro3
4 files changed, 96 insertions, 39 deletions
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp
index d785fbc..b4e9f1c 100644
--- a/kabc/converter/opie/opieconverter.cpp
+++ b/kabc/converter/opie/opieconverter.cpp
@@ -29,22 +29,48 @@ $Id$
#include "kglobal.h"
#include "opieconverter.h"
#include <qpe/categories.h>
+#include <qpe/categoryselect.h>
using namespace KABC;
-OpieConverter::OpieConverter()
+OpieConverter::OpieConverter() : catDB(0)
{
}
OpieConverter::~OpieConverter()
{
+ deinit();
+}
+
+bool OpieConverter::init()
+{
+ catDB = new Categories();
+ if (catDB)
+ {
+ catDB->load( categoryFileName() );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+}
+
+void OpieConverter::deinit()
+{
+ if (catDB)
+ {
+ delete catDB;
+ catDB = 0;
+ }
}
bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
{
// name
addr.setFormattedName(contact.fileAs());
@@ -58,26 +84,34 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
// email
QStringList emails = contact.emailList();
for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
}
- addr.insertEmail(contact.defaultEmail(), true);
+ if (!contact.defaultEmail().isEmpty())
+ addr.insertEmail(contact.defaultEmail(), true);
// home
- Address homeaddress;
- homeaddress.setType(Address::Home);
+ if ((!contact.homeStreet().isEmpty()) ||
+ (!contact.homeCity().isEmpty()) ||
+ (!contact.homeState().isEmpty()) ||
+ (!contact.homeZip().isEmpty()) ||
+ (!contact.homeCountry().isEmpty()))
+ {
+ Address homeaddress;
+ homeaddress.setType(Address::Home);
//US homeaddress.setPostOfficeBox( "" );
//US homeaddress.setExtended( "" );
- homeaddress.setStreet( contact.homeStreet() );
- homeaddress.setLocality( contact.homeCity() );
- homeaddress.setRegion( contact.homeState() );
- homeaddress.setPostalCode( contact.homeZip() );
- homeaddress.setCountry( contact.homeCountry() );
+ homeaddress.setStreet( contact.homeStreet() );
+ homeaddress.setLocality( contact.homeCity() );
+ homeaddress.setRegion( contact.homeState() );
+ homeaddress.setPostalCode( contact.homeZip() );
+ homeaddress.setCountry( contact.homeCountry() );
- addr.insertAddress( homeaddress );
+ addr.insertAddress( homeaddress );
+ }
if (!contact.homePhone().isEmpty())
{
PhoneNumber homephone;
homephone.setType( PhoneNumber::Home );
homephone.setNumber( contact.homePhone() );
@@ -101,24 +135,32 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
}
addr.setUrl( contact.homeWebpage() );
// business
- Address businessaddress;
- businessaddress.setType(Address::Work);
+ if ((!contact.businessStreet().isEmpty()) ||
+ (!contact.businessCity().isEmpty()) ||
+ (!contact.businessState().isEmpty()) ||
+ (!contact.businessZip().isEmpty()) ||
+ (!contact.businessCountry().isEmpty()))
+ {
+ Address businessaddress;
+ businessaddress.setType(Address::Work);
//US businessaddress.setPostOfficeBox( "" );
//US businessaddress.setExtended( "" );
- businessaddress.setStreet( contact.businessStreet() );
- businessaddress.setLocality( contact.businessCity() );
- businessaddress.setRegion( contact.businessState() );
- businessaddress.setPostalCode( contact.businessZip() );
- businessaddress.setCountry( contact.businessCountry() );
+ businessaddress.setStreet( contact.businessStreet() );
+ businessaddress.setLocality( contact.businessCity() );
+ businessaddress.setRegion( contact.businessState() );
+ businessaddress.setPostalCode( contact.businessZip() );
+ businessaddress.setCountry( contact.businessCountry() );
+
+ addr.insertAddress( businessaddress );
+ }
+
- addr.insertAddress( businessaddress );
-
if (!contact.businessPhone().isEmpty())
{
PhoneNumber businessphone;
businessphone.setType( PhoneNumber::Work );
businessphone.setNumber( contact.businessPhone() );
addr.insertPhoneNumber( businessphone );
@@ -158,18 +200,15 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
//personal
addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() );
if (contact.anniversary().isValid()) {
- int orgformat = KGlobal::locale()->getIntDateFormat();
- KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate
- QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true);
+ QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
//US
qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1());
- KGlobal::locale()->setIntDateFormat(orgformat );
addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
}
addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
if (contact.birthday().isValid())
addr.setBirthday( contact.birthday() );
@@ -187,15 +226,15 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
//US QString groups() const { return find( Qtopia::Groups ); }
//US QStringList groupList() const;
QStringList cats = contact.categoryNames("Contacts");
- for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
- qDebug("Cat: %s", (*it).latin1());
- }
+// for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
+// qDebug("Cat: %s", (*it).latin1());
+// }
addr.setCategories( contact.categoryNames("Contacts") );
// qDebug("Groups: %s", contact.groups().latin1());
// addr.setCategories( contact.groupList() );
@@ -320,19 +359,17 @@ bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact )
cat[counter] = (*it).toInt();
contact.setCategories( cat );
*/
Categories catDB;
- catDB.dump();
-//US catDB.load( contact.categoryFileName() );
- catDB.load( "contact" );
-
+ catDB.load( categoryFileName() );
QStringList cats = addr.categories();
- for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
- qDebug("categories: %s", (*it).latin1());
-// contact.setCategories(catDB.id(*it));
- }
+ QArray<int> iar;
+ if ( !cats.isEmpty() ) {
+ QArray<int> iar = catDB.ids("contact", cats);
+ contact.setCategories(iar);
+ }
return true;
}
diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h
index ef7300b..7d2ad85 100644
--- a/kabc/converter/opie/opieconverter.h
+++ b/kabc/converter/opie/opieconverter.h
@@ -30,12 +30,14 @@ $Id$
#include <qstring.h>
#include "addressee.h"
#include <opie/ocontact.h>
+class Categories;
+
namespace KABC {
class OpieConverter
{
public:
@@ -44,13 +46,16 @@ public:
*/
OpieConverter();
/**
* Destructor.
*/
- ~OpieConverter();
+ virtual ~OpieConverter();
+
+ virtual bool init();
+ virtual void deinit();
/**
* Converts a vcard string to an addressee.
*
* @param contact The opie contact.
* @param addr The addressee.
@@ -61,11 +66,15 @@ public:
* Converts an addressee to a vcard string.
*
* @param addr The addressee.
* @param contact The opie contact.
*/
bool addresseeToOpie( const Addressee &addr, OContact &contact );
+
+ private:
+ Categories* catDB;
+
};
}
#endif
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
index d1def18..8ee0725 100644
--- a/kaddressbook/xxport/opie/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -104,25 +104,35 @@ bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString
if ( !access ) {
qDebug("Unable to access file() %s", fileName.latin1());
addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
return false;
}
+ KABC::OpieConverter mConverter;
+
+ bool res = mConverter.init();
+ if (!res)
+ {
+ QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
+ qDebug(text);
+ KMessageBox::error( parentWidget(), text );
+ delete access;
+ return false;
+ }
+
//Now check if the file has already entries, and ask the user if he wants to delete them first.
OContactAccess::List contactList = access->allRecords();
if (contactList.count() > 0)
{
QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
// Clean the database..
access->clear();
}
}
-
- KABC::OpieConverter mConverter;
- bool res;
+
KABC::Addressee::List::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
OContact c;
KABC::Addressee addressee = (*it);
diff --git a/kaddressbook/xxport/opie/opie_xxportE.pro b/kaddressbook/xxport/opie/opie_xxportE.pro
index a660a48..c373e37 100644
--- a/kaddressbook/xxport/opie/opie_xxportE.pro
+++ b/kaddressbook/xxport/opie/opie_xxportE.pro
@@ -5,14 +5,15 @@ TARGET = kaddrbk_opie_xxport
OBJECTS_DIR = obj/$(PLATFORM)
MOC_DIR = moc/$(PLATFORM)
DESTDIR = $(QPEDIR)/lib
DEFINES += KAB_EMBEDDED
-INCLUDEPATH += ../.. ../../.. ../../../kabc ../../../kabc/converter/opie ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include
+INCLUDEPATH += ../.. ../../.. ../../../kabc ../../../kabc/converter/opie ../../../microkde ../../../microkde/kdeui ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(OPIEDIR)/include
LIBS += -L$(QPEDIR)/lib
+LIBS += -L$(OPIEDIR)/lib
LIBS += -lmicrokde
LIBS += -lmicrokabc
LIBS += -lopie
LIBS += -lqpe
LIBS += -lqte
LIBS += -lmicrokabc_opieconverter