diff options
author | Henrik Kinnunen <fluxgen@fluxbox.org> | 2008-09-28 08:46:49 (GMT) |
---|---|---|
committer | Henrik Kinnunen <fluxgen@fluxbox.org> | 2008-09-28 08:46:49 (GMT) |
commit | bcf37890b617730cfded161b9a3d18f7c377e724 (patch) | |
tree | d17e0fe6ac69d023fba66fdc1d176c16174e6a1b /src/FbTk/Signal.hh | |
parent | ed53f3c623e7c3ae35672b33ae3b52759dc1a6ed (diff) | |
download | fluxbox-bcf37890b617730cfded161b9a3d18f7c377e724.zip fluxbox-bcf37890b617730cfded161b9a3d18f7c377e724.tar.bz2 |
Change focused signal to use the new signal system
Diffstat (limited to 'src/FbTk/Signal.hh')
-rw-r--r-- | src/FbTk/Signal.hh | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh index 18b03b3..df30cda 100644 --- a/src/FbTk/Signal.hh +++ b/src/FbTk/Signal.hh | |||
@@ -191,8 +191,8 @@ public: | |||
191 | class SignalTracker { | 191 | class SignalTracker { |
192 | public: | 192 | public: |
193 | /// Internal type, do not use. | 193 | /// Internal type, do not use. |
194 | typedef std::list< std::pair<SigImpl::SignalHolder*, | 194 | typedef std::map<SigImpl::SignalHolder*, |
195 | SigImpl::SignalHolder::SlotID> > Connections; | 195 | SigImpl::SignalHolder::SlotID> Connections; |
196 | typedef Connections::iterator TrackID; ///< \c ID type for join/leave. | 196 | typedef Connections::iterator TrackID; ///< \c ID type for join/leave. |
197 | 197 | ||
198 | ~SignalTracker() { | 198 | ~SignalTracker() { |
@@ -203,9 +203,13 @@ public: | |||
203 | /// @return A tracking ID ( not unique ) | 203 | /// @return A tracking ID ( not unique ) |
204 | template <typename Signal, typename Functor> | 204 | template <typename Signal, typename Functor> |
205 | TrackID join(Signal& sig, const Functor& functor) { | 205 | TrackID join(Signal& sig, const Functor& functor) { |
206 | return | 206 | ValueType value = std::make_pair(&sig, sig.connect(functor)); |
207 | m_connections.insert(m_connections.end(), | 207 | std::pair<TrackID, bool> ret = m_connections.insert(value); |
208 | Connections::value_type(&sig, sig.connect(functor))); | 208 | if ( !ret.second ) { |
209 | // failed to insert this functor | ||
210 | sig.disconnect(value.second); | ||
211 | } | ||
212 | return ret.first; | ||
209 | } | 213 | } |
210 | 214 | ||
211 | /// Leave tracking for a signal | 215 | /// Leave tracking for a signal |
@@ -217,23 +221,29 @@ public: | |||
217 | /// Leave tracking for a signal | 221 | /// Leave tracking for a signal |
218 | /// @param sig the signal to leave | 222 | /// @param sig the signal to leave |
219 | template <typename Signal> | 223 | template <typename Signal> |
220 | void leave(const Signal &sig) { | 224 | void leave(Signal &sig) { |
221 | m_connections.erase(&sig); | 225 | Iterator it = m_connections.find(&sig); |
226 | if (it != m_connections.end()) { | ||
227 | it->first->disconnect( it->second ); | ||
228 | m_connections.erase(it); | ||
229 | } | ||
222 | } | 230 | } |
223 | 231 | ||
224 | 232 | ||
225 | void leaveAll() { | 233 | void leaveAll() { |
226 | // disconnect all connections | 234 | // disconnect all connections |
227 | for ( Connections::iterator conIt = m_connections.begin(); | 235 | for ( Iterator conIt = m_connections.begin(); |
228 | conIt != m_connections.end(); ) { | 236 | conIt != m_connections.end(); ++conIt) { |
229 | // keep temporary, while disconnecting we can | 237 | // keep temporary, while disconnecting we can |
230 | // in some strange cases get a call to this again | 238 | // in some strange cases get a call to this again |
231 | Connections::value_type tmp = *conIt; | 239 | ValueType tmp = *conIt; |
232 | conIt = m_connections.erase(conIt); | 240 | m_connections.erase(conIt); |
233 | tmp.first->disconnect(tmp.second); | 241 | tmp.first->disconnect(tmp.second); |
234 | } | 242 | } |
235 | } | 243 | } |
236 | private: | 244 | private: |
245 | typedef Connections::value_type ValueType; | ||
246 | typedef Connections::iterator Iterator; | ||
237 | /// holds all connections to different signals and slots. | 247 | /// holds all connections to different signals and slots. |
238 | Connections m_connections; | 248 | Connections m_connections; |
239 | }; | 249 | }; |