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 /** Whether the item is relevant but has broken requirements.
194 * A 'needed' Patch should be installed, while an 'unneeded' one
195 * is either applied or not relevant for the system.
197 bool isNeeded() const;
200 /** \name Query objects fate in case of commit.
211 /** True if either to delete or to install */
212 bool unmodified() const
213 { return fate() == UNMODIFIED; }
215 /** True if either to delete or to install */
216 bool toModify() const
217 { return fate() != UNMODIFIED; }
219 /** True if to delete */
220 bool toDelete() const
221 { return fate() == TO_DELETE; }
223 /** True if to install */
224 bool toInstall() const
225 { return fate() == TO_INSTALL; }
230 * \name Special inteface for Y2UI.
231 * \note This interface acts on \ref ResStatus::USER level.
232 * The \ref Status enum, and allowed state transitions are
233 * tightly related to the Y2UI. It might be not verry usefull
237 /** Return the current Status */
238 Status status() const;
241 * Try to set a new Status.
242 * Returns \c false if the transitions is not allowed.
244 bool setStatus( const Status state_r );
246 /** Try to set a new Status.
247 * Returns \c false if the transitions is not allowed.
249 ZYPP_DEPRECATED bool set_status( const Status state_r )
250 { return setStatus( state_r ); }
252 /** Return who caused the modification. */
253 ResStatus::TransactByValue modifiedBy() const;
255 /** Return value of LicenceConfirmed bit. */
256 bool hasLicenceConfirmed() const;
258 /** Set LicenceConfirmed bit. */
259 void setLicenceConfirmed( bool val_r = true );
265 /** Implementation */
267 typedef shared_ptr<Impl> Impl_Ptr;
269 Selectable( Impl_Ptr pimpl_r );
274 /** Pointer to implementation */
275 RW_pointer<Impl> _pimpl;
277 ///////////////////////////////////////////////////////////////////
279 /** \relates Selectable Stream output */
280 std::ostream & operator<<( std::ostream & str, const Selectable & obj );
282 /** Solvable to Selectable transform functor.
283 * \relates Selectable
284 * \relates sat::SolvIterMixin
288 typedef Selectable_Ptr result_type;
290 Selectable_Ptr operator()( const sat::Solvable & solv_r ) const;
292 Selectable_Ptr operator()( const PoolItem & pi_r ) const
293 { return operator()( pi_r.satSolvable() ); }
296 /////////////////////////////////////////////////////////////////
298 ///////////////////////////////////////////////////////////////////
299 /////////////////////////////////////////////////////////////////
301 ///////////////////////////////////////////////////////////////////
302 #endif // ZYPP_UI_SELECTABLE_H