static void
cm_ready (TpConnectionManager	*cm,
	  const GError		*in_error,
	  gpointer		 user_data,
	  GObject		*weak_obj)
{
	char **argv = (char **) user_data;

	g_print (" > cm_ready\n");

	if (in_error) g_error ("%s", in_error->message);

	const TpConnectionManagerProtocol *prot = tp_connection_manager_get_protocol (cm, "local-xmpp");
	if (!prot) g_error ("Protocol is not supported");

	/* request a new connection */
	GHashTable *parameters = tp_asv_new (
			"first-name", G_TYPE_STRING, argv[1],
			"last-name", G_TYPE_STRING, argv[2],
			NULL);

	tp_cli_connection_manager_call_request_connection (cm, -1,
			"local-xmpp",
			parameters,
			request_connection_cb,
			argv, NULL, NULL);

	g_hash_table_destroy (parameters);
}
/**
 * empathy_protocol_chooser_get_selected_protocol:
 * @protocol_chooser: an #EmpathyProtocolChooser
 *
 * Returns a pointer to the selected #TpConnectionManagerProtocol in
 * @protocol_chooser.
 *
 * Return value: a pointer to the selected #TpConnectionManagerProtocol
 */
TpConnectionManager *
empathy_protocol_chooser_dup_selected (
    EmpathyProtocolChooser *protocol_chooser,
    TpConnectionManagerProtocol **protocol,
    gchar **service)
{
  GtkTreeIter iter;
  TpConnectionManager *cm = NULL;
  GtkTreeModel *cur_model;

  g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), NULL);

  /* get the current model from the chooser, as we could either be filtering
   * or not.
   */
  cur_model = gtk_combo_box_get_model (GTK_COMBO_BOX (protocol_chooser));

  if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (protocol_chooser), &iter))
    {
      gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter,
          COL_CM, &cm,
          -1);

      if (protocol != NULL)
        {
          gchar *protocol_name = NULL;

          gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter,
              COL_PROTOCOL_NAME, &protocol_name,
              -1);

          *protocol = (TpConnectionManagerProtocol *)
            tp_connection_manager_get_protocol (cm, protocol_name);

          g_free (protocol_name);

          if (*protocol == NULL)
            {
              /* For some reason the CM doesn't know about this protocol
               * any more */
              g_object_unref (cm);
              return NULL;
            }
        }

      if (service != NULL)
        {
          gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter,
              COL_SERVICE, service,
              -1);
        }
    }

  return cm;
}
static gboolean
protocol_chooser_filter_visible_func (GtkTreeModel *model,
    GtkTreeIter *iter,
    gpointer user_data)
{
  EmpathyProtocolChooser *protocol_chooser = user_data;
  EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser);
  TpConnectionManager *cm = NULL;
  gchar *protocol_name = NULL;
  gboolean visible = FALSE;
  gchar *service;

  gtk_tree_model_get (model, iter,
      COL_CM, &cm,
      COL_PROTOCOL_NAME, &protocol_name,
      COL_SERVICE, &service,
      -1);

  if (cm != NULL && protocol_name != NULL)
    {
      TpConnectionManagerProtocol *protocol;

      protocol = (TpConnectionManagerProtocol *)
        tp_connection_manager_get_protocol (cm, protocol_name);

      if (protocol != NULL)
        {
          visible = priv->filter_func (cm, protocol, service,
              priv->filter_user_data);
        }
    }

  if (cm != NULL)
    g_object_unref (cm);

  g_free (service);
  return visible;
}
예제 #4
0
static void
create_salut_account_am_ready_cb (GObject *source_object,
    GAsyncResult *result,
    gpointer user_data)
{
  TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
  EmpathyConnectionManagers *managers = user_data;
  EmpathyAccountSettings  *settings;
  TpConnectionManager *manager;
  const TpConnectionManagerProtocol *protocol;
  EBook      *book;
  EContact   *contact;
  gchar      *nickname = NULL;
  gchar      *first_name = NULL;
  gchar      *last_name = NULL;
  gchar      *email = NULL;
  gchar      *jid = NULL;
  GError     *error = NULL;

  if (!tp_account_manager_prepare_finish (account_manager, result, &error))
    {
      DEBUG ("Failed to prepare account manager: %s", error->message);
      g_error_free (error);
      goto out;
    }

  if (!should_create_salut_account (account_manager))
    goto out;

  manager = empathy_connection_managers_get_cm (managers, "salut");
  if (manager == NULL)
    {
      DEBUG ("Salut not installed, not making a salut account");
      goto out;
    }

  protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
  if (protocol == NULL)
    {
      DEBUG ("Salut doesn't support local-xmpp!!");
      goto out;
    }

  DEBUG ("Trying to add a salut account...");

  /* Get self EContact from EDS */
  if (!e_book_get_self (&contact, &book, &error))
    {
      DEBUG ("Failed to get self econtact: %s",
          error ? error->message : "No error given");
      g_clear_error (&error);
      goto out;
    }

  settings = empathy_account_settings_new ("salut", "local-xmpp",
      _("People nearby"));

  nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
  first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
  last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
  email = e_contact_get (contact, E_CONTACT_EMAIL_1);
  jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);

  if (!tp_strdiff (nickname, "nickname"))
    {
      g_free (nickname);
      nickname = NULL;
    }

  DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
     "last-name=%s\nemail=%s\njid=%s\n",
     nickname, first_name, last_name, email, jid);

  empathy_account_settings_set_string (settings,
      "nickname", nickname ? nickname : "");
  empathy_account_settings_set_string (settings,
      "first-name", first_name ? first_name : "");
  empathy_account_settings_set_string (settings,
      "last-name", last_name ? last_name : "");
  empathy_account_settings_set_string (settings, "email", email ? email : "");
  empathy_account_settings_set_string (settings, "jid", jid ? jid : "");

  empathy_account_settings_apply_async (settings,
      salut_account_created, NULL);

  g_free (nickname);
  g_free (first_name);
  g_free (last_name);
  g_free (email);
  g_free (jid);
  g_object_unref (settings);
  g_object_unref (contact);
  g_object_unref (book);

 out:
  g_object_unref (managers);
}