statusicon.c 5.68 KB
Newer Older
1
2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
3
4
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
6
7
 *                                                                              
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *  (at your option) any later version.
 *                                                                                
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>
#include <actions.h>
#include <mainwindow.h>
24
#include <accountlist.h>
25
26
#include <statusicon.h>

27
#if GTK_CHECK_VERSION(2,10,0)
28
29
GtkStatusIcon *status;
GtkWidget *show_menu_item, *hangup_menu_item;
30
gboolean __minimized = MINIMIZED;
31

32
33
void
popup_main_window(void)
34
{
35
36
37
38
39
40
41
  if (__POPUP_WINDOW)
    {
      gtk_widget_show(get_main_window());
      gtk_window_move(GTK_WINDOW (get_main_window ()),
          dbus_get_window_position_x(), dbus_get_window_position_y());
      set_minimized(FALSE);
    }
42
43
}

44
45
46
47
void
show_status_hangup_icon()
{
  if (status) {
48
49
    DEBUG("Show Hangup in Systray");
    gtk_widget_show(GTK_WIDGET(hangup_menu_item));
50
  }
51
52
}

53
54
55
56
57
void
hide_status_hangup_icon()
{
  if (status) {
    DEBUG("Hide Hangup in Systray");
58
    gtk_widget_hide(GTK_WIDGET(hangup_menu_item));
59
  }
60
61
}

62
63
void
status_quit(void * foo UNUSED)
64
65
66
67
{
  sflphone_quit();
}

68
void
69
status_hangup()
70
71
{
  sflphone_hang_up();
72
}
73

74
void
75
76
status_icon_unminimize()
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
77
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE);
78
79
}

80
81
gboolean
main_widget_minimized()
Emmanuel Milou's avatar
test    
Emmanuel Milou committed
82
83
84
85
{
  return __minimized;
}

86
87
void
show_hide(void)
88
{
89
90
91
92
93
94
95
96
97
98
99
100
  if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item)))
    {
      gtk_widget_show(GTK_WIDGET(get_main_window()));
      gtk_window_move(GTK_WINDOW (get_main_window ()),
          dbus_get_window_position_x(), dbus_get_window_position_y());
      set_minimized(!MINIMIZED);
    }
  else
    {
      gtk_widget_hide(GTK_WIDGET(get_main_window()));
      set_minimized(MINIMIZED);
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
101
102
}

103
104
void
status_click(GtkStatusIcon *status_icon UNUSED, void * foo UNUSED)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
105
{
106
107
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item),
      !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item)));
108
109
}

110
111
112
void
menu(GtkStatusIcon *status_icon, guint button, guint activate_time,
    GtkWidget * menu)
113
{
114
115
  gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gtk_status_icon_position_menu,
      status_icon, button, activate_time);
116
117
}

118
119
GtkWidget*
create_menu()
120
121
122
{
  GtkWidget * menu;
  GtkWidget * menu_items;
123
  GtkWidget * image;
124
125
126
127
128

  menu = gtk_menu_new();

  show_menu_item
      = gtk_check_menu_item_new_with_mnemonic(_("_Show main window"));
129
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE);
130
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), show_menu_item);
131
  g_signal_connect(G_OBJECT (show_menu_item), "toggled",
132
133
134
      G_CALLBACK (show_hide),
      NULL);

135
  hangup_menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Hang up"));
136
  image = gtk_image_new_from_file(ICONS_DIR "/icon_hangup.svg");
137
138
139
  gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(hangup_menu_item), image);
  gtk_menu_shell_append(GTK_MENU_SHELL(menu), hangup_menu_item);
  g_signal_connect(G_OBJECT (hangup_menu_item), "activate",
140
141
      G_CALLBACK (status_hangup),
      NULL);
142

143
144
  menu_items = gtk_separator_menu_item_new();
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items);
145

146
147
  menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,
      get_accel_group());
148
  g_signal_connect_swapped (G_OBJECT (menu_items), "activate",
149
150
151
152
153
154
      G_CALLBACK (status_quit),
      NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items);

  gtk_widget_show_all(menu);

155
156
157
158
159
160
  return menu;
}

void
show_status_icon()
{
Emmanuel Milou's avatar
Emmanuel Milou committed
161
  status = gtk_status_icon_new_from_file(LOGO);
162
  g_signal_connect (G_OBJECT (status), "activate",
163
164
      G_CALLBACK (status_click),
      NULL);
165
  g_signal_connect (G_OBJECT (status), "popup-menu",
166
167
      G_CALLBACK (menu),
      create_menu());
168

169
  statusicon_set_tooltip();
170
171
}

172
void hide_status_icon (void) {
173

174
175
    g_object_unref (status);
    status = NULL;
176
177
178
}


179
180
void
statusicon_set_tooltip()
181
{
182
183
184
  int count;
  gchar *tip;

185
186
187
188
189
190
191
192
193
194
195
  if(status) {

    // Add a tooltip to the system tray icon
    count = account_list_get_registered_accounts();
    tip = g_markup_printf_escaped("%s - %s", _("SFLphone"),
        g_markup_printf_escaped(n_("%i active account", "%i active accounts", count), count));
    gtk_status_icon_set_tooltip(status, tip);
    g_free(tip);

  }

196
}
197

198
199
200
201
202
203
204
205
206
207
208
209
void
status_tray_icon_blink(gboolean active)
{
  if (status) {
  // Set a different icon to notify of an event
  active ? gtk_status_icon_set_from_file(status, LOGO_NOTIF)
      : gtk_status_icon_set_from_file(status, LOGO);
  }
}

void
status_tray_icon_online(gboolean online)
210
{
211
212
213
214
215
  if (status) {
  // Set a different icon to notify of an event
  online ? gtk_status_icon_set_from_file(status, LOGO)
      : gtk_status_icon_set_from_file(status, LOGO_OFFLINE);
  }
216
}
217

218
219
GtkStatusIcon*
get_status_icon(void)
220
221
222
{
  return status;
}
Emmanuel Milou's avatar
test    
Emmanuel Milou committed
223
224

void
225
set_minimized(gboolean state)
Emmanuel Milou's avatar
test    
Emmanuel Milou committed
226
{
227
  __minimized = state;
228
  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), !state);
Emmanuel Milou's avatar
test    
Emmanuel Milou committed
229
}
230
231

#endif