1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgGenericDetailsView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
19 #define y2log_component "qt-pkg"
20 #include <ycp/y2log.h>
25 #include "YQPkgGenericDetailsView.h"
33 YQPkgGenericDetailsView::YQPkgGenericDetailsView( QWidget * parent )
34 : QTextBrowser( parent )
37 _parentTab = dynamic_cast<QTabWidget *> (parent);
41 connect( parent, SIGNAL( currentChanged(QWidget *) ),
42 this, SLOT ( reload (QWidget *) ) );
47 YQPkgGenericDetailsView::~YQPkgGenericDetailsView()
54 YQPkgGenericDetailsView::reload( QWidget * newCurrent )
56 if ( newCurrent == this )
58 showDetailsIfVisible( _selectable );
64 YQPkgGenericDetailsView::showDetailsIfVisible( ZyppSel selectable )
66 _selectable = selectable;
68 if ( _parentTab ) // Is this view embedded into a tab widget?
70 if ( _parentTab->currentWidget() == this ) // Is this page the topmost?
72 showDetails( selectable );
75 else // No tab parent - simply show data unconditionally.
77 showDetails( selectable );
83 YQPkgGenericDetailsView::minimumSizeHint() const
90 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
95 ZyppObj zyppObj = selectable->theObj();
100 QString summary = fromUTF8( zyppObj->summary() );
102 QString html = "<table";
104 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
105 html += " bgcolor=#E0E0F8";
107 html += "><tr><td><b>"
108 + fromUTF8( zyppObj->name() )
112 html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
114 if ( ! summary.isEmpty() )
115 html += " - " + summary;
117 html += "</td></tr></table><br>";
125 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
127 QString html = plainText;
128 // y2debug( "Escaping '%s'", (const char *) plainText );
130 html.replace( QRegExp( "&" ), "&" );
131 html.replace( QRegExp( "<" ), "<" );
132 html.replace( QRegExp( ">" ), ">" );
139 YQPkgGenericDetailsView::table( const QString & contents )
141 QString html = "<table border=1";
143 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
144 html += " bgcolor=#F0F0F0";
145 html += ">" + contents + "</table>";
152 YQPkgGenericDetailsView::row( const QString & contents )
154 return "<tr>" + contents + "</tr>";
159 YQPkgGenericDetailsView::cell( QString contents )
161 contents = htmlEscape( contents );
162 return "<td valign=top>" + contents + "</td>";
167 YQPkgGenericDetailsView::cell( int contents )
170 html.sprintf( "<td valign=top>%d</td>", contents );
177 YQPkgGenericDetailsView::cell( const zypp::Date & date )
179 return cell( ( (time_t) date == (time_t) 0 ? "" : date.asString() ) );
184 YQPkgGenericDetailsView::cell( const string & contents )
186 return cell( fromUTF8( contents ) );
191 YQPkgGenericDetailsView::hcell( QString contents )
193 QString html = "<td valign=top";
195 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
196 html += " bgcolor=#D0D0D0";
198 html += ">" + contents + "</td>";
204 #include "YQPkgGenericDetailsView.moc"