]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgFileListView.cc
don't create QObjects in ycp thread - make timeouts work
[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>
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     setHtml( html );
72 }
73
74
75
76 QString YQPkgFileListView::formatFileList( const list<string> & fileList ) const
77 {
78     QString html;
79     unsigned line_count = 0;
80
81     for ( list<string>::const_iterator it = fileList.begin();
82           it != fileList.end() && line_count < MAX_LINES;
83           ++it, ++line_count )
84     {
85         QString line = htmlEscape( fromUTF8( *it ) );
86
87         if ( line.contains( "/bin/"  ) ||
88              line.contains( "/sbin/" )   )
89         {
90             line = "<b>" + line + "</b>";
91         }
92
93         html += line + "<br>";
94     }
95
96     if ( fileList.size() > MAX_LINES )
97     {
98         html += "...<br>";
99         html += "...<br>";
100     }
101
102     // %1 is the total number of files in a file list
103     html += "<br>" + _( "%1 files total" ).arg( (unsigned long) fileList.size() );
104
105     return "<p>" + html + "</p>";
106 }
107
108
109 #include "YQPkgFileListView.moc"