diff options
Diffstat (limited to 'kfile-plugins/xbm')
-rw-r--r-- | kfile-plugins/xbm/Makefile.am | 22 | ||||
-rw-r--r-- | kfile-plugins/xbm/kfile_xbm.cpp | 128 | ||||
-rw-r--r-- | kfile-plugins/xbm/kfile_xbm.desktop | 65 | ||||
-rw-r--r-- | kfile-plugins/xbm/kfile_xbm.h | 42 |
4 files changed, 257 insertions, 0 deletions
diff --git a/kfile-plugins/xbm/Makefile.am b/kfile-plugins/xbm/Makefile.am new file mode 100644 index 00000000..1b9d7ff9 --- /dev/null +++ b/kfile-plugins/xbm/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for xbm 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_xbm.h + +kde_module_LTLIBRARIES = kfile_xbm.la + +kfile_xbm_la_SOURCES = kfile_xbm.cpp +kfile_xbm_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_xbm_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) kfile_xbm.cpp -o $(podir)/kfile_xbm.pot + +services_DATA = kfile_xbm.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/xbm/kfile_xbm.cpp b/kfile-plugins/xbm/kfile_xbm.cpp new file mode 100644 index 00000000..d62471f5 --- /dev/null +++ b/kfile-plugins/xbm/kfile_xbm.cpp @@ -0,0 +1,128 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "kfile_xbm.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <qdict.h> +#include <qvalidator.h> +#include <qcstring.h> +#include <qfile.h> +#include <qdatetime.h> + +#if !defined(__osf__) +#include <inttypes.h> +#else +typedef unsigned short uint32_t; +#endif + +typedef KGenericFactory<KXbmPlugin> XbmFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_xbm, XbmFactory( "kfile_xbm" )) + +KXbmPlugin::KXbmPlugin(QObject *parent, const char *name, + const QStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-xbm" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), QVariant::Size); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit(item, KFileMimeTypeInfo::Pixels); +} + + +unsigned long KXbmPlugin::xbm_processLine(char * linebuf) +{ + const char * fsig = "#define "; + + // check it starts with #define + if (memcmp(linebuf, fsig, 8)) + return 0; + + // scan for the 2nd space and set up a pointer + uint32_t slen = strlen(linebuf); + bool done = false; + uint32_t spos = 0; + unsigned char spacecount = 0; + do { + + if (linebuf[spos] == 0x00) + return 0; + + if (linebuf[spos] == ' ') + ++spacecount; + + if (spacecount == 2) + done = true; + else + ++spos; + + } while (!done); + + return atoi(linebuf + spos); +} + + +bool KXbmPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + + QFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl; + return false; + } + + // we need a buffer for lines + char linebuf[1000]; + + // read the first line + file.readLine(linebuf, sizeof( linebuf )); + uint32_t width = xbm_processLine(linebuf); + + // read the 2nd line + file.readLine(linebuf, sizeof( linebuf )); + uint32_t height = xbm_processLine(linebuf); + + if ((width > 0) && (height > 0)) { + // we have valid looking data + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + appendItem(group, "Dimensions", QSize(width, height)); + return true; + } + + return false; +} + +#include "kfile_xbm.moc" diff --git a/kfile-plugins/xbm/kfile_xbm.desktop b/kfile-plugins/xbm/kfile_xbm.desktop new file mode 100644 index 00000000..c33407ac --- /dev/null +++ b/kfile-plugins/xbm/kfile_xbm.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=XBM Info +Name[af]=Xbm Inligting +Name[ar]=معلومات XBM +Name[br]=Titouroù XBM +Name[ca]=Informació d'XBM +Name[cs]=XBM info +Name[cy]=Gwybodaeth XBM +Name[da]=XBM-info +Name[de]=XBM-Info +Name[el]=Πληροφορίες XBM +Name[eo]=XBM-informo +Name[es]=Info XBM +Name[et]=XBM info +Name[fa]=اطلاعات XBM +Name[fi]=XBM-tiedot +Name[fr]=Informations sur XBM +Name[gl]=Inf. XBM +Name[he]=מידע XBM +Name[hi]=XBM जानकारी +Name[hr]=XBM Infoformacije +Name[hu]=XBM-jellemzők +Name[is]=XBM upplýsingar +Name[it]=Informazioni XBM +Name[ja]=XBM 情報 +Name[kk]=XBM мәліметі +Name[km]=ព័ត៌មាន XBM +Name[lt]=XBM informacija +Name[ms]=Maklumat XBM +Name[nds]=XBM-Info +Name[ne]=XBM सूचना +Name[nl]=XBM-info +Name[nn]=XBM-info +Name[nso]=Tshedimoso ya XBM +Name[pa]=XBM ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku XBM +Name[pt]=Informação do XBM +Name[pt_BR]=Informação sobre XBM +Name[ro]=Informaţii XBM +Name[ru]=Информация о XBM +Name[se]=XBM-dieđut +Name[sl]=Podatki o XBM +Name[sr]=XBM информације +Name[sr@Latn]=XBM informacije +Name[sv]=XBM-information +Name[ta]=XBM தகவல் +Name[tg]=Иттилоот оиди XBM +Name[th]=ข้อมูลแฟ้ม XBM +Name[tr]=XBM Bilgisi +Name[uk]=Інформація по XBM +Name[uz]=XBM haqida maʼlumot +Name[uz@cyrillic]=XBM ҳақида маълумот +Name[ven]=Mafhungo a XBM +Name[wa]=Informåcion sol imådje XBM +Name[xh]=Ulwazi lwe XBM +Name[zh_CN]=XBM 信息 +Name[zh_HK]=XBM 資訊 +Name[zh_TW]=XBM 資訊 +Name[zu]=Ulwazi lwe-XBM +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_xbm +MimeType=image/x-xbm +PreferredGroups=Technical +PreferredItems=Resolution diff --git a/kfile-plugins/xbm/kfile_xbm.h b/kfile-plugins/xbm/kfile_xbm.h new file mode 100644 index 00000000..8cc571e1 --- /dev/null +++ b/kfile-plugins/xbm/kfile_xbm.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_XBM_H__ +#define __KFILE_XBM_H__ + +#include <kfilemetainfo.h> + +class QStringList; + +class KXbmPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KXbmPlugin( QObject *parent, const char *name, const QStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); + +private: + + unsigned long xbm_processLine(char * linebuf); + +}; + +#endif |