~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/engine/gui/gtk-core/optional-buttons-gtk.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* Ekiga -- A VoIP and Video-Conferencing application
 
3
 * Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software Foundation,
 
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 *
 
19
 *
 
20
 * Ekiga is licensed under the GPL license and as a special exception,
 
21
 * you have permission to link or otherwise combine this program with the
 
22
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
 
23
 * without applying the requirements of the GNU GPL to the OPAL, OpenH323
 
24
 * and PWLIB programs, as long as you do follow the requirements of the
 
25
 * GNU GPL for all the rest of the software thus combined.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
30
 *                         optional-buttons-gtk.cpp  -  description
 
31
 *                         ------------------------------------------
 
32
 *   begin                : written in 2009 by Julien Puydt
 
33
 *   copyright            : (c) 2009 by Julien Puydt
 
34
 *   description          : implementation of a gtk+ optional buttons group
 
35
 *
 
36
 */
 
37
 
 
38
#include "optional-buttons-gtk.h"
 
39
 
 
40
/* here is some pretty simple stuff to keep data around correctly in a GObject,
 
41
 * (and react correctly to clicks on the buttons)
 
42
 */
 
43
 
 
44
struct OptionalButtonsGtkHelper
 
45
{
 
46
  boost::function0<void> callback;
 
47
};
 
48
 
 
49
static void
 
50
optional_buttons_gtk_helper_destroy (struct OptionalButtonsGtkHelper* helper)
 
51
{
 
52
  delete helper;
 
53
}
 
54
 
 
55
static void
 
56
on_optional_buttons_gtk_clicked (gpointer object,
 
57
                                 G_GNUC_UNUSED gpointer data)
 
58
{
 
59
  struct OptionalButtonsGtkHelper* helper = 
 
60
    (struct OptionalButtonsGtkHelper*)g_object_get_data (G_OBJECT (object),
 
61
                                                         "ekiga-optional-buttons-gtk-helper");
 
62
  helper->callback ();
 
63
}
 
64
 
 
65
// here comes the implementation of the public interface :
 
66
 
 
67
OptionalButtonsGtk::OptionalButtonsGtk (): nbr_elements(0)
 
68
{
 
69
}
 
70
 
 
71
OptionalButtonsGtk::~OptionalButtonsGtk ()
 
72
{
 
73
  for (buttons_type::iterator iter = buttons.begin ();
 
74
       iter != buttons.end ();
 
75
       ++iter) {
 
76
 
 
77
    g_object_unref (iter->second);
 
78
  }
 
79
}
 
80
 
 
81
void
 
82
OptionalButtonsGtk::add_button (const std::string label,
 
83
                                GtkButton* button)
 
84
{
 
85
  g_return_if_fail (GTK_IS_BUTTON (button));
 
86
  g_return_if_fail (buttons[label] == 0);
 
87
 
 
88
  g_object_ref (button);
 
89
  gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
 
90
  buttons[label] = button;
 
91
  struct OptionalButtonsGtkHelper* helper = new struct OptionalButtonsGtkHelper;
 
92
  g_object_set_data_full (G_OBJECT (button), "ekiga-optional-buttons-gtk-helper",
 
93
                          (gpointer)helper,(GDestroyNotify)optional_buttons_gtk_helper_destroy);
 
94
  g_signal_connect (button, "clicked",
 
95
                    G_CALLBACK (on_optional_buttons_gtk_clicked), NULL);
 
96
}
 
97
 
 
98
void
 
99
OptionalButtonsGtk::reset ()
 
100
{
 
101
  for (buttons_type::iterator iter = buttons.begin ();
 
102
       iter != buttons.end ();
 
103
       ++iter) {
 
104
 
 
105
    gtk_widget_set_sensitive (GTK_WIDGET (iter->second), FALSE);
 
106
    struct OptionalButtonsGtkHelper* helper =
 
107
      (struct OptionalButtonsGtkHelper*)g_object_get_data (G_OBJECT (iter->second),
 
108
                                                           "ekiga-optional-buttons-gtk-helper");
 
109
    helper->callback = boost::function0<void> ();
 
110
  }
 
111
  nbr_elements = 0;
 
112
}
 
113
 
 
114
void
 
115
OptionalButtonsGtk::add_action (const std::string icon,
 
116
                                G_GNUC_UNUSED const std::string label,
 
117
                                const boost::function0<void> callback)
 
118
{
 
119
  buttons_type::iterator iter = buttons.find (icon);
 
120
 
 
121
  if (iter != buttons.end ()) {
 
122
 
 
123
    struct OptionalButtonsGtkHelper* helper = 
 
124
      (struct OptionalButtonsGtkHelper*)g_object_get_data (G_OBJECT (iter->second),
 
125
                                                           "ekiga-optional-buttons-gtk-helper");
 
126
    helper->callback = callback;
 
127
    gtk_widget_set_sensitive (GTK_WIDGET (iter->second), TRUE);
 
128
    nbr_elements++;
 
129
  }
 
130
}