1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ui/SelectableImpl.cc
13 //#include "zypp/base/Logger.h"
15 #include "zypp/ui/SelectableImpl.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : StatusHelper
34 StatusHelper( const Selectable::Impl & impl )
36 , inst( impl.installedObj() )
37 , cand( impl.candidateObj() )
43 bool hasInstalled() const
46 bool hasCandidate() const
49 bool hasInstalledOnly() const
50 { return inst && !cand; }
52 bool hasCandidateOnly() const
53 { return cand && !inst; }
56 { return inst && cand; }
61 void resetTransactingCandidates() const
63 for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin();
64 it != _impl.availableEnd(); ++it )
66 (*it).status().setTransact( false, ResStatus::USER );
69 void unlockCandidates() const
71 for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin();
72 it != _impl.availableEnd(); ++it )
74 (*it).status().setTransact( false, ResStatus::USER );
75 (*it).status().setLock( false, ResStatus::USER );
78 void lockCandidates() const
80 for ( Selectable::Impl::available_const_iterator it = _impl.availableBegin();
81 it != _impl.availableEnd(); ++it )
83 (*it).status().setTransact( false, ResStatus::USER );
84 (*it).status().setLock( true, ResStatus::USER );
88 bool setInstall() const
93 inst.status().resetTransact( ResStatus::USER );
94 inst.status().setLock ( false, ResStatus::USER );
95 if ( ! cand->installOnly() )
97 // This is what the solver most probabely will do.
98 // If we are wrong the solver will correct it. But
99 // this way we will get a better disk usage result,
100 // even if no autosolving is on.
101 inst.status().setTransact( true, ResStatus::SOLVER );
105 return cand.status().setToBeInstalled( ResStatus::USER );
110 bool setDelete() const
114 resetTransactingCandidates();
115 inst.status().setLock( false, ResStatus::USER );
116 return inst.status().setToBeUninstalled( ResStatus::USER );
124 inst.status().resetTransact( ResStatus::USER );
125 inst.status().setLock( false, ResStatus::USER );
131 bool setProtected() const
134 resetTransactingCandidates();
135 inst.status().resetTransact( ResStatus::USER );
136 return inst.status().setLock( true, ResStatus::USER );
141 bool setTaboo() const
152 const Selectable::Impl & _impl;
156 ///////////////////////////////////////////////////////////////////
158 ///////////////////////////////////////////////////////////////////
160 // CLASS NAME : Selectable::Impl
162 ///////////////////////////////////////////////////////////////////
164 Status Selectable::Impl::status() const
166 PoolItem cand( candidateObj() );
167 if ( cand && cand.status().transacts() )
169 if ( cand.status().isByUser() )
170 return( installedObj() ? S_Update : S_Install );
172 return( installedObj() ? S_AutoUpdate : S_AutoInstall );
175 if ( installedObj() && installedObj().status().transacts() )
177 return( installedObj().status().isByUser() ? S_Del : S_AutoDel );
180 if ( installedObj() && installedObj().status().isLocked() )
183 if ( !installedObj() && allCandidatesLocked() )
186 // non packages are handled differently
187 if ( ! isKind<Package>(cand.resolvable()) )
189 return( cand.status().isSatisfied() ? S_KeepInstalled : S_NoInst );
192 return( installedObj() ? S_KeepInstalled : S_NoInst );
195 bool Selectable::Impl::setStatus( const Status state_r )
197 StatusHelper self( *this );
202 return self.setProtected();
204 return self.setTaboo();
208 // Auto level is SOLVER level. UI may query, but not
209 // set at this level.
213 return self.setDelete();
217 return self.hasCandidateOnly() && self.setInstall();
221 return self.hasBoth() && self.setInstall();
224 case S_KeepInstalled:
225 return self.hasInstalled() && self.unset();
229 return !self.hasInstalled() && self.unset();
236 PoolItem Selectable::Impl::setCandidate( ResObject::constPtr byUser_r )
238 _candidate = PoolItem();
240 if ( byUser_r ) // must be in available list
242 for ( available_const_iterator it = availableBegin();
243 it != availableEnd(); ++it )
245 if ( it->resolvable() == byUser_r )
255 PoolItem trans( transactingCandidate() );
256 if ( trans && trans != _candidate )
258 // adjust transact to the new cancidate
259 trans.status().setTransact( false, ResStatus::USER );
260 _candidate.status().setTransact( true, ResStatus::USER );
267 ResStatus::TransactByValue Selectable::Impl::modifiedBy() const
269 PoolItem cand( candidateObj() );
270 if ( cand && cand.status().transacts() )
271 return cand.status().getTransactByValue();
273 if ( installedObj() && installedObj().status().transacts() )
274 return installedObj().status().getTransactByValue();
277 return cand.status().getTransactByValue();
279 if ( installedObj() )
280 return installedObj().status().getTransactByValue();
282 return ResStatus::SOLVER;
285 /////////////////////////////////////////////////////////////////
287 ///////////////////////////////////////////////////////////////////
288 /////////////////////////////////////////////////////////////////
290 ///////////////////////////////////////////////////////////////////