libyui-qt-pkg  2.47.5
YQPkgGenericDetailsView.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: YQPkgGenericDetailsView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 #define YUILogComponent "qt-pkg"
41 #include "YUILog.h"
42 #include <QTabWidget>
43 #include <QRegExp>
44 #include <QDateTime>
45 
46 #include "YQPkgGenericDetailsView.h"
47 #include "YQi18n.h"
48 #include "utf8.h"
49 #include "QY2Styler.h"
50 
51 using std::string;
52 
54  : QTextBrowser( parent )
55 {
56  _selectable = 0;
57  _parentTab = dynamic_cast<QTabWidget *> (parent);
58 
59  if ( _parentTab )
60  {
61  connect( _parentTab, &QTabWidget::currentChanged,
63  }
64 
65  QString css;
66  css = "table.stats"
67  "{text-align: center;"
68  "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif ;"
69  "font-weight: normal;"
70  "font-size: small;"
71  "width: 100%;"
72  ""
73  "border: 1px;"
74  "border-collapse: collapse;"
75  "border-spacing: 4px;}"
76  ""
77  "table.stats td"
78  "{"
79  "padding: 4px;"
80  "text-align: left;"
81  "border: 1px; solid;"
82  "}"
83  ""
84  "table.stats td.hed"
85  "{"
86  "padding: 4px;"
87  "text-align: left;"
88  "border-bottom: 2px; solid;"
89  "font-size: small;"
90  "font-weight: bold;} "
91  "p.note"
92  "{color: grey;"
93  "font-style: italic;}";
94 
95  document()->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );
96 }
97 
98 
100 {
101  // NOP
102 }
103 
104 
105 void
107 {
108  if ( _parentTab && _parentTab->widget(newCurrent) == this )
109  {
110  showDetailsIfVisible( _selectable );
111  }
112 }
113 
114 
115 void
117 {
118  _selectable = selectable;
119 
120  if ( _parentTab ) // Is this view embedded into a tab widget?
121  {
122  if ( _parentTab->currentWidget() == this ) // Is this page the topmost?
123  {
124  showDetails( selectable );
125  }
126  }
127  else // No tab parent - simply show data unconditionally.
128  {
129  showDetails( selectable );
130  }
131 }
132 
133 
134 QSize
136 {
137  return QSize( 0, 0 );
138 }
139 
140 
141 QString
143 {
144  return "<html><head>"
145  "<link rel='stylesheet' type='text/css' href='format.css'>"
146  "</head><body>";
147 }
148 
149 QString
150 YQPkgGenericDetailsView::htmlEnd()
151 {
152  return "</body></html>";
153 }
154 
155 
156 QString
157 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
158 {
159  if ( ! selectable )
160  return "";
161 
162  ZyppObj zyppObj = selectable->theObj();
163 
164  if ( ! zyppObj )
165  return "";
166 
167  QString summary = fromUTF8( zyppObj->summary() );
168 
169  QString html = "<table";
170 
171  if ( ! QY2Styler::styler()->usingAlternateStyleSheet() )
172  html += " class=\"stats\"";
173 
174  html += "><tr><td><b>"
175  + fromUTF8( zyppObj->name() )
176  + "</b>";
177 
178  if ( showVersion )
179  html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
180 
181  if ( ! summary.isEmpty() )
182  html += " - " + summary;
183 
184  html += "</td></tr></table>";
185 
186  return html;
187 }
188 
189 
190 
191 QString
192 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
193 {
194  QString html = plainText;
195  // yuiDebug() << "Escaping \"" << plainText << "\"" << endl;
196 
197  html.replace( QRegExp( "&" ), "&amp;" );
198  html.replace( QRegExp( "<" ), "&lt;" );
199  html.replace( QRegExp( ">" ), "&gt;" );
200 
201  return html;
202 }
203 
204 
205 QString
206 YQPkgGenericDetailsView::table( const QString & contents )
207 {
208  QString html = "<table";
209  if ( ! QY2Styler::styler()->usingAlternateStyleSheet() )
210  html += " class=\"stats\"";
211 
212  html += ">" + contents + "</table>";
213 
214  return html;
215 }
216 
217 
218 QString
219 YQPkgGenericDetailsView::row( const QString & contents )
220 {
221  return "<tr>" + contents + "</tr>";
222 }
223 
224 
225 QString
226 YQPkgGenericDetailsView::cell( QString contents )
227 {
228  contents = htmlEscape( contents );
229  return "<td>" + contents + "</td>";
230 }
231 
232 
233 QString
234 YQPkgGenericDetailsView::cell( int contents )
235 {
236  return QString( "<td>%1</td>" ).arg( contents );
237 }
238 
239 
240 QString
241 YQPkgGenericDetailsView::cell( const zypp::Date & date )
242 {
243  return cell( ( (time_t) date == (time_t) 0 ? "" : date.asString() ) );
244 }
245 
246 
247 QString
248 YQPkgGenericDetailsView::cell( const string & contents )
249 {
250  return cell( fromUTF8( contents ) );
251 }
252 
253 
254 QString
256 {
257  return "<td>" + contents + "</td>";
258 }
259 
260 
static QString hcell(QString contents)
Returns a string containing a HTML table cell with &#39;contents&#39; for table headers.
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
Returns a uniform heading in HTML format for the specified selectable: name and summary or name...
void reloadTab(int newCurrent)
Show data for the last package.
static QString cell(QString contents)
Returns a string containing a HTML table cell with &#39;contents&#39;.
virtual void showDetails(ZyppSel selectable)=0
Show details for the specified package.
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; -> ...
void showDetailsIfVisible(ZyppSel selectable)
Show details for the specified package.
static QString table(const QString &contents)
Returns a string containing a HTML table with &#39;contents&#39;.
virtual ~YQPkgGenericDetailsView()
Destructor.
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
YQPkgGenericDetailsView(QWidget *parent)
Constructor.