libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgChangeLogView.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgChangeLogView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #define YUILogComponent "qt-pkg"
43 #include "YUILog.h"
44 
45 #include <qregexp.h>
46 #include "YQPkgChangeLogView.h"
47 #include "YQPkgDescriptionDialog.h"
48 #include "YQi18n.h"
49 #include "utf8.h"
50 
51 
52 
54  : YQPkgGenericDetailsView( parent )
55 {
56 }
57 
58 
60 {
61  // NOP
62 }
63 
64 
65 void
66 YQPkgChangeLogView::showDetails( ZyppSel selectable )
67 {
68  _selectable = selectable;
69 
70  if ( ! selectable )
71  {
72  clear();
73  return;
74  }
75 
76  QString html = htmlStart();
77  html += htmlHeading( selectable, false );
78 
79  ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
80 
81  if ( installed )
82  {
83  html += changeLogTable( installed->changelog() );
84  }
85  else
86  {
87  html += "<p><i>" + _( "Information only available for installed packages." ) + "</i></p>";
88  }
89  html += htmlEnd();
90 
91  setHtml( html );
92 }
93 
94 
95 
96 QString YQPkgChangeLogView::changeLogTable( const zypp::Changelog & changeLog ) const
97 {
98  QString html;
99 
100  for ( zypp::Changelog::const_iterator it = changeLog.begin();
101  it != changeLog.end();
102  ++it )
103  {
104  QString changes = htmlEscape( fromUTF8( (*it).text() ) );
105  changes.replace( "\n", "<br>" );
106  changes.replace( " ", "&nbsp;" );
107 
108  html += row(
109  cell( (*it).date() ) +
110  cell( (*it).author() ) +
111  "<td valign='top'>" + changes + "</td>" // cell() calls htmlEscape() !
112  );
113  }
114 
115  return html.isEmpty() ? "" : table( html );
116 }
117 
118 
119 #include "YQPkgChangeLogView.moc"
virtual ~YQPkgChangeLogView()
Destructor.
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
Returns a uniform heading in HTML format for the specified selectable: name and summary or name...
Abstract base class for details views.
static QString cell(QString contents)
Returns a string containing a HTML table cell with 'contents'.
YQPkgChangeLogView(QWidget *parent)
Constructor.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: '<' -> '<' '>' -> '>' '&' -> ...
static QString table(const QString &contents)
Returns a string containing a HTML table with 'contents'.
virtual void showDetails(ZyppSel selectable)
Show details for the specified package: In this case the package description.
static QString row(const QString &contents)
Returns a string containing a HTML table row with 'contents'.
static QString htmlStart()
starts the html tag and set the style
QString changeLogTable(const zypp::Changelog &changeLog) const
Format a change log list in HTML.