]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgGenericDetailsView.cc
0132fb50f36c240977111602f70677df9fd852fa
[duncan/yast2-qt4.git] / src / pkg / YQPkgGenericDetailsView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgGenericDetailsView.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 #include <qtabwidget.h>
24 #include <qregexp.h>
25 #include <qdatetime.h>
26
27 #include "YQPkgGenericDetailsView.h"
28 #include "YQi18n.h"
29 #include "YQUI.h"
30 #include "utf8.h"
31
32 using std::string;
33
34
35 YQPkgGenericDetailsView::YQPkgGenericDetailsView( QWidget * parent )
36     : Q3TextBrowser( parent )
37 {
38     _selectable = 0;
39     _parentTab  = dynamic_cast<QTabWidget *> (parent);
40
41     if ( _parentTab )
42     {
43         connect( parent, SIGNAL( currentChanged(QWidget *) ),
44                  this,   SLOT  ( reload        (QWidget *) ) );
45     }
46 }
47
48
49 YQPkgGenericDetailsView::~YQPkgGenericDetailsView()
50 {
51     // NOP
52 }
53
54
55 void
56 YQPkgGenericDetailsView::reload( QWidget * newCurrent )
57 {
58     if ( newCurrent == this )
59     {
60         showDetailsIfVisible( _selectable );
61     }
62 }
63
64
65 void
66 YQPkgGenericDetailsView::showDetailsIfVisible( ZyppSel selectable )
67 {
68     _selectable = selectable;
69
70     if ( _parentTab )           // Is this view embedded into a tab widget?
71     {
72         if ( _parentTab->currentPage() == this )  // Is this page the topmost?
73         {
74             showDetails( selectable );
75         }
76     }
77     else        // No tab parent - simply show data unconditionally.
78     {
79         showDetails( selectable );
80     }
81 }
82
83
84 QSize
85 YQPkgGenericDetailsView::minimumSizeHint() const
86 {
87     return QSize( 0, 0 );
88 }
89
90
91 QString
92 YQPkgGenericDetailsView::htmlHeading( ZyppSel selectable, bool showVersion )
93 {
94     if ( ! selectable )
95         return "";
96
97     ZyppObj zyppObj = selectable->theObj();
98
99     if ( ! zyppObj )
100         return "";
101
102     QString summary = fromUTF8( zyppObj->summary() );
103
104     QString html = "<table";
105
106     if ( ! YQUI::ui()->usingVisionImpairedPalette() )
107         html += " bgcolor=#E0E0F8";
108
109     html += "><tr><td><b>"
110         + fromUTF8( zyppObj->name() )
111         + "</b>";
112
113     if ( showVersion )
114         html += QString( "<b>-" ) + zyppObj->edition().asString().c_str() + "</b>";
115
116     if ( ! summary.isEmpty() )
117         html += " - " + summary;
118
119     html += "</td></tr></table><br>";
120
121     return html;
122 }
123
124
125
126 QString
127 YQPkgGenericDetailsView::htmlEscape( const QString & plainText )
128 {
129     QString html = plainText;
130     // y2debug( "Escaping '%s'", (const char *) plainText );
131
132     html.replace( QRegExp( "&" ), "&amp;" );
133     html.replace( QRegExp( "<" ), "&lt;"  );
134     html.replace( QRegExp( ">" ), "&gt;"  );
135
136     return html;
137 }
138
139
140 QString
141 YQPkgGenericDetailsView::table( const QString & contents )
142 {
143     QString html = "<table border=1";
144
145     if ( ! YQUI::ui()->usingVisionImpairedPalette() )
146         html += " bgcolor=#F0F0F0";
147     html += ">" + contents + "</table>";
148
149     return html;
150 }
151
152
153 QString
154 YQPkgGenericDetailsView::row( const QString & contents )
155 {
156     return "<tr>" + contents + "</tr>";
157 }
158
159
160 QString
161 YQPkgGenericDetailsView::cell( QString contents )
162 {
163     contents = htmlEscape( contents );
164     return "<td valign=top>" + contents + "</td>";
165 }
166
167
168 QString
169 YQPkgGenericDetailsView::cell( int contents )
170 {
171     QString html;
172     html.sprintf( "<td valign=top>%d</td>", contents );
173
174     return html;
175 }
176
177
178 QString
179 YQPkgGenericDetailsView::cell( const zypp::Date & date )
180 {
181     return cell( ( (time_t) date == (time_t) 0 ? "" : date.asString() ) );
182 }
183
184
185 QString
186 YQPkgGenericDetailsView::cell( const string & contents )
187 {
188     return cell( fromUTF8( contents ) );
189 }
190
191
192 QString
193 YQPkgGenericDetailsView::hcell( QString contents )
194 {
195     QString html = "<td valign=top";
196
197     if ( ! YQUI::ui()->usingVisionImpairedPalette() )
198         html += " bgcolor=#D0D0D0";
199
200     html += ">" + contents + "</td>";
201
202     return html;
203 }
204
205
206 #include "YQPkgGenericDetailsView.moc"