]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgTechnicalDetailsView.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / pkg / YQPkgTechnicalDetailsView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgTechnicalDetailsView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23
24 #include "YQPkgTechnicalDetailsView.h"
25 #include "YQi18n.h"
26 #include "utf8.h"
27 //Added by qt3to4:
28 #include <QList>
29
30 using std::list;
31 using std::string;
32
33
34 YQPkgTechnicalDetailsView::YQPkgTechnicalDetailsView( QWidget * parent )
35     : YQPkgGenericDetailsView( parent )
36 {
37 }
38
39
40 YQPkgTechnicalDetailsView::~YQPkgTechnicalDetailsView()
41 {
42     // NOP
43 }
44
45
46 void
47 YQPkgTechnicalDetailsView::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     ZyppPkg candidate = tryCastToZyppPkg( selectable->candidateObj() );
60     ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
61
62     if ( candidate && installed && candidate != installed )
63     {
64         html_text += complexTable( selectable, installed, candidate );
65     }
66     else
67     {
68         if ( candidate )
69             html_text += simpleTable( selectable, candidate );
70
71         if ( installed )
72             html_text += simpleTable( selectable, installed );
73     }
74
75     setHtml( html_text );
76 }
77
78
79 QString
80 YQPkgTechnicalDetailsView::authorsListCell( ZyppPkg pkg ) const
81 {
82     QString html = "<td align=top>";
83     QString line;
84     list<string> authors = pkg->authors();
85     list<string>::const_iterator it = authors.begin();
86
87     while ( it != authors.end() )
88     {
89         line = fromUTF8( *it );
90         line = htmlEscape( line );
91         html += line + "<br>";
92         ++it;
93     }
94
95     html += "</td>";
96
97     return html;
98 }
99
100
101 QString
102 YQPkgTechnicalDetailsView::formatRpmGroup( ZyppPkg pkg ) const
103 {
104     QStringList groups = fromUTF8( pkg->group() ).split( '/', QString::KeepEmptyParts );
105
106     // Translate group path components
107
108     QStringList translated;
109
110     for ( QStringList::const_iterator it = groups.begin();
111           it != groups.end();
112           ++it )
113     {
114         translated.append( QString::fromUtf8( dgettext( "rpm-groups", (*it).toUtf8() ) ) );
115     }
116
117     return translated.join( "/" );
118 }
119
120
121 QString
122 YQPkgTechnicalDetailsView::simpleTable( ZyppSel selectable,
123                                         ZyppPkg         pkg )
124 {
125     QString html;
126
127     html += row( hcell( _( "Version:"           ) ) + cell( pkg->edition().asString()           ) );
128     html += row( hcell( _( "Build Time:"        ) ) + cell( pkg->buildtime()                    ) );
129
130     html +=
131         pkg == selectable->installedObj() ?
132         row( hcell( _( "Install Time:" ) ) + cell( pkg->installtime() ) ) : "";
133
134     html += row( hcell( _( "Package Group:"     ) ) + cell( formatRpmGroup( pkg )               ) );
135     html += row( hcell( _( "License:"           ) ) + cell( pkg->license()                      ) );
136     html += row( hcell( _( "Installed Size:"    ) ) + cell( pkg->size().asString()              ) );
137     html += row( hcell( _( "Download Size:"     ) ) + cell( pkg->downloadSize().asString()      ) );
138     html += row( hcell( _( "Distribution:"      ) ) + cell( pkg->distribution()                 ) );
139     html += row( hcell( _( "Vendor:"            ) ) + cell( pkg->vendor()                       ) );
140     html += row( hcell( _( "Packager:"          ) ) + cell( pkg->packager()                     ) );
141     html += row( hcell( _( "Architecture:"      ) ) + cell( pkg->arch().asString()              ) );
142     html += row( hcell( _( "OS:"                ) ) + cell( pkg->os()                           ) );
143     html += row( hcell( _( "Build Host:"        ) ) + cell( pkg->buildhost()                    ) );
144     html += row( hcell( _( "URL:"               ) ) + cell( pkg->url()                          ) );
145     
146 #ifdef FIXME_missing_in_zypp
147     html += row( hcell( _( "Source RPM:"        ) ) + cell( pkg->sourceloc()                    ) );
148 #endif
149     html += row( hcell( _( "Media No.:"         ) ) + cell( pkg->mediaNr()                      ) );
150     html += row( hcell( _( "Authors:"           ) ) + authorsListCell( pkg                      ) );
151     
152     html = "<br>" + table( html );
153
154     return html;
155 }
156
157
158 QString
159 YQPkgTechnicalDetailsView::complexTable( ZyppSel        selectable,
160                                          ZyppPkg        installed,
161                                          ZyppPkg        candidate )
162 {
163     ZyppPkg p1 = candidate;
164     ZyppPkg p2 = installed;
165
166     QString p1_header = _( "<b>Alternate Version</b>" );
167     QString p2_header = _( "<b>Installed Version</b>" );
168
169     QString html;
170
171     html += row( hcell( QString( "" ) )             + hcell( "<b>" + p1_header + "</b>"         ) + hcell( "<b>" + p2_header + "</b>"   ) );
172
173     html += row( hcell( _( "Version:"           ) ) + cell( p1->edition().asString()            ) + cell( p2->edition().asString()      ) );
174     html += row( hcell( _( "Build Time:"        ) ) + cell( p1->buildtime()                     ) + cell( p2->buildtime()               ) );
175     html += row( hcell( _( "Install Time:"      ) ) + cell( p1->installtime()                   ) + cell( p2->installtime()             ) );
176     html += row( hcell( _( "Package Group:"     ) ) + cell( formatRpmGroup( p1 )                ) + cell( formatRpmGroup( p2 )          ) );
177     html += row( hcell( _( "License:"           ) ) + cell( p1->license()                       ) + cell( p2->license()                 ) );
178     html += row( hcell( _( "Installed Size:"    ) ) + cell( p1->size().asString()               ) + cell( p2->size().asString()         ) );
179     html += row( hcell( _( "Download Size:"     ) ) + cell( p1->downloadSize().asString()       ) + cell( p2->downloadSize().asString() ) );
180     html += row( hcell( _( "Distribution:"      ) ) + cell( p1->distribution()                  ) + cell( p2->distribution()            ) );
181     html += row( hcell( _( "Vendor:"            ) ) + cell( p1->vendor()                        ) + cell( p2->vendor()                  ) );
182     html += row( hcell( _( "Packager:"          ) ) + cell( p1->packager()                      ) + cell( p2->packager()                ) );
183     html += row( hcell( _( "Architecture:"      ) ) + cell( p1->arch().asString()               ) + cell( p2->arch().asString()         ) );
184     html += row( hcell( _( "OS:"                ) ) + cell( p1->os()                            ) + cell( p2->os()                      ) );
185     html += row( hcell( _( "Build Host:"        ) ) + cell( p1->buildhost()                     ) + cell( p2->buildhost()               ) );
186     html += row( hcell( _( "URL:"               ) ) + cell( p1->url()                           ) + cell( p2->url()                     ) );
187 #ifdef FIXME_missing_in_zypp
188     html += row( hcell( _( "Source RPM:"        ) ) + cell( p1->sourceloc()                     ) + cell( p2->sourceloc()               ) );
189 #endif
190     html += row( hcell( _( "Media No.:"         ) ) + cell( p1->mediaNr()                       ) + cell( p2->mediaNr()                 ) );
191     html += row( hcell( _( "Authors:"           ) ) + authorsListCell( p1                       ) + authorsListCell( p2                 ) );
192
193
194     html = "<br>" + table( html );
195     
196     return html;
197 }
198
199
200 #include "YQPkgTechnicalDetailsView.moc"