]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgChangeLogView.cc
b5c44a9a2b6e4425b068e3d4835f49f523bded86
[duncan/yast2-qt4.git] / src / pkg / YQPkgChangeLogView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQPkgChangeLogView.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17   Textdomain    "packages-qt"
18
19 /-*/
20
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23
24 #include <qregexp.h>
25 #include "YQPkgChangeLogView.h"
26 #include "YQPkgDescriptionDialog.h"
27 #include "YQi18n.h"
28 #include "utf8.h"
29
30
31
32 YQPkgChangeLogView::YQPkgChangeLogView( QWidget * parent )
33     : YQPkgGenericDetailsView( parent )
34 {
35 }
36
37
38 YQPkgChangeLogView::~YQPkgChangeLogView()
39 {
40     // NOP
41 }
42
43
44 void
45 YQPkgChangeLogView::showDetails( ZyppSel selectable )
46 {
47     _selectable = selectable;
48
49     if ( ! selectable )
50     {
51         clear();
52         return;
53     }
54
55     QString html = htmlHeading( selectable,
56                                 true ); // showVersion
57     
58     ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
59
60     if ( installed )
61     {
62         html += changeLogTable( installed->changelog() );
63     }
64     else
65     {
66         html += "<p><i>" + _( "Information only available for installed packages." ) + "</i></p>";
67     }
68
69     setTextFormat( Qt::RichText );
70     setText( html );
71 }
72
73
74
75 QString YQPkgChangeLogView::changeLogTable( const zypp::Changelog & changeLog ) const
76 {
77     QString html;
78
79     for ( zypp::Changelog::const_iterator it = changeLog.begin();
80           it != changeLog.end();
81           ++it )
82     {
83         QString changes = htmlEscape( fromUTF8( (*it).text() ) );
84         changes.replace( "\n", "<br>" );
85         changes.replace( " ", "&nbsp;" );
86
87         html += row(
88                     cell( (*it).date()   ) +
89                     cell( (*it).author() ) +
90                     "<td valign=top>" + changes + "</td>" // cell() calls htmlEscape() !
91                     );
92     }
93
94     return html.isEmpty() ? "" : table( html );
95 }
96
97
98 #include "YQPkgChangeLogView.moc"