* Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
*/
-#include <glib/gi18n.h>
-
-#include <telepathy-glib/telepathy-glib.h>
+#include "config.h"
+#include "empathy-contact-search-dialog.h"
-#include <libempathy/empathy-contact-manager.h>
-#include <libempathy/empathy-tp-contact-factory.h>
+#include <glib/gi18n-lib.h>
-#include <libempathy-gtk/empathy-account-chooser.h>
-#include <libempathy-gtk/empathy-cell-renderer-text.h>
-#include <libempathy-gtk/empathy-cell-renderer-activatable.h>
-#include <libempathy-gtk/empathy-contact-dialogs.h>
-#include <libempathy-gtk/empathy-images.h>
+#include "empathy-account-chooser.h"
+#include "empathy-cell-renderer-activatable.h"
+#include "empathy-cell-renderer-text.h"
+#include "empathy-client-factory.h"
+#include "empathy-images.h"
+#include "empathy-individual-information-dialog.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
#include "empathy-contact-search-dialog.h"
enum {
PAGE_SEARCH_RESULTS,
- PAGE_NO_MATCH
+ PAGE_NO_MATCH,
+ PAGE_NOT_SUPPORTED,
};
typedef struct _EmpathyContactSearchDialogPrivate EmpathyContactSearchDialogPrivate;
GtkWidget *spinner;
GtkWidget *add_button;
GtkWidget *find_button;
- GtkWidget *no_contact_found;
GtkWidget *search_entry;
/* GtkWidget *server_entry; */
+ GtkWidget *message;
+ GtkWidget *message_window;
+ GtkWidget *message_label;
};
static void
if (error != NULL)
{
DEBUG ("Failed to reset the TpContactSearch: %s", error->message);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ PAGE_NOT_SUPPORTED);
+
g_error_free (error);
return;
}
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ PAGE_SEARCH_RESULTS);
+
search = g_hash_table_new (g_str_hash, g_str_equal);
search_criteria = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
gtk_list_store_clear (priv->store);
tp_contact_search_start (priv->searcher, search);
- g_hash_table_destroy (search);
+ g_hash_table_unref (search);
}
static void
}
static void
-on_get_contact_factory_get_from_id_cb (TpConnection *connection,
- EmpathyContact *contact,
- const GError *error,
- gpointer user_data,
- GObject *object)
+on_get_contact_factory_get_from_id_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
+ gchar *message = user_data;
+ GError *error = NULL;
+ EmpathyContact *contact;
- if (error != NULL)
- {
- g_warning ("Error while getting the contact: %s", error->message);
- return;
- }
+ contact = empathy_client_factory_dup_contact_by_id_finish (
+ EMPATHY_CLIENT_FACTORY (source), result, &error);
+ if (contact == NULL)
+ {
+ g_warning ("Error while getting the contact: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
- empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager), contact, "");
+ empathy_contact_add_to_contact_list (contact, message);
+ g_object_unref (contact);
+
+out:
+ g_free (message);
}
static void
TpConnection *conn;
GtkTreeIter iter;
GtkTreeModel *model;
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+ gchar *message;
gboolean sel;
gchar *id;
+ EmpathyClientFactory *factory;
conn = empathy_account_chooser_get_connection (EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
DEBUG ("Requested to add contact: %s", id);
- empathy_tp_contact_factory_get_from_id (conn, id,
- on_get_contact_factory_get_from_id_cb, NULL,
- NULL, NULL);
+ buffer = gtk_text_view_get_buffer GTK_TEXT_VIEW (priv->message);
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+
+ factory = empathy_client_factory_dup ();
+
+ empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
+ on_get_contact_factory_get_from_id_cb, message);
+
+ g_object_unref (factory);
+
+ /* Close the dialog */
+ gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
}
static void
for (l = results; l != NULL; l = l->next)
{
TpContactSearchResult *result = l->data;
- GtkTreeIter iter;
-
- gtk_list_store_append (priv->store, &iter);
name = tp_contact_search_result_get_field (result, "fn");
- gtk_list_store_set (priv->store, &iter,
+ gtk_list_store_insert_with_values (priv->store, NULL, -1,
NAME_COLUMN, name ? name->field_value[0] : NULL,
LOGIN_COLUMN, tp_contact_search_result_get_identifier (result),
-1);
if (error != NULL)
{
DEBUG ("Failed to create a TpContactSearch: %s", error->message);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ PAGE_NOT_SUPPORTED);
+
g_error_free (error);
return;
}
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ PAGE_SEARCH_RESULTS);
+
g_signal_connect (priv->searcher, "search-results-received",
G_CALLBACK (_search_results_received), self);
g_signal_connect (priv->searcher, "notify::state",
G_CALLBACK (_on_search_state_changed_cb), self);
gtk_widget_set_sensitive (priv->find_button, TRUE);
+ gtk_widget_set_sensitive (priv->search_entry, TRUE);
}
static void
gtk_widget_set_sensitive (priv->add_button, sel);
}
+static void
+check_request_message_available (EmpathyContactSearchDialog *self,
+ TpConnection *conn)
+{
+ EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
+
+ gtk_widget_set_visible (priv->message_window,
+ tp_connection_get_can_change_contact_list (conn));
+ gtk_widget_set_visible (priv->message_label,
+ tp_connection_get_can_change_contact_list (conn));
+}
static void
_account_chooser_changed (EmpathyAccountChooser *chooser,
/* gtk_widget_set_sensitive (priv->server_entry, can_set_server); */
gtk_widget_set_sensitive (priv->find_button, FALSE);
+ gtk_widget_set_sensitive (priv->search_entry, FALSE);
DEBUG ("New account is %s", tp_proxy_get_object_path (account));
NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
0,
on_searcher_created, self);
+
+ /* Make the request message textview sensitive if it can be used */
+ check_request_message_available (self, conn);
}
static void
}
#endif
-typedef struct
-{
- EmpathyAccountChooserFilterResultCallback callback;
- gpointer user_data;
-} FilterCallbackData;
-
-static void
-supports_contact_search_cb (GObject *conn,
- GAsyncResult *result,
- gpointer user_data)
-{
- FilterCallbackData *data = user_data;
- GError *myerr = NULL;
- TpCapabilities *caps;
-
- if (!tp_proxy_prepare_finish (conn, result, &myerr))
- {
- data->callback (FALSE, data->user_data);
- g_slice_free (FilterCallbackData, data);
- return;
- }
-
- caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
- data->callback (tp_capabilities_supports_contact_search (caps, NULL, NULL),
- data->user_data);
-
- g_slice_free (FilterCallbackData, data);
-}
-
static void
empathy_account_chooser_filter_supports_contact_search (
TpAccount *account,
gpointer user_data)
{
TpConnection *connection;
- FilterCallbackData *cb_data;
- GQuark features[] = { TP_CONNECTION_FEATURE_CAPABILITIES, 0 };
-
- if (tp_account_get_connection_status (account, NULL)
- != TP_CONNECTION_STATUS_CONNECTED)
- {
- callback (FALSE, callback_data);
- return;
- }
+ gboolean supported = FALSE;
+ TpCapabilities *caps;
- /* check if CM supports contact search */
connection = tp_account_get_connection (account);
if (connection == NULL)
- {
- callback (FALSE, callback_data);
- return;
- }
+ goto out;
- cb_data = g_slice_new0 (FilterCallbackData);
- cb_data->callback = callback;
- cb_data->user_data = callback_data;
+ caps = tp_connection_get_capabilities (connection);
+ if (caps == NULL)
+ goto out;
- tp_proxy_prepare_async (connection, features, supports_contact_search_cb,
- cb_data);
+ supported = tp_capabilities_supports_contact_search (caps, NULL, NULL);
+
+out:
+ callback (supported, callback_data);
}
static void
}
static void
-on_profile_button_got_contact_cb (TpConnection *connection,
- EmpathyContact *contact,
- const GError *error,
- gpointer user_data,
- GObject *object)
+on_profile_button_got_contact_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- if (error != NULL)
- {
- g_warning ("Error while getting the contact: %s", error->message);
- return;
- }
+ GError *error = NULL;
+ EmpathyContact *contact;
+ FolksIndividual *individual;
+
+ contact = empathy_client_factory_dup_contact_by_id_finish (
+ EMPATHY_CLIENT_FACTORY (source), result, &error);
+ if (contact == NULL)
+ {
+ g_warning ("Error while getting the contact: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ individual = empathy_ensure_individual_from_tp_contact (
+ empathy_contact_get_tp_contact (contact));
- empathy_contact_information_dialog_show (contact, NULL);
+ empathy_display_individual_info (individual);
+
+ g_object_unref (contact);
+ g_object_unref (individual);
}
static void
GtkTreeModel *model;
gboolean valid;
gchar *id;
+ EmpathyClientFactory *factory;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree_view));
DEBUG ("Requested to show profile for contact: %s", id);
- empathy_tp_contact_factory_get_from_id (conn, id,
- on_profile_button_got_contact_cb, NULL,
- NULL, NULL);
+ factory = empathy_client_factory_dup ();
+
+ empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
+ on_profile_button_got_contact_cb, self);
+
+ g_object_unref (factory);
+}
+
+static void
+append_message_page (EmpathyContactSearchDialog *self,
+ const gchar *message)
+{
+ EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
+ GtkWidget *label;
+ gchar *tmp;
+
+ label = gtk_label_new (NULL);
+ tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>", message);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), label, NULL);
}
static void
GtkTreeViewColumn *col;
GtkTreeSelection *selection;
GtkSizeGroup *size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gchar *tmp;
/* Title */
gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
- vbox = gtk_vbox_new (FALSE, 3);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
/* Account chooser */
- hbox = gtk_hbox_new (FALSE, 6);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
label = gtk_label_new (_("Account:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
gtk_size_group_add_widget (size_group, label);
#endif
/* Search input */
- hbox = gtk_hbox_new (FALSE, 6);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
label = gtk_label_new (_("Search: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
gtk_size_group_add_widget (size_group, label);
gtk_container_add (GTK_CONTAINER (scrolled_window), priv->tree_view);
- priv->no_contact_found = gtk_label_new (NULL);
- tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
- _("No contacts found"));
- gtk_label_set_markup (GTK_LABEL (priv->no_contact_found), tmp);
- g_free (tmp);
-
- gtk_label_set_ellipsize (GTK_LABEL (priv->no_contact_found),
- PANGO_ELLIPSIZE_END);
-
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window,
NULL);
- gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
- priv->no_contact_found, NULL);
+
+ append_message_page (self, _("No contacts found"));
+ append_message_page (self, _("Contact search is not supported on this account"));
gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
+ /* Request message textview */
+ priv->message_label = gtk_label_new (
+ _("Your message introducing yourself:"));
+ gtk_misc_set_alignment (GTK_MISC (priv->message_label), 0, 0.5);
+
+ priv->message = gtk_text_view_new ();
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->message),
+ GTK_WRAP_WORD_CHAR);
+ gtk_text_buffer_set_text (
+ gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->message)),
+ _("Please let me see when you're online. Thanks!"), -1);
+
+ priv->message_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (
+ GTK_SCROLLED_WINDOW (priv->message_window),
+ GTK_SHADOW_ETCHED_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->message_window),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+
+ gtk_container_add (GTK_CONTAINER (priv->message_window), priv->message);
+
+ gtk_box_pack_start (GTK_BOX (vbox), priv->message_label, FALSE, TRUE, 3);
+ gtk_box_pack_start (GTK_BOX (vbox), priv->message_window, FALSE, TRUE, 3);
+
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
gtk_window_set_default_size (GTK_WINDOW (self), 200, 400);
gtk_widget_show_all (vbox);
gtk_widget_hide (priv->spinner);
+ g_object_unref (size_group);
}
GtkWidget *