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;
66 setTextFormat( Qt::RichText );
68 ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
74 YQPkgSelDescriptionView::htmlHeading( ZyppSel selectable )
76 ZyppObj zyppObj = selectable->theObj();
77 ZyppSelection selection = tryCastToZyppSelection( zyppObj );
78 ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
80 if ( ! selection && ! pattern )
81 return YQPkgGenericDetailsView::htmlHeading( selectable );
83 QString summary = fromUTF8( zyppObj->summary() );
84 bool useBigFont = ( summary.length() <= 40 );
86 if ( summary.isEmpty() ) // No summary?
87 summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
89 QString icon = pattern ? pattern->icon().asString().c_str() : "";
93 icon = zyppObj->name().c_str();
94 icon.replace( ' ', '_' );
97 if ( ! icon.isEmpty() )
99 if ( icon.startsWith( "./" ) )
100 icon.replace( QRegExp( "^\\./" ), "" );
102 if ( ! icon.endsWith( ".png", Qt::CaseInsensitive ) &&
103 ! icon.endsWith( ".jpg", Qt::CaseInsensitive ) )
106 QString origIconName = icon;
108 if ( ! icon.contains( "/" ) ) // no path at all
110 // Look in icon directories:
112 // /usr/share/YaST2/theme/current/icons/32x32/apps/
113 // /usr/share/YaST2/theme/current/icons/48x48/apps/
115 QString iconBaseName = icon;
116 icon = findIcon( QString( THEMEDIR ) + "/icons/32x32/apps/" + iconBaseName );
118 if ( icon.isEmpty() )
119 icon = findIcon( QString( THEMEDIR ) + "/icons/48x48/apps/" + iconBaseName );
121 else if ( ! icon.startsWith( "/" ) ) // relative path
123 // Use path relative to theme directory:
125 // /usr/share/YaST2/theme/current/ + icon
127 icon = findIcon( QString( THEMEDIR ) + "/" + icon );
130 if ( pattern && icon.isEmpty() )
131 y2warning( "No icon for pattern %s - icon name: %s",
132 zyppObj->name().c_str(), qPrintable(origIconName) );
136 QString html = "<table width=100%";
138 if ( ! YQUI::ui()->usingVisionImpairedPalette() )
139 html += " bgcolor=#C8C8F8"; // or #E0E0F8 (very light blueish grey)
142 + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
144 + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
148 if ( ! icon.isEmpty() )
150 html = QString( "<table width=100%><tr>" )
151 + "<td><img src=\"" + icon + "\"></td>"
152 + "<td width=100%>" + html + "</td>"
162 YQPkgSelDescriptionView::findIcon( const QString & icon ) const
164 if ( access( qPrintable(icon), R_OK ) == 0 )
166 y2debug( "Found icon %s", qPrintable(icon) );
171 y2debug( "No icon %s", qPrintable(icon) );
177 #include "YQPkgSelDescriptionView.moc"