libyui-qt-pkg  2.45.6
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 "YQUI.h"
49 #include "utf8.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 
92  document()->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );
93 }
94 
95 
97 {
98  // NOP
99 }
100 
101 
102 void
104 {
105  if ( _parentTab && _parentTab->widget(newCurrent) == this )
106  {
107  showDetailsIfVisible( _selectable );
108  }
109 }
110 
111 
112 void
114 {
115  _selectable = selectable;
116 
117  if ( _parentTab ) // Is this view embedded into a tab widget?
118  {
119  if ( _parentTab->currentWidget() == this ) // Is this page the topmost?
120  {
121  showDetails( selectable );
122  }
123  }
124  else // No tab parent - simply show data unconditionally.
125  {
126  showDetails( selectable );
127  }
128 }
129 
130 
131 QSize
133 {
134  return QSize( 0, 0 );
135 }
136 
137 
138 QString
140 {
141  return "<html><head>"
142  "<link rel='stylesheet' type='text/css' href='format.css'>"
143  "</head><body>";
144 }
145 
146 QString
147 YQPkgGenericDetailsView::htmlEnd()
148 {
149  return "</body></html>";
150 }
151 
152 
153 QString
154 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
155 {
156  if ( ! selectable )
157  return "";
158 
159  ZyppObj zyppObj = selectable->theObj();
160 
161  if ( ! zyppObj )
162  return "";
163 
164  QString summary = fromUTF8( zyppObj->summary() );
165 
166  QString html = "<table";
167 
168  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
169  html += " class=\"stats\"";
170 
171  html += "><tr><td><b>"
172  + fromUTF8( zyppObj->name() )
173  + "</b>";
174 
175  if ( showVersion )
176  html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
177 
178  if ( ! summary.isEmpty() )
179  html += " - " + summary;
180 
181  html += "</td></tr></table>";
182 
183  return html;
184 }
185 
186 
187 
188 QString
189 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
190 {
191  QString html = plainText;
192  // yuiDebug() << "Escaping \"" << plainText << "\"" << endl;
193 
194  html.replace( QRegExp( "&" ), "&amp;" );
195  html.replace( QRegExp( "<" ), "&lt;" );
196  html.replace( QRegExp( ">" ), "&gt;" );
197 
198  return html;
199 }
200 
201 
202 QString
203 YQPkgGenericDetailsView::table( const QString & contents )
204 {
205  QString html = "<table";
206  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
207  html += " class=\"stats\"";
208 
209  html += ">" + contents + "</table>";
210 
211  return html;
212 }
213 
214 
215 QString
216 YQPkgGenericDetailsView::row( const QString & contents )
217 {
218  return "<tr>" + contents + "</tr>";
219 }
220 
221 
222 QString
223 YQPkgGenericDetailsView::cell( QString contents )
224 {
225  contents = htmlEscape( contents );
226  return "<td>" + contents + "</td>";
227 }
228 
229 
230 QString
231 YQPkgGenericDetailsView::cell( int contents )
232 {
233  QString html;
234  html.sprintf( "<td>%d</td>", contents );
235 
236  return html;
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 
261 #include "YQPkgGenericDetailsView.moc"
static QString hcell(QString contents)
Returns a string containing a HTML table cell with &#39;contents&#39; for table headers.
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.
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
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.