]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDescriptionView.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / pkg / YQPkgDescriptionView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgDescriptionView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19 #define y2log_component "qt-pkg"
20 #include <ycp/y2log.h>
21
22 #include <QRegExp>
23 #include <QList>
24 #include "YQPkgDescriptionView.h"
25 #include "YQPkgDescriptionDialog.h"
26 #include "YQi18n.h"
27 #include "utf8.h"
28
29 using std::list;
30 using std::string;
31
32
33 YQPkgDescriptionView::YQPkgDescriptionView( QWidget * parent )
34     : YQPkgGenericDetailsView( parent )
35 {
36     //FIXME setMimeSourceFactory( 0 );
37 }
38
39
40 YQPkgDescriptionView::~YQPkgDescriptionView()
41 {
42     // NOP
43 }
44
45
46 void
47 YQPkgDescriptionView::showDetails( ZyppSel selectable )
48 {
49     _selectable = selectable;
50
51     if ( ! selectable )
52     {
53         clear();
54         return;
55     }
56
57     QString html_text = htmlHeading( selectable );
58
59     QString description = fromUTF8( selectable->theObj()->description() );
60
61     if ( ! description.contains( "<!-- DT:Rich -->" ) )
62         description = simpleHtmlParagraphs( description );
63
64     html_text += description;
65
66
67     setHtml( html_text );
68     //FIXME ensureVisible( 0, 0 );      // Otherwise hyperlinks will be centered
69 }
70
71
72
73 QString YQPkgDescriptionView::simpleHtmlParagraphs( QString text )
74 {
75     bool foundAuthorsList = false;
76     QString html_text = "<p>";
77
78     QStringList lines = text.trimmed().split( '\n', QString::KeepEmptyParts );
79     QStringList::const_iterator it = lines.begin();
80
81     while ( it != lines.end() )
82     {
83         QString line = htmlEscape( *it ).trimmed();
84
85         if ( line.startsWith( "Authors:" ) )
86         {
87             line = "<p><b>" + line + "</b><ul>";
88             foundAuthorsList = true;
89         }
90
91         if ( foundAuthorsList )
92         {
93             if ( ! line.startsWith( "-----" ) && ! line.isEmpty() )
94                 html_text += "<li>" + line + "</li>";
95         }
96         else
97         {
98             if ( line.isEmpty() )
99                 html_text += "</p><p>";
100             else
101                 html_text += " " + line;
102         }
103
104         ++it;
105     }
106
107     if ( foundAuthorsList )
108         html_text += "</ul>";
109     
110     html_text += "</p>";
111
112     return html_text;
113 }
114
115
116 void
117 YQPkgDescriptionView::showLink( const QUrl & url )
118 {
119     if ( url.scheme() == "pkg" )
120     {
121         QString pkgName = url.authority();
122         y2milestone( "Hyperlinking to package '%s'", qPrintable(pkgName) );
123         YQPkgDescriptionDialog::showDescriptionDialog( pkgName );
124     }
125     else
126     {
127         y2error( "Protocol not supported - can't follow hyperlink '%s'",
128                  qPrintable(url.toString()) );
129     }
130 }
131
132
133 void
134 YQPkgDescriptionView::setSource( const QUrl & url )
135 {
136     showLink( url );
137 }
138
139
140 #include "YQPkgDescriptionView.moc"