libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgFileListView.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: YQPkgFileListView.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>
46 #include "YQPkgFileListView.h"
47 #include "YQPkgDescriptionDialog.h"
48 #include "YQi18n.h"
49 #include "utf8.h"
50 
51 
52 #define MAX_LINES 500
53 
54 
56  : YQPkgGenericDetailsView( parent )
57 {
58 }
59 
60 
62 {
63  // NOP
64 }
65 
66 
67 void
68 YQPkgFileListView::showDetails( ZyppSel selectable )
69 {
70  _selectable = selectable;
71 
72  if ( ! selectable )
73  {
74  clear();
75  return;
76  }
77 
78  QString html = htmlHeading( selectable,
79  false ); // showVersion
80 
81  ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
82 
83  if ( installed )
84  {
85  // ma@: It might be worth passing Package::FileList directly
86  // instead of copying _all_ filenames into a list first.
87  // Package::FileList is a query, so it does not eat much memory.
88  zypp::Package::FileList f( installed->filelist() );
89  std::list<std::string> tmp( f.begin(), f.end() );
90  html += formatFileList( tmp );
91  }
92  else
93  {
94  html += "<p><i>" + _( "Information only available for installed packages." ) + "</i></p>";
95  }
96 
97  setHtml( html );
98 }
99 
100 
101 
102 QString YQPkgFileListView::formatFileList( const list<string> & fileList ) const
103 {
104  QString html;
105  unsigned line_count = 0;
106 
107  for ( list<string>::const_iterator it = fileList.begin();
108  it != fileList.end() && line_count < MAX_LINES;
109  ++it, ++line_count )
110  {
111  QString line = htmlEscape( fromUTF8( *it ) );
112 
113  if ( line.contains( "/bin/" ) ||
114  line.contains( "/sbin/" ) )
115  {
116  line = "<b>" + line + "</b>";
117  }
118 
119  html += line + "<br>";
120  }
121 
122  if ( fileList.size() > MAX_LINES )
123  {
124  html += "...<br>";
125  html += "...<br>";
126  }
127  else
128  {
129  // %1 is the total number of files in a file list
130  html += "<br>" + _( "%1 files total" ).arg( (unsigned long) fileList.size() );
131  }
132 
133  return "<p>" + html + "</p>";
134 }
135 
136 
137 #include "YQPkgFileListView.moc"
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.
virtual void showDetails(ZyppSel selectable)
Show details for the specified package: In this case the package description.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: '<' -> '<' '>' -> '>' '&' -> ...
QString formatFileList(const list< string > &fileList) const
Format a file list in HTML.
YQPkgFileListView(QWidget *parent)
Constructor.
virtual ~YQPkgFileListView()
Destructor.