1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgSelDescriptionView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
27 #include "YQPkgSelDescriptionView.h"
36 YQPkgSelDescriptionView::YQPkgSelDescriptionView( QWidget * parent )
37 : YQPkgDescriptionView( parent )
42 YQPkgSelDescriptionView::~YQPkgSelDescriptionView()
49 YQPkgSelDescriptionView::showDetails( ZyppSel selectable )
51 _selectable = selectable;
59 QString html_text = htmlHeading( selectable );
61 QString description = fromUTF8( selectable->theObj()->description() );
63 if ( ! description.contains( "<!-- DT:Rich -->" ) )
64 description = simpleHtmlParagraphs( description );
66 html_text += description;
68 setTextFormat( Qt::RichText );
70 ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
76 YQPkgSelDescriptionView::htmlHeading( ZyppSel selectable )
78 ZyppObj zyppObj = selectable->theObj();
79 ZyppSelection selection = tryCastToZyppSelection( zyppObj );
80 ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
82 if ( ! selection && ! pattern )
83 return YQPkgGenericDetailsView::htmlHeading( selectable );
85 QString summary = fromUTF8( zyppObj->summary() );
86 bool useBigFont = ( summary.length() <= 40 );
88 if ( summary.isEmpty() ) // No summary?
89 summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
91 QString icon = pattern ? pattern->icon().asString().c_str() : "";
95 icon = zyppObj->name().c_str();
96 icon.replace( ' ', '_' );
99 if ( ! icon.isEmpty() )
101 if ( icon.startsWith( "./" ) )
102 icon.replace( QRegExp( "^\\./" ), "" );
104 if ( ! icon.endsWith( ".png", false ) &&
105 ! icon.endsWith( ".jpg", false ) )
108 QString origIconName = icon;
110 if ( ! icon.contains( "/" ) ) // no path at all
112 // Look in icon directories:
114 // /usr/share/YaST2/theme/current/icons/32x32/apps/
115 // /usr/share/YaST2/theme/current/icons/48x48/apps/
117 QString iconBaseName = icon;
118 icon = findIcon( QString( THEMEDIR ) + "/icons/32x32/apps/" + iconBaseName );
120 if ( icon.isEmpty() )
121 icon = findIcon( QString( THEMEDIR ) + "/icons/48x48/apps/" + iconBaseName );
123 else if ( ! icon.startsWith( "/" ) ) // relative path
125 // Use path relative to theme directory:
127 // /usr/share/YaST2/theme/current/ + icon
129 icon = findIcon( QString( THEMEDIR ) + "/" + icon );
132 if ( pattern && icon.isEmpty() )
133 y2warning( "No icon for pattern %s - icon name: %s",
134 zyppObj->name().c_str(), (const char *) origIconName );
138 QString html = "<table width=100%";
140 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
141 html += " bgcolor=#C8C8F8"; // or #E0E0F8 (very light blueish grey)
144 + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
146 + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
150 if ( ! icon.isEmpty() )
152 html = QString( "<table width=100%><tr>" )
153 + "<td><img src=\"" + icon + "\"></td>"
154 + "<td width=100%>" + html + "</td>"
164 YQPkgSelDescriptionView::findIcon( const QString & icon ) const
166 if ( access( icon, R_OK ) == 0 )
168 y2debug( "Found icon %s", (const char *) icon );
173 y2debug( "No icon %s", (const char *) icon );
179 #include "YQPkgSelDescriptionView.moc"