Provide Selectable::setPickStatus instead of pickInstall/Delete
[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( const 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::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
92     { return _pimpl->setCandidate( newCandidate_r, causer_r ); }
93
94     PoolItem Selectable::setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r )
95     { return _pimpl->setCandidate( PoolItem( newCandidate_r ), causer_r ); }
96
97     bool Selectable::setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
98     {
99       if ( identicalInstalled( newCandidate_r ) )
100         return setFate( UNMODIFIED, causer_r );
101       return setCandidate( newCandidate_r, causer_r ) && setFate( TO_INSTALL, causer_r );
102     }
103
104     PoolItem Selectable::theObj() const
105     { return _pimpl->theObj(); }
106
107     ////////////////////////////////////////////////////////////////////////
108
109     bool Selectable::availableEmpty() const
110     { return _pimpl->availableEmpty(); }
111
112     Selectable::available_size_type Selectable::availableSize() const
113     { return _pimpl->availableSize(); }
114
115     Selectable::available_iterator Selectable::availableBegin() const
116     { return _pimpl->availableBegin(); }
117
118     Selectable::available_iterator Selectable::availableEnd() const
119     { return _pimpl->availableEnd(); }
120
121     ////////////////////////////////////////////////////////////////////////
122
123     bool Selectable::installedEmpty() const
124     { return _pimpl->installedEmpty(); }
125
126     Selectable::installed_size_type Selectable::installedSize() const
127     { return _pimpl->installedSize(); }
128
129     Selectable::installed_iterator Selectable::installedBegin() const
130     { return _pimpl->installedBegin(); }
131
132     Selectable::installed_iterator Selectable::installedEnd() const
133     { return _pimpl->installedEnd(); }
134
135     ////////////////////////////////////////////////////////////////////////
136
137     bool Selectable::picklistEmpty() const
138     { return _pimpl->picklistEmpty();  }
139
140     Selectable::picklist_size_type Selectable::picklistSize() const
141     { return _pimpl->picklistSize(); }
142
143     Selectable::picklist_iterator Selectable::picklistBegin() const
144     { return _pimpl->picklistBegin(); }
145
146     Selectable::picklist_iterator Selectable::picklistEnd() const
147     { return _pimpl->picklistEnd(); }
148
149     ////////////////////////////////////////////////////////////////////////
150
151     bool Selectable::isUnmaintained() const
152     { return _pimpl->isUnmaintained(); }
153
154     bool Selectable::multiversionInstall() const
155     { return _pimpl->multiversionInstall(); }
156
157     bool Selectable::setPickStatus( const PoolItem & pi_r, const Status state_r, ResStatus::TransactByValue causer_r )
158     { return _pimpl->setPickStatus( pi_r, state_r, causer_r ); }
159
160     Status Selectable::pickStatus( const PoolItem & pi_r ) const
161     { return _pimpl->pickStatus( pi_r ); }
162
163     ////////////////////////////////////////////////////////////////////////
164
165     bool Selectable::isUndetermined() const
166     { return _pimpl->isUndetermined(); }
167
168     bool Selectable::isRelevant() const
169     { return _pimpl->isRelevant(); }
170
171     bool Selectable::isSatisfied() const
172     { return _pimpl->isSatisfied(); }
173
174     bool Selectable::isBroken() const
175     { return _pimpl->isBroken(); }
176
177     bool Selectable::isNeeded() const
178     {
179       return fate() == TO_INSTALL || isBroken() ;
180     }
181
182     ResStatus::TransactByValue Selectable::modifiedBy() const
183     { return _pimpl->modifiedBy(); }
184
185     bool Selectable::hasLicenceConfirmed() const
186     { return _pimpl->hasLicenceConfirmed(); }
187
188     void Selectable::setLicenceConfirmed( bool val_r )
189     { _pimpl->setLicenceConfirmed( val_r ); }
190
191
192     Selectable::Fate Selectable::fate() const
193     {
194       switch ( status() ) {
195       case S_Update:
196       case S_Install:
197       case S_AutoUpdate:
198       case S_AutoInstall:
199         return TO_INSTALL;
200         break;
201
202       case S_Del:
203       case S_AutoDel:
204         return TO_DELETE;
205         break;
206
207       case S_Protected:
208       case S_Taboo:
209       case S_KeepInstalled:
210       case S_NoInst:
211         break;
212       }
213       return UNMODIFIED;
214     };
215
216     bool Selectable::setFate( Fate fate_r, ResStatus::TransactByValue causer_r )
217     {
218       switch ( fate_r )
219       {
220         case TO_INSTALL:
221           return setStatus( hasInstalledObj() ? S_Update : S_Install, causer_r );
222           break;
223
224         case TO_DELETE:
225           return setStatus( S_Del, causer_r );
226           break;
227
228         case UNMODIFIED:
229           switch ( status() ) {
230             case S_Protected:
231             case S_Taboo:
232               return true;
233               break;
234             default:
235               return setStatus( hasInstalledObj() ? S_KeepInstalled : S_NoInst, causer_r );
236               break;
237           }
238           break;
239       }
240       return false;
241     }
242
243     bool Selectable::setInstalled( ResStatus::TransactByValue causer_r )
244     {
245       return( hasInstalledObj() || setStatus( S_Install, causer_r ) );
246     }
247
248     bool Selectable::setUpToDate( ResStatus::TransactByValue causer_r )
249     {
250       if ( ! hasInstalledObj() )
251         return setStatus( S_Install, causer_r );
252
253       PoolItem cand( candidateObj() );
254       if ( ! cand )
255         return true;
256
257       return( installedObj()->edition() >= cand->edition()
258               || setStatus( S_Update, causer_r ) );
259     }
260
261     bool Selectable::setDeleted( ResStatus::TransactByValue causer_r )
262     {
263       return( ! hasInstalledObj() || setStatus( S_Del, causer_r ) );
264     }
265
266     /******************************************************************
267     **
268     **  FUNCTION NAME : operator<<
269     **  FUNCTION TYPE : std::ostream &
270     */
271     std::ostream & operator<<( std::ostream & str, const Selectable & obj )
272     { return str << *(obj._pimpl); }
273
274     std::ostream & dumpOn( std::ostream & str, const Selectable & obj )
275     { return dumpOn( str, *(obj._pimpl) ); }
276
277     /////////////////////////////////////////////////////////////////
278   } // namespace ui
279   ///////////////////////////////////////////////////////////////////
280   /////////////////////////////////////////////////////////////////
281 } // namespace zypp
282 ///////////////////////////////////////////////////////////////////