* Authors: Richard Hult <richard@imendio.com>
* Martyn Russell <martyn@imendio.com>
* Xavier Claessens <xclaesse@gmail.com>
- * Davyd Madeley <davyd.madeley@collabora.co.uk>
+ * Danielle Madeley <danielle.madeley@collabora.co.uk>
*/
#include "config.h"
TpConnectionPresenceType state;
PresenceChooserEntryType previous_type;
- TpConnectionPresenceType flash_state_1;
- TpConnectionPresenceType flash_state_2;
- guint flash_timeout_id;
-
TpAccountManager *account_manager;
+ GdkPixbuf *not_favorite_pixbuf;
} EmpathyPresenceChooserPriv;
/* States to be listed in the menu.
{ TP_CONNECTION_PRESENCE_TYPE_UNSET, },
};
+static void presence_chooser_constructed (GObject *object);
static void presence_chooser_finalize (GObject *object);
static void presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser);
-static gboolean presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser);
-static void presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
- TpConnectionPresenceType state_1,
- TpConnectionPresenceType state_2);
-static void presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
- TpConnectionPresenceType state);
static void presence_chooser_menu_add_item (GtkWidget *menu,
const gchar *str,
TpConnectionPresenceType state);
static void presence_chooser_custom_activate_cb (GtkWidget *item,
gpointer user_data);
-G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
+G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX);
static void
empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = presence_chooser_constructed;
object_class->finalize = presence_chooser_finalize;
g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
G_TYPE_BOOLEAN, /* COL_STATUS_CUSTOMISABLE */
G_TYPE_INT); /* COL_TYPE */
- custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message..."));
+ custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message…"));
for (i = 0; states[i].state != TP_CONNECTION_PRESENCE_TYPE_UNSET; i++) {
GList *list, *l;
g_list_free (list);
gtk_list_store_insert_with_values (store, NULL, -1,
- COL_STATUS_TEXT, _("Custom Message..."),
+ COL_STATUS_TEXT, _("Custom Message…"),
COL_STATE_ICON_NAME, icon_name,
COL_STATE, states[i].state,
COL_DISPLAY_MARKUP, custom_message,
-1);
gtk_list_store_insert_with_values (store, NULL, -1,
- COL_STATUS_TEXT, _("Edit Custom Messages..."),
+ COL_STATUS_TEXT, _("Edit Custom Messages…"),
COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
- COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
+ COL_DISPLAY_MARKUP, _("Edit Custom Messages…"),
COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
-1);
return type;
}
+static TpConnectionPresenceType
+get_state_and_status (EmpathyPresenceChooser *self,
+ gchar **status)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+ TpConnectionPresenceType state;
+ gchar *tmp;
+
+ state = tp_account_manager_get_most_available_presence (
+ priv->account_manager, NULL, &tmp);
+ if (EMP_STR_EMPTY (tmp)) {
+ /* no message, use the default message */
+ g_free (tmp);
+ tmp = g_strdup (empathy_presence_get_default_message (state));
+ }
+
+ if (status != NULL)
+ *status = tmp;
+ else
+ g_free (tmp);
+
+ return state;
+}
+
static gboolean
presence_chooser_is_preset (EmpathyPresenceChooser *self)
{
- EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
TpConnectionPresenceType state;
- const char *status;
+ char *status;
GList *presets, *l;
gboolean match = FALSE;
- state = empathy_idle_get_state (priv->idle);
- status = empathy_idle_get_status (priv->idle);
+ state = get_state_and_status (self, &status);
presets = empathy_status_presets_get (state, -1);
for (l = presets; l; l = l->next) {
DEBUG ("is_preset(%i, %s) = %i", state, status, match);
+ g_free (status);
return match;
}
static void
presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
GtkWidget *entry;
PresenceChooserEntryType type;
/* saved entries can be removed from the list */
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
GTK_ENTRY_ICON_SECONDARY,
- "empathy-starred");
+ "emblem-favorite");
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
GTK_ENTRY_ICON_SECONDARY,
_("Click to remove this status as a favorite"));
}
- else {
+ else if (priv->not_favorite_pixbuf != NULL) {
/* custom entries can be favorited */
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry),
GTK_ENTRY_ICON_SECONDARY,
- "empathy-unstarred");
+ priv->not_favorite_pixbuf);
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
GTK_ENTRY_ICON_SECONDARY,
_("Click to make this status a favorite"));
/* attempt to get the toplevel for this widget */
window = gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window)) {
+ if (gtk_widget_is_toplevel (window) && GTK_IS_WINDOW (window)) {
/* unset the focus */
gtk_window_set_focus (GTK_WINDOW (window), NULL);
}
else {
PresenceChooserEntryType type;
TpConnectionPresenceType state;
- const char *status;
+ char *status;
type = presence_chooser_get_entry_type (self);
- state = empathy_idle_get_state (priv->idle);
- status = empathy_idle_get_status (priv->idle);
+ state = get_state_and_status (self, &status);
- if (!empathy_status_presets_is_valid (state))
+ if (!empathy_status_presets_is_valid (state)) {
/* It doesn't make sense to add such presence as favorite */
+ g_free (status);
return;
+ }
if (presence_chooser_is_preset (self)) {
/* remove the entry */
/* update the icon */
presence_chooser_set_favorite_icon (self);
+ g_free (status);
}
}
{
EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
- if (priv->editing_status && event->keyval == GDK_Escape) {
+ if (priv->editing_status && event->keyval == GDK_KEY_Escape) {
/* the user pressed Escape, undo the editing */
presence_chooser_reset_status (self);
return TRUE;
}
- else if (event->keyval == GDK_Up || event->keyval == GDK_Down) {
+ else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down) {
/* ignore */
return TRUE;
}
if (!priv->editing_status &&
event->button == 1 &&
- !GTK_WIDGET_HAS_FOCUS (entry)) {
+ !gtk_widget_has_focus (entry)) {
gtk_widget_grab_focus (entry);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
/* attempt to get the toplevel for this widget */
window = gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window)) {
+ if (!gtk_widget_is_toplevel (window) || !GTK_IS_WINDOW (window)) {
window = NULL;
}
} else {
/* else preseed the text of their currently entered
* status message */
- const char *status;
+ char *status;
- status = empathy_idle_get_status (priv->idle);
+ get_state_and_status (EMPATHY_PRESENCE_CHOOSER (self),
+ &status);
gtk_entry_set_text (GTK_ENTRY (entry), status);
+ g_free (status);
}
/* grab the focus */
sensitive = FALSE;
gtk_widget_set_sensitive (GTK_WIDGET (chooser), sensitive);
+
+ presence_chooser_presence_changed_cb (chooser);
}
static void
presence_chooser_update_sensitivity (chooser);
}
+/* Create a greyed version of the 'favorite' icon */
+static GdkPixbuf *
+create_not_favorite_pixbuf (void)
+{
+ GdkPixbuf *favorite, *result;
+
+ favorite = empathy_pixbuf_from_icon_name ("emblem-favorite",
+ GTK_ICON_SIZE_MENU);
+
+ if (favorite == NULL)
+ return NULL;
+
+ result = gdk_pixbuf_copy (favorite);
+ gdk_pixbuf_saturate_and_pixelate (favorite, result, 1.0, TRUE);
+
+ g_object_unref (favorite);
+ return result;
+}
+
+static void
+icon_theme_changed_cb (GtkIconTheme *icon_theme,
+ EmpathyPresenceChooser *self)
+{
+ EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+ /* Theme has changed, recreate the not-favorite icon */
+ if (priv->not_favorite_pixbuf != NULL)
+ g_object_unref (priv->not_favorite_pixbuf);
+ priv->not_favorite_pixbuf = create_not_favorite_pixbuf ();
+
+ /* Update the icon */
+ presence_chooser_set_favorite_icon (self);
+}
+
static void
empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
{
EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
+
+ chooser->priv = priv;
+
+ /* Create the not-favorite icon */
+ priv->not_favorite_pixbuf = create_not_favorite_pixbuf ();
+}
+
+static void
+presence_chooser_constructed (GObject *object)
+{
+ EmpathyPresenceChooser *chooser = EMPATHY_PRESENCE_CHOOSER (object);
+ EmpathyPresenceChooserPriv *priv = chooser->priv;
GtkWidget *entry;
GtkCellRenderer *renderer;
- chooser->priv = priv;
+ tp_g_signal_connect_object (gtk_icon_theme_get_default (), "changed",
+ G_CALLBACK (icon_theme_changed_cb),
+ chooser, 0);
presence_chooser_create_model (chooser);
- gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
+ gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (chooser),
COL_STATUS_TEXT);
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
combo_row_separator_func,
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
"markup", COL_DISPLAY_MARKUP,
NULL);
+ g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_signal_connect (chooser, "notify::popup-shown",
G_CALLBACK (presence_chooser_popup_shown_cb), NULL);
chooser);
priv->idle = empathy_idle_dup_singleton ();
- presence_chooser_presence_changed_cb (chooser);
- g_signal_connect_swapped (priv->idle, "notify::state",
- G_CALLBACK (presence_chooser_presence_changed_cb),
- chooser);
priv->account_manager = tp_account_manager_dup ();
+ g_signal_connect_swapped (priv->account_manager,
+ "most-available-presence-changed",
+ G_CALLBACK (presence_chooser_presence_changed_cb),
+ chooser);
- empathy_signal_connect_weak (priv->account_manager, "account-validity-changed",
+ tp_g_signal_connect_object (priv->account_manager, "account-validity-changed",
G_CALLBACK (presence_chooser_account_manager_account_validity_changed_cb),
- G_OBJECT (chooser));
- empathy_signal_connect_weak (priv->account_manager, "account-removed",
+ chooser, 0);
+ tp_g_signal_connect_object (priv->account_manager, "account-removed",
G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
- G_OBJECT (chooser));
- empathy_signal_connect_weak (priv->account_manager, "account-enabled",
+ chooser, 0);
+ tp_g_signal_connect_object (priv->account_manager, "account-enabled",
G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
- G_OBJECT (chooser));
- empathy_signal_connect_weak (priv->account_manager, "account-disabled",
+ chooser, 0);
+ tp_g_signal_connect_object (priv->account_manager, "account-disabled",
G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
- G_OBJECT (chooser));
+ chooser, 0);
/* FIXME: this string sucks */
gtk_widget_set_tooltip_text (GTK_WIDGET (chooser),
_("Set your presence and current status"));
priv->connectivity = empathy_connectivity_dup_singleton ();
- empathy_signal_connect_weak (priv->connectivity,
+ tp_g_signal_connect_object (priv->connectivity,
"state-change",
G_CALLBACK (presence_chooser_connectivity_state_change),
- G_OBJECT (chooser));
+ chooser, 0);
presence_chooser_update_sensitivity (chooser);
}
priv = GET_PRIV (object);
- if (priv->flash_timeout_id) {
- g_source_remove (priv->flash_timeout_id);
- }
-
if (priv->focus_out_idle_source) {
g_source_remove (priv->focus_out_idle_source);
}
g_object_unref (priv->idle);
g_object_unref (priv->connectivity);
+ if (priv->not_favorite_pixbuf != NULL)
+ g_object_unref (priv->not_favorite_pixbuf);
G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
}
GtkWidget *
empathy_presence_chooser_new (void)
{
- GtkWidget *chooser;
-
- chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
-
- return chooser;
+ /* FIXME, why can't this go in init ()? */
+ return g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER,
+ "has-entry", TRUE,
+ NULL);
}
static void
{
EmpathyPresenceChooserPriv *priv;
TpConnectionPresenceType state;
- TpConnectionPresenceType flash_state;
- const gchar *status;
+ gchar *status;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean valid, match_state = FALSE, match = FALSE;
return;
}
- 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);
+ state = get_state_and_status (chooser, &status);
+ priv->state = state;
/* An unset presence here doesn't make any sense. Force it to appear as
* offline. */
ui_set_custom_state (chooser, state, status);
}
- if (flash_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
- presence_chooser_flash_start (chooser, state, flash_state);
- }
- else {
- presence_chooser_flash_stop (chooser, state);
- }
+ 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));
entry = gtk_bin_get_child (GTK_BIN (chooser));
gtk_editable_set_editable (GTK_EDITABLE (entry),
state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
-}
-
-static gboolean
-presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
-{
- EmpathyPresenceChooserPriv *priv;
- TpConnectionPresenceType state;
- static gboolean on = FALSE;
- GtkWidget *entry;
-
- priv = GET_PRIV (chooser);
-
- if (on) {
- state = priv->flash_state_1;
- }
- else {
- state = priv->flash_state_2;
- }
-
- 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;
- return TRUE;
-}
-
-static void
-presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
- TpConnectionPresenceType state_1,
- TpConnectionPresenceType state_2)
-{
- EmpathyPresenceChooserPriv *priv;
-
- g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
-
- priv = GET_PRIV (chooser);
-
- priv->flash_state_1 = state_1;
- priv->flash_state_2 = state_2;
-
- if (!priv->flash_timeout_id) {
- priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
- (GSourceFunc) presence_chooser_flash_timeout_cb,
- chooser);
- }
-}
-
-static void
-presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
- TpConnectionPresenceType state)
-{
- EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
- GtkWidget *entry;
-
- if (priv->flash_timeout_id) {
- g_source_remove (priv->flash_timeout_id);
- priv->flash_timeout_id = 0;
- }
-
- 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));
+ g_free (status);
}
/**
gtk_widget_show (item);
/* Custom messages */
- item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
+ item = gtk_image_menu_item_new_with_label (_("Custom messages…"));
image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);