1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2009 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Richard Hult <richard@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
24 * Davyd Madeley <davyd.madeley@collabora.co.uk>
32 #include <glib/gi18n-lib.h>
34 #include <gdk/gdkkeysyms.h>
36 #include <telepathy-glib/util.h>
37 #include <libmissioncontrol/mc-enum-types.h>
39 #include <libempathy/empathy-idle.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy/empathy-status-presets.h>
43 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
44 #include <libempathy/empathy-debug.h>
46 #include "empathy-ui-utils.h"
47 #include "empathy-images.h"
48 #include "empathy-presence-chooser.h"
49 #include "empathy-status-preset-dialog.h"
51 /* Flashing delay for icons (milliseconds). */
52 #define FLASH_TIMEOUT 500
54 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
56 /* For custom message dialog */
64 /* For combobox's model */
70 COL_STATUS_CUSTOMISABLE,
80 ENTRY_TYPE_EDIT_CUSTOM,
81 } PresenceChooserEntryType;
86 gboolean editing_status;
87 int block_set_editing;
89 guint focus_out_idle_source;
92 PresenceChooserEntryType previous_type;
94 McPresence flash_state_1;
95 McPresence flash_state_2;
96 guint flash_timeout_id;
97 } EmpathyPresenceChooserPriv;
99 /* States to be listed in the menu.
100 * Each state has a boolean telling if it can have custom message */
101 static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
102 MC_PRESENCE_DO_NOT_DISTURB, TRUE,
103 MC_PRESENCE_AWAY, TRUE,
104 MC_PRESENCE_HIDDEN, FALSE,
105 MC_PRESENCE_OFFLINE, FALSE};
107 static void presence_chooser_finalize (GObject *object);
108 static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
109 static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
110 static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
113 static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
115 static void presence_chooser_menu_add_item (GtkWidget *menu,
118 static void presence_chooser_noncustom_activate_cb (GtkWidget *item,
120 static void presence_chooser_set_state (McPresence state,
121 const gchar *status);
122 static void presence_chooser_custom_activate_cb (GtkWidget *item,
125 G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
128 empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
130 GObjectClass *object_class = G_OBJECT_CLASS (klass);
132 object_class->finalize = presence_chooser_finalize;
134 g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
138 presence_chooser_create_model (EmpathyPresenceChooser *self)
141 char *custom_message;
144 store = gtk_list_store_new (N_COLUMNS,
145 G_TYPE_STRING, /* COL_STATE_ICON_NAME */
146 MC_TYPE_PRESENCE, /* COL_STATE */
147 G_TYPE_STRING, /* COL_STATUS_TEXT */
148 G_TYPE_STRING, /* COL_DISPLAY_MARKUP */
149 G_TYPE_BOOLEAN, /* COL_STATUS_CUSTOMISABLE */
150 G_TYPE_INT); /* COL_TYPE */
152 custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message..."));
154 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
156 const char *status, *icon_name;
158 status = empathy_presence_get_default_message (states[i]);
159 icon_name = empathy_icon_name_for_presence (states[i]);
161 gtk_list_store_insert_with_values (store, NULL, -1,
162 COL_STATE_ICON_NAME, icon_name,
163 COL_STATE, states[i],
164 COL_STATUS_TEXT, status,
165 COL_DISPLAY_MARKUP, status,
166 COL_STATUS_CUSTOMISABLE, states[i+1],
167 COL_TYPE, ENTRY_TYPE_BUILTIN,
172 /* Set custom messages if wanted */
173 list = empathy_status_presets_get (states[i], 5);
174 for (l = list; l; l = l->next) {
175 gtk_list_store_insert_with_values (store,
177 COL_STATE_ICON_NAME, icon_name,
178 COL_STATE, states[i],
179 COL_STATUS_TEXT, l->data,
180 COL_DISPLAY_MARKUP, l->data,
181 COL_STATUS_CUSTOMISABLE, TRUE,
182 COL_TYPE, ENTRY_TYPE_SAVED,
187 gtk_list_store_insert_with_values (store, NULL, -1,
188 COL_STATE_ICON_NAME, icon_name,
189 COL_STATE, states[i],
191 COL_DISPLAY_MARKUP, custom_message,
192 COL_STATUS_CUSTOMISABLE, TRUE,
193 COL_TYPE, ENTRY_TYPE_CUSTOM,
199 /* add a separator */
200 gtk_list_store_insert_with_values (store, NULL, -1,
201 COL_TYPE, ENTRY_TYPE_SEPARATOR,
204 gtk_list_store_insert_with_values (store, NULL, -1,
205 COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
207 COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
208 COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
211 g_free (custom_message);
213 gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (store));
214 g_object_unref (store);
218 presence_chooser_popup_shown_cb (GObject *self,
222 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
225 g_object_get (self, "popup-shown", &shown, NULL);
230 /* see presence_chooser_entry_focus_out_cb() for what this does */
231 if (priv->focus_out_idle_source != 0) {
232 g_source_remove (priv->focus_out_idle_source);
233 priv->focus_out_idle_source = 0;
236 presence_chooser_create_model (EMPATHY_PRESENCE_CHOOSER (self));
239 static PresenceChooserEntryType
240 presence_chooser_get_entry_type (EmpathyPresenceChooser *self)
243 PresenceChooserEntryType type = -1;
245 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter)) {
246 type = ENTRY_TYPE_CUSTOM;
251 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
252 gtk_tree_model_get (model, &iter,
261 presence_chooser_is_preset (EmpathyPresenceChooser *self)
263 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
267 gboolean match = FALSE;
269 state = empathy_idle_get_state (priv->idle);
270 status = empathy_idle_get_status (priv->idle);
272 presets = empathy_status_presets_get (state, -1);
273 for (l = presets; l; l = l->next) {
274 char *preset = (char *) l->data;
276 if (!strcmp (status, preset)) {
282 g_list_free (presets);
284 DEBUG ("is_preset(%i, %s) = %i\n", state, status, match);
290 presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
293 PresenceChooserEntryType type;
295 entry = gtk_bin_get_child (GTK_BIN (self));
296 type = presence_chooser_get_entry_type (self);
298 if (type == ENTRY_TYPE_CUSTOM || type == ENTRY_TYPE_SAVED) {
299 if (presence_chooser_is_preset (self)) {
300 /* saved entries can be removed from the list */
301 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
302 GTK_ENTRY_ICON_SECONDARY,
304 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
305 GTK_ENTRY_ICON_SECONDARY,
306 _("Click to remove this status as a favorite"));
309 /* custom entries can be favorited */
310 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
311 GTK_ENTRY_ICON_SECONDARY,
312 "empathy-unstarred");
313 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
314 GTK_ENTRY_ICON_SECONDARY,
315 _("Click to make this status a favorite"));
319 /* built-in entries cannot be favorited */
320 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
321 GTK_ENTRY_ICON_SECONDARY,
323 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
324 GTK_ENTRY_ICON_SECONDARY,
330 presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
333 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
336 if (priv->block_set_editing) {
340 entry = gtk_bin_get_child (GTK_BIN (self));
342 priv->editing_status = TRUE;
344 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
345 GTK_ENTRY_ICON_SECONDARY,
347 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
348 GTK_ENTRY_ICON_SECONDARY,
350 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
351 GTK_ENTRY_ICON_PRIMARY,
356 presence_chooser_set_favorite_icon (self);
357 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
358 GTK_ENTRY_ICON_PRIMARY,
361 /* attempt to get the toplevel for this widget */
362 window = gtk_widget_get_toplevel (GTK_WIDGET (self));
363 if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window)) {
364 /* unset the focus */
365 gtk_window_set_focus (GTK_WINDOW (window), NULL);
368 /* see presence_chooser_entry_focus_out_cb()
369 * for what this does */
370 if (priv->focus_out_idle_source != 0) {
371 g_source_remove (priv->focus_out_idle_source);
372 priv->focus_out_idle_source = 0;
375 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
377 priv->editing_status = FALSE;
382 mc_set_custom_state (EmpathyPresenceChooser *self)
384 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
388 entry = gtk_bin_get_child (GTK_BIN (self));
389 /* update the status with MC */
390 status = gtk_entry_get_text (GTK_ENTRY (entry));
392 DEBUG ("Sending state to MC-> %s (%s)\n",
393 g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
394 priv->state)->value_name,
397 empathy_idle_set_presence (priv->idle, priv->state, status);
401 ui_set_custom_state (EmpathyPresenceChooser *self,
405 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
407 const char *icon_name;
409 entry = gtk_bin_get_child (GTK_BIN (self));
411 priv->block_set_editing++;
412 priv->block_changed++;
414 icon_name = empathy_icon_name_for_presence (state);
415 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
416 GTK_ENTRY_ICON_PRIMARY,
418 gtk_entry_set_text (GTK_ENTRY (entry), status);
419 presence_chooser_set_favorite_icon (self);
421 priv->block_changed--;
422 priv->block_set_editing--;
426 presence_chooser_reset_status (EmpathyPresenceChooser *self)
428 /* recover the status that was unset */
429 presence_chooser_set_status_editing (self, FALSE);
430 presence_chooser_presence_changed_cb (self);
434 presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
435 GtkEntryIconPosition icon_pos,
439 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
441 if (priv->editing_status) {
442 presence_chooser_set_status_editing (self, FALSE);
443 mc_set_custom_state (self);
446 PresenceChooserEntryType type;
450 type = presence_chooser_get_entry_type (self);
451 state = empathy_idle_get_state (priv->idle);
452 status = empathy_idle_get_status (priv->idle);
454 if (presence_chooser_is_preset (self)) {
455 /* remove the entry */
456 DEBUG ("REMOVING PRESET (%i, %s)\n", state, status);
457 empathy_status_presets_remove (state, status);
461 DEBUG ("SAVING PRESET (%i, %s)\n", state, status);
462 empathy_status_presets_set_last (state, status);
465 /* update the icon */
466 presence_chooser_set_favorite_icon (self);
471 presence_chooser_entry_activate_cb (EmpathyPresenceChooser *self,
474 presence_chooser_set_status_editing (self, FALSE);
475 mc_set_custom_state (self);
479 presence_chooser_entry_key_press_event_cb (EmpathyPresenceChooser *self,
483 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
485 if (priv->editing_status && event->keyval == GDK_Escape) {
486 /* the user pressed Escape, undo the editing */
487 presence_chooser_reset_status (self);
490 else if (event->keyval == GDK_Up || event->keyval == GDK_Down) {
495 return FALSE; /* send this event elsewhere */
499 presence_chooser_entry_button_press_event_cb (EmpathyPresenceChooser *self,
500 GdkEventButton *event,
503 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
505 if (!priv->editing_status &&
506 event->button == 1 &&
507 !GTK_WIDGET_HAS_FOCUS (entry)) {
508 gtk_widget_grab_focus (entry);
509 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
518 presence_chooser_entry_changed_cb (EmpathyPresenceChooser *self,
521 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
523 if (priv->block_changed){
527 /* the combo is being edited to a custom entry */
528 if (!priv->editing_status) {
529 presence_chooser_set_status_editing (self, TRUE);
534 presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
536 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
539 McPresence new_state;
540 gboolean customisable = TRUE;
541 PresenceChooserEntryType type = -1;
545 if (priv->block_changed ||
546 !gtk_combo_box_get_active_iter (self, &iter)) {
550 model = gtk_combo_box_get_model (self);
551 gtk_tree_model_get (model, &iter,
552 COL_STATE_ICON_NAME, &icon_name,
553 COL_STATE, &new_state,
554 COL_STATUS_CUSTOMISABLE, &customisable,
558 entry = gtk_bin_get_child (GTK_BIN (self));
560 /* some types of status aren't editable, set the editability of the
561 * entry appropriately. Unless we're just about to reset it anyway,
562 * in which case, don't fiddle with it */
563 if (type != ENTRY_TYPE_EDIT_CUSTOM) {
564 gtk_editable_set_editable (GTK_EDITABLE (entry), customisable);
565 priv->state = new_state;
568 if (type == ENTRY_TYPE_EDIT_CUSTOM) {
569 GtkWidget *window, *dialog;
571 presence_chooser_reset_status (EMPATHY_PRESENCE_CHOOSER (self));
573 /* attempt to get the toplevel for this widget */
574 window = gtk_widget_get_toplevel (GTK_WIDGET (self));
575 if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window)) {
579 dialog = empathy_status_preset_dialog_new (GTK_WINDOW (window));
580 gtk_dialog_run (GTK_DIALOG (dialog));
581 gtk_widget_destroy (dialog);
583 else if (type == ENTRY_TYPE_CUSTOM) {
584 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
585 GTK_ENTRY_ICON_PRIMARY,
588 /* preseed the status */
589 if (priv->previous_type == ENTRY_TYPE_BUILTIN) {
590 /* if their previous entry was a builtin, don't
592 gtk_entry_set_text (GTK_ENTRY (entry), "");
594 /* else preseed the text of their currently entered
598 status = empathy_idle_get_status (priv->idle);
599 gtk_entry_set_text (GTK_ENTRY (entry), status);
603 gtk_widget_grab_focus (entry);
607 /* just in case we were setting a new status when
608 * things were changed */
609 presence_chooser_set_status_editing (
610 EMPATHY_PRESENCE_CHOOSER (self),
613 gtk_tree_model_get (model, &iter,
614 COL_STATUS_TEXT, &status,
617 empathy_idle_set_presence (priv->idle, priv->state, status);
622 if (type != ENTRY_TYPE_EDIT_CUSTOM) {
623 priv->previous_type = type;
629 combo_row_separator_func (GtkTreeModel *model,
633 PresenceChooserEntryType type;
635 gtk_tree_model_get (model, iter,
639 return (type == ENTRY_TYPE_SEPARATOR);
643 presence_chooser_entry_focus_out_idle_cb (gpointer user_data)
645 EmpathyPresenceChooser *chooser;
648 DEBUG ("Autocommiting status message\n");
650 chooser = EMPATHY_PRESENCE_CHOOSER (user_data);
651 entry = gtk_bin_get_child (GTK_BIN (chooser));
653 presence_chooser_entry_activate_cb (chooser, GTK_ENTRY (entry));
659 presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser,
660 GdkEventFocus *event,
663 EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
665 if (priv->editing_status) {
666 /* this seems a bit evil and maybe it will be fragile,
667 * someone should think of a better way to do it.
669 * The entry has focused out, but we don't know where the focus
670 * has gone. If it goes to the combo box, we don't want to
671 * do anything. If it's gone anywhere else, we want to commit
674 * Thus we install this idle handler and store its source.
675 * If the source is scheduled when the popup handler runs,
676 * it will remove it, else the callback will commit the result.
678 priv->focus_out_idle_source = g_idle_add (
679 presence_chooser_entry_focus_out_idle_cb,
683 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
689 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
691 EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
692 EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
694 GtkCellRenderer *renderer;
696 chooser->priv = priv;
698 presence_chooser_create_model (chooser);
700 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
702 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
703 combo_row_separator_func,
706 entry = gtk_bin_get_child (GTK_BIN (chooser));
707 gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
708 GTK_ENTRY_ICON_PRIMARY,
711 g_signal_connect_swapped (entry, "icon-release",
712 G_CALLBACK (presence_chooser_entry_icon_release_cb),
714 g_signal_connect_swapped (entry, "activate",
715 G_CALLBACK (presence_chooser_entry_activate_cb),
717 g_signal_connect_swapped (entry, "key-press-event",
718 G_CALLBACK (presence_chooser_entry_key_press_event_cb),
720 g_signal_connect_swapped (entry, "button-press-event",
721 G_CALLBACK (presence_chooser_entry_button_press_event_cb),
724 gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
726 renderer = gtk_cell_renderer_pixbuf_new ();
727 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
728 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
729 "icon-name", COL_STATE_ICON_NAME,
731 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
733 renderer = gtk_cell_renderer_text_new ();
734 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
735 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
736 "markup", COL_DISPLAY_MARKUP,
739 g_signal_connect (chooser, "notify::popup-shown",
740 G_CALLBACK (presence_chooser_popup_shown_cb), NULL);
741 g_signal_connect (chooser, "changed",
742 G_CALLBACK (presence_chooser_changed_cb), NULL);
743 g_signal_connect_swapped (entry, "changed",
744 G_CALLBACK (presence_chooser_entry_changed_cb),
746 g_signal_connect_swapped (entry, "focus-out-event",
747 G_CALLBACK (presence_chooser_entry_focus_out_cb),
750 priv->idle = empathy_idle_dup_singleton ();
751 presence_chooser_presence_changed_cb (chooser);
752 g_signal_connect_swapped (priv->idle, "notify",
753 G_CALLBACK (presence_chooser_presence_changed_cb),
756 /* FIXME: this string sucks */
757 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser),
758 _("Set your presence and current status"));
762 presence_chooser_finalize (GObject *object)
764 EmpathyPresenceChooserPriv *priv;
766 priv = GET_PRIV (object);
768 if (priv->flash_timeout_id) {
769 g_source_remove (priv->flash_timeout_id);
772 if (priv->focus_out_idle_source) {
773 g_source_remove (priv->focus_out_idle_source);
776 g_signal_handlers_disconnect_by_func (priv->idle,
777 presence_chooser_presence_changed_cb,
779 g_object_unref (priv->idle);
781 G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
785 empathy_presence_chooser_new (void)
789 chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
795 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
797 EmpathyPresenceChooserPriv *priv;
799 McPresence flash_state;
803 gboolean valid, match_state = FALSE, match = FALSE;
805 priv = GET_PRIV (chooser);
807 if (priv->editing_status) {
811 priv->state = state = empathy_idle_get_state (priv->idle);
812 status = empathy_idle_get_status (priv->idle);
813 flash_state = empathy_idle_get_flash_state (priv->idle);
815 /* look through the model and attempt to find a matching state */
816 model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
817 for (valid = gtk_tree_model_get_iter_first (model, &iter);
819 valid = gtk_tree_model_iter_next (model, &iter)) {
824 gtk_tree_model_get (model, &iter,
829 if (m_type == ENTRY_TYPE_CUSTOM ||
830 m_type == ENTRY_TYPE_SEPARATOR ||
831 m_type == ENTRY_TYPE_EDIT_CUSTOM) {
834 else if (!match_state && state == m_state) {
835 /* we are now in the section that can contain our
839 else if (match_state && state != m_state) {
840 /* we have passed the section that can contain our
845 gtk_tree_model_get (model, &iter,
846 COL_STATUS_TEXT, &m_status,
849 match = !strcmp (status, m_status);
858 priv->block_changed++;
859 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
860 presence_chooser_set_favorite_icon (chooser);
861 priv->block_changed--;
864 ui_set_custom_state (chooser, state, status);
867 if (flash_state != MC_PRESENCE_UNSET) {
868 presence_chooser_flash_start (chooser, state, flash_state);
871 presence_chooser_flash_stop (chooser, state);
876 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
878 EmpathyPresenceChooserPriv *priv;
880 static gboolean on = FALSE;
883 priv = GET_PRIV (chooser);
886 state = priv->flash_state_1;
889 state = priv->flash_state_2;
892 entry = gtk_bin_get_child (GTK_BIN (chooser));
893 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
894 GTK_ENTRY_ICON_PRIMARY,
895 empathy_icon_name_for_presence (state));
903 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
907 EmpathyPresenceChooserPriv *priv;
909 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
911 priv = GET_PRIV (chooser);
913 priv->flash_state_1 = state_1;
914 priv->flash_state_2 = state_2;
916 if (!priv->flash_timeout_id) {
917 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
918 (GSourceFunc) presence_chooser_flash_timeout_cb,
924 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
927 EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
930 if (priv->flash_timeout_id) {
931 g_source_remove (priv->flash_timeout_id);
932 priv->flash_timeout_id = 0;
935 entry = gtk_bin_get_child (GTK_BIN (chooser));
936 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
937 GTK_ENTRY_ICON_PRIMARY,
938 empathy_icon_name_for_presence (state));
942 empathy_presence_chooser_create_menu (void)
950 menu = gtk_menu_new ();
952 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
955 status = empathy_presence_get_default_message (states[i]);
956 presence_chooser_menu_add_item (menu,
961 /* Set custom messages if wanted */
962 list = empathy_status_presets_get (states[i], 5);
963 for (l = list; l; l = l->next) {
964 presence_chooser_menu_add_item (menu,
974 item = gtk_menu_item_new ();
975 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
976 gtk_widget_show (item);
978 /* Custom messages */
979 item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
980 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
981 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
982 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
983 gtk_widget_show (image);
984 gtk_widget_show (item);
986 g_signal_connect (item,
988 G_CALLBACK (presence_chooser_custom_activate_cb),
995 presence_chooser_menu_add_item (GtkWidget *menu,
1001 const gchar *icon_name;
1003 item = gtk_image_menu_item_new_with_label (str);
1004 icon_name = empathy_icon_name_for_presence (state);
1006 g_signal_connect (item, "activate",
1007 G_CALLBACK (presence_chooser_noncustom_activate_cb),
1010 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
1011 gtk_widget_show (image);
1013 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1014 gtk_widget_show (item);
1016 g_object_set_data_full (G_OBJECT (item),
1017 "status", g_strdup (str),
1018 (GDestroyNotify) g_free);
1020 g_object_set_data (G_OBJECT (item), "state", GINT_TO_POINTER (state));
1022 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1026 presence_chooser_noncustom_activate_cb (GtkWidget *item,
1030 const gchar *status;
1032 status = g_object_get_data (G_OBJECT (item), "status");
1033 state = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "state"));
1035 presence_chooser_set_state (state, status);
1039 presence_chooser_set_state (McPresence state,
1040 const gchar *status)
1044 idle = empathy_idle_dup_singleton ();
1045 empathy_idle_set_presence (idle, state, status);
1046 g_object_unref (idle);
1050 presence_chooser_custom_activate_cb (GtkWidget *item,
1055 dialog = empathy_status_preset_dialog_new (NULL);
1056 gtk_dialog_run (GTK_DIALOG (dialog));
1057 gtk_widget_destroy (dialog);