- Added 'diffState' to ResPoolProxy (used by UI to determine whether user has
authorMichael Andres <ma@suse.de>
Wed, 22 Feb 2006 22:57:43 +0000 (22:57 +0000)
committerMichael Andres <ma@suse.de>
Wed, 22 Feb 2006 22:57:43 +0000 (22:57 +0000)
  to confirm 'canel' due to changes)

zypp/PoolItem.cc
zypp/PoolItem.h
zypp/ResPoolProxy.cc
zypp/ResPoolProxy.h

index 49b5535..4febe81 100644 (file)
@@ -55,8 +55,17 @@ namespace zypp
     { _savedStatus = _status; }
     void restoreState() const
     { _status = _savedStatus; }
+    bool sameState() const
+    {
+      if (    _status.getTransactValue() != _savedStatus.getTransactValue()
+           && !_status.isBySolver() )
+        return false;
+      if ( _status.isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
+        return false;
+      return true;
+    }
   private:
-    mutable ResStatus   _savedStatus;
+    mutable ResStatus _savedStatus;
     //@}
 
   public:
@@ -139,6 +148,9 @@ namespace zypp
   void PoolItem_Ref::restoreState() const
   { _pimpl->restoreState(); }
 
+  bool PoolItem_Ref::sameState() const
+  { _pimpl->sameState(); }
+
   /******************************************************************
    **
    **  FUNCTION NAME : operator<<
index f5e1aaa..55a6376 100644 (file)
@@ -98,6 +98,7 @@ namespace zypp
     friend class PoolItemSaver;
     void saveState() const;
     void restoreState() const;
+    bool sameState() const;
     //@}
   };
   ///////////////////////////////////////////////////////////////////
index 12ce8cb..be19c79 100644 (file)
@@ -39,6 +39,13 @@ namespace zypp
       std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
                      std::mem_fun_ref(&PoolItem::restoreState) );
     }
+
+    bool diffState( ResPool_Ref pool_r, const ResObject::Kind & kind_r ) const
+    {
+      // return whether some PoolItem::sameState reported \c false.
+      return( invokeOnEach( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
+                            std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
+    }
   };
 
   struct SelPoolHelper
@@ -159,6 +166,9 @@ namespace zypp
     void restoreState( const ResObject::Kind & kind_r ) const
     { PoolItemSaver().restoreState( _pool, kind_r ); }
 
+    bool diffState( const ResObject::Kind & kind_r ) const
+    { return PoolItemSaver().diffState( _pool, kind_r ); }
+
   private:
     ResPool_Ref _pool;
     mutable SelectablePool _selPool;
@@ -235,6 +245,9 @@ namespace zypp
   void ResPoolProxy::restoreState( const ResObject::Kind & kind_r ) const
   { _pimpl->restoreState( kind_r ); }
 
+  bool ResPoolProxy::diffState( const ResObject::Kind & kind_r ) const
+  { _pimpl->diffState( kind_r ); }
+
   /******************************************************************
    **
    **  FUNCTION NAME : operator<<
index 6029185..f2a66a2 100644 (file)
@@ -102,7 +102,11 @@ namespace zypp
 
   public:
     /** \name Save and restore state per kind of resolvable.
-     * Simple version, no savety net.
+     * Simple version, no savety net. So don't restore or diff,
+     * if you didn't save before.
+     *
+     * Diff returns true, if current stat differs from the saved
+     * state.
     */
     //@{
     void saveState( const ResObject::Kind & kind_r ) const;
@@ -116,6 +120,12 @@ namespace zypp
     template<class _Res>
       void restoreState() const
       { return restoreState( ResTraits<_Res>::kind ); }
+
+    bool diffState( const ResObject::Kind & kind_r ) const;
+
+    template<class _Res>
+      bool diffState() const
+      { return diffState( ResTraits<_Res>::kind ); }
     //@}
 
   private: