* Danielle Madeley <danielle.madeley@collabora.co.uk>
*/
-#include <config.h>
-
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-accounts-dialog.h"
-#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
-#include <dbus/dbus-glib.h>
-#include <gio/gdesktopappinfo.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/defs.h>
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-pkg-kit.h>
-#include <libempathy/empathy-tp-contact-factory.h>
-
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-protocol-chooser.h>
-#include <libempathy-gtk/empathy-account-widget.h>
-#include <libempathy-gtk/empathy-account-widget-irc.h>
-#include <libempathy-gtk/empathy-account-widget-sip.h>
-#include <libempathy-gtk/empathy-cell-renderer-activatable.h>
-#include <libempathy-gtk/empathy-contact-widget.h>
-#include <libempathy-gtk/empathy-images.h>
-#include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
-#include <libempathy-gtk/empathy-new-account-dialog.h>
#include "empathy-accounts-common.h"
-#include "empathy-accounts-dialog.h"
+#include "empathy-account-widget-sip.h"
#include "empathy-import-dialog.h"
#include "empathy-import-utils.h"
+#include "empathy-local-xmpp-assistant-widget.h"
+#include "empathy-new-account-dialog.h"
+#include "empathy-pkg-kit.h"
+#include "empathy-ui-utils.h"
+#include "empathy-user-info.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
/* Flashing delay for icons (milliseconds). */
#define FLASH_TIMEOUT 500
GtkWidget *label_name;
GtkWidget *label_type;
GtkWidget *dialog_content;
+ GtkWidget *user_info;
GtkWidget *notebook_account;
GtkWidget *spinner;
* That's kinda ugly; cf bgo #640417.
*
* */
- EmpathyAccountWidget *setting_widget_object;
+ EmpathyAccountWidget *setting_widget;
gboolean connecting_show;
guint connecting_id;
* EmpathyAccountsDialog object. */
gboolean force_change_row;
GtkTreeRowReference *destination_row;
+
+ GHashTable *icons_cache;
} EmpathyAccountsDialogPriv;
enum {
return FALSE;
/* Butterfly accounts shouldn't be used any more */
- if (!tp_strdiff (tp_account_get_connection_manager (account),
+ if (!tp_strdiff (tp_account_get_cm_name (account),
"butterfly"))
return FALSE;
}
else
{
- if (!tp_strdiff (tp_account_get_connection_manager (account),
+ if (!tp_strdiff (tp_account_get_cm_name (account),
"butterfly"))
{
const gchar *packages[] = { "telepathy-haze", NULL };
COL_ACCOUNT_SETTINGS, &settings,
COL_ACCOUNT, &account, -1);
- empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
+ empathy_account_widget_discard_pending_changes (priv->setting_widget);
if (account == NULL)
{
GtkTreeIter iter;
gboolean creating;
- g_object_get (priv->setting_widget_object,
+ g_object_get (priv->setting_widget,
"creating-account", &creating, NULL);
if (!creating)
{
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
EmpathyAccountSettings *settings;
- GtkWidget *subdialog, *content, *content_area, *align;
+ GtkWidget *subdialog, *content_area, *align;
settings = accounts_dialog_model_get_selected_settings (dialog);
if (settings == NULL)
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
NULL, NULL);
- priv->setting_widget_object =
+ gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
+
+ priv->setting_widget = (EmpathyAccountWidget *)
empathy_account_widget_new_for_protocol (settings, FALSE);
- g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
- (gpointer *) &priv->setting_widget_object);
+ g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
+ (gpointer *) &priv->setting_widget);
if (accounts_dialog_has_valid_accounts (dialog))
empathy_account_widget_set_other_accounts_exist (
- priv->setting_widget_object, TRUE);
-
- content = empathy_account_widget_get_widget (priv->setting_widget_object);
+ priv->setting_widget, TRUE);
- g_signal_connect (priv->setting_widget_object, "cancelled",
+ g_signal_connect (priv->setting_widget, "cancelled",
G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
- g_signal_connect_swapped (priv->setting_widget_object, "close",
+ g_signal_connect_swapped (priv->setting_widget, "close",
G_CALLBACK (gtk_widget_destroy), subdialog);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
align = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
- gtk_container_add (GTK_CONTAINER (align), content);
+ gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
- gtk_widget_show (content);
+ gtk_widget_show (GTK_WIDGET (priv->setting_widget));
gtk_widget_show (align);
gtk_widget_show (subdialog);
}
-static void
-start_external_app (GAppInfo *app_info)
-{
- GError *error = NULL;
- GdkAppLaunchContext *context = NULL;
- GdkDisplay *display;
-
- display = gdk_display_get_default ();
- context = gdk_display_get_app_launch_context (display);
-
- if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
- &error))
- {
- g_critical ("Failed to bisho: %s", error->message);
- g_clear_error (&error);
- }
-
- tp_clear_object (&context);
-}
-
static void
use_external_storage_provider (EmpathyAccountsDialog *self,
TpAccount *account)
provider = tp_account_get_storage_provider (account);
if (!tp_strdiff (provider, "com.meego.libsocialweb"))
{
- GDesktopAppInfo *desktop_info;
- gchar *cmd;
- GAppInfo *app_info;
- GError *error = NULL;
-
- desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
- if (desktop_info == NULL)
- {
- g_critical ("Could not locate 'gnome-control-center.desktop'");
- return;
- }
-
- /* glib doesn't have API to start a desktop file with args... (#637875) */
- cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
- (GAppInfo *) desktop_info));
-
- app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
-
- if (app_info == NULL)
- {
- DEBUG ("Failed to create app info: %s", error->message);
- g_error_free (error);
- }
- else
- {
- start_external_app (app_info);
- g_object_unref (app_info);
- }
-
- g_object_unref (desktop_info);
- g_free (cmd);
+ empathy_launch_external_app ("gnome-control-center.desktop",
+ "bisho.desktop", NULL);
return;
}
- else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
+ else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
{
- GDesktopAppInfo *desktop_info;
-
- desktop_info = g_desktop_app_info_new (
- "gnome-online-accounts-panel.desktop");
- if (desktop_info == NULL)
- {
- g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
- }
- else
- {
- start_external_app (G_APP_INFO (desktop_info));
- g_object_unref (desktop_info);
- }
-
+ empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
+ NULL, NULL);
+ return;
+ }
+ else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
+ {
+ empathy_launch_external_app ("gnome-credentials-panel.desktop",
+ NULL, NULL);
return;
}
else
}
}
-static void
-account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
- gboolean error)
-{
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- GtkWidget *infobar, *label;
-
- infobar = gtk_info_bar_new ();
-
- if (error)
- {
- gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
- label = gtk_label_new (_("Failed to retrieve your personal information "
- "from the server."));
- }
- else
- {
- gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
- label = gtk_label_new (_("Go online to edit your personal information."));
- }
-
- gtk_container_add (
- GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
- label);
- gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
- gtk_widget_show_all (infobar);
-}
-
-static void
-account_dialog_got_self_contact (TpConnection *conn,
- EmpathyContact *contact,
- const GError *in_error,
- gpointer user_data,
- GObject *dialog)
-{
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- GtkWidget *editor, *alig;
-
- if (in_error != NULL)
- {
- DEBUG ("Failed to get self-contact: %s", in_error->message);
- account_dialog_show_contact_details_failed (
- EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
- return;
- }
-
- alig = gtk_alignment_new (0.5, 0, 1, 1);
-
- /* create the contact info editor for this account */
- editor = empathy_contact_widget_new (contact,
- EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
- EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
- EMPATHY_CONTACT_WIDGET_NO_STATUS |
- EMPATHY_CONTACT_WIDGET_EDIT_DETAILS |
- EMPATHY_CONTACT_WIDGET_NO_ACCOUNT);
-
- gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
- gtk_container_add (GTK_CONTAINER (alig), editor);
- gtk_widget_show (alig);
- gtk_widget_show (editor);
-}
-
static void
account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings)
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
const gchar *icon_name;
TpAccount *account;
- TpConnection *conn = NULL;
GtkWidget *bbox, *button;
+ GtkWidget *alig;
account = empathy_account_settings_get_account (settings);
- // if (priv->setting_widget_object != NULL)
- // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
- // (gpointer *) &priv->setting_widget_object);
-
priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
priv->dialog_content);
gtk_widget_show (priv->dialog_content);
- /* request the self contact */
- if (account != NULL)
- conn = tp_account_get_connection (account);
-
- if (conn != NULL &&
- tp_proxy_get_invalidated (conn) == NULL)
- {
- empathy_tp_contact_factory_get_from_handle (conn,
- tp_connection_get_self_handle (conn),
- account_dialog_got_self_contact,
- NULL, NULL, G_OBJECT (dialog));
- }
- else
- {
- account_dialog_show_contact_details_failed (dialog, FALSE);
- }
+ alig = gtk_alignment_new (0.5, 0, 1, 1);
+ priv->user_info = empathy_user_info_new (account);
+ gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
+ gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
+ gtk_widget_show (alig);
+ gtk_widget_show (priv->user_info);
bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
- return priv->setting_widget_object != NULL
+ return priv->setting_widget != NULL
&& empathy_account_widget_contains_pending_changes (
- priv->setting_widget_object);
+ priv->setting_widget);
}
static void
response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response == GTK_RESPONSE_OK)
+ if (response == GTK_RESPONSE_APPLY)
{
EmpathyAccountSettings *settings;
TpAccount *account;
return;
}
- /* No account and no profile, warn the user */
+ /* No account selected */
gtk_widget_hide (priv->vbox_details);
- gtk_widget_set_sensitive (priv->button_add, FALSE);
+ gtk_widget_set_sensitive (priv->button_add, TRUE);
+ gtk_widget_set_sensitive (priv->button_remove, FALSE);
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
NOTEBOOK_PAGE_NO_PROTOCOL);
* one for the account selected */
gtk_widget_show (priv->vbox_details);
+ if (priv->user_info != NULL)
+ {
+ empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
+ NULL, NULL);
+ priv->user_info = NULL;
+ }
if (priv->dialog_content)
{
gtk_widget_destroy (priv->dialog_content);
return empathy_icon_name_for_presence (presence);
}
+static GdkPixbuf *
+ensure_icon (EmpathyAccountsDialog *self,
+ const gchar *icon_name)
+{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+ GdkPixbuf *pixbuf;
+
+ pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
+ if (pixbuf == NULL)
+ {
+ pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+
+ if (pixbuf == NULL)
+ return NULL;
+
+ g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
+ pixbuf);
+ }
+
+ return g_object_ref (pixbuf);
+}
+
static void
accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
EmpathyAccountsDialog *dialog)
{
TpAccount *account;
+ const gchar *icon_name;
+ GdkPixbuf *pixbuf;
gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
+ icon_name = get_status_icon_for_account (dialog, account);
+ pixbuf = ensure_icon (dialog, icon_name);
+
g_object_set (cell,
- "icon-name", get_status_icon_for_account (dialog, account),
+ "pixbuf", pixbuf,
NULL);
if (account != NULL)
g_object_unref (account);
+
+ if (pixbuf != NULL)
+ g_object_unref (pixbuf);
}
static void
-1);
icon_name = empathy_account_settings_get_icon_name (settings);
- pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+ pixbuf = ensure_icon (dialog, icon_name);
g_object_set (cell,
"visible", TRUE,
if (settings != NULL)
g_object_unref (settings);
- if (priv->setting_widget_object != NULL)
+ if (priv->setting_widget != NULL)
{
- g_object_get (priv->setting_widget_object,
+ g_object_get (priv->setting_widget,
"creating-account", &creating, NULL);
}
priv->force_change_row = TRUE;
empathy_account_widget_discard_pending_changes (
- priv->setting_widget_object);
+ priv->setting_widget);
path = gtk_tree_row_reference_get_path (priv->destination_row);
selection = gtk_tree_view_get_selection (
{
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- if (priv->setting_widget_object != NULL &&
+ if (priv->setting_widget != NULL &&
accounts_dialog_has_valid_accounts (dialog))
{
empathy_account_widget_set_other_accounts_exist (
- priv->setting_widget_object, TRUE);
+ priv->setting_widget, TRUE);
}
}
{
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- if (priv->setting_widget_object != NULL &&
+ if (priv->setting_widget != NULL &&
!accounts_dialog_has_valid_accounts (dialog))
{
empathy_account_widget_set_other_accounts_exist (
- priv->setting_widget_object, FALSE);
+ priv->setting_widget, FALSE);
}
}
dialog);
/* Add existing accounts */
- accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
+ accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
for (l = accounts; l; l = l->next)
{
accounts_dialog_add_account (dialog, l->data);
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
priv->cms = empathy_connection_managers_dup_singleton ();
EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+ if (priv->user_info != NULL)
+ {
+ empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
+ NULL, NULL);
+ priv->user_info = NULL;
+ }
+
if (priv->connecting_id != 0)
{
g_source_remove (priv->connecting_id);
priv->initial_selection = NULL;
}
+ tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
+
G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
}
EMPATHY_TYPE_ACCOUNTS_DIALOG,
EmpathyAccountsDialogPriv);
dialog->priv = priv;
+
+ priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
}
/* public methods */
return GTK_WIDGET (dialog);
}
-void
-empathy_accounts_dialog_show_application (GdkScreen *screen,
- TpAccount *selected_account,
+#ifdef HAVE_UOA
+typedef struct
+{
+ TpAccount *account;
+ gboolean if_needed;
+} LaunchUOACtx;
+
+static LaunchUOACtx *
+launch_uoa_ctx_new (TpAccount *account,
+ gboolean if_needed)
+{
+ LaunchUOACtx *ctx;
+
+ ctx = g_slice_new0 (LaunchUOACtx);
+ if (account != NULL)
+ ctx->account = g_object_ref (account);
+ ctx->if_needed = if_needed;
+
+ return ctx;
+}
+
+static void
+launch_uoa_ctx_free (LaunchUOACtx *ctx)
+{
+ g_clear_object (&ctx->account);
+ g_slice_free (LaunchUOACtx, ctx);
+}
+
+static void
+am_prepare_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
+ GError *error = NULL;
+ LaunchUOACtx *ctx = user_data;
+ gchar *args = NULL;
+
+ if (!tp_proxy_prepare_finish (manager, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
+ goto out;
+
+ if (ctx->account != NULL)
+ {
+ const GValue *value;
+
+ value = tp_account_get_storage_identifier (ctx->account);
+
+ if (G_VALUE_HOLDS_UINT (value))
+ args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
+ }
+
+ empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
+
+ g_free (args);
+out:
+ launch_uoa_ctx_free (ctx);
+}
+
+static void
+launch_uoa_panel (TpAccount *selected_account,
+ gboolean if_needed,
+ gboolean hidden)
+{
+ TpAccountManager *manager;
+
+ if (hidden)
+ /* Nothing to do */
+ return;
+
+ manager = tp_account_manager_dup ();
+
+ tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
+ launch_uoa_ctx_new (selected_account, if_needed));
+
+ g_object_unref (manager);
+}
+
+#else /* HAVE_UOA */
+
+static void
+launch_empathy_accounts (TpAccount *selected_account,
gboolean if_needed,
gboolean hidden)
{
g_string_free (args, TRUE);
}
+#endif /* HAVE_UOA */
+
+void
+empathy_accounts_dialog_show_application (GdkScreen *screen,
+ TpAccount *selected_account,
+ gboolean if_needed,
+ gboolean hidden)
+{
+#ifdef HAVE_UOA
+ launch_uoa_panel (selected_account, if_needed, hidden);
+#else
+ launch_empathy_accounts (selected_account, if_needed, hidden);
+#endif
+}
gboolean
empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
gboolean result = FALSE;
- if (priv->setting_widget_object == NULL)
+ if (priv->setting_widget == NULL)
goto out;
- g_object_get (priv->setting_widget_object,
+ g_object_get (priv->setting_widget,
"creating-account", &result, NULL);
out: