Exemplo n.º 1
0
void
empathy_init (void)
{
  static gboolean initialized = FALSE;
  TpAccountManager *am;
  EmpathyClientFactory *factory;

  if (initialized)
    return;

  g_type_init ();

  /* Setup gettext */
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

  /* Setup debug output for empathy and telepathy-glib */
  if (g_getenv ("EMPATHY_TIMING") != NULL)
    g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL);

  empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG"));
  tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE"));

  emp_cli_init ();

  initialized = TRUE;

  factory = empathy_client_factory_dup ();
  am = tp_account_manager_new_with_factory (TP_SIMPLE_CLIENT_FACTORY (factory));
  tp_account_manager_set_default (am);

  g_object_unref (factory);
  g_object_unref (am);
}
int
main (int argc,
    char **argv)
  {
    EmpathyClientFactory *factory;
    TpAccountManager *am;
    GMainLoop *loop;

    gtk_init (&argc, &argv);
    empathy_gtk_init ();

    /* The blocking dialog needs the contact list for the contacts completion
     * so we prepare it first. */
    factory = empathy_client_factory_dup ();

    tp_simple_client_factory_add_connection_features_varargs (
        TP_SIMPLE_CLIENT_FACTORY (factory),
        TP_CONNECTION_FEATURE_CONTACT_LIST,
        NULL);

    am = tp_account_manager_dup ();

    loop = g_main_loop_new (NULL, FALSE);

    tp_proxy_prepare_async (am, NULL, am_prepare_cb, loop);

    g_main_loop_run (loop);

    g_object_unref (am);
    return 0;
  }
static void
chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
    xmlNodePtr node)
{
  EmpathyChatroom *chatroom = NULL;
  TpAccount *account;
  xmlNodePtr child;
  gchar *str;
  gchar *name;
  gchar *room;
  gchar *account_id;
  gboolean auto_connect;
  gboolean always_urgent;
  EmpathyClientFactory *factory;
  GError *error = NULL;

  /* default values. */
  name = NULL;
  room = NULL;
  auto_connect = TRUE;
  always_urgent = FALSE;
  account_id = NULL;

  for (child = node->children; child; child = child->next)
    {
      gchar *tag;

      if (xmlNodeIsText (child))
        continue;

      tag = (gchar *) child->name;
      str = (gchar *) xmlNodeGetContent (child);

      if (strcmp (tag, "name") == 0)
        {
          name = g_strdup (str);
        }
      else if (strcmp (tag, "room") == 0)
        {
          room = g_strdup (str);
        }
      else if (strcmp (tag, "auto_connect") == 0)
        {
          if (strcmp (str, "yes") == 0)
            auto_connect = TRUE;
          else
            auto_connect = FALSE;
        }
      else if (!tp_strdiff (tag, "always_urgent"))
        {
          if (strcmp (str, "yes") == 0)
            always_urgent = TRUE;
          else
            always_urgent = FALSE;
        }
      else if (strcmp (tag, "account") == 0)
        {
          account_id = g_strdup (str);
        }

      xmlFree (str);
    }

  /* account has to be a valid Account object path */
  if (!tp_dbus_check_valid_object_path (account_id, NULL) ||
      !g_str_has_prefix (account_id, TP_ACCOUNT_OBJECT_PATH_BASE))
    goto out;

  factory = empathy_client_factory_dup ();

  account = tp_simple_client_factory_ensure_account (
          TP_SIMPLE_CLIENT_FACTORY (factory), account_id, NULL, &error);
  g_object_unref (factory);

  if (account == NULL)
    {
      DEBUG ("Failed to create account: %s", error->message);
      g_error_free (error);

      g_free (name);
      g_free (room);
      g_free (account_id);
      return;
    }

  chatroom = empathy_chatroom_new_full (account, room, name, auto_connect);
  empathy_chatroom_set_favorite (chatroom, TRUE);
  empathy_chatroom_set_always_urgent (chatroom, always_urgent);
  add_chatroom (manager, chatroom);
  g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);

out:
  g_free (name);
  g_free (room);
  g_free (account_id);
  tp_clear_object (&chatroom);
}