]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDependenciesView.cc
restart qt4 porting
[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     setTextFormat( Qt::RichText );
72     setText( html_text );
73 }
74
75
76 QString
77 YQPkgDependenciesView::simpleTable( ZyppObj pkg )
78 {
79     QString html = "<br>" +
80         table(
81               row( hcell( _( "Version:" ) ) + cell( pkg->edition().asString()   ) ) +
82
83               // Intentionally NOT translating the RPM depencency tags:
84               // They make only sense to users who have some basic knowledge what they are anyway.
85
86               row( "Provides:",         pkg->dep( zypp::Dep::PROVIDES           ) ) +
87               row( "Prerequires:",      pkg->dep( zypp::Dep::PREREQUIRES        ) ) +
88               row( "Requires:",         pkg->dep( zypp::Dep::REQUIRES           ) ) +
89               row( "Conflicts:",        pkg->dep( zypp::Dep::CONFLICTS          ) ) +
90               row( "Obsoletes:",        pkg->dep( zypp::Dep::OBSOLETES          ) ) +
91               row( "Recommends:",       pkg->dep( zypp::Dep::RECOMMENDS         ) ) +
92               row( "Suggests:",         pkg->dep( zypp::Dep::SUGGESTS           ) ) +
93               row( "Freshens:",         pkg->dep( zypp::Dep::FRESHENS           ) ) +
94               row( "Enances:",          pkg->dep( zypp::Dep::ENHANCES           ) ) +
95               row( "Supplements:",      pkg->dep( zypp::Dep::SUPPLEMENTS        ) )
96               );
97
98     return html;
99 }
100
101
102 QString
103 YQPkgDependenciesView::complexTable( ZyppObj installed, ZyppObj candidate )
104 {
105     ZyppObj p1 = candidate;
106     ZyppObj p2 = installed;
107
108     QString p1_header = _( "<b>Alternate Version</b>" );
109     QString p2_header = _( "<b>Installed Version</b>" );
110
111     QString html = "<br>" +
112         table(
113               row( hcell( QString( "" ) ) + hcell( "<b>" + p1_header + "</b>"       ) + hcell( "<b>" + p2_header + "</b>" ) ) +
114
115               row( hcell( _( "Version:" ) ) + cell( p1->edition().asString()    ) + cell( p2->edition().asString()      ) ) +
116
117               row( "Provides:",         p1->dep( zypp::Dep::PROVIDES    ), p2->dep( zypp::Dep::PROVIDES         ) ) +
118               row( "Prerequires:",      p1->dep( zypp::Dep::PREREQUIRES ), p2->dep( zypp::Dep::PREREQUIRES      ) ) +
119               row( "Requires:",         p1->dep( zypp::Dep::REQUIRES    ), p2->dep( zypp::Dep::REQUIRES         ) ) +
120               row( "Conflicts:",        p1->dep( zypp::Dep::CONFLICTS   ), p2->dep( zypp::Dep::CONFLICTS        ) ) +
121               row( "Obsoletes:",        p1->dep( zypp::Dep::OBSOLETES   ), p2->dep( zypp::Dep::OBSOLETES        ) ) +
122               row( "Recommends:",       p1->dep( zypp::Dep::RECOMMENDS  ), p2->dep( zypp::Dep::RECOMMENDS       ) ) +
123               row( "Suggests:",         p1->dep( zypp::Dep::SUGGESTS    ), p2->dep( zypp::Dep::SUGGESTS         ) ) +
124               row( "Freshens:",         p1->dep( zypp::Dep::FRESHENS    ), p2->dep( zypp::Dep::FRESHENS         ) ) +
125               row( "Enances:",          p1->dep( zypp::Dep::ENHANCES    ), p2->dep( zypp::Dep::ENHANCES         ) ) +
126               row( "Supplements:",      p1->dep( zypp::Dep::SUPPLEMENTS ), p2->dep( zypp::Dep::SUPPLEMENTS      ) )
127               );
128
129     return html;
130 }
131
132
133 QString
134 YQPkgDependenciesView::row( const QString &             heading,
135                             const zypp::CapSet &        capSet )
136 {
137     QString content = htmlLines( capSet );
138
139     if ( content.isEmpty() )
140         return "";
141
142     return QString( "<tr>" ) +
143         hcell( heading ) +
144         "<td>" + content + "</td>"
145         + "</tr>";
146 }
147
148
149 QString
150 YQPkgDependenciesView::row( const QString &             heading,
151                             const zypp::CapSet &        capSet1,
152                             const zypp::CapSet &        capSet2 )
153 {
154     QString content1 = htmlLines( capSet1 );
155     QString content2 = htmlLines( capSet2 );
156
157     if ( content1.isEmpty() && content2.isEmpty() )
158         return "";
159
160     return QString( "<tr>" ) +
161         hcell( heading ) +
162         "<td>" + content1 + "</td>" +
163         "<td>" + content2 + "</td>" +
164         "</tr>";
165 }
166
167
168 QString
169 YQPkgDependenciesView::htmlLines( const zypp::CapSet & capSet )
170 {
171     QString html;
172
173     for ( zypp::CapSet::const_iterator it = capSet.begin();
174           it != capSet.end();
175           ++it )
176     {
177         if ( ! html.isEmpty() )
178             html += "<br>";
179
180         html += htmlEscape( ( *it).asString().c_str() );
181     }
182
183     return html;
184 }
185
186
187 #include "YQPkgDependenciesView.moc"