Create one single GAction to join rooms
[empathy-mirror.git] / libempathy-gtk / empathy-individual-edit-dialog.c
blobdbd01c970d24d8205f97636c41992623cab3fe7a
1 /*
2 * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com>
19 * Philip Withnall <philip.withnall@collabora.co.uk>
20 * Travis Reitter <travis.reitter@collabora.co.uk>
23 #include "config.h"
24 #include "empathy-individual-edit-dialog.h"
26 #include <glib/gi18n-lib.h>
28 #include "empathy-individual-widget.h"
29 #include "empathy-utils.h"
31 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualEditDialog)
33 typedef struct {
34 FolksIndividual *individual; /* owned */
35 GtkWidget *individual_widget; /* child widget */
36 } EmpathyIndividualEditDialogPriv;
38 enum {
39 PROP_INDIVIDUAL = 1,
42 /* Edit dialogs currently open.
43 * Each dialog contains a referenced pointer to its Individual */
44 static GList *edit_dialogs = NULL;
46 static void individual_edit_dialog_set_individual (
47 EmpathyIndividualEditDialog *dialog,
48 FolksIndividual *individual);
50 G_DEFINE_TYPE (EmpathyIndividualEditDialog, empathy_individual_edit_dialog,
51 GTK_TYPE_DIALOG);
53 static void
54 individual_dialogs_response_cb (GtkDialog *dialog,
55 gint response,
56 GList **dialogs)
58 *dialogs = g_list_remove (*dialogs, dialog);
59 gtk_widget_destroy (GTK_WIDGET (dialog));
62 static gint
63 individual_dialogs_find (GObject *object,
64 FolksIndividual *individual)
66 EmpathyIndividualEditDialogPriv *priv = GET_PRIV (object);
68 return individual != priv->individual;
71 void
72 empathy_individual_edit_dialog_show (FolksIndividual *individual,
73 GtkWindow *parent)
75 GtkWidget *dialog;
76 GList *l;
78 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
79 g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
81 l = g_list_find_custom (edit_dialogs, individual,
82 (GCompareFunc) individual_dialogs_find);
84 if (l != NULL)
86 gtk_window_present (GTK_WINDOW (l->data));
87 return;
90 /* Create dialog */
91 dialog = g_object_new (EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG,
92 "individual", individual,
93 NULL);
95 edit_dialogs = g_list_prepend (edit_dialogs, dialog);
96 gtk_widget_show (dialog);
99 static void
100 individual_removed_cb (FolksIndividual *individual,
101 FolksIndividual *replacement_individual,
102 EmpathyIndividualEditDialog *self)
104 /* Update to show the new Individual (this will close the dialogue if there
105 * is no new Individual). */
106 individual_edit_dialog_set_individual (self, replacement_individual);
108 /* Destroy the dialogue */
109 if (replacement_individual == NULL)
111 individual_dialogs_response_cb (GTK_DIALOG (self),
112 GTK_RESPONSE_DELETE_EVENT, &edit_dialogs);
116 static void
117 individual_edit_dialog_set_individual (
118 EmpathyIndividualEditDialog *dialog,
119 FolksIndividual *individual)
121 EmpathyIndividualEditDialogPriv *priv;
123 g_return_if_fail (EMPATHY_INDIVIDUAL_EDIT_DIALOG (dialog));
124 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
126 priv = GET_PRIV (dialog);
128 /* Remove the old Individual */
129 if (priv->individual != NULL)
131 g_signal_handlers_disconnect_by_func (priv->individual,
132 (GCallback) individual_removed_cb, dialog);
135 tp_clear_object (&priv->individual);
137 /* Add the new Individual */
138 priv->individual = individual;
140 if (individual != NULL)
142 g_object_ref (individual);
143 g_signal_connect (individual, "removed",
144 (GCallback) individual_removed_cb, dialog);
146 /* Update the UI */
147 empathy_individual_widget_set_individual (
148 EMPATHY_INDIVIDUAL_WIDGET (priv->individual_widget), individual);
152 static void
153 individual_edit_dialog_get_property (GObject *object,
154 guint param_id,
155 GValue *value,
156 GParamSpec *pspec)
158 EmpathyIndividualEditDialogPriv *priv = GET_PRIV (object);
160 switch (param_id) {
161 case PROP_INDIVIDUAL:
162 g_value_set_object (value, priv->individual);
163 break;
164 default:
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
166 break;
170 static void
171 individual_edit_dialog_set_property (GObject *object,
172 guint param_id,
173 const GValue *value,
174 GParamSpec *pspec)
176 EmpathyIndividualEditDialog *dialog =
177 EMPATHY_INDIVIDUAL_EDIT_DIALOG (object);
179 switch (param_id) {
180 case PROP_INDIVIDUAL:
181 individual_edit_dialog_set_individual (dialog,
182 FOLKS_INDIVIDUAL (g_value_get_object (value)));
183 break;
184 default:
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
186 break;
190 static void
191 individual_edit_dialog_dispose (GObject *object)
193 individual_edit_dialog_set_individual (
194 EMPATHY_INDIVIDUAL_EDIT_DIALOG (object), NULL);
196 G_OBJECT_CLASS (
197 empathy_individual_edit_dialog_parent_class)->dispose (object);
200 static void
201 empathy_individual_edit_dialog_class_init (
202 EmpathyIndividualEditDialogClass *klass)
204 GObjectClass *object_class = G_OBJECT_CLASS (klass);
206 object_class->get_property = individual_edit_dialog_get_property;
207 object_class->set_property = individual_edit_dialog_set_property;
208 object_class->dispose = individual_edit_dialog_dispose;
210 g_object_class_install_property (object_class,
211 PROP_INDIVIDUAL,
212 g_param_spec_object ("individual",
213 "Folks Individual",
214 "Folks Individual to edit using the dialog.",
215 FOLKS_TYPE_INDIVIDUAL,
216 G_PARAM_CONSTRUCT_ONLY |
217 G_PARAM_READWRITE |
218 G_PARAM_STATIC_STRINGS));
220 g_type_class_add_private (object_class,
221 sizeof (EmpathyIndividualEditDialogPriv));
224 static void
225 empathy_individual_edit_dialog_init (
226 EmpathyIndividualEditDialog *dialog)
228 GtkWidget *button;
229 EmpathyIndividualEditDialogPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (
230 dialog, EMPATHY_TYPE_INDIVIDUAL_EDIT_DIALOG,
231 EmpathyIndividualEditDialogPriv);
233 dialog->priv = priv;
234 priv->individual = NULL;
236 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
237 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Contact Information"));
239 /* Individual widget */
240 priv->individual_widget = empathy_individual_widget_new (priv->individual,
241 EMPATHY_INDIVIDUAL_WIDGET_EDIT_ALIAS |
242 EMPATHY_INDIVIDUAL_WIDGET_EDIT_GROUPS |
243 EMPATHY_INDIVIDUAL_WIDGET_EDIT_FAVOURITE);
244 gtk_container_set_border_width (GTK_CONTAINER (priv->individual_widget), 8);
245 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
246 GTK_DIALOG (dialog))), priv->individual_widget, TRUE, TRUE, 0);
247 gtk_widget_show (priv->individual_widget);
249 /* Close button */
250 button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
251 gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
252 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
253 GTK_RESPONSE_CLOSE);
254 gtk_widget_set_can_default (button, TRUE);
255 gtk_window_set_default (GTK_WINDOW (dialog), button);
256 gtk_widget_show (button);
258 g_signal_connect (dialog, "response",
259 G_CALLBACK (individual_dialogs_response_cb), &edit_dialogs);