libyui-qt-pkg  2.45.15
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 // how many change log entries should be displayed at most,
52 // displaying huge changes takes too much time (bsc#1044777)
53 static const int MAX_DISPLAYED_CHANGES = 512;
54 
56  : YQPkgGenericDetailsView( parent )
57 {
58 }
59 
60 
62 {
63  // NOP
64 }
65 
66 
67 void
68 YQPkgChangeLogView::showDetails( ZyppSel selectable )
69 {
70  _selectable = selectable;
71 
72  if ( ! selectable )
73  {
74  clear();
75  return;
76  }
77 
78  yuiDebug() << "Generating changelog..." << std::endl;
79 
80  QString html = htmlStart();
81  html += htmlHeading( selectable, false );
82 
83  ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
84 
85  if ( installed )
86  {
87  html += changeLogTable( installed->changelog() );
88 
89  int not_displayed = installed->changelog().size() - MAX_DISPLAYED_CHANGES;
90  if (not_displayed > 0)
91  {
92  yuiWarning() << "Changelog size limit reached, ignoring last "
93  << not_displayed << " items" << std::endl;
94  html.append("<p class='note'>"
95  + notDisplayedChanges(not_displayed, installed->name() + "-" + installed->edition().asString())
96  + "</p>");
97  }
98  }
99  else
100  {
101  html += "<p><i>" + _( "Information only available for installed packages." ) + "</i></p>";
102  }
103  html += htmlEnd();
104 
105  yuiDebug() << "Changelog HTML size: " << html.size() << std::endl;
106  setHtml( html );
107  yuiDebug() << "Changes displayed" << std::endl;
108 }
109 
110 
111 
112 QString YQPkgChangeLogView::changeLogTable( const zypp::Changelog & changeLog ) const
113 {
114  yuiDebug() << "Changelog size: " << changeLog.size() << " entries" << std::endl;
115  QString html;
116 
117  int index = 0;
118  for ( zypp::Changelog::const_iterator it = changeLog.begin();
119  it != changeLog.end();
120  ++it )
121  {
122  QString changes = htmlEscape( fromUTF8( (*it).text() ) );
123  changes.replace( "\n", "<br>" );
124  changes.replace( " ", "&nbsp;" );
125 
126  html += row(
127  cell( (*it).date() ) +
128  cell( (*it).author() ) +
129  "<td valign='top'>" + changes + "</td>" // cell() calls htmlEscape() !
130  );
131 
132  if (++index == MAX_DISPLAYED_CHANGES)
133  break;
134  }
135 
136  return html.isEmpty() ? "" : table( html );
137 }
138 
139 QString YQPkgChangeLogView::notDisplayedChanges(int missing, const std::string &pkg)
140 {
141  // TRANSLATORS: The package change log is too long to display, only the latest
142  // changes are displayed. %1 is the number of the items which are not displayed,
143  // %2 contains a command for getting the full changes manually.
144  QString msg = _("(%1 more change entries are not displayed. Run \""
145  "%2\" to see the complete change log.)");
146 
147  QString cmd = QString("rpm -q --changelog %1").arg(pkg.c_str());
148  return msg.arg(QString::number(missing), cmd);
149 }
150 
151 #include "YQPkgChangeLogView.moc"
virtual ~YQPkgChangeLogView()
Destructor.
QString changeLogTable(const zypp::Changelog &changeLog) const
Format a change log list in HTML.
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 &#39;contents&#39;.
YQPkgChangeLogView(QWidget *parent)
Constructor.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: &#39;<&#39; -> &#39;<&#39; &#39;>&#39; -> &#39;>&#39; &#39;&&#39; -> ...
static QString table(const QString &contents)
Returns a string containing a HTML table with &#39;contents&#39;.
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 &#39;contents&#39;.
static QString htmlStart()
starts the html tag and set the style
QString notDisplayedChanges(int missing, const std::string &pkg)
Format an info message about not displayed changes.