[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH]: KFileMetaInfo and pdf
From: Rolf Magnus <ramagnus () t-online ! de>
Date: 2002-03-08 23:41:25
[Download RAW message or body]
Ok, this patch should fix both issues.
["kfile_pdf2.diff" (text/x-diff)]
Index: kfile_pdf.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kfile-plugins/pdf/kfile_pdf.cpp,v
retrieving revision 1.8
diff -u -3 -p -r1.8 kfile_pdf.cpp
--- kfile_pdf.cpp 2002/02/26 04:01:51 1.8
+++ kfile_pdf.cpp 2002/03/08 23:35:55
@@ -21,8 +21,6 @@
#include "kfile_pdf.h"
#include <kurl.h>
-#include <kprocess.h>
-#include <klocale.h>
#include <kgenericfactory.h>
#include <kdebug.h>
#include <kprocess.h>
@@ -48,9 +46,10 @@ bool KPdfPlugin::readInfo( KFileMetaInfo
{
KProcess p;
p << "pdfinfo" << info.path();
-
+ p.setEnvironment("LC_TIME", "C");
+
m_info = info;
-
+
QObject::connect(&p, SIGNAL(receivedStdout(KProcess*, char*, int)),
this, SLOT(slotReceivedStdout(KProcess*, char*, int)));
@@ -60,12 +59,47 @@ bool KPdfPlugin::readInfo( KFileMetaInfo
return false;
}
kdDebug(7034) << "subprocess finished\n";
-
+
info.setPreferredKeys(m_preferred);
info.setSupportsVariableKeys(false);
return true;
-}
+}
+QDateTime KPdfPlugin::pdfDate(const QString& s) const
+{
+ QRegExp rePdfDate("^([0-9]{4})([0-9]{2})?([0-9]{2})?([0-9]{2})?([0-9]{2})?([0-9]{2})?(?:(\\+|-|Z)([0-9]{2})'([0-9]{2})')?$");
+ QDateTime dt;
+ if (rePdfDate.search(s) > -1)
+ {
+ // pdfinfo < 1.00 returns date in YYYYMMDDHHmmSSOHH'mm'
+ int year = rePdfDate.cap(1).toInt();
+ int month = rePdfDate.cap(2).toInt();
+ int day = rePdfDate.cap(3).toInt();
+ QDate d = QDate(year, month, day);
+ int hour = rePdfDate.cap(4).toInt();
+ int min = rePdfDate.cap(5).toInt();
+ int sec = rePdfDate.cap(6).toInt();
+ QTime t = QTime(hour, min, sec);
+ dt.setDate(d);
+ dt.setTime(t);
+ QString zone = rePdfDate.cap(7);
+ if (!zone.isEmpty())
+ {
+ // Convert to UTC
+ int diff = rePdfDate.cap(8).toInt() * 3600;
+ diff += rePdfDate.cap(9).toInt() * 60;
+ if (zone == "+")
+ diff *= -1;
+ dt = dt.addSecs(diff);
+ }
+ }
+ else
+ {
+ // pdfinfo >= 1.00 returns date in C (text) format
+ dt = QDateTime::fromString(s);
+ }
+ return dt;
+}
void KPdfPlugin::slotReceivedStdout(KProcess*, char* buffer, int buflen)
{
@@ -77,27 +111,32 @@ void KPdfPlugin::slotReceivedStdout(KPro
QStringList l = QStringList::split("\n", s);
QStringList keys;
-
+
QStringList::Iterator it = l.begin();
for (; it != l.end(); ++it ) {
kdDebug() << *it << endl;
if ((*it).startsWith("CreationDate"))
{
- m_info.insert(KFileMetaInfoItem("Created", i18n("Created"),
- QVariant((*it).mid(13).stripWhiteSpace())));
+ //QDateTime dt = pdfDate("Thu Apr 22 13:01:41 1999");
+ QDateTime dt = pdfDate((*it).mid(13).stripWhiteSpace());
+ if (dt.isValid())
+ m_info.insert(KFileMetaInfoItem("Created", i18n("Created"),
+ QVariant(dt)));
}
else if ((*it).startsWith("ModDate"))
{
- m_info.insert(KFileMetaInfoItem("Modified", i18n("Modified"),
- QVariant((*it).mid(8).stripWhiteSpace())));
+ QDateTime dt = pdfDate((*it).mid(8).stripWhiteSpace());
+ if (dt.isValid())
+ m_info.insert(KFileMetaInfoItem("Modified", i18n("Modified"),
+ QVariant(dt)));
}
- else if ((*it).startsWith("Pages:"))
+ else if ((*it).startsWith("Pages"))
{
m_info.insert(KFileMetaInfoItem("Pages", i18n("Pages"),
QVariant((*it).mid(7).stripWhiteSpace().toInt())));
}
- else if ((*it).startsWith("Encrypted:"))
+ else if ((*it).startsWith("Encrypted"))
{
bool b = ((*it).mid(10).stripWhiteSpace() == "yes") ? true : false;
m_info.insert(KFileMetaInfoItem("Encrypted", i18n("Encrypted"),
Index: kfile_pdf.h
===================================================================
RCS file: /home/kde/kdegraphics/kfile-plugins/pdf/kfile_pdf.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 kfile_pdf.h
--- kfile_pdf.h 2002/02/26 04:01:51 1.3
+++ kfile_pdf.h 2002/03/08 23:35:55
@@ -34,11 +34,12 @@ public:
const QStringList& preferredItems );
virtual bool readInfo( KFileMetaInfo::Internal& info, int );
-
+
private slots:
void slotReceivedStdout(KProcess* p, char* buffer, int buflen);
private:
+ QDateTime pdfDate(const QString& s) const;
KFileMetaInfo::Internal m_info;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic