1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgSelDescriptionView.cc
15 Author: Stefan Hundhammer <sh@suse.de>
19 #define y2log_component "qt-pkg"
20 #include <ycp/y2log.h>
25 #include "YQPkgSelDescriptionView.h"
34 YQPkgSelDescriptionView::YQPkgSelDescriptionView( QWidget * parent )
35 : YQPkgDescriptionView( parent )
40 YQPkgSelDescriptionView::~YQPkgSelDescriptionView()
47 YQPkgSelDescriptionView::showDetails( ZyppSel selectable )
49 _selectable = selectable;
57 QString html_text = htmlHeading( selectable );
59 QString description = fromUTF8( selectable->theObj()->description() );
61 if ( ! description.contains( "<!-- DT:Rich -->" ) )
62 description = simpleHtmlParagraphs( description );
64 html_text += description;
67 //FIXME ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
73 YQPkgSelDescriptionView::htmlHeading( ZyppSel selectable )
75 ZyppObj zyppObj = selectable->theObj();
76 ZyppSelection selection = tryCastToZyppSelection( zyppObj );
77 ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
79 if ( ! selection && ! pattern )
80 return YQPkgGenericDetailsView::htmlHeading( selectable );
82 QString summary = fromUTF8( zyppObj->summary() );
83 bool useBigFont = ( summary.length() <= 40 );
85 if ( summary.isEmpty() ) // No summary?
86 summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
88 QString icon = pattern ? pattern->icon().asString().c_str() : "";
92 icon = zyppObj->name().c_str();
93 icon.replace( ' ', '_' );
96 if ( ! icon.isEmpty() )
98 if ( icon.startsWith( "./" ) )
99 icon.replace( QRegExp( "^\\./" ), "" );
101 if ( ! icon.endsWith( ".png", Qt::CaseInsensitive ) &&
102 ! icon.endsWith( ".jpg", Qt::CaseInsensitive ) )
105 QString origIconName = icon;
107 if ( ! icon.contains( "/" ) ) // no path at all
109 // Look in icon directories:
111 // /usr/share/YaST2/theme/current/icons/32x32/apps/
112 // /usr/share/YaST2/theme/current/icons/48x48/apps/
114 QString iconBaseName = icon;
115 icon = findIcon( QString( THEMEDIR ) + "/icons/32x32/apps/" + iconBaseName );
117 if ( icon.isEmpty() )
118 icon = findIcon( QString( THEMEDIR ) + "/icons/48x48/apps/" + iconBaseName );
120 else if ( ! icon.startsWith( "/" ) ) // relative path
122 // Use path relative to theme directory:
124 // /usr/share/YaST2/theme/current/ + icon
126 icon = findIcon( QString( THEMEDIR ) + "/" + icon );
129 if ( pattern && icon.isEmpty() )
130 y2warning( "No icon for pattern %s - icon name: %s",
131 zyppObj->name().c_str(), qPrintable(origIconName) );
135 QString html = "<table width=100%";
137 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
138 html += " bgcolor=#C8C8F8"; // or #E0E0F8 (very light blueish grey)
141 + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
143 + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
147 if ( ! icon.isEmpty() )
149 html = QString( "<table width=100%><tr>" )
150 + "<td><img src=\"" + icon + "\"></td>"
151 + "<td width=100%>" + html + "</td>"
161 YQPkgSelDescriptionView::findIcon( const QString & icon ) const
163 if ( access( qPrintable(icon), R_OK ) == 0 )
165 y2debug( "Found icon %s", qPrintable(icon) );
170 y2debug( "No icon %s", qPrintable(icon) );
176 #include "YQPkgSelDescriptionView.moc"