]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgChangeLogView.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[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     setHtml( html );
70 }
71
72
73
74 QString YQPkgChangeLogView::changeLogTable( const zypp::Changelog & changeLog ) const
75 {
76     QString html;
77
78     for ( zypp::Changelog::const_iterator it = changeLog.begin();
79           it != changeLog.end();
80           ++it )
81     {
82         QString changes = htmlEscape( fromUTF8( (*it).text() ) );
83         changes.replace( "\n", "<br>" );
84         changes.replace( " ", "&nbsp;" );
85
86         html += row(
87                     cell( (*it).date()   ) +
88                     cell( (*it).author() ) +
89                     "<td valign=top>" + changes + "</td>" // cell() calls htmlEscape() !
90                     );
91     }
92
93     return html.isEmpty() ? "" : table( html );
94 }
95
96
97 #include "YQPkgChangeLogView.moc"