Ejemplo n.º 1
0
static void
presence_chooser_dialog_status_changed_cb (GtkWidget           *widget,
					   CustomMessageDialog *dialog)
{
	GtkListStore *store;
	GtkTreeIter   iter;
	McPresence    presence = LAST_MC_PRESENCE;
	GList        *messages, *l;

	presence = presence_chooser_dialog_get_selected (dialog);

	store = gtk_list_store_new (1, G_TYPE_STRING);
	messages = empathy_status_presets_get (presence, -1);
	for (l = messages; l; l = l->next) {
		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter, 0, l->data, -1);
	}

	gtk_entry_set_text (GTK_ENTRY (dialog->entry_message),
			    messages ? messages->data : "");

	g_list_free (messages);

	gtk_combo_box_set_model (GTK_COMBO_BOX (dialog->comboboxentry_message),
				 GTK_TREE_MODEL (store));

	g_object_unref (store);
}
Ejemplo n.º 2
0
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);
	}
	list = g_list_reverse (list);

	return list;
}
Ejemplo n.º 3
0
static gboolean
presence_chooser_is_preset (EmpathyPresenceChooser *self)
{
	EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
	TpConnectionPresenceType state;
	const char *status;
	GList *presets, *l;
	gboolean match = FALSE;

	state = empathy_idle_get_state (priv->idle);
	status = empathy_idle_get_status (priv->idle);

	presets = empathy_status_presets_get (state, -1);
	for (l = presets; l; l = l->next) {
		char *preset = (char *) l->data;

		if (!strcmp (status, preset)) {
			match = TRUE;
			break;
		}
	}

	g_list_free (presets);

	DEBUG ("is_preset(%i, %s) = %i\n", state, status, match);

	return match;
}
Ejemplo n.º 4
0
GtkWidget *
empathy_presence_chooser_create_menu (void)
{
	const gchar *status;
	GtkWidget   *menu;
	GtkWidget   *item;
	GtkWidget   *image;
	guint        i;

	menu = gtk_menu_new ();

	for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
		GList       *list, *l;

		status = empathy_presence_get_default_message (states[i]);
		presence_chooser_menu_add_item (menu,
						status,
						states[i]);

		if (states[i+1]) {
			/* Set custom messages if wanted */
			list = empathy_status_presets_get (states[i], 5);
			for (l = list; l; l = l->next) {
				presence_chooser_menu_add_item (menu,
								l->data,
								states[i]);
			}
			g_list_free (list);
		}

	}

	/* Separator. */
	item = gtk_menu_item_new ();
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
	gtk_widget_show (item);

	/* 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);
	gtk_widget_show (image);
	gtk_widget_show (item);

	g_signal_connect (item,
			  "activate",
			  G_CALLBACK (presence_chooser_custom_activate_cb),
			  NULL);

	return menu;
}
Ejemplo n.º 5
0
static void
presence_chooser_dialog_message_changed_cb (GtkWidget           *widget,
					    CustomMessageDialog *dialog)
{
	McPresence   presence;
	GList       *messages, *l;
	const gchar *text;
	gboolean     found = FALSE;

	presence = presence_chooser_dialog_get_selected (dialog);
	text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_message));

	messages = empathy_status_presets_get (presence, -1);
	for (l = messages; l; l = l->next) {
		if (!tp_strdiff (text, l->data)) {
			found = TRUE;
			break;
		}
	}
	g_list_free (messages);

	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_save),
				      found);
}
Ejemplo n.º 6
0
static void
presence_chooser_create_model (EmpathyPresenceChooser *self)
{
	GtkListStore *store;
	char *custom_message;
	int i;

	store = gtk_list_store_new (N_COLUMNS,
				    G_TYPE_STRING,    /* COL_STATE_ICON_NAME */
				    G_TYPE_UINT,      /* COL_STATE */
				    G_TYPE_STRING,    /* COL_STATUS_TEXT */
				    G_TYPE_STRING,    /* COL_DISPLAY_MARKUP */
				    G_TYPE_BOOLEAN,   /* COL_STATUS_CUSTOMISABLE */
				    G_TYPE_INT);      /* COL_TYPE */

	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;
		const char *status, *icon_name;

		status = empathy_presence_get_default_message (states[i].state);
		icon_name = empathy_icon_name_for_presence (states[i].state);

		gtk_list_store_insert_with_values (store, NULL, -1,
			COL_STATE_ICON_NAME, icon_name,
			COL_STATE, states[i].state,
			COL_STATUS_TEXT, status,
			COL_DISPLAY_MARKUP, status,
			COL_STATUS_CUSTOMISABLE, states[i].customisable,
			COL_TYPE, ENTRY_TYPE_BUILTIN,
			-1);

		if (states[i].customisable) {
			/* Set custom messages if wanted */
			list = empathy_status_presets_get (states[i].state, -1);
			list = g_list_sort (list, (GCompareFunc) g_utf8_collate);
			for (l = list; l; l = l->next) {
				gtk_list_store_insert_with_values (store,
					NULL, -1,
					COL_STATE_ICON_NAME, icon_name,
					COL_STATE, states[i].state,
					COL_STATUS_TEXT, l->data,
					COL_DISPLAY_MARKUP, l->data,
					COL_STATUS_CUSTOMISABLE, TRUE,
					COL_TYPE, ENTRY_TYPE_SAVED,
					-1);
			}
			g_list_free (list);

			gtk_list_store_insert_with_values (store, NULL, -1,
				COL_STATE_ICON_NAME, icon_name,
				COL_STATE, states[i].state,
				COL_STATUS_TEXT, "",
				COL_DISPLAY_MARKUP, custom_message,
				COL_STATUS_CUSTOMISABLE, TRUE,
				COL_TYPE, ENTRY_TYPE_CUSTOM,
				-1);
		}

	}

	/* add a separator */
	gtk_list_store_insert_with_values (store, NULL, -1,
			COL_TYPE, ENTRY_TYPE_SEPARATOR,
			-1);

	gtk_list_store_insert_with_values (store, NULL, -1,
		COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
		COL_STATUS_TEXT, "",
		COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
		COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
		-1);

	g_free (custom_message);

	gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (store));
	g_object_unref (store);
}