3
* Ekiga -- A VoIP and Video-Conferencing application
4
* Copyright (C) 2000-2007 Damien Sandras
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version. This program is distributed in the hope
10
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
11
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Ekiga is licensed under the GPL license and as a special exception, you
19
* have permission to link or otherwise combine this program with the
20
* programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
21
* applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
22
* programs, as long as you do follow the requirements of the GNU GPL for all
23
* the rest of the software thus combined.
28
* lister.h - description
29
* ------------------------------------------
30
* begin : written in 2007 by Julien Puydt
31
* copyright : (c) 2007 by Julien Puydt
32
* description : declaration of an object able to list others
39
#include <sigc++/sigc++.h>
41
#include "ptr_array.h"
42
#include "ptr_array_iterator.h"
43
#include "ptr_array_const_iterator.h"
49
* This class is there to help write a dynamic object lister, that is an
50
* object which will own objects which will emit "updated"
51
* and "removed" signals.
53
* You can remove an object from an Ekiga::Lister in two ways:
54
* - either by calling the remove_object method,
55
* - or by emission of the object's removed signal.
57
* Notice that this class won't take care of removing the object from a
58
* backend -- only from the Ekiga::Lister.
59
* If you want the object *deleted* from the real backend, then you
60
* probably should have an organization like:
61
* - the object has a 'deleted' signal;
62
* - the lister child-class listens to this signal;
63
* - when the signal is received, then do a remove_object followed by
64
* calling the appropriate api function to delete the object in your
67
template<typename ObjectType>
73
typedef Ekiga::ptr_array<ObjectType> container_type;
74
typedef typename Ekiga::ptr_array_iterator<ObjectType> iterator;
75
typedef typename Ekiga::ptr_array_const_iterator<ObjectType> const_iterator;
88
/** Allows listing all objects
89
* @param The callback (the return value means "go on" and allows
92
void visit_objects (sigc::slot<bool, ObjectType &> visitor);
94
/** Returns a const iterator to the first object of the collection.
96
const_iterator begin () const;
99
/** Returns an iterator to the first object of the collection.
104
/** Returns a const iterator to the first object of the collection.
106
const_iterator end () const;
109
/** Returns an iterator to the last object of the collection.
113
/** Adds an object to the Ekiga::Lister.
114
* @param: The object to be added.
115
* @return: The Ekiga::Lister 'object_added' signal is emitted when
116
* the object has been added. The
117
* Ekiga::Lister 'object_updated' signal will be emitted
118
* when the object has been updated and the
119
* Ekiga::Lister 'object_removed' signal will be emitted when
120
* the object has been removed from the Ekiga::Lister.
122
void add_object (ObjectType &object);
125
/** Removes an object from the Ekiga::Lister.
126
* @param: The object to be removed.
127
* @return: The Ekiga::Lister 'object_removed' signal is emitted when
128
* the object has been removed.
130
void remove_object (ObjectType &object);
133
/** Signals emitted by this object
136
sigc::signal<void, ObjectType &> object_added;
137
sigc::signal<void, ObjectType &> object_removed;
138
sigc::signal<void, ObjectType &> object_updated;
142
/** Disconnects the signals for the object, emits the 'object_removed'
143
* signal on the Ekiga::Lister and takes care of the release of that
145
* @param: The object to remove.
147
void common_removal_steps (ObjectType &object);
150
/** This callback is triggered when the 'updated' signal is emitted on
152
* Emits the Ekiga::Lister 'object_updated' signal for that object.
153
* @param: The updated object.
155
void on_object_updated (ObjectType *object);
158
/** This callback is triggered when the 'removed' signal is emitted on
160
* Emits the Ekiga::Lister 'object_removed' signal for that object and
161
* takes care of the deletion of the object.
162
* @param: The removed object.
164
void on_object_removed (ObjectType *object);
168
container_type objects;
170
/** Are we shutting done, hence not reacting to our objects saying goodbye?
177
/* here begins the code from the template functions */
179
template<typename ObjectType>
180
Ekiga::Lister<ObjectType>::Lister (): shutting_down(false)
185
template<typename ObjectType>
186
Ekiga::Lister<ObjectType>::~Lister ()
188
shutting_down = true;
190
for (unsigned int ii = 0;
191
ii < objects.size ();
194
ObjectType *obj = objects[ii];
195
obj->removed.emit ();
200
template<typename ObjectType>
202
Ekiga::Lister<ObjectType>::visit_objects (sigc::slot<bool, ObjectType &> visitor)
205
for (unsigned int ii = 0;
206
ii < objects.size () && go_on; ii++)
207
go_on = visitor (*objects[ii]);
211
template<typename ObjectType>
212
typename Ekiga::Lister<ObjectType>::const_iterator
213
Ekiga::Lister<ObjectType>::begin () const
215
return const_iterator (objects);
219
template<typename ObjectType>
220
typename Ekiga::Lister<ObjectType>::iterator
221
Ekiga::Lister<ObjectType>::begin ()
223
return iterator (objects);
227
template<typename ObjectType>
228
typename Ekiga::Lister<ObjectType>::const_iterator
229
Ekiga::Lister<ObjectType>::end () const
231
return const_iterator (objects, objects.size ());
235
template<typename ObjectType>
236
typename Ekiga::Lister<ObjectType>::iterator
237
Ekiga::Lister<ObjectType>::end ()
239
return iterator (objects, objects.size ());
243
template<typename ObjectType>
245
Ekiga::Lister<ObjectType>::add_object (ObjectType &object)
247
object.removed.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_removed), &object));
248
object.updated.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_updated), &object));
249
objects.add (&object);
250
object_added.emit (object);
254
template<typename ObjectType>
256
Ekiga::Lister<ObjectType>::remove_object (ObjectType &object)
258
common_removal_steps (object);
261
template<typename ObjectType>
263
Ekiga::Lister<ObjectType>::common_removal_steps (ObjectType &object)
265
object_removed.emit (object);
266
objects.remove (&object);
270
template<typename ObjectType>
272
Ekiga::Lister<ObjectType>::on_object_updated (ObjectType *object)
274
object_updated.emit (*object);
278
template<typename ObjectType>
280
Ekiga::Lister<ObjectType>::on_object_removed (ObjectType *object)
283
common_removal_steps (*object);