1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgGenericDetailsView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23 #include <qtabwidget.h>
25 #include <qdatetime.h>
27 #include "YQPkgGenericDetailsView.h"
35 YQPkgGenericDetailsView::YQPkgGenericDetailsView( QWidget * parent )
36 : Q3TextBrowser( parent )
39 _parentTab = dynamic_cast<QTabWidget *> (parent);
43 connect( parent, SIGNAL( currentChanged(QWidget *) ),
44 this, SLOT ( reload (QWidget *) ) );
49 YQPkgGenericDetailsView::~YQPkgGenericDetailsView()
56 YQPkgGenericDetailsView::reload( QWidget * newCurrent )
58 if ( newCurrent == this )
60 showDetailsIfVisible( _selectable );
66 YQPkgGenericDetailsView::showDetailsIfVisible( ZyppSel selectable )
68 _selectable = selectable;
70 if ( _parentTab ) // Is this view embedded into a tab widget?
72 if ( _parentTab->currentPage() == this ) // Is this page the topmost?
74 showDetails( selectable );
77 else // No tab parent - simply show data unconditionally.
79 showDetails( selectable );
85 YQPkgGenericDetailsView::minimumSizeHint() const
92 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
97 ZyppObj zyppObj = selectable->theObj();
102 QString summary = fromUTF8( zyppObj->summary() );
104 QString html = "<table";
106 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
107 html += " bgcolor=#E0E0F8";
109 html += "><tr><td><b>"
110 + fromUTF8( zyppObj->name() )
114 html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
116 if ( ! summary.isEmpty() )
117 html += " - " + summary;
119 html += "</td></tr></table><br>";
127 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
129 QString html = plainText;
130 // y2debug( "Escaping '%s'", (const char *) plainText );
132 html.replace( QRegExp( "&" ), "&" );
133 html.replace( QRegExp( "<" ), "<" );
134 html.replace( QRegExp( ">" ), ">" );
141 YQPkgGenericDetailsView::table( const QString & contents )
143 QString html = "<table border=1";
145 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
146 html += " bgcolor=#F0F0F0";
147 html += ">" + contents + "</table>";
154 YQPkgGenericDetailsView::row( const QString & contents )
156 return "<tr>" + contents + "</tr>";
161 YQPkgGenericDetailsView::cell( QString contents )
163 contents = htmlEscape( contents );
164 return "<td valign=top>" + contents + "</td>";
169 YQPkgGenericDetailsView::cell( int contents )
172 html.sprintf( "<td valign=top>%d</td>", contents );
179 YQPkgGenericDetailsView::cell( const zypp::Date & date )
181 return cell( ( (time_t) date == (time_t) 0 ? "" : date.asString() ) );
186 YQPkgGenericDetailsView::cell( const string & contents )
188 return cell( fromUTF8( contents ) );
193 YQPkgGenericDetailsView::hcell( QString contents )
195 QString html = "<td valign=top";
197 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
198 html += " bgcolor=#D0D0D0";
200 html += ">" + contents + "</td>";
206 #include "YQPkgGenericDetailsView.moc"