2 * Copyright (C) 2010 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Philip Withnall <philip.withnall@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <folks/folks.h>
30 #include <folks/folks-telepathy.h>
32 #include <libempathy/empathy-individual-manager.h>
33 #include <libempathy/empathy-utils.h>
35 #include "empathy-linking-dialog.h"
36 #include "empathy-individual-linker.h"
37 #include "empathy-ui-utils.h"
40 * SECTION:empathy-individual-widget
41 * @title:EmpathyLinkingDialog
42 * @short_description: A dialog used to link individuals together
43 * @include: libempathy-empathy-linking-dialog.h
45 * #EmpathyLinkingDialog is a dialog which allows selection of individuals to
46 * link together, and preview of the newly linked individual. When submitted, it
47 * pushes the new links to backing storage.
51 * EmpathyLinkingDialog:
52 * @parent: parent object
54 * Widget which displays appropriate widgets with details about an individual,
55 * also allowing changing these details, if desired.
57 * Currently, it's just a thin wrapper around #EmpathyContactWidget, and
58 * displays the details of the first eligible persona found in the individual.
61 static GtkWidget *linking_dialog = NULL;
63 /* Fairly arbitrary response ID for the "Unlink" button */
64 #define RESPONSE_UNLINK 5
66 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLinkingDialog)
69 EmpathyIndividualLinker *linker; /* child widget */
70 GtkWidget *link_button; /* child widget */
71 } EmpathyLinkingDialogPriv;
73 G_DEFINE_TYPE (EmpathyLinkingDialog, empathy_linking_dialog,
77 linker_notify_has_changed_cb (EmpathyIndividualLinker *linker,
79 EmpathyLinkingDialog *self)
81 EmpathyLinkingDialogPriv *priv = GET_PRIV (self);
83 /* Only make the "Link" button sensitive if the linked Individual has been
85 gtk_widget_set_sensitive (priv->link_button,
86 empathy_individual_linker_get_has_changed (linker));
90 empathy_linking_dialog_class_init (EmpathyLinkingDialogClass *klass)
92 GObjectClass *object_class = G_OBJECT_CLASS (klass);
93 g_type_class_add_private (object_class, sizeof (EmpathyLinkingDialogPriv));
97 empathy_linking_dialog_init (EmpathyLinkingDialog *self)
99 EmpathyLinkingDialogPriv *priv;
102 GtkBox *content_area;
104 priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
105 EMPATHY_TYPE_LINKING_DIALOG, EmpathyLinkingDialogPriv);
108 dialog = GTK_DIALOG (self);
111 empathy_dialog_remove_separator (GTK_DIALOG (dialog));
112 gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
113 /* Translators: this is the title of the linking dialogue (reached by
114 * right-clicking on a contact and selecting "Link…"). "Link" in this title
116 gtk_window_set_title (GTK_WINDOW (self), _("Link Contacts"));
117 gtk_widget_set_size_request (GTK_WIDGET (self), 600, 500);
120 button = gtk_button_new_with_mnemonic (
121 C_("Unlink individual (button)", "_Unlink…"));
122 gtk_widget_set_tooltip_text (button, _("Completely split the displayed "
123 "meta-contact into the contacts it contains."));
124 gtk_dialog_add_action_widget (dialog, button, RESPONSE_UNLINK);
125 gtk_widget_show (button);
128 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
129 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
130 gtk_dialog_add_action_widget (dialog, button, GTK_RESPONSE_CANCEL);
131 gtk_widget_show (button);
134 /* Translators: this is an action button in the linking dialogue. "Link" is
135 * used here as a verb meaning "to connect two contacts to form a
137 priv->link_button = gtk_button_new_with_mnemonic (_("_Link"));
138 gtk_dialog_add_action_widget (dialog, priv->link_button, GTK_RESPONSE_OK);
139 gtk_widget_show (priv->link_button);
143 EMPATHY_INDIVIDUAL_LINKER (empathy_individual_linker_new (NULL));
144 g_signal_connect (priv->linker, "notify::has-changed",
145 (GCallback) linker_notify_has_changed_cb, self);
147 gtk_container_set_border_width (GTK_CONTAINER (priv->linker), 8);
148 content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
149 gtk_box_pack_start (content_area, GTK_WIDGET (priv->linker), TRUE, TRUE, 0);
150 gtk_widget_show (GTK_WIDGET (priv->linker));
154 linking_response_cb (EmpathyLinkingDialog *self,
158 EmpathyLinkingDialogPriv *priv = GET_PRIV (self);
160 if (response == GTK_RESPONSE_OK)
162 EmpathyIndividualManager *manager;
165 manager = empathy_individual_manager_dup_singleton ();
167 personas = empathy_individual_linker_get_linked_personas (priv->linker);
168 empathy_individual_manager_link_personas (manager, personas);
170 g_object_unref (manager);
172 else if (response == RESPONSE_UNLINK)
174 EmpathyIndividualManager *manager;
175 FolksIndividual *individual;
179 empathy_individual_linker_get_start_individual (priv->linker);
181 /* Show a confirmation dialogue first */
182 dialog = gtk_message_dialog_new (GTK_WINDOW (self), GTK_DIALOG_MODAL,
183 GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("Unlink meta-contact '%s'?"),
184 folks_individual_get_alias (individual));
185 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
186 _("Are you sure you want to unlink this meta-contact? This will "
187 "completely split the meta-contact into the contacts it "
189 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
190 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
191 C_("Unlink individual (button)", "_Unlink"), GTK_RESPONSE_OK,
194 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
196 gtk_widget_destroy (dialog);
200 gtk_widget_destroy (dialog);
202 manager = empathy_individual_manager_dup_singleton ();
203 empathy_individual_manager_unlink_individual (manager, individual);
204 g_object_unref (manager);
207 linking_dialog = NULL;
208 gtk_widget_destroy (GTK_WIDGET (self));
212 * empathy_linking_dialog_show:
213 * @individual: the #FolksIndividual to start linking against
214 * @parent: a parent window for the dialogue, or %NULL
216 * Create and show the linking dialogue, with @individual selected as the
217 * individual to link to. If the dialogue is already being shown, raise it and
218 * reset it so the start individual is @individual.
220 * Return value: the linking dialog
223 empathy_linking_dialog_show (FolksIndividual *individual,
226 EmpathyLinkingDialogPriv *priv;
228 guint num_personas = 0;
230 /* Create the dialogue if it doesn't exist */
231 if (linking_dialog == NULL)
233 linking_dialog = GTK_WIDGET (g_object_new (EMPATHY_TYPE_LINKING_DIALOG,
236 g_signal_connect (linking_dialog, "response",
237 (GCallback) linking_response_cb, NULL);
240 priv = GET_PRIV (linking_dialog);
243 gtk_window_set_transient_for (GTK_WINDOW (linking_dialog), parent);
245 empathy_individual_linker_set_start_individual (priv->linker, individual);
247 /* Count how many Telepathy personas we have, to see whether we can
249 personas = folks_individual_get_personas (individual);
250 for (l = personas; l != NULL; l = l->next)
252 if (TPF_IS_PERSONA (l->data))
256 /* Only make the "Unlink" button sensitive if we have enough personas */
257 gtk_dialog_set_response_sensitive (GTK_DIALOG (linking_dialog),
258 RESPONSE_UNLINK, (num_personas > 1) ? TRUE : FALSE);
260 gtk_window_present (GTK_WINDOW (linking_dialog));
262 return linking_dialog;
265 EmpathyIndividualLinker *
266 empathy_linking_dialog_get_individual_linker (EmpathyLinkingDialog *self)
268 g_return_val_if_fail (EMPATHY_IS_LINKING_DIALOG (self), NULL);
270 return GET_PRIV (self)->linker;