libyui-qt-pkg  2.45.5
 All Classes Functions Variables Enumerations
YQPkgDependenciesView.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: YQPkgDependenciesView.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 <qdatetime.h>
46 #include "YQPkgDependenciesView.h"
47 #include "YQi18n.h"
48 #include "utf8.h"
49 
50 
52  : YQPkgGenericDetailsView( parent )
53 {
54 }
55 
56 
58 {
59  // NOP
60 }
61 
62 
63 void
65 {
66  _selectable = selectable;
67 
68  if ( ! selectable )
69  {
70  clear();
71  return;
72  }
73 
74  QString html_text = htmlStart();
75  html_text += htmlHeading( selectable );
76 
77  ZyppObj candidate = selectable->candidateObj();
78  ZyppObj installed = selectable->installedObj();
79 
80  if ( candidate && installed && candidate != installed )
81  {
82  html_text += complexTable( installed, candidate );
83  }
84  else
85  {
86  if ( candidate )
87  html_text += simpleTable( candidate );
88 
89  if ( installed )
90  html_text += simpleTable( installed );
91  }
92 
93  html_text += htmlEnd();
94 
95  setHtml( html_text );
96 }
97 
98 
99 QString
101 {
102  QString html = "<br>" +
103  table(
104  row( hcell( _( "Version:" ) ) + cell( pkg->edition().asString() ) ) +
105 
106  row( _("Provides:"), pkg->dep( zypp::Dep::PROVIDES ) ) +
107  row( _("Prerequires:"), pkg->dep( zypp::Dep::PREREQUIRES ) ) +
108  row( _("Requires:"), pkg->dep( zypp::Dep::REQUIRES ) ) +
109  row( _("Conflicts:"), pkg->dep( zypp::Dep::CONFLICTS ) ) +
110  row( _("Obsoletes:"), pkg->dep( zypp::Dep::OBSOLETES ) ) +
111  row( _("Recommends:"), pkg->dep( zypp::Dep::RECOMMENDS ) ) +
112  row( _("Suggests:"), pkg->dep( zypp::Dep::SUGGESTS ) ) +
113  row( _("Enhances:"), pkg->dep( zypp::Dep::ENHANCES ) ) +
114  row( _("Supplements:"), pkg->dep( zypp::Dep::SUPPLEMENTS ) )
115  );
116 
117  return html;
118 }
119 
120 
121 QString
122 YQPkgDependenciesView::complexTable( ZyppObj installed, ZyppObj candidate )
123 {
124  ZyppObj p1 = candidate;
125  ZyppObj p2 = installed;
126 
127  QString p1_header = _( "<b>Alternate Version</b>" );
128  QString p2_header = _( "<b>Installed Version</b>" );
129 
130  QString html = "<br>" +
131  table(
132  row( hcell( QString( "" ) ) + hcell( "<b>" + p1_header + "</b>" ) + hcell( "<b>" + p2_header + "</b>" ) ) +
133 
134  row( hcell( _( "Version:" ) ) + cell( p1->edition().asString() ) + cell( p2->edition().asString() ) ) +
135 
136  row( _("Provides:"), p1->dep( zypp::Dep::PROVIDES ), p2->dep( zypp::Dep::PROVIDES ) ) +
137  row( _("Prerequires:"), p1->dep( zypp::Dep::PREREQUIRES ), p2->dep( zypp::Dep::PREREQUIRES ) ) +
138  row( _("Requires:"), p1->dep( zypp::Dep::REQUIRES ), p2->dep( zypp::Dep::REQUIRES ) ) +
139  row( _("Conflicts:"), p1->dep( zypp::Dep::CONFLICTS ), p2->dep( zypp::Dep::CONFLICTS ) ) +
140  row( _("Obsoletes:"), p1->dep( zypp::Dep::OBSOLETES ), p2->dep( zypp::Dep::OBSOLETES ) ) +
141  row( _("Recommends:"), p1->dep( zypp::Dep::RECOMMENDS ), p2->dep( zypp::Dep::RECOMMENDS ) ) +
142  row( _("Suggests:"), p1->dep( zypp::Dep::SUGGESTS ), p2->dep( zypp::Dep::SUGGESTS ) ) +
143  row( _("Enhances:"), p1->dep( zypp::Dep::ENHANCES ), p2->dep( zypp::Dep::ENHANCES ) ) +
144  row( _("Supplements:"), p1->dep( zypp::Dep::SUPPLEMENTS ), p2->dep( zypp::Dep::SUPPLEMENTS ) )
145  );
146 
147  return html;
148 }
149 
150 
151 QString
152 YQPkgDependenciesView::row( const QString & heading,
153  const zypp::Capabilities & capSet )
154 {
155  QString content = htmlLines( capSet );
156 
157  if ( content.isEmpty() )
158  return "";
159 
160  return QString( "<tr>" ) +
161  hcell( heading ) +
162  "<td>" + content + "</td>"
163  + "</tr>";
164 }
165 
166 
167 QString
168 YQPkgDependenciesView::row( const QString & heading,
169  const zypp::Capabilities & capSet1,
170  const zypp::Capabilities & capSet2 )
171 {
172  QString content1 = htmlLines( capSet1 );
173  QString content2 = htmlLines( capSet2 );
174 
175  if ( content1.isEmpty() && content2.isEmpty() )
176  return "";
177 
178  return QString( "<tr>" ) +
179  hcell( heading ) +
180  "<td>" + content1 + "</td>" +
181  "<td>" + content2 + "</td>" +
182  "</tr>";
183 }
184 
185 
186 QString
187 YQPkgDependenciesView::htmlLines( const zypp::Capabilities & capSet )
188 {
189  QString html;
190 
191  for ( zypp::Capabilities::const_iterator it = capSet.begin();
192  it != capSet.end();
193  ++it )
194  {
195  if ( ! html.isEmpty() )
196  html += "<br>";
197 
198  html += htmlEscape( ( *it).asString().c_str() );
199  }
200 
201  return html;
202 }
203 
204 
205 #include "YQPkgDependenciesView.moc"
static QString hcell(QString contents)
Returns a string containing a HTML table cell with 'contents' for table headers.
static QString row(const QString &heading, const zypp::Capabilities &capSet)
Format a zypp::CapSet (describing zypp::Dep::REQUIRES etc.) with a heading in HTML lines...
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
Returns a uniform heading in HTML format for the specified selectable: name and summary or name...
YQPkgDependenciesView(QWidget *parent)
Constructor.
Abstract base class for details views.
QString simpleTable(ZyppObj pkg)
Returns a string containing a HTML table for technical details for one package.
static QString cell(QString contents)
Returns a string containing a HTML table cell with 'contents'.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: '<' -> '<' '>' -> '>...
virtual ~YQPkgDependenciesView()
Destructor.
static QString table(const QString &contents)
Returns a string containing a HTML table with 'contents'.
static QString htmlLines(const zypp::Capabilities &capSet)
Format a zypp::Capabilities (describing zypp::Dep::REQUIRES etc.) in HTML lines, separated with ...
QString complexTable(ZyppObj installed, ZyppObj candidate)
Returns a string containing a HTML table for technical details for two package instances: The install...
static QString htmlStart()
starts the html tag and set the style
virtual void showDetails(ZyppSel selectable)
Show details for the specified selectable: In this case technical data, very much like "rpm -qi"...