#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
-#ifdef HAVE_MOBLIN
-#include <nbtk/nbtk-gtk.h>
-#endif
+#ifdef HAVE_MEEGO
+#include <mx-gtk/mx-gtk.h>
+#endif /* HAVE_MEEGO */
+#include <gio/gdesktopappinfo.h>
#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-idle.h>
#include <telepathy-glib/account.h>
+#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/connection-manager.h>
#include <telepathy-glib/util.h>
#include <dbus/dbus-protocol.h>
GtkWidget *apply_button;
GtkWidget *cancel_button;
GtkWidget *entry_password;
- GtkWidget *button_forget;
GtkWidget *spinbutton_port;
GtkWidget *enabled_checkbox;
+ GtkWidget *radiobutton_reuse;
gboolean simple;
/* An EmpathyAccountWidget can be used to either create an account or
* modify it. When we are creating an account, this member is set to TRUE */
gboolean creating_account;
- /* If we are creating a new account, this member is set to TRUE once the
- * account has been created */
- gboolean account_created;
- EmpathyIdle *idle;
+ /* whether there are any other real accounts. Necessary so we know whether
+ * it's safe to dismiss this widget in some cases (eg, whether the Cancel
+ * button should be sensitive) */
+ gboolean other_accounts_exist;
+
+ /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
+ * embedded in this account widget can't be used any more
+ * workaround because some async callbacks can be called after the
+ * widget has been destroyed */
+ gboolean destroyed;
+
+ TpAccountManager *account_manager;
+
+ GtkWidget *param_account_widget;
+ GtkWidget *param_password_widget;
+
+ /* Used only for IRC accounts */
+ EmpathyIrcNetworkChooser *irc_network_chooser;
gboolean dispose_run;
} EmpathyAccountWidgetPriv;
PROP_PROTOCOL = 1,
PROP_SETTINGS,
PROP_SIMPLE,
- PROP_CREATING_ACCOUNT
+ PROP_CREATING_ACCOUNT,
+ PROP_OTHER_ACCOUNTS_EXIST,
};
enum {
LAST_SIGNAL
};
+static void account_widget_apply_and_log_in (EmpathyAccountWidget *);
+
+enum {
+ RESPONSE_LAUNCH
+};
+
static guint signals[LAST_SIGNAL] = { 0 };
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
#define CHANGED_TIMEOUT 300
+#define DIGIT "0-9"
+#define DIGITS "(["DIGIT"]+)"
+#define ALPHA "a-zA-Z"
+#define ALPHAS "(["ALPHA"]+)"
+#define ALPHADIGIT ALPHA DIGIT
+#define ALPHADIGITS "(["ALPHADIGIT"]+)"
+#define ALPHADIGITDASH ALPHA DIGIT "-"
+#define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
+
+#define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
+#define TOPLABEL ALPHAS"|(["ALPHA"]" ALPHADIGITDASHS "["ALPHADIGIT"])"
+#define DOMAINLABEL ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
+ "["ALPHADIGIT"])"
+#define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
+/* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
+#define HOST "("HOSTNAME "|" HOSTNUMBER")"
+/* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
+#define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
+
+/* UIN is digital according to the unofficial specification:
+ * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
+ * 5 digits minimun according to http://en.wikipedia.org/wiki/ICQ#UIN */
+#define ICQ_USER_NAME "(["DIGIT"]{5,})"
+/* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
+#define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
+#define IRC_USER_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
+/* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
+ * We just exclude invalid characters to avoid ucschars and other redundant
+ * complexity */
+#define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
+/* ID is an email according to the unofficial specification:
+ * http://www.hypothetic.org/docs/msn/general/names.php */
+#define MSN_USER_NAME EMAIL_LOCALPART
+/* Based on the official help:
+ * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html */
+#define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})"
+
+#define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
+#define ACCOUNT_REGEX_IRC "^"IRC_USER_NAME"$"
+#define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@"HOST"$"
+#define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
+#define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
+
static void
account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
gboolean sensitive)
if (!priv->simple)
{
+ /* we hit this case because of the 'other-accounts-exist' property handler
+ * being called during init (before constructed()) */
+ if (priv->apply_button == NULL || priv->cancel_button == NULL)
+ return;
+
gtk_widget_set_sensitive (priv->apply_button, sensitive);
- gtk_widget_set_sensitive (
- priv->cancel_button, sensitive || priv->creating_account);
+ gtk_widget_set_sensitive (priv->cancel_button,
+ (sensitive || priv->creating_account) && priv->other_accounts_exist);
+
+ if (sensitive)
+ {
+ /* We can't grab default if the widget hasn't be packed in a
+ * window */
+ GtkWidget *window;
+
+ window = gtk_widget_get_toplevel (priv->apply_button);
+ if (window != NULL &&
+ gtk_widget_is_toplevel (window))
+ {
+ gtk_widget_set_can_default (priv->apply_button, TRUE);
+ gtk_widget_grab_default (priv->apply_button);
+ }
+ }
+ }
+}
+
+static void
+account_widget_set_entry_highlighting (GtkEntry *entry, gboolean highlight)
+{
+ GdkColor color;
+ GtkStyle *style;
+
+ g_return_if_fail (GTK_IS_ENTRY (entry));
- priv->contains_pending_changes = sensitive;
+ style = gtk_widget_get_style (GTK_WIDGET (entry));
+
+ if (highlight)
+ {
+ color = style->bg[GTK_STATE_SELECTED];
+
+ /* Here we take the current theme colour and add it to
+ * the colour for white and average the two. This
+ * gives a colour which is inline with the theme but
+ * slightly whiter.
+ */
+ color.red = (color.red + (style->white).red) / 2;
+ color.green = (color.green + (style->white).green) / 2;
+ color.blue = (color.blue + (style->white).blue) / 2;
+
+ gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &color);
}
+ else
+ gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
}
static void
const gchar *str;
const gchar *param_name;
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ gboolean prev_status;
+ gboolean curr_status;
str = gtk_entry_get_text (entry);
param_name = g_object_get_data (G_OBJECT (entry), "param_name");
+ prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
+ param_name);
if (EMP_STR_EMPTY (str))
{
tp_strdiff (param_name, "password") ? str : "***");
empathy_account_settings_set_string (priv->settings, param_name, str);
}
+
+ curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
+ param_name);
+ if (curr_status != prev_status)
+ account_widget_set_entry_highlighting (entry, !curr_status);
}
static void
EmpathyAccountWidget *self)
{
account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
- account_widget_handle_control_buttons_sensitivity (self);
+ empathy_account_widget_changed (self);
+}
+
+static void
+account_widget_entry_map_cb (GtkEntry *entry,
+ EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ const gchar *param_name;
+ gboolean is_valid;
+
+ /* need to initialize input highlighting */
+ param_name = g_object_get_data (G_OBJECT (entry), "param_name");
+ is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
+ param_name);
+ account_widget_set_entry_highlighting (entry, !is_valid);
}
static void
g_return_if_reached ();
}
- account_widget_handle_control_buttons_sensitivity (self);
+ empathy_account_widget_changed (self);
}
static void
empathy_account_settings_set_boolean (priv->settings, param_name, value);
}
- account_widget_handle_control_buttons_sensitivity (self);
+ empathy_account_widget_changed (self);
+}
+
+static void
+account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
+ EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ gboolean value;
+ gint32 port = 0;
+
+ value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
+ port = empathy_account_settings_get_uint32 (priv->settings, "port");
+
+ if (value)
+ {
+ if (port == 5222 || port == 0)
+ port = 5223;
+ }
+ else
+ {
+ if (port == 5223 || port == 0)
+ port = 5222;
+ }
+
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
+
+ priv->contains_pending_changes = TRUE;
+}
+
+static void
+account_widget_combobox_changed_cb (GtkWidget *widget,
+ EmpathyAccountWidget *self)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ const gchar *value;
+ const GValue *v;
+ const gchar *default_value = NULL;
+ const gchar *param_name;
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
+ return;
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+ /* the param value is stored in the first column */
+ gtk_tree_model_get (model, &iter, 0, &value, -1);
+
+ param_name = g_object_get_data (G_OBJECT (widget), "param_name");
+
+ v = empathy_account_settings_get_default (priv->settings, param_name);
+ if (v != NULL)
+ default_value = g_value_get_string (v);
+
+ if (!tp_strdiff (value, default_value))
+ {
+ DEBUG ("Unset %s and restore to %s", param_name, default_value);
+ empathy_account_settings_unset (priv->settings, param_name);
+ }
+ else
+ {
+ DEBUG ("Setting %s to %s", param_name, value);
+ empathy_account_settings_set_string (priv->settings, param_name, value);
+ }
+
+ empathy_account_widget_changed (self);
}
static void
-account_widget_forget_clicked_cb (GtkWidget *button,
+clear_icon_released_cb (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
EmpathyAccountWidget *self)
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
const gchar *param_name;
- param_name = g_object_get_data (G_OBJECT (priv->entry_password),
- "param_name");
+ param_name = g_object_get_data (G_OBJECT (entry), "param_name");
DEBUG ("Unset %s", param_name);
empathy_account_settings_unset (priv->settings, param_name);
- gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
+ gtk_entry_set_text (entry, "");
- account_widget_handle_control_buttons_sensitivity (self);
+ empathy_account_widget_changed (self);
}
static void
-account_widget_password_changed_cb (GtkWidget *entry,
+password_entry_changed_cb (GtkEditable *entry,
EmpathyAccountWidget *self)
{
- EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
const gchar *str;
str = gtk_entry_get_text (GTK_ENTRY (entry));
- gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
+
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
}
static void
-account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
+password_entry_activated_cb (GtkEntry *entry,
EmpathyAccountWidget *self)
{
- EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
- gboolean value;
- gint32 port = 0;
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
- value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
- port = empathy_account_settings_get_uint32 (priv->settings, "port");
+ if (gtk_widget_get_sensitive (priv->apply_button))
+ account_widget_apply_and_log_in (self);
+}
- if (value)
- {
- if (port == 5222 || port == 0)
- port = 5223;
- }
- else
- {
- if (port == 5223 || port == 0)
- port = 5222;
- }
+static void
+account_entry_activated_cb (GtkEntry *entry,
+ EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
+ if (gtk_widget_get_sensitive (priv->apply_button))
+ account_widget_apply_and_log_in (self);
}
-static void
-account_widget_setup_widget (EmpathyAccountWidget *self,
+void
+empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
GtkWidget *widget,
const gchar *param_name)
{
str = empathy_account_settings_get_string (priv->settings, param_name);
gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
+ if (!tp_strdiff (param_name, "account"))
+ priv->param_account_widget = widget;
+ else if (!tp_strdiff (param_name, "password"))
+ priv->param_password_widget = widget;
+
if (strstr (param_name, "password"))
{
gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
+
+ /* Add 'clear' icon */
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
+ GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
+ GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
+
+ g_signal_connect (widget, "icon-release",
+ G_CALLBACK (clear_icon_released_cb), self);
+ g_signal_connect (widget, "changed",
+ G_CALLBACK (password_entry_changed_cb), self);
+ g_signal_connect (widget, "activate",
+ G_CALLBACK (password_entry_activated_cb), self);
}
+ else if (strstr (param_name, "account"))
+ g_signal_connect (widget, "activate",
+ G_CALLBACK (account_entry_activated_cb), self);
+
g_signal_connect (widget, "changed",
G_CALLBACK (account_widget_entry_changed_cb), self);
+ g_signal_connect (widget, "map",
+ G_CALLBACK (account_widget_entry_map_cb), self);
}
else if (GTK_IS_TOGGLE_BUTTON (widget))
{
G_CALLBACK (account_widget_checkbutton_toggled_cb),
self);
}
+ else if (GTK_IS_COMBO_BOX (widget))
+ {
+ /* The combo box's model has to contain the param value in its first
+ * column (as a string) */
+ const gchar *str;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean valid;
+
+ str = empathy_account_settings_get_string (priv->settings, param_name);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+
+ valid = gtk_tree_model_get_iter_first (model, &iter);
+ while (valid)
+ {
+ gchar *name;
+
+ gtk_tree_model_get (model, &iter, 0, &name, -1);
+ if (!tp_strdiff (name, str))
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
+ valid = FALSE;
+ }
+ else
+ {
+ valid = gtk_tree_model_iter_next (model, &iter);
+ }
+
+ g_free (name);
+ }
+
+ g_signal_connect (widget, "changed",
+ G_CALLBACK (account_widget_combobox_changed_cb),
+ self);
+ }
else
{
DEBUG ("Unknown type of widget for param %s", param_name);
}
}
+static GHashTable *
+build_translated_params (void)
+{
+ GHashTable *hash;
+
+ hash = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (hash, "account", _("Account"));
+ g_hash_table_insert (hash, "password", _("Password"));
+ g_hash_table_insert (hash, "server", _("Server"));
+ g_hash_table_insert (hash, "port", _("Port"));
+
+ return hash;
+}
+
static gchar *
account_widget_generic_format_param_name (const gchar *param_name)
{
gchar *str;
gchar *p;
+ static GHashTable *translated_params = NULL;
+
+ if (G_UNLIKELY (translated_params == NULL))
+ translated_params = build_translated_params ();
+
+ /* Translate most common parameters */
+ str = g_hash_table_lookup (translated_params, param_name);
+ if (str != NULL)
+ return g_strdup (str);
str = g_strdup (param_name);
case 't': minint = 0; maxint = G_MAXUINT64; break;
case 'd': minint = G_MININT32; maxint = G_MAXINT32;
step = 0.1; break;
+ default: g_assert_not_reached ();
}
str = g_strdup_printf (_("%s:"), param_name_formatted);
}
if (widget)
- account_widget_setup_widget (self, widget, param->name);
+ empathy_account_widget_setup_widget (self, widget, param->name);
g_free (param_name_formatted);
}
continue;
}
- account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
+ empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
+ param_name);
}
}
if (error != NULL)
{
- DEBUG ("Could not automatically enable new account: %s", error->message);
+ DEBUG ("Could not enable the account: %s", error->message);
g_error_free (error);
}
else
{
- priv->account_created = TRUE;
- g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
+ empathy_connect_new_account (account, priv->account_manager);
}
+
+ /* unref widget - part of the workaround */
+ g_object_unref (widget);
}
static void
if (priv->creating_account)
{
/* By default, when an account is created, we enable it. */
+
+ /* workaround to keep widget alive during async call */
+ g_object_ref (widget);
+
tp_account_set_enabled_async (account, TRUE,
account_widget_account_enabled_cb, widget);
+ g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
}
else if (priv->enabled_checkbox != NULL)
{
gboolean enabled_checked;
enabled_checked =
-#ifndef HAVE_MOBLIN
+#ifdef HAVE_MEEGO
+ mx_gtk_light_switch_get_active (
+ MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
+#else
gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
-#else
- nbtk_gtk_light_switch_get_active (
- NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
-#endif
+#endif /* HAVE_MEEGO */
if (tp_account_is_enabled (account) && enabled_checked)
{
}
}
- account_widget_set_control_buttons_sensitivity (widget, FALSE);
+ if (!priv->destroyed)
+ account_widget_set_control_buttons_sensitivity (widget, FALSE);
+
+ priv->contains_pending_changes = FALSE;
+
+ /* unref the widget - part of the workaround */
+ g_object_unref (widget);
}
static void
-account_widget_apply_clicked_cb (GtkWidget *button,
- EmpathyAccountWidget *self)
+account_widget_apply_and_log_in (EmpathyAccountWidget *self)
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ gboolean display_name_overridden;
+
+ if (priv->radiobutton_reuse != NULL)
+ {
+ gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
+ priv->radiobutton_reuse));
+
+ DEBUG ("Set register param: %d", !reuse);
+ empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
+ }
+
+ g_object_get (priv->settings,
+ "display-name-overridden", &display_name_overridden, NULL);
+
+ if (priv->creating_account || !display_name_overridden)
+ {
+ gchar *display_name;
+
+ /* set default display name for new accounts or update if user didn't
+ * manually override it. */
+ display_name = empathy_account_widget_get_default_display_name (self);
+
+ empathy_account_settings_set_display_name_async (priv->settings,
+ display_name, NULL, NULL);
+ g_free (display_name);
+ }
+
+ /* workaround to keep widget alive during async call */
+ g_object_ref (self);
empathy_account_settings_apply_async (priv->settings,
account_widget_applied_cb, self);
}
+static void
+account_widget_apply_clicked_cb (GtkWidget *button,
+ EmpathyAccountWidget *self)
+{
+ account_widget_apply_and_log_in (self);
+}
+
static void
account_widget_setup_generic (EmpathyAccountWidget *self)
{
G_CALLBACK (account_widget_settings_ready_cb), self);
}
+static void
+account_widget_launch_external_clicked (GtkWidget *button,
+ TpAccount *account)
+{
+ if (!tp_strdiff (tp_account_get_storage_provider (account),
+ "com.meego.libsocialweb"))
+ {
+ /* we know how to handle this external provider */
+ GDesktopAppInfo *app_info;
+ const gchar *args[3] = { NULL, };
+ GError *error = NULL;
+
+ app_info = g_desktop_app_info_new ("gnome-control-center.desktop");
+
+ if (app_info == NULL)
+ {
+ g_critical ("Could not locate 'gnome-control-center.desktop'");
+ return;
+ }
+
+ args[0] = g_app_info_get_commandline (G_APP_INFO (app_info));
+ args[1] = "bisho.desktop";
+ args[2] = NULL;
+
+ gdk_spawn_on_screen (gtk_widget_get_screen (button),
+ NULL, (gchar **) args, NULL,
+ G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
+ if (error != NULL)
+ {
+ g_critical ("Failed to launch editor: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_object_unref (app_info);
+ }
+}
+
+static void
+account_widget_build_external (EmpathyAccountWidget *self,
+ EmpathyAccountSettings *settings)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ TpAccount *account = empathy_account_settings_get_account (settings);
+ GtkWidget *bar, *widget;
+ gchar *str;
+
+ self->ui_details->widget = gtk_vbox_new (FALSE, 6);
+ priv->table_common_settings = gtk_table_new (1, 2, FALSE);
+
+ if (!tp_strdiff (tp_account_get_storage_provider (account),
+ "com.meego.libsocialweb"))
+ {
+ /* we know how to handle this external provider */
+ str = g_strdup_printf (
+ _("The account %s is edited via My Web Accounts."),
+ empathy_account_settings_get_display_name (settings));
+ }
+ else
+ {
+ str = g_strdup_printf (
+ _("The account %s cannot be edited in Empathy."),
+ empathy_account_settings_get_display_name (settings));
+ }
+
+ widget = gtk_label_new (str);
+ gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
+ g_free (str);
+
+ bar = gtk_info_bar_new ();
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
+ gtk_container_add (
+ GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
+ widget);
+ gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
+
+ if (!tp_strdiff (tp_account_get_storage_provider (account),
+ "com.meego.libsocialweb"))
+ {
+ /* we know how to handle this external provider */
+ widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ _("Launch My Web Accounts"), RESPONSE_LAUNCH);
+
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (account_widget_launch_external_clicked), account);
+ }
+
+ gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
+ FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
+ priv->table_common_settings, FALSE, TRUE, 0);
+
+ gtk_widget_show_all (self->ui_details->widget);
+}
+
static void
account_widget_build_salut (EmpathyAccountWidget *self,
const char *filename)
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ GtkWidget *expander_advanced;
self->ui_details->gui = empathy_builder_get_file (filename,
"table_common_settings", &priv->table_common_settings,
"vbox_salut_settings", &self->ui_details->widget,
+ "expander_advanced_settings", &expander_advanced,
NULL);
empathy_account_widget_handle_params (self,
"entry_jid", "jid",
NULL);
- self->ui_details->default_focus = g_strdup ("entry_nickname");
+ if (priv->simple)
+ gtk_widget_hide (expander_advanced);
+
+ self->ui_details->default_focus = g_strdup ("entry_first_name");
}
static void
const char *filename)
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
- empathy_account_widget_irc_build (self, filename,
- &priv->table_common_settings);
+
+ empathy_account_settings_set_regex (priv->settings, "account",
+ ACCOUNT_REGEX_IRC);
+
+ if (priv->simple)
+ {
+ priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
+ filename);
+ }
+ else
+ {
+ priv->irc_network_chooser = empathy_account_widget_irc_build (self,
+ filename, &priv->table_common_settings);
+ }
}
static void
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ empathy_account_settings_set_regex (priv->settings, "account",
+ ACCOUNT_REGEX_MSN);
+
if (priv->simple)
{
self->ui_details->gui = empathy_builder_get_file (filename,
NULL);
self->ui_details->default_focus = g_strdup ("entry_id");
- self->ui_details->add_forget = TRUE;
}
}
+static gboolean
+account_widget_is_gtalk (EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
+ "im-google-talk");
+}
+
+static gboolean
+account_widget_is_facebook (EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
+ "im-facebook");
+}
+
+#define FACEBOOK_SUFFIX "@chat.facebook.com"
+
+static void
+facebook_id_widget_changed_cb (GtkWidget *entry,
+ EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ const gchar *account;
+
+ account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
+
+ account = empathy_account_settings_get_string (priv->settings, "account");
+ if (!EMP_STR_EMPTY (account) &&
+ !g_str_has_suffix (account, FACEBOOK_SUFFIX))
+ {
+ gchar *tmp;
+
+ tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
+
+ DEBUG ("Change account from '%s' to '%s'", account, tmp);
+
+ empathy_account_settings_set_string (priv->settings, "account", tmp);
+ g_free (tmp);
+ }
+
+ empathy_account_widget_changed (self);
+}
+
+static gchar *
+remove_facebook_suffix (const gchar *str)
+{
+ if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
+ return g_strdup (str);
+
+ return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
+}
+
+static void
+setup_facebook_id_widget (EmpathyAccountWidget *self,
+ GtkWidget *widget)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ const gchar *str = NULL;
+
+ g_object_set_data_full (G_OBJECT (widget), "param_name",
+ g_strdup ("account"), g_free);
+
+ str = empathy_account_settings_get_string (priv->settings, "account");
+ if (str != NULL)
+ {
+ gchar *tmp;
+
+ tmp = remove_facebook_suffix (str);
+ gtk_entry_set_text (GTK_ENTRY (widget), tmp);
+ g_free (tmp);
+ }
+
+ priv->param_account_widget = widget;
+
+ g_signal_connect (widget, "changed",
+ G_CALLBACK (facebook_id_widget_changed_cb), self);
+}
+
static void
account_widget_build_jabber (EmpathyAccountWidget *self,
const char *filename)
GtkWidget *checkbutton_ssl;
GtkWidget *label_id, *label_password;
GtkWidget *label_id_create, *label_password_create;
- GtkWidget *label_example_gtalk, *label_example_jabber;
- gboolean is_gtalk;
+ GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
+ gboolean is_gtalk, is_facebook;
+ GtkWidget *expander_advanced;
+ GtkWidget *entry_id;
- is_gtalk = !tp_strdiff (
- empathy_account_settings_get_icon_name (priv->settings),
- "im-google-talk");
+ is_gtalk = account_widget_is_gtalk (self);
+ is_facebook = account_widget_is_facebook (self);
+
+ empathy_account_settings_set_regex (priv->settings, "account",
+ ACCOUNT_REGEX_JABBER);
- if (priv->simple && !is_gtalk)
+ if (priv->simple && !is_gtalk && !is_facebook)
{
+ /* Simple widget for XMPP */
self->ui_details->gui = empathy_builder_get_file (filename,
"vbox_jabber_simple", &self->ui_details->widget,
"label_id_simple", &label_id,
}
else if (priv->simple && is_gtalk)
{
+ /* Simple widget for Google Talk */
self->ui_details->gui = empathy_builder_get_file (filename,
"vbox_gtalk_simple", &self->ui_details->widget,
NULL);
self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
}
+ else if (priv->simple && is_facebook)
+ {
+ /* Simple widget for Facebook */
+ self->ui_details->gui = empathy_builder_get_file (filename,
+ "vbox_fb_simple", &self->ui_details->widget,
+ "entry_id_fb_simple", &entry_id,
+ NULL);
+
+ empathy_account_widget_handle_params (self,
+ "entry_password_fb_simple", "password",
+ NULL);
+
+ setup_facebook_id_widget (self, entry_id);
+
+ self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
+ }
else
{
+ /* Full widget for XMPP, Google Talk and Facebook*/
self->ui_details->gui = empathy_builder_get_file (filename,
"table_common_settings", &priv->table_common_settings,
"vbox_jabber_settings", &self->ui_details->widget,
"checkbutton_ssl", &checkbutton_ssl,
"label_username_example", &label_example_jabber,
"label_username_g_example", &label_example_gtalk,
+ "label_username_f_example", &label_example_fb,
+ "expander_advanced", &expander_advanced,
+ "entry_id", &entry_id,
+ "label_id", &label_id,
NULL);
empathy_account_widget_handle_params (self,
- "entry_id", "account",
"entry_password", "password",
"entry_resource", "resource",
"entry_server", "server",
"checkbutton_encryption", "require-encryption",
NULL);
+ if (is_facebook)
+ {
+ gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
+
+ /* Facebook special case the entry ID widget to hide the
+ * "@chat.facebook.com" part */
+ setup_facebook_id_widget (self, entry_id);
+ }
+ else
+ {
+ empathy_account_widget_setup_widget (self, entry_id, "account");
+ }
+
self->ui_details->default_focus = g_strdup ("entry_id");
- self->ui_details->add_forget = TRUE;
priv->spinbutton_port = spinbutton_port;
g_signal_connect (checkbutton_ssl, "toggled",
gtk_widget_hide (label_example_jabber);
gtk_widget_show (label_example_gtalk);
}
+ else if (is_facebook)
+ {
+ GtkContainer *parent;
+ GList *children;
+
+ gtk_widget_hide (label_example_jabber);
+
+ /* Removing the label from list of focusable widgets */
+ parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
+ children = gtk_container_get_children (parent);
+ children = g_list_remove (children, label_example_fb);
+ gtk_container_set_focus_chain (parent, children);
+ g_list_free (children);
+
+ gtk_widget_show (label_example_fb);
+ gtk_widget_hide (expander_advanced);
+ }
}
}
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
GtkWidget *spinbutton_port;
+ empathy_account_settings_set_regex (priv->settings, "account",
+ ACCOUNT_REGEX_ICQ);
+
if (priv->simple)
{
self->ui_details->gui = empathy_builder_get_file (filename,
NULL);
self->ui_details->default_focus = g_strdup ("entry_uin");
- self->ui_details->add_forget = TRUE;
}
}
NULL);
self->ui_details->default_focus = g_strdup ("entry_screenname");
- self->ui_details->add_forget = TRUE;
}
}
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ empathy_account_settings_set_regex (priv->settings, "account",
+ ACCOUNT_REGEX_YAHOO);
+
if (priv->simple)
{
self->ui_details->gui = empathy_builder_get_file (filename,
"entry_locale", "room-list-locale",
"entry_charset", "charset",
"spinbutton_port", "port",
- "checkbutton_yahoojp", "yahoojp",
"checkbutton_ignore_invites", "ignore-invites",
NULL);
self->ui_details->default_focus = g_strdup ("entry_id");
- self->ui_details->add_forget = TRUE;
}
}
NULL);
self->ui_details->default_focus = g_strdup ("entry_id");
- self->ui_details->add_forget = TRUE;
}
}
account_widget_destroy_cb (GtkWidget *widget,
EmpathyAccountWidget *self)
{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ /* set the destroyed flag - workaround */
+ priv->destroyed = TRUE;
+
g_object_unref (self);
}
if (priv->enabled_checkbox != NULL)
{
-#ifndef HAVE_MOBLIN
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
+#ifdef HAVE_MEEGO
+ mx_gtk_light_switch_set_active (
+ MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
enabled);
#else
- nbtk_gtk_light_switch_set_active (
- NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
enabled);
-#endif /* HAVE_MOBLIN */
+#endif /* HAVE_MEEGO */
}
}
static void
-#ifndef HAVE_MOBLIN
-account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
+#ifdef HAVE_MEEGO
+account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
+ gboolean state,
gpointer user_data)
#else
-account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw,
- gboolean state,
+account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
gpointer user_data)
-#endif /* HAVE_MOBLIN */
+#endif /* HAVE_MEEGO */
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
TpAccount *account;
-#ifndef HAVE_MOBLIN
+#ifndef HAVE_MEEGO
gboolean state;
state = gtk_toggle_button_get_active (toggle_button);
-#endif
+#endif /* HAVE_MEEGO */
account = empathy_account_settings_get_account (priv->settings);
/* Enable the account according to the value of the "Enabled" checkbox */
- tp_account_set_enabled_async (account, state, NULL, NULL);
+ /* workaround to keep widget alive during async call */
+ g_object_ref (user_data);
+ tp_account_set_enabled_async (account, state,
+ account_widget_account_enabled_cb, user_data);
+}
+
+void
+empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
+ gboolean others_exist)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ priv->other_accounts_exist = others_exist;
+
+ if (priv->creating_account)
+ account_widget_handle_control_buttons_sensitivity (self);
}
static void
case PROP_CREATING_ACCOUNT:
priv->creating_account = g_value_get_boolean (value);
break;
+ case PROP_OTHER_ACCOUNTS_EXIST:
+ empathy_account_widget_set_other_accounts_exist (
+ EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
case PROP_CREATING_ACCOUNT:
g_value_set_boolean (value, priv->creating_account);
break;
+ case PROP_OTHER_ACCOUNTS_EXIST:
+ g_value_set_boolean (value, priv->other_accounts_exist);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-idle_state_change_cb (EmpathyIdle *idle,
- GParamSpec *spec,
+set_apply_button (EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ GtkWidget *image;
+
+ /* We can't use the stock button as its accelerator ('A') clashes with the
+ * Add button. */
+ gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
+
+ gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
+ gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
+
+ image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
+}
+
+static void
+presence_changed_cb (TpAccountManager *manager,
+ TpConnectionPresenceType state,
+ const gchar *status,
+ const gchar *message,
EmpathyAccountWidget *self)
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
- TpConnectionPresenceType state;
- state = empathy_idle_get_state (priv->idle);
+ if (priv->destroyed)
+ return;
+
+ if (priv->apply_button == NULL)
+ /* This button doesn't exist in 'simple' mode */
+ return;
- if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
+ if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
+ priv->creating_account)
{
- g_object_set (priv->apply_button, "label", GTK_STOCK_CONNECT, NULL);
+ /* We are online and creating a new account, display a Login button */
+ GtkWidget *image;
+
+ gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
+ gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
+
+ image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
+ GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
}
else
{
- g_object_set (priv->apply_button, "label", GTK_STOCK_APPLY, NULL);
+ /* We are offline or modifying an existing account, display
+ * a Save button */
+ set_apply_button (self);
}
}
+static void
+account_manager_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
+ TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
+ GError *error = NULL;
+ TpConnectionPresenceType state;
+
+ if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ state = tp_account_manager_get_most_available_presence (account_manager, NULL,
+ NULL);
+
+ /* simulate a presence change so the apply button will be changed
+ * if needed */
+ presence_changed_cb (account_manager, state, NULL, NULL, self);
+
+out:
+ g_object_unref (self);
+}
+
#define WIDGET(cm, proto) \
{ #cm, #proto, "empathy-account-widget-"#proto".ui", \
account_widget_build_##proto }
+static void
+add_enable_checkbox (EmpathyAccountWidget *self,
+ TpAccount *account)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+#ifdef HAVE_MEEGO
+ GtkWidget *w;
+#else
+ GtkWidget *vbox = self->ui_details->widget;
+#endif /* HAVE_MEEGO */
+ guint nb_rows, nb_columns;
+ gboolean is_enabled;
+
+ /* handle the "Enabled" checkbox. We only add it when modifying an account */
+ if (priv->creating_account || priv->table_common_settings == NULL)
+ return;
+
+ is_enabled = tp_account_is_enabled (account);
+
+#ifdef HAVE_MEEGO
+ w = gtk_label_new (_("Account:"));
+ gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+
+ priv->enabled_checkbox = mx_gtk_light_switch_new ();
+
+ mx_gtk_light_switch_set_active (
+ MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
+
+ gtk_widget_show (w);
+#else
+ priv->enabled_checkbox =
+ gtk_check_button_new_with_mnemonic (_("_Enabled"));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
+ is_enabled);
+#endif /* HAVE_MEEGO */
+
+ g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
+ "n-columns", &nb_columns, NULL);
+
+ gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
+ nb_columns);
+
+#ifdef HAVE_MEEGO
+ gtk_table_attach (GTK_TABLE (priv->table_common_settings),
+ w,
+ 0, 1, nb_rows - 1, nb_rows,
+ GTK_FILL, 0, 0, 0);
+ gtk_table_attach (GTK_TABLE (priv->table_common_settings),
+ priv->enabled_checkbox,
+ 1, nb_columns, nb_rows - 1, nb_rows,
+ GTK_EXPAND | GTK_FILL, 0, 0, 0);
+#else
+ gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
+ gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
+#endif /* HAVE_MEEGO */
+
+ gtk_widget_show (priv->enabled_checkbox);
+
+#ifdef HAVE_MEEGO
+ g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
+ G_CALLBACK (account_widget_switch_flipped_cb), self);
+#else
+ g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
+ G_CALLBACK (account_widget_enabled_toggled_cb), self);
+#endif /* HAVE_MEEGO */
+}
+
+#ifndef HAVE_MEEGO
+/* Meego doesn't support registration */
+static void
+add_register_buttons (EmpathyAccountWidget *self,
+ TpAccount *account)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+ const TpConnectionManagerProtocol *protocol;
+ GtkWidget *radiobutton_register;
+ GtkWidget *vbox = self->ui_details->widget;
+
+ if (!priv->creating_account)
+ return;
+
+ protocol = empathy_account_settings_get_tp_protocol (priv->settings);
+ if (protocol == NULL)
+ return;
+
+ if (!tp_connection_manager_protocol_can_register (protocol))
+ return;
+
+ if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
+ return;
+
+ if (priv->simple)
+ return;
+
+ priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
+ _("This account already exists on the server"));
+ radiobutton_register = gtk_radio_button_new_with_label (
+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
+ _("Create a new account on the server"));
+
+ gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
+ gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
+ gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
+ gtk_widget_show (priv->radiobutton_reuse);
+ gtk_widget_show (radiobutton_register);
+}
+#endif /* HAVE_MEEGO */
+
static void
do_constructed (GObject *obj)
{
EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
TpAccount *account;
- const gchar *protocol, *cm_name;
+ TpStorageRestrictionFlags storage_restrictions;
+ const gchar *display_name, *default_display_name;
guint i = 0;
struct {
const gchar *cm_name;
WIDGET (sofiasip, sip),
};
- cm_name = empathy_account_settings_get_cm (priv->settings);
- protocol = empathy_account_settings_get_protocol (priv->settings);
+ account = empathy_account_settings_get_account (priv->settings);
+
+ if (account != NULL)
+ storage_restrictions = tp_account_get_storage_restrictions (account);
+ else
+ storage_restrictions = 0;
- for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
+ /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
+ if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
{
- if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
- !tp_strdiff (widgets[i].protocol, protocol))
+ DEBUG ("Account is provided by an external storage provider");
+
+ account_widget_build_external (self, priv->settings);
+ }
+ else
+ {
+ const gchar *protocol, *cm_name;
+
+ cm_name = empathy_account_settings_get_cm (priv->settings);
+ protocol = empathy_account_settings_get_protocol (priv->settings);
+
+ for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
{
- gchar *filename;
+ if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
+ !tp_strdiff (widgets[i].protocol, protocol))
+ {
+ gchar *filename;
- filename = empathy_file_lookup (widgets[i].file,
- "libempathy-gtk");
- widgets[i].func (self, filename);
- g_free (filename);
+ filename = empathy_file_lookup (widgets[i].file,
+ "libempathy-gtk");
+ widgets[i].func (self, filename);
+ g_free (filename);
- break;
+ break;
+ }
}
- }
- if (i == G_N_ELEMENTS (widgets))
- {
- gchar *filename = empathy_file_lookup (
- "empathy-account-widget-generic.ui", "libempathy-gtk");
- account_widget_build_generic (self, filename);
- g_free (filename);
+ if (i == G_N_ELEMENTS (widgets))
+ {
+ gchar *filename = empathy_file_lookup (
+ "empathy-account-widget-generic.ui", "libempathy-gtk");
+ account_widget_build_generic (self, filename);
+ g_free (filename);
+ }
}
/* handle default focus */
NULL);
}
- /* handle forget button */
- if (self->ui_details->add_forget)
- {
- const gchar *password = NULL;
+ /* dup and init the account-manager */
+ priv->account_manager = tp_account_manager_dup ();
- priv->button_forget = GTK_WIDGET (gtk_builder_get_object
- (self->ui_details->gui, "button_forget"));
- priv->entry_password = GTK_WIDGET (gtk_builder_get_object
- (self->ui_details->gui, "entry_password"));
-
- password = empathy_account_settings_get_string (priv->settings,
- "password");
- gtk_widget_set_sensitive (priv->button_forget,
- !EMP_STR_EMPTY (password));
-
- g_signal_connect (priv->button_forget, "clicked",
- G_CALLBACK (account_widget_forget_clicked_cb),
- self);
- g_signal_connect (priv->entry_password, "changed",
- G_CALLBACK (account_widget_password_changed_cb),
- self);
- }
+ g_object_ref (self);
+ tp_account_manager_prepare_async (priv->account_manager, NULL,
+ account_manager_ready_cb, self);
/* handle apply and cancel button */
- if (!priv->simple)
+ if (!priv->simple &&
+ !(storage_restrictions &
+ TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
{
GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
+ GtkWidget *image;
- priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+ /* We can't use the stock button as its accelerator ('C') clashes with
+ * the Close button. */
+ priv->cancel_button = gtk_button_new ();
+ gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
+ gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
- if (priv->creating_account)
- {
- TpConnectionPresenceType state;
- priv->idle = empathy_idle_dup_singleton ();
-
- empathy_signal_connect_weak (priv->idle, "notify::state",
- G_CALLBACK (idle_state_change_cb), obj);
+ image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
- state = empathy_idle_get_state (priv->idle);
+ priv->apply_button = gtk_button_new ();
+ set_apply_button (self);
- if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
- {
- /* We are online, display a Login button */
- GtkWidget *image;
-
- priv->apply_button = gtk_button_new_with_mnemonic (_("L_og in"));
- image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
- GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
- }
- else
- {
- /* We are offline, display a Save button */
- priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
- }
- }
- else
- {
- /* We are editing an existing account, display an Apply button */
- priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
- }
+ /* We'll change this button to a "Log in" one if we are creating a new
+ * account and are connected. */
+ tp_g_signal_connect_object (priv->account_manager,
+ "most-available-presence-changed",
+ G_CALLBACK (presence_changed_cb), obj, 0);
gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
TRUE, 3);
account_widget_set_control_buttons_sensitivity (self, FALSE);
}
- account = empathy_account_settings_get_account (priv->settings);
-
if (account != NULL)
{
g_signal_connect (account, "notify::enabled",
G_CALLBACK (empathy_account_widget_enabled_cb), self);
}
- /* handle the "Enabled" checkbox. We only add it when modifying an account */
- if (!priv->creating_account && priv->table_common_settings != NULL)
- {
-#ifdef HAVE_MOBLIN
- GtkWidget *w;
-#endif
- guint nb_rows, nb_columns;
- gboolean is_enabled;
+#ifndef HAVE_MEEGO
+ add_register_buttons (self, account);
+#endif /* HAVE_MEEGO */
- is_enabled = tp_account_is_enabled (account);
-
-#ifndef HAVE_MOBLIN
- priv->enabled_checkbox =
- gtk_check_button_new_with_label (_("Enabled"));
-
- gtk_toggle_button_set_active (
- GTK_TOGGLE_BUTTON (priv->enabled_checkbox), is_enabled);
-#else
- /* Translators: this is used only when built on a moblin platform */
- w = gtk_label_new (_("Account:"));
- gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
-
- priv->enabled_checkbox = nbtk_gtk_light_switch_new ();
-
- nbtk_gtk_light_switch_set_active (
- NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
-
- gtk_widget_show (w);
-#endif /* HAVE_MOBLIN */
-
- g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
- "n-columns", &nb_columns, NULL);
-
- gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
- nb_columns);
-
-#ifndef HAVE_MOBLIN
- gtk_table_attach (GTK_TABLE (priv->table_common_settings),
- priv->enabled_checkbox,
- 0, nb_columns, nb_rows - 1, nb_rows,
- GTK_EXPAND | GTK_FILL, 0, 0, 0);
-#else
- gtk_table_attach (GTK_TABLE (priv->table_common_settings),
- w,
- 0, 1, nb_rows - 1, nb_rows,
- GTK_FILL, 0, 0, 0);
- gtk_table_attach (GTK_TABLE (priv->table_common_settings),
- priv->enabled_checkbox,
- 1, nb_columns, nb_rows - 1, nb_rows,
- GTK_EXPAND | GTK_FILL, 0, 0, 0);
-#endif /* HAVE_MOBLIN */
-
- gtk_widget_show (priv->enabled_checkbox);
-
-#ifndef HAVE_MOBLIN
- g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
- G_CALLBACK (account_widget_enabled_released_cb), self);
-#else
- g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
- G_CALLBACK (account_widget_switch_flipped_cb), self);
-#endif /* HAVE_MOBLIN */
- }
+ /* add the Enable checkbox to accounts that support it */
+ if (!(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED))
+ add_enable_checkbox (self, account);
/* hook up to widget destruction to unref ourselves */
g_signal_connect (self->ui_details->widget, "destroy",
G_CALLBACK (account_widget_destroy_cb), self);
- empathy_builder_unref_and_keep_widget (self->ui_details->gui,
- self->ui_details->widget);
- self->ui_details->gui = NULL;
+ if (self->ui_details->gui != NULL)
+ {
+ empathy_builder_unref_and_keep_widget (self->ui_details->gui,
+ self->ui_details->widget);
+ self->ui_details->gui = NULL;
+ }
+
+ display_name = empathy_account_settings_get_display_name (priv->settings);
+ default_display_name = empathy_account_widget_get_default_display_name (self);
+
+ if (tp_strdiff (display_name, default_display_name) &&
+ !priv->creating_account)
+ {
+ /* The display name of the account is not the one that we'd assign by
+ * default; assume that the user changed it manually */
+ g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
+ }
}
static void
priv->dispose_run = TRUE;
- empathy_account_settings_is_ready (priv->settings);
-
if (priv->settings != NULL)
{
TpAccount *account;
priv->settings = NULL;
}
- if (priv->idle != NULL)
+ if (priv->account_manager != NULL)
{
- g_object_unref (priv->idle);
- priv->idle = NULL;
+ g_object_unref (priv->account_manager);
+ priv->account_manager = NULL;
}
if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
+ param_spec = g_param_spec_boolean ("other-accounts-exist",
+ "other-accounts-exist",
+ "TRUE if there are any other accounts (even if this isn't yet saved)",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
+ param_spec);
+
signals[HANDLE_APPLY] =
g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
signals[ACCOUNT_CREATED] =
g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
+ g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
- 0);
+ 1, G_TYPE_OBJECT);
signals[CANCELLED] =
g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
{
EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
- if (priv->creating_account && !priv->account_created)
- /* We always want to warn the user if he's in the process of creating a
- * new account which hasn't been actually created yet. */
- return TRUE;
-
return priv->contains_pending_changes;
}
/* TODO: this should be done in empathy-account-widget-irc */
if (!tp_strdiff (protocol, "irc"))
{
- const gchar* server;
- server = empathy_account_settings_get_string (priv->settings,
- "server");
+ EmpathyIrcNetwork *network;
+
+ network = empathy_irc_network_chooser_get_network (
+ priv->irc_network_chooser);
+ g_assert (network != NULL);
/* To translators: The first parameter is the login id and the
- * second one is the server. The resulting string will be something
- * like: "MyUserName on chat.freenode.net".
+ * second one is the network. The resulting string will be something
+ * like: "MyUserName on freenode".
* You should reverse the order of these arguments if the
* server should come before the login id in your locale.*/
default_display_name = g_strdup_printf (_("%1$s on %2$s"),
- login_id, server);
+ login_id, empathy_irc_network_get_name (network));
+ }
+ else if (account_widget_is_facebook (self))
+ {
+ gchar *tmp;
+
+ tmp = remove_facebook_suffix (login_id);
+ default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
+ g_free (tmp);
}
else
{
return default_display_name;
}
+
+/* Used by subclass to indicate that widget contains pending changes */
+void
+empathy_account_widget_changed (EmpathyAccountWidget *self)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ account_widget_handle_control_buttons_sensitivity (self);
+ priv->contains_pending_changes = TRUE;
+}
+
+void
+empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
+ const gchar *account)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ if (priv->param_account_widget == NULL)
+ return;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
+}
+
+void
+empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
+ const gchar *account)
+{
+ EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+ if (priv->param_password_widget == NULL)
+ return;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);
+}