]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDependenciesView.cc
various compilation
[duncan/yast2-qt4.git] / src / pkg / YQPkgDependenciesView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgDependenciesView.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 <qdatetime.h>
25 #include "YQPkgDependenciesView.h"
26 #include "YQi18n.h"
27 #include "utf8.h"
28
29
30 YQPkgDependenciesView::YQPkgDependenciesView( QWidget * parent )
31     : YQPkgGenericDetailsView( parent )
32 {
33 }
34
35
36 YQPkgDependenciesView::~YQPkgDependenciesView()
37 {
38     // NOP
39 }
40
41
42 void
43 YQPkgDependenciesView::showDetails( ZyppSel selectable )
44 {
45     _selectable = selectable;
46
47     if ( ! selectable )
48     {
49         clear();
50         return;
51     }
52
53     QString html_text = htmlHeading( selectable );
54
55     ZyppObj candidate = selectable->candidateObj();
56     ZyppObj installed = selectable->installedObj();
57
58     if ( candidate && installed && candidate != installed )
59     {
60         html_text += complexTable( installed, candidate );
61     }
62     else
63     {
64         if ( candidate )
65             html_text += simpleTable( candidate );
66
67         if ( installed )
68             html_text += simpleTable( installed );
69     }
70
71     setHtml( html_text );
72 }
73
74
75 QString
76 YQPkgDependenciesView::simpleTable( ZyppObj pkg )
77 {
78     QString html = "<br>" +
79         table(
80               row( hcell( _( "Version:" ) ) + cell( pkg->edition().asString()   ) ) +
81
82               // Intentionally NOT translating the RPM depencency tags:
83               // They make only sense to users who have some basic knowledge what they are anyway.
84
85               row( "Provides:",         pkg->dep( zypp::Dep::PROVIDES           ) ) +
86               row( "Prerequires:",      pkg->dep( zypp::Dep::PREREQUIRES        ) ) +
87               row( "Requires:",         pkg->dep( zypp::Dep::REQUIRES           ) ) +
88               row( "Conflicts:",        pkg->dep( zypp::Dep::CONFLICTS          ) ) +
89               row( "Obsoletes:",        pkg->dep( zypp::Dep::OBSOLETES          ) ) +
90               row( "Recommends:",       pkg->dep( zypp::Dep::RECOMMENDS         ) ) +
91               row( "Suggests:",         pkg->dep( zypp::Dep::SUGGESTS           ) ) +
92               row( "Freshens:",         pkg->dep( zypp::Dep::FRESHENS           ) ) +
93               row( "Enances:",          pkg->dep( zypp::Dep::ENHANCES           ) ) +
94               row( "Supplements:",      pkg->dep( zypp::Dep::SUPPLEMENTS        ) )
95               );
96
97     return html;
98 }
99
100
101 QString
102 YQPkgDependenciesView::complexTable( ZyppObj installed, ZyppObj candidate )
103 {
104     ZyppObj p1 = candidate;
105     ZyppObj p2 = installed;
106
107     QString p1_header = _( "<b>Alternate Version</b>" );
108     QString p2_header = _( "<b>Installed Version</b>" );
109
110     QString html = "<br>" +
111         table(
112               row( hcell( QString( "" ) ) + hcell( "<b>" + p1_header + "</b>"       ) + hcell( "<b>" + p2_header + "</b>" ) ) +
113
114               row( hcell( _( "Version:" ) ) + cell( p1->edition().asString()    ) + cell( p2->edition().asString()      ) ) +
115
116               row( "Provides:",         p1->dep( zypp::Dep::PROVIDES    ), p2->dep( zypp::Dep::PROVIDES         ) ) +
117               row( "Prerequires:",      p1->dep( zypp::Dep::PREREQUIRES ), p2->dep( zypp::Dep::PREREQUIRES      ) ) +
118               row( "Requires:",         p1->dep( zypp::Dep::REQUIRES    ), p2->dep( zypp::Dep::REQUIRES         ) ) +
119               row( "Conflicts:",        p1->dep( zypp::Dep::CONFLICTS   ), p2->dep( zypp::Dep::CONFLICTS        ) ) +
120               row( "Obsoletes:",        p1->dep( zypp::Dep::OBSOLETES   ), p2->dep( zypp::Dep::OBSOLETES        ) ) +
121               row( "Recommends:",       p1->dep( zypp::Dep::RECOMMENDS  ), p2->dep( zypp::Dep::RECOMMENDS       ) ) +
122               row( "Suggests:",         p1->dep( zypp::Dep::SUGGESTS    ), p2->dep( zypp::Dep::SUGGESTS         ) ) +
123               row( "Freshens:",         p1->dep( zypp::Dep::FRESHENS    ), p2->dep( zypp::Dep::FRESHENS         ) ) +
124               row( "Enances:",          p1->dep( zypp::Dep::ENHANCES    ), p2->dep( zypp::Dep::ENHANCES         ) ) +
125               row( "Supplements:",      p1->dep( zypp::Dep::SUPPLEMENTS ), p2->dep( zypp::Dep::SUPPLEMENTS      ) )
126               );
127
128     return html;
129 }
130
131
132 QString
133 YQPkgDependenciesView::row( const QString &             heading,
134                             const zypp::CapSet &        capSet )
135 {
136     QString content = htmlLines( capSet );
137
138     if ( content.isEmpty() )
139         return "";
140
141     return QString( "<tr>" ) +
142         hcell( heading ) +
143         "<td>" + content + "</td>"
144         + "</tr>";
145 }
146
147
148 QString
149 YQPkgDependenciesView::row( const QString &             heading,
150                             const zypp::CapSet &        capSet1,
151                             const zypp::CapSet &        capSet2 )
152 {
153     QString content1 = htmlLines( capSet1 );
154     QString content2 = htmlLines( capSet2 );
155
156     if ( content1.isEmpty() && content2.isEmpty() )
157         return "";
158
159     return QString( "<tr>" ) +
160         hcell( heading ) +
161         "<td>" + content1 + "</td>" +
162         "<td>" + content2 + "</td>" +
163         "</tr>";
164 }
165
166
167 QString
168 YQPkgDependenciesView::htmlLines( const zypp::CapSet & capSet )
169 {
170     QString html;
171
172     for ( zypp::CapSet::const_iterator it = capSet.begin();
173           it != capSet.end();
174           ++it )
175     {
176         if ( ! html.isEmpty() )
177             html += "<br>";
178
179         html += htmlEscape( ( *it).asString().c_str() );
180     }
181
182     return html;
183 }
184
185
186 #include "YQPkgDependenciesView.moc"