1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glib/gi18n-lib.h>
30 #include <telepathy-glib/util.h>
31 #include <folks/folks.h>
33 #include <libempathy/empathy-individual-manager.h>
34 #include <libempathy/empathy-utils.h>
36 #include "empathy-individual-dialogs.h"
37 #include "empathy-contact-widget.h"
38 #include "empathy-ui-utils.h"
40 static GtkWidget *new_individual_dialog = NULL;
47 can_add_contact_to_account (TpAccount *account,
48 EmpathyAccountChooserFilterResultCallback callback,
49 gpointer callback_data,
52 EmpathyIndividualManager *individual_manager;
53 TpConnection *connection;
56 connection = tp_account_get_connection (account);
57 if (connection == NULL)
59 callback (FALSE, callback_data);
63 individual_manager = empathy_individual_manager_dup_singleton ();
64 result = empathy_connection_can_add_personas (connection);
65 g_object_unref (individual_manager);
67 callback (result, callback_data);
71 new_individual_response_cb (GtkDialog *dialog,
73 GtkWidget *contact_widget)
75 EmpathyIndividualManager *individual_manager;
76 EmpathyContact *contact;
78 individual_manager = empathy_individual_manager_dup_singleton ();
79 contact = empathy_contact_widget_get_contact (contact_widget);
81 if (contact && response == GTK_RESPONSE_OK)
82 empathy_individual_manager_add_from_contact (individual_manager, contact);
84 new_individual_dialog = NULL;
85 gtk_widget_destroy (GTK_WIDGET (dialog));
86 g_object_unref (individual_manager);
90 empathy_new_individual_dialog_show (GtkWindow *parent)
92 empathy_new_individual_dialog_show_with_individual (parent, NULL);
96 empathy_new_individual_dialog_show_with_individual (GtkWindow *parent,
97 FolksIndividual *individual)
101 EmpathyContact *contact = NULL;
102 GtkWidget *contact_widget;
104 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
106 if (new_individual_dialog)
108 gtk_window_present (GTK_WINDOW (new_individual_dialog));
113 dialog = gtk_dialog_new ();
114 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
115 gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
118 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
119 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
120 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
121 GTK_RESPONSE_CANCEL);
122 gtk_widget_show (button);
125 button = gtk_button_new_with_label (GTK_STOCK_ADD);
126 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
127 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
128 gtk_widget_show (button);
130 /* Contact info widget */
131 if (individual != NULL)
132 contact = empathy_contact_dup_from_folks_individual (individual);
134 contact_widget = empathy_contact_widget_new (contact,
135 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
136 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
137 EMPATHY_CONTACT_WIDGET_EDIT_ID |
138 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
139 gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
141 GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
142 contact_widget, TRUE, TRUE, 0);
143 empathy_contact_widget_set_account_filter (contact_widget,
144 can_add_contact_to_account, NULL);
145 gtk_widget_show (contact_widget);
147 new_individual_dialog = dialog;
149 g_signal_connect (dialog, "response", G_CALLBACK (new_individual_response_cb),
153 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
155 gtk_widget_show (dialog);
157 tp_clear_object (&contact);