static void empathy_account_manager_init (EmpathyAccountManager *manager) { EmpathyAccountManagerPriv *priv; GList *mc_accounts, *l; priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerPriv); manager->priv = priv; priv->monitor = mc_account_monitor_new (); priv->mc = empathy_mission_control_dup_singleton (); priv->connected = priv->connecting = 0; priv->dispose_run = FALSE; priv->accounts = g_hash_table_new_full (empathy_account_hash, empathy_account_equal, g_object_unref, (GDestroyNotify) account_data_free); priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, g_object_unref); mc_accounts = mc_accounts_list (); for (l = mc_accounts; l; l = l->next) account_created_cb (priv->monitor, (char *) mc_account_get_unique_name (l->data), manager); g_signal_connect (priv->monitor, "account-created", G_CALLBACK (account_created_cb), manager); g_signal_connect (priv->monitor, "account-deleted", G_CALLBACK (account_deleted_cb), manager); g_signal_connect (priv->monitor, "account-disabled", G_CALLBACK (account_disabled_cb), manager); g_signal_connect (priv->monitor, "account-enabled", G_CALLBACK (account_enabled_cb), manager); g_signal_connect (priv->monitor, "account-changed", G_CALLBACK (account_changed_cb), manager); dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged", G_CALLBACK (account_status_changed_cb), manager, NULL); mc_accounts_list_free (mc_accounts); }
EmpathyTpRoomlist * empathy_tp_roomlist_new (McAccount *account) { EmpathyTpRoomlist *list; MissionControl *mc; TpConnection *connection; g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); mc = empathy_mission_control_dup_singleton (); connection = mission_control_get_tpconnection (mc, account, NULL); list = g_object_new (EMPATHY_TYPE_TP_ROOMLIST, "connection", connection, NULL); g_object_unref (mc); g_object_unref (connection); return list; }
static void tp_roomlist_constructed (GObject *list) { EmpathyTpRoomlistPriv *priv = GET_PRIV (list); MissionControl *mc; mc = empathy_mission_control_dup_singleton (); priv->account = mission_control_get_account_for_tpconnection (mc, priv->connection, NULL); g_object_unref (mc); tp_cli_connection_call_request_channel (priv->connection, -1, TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE, 0, TRUE, tp_roomlist_request_channel_cb, NULL, NULL, list); }
int main (int argc, char *argv[]) { guint32 startup_timestamp; EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; GtkWidget *window; MissionControl *mc; EmpathyIdle *idle; gboolean autoconnect = TRUE; gboolean no_connect = FALSE; gboolean hide_contact_list = FALSE; gboolean accounts_dialog = FALSE; GError *error = NULL; GOptionEntry options[] = { { "no-connect", 'n', 0, G_OPTION_ARG_NONE, &no_connect, N_("Don't connect on startup"), NULL }, { "hide-contact-list", 'h', 0, G_OPTION_ARG_NONE, &hide_contact_list, N_("Don't show the contact list on startup"), NULL }, { "accounts", 'a', 0, G_OPTION_ARG_NONE, &accounts_dialog, N_("Show the accounts dialog"), NULL }, { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL }, { NULL } }; /* Init */ g_thread_init (NULL); empathy_init (); if (!gtk_init_with_args (&argc, &argv, N_("- Empathy Instant Messenger"), options, GETTEXT_PACKAGE, &error)) { g_warning ("Error in empathy init: %s", error->message); return EXIT_FAILURE; } empathy_gtk_init (); g_set_application_name (_(PACKAGE_NAME)); gst_init (&argc, &argv); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); /* Setting up the bacon connection */ startup_timestamp = get_startup_timestamp (); connection = bacon_message_connection_new ("empathy"); if (connection != NULL) { if (!bacon_message_connection_get_is_server (connection)) { gchar *message; if (accounts_dialog) { DEBUG ("Showing accounts dialog from existing Empathy instance"); message = g_strdup ("accounts"); } else { DEBUG ("Activating existing instance"); message = g_strdup_printf ("%" G_GUINT32_FORMAT, startup_timestamp); } bacon_message_connection_send (connection, message); /* We never popup a window, so tell startup-notification * that we are done. */ gdk_notify_startup_complete (); g_free (message); bacon_message_connection_free (connection); return EXIT_SUCCESS; } } else { g_warning ("Cannot create the 'empathy' bacon connection."); } /* Setting up MC */ mc = empathy_mission_control_dup_singleton (); g_signal_connect (mc, "ServiceEnded", G_CALLBACK (service_ended_cb), NULL); g_signal_connect (mc, "Error", G_CALLBACK (operation_error_cb), NULL); if (accounts_dialog) { GtkWidget *dialog; dialog = empathy_accounts_dialog_show (NULL, NULL); g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_main (); return 0; } /* Setting up Idle */ idle = empathy_idle_dup_singleton (); empathy_idle_set_auto_away (idle, TRUE); use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle); empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM, use_nm_notify_cb, idle); /* Autoconnect */ empathy_conf_get_bool (empathy_conf_get(), EMPATHY_PREFS_AUTOCONNECT, &autoconnect); if (autoconnect && ! no_connect && empathy_idle_get_state (idle) <= MC_PRESENCE_OFFLINE) { empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE); } create_salut_account (); /* Setting up UI */ window = empathy_main_window_show (); icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list); if (connection) { /* We se the callback here because we need window */ bacon_message_connection_set_callback (connection, on_bacon_message_received, window); } /* Handle channels */ dispatcher = empathy_dispatcher_dup_singleton (); g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL); chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); empathy_chatroom_manager_observe (chatroom_manager, dispatcher); notify_init (_(PACKAGE_NAME)); /* Create the call factory */ call_factory = empathy_call_factory_initialise (); g_signal_connect (G_OBJECT (call_factory), "new-call-handler", G_CALLBACK (new_call_handler_cb), NULL); gtk_main (); empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE); g_object_unref (mc); g_object_unref (idle); g_object_unref (icon); g_object_unref (dispatcher); g_object_unref (chatroom_manager); notify_uninit (); return EXIT_SUCCESS; }
EmpathyTpTube * empathy_tp_tube_new_stream_tube (EmpathyContact *contact, TpSocketAddressType type, const gchar *hostname, guint port, const gchar *service, GHashTable *parameters) { MissionControl *mc; McAccount *account; TpConnection *connection; TpChannel *channel; gchar *object_path; GHashTable *params; GValue *address; GValue *control_param; EmpathyTpTube *tube = NULL; GError *error = NULL; GHashTable *request; GHashTable *channel_properties; GValue *value; g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); g_return_val_if_fail (hostname != NULL, NULL); g_return_val_if_fail (service != NULL, NULL); mc = empathy_mission_control_dup_singleton (); account = empathy_contact_get_account (contact); connection = mission_control_get_tpconnection (mc, account, NULL); g_object_unref (mc); tp_connection_run_until_ready (connection, FALSE, NULL, NULL); request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); /* org.freedesktop.Telepathy.Channel.ChannelType */ value = tp_g_value_slice_new (G_TYPE_STRING); g_value_set_string (value, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE); g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value); /* org.freedesktop.Telepathy.Channel.TargetHandleType */ value = tp_g_value_slice_new (G_TYPE_UINT); g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT); g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value); /* org.freedesktop.Telepathy.Channel.TargetHandleType */ value = tp_g_value_slice_new (G_TYPE_UINT); g_value_set_uint (value, empathy_contact_get_handle (contact)); g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value); /* org.freedesktop.Telepathy.Channel.Type.StreamTube.Service */ value = tp_g_value_slice_new (G_TYPE_STRING); g_value_set_string (value, service); g_hash_table_insert (request, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE ".Service", value); if (!tp_cli_connection_interface_requests_run_create_channel (connection, -1, request, &object_path, &channel_properties, &error, NULL)) { DEBUG ("Error requesting channel: %s", error->message); g_clear_error (&error); g_object_unref (connection); return NULL; } DEBUG ("Offering a new stream tube"); channel = tp_channel_new_from_properties (connection, object_path, channel_properties, NULL); tp_channel_run_until_ready (channel, NULL, NULL); #define ADDRESS_TYPE dbus_g_type_get_struct ("GValueArray",\ G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID) params = g_hash_table_new (g_str_hash, g_str_equal); address = tp_g_value_slice_new (ADDRESS_TYPE); g_value_take_boxed (address, dbus_g_type_specialized_construct (ADDRESS_TYPE)); dbus_g_type_struct_set (address, 0, hostname, 1, port, G_MAXUINT); control_param = tp_g_value_slice_new (G_TYPE_STRING); if (!emp_cli_channel_type_stream_tube_run_offer_stream_tube ( TP_PROXY(channel), -1, type, address, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, parameters, &error, NULL)) { DEBUG ("Couldn't offer tube: %s", error->message); g_clear_error (&error); goto OUT; } DEBUG ("Stream tube offered"); tube = empathy_tp_tube_new (channel); OUT: g_object_unref (channel); g_free (object_path); g_hash_table_destroy (request); g_hash_table_destroy (channel_properties); tp_g_value_slice_free (address); tp_g_value_slice_free (control_param); g_object_unref (connection); return tube; }
static void debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser, EmpathyDebugDialog *debug_dialog) { EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog); MissionControl *mc; TpDBusDaemon *dbus; GError *error = NULL; gchar *bus_name; TpProxy *proxy; GtkTreeIter iter; if (!gtk_combo_box_get_active_iter (cm_chooser, &iter)) { DEBUG ("No CM is selected"); if (gtk_tree_model_iter_n_children ( GTK_TREE_MODEL (priv->cms), NULL) > 0) { gtk_combo_box_set_active (cm_chooser, 0); } return; } mc = empathy_mission_control_dup_singleton (); dbus = tp_dbus_daemon_dup (&error); if (error != NULL) { DEBUG ("Failed at duping the dbus daemon: %s", error->message); g_object_unref (mc); } gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter, COL_CM_UNIQUE_NAME, &bus_name, -1); proxy = g_object_new (TP_TYPE_PROXY, "bus-name", bus_name, "dbus-daemon", dbus, "object-path", DEBUG_OBJECT_PATH, NULL); g_free (bus_name); gtk_list_store_clear (priv->store); /* Disable debug signalling */ if (priv->proxy != NULL) debug_dialog_set_enabled (debug_dialog, FALSE); /* Disconnect from previous NewDebugMessage signal */ if (priv->new_debug_message_signal != NULL) { tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal); priv->new_debug_message_signal = NULL; } if (priv->proxy != NULL) g_object_unref (priv->proxy); priv->proxy = proxy; tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ()); emp_cli_debug_call_get_messages (priv->proxy, -1, debug_dialog_get_messages_cb, debug_dialog, NULL, NULL); g_object_unref (dbus); g_object_unref (mc); }