libyui-qt-pkg  2.42.13
 All Classes Functions Variables Enumerations
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( parent, SIGNAL( currentChanged(QWidget *) ),
62  this, SLOT ( reload (QWidget *) ) );
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  ";color: "
72  + QApplication::palette().color( QPalette::Active, QPalette::Base).name() +
73  ";"
74  "width: 100%;"
75  ""
76  "border: 1px;"
77  "border-collapse: collapse;"
78  "border-spacing: 4px;}"
79  ""
80  "table.stats td"
81  "{"
82  ";color: "
83  + QApplication::palette().color( QPalette::Active, QPalette::WindowText).name() +
84  ";"
85  "padding: 4px;"
86  "text-align: left;"
87  "border: 1px "
88  + QApplication::palette().color( QPalette::Active, QPalette::Base).name() +
89  " solid;}"
90  ""
91  "table.stats td.hed"
92  "{"
93  ";color: "
94  + QApplication::palette().color( QPalette::Active, QPalette::Base).name() +
95  ";"
96  "padding: 4px;"
97  "text-align: left;"
98  "border-bottom: 2px "
99  + QApplication::palette().color( QPalette::Active, QPalette::Base).name() +
100  " solid;"
101  "font-size: small;"
102  "font-weight: bold;} ";
103 
104  document()->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );
105 }
106 
107 
109 {
110  // NOP
111 }
112 
113 
114 void
115 YQPkgGenericDetailsView::reload( QWidget * newCurrent )
116 {
117  if ( newCurrent == this )
118  {
119  showDetailsIfVisible( _selectable );
120  }
121 }
122 
123 
124 void
126 {
127  _selectable = selectable;
128 
129  if ( _parentTab ) // Is this view embedded into a tab widget?
130  {
131  if ( _parentTab->currentWidget() == this ) // Is this page the topmost?
132  {
133  showDetails( selectable );
134  }
135  }
136  else // No tab parent - simply show data unconditionally.
137  {
138  showDetails( selectable );
139  }
140 }
141 
142 
143 QSize
145 {
146  return QSize( 0, 0 );
147 }
148 
149 
150 QString
152 {
153  return "<html><head>"
154  "<link rel='stylesheet' type='text/css' href='format.css'>"
155  "</head><body>";
156 }
157 
158 QString
159 YQPkgGenericDetailsView::htmlEnd()
160 {
161  return "</body></html>";
162 }
163 
164 
165 QString
166 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
167 {
168  if ( ! selectable )
169  return "";
170 
171  ZyppObj zyppObj = selectable->theObj();
172 
173  if ( ! zyppObj )
174  return "";
175 
176  QString summary = fromUTF8( zyppObj->summary() );
177 
178  QString html = "<table";
179 
180  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
181  html += " class=\"stats\"";
182 
183  html += "><tr><td><b>"
184  + fromUTF8( zyppObj->name() )
185  + "</b>";
186 
187  if ( showVersion )
188  html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
189 
190  if ( ! summary.isEmpty() )
191  html += " - " + summary;
192 
193  html += "</td></tr></table>";
194 
195  return html;
196 }
197 
198 
199 
200 QString
201 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
202 {
203  QString html = plainText;
204  // yuiDebug() << "Escaping \"" << plainText << "\"" << endl;
205 
206  html.replace( QRegExp( "&" ), "&amp;" );
207  html.replace( QRegExp( "<" ), "&lt;" );
208  html.replace( QRegExp( ">" ), "&gt;" );
209 
210  return html;
211 }
212 
213 
214 QString
215 YQPkgGenericDetailsView::table( const QString & contents )
216 {
217  QString html = "<table";
218  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
219  html += " class=\"stats\"";
220 
221  html += ">" + contents + "</table>";
222 
223  return html;
224 }
225 
226 
227 QString
228 YQPkgGenericDetailsView::row( const QString & contents )
229 {
230  return "<tr>" + contents + "</tr>";
231 }
232 
233 
234 QString
235 YQPkgGenericDetailsView::cell( QString contents )
236 {
237  contents = htmlEscape( contents );
238  return "<td>" + contents + "</td>";
239 }
240 
241 
242 QString
243 YQPkgGenericDetailsView::cell( int contents )
244 {
245  QString html;
246  html.sprintf( "<td>%d</td>", contents );
247 
248  return html;
249 }
250 
251 
252 QString
253 YQPkgGenericDetailsView::cell( const zypp::Date & date )
254 {
255  return cell( ( (time_t) date == (time_t) 0 ? "" : date.asString() ) );
256 }
257 
258 
259 QString
260 YQPkgGenericDetailsView::cell( const string & contents )
261 {
262  return cell( fromUTF8( contents ) );
263 }
264 
265 
266 QString
268 {
269 
270 
271 
272  QString html = "<td";
273 
274  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
275  html += " bgcolor=\""
276  + QApplication::palette().color( QPalette::Active, QPalette::Window).name()
277  + "\"";
278 
279  html += ">" + contents + "</td>";
280 
281  return html;
282 }
283 
284 
285 #include "YQPkgGenericDetailsView.moc"
static QString hcell(QString contents)
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
static QString cell(QString contents)
virtual void showDetails(ZyppSel selectable)=0
static QString htmlEscape(const QString &plainText)
void reload(QWidget *newCurrent)
void showDetailsIfVisible(ZyppSel selectable)
virtual QSize minimumSizeHint() const
static QString table(const QString &contents)
static QString row(const QString &contents)
YQPkgGenericDetailsView(QWidget *parent)