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"
52 * SECTION:empathy-presence-chooser
53 * @title:EmpathyPresenceChooser
54 * @short_description: A widget used to change presence
55 * @include: libempathy-gtk/empathy-presence-chooser.h
57 * #EmpathyPresenceChooser is a widget which extends #GtkComboBoxEntry
62 * EmpathyAccountChooser:
63 * @parent: parent object
65 * Widget which extends #GtkComboBoxEntry to change presence.
68 /* Flashing delay for icons (milliseconds). */
69 #define FLASH_TIMEOUT 500
71 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
73 /* For custom message dialog */
81 /* For combobox's model */
87 COL_STATUS_CUSTOMISABLE,
97 ENTRY_TYPE_EDIT_CUSTOM,
98 } PresenceChooserEntryType;
103 gboolean editing_status;
104 int block_set_editing;
106 guint focus_out_idle_source;
109 PresenceChooserEntryType previous_type;
111 McPresence flash_state_1;
112 McPresence flash_state_2;
113 guint flash_timeout_id;
114 } EmpathyPresenceChooserPriv;
116 /* States to be listed in the menu.
117 * Each state has a boolean telling if it can have custom message */
118 static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
119 MC_PRESENCE_DO_NOT_DISTURB, TRUE,
120 MC_PRESENCE_AWAY, TRUE,
121 MC_PRESENCE_HIDDEN, FALSE,
122 MC_PRESENCE_OFFLINE, FALSE};
124 static void presence_chooser_finalize (GObject *object);
125 static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
126 static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
127 static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
130 static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
132 static void presence_chooser_menu_add_item (GtkWidget *menu,
135 static void presence_chooser_noncustom_activate_cb (GtkWidget *item,
137 static void presence_chooser_set_state (McPresence state,
138 const gchar *status);
139 static void presence_chooser_custom_activate_cb (GtkWidget *item,
142 G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
145 empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
147 GObjectClass *object_class = G_OBJECT_CLASS (klass);
149 object_class->finalize = presence_chooser_finalize;
151 g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
155 presence_chooser_create_model (EmpathyPresenceChooser *self)
158 char *custom_message;
161 store = gtk_list_store_new (N_COLUMNS,
162 G_TYPE_STRING, /* COL_STATE_ICON_NAME */
163 MC_TYPE_PRESENCE, /* COL_STATE */
164 G_TYPE_STRING, /* COL_STATUS_TEXT */
165 G_TYPE_STRING, /* COL_DISPLAY_MARKUP */
166 G_TYPE_BOOLEAN, /* COL_STATUS_CUSTOMISABLE */
167 G_TYPE_INT); /* COL_TYPE */
169 custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message..."));
171 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
173 const char *status, *icon_name;
175 status = empathy_presence_get_default_message (states[i]);
176 icon_name = empathy_icon_name_for_presence (states[i]);
178 gtk_list_store_insert_with_values (store, NULL, -1,
179 COL_STATE_ICON_NAME, icon_name,
180 COL_STATE, states[i],
181 COL_STATUS_TEXT, status,
182 COL_DISPLAY_MARKUP, status,
183 COL_STATUS_CUSTOMISABLE, states[i+1],
184 COL_TYPE, ENTRY_TYPE_BUILTIN,
189 /* Set custom messages if wanted */
190 list = empathy_status_presets_get (states[i], -1);
191 list = g_list_sort (list, (GCompareFunc) g_utf8_collate);
192 for (l = list; l; l = l->next) {
193 gtk_list_store_insert_with_values (store,
195 COL_STATE_ICON_NAME, icon_name,
196 COL_STATE, states[i],
197 COL_STATUS_TEXT, l->data,
198 COL_DISPLAY_MARKUP, l->data,
199 COL_STATUS_CUSTOMISABLE, TRUE,
200 COL_TYPE, ENTRY_TYPE_SAVED,
205 gtk_list_store_insert_with_values (store, NULL, -1,
206 COL_STATE_ICON_NAME, icon_name,
207 COL_STATE, states[i],
209 COL_DISPLAY_MARKUP, custom_message,
210 COL_STATUS_CUSTOMISABLE, TRUE,
211 COL_TYPE, ENTRY_TYPE_CUSTOM,
217 /* add a separator */
218 gtk_list_store_insert_with_values (store, NULL, -1,
219 COL_TYPE, ENTRY_TYPE_SEPARATOR,
222 gtk_list_store_insert_with_values (store, NULL, -1,
223 COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
225 COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
226 COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
229 g_free (custom_message);
231 gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (store));
232 g_object_unref (store);
236 presence_chooser_popup_shown_cb (GObject *self,
240 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
243 g_object_get (self, "popup-shown", &shown, NULL);
248 /* see presence_chooser_entry_focus_out_cb() for what this does */
249 if (priv->focus_out_idle_source != 0) {
250 g_source_remove (priv->focus_out_idle_source);
251 priv->focus_out_idle_source = 0;
254 presence_chooser_create_model (EMPATHY_PRESENCE_CHOOSER (self));
257 static PresenceChooserEntryType
258 presence_chooser_get_entry_type (EmpathyPresenceChooser *self)
261 PresenceChooserEntryType type = -1;
263 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter)) {
264 type = ENTRY_TYPE_CUSTOM;
269 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
270 gtk_tree_model_get (model, &iter,
279 presence_chooser_is_preset (EmpathyPresenceChooser *self)
281 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
285 gboolean match = FALSE;
287 state = empathy_idle_get_state (priv->idle);
288 status = empathy_idle_get_status (priv->idle);
290 presets = empathy_status_presets_get (state, -1);
291 for (l = presets; l; l = l->next) {
292 char *preset = (char *) l->data;
294 if (!strcmp (status, preset)) {
300 g_list_free (presets);
302 DEBUG ("is_preset(%i, %s) = %i\n", state, status, match);
308 presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
311 PresenceChooserEntryType type;
313 entry = gtk_bin_get_child (GTK_BIN (self));
314 type = presence_chooser_get_entry_type (self);
316 if (type == ENTRY_TYPE_CUSTOM || type == ENTRY_TYPE_SAVED) {
317 if (presence_chooser_is_preset (self)) {
318 /* saved entries can be removed from the list */
319 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
320 GTK_ENTRY_ICON_SECONDARY,
322 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
323 GTK_ENTRY_ICON_SECONDARY,
324 _("Click to remove this status as a favorite"));
327 /* custom entries can be favorited */
328 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
329 GTK_ENTRY_ICON_SECONDARY,
330 "empathy-unstarred");
331 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
332 GTK_ENTRY_ICON_SECONDARY,
333 _("Click to make this status a favorite"));
337 /* built-in entries cannot be favorited */
338 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
339 GTK_ENTRY_ICON_SECONDARY,
341 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
342 GTK_ENTRY_ICON_SECONDARY,
348 presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
351 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
354 if (priv->block_set_editing) {
358 entry = gtk_bin_get_child (GTK_BIN (self));
360 priv->editing_status = TRUE;
362 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
363 GTK_ENTRY_ICON_SECONDARY,
365 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
366 GTK_ENTRY_ICON_SECONDARY,
368 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
369 GTK_ENTRY_ICON_PRIMARY,
374 presence_chooser_set_favorite_icon (self);
375 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
376 GTK_ENTRY_ICON_PRIMARY,
379 /* attempt to get the toplevel for this widget */
380 window = gtk_widget_get_toplevel (GTK_WIDGET (self));
381 if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window)) {
382 /* unset the focus */
383 gtk_window_set_focus (GTK_WINDOW (window), NULL);
386 /* see presence_chooser_entry_focus_out_cb()
387 * for what this does */
388 if (priv->focus_out_idle_source != 0) {
389 g_source_remove (priv->focus_out_idle_source);
390 priv->focus_out_idle_source = 0;
393 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
395 priv->editing_status = FALSE;
400 mc_set_custom_state (EmpathyPresenceChooser *self)
402 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
406 entry = gtk_bin_get_child (GTK_BIN (self));
407 /* update the status with MC */
408 status = gtk_entry_get_text (GTK_ENTRY (entry));
410 DEBUG ("Sending state to MC-> %s (%s)\n",
411 g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
412 priv->state)->value_name,
415 empathy_idle_set_presence (priv->idle, priv->state, status);
419 ui_set_custom_state (EmpathyPresenceChooser *self,
423 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
425 const char *icon_name;
427 entry = gtk_bin_get_child (GTK_BIN (self));
429 priv->block_set_editing++;
430 priv->block_changed++;
432 icon_name = empathy_icon_name_for_presence (state);
433 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
434 GTK_ENTRY_ICON_PRIMARY,
436 gtk_entry_set_text (GTK_ENTRY (entry), status);
437 presence_chooser_set_favorite_icon (self);
439 priv->block_changed--;
440 priv->block_set_editing--;
444 presence_chooser_reset_status (EmpathyPresenceChooser *self)
446 /* recover the status that was unset */
447 presence_chooser_set_status_editing (self, FALSE);
448 presence_chooser_presence_changed_cb (self);
452 presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
453 GtkEntryIconPosition icon_pos,
457 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
459 if (priv->editing_status) {
460 presence_chooser_set_status_editing (self, FALSE);
461 mc_set_custom_state (self);
464 PresenceChooserEntryType type;
468 type = presence_chooser_get_entry_type (self);
469 state = empathy_idle_get_state (priv->idle);
470 status = empathy_idle_get_status (priv->idle);
472 if (presence_chooser_is_preset (self)) {
473 /* remove the entry */
474 DEBUG ("REMOVING PRESET (%i, %s)\n", state, status);
475 empathy_status_presets_remove (state, status);
479 DEBUG ("SAVING PRESET (%i, %s)\n", state, status);
480 empathy_status_presets_set_last (state, status);
483 /* update the icon */
484 presence_chooser_set_favorite_icon (self);
489 presence_chooser_entry_activate_cb (EmpathyPresenceChooser *self,
492 presence_chooser_set_status_editing (self, FALSE);
493 mc_set_custom_state (self);
497 presence_chooser_entry_key_press_event_cb (EmpathyPresenceChooser *self,
501 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
503 if (priv->editing_status && event->keyval == GDK_Escape) {
504 /* the user pressed Escape, undo the editing */
505 presence_chooser_reset_status (self);
508 else if (event->keyval == GDK_Up || event->keyval == GDK_Down) {
513 return FALSE; /* send this event elsewhere */
517 presence_chooser_entry_button_press_event_cb (EmpathyPresenceChooser *self,
518 GdkEventButton *event,
521 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
523 if (!priv->editing_status &&
524 event->button == 1 &&
525 !GTK_WIDGET_HAS_FOCUS (entry)) {
526 gtk_widget_grab_focus (entry);
527 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
536 presence_chooser_entry_changed_cb (EmpathyPresenceChooser *self,
539 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
541 if (priv->block_changed){
545 /* the combo is being edited to a custom entry */
546 if (!priv->editing_status) {
547 presence_chooser_set_status_editing (self, TRUE);
552 presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
554 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
557 McPresence new_state;
558 gboolean customisable = TRUE;
559 PresenceChooserEntryType type = -1;
563 if (priv->block_changed ||
564 !gtk_combo_box_get_active_iter (self, &iter)) {
568 model = gtk_combo_box_get_model (self);
569 gtk_tree_model_get (model, &iter,
570 COL_STATE_ICON_NAME, &icon_name,
571 COL_STATE, &new_state,
572 COL_STATUS_CUSTOMISABLE, &customisable,
576 entry = gtk_bin_get_child (GTK_BIN (self));
578 /* some types of status aren't editable, set the editability of the
579 * entry appropriately. Unless we're just about to reset it anyway,
580 * in which case, don't fiddle with it */
581 if (type != ENTRY_TYPE_EDIT_CUSTOM) {
582 gtk_editable_set_editable (GTK_EDITABLE (entry), customisable);
583 priv->state = new_state;
586 if (type == ENTRY_TYPE_EDIT_CUSTOM) {
587 GtkWidget *window, *dialog;
589 presence_chooser_reset_status (EMPATHY_PRESENCE_CHOOSER (self));
591 /* attempt to get the toplevel for this widget */
592 window = gtk_widget_get_toplevel (GTK_WIDGET (self));
593 if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window)) {
597 dialog = empathy_status_preset_dialog_new (GTK_WINDOW (window));
598 gtk_dialog_run (GTK_DIALOG (dialog));
599 gtk_widget_destroy (dialog);
601 else if (type == ENTRY_TYPE_CUSTOM) {
602 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
603 GTK_ENTRY_ICON_PRIMARY,
606 /* preseed the status */
607 if (priv->previous_type == ENTRY_TYPE_BUILTIN) {
608 /* if their previous entry was a builtin, don't
610 gtk_entry_set_text (GTK_ENTRY (entry), "");
612 /* else preseed the text of their currently entered
616 status = empathy_idle_get_status (priv->idle);
617 gtk_entry_set_text (GTK_ENTRY (entry), status);
621 gtk_widget_grab_focus (entry);
625 /* just in case we were setting a new status when
626 * things were changed */
627 presence_chooser_set_status_editing (
628 EMPATHY_PRESENCE_CHOOSER (self),
631 gtk_tree_model_get (model, &iter,
632 COL_STATUS_TEXT, &status,
635 empathy_idle_set_presence (priv->idle, priv->state, status);
640 if (type != ENTRY_TYPE_EDIT_CUSTOM) {
641 priv->previous_type = type;
647 combo_row_separator_func (GtkTreeModel *model,
651 PresenceChooserEntryType type;
653 gtk_tree_model_get (model, iter,
657 return (type == ENTRY_TYPE_SEPARATOR);
661 presence_chooser_entry_focus_out_idle_cb (gpointer user_data)
663 EmpathyPresenceChooser *chooser;
666 DEBUG ("Autocommiting status message\n");
668 chooser = EMPATHY_PRESENCE_CHOOSER (user_data);
669 entry = gtk_bin_get_child (GTK_BIN (chooser));
671 presence_chooser_entry_activate_cb (chooser, GTK_ENTRY (entry));
677 presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser,
678 GdkEventFocus *event,
681 EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
683 if (priv->editing_status) {
684 /* this seems a bit evil and maybe it will be fragile,
685 * someone should think of a better way to do it.
687 * The entry has focused out, but we don't know where the focus
688 * has gone. If it goes to the combo box, we don't want to
689 * do anything. If it's gone anywhere else, we want to commit
692 * Thus we install this idle handler and store its source.
693 * If the source is scheduled when the popup handler runs,
694 * it will remove it, else the callback will commit the result.
696 priv->focus_out_idle_source = g_idle_add (
697 presence_chooser_entry_focus_out_idle_cb,
701 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
707 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
709 EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
710 EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
712 GtkCellRenderer *renderer;
714 chooser->priv = priv;
716 presence_chooser_create_model (chooser);
718 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
720 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
721 combo_row_separator_func,
724 entry = gtk_bin_get_child (GTK_BIN (chooser));
725 gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
726 GTK_ENTRY_ICON_PRIMARY,
729 g_signal_connect_swapped (entry, "icon-release",
730 G_CALLBACK (presence_chooser_entry_icon_release_cb),
732 g_signal_connect_swapped (entry, "activate",
733 G_CALLBACK (presence_chooser_entry_activate_cb),
735 g_signal_connect_swapped (entry, "key-press-event",
736 G_CALLBACK (presence_chooser_entry_key_press_event_cb),
738 g_signal_connect_swapped (entry, "button-press-event",
739 G_CALLBACK (presence_chooser_entry_button_press_event_cb),
742 gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
744 renderer = gtk_cell_renderer_pixbuf_new ();
745 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
746 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
747 "icon-name", COL_STATE_ICON_NAME,
749 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
751 renderer = gtk_cell_renderer_text_new ();
752 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
753 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
754 "markup", COL_DISPLAY_MARKUP,
757 g_signal_connect (chooser, "notify::popup-shown",
758 G_CALLBACK (presence_chooser_popup_shown_cb), NULL);
759 g_signal_connect (chooser, "changed",
760 G_CALLBACK (presence_chooser_changed_cb), NULL);
761 g_signal_connect_swapped (entry, "changed",
762 G_CALLBACK (presence_chooser_entry_changed_cb),
764 g_signal_connect_swapped (entry, "focus-out-event",
765 G_CALLBACK (presence_chooser_entry_focus_out_cb),
768 priv->idle = empathy_idle_dup_singleton ();
769 presence_chooser_presence_changed_cb (chooser);
770 g_signal_connect_swapped (priv->idle, "notify",
771 G_CALLBACK (presence_chooser_presence_changed_cb),
774 /* FIXME: this string sucks */
775 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser),
776 _("Set your presence and current status"));
780 presence_chooser_finalize (GObject *object)
782 EmpathyPresenceChooserPriv *priv;
784 priv = GET_PRIV (object);
786 if (priv->flash_timeout_id) {
787 g_source_remove (priv->flash_timeout_id);
790 if (priv->focus_out_idle_source) {
791 g_source_remove (priv->focus_out_idle_source);
794 g_signal_handlers_disconnect_by_func (priv->idle,
795 presence_chooser_presence_changed_cb,
797 g_object_unref (priv->idle);
799 G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
803 * empathy_presence_chooser_new:
805 * Creates a new #EmpathyPresenceChooser widget.
807 * Return value: A new #EmpathyPresenceChooser widget
810 empathy_presence_chooser_new (void)
814 chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
820 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
822 EmpathyPresenceChooserPriv *priv;
824 McPresence flash_state;
828 gboolean valid, match_state = FALSE, match = FALSE;
830 priv = GET_PRIV (chooser);
832 if (priv->editing_status) {
836 priv->state = state = empathy_idle_get_state (priv->idle);
837 status = empathy_idle_get_status (priv->idle);
838 flash_state = empathy_idle_get_flash_state (priv->idle);
840 /* look through the model and attempt to find a matching state */
841 model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
842 for (valid = gtk_tree_model_get_iter_first (model, &iter);
844 valid = gtk_tree_model_iter_next (model, &iter)) {
849 gtk_tree_model_get (model, &iter,
854 if (m_type == ENTRY_TYPE_CUSTOM ||
855 m_type == ENTRY_TYPE_SEPARATOR ||
856 m_type == ENTRY_TYPE_EDIT_CUSTOM) {
859 else if (!match_state && state == m_state) {
860 /* we are now in the section that can contain our
864 else if (match_state && state != m_state) {
865 /* we have passed the section that can contain our
870 gtk_tree_model_get (model, &iter,
871 COL_STATUS_TEXT, &m_status,
874 match = !strcmp (status, m_status);
883 priv->block_changed++;
884 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
885 presence_chooser_set_favorite_icon (chooser);
886 priv->block_changed--;
889 ui_set_custom_state (chooser, state, status);
892 if (flash_state != MC_PRESENCE_UNSET) {
893 presence_chooser_flash_start (chooser, state, flash_state);
896 presence_chooser_flash_stop (chooser, state);
901 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
903 EmpathyPresenceChooserPriv *priv;
905 static gboolean on = FALSE;
908 priv = GET_PRIV (chooser);
911 state = priv->flash_state_1;
914 state = priv->flash_state_2;
917 entry = gtk_bin_get_child (GTK_BIN (chooser));
918 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
919 GTK_ENTRY_ICON_PRIMARY,
920 empathy_icon_name_for_presence (state));
928 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
932 EmpathyPresenceChooserPriv *priv;
934 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
936 priv = GET_PRIV (chooser);
938 priv->flash_state_1 = state_1;
939 priv->flash_state_2 = state_2;
941 if (!priv->flash_timeout_id) {
942 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
943 (GSourceFunc) presence_chooser_flash_timeout_cb,
949 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
952 EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
955 if (priv->flash_timeout_id) {
956 g_source_remove (priv->flash_timeout_id);
957 priv->flash_timeout_id = 0;
960 entry = gtk_bin_get_child (GTK_BIN (chooser));
961 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
962 GTK_ENTRY_ICON_PRIMARY,
963 empathy_icon_name_for_presence (state));
967 * empathy_presence_chooser_create_menu:
969 * Creates a new #GtkMenu allowing users to change their presence from a menu.
971 * Return value: a new #GtkMenu for changing presence in a menu.
974 empathy_presence_chooser_create_menu (void)
982 menu = gtk_menu_new ();
984 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
987 status = empathy_presence_get_default_message (states[i]);
988 presence_chooser_menu_add_item (menu,
993 /* Set custom messages if wanted */
994 list = empathy_status_presets_get (states[i], 5);
995 for (l = list; l; l = l->next) {
996 presence_chooser_menu_add_item (menu,
1006 item = gtk_menu_item_new ();
1007 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1008 gtk_widget_show (item);
1010 /* Custom messages */
1011 item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
1012 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1013 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1014 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1015 gtk_widget_show (image);
1016 gtk_widget_show (item);
1018 g_signal_connect (item,
1020 G_CALLBACK (presence_chooser_custom_activate_cb),
1027 presence_chooser_menu_add_item (GtkWidget *menu,
1033 const gchar *icon_name;
1035 item = gtk_image_menu_item_new_with_label (str);
1036 icon_name = empathy_icon_name_for_presence (state);
1038 g_signal_connect (item, "activate",
1039 G_CALLBACK (presence_chooser_noncustom_activate_cb),
1042 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
1043 gtk_widget_show (image);
1045 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1046 gtk_widget_show (item);
1048 g_object_set_data_full (G_OBJECT (item),
1049 "status", g_strdup (str),
1050 (GDestroyNotify) g_free);
1052 g_object_set_data (G_OBJECT (item), "state", GINT_TO_POINTER (state));
1054 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1058 presence_chooser_noncustom_activate_cb (GtkWidget *item,
1062 const gchar *status;
1064 status = g_object_get_data (G_OBJECT (item), "status");
1065 state = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "state"));
1067 presence_chooser_set_state (state, status);
1071 presence_chooser_set_state (McPresence state,
1072 const gchar *status)
1076 idle = empathy_idle_dup_singleton ();
1077 empathy_idle_set_presence (idle, state, status);
1078 g_object_unref (idle);
1082 presence_chooser_custom_activate_cb (GtkWidget *item,
1087 dialog = empathy_status_preset_dialog_new (NULL);
1088 gtk_dialog_run (GTK_DIALOG (dialog));
1089 gtk_widget_destroy (dialog);