From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- kghostview/infodialog.cpp | 131 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 kghostview/infodialog.cpp (limited to 'kghostview/infodialog.cpp') diff --git a/kghostview/infodialog.cpp b/kghostview/infodialog.cpp new file mode 100644 index 00000000..b9cc8a91 --- /dev/null +++ b/kghostview/infodialog.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2000 the KGhostView authors. See file AUTHORS. + * + * 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 +#include +#include +#include +#include + +#include +#include +#include + +#include "infodialog.h" + +// +// Using KDialogBase in message box mode (gives centered action button) +// +InfoDialog::InfoDialog( QWidget *parent, const char *name, bool modal ) + :KDialogBase( i18n("Document Information"), Yes, Yes, Yes, parent, + name, modal, true, KStdGuiItem::ok() ) +{ + QFrame *page = makeMainWidget(); + QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); + QGridLayout *glay = new QGridLayout( topLayout, 3, 2 ); + glay->setColStretch(1,1); + + QLabel *label = new QLabel( i18n("File name:" ), page ); + glay->addWidget( label, 0, 0, AlignRight|AlignVCenter ); + mFileLabel = new QLabel( page ); + glay->addWidget( mFileLabel, 0, 1 ); + + label = new QLabel( i18n("Document title:" ), page ); + glay->addWidget( label, 1, 0, AlignRight|AlignVCenter ); + mTitleLabel = new QLabel( page ); + glay->addWidget( mTitleLabel, 1, 1 ); + + label = new QLabel( i18n("Publication date:" ), page ); + glay->addWidget( label, 2, 0, AlignRight|AlignVCenter ); + mDateLabel = new QLabel( page ); + glay->addWidget( mDateLabel, 2, 1 ); + + topLayout->addStretch(1); +} + +namespace { + /* For PDF files, the dates are in a standard format. + * + * According to the spec at http://partners.adobe.com/asn/tech/pdf/specifications.jsp + * That format is "(D:YYYYMMDDHHmmSSOHH'mm')", where + * YYYY is year, + * MM month + * DD day + * HH hour + * mm minute + * SS second + * O is "+" or "-" + * HH is hour + * mm is minute + * + * OHH'mm' form together the desviation to UCT time ( the timezone ). + * Everything after the YYYY is optional. + * The D: is "highly recommended", but legally optional + * + * For PS files, there is no such standard and dates appear + * in any format they desire. + */ + QString parseDate( const QString& dateStr ) { + kdDebug( 4500 ) << "parseDate( \"" << dateStr << "\" )" << endl; + QRegExp exp( "\\((?:D:)?" + "(\\d\\d\\d\\d)" + "(\\d\\d)?(\\d\\d)?(\\d\\d)?.*" + "(\\d\\d)?(\\d\\d)?.*" + "(?:(\\+|\\-)(\\d\\d)\'?(\\d\\d)\'?)?" + "\\)" ); + if ( exp.exactMatch( dateStr ) ) { + QStringList list = exp.capturedTexts(); + QStringList::iterator iter = list.begin(); + ++iter; // whole string! +#undef GET +#define GET( variable, def ) \ + unsigned variable = def; \ + if ( iter != list.end() ) { \ + variable = ( *iter ).toUInt();\ + ++iter; \ + } + GET( year, 1 ) + GET( month, 1 ) + GET( day, 1 ) + GET( hour, 0 ) + GET( min, 0 ) + GET( sec, 0 ) +#undef GET + // FIXME: this ignores the timezone + QDate date( year, month, day ); + QTime time( hour, min, sec ); + KLocale locale( "kghostview" ); + return locale.formatDateTime( QDateTime( date, time ) ); + } + kdDebug( 4500 ) << "parseDate failed." << endl; + return dateStr; + } +} + +void InfoDialog::setup( const QString &fileName, const QString &documentTitle, + const QString &publicationDate ) +{ + mFileLabel->setText( fileName ); + mTitleLabel->setText( documentTitle ); + mDateLabel->setText( parseDate( publicationDate ) ); +} + +#include "infodialog.moc" + +// vim:sw=4:sts=4:ts=8:noet -- cgit v1.2.1