/*
* Copyright (C) 2007 Collabora Ltd.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
return information->contact;
}
+
+void
+empathy_contact_widget_set_contact (GtkWidget *widget,
+ EmpathyContact *contact)
+{
+ EmpathyContactWidget *information;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+ information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
+ if (!information) {
+ return;
+ }
+
+ contact_widget_set_contact (information, contact);
+}
+
+void
+empathy_contact_widget_set_account_filter (GtkWidget *widget,
+ EmpathyAccountChooserFilterFunc filter,
+ gpointer user_data)
+{
+ EmpathyContactWidget *information;
+ EmpathyAccountChooser *chooser;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
+ if (!information) {
+ return;
+ }
+
+ chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
+ if (chooser) {
+ empathy_account_chooser_set_filter (chooser, filter, user_data);
+ }
+}
static void
contact_widget_destroy_cb (GtkWidget *widget,
contact_widget_set_contact (EmpathyContactWidget *information,
EmpathyContact *contact)
{
+ if (contact == information->contact ||
+ (contact && information->contact &&
+ empathy_contact_equal (contact, information->contact))) {
+ return;
+ }
+
contact_widget_remove_contact (information);
if (contact) {
information->contact = g_object_ref (contact);
contact_widget_client_update (information);
}
-static gboolean
-contact_widget_can_add_contact_to_account (McAccount *account,
- gpointer user_data)
-{
- MissionControl *mc;
- TpConn *tp_conn;
- McProfile *profile;
- const gchar *protocol_name;
-
- mc = empathy_mission_control_new ();
- tp_conn = mission_control_get_connection (mc, account, NULL);
- g_object_unref (mc);
- if (tp_conn == NULL) {
- /* Account is disconnected */
- return FALSE;
- }
- g_object_unref (tp_conn);
-
- profile = mc_account_get_profile (account);
- protocol_name = mc_profile_get_protocol_name (profile);
- if (strcmp (protocol_name, "local-xmpp") == 0) {
- /* We can't add accounts to a XMPP LL connection
- * FIXME: We should inspect the flags of the contact list group interface
- */
- g_object_unref (profile);
- return FALSE;
- }
-
- g_object_unref (profile);
- return TRUE;
-}
-
static gboolean
contact_widget_id_activate_timeout (EmpathyContactWidget *self)
{
/* Setup account label/chooser */
if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
information->widget_account = empathy_account_chooser_new ();
- empathy_account_chooser_set_filter (
- EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
- contact_widget_can_add_contact_to_account,
- NULL);
g_signal_connect (information->widget_account, "changed",
G_CALLBACK (contact_widget_account_changed_cb),
contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
EmpathyContactWidget *information)
{
- McAccount *account;
- gchar *data;
- gsize size;
+ if (information->contact &&
+ empathy_contact_is_user (information->contact)) {
+ McAccount *account;
+ const gchar *data;
+ gsize size;
+ const gchar *mime_type;
- account = empathy_contact_get_account (information->contact);
- empathy_avatar_chooser_get_image_data (EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
- &data, &size);
- mc_account_set_avatar_from_data (account, data, size, "png");
+ account = empathy_contact_get_account (information->contact);
+ empathy_avatar_chooser_get_image_data (EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
+ &data, &size, &mime_type);
+ empathy_contact_factory_set_avatar (information->factory,
+ account,
+ data, size, mime_type);
+ }
}
static void
EmpathyContactWidget *information)
{
if (information->contact) {
- const gchar *name;
+ const gchar *alias;
- name = gtk_entry_get_text (GTK_ENTRY (editable));
- empathy_contact_factory_set_name (information->factory,
+ alias = gtk_entry_get_text (GTK_ENTRY (editable));
+ empathy_contact_factory_set_alias (information->factory,
information->contact,
- name);
+ alias);
}
return FALSE;