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 <libempathy/empathy-individual-manager.h>
30 #include <libempathy/empathy-utils.h>
32 #include "empathy-linking-dialog.h"
33 #include "empathy-individual-linker.h"
36 * SECTION:empathy-individual-widget
37 * @title:EmpathyLinkingDialog
38 * @short_description: A dialog used to link individuals together
39 * @include: libempathy-empathy-linking-dialog.h
41 * #EmpathyLinkingDialog is a dialog which allows selection of individuals to
42 * link together, and preview of the newly linked individual. When submitted, it
43 * pushes the new links to backing storage.
47 * EmpathyLinkingDialog:
48 * @parent: parent object
50 * Widget which displays appropriate widgets with details about an individual,
51 * also allowing changing these details, if desired.
53 * Currently, it's just a thin wrapper around #EmpathyContactWidget, and
54 * displays the details of the first eligible persona found in the individual.
57 static GtkWidget *linking_dialog = NULL;
59 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLinkingDialog)
62 EmpathyIndividualLinker *linker; /* child widget */
63 GtkWidget *link_button; /* child widget */
64 } EmpathyLinkingDialogPriv;
66 G_DEFINE_TYPE (EmpathyLinkingDialog, empathy_linking_dialog,
70 linker_notify_has_changed_cb (EmpathyIndividualLinker *linker,
72 EmpathyLinkingDialog *self)
74 EmpathyLinkingDialogPriv *priv = GET_PRIV (self);
76 /* Only make the "Link" button sensitive if the linked Individual has been
78 gtk_widget_set_sensitive (priv->link_button,
79 empathy_individual_linker_get_has_changed (linker));
83 empathy_linking_dialog_class_init (EmpathyLinkingDialogClass *klass)
85 GObjectClass *object_class = G_OBJECT_CLASS (klass);
86 g_type_class_add_private (object_class, sizeof (EmpathyLinkingDialogPriv));
90 empathy_linking_dialog_init (EmpathyLinkingDialog *self)
92 EmpathyLinkingDialogPriv *priv;
97 priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
98 EMPATHY_TYPE_LINKING_DIALOG, EmpathyLinkingDialogPriv);
101 dialog = GTK_DIALOG (self);
104 gtk_dialog_set_has_separator (dialog, FALSE);
105 gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
106 /* Translators: this is the title of the linking dialogue (reached by
107 * right-clicking on a contact and selecting "Linkā¦"). "Link" in this title
109 gtk_window_set_title (GTK_WINDOW (self), _("Link Contacts"));
110 gtk_widget_set_size_request (GTK_WIDGET (self), 600, 500);
113 button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
114 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
115 gtk_dialog_add_action_widget (dialog, button, GTK_RESPONSE_CANCEL);
116 gtk_widget_show (button);
119 /* Translators: this is an action button in the linking dialogue. "Link" is
120 * used here as a verb meaning "to connect two contacts to form a
122 priv->link_button = gtk_button_new_with_mnemonic (_("_Link"));
123 gtk_dialog_add_action_widget (dialog, priv->link_button, GTK_RESPONSE_OK);
124 gtk_widget_show (priv->link_button);
128 EMPATHY_INDIVIDUAL_LINKER (empathy_individual_linker_new (NULL));
129 g_signal_connect (priv->linker, "notify::has-changed",
130 (GCallback) linker_notify_has_changed_cb, self);
132 gtk_container_set_border_width (GTK_CONTAINER (priv->linker), 8);
133 content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
134 gtk_box_pack_start (content_area, GTK_WIDGET (priv->linker), TRUE, TRUE, 0);
135 gtk_widget_show (GTK_WIDGET (priv->linker));
139 linking_response_cb (EmpathyLinkingDialog *self,
143 EmpathyLinkingDialogPriv *priv = GET_PRIV (self);
145 if (response == GTK_RESPONSE_OK) {
146 EmpathyIndividualManager *manager;
149 manager = empathy_individual_manager_dup_singleton ();
151 personas = empathy_individual_linker_get_linked_personas (priv->linker);
152 empathy_individual_manager_link_personas (manager, personas);
154 g_object_unref (manager);
157 linking_dialog = NULL;
158 gtk_widget_destroy (GTK_WIDGET (self));
162 * empathy_linking_dialog_show:
163 * @individual: the #FolksIndividual to start linking against
164 * @parent: a parent window for the dialogue, or %NULL
166 * Create and show the linking dialogue, with @individual selected as the
167 * individual to link to. If the dialogue is already being shown, raise it and
168 * reset it so the start individual is @individual.
170 * Return value: the linking dialog
173 empathy_linking_dialog_show (FolksIndividual *individual,
176 EmpathyLinkingDialogPriv *priv;
178 /* Create the dialogue if it doesn't exist */
179 if (linking_dialog == NULL)
181 linking_dialog = GTK_WIDGET (g_object_new (EMPATHY_TYPE_LINKING_DIALOG,
184 g_signal_connect (linking_dialog, "response",
185 (GCallback) linking_response_cb, NULL);
188 priv = GET_PRIV (linking_dialog);
191 gtk_window_set_transient_for (GTK_WINDOW (linking_dialog), parent);
193 empathy_individual_linker_set_start_individual (priv->linker, individual);
195 gtk_window_present (GTK_WINDOW (linking_dialog));
197 return linking_dialog;