Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / ResObject.cc
index dfd8018..5407b3a 100644 (file)
@@ -10,7 +10,6 @@
  *
 */
 
-#include <zypp/base/Logger.h>
 #include "zypp/ResObject.h"
 #include "zypp/sat/SolvAttr.h"
 #include "zypp/sat/Solvable.h"
@@ -18,6 +17,8 @@
 #include "zypp/RepoInfo.h"
 #include "zypp/IdString.h"
 
+#include "zypp/ui/Selectable.h"
+
 using namespace zypp;
 using namespace std;
 
@@ -55,10 +56,6 @@ namespace zypp
   }
 
   ///////////////////////////////////////////////////////////////////
-  //
-  //   ResObject interface forwarded to implementation
-  //
-  ///////////////////////////////////////////////////////////////////
 
   std::string ResObject::summary( const Locale & lang_r ) const
   { return lookupStrAttribute( sat::SolvAttr::summary, lang_r ); }
@@ -73,13 +70,35 @@ namespace zypp
   { return lookupStrAttribute( sat::SolvAttr::delnotify, lang_r ); }
 
   std::string ResObject::licenseToConfirm( const Locale & lang_r ) const
-  { return lookupStrAttribute( sat::SolvAttr::eula, lang_r ); }
+  {
+    std::string ret = lookupStrAttribute( sat::SolvAttr::eula, lang_r );
+    if ( ret.empty() && isKind<Product>() )
+    {
+      const RepoInfo & ri( repoInfo() );
+      if ( ri.needToAcceptLicense() || ! ui::Selectable::get( *this )->hasInstalledObj() )
+       ret = ri.getLicense( lang_r ); // bnc#908976: suppress informal license upon update
+    }
+    return ret;
+  }
+
+  bool ResObject::needToAcceptLicense() const
+  {
+    if ( isKind<Product>() )
+      return repoInfo().needToAcceptLicense( );
+    return true;
+  }
+
+  std::string ResObject::distribution() const
+  { return lookupStrAttribute( sat::SolvAttr::distribution ); }
+
+  CpeId ResObject::cpeId() const
+  { return CpeId( lookupStrAttribute( sat::SolvAttr::cpeid ), CpeId::noThrow ); }
 
   ByteCount ResObject::installSize() const
-  { return ByteCount( lookupNumAttribute( sat::SolvAttr::installsize ), ByteCount::K ); }
+  { return ByteCount( lookupNumAttribute( sat::SolvAttr::installsize ) ); }
 
   ByteCount ResObject::downloadSize() const
-  { return ByteCount( lookupNumAttribute( sat::SolvAttr::downloadsize ), ByteCount::K ); }
+  { return ByteCount( lookupNumAttribute( sat::SolvAttr::downloadsize ) ); }
 
   unsigned ResObject::mediaNr() const
   { return lookupNumAttribute( sat::SolvAttr::medianr ); }
@@ -90,13 +109,6 @@ namespace zypp
   Date ResObject::installtime() const
   { return Date( lookupNumAttribute( sat::SolvAttr::installtime ) ); }
 
-#warning DUMMY diskusage
-  const DiskUsage & ResObject::diskusage() const
-  {
-    static DiskUsage _du;
-    return _du;
-  }
-
    /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
@@ -109,6 +121,9 @@ namespace zypp
 
   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r )
   {
+    if ( ! solvable_r )
+      return 0;
+
     ResKind kind( solvable_r.kind() );
 #define OUTS(X)  if ( kind == ResTraits<X>::kind ) return make<X>( solvable_r );
     OUTS( Package );
@@ -116,8 +131,10 @@ namespace zypp
     OUTS( Pattern );
     OUTS( Product );
     OUTS( SrcPackage );
+    OUTS( Application );
 #undef OUTS
-    return 0;
+    // unknow => return a plain ResObject
+    return new ResObject( solvable_r );
   }
 
   /////////////////////////////////////////////////////////////////