]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDescriptionView.cc
various compilation
[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 QT3_SUPPORT 1
20
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23
24 #include <QRegExp>
25 #include <QList>
26 #include "YQPkgDescriptionView.h"
27 #include "YQPkgDescriptionDialog.h"
28 #include "YQi18n.h"
29 #include "utf8.h"
30
31 using std::list;
32 using std::string;
33
34
35 YQPkgDescriptionView::YQPkgDescriptionView( QWidget * parent )
36     : YQPkgGenericDetailsView( parent )
37 {
38     //FIXME setMimeSourceFactory( 0 );
39 }
40
41
42 YQPkgDescriptionView::~YQPkgDescriptionView()
43 {
44     // NOP
45 }
46
47
48 void
49 YQPkgDescriptionView::showDetails( ZyppSel selectable )
50 {
51     _selectable = selectable;
52
53     if ( ! selectable )
54     {
55         clear();
56         return;
57     }
58
59     QString html_text = htmlHeading( selectable );
60
61     QString description = fromUTF8( selectable->theObj()->description() );
62
63     if ( ! description.contains( "<!-- DT:Rich -->" ) )
64         description = simpleHtmlParagraphs( description );
65
66     html_text += description;
67
68
69     setHtml( html_text );
70     //FIXME ensureVisible( 0, 0 );      // Otherwise hyperlinks will be centered
71 }
72
73
74
75 QString YQPkgDescriptionView::simpleHtmlParagraphs( QString text )
76 {
77     bool foundAuthorsList = false;
78     QString html_text = "<p>";
79
80     QStringList lines = text.trimmed().split( '\n', QString::KeepEmptyParts );
81     QStringList::const_iterator it = lines.begin();
82
83     while ( it != lines.end() )
84     {
85         QString line = htmlEscape( *it ).stripWhiteSpace();
86
87         if ( line.startsWith( "Authors:" ) )
88         {
89             line = "<p><b>" + line + "</b><ul>";
90             foundAuthorsList = true;
91         }
92
93         if ( foundAuthorsList )
94         {
95             if ( ! line.startsWith( "-----" ) && ! line.isEmpty() )
96                 html_text += "<li>" + line + "</li>";
97         }
98         else
99         {
100             if ( line.isEmpty() )
101                 html_text += "</p><p>";
102             else
103                 html_text += " " + line;
104         }
105
106         ++it;
107     }
108
109     if ( foundAuthorsList )
110         html_text += "</ul>";
111     
112     html_text += "</p>";
113
114     return html_text;
115 }
116
117
118 void
119 YQPkgDescriptionView::showLink( const QString & url )
120 {
121     if ( url.startsWith( "pkg:" ) )
122     {
123         QString pkgName = url;
124         pkgName.remove( QRegExp( "^pkg:/*" ) ); // Remove leading protocol and slashes
125         pkgName.remove( QRegExp( "/*$" ) );     // Remove trailing slashes
126         y2milestone( "Hyperlinking to package '%s'", (const char *) pkgName );
127         YQPkgDescriptionDialog::showDescriptionDialog( pkgName );
128     }
129     else
130     {
131         y2error( "Protocol not supported - can't follow hyperlink '%s'",
132                  (const char *) url );
133     }
134 }
135
136
137 void
138 YQPkgDescriptionView::setSource( const QString & url )
139 {
140     showLink( url );
141 }
142
143
144 #include "YQPkgDescriptionView.moc"