2 * empathy-app-plugin-widget.c
4 * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <glib/gi18n-lib.h>
25 #include <telepathy-glib/telepathy-glib.h>
27 #include <libaccounts-glib/ag-manager.h>
28 #include <libaccounts-glib/ag-provider.h>
30 #include "empathy-contact.h"
31 #include "empathy-user-info.h"
33 #include "empathy-app-plugin-widget.h"
35 G_DEFINE_TYPE (EmpathyAppPluginWidget, empathy_app_plugin_widget, GTK_TYPE_BOX)
49 static guint signals[LAST_SIGNAL];
51 struct _EmpathyAppPluginWidgetPriv
59 empathy_app_plugin_widget_get_property (GObject *object,
64 EmpathyAppPluginWidget *self = EMPATHY_APP_PLUGIN_WIDGET (object);
69 g_value_set_object (value, self->priv->account);
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
78 empathy_app_plugin_widget_set_property (GObject *object,
83 EmpathyAppPluginWidget *self = EMPATHY_APP_PLUGIN_WIDGET (object);
88 g_assert (self->priv->account == NULL); /* construct only */
89 self->priv->account = g_value_dup_object (value);
92 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98 response_cb (GtkWidget *widget,
100 EmpathyAppPluginWidget *self)
102 if (self->priv->user_info != NULL)
104 EmpathyUserInfo *user_info = (EmpathyUserInfo *) self->priv->user_info;
106 if (response == GTK_RESPONSE_OK)
107 empathy_user_info_apply_async (user_info, NULL, NULL);
109 empathy_user_info_discard (user_info);
112 g_signal_emit (self, signals[SIG_DONE], 0);
116 create_top_bar (EmpathyAppPluginWidget *self)
118 GtkWidget *bar, *content, *action, *label;
120 AgProvider *provider;
122 GError *error = NULL;
124 bar = gtk_info_bar_new_with_buttons (
125 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
126 _("Done"), GTK_RESPONSE_OK,
128 gtk_widget_set_hexpand (bar, TRUE);
129 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_QUESTION);
130 action = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
131 gtk_orientable_set_orientation (GTK_ORIENTABLE (action),
132 GTK_ORIENTATION_HORIZONTAL);
133 gtk_widget_set_name (bar, "authorization-infobar");
134 css = gtk_css_provider_new ();
135 if (gtk_css_provider_load_from_data (css,
136 "@define-color question_bg_color rgb (222, 222, 222);"
137 "GtkInfoBar#authorization-infobar"
143 GtkStyleContext *context = gtk_widget_get_style_context (bar);
145 gtk_style_context_add_provider (context, (GtkStyleProvider *) css,
146 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
150 g_warning ("Error processing CSS theme override: %s", error->message);
151 g_clear_error (&error);
153 g_object_unref (css);
155 content = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
157 provider = ag_manager_get_provider (
158 ag_account_get_manager (self->priv->account),
159 ag_account_get_provider_name (self->priv->account));
160 str = g_strdup_printf (_("Edit %s account options"),
161 ag_provider_get_display_name (provider));
162 label = gtk_label_new (str);
163 gtk_container_add (GTK_CONTAINER (content), label);
164 gtk_widget_show (label);
165 ag_provider_unref (provider);
168 g_signal_connect (bar, "response",
169 G_CALLBACK (response_cb), self);
175 manager_prepared_cb (GObject *source,
176 GAsyncResult *result,
179 TpWeakRef *wr = user_data;
180 EmpathyAppPluginWidget *self = tp_weak_ref_dup_object (wr);
181 TpAccountManager *manager = (TpAccountManager *) source;
183 GError *error = NULL;
187 tp_weak_ref_destroy (wr);
191 if (!tp_proxy_prepare_finish (manager, result, &error))
193 g_debug ("Error preparing Account Manager: %s", error->message);
194 g_clear_error (&error);
198 accounts = tp_account_manager_dup_valid_accounts (manager);
199 while (accounts != NULL)
201 TpAccount *account = accounts->data;
204 value = tp_account_get_storage_identifier (account);
205 if (G_VALUE_HOLDS_UINT (value) &&
206 g_value_get_uint (value) == self->priv->account->id)
210 alig = gtk_alignment_new (0.5, 0, 0, 0);
211 self->priv->user_info = empathy_user_info_new (account);
212 gtk_container_add (GTK_CONTAINER (alig), self->priv->user_info);
213 gtk_widget_show (self->priv->user_info);
215 gtk_box_pack_start (GTK_BOX (self), alig, TRUE, TRUE, 0);
216 gtk_widget_show (alig);
220 accounts = g_list_delete_link (accounts, accounts);
222 g_list_free_full (accounts, g_object_unref);
225 tp_weak_ref_destroy (wr);
226 g_object_unref (self);
230 empathy_app_plugin_widget_constructed (GObject *object)
232 EmpathyAppPluginWidget *self = EMPATHY_APP_PLUGIN_WIDGET (object);
233 void (*chain_up) (GObject *) =
234 ((GObjectClass *) empathy_app_plugin_widget_parent_class)->constructed;
236 TpAccountManager *manager;
238 if (chain_up != NULL)
241 g_assert (AG_IS_ACCOUNT (self->priv->account));
244 top = create_top_bar (self);
245 gtk_widget_show (top);
246 gtk_box_pack_start (GTK_BOX (self), top, FALSE, FALSE, 0);
248 /* Prepare tp's account manager to find the TpAccount corresponding to our
250 manager = tp_account_manager_dup ();
251 tp_proxy_prepare_async (manager, NULL,
252 manager_prepared_cb, tp_weak_ref_new (self, NULL, NULL));
253 g_object_unref (manager);
257 empathy_app_plugin_widget_dispose (GObject *object)
259 EmpathyAppPluginWidget *self = EMPATHY_APP_PLUGIN_WIDGET (object);
260 void (*chain_up) (GObject *) =
261 ((GObjectClass *) empathy_app_plugin_widget_parent_class)->dispose;
263 g_clear_object (&self->priv->account);
265 if (chain_up != NULL)
270 empathy_app_plugin_widget_class_init (
271 EmpathyAppPluginWidgetClass *klass)
273 GObjectClass *oclass = G_OBJECT_CLASS (klass);
276 oclass->get_property = empathy_app_plugin_widget_get_property;
277 oclass->set_property = empathy_app_plugin_widget_set_property;
278 oclass->constructed = empathy_app_plugin_widget_constructed;
279 oclass->dispose = empathy_app_plugin_widget_dispose;
281 spec = g_param_spec_object ("account", "account",
284 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
285 g_object_class_install_property (oclass, PROP_ACCOUNT, spec);
287 signals[SIG_DONE] = g_signal_new ("done",
288 G_OBJECT_CLASS_TYPE (klass),
294 g_type_class_add_private (klass, sizeof (EmpathyAppPluginWidgetPriv));
298 empathy_app_plugin_widget_init (EmpathyAppPluginWidget *self)
300 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
301 EMPATHY_TYPE_APP_PLUGIN_WIDGET, EmpathyAppPluginWidgetPriv);
305 empathy_app_plugin_widget_new (AgAccount *account)
307 return g_object_new (EMPATHY_TYPE_APP_PLUGIN_WIDGET,
309 "orientation", GTK_ORIENTATION_VERTICAL,