summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/dvi
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kfile-plugins/dvi
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.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/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfile-plugins/dvi')
-rw-r--r--kfile-plugins/dvi/Makefile.am22
-rw-r--r--kfile-plugins/dvi/kfile_dvi.cpp150
-rw-r--r--kfile-plugins/dvi/kfile_dvi.desktop60
-rw-r--r--kfile-plugins/dvi/kfile_dvi.h37
4 files changed, 269 insertions, 0 deletions
diff --git a/kfile-plugins/dvi/Makefile.am b/kfile-plugins/dvi/Makefile.am
new file mode 100644
index 00000000..61791bdc
--- /dev/null
+++ b/kfile-plugins/dvi/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for the dvi 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_dvi.h
+
+kde_module_LTLIBRARIES = kfile_dvi.la
+
+kfile_dvi_la_SOURCES = kfile_dvi.cpp
+kfile_dvi_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_dvi_la_LIBADD = $(LIB_KIO)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kfile_dvi.pot
+
+services_DATA = kfile_dvi.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kfile-plugins/dvi/kfile_dvi.cpp b/kfile-plugins/dvi/kfile_dvi.cpp
new file mode 100644
index 00000000..4140b98b
--- /dev/null
+++ b/kfile-plugins/dvi/kfile_dvi.cpp
@@ -0,0 +1,150 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Matthias Witzgall <witzi@gmx.net>
+ *
+ * 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.
+ *
+ */
+
+
+/* further informations about the dvi file format could be downloaded from: http://www.rpi.edu/~sofkam/DVI/archive/standards/dvistd0.dvi */
+
+#include "kfile_dvi.h"
+
+#include <kgenericfactory.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kfilemetainfo.h>
+
+#include <qstring.h>
+#include <qvariant.h>
+#include <qdatetime.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qregexp.h>
+
+
+// preprocessormacro K_EXPORT_COMPONENT_FACTORY loads shared library 'kfile_dvi.so' dynamic if necessary
+typedef KGenericFactory<KDviPlugin> DviFactory;
+K_EXPORT_COMPONENT_FACTORY(kfile_dvi, DviFactory("kfile_dvi"))
+
+KDviPlugin::KDviPlugin (QObject * parent, const char * name, const QStringList & preferredItems)
+ : KFilePlugin(parent, name, preferredItems)
+{
+ kdDebug(7034) << "dvi plugin" << endl;
+
+ // set up our mime type
+ KFileMimeTypeInfo * info = this->addMimeTypeInfo("application/x-dvi");
+
+
+ KFileMimeTypeInfo::GroupInfo * group = this->addGroupInfo(info, "General", "General");
+
+ this->addItemInfo(group, "3_Created", i18n("Created"), QVariant::String);
+ this->addItemInfo(group, "6_Comment", i18n("Comment"), QVariant::String);
+ this->addItemInfo(group, "7_Pages", i18n("Pages"), QVariant::UInt);
+}
+
+bool KDviPlugin::readInfo (KFileMetaInfo & info, uint /* what (unused in this plugin) */)
+{
+ if ( info.path().isEmpty() )
+ return false;
+ KFileMetaInfoGroup GeneralGroup = appendGroup(info, "General");
+ QFile f(info.path());
+ QFileInfo f_info;
+ Q_UINT16 bytes_to_read;
+ Q_UINT8 comment_length;
+ QString comment;
+ Q_UINT16 pages;
+ Q_UINT8 buffer[270]; // buffer for reading data; no data is read with more than 270 bytes
+ Q_UINT32 ptr;
+ int i; // running index
+
+ // open file and try to get the comment
+ f.open(IO_ReadOnly);
+
+ if ( f.isOpen() == false ){
+ kdDebug(7034) << "cannot open file" << endl;
+ return false;
+ }
+
+ f_info.setFile(f); // create fileinfoobject
+ bytes_to_read = QMIN(f_info.size(), 270); // check, if the file size is smaller than 270 bytes
+ // (if the comment is as large as possible, we don't have to
+ // read more than 270 bytes)
+
+ if ( f.readBlock((char *)buffer, bytes_to_read) != bytes_to_read ){ // cast to (char *) is necessary
+ kdDebug(7034) << "read error (1)" << endl;
+ return false;
+ }
+
+ if ( (buffer[0] != 247) || (buffer[1] != 2) ){
+ // magic numbers are not right
+ kdDebug(7034) << "wrong file format" << endl;;
+ return false;
+ }
+
+ comment_length = buffer[14]; // set up length of comment
+ comment.setLength(comment_length); // used to avoid permanent reallocation when extracting the comment from buffer
+
+ for ( i = 15; i <= 14+comment_length; ++i ) // extract comment from buffer
+ comment[i-15] = (char)buffer[i];
+
+ appendItem(GeneralGroup, "6_Comment", comment.simplifyWhiteSpace() );
+
+ // comment is ok, now get total number of pages
+ f.at( f.size() - 13);
+ if ( f.readBlock((char *)buffer, 13) != 13 ){
+ kdDebug(7034) << "read error (2)" << endl;
+ return false;
+ }
+
+ i = 12; // reset running index i
+ while ( buffer[i] == 223 ){ --i; } // skip all trailing bytes
+
+ if ( (buffer[i] != 2) || (i > 8) || (i < 5) ){
+ kdDebug(7034) << "wrong file formatx" << endl;
+ return false;
+ }
+
+ // now we know the position of the pointer to the beginning of the postamble and we can read it
+ ptr = buffer[i-4];
+ ptr = (ptr << 8) | buffer[i-3];
+ ptr = (ptr << 8) | buffer[i-2];
+ ptr = (ptr << 8) | buffer[i-1];
+
+ // bytes for total number of pages have a offset of 27 to the beginning of the postamble
+ f.at(ptr + 27);
+
+ // now read total number of pages from file
+ if ( f.readBlock((char *)buffer, 2) != 2 ){
+ kdDebug(7034) << "read error (3)" << endl;
+ return false;
+ }
+ pages = buffer[0];
+ pages = (pages << 8) | buffer[1];
+
+ appendItem(GeneralGroup, "7_Pages", QVariant(pages) );
+
+ f.close();
+
+ // now get and set up some basic informations about the file (same informations would be displayed, if there is no dvi-plugin)
+ appendItem(GeneralGroup, "1_Type", QVariant( i18n("TeX Device Independent file") ) ); // set up type of file
+
+ appendItem(GeneralGroup, "4_Modified", QVariant(f_info.lastModified().toString("yyyy-MM-dd hh:mm")) );
+ // ISO 8601 date format (without seconds)
+
+ return true;
+}
+
+#include "kfile_dvi.moc"
diff --git a/kfile-plugins/dvi/kfile_dvi.desktop b/kfile-plugins/dvi/kfile_dvi.desktop
new file mode 100644
index 00000000..ed640afb
--- /dev/null
+++ b/kfile-plugins/dvi/kfile_dvi.desktop
@@ -0,0 +1,60 @@
+[Desktop Entry]
+Icon=
+MimeType=application/x-dvi
+Name=DVI Info
+Name[ar]=معلومات DVI
+Name[br]=Titouroù DVI
+Name[ca]=Informació de DVI
+Name[cs]=DVI info
+Name[cy]=Gwybodaeth DVI
+Name[da]=DVI-info
+Name[de]=DVI-Info
+Name[el]=Πληροφορίες DVI
+Name[eo]=DVI-informo
+Name[es]=Info DVI
+Name[et]=DVI info
+Name[fa]=اطلاعات DVI
+Name[fi]=DVI-tiedot
+Name[fr]=Informations DVI
+Name[ga]=Eolas faoi DVI
+Name[gl]=Inf. DVI
+Name[he]=מידע DVI
+Name[hi]=DVI जानकारी
+Name[hu]=DVI-jellemzők
+Name[is]=DVI upplýsingar
+Name[it]=Informazioni DVI
+Name[ja]=DVI 情報
+Name[kk]=DVI мәліметі
+Name[km]=ព័ត៌មាន DVI
+Name[lt]=DVI informacija
+Name[ms]=Maklumat DVI
+Name[nds]=DVI-Info
+Name[ne]=DVI सूचना
+Name[nl]=DVI-info
+Name[nn]=DVI-info
+Name[pa]=DVI ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o pliku DVI
+Name[pt]=Informação do DVI
+Name[pt_BR]=Informação sobre DVI
+Name[ro]=Informaţii DVI
+Name[ru]=Информация о DVI
+Name[se]=DVI-dieđut
+Name[sl]=Podatki o DVI
+Name[sr]=DVI информације
+Name[sr@Latn]=DVI informacije
+Name[sv]=DVI-information
+Name[ta]=DVI தகவல்
+Name[tg]=Иттилоот оиди DVI
+Name[th]=ข้อมูลแฟ้ม DVI
+Name[tr]=DVI Bilgisi
+Name[uk]=Інформація по DVI
+Name[uz]=DVI haqida maʼlumot
+Name[uz@cyrillic]=DVI ҳақида маълумот
+Name[wa]=Informåcion sol documint DVI
+Name[zh_CN]=DVI 信息
+Name[zh_HK]=DVI 資訊
+Name[zh_TW]=DVI 資訊
+ServiceTypes=KFilePlugin
+Type=Service
+X-KDE-Library=kfile_dvi
+PreferredItems=Title,Author,Subject,Creator,Producer,CreationDate,ModDate,Keywords
diff --git a/kfile-plugins/dvi/kfile_dvi.h b/kfile-plugins/dvi/kfile_dvi.h
new file mode 100644
index 00000000..66e7b218
--- /dev/null
+++ b/kfile-plugins/dvi/kfile_dvi.h
@@ -0,0 +1,37 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Matthias Witzgall <witzi@gmx.net>
+ *
+ * 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_DVI_H__
+#define __KFILE_DVI_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+
+class KDviPlugin : public KFilePlugin
+{
+ Q_OBJECT
+public:
+ KDviPlugin ( QObject * parent, const char * name, const QStringList & preferredItems );
+
+ virtual bool readInfo (KFileMetaInfo & info, uint what);
+};
+
+#endif