- backup
authorMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 08:59:31 +0000 (08:59 +0000)
committerMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 08:59:31 +0000 (08:59 +0000)
zypp/ui/SelectableImpl.cc
zypp/ui/SelectableImpl.h

index ef708e0..a552246 100644 (file)
@@ -23,6 +23,50 @@ namespace zypp
   namespace ui
   { /////////////////////////////////////////////////////////////////
 
+    struct StatusHelper
+    {
+      StatusHelper( const Selectable::Impl & impl )
+      : _impl( impl )
+      , inst( impl.installedObj() )
+      , cand( impl.candidateObj() )
+      {}
+
+      bool hasInstalled() const
+      { return inst; }
+
+      bool hasCandidate() const
+      { return cand; }
+
+      bool hasInstalledOnly() const
+      { return inst && !cand; }
+
+      bool hasCandidateOnly() const
+      { return cand && !inst; }
+
+      bool hasBoth() const
+      { return inst && cand; }
+
+
+      bool userSetInstall() const
+      { return false; }
+
+      bool userSetDelete() const
+      { return false; }
+
+      bool userUnset() const
+      { return false; }
+
+      bool autoSetInstall() const
+      { return false; }
+
+      bool autoSetDelete() const
+      { return false; }
+
+      const Selectable::Impl & _impl;
+      PoolItem inst;
+      PoolItem cand;
+    };
+
     /**
      * \todo Still open questions in state calculation;
      * neglecting TABOO/PROTECTED
@@ -47,6 +91,57 @@ namespace zypp
       return( installedObj() ? S_KeepInstalled : S_NoInst );
     }
 
+
+    /**
+     * \todo Neglecting TABOO/PROTECTED
+    */
+    bool Selectable::Impl::set_status( const Status state_r )
+    {
+      StatusHelper self( *this );
+
+      switch ( state_r )
+        {
+        case S_Protected:
+        case S_Taboo:
+          return false;
+
+        case S_Del:
+          return self.userSetDelete();
+          break;
+
+        case S_Install:
+          return self.hasCandidateOnly() && self.userSetInstall();
+          break;
+
+        case S_Update:
+          return self.hasBoth() && self.userSetInstall();
+          break;
+
+        case S_AutoDel:
+          return self.autoSetDelete();
+          break;
+
+        case S_AutoInstall:
+          return self.hasCandidateOnly() && self.autoSetInstall();
+          break;
+
+        case S_AutoUpdate:
+          return self.hasBoth() && self.autoSetInstall();
+          break;
+
+        case S_KeepInstalled:
+          return self.hasInstalled() && self.userUnset();
+          break;
+
+        case S_NoInst:
+          return !self.hasInstalled() && self.userUnset();
+          break;
+        }
+
+      return false;
+    }
+
+
     /////////////////////////////////////////////////////////////////
   } // namespace ui
   ///////////////////////////////////////////////////////////////////
index c25e491..841c875 100644 (file)
@@ -70,15 +70,15 @@ namespace zypp
       Status status() const;
 
       /**  */
-      bool set_status( const Status state_r )
-      { return false; }
+      bool set_status( const Status state_r );
 
       /** Installed object. */
       PoolItem installedObj() const
       { return _installedItem; }
 
       /** Best among available objects.
-       * \nore Transacted Objects prefered, Status calculation relies on it.
+       * \note Transacted Objects prefered, Status calculation relies on it.
+       * \note Need sort order based on (arch,edition), requires arch compat lists.
       */
       PoolItem candidateObj() const
       { return( _availableItems.empty() ? PoolItem() : *_availableItems.begin() ); }