libyui-qt-pkg  2.45.6
 All Classes Functions Variables Enumerations
YQPkgSelDescriptionView.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgSelDescriptionView.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 #define YUILogComponent "qt-pkg"
41 #include "YUILog.h"
42 #include <yui/Libyui_config.h>
43 
44 #include <unistd.h>
45 #include <QRegExp>
46 
47 #include "YQPkgSelDescriptionView.h"
48 #include "YQUI.h"
49 #include "YQi18n.h"
50 #include "utf8.h"
51 
52 using std::endl;
53 using std::list;
54 using std::string;
55 
56 
58  : YQPkgDescriptionView( parent )
59 {
60 }
61 
62 
64 {
65  // NOP
66 }
67 
68 
69 void
71 {
72  _selectable = selectable;
73 
74  if ( ! selectable )
75  {
76  clear();
77  return;
78  }
79 
80  QString html_text = htmlHeading( selectable );
81 
82  QString description = fromUTF8( selectable->theObj()->description() );
83 
84  if ( ! description.contains( "<!-- DT:Rich -->" ) )
85  description = simpleHtmlParagraphs( description );
86 
87  html_text += description;
88 
89  setHtml( html_text );
90  //FIXME ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
91 }
92 
93 
94 
95 QString
97 {
98  ZyppObj zyppObj = selectable->theObj();
99  ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
100 
101  if ( ! pattern )
102  return YQPkgGenericDetailsView::htmlHeading( selectable );
103 
104  QString summary = fromUTF8( zyppObj->summary() );
105  bool useBigFont = ( summary.length() <= 40 );
106 
107  if ( summary.isEmpty() ) // No summary?
108  summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
109 
110  QString icon = pattern ? pattern->icon().asString().c_str() : "";
111 
112  if ( icon.isEmpty() )
113  {
114  icon = zyppObj->name().c_str();
115  icon.replace( ' ', '_' );
116  }
117 
118  if ( ! icon.isEmpty() )
119  {
120  if ( icon.startsWith( "./" ) )
121  icon.replace( QRegExp( "^\\./" ), "" );
122 
123  if ( ! icon.endsWith( ".png", Qt::CaseInsensitive ) &&
124  ! icon.endsWith( ".jpg", Qt::CaseInsensitive ) )
125  icon += ".png";
126 
127  QString origIconName = icon;
128 
129  if ( ! icon.contains( "/" ) ) // no path at all
130  {
131  // Look in icon directories:
132  //
133  // /usr/share/YaST2/theme/current/icons/32x32/apps/
134  // /usr/share/YaST2/theme/current/icons/48x48/apps/
135 
136  QString iconBaseName = icon;
137  icon = findIcon( QString( THEMEDIR ) + "/icons/32x32/apps/" + iconBaseName );
138 
139  if ( icon.isEmpty() )
140  icon = findIcon( QString( THEMEDIR ) + "/icons/48x48/apps/" + iconBaseName );
141  }
142  else if ( ! icon.startsWith( "/" ) ) // relative path
143  {
144  // Use path relative to theme directory:
145  //
146  // /usr/share/YaST2/theme/current/ + icon
147 
148  icon = findIcon( QString( THEMEDIR ) + "/" + icon );
149  }
150 
151  if ( pattern && icon.isEmpty() )
152  yuiWarning() << "No icon for pattern " << zyppObj->name()
153  << " - icon name: " << origIconName
154  << endl;
155  }
156 
157 
158  QString html = "<table width='100%'><tr><td>"
159  + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
160  + summary
161  + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
162  + "</td></tr>"
163  + "</table>";
164 
165  if ( ! icon.isEmpty() )
166  {
167  html = QString( "<table width='100%'><tr>" )
168  + "<td><img src=\"" + icon + "\"></td>"
169  + "<td width='100%'>" + html + "</td>"
170  + "</tr></table>";
171  }
172 
173  return html;
174 }
175 
176 
177 
178 QString
179 YQPkgSelDescriptionView::findIcon( const QString & icon ) const
180 {
181  if ( access( qPrintable( icon ), R_OK ) == 0 )
182  {
183  yuiDebug() << "Found icon " << icon << endl;
184  return icon;
185  }
186  else
187  {
188  yuiDebug() << "No icon " << icon << endl;
189  return "";
190  }
191 }
192 
193 
194 #include "YQPkgSelDescriptionView.moc"
Display the description of a ZyppObj derived object along with its name and summary.
QString simpleHtmlParagraphs(QString text)
Format a multi-line text into paragraphs.
QString htmlHeading(ZyppSel selectable)
Format the heading in HTML.
YQPkgSelDescriptionView(QWidget *parent)
Constructor.
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
Returns a uniform heading in HTML format for the specified selectable: name and summary or name...
QString findIcon(const QString &icon) const
Check if 'icon' exists.
virtual ~YQPkgSelDescriptionView()
Destructor.
virtual void showDetails(ZyppSel selectable)
Show details for the specified package: In this case the package description.