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 <glade/glade.h>
35 #include <gdk/gdkkeysyms.h>
37 #include <telepathy-glib/util.h>
38 #include <libmissioncontrol/mc-enum-types.h>
40 #include <libempathy/empathy-idle.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy/empathy-status-presets.h>
44 // FIXME - what's the correct debug flag?
45 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
46 #include <libempathy/empathy-debug.h>
48 #include "empathy-ui-utils.h"
49 #include "empathy-images.h"
50 #include "empathy-presence-chooser.h"
52 /* Flashing delay for icons (milliseconds). */
53 #define FLASH_TIMEOUT 500
55 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
59 gboolean editing_status;
60 int block_set_editing;
65 McPresence flash_state_1;
66 McPresence flash_state_2;
67 guint flash_timeout_id;
68 } EmpathyPresenceChooserPriv;
72 GtkWidget *checkbutton_save;
73 GtkWidget *comboboxentry_message;
74 GtkWidget *entry_message;
75 GtkWidget *combobox_status;
76 GtkTreeModel *model_status;
77 } CustomMessageDialog;
86 static CustomMessageDialog *message_dialog = NULL;
87 /* States to be listed in the menu.
88 * Each state has a boolean telling if it can have custom message */
89 static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
90 MC_PRESENCE_DO_NOT_DISTURB, TRUE,
91 MC_PRESENCE_AWAY, TRUE,
92 MC_PRESENCE_HIDDEN, FALSE,
93 MC_PRESENCE_OFFLINE, FALSE};
95 static void presence_chooser_finalize (GObject *object);
96 static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
97 static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
98 static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
101 static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
103 static void presence_chooser_menu_add_item (GtkWidget *menu,
106 static void presence_chooser_noncustom_activate_cb (GtkWidget *item,
108 static void presence_chooser_set_state (McPresence state,
109 const gchar *status);
110 static void presence_chooser_custom_activate_cb (GtkWidget *item,
112 static void presence_chooser_dialog_show (GtkWindow *parent);
114 G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
117 empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
119 GObjectClass *object_class = G_OBJECT_CLASS (klass);
121 object_class->finalize = presence_chooser_finalize;
123 g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
141 ENTRY_TYPE_SEPARATOR,
142 ENTRY_TYPE_EDIT_CUSTOM,
145 static GtkTreeModel *
148 GtkListStore *store = gtk_list_store_new (N_COLUMNS,
149 G_TYPE_STRING, /* COL_STATE_ICON_NAME */
150 MC_TYPE_PRESENCE, /* COL_STATE */
151 G_TYPE_STRING, /* COL_STATUS_TEXT */
152 G_TYPE_STRING, /* COL_DISPLAY_MARKUP */
153 G_TYPE_INT); /* COL_TYPE */
158 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
161 const char *status = empathy_presence_get_default_message (states[i]);
162 const char *icon_name = empathy_icon_name_for_presence (states[i]);
164 gtk_list_store_append (store, &iter);
165 gtk_list_store_set (store, &iter,
166 COL_STATE_ICON_NAME, icon_name,
167 COL_STATE, states[i],
168 COL_STATUS_TEXT, status,
169 COL_DISPLAY_MARKUP, status,
170 COL_TYPE, ENTRY_TYPE_BUILTIN,
174 /* Set custom messages if wanted */
175 list = empathy_status_presets_get (states[i], 5);
176 for (l = list; l; l = l->next) {
177 gtk_list_store_append (store, &iter);
178 gtk_list_store_set (store, &iter,
179 COL_STATE_ICON_NAME, icon_name,
180 COL_STATE, states[i],
181 COL_STATUS_TEXT, l->data,
182 COL_DISPLAY_MARKUP, l->data,
183 COL_TYPE, ENTRY_TYPE_SAVED,
188 gtk_list_store_append (store, &iter);
189 gtk_list_store_set (store, &iter,
190 COL_STATE_ICON_NAME, icon_name,
191 COL_STATE, states[i],
193 COL_DISPLAY_MARKUP, "<i>Custom Message...</i>",
194 COL_TYPE, ENTRY_TYPE_CUSTOM,
200 /* add a separator */
201 gtk_list_store_append (store, &iter);
202 gtk_list_store_set (store, &iter,
203 COL_TYPE, ENTRY_TYPE_SEPARATOR,
206 gtk_list_store_append (store, &iter);
207 gtk_list_store_set (store, &iter,
208 COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
210 COL_DISPLAY_MARKUP, "Edit Custom Messages...",
211 COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
214 return GTK_TREE_MODEL (store);
218 popup_shown_cb (GObject *self, GParamSpec *pspec, gpointer user_data)
221 g_object_get (self, "popup-shown", &shown, NULL);
225 GtkTreeModel *model = create_model ();
227 gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (model));
229 g_object_unref (model);
233 set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
235 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
236 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
238 if (priv->block_set_editing) return;
242 priv->editing_status = TRUE;
243 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
244 GTK_ENTRY_ICON_SECONDARY,
246 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
247 GTK_ENTRY_ICON_SECONDARY,
249 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
250 GTK_ENTRY_ICON_PRIMARY,
255 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
256 GTK_ENTRY_ICON_SECONDARY,
258 gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
259 GTK_ENTRY_ICON_SECONDARY,
261 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
262 GTK_ENTRY_ICON_PRIMARY,
265 /* attempt to get the toplevel for this widget */
266 GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
267 if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window))
269 /* unset the focus */
270 gtk_window_set_focus (GTK_WINDOW (window), NULL);
272 gtk_editable_set_position (GTK_EDITABLE (entry), 0);
274 priv->editing_status = FALSE;
279 mc_set_custom_state (EmpathyPresenceChooser *self)
281 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
282 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
284 /* update the status with MC */
285 const char *status = gtk_entry_get_text (GTK_ENTRY (entry));
286 DEBUG ("Sending state to MC-> %s (%s)\n",
287 g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
288 priv->state)->value_name,
290 empathy_idle_set_presence (priv->idle, priv->state, status);
294 ui_set_custom_state (EmpathyPresenceChooser *self,
298 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
299 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
300 const char *icon_name;
302 priv->block_set_editing++;
303 priv->block_changed++;
305 icon_name = empathy_icon_name_for_presence (state);
306 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
307 GTK_ENTRY_ICON_PRIMARY,
309 gtk_entry_set_text (GTK_ENTRY (entry), status);
311 priv->block_changed--;
312 priv->block_set_editing--;
316 entry_icon_release_cb (EmpathyPresenceChooser *self,
317 GtkEntryIconPosition icon_pos,
321 set_status_editing (self, FALSE);
322 mc_set_custom_state (self);
326 entry_activate_cb (EmpathyPresenceChooser *self,
329 set_status_editing (self, FALSE);
330 mc_set_custom_state (self);
334 entry_key_press_event_cb (EmpathyPresenceChooser *self,
338 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
340 if (priv->editing_status && event->keyval == GDK_Escape)
342 /* the user pressed Escape, undo the editing */
343 set_status_editing (self, FALSE);
344 presence_chooser_presence_changed_cb (self);
349 return FALSE; /* send this event elsewhere */
353 changed_cb (GtkComboBox *self, gpointer user_data)
355 EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
357 if (priv->block_changed) return;
363 GtkTreeModel *model = gtk_combo_box_get_model (self);
364 if (!gtk_combo_box_get_active_iter (self, &iter))
366 /* the combo is being edited to a custom entry */
367 if (!priv->editing_status)
369 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
374 gtk_tree_model_get (model, &iter,
375 COL_STATE_ICON_NAME, &icon_name,
376 COL_STATE, &priv->state,
380 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
382 if (type == ENTRY_TYPE_EDIT_CUSTOM)
384 /* recover the status that was unset because COL_STATUS_TEXT
385 * is "". Unfortunately if you try and set COL_STATUS_TEXT to
386 * NULL, it generates a g_critical. I wonder if there is a
387 * better way around this. */
388 const char *status = empathy_idle_get_status (priv->idle);
389 priv->block_set_editing++;
390 gtk_entry_set_text (GTK_ENTRY (entry), status);
391 priv->block_set_editing--;
393 /* attempt to get the toplevel for this widget */
394 GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
395 if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window))
400 presence_chooser_dialog_show (GTK_WINDOW (window));
402 else if (type == ENTRY_TYPE_CUSTOM)
404 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
405 GTK_ENTRY_ICON_PRIMARY,
408 /* preseed the status */
409 const char *status = empathy_idle_get_status (priv->idle);
410 priv->block_set_editing++;
411 gtk_entry_set_text (GTK_ENTRY (entry), status);
412 priv->block_set_editing--;
415 gtk_widget_grab_focus (entry);
417 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
422 /* just in case we were setting a new status when
423 * things were changed */
424 set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), FALSE);
426 gtk_tree_model_get (model, &iter,
427 COL_STATUS_TEXT, &status,
430 empathy_idle_set_presence (priv->idle, priv->state, status);
439 combo_row_separator_func (GtkTreeModel *model,
444 gtk_tree_model_get (model, iter,
448 return (type == ENTRY_TYPE_SEPARATOR);
452 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
454 EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
455 EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
457 chooser->priv = priv;
459 GtkTreeModel *model = create_model ();
461 gtk_combo_box_set_model (GTK_COMBO_BOX (chooser), GTK_TREE_MODEL (model));
462 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
464 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
465 combo_row_separator_func,
468 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
469 gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
470 GTK_ENTRY_ICON_PRIMARY, FALSE);
471 g_signal_connect_object (entry, "icon-release",
472 G_CALLBACK (entry_icon_release_cb), chooser,
474 g_signal_connect_object (entry, "activate",
475 G_CALLBACK (entry_activate_cb), chooser,
477 g_signal_connect_object (entry, "key-press-event",
478 G_CALLBACK (entry_key_press_event_cb), chooser,
480 // FIXME - should this also happen when the user presses TAB ?
482 GtkCellRenderer *renderer;
483 gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
485 renderer = gtk_cell_renderer_pixbuf_new ();
486 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
487 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
488 "icon-name", COL_STATE_ICON_NAME,
490 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
492 renderer = gtk_cell_renderer_text_new ();
493 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
494 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
495 "markup", COL_DISPLAY_MARKUP,
498 g_object_unref (model);
500 g_signal_connect (chooser, "notify::popup-shown",
501 G_CALLBACK (popup_shown_cb), NULL);
502 g_signal_connect (chooser, "changed",
503 G_CALLBACK (changed_cb), NULL);
504 g_signal_connect_swapped (entry, "changed",
505 G_CALLBACK (changed_cb), chooser);
507 priv->idle = empathy_idle_dup_singleton ();
508 presence_chooser_presence_changed_cb (chooser);
509 g_signal_connect_swapped (priv->idle, "notify",
510 G_CALLBACK (presence_chooser_presence_changed_cb),
513 g_object_set (chooser,
514 // FIXME: this string sucks
515 "tooltip-text", _("Set your presence and current status"),
520 presence_chooser_finalize (GObject *object)
522 EmpathyPresenceChooserPriv *priv;
524 priv = GET_PRIV (object);
526 if (priv->flash_timeout_id) {
527 g_source_remove (priv->flash_timeout_id);
530 g_signal_handlers_disconnect_by_func (priv->idle,
531 presence_chooser_presence_changed_cb,
533 g_object_unref (priv->idle);
535 G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
539 empathy_presence_chooser_new (void)
543 chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
549 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
551 EmpathyPresenceChooserPriv *priv;
553 McPresence flash_state;
556 priv = GET_PRIV (chooser);
558 priv->state = state = empathy_idle_get_state (priv->idle);
559 status = empathy_idle_get_status (priv->idle);
560 flash_state = empathy_idle_get_flash_state (priv->idle);
562 /* look through the model and attempt to find a matching state */
563 GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
565 gboolean valid, match_state = FALSE, match = FALSE;
566 for (valid = gtk_tree_model_get_iter_first (model, &iter);
568 valid = gtk_tree_model_iter_next (model, &iter))
574 gtk_tree_model_get (model, &iter,
579 if (m_type == ENTRY_TYPE_CUSTOM ||
580 m_type == ENTRY_TYPE_SEPARATOR ||
581 m_type == ENTRY_TYPE_EDIT_CUSTOM)
585 else if (!match_state && state == m_state)
587 /* we are now in the section that can contain our
591 else if (match_state && state != m_state)
593 /* we have passed the section that can contain our
598 gtk_tree_model_get (model, &iter,
599 COL_STATUS_TEXT, &m_status,
602 match = !strcmp (status, m_status);
612 priv->block_changed++;
613 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
614 priv->block_changed--;
618 // FIXME - do we insert the match into the menu?
619 ui_set_custom_state (chooser, state, status);
622 if (flash_state != MC_PRESENCE_UNSET) {
623 presence_chooser_flash_start (chooser, state, flash_state);
625 presence_chooser_flash_stop (chooser, state);
630 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
632 EmpathyPresenceChooserPriv *priv;
634 static gboolean on = FALSE;
636 priv = GET_PRIV (chooser);
639 state = priv->flash_state_1;
641 state = priv->flash_state_2;
644 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
645 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
646 GTK_ENTRY_ICON_PRIMARY,
647 empathy_icon_name_for_presence (state));
655 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
659 EmpathyPresenceChooserPriv *priv;
661 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
663 priv = GET_PRIV (chooser);
665 priv->flash_state_1 = state_1;
666 priv->flash_state_2 = state_2;
668 if (!priv->flash_timeout_id) {
669 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
670 (GSourceFunc) presence_chooser_flash_timeout_cb,
676 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
679 EmpathyPresenceChooserPriv *priv;
681 g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
683 priv = GET_PRIV (chooser);
685 if (priv->flash_timeout_id) {
686 g_source_remove (priv->flash_timeout_id);
687 priv->flash_timeout_id = 0;
689 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
691 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
692 GTK_ENTRY_ICON_PRIMARY,
693 empathy_icon_name_for_presence (state));
695 // FIXME - what does this do?
696 // priv->last_state = state;
700 empathy_presence_chooser_create_menu (void)
708 menu = gtk_menu_new ();
710 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
713 status = empathy_presence_get_default_message (states[i]);
714 presence_chooser_menu_add_item (menu,
719 /* Set custom messages if wanted */
720 list = empathy_status_presets_get (states[i], 5);
721 for (l = list; l; l = l->next) {
722 presence_chooser_menu_add_item (menu,
732 item = gtk_menu_item_new ();
733 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
734 gtk_widget_show (item);
736 /* Custom messages */
737 item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
738 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
739 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
740 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
741 gtk_widget_show (image);
742 gtk_widget_show (item);
744 g_signal_connect (item,
746 G_CALLBACK (presence_chooser_custom_activate_cb),
753 presence_chooser_menu_add_item (GtkWidget *menu,
759 const gchar *icon_name;
761 item = gtk_image_menu_item_new_with_label (str);
762 icon_name = empathy_icon_name_for_presence (state);
764 g_signal_connect (item, "activate",
765 G_CALLBACK (presence_chooser_noncustom_activate_cb),
768 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
769 gtk_widget_show (image);
771 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
772 gtk_widget_show (item);
774 g_object_set_data_full (G_OBJECT (item),
775 "status", g_strdup (str),
776 (GDestroyNotify) g_free);
778 g_object_set_data (G_OBJECT (item), "state", GINT_TO_POINTER (state));
780 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
784 presence_chooser_noncustom_activate_cb (GtkWidget *item,
790 status = g_object_get_data (G_OBJECT (item), "status");
791 state = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "state"));
793 presence_chooser_set_state (state, status);
797 presence_chooser_set_state (McPresence state,
802 idle = empathy_idle_dup_singleton ();
803 empathy_idle_set_presence (idle, state, status);
804 g_object_unref (idle);
808 presence_chooser_custom_activate_cb (GtkWidget *item,
811 presence_chooser_dialog_show (NULL);
815 presence_chooser_dialog_get_selected (CustomMessageDialog *dialog)
819 McPresence presence = LAST_MC_PRESENCE;
821 model = gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->combobox_status));
822 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->combobox_status), &iter)) {
823 gtk_tree_model_get (model, &iter,
824 COL_PRESENCE, &presence,
832 presence_chooser_dialog_status_changed_cb (GtkWidget *widget,
833 CustomMessageDialog *dialog)
837 McPresence presence = LAST_MC_PRESENCE;
840 presence = presence_chooser_dialog_get_selected (dialog);
842 store = gtk_list_store_new (1, G_TYPE_STRING);
843 messages = empathy_status_presets_get (presence, -1);
844 for (l = messages; l; l = l->next) {
845 gtk_list_store_append (store, &iter);
846 gtk_list_store_set (store, &iter, 0, l->data, -1);
849 gtk_entry_set_text (GTK_ENTRY (dialog->entry_message),
850 messages ? messages->data : "");
852 g_list_free (messages);
854 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->comboboxentry_message),
855 GTK_TREE_MODEL (store));
857 g_object_unref (store);
861 presence_chooser_dialog_message_changed_cb (GtkWidget *widget,
862 CustomMessageDialog *dialog)
867 gboolean found = FALSE;
869 presence = presence_chooser_dialog_get_selected (dialog);
870 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
872 messages = empathy_status_presets_get (presence, -1);
873 for (l = messages; l; l = l->next) {
874 if (!tp_strdiff (text, l->data)) {
879 g_list_free (messages);
881 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save),
886 presence_chooser_dialog_save_toggled_cb (GtkWidget *widget,
887 CustomMessageDialog *dialog)
893 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save));
894 state = presence_chooser_dialog_get_selected (dialog);
895 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
898 empathy_status_presets_set_last (state, text);
900 empathy_status_presets_remove (state, text);
905 presence_chooser_dialog_setup (CustomMessageDialog *dialog)
908 GtkCellRenderer *renderer;
912 store = gtk_list_store_new (COL_COUNT,
913 G_TYPE_STRING, /* Icon name */
914 G_TYPE_STRING, /* Label */
915 MC_TYPE_PRESENCE); /* Presence */
916 gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->combobox_status),
917 GTK_TREE_MODEL (store));
919 renderer = gtk_cell_renderer_pixbuf_new ();
920 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, FALSE);
921 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
922 "icon-name", COL_ICON,
924 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
926 renderer = gtk_cell_renderer_text_new ();
927 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dialog->combobox_status), renderer, TRUE);
928 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dialog->combobox_status), renderer,
932 for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
937 gtk_list_store_append (store, &iter);
938 gtk_list_store_set (store, &iter,
939 COL_ICON, empathy_icon_name_for_presence (states[i]),
940 COL_LABEL, empathy_presence_get_default_message (states[i]),
941 COL_PRESENCE, states[i],
945 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_status), 0);
949 presence_chooser_dialog_response_cb (GtkWidget *widget,
951 CustomMessageDialog *dialog)
953 if (response == GTK_RESPONSE_APPLY) {
957 state = presence_chooser_dialog_get_selected (dialog);
958 text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));
960 presence_chooser_set_state (state, text);
963 gtk_widget_destroy (widget);
967 presence_chooser_dialog_destroy_cb (GtkWidget *widget,
968 CustomMessageDialog *dialog)
972 message_dialog = NULL;
976 presence_chooser_dialog_show (GtkWindow *parent)
981 if (message_dialog) {
982 gtk_window_present (GTK_WINDOW (message_dialog->dialog));
986 message_dialog = g_new0 (CustomMessageDialog, 1);
988 filename = empathy_file_lookup ("empathy-presence-chooser.glade",
990 glade = empathy_glade_get_file (filename,
991 "custom_message_dialog",
993 "custom_message_dialog", &message_dialog->dialog,
994 "checkbutton_save", &message_dialog->checkbutton_save,
995 "comboboxentry_message", &message_dialog->comboboxentry_message,
996 "combobox_status", &message_dialog->combobox_status,
1000 empathy_glade_connect (glade,
1002 "custom_message_dialog", "destroy", presence_chooser_dialog_destroy_cb,
1003 "custom_message_dialog", "response", presence_chooser_dialog_response_cb,
1004 "combobox_status", "changed", presence_chooser_dialog_status_changed_cb,
1005 "checkbutton_save", "toggled", presence_chooser_dialog_save_toggled_cb,
1008 g_object_unref (glade);
1010 /* Setup the message combobox */
1011 message_dialog->entry_message = GTK_BIN (message_dialog->comboboxentry_message)->child;
1012 gtk_entry_set_activates_default (GTK_ENTRY (message_dialog->entry_message), TRUE);
1013 gtk_entry_set_width_chars (GTK_ENTRY (message_dialog->entry_message), 25);
1014 g_signal_connect (message_dialog->entry_message, "changed",
1015 G_CALLBACK (presence_chooser_dialog_message_changed_cb),
1018 presence_chooser_dialog_setup (message_dialog);
1020 gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0);
1024 gtk_window_set_transient_for (
1025 GTK_WINDOW (message_dialog->dialog),
1029 gtk_widget_show_all (message_dialog->dialog);