+enum {
+ COMPLETION_COL_TEXT,
+ COMPLETION_COL_ID,
+ COMPLETION_COL_NAME,
+} CompletionCol;
+
+static void
+new_message_dialog_account_changed_cb (GtkWidget *widget,
+ EmpathyNewMessageDialog *dialog)
+{
+ EmpathyAccountChooser *chooser;
+ TpConnection *connection;
+ EmpathyTpContactList *contact_list;
+ GList *members;
+ GtkListStore *store;
+ GtkEntryCompletion *completion;
+ GtkTreeIter iter;
+ gchar *tmpstr;
+
+ /* Remove completions */
+ completion = gtk_entry_get_completion (GTK_ENTRY (dialog->entry_id));
+ store = GTK_LIST_STORE (gtk_entry_completion_get_model (completion));
+ gtk_list_store_clear (store);
+
+ /* Get members of the new account */
+ chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
+ connection = empathy_account_chooser_get_connection (chooser);
+ if (!connection) {
+ return;
+ }
+ contact_list = empathy_contact_manager_get_list (dialog->contact_manager,
+ connection);
+ members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (contact_list));
+
+ /* Add members to the completion */
+ while (members) {
+ EmpathyContact *contact = members->data;
+
+ if (empathy_contact_is_online (contact)) {
+ DEBUG ("Adding contact ID %s, Name %s",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_name (contact));
+
+ tmpstr = g_strdup_printf ("%s (%s)",
+ empathy_contact_get_name (contact),
+ empathy_contact_get_id (contact));
+
+ gtk_list_store_insert_with_values (store, &iter, -1,
+ COMPLETION_COL_TEXT, tmpstr,
+ COMPLETION_COL_ID, empathy_contact_get_id (contact),
+ COMPLETION_COL_NAME, empathy_contact_get_name (contact),
+ -1);
+
+ g_free (tmpstr);
+ }
+
+ g_object_unref (contact);
+ members = g_list_delete_link (members, members);
+ }
+}
+
+static gboolean
+new_message_dialog_match_selected_cb (GtkEntryCompletion *widget,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ EmpathyNewMessageDialog *dialog)
+{
+ gchar *id;
+
+ if (!iter || !model) {
+ return FALSE;
+ }
+
+ gtk_tree_model_get (model, iter, COMPLETION_COL_ID, &id, -1);
+ gtk_entry_set_text (GTK_ENTRY (dialog->entry_id), id);
+
+ DEBUG ("Got selected match **%s**", id);
+
+ g_free (id);
+
+ return TRUE;
+}
+
+static gboolean
+new_message_dialog_match_func (GtkEntryCompletion *completion,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ GtkTreeModel *model;
+ gchar *id;
+ gchar *name;
+
+ model = gtk_entry_completion_get_model (completion);
+ if (!model || !iter) {
+ return FALSE;
+ }
+
+ gtk_tree_model_get (model, iter, COMPLETION_COL_NAME, &name, -1);
+ if (strstr (name, key)) {
+ DEBUG ("Key %s is matching name **%s**", key, name);
+ g_free (name);
+ return TRUE;
+ }
+ g_free (name);
+
+ gtk_tree_model_get (model, iter, COMPLETION_COL_ID, &id, -1);
+ if (strstr (id, key)) {
+ DEBUG ("Key %s is matching ID **%s**", key, id);
+ g_free (id);
+ return TRUE;
+ }
+ g_free (id);
+
+ return FALSE;
+}
+
+static void
+new_message_dialog_call_got_contact_cb (EmpathyTpContactFactory *factory,
+ EmpathyContact *contact,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyCallFactory *call_factory;
+
+ if (error != NULL) {
+ DEBUG ("Error: %s", error->message);
+ return;
+ }
+
+ call_factory = empathy_call_factory_get();
+ empathy_call_factory_new_call (call_factory, contact);
+}