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 gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
112 /* Translators: this is the title of the linking dialogue (reached by
113 * right-clicking on a contact and selecting "Link…"). "Link" in this title
115 gtk_window_set_title (GTK_WINDOW (self), _("Link Contacts"));
116 gtk_widget_set_size_request (GTK_WIDGET (self), 600, 500);
119 button = gtk_button_new_with_mnemonic (
120 C_("Unlink individual (button)", "_Unlink…"));
121 gtk_widget_set_tooltip_text (button, _("Completely split the displayed "
122 "meta-contact into the contacts it contains."));
123 gtk_dialog_add_action_widget (dialog, button, RESPONSE_UNLINK);
124 gtk_widget_show (button);
127 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
128 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
129 gtk_dialog_add_action_widget (dialog, button, GTK_RESPONSE_CANCEL);
130 gtk_widget_show (button);
133 /* Translators: this is an action button in the linking dialogue. "Link" is
134 * used here as a verb meaning "to connect two contacts to form a
136 priv->link_button = gtk_button_new_with_mnemonic (_("_Link"));
137 gtk_dialog_add_action_widget (dialog, priv->link_button, GTK_RESPONSE_OK);
138 gtk_widget_show (priv->link_button);
142 EMPATHY_INDIVIDUAL_LINKER (empathy_individual_linker_new (NULL));
143 g_signal_connect (priv->linker, "notify::has-changed",
144 (GCallback) linker_notify_has_changed_cb, self);
146 gtk_container_set_border_width (GTK_CONTAINER (priv->linker), 8);
147 content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
148 gtk_box_pack_start (content_area, GTK_WIDGET (priv->linker), TRUE, TRUE, 0);
149 gtk_widget_show (GTK_WIDGET (priv->linker));
153 linking_response_cb (EmpathyLinkingDialog *self,
157 EmpathyLinkingDialogPriv *priv = GET_PRIV (self);
159 if (response == GTK_RESPONSE_OK)
161 EmpathyIndividualManager *manager;
164 manager = empathy_individual_manager_dup_singleton ();
166 personas = empathy_individual_linker_get_linked_personas (priv->linker);
167 empathy_individual_manager_link_personas (manager, personas);
169 g_object_unref (manager);
171 else if (response == RESPONSE_UNLINK)
173 EmpathyIndividualManager *manager;
174 FolksIndividual *individual;
178 empathy_individual_linker_get_start_individual (priv->linker);
180 /* Show a confirmation dialogue first */
181 dialog = gtk_message_dialog_new (GTK_WINDOW (self), GTK_DIALOG_MODAL,
182 GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("Unlink meta-contact '%s'?"),
183 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
184 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
185 _("Are you sure you want to unlink this meta-contact? This will "
186 "completely split the meta-contact into the contacts it "
188 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
189 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
190 C_("Unlink individual (button)", "_Unlink"), GTK_RESPONSE_OK,
193 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
195 gtk_widget_destroy (dialog);
199 gtk_widget_destroy (dialog);
201 manager = empathy_individual_manager_dup_singleton ();
202 empathy_individual_manager_unlink_individual (manager, individual);
203 g_object_unref (manager);
206 linking_dialog = NULL;
207 gtk_widget_destroy (GTK_WIDGET (self));
211 * empathy_linking_dialog_show:
212 * @individual: the #FolksIndividual to start linking against
213 * @parent: a parent window for the dialogue, or %NULL
215 * Create and show the linking dialogue, with @individual selected as the
216 * individual to link to. If the dialogue is already being shown, raise it and
217 * reset it so the start individual is @individual.
219 * Return value: the linking dialog
222 empathy_linking_dialog_show (FolksIndividual *individual,
225 EmpathyLinkingDialogPriv *priv;
227 guint num_personas = 0;
229 /* Create the dialogue if it doesn't exist */
230 if (linking_dialog == NULL)
232 linking_dialog = GTK_WIDGET (g_object_new (EMPATHY_TYPE_LINKING_DIALOG,
235 g_signal_connect (linking_dialog, "response",
236 (GCallback) linking_response_cb, NULL);
239 priv = GET_PRIV (linking_dialog);
242 gtk_window_set_transient_for (GTK_WINDOW (linking_dialog), parent);
244 empathy_individual_linker_set_start_individual (priv->linker, individual);
246 /* Count how many Telepathy personas we have, to see whether we can
248 personas = folks_individual_get_personas (individual);
249 for (l = personas; l != NULL; l = l->next)
251 if (TPF_IS_PERSONA (l->data))
255 /* Only make the "Unlink" button sensitive if we have enough personas */
256 gtk_dialog_set_response_sensitive (GTK_DIALOG (linking_dialog),
257 RESPONSE_UNLINK, (num_personas > 1) ? TRUE : FALSE);
259 gtk_window_present (GTK_WINDOW (linking_dialog));
261 return linking_dialog;
264 EmpathyIndividualLinker *
265 empathy_linking_dialog_get_individual_linker (EmpathyLinkingDialog *self)
267 g_return_val_if_fail (EMPATHY_IS_LINKING_DIALOG (self), NULL);
269 return GET_PRIV (self)->linker;