1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
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 GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Richard Hult <richard@imendio.com>
21 * Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
30 #include <glib/gi18n-lib.h>
32 #include <glade/glade.h>
33 #include <gdk/gdkkeysyms.h>
35 #include <telepathy-glib/util.h>
36 #include <libmissioncontrol/mc-enum-types.h>
38 #include <libempathy/empathy-idle.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-status-presets.h>
42 // FIXME - what's the correct debug flag?
43 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
44 #include <libempathy/empathy-debug.h>
46 #include "empathy-ui-utils.h"
47 #include "empathy-images.h"
48 #include "empathy-presence-chooser.h"
50 /* Flashing delay for icons (milliseconds). */
51 #define FLASH_TIMEOUT 500
53 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
57 gboolean editing_status;
58 int block_set_editing;
63 McPresence flash_state_1;
64 McPresence flash_state_2;
65 guint flash_timeout_id;
66 } EmpathyPresenceChooserPriv;
70 GtkWidget *checkbutton_save;
71 GtkWidget *comboboxentry_message;
72 GtkWidget *entry_message;
73 GtkWidget *combobox_status;
74 GtkTreeModel *model_status;
75 } CustomMessageDialog;
84 static CustomMessageDialog *message_dialog = NULL;
85 /* States to be listed in the menu.
86 * Each state has a boolean telling if it can have custom message */
87 static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
88 MC_PRESENCE_DO_NOT_DISTURB, TRUE,
89 MC_PRESENCE_AWAY, TRUE,
90 MC_PRESENCE_HIDDEN, FALSE,
91 MC_PRESENCE_OFFLINE, FALSE};
93 static void presence_chooser_finalize (GObject *object);
94 static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
95 static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
96 static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
99 static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
101 static void presence_chooser_menu_add_item (GtkWidget *menu,
104 static void presence_chooser_noncustom_activate_cb (GtkWidget *item,
106 static void presence_chooser_set_state (McPresence state,
107 const gchar *status);
108 static void presence_chooser_custom_activate_cb (GtkWidget *item,
110 static void presence_chooser_dialog_show (GtkWindow *parent);
112 G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
115 empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
117 GObjectClass *object_class = G_OBJECT_CLASS (klass);
119 object_class->finalize = presence_chooser_finalize;
121 g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
139 ENTRY_TYPE_SEPARATOR,
140 ENTRY_TYPE_EDIT_CUSTOM,
143 static GtkTreeModel *
146 GtkListStore *store = gtk_list_store_new (N_COLUMNS,
147 G_TYPE_STRING, /* COL_STATE_ICON_NAME */
148 MC_TYPE_PRESENCE, /* COL_STATE */
149 G_TYPE_STRING, /* COL_STATUS_TEXT */
150 G_TYPE_STRING, /* COL_DISPLAY_MARKUP */
151 G_TYPE_INT); /* COL_TYPE */
156 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
159 const char *status = empathy_presence_get_default_message (states[i]);
160 const char *icon_name = empathy_icon_name_for_presence (states[i]);
162 gtk_list_store_append (store, &iter);
163 gtk_list_store_set (store, &iter,
164 COL_STATE_ICON_NAME, icon_name,
165 COL_STATE, states[i],
166 COL_STATUS_TEXT, status,
167 COL_DISPLAY_MARKUP, status,
168 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_append (store, &iter);
176 gtk_list_store_set (store, &iter,
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_TYPE, ENTRY_TYPE_SAVED,
186 gtk_list_store_append (store, &iter);
187 gtk_list_store_set (store, &iter,
188 COL_STATE_ICON_NAME, icon_name,
189 COL_STATE, states[i],
191 COL_DISPLAY_MARKUP, "<i>Custom Message...</i>",
192 COL_TYPE, ENTRY_TYPE_CUSTOM,
198 /* add a separator */
199 gtk_list_store_append (store, &iter);
200 gtk_list_store_set (store, &iter,
201 COL_TYPE, ENTRY_TYPE_SEPARATOR,
204 gtk_list_store_append (store, &iter);
205 gtk_list_store_set (store, &iter,
206 COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
208 COL_DISPLAY_MARKUP, "Edit Custom Messages...",
209 COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
212 return GTK_TREE_MODEL (store);
216 popup_shown_cb (GObject *self, GParamSpec *pspec, gpointer user_data)
219 g_object_get (self, "popup-shown", &shown, NULL);
223 GtkTreeModel *model = create_model ();
225 gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (model));
227 g_object_unref (model);
231 set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
233 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
234 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
236 if (priv->block_set_editing) return;
240 priv->editing_status = TRUE;
241 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
242 GTK_ENTRY_ICON_SECONDARY,
244 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
245 GTK_ENTRY_ICON_SECONDARY,
247 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
248 GTK_ENTRY_ICON_PRIMARY,
253 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
254 GTK_ENTRY_ICON_SECONDARY,
256 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
257 GTK_ENTRY_ICON_SECONDARY,
259 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
260 GTK_ENTRY_ICON_PRIMARY,
263 // FIXME - move the focus somewhere
265 priv->editing_status = FALSE;
270 mc_set_custom_state (EmpathyPresenceChooser *self)
272 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
273 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
275 /* update the status with MC */
276 const char *status = gtk_entry_get_text (GTK_ENTRY (entry));
277 DEBUG ("Sending state to MC-> %s (%s)\n",
278 g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
279 priv->state)->value_name,
281 empathy_idle_set_presence (priv->idle, priv->state, status);
285 ui_set_custom_state (EmpathyPresenceChooser *self,
289 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
290 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
291 const char *icon_name;
293 priv->block_set_editing++;
294 priv->block_changed++;
296 icon_name = empathy_icon_name_for_presence (state);
297 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
298 GTK_ENTRY_ICON_PRIMARY,
300 gtk_entry_set_text (GTK_ENTRY (entry), status);
302 priv->block_changed--;
303 priv->block_set_editing--;
307 entry_icon_release_cb (EmpathyPresenceChooser *self,
308 GtkEntryIconPosition icon_pos,
312 set_status_editing (self, FALSE);
313 mc_set_custom_state (self);
317 entry_activate_cb (EmpathyPresenceChooser *self,
320 set_status_editing (self, FALSE);
321 mc_set_custom_state (self);
325 entry_key_press_event_cb (EmpathyPresenceChooser *self,
329 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
331 if (priv->editing_status && event->keyval == GDK_Escape)
333 /* the user pressed Escape, undo the editing */
334 set_status_editing (self, FALSE);
335 presence_chooser_presence_changed_cb (self);
340 return FALSE; /* send this event elsewhere */
344 changed_cb (GtkComboBox *self, gpointer user_data)
346 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
348 if (priv->block_changed) return;
354 GtkTreeModel *model = gtk_combo_box_get_model (self);
355 if (!gtk_combo_box_get_active_iter (self, &iter))
357 /* the combo is being edited to a custom entry */
358 if (!priv->editing_status)
360 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
365 gtk_tree_model_get (model, &iter,
366 COL_STATE_ICON_NAME, &icon_name,
367 COL_STATE, &priv->state,
371 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
373 if (type == ENTRY_TYPE_EDIT_CUSTOM)
375 /* recover the status that was unset because COL_STATUS_TEXT
376 * is "". Unfortunately if you try and set COL_STATUS_TEXT to
377 * NULL, it generates a g_critical. I wonder if there is a
378 * better way around this. */
379 const char *status = empathy_idle_get_status (priv->idle);
380 priv->block_set_editing++;
381 gtk_entry_set_text (GTK_ENTRY (entry), status);
382 priv->block_set_editing--;
384 /* attempt to get the toplevel for this widget */
385 GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
386 if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window))
391 presence_chooser_dialog_show (GTK_WINDOW (window));
393 else if (type == ENTRY_TYPE_CUSTOM)
395 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
396 GTK_ENTRY_ICON_PRIMARY,
400 gtk_widget_grab_focus (entry);
402 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
407 /* just in case we were setting a new status when
408 * things were changed */
409 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), FALSE);
411 gtk_tree_model_get (model, &iter,
412 COL_STATUS_TEXT, &status,
415 empathy_idle_set_presence (priv->idle, priv->state, status);
424 combo_row_separator_func (GtkTreeModel *model,
429 gtk_tree_model_get (model, iter,
433 return (type == ENTRY_TYPE_SEPARATOR);
437 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
439 EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
440 EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
442 chooser->priv = priv;
444 GtkTreeModel *model = create_model ();
446 gtk_combo_box_set_model (GTK_COMBO_BOX (chooser), GTK_TREE_MODEL (model));
447 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
449 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
450 combo_row_separator_func,
453 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
454 gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
455 GTK_ENTRY_ICON_PRIMARY, FALSE);
456 g_signal_connect_object (entry, "icon-release",
457 G_CALLBACK (entry_icon_release_cb), chooser,
459 g_signal_connect_object (entry, "activate",
460 G_CALLBACK (entry_activate_cb), chooser,
462 g_signal_connect_object (entry, "key-press-event",
463 G_CALLBACK (entry_key_press_event_cb), chooser,
465 // FIXME - should this also happen when the user presses TAB ?
467 GtkCellRenderer *renderer;
468 gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
470 renderer = gtk_cell_renderer_pixbuf_new ();
471 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
472 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
473 "icon-name", COL_STATE_ICON_NAME,
475 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
477 renderer = gtk_cell_renderer_text_new ();
478 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
479 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
480 "markup", COL_DISPLAY_MARKUP,
483 g_object_unref (model);
485 g_signal_connect (chooser, "notify::popup-shown",
486 G_CALLBACK (popup_shown_cb), NULL);
487 g_signal_connect (chooser, "changed",
488 G_CALLBACK (changed_cb), NULL);
490 priv->idle = empathy_idle_dup_singleton ();
491 presence_chooser_presence_changed_cb (chooser);
492 g_signal_connect_swapped (priv->idle, "notify",
493 G_CALLBACK (presence_chooser_presence_changed_cb),
496 g_object_set (chooser,
497 // FIXME: this string sucks
498 "tooltip-text", _("Set your presence and current status"),
503 presence_chooser_finalize (GObject *object)
505 EmpathyPresenceChooserPriv *priv;
507 priv = GET_PRIV (object);
509 if (priv->flash_timeout_id) {
510 g_source_remove (priv->flash_timeout_id);
513 g_signal_handlers_disconnect_by_func (priv->idle,
514 presence_chooser_presence_changed_cb,
516 g_object_unref (priv->idle);
518 G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
522 empathy_presence_chooser_new (void)
526 chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
532 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
534 EmpathyPresenceChooserPriv *priv;
536 McPresence flash_state;
539 priv = GET_PRIV (chooser);
541 priv->state = state = empathy_idle_get_state (priv->idle);
542 status = empathy_idle_get_status (priv->idle);
543 flash_state = empathy_idle_get_flash_state (priv->idle);
545 /* look through the model and attempt to find a matching state */
546 GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
548 gboolean valid, match_state = FALSE, match = FALSE;
549 for (valid = gtk_tree_model_get_iter_first (model, &iter);
551 valid = gtk_tree_model_iter_next (model, &iter))
557 gtk_tree_model_get (model, &iter,
562 if (m_type == ENTRY_TYPE_CUSTOM)
566 else if (!match_state && state == m_state)
568 /* we are now in the section that can contain our
572 else if (match_state && state != m_state)
574 /* we have passed the section that can contain our
579 gtk_tree_model_get (model, &iter,
580 COL_STATUS_TEXT, &m_status,
583 match = !strcmp (status, m_status);
593 priv->block_changed++;
594 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
595 priv->block_changed--;
599 // FIXME - do we insert the match into the menu?
600 ui_set_custom_state (chooser, state, status);
603 if (flash_state != MC_PRESENCE_UNSET) {
604 presence_chooser_flash_start (chooser, state, flash_state);
606 presence_chooser_flash_stop (chooser, state);
611 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
613 EmpathyPresenceChooserPriv *priv;
615 static gboolean on = FALSE;
617 priv = GET_PRIV (chooser);
620 state = priv->flash_state_1;
622 state = priv->flash_state_2;
625 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
626 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
627 GTK_ENTRY_ICON_PRIMARY,
628 empathy_icon_name_for_presence (state));
636 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
640 EmpathyPresenceChooserPriv *priv;
642 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
644 priv = GET_PRIV (chooser);
646 priv->flash_state_1 = state_1;
647 priv->flash_state_2 = state_2;
649 if (!priv->flash_timeout_id) {
650 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
651 (GSourceFunc) presence_chooser_flash_timeout_cb,
657 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
660 EmpathyPresenceChooserPriv *priv;
662 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
664 priv = GET_PRIV (chooser);
666 if (priv->flash_timeout_id) {
667 g_source_remove (priv->flash_timeout_id);
668 priv->flash_timeout_id = 0;
670 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
672 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
673 GTK_ENTRY_ICON_PRIMARY,
674 empathy_icon_name_for_presence (state));
676 // FIXME - what does this do?
677 // priv->last_state = state;
681 empathy_presence_chooser_create_menu (void)
689 menu = gtk_menu_new ();
691 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
694 status = empathy_presence_get_default_message (states[i]);
695 presence_chooser_menu_add_item (menu,
700 /* Set custom messages if wanted */
701 list = empathy_status_presets_get (states[i], 5);
702 for (l = list; l; l = l->next) {
703 presence_chooser_menu_add_item (menu,
713 item = gtk_menu_item_new ();
714 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
715 gtk_widget_show (item);
717 /* Custom messages */
718 item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
719 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
720 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
721 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
722 gtk_widget_show (image);
723 gtk_widget_show (item);
725 g_signal_connect (item,
727 G_CALLBACK (presence_chooser_custom_activate_cb),
734 presence_chooser_menu_add_item (GtkWidget *menu,
740 const gchar *icon_name;
742 item = gtk_image_menu_item_new_with_label (str);
743 icon_name = empathy_icon_name_for_presence (state);
745 g_signal_connect (item, "activate",
746 G_CALLBACK (presence_chooser_noncustom_activate_cb),
749 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
750 gtk_widget_show (image);
752 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
753 gtk_widget_show (item);
755 g_object_set_data_full (G_OBJECT (item),
756 "status", g_strdup (str),
757 (GDestroyNotify) g_free);
759 g_object_set_data (G_OBJECT (item), "state", GINT_TO_POINTER (state));
761 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
765 presence_chooser_noncustom_activate_cb (GtkWidget *item,
771 status = g_object_get_data (G_OBJECT (item), "status");
772 state = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "state"));
774 presence_chooser_set_state (state, status);
778 presence_chooser_set_state (McPresence state,
783 idle = empathy_idle_dup_singleton ();
784 empathy_idle_set_presence (idle, state, status);
785 g_object_unref (idle);
789 presence_chooser_custom_activate_cb (GtkWidget *item,
792 presence_chooser_dialog_show (NULL);
796 presence_chooser_dialog_get_selected (CustomMessageDialog *dialog)
800 McPresence presence = LAST_MC_PRESENCE;
802 model = gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->combobox_status));
803 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->combobox_status), &iter)) {
804 gtk_tree_model_get (model, &iter,
805 COL_PRESENCE, &presence,
813 presence_chooser_dialog_status_changed_cb (GtkWidget *widget,
814 CustomMessageDialog *dialog)
818 McPresence presence = LAST_MC_PRESENCE;
821 presence = presence_chooser_dialog_get_selected (dialog);
823 store = gtk_list_store_new (1, G_TYPE_STRING);
824 messages = empathy_status_presets_get (presence, -1);
825 for (l = messages; l; l = l->next) {
826 gtk_list_store_append (store, &iter);
827 gtk_list_store_set (store, &iter, 0, l->data, -1);
830 gtk_entry_set_text (GTK_ENTRY (dialog->entry_message),
831 messages ? messages->data : "");
833 g_list_free (messages);
835 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->comboboxentry_message),
836 GTK_TREE_MODEL (store));
838 g_object_unref (store);
842 presence_chooser_dialog_message_changed_cb (GtkWidget *widget,
843 CustomMessageDialog *dialog)
848 gboolean found = FALSE;
850 presence = presence_chooser_dialog_get_selected (dialog);
851 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
853 messages = empathy_status_presets_get (presence, -1);
854 for (l = messages; l; l = l->next) {
855 if (!tp_strdiff (text, l->data)) {
860 g_list_free (messages);
862 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save),
867 presence_chooser_dialog_save_toggled_cb (GtkWidget *widget,
868 CustomMessageDialog *dialog)
874 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save));
875 state = presence_chooser_dialog_get_selected (dialog);
876 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
879 empathy_status_presets_set_last (state, text);
881 empathy_status_presets_remove (state, text);
886 presence_chooser_dialog_setup (CustomMessageDialog *dialog)
889 GtkCellRenderer *renderer;
893 store = gtk_list_store_new (COL_COUNT,
894 G_TYPE_STRING, /* Icon name */
895 G_TYPE_STRING, /* Label */
896 MC_TYPE_PRESENCE); /* Presence */
897 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->combobox_status),
898 GTK_TREE_MODEL (store));
900 renderer = gtk_cell_renderer_pixbuf_new ();
901 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, FALSE);
902 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
903 "icon-name", COL_ICON,
905 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
907 renderer = gtk_cell_renderer_text_new ();
908 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, TRUE);
909 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
913 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
918 gtk_list_store_append (store, &iter);
919 gtk_list_store_set (store, &iter,
920 COL_ICON, empathy_icon_name_for_presence (states[i]),
921 COL_LABEL, empathy_presence_get_default_message (states[i]),
922 COL_PRESENCE, states[i],
926 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_status), 0);
930 presence_chooser_dialog_response_cb (GtkWidget *widget,
932 CustomMessageDialog *dialog)
934 if (response == GTK_RESPONSE_APPLY) {
938 state = presence_chooser_dialog_get_selected (dialog);
939 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
941 presence_chooser_set_state (state, text);
944 gtk_widget_destroy (widget);
948 presence_chooser_dialog_destroy_cb (GtkWidget *widget,
949 CustomMessageDialog *dialog)
953 message_dialog = NULL;
957 presence_chooser_dialog_show (GtkWindow *parent)
962 if (message_dialog) {
963 gtk_window_present (GTK_WINDOW (message_dialog->dialog));
967 message_dialog = g_new0 (CustomMessageDialog, 1);
969 filename = empathy_file_lookup ("empathy-presence-chooser.glade",
971 glade = empathy_glade_get_file (filename,
972 "custom_message_dialog",
974 "custom_message_dialog", &message_dialog->dialog,
975 "checkbutton_save", &message_dialog->checkbutton_save,
976 "comboboxentry_message", &message_dialog->comboboxentry_message,
977 "combobox_status", &message_dialog->combobox_status,
981 empathy_glade_connect (glade,
983 "custom_message_dialog", "destroy", presence_chooser_dialog_destroy_cb,
984 "custom_message_dialog", "response", presence_chooser_dialog_response_cb,
985 "combobox_status", "changed", presence_chooser_dialog_status_changed_cb,
986 "checkbutton_save", "toggled", presence_chooser_dialog_save_toggled_cb,
989 g_object_unref (glade);
991 /* Setup the message combobox */
992 message_dialog->entry_message = GTK_BIN (message_dialog->comboboxentry_message)->child;
993 gtk_entry_set_activates_default (GTK_ENTRY (message_dialog->entry_message), TRUE);
994 gtk_entry_set_width_chars (GTK_ENTRY (message_dialog->entry_message), 25);
995 g_signal_connect (message_dialog->entry_message, "changed",
996 G_CALLBACK (presence_chooser_dialog_message_changed_cb),
999 presence_chooser_dialog_setup (message_dialog);
1001 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0);
1005 gtk_window_set_transient_for (
1006 GTK_WINDOW (message_dialog->dialog),
1010 gtk_widget_show_all (message_dialog->dialog);