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 | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /kfile-plugins | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.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/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfile-plugins')
38 files changed, 2545 insertions, 0 deletions
diff --git a/kfile-plugins/Makefile.am b/kfile-plugins/Makefile.am new file mode 100644 index 0000000..23348fb --- /dev/null +++ b/kfile-plugins/Makefile.am @@ -0,0 +1,5 @@ +if include_kfileplugin_cert_SUBDIR +CERT_SUBDIR=cert +endif + +SUBDIRS=txt html desktop folder lnk $(CERT_SUBDIR) mhtml diff --git a/kfile-plugins/RETURNED_ITEMS b/kfile-plugins/RETURNED_ITEMS new file mode 100644 index 0000000..245dbff --- /dev/null +++ b/kfile-plugins/RETURNED_ITEMS @@ -0,0 +1,28 @@ +If you make a new plugin, please add the list of returned items to this list. + +kfile_txt +========= +int Characters +int Words +int Lines +QString Format (Unix/DOS/Macintosh) + +kfile_folder +============ +int items +QString size (as a string to display bytes, kB, MB, etc) + +kfile_lnk +============ +int Size of target +QString Location +QString Points to +QString Description + +kfile_mhtml +=========== +QString Sender +QString Recipient +QString CopyTo (The CC: field) +QString Subject +QString Date diff --git a/kfile-plugins/cert/Makefile.am b/kfile-plugins/cert/Makefile.am new file mode 100644 index 0000000..0c8c1be --- /dev/null +++ b/kfile-plugins/cert/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for cert 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_cert.h + +kde_module_LTLIBRARIES = kfile_cert.la + +kfile_cert_la_SOURCES = kfile_cert.cpp +kfile_cert_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_cert_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) kfile_cert.cpp -o $(podir)/kfile_cert.pot + +services_DATA = kfile_cert.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/cert/configure.in.in b/kfile-plugins/cert/configure.in.in new file mode 100644 index 0000000..29f0193 --- /dev/null +++ b/kfile-plugins/cert/configure.in.in @@ -0,0 +1,2 @@ +KDE_CHECK_SSL +AM_CONDITIONAL(include_kfileplugin_cert_SUBDIR, test "$have_ssl" = yes) diff --git a/kfile-plugins/cert/kfile_cert.cpp b/kfile-plugins/cert/kfile_cert.cpp new file mode 100644 index 0000000..78c20f5 --- /dev/null +++ b/kfile-plugins/cert/kfile_cert.cpp @@ -0,0 +1,161 @@ +/*************************************************************************** + * Copyright (C) 2004 by Leonid Zeitlin * + * lz@europe.com * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <config.h> +#include "kfile_cert.h" + +#include <kgenericfactory.h> +#include <ksslcertificate.h> +#include <ksslx509map.h> +#include <kopenssl.h> +//#include <kstandarddirs.h> +//#include <kdebug.h> +//#include <kio/global.h> + +#include <qdatetime.h> +#include <qfile.h> +#include <qcstring.h> +//#include <qfileinfo.h> +//#include <qdir.h> + +typedef KGenericFactory<CertPlugin> CertFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_cert, CertFactory("kfile-cert")) + +CertPlugin::CertPlugin(QObject *parent, const char *name, const QStringList &args) + : KFilePlugin(parent, name, args) +{ + //add the mimetype here - example: + //KFileMimeTypeInfo* info = addMimeTypeInfo( "text/html" ); + KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-x509-ca-cert" ); + + // our new group + KFileMimeTypeInfo::GroupInfo* group = 0L; + KFileMimeTypeInfo::ItemInfo* item; + + group = addGroupInfo(info, "certInfo", i18n("Certificate Information")); + item = addItemInfo(group, "ValidFrom", i18n("Valid From"), QVariant::DateTime); + item = addItemInfo(group, "ValidUntil", i18n("Valid Until"), QVariant::DateTime); + item = addItemInfo(group, "State", i18n("State"), QVariant::String); + item = addItemInfo(group, "SerialNo", i18n("Serial Number"), QVariant::String); + + group = addGroupInfo(info, "certSubjectInfo", i18n("Subject")); + item = addItemInfo(group, "O", i18n("Organization"), QVariant::String); + item = addItemInfo(group, "OU", i18n("Organizational Unit"), QVariant::String); + item = addItemInfo(group, "L", i18n("Locality"), QVariant::String); + item = addItemInfo(group, "C", i18n("Country"), QVariant::String); + item = addItemInfo(group, "CN", i18n("Common Name"), QVariant::String); + item = addItemInfo(group, "E", i18n("Email"), QVariant::String); + + group = addGroupInfo(info, "certIssuerInfo", i18n("Issuer")); + item = addItemInfo(group, "O", i18n("Organization"), QVariant::String); + item = addItemInfo(group, "OU", i18n("Organizational Unit"), QVariant::String); + item = addItemInfo(group, "L", i18n("Locality"), QVariant::String); + item = addItemInfo(group, "C", i18n("Country"), QVariant::String); + item = addItemInfo(group, "CN", i18n("Common Name"), QVariant::String); + item = addItemInfo(group, "E", i18n("Email"), QVariant::String); + + //setUnit(item, KFileMimeTypeInfo::KiloBytes); + + // strings are possible, too: + //addItemInfo(group, "Text", i18n("Document Type"), QVariant::String); +} + +void CertPlugin::appendDNItems(KFileMetaInfoGroup &group, const QString &DN) +{ + KSSLX509Map map(DN); + QString value; + //QString dbg; + QStringList keys = group.supportedKeys(); + QStringList::ConstIterator end = keys.end(); + for (QStringList::ConstIterator it = keys.begin(); it != end; ++it) { + value = map.getValue(*it); + //dbg += *it + " = " + value + "; "; + if (!value.isNull()) appendItem(group, *it, value); + //appendItem(group, "CN", dbg); + } +} + +static KSSLCertificate *readCertFromFile(const QString &path) +{ + KSSLCertificate *ret = NULL; + + QFile file(path); + if (!file.open(IO_ReadOnly)) return NULL; + QByteArray file_data = file.readAll(); + file.close(); + + QCString file_string = QCString(file_data.data(), file_data.size()); + // try as is: + ret = KSSLCertificate::fromString(file_string); + if (ret) return ret; + // didn't work. Let's see if begin/end lines are there: + KOSSL::self()->ERR_clear_error(); + const char *begin_line = "-----BEGIN CERTIFICATE-----\n"; + const char *end_line = "\n-----END CERTIFICATE-----"; + int begin_pos = file_string.find(begin_line); + if (begin_pos >= 0) { + begin_pos += strlen(begin_line); + int end_pos = file_string.find(end_line, begin_pos); + if (end_pos >= 0) { + // read the data between begin and end lines + QCString body = file_string.mid(begin_pos, end_pos - begin_pos); + ret = KSSLCertificate::fromString(body); + return ret; // even if it's NULL, we can't help it + } + } + // still didn't work. Assume the file was in DER (binary) encoding + unsigned char *p = (unsigned char*) file_data.data(); + KOSSL::self()->ERR_clear_error(); + X509 *x = KOSSL::self()->d2i_X509(NULL, &p, file_data.size()); + if (x) { + ret = KSSLCertificate::fromX509(x); + KOSSL::self()->X509_free(x); + return ret; + } + else return NULL; +} + +bool CertPlugin::readInfo(KFileMetaInfo& info, uint /*what*/) +{ + KSSLCertificate *cert = readCertFromFile(info.path()); + if (cert) { + KFileMetaInfoGroup group = appendGroup(info, "certInfo"); + appendItem(group, "ValidFrom", cert->getQDTNotBefore()); + appendItem(group, "ValidUntil", cert->getQDTNotAfter()); + appendItem(group, "State", KSSLCertificate::verifyText(cert->validate())); + appendItem(group, "SerialNo", cert->getSerialNumber()); + + group = appendGroup(info, "certSubjectInfo"); + appendDNItems(group, cert->getSubject()); + + group = appendGroup(info, "certIssuerInfo"); + appendDNItems(group, cert->getIssuer()); + + delete cert; + return true; + } + else { + KOSSL::self()->ERR_clear_error(); // don't leave errors behind + return false; + } +} + +#include "kfile_cert.moc" diff --git a/kfile-plugins/cert/kfile_cert.desktop b/kfile-plugins/cert/kfile_cert.desktop new file mode 100644 index 0000000..a1571fd --- /dev/null +++ b/kfile-plugins/cert/kfile_cert.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=Certificate Info +Name[bg]=Информация за удостоверение +Name[br]=Titouroù diwar-benn an testeni +Name[ca]=Informació del certificat +Name[cs]=Informace o certifikátu +Name[da]=Information om certifikat +Name[de]=Information zum Zertifikat +Name[el]=Πληροφορίες πιστοποιητικού +Name[eo]=Atesta informo +Name[es]=Información del certificado +Name[et]=Sertifikaadi info +Name[eu]=Ziurtagiriaren informazioa +Name[fa]=اطلاعات گواهینامه +Name[fi]=Sertifikaatin tiedot +Name[fr]=Informations sur le certificat +Name[fy]=Sertifikaatynformaasje +Name[ga]=Eolas faoin Teastas +Name[gl]=Informacións do Certificado +Name[hi]=प्रमाणपत्र जानकारी +Name[hr]=Podaci potvrde +Name[hu]=Tanúsítvány-jellemzők +Name[is]=Upplýsingar um skírteini +Name[it]=Informazioni del certificato +Name[ja]=認証情報 +Name[ka]=სერტიფიკატის ინფორმაცია +Name[kk]=Куәлік мәліметтері +Name[km]=ព័ត៌មានវិញ្ញាបនបត្រ +Name[lt]=Sertifikato informacija +Name[mk]=Информации за сертификати +Name[ms]=Maklumat Sijil +Name[nb]=Sertifikatinformasjon +Name[nds]=Zertifikaat-Informatschonen +Name[ne]=प्रमाणपत्र सूचना +Name[nl]=Certificaatinformatie +Name[nn]=Informasjon om sertifikat +Name[pa]=ਸਰਟੀਫਿਕੇਟ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o certyfikacie +Name[pt]=Informações do Certificado +Name[pt_BR]=Informações sobre Certificado +Name[ru]=Информация о сертификате +Name[sk]=Informácie o certifikáte +Name[sl]=Informacija o certifikatu +Name[sr]=Информације о сертификату +Name[sr@Latn]=Informacije o sertifikatu +Name[sv]=Information om certifikat +Name[ta]=சான்றிதழ் தகவல் +Name[tr]=Sertifika Bilgisi +Name[uk]=Інформація про сертифікат +Name[uz]=Sertifikat haqida maʼlumot +Name[uz@cyrillic]=Сертификат ҳақида маълумот +Name[vi]=Thông tin chứng nhận +Name[zh_CN]=证书信息 +Name[zh_TW]=憑證資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_cert +MimeType=application/x-x509-ca-cert +PreferredGroups=certInfo,certSubjectInfo +PreferredItems=State,CN,O,OU,L,C diff --git a/kfile-plugins/cert/kfile_cert.h b/kfile-plugins/cert/kfile_cert.h new file mode 100644 index 0000000..544ef39 --- /dev/null +++ b/kfile-plugins/cert/kfile_cert.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2004 by Leonid Zeitlin * + * lz@europe.com * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef __KFILE_CERT_H__ +#define __KFILE_CERT_H__ + +/** + * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h> + */ +#include <kfilemetainfo.h> + +class QStringList; +class QString; + +class CertPlugin: public KFilePlugin { + Q_OBJECT +private: + void appendDNItems(KFileMetaInfoGroup &group, const QString &DN); +public: + CertPlugin(QObject *parent, const char *name, const QStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); +}; + +#endif // __KFILE_CERT_H__ + diff --git a/kfile-plugins/desktop/Makefile.am b/kfile-plugins/desktop/Makefile.am new file mode 100644 index 0000000..4fdfa7f --- /dev/null +++ b/kfile-plugins/desktop/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for .desktop 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_desktop.h + +kde_module_LTLIBRARIES = kfile_desktop.la + +kfile_desktop_la_SOURCES = kfile_desktop.cpp +kfile_desktop_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_desktop_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_desktop.pot + +services_DATA = kfile_desktop.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/desktop/kfile_desktop.cpp b/kfile-plugins/desktop/kfile_desktop.cpp new file mode 100644 index 0000000..3a78dbc --- /dev/null +++ b/kfile-plugins/desktop/kfile_desktop.cpp @@ -0,0 +1,128 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + * + * 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 "kfile_desktop.h" + +#include <kurl.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> +#include <kdesktopfile.h> +#include <kmimetype.h> + +typedef KGenericFactory<KDotDesktopPlugin> DotDesktopFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_desktop, DotDesktopFactory("kfile_desktop")) + +KDotDesktopPlugin::KDotDesktopPlugin(QObject *parent, const char *name, + const QStringList &preferredItems) + : KFilePlugin(parent, name, preferredItems) +{ + kdDebug(7034) << ".desktop plugin\n"; + + KFileMimeTypeInfo* info; + KFileMimeTypeInfo::GroupInfo* group; + KFileMimeTypeInfo::ItemInfo* item; + + info = addMimeTypeInfo("application/x-desktop"); + group = addGroupInfo(info, "General", i18n("General")); + + item = addItemInfo(group, "Name", i18n("Name"), QVariant::String); + setHint(item, KFileMimeTypeInfo::Name); + item = addItemInfo(group, "Comment", i18n("Comment"), QVariant::String); + setHint(item, KFileMimeTypeInfo::Description); + + addItemInfo(group, "Type", i18n("Type"), QVariant::String); + + addItemInfo(group, "Device", i18n("Device"), QVariant::String); + addItemInfo(group, "Mount Point", i18n("Mount Point"), QVariant::String); + addItemInfo(group, "File System", i18n("File System"), QVariant::String); + addItemInfo(group, "Writable", i18n("Writable"), QVariant::Bool); + + addItemInfo(group, "File Type", i18n("File Type"), QVariant::String); + addItemInfo(group, "Service Type", i18n("Service Type"), QVariant::String); + addItemInfo(group, "Preferred Items", i18n("Preferred Items"), QVariant::String); + addItemInfo(group, "Link To", i18n("Link To"), QVariant::String); +} + +bool KDotDesktopPlugin::readInfo( KFileMetaInfo& info, uint ) +{ + if ( info.path().isEmpty() ) // remote file + return false; + + KDesktopFile file(info.path(), true); + + QString s; + + KFileMetaInfoGroup group = appendGroup(info, "General"); + + s = file.readName(); + if (!s.isEmpty()) appendItem(group, "Name", s); + + s = file.readComment(); + if (!s.isEmpty()) appendItem(group, "Comment", s); + + QString type = file.readType(); + if (type == "FSDevice") + { + appendItem(group, "Type", i18n("Device")); + + s = file.readDevice(); + if (!s.isEmpty()) appendItem(group, "Device", s); + + s = file.readEntry("MountPoint"); + if (!s.isEmpty()) appendItem(group, "Mount Point", s); + + s = i18n(file.readEntry("FSType").local8Bit()); + if (!s.isEmpty()) appendItem(group, "File System", s); + + appendItem(group, "Writable", + QVariant(!file.readBoolEntry("ReadOnly", true), 42)); + + } + else if (type == "Service") + { + appendItem(group, "Type", i18n("Service")); + + s = file.readEntry("MimeType"); + if (!s.isEmpty()) + { + KMimeType::Ptr mt = KMimeType::mimeType(s); + appendItem(group, "File Type", mt->comment()); + } + + QString sType = file.readEntry("ServiceTypes"); + appendItem(group, "Service Type", sType); + + if (sType == "KFilePlugin") + { + QStringList preferred = file.readListEntry("PreferredItems"); + appendItem(group, "Preferred Items", preferred); + } + } + else if (type == "Link") + { + QString url = file.readPathEntry("URL"); + appendItem(group, "Link To", url); + } + + return true; +} + +#include "kfile_desktop.moc" diff --git a/kfile-plugins/desktop/kfile_desktop.desktop b/kfile-plugins/desktop/kfile_desktop.desktop new file mode 100644 index 0000000..4bcb494 --- /dev/null +++ b/kfile-plugins/desktop/kfile_desktop.desktop @@ -0,0 +1,68 @@ +[Desktop Entry] +Type=Service +Name=Desktop Entry Info +Name[af]=Werkskerm Inskrywing Inligting +Name[ar]=معلومات مدخل سطح المكتب +Name[az]=Masa Üstü Girişi Mə'lumatı +Name[bg]=Информация за файл Desktop +Name[br]=Titouroù diwar-benn ar vouetadur burev +Name[bs]=Informacije o desktop stavci +Name[ca]=Informació de l'entrada a l'escriptori +Name[cs]=Info o položce pracovní plochy +Name[cy]=Gwybodaeth Cofnod Penbwrdd +Name[da]=Information om desktopindgang +Name[de]=Information zum Arbeitsflächeneintrag +Name[el]=Πληροφορίες καταχώρησης επιφάνειας εργασίας +Name[eo]=Tabula ero informo +Name[es]=Información de la entrada del escritorio +Name[et]=Töölaua kirje info +Name[eu]=Mahaigainaren sarreraren informazioa +Name[fa]=اطلاعات مدخل رومیزی +Name[fi]=Työpöytätietueen tiedot +Name[fo]=Upplýsingar um inngang á skriviborði +Name[fr]=Informations sur l'entrée du bureau +Name[fy]=Buroblêdyngong-ynformaasje +Name[gl]=Información do Campo Desktop +Name[he]=מידע רשומת שולחן עבודה +Name[hi]=डेस्कटॉप एन्ट्री जानकारी +Name[hr]=Podaci o stavki radne površine +Name[hu]=Információ a munkaasztali bejegyzésekről +Name[is]=Upplýsingar un skjáborðsfærslu +Name[it]=Informazioni sulle voci Desktop +Name[ja]=デスクトップエントリ情報 +Name[ka]=სამუშაო მაგიდის ჩანაწერის ინფორმაცია +Name[kk]=.desktop жазуының мәліметі +Name[km]=ព័ត៌មានធាតុផ្ទៃតុ +Name[lt]=Darbastalio įrašo informacija +Name[mk]=Информации за елемент од работната околина +Name[ms]=Maklumat Entri Desktop +Name[nb]=Informasjon om skrivebordsoppføring +Name[nds]=Schriefdischindrag-Informatschonen +Name[ne]=डेस्कटप प्रविष्टि सूचना +Name[nl]=Bureaubladingang-informatie +Name[nn]=Informasjon om skrivebordsoppføring +Name[nso]=Tshedimoso Tsenelo ya Desktop +Name[pa]=ਵੇਹੜਾ ਇੰਦਰਾਜ਼ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o plikach Desktop +Name[pt]=Informação do Campo do 'Desktop' +Name[pt_BR]=Informações sobre a entrada desktop +Name[ro]=Informaţii înregistrare ecran +Name[ru]=Информация об элементе .desktop +Name[sk]=Informácie o položke pracovnej plochy +Name[sl]=Informacije o vnosu namizja +Name[sr]=Информације о уносу на радној површини +Name[sr@Latn]=Informacije o unosu na radnoj površini +Name[sv]=Information om skrivbordsfil +Name[ta]=மேல்மேசை உள்ளிடு தகவல் +Name[tg]=Ахборот дар бораи ҷузъи мизи корӣ +Name[th]=ข้อมูลรายการพื้นที่ทำงาน +Name[tr]=Masaüstü Girdi Bilgisi +Name[uk]=Інформація про елемент стільниці +Name[vi]=Thông tin mục nhập môi trường +Name[xh]=Ungeniso Lolwazi lwe Desktop +Name[zh_CN]=桌面项目信息 +Name[zh_TW]=桌面項目資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_desktop +MimeType=application/x-desktop +PreferredItems=Name,Comment,Type,Service Type diff --git a/kfile-plugins/desktop/kfile_desktop.h b/kfile-plugins/desktop/kfile_desktop.h new file mode 100644 index 0000000..1001e22 --- /dev/null +++ b/kfile-plugins/desktop/kfile_desktop.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + * + * 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_DESKTOP_H__ +#define __KFILE_DESKTOP_H__ + +#include <kfilemetainfo.h> +#include <kurl.h> + +class QStringList; + +class KDotDesktopPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KDotDesktopPlugin( QObject *parent, const char *name, + const QStringList& args ); + + virtual bool readInfo ( KFileMetaInfo& info, uint what ); +}; + +#endif diff --git a/kfile-plugins/folder/Makefile.am b/kfile-plugins/folder/Makefile.am new file mode 100644 index 0000000..8c689dc --- /dev/null +++ b/kfile-plugins/folder/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for folder file meta info plugin + +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_folder.h + +kde_module_LTLIBRARIES = kfile_folder.la + +kfile_folder_la_SOURCES = kfile_folder.cpp +kfile_folder_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_folder_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +services_DATA = kfile_folder.desktop +servicesdir = $(kde_servicesdir) + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_folder.pot diff --git a/kfile-plugins/folder/kfile_folder.cpp b/kfile-plugins/folder/kfile_folder.cpp new file mode 100644 index 0000000..911a2e5 --- /dev/null +++ b/kfile-plugins/folder/kfile_folder.cpp @@ -0,0 +1,86 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Simon MacMullen + * + * 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 <config.h> +#include "kfile_folder.h" + +#include <kgenericfactory.h> +#include <kio/global.h> + +#include <qfileinfo.h> +#include <qdir.h> + +typedef KGenericFactory<KFolderPlugin> KFolderFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_folder, KFolderFactory( "kfile_folder" )) + +KFolderPlugin::KFolderPlugin(QObject *parent, const char *name, + const QStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "inode/directory" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "FolderInfo", i18n("Folder Information")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Items", i18n("Items"), QVariant::Int); + item = addItemInfo(group, "Size", i18n("Size"), QVariant::Int); + setUnit(item, KFileMimeTypeInfo::Bytes); +} + +bool KFolderPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + KFileMetaInfoGroup group = appendGroup(info, "FolderInfo"); + + if (info.path().isEmpty()) + return false; + + QDir dir; + if ( !dir.cd(info.path()) ) + return false; + + const QPtrList<QFileInfo> *fileList = dir.entryInfoList(); + if (!fileList) + return false; + + QPtrListIterator<QFileInfo> list = QPtrListIterator<QFileInfo>(*fileList); + + QFileInfo* file; + int items = 0; + KIO::filesize_t bytes = 0; + + while ( (file = list.current()) != 0 ) { + ++list; + if (!file->fileName().startsWith(".")) { + items++; + bytes += file->size(); + } + } + + appendItem(group, "Items", items); + appendItem(group, "Size", bytes); + + return true; +} + +#include "kfile_folder.moc" diff --git a/kfile-plugins/folder/kfile_folder.desktop b/kfile-plugins/folder/kfile_folder.desktop new file mode 100644 index 0000000..2cd6873 --- /dev/null +++ b/kfile-plugins/folder/kfile_folder.desktop @@ -0,0 +1,70 @@ +[Desktop Entry] +Type=Service +Name=Folder Info +Name[af]=Kabinet Inligting +Name[ar]=معلومات المجلد +Name[az]=Qovluq Mə'lumatı +Name[bg]=Информация за директория +Name[br]=Titouroù diwar-benn ar renkell +Name[bs]=Informacije o direktoriju +Name[ca]=Info. de la carpeta +Name[cs]=Info o adresáři +Name[cy]=Gwybodaeth Plygell +Name[da]=Mappeinformation +Name[de]=Ordnerinformation +Name[el]=Πληροφορίες φακέλου +Name[eo]=Dosieruja informo +Name[es]=Información de carpeta +Name[et]=Kataloogi info +Name[eu]=Karpetaren informazioa +Name[fa]=اطلاعات پوشه +Name[fi]=Kansion tiedot +Name[fo]=Upplýsingar um inngangar á skriviborði +Name[fr]=Informations sur le dossier +Name[fy]=Mappenynformaasje +Name[gl]=Información do Cartafol +Name[he]=מידע תיקייה +Name[hi]=फ़ोल्डर जानकारी +Name[hr]=Podaci mape +Name[hu]=Mappajellemzők +Name[is]=Möppuupplýsingar +Name[it]=Informazioni su directory +Name[ja]=フォルダ情報 +Name[ka]=საქაღალდის ინფორმაცია +Name[kk]=Қапшық мәліметі +Name[km]=ព័ត៌មានថត +Name[lt]=Aplanko informacija +Name[mk]=Информации за папка +Name[ms]=Maklumat Folder +Name[nb]=Mappeinformasjon +Name[nds]=Orner-Informatschonen +Name[ne]=फोल्डर सूचना +Name[nl]=Mappeninformatie +Name[nn]=Kataloginformasjon +Name[pa]=ਫੋਲਡਰ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o katalogach +Name[pt]=Informações de Pastas +Name[pt_BR]=Informações sobre a Pasta +Name[ro]=Informaţii folder +Name[ru]=Информация о папке +Name[sk]=Informácie o priečinku +Name[sl]=Informacije o mapi +Name[sr]=Информације о фасцикли +Name[sr@Latn]=Informacije o fascikli +Name[sv]=Kataloginformation +Name[ta]=அடைவுத்தகவல் +Name[tg]=Ахборот дар бораи каталог +Name[th]=ข้อมูลโฟลเดอร์ +Name[tr]=Dizin Bilgisi +Name[uk]=Інформація про теку +Name[uz]=Jild haqida maʼlumot +Name[uz@cyrillic]=Жилд ҳақида маълумот +Name[vi]=Thông tin thư mục +Name[xh]=Ulwazi lwencwadi enencukhacha +Name[zh_CN]=文件夹信息 +Name[zh_TW]=資料夾資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_folder +MimeType=inode/directory +PreferredGroups=FolderInfo +PreferredItems=Items,Size diff --git a/kfile-plugins/folder/kfile_folder.h b/kfile-plugins/folder/kfile_folder.h new file mode 100644 index 0000000..602c369 --- /dev/null +++ b/kfile-plugins/folder/kfile_folder.h @@ -0,0 +1,37 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Simon MacMullen + * + * 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_KFOLDER_H__ +#define __KFILE_KFOLDER_H__ + +#include <kfilemetainfo.h> + +class QStringList; + +class KFolderPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KFolderPlugin( QObject *parent, const char *name, const QStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/kfile-plugins/html/Makefile.am b/kfile-plugins/html/Makefile.am new file mode 100644 index 0000000..610b74f --- /dev/null +++ b/kfile-plugins/html/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for html 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_html.h + +kde_module_LTLIBRARIES = kfile_html.la + +kfile_html_la_SOURCES = kfile_html.cpp +kfile_html_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_html_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) kfile_html.cpp -o $(podir)/kfile_html.pot + +services_DATA = kfile_html.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/html/kfile_html.cpp b/kfile-plugins/html/kfile_html.cpp new file mode 100644 index 0000000..bfe736b --- /dev/null +++ b/kfile-plugins/html/kfile_html.cpp @@ -0,0 +1,158 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org> + * + * 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. + * + * $Id$ + */ + +#include "kfile_html.h" +#include "kfile_html.moc" +#include <kgenericfactory.h> +#include <kmimetype.h> +#include <kurl.h> +#include <kprocess.h> +#include <kdebug.h> +#include <qcstring.h> +#include <qfile.h> +#include <qregexp.h> +#include <qtextcodec.h> + +typedef KGenericFactory<KHtmlPlugin> HtmlFactory; + +K_EXPORT_COMPONENT_FACTORY( kfile_html, HtmlFactory( "kfile_html" ) ) + +KHtmlPlugin::KHtmlPlugin( QObject *parent, const char *name, + const QStringList &args ) + : KFilePlugin( parent, name, args ) +{ + kdDebug(7034) << "html plugin\n"; + + KFileMimeTypeInfo* info = addMimeTypeInfo("text/html"); + + KFileMimeTypeInfo::GroupInfo* group; + KFileMimeTypeInfo::ItemInfo* item; + + group = addGroupInfo(info, "General", i18n("General")); + addItemInfo(group, "Doctype", i18n("Document Type"), QVariant::String); + addItemInfo(group, "Javascript", i18n("JavaScript"), QVariant::Bool); + item = addItemInfo(group, "Title", i18n("Title"), QVariant::String); + setHint(item, KFileMimeTypeInfo::Name); + + group = addGroupInfo(info, "Metatags", i18n("Meta Tags")); + addVariableInfo(group, QVariant::String, 0); +} + + +bool KHtmlPlugin::readInfo( KFileMetaInfo& info, uint ) +{ + if ( info.path().isEmpty() ) // remote file + return false; + + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) + return false; + + // we're only interested in the header, so just read until before </head> + // or until <body> if the author forgot it + // In this case, it's better to limit the size of the buffer to something + // sensible. Think a 0-filled 3GB file with an .html extension. + int maxBufSize = QMIN(f.size(), 32768); + QByteArray data(maxBufSize + 1); + f.readBlock(data.data(), maxBufSize); + data[maxBufSize]='\0'; + + QString s(data); + + int start=0, last=0; + QRegExp exp; + exp.setCaseSensitive(false); + exp.setMinimal(true); + + KFileMetaInfoGroup group = appendGroup(info, "General"); + + exp.setPattern("\\s*<\\s*!doctype\\s*([^>]*)\\s*>"); + if (exp.search(s, last) != -1) + { + kdDebug(7034) << "DocType: " << exp.capturedTexts().join("-") << endl; + appendItem(group, "Doctype", exp.cap(1)); + last += exp.matchedLength(); + } + + QString title; + exp.setPattern("<\\s*title\\s*>\\s*(.*)\\s*<\\s*/\\s*title\\s*>"); + if (exp.search(s, last) != -1) + { + title = exp.cap(1); + last += exp.matchedLength(); + } + + KFileMetaInfoGroup metatags = appendGroup(info, "Metatags"); + + QString meta, name, content; + exp.setPattern("<\\s*meta\\s*([^>]*)\\s*>"); + QRegExp rxName("(?:name|http-equiv)\\s*=\\s*\"([^\"]+)\"", false); + QRegExp rxContent("content\\s*=\\s*\"([^\"]+)\"", false); + QRegExp rxCharset("charset\\s*=\\s*(.*)", false); + QTextCodec *codec = 0; + + // find the meta tags + last = 0; + while (1) + { + if ((start=exp.search(s, last)) == -1) + break; + meta = exp.cap(1); + last = start+exp.matchedLength(); + + kdDebug(7034) << "Found Meta: " << meta << endl; + + if (rxName.search(meta) == -1) + continue; + name = rxName.cap(1); + + if (rxContent.search(meta) == -1) + continue; + content = rxContent.cap(1); + + appendItem(metatags, name, content.left(50)); + + // check if it has a charset defined + if ( rxCharset.search(content) != -1 ) + { + kdDebug(7034) << "CodecForName : " << rxCharset.cap(1) << endl; + codec = QTextCodec::codecForName(rxCharset.cap(1).ascii()); + } + } + + if ( ! title.isEmpty() ) + { + if ( codec ) + { + title = codec->toUnicode(title.ascii()); + kdDebug(7034) << "Codec : " << codec->name() << endl; + } + + appendItem(group, "Title", title); + } + + // find out if it contains javascript + exp.setPattern("<script>"); + + appendItem(group, "Javascript", QVariant( s.find(exp)!=-1, 42)); + + return true; +} + diff --git a/kfile-plugins/html/kfile_html.desktop b/kfile-plugins/html/kfile_html.desktop new file mode 100644 index 0000000..fd75703 --- /dev/null +++ b/kfile-plugins/html/kfile_html.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +Type=Service +Name=HTML Playlist Info +Name[af]=Html Liedjielys Inligting +Name[ar]=معلومات قائمة أغاني HTML +Name[az]=HTML Çalğı Siyahısı Mə'lumatı +Name[bg]=Информация за HTML файл +Name[br]=Titouroù diwar-benn ar roll tonioù HTML +Name[ca]=Info. de la llista de reproducció HTML +Name[cs]=Informace o seznamu skladeb HTML +Name[cy]=Gwybodaeth Rhestr Chwarae HTML +Name[da]=Information om HTML-spilleliste +Name[de]=HTML-Wiedergabelisteninfo +Name[el]=Πληροφορίες λίστας αναπαραγωγής HTML +Name[eo]=HTML-ludlistinformo +Name[es]=Información de la lista de reproducción HTML +Name[et]=HTML esitusnimekirja info +Name[eu]=HTML erreprodukzio-zerrendaren informazioa +Name[fa]=اطلاعات فهرست پخش زنگام +Name[fi]=HTML soittolistan tiedot +Name[fo]=HTML spælilistaupplýsingar +Name[fr]=Informations sur une liste de lecture HTML +Name[fy]=HTML-ôfspyllistynfo +Name[gl]=Información de Listas de Reprodución HTML +Name[he]=מידע רשימת ניגון HTML +Name[hi]=एचटीएमएल प्लेलिस्ट जानकारी +Name[hr]=HTML podaci o popisu za sviranje +Name[hu]=HTML lejátszási lista jellemzői +Name[is]=Upplýsingar um HTML lagalista +Name[it]=Informazioni playlist HTML +Name[ja]=HTML プレイリスト情報 +Name[ka]=HTML სიმღერათა სიის ინფორმაცია +Name[kk]=HTML орындау тізім мәліметі +Name[km]=ព័ត៌មានបញ្ជីចាក់ HTML +Name[lt]=HTML grojaraščio informacija +Name[mk]=Информации за HTML-листа на нумери +Name[ms]=Maklumat Senarai Main HTML +Name[nb]=HTML-spilleliste-informasjon +Name[nds]=HTML-Afspellistinformatschonen +Name[ne]=एचटीएमएल प्लेसूची सूचना +Name[nl]=HTML-afspeellijstinfo +Name[nn]=Informasjon om HTML-speleliste +Name[pa]=HTML ਸੰਗੀਤ-ਸੂਚੀ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o liście nagrań w HTML-u +Name[pt]=Informações de Listas de Músicas HTML +Name[pt_BR]=Informação de listas de reprodução HTML +Name[ro]=Informaţii listă de redare HTML +Name[ru]=Информация о списке песен в формате HTML +Name[sk]=HTML informácie o playliste +Name[sl]=Informacije o predvajalnem seznamu HTML +Name[sr]=HTML информације о листи нумера +Name[sr@Latn]=HTML informacije o listi numera +Name[sv]=Information om HTML-spellista +Name[ta]=HTML வாசிப்புப்பட்டியல் தகவல் +Name[tg]=Ахборот дар бораи рӯйхати сурудҳо дар HTML +Name[th]=ข้อมูลรายการเล่น HTML +Name[tr]=HTML Çalma Listesi Bilgisi +Name[uk]=Інформація списку композицій в HTML +Name[vi]=Thông tin danh mục nhạc HTML +Name[xh]=Ulwazi loluhlu lodweliso lomdlali we HTML +Name[zh_CN]=HTML 播放列表信息 +Name[zh_TW]=HTML 播放清單資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_html +MimeType=text/html +PreferredItems=Title,Javascript,Doctype,Keywords diff --git a/kfile-plugins/html/kfile_html.h b/kfile-plugins/html/kfile_html.h new file mode 100644 index 0000000..4d9eec6 --- /dev/null +++ b/kfile-plugins/html/kfile_html.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org> + * + * 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. + * + * $Id$ + */ + +#ifndef __KMIME_HTML_H__ +#define __KMIME_HTML_H__ + +#include <kfilemetainfo.h> +#include <kurl.h> + +class QStringList; + +class KHtmlPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KHtmlPlugin( QObject *parent, const char *name, const QStringList& args ); + virtual bool readInfo( KFileMetaInfo& info, uint what ); +}; + +#endif diff --git a/kfile-plugins/lnk/Makefile.am b/kfile-plugins/lnk/Makefile.am new file mode 100644 index 0000000..9d97978 --- /dev/null +++ b/kfile-plugins/lnk/Makefile.am @@ -0,0 +1,34 @@ +## Makefile.am for lnk file meta info plugin + +INCLUDES = $(all_includes) + +bin_PROGRAMS = lnkforward + +lnkforward_SOURCES = lnkforward.cpp +lnkforward_LDADD = $(LIB_KDECORE) $(LIB_KIO) +lnkforward_LDFLAGS = $(all_libraries) $(KDE_RPATH) +lnkforward_METASOURCES = lnkforward.moc + +lnkforward_DATA = lnkforward.desktop +lnkforwarddir = $(kde_appsdir)/.hidden + +# these are the headers for your project +noinst_HEADERS = kfile_lnk.h read_lnk.h lnkforward.h + +kde_module_LTLIBRARIES = kfile_lnk.la + +kfile_lnk_la_SOURCES = kfile_lnk.cpp read_lnk.cpp +kfile_lnk_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_lnk_la_LIBADD = $(LIB_KIO) +kfile_lnk_la_METASOURCES = kfile_lnk.moc + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +kde_services_DATA = kfile_lnk.desktop + +mime_DATA = x-win-lnk.desktop +mimedir = $(kde_mimedir)/application + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_lnk.pot diff --git a/kfile-plugins/lnk/README b/kfile-plugins/lnk/README new file mode 100644 index 0000000..a61c473 --- /dev/null +++ b/kfile-plugins/lnk/README @@ -0,0 +1,29 @@ +29.May 2004, Martin Koller, m.koller@surfeu.at + +This package shall help a better integration of KDE/Linux into a Windows environment +by providing tools to work with Windows .lnk files + +This package contains 2 tools: + +- a KFile plugin, kfile_lnk, which gives metadata information for a .lnk file (where does it point to) + +- a small tool, lnkforward, to start an associated application for which the path is in a .lnk file + (e.g. when you double-click a file in konqueror) + +The .lnk file is registered as MIME type application/x-win-lnk + +If you have a dual-boot machine, and you have your Windows partition(s) mounted, +then you should adapt where konqi can find the corresponding C:, D: or other drives. +For this you have to adapt the used commandline arguments for lnkforward, which you +can do in konqis file-associations for the MIME type application/x-win-lnk + +The lnkforward tool shall get a commandline option like this: + +-map C=/mnt/winC -map D=/mnt/winD + +NOTE: both tools work with .lnk files which are either readable via the local filesystem +(smbfs mounted filesystems) or also via URLs on the network, e.g. smb://something + +Have fun. + +Martin diff --git a/kfile-plugins/lnk/kfile_lnk.cpp b/kfile-plugins/lnk/kfile_lnk.cpp new file mode 100644 index 0000000..6d8ea94 --- /dev/null +++ b/kfile-plugins/lnk/kfile_lnk.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +// format of a .lnk file retrieved from: +// http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf + +#include <config.h> +#include "kfile_lnk.h" +#include "read_lnk.h" + +#include <kgenericfactory.h> + +//-------------------------------------------------------------------------------- + +typedef KGenericFactory<lnkPlugin> lnkFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_lnk, lnkFactory( "kfile_lnk" )) + +//-------------------------------------------------------------------------------- + +lnkPlugin::lnkPlugin(QObject *parent, const char *name, + const QStringList &args) + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-win-lnk" ); + + // our new group + KFileMimeTypeInfo::GroupInfo* group = 0; + group = addGroupInfo(info, "lnkInfo", i18n("Windows Link File Information")); + + KFileMimeTypeInfo::ItemInfo* item; + + // our new items in the group + item = addItemInfo(group, "TargetSize", i18n("Size of Target"), QVariant::Int); + setUnit(item, KFileMimeTypeInfo::Bytes); + + addItemInfo(group, "Where", i18n("Location"), QVariant::String); + addItemInfo(group, "PointsTo", i18n("Points To"), QVariant::String); + addItemInfo(group, "Description", i18n("Description"), QVariant::String); +} + +//-------------------------------------------------------------------------------- + +bool lnkPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + KFileMetaInfoGroup group = appendGroup(info, "lnkInfo"); + + LNKInfo lnkInfo; + bool ret = readLNK(info.url(), lnkInfo); + + if ( ! ret ) return false; + + if ( ! lnkInfo.isDirectory ) // not a directory + appendItem(group, "TargetSize", lnkInfo.fileSize); + + if ( ! lnkInfo.isFileOrDir ) // points to something != file or directory + return false; + + if ( ! lnkInfo.isNetworkPath ) + { + appendItem(group, "Where", i18n("on Windows disk: %1").arg(lnkInfo.volumeName)); // volume label + appendItem(group, "PointsTo", QString("%1%2").arg(lnkInfo.driveName).arg(lnkInfo.path)); + } + else + { + appendItem(group, "Where", i18n("on network share")); + appendItem(group, "PointsTo", lnkInfo.path); + } + + if ( ! lnkInfo.description.isNull() ) // has description string + appendItem(group, "Description", lnkInfo.description); + + return true; +} + +#include "kfile_lnk.moc" diff --git a/kfile-plugins/lnk/kfile_lnk.desktop b/kfile-plugins/lnk/kfile_lnk.desktop new file mode 100644 index 0000000..bad39b3 --- /dev/null +++ b/kfile-plugins/lnk/kfile_lnk.desktop @@ -0,0 +1,62 @@ +[Desktop Entry] +Type=Service +Name=Windows lnk File Info +Name[bg]=Информация за файл връзка на Windows +Name[br]=Titouroù diwar-benn ar restr Windows lnk +Name[bs]=Windows lnk informacije o datoteci +Name[ca]=Informació dels fitxers lnk de Windows +Name[cs]=Informace o Windows lnk souboru +Name[da]=Information om Windows lnk-fil +Name[de]=Informationen zur Windows-Verknüpfungsdatei +Name[el]=Πληροφορίες αρχείου lnk των Windows +Name[eo]=Vindoza lnk dosiera informo +Name[es]=Información del archivo lnk de Windows +Name[et]=Windowsi .lnk-faili info +Name[eu]=Windowsen Ink fitxategiaren informazioa +Name[fa]=اطلاعات پروندۀ lnk ویندوز +Name[fi]=Windows lnk-tiedoston tiedot +Name[fr]=Informations sur le fichier « .lnk » Windows +Name[fy]=Windows lnk-triemynformaasje +Name[ga]=Eolas faoin Chomhad lnk Windows +Name[gl]=Información de Ficheiros lnk de Windows +Name[he]= מידע קובץ lnk של Windows +Name[hi]=विंडो लिंक फ़ाइल जानकारी +Name[hr]=Podaci Windows prečaca +Name[hu]=Információ Windows-os Lnk-fájlokról +Name[is]=Upplýsingar um Windows lnk-skrá +Name[it]=File di informazioni Windows lnk +Name[ja]=Windows lnk ファイル情報 +Name[ka]=Windows lnk ფაილის ინფორმაცია +Name[kk]=Windows жарлық файлдың мәліметі +Name[km]=ព័ត៌មានឯកសារបង្អួចឯកសារ lnk +Name[lt]=Windows lnk bylos informacija +Name[mk]=Информации за Windows Ink-датотека +Name[ms]=Maklumat Fail Dakwat Tetingkap +Name[nb]=Informasjon om Windows lnk-fil +Name[nds]=Informatschonen över de Windows-Linkdatei (.lnk) +Name[ne]=विन्डोज lnk फाइल सूचना +Name[nl]=Windows lnk-bestandsinformatie +Name[nn]=Informasjon om Windows lnk-fil +Name[pa]=Windows lnk ਫਾਇਲ ਜਾਣਕਾਰੀ +Name[pl]=Informacja plików lnk systemu Windows +Name[pt]=Informação do Ficheiro '.lnk' do Windows +Name[pt_BR]=Informações de Arquivo do Windows +Name[ru]=Сведения о ярлыке Windows +Name[sk]=Informácie o súbore Windows lnk +Name[sl]=Informacija o datoteki Windows .lnk +Name[sr]=Подаци о Windows-овом .lnk фајлу +Name[sr@Latn]=Podaci o Windows-ovom .lnk fajlu +Name[sv]=Information om Windows länkfil +Name[ta]=விண்டோஸ் இங்க் கோப்பு தகவல் +Name[tg]=Маълумотҳо дар бораи ярлиқи Windows +Name[tr]=Windows lnk Dosya Bilgisi +Name[uk]=Інформація про файл lnk для Windows +Name[uz]=Windows lnk fayli haqida maʼlumot +Name[uz@cyrillic]=Windows lnk файли ҳақида маълумот +Name[vi]=Thông tin tập tin Ink Windows +Name[zh_CN]=Windows lnk 文件信息 +Name[zh_TW]=Windows lnk 檔資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_lnk +MimeType=application/x-win-lnk +PreferredItems=PointsTo,Where,TargetSize,Description diff --git a/kfile-plugins/lnk/kfile_lnk.h b/kfile-plugins/lnk/kfile_lnk.h new file mode 100644 index 0000000..3ee4ae8 --- /dev/null +++ b/kfile-plugins/lnk/kfile_lnk.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This plugin provides information about the content of a * + * M$-Windoze .lnk file, which is useful if you work in a mixed * + * Linux/Windoze environment. * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef __KFILE_LNK_H__ +#define __KFILE_LNK_H__ + +/** + * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h> + */ +#include <kfilemetainfo.h> + +class QStringList; + +class lnkPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + lnkPlugin( QObject *parent, const char *name, const QStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif // __KFILE_LNK_H__ + diff --git a/kfile-plugins/lnk/lnkforward.cpp b/kfile-plugins/lnk/lnkforward.cpp new file mode 100644 index 0000000..a79a7db --- /dev/null +++ b/kfile-plugins/lnk/lnkforward.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This helper app runs the associated action for a linked file inside a * + * M$-Windoze .lnk file, which is useful if you work in a mixed * + * Linux/Windoze environment. * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "read_lnk.cpp" +#include "lnkforward.h" + +#include <stdlib.h> + +#include <klocale.h> +#include <krun.h> +#include <kdebug.h> + +//-------------------------------------------------------------------------------- + +static const char appName[] = "lnkforward"; +static const char programName[] = I18N_NOOP("lnkforward"); + +static const char description[] = I18N_NOOP("KDE tool for opening URLs given in a Windows .lnk file"); + +static const char version[] = "1.0"; + +static const KCmdLineOptions options[] = +{ + { "map <drive=path>", I18N_NOOP("Map a Windows drive to a local mountpoint, e.g. \"C=/mnt/windows\"" + "\nThis option can be given multiple times"), 0}, + { "+URL", I18N_NOOP("Windows .lnk file to open"), 0}, + KCmdLineLastOption +}; + +//-------------------------------------------------------------------------------- + +int main(int argc, char **argv) +{ + KCmdLineArgs::init(argc, argv, appName, programName, description, version, false); + + KCmdLineArgs::addCmdLineOptions(options); + + LNKForwarder app; + + return app.run(KCmdLineArgs::parsedArgs()); +} + +//-------------------------------------------------------------------------------- + +int LNKForwarder::run(KCmdLineArgs *args) +{ + if ( args->count() == 0 ) return 1; + + LNKInfo info; + + bool ret = readLNK(args->arg(0), info); + if ( ! ret ) return 1; + + info.path.replace(QChar('\\'), QChar('/')); + + QString path; + + if ( info.isNetworkPath ) + { + path = "smb:" + info.path; + } + else + { + if ( info.driveName.isNull() ) return 1; // can this ever happen ? + + QCStringList map = args->getOptionList("map"); + bool found = false; + + for (unsigned int i = 0; i < map.count(); i++) + { + if ( map[i].lower()[0] == info.driveName.lower()[0] ) + { + if ( map[i].length() < 3 ) + { + return 1; + } + path = map[i].mid(2); // skip e.g. "C=" + found = true; + break; + } + } + + if ( !found ) return 1; // no mapped drive found + + path += '/'; // make sure that the dir ends with / + path += info.path; + } + + kdDebug(7034) << "running:" << path << endl; + KRun * run = new KRun(path); + QObject::connect(run, SIGNAL(finished()), this, SLOT(delayedQuit())); + QObject::connect(run, SIGNAL(error()), this, SLOT(delayedQuit())); + + return exec(); +} + +//-------------------------------------------------------------------------------- +// copied from kfmclient.cc + +void LNKForwarder::delayedQuit() +{ + // Quit in 2 seconds. This leaves time for KRun to pop up + // "app not found" in KProcessRunner, if that was the case. + QTimer::singleShot(2000, this, SLOT(deref())); +} + +//-------------------------------------------------------------------------------- + +#include "lnkforward.moc" diff --git a/kfile-plugins/lnk/lnkforward.desktop b/kfile-plugins/lnk/lnkforward.desktop new file mode 100644 index 0000000..b7e2303 --- /dev/null +++ b/kfile-plugins/lnk/lnkforward.desktop @@ -0,0 +1,114 @@ +[Desktop Entry] +Type=Application +Comment=Start link given in Windows .lnk file +Comment[bg]=Стартиране на файл връзка на Windows +Comment[bs]=Pokreni link dat u Windows .lnk datoteci +Comment[ca]=Inicia l'enllaç donat pel fitxer .lnk de Windows +Comment[cs]=Spustit odkaz daný v .lnk souboru +Comment[da]=Start link givet i Windows .lnk-fil +Comment[de]=Ausführen der Verknüpfung aus einer Windows-Verknüpfungsdatei +Comment[el]=Εκκίνηση του δεσμού που δίνεται στο αρχείο .lnk των Windows +Comment[es]=Inicia el enlace que se encuentra en el archivo .lnk de Windows +Comment[et]=Käivitab Windowsi .lnk-failis antud viida +Comment[eu]=Hasieratu Windowsen .Ink fitxategiaren esteka +Comment[fa]=آغاز پیوند دادهشده در پروندۀ .lnk ویندوز +Comment[fi]=Käynnistä Windows .lnk-tiedostossa annettu linkki +Comment[fr]=Lancer le lien issu d'un fichier « .lnk » Windows +Comment[fy]=Folget keppeling yn de Windows .lnk-triem +Comment[ga]=Nasc tosaigh ón chomhad .lnk Windows +Comment[gl]=Iniciar o enlace dado nun ficheiro .lnk de Windows +Comment[he]=התחל קיצור בקובץ lnk של Windows +Comment[hi]=विंडोज़ के .lnk फ़ाइल में स्टार्ट लिंक दिया गया है +Comment[hr]=Pokretanje veze iz Windows datoteke .lnk +Comment[hu]=Link megnyitása Windows-os Lnk-fájl alapján +Comment[is]=Ræsa tengil í Windows lnk skrá +Comment[it]=Collegamento iniziale dato nel file .lnk di Windows +Comment[ja]=Windows の .lnk ファイルのリンクを開始 +Comment[ka]=Windows .lnk ფაილში მოცემული ბმულის გაშვება +Comment[kk]=Windows .lnk файл сілтегенің жегу +Comment[km]=ចាប់ផ្ដើមតំណដែលបានផ្ដល់ក្នុងបង្អួចឯកសារ .lnk +Comment[lt]=Atverti nuorodą, nurodytą Windows .lnk byloje +Comment[mk]=Ја стартува врската дадена во Windows .lnk-датотека +Comment[ms]=Mulakan pautan yang diberikan dalam Tetingkap. Fail dakwat +Comment[nb]=Start lenka oppgitt i en Windows .lnk-fil +Comment[nds]=Den Link ut Windows-Linkdatei utföhren +Comment[ne]=विन्डोज .lnk फाइलमा दिएको लिङ्क सुरुआत गर्नुहोस् +Comment[nl]=Volgt koppeling in het Windows .lnk-bestand +Comment[nn]=Start lenkja oppgjeve i ei Windows .lnk-fil +Comment[pl]=Uruchamia odnośnik znajdujący się w plikach .lnk systemu Windows +Comment[pt]=Iniciar a ligação definida pelo ficheiro .lnk do Windows +Comment[pt_BR]=Inicia um link fornecido de um arquivo .lnk do Windows +Comment[ru]=Перейти по ссылке из ярлыка Windows (.lnk) +Comment[sk]=Spustenie zadaného odkazu v súbore Windows .lnk +Comment[sl]=Zaženi povezavo, dano v datoteki Windows .lnk +Comment[sr]=Покреће везу дату у Windows-овом .lnk фајлу +Comment[sr@Latn]=Pokreće vezu datu u Windows-ovom .lnk fajlu +Comment[sv]=Starta länk given i en Windows länkfil +Comment[ta]=விண்டோஸ் .lnk fileசில் கொடுக்கப்பட்டதற்கு இணைப்பை துவக்கவும் +Comment[tg]=Гузаштан бо истинод аз ярлиқи Windows (.lnk) +Comment[tr]=Windows .lnk dosyasında verilen başlangıç kısayolu +Comment[uk]=Перейти по посиланню з файла .lnk для Windows +Comment[uz]=Windows .lnk faylida koʻrsatilgan bogʻga oʻtish +Comment[uz@cyrillic]=Windows .lnk файлида кўрсатилган боғга ўтиш +Comment[vi]=Liên kết bắt đầu được ghi trong tập tin .Ink của Windows +Comment[zh_CN]=启动 Windows .lnk 文件中给出的链接 +Comment[zh_TW]=連結 Windows .lnk 檔中指定的網址 +Exec=lnkforward -map C=/mnt/winc +MimeType=application/x-win-lnk +Name=Windows lnk File Forwarder +Name[bg]=Препращане за файл връзка на Windows +Name[bs]=Windows lnk datoteka preusmjerivač +Name[ca]=Enviador de fitxers Windows Ink +Name[cs]=Informace o odkazech +Name[da]=Videresender af Windows ink-fil +Name[de]=Weiterleitung für Windows-Verknüpfungsdateien +Name[el]=Προωθητής αρχείου lnk των Windows +Name[eo]=Vindoza lnk dosiera antaŭigilo +Name[es]=Expedidor de archivos lnk de Windows +Name[et]=Windowsi .lnk-faili käivitaja +Name[eu]=Windowsen Ink fitxategiaren berbidaltzailea +Name[fa]=پیشسوی پروندۀ lnk ویندوز +Name[fi]=Windows lnk-tiedoston edelleenohjaus +Name[fr]=Transmetteur de fichiers « .lnk » Windows +Name[fy]=Windows lnk-triemferwizing +Name[gl]=Reenvio através de Ficheiros Windows lnk +Name[he]=קיצור דרך של Windows +Name[hi]=विंडोज़ लिंक फ़ाइल फॉर्वर्डर +Name[hr]=Prosljeđivanje Windows prečaca +Name[hu]=Windows-os Lnk-fájl továbbítása +Name[is]=Windows lnk skráarframsendir +Name[it]=File lnk di windows con funzione forwarder +Name[ja]=Windows lnk ファイルフォワーダ +Name[ka]=Windows lnk ფაილის გადამცემი +Name[kk]=Windows жарлығының сілтемесіне өту +Name[km]=កម្មវិធីបញ្ជូនបន្តបង្អួចឯកសារ lnk +Name[lt]=Windows lnk bylų nuorodos +Name[mk]=Пренасочувач на Windows lnk-датотеки +Name[ms]=Pemaju Fail Dakwat Tetingkap +Name[nb]=Videresender Windows lnk-fil +Name[nds]=Wiederledden för Windows-Linkdateien +Name[ne]=विन्डोज lnk फाइल अगाडि बढाउने +Name[nl]=Windows lnk-bestandsverwijzing +Name[nn]=Vidaresender Windows lnk-fil +Name[pa]=Windows lnk ਫਾਇਲ ਫਾਰਵਰਡਰ +Name[pl]=Interpretacja plików lnk systemu Windows +Name[pt]=Encaminhamento de Ficheiros do Windows +Name[pt_BR]=Informações de Aplicativos do Windows +Name[ru]=Перенаправление по ярлыку Windows +Name[sk]=Presmerovač súborov Windows lnk +Name[sl]=Posredovalnik za bližnjice v Windows +Name[sr]=Прослеђивач Windows-ових .lnk фајлова +Name[sr@Latn]=Prosleđivač Windows-ovih .lnk fajlova +Name[sv]=Följ Windows länkfil +Name[ta]=விண்டோஸ் மை கோப்பு திருப்புபவன் +Name[tg]=Равона бо ярлиқи Windows +Name[tr]=Windows lnk Dosya Yönlendirici +Name[uk]=Спрямування за файлом lnk для Windows +Name[vi]=Bộ chuyển tiếp tập tin Ink Windows +Name[zh_CN]=Windows lnk 文件转发器 +Name[zh_TW]=Windows lnk 檔轉載 +StartupNotify=false +Terminal=false +X-KDE-SubstituteUID=false +Icon=exec_wine +NoDisplay=true diff --git a/kfile-plugins/lnk/lnkforward.h b/kfile-plugins/lnk/lnkforward.h new file mode 100644 index 0000000..8810902 --- /dev/null +++ b/kfile-plugins/lnk/lnkforward.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This helper app runs the associated action for a linked file inside a * + * M$-Windoze .lnk file, which is useful if you work in a mixed * + * Linux/Windoze environment. * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <kapplication.h> +#include <kcmdlineargs.h> + +#ifndef _LNKFORWARDER_H_ +#define _LNKFORWARDER_H_ + +class LNKForwarder : public KApplication +{ + Q_OBJECT + + public: + int run(KCmdLineArgs *args); + + protected slots: + void delayedQuit(); +}; + +#endif diff --git a/kfile-plugins/lnk/read_lnk.cpp b/kfile-plugins/lnk/read_lnk.cpp new file mode 100644 index 0000000..2d627fb --- /dev/null +++ b/kfile-plugins/lnk/read_lnk.cpp @@ -0,0 +1,227 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This function reads the content of a M$-Windoze .lnk file * + * and returns data in the given structure. * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "read_lnk.h" +#include <stdio.h> +#include <kdebug.h> +#include <kio/netaccess.h> + +//-------------------------------------------------------------------------------- + +//TODO: little/big endian problem ? +struct LNKHeader +{ + char magic[4]; + char GUID[16]; + Q_UINT32 flags; + Q_UINT32 attributes; + char time1[8]; + char time2[8]; + char time3[8]; + Q_UINT32 length; + Q_UINT32 iconNum; + Q_UINT32 showWnd; + Q_UINT32 hotKey; + char filler[8]; +}; + +struct LNKFileLocation +{ + Q_UINT32 totalLen; + Q_UINT32 ptr; + Q_UINT32 flags; + Q_UINT32 localVolume; + Q_UINT32 basePath; + Q_UINT32 netVolume; + Q_UINT32 pathname; +}; + +//-------------------------------------------------------------------------------- + +bool readLNK(const KURL &url, LNKInfo &info) +{ + const char* lnkFile = 0; + + QString tempFile; + if ( KIO::NetAccess::download(url, tempFile, 0) ) + lnkFile = tempFile.latin1(); + else + return false; + + kdDebug(7034) << "opening:" << lnkFile << endl; + FILE *fd = fopen(lnkFile, "rb"); + if ( !fd ) + { + kdWarning(7034) << "could not open file " << lnkFile << endl; + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + LNKHeader header; + + if ( fread(&header, sizeof(header), 1, fd) != 1 ) + { + kdWarning(7034) << "wrong header size" << endl; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + if ( memcmp(header.magic, "L\0\0\0", 4) != 0 ) + { + kdWarning(7034) << "wrong magic in header" << endl; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + if ( header.flags & 0x1 ) // the shell item id list is present + { + Q_UINT16 len; + + // skip that list + if ( (fread(&len, sizeof(len), 1, fd) != 1) || (fseek(fd, len, SEEK_CUR) != 0) ) + { + kdWarning(7034) << "could not read shell item id list" << endl; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + } + + info.isDirectory = (header.attributes & 0x10); + + if ( ! info.isDirectory ) // not a directory + info.fileSize = header.length; + + info.isFileOrDir = (header.flags & 0x2); // points to file or directory + + if ( info.isFileOrDir ) + { + LNKFileLocation loc; + + if ( fread(&loc, sizeof(loc), 1, fd) != 1 ) + { + kdWarning(7034) << "could not read file localtion table" << endl; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + // limit the following "new", because the size to allocate is in the file + // which can easily be manipulted to contain a huge number and lead to a crash + if ( (loc.totalLen <= sizeof(loc)) || (loc.totalLen > 4096) ) // 4096 is just an arbitrary number I think shall be enough + { + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + size_t size = loc.totalLen - sizeof(loc); + char *data = new char[size]; + char *start = data - sizeof(loc); + + if ( fread(data, size, 1, fd) != 1 ) + { + kdWarning(7034) << "could not read pathes data" << endl; + delete [] data; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + info.isNetworkPath = !(loc.flags & 0x1); + + if ( !info.isNetworkPath ) + { + info.volumeName = (start + loc.localVolume + 0x10); // volume label + + info.path = QString::null; + + if ( *(start + loc.basePath) ) + { + // Don't put any more than "X:" into info.driveName. + info.driveName = *(start + loc.basePath); + info.driveName += ':'; + + // If we in fact do have more than just "X:", store any additional + // path information separately in info.path. + if ( *(start + loc.basePath + 1) == ':' && + *(start + loc.basePath + 2) != 0) + info.path = (start + loc.basePath + 2); + } + + if ( *(start + loc.pathname) != 0 ) + { + if ( info.path.isNull() ) + info.path = (start + loc.pathname); + else + info.path = info.path + "\\" + (start + loc.pathname); + } + } + else // network path + { + info.path = QString("%1\\%2") + .arg(start + loc.netVolume + 0x14) // network share name + .arg(start + loc.pathname); + } + + delete [] data; + data = 0; + + if ( header.flags & 0x4 ) // has description string + { + Q_UINT16 len; + + if ( fread(&len, sizeof(len), 1, fd) != 1 ) + { + kdWarning(7034) << "could not read description string length" << endl; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + data = new char[len+1]; // this can never be > 65K, so its OK to not check the size + + if ( fread(data, len, 1, fd) != 1 ) + { + kdWarning(7034) << "could not read description string" << endl; + delete [] data; + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + return false; + } + + data[len] = 0; // nullbyte seems to miss + + info.description = data; + + delete [] data; + } + } + + fclose(fd); + KIO::NetAccess::removeTempFile(tempFile); + + return true; +} diff --git a/kfile-plugins/lnk/read_lnk.h b/kfile-plugins/lnk/read_lnk.h new file mode 100644 index 0000000..da947a1 --- /dev/null +++ b/kfile-plugins/lnk/read_lnk.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This function reads the content of a M$-Windoze .lnk file * + * and returns data in the given structure. * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef _READ_LNK_H_ +#define _READ_LNK_H_ + +#include <qstring.h> +class KURL; + +struct LNKInfo +{ + LNKInfo() : fileSize(0), isNetworkPath(false), isDirectory(false), isFileOrDir(false) {} + + Q_UINT32 fileSize; + bool isNetworkPath; + bool isDirectory; + bool isFileOrDir; + QString volumeName; + QString driveName; + QString path; + QString description; +}; + +bool readLNK(const KURL &url, LNKInfo &info); + +#endif diff --git a/kfile-plugins/lnk/x-win-lnk.desktop b/kfile-plugins/lnk/x-win-lnk.desktop new file mode 100644 index 0000000..18429dc --- /dev/null +++ b/kfile-plugins/lnk/x-win-lnk.desktop @@ -0,0 +1,61 @@ +[Desktop Entry] +Type=MimeType +Comment=Windows Link-File +Comment[bg]=Файл връзка на Windows +Comment[bs]=Windows link datoteka +Comment[ca]=Fitxer enllaç de Windows +Comment[cs]=Soubor s odkazem Windows +Comment[da]=Windows link-fil +Comment[de]=Windows-Verknüpfungsdatei +Comment[el]=Αρχείο δεσμού των Windows +Comment[eo]=Vindoza ligdosiero +Comment[es]=Archivo de enlace de Windows +Comment[et]=Windowsi link-fail +Comment[eu]=Windowsen esteka-fitxategia +Comment[fa]=پروندۀ پیوند ویندوز +Comment[fi]=Windows linkkitiedosto +Comment[fr]=Fichier de lien de Windows +Comment[fy]=Windows snelkeppeling +Comment[ga]=Comhad Naisc Windows +Comment[gl]=Ficheiro Windows Link +Comment[he]=קיצור דרך של Windows +Comment[hi]=विंडो लिंक-फ़ाइल +Comment[hr]=Datoteka Windows prečaca +Comment[hu]=Windows-os Lnk-fájl +Comment[is]=Windows tengiskrá +Comment[it]=Windows file di link +Comment[ja]=Windows リンクファイル +Comment[ka]=Windows-ის ბმულის ფაილი +Comment[kk]=Windows сілтеме файлы +Comment[km]=បង្អួចឯកសារតំណ +Comment[lt]=Windows bylų nuorodos +Comment[mk]=Windows Link-датотека +Comment[ms]=Fail Pautan Tetingkap +Comment[nb]=Windows Link-fil +Comment[nds]=Windows-Linkdatei +Comment[ne]=विन्डोज लिङ्क- फाइल +Comment[nl]=Windows snelkoppeling +Comment[nn]=Windows lenkjefil +Comment[pa]=Windows ਸਬੰਧ-ਫਾਇਲ +Comment[pl]=Plik odnośnika Windows +Comment[pt]=Ficheiro Windows Link +Comment[pt_BR]=Arquivo Link do Windows +Comment[ru]=Ярлык Windows +Comment[sk]=Odkaz Windows +Comment[sl]=Datoteka z bližnjico v Windows +Comment[sr]=Windows-ов фајл везе +Comment[sr@Latn]=Windows-ov fajl veze +Comment[sv]=Windows länkfil +Comment[ta]=விண்டோஸ் இணைப்பு-கோப்பு +Comment[tg]=Ярлиқи Windows +Comment[tr]=Windows Kısayol Dosyası +Comment[uk]=файл посилання для Windows +Comment[uz]=Windows bogʻ fayli +Comment[uz@cyrillic]=Windows боғ файли +Comment[vi]=Tập tin liên kết Windows +Comment[zh_CN]=Windows 快捷方式文件 +Comment[zh_TW]=Windows Link 檔 +Hidden=false +Icon=exec_wine +MimeType=application/x-win-lnk +Patterns=*.lnk diff --git a/kfile-plugins/mhtml/Makefile.am b/kfile-plugins/mhtml/Makefile.am new file mode 100644 index 0000000..326820d --- /dev/null +++ b/kfile-plugins/mhtml/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for folder file meta info plugin + +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_mhtml.h + +kde_module_LTLIBRARIES = kfile_mhtml.la + +kfile_mhtml_la_SOURCES = kfile_mhtml.cpp +kfile_mhtml_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_mhtml_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +services_DATA = kfile_mhtml.desktop +servicesdir = $(kde_servicesdir) + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_mhtml.pot diff --git a/kfile-plugins/mhtml/kfile_mhtml.cpp b/kfile-plugins/mhtml/kfile_mhtml.cpp new file mode 100644 index 0000000..f9ef320 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (C) 2005 by Spiros Georgaras * + * sngeorgaras@otenet.gr * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include <config.h> +#include "kfile_mhtml.h" + +#include <kgenericfactory.h> +#include <kmdcodec.h> +#include <qstring.h> +#include <qcstring.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qtextcodec.h> + +typedef KGenericFactory<mhtmlPlugin> mhtmlFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_mhtml, mhtmlFactory( "kfile_mhtml" )) + +mhtmlPlugin::mhtmlPlugin(QObject *parent, const char *name, + const QStringList &args) + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-mimearchive" ); + KFileMimeTypeInfo::GroupInfo* group = 0L; + group = addGroupInfo(info, "mhtmlInfo", i18n("Document Information")); + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Subject", i18n("Subject"), QVariant::String); + item = addItemInfo(group, "Sender", i18n("Sender"), QVariant::String); + item = addItemInfo(group, "Recipient", i18n("Recipient"), QVariant::String); + item = addItemInfo(group, "CopyTo", i18n("CC"), QVariant::String); + item = addItemInfo(group, "BlindCopyTo", i18n("BCC"), QVariant::String); + item = addItemInfo(group, "Date", i18n("Date"), QVariant::String); +} + +bool mhtmlPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + QString mSender; + QString mRecipient; + QString mCopyTo; + QString mBlindCopyTo; + QString mSubject; + QString mDate; + bool canUnfold; + if ( info.path().isEmpty() ) // remote file + return false; + + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) return false; + QTextStream stream(&f); + QString l=stream.readLine(); + int nFieldsFound = 0; + while(!l.isEmpty()){ + if(l.startsWith("From: ")) { + mSender=l.mid(6); + nFieldsFound |= 1; + canUnfold=TRUE; + } else if(l.startsWith("To: ")) { + mRecipient=l.mid(4); + nFieldsFound |= 2; + canUnfold=TRUE; + } else if(l.startsWith("Subject: ")) { + mSubject=l.mid(9); + nFieldsFound |= 4; + canUnfold=TRUE; + } else if(l.startsWith("Cc: ")) { + mCopyTo=l.mid(4); + nFieldsFound |= 8; + canUnfold=TRUE; + } else if(l.startsWith("Bcc: ")) { + mBlindCopyTo=l.mid(5); + nFieldsFound |= 16; + canUnfold=TRUE; + } else if(l.startsWith("Date: ")) { + mDate=l.mid(6); + nFieldsFound |= 32; + canUnfold=FALSE; + }else if(l.startsWith(" ") || l.startsWith("\t")){ + // unfold field + if(canUnfold){ + QString tmp=l.stripWhiteSpace(); + if(nFieldsFound & 16) mBlindCopyTo=mBlindCopyTo+" "+tmp; + else if(nFieldsFound & 8) mCopyTo=mCopyTo+" "+tmp; + else if(nFieldsFound & 4) mSubject=mSubject+" "+tmp; + else if(nFieldsFound & 2) mRecipient=mRecipient+" "+tmp; + else if(nFieldsFound & 1) mSender=mSender+" "+tmp; + } + }else canUnfold=FALSE; + // break out of the loop once the six fields have been found + if ( nFieldsFound == 32+16+8+4+2+1 ) + break; + l=stream.readLine(); + } + f.close(); + KFileMetaInfoGroup group = appendGroup(info, "mhtmlInfo"); + appendItem(group, "Subject", decodeRFC2047Phrase(mSubject,FALSE)); + appendItem(group, "Sender", decodeRFC2047Phrase(mSender)); + appendItem(group, "Recipient", decodeRFC2047Phrase(mRecipient)); + appendItem(group, "CopyTo", decodeRFC2047Phrase(mCopyTo)); + appendItem(group, "BlindCopyTo", decodeRFC2047Phrase(mBlindCopyTo)); + appendItem(group, "Date", mDate); + return true; +} + +QString mhtmlPlugin::decodeRFC2047Phrase(const QString &msg, bool removeLessGreater){ + int st=msg.find("=?"); + int en=-1; + QString msgCopy=msg; + QString decodedText=msgCopy.left(st); + QString encodedText=msgCopy.mid(st); + st=encodedText.find("=?"); + while(st!=-1){ + en=encodedText.find("?="); + while(encodedText.mid(en+2,1)!=" " && en+2<(int)encodedText.length()) en=encodedText.find("?=",en+1); + if(en==-1) break; + decodedText+=encodedText.left(st); + QString tmp=encodedText.mid(st,en-st+2); + encodedText=encodedText.mid(en+2); + decodedText+=decodeRFC2047String(tmp); + st=encodedText.find("=?",st+1); + } + decodedText += encodedText; + // remove unwanted '<' and '>' + if(removeLessGreater){ + if(decodedText.stripWhiteSpace().startsWith("<") && decodedText.stripWhiteSpace().endsWith(">")){ + QString tmp=decodedText.stripWhiteSpace(); + tmp=tmp.mid(1,tmp.length()-2); + decodedText=tmp; + }else{ + QString dec=decodedText; + QString tmp; + + st=decodedText.find("<"); + while(st!=-1){ + st=dec.find("<",st); + if(st==0 || (st!=0 && (dec.mid(st-2,2)==", "))){ + en=dec.find(">",st); + if(en==-1 && dec.find(",",st)<en){ + st++; + continue; + } + dec=dec.left(st)+dec.mid(st+1,en-st-1)+dec.mid(en+1); + }else if(st!=-1) st++; + } + decodedText=dec; + } + } + return decodedText; +} + +QString mhtmlPlugin::decodeRFC2047String(const QString &msg){ + QString charset; + QString encoding; + QString notEncodedText; + QString encodedText; + QString decodedText; + int encEnd=0; + if(msg.startsWith("=?") && (encEnd=msg.findRev("?="))!=-1){ + notEncodedText=msg.mid(encEnd+2); + encodedText=msg.left(encEnd); + encodedText=encodedText.mid(2,encodedText.length()-2); + int questionMark=encodedText.find('?'); + if(questionMark==-1) return msg; + charset=encodedText.left(questionMark).lower(); + encoding=encodedText.mid(questionMark+1,1).lower(); + if(encoding!="b" && encoding!="q") return msg; + encodedText=encodedText.mid(questionMark+3); + if(charset.find(" ")!=-1 && encodedText.find(" ")!=-1) return msg; + QCString tmpIn; + QCString tmpOut; + tmpIn = encodedText.local8Bit(); + if(encoding=="q")tmpOut=KCodecs::quotedPrintableDecode(tmpIn); + else tmpOut=KCodecs::base64Decode(tmpIn); + if(charset!="us-ascii"){ + QTextCodec *codec = QTextCodec::codecForName(charset.local8Bit()); + if(!codec) return msg; + decodedText=codec->toUnicode(tmpOut); + decodedText=decodedText.replace("_"," "); + }else decodedText=tmpOut.replace("_"," "); + return decodedText + notEncodedText; + }else return msg; +} +#include "kfile_mhtml.moc" + diff --git a/kfile-plugins/mhtml/kfile_mhtml.desktop b/kfile-plugins/mhtml/kfile_mhtml.desktop new file mode 100644 index 0000000..5e73302 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=mhtml Info +Name[bg]=Информация за mhtml +Name[br]=Titouroù mhtml +Name[ca]=Informació mhtml +Name[cs]=mhtml informace +Name[da]=mhtml-info +Name[de]=MHTML-Information +Name[el]=Πληροφορίες mhtml +Name[eo]=mhtml informo +Name[es]=Información mhtml +Name[et]=mhtmli info +Name[eu]=mhtml infoa +Name[fa]=اطلاعات mhtml +Name[fi]=mhtml tiedot +Name[fr]=Informations sur « mhtml » +Name[fy]=mhtml-ynformaasje +Name[ga]=Eolas mhtml +Name[gl]=Información de mhtml +Name[he]=מידע אודות mhtml +Name[hr]=Podaci o mhtml +Name[hu]=Mhtml-információ +Name[is]=Upplýsingar um mhtml +Name[it]=Informazioni su mhtml +Name[ja]=mhtml 情報 +Name[ka]=mhtml ინფორმაცია +Name[kk]=mhtml мәліметі +Name[km]=ព័ត៌មាន mhtml +Name[lt]=mhtml info +Name[mk]=Информации за mhtml +Name[ms]=Maklumat mhtml +Name[nb]=mhtml-informasjon +Name[nds]=MHTML-Informatschonen +Name[ne]=एमएचटीएमएल सूचना +Name[nl]=mhtml-informatie +Name[nn]=mhtml-informasjon +Name[pa]=mhtml ਜਾਣਕਾਰੀ +Name[pl]=Informacja mhtml +Name[pt]=Informações de mhtml +Name[pt_BR]=Informações sobre mhtml +Name[ru]=Информация mhtml +Name[sk]=Informácie o mhtml +Name[sl]=Informacija o mhtml +Name[sr]=MHTML информације +Name[sr@Latn]=MHTML informacije +Name[sv]=MHTML-information +Name[ta]=mhtml தகவல் +Name[tr]=mhtml Bilgisi +Name[uk]=Інформація про mhtml +Name[uz]=mhtml fayllari haqida maʼlumot +Name[uz@cyrillic]=mhtml файллари ҳақида маълумот +Name[vi]=Thông tin mhtml +Name[zh_CN]=mhtml 信息 +Name[zh_TW]=mhtml 資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_mhtml +MimeType=application/x-mimearchive +PreferredGroups=mhtmlInfo +PreferredItems=Subject,Sender,Recipient,CopyTo,BlindCopyTo,Date diff --git a/kfile-plugins/mhtml/kfile_mhtml.h b/kfile-plugins/mhtml/kfile_mhtml.h new file mode 100644 index 0000000..dc29ec3 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Spiros Georgaras * + * sngeorgaras@otenet.gr * + * * + * 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; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#ifndef __KFILE_MHTML_H__ +#define __KFILE_MHTML_H__ + +/** + * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h> + */ +#include <kfilemetainfo.h> + +class QStringList; + +class mhtmlPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + mhtmlPlugin( QObject *parent, const char *name, const QStringList& args ); + virtual bool readInfo( KFileMetaInfo& info, uint what); +private: + QString decodeRFC2047Phrase(const QString &msg, bool removeLessGreater=TRUE); + QString decodeRFC2047String(const QString &msg); +}; + +#endif // __KFILE_MHTML_H__ + diff --git a/kfile-plugins/txt/Makefile.am b/kfile-plugins/txt/Makefile.am new file mode 100644 index 0000000..84e6ce7 --- /dev/null +++ b/kfile-plugins/txt/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for text file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +noinst_HEADERS = kfile_txt.h + +kde_module_LTLIBRARIES = kfile_txt.la + +kfile_txt_la_SOURCES = kfile_txt.cpp +kfile_txt_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_txt_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_txt.pot + +services_DATA = kfile_txt.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/txt/kfile_txt.cpp b/kfile-plugins/txt/kfile_txt.cpp new file mode 100644 index 0000000..02e166c --- /dev/null +++ b/kfile-plugins/txt/kfile_txt.cpp @@ -0,0 +1,129 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org> + * + * 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 "kfile_txt.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <qfile.h> +#include <qstringlist.h> +#include <qregexp.h> + +typedef KGenericFactory<KTxtPlugin> TxtFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_txt, TxtFactory("kfile_txt")) + +KTxtPlugin::KTxtPlugin(QObject *parent, const char *name, + const QStringList &args) : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "Text file meta info plugin\n"; + makeMimeTypeInfo( "text/plain" ); +} + +void KTxtPlugin::makeMimeTypeInfo(const QString& mimeType) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo(mimeType); + + KFileMimeTypeInfo::GroupInfo* group = + addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Lines", i18n("Lines"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Words", i18n("Words"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Characters", i18n("Characters"), QVariant::ULongLong); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Format", i18n("Format"), QVariant::String); +} + +bool KTxtPlugin::readInfo(KFileMetaInfo& info, uint) +{ + if ( info.path().isEmpty() ) // remote file + return false; + + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) + return false; + + bool firstline = true; + int totLines = 0; + int totWords = 0; + unsigned long long totChars = f.size(); + QString fileFormat; + QString line; + bool skipTotals = (totChars > 100*1024); // 100K is the max we read + + unsigned int bytesRead = 0; + while (!f.atEnd()) + { + f.readLine(line, 4096); + + int len = line.length(); + + // The checks below are necessary to handle embedded NULLs + // QFile::readLine() does not handle them well + bytesRead += len; + if (bytesRead > totChars) + break; + if (len == 0) + break; + + if (firstline) + { + firstline = false; + if (line[len-1]=='\n') + { + if (len>=2 && line[len-2]=='\r') + fileFormat = i18n("DOS"); + else + fileFormat = i18n("UNIX"); + } + else if (line[len-1]=='\r') + fileFormat = i18n("Macintosh"); + if (skipTotals) + break; + } + + totWords += (QStringList::split(QRegExp("\\s+"), line)).count(); + totLines++; + } + + if (fileFormat.isEmpty()) + fileFormat = i18n("Unknown"); + + kdDebug(7034) << "Lines: " << totLines << endl; + kdDebug(7034) << "Words: " << totWords << endl; + kdDebug(7034) << "Characters: " << totChars << endl; + kdDebug(7034) << "fileFormat: " << fileFormat << endl; + + KFileMetaInfoGroup group = appendGroup(info, "General"); + if (!skipTotals) + { + appendItem(group, "Lines", totLines); + appendItem(group, "Words", totWords); + } + appendItem(group, "Characters", totChars); + appendItem(group, "Format", fileFormat); + + return true; +} + +#include "kfile_txt.moc" diff --git a/kfile-plugins/txt/kfile_txt.desktop b/kfile-plugins/txt/kfile_txt.desktop new file mode 100644 index 0000000..2c332f3 --- /dev/null +++ b/kfile-plugins/txt/kfile_txt.desktop @@ -0,0 +1,70 @@ +[Desktop Entry] +Type=Service +Name=Text File Info +Name[af]=Teks Lêer Inligting +Name[ar]=معلومات ملف نصي +Name[az]=Mətn Faylı Mə'lumatı +Name[bg]=Информация за текстов файл +Name[br]=Titouroù diwar-benn ar skrid restr +Name[bs]=Info o tekst datoteci +Name[ca]=Info. del fitxer de text +Name[cs]=Info o textovém souboru +Name[cy]=Gwybodaeth Ffeil Testun +Name[da]=Information om tekstfil +Name[de]=Informationen zur Textdatei +Name[el]=Πληροφορίες αρχείου κειμένου +Name[eo]=Tekstdosiera informo +Name[es]=Información del archivo de texto +Name[et]=Tekstifaili info +Name[eu]=Testu fitxategiaren informazioa +Name[fa]=اطلاعات پروندۀ متن +Name[fi]=Tekstitiedoston tiedot +Name[fo]=Tekstfíluupplýsingar +Name[fr]=Informations sur le fichier texte +Name[fy]=Teksttriem-ynfo +Name[gl]=Información de Ficheiro de Texto +Name[he]=מידע קובץ טקסט +Name[hi]=पाठ फ़ाइल जानकारी +Name[hr]=Podaci o tekstualnoj datoteci +Name[hu]=Információ szöveges fájlokról +Name[is]=Upplýsingar um textaskrá +Name[it]=Informazioni File di testo +Name[ja]=テキストファイル情報 +Name[ka]=ტექსტური ფაილის ინფორმაცია +Name[kk]=Мәтін файлдың мәліметі +Name[km]=ព័ត៌មានឯកសារអត្ថបទ +Name[lt]=Teksto bylos informacija +Name[mk]=Информации за текстуална датотека +Name[ms]=Maklumat Fail Teks +Name[nb]=Tekstfilinformasjon +Name[nds]=Textdatei-Informatschonen +Name[ne]=पाठ फाइल सूचना +Name[nl]=Tekstbestand-info +Name[nn]=Informasjon om tekstfil +Name[pa]=ਪਾਠ ਫਾਇਲ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o plikach tekstowych +Name[pt]=Informações de Ficheiros de Texto +Name[pt_BR]=Informações Sobre Arquivo texto +Name[ro]=Informaţii fişier text +Name[ru]=Информация о текстовом файле +Name[sk]=Informácie o textovom súbore +Name[sl]=Informacije o besedilni datoteki +Name[sr]=Информације о текстуалном фајлу +Name[sr@Latn]=Informacije o tekstualnom fajlu +Name[sv]=Information om textfil +Name[ta]=உரைக் கோப்பு தகவல் +Name[tg]=Ахборот дар бораи файли матнӣ +Name[th]=ข้อมูลแฟ้มข้อความ +Name[tr]=Metin Dosyası Bilgisi +Name[uk]=Інформація про текстовий файл +Name[uz]=Matn fayli haqida maʼlumot +Name[uz@cyrillic]=Матн файли ҳақида маълумот +Name[vi]=Thông tin tập tin văn bản +Name[xh]=Ulwazi Lombhalo Wefayile +Name[zh_CN]=文本文件信息 +Name[zh_TW]=文字檔案資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_txt +MimeType=text/plain +PreferredGroups=General +PreferredItems=Lines,Words,Characters,Format diff --git a/kfile-plugins/txt/kfile_txt.h b/kfile-plugins/txt/kfile_txt.h new file mode 100644 index 0000000..9b0196d --- /dev/null +++ b/kfile-plugins/txt/kfile_txt.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org> + * + * 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_TXT_H_ +#define __KFILE_TXT_H_ + +#include <kfilemetainfo.h> + +class QStringList; + +class KTxtPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KTxtPlugin(QObject *parent, const char *name, const QStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: + void makeMimeTypeInfo(const QString& mimeType); +}; + +#endif |