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 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
33 DEFINE_PTR_TYPE(Selectable);
35 ///////////////////////////////////////////////////////////////////
37 // CLASS NAME : Selectable
39 /** Collects PoolItems of same kind and name.
41 * Selectable is a status wrapper. That's why it offers the
42 * PoolItems ResObjects but hides their individual ResStatus.
43 * The ui::Status is calculated from (and transated to)
44 * PoolItems individual ResStatus values.
46 * \note There's one Selectable per installed item, in case more
47 * than one item is intalled.
49 class Selectable : public base::ReferenceCounted, private base::NonCopyable
51 friend std::ostream & operator<<( std::ostream & str, const Selectable & obj );
52 friend std::ostream & dumpOn( std::ostream & str, const Selectable & obj );
55 typedef intrusive_ptr<Selectable> Ptr;
56 typedef intrusive_ptr<const Selectable> constPtr;
58 /** Iterates over ResObject::constPtr */
59 typedef SelectableTraits::available_iterator available_iterator;
60 typedef SelectableTraits::available_size_type available_size_type;
62 typedef SelectableTraits::installed_iterator installed_iterator;
63 typedef SelectableTraits::installed_size_type installed_size_type;
66 /** \name Static ctor substitues picking the item from the pool.
68 * Selectable::Ptr item;
69 * item = Selectable::get( "amarok ); // package amamrok
70 * item = Selectable::get( ResKind::patch, "amarok ); // patch amamrok
71 * item = Selectable::get( IdString( "patch:amarok" ); // patch amamrok
75 /** Get the \ref Selctable */
76 static Ptr get( const pool::ByIdent & ident_r );
78 /** Get the \ref Selctable by it's \c sat-identifyer. */
79 static Ptr get( IdString ident_r )
80 { return get( pool::ByIdent( ident_r ) ); }
82 /** Get the \ref Selctable by \c kind and \c name. */
83 static Ptr get( ResKind kind_r, const std::string & name_r )
84 { return get( pool::ByIdent( kind_r, name_r ) ); }
86 /** Get the \c Package \ref Selctable by \c name. */
87 static Ptr get( const std::string & name_r )
88 { return get( pool::ByIdent( ResKind::package, name_r ) ); }
90 /** Get the \ref Selctable containing a specific \ref sat::Solvable. */
91 static Ptr get( const sat::Solvable & solv_r )
92 { return get( pool::ByIdent( solv_r ) ); }
94 /** Get the \ref Selctable containing a specific \ref ResObject. */
95 static Ptr get( const ResObject::constPtr & resolvable_r )
96 { return resolvable_r ? get( resolvable_r->satSolvable() ) : Ptr(); }
98 /** Get the \ref Selctable containing a specific \ref PoolItem. */
99 static Ptr get( const PoolItem & pi_r )
100 { return get( pi_r.satSolvable() ); }
105 * This is the solvables \ref name, \b except for packages and
106 * source packes, prefixed by it's \ref kind.
107 * \see \ref sat::Solvable.
109 IdString ident() const;
111 /** The ResObjects kind. */
112 ResObject::Kind kind() const;
114 /** The ResObjects name. */
115 const std::string & name() const;
117 /** The last Installed object. */
118 PoolItem installedObj() const;
120 /** Best among available objects.
121 * The user selected candiate, or a default.
123 PoolItem candidateObj() const;
125 /** Set a candidate (out of available objects).
126 * \return The new candidate, or NULL if choice was invalid
127 * (NULL or not among availableObjs). An invalid choice
128 * selects the default candidate.
130 PoolItem setCandidate( ResObject::constPtr byUser_r );
132 /** Best among all objects. */
133 PoolItem theObj() const;
135 ////////////////////////////////////////////////////////////////////////
137 /** \name Available objects iterators.
138 * Oredered according to solver policy. 'Best' first.
141 bool availableEmpty() const;
142 available_size_type availableSize() const;
143 available_iterator availableBegin() const;
144 available_iterator availableEnd() const;
147 ////////////////////////////////////////////////////////////////////////
149 /** \name Insatlled objects iterators.
150 * Ordered by install time. Latest first.
153 bool installedEmpty() const;
154 installed_size_type installedSize() const;
155 installed_iterator installedBegin() const;
156 installed_iterator installedEnd() const;
159 ////////////////////////////////////////////////////////////////////////
162 /** \name Query for objects within this Selectable.
165 /** True if either installed or candidate object is present */
166 bool hasObject() const
167 { return (! installedEmpty()) || candidateObj(); }
169 /** True if installed object is present. */
170 bool hasInstalledObj() const
171 { return ! installedEmpty(); }
173 /** True if candidate object is present. */
174 bool hasCandidateObj() const
175 { return candidateObj(); }
177 /** True if installed and candidate object is present */
178 bool hasBothObjects() const
179 { return (! installedEmpty()) && candidateObj(); }
181 /** True if installed object is present but no candidate. */
182 bool hasInstalledObjOnly() const
183 { return (! installedEmpty()) && ! candidateObj(); }
185 /** True if candidate object is present but no installed. */
186 bool hasCandidateObjOnly() const
187 { return ( installedEmpty() ) && candidateObj(); }
191 * True if this package has no replacement from
192 * the available repositories
194 bool isUnmaintained() const;
196 /** \name Classification of available patches (pseudo installed items).
197 * A patch is either \c not \c relevant, \c satisfied or \c broken.
198 * The same applies to other pseudo installed kinds.
199 * \see \ref traits::isPseudoInstalled
202 /** Returns true for packages, because packages are not
203 * classified by the solver.
205 bool isUndetermined() const;
207 /** Returns true if the patch is relevant which means that at least
208 * one package of the patch is installed.
210 bool isRelevant() const;
212 /** Whether a relevant patchs requirements are met. */
213 bool isSatisfied() const;
215 /** Whether a relevant patchs requirements are broken. */
216 bool isBroken() const;
218 /** This includes still broken patches, as well as those already
219 * selected to be installed.
220 * This is because already selected patches will be classified as
223 bool isNeeded() const;
227 /** \name Query objects fate in case of commit.
238 /** True if either to delete or to install */
239 bool unmodified() const
240 { return fate() == UNMODIFIED; }
242 /** True if either to delete or to install */
243 bool toModify() const
244 { return fate() != UNMODIFIED; }
246 /** True if to delete */
247 bool toDelete() const
248 { return fate() == TO_DELETE; }
250 /** True if to install */
251 bool toInstall() const
252 { return fate() == TO_INSTALL; }
257 * \name Special inteface for Y2UI.
258 * \note This interface acts on \ref ResStatus::USER level.
259 * The \ref Status enum, and allowed state transitions are
260 * tightly related to the Y2UI. It might be not verry usefull
264 /** Return the current Status */
265 Status status() const;
268 * Try to set a new Status.
269 * Returns \c false if the transitions is not allowed.
271 bool setStatus( const Status state_r );
273 /** Return who caused the modification. */
274 ResStatus::TransactByValue modifiedBy() const;
276 /** Return value of LicenceConfirmed bit. */
277 bool hasLicenceConfirmed() const;
279 /** Set LicenceConfirmed bit. */
280 void setLicenceConfirmed( bool val_r = true );
284 /** Implementation */
286 typedef shared_ptr<Impl> Impl_Ptr;
288 Selectable( Impl_Ptr pimpl_r );
293 /** Pointer to implementation */
294 RW_pointer<Impl> _pimpl;
296 ///////////////////////////////////////////////////////////////////
298 /** \relates Selectable Stream output */
299 std::ostream & operator<<( std::ostream & str, const Selectable & obj );
301 /** \relates Selectable More verbose stream output */
302 std::ostream & dumpOn( std::ostream & str, const Selectable & obj );
304 /** Solvable to Selectable transform functor.
305 * \relates Selectable
306 * \relates sat::SolvIterMixin
310 typedef Selectable_Ptr result_type;
312 Selectable_Ptr operator()( const sat::Solvable & solv_r ) const;
314 Selectable_Ptr operator()( const PoolItem & pi_r ) const
315 { return operator()( pi_r.satSolvable() ); }
318 /////////////////////////////////////////////////////////////////
320 ///////////////////////////////////////////////////////////////////
321 /////////////////////////////////////////////////////////////////
323 ///////////////////////////////////////////////////////////////////
324 #endif // ZYPP_UI_SELECTABLE_H