kfile_vcf.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include "kfile_vcf.h"
00022
00023 #include <kprocess.h>
00024 #include <klocale.h>
00025 #include <kgenericfactory.h>
00026 #include <kstringvalidator.h>
00027 #include <kdebug.h>
00028
00029 #include <qdict.h>
00030 #include <qvalidator.h>
00031 #include <qcstring.h>
00032 #include <qfile.h>
00033 #include <qdatetime.h>
00034
00035 #if !defined(__osf__)
00036 #include <inttypes.h>
00037 #else
00038 typedef unsigned short uint32_t;
00039 #endif
00040
00041 typedef KGenericFactory<KVcfPlugin> VcfFactory;
00042
00043 K_EXPORT_COMPONENT_FACTORY(kfile_vcf, VcfFactory( "kfile_vcf" ))
00044
00045 KVcfPlugin::KVcfPlugin(QObject *parent, const char *name,
00046 const QStringList &args)
00047
00048 : KFilePlugin(parent, name, args)
00049 {
00050 KFileMimeTypeInfo* info = addMimeTypeInfo( "text/x-vcard" );
00051
00052 KFileMimeTypeInfo::GroupInfo* group = 0L;
00053
00054 group = addGroupInfo(info, "Technical", i18n("Technical Details"));
00055
00056 KFileMimeTypeInfo::ItemInfo* item;
00057
00058 item = addItemInfo(group, "Name", i18n("Name"), QVariant::String);
00059 item = addItemInfo(group, "Email", i18n("Email"), QVariant::String);
00060 item = addItemInfo(group, "Telephone", i18n("Telephone"), QVariant::String);
00061
00062 }
00063
00064
00065 bool KVcfPlugin::readInfo( KFileMetaInfo& info, uint )
00066 {
00067
00068 QFile file(info.path());
00069
00070 if (!file.open(IO_ReadOnly))
00071 {
00072 kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl;
00073 return false;
00074 }
00075
00076 char id_name[] = "FN:";
00077 char id_email[] = "EMAIL;INTERNET:";
00078
00079
00080 char linebuf[1000];
00081
00082
00083 char buf_name[1000] = "";
00084 char buf_email[1000] = "";
00085 buf_name[999] = '\0';
00086 buf_email[999] = '\0';
00087 char * myptr;
00088
00089 bool done=false;
00090 while (!done) {
00091
00092
00093 int r = file.readLine(linebuf, sizeof( linebuf ));
00094
00095 if ( r < 0 ) {
00096 done = true;
00097 break;
00098 }
00099
00100
00101 if (memcmp(linebuf, id_name, 3) == 0) {
00102
00103 myptr = linebuf + 3;
00104 strlcpy(buf_name, myptr, sizeof( buf_name ));
00105 } else if (memcmp(linebuf, id_email, 15) == 0) {
00106
00107 myptr = linebuf + 15;
00108 strlcpy(buf_email, myptr, sizeof( buf_email ));
00109 }
00110
00111
00112 if (
00113 ((strlen(buf_name) > 0) && (strlen(buf_email) > 0)) ||
00114 (file.atEnd())
00115 )
00116 done = true;
00117
00118 };
00119
00120
00121 KFileMetaInfoGroup group = appendGroup(info, "Technical");
00122
00123 if (strlen(buf_name) > 0)
00124 appendItem(group, "Name", buf_name);
00125
00126 if (strlen(buf_email) > 0)
00127 appendItem(group, "Email", buf_email);
00128
00129 return true;
00130 }
00131
00132 #include "kfile_vcf.moc"
This file is part of the documentation for kfile-plugins Library Version 3.2.2.