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,
50 EmpathyIndividualManager *individual_manager;
51 TpConnection *connection;
54 connection = tp_account_get_connection (account);
55 if (connection == NULL)
58 individual_manager = empathy_individual_manager_dup_singleton ();
59 result = empathy_individual_manager_get_flags_for_connection (
60 individual_manager, connection) & EMPATHY_INDIVIDUAL_MANAGER_CAN_ADD;
61 g_object_unref (individual_manager);
67 new_individual_response_cb (GtkDialog *dialog,
69 GtkWidget *contact_widget)
71 EmpathyIndividualManager *individual_manager;
72 EmpathyContact *contact;
74 individual_manager = empathy_individual_manager_dup_singleton ();
75 contact = empathy_contact_widget_get_contact (contact_widget);
77 if (contact && response == GTK_RESPONSE_OK)
78 empathy_individual_manager_add_from_contact (individual_manager, contact);
80 new_individual_dialog = NULL;
81 gtk_widget_destroy (GTK_WIDGET (dialog));
82 g_object_unref (individual_manager);
86 empathy_new_individual_dialog_show (GtkWindow *parent)
88 empathy_new_individual_dialog_show_with_individual (parent, NULL);
92 empathy_new_individual_dialog_show_with_individual (GtkWindow *parent,
93 FolksIndividual *individual)
97 EmpathyContact *contact = NULL;
98 GtkWidget *contact_widget;
100 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
102 if (new_individual_dialog)
104 gtk_window_present (GTK_WINDOW (new_individual_dialog));
109 dialog = gtk_dialog_new ();
110 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
111 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
112 gtk_window_set_title (GTK_WINDOW (dialog), _("New Contact"));
115 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
116 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
117 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
118 GTK_RESPONSE_CANCEL);
119 gtk_widget_show (button);
122 button = gtk_button_new_with_label (GTK_STOCK_ADD);
123 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
124 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
125 gtk_widget_show (button);
127 /* Contact info widget */
128 if (individual != NULL)
129 contact = empathy_contact_dup_from_folks_individual (individual);
131 contact_widget = empathy_contact_widget_new (contact,
132 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
133 EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
134 EMPATHY_CONTACT_WIDGET_EDIT_ID |
135 EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
136 gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
138 GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
139 contact_widget, TRUE, TRUE, 0);
140 empathy_contact_widget_set_account_filter (contact_widget,
141 can_add_contact_to_account, NULL);
142 gtk_widget_show (contact_widget);
144 new_individual_dialog = dialog;
146 g_signal_connect (dialog, "response", G_CALLBACK (new_individual_response_cb),
150 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
152 gtk_widget_show (dialog);
154 tp_clear_object (&contact);