~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-client-gnome/src/statusicon.c

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 
 *                                                                              
 
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
8
8
 *  the Free Software Foundation; either version 3 of the License, or
9
9
 *  (at your option) any later version.
10
 
 *                                                                                
 
10
 *
11
11
 *  This program is distributed in the hope that it will be useful,
12
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 *  GNU General Public License for more details.
15
 
 *                                                                              
 
15
 *
16
16
 *  You should have received a copy of the GNU General Public License
17
17
 *  along with this program; if not, write to the Free Software
18
18
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34
34
#include <mainwindow.h>
35
35
#include <accountlist.h>
36
36
#include <statusicon.h>
 
37
#include <eel-gconf-extensions.h>
37
38
 
38
39
#if GTK_CHECK_VERSION(2,10,0)
39
40
GtkStatusIcon *status;
41
42
gboolean __minimized = MINIMIZED;
42
43
 
43
44
void
44
 
popup_main_window(void)
 
45
popup_main_window (void)
45
46
{
46
 
  if (__POPUP_WINDOW)
47
 
    {
48
 
      gtk_widget_show(get_main_window());
49
 
      gtk_window_move(GTK_WINDOW (get_main_window ()),
50
 
          dbus_get_window_position_x(), dbus_get_window_position_y());
51
 
      set_minimized(FALSE);
 
47
    if (__POPUP_WINDOW) {
 
48
        gtk_widget_show (get_main_window());
 
49
        //gtk_window_move(GTK_WINDOW (get_main_window ()),
 
50
        //    dbus_get_window_position_x(), dbus_get_window_position_y());
 
51
        set_minimized (FALSE);
52
52
    }
53
53
}
54
54
 
55
55
void
56
56
show_status_hangup_icon()
57
57
{
58
 
  if (status) {
59
 
    DEBUG("Show Hangup in Systray");
60
 
    gtk_widget_show(GTK_WIDGET(hangup_menu_item));
61
 
  }
 
58
    if (__POPUP_WINDOW) {
 
59
        gtk_widget_show (get_main_window ());
 
60
        gtk_window_move (GTK_WINDOW (get_main_window ()), eel_gconf_get_integer (CONF_MAIN_WINDOW_POSITION_X), eel_gconf_get_integer (CONF_MAIN_WINDOW_POSITION_Y));
 
61
        set_minimized (FALSE);
 
62
    }
62
63
}
63
64
 
64
65
void
65
66
hide_status_hangup_icon()
66
67
{
67
 
  if (status) {
68
 
    DEBUG("Hide Hangup in Systray");
69
 
    gtk_widget_hide(GTK_WIDGET(hangup_menu_item));
70
 
  }
 
68
    if (status) {
 
69
        DEBUG ("Hide Hangup in Systray");
 
70
        gtk_widget_hide (GTK_WIDGET (hangup_menu_item));
 
71
    }
71
72
}
72
73
 
73
74
void
74
 
status_quit(void * foo UNUSED)
 
75
status_quit (void * foo UNUSED)
75
76
{
76
 
  sflphone_quit();
 
77
    sflphone_quit();
77
78
}
78
79
 
79
80
void
80
81
status_hangup()
81
82
{
82
 
  sflphone_hang_up();
 
83
    sflphone_hang_up();
83
84
}
84
85
 
85
86
void
86
87
status_icon_unminimize()
87
88
{
88
 
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE);
 
89
    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_menu_item), TRUE);
89
90
}
90
91
 
91
92
gboolean
92
93
main_widget_minimized()
93
94
{
94
 
  return __minimized;
95
 
}
96
 
 
97
 
void
98
 
show_hide(void)
99
 
{
100
 
  if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item)))
101
 
    {
102
 
      gtk_widget_show(GTK_WIDGET(get_main_window()));
103
 
      gtk_window_move(GTK_WINDOW (get_main_window ()),
104
 
          dbus_get_window_position_x(), dbus_get_window_position_y());
105
 
      set_minimized(!MINIMIZED);
106
 
    }
107
 
  else
108
 
    {
109
 
      gtk_widget_hide(GTK_WIDGET(get_main_window()));
110
 
      set_minimized(MINIMIZED);
111
 
    }
112
 
}
113
 
 
114
 
void
115
 
status_click(GtkStatusIcon *status_icon UNUSED, void * foo UNUSED)
116
 
{
117
 
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item),
118
 
      !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item)));
119
 
}
120
 
 
121
 
void
122
 
menu(GtkStatusIcon *status_icon, guint button, guint activate_time,
123
 
    GtkWidget * menu)
124
 
{
125
 
  gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gtk_status_icon_position_menu,
126
 
      status_icon, button, activate_time);
 
95
    return __minimized;
 
96
}
 
97
 
 
98
void
 
99
show_hide (void)
 
100
{
 
101
    if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (show_menu_item))) {
 
102
        gtk_widget_show (GTK_WIDGET (get_main_window()));
 
103
        gtk_window_move (GTK_WINDOW (get_main_window ()), eel_gconf_get_integer (CONF_MAIN_WINDOW_POSITION_X), eel_gconf_get_integer (CONF_MAIN_WINDOW_POSITION_Y));
 
104
        set_minimized (!MINIMIZED);
 
105
    } else {
 
106
        gtk_widget_hide (GTK_WIDGET (get_main_window()));
 
107
        set_minimized (MINIMIZED);
 
108
    }
 
109
}
 
110
 
 
111
void
 
112
status_click (GtkStatusIcon *status_icon UNUSED, void * foo UNUSED)
 
113
{
 
114
    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_menu_item),
 
115
                                    !gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (show_menu_item)));
 
116
}
 
117
 
 
118
void
 
119
menu (GtkStatusIcon *status_icon, guint button, guint activate_time,
 
120
      GtkWidget * menu)
 
121
{
 
122
    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu,
 
123
                    status_icon, button, activate_time);
127
124
}
128
125
 
129
126
GtkWidget*
130
127
create_menu()
131
128
{
132
 
  GtkWidget * menu;
133
 
  GtkWidget * menu_items;
134
 
  GtkWidget * image;
135
 
 
136
 
  menu = gtk_menu_new();
137
 
 
138
 
  show_menu_item
139
 
      = gtk_check_menu_item_new_with_mnemonic(_("_Show main window"));
140
 
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE);
141
 
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), show_menu_item);
142
 
  g_signal_connect(G_OBJECT (show_menu_item), "toggled",
143
 
      G_CALLBACK (show_hide),
144
 
      NULL);
145
 
 
146
 
  hangup_menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Hang up"));
147
 
  image = gtk_image_new_from_file(ICONS_DIR "/icon_hangup.svg");
148
 
  gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(hangup_menu_item), image);
149
 
  gtk_menu_shell_append(GTK_MENU_SHELL(menu), hangup_menu_item);
150
 
  g_signal_connect(G_OBJECT (hangup_menu_item), "activate",
151
 
      G_CALLBACK (status_hangup),
152
 
      NULL);
153
 
 
154
 
  menu_items = gtk_separator_menu_item_new();
155
 
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items);
156
 
 
157
 
  menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,
158
 
      get_accel_group());
159
 
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
160
 
      G_CALLBACK (status_quit),
161
 
      NULL);
162
 
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items);
163
 
 
164
 
  gtk_widget_show_all(menu);
165
 
 
166
 
  return menu;
 
129
    GtkWidget * menu;
 
130
    GtkWidget * menu_items;
 
131
    GtkWidget * image;
 
132
 
 
133
    menu = gtk_menu_new();
 
134
 
 
135
    show_menu_item
 
136
    = gtk_check_menu_item_new_with_mnemonic (_ ("_Show main window"));
 
137
    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_menu_item), TRUE);
 
138
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), show_menu_item);
 
139
    g_signal_connect (G_OBJECT (show_menu_item), "toggled",
 
140
                      G_CALLBACK (show_hide),
 
141
                      NULL);
 
142
 
 
143
    hangup_menu_item = gtk_image_menu_item_new_with_mnemonic (_ ("_Hang up"));
 
144
    image = gtk_image_new_from_file (ICONS_DIR "/icon_hangup.svg");
 
145
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (hangup_menu_item), image);
 
146
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), hangup_menu_item);
 
147
    g_signal_connect (G_OBJECT (hangup_menu_item), "activate",
 
148
                      G_CALLBACK (status_hangup),
 
149
                      NULL);
 
150
 
 
151
    menu_items = gtk_separator_menu_item_new();
 
152
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
 
153
 
 
154
    menu_items = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT,
 
155
                 get_accel_group());
 
156
    g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
 
157
                              G_CALLBACK (status_quit),
 
158
                              NULL);
 
159
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
 
160
 
 
161
    gtk_widget_show_all (menu);
 
162
 
 
163
    return menu;
167
164
}
168
165
 
169
166
void
170
167
show_status_icon()
171
168
{
172
 
  status = gtk_status_icon_new_from_file(LOGO);
173
 
  g_signal_connect (G_OBJECT (status), "activate",
174
 
      G_CALLBACK (status_click),
175
 
      NULL);
176
 
  g_signal_connect (G_OBJECT (status), "popup-menu",
177
 
      G_CALLBACK (menu),
178
 
      create_menu());
 
169
    status = gtk_status_icon_new_from_file (LOGO);
 
170
    g_signal_connect (G_OBJECT (status), "activate",
 
171
                      G_CALLBACK (status_click),
 
172
                      NULL);
 
173
    g_signal_connect (G_OBJECT (status), "popup-menu",
 
174
                      G_CALLBACK (menu),
 
175
                      create_menu());
179
176
 
180
 
  statusicon_set_tooltip();
 
177
    statusicon_set_tooltip();
181
178
}
182
179
 
183
 
void hide_status_icon (void) {
 
180
void hide_status_icon (void)
 
181
{
184
182
 
185
183
    g_object_unref (status);
186
184
    status = NULL;
190
188
void
191
189
statusicon_set_tooltip()
192
190
{
193
 
  int count;
194
 
  gchar *tip;
195
 
 
196
 
  if(status) {
197
 
 
198
 
    // Add a tooltip to the system tray icon
199
 
    count = account_list_get_registered_accounts();
200
 
    tip = g_markup_printf_escaped("%s - %s", _("SFLphone"),
201
 
        g_markup_printf_escaped(n_("%i active account", "%i active accounts", count), count));
202
 
    gtk_status_icon_set_tooltip(status, tip);
203
 
    g_free(tip);
204
 
 
205
 
  }
206
 
 
207
 
}
208
 
 
209
 
void
210
 
status_tray_icon_blink(gboolean active)
211
 
{
212
 
  if (status) {
213
 
  // Set a different icon to notify of an event
214
 
  active ? gtk_status_icon_set_from_file(status, LOGO_NOTIF)
215
 
      : gtk_status_icon_set_from_file(status, LOGO);
216
 
  }
217
 
}
218
 
 
219
 
void
220
 
status_tray_icon_online(gboolean online)
221
 
{
222
 
  if (status) {
223
 
  // Set a different icon to notify of an event
224
 
  online ? gtk_status_icon_set_from_file(status, LOGO)
225
 
      : gtk_status_icon_set_from_file(status, LOGO_OFFLINE);
226
 
  }
 
191
    int count;
 
192
    gchar *tip;
 
193
 
 
194
    if (status) {
 
195
 
 
196
        // Add a tooltip to the system tray icon
 
197
        count = account_list_get_registered_accounts();
 
198
        tip = g_markup_printf_escaped ("%s - %s", _ ("SFLphone"),
 
199
                                       g_markup_printf_escaped (n_ ("%i active account", "%i active accounts", count), count));
 
200
        gtk_status_icon_set_tooltip (status, tip);
 
201
        g_free (tip);
 
202
 
 
203
    }
 
204
}
 
205
 
 
206
void
 
207
status_tray_icon_blink (gboolean active)
 
208
{
 
209
    if (status) {
 
210
        // Set a different icon to notify of an event
 
211
        active ? gtk_status_icon_set_from_file (status, LOGO_NOTIF)
 
212
        : gtk_status_icon_set_from_file (status, LOGO);
 
213
    }
 
214
}
 
215
 
 
216
void
 
217
status_tray_icon_online (gboolean online)
 
218
{
 
219
    if (status) {
 
220
        // Set a different icon to notify of an event
 
221
        online ? gtk_status_icon_set_from_file (status, LOGO)
 
222
        : gtk_status_icon_set_from_file (status, LOGO_OFFLINE);
 
223
    }
227
224
}
228
225
 
229
226
GtkStatusIcon*
230
 
get_status_icon(void)
 
227
get_status_icon (void)
231
228
{
232
 
  return status;
 
229
    return status;
233
230
}
234
231
 
235
232
void
236
 
set_minimized(gboolean state)
 
233
set_minimized (gboolean state)
237
234
{
238
 
  __minimized = state;
239
 
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), !state);
 
235
    __minimized = state;
 
236
    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_menu_item), !state);
240
237
}
241
238
 
242
239
#endif