diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-27 01:05:15 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-27 01:05:15 -0600 |
commit | 64df902cf71a8ee258fb85f6be26248f399aa01f (patch) | |
tree | dba58f705042c22cea26b678d5b0e4e9a34bf202 /tdefile-plugins/vcf/tdefile_vcf.cpp | |
parent | de53c98cab07e9c4b0f5e25dab82830fb6fc67ec (diff) | |
download | tdepim-64df902cf71a8ee258fb85f6be26248f399aa01f.tar.gz tdepim-64df902cf71a8ee258fb85f6be26248f399aa01f.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tdefile-plugins/vcf/tdefile_vcf.cpp')
-rw-r--r-- | tdefile-plugins/vcf/tdefile_vcf.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/tdefile-plugins/vcf/tdefile_vcf.cpp b/tdefile-plugins/vcf/tdefile_vcf.cpp new file mode 100644 index 000000000..e8746c56a --- /dev/null +++ b/tdefile-plugins/vcf/tdefile_vcf.cpp @@ -0,0 +1,103 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <kdebug.h> +#include <config.h> +#include "tdefile_vcf.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kabc/vcardconverter.h> + +#include <tqdict.h> +#include <tqfile.h> + +typedef KGenericFactory<KVcfPlugin> VcfFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_vcf, VcfFactory( "tdefile_vcf" )) + +KVcfPlugin::KVcfPlugin(TQObject *parent, const char *name, + const TQStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "text/x-vcard" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Name", i18n("Name"), TQVariant::String); + item = addItemInfo(group, "Email", i18n("Email"), TQVariant::String); + item = addItemInfo(group, "Telephone", i18n("Telephone"), TQVariant::String); +} + + +bool KVcfPlugin::readInfo( KFileMetaInfo& info, uint /*what*/ ) +{ + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << TQString(TQFile::encodeName(info.path())) << endl; + return false; + } + + // even the vcard thumbnail TQString::fromUtf8(buf_name));creator reads the full file ... + // The following is partly copied from there + TQString contents = file.readAll(); + file.close(); + + KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + KABC::Addressee addr = converter.parseVCardRaw( contents.utf8() ); +#else + KABC::Addressee addr = converter.parseVCard( contents ); +#endif + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + + // prepare the text + TQString name = addr.formattedName().simplifyWhiteSpace(); + if ( name.isEmpty() ) + name = addr.givenName() + " " + addr.familyName(); + name = name.simplifyWhiteSpace(); + + if ( ! name.isEmpty() ) + appendItem(group, "Name", name); + + if ( ! addr.preferredEmail().isEmpty() ) + appendItem(group, "Email", addr.preferredEmail()); + + KABC::PhoneNumber::List pnList = addr.phoneNumbers(); + TQStringList phoneNumbers; + for (unsigned int no=0; no<pnList.count(); ++no) { + TQString pn = pnList[no].number().simplifyWhiteSpace(); + if (!pn.isEmpty() && !phoneNumbers.contains(pn)) + phoneNumbers.append(pn); + } + if ( !phoneNumbers.isEmpty() ) + appendItem(group, "Telephone", phoneNumbers.join("\n")); + + return true; +} + +#include "tdefile_vcf.moc" |