libyui-qt-pkg  2.47.5
YQPkgTechnicalDetailsView.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: YQPkgTechnicalDetailsView.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 "YQPkgTechnicalDetailsView.h"
46 #include "YQi18n.h"
47 #include "utf8.h"
48 
49 using std::list;
50 using std::string;
51 
52 
54  : YQPkgGenericDetailsView( parent )
55 {
56 }
57 
58 
60 {
61  // NOP
62 }
63 
64 
65 void
67 {
68  _selectable = selectable;
69 
70  if ( ! selectable )
71  {
72  clear();
73  return;
74  }
75 
76 
77 
78  QString html_text = htmlStart();
79 
80  html_text += htmlHeading( selectable );
81 
82  ZyppPkg candidate = tryCastToZyppPkg( selectable->candidateObj() );
83  ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
84 
85  if ( candidate && installed && candidate != installed )
86  {
87  html_text += complexTable( selectable, installed, candidate );
88  }
89  else
90  {
91  if ( candidate )
92  html_text += simpleTable( selectable, candidate );
93 
94  if ( installed )
95  html_text += simpleTable( selectable, installed );
96  }
97 
98  html_text += htmlEnd();
99 
100  setHtml( html_text );
101 }
102 
103 
104 QString
106 {
107  QString html = "<td align='top'>";
108  QString line;
109  list<string> authors = pkg->authors();
110  list<string>::const_iterator it = authors.begin();
111 
112  while ( it != authors.end() )
113  {
114  line = fromUTF8( *it );
115  line = htmlEscape( line );
116  html += line + "<br>";
117  ++it;
118  }
119 
120  html += "</td>";
121 
122  return html;
123 }
124 
125 
126 QString
128  ZyppPkg pkg )
129 {
130  QString html;
131 
132  html += row( hcell( _( "Version:" ) ) + cell( pkg->edition().asString() ) );
133  html += row( hcell( _( "Build Time:" ) ) + cell( pkg->buildtime() ) );
134 
135  html +=
136  *pkg == selectable->installedObj() ?
137  row( hcell( _( "Install Time:" ) ) + cell( pkg->installtime() ) ) : "";
138 
139  html += row( hcell( _( "License:" ) ) + cell( pkg->license() ) );
140  html += row( hcell( _( "Installed Size:" ) ) + cell( pkg->installSize().asString() ) );
141  html += row( hcell( _( "Download Size:" ) ) + cell( pkg->downloadSize().asString() ) );
142  html += row( hcell( _( "Distribution:" ) ) + cell( pkg->distribution() ) );
143  html += row( hcell( _( "Vendor:" ) ) + cell( pkg->vendor() ) );
144  html += row( hcell( _( "Packager:" ) ) + cell( pkg->packager() ) );
145  html += row( hcell( _( "Architecture:" ) ) + cell( pkg->arch().asString() ) );
146  html += row( hcell( _( "Build Host:" ) ) + cell( pkg->buildhost() ) );
147  html += row( hcell( _( "URL:" ) ) + cell( pkg->url() ) );
148  html += row( hcell( _( "Source Package:" ) ) + cell( pkg->sourcePkgName() + "-" + pkg->sourcePkgEdition().asString() ) );
149  html += row( hcell( _( "Media No.:" ) ) + cell( pkg->mediaNr() ) );
150  html += row( hcell( _( "Authors:" ) ) + authorsListCell( pkg ) );
151 
152  html = "<br>" + table( html );
153 
154  return html;
155 }
156 
157 
158 QString
160  ZyppPkg installed,
161  ZyppPkg candidate )
162 {
163  ZyppPkg p1 = candidate;
164  ZyppPkg p2 = installed;
165 
166  QString p1_header = _( "<b>Alternate Version</b>" );
167  QString p2_header = _( "<b>Installed Version</b>" );
168 
169  QString html;
170 
171  html += row( hcell( QString( "" ) ) + hcell( "<b>" + p1_header + "</b>" ) + hcell( "<b>" + p2_header + "</b>" ) );
172 
173  html += row( hcell( _( "Version:" ) ) + cell( p1->edition().asString() ) + cell( p2->edition().asString() ) );
174  html += row( hcell( _( "Build Time:" ) ) + cell( p1->buildtime() ) + cell( p2->buildtime() ) );
175  html += row( hcell( _( "Install Time:" ) ) + cell( p1->installtime() ) + cell( p2->installtime() ) );
176  html += row( hcell( _( "License:" ) ) + cell( p1->license() ) + cell( p2->license() ) );
177  html += row( hcell( _( "Installed Size:" ) ) + cell( p1->installSize().asString() ) + cell( p2->installSize().asString() ) );
178  html += row( hcell( _( "Download Size:" ) ) + cell( p1->downloadSize().asString() ) + cell( p2->downloadSize().asString() ) );
179  html += row( hcell( _( "Distribution:" ) ) + cell( p1->distribution() ) + cell( p2->distribution() ) );
180  html += row( hcell( _( "Vendor:" ) ) + cell( p1->vendor() ) + cell( p2->vendor() ) );
181  html += row( hcell( _( "Packager:" ) ) + cell( p1->packager() ) + cell( p2->packager() ) );
182  html += row( hcell( _( "Architecture:" ) ) + cell( p1->arch().asString() ) + cell( p2->arch().asString() ) );
183  html += row( hcell( _( "Build Host:" ) ) + cell( p1->buildhost() ) + cell( p2->buildhost() ) );
184  html += row( hcell( _( "URL:" ) ) + cell( p1->url() ) + cell( p2->url() ) );
185  html += row( hcell( _( "Source Package:" ) ) + cell( p1->sourcePkgName() + "-" + p1->sourcePkgEdition().asString() )
186  + cell( p2->sourcePkgName() + "-" + p2->sourcePkgEdition().asString() ) );
187  html += row( hcell( _( "Media No.:" ) ) + cell( p1->mediaNr() ) + cell( p2->mediaNr() ) );
188  html += row( hcell( _( "Authors:" ) ) + authorsListCell( p1 ) + authorsListCell( p2 ) );
189 
190 
191  html = "<br>" + table( html );
192 
193  return html;
194 }
195 
196 
static QString hcell(QString contents)
Returns a string containing a HTML table cell with &#39;contents&#39; for table headers.
virtual ~YQPkgTechnicalDetailsView()
Destructor.
virtual void showDetails(ZyppSel selectable)
Show details for the specified zypp::ResObject: In this case technical data, very much like "rpm -qi"...
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.
static QString cell(QString contents)
Returns a string containing a HTML table cell with &#39;contents&#39;.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: &#39;<&#39; -> &#39;<&#39; &#39;>&#39; -> &#39;>&#39; &#39;&&#39; -> ...
QString complexTable(ZyppSel selectable, ZyppPkg installedPkg, ZyppPkg candidatePkg)
Returns a string containing a HTML table for technical details for two package instances: The install...
QString authorsListCell(ZyppPkg pkg) const
Returns a string containing HTML code for a package&#39;s authors list.
YQPkgTechnicalDetailsView(QWidget *parent)
Constructor.
QString simpleTable(ZyppSel selectable, ZyppPkg pkg)
Returns a string containing a HTML table for technical details for one package.
static QString table(const QString &contents)
Returns a string containing a HTML table with &#39;contents&#39;.
static QString row(const QString &contents)
Returns a string containing a HTML table row with &#39;contents&#39;.
static QString htmlStart()
starts the html tag and set the style