Esempio n. 1
0
static void
idle_state_change_cb (EmpathyConnectivity *connectivity,
		      gboolean new_online,
		      EmpathyIdle *idle)
{
	EmpathyIdlePriv *priv;

	priv = GET_PRIV (idle);

	if (!new_online) {
		/* We are no longer connected */
		DEBUG ("Disconnected: Save state %d (%s)",
				priv->state, priv->status);
		priv->saved_state = priv->state;
		g_free (priv->saved_status);
		priv->saved_status = g_strdup (priv->status);
		empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
	}
	else if (new_online
			&& priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
		/* We are now connected */
		DEBUG ("Reconnected: Restore state %d (%s)",
				priv->saved_state, priv->saved_status);
		empathy_idle_set_presence (idle,
				priv->saved_state,
				priv->saved_status);
		priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
		g_free (priv->saved_status);
		priv->saved_status = NULL;
	}
}
Esempio n. 2
0
static void
presence_chooser_set_state (McPresence   state,
			    const gchar *status)
{
	EmpathyIdle *idle;

	idle = empathy_idle_dup_singleton ();
	empathy_idle_set_presence (idle, state, status);
	g_object_unref (idle);
}
Esempio n. 3
0
void
empathy_idle_set_status (EmpathyIdle *idle,
			 const gchar *status)
{
	EmpathyIdlePriv *priv;

	priv = GET_PRIV (idle);

	empathy_idle_set_presence (idle, priv->state, status);
}
Esempio n. 4
0
void
empathy_idle_set_state (EmpathyIdle *idle,
			TpConnectionPresenceType   state)
{
	EmpathyIdlePriv *priv;

	priv = GET_PRIV (idle);

	empathy_idle_set_presence (idle, state, priv->status);
}
Esempio n. 5
0
static void
mc_set_custom_state (EmpathyPresenceChooser *self)
{
	EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
	GtkWidget *entry;
	const char *status;

	entry = gtk_bin_get_child (GTK_BIN (self));
	/* update the status with MC */
	status = gtk_entry_get_text (GTK_ENTRY (entry));

	DEBUG ("Sending state to MC-> %d (%s)\n", priv->state, status);

	empathy_idle_set_presence (priv->idle, priv->state, status);
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
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;
	}

	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;
				}
			}
			break;
		}

		sas = NULL;
	}

	if (sas) {
		presence_chooser_reset_scroll_timeout (chooser);

		priv->scroll_status = g_strdup (sas->status);
		priv->scroll_state = sas->state;

		priv->scroll_timeout_id =
			g_timeout_add_seconds (1,
					       (GSourceFunc) presence_chooser_scroll_timeout_cb,
					       chooser);

		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;
}
Esempio n. 8
0
static void
idle_session_status_changed_cb (DBusGProxy    *gs_proxy,
				SessionStatus  status,
				EmpathyIdle   *idle)
{
	EmpathyIdlePriv *priv;
	gboolean is_idle;

	priv = GET_PRIV (idle);

	is_idle = (status == SESSION_STATUS_IDLE);

	DEBUG ("Session idle state changed, %s -> %s",
		priv->is_idle ? "yes" : "no",
		is_idle ? "yes" : "no");

	if (!priv->auto_away ||
	    (priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
	     (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
	      priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
		/* We don't want to go auto away OR we explicitely asked to be
		 * offline, nothing to do here */
		priv->is_idle = is_idle;
		return;
	}

	if (is_idle && !priv->is_idle) {
		TpConnectionPresenceType new_state;
		/* We are now idle */

		idle_ext_away_start (idle);

		if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
		    	/* We are disconnected, when coming back from away
		    	 * we want to restore the presence before the
		    	 * disconnection. */
			priv->away_saved_state = priv->saved_state;
		} else {
			priv->away_saved_state = priv->state;
		}

		new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
		if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
			new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
		}

		DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
			priv->away_saved_state, new_state);
		empathy_idle_set_state (idle, new_state);
	} else if (!is_idle && priv->is_idle) {
		const gchar *new_status;
		/* We are no more idle, restore state */

		idle_ext_away_stop (idle);

		if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
		    priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
			priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
			new_status = NULL;
		} else {
			new_status = priv->status;
		}

		/* Only try and set the presence if the away saved state is not
		 * unset. This is an odd case because it means that the session
		 * didn't notify us of the state change to idle, and as a
		 * result, we couldn't save the current state at that time.
		 */
		if (priv->away_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
			DEBUG ("Restoring state to %d, reset status to %s",
				priv->away_saved_state, new_status);

			empathy_idle_set_presence (idle,
						   priv->away_saved_state,
						   new_status);
		} else {
			DEBUG ("Away saved state is unset. This means that we "
			       "weren't told when the session went idle. "
			       "As a result, I'm not trying to set presence");
		}

		priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
	}

	priv->is_idle = is_idle;
}
Esempio n. 9
0
static void
presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
{
	EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
	GtkTreeIter iter;
	char *icon_name;
	TpConnectionPresenceType new_state;
	gboolean customisable = TRUE;
	PresenceChooserEntryType type = -1;
	GtkWidget *entry;
	GtkTreeModel *model;

	if (priv->block_changed ||
	    !gtk_combo_box_get_active_iter (self, &iter)) {
		return;
	}

	model = gtk_combo_box_get_model (self);
	gtk_tree_model_get (model, &iter,
			    COL_STATE_ICON_NAME, &icon_name,
			    COL_STATE, &new_state,
			    COL_STATUS_CUSTOMISABLE, &customisable,
			    COL_TYPE, &type,
			    -1);

	entry = gtk_bin_get_child (GTK_BIN (self));

	/* some types of status aren't editable, set the editability of the
	 * entry appropriately. Unless we're just about to reset it anyway,
	 * in which case, don't fiddle with it */
	if (type != ENTRY_TYPE_EDIT_CUSTOM) {
		gtk_editable_set_editable (GTK_EDITABLE (entry), customisable);
		priv->state = new_state;
	}

	if (type == ENTRY_TYPE_EDIT_CUSTOM) {
		GtkWidget *window, *dialog;

		presence_chooser_reset_status (EMPATHY_PRESENCE_CHOOSER (self));

		/* 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)) {
			window = NULL;
		}

		dialog = empathy_status_preset_dialog_new (GTK_WINDOW (window));
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
	}
	else if (type == ENTRY_TYPE_CUSTOM) {
		gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
						   GTK_ENTRY_ICON_PRIMARY,
						   icon_name);

		/* preseed the status */
		if (priv->previous_type == ENTRY_TYPE_BUILTIN) {
			/* if their previous entry was a builtin, don't
			 * preseed */
			gtk_entry_set_text (GTK_ENTRY (entry), "");
		} else {
			/* else preseed the text of their currently entered
			 * status message */
			const char *status;

			status = empathy_idle_get_status (priv->idle);
			gtk_entry_set_text (GTK_ENTRY (entry), status);
		}

		/* grab the focus */
		gtk_widget_grab_focus (entry);
	} else {
		char *status;

		/* just in case we were setting a new status when
		 * things were changed */
		presence_chooser_set_status_editing (
			EMPATHY_PRESENCE_CHOOSER (self),
			FALSE);
		gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
					   GTK_ENTRY_ICON_PRIMARY,
					   icon_name);

		gtk_tree_model_get (model, &iter,
				    COL_STATUS_TEXT, &status,
				    -1);

		empathy_idle_set_presence (priv->idle, priv->state, status);

		g_free (status);
	}

	if (type != ENTRY_TYPE_EDIT_CUSTOM) {
		priv->previous_type = type;
	}
	g_free (icon_name);
}