#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
+#include <gdk/gdkkeysyms.h>
#include <telepathy-glib/util.h>
#include <libmissioncontrol/mc-enum-types.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-status-presets.h>
+// FIXME - what's the correct debug flag?
+#define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
+#include <libempathy/empathy-debug.h>
+
#include "empathy-ui-utils.h"
#include "empathy-images.h"
#include "empathy-presence-chooser.h"
typedef struct {
EmpathyIdle *idle;
- GtkWidget *hbox;
- GtkWidget *image;
- GtkWidget *label;
- GtkWidget *menu;
+ gboolean editing_status;
+ int block_set_editing;
+ int block_changed;
- McPresence last_state;
+ McPresence state;
McPresence flash_state_1;
McPresence flash_state_2;
guint flash_timeout_id;
-
- /* The handle the kind of unnessecary scroll support. */
- guint scroll_timeout_id;
- McPresence scroll_state;
- gchar *scroll_status;
} EmpathyPresenceChooserPriv;
typedef struct {
COL_COUNT
};
-typedef struct {
- McPresence state;
- const gchar *status;
-} StateAndStatus;
-
static CustomMessageDialog *message_dialog = NULL;
/* States to be listed in the menu.
* Each state has a boolean telling if it can have custom message */
static void presence_chooser_finalize (GObject *object);
static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
-static void presence_chooser_reset_scroll_timeout (EmpathyPresenceChooser *chooser);
-static gboolean presence_chooser_scroll_timeout_cb (EmpathyPresenceChooser *chooser);
-static gboolean presence_chooser_scroll_event_cb (EmpathyPresenceChooser *chooser,
- GdkEventScroll *event,
- gpointer user_data);
-static GList * presence_chooser_get_presets (EmpathyPresenceChooser *chooser);
-static StateAndStatus *presence_chooser_state_and_status_new (McPresence state,
- const gchar *status);
static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
McPresence state_1,
McPresence state_2);
static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
McPresence state);
-static gboolean presence_chooser_button_press_event_cb (GtkWidget *chooser,
- GdkEventButton *event,
- gpointer user_data);
-static void presence_chooser_toggled_cb (GtkWidget *chooser,
- gpointer user_data);
-static void presence_chooser_menu_popup (EmpathyPresenceChooser *chooser);
-static void presence_chooser_menu_popdown (EmpathyPresenceChooser *chooser);
-static void presence_chooser_menu_selection_done_cb (GtkMenuShell *menushell,
- EmpathyPresenceChooser *chooser);
-static void presence_chooser_menu_destroy_cb (GtkWidget *menu,
- EmpathyPresenceChooser *chooser);
-static void presence_chooser_menu_detach (GtkWidget *attach_widget,
- GtkMenu *menu);
-static void presence_chooser_menu_align_func (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- GtkWidget *widget);
static void presence_chooser_menu_add_item (GtkWidget *menu,
const gchar *str,
McPresence state);
const gchar *status);
static void presence_chooser_custom_activate_cb (GtkWidget *item,
gpointer user_data);
-static void presence_chooser_dialog_show (void);
+static void presence_chooser_dialog_show (GtkWindow *parent);
-G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_TOGGLE_BUTTON);
+G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
static void
empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
}
+enum
+{
+ COL_STATE_ICON_NAME,
+ COL_STATE,
+ COL_STATUS_TEXT,
+ COL_DISPLAY_MARKUP,
+ COL_TYPE,
+ N_COLUMNS
+};
+
+enum
+{
+ ENTRY_TYPE_BUILTIN,
+ ENTRY_TYPE_SAVED,
+ ENTRY_TYPE_CUSTOM,
+};
+
+static GtkTreeModel *
+create_model (void)
+{
+ GtkListStore *store = gtk_list_store_new (N_COLUMNS,
+ G_TYPE_STRING, /* COL_STATE_ICON_NAME */
+ MC_TYPE_PRESENCE, /* COL_STATE */
+ G_TYPE_STRING, /* COL_STATUS_TEXT */
+ G_TYPE_STRING, /* COL_DISPLAY_MARKUP */
+ G_TYPE_INT); /* COL_TYPE */
+
+ GtkTreeIter iter;
+
+ int i;
+ for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
+ GList *list, *l;
+
+ const char *status = empathy_presence_get_default_message (states[i]);
+ const char *icon_name = empathy_icon_name_for_presence (states[i]);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_STATE_ICON_NAME, icon_name,
+ COL_STATE, states[i],
+ COL_STATUS_TEXT, status,
+ COL_DISPLAY_MARKUP, status,
+ COL_TYPE, ENTRY_TYPE_BUILTIN,
+ -1);
+
+ if (states[i+1]) {
+ /* Set custom messages if wanted */
+ list = empathy_status_presets_get (states[i], 5);
+ for (l = list; l; l = l->next) {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_STATE_ICON_NAME, icon_name,
+ COL_STATE, states[i],
+ COL_STATUS_TEXT, l->data,
+ COL_DISPLAY_MARKUP, l->data,
+ COL_TYPE, ENTRY_TYPE_SAVED,
+ -1);
+ }
+ g_list_free (list);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_STATE_ICON_NAME, icon_name,
+ COL_STATE, states[i],
+ COL_STATUS_TEXT, "",
+ COL_DISPLAY_MARKUP, "<i>Custom Message...</i>",
+ COL_TYPE, ENTRY_TYPE_CUSTOM,
+ -1);
+ }
+
+ }
+
+ return GTK_TREE_MODEL (store);
+}
+
+static void
+popup_shown_cb (GObject *self, GParamSpec *pspec, gpointer user_data)
+{
+ gboolean shown;
+ g_object_get (self, "popup-shown", &shown, NULL);
+
+ if (!shown) return;
+
+ GtkTreeModel *model = create_model ();
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (model));
+
+ g_object_unref (model);
+}
+
+static void
+set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+
+ if (priv->block_set_editing) return;
+
+ if (editing)
+ {
+ priv->editing_status = TRUE;
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ GTK_STOCK_OK);
+ gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ _("Set status"));
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ FALSE);
+ }
+ else
+ {
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ NULL);
+ gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ NULL);
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ TRUE);
+
+ // FIXME - move the focus somewhere
+
+ priv->editing_status = FALSE;
+ }
+}
+
+static void
+mc_set_custom_state (EmpathyPresenceChooser *self)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+
+ /* update the status with MC */
+ const char *status = gtk_entry_get_text (GTK_ENTRY (entry));
+ DEBUG ("Sending state to MC-> %s (%s)\n",
+ g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
+ priv->state)->value_name,
+ status);
+ empathy_idle_set_presence (priv->idle, priv->state, status);
+}
+
+static void
+ui_set_custom_state (EmpathyPresenceChooser *self,
+ McPresence state,
+ const char *status)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+ const char *icon_name;
+
+ priv->block_set_editing++;
+ priv->block_changed++;
+
+ icon_name = empathy_icon_name_for_presence (state);
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ icon_name);
+ gtk_entry_set_text (GTK_ENTRY (entry), status);
+
+ priv->block_changed--;
+ priv->block_set_editing--;
+}
+
+static void
+entry_icon_release_cb (EmpathyPresenceChooser *self,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
+ GtkEntry *entry)
+{
+ set_status_editing (self, FALSE);
+ mc_set_custom_state (self);
+}
+
+static void
+entry_activate_cb (EmpathyPresenceChooser *self,
+ GtkEntry *entry)
+{
+ set_status_editing (self, FALSE);
+ mc_set_custom_state (self);
+}
+
+static gboolean
+entry_key_press_event_cb (EmpathyPresenceChooser *self,
+ GdkEventKey *event,
+ GtkWidget *entry)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+ if (priv->editing_status && event->keyval == GDK_Escape)
+ {
+ /* the user pressed Escape, undo the editing */
+ set_status_editing (self, FALSE);
+ presence_chooser_presence_changed_cb (self);
+
+ return TRUE;
+ }
+
+ return FALSE; /* send this event elsewhere */
+}
+
+static void
+changed_cb (GtkComboBox *self, gpointer user_data)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+ if (priv->block_changed) return;
+
+ GtkTreeIter iter;
+ char *icon_name;
+ int type = -1;
+
+ GtkTreeModel *model = gtk_combo_box_get_model (self);
+ if (!gtk_combo_box_get_active_iter (self, &iter))
+ {
+ /* the combo is being edited to a custom entry */
+ if (!priv->editing_status)
+ {
+ set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
+ }
+ return;
+ }
+
+ gtk_tree_model_get (model, &iter,
+ COL_STATE_ICON_NAME, &icon_name,
+ COL_STATE, &priv->state,
+ COL_TYPE, &type,
+ -1);
+
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ icon_name);
+
+ if (type == ENTRY_TYPE_CUSTOM)
+ {
+ /* grab the focus */
+ gtk_widget_grab_focus (entry);
+ set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
+ }
+ else
+ {
+ char *status;
+ /* just in case we were setting a new status when
+ * things were changed */
+ set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), FALSE);
+
+ gtk_tree_model_get (model, &iter,
+ COL_STATUS_TEXT, &status,
+ -1);
+
+ empathy_idle_set_presence (priv->idle, priv->state, status);
+
+ g_free (status);
+ }
+
+ g_free (icon_name);
+}
+
static void
empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
{
- GtkWidget *arrow;
- GtkWidget *alignment;
EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
chooser->priv = priv;
- gtk_button_set_relief (GTK_BUTTON (chooser), GTK_RELIEF_NONE);
- gtk_button_set_focus_on_click (GTK_BUTTON (chooser), FALSE);
-
- alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
- gtk_widget_show (alignment);
- gtk_container_add (GTK_CONTAINER (chooser), alignment);
- gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 1, 0);
-
- priv->hbox = gtk_hbox_new (FALSE, 1);
- gtk_widget_show (priv->hbox);
- gtk_container_add (GTK_CONTAINER (alignment), priv->hbox);
-
- priv->image = gtk_image_new ();
- gtk_widget_show (priv->image);
- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->image, FALSE, TRUE, 0);
-
- priv->label = gtk_label_new (NULL);
- gtk_widget_show (priv->label);
- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label, TRUE, TRUE, 0);
- gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
- gtk_misc_set_alignment (GTK_MISC (priv->label), 0, 0.5);
- gtk_misc_set_padding (GTK_MISC (priv->label), 4, 1);
-
- alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
- gtk_widget_show (alignment);
- gtk_box_pack_start (GTK_BOX (priv->hbox), alignment, FALSE, FALSE, 0);
-
- arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
- gtk_widget_show (arrow);
- gtk_container_add (GTK_CONTAINER (alignment), arrow);
-
- g_signal_connect (chooser, "toggled",
- G_CALLBACK (presence_chooser_toggled_cb),
- NULL);
- g_signal_connect (chooser, "button-press-event",
- G_CALLBACK (presence_chooser_button_press_event_cb),
- NULL);
- g_signal_connect (chooser, "scroll-event",
- G_CALLBACK (presence_chooser_scroll_event_cb),
- NULL);
+
+ GtkTreeModel *model = create_model ();
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (chooser), GTK_TREE_MODEL (model));
+ gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser), COL_STATUS_TEXT);
+
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
+ gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY, FALSE);
+ g_signal_connect_object (entry, "icon-release",
+ G_CALLBACK (entry_icon_release_cb), chooser,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (entry, "activate",
+ G_CALLBACK (entry_activate_cb), chooser,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (entry, "key-press-event",
+ G_CALLBACK (entry_key_press_event_cb), chooser,
+ G_CONNECT_SWAPPED);
+ // FIXME - should this also happen when the user presses TAB ?
+
+ GtkCellRenderer *renderer;
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
+ "icon-name", COL_STATE_ICON_NAME,
+ NULL);
+ g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
+ "markup", COL_DISPLAY_MARKUP,
+ NULL);
+
+ g_object_unref (model);
+
+ g_signal_connect (chooser, "notify::popup-shown",
+ G_CALLBACK (popup_shown_cb), NULL);
+ g_signal_connect (chooser, "changed",
+ G_CALLBACK (changed_cb), NULL);
priv->idle = empathy_idle_dup_singleton ();
presence_chooser_presence_changed_cb (chooser);
g_signal_connect_swapped (priv->idle, "notify",
G_CALLBACK (presence_chooser_presence_changed_cb),
chooser);
+
+ g_object_set (chooser,
+ // FIXME: this string sucks
+ "tooltip-text", _("Set your presence and current status"),
+ NULL);
}
static void
g_source_remove (priv->flash_timeout_id);
}
- if (priv->scroll_timeout_id) {
- g_source_remove (priv->scroll_timeout_id);
- }
-
g_signal_handlers_disconnect_by_func (priv->idle,
presence_chooser_presence_changed_cb,
object);
priv = GET_PRIV (chooser);
- state = empathy_idle_get_state (priv->idle);
+ priv->state = state = empathy_idle_get_state (priv->idle);
status = empathy_idle_get_status (priv->idle);
flash_state = empathy_idle_get_flash_state (priv->idle);
- presence_chooser_reset_scroll_timeout (chooser);
- gtk_label_set_text (GTK_LABEL (priv->label), status);
-
- if (flash_state != MC_PRESENCE_UNSET) {
- presence_chooser_flash_start (chooser, state, flash_state);
- } else {
- presence_chooser_flash_stop (chooser, state);
- }
-}
-
-static void
-presence_chooser_reset_scroll_timeout (EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
-
- priv = GET_PRIV (chooser);
-
- if (priv->scroll_timeout_id) {
- g_source_remove (priv->scroll_timeout_id);
- priv->scroll_timeout_id = 0;
- }
-
- g_free (priv->scroll_status);
- priv->scroll_status = NULL;
-}
+ /* look through the model and attempt to find a matching state */
+ GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
+ GtkTreeIter iter;
+ gboolean valid, match_state = FALSE, match = FALSE;
+ for (valid = gtk_tree_model_get_iter_first (model, &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (model, &iter))
+ {
+ int m_type;
+ McPresence m_state;
+ char *m_status;
-static gboolean
-presence_chooser_scroll_timeout_cb (EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
-
- priv = GET_PRIV (chooser);
-
- priv->scroll_timeout_id = 0;
-
- empathy_idle_set_presence (priv->idle,
- priv->scroll_state,
- priv->scroll_status);
-
- g_free (priv->scroll_status);
- priv->scroll_status = NULL;
-
- return FALSE;
-}
-
-static gboolean
-presence_chooser_scroll_event_cb (EmpathyPresenceChooser *chooser,
- GdkEventScroll *event,
- gpointer user_data)
-{
- EmpathyPresenceChooserPriv *priv;
- GList *list, *l;
- const gchar *current_status;
- StateAndStatus *sas;
- gboolean match;
-
- priv = GET_PRIV (chooser);
-
- switch (event->direction) {
- case GDK_SCROLL_UP:
- break;
- case GDK_SCROLL_DOWN:
- break;
- default:
- return FALSE;
- }
+ gtk_tree_model_get (model, &iter,
+ COL_STATE, &m_state,
+ COL_TYPE, &m_type,
+ -1);
- current_status = gtk_label_get_text (GTK_LABEL (priv->label));
-
- /* Get the list of presets, which in this context means all the items
- * without a trailing "...".
- */
- list = presence_chooser_get_presets (chooser);
- sas = NULL;
- match = FALSE;
- for (l = list; l; l = l->next) {
- sas = l->data;
-
- if (sas->state == priv->last_state &&
- strcmp (sas->status, current_status) == 0) {
- sas = NULL;
- match = TRUE;
- if (event->direction == GDK_SCROLL_UP) {
- if (l->prev) {
- sas = l->prev->data;
- }
- }
- else if (event->direction == GDK_SCROLL_DOWN) {
- if (l->next) {
- sas = l->next->data;
- }
- }
+ if (m_type == ENTRY_TYPE_CUSTOM)
+ {
+ continue;
+ }
+ else if (!match_state && state == m_state)
+ {
+ /* we are now in the section that can contain our
+ * match */
+ match_state = TRUE;
+ }
+ else if (match_state && state != m_state)
+ {
+ /* we have passed the section that can contain our
+ * match */
break;
}
- sas = NULL;
- }
+ gtk_tree_model_get (model, &iter,
+ COL_STATUS_TEXT, &m_status,
+ -1);
- if (sas) {
- presence_chooser_reset_scroll_timeout (chooser);
+ match = !strcmp (status, m_status);
- priv->scroll_status = g_strdup (sas->status);
- priv->scroll_state = sas->state;
+ g_free (m_status);
- priv->scroll_timeout_id =
- g_timeout_add_seconds (1,
- (GSourceFunc) presence_chooser_scroll_timeout_cb,
- chooser);
+ if (match) break;
- presence_chooser_flash_stop (chooser, sas->state);
- gtk_label_set_text (GTK_LABEL (priv->label), sas->status);
}
- else if (!match) {
- const gchar *status;
- /* If we didn't get any match at all, it means the last state
- * was a custom one. Just switch to the first one.
- */
- status = empathy_presence_get_default_message (states[0]);
-
- presence_chooser_reset_scroll_timeout (chooser);
- empathy_idle_set_presence (priv->idle, states[0], status);
- }
-
- g_list_foreach (list, (GFunc) g_free, NULL);
- g_list_free (list);
-
- return TRUE;
-}
-
-static GList *
-presence_chooser_get_presets (EmpathyPresenceChooser *chooser)
-{
- GList *list = NULL;
- guint i;
-
- for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
- GList *presets, *p;
- StateAndStatus *sas;
- const gchar *status;
-
- status = empathy_presence_get_default_message (states[i]);
- sas = presence_chooser_state_and_status_new (states[i], status);
- list = g_list_prepend (list, sas);
-
- /* Go to next state if we don't want messages for that state */
- if (!states[i+1]) {
- continue;
- }
- presets = empathy_status_presets_get (states[i], 5);
- for (p = presets; p; p = p->next) {
- sas = presence_chooser_state_and_status_new (states[i], p->data);
- list = g_list_prepend (list, sas);
- }
- g_list_free (presets);
+ if (match)
+ {
+ priv->block_changed++;
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
+ priv->block_changed--;
+ }
+ else
+ {
+ // FIXME - do we insert the match into the menu?
+ ui_set_custom_state (chooser, state, status);
}
- list = g_list_reverse (list);
-
- return list;
-}
-
-static StateAndStatus *
-presence_chooser_state_and_status_new (McPresence state,
- const gchar *status)
-{
- StateAndStatus *sas;
-
- sas = g_new0 (StateAndStatus, 1);
-
- sas->state = state;
- sas->status = status;
- return sas;
+ if (flash_state != MC_PRESENCE_UNSET) {
+ presence_chooser_flash_start (chooser, state, flash_state);
+ } else {
+ presence_chooser_flash_stop (chooser, state);
+ }
}
static gboolean
state = priv->flash_state_2;
}
- gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
- empathy_icon_name_for_presence (state),
- GTK_ICON_SIZE_MENU);
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ empathy_icon_name_for_presence (state));
on = !on;
g_source_remove (priv->flash_timeout_id);
priv->flash_timeout_id = 0;
}
+ GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
+
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_PRIMARY,
+ empathy_icon_name_for_presence (state));
- gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
- empathy_icon_name_for_presence (state),
- GTK_ICON_SIZE_MENU);
-
- priv->last_state = state;
-}
-
-static gboolean
-presence_chooser_button_press_event_cb (GtkWidget *chooser,
- GdkEventButton *event,
- gpointer user_data)
-{
- if (event->button != 1 || event->type != GDK_BUTTON_PRESS) {
- return FALSE;
- }
-
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chooser))) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chooser), TRUE);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-presence_chooser_toggled_cb (GtkWidget *chooser,
- gpointer user_data)
-{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chooser))) {
- presence_chooser_menu_popup (EMPATHY_PRESENCE_CHOOSER (chooser));
- } else {
- presence_chooser_menu_popdown (EMPATHY_PRESENCE_CHOOSER (chooser));
- }
-}
-
-static void
-presence_chooser_menu_popup (EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
- GtkWidget *menu;
-
- priv = GET_PRIV (chooser);
-
- if (priv->menu) {
- return;
- }
-
- menu = empathy_presence_chooser_create_menu ();
-
- g_signal_connect_after (menu, "selection-done",
- G_CALLBACK (presence_chooser_menu_selection_done_cb),
- chooser);
-
- g_signal_connect (menu, "destroy",
- G_CALLBACK (presence_chooser_menu_destroy_cb),
- chooser);
-
- gtk_menu_attach_to_widget (GTK_MENU (menu),
- GTK_WIDGET (chooser),
- presence_chooser_menu_detach);
-
- gtk_menu_popup (GTK_MENU (menu),
- NULL, NULL,
- (GtkMenuPositionFunc) presence_chooser_menu_align_func,
- chooser,
- 1,
- gtk_get_current_event_time ());
-
- priv->menu = menu;
-}
-
-static void
-presence_chooser_menu_popdown (EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
-
- priv = GET_PRIV (chooser);
-
- if (priv->menu) {
- gtk_widget_destroy (priv->menu);
- }
-}
-
-static void
-presence_chooser_menu_selection_done_cb (GtkMenuShell *menushell,
- EmpathyPresenceChooser *chooser)
-{
- gtk_widget_destroy (GTK_WIDGET (menushell));
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chooser), FALSE);
-}
-
-static void
-presence_chooser_menu_destroy_cb (GtkWidget *menu,
- EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
-
- priv = GET_PRIV (chooser);
-
- priv->menu = NULL;
-}
-
-static void
-presence_chooser_menu_detach (GtkWidget *attach_widget,
- GtkMenu *menu)
-{
- /* We don't need to do anything, but attaching the menu means
- * we don't own the ref count and it is cleaned up properly.
- */
-}
-
-static void
-presence_chooser_menu_align_func (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- GtkWidget *widget)
-{
- GtkRequisition req;
- GdkScreen *screen;
- gint screen_height;
-
- gtk_widget_size_request (GTK_WIDGET (menu), &req);
-
- gdk_window_get_origin (widget->window, x, y);
-
- *x += widget->allocation.x + 1;
- *y += widget->allocation.y;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (menu));
- screen_height = gdk_screen_get_height (screen);
-
- if (req.height > screen_height) {
- /* Too big for screen height anyway. */
- *y = 0;
- return;
- }
-
- if ((*y + req.height + widget->allocation.height) > screen_height) {
- /* Can't put it below the button. */
- *y -= req.height;
- *y += 1;
- } else {
- /* Put menu below button. */
- *y += widget->allocation.height;
- *y -= 1;
- }
-
- *push_in = FALSE;
+ // FIXME - what does this do?
+ // priv->last_state = state;
}
GtkWidget *
presence_chooser_custom_activate_cb (GtkWidget *item,
gpointer user_data)
{
- presence_chooser_dialog_show ();
+ presence_chooser_dialog_show (NULL);
}
static McPresence
}
static void
-presence_chooser_dialog_show (void)
+presence_chooser_dialog_show (GtkWindow *parent)
{
GladeXML *glade;
gchar *filename;
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0);
- /* FIXME: Set transian for a window ? */
+ if (parent)
+ {
+ gtk_window_set_transient_for (
+ GTK_WINDOW (message_dialog->dialog),
+ parent);
+ }
gtk_widget_show_all (message_dialog->dialog);
}