libyui-qt-pkg  2.45.27
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 #include <qbuffer.h>
52 
53 using std::endl;
54 using std::list;
55 using std::string;
56 
57 
59  : YQPkgDescriptionView( parent )
60 {
61 }
62 
63 
65 {
66  // NOP
67 }
68 
69 
70 void
72 {
73  _selectable = selectable;
74 
75  if ( ! selectable )
76  {
77  clear();
78  return;
79  }
80 
81  QString html_text = htmlHeading( selectable );
82 
83  QString description = fromUTF8( selectable->theObj()->description() );
84 
85  if ( ! description.contains( "<!-- DT:Rich -->" ) )
86  description = simpleHtmlParagraphs( description );
87 
88  html_text += description;
89 
90  setHtml( html_text );
91  //FIXME ensureVisible( 0, 0 ); // Otherwise hyperlinks will be centered
92 }
93 
94 
95 
96 QString
98 {
99  ZyppObj zyppObj = selectable->theObj();
100  ZyppPattern pattern = tryCastToZyppPattern ( zyppObj );
101 
102  if ( ! pattern )
103  return YQPkgGenericDetailsView::htmlHeading( selectable );
104 
105  QString summary = fromUTF8( zyppObj->summary() );
106  bool useBigFont = ( summary.length() <= 40 );
107 
108  if ( summary.isEmpty() ) // No summary?
109  summary = fromUTF8( zyppObj->name() ); // Use name instead (internal only normally)
110 
111  QString iconName = pattern ? pattern->icon().asString().c_str() : "";
112 
113  if ( iconName.isEmpty() )
114  {
115  iconName = zyppObj->name().c_str();
116  iconName.replace( ' ', '_' );
117  }
118 
119  if ( ! iconName.isEmpty() )
120  {
121  if ( iconName.startsWith( "./" ) )
122  iconName.replace( QRegExp( "^\\./" ), "" );
123 
124  if ( pattern && iconName.isEmpty() )
125  yuiWarning() << "No icon for pattern " << zyppObj->name() << endl;
126  }
127 
128 
129  QString html = "<table width='100%'><tr><td>"
130  + ( useBigFont ? QString( "<h2>" ) : QString( "<b>" ) )
131  + summary
132  + ( useBigFont ? QString( "</h2>" ) : QString( "</b>" ) )
133  + "</td></tr>"
134  + "</table>";
135 
136  if ( ! iconName.isEmpty() )
137  {
138  QIcon icon = YQUI::ui()->loadIcon( iconName.toStdString() );
139  QPixmap pixmap = icon.pixmap(16);
140  QByteArray byteArray;
141  QBuffer buffer(&byteArray);
142  pixmap.save(&buffer, "PNG");
143  html = QString( "<table width='100%'><tr>" )
144  + "<td><img src=\"data:image/png;base64," + byteArray.toBase64() + "\"/></td>"
145  + "<td width='100%'>" + html + "</td>"
146  + "</tr></table>";
147  }
148 
149  return html;
150 }
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...
virtual ~YQPkgSelDescriptionView()
Destructor.
virtual void showDetails(ZyppSel selectable)
Show details for the specified package: In this case the package description.