diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kfile-plugins/vcf | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfile-plugins/vcf')
-rw-r--r-- | kfile-plugins/vcf/Makefile.am | 22 | ||||
-rw-r--r-- | kfile-plugins/vcf/kfile_vcf.cpp | 100 | ||||
-rw-r--r-- | kfile-plugins/vcf/kfile_vcf.desktop | 66 | ||||
-rw-r--r-- | kfile-plugins/vcf/kfile_vcf.h | 37 |
4 files changed, 225 insertions, 0 deletions
diff --git a/kfile-plugins/vcf/Makefile.am b/kfile-plugins/vcf/Makefile.am new file mode 100644 index 000000000..5350fb1c1 --- /dev/null +++ b/kfile-plugins/vcf/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for vcf file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_vcf.h + +kde_module_LTLIBRARIES = kfile_vcf.la + +kfile_vcf_la_SOURCES = kfile_vcf.cpp +kfile_vcf_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_vcf_la_LIBADD = $(LIB_KSYCOCA) $(LIB_KABC) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) kfile_vcf.cpp -o $(podir)/kfile_vcf.pot + +services_DATA = kfile_vcf.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/vcf/kfile_vcf.cpp b/kfile-plugins/vcf/kfile_vcf.cpp new file mode 100644 index 000000000..f9440f6d1 --- /dev/null +++ b/kfile-plugins/vcf/kfile_vcf.cpp @@ -0,0 +1,100 @@ +/* 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 "kfile_vcf.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kabc/vcardconverter.h> + +#include <qdict.h> +#include <qfile.h> + +typedef KGenericFactory<KVcfPlugin> VcfFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_vcf, VcfFactory( "kfile_vcf" )) + +KVcfPlugin::KVcfPlugin(QObject *parent, const char *name, + const QStringList &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"), QVariant::String); + item = addItemInfo(group, "Email", i18n("Email"), QVariant::String); + item = addItemInfo(group, "Telephone", i18n("Telephone"), QVariant::String); +} + + +bool KVcfPlugin::readInfo( KFileMetaInfo& info, uint /*what*/ ) +{ + QFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl; + return false; + } + + // even the vcard thumbnail QString::fromUtf8(buf_name));creator reads the full file ... + // The following is partly copied from there + QString contents = file.readAll(); + file.close(); + + KABC::VCardConverter converter; + KABC::Addressee addr = converter.parseVCard(contents); + + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + + // prepare the text + QString 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(); + QStringList phoneNumbers; + for (unsigned int no=0; no<pnList.count(); ++no) { + QString 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 "kfile_vcf.moc" diff --git a/kfile-plugins/vcf/kfile_vcf.desktop b/kfile-plugins/vcf/kfile_vcf.desktop new file mode 100644 index 000000000..ced0dfc34 --- /dev/null +++ b/kfile-plugins/vcf/kfile_vcf.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +Type=Service +Name=vCard Info +Name[af]=Vkaart Inligting +Name[be]=Інфармацыя аб vCard +Name[bg]=Информация за vCard +Name[br]=Titouroù diwar-benn vCard +Name[ca]=Informació de vCard +Name[cs]=VCard info +Name[cy]=Gwybodaeth vCard +Name[da]=VCard-info +Name[de]=vCard-Info +Name[el]=Πληροφορίες vCard +Name[eo]=vCard-informo +Name[es]=Info de vCard +Name[et]=vCardi info +Name[eu]=vCard informazioa +Name[fa]=اطلاعات vCard +Name[fi]=vCard-tiedot +Name[fr]=Informations vCard +Name[fy]=vCard-ynformaasje +Name[gl]=Información de vCard +Name[he]=מידע vCard +Name[hi]=वी-कार्ड जानकारी +Name[hu]=VCard-jellemzők +Name[is]=vCard upplýsingar +Name[it]=Informazioni vCard +Name[ja]=vCard 情報 +Name[ka]=vCard ინფორმაცია +Name[kk]=vCard мәліметі +Name[km]=ព័ត៌មាន vCard +Name[lt]=vCard informacija +Name[mk]=Информации за vCard +Name[ms]=Info vCard +Name[mt]=Informazzjoni vCard +Name[nb]=vCard info +Name[nds]=vCard-Informatschonen +Name[ne]=भी कार्ड सुचना +Name[nl]=vCard-informatie +Name[nn]=vCard-info +Name[nso]=Tshedimoso ya vKarata +Name[pa]=vCard ਜਾਣਕਾਰੀ +Name[pl]=Informacja vCard +Name[pt]=Informação do vCard +Name[pt_BR]=Informações sobre vCard +Name[ro]=Informaţii vCard +Name[ru]=Сведения о визитке vCard +Name[se]=vCard-dieđut +Name[sl]=Informacije o vCard +Name[sr]=vCard информације +Name[sr@Latn]=vCard informacije +Name[sv]=vCard-information +Name[ta]=விஅட்டை தகவல் +Name[tg]=Иттилоот дар бораи визиткаи vCard +Name[tr]=VCard Bilgisi +Name[uk]=Інформація про vCard +Name[ven]=Mafhungo a vCard +Name[xh]=Inkcukacha ye vCard +Name[zh_CN]=vCard 信息 +Name[zh_TW]=vCard 資訊 +Name[zu]=Ulwazi lwe-vCard +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_vcf +MimeType=text/x-vcard +PreferredGroups=Technical +PreferredItems=Name,Email,Telephone diff --git a/kfile-plugins/vcf/kfile_vcf.h b/kfile-plugins/vcf/kfile_vcf.h new file mode 100644 index 000000000..a0b147c63 --- /dev/null +++ b/kfile-plugins/vcf/kfile_vcf.h @@ -0,0 +1,37 @@ +/* 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. + * + */ + +#ifndef __KFILE_VCF_H__ +#define __KFILE_VCF_H__ + +#include <kfilemetainfo.h> + +class QStringList; + +class KVcfPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KVcfPlugin( QObject *parent, const char *name, const QStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif |