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 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : Selectable
36 /** Collects ResObject of same kind and name.
38 * \note There's one Selectable per installed item, in case more
39 * than one item is intalled.
41 * \todo Make it a _Ref.
43 class Selectable : public base::ReferenceCounted, private base::NonCopyable
45 friend std::ostream & operator<<( std::ostream & str, const Selectable & obj );
48 typedef intrusive_ptr<Selectable> Ptr;
49 typedef intrusive_ptr<const Selectable> constPtr;
51 /** Iterates over ResObject::constPtr */
52 typedef SelectableTraits::available_iterator available_iterator;
53 typedef SelectableTraits::availableItem_size_type size_type;
56 /** The ResObjects kind. */
57 ResObject::Kind kind() const;
59 /** The ResObjects name. */
60 const std::string & name() const;
62 /** Installed object. */
63 ResObject::constPtr installedObj() const;
65 /** Best among available objects. */
66 ResObject::constPtr candidateObj() const;
68 /** Best among all objects. */
69 ResObject::constPtr theObj() const;
71 /** Number of available objects. */
72 size_type availableObjs() const;
75 available_iterator availableBegin() const;
78 available_iterator availableEnd() const;
81 /** \name Query for objects within this Selectable.
84 /** True if either installed or candidate object is present */
85 bool hasObject() const
86 { return installedObj() || candidateObj(); }
88 /** True if installed object is present. */
89 bool hasInstalledObj() const
90 { return installedObj(); }
92 /** True if candidate object is present. */
93 bool hasCandidateObj() const
94 { return candidateObj(); }
96 /** True if installed and candidate object is present */
97 bool hasBothObjects() const
98 { return installedObj() && candidateObj(); }
100 /** True if installed object is present but no candidate. */
101 bool hasInstalledObjOnly() const
102 { return installedObj() && ! candidateObj(); }
104 /** True if candidate object is present but no installed. */
105 bool hasCandidateObjOnly() const
106 { return ! installedObj() && candidateObj(); }
110 /** \name Query objects fate in case of commit.
119 Fate fate() const { return UNMODIFIED; } //TBI
121 /** True if either to delete or to install */
122 bool unmodified() const
123 { return fate() == UNMODIFIED; }
125 /** True if either to delete or to install */
126 bool toModify() const
127 { return fate() != UNMODIFIED; }
129 /** True if to delete */
130 bool toDelete() const
131 { return fate() == TO_DELETE; }
133 /** True if to install */
134 bool toInstall() const
135 { return fate() == TO_INSTALL; }
137 /** Return who caused the modification. */
138 ResStatus::TransactByValue modifiedBy() const { return ResStatus::USER; } //TBI
140 /** True if modification was caused by by_r. */
141 bool isModifiedBy( ResStatus::TransactByValue by_r ) const;
143 /** True if the object won't be present on the targetSystem after commit. */
144 bool isOffSystem() const { return false; } //TBI
146 /** True if the object will be present on the targetSystem after commit. */
147 bool isOnSystem() const { return false; } //TBI
151 /** \name Status manipulation.
153 * \note Every status manipulation will fail, if it
154 * contradicts an action with higher ResStatus::TransactByValue.
157 bool setFate( Fate fate_r, ResStatus::TransactByValue by_r )
158 { return false; } //TBI
161 bool setUnmodified( ResStatus::TransactByValue by_r )
162 { return setFate( UNMODIFIED, by_r ); }
164 /** Request to delete an installed object.
165 * Also fails if no installed object is present.
167 bool setToDelete( ResStatus::TransactByValue by_r )
168 { return setFate( TO_DELETE, by_r ); }
170 /** Request to install an available object.
171 * Also fails if no available object is present.
173 bool setToInstall( ResStatus::TransactByValue by_r )
174 { return setFate( TO_INSTALL, by_r ); }
176 /** Request to take care the object is not present after commit.
177 * Delete if installed, and do not install.
179 bool setOffSystem( ResStatus::TransactByValue by_r )
180 { return false; } //TBI
182 /** Request to take care the object is present after commit.
183 * Install if not installed, and do not delete.
185 bool setOnSystem( ResStatus::TransactByValue by_r )
186 { return false; } //TBI
188 /** Request to take care the object is present after commit,
189 * replacing the installed one, if a newer candidate is available.
190 * Install if not installed, and do not delete.
192 bool setOnSystemNew( ResStatus::TransactByValue by_r )
193 { return false; } //TBI
198 /** \name Special inteface for Y2UI.
199 * \note This interface acts on \ref ResStatus::USER level.
200 * The \ref Status enum, and allowed state transitions are
201 * tightly related to the Y2UI. It might be not verry usefull
205 /** Return the current Status */
206 Status status() const;
207 /** Try to set a new Status.
208 * Returns \c false if the transitions is not allowed.
210 bool set_status( const Status state_r );
214 /** Implementation */
216 typedef shared_ptr<Impl> Impl_Ptr;
218 Selectable( Impl_Ptr pimpl_r );
223 /** Pointer to implementation */
224 RW_pointer<Impl> _pimpl;
226 ///////////////////////////////////////////////////////////////////
228 /** \relates Selectable Stream output */
229 std::ostream & operator<<( std::ostream & str, const Selectable & obj );
231 /////////////////////////////////////////////////////////////////
233 ///////////////////////////////////////////////////////////////////
234 /////////////////////////////////////////////////////////////////
236 ///////////////////////////////////////////////////////////////////
237 #endif // ZYPP_UI_SELECTABLE_H