1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDescriptionView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
19 #define y2log_component "qt-pkg"
20 #include <ycp/y2log.h>
23 #include "YQPkgDescriptionView.h"
24 #include "YQPkgDescriptionDialog.h"
32 YQPkgDescriptionView::YQPkgDescriptionView( QWidget * parent )
33 : YQPkgGenericDetailsView( parent )
35 setMimeSourceFactory( 0 );
39 YQPkgDescriptionView::~YQPkgDescriptionView()
46 YQPkgDescriptionView::showDetails( ZyppSel selectable )
48 _selectable = selectable;
56 QString html_text = htmlHeading( selectable );
58 QString description = fromUTF8( selectable->theObj()->description() );
60 if ( ! description.contains( "<!-- DT:Rich -->" ) )
61 description = simpleHtmlParagraphs( description );
63 html_text += description;
66 setTextFormat( Qt::RichText );
68 ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
73 QString YQPkgDescriptionView::simpleHtmlParagraphs( QString text )
75 bool foundAuthorsList = false;
76 QString html_text = "<p>";
78 QStringList lines = QStringList::split( '\n', text.stripWhiteSpace(),
79 true ); // allowEmptyEntries
80 QValueList<QString>::const_iterator it = lines.begin();
82 while ( it != lines.end() )
84 QString line = htmlEscape( *it ).stripWhiteSpace();
86 if ( line.startsWith( "Authors:" ) )
88 line = "<p><b>" + line + "</b><ul>";
89 foundAuthorsList = true;
92 if ( foundAuthorsList )
94 if ( ! line.startsWith( "-----" ) && ! line.isEmpty() )
95 html_text += "<li>" + line + "</li>";
100 html_text += "</p><p>";
102 html_text += " " + line;
108 if ( foundAuthorsList )
109 html_text += "</ul>";
118 YQPkgDescriptionView::showLink( const QString & url )
120 if ( url.startsWith( "pkg:" ) )
122 QString pkgName = url;
123 pkgName.remove( QRegExp( "^pkg:/*" ) ); // Remove leading protocol and slashes
124 pkgName.remove( QRegExp( "/*$" ) ); // Remove trailing slashes
125 y2milestone( "Hyperlinking to package '%s'", (const char *) pkgName );
126 YQPkgDescriptionDialog::showDescriptionDialog( pkgName );
130 y2error( "Protocol not supported - can't follow hyperlink '%s'",
131 (const char *) url );
137 YQPkgDescriptionView::setSource( const QString & url )
143 #include "YQPkgDescriptionView.moc"