Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / ResObject.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResObject.cc
10  *
11 */
12
13 #include "zypp/ResObject.h"
14 #include "zypp/sat/SolvAttr.h"
15 #include "zypp/sat/Solvable.h"
16 #include "zypp/Repository.h"
17 #include "zypp/RepoInfo.h"
18 #include "zypp/IdString.h"
19
20 #include "zypp/ui/Selectable.h"
21
22 using namespace zypp;
23 using namespace std;
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   IMPL_PTR_TYPE(ResObject);
30
31   ///////////////////////////////////////////////////////////////////
32   //
33   //    METHOD NAME : ResObject::ResObject
34   //    METHOD TYPE : Ctor
35   //
36   ResObject::ResObject( const sat::Solvable & solvable_r )
37   : Resolvable( solvable_r )
38   {}
39
40   ///////////////////////////////////////////////////////////////////
41   //
42   //    METHOD NAME : ResObject::~ResObject
43   //    METHOD TYPE : Dtor
44   //
45   ResObject::~ResObject()
46   {}
47
48   ///////////////////////////////////////////////////////////////////
49   //
50   //    METHOD NAME : ResObject::dumpOn
51   //    METHOD TYPE : std::ostream &
52   //
53   std::ostream & ResObject::dumpOn( std::ostream & str ) const
54   {
55     return Resolvable::dumpOn( str );
56   }
57
58   ///////////////////////////////////////////////////////////////////
59
60   std::string ResObject::summary( const Locale & lang_r ) const
61   { return lookupStrAttribute( sat::SolvAttr::summary, lang_r ); }
62
63   std::string ResObject::description( const Locale & lang_r ) const
64   { return lookupStrAttribute( sat::SolvAttr::description, lang_r ); }
65
66   std::string ResObject::insnotify( const Locale & lang_r ) const
67   { return lookupStrAttribute( sat::SolvAttr::insnotify, lang_r ); }
68
69   std::string ResObject::delnotify( const Locale & lang_r ) const
70   { return lookupStrAttribute( sat::SolvAttr::delnotify, lang_r ); }
71
72   std::string ResObject::licenseToConfirm( const Locale & lang_r ) const
73   {
74     std::string ret = lookupStrAttribute( sat::SolvAttr::eula, lang_r );
75     if ( ret.empty() && isKind<Product>() )
76     {
77       const RepoInfo & ri( repoInfo() );
78       if ( ri.needToAcceptLicense() || ! ui::Selectable::get( *this )->hasInstalledObj() )
79         ret = ri.getLicense( lang_r ); // bnc#908976: suppress informal license upon update
80     }
81     return ret;
82   }
83
84   bool ResObject::needToAcceptLicense() const
85   {
86     if ( isKind<Product>() )
87       return repoInfo().needToAcceptLicense( );
88     return true;
89   }
90
91   std::string ResObject::distribution() const
92   { return lookupStrAttribute( sat::SolvAttr::distribution ); }
93
94   CpeId ResObject::cpeId() const
95   { return CpeId( lookupStrAttribute( sat::SolvAttr::cpeid ), CpeId::noThrow ); }
96
97   ByteCount ResObject::installSize() const
98   { return ByteCount( lookupNumAttribute( sat::SolvAttr::installsize ) ); }
99
100   ByteCount ResObject::downloadSize() const
101   { return ByteCount( lookupNumAttribute( sat::SolvAttr::downloadsize ) ); }
102
103   unsigned ResObject::mediaNr() const
104   { return lookupNumAttribute( sat::SolvAttr::medianr ); }
105
106   Date ResObject::buildtime() const
107   { return Date( lookupNumAttribute( sat::SolvAttr::buildtime ) ); }
108
109   Date ResObject::installtime() const
110   { return Date( lookupNumAttribute( sat::SolvAttr::installtime ) ); }
111
112    /////////////////////////////////////////////////////////////////
113 } // namespace zypp
114 ///////////////////////////////////////////////////////////////////
115
116 #include "zypp/ResObjects.h"
117
118 ///////////////////////////////////////////////////////////////////
119 namespace zypp
120 { /////////////////////////////////////////////////////////////////
121
122   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r )
123   {
124     if ( ! solvable_r )
125       return 0;
126
127     ResKind kind( solvable_r.kind() );
128 #define OUTS(X)  if ( kind == ResTraits<X>::kind ) return make<X>( solvable_r );
129     OUTS( Package );
130     OUTS( Patch );
131     OUTS( Pattern );
132     OUTS( Product );
133     OUTS( SrcPackage );
134     OUTS( Application );
135 #undef OUTS
136     // unknow => return a plain ResObject
137     return new ResObject( solvable_r );
138   }
139
140   /////////////////////////////////////////////////////////////////
141 } // namespace zypp
142 ///////////////////////////////////////////////////////////////////