예제 #1
0
static void
presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
{
	EmpathyPresenceChooserPriv *priv;
	McPresence                 state;
	McPresence                 flash_state;
	const gchar               *status;

	priv = GET_PRIV (chooser);

	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);
	}
}
예제 #2
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;
}
예제 #3
0
static void
presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
{
	EmpathyPresenceChooserPriv *priv;
	TpConnectionPresenceType    state;
	TpConnectionPresenceType    flash_state;
	const gchar                *status;
	GtkTreeModel               *model;
	GtkTreeIter                 iter;
	gboolean valid, match_state = FALSE, match = FALSE;

	priv = GET_PRIV (chooser);

	if (priv->editing_status) {
		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);

	/* look through the model and attempt to find a matching state */
	model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
	for (valid = gtk_tree_model_get_iter_first (model, &iter);
	     valid;
	     valid = gtk_tree_model_iter_next (model, &iter)) {
		int m_type;
		TpConnectionPresenceType m_state;
		char *m_status;

		gtk_tree_model_get (model, &iter,
				COL_STATE, &m_state,
				COL_TYPE, &m_type,
				-1);

		if (m_type == ENTRY_TYPE_CUSTOM ||
		    m_type == ENTRY_TYPE_SEPARATOR ||
		    m_type == ENTRY_TYPE_EDIT_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;
		}

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

		match = !tp_strdiff (status, m_status);

		g_free (m_status);

		if (match) break;

	}

	if (match) {
		priv->block_changed++;
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
		presence_chooser_set_favorite_icon (chooser);
		priv->block_changed--;
	}
	else {
		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);
	}
}