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