TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.1KB

  1. /*
  2. * Copyright (C) 2000 the KGhostView authors. See file AUTHORS.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. */
  19. #include <tqframe.h>
  20. #include <tqlabel.h>
  21. #include <tqlayout.h>
  22. #include <tqdatetime.h>
  23. #include <tqregexp.h>
  24. #include <kdebug.h>
  25. #include <tdelocale.h>
  26. #include <kstdguiitem.h>
  27. #include "infodialog.h"
  28. //
  29. // Using KDialogBase in message box mode (gives centered action button)
  30. //
  31. InfoDialog::InfoDialog( TQWidget *parent, const char *name, bool modal )
  32. :KDialogBase( i18n("Document Information"), Yes, Yes, Yes, parent,
  33. name, modal, true, KStdGuiItem::ok() )
  34. {
  35. TQFrame *page = makeMainWidget();
  36. TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
  37. TQGridLayout *glay = new TQGridLayout( topLayout, 3, 2 );
  38. glay->setColStretch(1,1);
  39. TQLabel *label = new TQLabel( i18n("File name:" ), page );
  40. glay->addWidget( label, 0, 0, AlignRight|AlignVCenter );
  41. mFileLabel = new TQLabel( page );
  42. glay->addWidget( mFileLabel, 0, 1 );
  43. label = new TQLabel( i18n("Document title:" ), page );
  44. glay->addWidget( label, 1, 0, AlignRight|AlignVCenter );
  45. mTitleLabel = new TQLabel( page );
  46. glay->addWidget( mTitleLabel, 1, 1 );
  47. label = new TQLabel( i18n("Publication date:" ), page );
  48. glay->addWidget( label, 2, 0, AlignRight|AlignVCenter );
  49. mDateLabel = new TQLabel( page );
  50. glay->addWidget( mDateLabel, 2, 1 );
  51. topLayout->addStretch(1);
  52. }
  53. namespace {
  54. /* For PDF files, the dates are in a standard format.
  55. *
  56. * According to the spec at http://partners.adobe.com/asn/tech/pdf/specifications.jsp
  57. * That format is "(D:YYYYMMDDHHmmSSOHH'mm')", where
  58. * YYYY is year,
  59. * MM month
  60. * DD day
  61. * HH hour
  62. * mm minute
  63. * SS second
  64. * O is "+" or "-"
  65. * HH is hour
  66. * mm is minute
  67. *
  68. * OHH'mm' form together the desviation to UCT time ( the timezone ).
  69. * Everything after the YYYY is optional.
  70. * The D: is "highly recommended", but legally optional
  71. *
  72. * For PS files, there is no such standard and dates appear
  73. * in any format they desire.
  74. */
  75. TQString parseDate( const TQString& dateStr ) {
  76. kdDebug( 4500 ) << "parseDate( \"" << dateStr << "\" )" << endl;
  77. TQRegExp exp( "\\((?:D:)?"
  78. "(\\d\\d\\d\\d)"
  79. "(\\d\\d)?(\\d\\d)?(\\d\\d)?.*"
  80. "(\\d\\d)?(\\d\\d)?.*"
  81. "(?:(\\+|\\-)(\\d\\d)\'?(\\d\\d)\'?)?"
  82. "\\)" );
  83. if ( exp.exactMatch( dateStr ) ) {
  84. TQStringList list = exp.capturedTexts();
  85. TQStringList::iterator iter = list.begin();
  86. ++iter; // whole string!
  87. #undef GET
  88. #define GET( variable, def ) \
  89. unsigned variable = def; \
  90. if ( iter != list.end() ) { \
  91. variable = ( *iter ).toUInt();\
  92. ++iter; \
  93. }
  94. GET( year, 1 )
  95. GET( month, 1 )
  96. GET( day, 1 )
  97. GET( hour, 0 )
  98. GET( min, 0 )
  99. GET( sec, 0 )
  100. #undef GET
  101. // FIXME: this ignores the timezone
  102. TQDate date( year, month, day );
  103. TQTime time( hour, min, sec );
  104. TDELocale locale( "kghostview" );
  105. return locale.formatDateTime( TQDateTime( date, time ) );
  106. }
  107. kdDebug( 4500 ) << "parseDate failed." << endl;
  108. return dateStr;
  109. }
  110. }
  111. void InfoDialog::setup( const TQString &fileName, const TQString &documentTitle,
  112. const TQString &publicationDate )
  113. {
  114. mFileLabel->setText( fileName );
  115. mTitleLabel->setText( documentTitle );
  116. mDateLabel->setText( parseDate( publicationDate ) );
  117. }
  118. #include "infodialog.moc"
  119. // vim:sw=4:sts=4:ts=8:noet