gboolean
empathy_migrate_butterfly_logs (EmpathyContact *contact)
{
  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
  gchar *cm;

  /* Already in progress. */
  if (butterfly_log_migration_id != 0)
    return FALSE;

  /* Already done. */
  if (g_settings_get_boolean (gsettings, EMPATHY_PREFS_BUTTERFLY_LOGS_MIGRATED))
    return FALSE;

  tp_account_parse_object_path (
      tp_proxy_get_object_path (empathy_contact_get_account (contact)),
      &cm, NULL, NULL, NULL);

  if (tp_strdiff (cm, "butterfly"))
    {
      g_free (cm);
      return TRUE;
    }
  g_free (cm);

  if (g_str_has_suffix (empathy_contact_get_id (contact), "#32")
      || g_str_has_suffix (empathy_contact_get_id (contact), "#1"))
    return TRUE;

  /* Okay, we know a new butterfly is being used, so we should migrate its logs */
  butterfly_log_migration_id = g_idle_add_full (G_PRIORITY_LOW,
      migrate_logs, NULL, NULL);

  return FALSE;
}
Ejemplo n.º 2
0
GtkWidget *
empathy_contact_log_menu_item_new (EmpathyContact *contact)
{
	EmpathyLogManager *manager;
	gboolean           have_log;
	GtkWidget         *item;
	GtkWidget         *image;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	manager = empathy_log_manager_new ();
	have_log = empathy_log_manager_exists (manager,
					       empathy_contact_get_account (contact),
					       empathy_contact_get_id (contact),
					       FALSE);
	g_object_unref (manager);

	item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
	image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
					      GTK_ICON_SIZE_MENU);
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
	gtk_widget_set_sensitive (item, have_log);
	gtk_widget_show (image);

	g_signal_connect_swapped (item, "activate",
				  G_CALLBACK (contact_log_menu_item_activate_cb),
				  contact);
	
	return item;
}
static void
tp_contact_list_forget_group (EmpathyTpContactList *list,
			      TpChannel *channel)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	const TpIntSet *members;
	TpIntSetIter iter;
	const gchar *group_name;

	group_name = tp_channel_get_identifier (channel);

	/* Signal that all members are not in that group anymore */
	members = tp_channel_group_get_members (channel);
	tp_intset_iter_init (&iter, members);
	while (tp_intset_iter_next (&iter)) {
		EmpathyContact *contact;

		contact = g_hash_table_lookup (priv->members,
					       GUINT_TO_POINTER (iter.element));
		if (contact == NULL) {
			continue;
		}

		DEBUG ("Contact %s (%d) removed from group %s",
			empathy_contact_get_id (contact), iter.element,
			group_name);
		g_signal_emit_by_name (list, "groups-changed", contact,
				       group_name,
				       FALSE);
	}
}
Ejemplo n.º 4
0
static void
contact_list_view_drag_got_contact (EmpathyTpContactFactory *factory,
				    EmpathyContact          *contact,
				    const GError            *error,
				    gpointer                 user_data,
				    GObject                 *view)
{
	EmpathyContactListViewPriv *priv = GET_PRIV (view);
	DndGetContactData          *data = user_data;
	EmpathyContactList         *list;

	if (error != NULL) {
		DEBUG ("Error: %s", error->message);
		return;
	}

	DEBUG ("contact %s (%d) dragged from '%s' to '%s'",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact),
		data->old_group, data->new_group);

	list = empathy_contact_list_store_get_list_iface (priv->store);
	if (data->new_group) {
		empathy_contact_list_add_to_group (list, contact, data->new_group);
	}
	if (data->old_group && data->action == GDK_ACTION_MOVE) {
		empathy_contact_list_remove_from_group (list, contact, data->old_group);
	}
}
static EmpathyContact *
contact_manager_lookup_contact (EmpathyContactManager *manager,
				const gchar           *account_name,
				const gchar           *contact_id)
{
	EmpathyContact *retval = NULL;
	GList *members, *l;

	/* XXX: any more efficient way to do this (other than having to build
	 * and maintain a hash)? */
	members = empathy_contact_list_get_members (
			EMPATHY_CONTACT_LIST (manager));
	for (l = members; l; l = l->next) {
		EmpathyContact *contact = l->data;
		TpAccount *account = empathy_contact_get_account (contact);
		const gchar *id_cur;
		const gchar *name_cur;

		id_cur = empathy_contact_get_id (contact);
		name_cur = tp_proxy_get_object_path (TP_PROXY (account));

		if (!tp_strdiff (contact_id, id_cur) &&
			!tp_strdiff (account_name, name_cur)) {
			retval = contact;
		}

		g_object_unref (contact);
	}

	g_list_free (members);

	return retval;
}
Ejemplo n.º 6
0
static void
tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
					guint         handle,
					const gchar  *token,
					const GArray *avatar_data,
					const gchar  *mime_type,
					gpointer      user_data,
					GObject      *tp_factory)
{
	EmpathyContact *contact;

	contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
						     handle);
	if (!contact) {
		return;
	}

	DEBUG ("Avatar retrieved for contact %s (%d)",
		empathy_contact_get_id (contact),
		handle);

	empathy_contact_load_avatar_data (contact,
					  (guchar *) avatar_data->data,
					  avatar_data->len,
					  mime_type,
					  token);
}
static void
contacts_added_to_group (EmpathyTpContactList *list,
			 TpChannel *channel,
			 GArray *added)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	const gchar *group_name;
	guint i;

	group_name = tp_channel_get_identifier (channel);

	for (i = 0; i < added->len; i++) {
		EmpathyContact *contact;
		TpHandle handle;

		handle = g_array_index (added, TpHandle, i);
		contact = g_hash_table_lookup (priv->members,
					       GUINT_TO_POINTER (handle));
		if (contact == NULL) {
			continue;
		}

		DEBUG ("Contact %s (%d) added to group %s",
			empathy_contact_get_id (contact), handle, group_name);
		g_signal_emit_by_name (list, "groups-changed", contact,
				       group_name,
				       TRUE);
	}
}
Ejemplo n.º 8
0
static void
contact_list_store_groups_changed_cb (EmpathyContactList      *list_iface,
				      EmpathyContact          *contact,
				      gchar                   *group,
				      gboolean                 is_member,
				      EmpathyContactListStore *store)
{
	EmpathyContactListStorePriv *priv;
	gboolean                     show_active;

	priv = GET_PRIV (store);

	DEBUG ("Updating groups for contact %s (%d)",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact));

	/* We do this to make sure the groups are correct, if not, we
	 * would have to check the groups already set up for each
	 * contact and then see what has been updated.
	 */
	show_active = priv->show_active;
	priv->show_active = FALSE;
	contact_list_store_remove_contact (store, contact);
	contact_list_store_add_contact (store, contact);
	priv->show_active = show_active;
}
Ejemplo n.º 9
0
static void
update_contact_capabilities (EmpathyTpContactFactory *self,
			     GHashTable *caps)
{
	GHashTableIter iter;
	gpointer key, value;

	g_hash_table_iter_init (&iter, caps);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		TpHandle handle = GPOINTER_TO_UINT (key);
		GPtrArray *classes = value;
		EmpathyContact *contact;
		EmpathyCapabilities  capabilities;

		contact = tp_contact_factory_find_by_handle (self, handle);
		if (contact == NULL)
			continue;

		capabilities = empathy_contact_get_capabilities (contact);
		capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;

		capabilities |= channel_classes_to_capabilities (classes, TRUE);

		DEBUG ("Changing capabilities for contact %s (%d) to %d",
			empathy_contact_get_id (contact),
			empathy_contact_get_handle (contact),
			capabilities);

		empathy_contact_set_capabilities (contact, capabilities);
	}
}
Ejemplo n.º 10
0
static gboolean
megaphone_applet_button_press_event_cb (GtkWidget       *widget,
					GdkEventButton  *event, 
					MegaphoneApplet *applet)
{
	MegaphoneAppletPriv *priv = GET_PRIV (applet);

	/* Only react on left-clicks */
	if (event->button != 1 || event->type != GDK_BUTTON_PRESS) {
		return FALSE;
	}

	/* If the contact is unavailable we display the preferences dialog */
	if (priv->contact == NULL) {
		megaphone_applet_show_preferences (applet);
		return TRUE;
	}
	
	DEBUG ("Requesting text channel for contact %s (%d)",
		empathy_contact_get_id (priv->contact),
		empathy_contact_get_handle (priv->contact));

	empathy_dispatcher_chat_with_contact (priv->contact, NULL, NULL);

	return TRUE;
}
static void
contact_log_menu_item_activate_cb (EmpathyContact *contact)
{
	empathy_log_window_show (empathy_contact_get_account (contact),
				 empathy_contact_get_id (contact),
				 FALSE, NULL);
}
static gboolean
contact_manager_is_favourite (EmpathyContactList *manager,
			      EmpathyContact     *contact)
{
	EmpathyContactManagerPriv *priv;
	TpAccount *account;
	const gchar *account_name;
	GHashTable *contact_hash;

	g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), FALSE);
	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);

	priv = GET_PRIV (manager);

	account = empathy_contact_get_account (contact);
	account_name = tp_proxy_get_object_path (TP_PROXY (account));
	contact_hash = g_hash_table_lookup (priv->favourites, account_name);

	if (contact_hash != NULL) {
		const gchar *contact_id = empathy_contact_get_id (contact);

		if (g_hash_table_lookup (contact_hash, contact_id) != NULL)
			return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 13
0
static void
dispatch_cb (EmpathyDispatcher *dispatcher,
	     EmpathyDispatchOperation *operation,
	     gpointer           user_data)
{
	GQuark channel_type;

	channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

	if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) {
		EmpathyTpChat *tp_chat;
		EmpathyChat   *chat = NULL;
		const gchar   *id;

		tp_chat = EMPATHY_TP_CHAT (
			empathy_dispatch_operation_get_channel_wrapper (operation));

		id = empathy_tp_chat_get_id (tp_chat);
		if (!id) {
			EmpathyContact *contact;

			contact = empathy_tp_chat_get_remote_contact (tp_chat);
			if (contact) {
				id = empathy_contact_get_id (contact);
			}
		}

		if (id) {
			McAccount *account;

			account = empathy_tp_chat_get_account (tp_chat);
			chat = empathy_chat_window_find_chat (account, id);
		}

		if (chat) {
			empathy_chat_set_tp_chat (chat, tp_chat);
		} else {
			chat = empathy_chat_new (tp_chat);
		}

		empathy_chat_window_present_chat (chat);

		empathy_dispatch_operation_claim (operation);
	} else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) {
		EmpathyCallFactory *factory;

		factory = empathy_call_factory_get ();
		empathy_call_factory_claim_channel (factory, operation);
	} else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) {
		EmpathyFTManager *ft_manager;
		EmpathyTpFile    *tp_file;

		ft_manager = empathy_ft_manager_dup_singleton ();
		tp_file = EMPATHY_TP_FILE (
			empathy_dispatch_operation_get_channel_wrapper (operation));
		empathy_ft_manager_add_tp_file (ft_manager, tp_file);
		empathy_dispatch_operation_claim (operation);
	}
}
void
empathy_chat_with_contact (EmpathyContact *contact,
    gint64 timestamp)
{
  empathy_chat_with_contact_id (
      empathy_contact_get_account (contact), empathy_contact_get_id (contact),
      timestamp, NULL, NULL);
}
static void
empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
	EmpathyContact *contact)
{
	empathy_call_new_with_streams (empathy_contact_get_id (contact),
		empathy_contact_get_account (contact),
		TRUE, TRUE,
		empathy_get_current_action_time ());
}
Ejemplo n.º 16
0
static void
contact_list_view_drag_data_get (GtkWidget        *widget,
				 GdkDragContext   *context,
				 GtkSelectionData *selection,
				 guint             info,
				 guint             time)
{
	EmpathyContactListViewPriv *priv;
	GtkTreePath                *src_path;
	GtkTreeIter                 iter;
	GtkTreeModel               *model;
	EmpathyContact             *contact;
	McAccount                  *account;
	const gchar                *contact_id;
	const gchar                *account_id;
	gchar                      *str;

	priv = GET_PRIV (widget);

	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
	if (!priv->drag_row) {
		return;
	}

	src_path = gtk_tree_row_reference_get_path (priv->drag_row);
	if (!src_path) {
		return;
	}

	if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
		gtk_tree_path_free (src_path);
		return;
	}

	gtk_tree_path_free (src_path);

	contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
	if (!contact) {
		return;
	}

	account = empathy_contact_get_account (contact);
	account_id = mc_account_get_unique_name (account);
	contact_id = empathy_contact_get_id (contact);
	g_object_unref (contact);
	str = g_strconcat (account_id, "/", contact_id, NULL);

	switch (info) {
	case DND_DRAG_TYPE_CONTACT_ID:
		gtk_selection_data_set (selection, drag_atoms_source[info], 8,
					(guchar*)str, strlen (str) + 1);
		break;
	}

	g_free (str);
}
Ejemplo n.º 17
0
void
empathy_call_handler_start_call (EmpathyCallHandler *handler,
    gint64 timestamp)
{
  EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
  TpAccountChannelRequest *req;
  TpAccount *account;
  GHashTable *request;

  if (priv->call != NULL)
    {
      empathy_call_handler_start_tpfs (handler);

      if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
        {
          /* accept outgoing channels immediately */
          tp_call_channel_accept_async (priv->call,
              on_call_accepted_cb, NULL);
        }
      else
        {
          /* accepting incoming channels when they are INITIALISED */
          if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
              TP_CALL_STATE_INITIALISED)
            tp_call_channel_accept_async (priv->call,
                on_call_accepted_cb, NULL);
          else
            priv->accept_when_initialised = TRUE;
        }

      return;
    }

  /* No TpCallChannel (we are redialing). Request a new call channel */
  g_assert (priv->contact != NULL);

  account = empathy_contact_get_account (priv->contact);
  request = empathy_call_create_call_request (
      empathy_contact_get_id (priv->contact),
      priv->initial_audio, priv->initial_video);

  req = tp_account_channel_request_new (account, request, timestamp);

  tp_account_channel_request_create_and_handle_channel_async (req, NULL,
      empathy_call_handler_request_cb, handler);

  g_object_unref (req);
  g_hash_table_unref (request);
}
Ejemplo n.º 18
0
static void
dispatch_channel_cb (EmpathyDispatcher *dispatcher,
		     TpChannel         *channel,
		     gpointer           user_data)
{
	gchar *channel_type;

	g_object_get (channel, "channel-type", &channel_type, NULL);
	if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) {
		EmpathyTpChat *tp_chat;
		EmpathyChat   *chat = NULL;
		const gchar   *id;

		tp_chat = empathy_tp_chat_new (channel);
		empathy_run_until_ready (tp_chat);

		id = empathy_tp_chat_get_id (tp_chat);
		if (!id) {
			EmpathyContact *contact;

			contact = empathy_tp_chat_get_remote_contact (tp_chat);
			if (contact) {
				id = empathy_contact_get_id (contact);
			}
		}

		if (id) {
			McAccount *account;

			account = empathy_tp_chat_get_account (tp_chat);
			chat = empathy_chat_window_find_chat (account, id);
		}

		if (chat) {
			empathy_chat_set_tp_chat (chat, tp_chat);
		} else {
			chat = empathy_chat_new (tp_chat);
		}

		empathy_chat_window_present_chat (chat);
		g_object_unref (tp_chat);
	}
	else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)) {
		empathy_call_window_new (channel);
	}
}
Ejemplo n.º 19
0
static void
contact_list_store_members_changed_cb (EmpathyContactList      *list_iface,
				       EmpathyContact          *contact,
				       EmpathyContact          *actor,
				       guint                    reason,
				       gchar                   *message,
				       gboolean                 is_member,
				       EmpathyContactListStore *store)
{
	EmpathyContactListStorePriv *priv;

	priv = GET_PRIV (store);

	DEBUG ("Contact %s (%d) %s",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact),
		is_member ? "added" : "removed");

	if (is_member) {
		g_signal_connect (contact, "notify::presence",
				  G_CALLBACK (contact_list_store_contact_updated_cb),
				  store);
		g_signal_connect (contact, "notify::presence-message",
				  G_CALLBACK (contact_list_store_contact_updated_cb),
				  store);
		g_signal_connect (contact, "notify::name",
				  G_CALLBACK (contact_list_store_contact_updated_cb),
				  store);
		g_signal_connect (contact, "notify::avatar",
				  G_CALLBACK (contact_list_store_contact_updated_cb),
				  store);
		g_signal_connect (contact, "notify::capabilities",
				  G_CALLBACK (contact_list_store_contact_updated_cb),
				  store);

		contact_list_store_add_contact (store, contact);
	} else {
		g_signal_handlers_disconnect_by_func (contact,
						      G_CALLBACK (contact_list_store_contact_updated_cb),
						      store);

		contact_list_store_remove_contact (store, contact);
	}
}
static void
contact_manager_remove_favourite (EmpathyContactList *manager,
				  EmpathyContact *contact)
{
	EmpathyContactManagerPriv *priv;
	TpAccount *account;
	const gchar *account_name;

	g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
	g_return_if_fail (EMPATHY_IS_CONTACT (contact));

	priv = GET_PRIV (manager);

	account = empathy_contact_get_account (contact);
	account_name = tp_proxy_get_object_path (TP_PROXY (account));

	emp_cli_logger_call_remove_favourite_contact (priv->logger, -1,
						      account_name,
						      empathy_contact_get_id (contact),
						      remove_favourite_contact_cb, NULL, NULL, G_OBJECT (manager));
}
static void
tp_contact_list_remove_from_group (EmpathyContactList *list,
				   EmpathyContact     *contact,
				   const gchar        *group_name)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	TpChannel                *channel;
	TpHandle                  handle;
	GArray                    handles = {(gchar *) &handle, 1};

	channel = g_hash_table_lookup (priv->groups, group_name);
	if (channel == NULL) {
		return;
	}

	handle = empathy_contact_get_handle (contact);
	DEBUG ("remove contact %s (%d) from group %s",
		empathy_contact_get_id (contact), handle, group_name);

	tp_cli_channel_interface_group_call_remove_members (channel, -1,
		&handles, NULL, NULL, NULL, NULL, NULL);
}
static void
tp_contact_list_group_members_changed_cb (TpChannel     *channel,
					  gchar         *message,
					  GArray        *added,
					  GArray        *removed,
					  GArray        *local_pending,
					  GArray        *remote_pending,
					  guint          actor,
					  guint          reason,
					  EmpathyTpContactList *list)
{
	EmpathyTpContactListPriv  *priv = GET_PRIV (list);
	const gchar *group_name;
	guint i;

	contacts_added_to_group (list, channel, added);

	group_name = tp_channel_get_identifier (channel);

	for (i = 0; i < removed->len; i++) {
		EmpathyContact *contact;
		TpHandle handle;

		handle = g_array_index (removed, TpHandle, i);
		contact = g_hash_table_lookup (priv->members,
					       GUINT_TO_POINTER (handle));
		if (contact == NULL) {
			continue;
		}

		DEBUG ("Contact %s (%d) removed from group %s",
			empathy_contact_get_id (contact), handle, group_name);

		g_signal_emit_by_name (list, "groups-changed", contact,
				       group_name,
				       FALSE);
	}
}
Ejemplo n.º 23
0
static void
megaphone_applet_preferences_response_cb (GtkWidget       *dialog,
					  gint             response,
					  MegaphoneApplet *applet) 
{
	if (response == GTK_RESPONSE_ACCEPT) {
		EmpathyContactListView *contact_list;
		EmpathyContact         *contact;

		/* Retrieve the selected contact, if any and set it up in gconf.
		 * GConf will notify us from the change and we will adjust ourselves */
		contact_list = g_object_get_data (G_OBJECT (dialog), "contact-list");
		contact = empathy_contact_list_view_dup_selected (contact_list);
		if (contact) {
			EmpathyAccount   *account;
			const gchar *account_id;
			const gchar *contact_id;
			gchar       *str;

			account = empathy_contact_get_account (contact);
			account_id = empathy_account_get_unique_name (account);
			contact_id = empathy_contact_get_id (contact);

			str = g_strconcat (account_id, "/", contact_id, NULL);
			panel_applet_gconf_set_string (PANEL_APPLET (applet),
						       "avatar_token", "",
						       NULL);
			panel_applet_gconf_set_string (PANEL_APPLET (applet),
						       "contact_id", str,
						       NULL);
			g_free (str);
			g_object_unref (contact);
		}
	}
	gtk_widget_destroy (dialog);
}
Ejemplo n.º 24
0
void
empathy_tp_contact_factory_set_alias (EmpathyTpContactFactory *tp_factory,
				      EmpathyContact          *contact,
				      const gchar             *alias)
{
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
	GHashTable                  *new_alias;
	guint                        handle;

	g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
	g_return_if_fail (EMPATHY_IS_CONTACT (contact));

	handle = empathy_contact_get_handle (contact);

	DEBUG ("Setting alias for contact %s (%d) to %s",
		empathy_contact_get_id (contact),
		handle, alias);

	new_alias = g_hash_table_new_full (g_direct_hash,
					   g_direct_equal,
					   NULL,
					   g_free);

	g_hash_table_insert (new_alias,
			     GUINT_TO_POINTER (handle),
			     g_strdup (alias));

	tp_cli_connection_interface_aliasing_call_set_aliases (priv->connection,
							       -1,
							       new_alias,
							       tp_contact_factory_set_aliases_cb,
							       NULL, NULL,
							       G_OBJECT (tp_factory));

	g_hash_table_destroy (new_alias);
}
Ejemplo n.º 25
0
static void
tp_contact_factory_update_capabilities (EmpathyTpContactFactory *tp_factory,
					guint                    handle,
					const gchar             *channel_type,
					guint                    generic,
					guint                    specific)
{
	EmpathyContact      *contact;
	EmpathyCapabilities  capabilities;

	contact = tp_contact_factory_find_by_handle (tp_factory, handle);
	if (!contact) {
		return;
	}

	capabilities = empathy_contact_get_capabilities (contact);
	capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;

	if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) == 0) {
		capabilities &= ~EMPATHY_CAPABILITIES_AUDIO;
		capabilities &= ~EMPATHY_CAPABILITIES_VIDEO;
		if (specific & TP_CHANNEL_MEDIA_CAPABILITY_AUDIO) {
			capabilities |= EMPATHY_CAPABILITIES_AUDIO;
		}
		if (specific & TP_CHANNEL_MEDIA_CAPABILITY_VIDEO) {
			capabilities |= EMPATHY_CAPABILITIES_VIDEO;
		}
	}

	DEBUG ("Changing capabilities for contact %s (%d) to %d",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact),
		capabilities);

	empathy_contact_set_capabilities (contact, capabilities);
}
Ejemplo n.º 26
0
static void
contact_widget_contact_update (EmpathyContactWidget *information)
{
  EmpathyAccount *account = NULL;
  const gchar *id = NULL;

  /* Connect and get info from new contact */
  if (information->contact)
    {
      g_signal_connect_swapped (information->contact, "notify::name",
          G_CALLBACK (contact_widget_name_notify_cb), information);
      g_signal_connect_swapped (information->contact, "notify::presence",
          G_CALLBACK (contact_widget_presence_notify_cb), information);
      g_signal_connect_swapped (information->contact,
          "notify::presence-message",
          G_CALLBACK (contact_widget_presence_notify_cb), information);
      g_signal_connect_swapped (information->contact, "notify::avatar",
          G_CALLBACK (contact_widget_avatar_notify_cb), information);

      account = empathy_contact_get_account (information->contact);
      id = empathy_contact_get_id (information->contact);
    }

  /* Update account widget */
  if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
    {
      if (account)
        {
          g_signal_handlers_block_by_func (information->widget_account,
                   contact_widget_change_contact,
                   information);
          empathy_account_chooser_set_account (
              EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
          g_signal_handlers_unblock_by_func (information->widget_account,
              contact_widget_change_contact, information);
        }
    }
  else
    {
      if (account)
        {
          const gchar *name;

          name = empathy_account_get_display_name (account);
          gtk_label_set_label (GTK_LABEL (information->widget_account), name);
        }
    }

  /* Update id widget */
  if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
      gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
  else
      gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");

  /* Update other widgets */
  if (information->contact)
    {
      contact_widget_name_notify_cb (information);
      contact_widget_presence_notify_cb (information);
      contact_widget_avatar_notify_cb (information);

      gtk_widget_show (information->label_alias);
      gtk_widget_show (information->widget_alias);
      gtk_widget_show (information->hbox_presence);
      gtk_widget_show (information->widget_avatar);
    }
  else
    {
      gtk_widget_hide (information->label_alias);
      gtk_widget_hide (information->widget_alias);
      gtk_widget_hide (information->hbox_presence);
      gtk_widget_hide (information->widget_avatar);
    }
}
Ejemplo n.º 27
0
static void
save_avatar_menu_activate_cb (GtkWidget *widget,
                              EmpathyContactWidget *information)
{
  GtkWidget *dialog;
  EmpathyAvatar *avatar;
  gchar *ext = NULL, *filename;

  dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
      NULL,
      GTK_FILE_CHOOSER_ACTION_SAVE,
      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
      NULL);

  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
      TRUE);

  /* look for the avatar extension */
  avatar = empathy_contact_get_avatar (information->contact);
  if (avatar->format != NULL)
    {
      gchar **splitted;

      splitted = g_strsplit (avatar->format, "/", 2);
      if (splitted[0] != NULL && splitted[1] != NULL)
          ext = g_strdup (splitted[1]);

      g_strfreev (splitted);
    }
  else
    {
      /* Avatar was loaded from the cache so was converted to PNG */
      ext = g_strdup ("png");
    }

  if (ext != NULL)
    {
      gchar *id;

      id = tp_escape_as_identifier (empathy_contact_get_id (
            information->contact));

      filename = g_strdup_printf ("%s.%s", id, ext);
      gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);

      g_free (id);
      g_free (ext);
      g_free (filename);
    }

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
      GError *error = NULL;

      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

      if (!empathy_avatar_save_to_file (avatar, filename, &error))
        {
          /* Save error */
          GtkWidget *dialog;

          dialog = gtk_message_dialog_new (NULL, 0,
              GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
              _("Unable to save avatar"));

          gtk_message_dialog_format_secondary_text (
              GTK_MESSAGE_DIALOG (dialog), "%s", error->message);

          g_signal_connect (dialog, "response",
              G_CALLBACK (gtk_widget_destroy), NULL);

          gtk_window_present (GTK_WINDOW (dialog));

          g_clear_error (&error);
        }

      g_free (filename);
    }

  gtk_widget_destroy (dialog);
}
Ejemplo n.º 28
0
static void
chat_window_update_chat_tab (EmpathyChat *chat)
{
	EmpathyChatWindow     *window;
	EmpathyChatWindowPriv *priv;
	EmpathyContact        *remote_contact;
	const gchar           *name;
	const gchar           *subject;
	GtkWidget             *widget;
	GString               *tooltip;
	gchar                 *str;
	const gchar           *icon_name;

	window = chat_window_find_chat (chat);
	if (!window) {
		return;
	}
	priv = GET_PRIV (window);

	/* Get information */
	name = chat_window_get_chat_name (chat);
	subject = empathy_chat_get_subject (chat);
	remote_contact = empathy_chat_get_remote_contact (chat);

	DEBUG ("Updating chat tab, name=%s, subject=%s, remote_contact=%p",
		name, subject, remote_contact);

	/* Update tab image */
	if (g_list_find (priv->chats_new_msg, chat)) {
		icon_name = EMPATHY_IMAGE_MESSAGE;
	}
	else if (g_list_find (priv->chats_composing, chat)) {
		icon_name = EMPATHY_IMAGE_TYPING;
	}
	else if (remote_contact) {
		icon_name = empathy_icon_name_for_contact (remote_contact);
	} else {
		icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
	}
	widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
	gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);

	/* Update tab tooltip */
	tooltip = g_string_new (NULL);
	if (remote_contact) {
		g_string_append_printf (tooltip, "%s\n%s",
					empathy_contact_get_id (remote_contact),
					empathy_contact_get_status (remote_contact));
	}
	else {
		g_string_append (tooltip, name);
	}
	if (subject) {
		g_string_append_printf (tooltip, "\n%s %s", _("Topic:"), subject);
	}
	if (g_list_find (priv->chats_composing, chat)) {
		g_string_append_printf (tooltip, "\n%s", _("Typing a message."));
	}
	str = g_string_free (tooltip, FALSE);
	widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
	gtk_widget_set_tooltip_text (widget, str);
	g_free (str);

	/* Update tab label */
	widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
	gtk_label_set_text (GTK_LABEL (widget), name);

	/* Update the window if it's the current chat */
	if (priv->current_chat == chat) {
		chat_window_update (window);
	}
}
Ejemplo n.º 29
0
void
empathy_log_manager_add_message (EmpathyLogManager *manager,
				 const gchar       *chat_id,
				 gboolean           chatroom,
				 EmpathyMessage     *message)
{
	FILE          *file;
	McAccount     *account;
	EmpathyContact *sender;
	const gchar   *body_str;
	const gchar   *str;
	EmpathyAvatar *avatar;
	gchar         *avatar_token = NULL;
	gchar         *filename;
	gchar         *basedir;
	gchar         *body;
	gchar         *timestamp;
	gchar         *contact_name;
	gchar         *contact_id;
	TpChannelTextMessageType msg_type;

	g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager));
	g_return_if_fail (chat_id != NULL);
	g_return_if_fail (EMPATHY_IS_MESSAGE (message));

	sender = empathy_message_get_sender (message);
	account = empathy_contact_get_account (sender);
	body_str = empathy_message_get_body (message);
	msg_type = empathy_message_get_tptype (message);

	if (EMP_STR_EMPTY (body_str)) {
		return;
	}

	filename = log_manager_get_filename (manager, account, chat_id, chatroom);
	basedir = g_path_get_dirname (filename);
	if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
		DEBUG ("Creating directory:'%s'", basedir);

		g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE);
	}
	g_free (basedir);

	DEBUG ("Adding message: '%s' to file: '%s'", body_str, filename);

	if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
		file = g_fopen (filename, "w+");
		if (file) {
			g_fprintf (file, LOG_HEADER);
		}
		g_chmod (filename, LOG_FILE_CREATE_MODE);
	} else {
		file = g_fopen (filename, "r+");
		if (file) {
			fseek (file, - strlen (LOG_FOOTER), SEEK_END);
		}
	}

	body = g_markup_escape_text (body_str, -1);
	timestamp = log_manager_get_timestamp_from_message (message);

	str = empathy_contact_get_name (sender);
	contact_name = g_markup_escape_text (str, -1);

	str = empathy_contact_get_id (sender);
	contact_id = g_markup_escape_text (str, -1);

	avatar = empathy_contact_get_avatar (sender);
	if (avatar) {
		avatar_token = g_markup_escape_text (avatar->token, -1);		
	}

	g_fprintf (file,
		   "<message time='%s' id='%s' name='%s' token='%s' isuser='******' type='%s'>%s</message>\n" LOG_FOOTER,
		   timestamp,
		   contact_id,
		   contact_name,
		   avatar_token ? avatar_token : "",
		   empathy_contact_is_user (sender) ? "true" : "false",
		   empathy_message_type_to_str (msg_type),
		   body);

	fclose (file);
	g_free (filename);
	g_free (contact_id);
	g_free (contact_name);
	g_free (timestamp);
	g_free (body);
	g_free (avatar_token);
}
Ejemplo n.º 30
0
static void
tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
				EmpathyContact          *contact)
{
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
	TpHandle self_handle;
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};
	EmpathyCapabilities caps;

	/* Keep a weak ref to that contact */
	g_object_weak_ref (G_OBJECT (contact),
			   tp_contact_factory_weak_notify,
			   tp_factory);
	priv->contacts = g_list_prepend (priv->contacts, contact);

	/* The contact keeps a ref to its factory */
	g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
				g_object_ref (tp_factory),
				g_object_unref);

	caps = empathy_contact_get_capabilities (contact);

	/* Set the FT capability */
	if (!priv->contact_caps_supported) {
		/* ContactCapabilities is not supported; assume all contacts can do file
		 * transfer if it's implemented in the CM */
		if (priv->can_request_ft) {
			caps |= EMPATHY_CAPABILITIES_FT;
		}

		/* Set the Stream Tube capability */
		if (priv->can_request_st) {
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
		}
	}

	empathy_contact_set_capabilities (contact, caps);

	/* Set is-user property. Note that it could still be the handle is
	 * different from the connection's self handle, in the case the handle
	 * comes from a group interface. */
	self_handle = tp_connection_get_self_handle (priv->connection);
	handle = empathy_contact_get_handle (contact);
	empathy_contact_set_is_user (contact, self_handle == handle);

	/* FIXME: This should be done by TpContact */
	if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) {
		tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (
			priv->connection, -1, &handles,
			tp_contact_factory_got_known_avatar_tokens, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	if (priv->contact_caps_supported) {
		tp_cli_connection_interface_contact_capabilities_call_get_contact_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_contact_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}
	else if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES)) {
		tp_cli_connection_interface_capabilities_call_get_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	DEBUG ("Contact added: %s (%d)",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact));
}