1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgSelDescriptionView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-pkg"
21 #include <ycp/y2log.h>
26 #include "YQPkgSelDescriptionView.h"
35 YQPkgSelDescriptionView::YQPkgSelDescriptionView( QWidget * parent )
36 : YQPkgDescriptionView( parent )
41 YQPkgSelDescriptionView::~YQPkgSelDescriptionView()
48 YQPkgSelDescriptionView::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;
67 setTextFormat( Qt::RichText );
69 ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
75 YQPkgSelDescriptionView::htmlHeading( ZyppSel selectable )
77 ZyppObj zyppObj = selectable->theObj();
78 ZyppSelection selection = tryCastToZyppSelection( zyppObj );
79 ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
81 if ( ! selection && ! pattern )
82 return YQPkgGenericDetailsView::htmlHeading( selectable );
84 QString summary = fromUTF8( zyppObj->summary() );
85 bool useBigFont = ( summary.length() <= 40 );
87 if ( summary.isEmpty() ) // No summary?
88 summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
90 QString icon = pattern ? pattern->icon().asString().c_str() : "";
94 icon = zyppObj->name().c_str();
95 icon.replace( ' ', '_' );
98 if ( ! icon.isEmpty() )
100 if ( icon.startsWith( "./" ) )
101 icon.replace( QRegExp( "^\\./" ), "" );
103 if ( ! icon.endsWith( ".png", false ) &&
104 ! icon.endsWith( ".jpg", false ) )
107 QString origIconName = icon;
109 if ( ! icon.contains( "/" ) ) // no path at all
111 // Look in icon directories:
113 // /usr/share/YaST2/theme/current/icons/32x32/apps/
114 // /usr/share/YaST2/theme/current/icons/48x48/apps/
116 QString iconBaseName = icon;
117 icon = findIcon( QString( THEMEDIR ) + "/icons/32x32/apps/" + iconBaseName );
119 if ( icon.isEmpty() )
120 icon = findIcon( QString( THEMEDIR ) + "/icons/48x48/apps/" + iconBaseName );
122 else if ( ! icon.startsWith( "/" ) ) // relative path
124 // Use path relative to theme directory:
126 // /usr/share/YaST2/theme/current/ + icon
128 icon = findIcon( QString( THEMEDIR ) + "/" + icon );
131 if ( pattern && icon.isEmpty() )
132 y2warning( "No icon for pattern %s - icon name: %s",
133 zyppObj->name().c_str(), (const char *) origIconName );
137 QString html = "<table width=100%";
139 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
140 html += " bgcolor=#C8C8F8"; // or #E0E0F8 (very light blueish grey)
143 + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
145 + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
149 if ( ! icon.isEmpty() )
151 html = QString( "<table width=100%><tr>" )
152 + "<td><img src=\"" + icon + "\"></td>"
153 + "<td width=100%>" + html + "</td>"
163 YQPkgSelDescriptionView::findIcon( const QString & icon ) const
165 if ( access( icon, R_OK ) == 0 )
167 y2debug( "Found icon %s", (const char *) icon );
172 y2debug( "No icon %s", (const char *) icon );
178 #include "YQPkgSelDescriptionView.moc"