1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ui/Selectable.h
12 #ifndef ZYPP_UI_SELECTABLE_H
13 #define ZYPP_UI_SELECTABLE_H
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/base/Iterator.h"
22 #include "zypp/ui/SelectableTraits.h"
23 #include "zypp/ui/Status.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 DEFINE_PTR_TYPE(Selectable);
34 ///////////////////////////////////////////////////////////////////
36 // CLASS NAME : Selectable
38 /** Collects PoolItems of same kind and name.
40 * Selectable is a status wrapper. That's why it offers the
41 * PoolItems ResObjects but hides their individual ResStatus.
42 * The ui::Status is calculated from (and transated to)
43 * PoolItems individual ResStatus values.
45 * \note There's one Selectable per installed item, in case more
46 * than one item is intalled.
48 class Selectable : public base::ReferenceCounted, private base::NonCopyable
50 friend std::ostream & operator<<( std::ostream & str, const Selectable & obj );
53 typedef intrusive_ptr<Selectable> Ptr;
54 typedef intrusive_ptr<const Selectable> constPtr;
56 /** Iterates over ResObject::constPtr */
57 typedef SelectableTraits::available_iterator available_iterator;
58 typedef SelectableTraits::available_size_type available_size_type;
60 typedef SelectableTraits::installed_iterator installed_iterator;
61 typedef SelectableTraits::installed_size_type installed_size_type;
65 * This is the solvables \ref name, \b except for packages and
66 * source packes, prefixed by it's \ref kind.
67 * \see \ref sat::Solvable.
69 IdString ident() const;
71 /** The ResObjects kind. */
72 ResObject::Kind kind() const;
74 /** The ResObjects name. */
75 const std::string & name() const;
78 * return the first Installed object
81 PoolItem installedObj() const;
84 * \deprecated use installedObj
85 * PoolItem corresponding to the installed object.
87 ZYPP_DEPRECATED PoolItem installedPoolItem() const
88 { return installedObj(); }
90 /** Best among available objects.
91 + The user selected candiate, or a default.
93 PoolItem candidateObj() const;
95 /** PoolItem corresponding to the candidate object. */
96 ZYPP_DEPRECATED PoolItem candidatePoolItem() const
97 { return candidateObj(); }
99 /** Set a candidate (out of available objects).
100 * \return The new candidate, or NULL if choice was invalid
101 * (NULL or not among availableObjs). An invalid choice
102 * selects the default candidate.
104 PoolItem setCandidate( ResObject::constPtr byUser_r );
106 /** Best among all objects. */
107 PoolItem theObj() const;
109 ////////////////////////////////////////////////////////////////////////
112 * Are there available objects?
114 bool availableEmpty() const;
117 * Number of available objects.
119 available_size_type availableSize() const;
122 * Number of available objects.
123 * \deprecated Use availableSize
125 ZYPP_DEPRECATED available_size_type availableObjs() const
126 { return availableSize(); }
129 available_iterator availableBegin() const;
132 available_iterator availableEnd() const;
134 ////////////////////////////////////////////////////////////////////////
137 * Installed object iterators
141 * Are there installed objects?
143 bool installedEmpty() const;
146 * Number of available objects.
148 installed_size_type installedSize() const;
151 installed_iterator installedBegin() const;
154 installed_iterator installedEnd() const;
156 ////////////////////////////////////////////////////////////////////////
159 /** \name Query for objects within this Selectable.
162 /** True if either installed or candidate object is present */
163 bool hasObject() const
164 { return (! installedEmpty()) || candidateObj(); }
166 /** True if installed object is present. */
167 bool hasInstalledObj() const
168 { return ! installedEmpty(); }
170 /** True if candidate object is present. */
171 bool hasCandidateObj() const
172 { return candidateObj(); }
174 /** True if installed and candidate object is present */
175 bool hasBothObjects() const
176 { return (! installedEmpty()) && candidateObj(); }
178 /** True if installed object is present but no candidate. */
179 bool hasInstalledObjOnly() const
180 { return (! installedEmpty()) && ! candidateObj(); }
182 /** True if candidate object is present but no installed. */
183 bool hasCandidateObjOnly() const
184 { return ( installedEmpty() ) && candidateObj(); }
188 * True if this package has no replacement from
189 * the available repositories
191 bool isUnmaintained() const;
193 /** \name Classification of available patches (patterns, products).
194 * A patch is either \c not \c relevant, \c satisfied or \c broken.
197 /** Returns true for packages, because packages are not
198 * classified by the solver.
200 bool isUndetermined() const;
202 /** Returns true if the patch is relevant which means that at least
203 * one package of the patch is installed.
205 bool isRelevant() const;
207 /** Whether a relevant patchs requirements are met. */
208 bool isSatisfied() const;
210 /** Whether a relevant patchs requirements are broken. */
211 bool isBroken() const;
213 /** This includes still broken patches, as well as those already
214 * selected to be installed.
215 * This is because already selected patches will be classified as
218 bool isNeeded() const;
222 /** \name Query objects fate in case of commit.
233 /** True if either to delete or to install */
234 bool unmodified() const
235 { return fate() == UNMODIFIED; }
237 /** True if either to delete or to install */
238 bool toModify() const
239 { return fate() != UNMODIFIED; }
241 /** True if to delete */
242 bool toDelete() const
243 { return fate() == TO_DELETE; }
245 /** True if to install */
246 bool toInstall() const
247 { return fate() == TO_INSTALL; }
252 * \name Special inteface for Y2UI.
253 * \note This interface acts on \ref ResStatus::USER level.
254 * The \ref Status enum, and allowed state transitions are
255 * tightly related to the Y2UI. It might be not verry usefull
259 /** Return the current Status */
260 Status status() const;
263 * Try to set a new Status.
264 * Returns \c false if the transitions is not allowed.
266 bool setStatus( const Status state_r );
268 /** Try to set a new Status.
269 * Returns \c false if the transitions is not allowed.
271 ZYPP_DEPRECATED bool set_status( const Status state_r )
272 { return setStatus( state_r ); }
274 /** Return who caused the modification. */
275 ResStatus::TransactByValue modifiedBy() const;
277 /** Return value of LicenceConfirmed bit. */
278 bool hasLicenceConfirmed() const;
280 /** Set LicenceConfirmed bit. */
281 void setLicenceConfirmed( bool val_r = true );
285 /** Implementation */
287 typedef shared_ptr<Impl> Impl_Ptr;
289 Selectable( Impl_Ptr pimpl_r );
294 /** Pointer to implementation */
295 RW_pointer<Impl> _pimpl;
297 ///////////////////////////////////////////////////////////////////
299 /** \relates Selectable Stream output */
300 std::ostream & operator<<( std::ostream & str, const Selectable & obj );
302 /** Solvable to Selectable transform functor.
303 * \relates Selectable
304 * \relates sat::SolvIterMixin
308 typedef Selectable_Ptr result_type;
310 Selectable_Ptr operator()( const sat::Solvable & solv_r ) const;
312 Selectable_Ptr operator()( const PoolItem & pi_r ) const
313 { return operator()( pi_r.satSolvable() ); }
316 /////////////////////////////////////////////////////////////////
318 ///////////////////////////////////////////////////////////////////
319 /////////////////////////////////////////////////////////////////
321 ///////////////////////////////////////////////////////////////////
322 #endif // ZYPP_UI_SELECTABLE_H