示例#1
0
static GObject *
empathy_chatroom_manager_constructor (GType type,
                                      guint n_props,
                                      GObjectConstructParam *props)
{
  GObject *obj;
  EmpathyChatroomManager *self;
  EmpathyChatroomManagerPriv *priv;

  if (chatroom_manager_singleton != NULL)
    return g_object_ref (chatroom_manager_singleton);

  /* Parent constructor chain */
  obj = G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->
        constructor (type, n_props, props);

  self = EMPATHY_CHATROOM_MANAGER (obj);
  priv = GET_PRIV (self);

  priv->ready = FALSE;

  chatroom_manager_singleton = self;
  g_object_add_weak_pointer (obj, (gpointer) &chatroom_manager_singleton);

  priv->account_manager = empathy_account_manager_dup_singleton ();

  priv->account_manager_ready_handler_id = 0;

  if (empathy_account_manager_is_ready (priv->account_manager))
    chatroom_manager_get_all (self);
  else
    priv->account_manager_ready_handler_id =  g_signal_connect (
        G_OBJECT (priv->account_manager), "notify::ready",
        G_CALLBACK (account_manager_ready_cb), self);

  if (priv->file == NULL)
    {
      /* Set the default file path */
      gchar *dir;

      dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
      if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
        g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);

      priv->file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL);
      g_free (dir);
    }

  return obj;
}
示例#2
0
static void
account_manager_ready_cb (GObject *gobject,
                          GParamSpec *pspec,
                          gpointer user_data)
{
  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (user_data);
  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);

  chatroom_manager_get_all (self);

  g_signal_handler_disconnect (gobject,
      priv->account_manager_ready_handler_id);
  priv->account_manager_ready_handler_id = 0;
}
static void
empathy_chatroom_manager_set_property (GObject *object,
    guint property_id,
    const GValue *value,
    GParamSpec *pspec)
{
  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);

  switch (property_id)
    {
      case PROP_FILE:
        g_free (priv->file);
        priv->file = g_value_dup_string (value);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}
static void
account_manager_ready_cb (GObject *source_object,
    GAsyncResult *result,
    gpointer user_data)
{
  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (user_data);
  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
  GError *error = NULL;
  GFile *file = NULL;

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

  chatroom_manager_get_all (self);

  /* Set up file monitor */
  file = g_file_new_for_path (priv->file);

  priv->monitor = g_file_monitor (file, 0, NULL, &error);
  if (priv->monitor == NULL)
    {
      DEBUG ("Failed to create file monitor on %s: %s", priv->file,
          error->message);

      g_error_free (error);
      goto out;
    }

  g_signal_connect (priv->monitor, "changed", G_CALLBACK (file_changed_cb),
      self);

out:
  tp_clear_object (&file);
  g_object_unref (self);
}
示例#5
0
static void
chatroom_manager_finalize (GObject *object)
{
  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
  EmpathyChatroomManagerPriv *priv;
  GList *l;

  priv = GET_PRIV (object);

  if (priv->account_manager_ready_handler_id > 0)
    {
      g_signal_handler_disconnect (priv->account_manager,
          priv->account_manager_ready_handler_id);
    }

  g_object_unref (priv->account_manager);

  if (priv->save_timer_id > 0)
    {
      /* have to save before destroy the object */
      g_source_remove (priv->save_timer_id);
      priv->save_timer_id = 0;
      chatroom_manager_file_save (self);
    }

  for (l = priv->chatrooms; l != NULL; l = g_list_next (l))
    {
      EmpathyChatroom *chatroom = l->data;

      g_signal_handlers_disconnect_by_func (chatroom, chatroom_changed_cb,
          self);

      g_object_unref (chatroom);
    }

  g_list_free (priv->chatrooms);
  g_free (priv->file);

  (G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->finalize) (object);
}
static void
chatroom_manager_finalize (GObject *object)
{
  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
  EmpathyChatroomManagerPriv *priv;

  priv = GET_PRIV (object);

  g_object_unref (priv->account_manager);

  if (priv->save_timer_id > 0)
    {
      /* have to save before destroy the object */
      g_source_remove (priv->save_timer_id);
      priv->save_timer_id = 0;
      chatroom_manager_file_save (self);
    }

  clear_chatrooms (self);

  g_free (priv->file);

  (G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->finalize) (object);
}
EmpathyChatroomManager *
empathy_chatroom_manager_dup_singleton (const gchar *file)
{
  return EMPATHY_CHATROOM_MANAGER (g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER,
      "file", file, NULL));
}
static GObject *
empathy_chatroom_manager_constructor (GType type,
    guint n_props,
    GObjectConstructParam *props)
{
  GObject *obj;
  EmpathyChatroomManager *self;
  EmpathyChatroomManagerPriv *priv;
  GError *error = NULL;

  if (chatroom_manager_singleton != NULL)
    return g_object_ref (chatroom_manager_singleton);

  /* Parent constructor chain */
  obj = G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->
        constructor (type, n_props, props);

  self = EMPATHY_CHATROOM_MANAGER (obj);
  priv = GET_PRIV (self);

  priv->ready = FALSE;

  chatroom_manager_singleton = self;
  g_object_add_weak_pointer (obj, (gpointer) &chatroom_manager_singleton);

  priv->account_manager = tp_account_manager_dup ();

  tp_proxy_prepare_async (priv->account_manager, NULL,
      account_manager_ready_cb, g_object_ref (self));

  if (priv->file == NULL)
    {
      /* Set the default file path */
      gchar *dir;

      dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
      if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
        g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);

      priv->file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL);
      g_free (dir);
    }

  /* Setup a room observer */
  priv->observer = tp_simple_observer_new_with_am (priv->account_manager, TRUE,
      "Empathy.ChatroomManager", TRUE, observe_channels_cb, self, NULL);

  tp_base_client_take_observer_filter (priv->observer, tp_asv_new (
      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
        TP_IFACE_CHANNEL_TYPE_TEXT,
      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
        TP_HANDLE_TYPE_ROOM,
      NULL));

  if (!tp_base_client_register (priv->observer, &error))
    {
      g_critical ("Failed to register Observer: %s", error->message);

      g_error_free (error);
    }

  return obj;
}