]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgTechnicalDetailsView.cc
compile
[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 <q3valuelist.h>
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     setTextFormat( Qt::RichText );
76     setText( html_text );
77 }
78
79
80 QString
81 YQPkgTechnicalDetailsView::authorsListCell( ZyppPkg pkg ) const
82 {
83     QString html = "<td align=top>";
84     QString line;
85     list<string> authors = pkg->authors();
86     list<string>::const_iterator it = authors.begin();
87
88     while ( it != authors.end() )
89     {
90         line = fromUTF8( *it );
91         line = htmlEscape( line );
92         html += line + "<br>";
93         ++it;
94     }
95
96     html += "</td>";
97
98     return html;
99 }
100
101
102 QString
103 YQPkgTechnicalDetailsView::formatRpmGroup( ZyppPkg pkg ) const
104 {
105     QStringList groups = fromUTF8( pkg->group() ).split( '/', QString::KeepEmptyParts );
106
107     // Translate group path components
108
109     QStringList translated;
110
111     for ( QStringList::const_iterator it = groups.begin();
112           it != groups.end();
113           ++it )
114     {
115         translated.append( QString::fromUtf8( dgettext( "rpm-groups", (*it).utf8() ) ) );
116     }
117
118     return translated.join( "/" );
119 }
120
121
122 QString
123 YQPkgTechnicalDetailsView::simpleTable( ZyppSel selectable,
124                                         ZyppPkg         pkg )
125 {
126     QString html;
127
128     html += row( hcell( _( "Version:"           ) ) + cell( pkg->edition().asString()           ) );
129     html += row( hcell( _( "Build Time:"        ) ) + cell( pkg->buildtime()                    ) );
130
131     html +=
132         pkg == selectable->installedObj() ?
133         row( hcell( _( "Install Time:" ) ) + cell( pkg->installtime() ) ) : "";
134
135     html += row( hcell( _( "Package Group:"     ) ) + cell( formatRpmGroup( pkg )               ) );
136     html += row( hcell( _( "License:"           ) ) + cell( pkg->license()                      ) );
137     html += row( hcell( _( "Installed Size:"    ) ) + cell( pkg->size().asString()              ) );
138     html += row( hcell( _( "Download Size:"     ) ) + cell( pkg->downloadSize().asString()      ) );
139     html += row( hcell( _( "Distribution:"      ) ) + cell( pkg->distribution()                 ) );
140     html += row( hcell( _( "Vendor:"            ) ) + cell( pkg->vendor()                       ) );
141     html += row( hcell( _( "Packager:"          ) ) + cell( pkg->packager()                     ) );
142     html += row( hcell( _( "Architecture:"      ) ) + cell( pkg->arch().asString()              ) );
143     html += row( hcell( _( "OS:"                ) ) + cell( pkg->os()                           ) );
144     html += row( hcell( _( "Build Host:"        ) ) + cell( pkg->buildhost()                    ) );
145     html += row( hcell( _( "URL:"               ) ) + cell( pkg->url()                          ) );
146     
147 #ifdef FIXME_missing_in_zypp
148     html += row( hcell( _( "Source RPM:"        ) ) + cell( pkg->sourceloc()                    ) );
149 #endif
150     html += row( hcell( _( "Media No.:"         ) ) + cell( pkg->mediaNr()                      ) );
151     html += row( hcell( _( "Authors:"           ) ) + authorsListCell( pkg                      ) );
152     
153     html = "<br>" + table( html );
154
155     return html;
156 }
157
158
159 QString
160 YQPkgTechnicalDetailsView::complexTable( ZyppSel        selectable,
161                                          ZyppPkg        installed,
162                                          ZyppPkg        candidate )
163 {
164     ZyppPkg p1 = candidate;
165     ZyppPkg p2 = installed;
166
167     QString p1_header = _( "<b>Alternate Version</b>" );
168     QString p2_header = _( "<b>Installed Version</b>" );
169
170     QString html;
171
172     html += row( hcell( QString( "" ) )             + hcell( "<b>" + p1_header + "</b>"         ) + hcell( "<b>" + p2_header + "</b>"   ) );
173
174     html += row( hcell( _( "Version:"           ) ) + cell( p1->edition().asString()            ) + cell( p2->edition().asString()      ) );
175     html += row( hcell( _( "Build Time:"        ) ) + cell( p1->buildtime()                     ) + cell( p2->buildtime()               ) );
176     html += row( hcell( _( "Install Time:"      ) ) + cell( p1->installtime()                   ) + cell( p2->installtime()             ) );
177     html += row( hcell( _( "Package Group:"     ) ) + cell( formatRpmGroup( p1 )                ) + cell( formatRpmGroup( p2 )          ) );
178     html += row( hcell( _( "License:"           ) ) + cell( p1->license()                       ) + cell( p2->license()                 ) );
179     html += row( hcell( _( "Installed Size:"    ) ) + cell( p1->size().asString()               ) + cell( p2->size().asString()         ) );
180     html += row( hcell( _( "Download Size:"     ) ) + cell( p1->downloadSize().asString()       ) + cell( p2->downloadSize().asString() ) );
181     html += row( hcell( _( "Distribution:"      ) ) + cell( p1->distribution()                  ) + cell( p2->distribution()            ) );
182     html += row( hcell( _( "Vendor:"            ) ) + cell( p1->vendor()                        ) + cell( p2->vendor()                  ) );
183     html += row( hcell( _( "Packager:"          ) ) + cell( p1->packager()                      ) + cell( p2->packager()                ) );
184     html += row( hcell( _( "Architecture:"      ) ) + cell( p1->arch().asString()               ) + cell( p2->arch().asString()         ) );
185     html += row( hcell( _( "OS:"                ) ) + cell( p1->os()                            ) + cell( p2->os()                      ) );
186     html += row( hcell( _( "Build Host:"        ) ) + cell( p1->buildhost()                     ) + cell( p2->buildhost()               ) );
187     html += row( hcell( _( "URL:"               ) ) + cell( p1->url()                           ) + cell( p2->url()                     ) );
188 #ifdef FIXME_missing_in_zypp
189     html += row( hcell( _( "Source RPM:"        ) ) + cell( p1->sourceloc()                     ) + cell( p2->sourceloc()               ) );
190 #endif
191     html += row( hcell( _( "Media No.:"         ) ) + cell( p1->mediaNr()                       ) + cell( p2->mediaNr()                 ) );
192     html += row( hcell( _( "Authors:"           ) ) + authorsListCell( p1                       ) + authorsListCell( p2                 ) );
193
194
195     html = "<br>" + table( html );
196     
197     return html;
198 }
199
200
201 #include "YQPkgTechnicalDetailsView.moc"