8095e2186c484fb82d71dee28b2e5b9db6a27ad2
[platform/upstream/libzypp.git] / zypp / ui / Selectable.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ui/Selectable.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/ui/Selectable.h"
16 #include "zypp/ui/SelectableImpl.h"
17 #include "zypp/ResPool.h"
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22   ///////////////////////////////////////////////////////////////////
23   namespace ui
24   { /////////////////////////////////////////////////////////////////
25
26     IMPL_PTR_TYPE(Selectable);
27
28     Selectable::Ptr Selectable::get( const pool::ByIdent & ident_r )
29     { return ResPool::instance().proxy().lookup( ident_r ); }
30
31     ///////////////////////////////////////////////////////////////////
32     //
33     //  METHOD NAME : Selectable::Selectable
34     //  METHOD TYPE : Ctor
35     //
36     Selectable::Selectable( Impl_Ptr pimpl_r )
37     : _pimpl( pimpl_r )
38     {}
39
40     ///////////////////////////////////////////////////////////////////
41     //
42     //  METHOD NAME : Selectable::~Selectable
43     //  METHOD TYPE : Dtor
44     //
45     Selectable::~Selectable()
46     {}
47
48     ///////////////////////////////////////////////////////////////////
49     //
50     // Forward to implementation.
51     // Restrict PoolItems to ResObject::constPtr!
52     //
53     ///////////////////////////////////////////////////////////////////
54
55     IdString Selectable::ident() const
56     { return _pimpl->ident(); }
57
58     ResObject::Kind Selectable::kind() const
59     { return _pimpl->kind(); }
60
61     const std::string & Selectable::name() const
62     { return _pimpl->name(); }
63
64     Status Selectable::status() const
65     { return _pimpl->status(); }
66
67     bool Selectable::setStatus( Status state_r, ResStatus::TransactByValue causer_r )
68     { return _pimpl->setStatus( state_r, causer_r ); }
69
70     PoolItem Selectable::installedObj() const
71     { return _pimpl->installedObj(); }
72
73     PoolItem Selectable::candidateObj() const
74     { return _pimpl->candidateObj(); }
75
76     PoolItem Selectable::candidateObjFrom( Repository repo_r ) const
77     { return _pimpl->candidateObjFrom( repo_r ); }
78
79     PoolItem Selectable::updateCandidateObj() const
80     { return _pimpl->updateCandidateObj(); }
81
82     PoolItem Selectable::highestAvailableVersionObj() const
83     { return _pimpl->highestAvailableVersionObj(); }
84
85     bool Selectable::identicalAvailable( const PoolItem & rhs ) const
86     { return _pimpl->identicalAvailable( rhs ); }
87
88     bool Selectable::identicalInstalled( const PoolItem & rhs ) const
89     { return _pimpl->identicalInstalled( rhs ); }
90
91     PoolItem Selectable::identicalAvailableObj( const PoolItem & rhs ) const
92     { return _pimpl->identicalAvailableObj( rhs ); }
93
94     PoolItem Selectable::identicalInstalledObj( const PoolItem & rhs ) const
95     { return _pimpl->identicalInstalledObj( rhs ); }
96
97     PoolItem Selectable::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
98     { return _pimpl->setCandidate( newCandidate_r, causer_r ); }
99
100     PoolItem Selectable::setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r )
101     { return _pimpl->setCandidate( PoolItem( newCandidate_r ), causer_r ); }
102
103     bool Selectable::setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
104     {
105       if ( identicalInstalled( newCandidate_r ) )
106         return setFate( UNMODIFIED, causer_r );
107       return setCandidate( newCandidate_r, causer_r ) && setFate( TO_INSTALL, causer_r );
108     }
109
110     PoolItem Selectable::theObj() const
111     { return _pimpl->theObj(); }
112
113     ////////////////////////////////////////////////////////////////////////
114
115     bool Selectable::availableEmpty() const
116     { return _pimpl->availableEmpty(); }
117
118     Selectable::available_size_type Selectable::availableSize() const
119     { return _pimpl->availableSize(); }
120
121     Selectable::available_iterator Selectable::availableBegin() const
122     { return _pimpl->availableBegin(); }
123
124     Selectable::available_iterator Selectable::availableEnd() const
125     { return _pimpl->availableEnd(); }
126
127     ////////////////////////////////////////////////////////////////////////
128
129     bool Selectable::installedEmpty() const
130     { return _pimpl->installedEmpty(); }
131
132     Selectable::installed_size_type Selectable::installedSize() const
133     { return _pimpl->installedSize(); }
134
135     Selectable::installed_iterator Selectable::installedBegin() const
136     { return _pimpl->installedBegin(); }
137
138     Selectable::installed_iterator Selectable::installedEnd() const
139     { return _pimpl->installedEnd(); }
140
141     ////////////////////////////////////////////////////////////////////////
142
143     bool Selectable::picklistEmpty() const
144     { return _pimpl->picklistEmpty();  }
145
146     Selectable::picklist_size_type Selectable::picklistSize() const
147     { return _pimpl->picklistSize(); }
148
149     Selectable::picklist_iterator Selectable::picklistBegin() const
150     { return _pimpl->picklistBegin(); }
151
152     Selectable::picklist_iterator Selectable::picklistEnd() const
153     { return _pimpl->picklistEnd(); }
154
155     ////////////////////////////////////////////////////////////////////////
156
157     bool Selectable::isUnmaintained() const
158     { return _pimpl->isUnmaintained(); }
159
160     bool Selectable::multiversionInstall() const
161     { return _pimpl->multiversionInstall(); }
162
163     bool Selectable::pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
164     { return _pimpl->pickInstall( pi_r, causer_r, yesno_r ); }
165
166     bool Selectable::pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
167     { return _pimpl->pickDelete( pi_r, causer_r, yesno_r ); }
168
169     Status Selectable::pickStatus( const PoolItem & pi_r ) const
170     { return _pimpl->pickStatus( pi_r ); }
171
172     bool Selectable::setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r )
173     { return _pimpl->setPickStatus( pi_r, state_r, causer_r ); }
174
175     ////////////////////////////////////////////////////////////////////////
176
177     bool Selectable::isUndetermined() const
178     { return _pimpl->isUndetermined(); }
179
180     bool Selectable::isRelevant() const
181     { return _pimpl->isRelevant(); }
182
183     bool Selectable::isSatisfied() const
184     { return _pimpl->isSatisfied(); }
185
186     bool Selectable::isBroken() const
187     { return _pimpl->isBroken(); }
188
189     bool Selectable::isNeeded() const
190     {
191       return fate() == TO_INSTALL || ( ! locked() && isBroken() );
192     }
193
194     bool Selectable::isUnwanted() const
195     {
196       return locked() && isBroken() ;
197     }
198
199     ResStatus::TransactByValue Selectable::modifiedBy() const
200     { return _pimpl->modifiedBy(); }
201
202     bool Selectable::hasLicenceConfirmed() const
203     { return _pimpl->hasLicenceConfirmed(); }
204
205     void Selectable::setLicenceConfirmed( bool val_r )
206     { _pimpl->setLicenceConfirmed( val_r ); }
207
208     bool Selectable::hasLocks() const
209     { return  _pimpl->hasLocks(); }
210
211     Selectable::Fate Selectable::fate() const
212     {
213       switch ( status() ) {
214       case S_Update:
215       case S_Install:
216       case S_AutoUpdate:
217       case S_AutoInstall:
218         return TO_INSTALL;
219         break;
220
221       case S_Del:
222       case S_AutoDel:
223         return TO_DELETE;
224         break;
225
226       case S_Protected:
227       case S_Taboo:
228       case S_KeepInstalled:
229       case S_NoInst:
230         break;
231       }
232       return UNMODIFIED;
233     };
234
235     bool Selectable::setFate( Fate fate_r, ResStatus::TransactByValue causer_r )
236     {
237       switch ( fate_r )
238       {
239         case TO_INSTALL:
240           return setStatus( hasInstalledObj() ? S_Update : S_Install, causer_r );
241           break;
242
243         case TO_DELETE:
244           return setStatus( S_Del, causer_r );
245           break;
246
247         case UNMODIFIED:
248           switch ( status() ) {
249             case S_Protected:
250             case S_Taboo:
251               return true;
252               break;
253             default:
254               return setStatus( hasInstalledObj() ? S_KeepInstalled : S_NoInst, causer_r );
255               break;
256           }
257           break;
258       }
259       return false;
260     }
261
262     bool Selectable::setInstalled( ResStatus::TransactByValue causer_r )
263     {
264       return( hasInstalledObj() || setStatus( S_Install, causer_r ) );
265     }
266
267     bool Selectable::setUpToDate( ResStatus::TransactByValue causer_r )
268     {
269       if ( ! hasInstalledObj() )
270         return setStatus( S_Install, causer_r );
271
272       PoolItem cand( candidateObj() );
273       if ( ! cand )
274         return true;
275
276       return( installedObj()->edition() >= cand->edition()
277               || setStatus( S_Update, causer_r ) );
278     }
279
280     bool Selectable::setDeleted( ResStatus::TransactByValue causer_r )
281     {
282       return( ! hasInstalledObj() || setStatus( S_Del, causer_r ) );
283     }
284
285     /******************************************************************
286     **
287     **  FUNCTION NAME : operator<<
288     **  FUNCTION TYPE : std::ostream &
289     */
290     std::ostream & operator<<( std::ostream & str, const Selectable & obj )
291     { return str << *(obj._pimpl); }
292
293     std::ostream & dumpOn( std::ostream & str, const Selectable & obj )
294     { return dumpOn( str, *(obj._pimpl) ); }
295
296     /////////////////////////////////////////////////////////////////
297   } // namespace ui
298   ///////////////////////////////////////////////////////////////////
299   /////////////////////////////////////////////////////////////////
300 } // namespace zypp
301 ///////////////////////////////////////////////////////////////////