]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgFileListView.cc
9e44daf99950dd17984f164959bd21ad062dca38
[duncan/yast2-qt4.git] / src / pkg / YQPkgFileListView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQPkgFileListView.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 "YQPkgFileListView.h"
26 #include "YQPkgDescriptionDialog.h"
27 #include "YQi18n.h"
28 #include "utf8.h"
29
30
31 #define MAX_LINES 5000
32
33
34 YQPkgFileListView::YQPkgFileListView( QWidget * parent )
35     : YQPkgGenericDetailsView( parent )
36 {
37 }
38
39
40 YQPkgFileListView::~YQPkgFileListView()
41 {
42     // NOP
43 }
44
45
46 void
47 YQPkgFileListView::showDetails( ZyppSel selectable )
48 {
49     _selectable = selectable;
50
51     if ( ! selectable )
52     {
53         clear();
54         return;
55     }
56
57     QString html = htmlHeading( selectable,
58                                 true ); // showVersion
59     
60     ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
61
62     if ( installed )
63     {
64         html += formatFileList( installed->filenames() );
65     }
66     else
67     {
68         html += "<p><i>" + _( "Information only available for installed packages." ) + "</i></p>";
69     }
70
71     setTextFormat( Qt::RichText );
72     setText( html );
73 }
74
75
76
77 QString YQPkgFileListView::formatFileList( const list<string> & fileList ) const
78 {
79     QString html;
80     unsigned line_count = 0;
81
82     for ( list<string>::const_iterator it = fileList.begin();
83           it != fileList.end() && line_count < MAX_LINES;
84           ++it, ++line_count )
85     {
86         QString line = htmlEscape( fromUTF8( *it ) );
87
88         if ( line.contains( "/bin/"  ) ||
89              line.contains( "/sbin/" )   )
90         {
91             line = "<b>" + line + "</b>";
92         }
93
94         html += line + "<br>";
95     }
96
97     if ( fileList.size() > MAX_LINES )
98     {
99         html += "...<br>";
100         html += "...<br>";
101     }
102
103     // %1 is the total number of files in a file list
104     html += "<br>" + _( "%1 files total" ).arg( (unsigned long) fileList.size() );
105
106     return "<p>" + html + "</p>";
107 }
108
109
110 #include "YQPkgFileListView.moc"