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 /* attempt to get the toplevel for this widget */
264 GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
265 if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window))
267 /* unset the focus */
268 gtk_window_set_focus (GTK_WINDOW (window), NULL);
271 priv->editing_status = FALSE;
276 mc_set_custom_state (EmpathyPresenceChooser *self)
278 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
279 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
281 /* update the status with MC */
282 const char *status = gtk_entry_get_text (GTK_ENTRY (entry));
283 DEBUG ("Sending state to MC-> %s (%s)\n",
284 g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
285 priv->state)->value_name,
287 empathy_idle_set_presence (priv->idle, priv->state, status);
291 ui_set_custom_state (EmpathyPresenceChooser *self,
295 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
296 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
297 const char *icon_name;
299 priv->block_set_editing++;
300 priv->block_changed++;
302 icon_name = empathy_icon_name_for_presence (state);
303 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
304 GTK_ENTRY_ICON_PRIMARY,
306 gtk_entry_set_text (GTK_ENTRY (entry), status);
308 priv->block_changed--;
309 priv->block_set_editing--;
313 entry_icon_release_cb (EmpathyPresenceChooser *self,
314 GtkEntryIconPosition icon_pos,
318 set_status_editing (self, FALSE);
319 mc_set_custom_state (self);
323 entry_activate_cb (EmpathyPresenceChooser *self,
326 set_status_editing (self, FALSE);
327 mc_set_custom_state (self);
331 entry_key_press_event_cb (EmpathyPresenceChooser *self,
335 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
337 if (priv->editing_status && event->keyval == GDK_Escape)
339 /* the user pressed Escape, undo the editing */
340 set_status_editing (self, FALSE);
341 presence_chooser_presence_changed_cb (self);
346 return FALSE; /* send this event elsewhere */
350 changed_cb (GtkComboBox *self, gpointer user_data)
352 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
354 if (priv->block_changed) return;
360 GtkTreeModel *model = gtk_combo_box_get_model (self);
361 if (!gtk_combo_box_get_active_iter (self, &iter))
363 /* the combo is being edited to a custom entry */
364 if (!priv->editing_status)
366 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
371 gtk_tree_model_get (model, &iter,
372 COL_STATE_ICON_NAME, &icon_name,
373 COL_STATE, &priv->state,
377 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
379 if (type == ENTRY_TYPE_EDIT_CUSTOM)
381 /* recover the status that was unset because COL_STATUS_TEXT
382 * is "". Unfortunately if you try and set COL_STATUS_TEXT to
383 * NULL, it generates a g_critical. I wonder if there is a
384 * better way around this. */
385 const char *status = empathy_idle_get_status (priv->idle);
386 priv->block_set_editing++;
387 gtk_entry_set_text (GTK_ENTRY (entry), status);
388 priv->block_set_editing--;
390 /* attempt to get the toplevel for this widget */
391 GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
392 if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window))
397 presence_chooser_dialog_show (GTK_WINDOW (window));
399 else if (type == ENTRY_TYPE_CUSTOM)
401 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
402 GTK_ENTRY_ICON_PRIMARY,
406 gtk_widget_grab_focus (entry);
408 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
413 /* just in case we were setting a new status when
414 * things were changed */
415 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), FALSE);
417 gtk_tree_model_get (model, &iter,
418 COL_STATUS_TEXT, &status,
421 empathy_idle_set_presence (priv->idle, priv->state, status);
430 combo_row_separator_func (GtkTreeModel *model,
435 gtk_tree_model_get (model, iter,
439 return (type == ENTRY_TYPE_SEPARATOR);
443 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
445 EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
446 EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
448 chooser->priv = priv;
450 GtkTreeModel *model = create_model ();
452 gtk_combo_box_set_model (GTK_COMBO_BOX (chooser), GTK_TREE_MODEL (model));
453 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
455 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
456 combo_row_separator_func,
459 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
460 gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
461 GTK_ENTRY_ICON_PRIMARY, FALSE);
462 g_signal_connect_object (entry, "icon-release",
463 G_CALLBACK (entry_icon_release_cb), chooser,
465 g_signal_connect_object (entry, "activate",
466 G_CALLBACK (entry_activate_cb), chooser,
468 g_signal_connect_object (entry, "key-press-event",
469 G_CALLBACK (entry_key_press_event_cb), chooser,
471 // FIXME - should this also happen when the user presses TAB ?
473 GtkCellRenderer *renderer;
474 gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
476 renderer = gtk_cell_renderer_pixbuf_new ();
477 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
478 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
479 "icon-name", COL_STATE_ICON_NAME,
481 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
483 renderer = gtk_cell_renderer_text_new ();
484 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
485 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
486 "markup", COL_DISPLAY_MARKUP,
489 g_object_unref (model);
491 g_signal_connect (chooser, "notify::popup-shown",
492 G_CALLBACK (popup_shown_cb), NULL);
493 g_signal_connect (chooser, "changed",
494 G_CALLBACK (changed_cb), NULL);
496 priv->idle = empathy_idle_dup_singleton ();
497 presence_chooser_presence_changed_cb (chooser);
498 g_signal_connect_swapped (priv->idle, "notify",
499 G_CALLBACK (presence_chooser_presence_changed_cb),
502 g_object_set (chooser,
503 // FIXME: this string sucks
504 "tooltip-text", _("Set your presence and current status"),
509 presence_chooser_finalize (GObject *object)
511 EmpathyPresenceChooserPriv *priv;
513 priv = GET_PRIV (object);
515 if (priv->flash_timeout_id) {
516 g_source_remove (priv->flash_timeout_id);
519 g_signal_handlers_disconnect_by_func (priv->idle,
520 presence_chooser_presence_changed_cb,
522 g_object_unref (priv->idle);
524 G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
528 empathy_presence_chooser_new (void)
532 chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
538 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
540 EmpathyPresenceChooserPriv *priv;
542 McPresence flash_state;
545 priv = GET_PRIV (chooser);
547 priv->state = state = empathy_idle_get_state (priv->idle);
548 status = empathy_idle_get_status (priv->idle);
549 flash_state = empathy_idle_get_flash_state (priv->idle);
551 /* look through the model and attempt to find a matching state */
552 GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
554 gboolean valid, match_state = FALSE, match = FALSE;
555 for (valid = gtk_tree_model_get_iter_first (model, &iter);
557 valid = gtk_tree_model_iter_next (model, &iter))
563 gtk_tree_model_get (model, &iter,
568 if (m_type == ENTRY_TYPE_CUSTOM)
572 else if (!match_state && state == m_state)
574 /* we are now in the section that can contain our
578 else if (match_state && state != m_state)
580 /* we have passed the section that can contain our
585 gtk_tree_model_get (model, &iter,
586 COL_STATUS_TEXT, &m_status,
589 match = !strcmp (status, m_status);
599 priv->block_changed++;
600 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
601 priv->block_changed--;
605 // FIXME - do we insert the match into the menu?
606 ui_set_custom_state (chooser, state, status);
609 if (flash_state != MC_PRESENCE_UNSET) {
610 presence_chooser_flash_start (chooser, state, flash_state);
612 presence_chooser_flash_stop (chooser, state);
617 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
619 EmpathyPresenceChooserPriv *priv;
621 static gboolean on = FALSE;
623 priv = GET_PRIV (chooser);
626 state = priv->flash_state_1;
628 state = priv->flash_state_2;
631 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
632 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
633 GTK_ENTRY_ICON_PRIMARY,
634 empathy_icon_name_for_presence (state));
642 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
646 EmpathyPresenceChooserPriv *priv;
648 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
650 priv = GET_PRIV (chooser);
652 priv->flash_state_1 = state_1;
653 priv->flash_state_2 = state_2;
655 if (!priv->flash_timeout_id) {
656 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
657 (GSourceFunc) presence_chooser_flash_timeout_cb,
663 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
666 EmpathyPresenceChooserPriv *priv;
668 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
670 priv = GET_PRIV (chooser);
672 if (priv->flash_timeout_id) {
673 g_source_remove (priv->flash_timeout_id);
674 priv->flash_timeout_id = 0;
676 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
678 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
679 GTK_ENTRY_ICON_PRIMARY,
680 empathy_icon_name_for_presence (state));
682 // FIXME - what does this do?
683 // priv->last_state = state;
687 empathy_presence_chooser_create_menu (void)
695 menu = gtk_menu_new ();
697 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
700 status = empathy_presence_get_default_message (states[i]);
701 presence_chooser_menu_add_item (menu,
706 /* Set custom messages if wanted */
707 list = empathy_status_presets_get (states[i], 5);
708 for (l = list; l; l = l->next) {
709 presence_chooser_menu_add_item (menu,
719 item = gtk_menu_item_new ();
720 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
721 gtk_widget_show (item);
723 /* Custom messages */
724 item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
725 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
726 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
727 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
728 gtk_widget_show (image);
729 gtk_widget_show (item);
731 g_signal_connect (item,
733 G_CALLBACK (presence_chooser_custom_activate_cb),
740 presence_chooser_menu_add_item (GtkWidget *menu,
746 const gchar *icon_name;
748 item = gtk_image_menu_item_new_with_label (str);
749 icon_name = empathy_icon_name_for_presence (state);
751 g_signal_connect (item, "activate",
752 G_CALLBACK (presence_chooser_noncustom_activate_cb),
755 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
756 gtk_widget_show (image);
758 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
759 gtk_widget_show (item);
761 g_object_set_data_full (G_OBJECT (item),
762 "status", g_strdup (str),
763 (GDestroyNotify) g_free);
765 g_object_set_data (G_OBJECT (item), "state", GINT_TO_POINTER (state));
767 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
771 presence_chooser_noncustom_activate_cb (GtkWidget *item,
777 status = g_object_get_data (G_OBJECT (item), "status");
778 state = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "state"));
780 presence_chooser_set_state (state, status);
784 presence_chooser_set_state (McPresence state,
789 idle = empathy_idle_dup_singleton ();
790 empathy_idle_set_presence (idle, state, status);
791 g_object_unref (idle);
795 presence_chooser_custom_activate_cb (GtkWidget *item,
798 presence_chooser_dialog_show (NULL);
802 presence_chooser_dialog_get_selected (CustomMessageDialog *dialog)
806 McPresence presence = LAST_MC_PRESENCE;
808 model = gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->combobox_status));
809 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->combobox_status), &iter)) {
810 gtk_tree_model_get (model, &iter,
811 COL_PRESENCE, &presence,
819 presence_chooser_dialog_status_changed_cb (GtkWidget *widget,
820 CustomMessageDialog *dialog)
824 McPresence presence = LAST_MC_PRESENCE;
827 presence = presence_chooser_dialog_get_selected (dialog);
829 store = gtk_list_store_new (1, G_TYPE_STRING);
830 messages = empathy_status_presets_get (presence, -1);
831 for (l = messages; l; l = l->next) {
832 gtk_list_store_append (store, &iter);
833 gtk_list_store_set (store, &iter, 0, l->data, -1);
836 gtk_entry_set_text (GTK_ENTRY (dialog->entry_message),
837 messages ? messages->data : "");
839 g_list_free (messages);
841 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->comboboxentry_message),
842 GTK_TREE_MODEL (store));
844 g_object_unref (store);
848 presence_chooser_dialog_message_changed_cb (GtkWidget *widget,
849 CustomMessageDialog *dialog)
854 gboolean found = FALSE;
856 presence = presence_chooser_dialog_get_selected (dialog);
857 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
859 messages = empathy_status_presets_get (presence, -1);
860 for (l = messages; l; l = l->next) {
861 if (!tp_strdiff (text, l->data)) {
866 g_list_free (messages);
868 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save),
873 presence_chooser_dialog_save_toggled_cb (GtkWidget *widget,
874 CustomMessageDialog *dialog)
880 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save));
881 state = presence_chooser_dialog_get_selected (dialog);
882 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
885 empathy_status_presets_set_last (state, text);
887 empathy_status_presets_remove (state, text);
892 presence_chooser_dialog_setup (CustomMessageDialog *dialog)
895 GtkCellRenderer *renderer;
899 store = gtk_list_store_new (COL_COUNT,
900 G_TYPE_STRING, /* Icon name */
901 G_TYPE_STRING, /* Label */
902 MC_TYPE_PRESENCE); /* Presence */
903 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->combobox_status),
904 GTK_TREE_MODEL (store));
906 renderer = gtk_cell_renderer_pixbuf_new ();
907 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, FALSE);
908 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
909 "icon-name", COL_ICON,
911 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
913 renderer = gtk_cell_renderer_text_new ();
914 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, TRUE);
915 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
919 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
924 gtk_list_store_append (store, &iter);
925 gtk_list_store_set (store, &iter,
926 COL_ICON, empathy_icon_name_for_presence (states[i]),
927 COL_LABEL, empathy_presence_get_default_message (states[i]),
928 COL_PRESENCE, states[i],
932 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_status), 0);
936 presence_chooser_dialog_response_cb (GtkWidget *widget,
938 CustomMessageDialog *dialog)
940 if (response == GTK_RESPONSE_APPLY) {
944 state = presence_chooser_dialog_get_selected (dialog);
945 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
947 presence_chooser_set_state (state, text);
950 gtk_widget_destroy (widget);
954 presence_chooser_dialog_destroy_cb (GtkWidget *widget,
955 CustomMessageDialog *dialog)
959 message_dialog = NULL;
963 presence_chooser_dialog_show (GtkWindow *parent)
968 if (message_dialog) {
969 gtk_window_present (GTK_WINDOW (message_dialog->dialog));
973 message_dialog = g_new0 (CustomMessageDialog, 1);
975 filename = empathy_file_lookup ("empathy-presence-chooser.glade",
977 glade = empathy_glade_get_file (filename,
978 "custom_message_dialog",
980 "custom_message_dialog", &message_dialog->dialog,
981 "checkbutton_save", &message_dialog->checkbutton_save,
982 "comboboxentry_message", &message_dialog->comboboxentry_message,
983 "combobox_status", &message_dialog->combobox_status,
987 empathy_glade_connect (glade,
989 "custom_message_dialog", "destroy", presence_chooser_dialog_destroy_cb,
990 "custom_message_dialog", "response", presence_chooser_dialog_response_cb,
991 "combobox_status", "changed", presence_chooser_dialog_status_changed_cb,
992 "checkbutton_save", "toggled", presence_chooser_dialog_save_toggled_cb,
995 g_object_unref (glade);
997 /* Setup the message combobox */
998 message_dialog->entry_message = GTK_BIN (message_dialog->comboboxentry_message)->child;
999 gtk_entry_set_activates_default (GTK_ENTRY (message_dialog->entry_message), TRUE);
1000 gtk_entry_set_width_chars (GTK_ENTRY (message_dialog->entry_message), 25);
1001 g_signal_connect (message_dialog->entry_message, "changed",
1002 G_CALLBACK (presence_chooser_dialog_message_changed_cb),
1005 presence_chooser_dialog_setup (message_dialog);
1007 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0);
1011 gtk_window_set_transient_for (
1012 GTK_WINDOW (message_dialog->dialog),
1016 gtk_widget_show_all (message_dialog->dialog);