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>
24 #include <q3valuelist.h>
25 #include "YQPkgDescriptionView.h"
26 #include "YQPkgDescriptionDialog.h"
34 YQPkgDescriptionView::YQPkgDescriptionView( QWidget * parent )
35 : YQPkgGenericDetailsView( parent )
37 setMimeSourceFactory( 0 );
41 YQPkgDescriptionView::~YQPkgDescriptionView()
48 YQPkgDescriptionView::showDetails( ZyppSel selectable )
50 _selectable = selectable;
58 QString html_text = htmlHeading( selectable );
60 QString description = fromUTF8( selectable->theObj()->description() );
62 if ( ! description.contains( "<!-- DT:Rich -->" ) )
63 description = simpleHtmlParagraphs( description );
65 html_text += description;
68 setTextFormat( Qt::RichText );
70 ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
75 QString YQPkgDescriptionView::simpleHtmlParagraphs( QString text )
77 bool foundAuthorsList = false;
78 QString html_text = "<p>";
80 QStringList lines = text.trimmed().split( '\n', QString::KeepEmptyParts );
81 QStringList::const_iterator it = lines.begin();
83 while ( it != lines.end() )
85 QString line = htmlEscape( *it ).stripWhiteSpace();
87 if ( line.startsWith( "Authors:" ) )
89 line = "<p><b>" + line + "</b><ul>";
90 foundAuthorsList = true;
93 if ( foundAuthorsList )
95 if ( ! line.startsWith( "-----" ) && ! line.isEmpty() )
96 html_text += "<li>" + line + "</li>";
100 if ( line.isEmpty() )
101 html_text += "</p><p>";
103 html_text += " " + line;
109 if ( foundAuthorsList )
110 html_text += "</ul>";
119 YQPkgDescriptionView::showLink( const QString & url )
121 if ( url.startsWith( "pkg:" ) )
123 QString pkgName = url;
124 pkgName.remove( QRegExp( "^pkg:/*" ) ); // Remove leading protocol and slashes
125 pkgName.remove( QRegExp( "/*$" ) ); // Remove trailing slashes
126 y2milestone( "Hyperlinking to package '%s'", (const char *) pkgName );
127 YQPkgDescriptionDialog::showDescriptionDialog( pkgName );
131 y2error( "Protocol not supported - can't follow hyperlink '%s'",
132 (const char *) url );
138 YQPkgDescriptionView::setSource( const QString & url )
144 #include "YQPkgDescriptionView.moc"