From 5cbc27ef0f4373175af5725d1a0b78d464bb23b3 Mon Sep 17 00:00:00 2001 From: Emanuele Aina Date: Mon, 25 Mar 2013 16:38:16 +0100 Subject: tp-account-widgets: Move account widgets code in the tp-account-widgets subdir Start moving the account widgets code in a subdir before fully isolating it and stubbing it out in a submodule. https://bugzilla.gnome.org/show_bug.cgi?id=699492 --- Makefile.am | 5 +- configure.ac | 1 + libempathy-gtk/.gitignore | 1 - libempathy-gtk/Makefile.am | 29 +- libempathy-gtk/empathy-account-widget-aim.ui | 299 --- libempathy-gtk/empathy-account-widget-generic.ui | 122 - libempathy-gtk/empathy-account-widget-groupwise.ui | 292 --- libempathy-gtk/empathy-account-widget-icq.ui | 320 --- libempathy-gtk/empathy-account-widget-irc.c | 242 -- libempathy-gtk/empathy-account-widget-irc.h | 42 - libempathy-gtk/empathy-account-widget-irc.ui | 603 ----- libempathy-gtk/empathy-account-widget-jabber.ui | 792 ------- .../empathy-account-widget-local-xmpp.ui | 217 -- libempathy-gtk/empathy-account-widget-msn.ui | 292 --- libempathy-gtk/empathy-account-widget-private.h | 46 - libempathy-gtk/empathy-account-widget-sip.c | 260 --- libempathy-gtk/empathy-account-widget-sip.h | 34 - libempathy-gtk/empathy-account-widget-sip.ui | 731 ------ libempathy-gtk/empathy-account-widget-yahoo.ui | 330 --- libempathy-gtk/empathy-account-widget.c | 2331 -------------------- libempathy-gtk/empathy-account-widget.h | 95 - .../empathy-account-widgets.gresource.xml | 16 - .../empathy-irc-network-chooser-dialog.c | 740 ------- .../empathy-irc-network-chooser-dialog.h | 71 - libempathy-gtk/empathy-irc-network-chooser.c | 421 ---- libempathy-gtk/empathy-irc-network-chooser.h | 65 - libempathy-gtk/empathy-irc-network-dialog.c | 588 ----- libempathy-gtk/empathy-irc-network-dialog.h | 35 - libempathy-gtk/totem-subtitle-encoding.c | 584 ----- libempathy-gtk/totem-subtitle-encoding.h | 41 - src/Makefile.am | 2 + tp-account-widgets/.gitignore | 1 + tp-account-widgets/Makefile.am | 94 + tp-account-widgets/empathy-account-widget-aim.ui | 299 +++ .../empathy-account-widget-generic.ui | 122 + .../empathy-account-widget-groupwise.ui | 292 +++ tp-account-widgets/empathy-account-widget-icq.ui | 320 +++ tp-account-widgets/empathy-account-widget-irc.c | 242 ++ tp-account-widgets/empathy-account-widget-irc.h | 42 + tp-account-widgets/empathy-account-widget-irc.ui | 603 +++++ .../empathy-account-widget-jabber.ui | 792 +++++++ .../empathy-account-widget-local-xmpp.ui | 217 ++ tp-account-widgets/empathy-account-widget-msn.ui | 292 +++ .../empathy-account-widget-private.h | 46 + tp-account-widgets/empathy-account-widget-sip.c | 260 +++ tp-account-widgets/empathy-account-widget-sip.h | 34 + tp-account-widgets/empathy-account-widget-sip.ui | 731 ++++++ tp-account-widgets/empathy-account-widget-yahoo.ui | 330 +++ tp-account-widgets/empathy-account-widget.c | 2331 ++++++++++++++++++++ tp-account-widgets/empathy-account-widget.h | 95 + .../empathy-account-widgets.gresource.xml | 16 + .../empathy-irc-network-chooser-dialog.c | 740 +++++++ .../empathy-irc-network-chooser-dialog.h | 71 + tp-account-widgets/empathy-irc-network-chooser.c | 421 ++++ tp-account-widgets/empathy-irc-network-chooser.h | 65 + tp-account-widgets/empathy-irc-network-dialog.c | 588 +++++ tp-account-widgets/empathy-irc-network-dialog.h | 35 + tp-account-widgets/totem-subtitle-encoding.c | 584 +++++ tp-account-widgets/totem-subtitle-encoding.h | 41 + 59 files changed, 9713 insertions(+), 9638 deletions(-) delete mode 100644 libempathy-gtk/empathy-account-widget-aim.ui delete mode 100644 libempathy-gtk/empathy-account-widget-generic.ui delete mode 100644 libempathy-gtk/empathy-account-widget-groupwise.ui delete mode 100644 libempathy-gtk/empathy-account-widget-icq.ui delete mode 100644 libempathy-gtk/empathy-account-widget-irc.c delete mode 100644 libempathy-gtk/empathy-account-widget-irc.h delete mode 100644 libempathy-gtk/empathy-account-widget-irc.ui delete mode 100644 libempathy-gtk/empathy-account-widget-jabber.ui delete mode 100644 libempathy-gtk/empathy-account-widget-local-xmpp.ui delete mode 100644 libempathy-gtk/empathy-account-widget-msn.ui delete mode 100644 libempathy-gtk/empathy-account-widget-private.h delete mode 100644 libempathy-gtk/empathy-account-widget-sip.c delete mode 100644 libempathy-gtk/empathy-account-widget-sip.h delete mode 100644 libempathy-gtk/empathy-account-widget-sip.ui delete mode 100644 libempathy-gtk/empathy-account-widget-yahoo.ui delete mode 100644 libempathy-gtk/empathy-account-widget.c delete mode 100644 libempathy-gtk/empathy-account-widget.h delete mode 100644 libempathy-gtk/empathy-account-widgets.gresource.xml delete mode 100644 libempathy-gtk/empathy-irc-network-chooser-dialog.c delete mode 100644 libempathy-gtk/empathy-irc-network-chooser-dialog.h delete mode 100644 libempathy-gtk/empathy-irc-network-chooser.c delete mode 100644 libempathy-gtk/empathy-irc-network-chooser.h delete mode 100644 libempathy-gtk/empathy-irc-network-dialog.c delete mode 100644 libempathy-gtk/empathy-irc-network-dialog.h delete mode 100644 libempathy-gtk/totem-subtitle-encoding.c delete mode 100644 libempathy-gtk/totem-subtitle-encoding.h create mode 100644 tp-account-widgets/.gitignore create mode 100644 tp-account-widgets/Makefile.am create mode 100644 tp-account-widgets/empathy-account-widget-aim.ui create mode 100644 tp-account-widgets/empathy-account-widget-generic.ui create mode 100644 tp-account-widgets/empathy-account-widget-groupwise.ui create mode 100644 tp-account-widgets/empathy-account-widget-icq.ui create mode 100644 tp-account-widgets/empathy-account-widget-irc.c create mode 100644 tp-account-widgets/empathy-account-widget-irc.h create mode 100644 tp-account-widgets/empathy-account-widget-irc.ui create mode 100644 tp-account-widgets/empathy-account-widget-jabber.ui create mode 100644 tp-account-widgets/empathy-account-widget-local-xmpp.ui create mode 100644 tp-account-widgets/empathy-account-widget-msn.ui create mode 100644 tp-account-widgets/empathy-account-widget-private.h create mode 100644 tp-account-widgets/empathy-account-widget-sip.c create mode 100644 tp-account-widgets/empathy-account-widget-sip.h create mode 100644 tp-account-widgets/empathy-account-widget-sip.ui create mode 100644 tp-account-widgets/empathy-account-widget-yahoo.ui create mode 100644 tp-account-widgets/empathy-account-widget.c create mode 100644 tp-account-widgets/empathy-account-widget.h create mode 100644 tp-account-widgets/empathy-account-widgets.gresource.xml create mode 100644 tp-account-widgets/empathy-irc-network-chooser-dialog.c create mode 100644 tp-account-widgets/empathy-irc-network-chooser-dialog.h create mode 100644 tp-account-widgets/empathy-irc-network-chooser.c create mode 100644 tp-account-widgets/empathy-irc-network-chooser.h create mode 100644 tp-account-widgets/empathy-irc-network-dialog.c create mode 100644 tp-account-widgets/empathy-irc-network-dialog.h create mode 100644 tp-account-widgets/totem-subtitle-encoding.c create mode 100644 tp-account-widgets/totem-subtitle-encoding.h diff --git a/Makefile.am b/Makefile.am index dc120d5fb..0a8b1cb32 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,11 +1,12 @@ MY_SUBDIRS = tools extensions po data libempathy libempathy-gtk src help tests +TPAW_SUBDIRS = tp-account-widgets NST_SUBDIRS = nautilus-sendto-plugin GOA_SUBDIRS = goa-mc-plugin UOA_SUBDIRS = ubuntu-online-accounts -DIST_SUBDIRS = $(MY_SUBDIRS) $(NST_SUBDIRS) $(GOA_SUBDIRS) $(UOA_SUBDIRS) +DIST_SUBDIRS = $(TPAW_SUBDIRS) $(MY_SUBDIRS) $(NST_SUBDIRS) $(GOA_SUBDIRS) $(UOA_SUBDIRS) -SUBDIRS = $(MY_SUBDIRS) +SUBDIRS = $(TPAW_SUBDIRS) $(MY_SUBDIRS) if HAVE_NST SUBDIRS += $(NST_SUBDIRS) diff --git a/configure.ac b/configure.ac index b0228ec6e..d0291e615 100644 --- a/configure.ac +++ b/configure.ac @@ -637,6 +637,7 @@ AC_CONFIG_FILES([ data/themes/Makefile extensions/Makefile po/Makefile.in + tp-account-widgets/Makefile libempathy/Makefile libempathy-gtk/Makefile src/Makefile diff --git a/libempathy-gtk/.gitignore b/libempathy-gtk/.gitignore index 3e651d7f4..3e3f6f051 100644 --- a/libempathy-gtk/.gitignore +++ b/libempathy-gtk/.gitignore @@ -1,3 +1,2 @@ -empathy-account-widgets-resources.[ch] empathy-gtk-marshal.* *.gladep diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 72c27b4b2..3605eea78 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -4,6 +4,7 @@ include $(top_srcdir)/tools/flymake.mk AM_CPPFLAGS = \ $(ERROR_CFLAGS) \ + -I$(top_srcdir)/tp-account-widgets \ -I$(top_srcdir)/libempathy \ -I$(top_srcdir)/extensions \ -DDATADIR=\""$(datadir)"\" \ @@ -22,18 +23,12 @@ AM_CPPFLAGS = \ $(DISABLE_DEPRECATED) BUILT_SOURCES = \ - empathy-account-widgets-resources.c \ - empathy-account-widgets-resources.h \ empathy-gtk-enum-types.h \ empathy-gtk-enum-types.c libempathy_gtk_handwritten_source = \ empathy-account-chooser.c \ empathy-account-selector-dialog.c \ - empathy-account-widget-irc.c \ - empathy-account-widget-private.h \ - empathy-account-widget-sip.c \ - empathy-account-widget.c \ empathy-avatar-chooser.c \ empathy-avatar-image.c \ empathy-bad-password-dialog.c \ @@ -64,9 +59,6 @@ libempathy_gtk_handwritten_source = \ empathy-individual-view.c \ empathy-individual-widget.c \ empathy-input-text-view.c \ - empathy-irc-network-chooser.c \ - empathy-irc-network-chooser-dialog.c \ - empathy-irc-network-dialog.c \ empathy-local-xmpp-assistant-widget.c \ empathy-log-window.c \ empathy-new-account-dialog.c \ @@ -102,9 +94,6 @@ libempathy_gtk_handwritten_source = \ libempathy_gtk_headers = \ empathy-account-chooser.h \ empathy-account-selector-dialog.h \ - empathy-account-widget-irc.h \ - empathy-account-widget-sip.h \ - empathy-account-widget.h \ empathy-avatar-chooser.h \ empathy-avatar-image.h \ empathy-bad-password-dialog.h \ @@ -136,9 +125,6 @@ libempathy_gtk_headers = \ empathy-individual-view.h \ empathy-individual-widget.h \ empathy-input-text-view.h \ - empathy-irc-network-chooser.h \ - empathy-irc-network-chooser-dialog.h \ - empathy-irc-network-dialog.h \ empathy-local-xmpp-assistant-widget.h \ empathy-log-window.h \ empathy-new-account-dialog.h \ @@ -183,7 +169,7 @@ libempathy_gtk_la_LDFLAGS = \ libempathy_gtk_la_SOURCES = \ $(libempathy_gtk_handwritten_source) \ $(libempathy_gtk_headers) \ - totem-subtitle-encoding.c totem-subtitle-encoding.h + $(NULL) # do not distribute generated files nodist_libempathy_gtk_la_SOURCES =\ @@ -202,6 +188,7 @@ libempathy_gtk_la_LIBADD = \ $(GCR_LIBS) \ $(MEEGO_LIBS) \ $(CHEESE_LIBS) \ + $(top_builddir)/tp-account-widgets/libtp-account-widgets.la \ $(top_builddir)/libempathy-gtk/egg-list-box/libegglistbox.la \ $(top_builddir)/libempathy/libempathy.la @@ -272,17 +259,7 @@ empathy-gtk-enum-types.c: Makefile $(libempathy_gtk_headers) && cp xgen-gtc $(@F) \ && rm -f xgen-gtc -account_widgets_resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) $(srcdir)/empathy-account-widgets.gresource.xml) - -empathy-account-widgets-resources.c: empathy-account-widgets.gresource.xml $(account_widgets_resource_files) - $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $< - -empathy-account-widgets-resources.h: empathy-account-widgets.gresource.xml $(account_widgets_resource_files) - $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-header $< - EXTRA_DIST = \ - empathy-account-widgets.gresource.xml \ - $(account_widgets_ui_files) \ $(ui_DATA) if HAVE_GEOCLUE diff --git a/libempathy-gtk/empathy-account-widget-aim.ui b/libempathy-gtk/empathy-account-widget-aim.ui deleted file mode 100644 index 8ceacbf47..000000000 --- a/libempathy-gtk/empathy-account-widget-aim.ui +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - 5222 - 65555 - 1 - 10 - - - True - vertical - 6 - - - True - 12 - 6 - - - True - 1 - Pass_word - True - entry_password - - - - 2 - - - - - True - 1 - Screen _Name - True - entry_screenname - - - - - - - - True - True - - - 1 - - - - - True - True - False - - - 1 - 2 - - - - - True - 0 - 3 - <b>Example:</b> MyScreenName - True - - - - - - 1 - 1 - - - - - Remember password - True - True - False - True - True - - - 1 - 3 - - - - - - - - - - - False - False - 0 - - - - - True - True - - - True - 12 - 6 - - - True - True - adjustment1 - 1 - True - True - - - 1 - 1 - - - - - True - 1 - _Port - True - spinbutton_port - - - - 0 - 1 - - - - - True - True - True - - - 1 - 0 - - - - - True - 1 - _Server - True - entry_server - - - - 0 - 0 - - - - - - - True - Advanced - - - - - - - - False - False - 1 - - - - - True - vertical - 6 - - - True - 0 - What is your AIM screen name? - - - 0 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - vertical - 4 - - - True - True - - - 0 - - - - - True - 0.10000000149011612 - <b>Example:</b> MyScreenName - True - - - - - - 1 - - - - - - - 1 - - - - - True - 0 - What is your AIM password? - - - 2 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - 3 - - - - - Remember Password - True - True - False - True - True - - - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget-generic.ui b/libempathy-gtk/empathy-account-widget-generic.ui deleted file mode 100644 index c37da5e01..000000000 --- a/libempathy-gtk/empathy-account-widget-generic.ui +++ /dev/null @@ -1,122 +0,0 @@ - - - - - True - False - 6 - - - True - False - 6 - 12 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - False - 0 - - - - - True - True - - - 150 - True - True - never - in - - - True - False - 6 - queue - - - True - False - 6 - 12 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - False - Advanced - - - - - - - - True - True - 1 - - - - diff --git a/libempathy-gtk/empathy-account-widget-groupwise.ui b/libempathy-gtk/empathy-account-widget-groupwise.ui deleted file mode 100644 index cfca2e345..000000000 --- a/libempathy-gtk/empathy-account-widget-groupwise.ui +++ /dev/null @@ -1,292 +0,0 @@ - - - - - - 65535 - 1 - 10 - - - True - vertical - 6 - - - True - 12 - 6 - - - True - 1 - Pass_word - True - - - - 2 - - - - - True - 1 - Login I_D - True - entry_id - - - - - - - - True - True - - - 1 - - - - - True - 0 - 3 - <b>Example:</b> username - True - - - - - - 1 - 1 - - - - - True - True - False - - - 1 - 2 - - - - - Remember password - True - True - False - True - True - - - 1 - 3 - - - - - - - - - - - False - 0 - - - - - True - True - - - True - 6 - 6 - - - True - 1 - _Port - True - spinbutton_port - - - - 1 - - - - - True - 1 - _Server - True - entry_server - - - - 0 - - - - - True - True - - - 1 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - adjustment1 - 1 - True - - - 1 - 1 - - - - - - - True - Advanced - - - - - - - - False - False - 1 - - - - - True - vertical - 6 - - - True - 0 - What is your GroupWise User ID? - - - 0 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - vertical - 4 - - - True - True - - - 0 - - - - - True - 0.10000000149011612 - <b>Example:</b> username - True - - - - - - 1 - - - - - - - 1 - - - - - True - 0 - What is your GroupWise password? - - - 2 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - 3 - - - - - Remember Password - True - True - False - True - True - - - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget-icq.ui b/libempathy-gtk/empathy-account-widget-icq.ui deleted file mode 100644 index 865a33c08..000000000 --- a/libempathy-gtk/empathy-account-widget-icq.ui +++ /dev/null @@ -1,320 +0,0 @@ - - - - - - 5222 - 65555 - 1 - 10 - - - True - vertical - 6 - - - True - 12 - 6 - - - True - 1 - Pass_word - True - entry_password - - - - 2 - - - - - True - 1 - ICQ _UIN - True - entry_uin - - - - - - - - True - True - - - 1 - - - - - True - True - False - - - 1 - 2 - - - - - True - 0 - 3 - <b>Example:</b> 123456789 - True - - - - - - 1 - 1 - - - - - Remember password - True - True - False - True - True - - - 1 - 3 - - - - - - - - - - - False - False - 0 - - - - - True - True - - - True - 12 - 6 - - - True - 1 - Ch_aracter set - True - entry_charset - - - - - - - - True - True - adjustment1 - 1 - True - - - 1 - 2 - - - - - True - True - - - 1 - 1 - - - - - True - 1 - _Port - True - spinbutton_port - - - - 2 - 0 - - - - - True - 1 - _Server - True - entry_server - - - - 1 - 0 - - - - - True - True - - - 1 - - - - - - - True - Advanced - - - - - - - - False - False - 1 - - - - - True - vertical - 6 - - - True - 0 - What is your ICQ UIN? - - - 0 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - vertical - 4 - - - True - True - - - 0 - - - - - True - 0.10000000149011612 - <b>Example:</b> 123456789 - True - - - - - - 1 - - - - - - - 1 - - - - - True - 0 - What is your ICQ password? - - - 2 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - 3 - - - - - Remember Password - True - True - False - True - True - - - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c deleted file mode 100644 index e86cec417..000000000 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#include "config.h" -#include "empathy-account-widget-irc.h" - -#include "empathy-account-widget-private.h" -#include "empathy-ui-utils.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC -#include "empathy-debug.h" - -typedef struct { - EmpathyAccountWidget *self; - - GtkWidget *vbox_settings; - - GtkWidget *network_chooser; -} EmpathyAccountWidgetIrc; - -static void -account_widget_irc_destroy_cb (GtkWidget *widget, - EmpathyAccountWidgetIrc *settings) -{ - g_slice_free (EmpathyAccountWidgetIrc, settings); -} - -static void -account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) -{ - gchar *nick = NULL; - gchar *fullname = NULL; - EmpathyAccountSettings *ac_settings; - - g_object_get (settings->self, "settings", &ac_settings, NULL); - - nick = empathy_account_settings_dup_string (ac_settings, "account"); - fullname = empathy_account_settings_dup_string (ac_settings, - "fullname"); - - if (nick == NULL) - { - nick = g_strdup (g_get_user_name ()); - - empathy_account_settings_set (ac_settings, - "account", g_variant_new_string (nick)); - } - - if (fullname == NULL) - { - fullname = g_strdup (g_get_real_name ()); - - if (fullname == NULL) - fullname = g_strdup (nick); - - empathy_account_settings_set (ac_settings, - "fullname", g_variant_new_string (fullname)); - } - - g_free (nick); - g_free (fullname); -} - -static void -network_changed_cb (EmpathyIrcNetworkChooser *chooser, - EmpathyAccountWidgetIrc *settings) -{ - empathy_account_widget_changed (settings->self); -} - -/** - * set_password_prompt_if_needed: - * - * If @password is not empty, this function sets the 'password-prompt' param - * on @ac_settings. This will ensure that Idle actually asks for the password - * when connecting. - * - * Return: %TRUE if the password-prompt param has been changed - */ -static gboolean -set_password_prompt_if_needed (EmpathyAccountSettings *ac_settings, - const gchar *password) -{ - gboolean prompt; - - prompt = !tp_str_empty (password); - - if (prompt == empathy_account_settings_get_boolean (ac_settings, - "password-prompt")) - return FALSE; - - empathy_account_settings_set (ac_settings, "password-prompt", - g_variant_new_boolean (prompt)); - - return TRUE; -} - -static void -entry_password_changed_cb (GtkEntry *entry, - EmpathyAccountWidgetIrc *settings) -{ - const gchar *password; - EmpathyAccountSettings *ac_settings; - - g_object_get (settings->self, "settings", &ac_settings, NULL); - - password = gtk_entry_get_text (entry); - - set_password_prompt_if_needed (ac_settings, password); - - g_object_unref (ac_settings); -} - -EmpathyIrcNetworkChooser * -empathy_account_widget_irc_build (EmpathyAccountWidget *self, - const char *filename, - GtkWidget **table_common_settings, - GtkWidget **box) -{ - EmpathyAccountWidgetIrc *settings; - EmpathyAccountSettings *ac_settings; - GtkWidget *entry_password; - gchar *password; - - settings = g_slice_new0 (EmpathyAccountWidgetIrc); - settings->self = self; - - self->ui_details->gui = empathy_builder_get_resource (filename, - "table_irc_settings", table_common_settings, - "vbox_irc", box, - "table_irc_settings", &settings->vbox_settings, - "entry_password", &entry_password, - NULL); - - /* Add network chooser button */ - g_object_get (settings->self, "settings", &ac_settings, NULL); - - settings->network_chooser = empathy_irc_network_chooser_new (ac_settings); - - g_signal_connect (settings->network_chooser, "changed", - G_CALLBACK (network_changed_cb), settings); - - gtk_grid_attach (GTK_GRID (*table_common_settings), - settings->network_chooser, 1, 0, 1, 1); - - gtk_widget_show (settings->network_chooser); - - account_widget_irc_setup (settings); - - empathy_account_widget_handle_params (self, - "entry_nick", "account", - "entry_fullname", "fullname", - "entry_password", "password", - "entry_quit_message", "quit-message", - "entry_username", "username", - NULL); - - empathy_builder_connect (self->ui_details->gui, settings, - "table_irc_settings", "destroy", account_widget_irc_destroy_cb, - NULL); - - self->ui_details->default_focus = g_strdup ("entry_nick"); - - g_object_unref (ac_settings); - - /* Automatically set password-prompt when needed */ - password = empathy_account_settings_dup_string (ac_settings, "password"); - - if (set_password_prompt_if_needed (ac_settings, password)) - { - /* Apply right now to save password-prompt */ - empathy_account_settings_apply_async (ac_settings, NULL, NULL); - } - - g_free (password); - - g_signal_connect (entry_password, "changed", - G_CALLBACK (entry_password_changed_cb), settings); - - return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser); -} - -EmpathyIrcNetworkChooser * -empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self, - const char *filename, - GtkWidget **box) -{ - EmpathyAccountWidgetIrc *settings; - EmpathyAccountSettings *ac_settings; - GtkAlignment *alignment; - - settings = g_slice_new0 (EmpathyAccountWidgetIrc); - settings->self = self; - - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_irc_simple", box, - "alignment_network_simple", &alignment, - NULL); - - /* Add network chooser button */ - g_object_get (settings->self, "settings", &ac_settings, NULL); - - settings->network_chooser = empathy_irc_network_chooser_new (ac_settings); - - g_signal_connect (settings->network_chooser, "changed", - G_CALLBACK (network_changed_cb), settings); - - gtk_container_add (GTK_CONTAINER (alignment), settings->network_chooser); - - gtk_widget_show (settings->network_chooser); - - empathy_account_widget_handle_params (self, - "entry_nick_simple", "account", - NULL); - - empathy_builder_connect (self->ui_details->gui, settings, - "vbox_irc_simple", "destroy", account_widget_irc_destroy_cb, - NULL); - - self->ui_details->default_focus = g_strdup ("entry_nick_simple"); - - g_object_unref (ac_settings); - - return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser); -} diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h deleted file mode 100644 index c102d6ea6..000000000 --- a/libempathy-gtk/empathy-account-widget-irc.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#ifndef __EMPATHY_ACCOUNT_WIDGET_IRC_H__ -#define __EMPATHY_ACCOUNT_WIDGET_IRC_H__ - -#include "empathy-account-widget.h" -#include "empathy-irc-network-chooser.h" - -G_BEGIN_DECLS - -EmpathyIrcNetworkChooser * empathy_account_widget_irc_build ( - EmpathyAccountWidget *self, - const char *filename, - GtkWidget **table_common_settings, - GtkWidget **box); - -EmpathyIrcNetworkChooser * empathy_account_widget_irc_build_simple ( - EmpathyAccountWidget *self, - const char *filename, - GtkWidget **box); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_WIDGET_IRC_H__ */ diff --git a/libempathy-gtk/empathy-account-widget-irc.ui b/libempathy-gtk/empathy-account-widget-irc.ui deleted file mode 100644 index fc72974b3..000000000 --- a/libempathy-gtk/empathy-account-widget-irc.ui +++ /dev/null @@ -1,603 +0,0 @@ - - - - - False - 5 - Network - center-on-parent - gtk-edit - dialog - True - True - - - True - False - 2 - - - True - False - end - - - gtk-close - True - True - True - False - False - True - - - False - False - 0 - - - - - False - True - end - 0 - - - - - True - False - 0 - none - - - True - False - 6 - 12 - - - True - False - 6 - 12 - - - True - False - 1 - Network - - - - 0 - 0 - 1 - 1 - - - - - True - False - 1 - Character set - - - - 0 - 1 - 1 - 1 - - - - - True - True - - - 1 - 0 - 1 - 1 - - - - - True - False - - - 1 - 1 - 1 - 1 - - - - - - - - - True - False - Network - - - - - - - - False - True - 1 - - - - - True - False - 0 - none - - - True - False - 6 - 12 - - - True - False - 6 - 6 - - - True - 0 - - - 120 - True - True - never - in - True - - - True - True - False - - - - - - - - True - True - 0 - - - - - True - 1 - - - - Add… - True - True - True - list-add-symbolic - True - - - - - - - Remove - True - True - True - list-remove-symbolic - True - - - - - - - Up - True - True - True - go-up-symbolic - True - - - - - - - Down - True - True - True - go-down-symbolic - True - - - - - - - False - True - 1 - - - - - - - - - - - True - False - Servers - - - - - - - - False - True - 2 - - - - - - button_close - - - - True - False - - - True - False - 6 - 12 - - - True - True - False - - - 1 - 2 - 1 - 1 - - - - - True - True - - - 1 - 1 - 1 - 1 - - - - - True - True - 0 - 0 - 3 - Most IRC servers don't need a password, so if you're not sure, don't enter a password. - True - True - - - - - - 1 - 3 - 1 - 1 - - - - - True - False - 1 - Network - TrueA - - - - 0 - 0 - 1 - 1 - - - - - True - False - 1 - Nickname - True - entry_nick - - - - 0 - 1 - 1 - 1 - - - - - True - False - 1 - Password - - - - 0 - 2 - 1 - 1 - - - - - False - False - 0 - - - - - True - True - - - True - False - 6 - 12 - - - True - True - - - 1 - 2 - 1 - 1 - - - - - True - False - 1 - Quit message - - - - 0 - 2 - 1 - 1 - - - - - True - True - - - 1 - 1 - 1 - 1 - - - - - True - False - 1 - Real name - True - entry_nick - - - - 0 - 1 - 1 - 1 - - - - - True - False - 1 - Username - True - - - - 0 - 0 - 1 - 1 - - - - - True - True - - - 1 - 0 - 1 - 1 - - - - - - - True - False - Advanced - - - - - - - - True - True - 1 - - - - - True - False - - - True - False - 0 - Which IRC network? - - - True - True - 0 - - - - - True - False - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 6 - 3 - 12 - - - - - - True - True - 1 - - - - - True - False - 0 - What is your IRC nickname? - - - True - True - 2 - - - - - True - False - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 6 - 3 - 12 - - - True - True - - - - - True - True - 3 - - - - - - - - - - - - - - diff --git a/libempathy-gtk/empathy-account-widget-jabber.ui b/libempathy-gtk/empathy-account-widget-jabber.ui deleted file mode 100644 index 8422daa0c..000000000 --- a/libempathy-gtk/empathy-account-widget-jabber.ui +++ /dev/null @@ -1,792 +0,0 @@ - - - - - 127 - 1 - 10 - - - 65555 - 5222 - 1 - 10 - - - True - False - - - True - False - 0 - What is your Facebook username? - - - False - False - 0 - - - - - True - False - 12 - - - True - True - - - False - False - 0 - - - - - True - False - 4 - 0.10000000149011612 - This is your username, not your normal Facebook login. -If you are facebook.com/<b>badger</b>, enter <b>badger</b>. -Use <a href="http://www.facebook.com/username/">this page</a> to choose a Facebook username if you don't have one. - True - - - - - - True - True - 1 - - - - - False - False - 1 - - - - - True - False - 0 - 6 - What is your Facebook password? - - - False - False - 2 - - - - - True - True - 12 - False - - - False - True - 3 - - - - - Remember Password - True - True - False - False - 0 - True - True - - - False - True - 4 - - - - - True - False - - - True - False - 0 - What is your Google ID? - - - False - True - 0 - - - - - True - False - 12 - 4 - - - True - True - - - True - True - 0 - - - - - True - False - 0.10000000149011612 - <b>Example:</b> user@gmail.com - True - - - - - - True - True - 1 - - - - - False - True - 1 - - - - - True - False - 0 - 6 - What is your Google password? - - - False - True - 2 - - - - - True - True - 12 - False - - - False - True - 3 - - - - - Remember Password - True - True - False - False - True - True - - - False - True - 4 - - - - - True - False - 6 - - - True - False - True - 6 - 12 - - - True - True - start - True - False - - - 1 - 2 - 1 - 1 - - - - - True - True - True - - - 1 - 0 - 1 - 1 - - - - - True - False - start - - - False - start - True - 0 - 3 - <b>Example:</b> user@jabber.org - True - - - - - - 0 - 0 - 1 - 1 - - - - - False - start - True - 0 - 3 - <b>Example:</b> user@gmail.com - True - - - - - - 0 - 1 - 1 - 1 - - - - - False - start - True - 0 - 3 - This is your username, not your normal Facebook login. -If you are facebook.com/<b>badger</b>, enter <b>badger</b>. -Use <a href="http://www.facebook.com/username/">this page</a> to choose a Facebook username if you don't have one. - True - True - - - - - - 0 - 2 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - 1 - 1 - 1 - 1 - - - - - Remember password - True - True - False - True - False - True - True - - - 1 - 3 - 1 - 1 - - - - - True - False - 1 - Login I_D - True - entry_id - - - - 0 - 0 - 1 - 1 - - - - - True - False - 1 - Pass_word - True - right - entry_password - - - - 0 - 2 - 1 - 1 - - - - - - - - - - - - - - - - - False - False - 0 - - - - - True - True - - - 200 - True - True - never - in - - - True - False - none - - - True - False - 6 - 6 - 12 - - - True - True - - - 1 - 2 - 1 - 1 - - - - - True - True - adjustment1 - 1 - - - 1 - 3 - 1 - 1 - - - - - I_gnore SSL certificate errors - True - True - False - False - True - 0 - True - - - 0 - 1 - 2 - 1 - - - - - True - False - 1 - Priori_ty - True - spinbutton_priority - - - 0 - 3 - 1 - 1 - - - - - True - False - 1 - Reso_urce - True - entry_resource - - - 0 - 2 - 1 - 1 - - - - - Encr_yption required (TLS/SSL) - True - True - False - False - True - 0 - True - - - 0 - 0 - 2 - 1 - - - - - True - False - 0 - Override server settings - - - - - - 0 - 4 - 2 - 1 - - - - - True - False - 1 - _Server - True - entry_server - - - 0 - 5 - 1 - 1 - - - - - True - False - 1 - _Port - True - spinbutton_port - - - 0 - 6 - 1 - 1 - - - - - Use old SS_L - True - True - False - False - True - 0 - True - - - 0 - 7 - 2 - 1 - - - - - True - True - - - - 1 - 5 - 1 - 1 - - - - - True - True - - adjustment2 - 1 - True - - - 1 - 6 - 1 - 1 - - - - - - - - - - - True - False - Advanced - - - - - - - - True - True - 1 - - - - - True - False - - - True - False - 0 - What is your Jabber ID? - - - False - True - 0 - - - - - False - 0 - What is your desired Jabber ID? - - - False - True - 1 - - - - - True - False - 12 - 4 - - - True - True - - - True - True - 0 - - - - - True - False - 0.10000000149011612 - <b>Example:</b> user@jabber.org - True - - - - - - True - True - 1 - - - - - False - True - 2 - - - - - True - False - 0 - 6 - What is your Jabber password? - - - False - True - 3 - - - - - False - 0 - 6 - What is your desired Jabber password? - - - False - True - 4 - - - - - True - True - 12 - False - - - False - True - 5 - - - - - Remember Password - True - True - False - False - True - True - - - False - True - 6 - - - - diff --git a/libempathy-gtk/empathy-account-widget-local-xmpp.ui b/libempathy-gtk/empathy-account-widget-local-xmpp.ui deleted file mode 100644 index 460c41cbf..000000000 --- a/libempathy-gtk/empathy-account-widget-local-xmpp.ui +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - True - vertical - 6 - - - True - 12 - 6 - - - True - True - True - - - 1 - 2 - - - - - True - True - True - - - 1 - 1 - - - - - True - True - True - - - 1 - - - - - True - 1 - Nic_kname - True - entry_nickname - - - - 2 - 0 - - - - - True - 1 - _Last Name - True - entry_last_name - - - - 1 - 0 - - - - - True - 1 - _First Name - True - entry_first_name - - - - 0 - - - - - False - False - 0 - - - - - True - True - - - True - 12 - 6 - - - True - True - True - - - 1 - - - - - True - 1 - _Published Name - True - entry_published - - - - 0 - - - - - True - True - True - - - 1 - 2 - - - - - True - True - True - - - 1 - 1 - - - - - True - 1 - _Jabber ID - True - entry_jid - - - - 2 - 0 - - - - - True - 1 - E-_mail address - True - entry_email - - - - 1 - 0 - - - - - - - True - Advanced - - - - - - - - False - False - 1 - - - - - - - - - - - - - - diff --git a/libempathy-gtk/empathy-account-widget-msn.ui b/libempathy-gtk/empathy-account-widget-msn.ui deleted file mode 100644 index 4b0614f33..000000000 --- a/libempathy-gtk/empathy-account-widget-msn.ui +++ /dev/null @@ -1,292 +0,0 @@ - - - - - - 65535 - 1 - 10 - - - True - vertical - 6 - - - True - 12 - 6 - - - True - 1 - Pass_word - True - - - - 2 - - - - - True - 1 - Login I_D - True - entry_id - - - - - - - - True - True - - - 1 - - - - - True - 0 - 3 - <b>Example:</b> user@hotmail.com - True - - - - - - 1 - 1 - - - - - True - True - False - - - 1 - 2 - - - - - Remember password - True - True - False - True - True - - - 1 - 3 - - - - - - - - - - - False - 0 - - - - - True - True - - - True - 6 - 6 - - - True - 1 - _Port - True - spinbutton_port - - - - 1 - - - - - True - 1 - _Server - True - entry_server - - - - 0 - - - - - True - True - - - 1 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - adjustment1 - 1 - True - - - 1 - 1 - - - - - - - True - Advanced - - - - - - - - True - True - 1 - - - - - True - vertical - 6 - - - True - 0 - What is your Windows Live ID? - - - 0 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - vertical - 4 - - - True - True - - - 0 - - - - - True - 0.10000000149011612 - <b>Example:</b> user@hotmail.com - True - - - - - - 1 - - - - - - - 1 - - - - - True - 0 - What is your Windows Live password? - - - 2 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - 3 - - - - - Remember Password - True - True - False - True - True - - - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget-private.h b/libempathy-gtk/empathy-account-widget-private.h deleted file mode 100644 index 044e3a991..000000000 --- a/libempathy-gtk/empathy-account-widget-private.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2009 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Cosimo Cecchi - */ - -#ifndef __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ -#define __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ - -#include "empathy-account-widget.h" - -G_BEGIN_DECLS - -struct _EmpathyAccountWidgetUIDetails { - GtkBuilder *gui; - - char *default_focus; -}; - - -void empathy_account_widget_handle_params (EmpathyAccountWidget *self, - const gchar *first_widget, - ...); - -void empathy_account_widget_setup_widget (EmpathyAccountWidget *self, - GtkWidget *widget, - const gchar *param_name); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ */ diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c deleted file mode 100644 index b76078d5c..000000000 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - * Frederic Peters - */ - -#include "config.h" -#include "empathy-account-widget-sip.h" - -#include - -#include "empathy-account-widget-private.h" -#include "empathy-ui-utils.h" - -typedef struct { - EmpathyAccountWidget *self; - GtkWidget *vbox_settings; - - GtkWidget *label_stun_server; - GtkWidget *entry_stun_server; - GtkWidget *label_stun_port; - GtkWidget *spinbutton_stun_port; - GtkWidget *checkbutton_discover_stun; - GtkWidget *combobox_transport; - GtkWidget *combobox_keep_alive_mechanism; - GtkWidget *spinbutton_keepalive_interval; -} EmpathyAccountWidgetSip; - -static void -account_widget_sip_destroy_cb (GtkWidget *widget, - EmpathyAccountWidgetSip *settings) -{ - g_slice_free (EmpathyAccountWidgetSip, settings); -} - -static void -account_widget_sip_discover_stun_toggled_cb ( - GtkWidget *checkbox, - EmpathyAccountWidgetSip *settings) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)); - gtk_widget_set_sensitive (settings->label_stun_server, !active); - gtk_widget_set_sensitive (settings->entry_stun_server, !active); - gtk_widget_set_sensitive (settings->label_stun_port, !active); - gtk_widget_set_sensitive (settings->spinbutton_stun_port, !active); -} - -static void -keep_alive_mechanism_combobox_change_cb (GtkWidget *widget, - EmpathyAccountWidgetSip *self) -{ - GtkTreeIter iter; - GtkTreeModel *model; - gchar *mechanism; - gboolean enabled; - - /* Unsensitive the keep-alive spin button if keep-alive is disabled */ - if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) - return; - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); - gtk_tree_model_get (model, &iter, 0, &mechanism, -1); - - enabled = tp_strdiff (mechanism, "none"); - - gtk_widget_set_sensitive (self->spinbutton_keepalive_interval, enabled); - g_free (mechanism); -} - -static void -checkbutton_tel_toggled ( - GtkWidget *checkbox, - EmpathyAccountWidgetSip *sip_settings) -{ - EmpathyAccountSettings *settings; - - settings = empathy_account_widget_get_settings (sip_settings->self); - - empathy_account_settings_set_uri_scheme_tel (settings, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))); - - empathy_account_widget_changed (sip_settings->self); -} - -GtkWidget * -empathy_account_widget_sip_build (EmpathyAccountWidget *self, - const char *filename, - GtkWidget **grid_common_settings) -{ - EmpathyAccountWidgetSip *settings; - GtkWidget *vbox_settings; - gboolean is_simple; - GtkWidget *grid_advanced; - - g_object_get (self, "simple", &is_simple, NULL); - - if (is_simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_sip_simple", &vbox_settings, - NULL); - - empathy_account_widget_handle_params (self, - "entry_userid_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_userid_simple"); - } - else - { - GtkListStore *store; - GtkCellRenderer *renderer; - GtkToggleButton *checkbutton_tel; - - settings = g_slice_new0 (EmpathyAccountWidgetSip); - settings->self = self; - - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", grid_common_settings, - "grid_advanced_sip_settings", &grid_advanced, - "vbox_sip_settings", &vbox_settings, - "label_stun-server", &settings->label_stun_server, - "entry_stun-server", &settings->entry_stun_server, - "label_stun-port", &settings->label_stun_port, - "spinbutton_stun-port", &settings->spinbutton_stun_port, - "checkbutton_discover-stun", &settings->checkbutton_discover_stun, - "spinbutton_keepalive-interval", - &settings->spinbutton_keepalive_interval, - "checkbutton_tel", &checkbutton_tel, - NULL); - settings->vbox_settings = vbox_settings; - - gtk_toggle_button_set_active (checkbutton_tel, - empathy_account_settings_has_uri_scheme_tel ( - empathy_account_widget_get_settings (self))); - - empathy_account_widget_handle_params (self, - "entry_userid", "account", - "entry_password", "password", - "checkbutton_discover-stun", "discover-stun", - "entry_stun-server", "stun-server", - "spinbutton_stun-port", "stun-port", - "entry_auth-user", "auth-user", - "entry_proxy-host", "proxy-host", - "spinbutton_port", "port", - "checkbutton_loose-routing", "loose-routing", - "checkbutton_discover-binding", "discover-binding", - "spinbutton_keepalive-interval", "keepalive-interval", - "checkbutton_ignore-tls-errors", "ignore-tls-errors", - "entry_local-ip-address", "local-ip-address", - "spinbutton_local-port", "local-port", - NULL); - - account_widget_sip_discover_stun_toggled_cb ( - settings->checkbutton_discover_stun, - settings); - - empathy_builder_connect (self->ui_details->gui, settings, - "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, - "checkbutton_discover-stun", "toggled", - account_widget_sip_discover_stun_toggled_cb, - "checkbutton_tel", "toggled", checkbutton_tel_toggled, - NULL); - - self->ui_details->default_focus = g_strdup ("entry_userid"); - - /* Create the 'transport' combo box. The first column has to contain the - * value of the param. */ - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - settings->combobox_transport = gtk_combo_box_new_with_model ( - GTK_TREE_MODEL (store)); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start ( - GTK_CELL_LAYOUT (settings->combobox_transport), renderer, TRUE); - gtk_cell_layout_add_attribute ( - GTK_CELL_LAYOUT (settings->combobox_transport), renderer, "text", 1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "auto", 1, _("Auto"), -1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "udp", 1, _("UDP"), -1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "tcp", 1, _("TCP"), -1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "tls", 1, _("TLS"), -1); - - empathy_account_widget_setup_widget (self, settings->combobox_transport, - "transport"); - - gtk_grid_attach (GTK_GRID (grid_advanced), settings->combobox_transport, - 1, 11, 3, 1); - - gtk_widget_show (settings->combobox_transport); - - /* Create the 'keep-alive mechanism' combo box */ - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - settings->combobox_keep_alive_mechanism = gtk_combo_box_new_with_model ( - GTK_TREE_MODEL (store)); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start ( - GTK_CELL_LAYOUT (settings->combobox_keep_alive_mechanism), renderer, - TRUE); - gtk_cell_layout_add_attribute ( - GTK_CELL_LAYOUT (settings->combobox_keep_alive_mechanism), renderer, - "text", 1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "auto", 1, _("Auto"), -1); - - /* translators: this string is very specific to SIP's internal; maybe - * best to keep the English version. */ - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "register", 1, _("Register"), -1); - - /* translators: this string is very specific to SIP's internal; maybe - * best to keep the English version. */ - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "options", 1, _("Options"), -1); - - gtk_list_store_insert_with_values (store, NULL, -1, - 0, "none", 1, _("None"), -1); - - g_signal_connect (settings->combobox_keep_alive_mechanism, "changed", - G_CALLBACK (keep_alive_mechanism_combobox_change_cb), settings); - - empathy_account_widget_setup_widget (self, - settings->combobox_keep_alive_mechanism, "keepalive-mechanism"); - - gtk_grid_attach (GTK_GRID (grid_advanced), - settings->combobox_keep_alive_mechanism, - 1, 7, 3, 1); - - gtk_widget_show (settings->combobox_keep_alive_mechanism); - } - - return vbox_settings; -} diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h deleted file mode 100644 index 4fed35ec9..000000000 --- a/libempathy-gtk/empathy-account-widget-sip.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Frederic Peters - */ - -#ifndef __EMPATHY_ACCOUNT_WIDGET_SIP_H__ -#define __EMPATHY_ACCOUNT_WIDGET_SIP_H__ - -#include "empathy-account-widget.h" - -G_BEGIN_DECLS - -GtkWidget * empathy_account_widget_sip_build (EmpathyAccountWidget *self, - const char *filename, - GtkWidget **grid_common_settings); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_WIDGET_SIP_H__ */ diff --git a/libempathy-gtk/empathy-account-widget-sip.ui b/libempathy-gtk/empathy-account-widget-sip.ui deleted file mode 100644 index 7caa7cad6..000000000 --- a/libempathy-gtk/empathy-account-widget-sip.ui +++ /dev/null @@ -1,731 +0,0 @@ - - - - - 65535 - 1 - 10 - - - 65535 - 1 - 10 - - - 10000 - 1 - 10 - - - 65535 - 1 - 10 - - - True - False - - - True - False - 12 - 6 - - - True - False - 1 - Pass_word - True - entry_password - - - - 2 - - - - - True - True - - - 1 - - - - - True - False - 1 - _Username - True - entry_userid - - - - 0 - - - - - True - False - 0 - 3 - <b>Example:</b> user@my.sip.server - True - - - - - - 1 - 1 - - - - - True - True - - - 1 - 2 - - - - - Remember password - True - True - False - False - True - True - - - 1 - 3 - - - - - Use this account to call _landlines and mobile phones - True - True - False - False - True - 0 - True - - - 4 - 0 - 4 - - - - - - - - - - - False - False - 0 - - - - - True - True - - - 200 - True - True - never - in - - - True - False - queue - none - - - True - False - 0 - 6 - - - True - False - 6 - 6 - - - True - True - - - 1 - 2 - - - - - True - True - - - 1 - 10 - 3 - - - - - True - True - - - 1 - 5 - - - - - True - True - adjustment3 - - - 1 - 8 - 3 - - - - - True - True - - - 1 - 14 - - - - - True - False - 0 - NAT Traversal Options - - - - - - - - - - True - False - 0 - Proxy Options - - - - - - 4 - 0 - - - - - True - False - 0 - Miscellaneous Options - - - - - - 9 - 0 - - - - - True - False - 24 - - - True - False - 0 - STUN Server - entry_stun-server - - - - - 2 - 0 - - - - - True - False - 12 - - - Discover the STUN server automatically - True - True - False - False - True - True - - - - - 1 - 0 - 4 - - - - - True - False - 12 - - - Discover Binding - True - True - False - False - True - - - - - 3 - 0 - 4 - - - - - True - False - 12 - - - True - False - 0 - Server - - - - - 5 - 0 - - - - - True - False - 0 - Keep-Alive Options - - - - - - 6 - 0 - - - - - True - False - 12 - - - True - False - 0 - Mechanism - - - - - 7 - 0 - - - - - True - False - 12 - - - True - False - 0 - Interval (seconds) - - - - - 8 - 0 - - - - - True - False - 12 - - - True - False - 0 - Authentication username - - - - - 10 - 0 - - - - - True - False - 12 - - - True - False - 0 - Transport - - - - - 11 - 0 - - - - - True - False - 12 - - - Loose Routing - True - True - False - False - True - - - - - 12 - 0 - 4 - - - - - True - False - 12 - - - Ignore TLS Errors - True - True - False - False - True - - - - - 13 - 0 - 4 - - - - - True - False - 0 - Port - spinbutton_stun-port - - - 2 - 2 - - - - - True - True - adjustment1 - 1 - - - 3 - 2 - - - - - True - False - 0 - Port - - - 2 - 5 - - - - - True - True - adjustment2 - 1 - - - 3 - 5 - - - - - True - False - 12 - - - True - False - 0 - Local IP Address - entry_local-ip-address - - - - - 0 - 14 - - - - - True - False - 0 - Port - spinbutton_local-port - - - 2 - 14 - - - - - True - True - adjustment4 - - - 3 - 14 - - - - - - - - - - - - - True - False - Advanced - - - - - - - - True - True - 1 - - - - - True - False - 6 - - - True - False - 0 - What is your SIP login ID? - - - True - True - 0 - - - - - True - False - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - False - 4 - - - True - True - - - True - True - 0 - - - - - True - False - 0.10000000149011612 - <b>Example:</b> user@my.sip.server - True - - - - - - True - True - 1 - - - - - - - True - True - 1 - - - - - True - False - 0 - What is your SIP account password? - - - True - True - 2 - - - - - True - False - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - True - True - 3 - - - - - Remember Password - True - True - False - False - True - True - - - True - True - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget-yahoo.ui b/libempathy-gtk/empathy-account-widget-yahoo.ui deleted file mode 100644 index 9d002538c..000000000 --- a/libempathy-gtk/empathy-account-widget-yahoo.ui +++ /dev/null @@ -1,330 +0,0 @@ - - - - - - 5050 - 1 - 65555 - 1 - 10 - - - True - vertical - 6 - - - True - 12 - 6 - - - True - 0 - Pass_word: - True - entry_password - - - 2 - - - - - True - 0 - Yahoo! I_D: - True - entry_id - - - - - - - True - True - - - 1 - - - - - True - True - False - - - 1 - 2 - - - - - True - 0 - 3 - <b>Example:</b> username - True - - - - - - 1 - 1 - - - - - Remember password - True - True - False - True - True - - - 1 - 3 - - - - - - - - - - - False - False - 0 - - - - - True - True - - - True - - - True - 12 - 6 - - - I_gnore conference and chat room invitations - True - True - False - True - True - - - 2 - - - - - True - 0 - _Room List locale: - True - entry_locale - - - 1 - 0 - - - - - True - 0 - Ch_aracter set: - True - entry_charset - - - 2 - 0 - - - - - True - True - - - 1 - 1 - - - - - True - True - - - 1 - 2 - - - - - True - 0 - _Port: - True - spinbutton_port - - - 3 - 0 - - - - - True - True - adjustment1 - 1 - True - - - 1 - 3 - - - - - 0 - - - - - - - True - Advanced - - - - - - - - True - True - 1 - - - - - True - vertical - 6 - - - True - 0 - What is your Yahoo! ID? - - - 0 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 3 - 12 - - - True - vertical - 4 - - - True - True - - - 0 - - - - - True - 0.10000000149011612 - <b>Example:</b> username - True - - - - - - 1 - - - - - - - 1 - - - - - True - 0 - What is your Yahoo! password? - - - 2 - - - - - True - 0 - 0 - 0.34999999403953552 - 0.34999999403953552 - 12 - - - True - True - False - - - - - 3 - - - - - Remember password - True - True - False - True - True - - - 4 - - - - diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c deleted file mode 100644 index 0751b24a4..000000000 --- a/libempathy-gtk/empathy-account-widget.c +++ /dev/null @@ -1,2331 +0,0 @@ -/* - * Copyright (C) 2006-2007 Imendio AB - * Copyright (C) 2007-2009 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - * Martyn Russell - * Cosimo Cecchi - * Jonathan Tellier - * Danielle Madeley - */ - -#include "config.h" -#include "empathy-account-widget.h" -#include "empathy-account-widget-private.h" - -#include -#include - -#include "empathy-account-widget-irc.h" -#include "empathy-account-widget-private.h" -#include "empathy-account-widget-sip.h" -#include "empathy-ui-utils.h" -#include "empathy-utils.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT -#include "empathy-debug.h" - -G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, GTK_TYPE_BOX) - -typedef enum -{ - NO_SERVICE = 0, - GTALK_SERVICE, - FACEBOOK_SERVICE, - N_SERVICES -} Service; - -typedef struct -{ - const gchar *label_username_example; - gboolean show_advanced; -} ServiceInfo; - -static ServiceInfo services_infos[N_SERVICES] = { - { "label_username_example", TRUE }, - { "label_username_g_example", FALSE }, - { "label_username_f_example", FALSE }, -}; - -struct _EmpathyAccountWidgetPriv { - EmpathyAccountSettings *settings; - - GtkWidget *grid_common_settings; - GtkWidget *apply_button; - GtkWidget *cancel_button; - GtkWidget *entry_password; - GtkWidget *spinbutton_port; - GtkWidget *radiobutton_reuse; - GtkWidget *hbox_buttons; - - gboolean simple; - - gboolean contains_pending_changes; - - /* 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; - - /* 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; - - gboolean automatic_change; - GtkWidget *remember_password_widget; - - /* Used only for IRC accounts */ - EmpathyIrcNetworkChooser *irc_network_chooser; - - /* Used for 'special' XMPP account having a service associated ensuring that - * JIDs have a specific suffix; such as Facebook for example */ - gchar *jid_suffix; -}; - -enum { - PROP_PROTOCOL = 1, - PROP_SETTINGS, - PROP_SIMPLE, - PROP_CREATING_ACCOUNT, - PROP_OTHER_ACCOUNTS_EXIST, -}; - -enum { - HANDLE_APPLY, - ACCOUNT_CREATED, - CANCELLED, - CLOSE, - LAST_SIGNAL -}; - -enum { - RESPONSE_LAUNCH -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -#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 minimum according to http://en.wikipedia.org/wiki/ICQ#UIN - * According to an user, we can also provide an email address instead of the - * ICQ UIN. */ -#define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")" - -/* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */ -#define IRC_SPECIAL "_\\[\\]{}\\\\|`^" -#define IRC_NICK_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 - * Looks like an email address can be used as well (bgo #655959) - * */ -#define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")" - -#define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$" -#define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$" -#define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@[^@/]+" -#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) -{ - /* we hit this case because of the 'other-accounts-exist' property handler - * being called during init (before constructed()) */ - if (self->priv->apply_button == NULL || self->priv->cancel_button == NULL) - return; - - gtk_widget_set_sensitive (self->priv->apply_button, sensitive); - - if (sensitive) - { - /* We can't grab default if the widget hasn't be packed in a - * window */ - GtkWidget *window; - - window = gtk_widget_get_toplevel (self->priv->apply_button); - if (window != NULL && - gtk_widget_is_toplevel (window)) - { - gtk_widget_set_can_default (self->priv->apply_button, TRUE); - gtk_widget_grab_default (self->priv->apply_button); - } - } -} - -static void -account_widget_set_entry_highlighting (GtkEntry *entry, - gboolean highlight) -{ - g_return_if_fail (GTK_IS_ENTRY (entry)); - - if (highlight) - { - GtkStyleContext *style; - GdkRGBA color; - - style = gtk_widget_get_style_context (GTK_WIDGET (entry)); - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, - &color); - - /* 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. - */ - empathy_make_color_whiter (&color); - - gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color); - } - else - { - gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL); - } -} - -static void -account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self) -{ - gboolean is_valid; - - is_valid = empathy_account_settings_is_valid (self->priv->settings); - - account_widget_set_control_buttons_sensitivity (self, is_valid); - - g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid); -} - -static void -account_widget_entry_changed_common (EmpathyAccountWidget *self, - GtkEntry *entry, gboolean focus) -{ - const gchar *str; - const gchar *param_name; - 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 ( - self->priv->settings, param_name); - - if (EMP_STR_EMPTY (str)) - { - empathy_account_settings_unset (self->priv->settings, param_name); - - if (focus) - { - gchar *value; - - value = empathy_account_settings_dup_string (self->priv->settings, - param_name); - - DEBUG ("Unset %s and restore to %s", param_name, value); - gtk_entry_set_text (entry, value ? value : ""); - g_free (value); - } - } - else - { - DEBUG ("Setting %s to %s", param_name, - tp_strdiff (param_name, "password") ? str : "***"); - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_string (str)); - } - - curr_status = empathy_account_settings_parameter_is_valid ( - self->priv->settings, param_name); - - if (curr_status != prev_status) - account_widget_set_entry_highlighting (entry, !curr_status); -} - -static void -account_widget_entry_changed_cb (GtkEditable *entry, - EmpathyAccountWidget *self) -{ - if (self->priv->automatic_change) - return; - - account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); - empathy_account_widget_changed (self); -} - -static void -account_widget_entry_map_cb (GtkEntry *entry, - EmpathyAccountWidget *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 (self->priv->settings, - param_name); - account_widget_set_entry_highlighting (entry, !is_valid); -} - -static void -account_widget_int_changed_cb (GtkWidget *widget, - EmpathyAccountWidget *self) -{ - const gchar *param_name; - gint value; - const gchar *signature; - - value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - - signature = empathy_account_settings_get_dbus_signature (self->priv->settings, - param_name); - g_return_if_fail (signature != NULL); - - DEBUG ("Setting %s to %d", param_name, value); - - switch ((int)*signature) - { - case DBUS_TYPE_INT16: - case DBUS_TYPE_INT32: - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_int32 (value)); - break; - case DBUS_TYPE_INT64: - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_int64 (value)); - break; - case DBUS_TYPE_UINT16: - case DBUS_TYPE_UINT32: - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_uint32 (value)); - break; - case DBUS_TYPE_UINT64: - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_uint64 (value)); - break; - default: - g_return_if_reached (); - } - - empathy_account_widget_changed (self); -} - -static void -account_widget_checkbutton_toggled_cb (GtkWidget *widget, - EmpathyAccountWidget *self) -{ - gboolean value; - gboolean default_value; - const gchar *param_name; - - value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - - /* FIXME: This is ugly! checkbox don't have a "not-set" value so we - * always unset the param and set the value if different from the - * default value. */ - empathy_account_settings_unset (self->priv->settings, param_name); - default_value = empathy_account_settings_get_boolean (self->priv->settings, - param_name); - - if (default_value == value) - { - DEBUG ("Unset %s and restore to %d", param_name, default_value); - } - else - { - DEBUG ("Setting %s to %d", param_name, value); - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_boolean (value)); - } - - empathy_account_widget_changed (self); -} - -static void -account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, - EmpathyAccountWidget *self) -{ - gboolean value; - gint32 port = 0; - - value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); - port = empathy_account_settings_get_uint32 (self->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 (self->priv->spinbutton_port), - port); - - self->priv->contains_pending_changes = TRUE; -} - -static void -account_widget_combobox_changed_cb (GtkWidget *widget, - EmpathyAccountWidget *self) -{ - GtkTreeIter iter; - GtkTreeModel *model; - const gchar *value; - GVariant *v; - const gchar *default_value = NULL; - const gchar *param_name; - - 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_dup_default (self->priv->settings, param_name); - if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) - default_value = g_variant_get_string (v, NULL); - - if (!tp_strdiff (value, default_value)) - { - DEBUG ("Unset %s and restore to %s", param_name, default_value); - empathy_account_settings_unset (self->priv->settings, param_name); - } - else - { - DEBUG ("Setting %s to %s", param_name, value); - empathy_account_settings_set (self->priv->settings, param_name, - g_variant_new_string (value)); - } - - empathy_account_widget_changed (self); - - tp_clear_pointer (&v, g_variant_unref); -} - -static void -clear_icon_released_cb (GtkEntry *entry, - GtkEntryIconPosition icon_pos, - GdkEvent *event, - EmpathyAccountWidget *self) -{ - const gchar *param_name; - - param_name = g_object_get_data (G_OBJECT (entry), "param_name"); - - DEBUG ("Unset %s", param_name); - empathy_account_settings_unset (self->priv->settings, param_name); - gtk_entry_set_text (entry, ""); - - empathy_account_widget_changed (self); -} - -static void -password_entry_changed_cb (GtkEditable *entry, - EmpathyAccountWidget *self) -{ - const gchar *str; - - str = gtk_entry_get_text (GTK_ENTRY (entry)); - - gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), - GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str)); -} - -static void -password_entry_activated_cb (GtkEntry *entry, - EmpathyAccountWidget *self) -{ - if (gtk_widget_get_sensitive (self->priv->apply_button)) - empathy_account_widget_apply_and_log_in (self); -} - -static void -account_entry_activated_cb (GtkEntry *entry, - EmpathyAccountWidget *self) -{ - if (gtk_widget_get_sensitive (self->priv->apply_button)) - empathy_account_widget_apply_and_log_in (self); -} - -void -empathy_account_widget_setup_widget (EmpathyAccountWidget *self, - GtkWidget *widget, - const gchar *param_name) -{ - g_object_set_data_full (G_OBJECT (widget), "param_name", - g_strdup (param_name), g_free); - - if (GTK_IS_SPIN_BUTTON (widget)) - { - gint value = 0; - const gchar *signature; - - signature = empathy_account_settings_get_dbus_signature ( - self->priv->settings, param_name); - g_return_if_fail (signature != NULL); - - switch ((int)*signature) - { - case DBUS_TYPE_INT16: - case DBUS_TYPE_INT32: - value = empathy_account_settings_get_int32 (self->priv->settings, - param_name); - break; - case DBUS_TYPE_INT64: - value = empathy_account_settings_get_int64 (self->priv->settings, - param_name); - break; - case DBUS_TYPE_UINT16: - case DBUS_TYPE_UINT32: - value = empathy_account_settings_get_uint32 (self->priv->settings, - param_name); - break; - case DBUS_TYPE_UINT64: - value = empathy_account_settings_get_uint64 (self->priv->settings, - param_name); - break; - default: - g_return_if_reached (); - } - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); - - g_signal_connect (widget, "value-changed", - G_CALLBACK (account_widget_int_changed_cb), - self); - } - else if (GTK_IS_ENTRY (widget)) - { - gchar *str; - - str = empathy_account_settings_dup_string (self->priv->settings, - param_name); - gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); - - if (!tp_strdiff (param_name, "account")) - self->priv->param_account_widget = widget; - else if (!tp_strdiff (param_name, "password")) - self->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); - - g_free (str); - } - else if (GTK_IS_TOGGLE_BUTTON (widget)) - { - gboolean value = FALSE; - - value = empathy_account_settings_get_boolean (self->priv->settings, - param_name); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); - - g_signal_connect (widget, "toggled", - 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) */ - gchar *str; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid; - - str = empathy_account_settings_dup_string (self->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_free (str); - - g_signal_connect (widget, "changed", - G_CALLBACK (account_widget_combobox_changed_cb), - self); - } - else - { - DEBUG ("Unknown type of widget for param %s", param_name); - } - - gtk_widget_set_sensitive (widget, - empathy_account_settings_param_is_supported (self->priv->settings, - 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; - - g_return_val_if_fail (param_name != NULL, 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); - - if (str && g_ascii_isalpha (str[0])) - str[0] = g_ascii_toupper (str[0]); - - while ((p = strchr (str, '-')) != NULL) - { - if (p[1] != '\0' && g_ascii_isalpha (p[1])) - { - p[0] = ' '; - p[1] = g_ascii_toupper (p[1]); - } - - p++; - } - - return str; -} - -static void -accounts_widget_generic_setup (EmpathyAccountWidget *self, - GtkWidget *grid_common_settings, - GtkWidget *grid_advanced_settings) -{ - GList *params, *l; - guint row_common = 0, row_advanced = 0; - - params = empathy_account_settings_dup_tp_params (self->priv->settings); - - for (l = params; l != NULL; l = g_list_next (l)) - { - TpConnectionManagerParam *param = l->data; - GtkWidget *grid_settings; - guint row; - GtkWidget *widget = NULL; - gchar *param_name_formatted; - const gchar *dbus_signature; - - if (tp_connection_manager_param_is_required (param)) - { - grid_settings = grid_common_settings; - row = row_common++; - } - else if (self->priv->simple) - { - continue; - } - else - { - grid_settings = grid_advanced_settings; - row = row_advanced++; - } - - param_name_formatted = account_widget_generic_format_param_name ( - tp_connection_manager_param_get_name (param)); - - dbus_signature = tp_connection_manager_param_get_dbus_signature (param); - - if (dbus_signature[0] == 's') - { - gchar *str; - - str = g_strdup_printf (_("%s"), param_name_formatted); - widget = gtk_label_new (str); - gtk_misc_set_alignment (GTK_MISC (widget), 1., 0.5); - gtk_style_context_add_class (gtk_widget_get_style_context (widget), - GTK_STYLE_CLASS_DIM_LABEL); - g_free (str); - - gtk_grid_attach (GTK_GRID (grid_settings), - widget, 0, row, 1, 1); - - gtk_widget_show (widget); - - widget = gtk_entry_new (); - if (strcmp (tp_connection_manager_param_get_name (param), - "account") == 0) - { - g_signal_connect (widget, "realize", - G_CALLBACK (gtk_widget_grab_focus), - NULL); - } - - gtk_grid_attach (GTK_GRID (grid_settings), - widget, 1, row, 1, 1); - - gtk_widget_show (widget); - } - /* int types: ynqiuxt. double type is 'd' */ - else if (dbus_signature[0] == 'y' || - dbus_signature[0] == 'n' || - dbus_signature[0] == 'q' || - dbus_signature[0] == 'i' || - dbus_signature[0] == 'u' || - dbus_signature[0] == 'x' || - dbus_signature[0] == 't' || - dbus_signature[0] == 'd') - { - gchar *str = NULL; - gdouble minint = 0; - gdouble maxint = 0; - gdouble step = 1; - - switch (dbus_signature[0]) - { - case 'y': minint = G_MININT8; maxint = G_MAXINT8; break; - case 'n': minint = G_MININT16; maxint = G_MAXINT16; break; - case 'q': minint = 0; maxint = G_MAXUINT16; break; - case 'i': minint = G_MININT32; maxint = G_MAXINT32; break; - case 'u': minint = 0; maxint = G_MAXUINT32; break; - case 'x': minint = G_MININT64; maxint = G_MAXINT64; break; - 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); - widget = gtk_label_new (str); - gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5); - g_free (str); - - gtk_grid_attach (GTK_GRID (grid_settings), - widget, 0, row, 1, 1); - gtk_widget_show (widget); - - widget = gtk_spin_button_new_with_range (minint, maxint, step); - gtk_grid_attach (GTK_GRID (grid_settings), - widget, 1, row, 1, 1); - gtk_widget_show (widget); - } - else if (dbus_signature[0] == 'b') - { - widget = gtk_check_button_new_with_label (param_name_formatted); - gtk_grid_attach (GTK_GRID (grid_settings), - widget, 0, row, 2, 1); - gtk_widget_show (widget); - } - else - { - DEBUG ("Unknown signature for param %s: %s", - param_name_formatted, dbus_signature); - } - - if (widget) - empathy_account_widget_setup_widget (self, widget, - tp_connection_manager_param_get_name (param)); - - g_free (param_name_formatted); - } - - g_list_free_full (params, (GDestroyNotify) tp_connection_manager_param_free); -} - -static void -account_widget_handle_params_valist (EmpathyAccountWidget *self, - const gchar *first_widget, - va_list args) -{ - GObject *object; - const gchar *name; - - for (name = first_widget; name; name = va_arg (args, const gchar *)) - { - const gchar *param_name; - - param_name = va_arg (args, const gchar *); - object = gtk_builder_get_object (self->ui_details->gui, name); - - if (!object) - { - g_warning ("Builder is missing object '%s'.", name); - continue; - } - - empathy_account_widget_setup_widget (self, GTK_WIDGET (object), - param_name); - } -} - -static void -account_widget_cancel_clicked_cb (GtkWidget *button, - EmpathyAccountWidget *self) -{ - g_signal_emit (self, signals[CANCELLED], 0); - g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_CANCEL); -} - -static void -account_widget_account_enabled_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - TpAccount *account = TP_ACCOUNT (source_object); - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data); - - tp_account_set_enabled_finish (account, res, &error); - - if (error != NULL) - { - DEBUG ("Could not enable the account: %s", error->message); - g_error_free (error); - } - else - { - empathy_connect_new_account (account, self->priv->account_manager); - } - - g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY); - - /* unref self - part of the workaround */ - g_object_unref (self); -} - -static void -account_widget_applied_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - TpAccount *account; - EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object); - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data); - gboolean reconnect_required; - gboolean fire_close = TRUE; - - empathy_account_settings_apply_finish (settings, res, &reconnect_required, - &error); - - if (error != NULL) - { - DEBUG ("Could not apply changes to account: %s", error->message); - g_error_free (error); - return; - } - - account = empathy_account_settings_get_account (self->priv->settings); - - if (account != NULL) - { - if (self->priv->creating_account) - { - /* By default, when an account is created, we enable it. */ - - /* workaround to keep self alive during async call */ - g_object_ref (self); - - tp_account_set_enabled_async (account, TRUE, - account_widget_account_enabled_cb, self); - g_signal_emit (self, signals[ACCOUNT_CREATED], 0, account); - - /* Will be fired in account_widget_account_enabled_cb */ - fire_close = FALSE; - } - else - { - /* If the account was offline, we always want to try reconnecting, - * to give it a chance to connect if the previous params were wrong. - * tp_account_reconnect_async() won't do anything if the requested - * presence is offline anyway. */ - if (tp_account_get_connection_status (account, NULL) == - TP_CONNECTION_STATUS_DISCONNECTED) - reconnect_required = TRUE; - - if (reconnect_required && tp_account_is_enabled (account) - && tp_account_is_enabled (account)) - { - /* After having applied changes to a user account, we - * reconnect it if needed. This is done so the new - * information entered by the user is validated on the server. */ - tp_account_reconnect_async (account, NULL, NULL); - } - } - } - - if (!self->priv->destroyed) - account_widget_set_control_buttons_sensitivity (self, FALSE); - - self->priv->contains_pending_changes = FALSE; - - if (fire_close) - { - /* announce the widget can be closed */ - g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY); - } - - /* unref the widget - part of the workaround */ - g_object_unref (self); -} - -void -empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self) -{ - gboolean display_name_overridden; - - if (self->priv->radiobutton_reuse != NULL) - { - gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ( - self->priv->radiobutton_reuse)); - - DEBUG ("Set register param: %d", !reuse); - empathy_account_settings_set (self->priv->settings, "register", - g_variant_new_boolean (!reuse)); - } - - g_object_get (self->priv->settings, - "display-name-overridden", &display_name_overridden, NULL); - - if (self->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 (self->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 (self->priv->settings, - account_widget_applied_cb, self); -} - -static void -account_widget_apply_clicked_cb (GtkWidget *button, - EmpathyAccountWidget *self) -{ - empathy_account_widget_apply_and_log_in (self); -} - -static void -account_widget_setup_generic (EmpathyAccountWidget *self) -{ - GtkWidget *grid_common_settings; - GtkWidget *grid_advanced_settings; - - grid_common_settings = GTK_WIDGET (gtk_builder_get_object - (self->ui_details->gui, "grid_common_settings")); - grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object - (self->ui_details->gui, "grid_advanced_settings")); - - accounts_widget_generic_setup (self, grid_common_settings, - grid_advanced_settings); - - g_object_unref (self->ui_details->gui); -} - -static void -account_widget_settings_ready_cb (EmpathyAccountSettings *settings, - GParamSpec *pspec, - gpointer user_data) -{ - EmpathyAccountWidget *self = user_data; - - if (empathy_account_settings_is_ready (self->priv->settings)) - account_widget_setup_generic (self); -} - -static GtkWidget * -account_widget_build_generic (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *expander_advanced, *box; - - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_generic_settings", &box, - "expander_advanced_settings", &expander_advanced, - NULL); - - if (self->priv->simple) - gtk_widget_hide (expander_advanced); - - g_object_ref (self->ui_details->gui); - - if (empathy_account_settings_is_ready (self->priv->settings)) - account_widget_setup_generic (self); - else - g_signal_connect (self->priv->settings, "notify::ready", - G_CALLBACK (account_widget_settings_ready_cb), self); - - return box; -} - -static GtkWidget * -account_widget_build_salut (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *expander_advanced, *box; - - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_salut_settings", &box, - "expander_advanced_settings", &expander_advanced, - NULL); - - empathy_account_widget_handle_params (self, - "entry_published", "published-name", - "entry_nickname", "nickname", - "entry_first_name", "first-name", - "entry_last_name", "last-name", - "entry_email", "email", - "entry_jid", "jid", - NULL); - - if (self->priv->simple) - gtk_widget_hide (expander_advanced); - - self->ui_details->default_focus = g_strdup ("entry_first_name"); - - return box; -} - -static GtkWidget * -account_widget_build_irc (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *box; - - empathy_account_settings_set_regex (self->priv->settings, "account", - ACCOUNT_REGEX_IRC); - - if (self->priv->simple) - { - self->priv->irc_network_chooser = empathy_account_widget_irc_build_simple - (self, filename, &box); - } - else - { - self->priv->irc_network_chooser = empathy_account_widget_irc_build (self, - filename, &self->priv->grid_common_settings, &box); - } - - return box; -} - -static GtkWidget * -account_widget_build_sip (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *box; - - box = empathy_account_widget_sip_build (self, filename, - &self->priv->grid_common_settings); - - if (self->priv->simple) - { - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -static GtkWidget * -account_widget_build_msn (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *box; - - empathy_account_settings_set_regex (self->priv->settings, "account", - ACCOUNT_REGEX_MSN); - - if (self->priv->simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_msn_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_msn_settings", &self->priv->grid_common_settings, - "vbox_msn_settings", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -static void -suffix_id_widget_changed_cb (GtkWidget *entry, - EmpathyAccountWidget *self) -{ - gchar *account; - - g_assert (self->priv->jid_suffix != NULL); - - account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); - - account = empathy_account_settings_dup_string (self->priv->settings, - "account"); - - if (!EMP_STR_EMPTY (account) && - !g_str_has_suffix (account, self->priv->jid_suffix)) - { - gchar *tmp; - - tmp = g_strdup_printf ("%s%s", account, self->priv->jid_suffix); - - DEBUG ("Change account from '%s' to '%s'", account, tmp); - - empathy_account_settings_set (self->priv->settings, "account", - g_variant_new_string (tmp)); - g_free (tmp); - } - - empathy_account_widget_changed (self); - - g_free (account); -} - -static gchar * -remove_jid_suffix (EmpathyAccountWidget *self, - const gchar *str) -{ - g_assert (self->priv->jid_suffix != NULL); - - if (!g_str_has_suffix (str, self->priv->jid_suffix)) - return g_strdup (str); - - return g_strndup (str, strlen (str) - strlen (self->priv->jid_suffix)); -} - -static void -setup_id_widget_with_suffix (EmpathyAccountWidget *self, - GtkWidget *widget, - const gchar *suffix) -{ - gchar *str = NULL; - - g_object_set_data_full (G_OBJECT (widget), "param_name", - g_strdup ("account"), g_free); - - g_assert (self->priv->jid_suffix == NULL); - self->priv->jid_suffix = g_strdup (suffix); - - str = empathy_account_settings_dup_string (self->priv->settings, "account"); - if (str != NULL) - { - gchar *tmp; - - tmp = remove_jid_suffix (self, str); - gtk_entry_set_text (GTK_ENTRY (widget), tmp); - g_free (tmp); - g_free (str); - } - - self->priv->param_account_widget = widget; - - g_signal_connect (widget, "changed", - G_CALLBACK (suffix_id_widget_changed_cb), self); -} - -static Service -account_widget_get_service (EmpathyAccountWidget *self) -{ - const gchar *icon_name, *service; - - icon_name = empathy_account_settings_get_icon_name (self->priv->settings); - service = empathy_account_settings_get_service (self->priv->settings); - - /* Previous versions of Empathy didn't set the Service property on Facebook - * and gtalk accounts, so we check using the icon name as well. */ - if (!tp_strdiff (icon_name, "im-google-talk") || - !tp_strdiff (service, "google-talk")) - return GTALK_SERVICE; - - if (!tp_strdiff (icon_name, "im-facebook") || - !tp_strdiff (service, "facebook")) - return FACEBOOK_SERVICE; - - return NO_SERVICE; -} - -static GtkWidget * -account_widget_build_jabber (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *spinbutton_port; - GtkWidget *checkbutton_ssl; - GtkWidget *label_id, *label_password; - GtkWidget *label_id_create, *label_password_create; - GtkWidget *label_example_fb; - GtkWidget *label_example; - GtkWidget *expander_advanced; - GtkWidget *entry_id; - GtkWidget *box; - Service service; - - service = account_widget_get_service (self); - - empathy_account_settings_set_regex (self->priv->settings, "account", - ACCOUNT_REGEX_JABBER); - - if (self->priv->simple && service == NO_SERVICE) - { - /* Simple widget for XMPP */ - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_jabber_simple", &box, - "label_id_simple", &label_id, - "label_id_create", &label_id_create, - "label_password_simple", &label_password, - "label_password_create", &label_password_create, - NULL); - - if (empathy_account_settings_get_boolean (self->priv->settings, - "register")) - { - gtk_widget_hide (label_id); - gtk_widget_hide (label_password); - gtk_widget_show (label_id_create); - gtk_widget_show (label_password_create); - } - - empathy_account_widget_handle_params (self, - "entry_id_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else if (self->priv->simple && service == GTALK_SERVICE) - { - /* Simple widget for Google Talk */ - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_gtalk_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id_g_simple", "account", - "entry_password_g_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id_g_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_g_simple")); - } - else if (self->priv->simple && service == FACEBOOK_SERVICE) - { - /* Simple widget for Facebook */ - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_fb_simple", &box, - "entry_id_fb_simple", &entry_id, - NULL); - - empathy_account_widget_handle_params (self, - "entry_password_fb_simple", "password", - NULL); - - setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com"); - - self->ui_details->default_focus = g_strdup ("entry_id_fb_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_fb_simple")); - } - else - { - ServiceInfo info = services_infos[service]; - - /* Full widget for XMPP, Google Talk and Facebook*/ - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_jabber_settings", &box, - "spinbutton_port", &spinbutton_port, - "checkbutton_ssl", &checkbutton_ssl, - "label_username_f_example", &label_example_fb, - info.label_username_example, &label_example, - "expander_advanced", &expander_advanced, - "entry_id", &entry_id, - "label_id", &label_id, - NULL); - - empathy_account_widget_handle_params (self, - "entry_password", "password", - "entry_resource", "resource", - "entry_server", "server", - "spinbutton_port", "port", - "spinbutton_priority", "priority", - "checkbutton_ssl", "old-ssl", - "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", - "checkbutton_encryption", "require-encryption", - NULL); - - if (service == FACEBOOK_SERVICE) - { - gtk_label_set_label (GTK_LABEL (label_id), _("Username:")); - - /* Facebook special case the entry ID widget to hide the - * "@chat.facebook.com" part */ - setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com"); - } - else - { - empathy_account_widget_setup_widget (self, entry_id, "account"); - } - - self->ui_details->default_focus = g_strdup ("entry_id"); - self->priv->spinbutton_port = spinbutton_port; - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - - g_signal_connect (checkbutton_ssl, "toggled", - G_CALLBACK (account_widget_jabber_ssl_toggled_cb), - self); - - if (service == FACEBOOK_SERVICE) - { - GtkContainer *parent; - GList *children; - - /* 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); - - if (!info.show_advanced) - gtk_widget_hide (expander_advanced); - } - - return box; -} - -static GtkWidget * -account_widget_build_icq (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *spinbutton_port; - GtkWidget *box; - - empathy_account_settings_set_regex (self->priv->settings, "account", - ACCOUNT_REGEX_ICQ); - - if (self->priv->simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_icq_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_uin_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_uin_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_icq_settings", &box, - "spinbutton_port", &spinbutton_port, - NULL); - - empathy_account_widget_handle_params (self, - "entry_uin", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - "entry_charset", "charset", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_uin"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -static GtkWidget * -account_widget_build_aim (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *spinbutton_port, *box; - - if (self->priv->simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_aim_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_screenname_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_screenname_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_aim_settings", &box, - "spinbutton_port", &spinbutton_port, - NULL); - - empathy_account_widget_handle_params (self, - "entry_screenname", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_screenname"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -static GtkWidget * -account_widget_build_yahoo (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *box; - - empathy_account_settings_set_regex (self->priv->settings, "account", - ACCOUNT_REGEX_YAHOO); - - if (self->priv->simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_yahoo_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_settings", &self->priv->grid_common_settings, - "vbox_yahoo_settings", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_locale", "room-list-locale", - "entry_charset", "charset", - "spinbutton_port", "port", - "checkbutton_ignore_invites", "ignore-invites", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -static GtkWidget * -account_widget_build_groupwise (EmpathyAccountWidget *self, - const char *filename) -{ - GtkWidget *box; - - if (self->priv->simple) - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "vbox_groupwise_simple", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id_simple", "account", - "entry_password_simple", "password", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id_simple"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, - "remember_password_simple")); - } - else - { - self->ui_details->gui = empathy_builder_get_resource (filename, - "grid_common_groupwise_settings", &self->priv->grid_common_settings, - "vbox_groupwise_settings", &box, - NULL); - - empathy_account_widget_handle_params (self, - "entry_id", "account", - "entry_password", "password", - "entry_server", "server", - "spinbutton_port", "port", - NULL); - - self->ui_details->default_focus = g_strdup ("entry_id"); - - self->priv->remember_password_widget = GTK_WIDGET ( - gtk_builder_get_object (self->ui_details->gui, "remember_password")); - } - - return box; -} - -void -empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self, - gboolean others_exist) -{ - self->priv->other_accounts_exist = others_exist; - - if (self->priv->creating_account) - account_widget_handle_control_buttons_sensitivity (self); -} - -static void -do_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object); - - switch (prop_id) - { - case PROP_SETTINGS: - self->priv->settings = g_value_dup_object (value); - break; - case PROP_SIMPLE: - self->priv->simple = g_value_get_boolean (value); - break; - case PROP_CREATING_ACCOUNT: - self->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); - } -} - -static void -do_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object); - - switch (prop_id) - { - case PROP_PROTOCOL: - g_value_set_string (value, - empathy_account_settings_get_protocol (self->priv->settings)); - break; - case PROP_SETTINGS: - g_value_set_object (value, self->priv->settings); - break; - case PROP_SIMPLE: - g_value_set_boolean (value, self->priv->simple); - break; - case PROP_CREATING_ACCOUNT: - g_value_set_boolean (value, self->priv->creating_account); - break; - case PROP_OTHER_ACCOUNTS_EXIST: - g_value_set_boolean (value, self->priv->other_accounts_exist); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -set_apply_button (EmpathyAccountWidget *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 (self->priv->apply_button), FALSE); - - gtk_button_set_label (GTK_BUTTON (self->priv->apply_button), _("A_pply")); - gtk_button_set_use_underline (GTK_BUTTON (self->priv->apply_button), TRUE); - - image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image); -} - -static void -presence_changed_cb (TpAccountManager *manager, - TpConnectionPresenceType state, - const gchar *status, - const gchar *message, - EmpathyAccountWidget *self) -{ - if (self->priv->destroyed) - return; - - if (self->priv->apply_button == NULL) - /* This button doesn't exist in 'simple' mode */ - return; - - if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE && - self->priv->creating_account) - { - /* We are online and creating a new account, display a Login button */ - GtkWidget *image; - - gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE); - gtk_button_set_label (GTK_BUTTON (self->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 (self->priv->apply_button), image); - } - else - { - /* 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_proxy_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, ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-"#proto".ui", \ - account_widget_build_##proto } - -static void -add_register_buttons (EmpathyAccountWidget *self, - TpAccount *account) -{ - TpProtocol *protocol; - GtkWidget *radiobutton_register; - - if (!self->priv->creating_account) - return; - - protocol = empathy_account_settings_get_tp_protocol (self->priv->settings); - if (protocol == NULL) - return; - - if (!tp_protocol_can_register (protocol)) - return; - - if (account_widget_get_service (self) != NO_SERVICE) - return; - - if (self->priv->simple) - return; - - self->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 (self->priv->radiobutton_reuse)), - _("Create a new account on the server")); - - gtk_box_pack_start (GTK_BOX (self), self->priv->radiobutton_reuse, FALSE, - FALSE, 0); - gtk_box_pack_start (GTK_BOX (self), radiobutton_register, FALSE, FALSE, 0); - gtk_box_reorder_child (GTK_BOX (self), self->priv->radiobutton_reuse, 0); - gtk_box_reorder_child (GTK_BOX (self), radiobutton_register, 1); - gtk_widget_show (self->priv->radiobutton_reuse); - gtk_widget_show (radiobutton_register); -} - -static void -remember_password_toggled_cb (GtkToggleButton *button, - EmpathyAccountWidget *self) -{ - empathy_account_settings_set_remember_password (self->priv->settings, - gtk_toggle_button_get_active (button)); - - if (!self->priv->automatic_change) - empathy_account_widget_changed (self); -} - -static void -account_settings_password_retrieved_cb (GObject *object, - gpointer user_data) -{ - EmpathyAccountWidget *self = user_data; - gchar *password; - - password = empathy_account_settings_dup_string ( - self->priv->settings, "password"); - - /* We have to do this so that when we call gtk_entry_set_text, - * the ::changed callback doesn't think the user made the - * change. This is also used in remember_password_toggled_cb. */ - self->priv->automatic_change = TRUE; - - if (password != NULL) - { - gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), - password); - } - - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), - !EMP_STR_EMPTY (password)); - - self->priv->automatic_change = FALSE; - - g_free (password); -} - -static void -do_constructed (GObject *obj) -{ - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); - TpAccount *account; - const gchar *display_name, *default_display_name; - guint i = 0; - struct { - const gchar *cm_name; - const gchar *protocol; - const char *file; - GtkWidget * (*func)(EmpathyAccountWidget *self, const gchar *filename); - } widgets [] = { - { "salut", "local-xmpp", ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-local-xmpp.ui", - account_widget_build_salut }, - WIDGET (gabble, jabber), - WIDGET (haze, msn), - WIDGET (haze, icq), - WIDGET (haze, aim), - WIDGET (haze, yahoo), - WIDGET (haze, groupwise), - WIDGET (idle, irc), - WIDGET (sofiasip, sip), - }; - const gchar *protocol, *cm_name; - GtkWidget *box; - - account = empathy_account_settings_get_account (self->priv->settings); - - cm_name = empathy_account_settings_get_cm (self->priv->settings); - protocol = empathy_account_settings_get_protocol (self->priv->settings); - - for (i = 0 ; i < G_N_ELEMENTS (widgets); i++) - { - if (!tp_strdiff (widgets[i].cm_name, cm_name) && - !tp_strdiff (widgets[i].protocol, protocol)) - { - box = widgets[i].func (self, widgets[i].file); - break; - } - } - - if (i == G_N_ELEMENTS (widgets)) - { - gchar *filename = ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-generic.ui"; - box = account_widget_build_generic (self, filename); - } - - gtk_container_add (GTK_CONTAINER (self), box); - - /* handle default focus */ - if (self->ui_details->default_focus != NULL) - { - GObject *default_focus_entry; - - default_focus_entry = gtk_builder_get_object - (self->ui_details->gui, self->ui_details->default_focus); - g_signal_connect (default_focus_entry, "realize", - G_CALLBACK (gtk_widget_grab_focus), - NULL); - } - - /* remember password */ - if (self->priv->param_password_widget != NULL - && self->priv->remember_password_widget != NULL - && empathy_account_settings_supports_sasl (self->priv->settings)) - { - if (self->priv->simple) - { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), TRUE); - } - else - { - gchar *password; - - password = empathy_account_settings_dup_string (self->priv->settings, - "password"); - - /* FIXME: we should enable this checkbox only if the password is - * stored for good in the password storage, not only for the session - * (bgo #683571) */ - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), - !EMP_STR_EMPTY (password)); - - /* The password might not have been retrieved from the - * keyring yet. We should update the remember password - * toggle button and the password entry when/if it is. */ - tp_g_signal_connect_object (self->priv->settings, - "password-retrieved", - G_CALLBACK (account_settings_password_retrieved_cb), self, 0); - - g_free (password); - } - - g_signal_connect (self->priv->remember_password_widget, "toggled", - G_CALLBACK (remember_password_toggled_cb), self); - - self->priv->automatic_change = TRUE; - remember_password_toggled_cb ( - GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), self); - self->priv->automatic_change = FALSE; - } - else if (self->priv->remember_password_widget != NULL - && !empathy_account_settings_supports_sasl (self->priv->settings)) - { - gtk_widget_set_visible (self->priv->remember_password_widget, FALSE); - empathy_account_settings_set_remember_password (self->priv->settings, - TRUE); - } - - /* dup and init the account-manager */ - self->priv->account_manager = tp_account_manager_dup (); - - g_object_ref (self); - tp_proxy_prepare_async (self->priv->account_manager, NULL, - account_manager_ready_cb, self); - - /* handle apply and cancel button */ - self->priv->hbox_buttons = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); - - gtk_box_set_homogeneous (GTK_BOX (self->priv->hbox_buttons), TRUE); - - self->priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); - - self->priv->apply_button = gtk_button_new (); - set_apply_button (self); - - /* 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 (self->priv->account_manager, - "most-available-presence-changed", - G_CALLBACK (presence_changed_cb), obj, 0); - - gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons), - self->priv->apply_button, TRUE, TRUE, 3); - gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons), - self->priv->cancel_button, TRUE, TRUE, 3); - - gtk_box_pack_end (GTK_BOX (self), self->priv->hbox_buttons, FALSE, - FALSE, 3); - - g_signal_connect (self->priv->cancel_button, "clicked", - G_CALLBACK (account_widget_cancel_clicked_cb), - self); - g_signal_connect (self->priv->apply_button, "clicked", - G_CALLBACK (account_widget_apply_clicked_cb), - self); - gtk_widget_show_all (self->priv->hbox_buttons); - - if (self->priv->creating_account) - /* When creating an account, the user might have nothing to enter. - * That means that no control interaction might occur, - * so we update the control button sensitivity manually. - */ - account_widget_handle_control_buttons_sensitivity (self); - else - account_widget_set_control_buttons_sensitivity (self, FALSE); - - add_register_buttons (self, account); - - g_clear_object (&self->ui_details->gui); - - display_name = empathy_account_settings_get_display_name ( - self->priv->settings); - default_display_name = empathy_account_widget_get_default_display_name (self); - - if (tp_strdiff (display_name, default_display_name) && - !self->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 (self->priv->settings, "display-name-overridden", TRUE, - NULL); - } -} - -static void -do_dispose (GObject *obj) -{ - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); - - g_clear_object (&self->priv->settings); - g_clear_object (&self->priv->account_manager); - - if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL) - G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj); -} - -static void -do_finalize (GObject *obj) -{ - EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); - - g_free (self->ui_details->default_focus); - g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details); - - g_free (self->priv->jid_suffix); - - if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL) - G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj); -} - -static void -empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) -{ - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - oclass->get_property = do_get_property; - oclass->set_property = do_set_property; - oclass->constructed = do_constructed; - oclass->dispose = do_dispose; - oclass->finalize = do_finalize; - - param_spec = g_param_spec_string ("protocol", - "protocol", "The protocol of the account", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec); - - param_spec = g_param_spec_object ("settings", - "settings", "The settings of the account", - EMPATHY_TYPE_ACCOUNT_SETTINGS, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); - - param_spec = g_param_spec_boolean ("simple", - "simple", "Whether the account widget is a simple or an advanced one", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (oclass, PROP_SIMPLE, param_spec); - - param_spec = g_param_spec_boolean ("creating-account", - "creating-account", - "TRUE if we're creating an account, FALSE if we're modifying it", - FALSE, - 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, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, G_TYPE_BOOLEAN); - - /* This signal is emitted when an account has been created and enabled. */ - signals[ACCOUNT_CREATED] = - g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, G_TYPE_OBJECT); - - signals[CANCELLED] = - g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 0); - - signals[CLOSE] = - g_signal_new ("close", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, - 1, G_TYPE_INT); - - g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); -} - -static void -empathy_account_widget_init (EmpathyAccountWidget *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, - EmpathyAccountWidgetPriv); - - self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); -} - -/* public methods */ - -void -empathy_account_widget_discard_pending_changes (EmpathyAccountWidget *self) -{ - empathy_account_settings_discard_changes (self->priv->settings); - self->priv->contains_pending_changes = FALSE; -} - -gboolean -empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *self) -{ - return self->priv->contains_pending_changes; -} - -void -empathy_account_widget_handle_params (EmpathyAccountWidget *self, - const gchar *first_widget, - ...) -{ - va_list args; - - va_start (args, first_widget); - account_widget_handle_params_valist (self, first_widget, args); - va_end (args); -} - -EmpathyAccountWidget * -empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings, - gboolean simple) -{ - g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); - - return g_object_new (EMPATHY_TYPE_ACCOUNT_WIDGET, - "orientation", GTK_ORIENTATION_VERTICAL, - "settings", settings, - "simple", simple, - "creating-account", - empathy_account_settings_get_account (settings) == NULL, - NULL); -} - -gchar * -empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self) -{ - gchar *login_id; - const gchar *protocol, *p; - gchar *default_display_name; - Service service; - - login_id = empathy_account_settings_dup_string (self->priv->settings, - "account"); - protocol = empathy_account_settings_get_protocol (self->priv->settings); - service = account_widget_get_service (self); - - if (login_id != NULL) - { - /* TODO: this should be done in empathy-account-widget-irc */ - if (!tp_strdiff (protocol, "irc")) - { - EmpathyIrcNetwork *network; - - network = empathy_irc_network_chooser_get_network ( - self->priv->irc_network_chooser); - g_assert (network != NULL); - - /* To translators: The first parameter is the login id and the - * 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, empathy_irc_network_get_name (network)); - } - else if (service == FACEBOOK_SERVICE && self->priv->jid_suffix != NULL) - { - gchar *tmp; - - tmp = remove_jid_suffix (self, login_id); - default_display_name = g_strdup_printf ("Facebook (%s)", tmp); - g_free (tmp); - } - else - { - default_display_name = g_strdup (login_id); - } - - return default_display_name; - } - - if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL) - protocol = p; - - if (protocol != NULL) - { - /* To translators: The parameter is the protocol name. The resulting - * string will be something like: "Jabber Account" */ - default_display_name = g_strdup_printf (_("%s Account"), protocol); - } - else - { - default_display_name = g_strdup (_("New account")); - } - - g_free (login_id); - - return default_display_name; -} - -/* Used by subclass to indicate that widget contains pending changes */ -void -empathy_account_widget_changed (EmpathyAccountWidget *self) -{ - account_widget_handle_control_buttons_sensitivity (self); - self->priv->contains_pending_changes = TRUE; -} - -void -empathy_account_widget_set_account_param (EmpathyAccountWidget *self, - const gchar *account) -{ - if (self->priv->param_account_widget == NULL) - return; - - gtk_entry_set_text (GTK_ENTRY (self->priv->param_account_widget), account); -} - -void -empathy_account_widget_set_password_param (EmpathyAccountWidget *self, - const gchar *account) -{ - if (self->priv->param_password_widget == NULL) - return; - - gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), account); -} - -EmpathyAccountSettings * -empathy_account_widget_get_settings (EmpathyAccountWidget *self) -{ - return self->priv->settings; -} - -void -empathy_account_widget_hide_buttons (EmpathyAccountWidget *self) -{ - gtk_widget_hide (self->priv->hbox_buttons); -} diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h deleted file mode 100644 index 65de952c7..000000000 --- a/libempathy-gtk/empathy-account-widget.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2006-2007 Imendio AB - * Copyright (C) 2007-2008 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - * Martyn Russell - */ - -#ifndef __EMPATHY_ACCOUNT_WIDGET_H__ -#define __EMPATHY_ACCOUNT_WIDGET_H__ - -#include - -#include "empathy-account-settings.h" - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_ACCOUNT_WIDGET empathy_account_widget_get_type() -#define EMPATHY_ACCOUNT_WIDGET(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidget)) -#define EMPATHY_ACCOUNT_WIDGET_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) -#define EMPATHY_IS_ACCOUNT_WIDGET(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET)) -#define EMPATHY_IS_ACCOUNT_WIDGET_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET)) -#define EMPATHY_ACCOUNT_WIDGET_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) - -typedef struct _EmpathyAccountWidgetPriv EmpathyAccountWidgetPriv; -typedef struct _EmpathyAccountWidgetUIDetails EmpathyAccountWidgetUIDetails; - -typedef struct { - GtkBox parent; - - EmpathyAccountWidgetUIDetails *ui_details; - - EmpathyAccountWidgetPriv *priv; -} EmpathyAccountWidget; - -typedef struct { - GtkBoxClass parent_class; -} EmpathyAccountWidgetClass; - -GType empathy_account_widget_get_type (void); - -EmpathyAccountWidget * empathy_account_widget_new_for_protocol ( - EmpathyAccountSettings *settings, - gboolean simple); - -gboolean empathy_account_widget_contains_pending_changes - (EmpathyAccountWidget *widget); -void empathy_account_widget_discard_pending_changes - (EmpathyAccountWidget *widget); - -gchar * empathy_account_widget_get_default_display_name ( - EmpathyAccountWidget *widget); - -void empathy_account_widget_set_account_param (EmpathyAccountWidget *widget, - const gchar *account); - -void empathy_account_widget_set_password_param (EmpathyAccountWidget *self, - const gchar *password); - -void empathy_account_widget_set_other_accounts_exist ( - EmpathyAccountWidget *self, gboolean others_exist); - -void empathy_account_widget_hide_buttons (EmpathyAccountWidget *self); - -void empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self); - -/* protected methods */ -void empathy_account_widget_changed (EmpathyAccountWidget *widget); - -EmpathyAccountSettings * empathy_account_widget_get_settings ( - EmpathyAccountWidget *self); - -G_END_DECLS - -#endif /* __EMPATHY_ACCOUNT_WIDGET_H__ */ diff --git a/libempathy-gtk/empathy-account-widgets.gresource.xml b/libempathy-gtk/empathy-account-widgets.gresource.xml deleted file mode 100644 index 093cb2a93..000000000 --- a/libempathy-gtk/empathy-account-widgets.gresource.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - empathy-account-widget-generic.ui - empathy-account-widget-jabber.ui - empathy-account-widget-msn.ui - empathy-account-widget-sip.ui - empathy-account-widget-local-xmpp.ui - empathy-account-widget-irc.ui - empathy-account-widget-icq.ui - empathy-account-widget-yahoo.ui - empathy-account-widget-groupwise.ui - empathy-account-widget-aim.ui - - - diff --git a/libempathy-gtk/empathy-irc-network-chooser-dialog.c b/libempathy-gtk/empathy-irc-network-chooser-dialog.c deleted file mode 100644 index 60945aed6..000000000 --- a/libempathy-gtk/empathy-irc-network-chooser-dialog.c +++ /dev/null @@ -1,740 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#include "config.h" -#include "empathy-irc-network-chooser-dialog.h" - -#include - -#include "empathy-irc-network-dialog.h" -#include "empathy-irc-network-manager.h" -#include "empathy-live-search.h" -#include "empathy-utils.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC -#include "empathy-debug.h" - -#include "empathy-irc-network-chooser-dialog.h" - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkChooserDialog) - -enum { - PROP_SETTINGS = 1, - PROP_NETWORK -}; - -enum { - RESPONSE_RESET = 0 -}; - -typedef struct { - EmpathyAccountSettings *settings; - EmpathyIrcNetwork *network; - - EmpathyIrcNetworkManager *network_manager; - gboolean changed; - - GtkWidget *treeview; - GtkListStore *store; - GtkTreeModelFilter *filter; - GtkWidget *search; - GtkWidget *select_button; - - gulong search_sig; - gulong activate_sig; -} EmpathyIrcNetworkChooserDialogPriv; - -enum { - COL_NETWORK_OBJ, - COL_NETWORK_NAME, -}; - -G_DEFINE_TYPE (EmpathyIrcNetworkChooserDialog, empathy_irc_network_chooser_dialog, - GTK_TYPE_DIALOG); - -static void -empathy_irc_network_chooser_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (object); - - switch (prop_id) - { - case PROP_SETTINGS: - priv->settings = g_value_dup_object (value); - break; - case PROP_NETWORK: - priv->network = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -empathy_irc_network_chooser_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (object); - - switch (prop_id) - { - case PROP_SETTINGS: - g_value_set_object (value, priv->settings); - break; - case PROP_NETWORK: - g_value_set_object (value, priv->network); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/* The iter returned by *it is a priv->store iter (not a filter one) */ -static EmpathyIrcNetwork * -dup_selected_network (EmpathyIrcNetworkChooserDialog *self, - GtkTreeIter *it) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - EmpathyIrcNetwork *network; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreeModel *model; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); - if (selection == NULL) - return NULL; - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return NULL; - - gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1); - g_assert (network != NULL); - - if (it != NULL) - { - gtk_tree_model_filter_convert_iter_to_child_iter (priv->filter, it, - &iter); - } - - return network; -} - -static void -treeview_changed_cb (GtkTreeView *treeview, - EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - EmpathyIrcNetwork *network; - - network = dup_selected_network (self, NULL); - if (network == priv->network) - { - g_clear_object (&network); - return; - } - - tp_clear_object (&priv->network); - /* Transfer the reference */ - priv->network = network; - - priv->changed = TRUE; -} - -/* Take a filter iterator as argument */ -static void -scroll_to_iter (EmpathyIrcNetworkChooserDialog *self, - GtkTreeIter *filter_iter) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GtkTreePath *path; - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), filter_iter); - - if (path != NULL) - { - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), - path, NULL, FALSE, 0, 0); - - gtk_tree_path_free (path); - } -} - -/* Take a filter iterator as argument */ -static void -select_iter (EmpathyIrcNetworkChooserDialog *self, - GtkTreeIter *filter_iter, - gboolean emulate_changed) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GtkTreeSelection *selection; - GtkTreePath *path; - - /* Select the network */ - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (priv->treeview)); - - gtk_tree_selection_select_iter (selection, filter_iter); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), filter_iter); - if (path != NULL) - { - gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path, - NULL, FALSE); - - gtk_tree_path_free (path); - } - - /* Scroll to the selected network */ - scroll_to_iter (self, filter_iter); - - if (emulate_changed) - { - /* gtk_tree_selection_select_iter doesn't fire the 'cursor-changed' signal - * so we call the callback manually. */ - treeview_changed_cb (GTK_TREE_VIEW (priv->treeview), self); - } -} - -static GtkTreeIter -iter_to_filter_iter (EmpathyIrcNetworkChooserDialog *self, - GtkTreeIter *iter) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GtkTreeIter filter_iter; - - g_assert (gtk_tree_model_filter_convert_child_iter_to_iter (priv->filter, - &filter_iter, iter)); - - return filter_iter; -} - -static void -fill_store (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GSList *networks, *l; - - networks = empathy_irc_network_manager_get_networks ( - priv->network_manager); - - for (l = networks; l != NULL; l = g_slist_next (l)) - { - EmpathyIrcNetwork *network = l->data; - GtkTreeIter iter; - - gtk_list_store_insert_with_values (priv->store, &iter, -1, - COL_NETWORK_OBJ, network, - COL_NETWORK_NAME, empathy_irc_network_get_name (network), - -1); - - if (network == priv->network) - { - GtkTreeIter filter_iter = iter_to_filter_iter (self, &iter); - - select_iter (self, &filter_iter, FALSE); - } - - g_object_unref (network); - } - - g_slist_free (networks); -} - -static void -irc_network_dialog_destroy_cb (GtkWidget *widget, - EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - EmpathyIrcNetwork *network; - GtkTreeIter iter, filter_iter; - - priv->changed = TRUE; - - network = dup_selected_network (self, &iter); - if (network == NULL) - return; - - /* name could be changed */ - gtk_list_store_set (GTK_LIST_STORE (priv->store), &iter, - COL_NETWORK_NAME, empathy_irc_network_get_name (network), -1); - - filter_iter = iter_to_filter_iter (self, &iter); - scroll_to_iter (self, &filter_iter); - - gtk_widget_grab_focus (priv->treeview); - - g_object_unref (network); -} - -static void -display_irc_network_dialog (EmpathyIrcNetworkChooserDialog *self, - EmpathyIrcNetwork *network) -{ - GtkWidget *dialog; - - dialog = empathy_irc_network_dialog_show (network, GTK_WIDGET (self)); - - g_signal_connect (dialog, "destroy", - G_CALLBACK (irc_network_dialog_destroy_cb), self); -} - -static void -edit_network (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetwork *network; - - network = dup_selected_network (self, NULL); - if (network == NULL) - return; - - display_irc_network_dialog (self, network); - - g_object_unref (network); -} - -static void -add_network (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - EmpathyIrcNetwork *network; - GtkTreeIter iter, filter_iter; - - gtk_widget_hide (priv->search); - - network = empathy_irc_network_new (_("New Network")); - empathy_irc_network_manager_add (priv->network_manager, network); - - gtk_list_store_insert_with_values (priv->store, &iter, -1, - COL_NETWORK_OBJ, network, - COL_NETWORK_NAME, empathy_irc_network_get_name (network), - -1); - - filter_iter = iter_to_filter_iter (self, &iter); - select_iter (self, &filter_iter, TRUE); - - display_irc_network_dialog (self, network); - - g_object_unref (network); -} - -static void -remove_network (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - EmpathyIrcNetwork *network; - GtkTreeIter iter; - - network = dup_selected_network (self, &iter); - if (network == NULL) - return; - - /* Hide the search after picking the network to get the right one */ - gtk_widget_hide (priv->search); - - DEBUG ("Remove network %s", empathy_irc_network_get_name (network)); - - /* Delete network and select next network */ - if (gtk_list_store_remove (priv->store, &iter)) - { - GtkTreeIter filter_iter = iter_to_filter_iter (self, &iter); - - select_iter (self, &filter_iter, TRUE); - } - else - { - /* this should only happen if the last network was deleted */ - GtkTreeIter last, filter_iter; - gint n_elements; - - n_elements = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), - NULL); - - if (n_elements > 0) - { - gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store), &last, - NULL, (n_elements-1)); - filter_iter = iter_to_filter_iter (self, &last); - - select_iter (self, &filter_iter, TRUE); - } - } - - empathy_irc_network_manager_remove (priv->network_manager, network); - gtk_widget_grab_focus (priv->treeview); - - g_object_unref (network); -} - -static void -reset_networks (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GSList *networks, *l; - - networks = empathy_irc_network_manager_get_dropped_networks ( - priv->network_manager); - - for (l = networks; l != NULL; l = g_slist_next (l)) - { - EmpathyIrcNetwork *network; - GtkTreeIter iter; - - network = EMPATHY_IRC_NETWORK (l->data); - empathy_irc_network_activate (network); - - gtk_list_store_insert_with_values (priv->store, &iter, -1, - COL_NETWORK_OBJ, network, - COL_NETWORK_NAME, empathy_irc_network_get_name (network), - -1); - } - - g_slist_foreach (networks, (GFunc) g_object_unref, NULL); -} - -static void -dialog_response_cb (GtkDialog *dialog, - gint response, - EmpathyIrcNetworkChooserDialog *self) -{ - if (response == RESPONSE_RESET) - reset_networks (self); -} - -static gboolean -filter_visible_func (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer user_data) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (user_data); - EmpathyIrcNetwork *network; - gboolean visible; - - gtk_tree_model_get (model, iter, COL_NETWORK_OBJ, &network, -1); - - visible = empathy_live_search_match (EMPATHY_LIVE_SEARCH (priv->search), - empathy_irc_network_get_name (network)); - - g_object_unref (network); - return visible; -} - -static void -search_activate_cb (GtkWidget *search, - EmpathyIrcNetworkChooserDialog *self) -{ - gtk_widget_hide (search); - gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CLOSE); -} - -static void -search_text_notify_cb (EmpathyLiveSearch *search, - GParamSpec *pspec, - EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GtkTreeIter filter_iter; - gboolean sensitive = FALSE; - - gtk_tree_model_filter_refilter (priv->filter); - - /* Is there at least one network in the view ? */ - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), - &filter_iter)) - { - const gchar *text; - - text = empathy_live_search_get_text (EMPATHY_LIVE_SEARCH (priv->search)); - if (!EMP_STR_EMPTY (text)) - { - /* We are doing a search, select the first matching network */ - select_iter (self, &filter_iter, TRUE); - } - else - { - /* Search has been cancelled. Scroll to the selected network */ - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (priv->treeview)); - - if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter)) - scroll_to_iter (self, &filter_iter); - } - - sensitive = TRUE; - } - - gtk_widget_set_sensitive (priv->select_button, sensitive); -} - -static void -add_clicked_cb (GtkToolButton *button, - EmpathyIrcNetworkChooserDialog *self) -{ - add_network (self); -} - -static void -remove_clicked_cb (GtkToolButton *button, - EmpathyIrcNetworkChooserDialog *self) -{ - remove_network (self); -} - -static void -edit_clicked_cb (GtkToolButton *button, - EmpathyIrcNetworkChooserDialog *self) -{ - edit_network (self); -} - -static void -empathy_irc_network_chooser_dialog_constructed (GObject *object) -{ - EmpathyIrcNetworkChooserDialog *self = (EmpathyIrcNetworkChooserDialog *) object; - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - GtkDialog *dialog = GTK_DIALOG (self); - GtkCellRenderer *renderer; - GtkWidget *vbox; - GtkTreeViewColumn *column; - GtkWidget *scroll; - GtkWidget *toolbar; - GtkToolItem *item; - GtkStyleContext *context; - - g_assert (priv->settings != NULL); - - gtk_window_set_title (GTK_WINDOW (self), _("Choose an IRC network")); - - /* Create store and treeview */ - priv->store = gtk_list_store_new (2, G_TYPE_OBJECT, G_TYPE_STRING); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), - COL_NETWORK_NAME, - GTK_SORT_ASCENDING); - - priv->treeview = gtk_tree_view_new (); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE); - - column = gtk_tree_view_column_new (); - gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), - renderer, - "text", COL_NETWORK_NAME, - NULL); - - /* add the treeview in a GtkScrolledWindow */ - vbox = gtk_dialog_get_content_area (dialog); - - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - - gtk_container_add (GTK_CONTAINER (scroll), priv->treeview); - gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 6); - - /* Treeview toolbar */ - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU); - gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0); - - item = gtk_tool_button_new (NULL, ""); - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "list-add-symbolic"); - g_signal_connect (item, "clicked", G_CALLBACK (add_clicked_cb), self); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - - item = gtk_tool_button_new (NULL, ""); - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), - "list-remove-symbolic"); - g_signal_connect (item, "clicked", G_CALLBACK (remove_clicked_cb), self); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - - item = gtk_tool_button_new (NULL, ""); - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), - "preferences-system-symbolic"); - g_signal_connect (item, "clicked", G_CALLBACK (edit_clicked_cb), self); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - - context = gtk_widget_get_style_context (scroll); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); - - context = gtk_widget_get_style_context (toolbar); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); - - /* Live search */ - priv->search = empathy_live_search_new (priv->treeview); - - gtk_box_pack_start (GTK_BOX (vbox), priv->search, FALSE, TRUE, 0); - - priv->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new ( - GTK_TREE_MODEL (priv->store), NULL)); - gtk_tree_model_filter_set_visible_func (priv->filter, - filter_visible_func, self, NULL); - - gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), - GTK_TREE_MODEL (priv->filter)); - - priv->search_sig = g_signal_connect (priv->search, "notify::text", - G_CALLBACK (search_text_notify_cb), self); - - priv->activate_sig = g_signal_connect (priv->search, "activate", - G_CALLBACK (search_activate_cb), self); - - /* Add buttons */ - gtk_dialog_add_buttons (dialog, - _("Reset _Networks List"), RESPONSE_RESET, - NULL); - - priv->select_button = gtk_dialog_add_button (dialog, - C_("verb displayed on a button to select an IRC network", "Select"), - GTK_RESPONSE_CLOSE); - - fill_store (self); - - g_signal_connect (priv->treeview, "cursor-changed", - G_CALLBACK (treeview_changed_cb), self); - - g_signal_connect (self, "response", - G_CALLBACK (dialog_response_cb), self); - - /* Request a side ensuring to display at least some networks */ - gtk_widget_set_size_request (GTK_WIDGET (self), -1, 300); - - gtk_window_set_modal (GTK_WINDOW (self), TRUE); -} - -static void -empathy_irc_network_chooser_dialog_dispose (GObject *object) -{ - EmpathyIrcNetworkManager *self = (EmpathyIrcNetworkManager *) object; - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - - if (priv->search_sig != 0) - { - g_signal_handler_disconnect (priv->search, priv->search_sig); - priv->search_sig = 0; - } - - if (priv->activate_sig != 0) - { - g_signal_handler_disconnect (priv->search, priv->activate_sig); - priv->activate_sig = 0; - } - - if (priv->search != NULL) - { - empathy_live_search_set_hook_widget (EMPATHY_LIVE_SEARCH (priv->search), - NULL); - - priv->search = NULL; - } - - tp_clear_object (&priv->settings); - tp_clear_object (&priv->network); - tp_clear_object (&priv->network_manager); - tp_clear_object (&priv->store); - tp_clear_object (&priv->filter); - - if (G_OBJECT_CLASS (empathy_irc_network_chooser_dialog_parent_class)->dispose) - G_OBJECT_CLASS (empathy_irc_network_chooser_dialog_parent_class)->dispose (object); -} - -static void -empathy_irc_network_chooser_dialog_class_init (EmpathyIrcNetworkChooserDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = empathy_irc_network_chooser_dialog_get_property; - object_class->set_property = empathy_irc_network_chooser_dialog_set_property; - object_class->constructed = empathy_irc_network_chooser_dialog_constructed; - object_class->dispose = empathy_irc_network_chooser_dialog_dispose; - - g_object_class_install_property (object_class, PROP_SETTINGS, - g_param_spec_object ("settings", - "Settings", - "The EmpathyAccountSettings to show and edit", - EMPATHY_TYPE_ACCOUNT_SETTINGS, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_NETWORK, - g_param_spec_object ("network", - "Network", - "The EmpathyIrcNetwork selected in the treeview", - EMPATHY_TYPE_IRC_NETWORK, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_type_class_add_private (object_class, - sizeof (EmpathyIrcNetworkChooserDialogPriv)); -} - -static void -empathy_irc_network_chooser_dialog_init (EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv; - - priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialogPriv); - self->priv = priv; - - priv->network_manager = empathy_irc_network_manager_dup_default (); -} - -GtkWidget * -empathy_irc_network_chooser_dialog_new (EmpathyAccountSettings *settings, - EmpathyIrcNetwork *network, - GtkWindow *parent) -{ - return g_object_new (EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, - "settings", settings, - "network", network, - "transient-for", parent, - NULL); -} - -EmpathyIrcNetwork * -empathy_irc_network_chooser_dialog_get_network ( - EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - - return priv->network; -} - -gboolean -empathy_irc_network_chooser_dialog_get_changed ( - EmpathyIrcNetworkChooserDialog *self) -{ - EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); - - return priv->changed; -} diff --git a/libempathy-gtk/empathy-irc-network-chooser-dialog.h b/libempathy-gtk/empathy-irc-network-chooser-dialog.h deleted file mode 100644 index 1e4654916..000000000 --- a/libempathy-gtk/empathy-irc-network-chooser-dialog.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#ifndef __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ -#define __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ - -#include - -#include "empathy-account-settings.h" -#include "empathy-irc-network.h" - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG (empathy_irc_network_chooser_dialog_get_type ()) -#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialog)) -#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialogClass)) -#define EMPATHY_IS_IRC_NETWORK_CHOOSER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG)) -#define EMPATHY_IS_IRC_NETWORK_CHOOSER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG)) -#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_GET_CLASS(o) ( \ - G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, \ - EmpathyIrcNetworkChooserDialogClass)) - -typedef struct { - GtkDialog parent; - - /**/ - gpointer priv; -} EmpathyIrcNetworkChooserDialog; - -typedef struct { - GtkDialogClass parent_class; -} EmpathyIrcNetworkChooserDialogClass; - -GType empathy_irc_network_chooser_dialog_get_type (void) G_GNUC_CONST; - -GtkWidget * empathy_irc_network_chooser_dialog_new ( - EmpathyAccountSettings *settings, - EmpathyIrcNetwork *network, - GtkWindow *parent); - -EmpathyIrcNetwork * empathy_irc_network_chooser_dialog_get_network ( - EmpathyIrcNetworkChooserDialog *self); - -gboolean empathy_irc_network_chooser_dialog_get_changed ( - EmpathyIrcNetworkChooserDialog *self); - -G_END_DECLS - -#endif /* __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ */ diff --git a/libempathy-gtk/empathy-irc-network-chooser.c b/libempathy-gtk/empathy-irc-network-chooser.c deleted file mode 100644 index fab6a3a3f..000000000 --- a/libempathy-gtk/empathy-irc-network-chooser.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#include "config.h" -#include "empathy-irc-network-chooser.h" - -#include "empathy-irc-network-chooser-dialog.h" -#include "empathy-irc-network-manager.h" -#include "empathy-ui-utils.h" -#include "empathy-utils.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC -#include "empathy-debug.h" - -#define DEFAULT_IRC_NETWORK "irc.gimp.org" -#define DEFAULT_IRC_PORT 6667 -#define DEFAULT_IRC_SSL FALSE - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkChooser) - -enum { - PROP_SETTINGS = 1 -}; - -enum { - SIG_CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -typedef struct { - EmpathyAccountSettings *settings; - - EmpathyIrcNetworkManager *network_manager; - GtkWidget *dialog; - /* Displayed network */ - EmpathyIrcNetwork *network; -} EmpathyIrcNetworkChooserPriv; - -G_DEFINE_TYPE (EmpathyIrcNetworkChooser, empathy_irc_network_chooser, - GTK_TYPE_BUTTON); - -static void -empathy_irc_network_chooser_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (object); - - switch (prop_id) - { - case PROP_SETTINGS: - priv->settings = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -empathy_irc_network_chooser_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (object); - - switch (prop_id) - { - case PROP_SETTINGS: - g_value_set_object (value, priv->settings); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -unset_server_params (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - - DEBUG ("Unset server, port and use-ssl"); - empathy_account_settings_unset (priv->settings, "server"); - empathy_account_settings_unset (priv->settings, "port"); - empathy_account_settings_unset (priv->settings, "use-ssl"); -} - -static gchar * -dup_network_service (EmpathyIrcNetwork *network) -{ - /* Account.Service has to be a lower case alphanumeric string which may - * also contain '-' but not start with it. */ -#define VALID G_CSET_a_2_z G_CSET_DIGITS "-" - gchar *service, *tmp; - - service = g_strdup (empathy_irc_network_get_name (network)); - service = g_strstrip (service); - - if (tp_str_empty (service)) - { - g_free (service); - return NULL; - } - - tmp = service; - service = g_ascii_strdown (service, -1); - g_free (tmp); - - service = g_strcanon (service, VALID, '-'); - - if (service[0] == '-') - { - tmp = service; - service = g_strdup (service + 1); - - g_free (tmp); - } - - return service; -} - -static void -update_server_params (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - GSList *servers; - const gchar *charset; - - g_assert (priv->network != NULL); - - charset = empathy_irc_network_get_charset (priv->network); - DEBUG ("Setting charset to %s", charset); - empathy_account_settings_set (priv->settings, "charset", - g_variant_new_string (charset)); - - servers = empathy_irc_network_get_servers (priv->network); - if (g_slist_length (servers) > 0) - { - /* set the first server as CM server */ - EmpathyIrcServer *server = servers->data; - gchar *address; - guint port; - gboolean ssl; - gchar *service; - - g_object_get (server, - "address", &address, - "port", &port, - "ssl", &ssl, - NULL); - - DEBUG ("Setting server to %s", address); - empathy_account_settings_set (priv->settings, "server", - g_variant_new_string (address)); - DEBUG ("Setting port to %u", port); - empathy_account_settings_set (priv->settings, "port", - g_variant_new_uint32 (port)); - DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" ); - empathy_account_settings_set (priv->settings, "use-ssl", - g_variant_new_boolean (ssl)); - - /* Set Account.Service */ - service = dup_network_service (priv->network); - DEBUG ("Setting Service to %s", service); - empathy_account_settings_set_service (priv->settings, service); - - g_free (address); - g_free (service); - } - else - { - /* No server. Unset values */ - unset_server_params (self); - } - - g_slist_foreach (servers, (GFunc) g_object_unref, NULL); - g_slist_free (servers); -} - -static void -set_label (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - - g_assert (priv->network != NULL); - - gtk_button_set_label (GTK_BUTTON (self), - empathy_irc_network_get_name (priv->network)); -} - -static void -set_label_from_settings (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - gchar *server; - - tp_clear_object (&priv->network); - - server = empathy_account_settings_dup_string (priv->settings, "server"); - - if (server != NULL) - { - EmpathyIrcServer *srv; - gint port; - gboolean ssl; - - priv->network = empathy_irc_network_manager_find_network_by_address ( - priv->network_manager, server); - - if (priv->network != NULL) - { - /* The network is known */ - g_object_ref (priv->network); - set_label (self); - return; - } - - /* We don't have this network. Let's create it */ - port = empathy_account_settings_get_uint32 (priv->settings, "port"); - ssl = empathy_account_settings_get_boolean (priv->settings, - "use-ssl"); - - DEBUG ("Create a network %s", server); - priv->network = empathy_irc_network_new (server); - srv = empathy_irc_server_new (server, port, ssl); - - empathy_irc_network_append_server (priv->network, srv); - empathy_irc_network_manager_add (priv->network_manager, priv->network); - - set_label (self); - - g_object_unref (srv); - g_free (server); - return; - } - - /* Set default network */ - priv->network = empathy_irc_network_manager_find_network_by_address ( - priv->network_manager, DEFAULT_IRC_NETWORK); - - if (priv->network == NULL) - { - /* Default network is not known, recreate it */ - EmpathyIrcServer *srv; - - priv->network = empathy_irc_network_new (DEFAULT_IRC_NETWORK); - - srv = empathy_irc_server_new (DEFAULT_IRC_NETWORK, DEFAULT_IRC_PORT, - DEFAULT_IRC_SSL); - - empathy_irc_network_append_server (priv->network, srv); - empathy_irc_network_manager_add (priv->network_manager, priv->network); - - g_object_unref (srv); - } - - set_label (self); - update_server_params (self); - g_object_ref (priv->network); -} - -static void -dialog_response_cb (GtkDialog *dialog, - gint response, - EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - EmpathyIrcNetworkChooserDialog *chooser = - EMPATHY_IRC_NETWORK_CHOOSER_DIALOG (priv->dialog); - - if (response != GTK_RESPONSE_CLOSE && - response != GTK_RESPONSE_DELETE_EVENT) - return; - - if (empathy_irc_network_chooser_dialog_get_changed (chooser)) - { - tp_clear_object (&priv->network); - - priv->network = g_object_ref ( - empathy_irc_network_chooser_dialog_get_network (chooser)); - - update_server_params (self); - set_label (self); - - g_signal_emit (self, signals[SIG_CHANGED], 0); - } - - gtk_widget_destroy (priv->dialog); - priv->dialog = NULL; -} - -static void -clicked_cb (GtkButton *button, - gpointer user_data) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (button); - GtkWindow *window; - - if (priv->dialog != NULL) - goto out; - - window = empathy_get_toplevel_window (GTK_WIDGET (button)); - - priv->dialog = empathy_irc_network_chooser_dialog_new (priv->settings, - priv->network, window); - gtk_widget_show_all (priv->dialog); - - tp_g_signal_connect_object (priv->dialog, "response", - G_CALLBACK (dialog_response_cb), button, 0); - -out: - empathy_window_present (GTK_WINDOW (priv->dialog)); -} - -static void -empathy_irc_network_chooser_constructed (GObject *object) -{ - EmpathyIrcNetworkChooser *self = (EmpathyIrcNetworkChooser *) object; - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - - g_assert (priv->settings != NULL); - - set_label_from_settings (self); - - g_signal_connect (self, "clicked", G_CALLBACK (clicked_cb), self); -} - -static void -empathy_irc_network_chooser_dispose (GObject *object) -{ - EmpathyIrcNetworkManager *self = (EmpathyIrcNetworkManager *) object; - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - - tp_clear_object (&priv->settings); - tp_clear_object (&priv->network_manager); - tp_clear_object (&priv->network); - - if (G_OBJECT_CLASS (empathy_irc_network_chooser_parent_class)->dispose) - G_OBJECT_CLASS (empathy_irc_network_chooser_parent_class)->dispose (object); -} - -static void -empathy_irc_network_chooser_class_init (EmpathyIrcNetworkChooserClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = empathy_irc_network_chooser_get_property; - object_class->set_property = empathy_irc_network_chooser_set_property; - object_class->constructed = empathy_irc_network_chooser_constructed; - object_class->dispose = empathy_irc_network_chooser_dispose; - - g_object_class_install_property (object_class, PROP_SETTINGS, - g_param_spec_object ("settings", - "Settings", - "The EmpathyAccountSettings to show and edit", - EMPATHY_TYPE_ACCOUNT_SETTINGS, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - signals[SIG_CHANGED] = g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 0); - - g_type_class_add_private (object_class, - sizeof (EmpathyIrcNetworkChooserPriv)); -} - -static void -empathy_irc_network_chooser_init (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv; - - priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooserPriv); - self->priv = priv; - - priv->network_manager = empathy_irc_network_manager_dup_default (); -} - -GtkWidget * -empathy_irc_network_chooser_new (EmpathyAccountSettings *settings) -{ - return g_object_new (EMPATHY_TYPE_IRC_NETWORK_CHOOSER, - "settings", settings, - NULL); -} - -EmpathyIrcNetwork * -empathy_irc_network_chooser_get_network (EmpathyIrcNetworkChooser *self) -{ - EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - - return priv->network; -} diff --git a/libempathy-gtk/empathy-irc-network-chooser.h b/libempathy-gtk/empathy-irc-network-chooser.h deleted file mode 100644 index f4c603288..000000000 --- a/libempathy-gtk/empathy-irc-network-chooser.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#ifndef __EMPATHY_IRC_NETWORK_CHOOSER_H__ -#define __EMPATHY_IRC_NETWORK_CHOOSER_H__ - -#include - -#include "empathy-account-settings.h" -#include "empathy-irc-network.h" - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_IRC_NETWORK_CHOOSER (empathy_irc_network_chooser_get_type ()) -#define EMPATHY_IRC_NETWORK_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooser)) -#define EMPATHY_IRC_NETWORK_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooserClass)) -#define EMPATHY_IS_IRC_NETWORK_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER)) -#define EMPATHY_IS_IRC_NETWORK_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_IRC_NETWORK_CHOOSER)) -#define EMPATHY_IRC_NETWORK_CHOOSER_GET_CLASS(o) ( \ - G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK_CHOOSER, \ - EmpathyIrcNetworkChooserClass)) - -typedef struct { - GtkButton parent; - - /**/ - gpointer priv; -} EmpathyIrcNetworkChooser; - -typedef struct { - GtkButtonClass parent_class; -} EmpathyIrcNetworkChooserClass; - -GType empathy_irc_network_chooser_get_type (void) G_GNUC_CONST; - -GtkWidget * empathy_irc_network_chooser_new (EmpathyAccountSettings *settings); - -EmpathyIrcNetwork * empathy_irc_network_chooser_get_network ( - EmpathyIrcNetworkChooser *self); - -G_END_DECLS - -#endif /* __EMPATHY_IRC_NETWORK_CHOOSER_H__ */ diff --git a/libempathy-gtk/empathy-irc-network-dialog.c b/libempathy-gtk/empathy-irc-network-dialog.c deleted file mode 100644 index 35457f592..000000000 --- a/libempathy-gtk/empathy-irc-network-dialog.c +++ /dev/null @@ -1,588 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#include "config.h" -#include "empathy-irc-network-dialog.h" - -#include - -#include "empathy-ui-utils.h" -#include "totem-subtitle-encoding.h" - -typedef struct { - EmpathyIrcNetwork *network; - - GtkWidget *dialog; - GtkWidget *button_close; - - GtkWidget *entry_network; - GtkWidget *combobox_charset; - - GtkWidget *treeview_servers; - GtkWidget *button_add; - GtkWidget *button_remove; - GtkWidget *button_up; - GtkWidget *button_down; -} EmpathyIrcNetworkDialog; - -static void -irc_network_dialog_destroy_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - g_object_unref (dialog->network); - - g_slice_free (EmpathyIrcNetworkDialog, dialog); -} - -static void -irc_network_dialog_close_clicked_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - gtk_widget_destroy (dialog->dialog); -} - -enum { - COL_SRV_OBJ, - COL_ADR, - COL_PORT, - COL_SSL -}; - -static void -add_server_to_store (GtkListStore *store, - EmpathyIrcServer *server, - GtkTreeIter *iter) -{ - gchar *address; - guint port; - gboolean ssl; - - g_object_get (server, - "address", &address, - "port", &port, - "ssl", &ssl, - NULL); - - gtk_list_store_insert_with_values (store, iter, -1, - COL_SRV_OBJ, server, - COL_ADR, address, - COL_PORT, port, - COL_SSL, ssl, - -1); - - g_free (address); -} - -static void -irc_network_dialog_setup (EmpathyIrcNetworkDialog *dialog) -{ - gchar *name, *charset; - GSList *servers, *l; - GtkListStore *store; - - g_object_get (dialog->network, - "name", &name, - "charset", &charset, - NULL); - gtk_entry_set_text (GTK_ENTRY (dialog->entry_network), name); - - store = GTK_LIST_STORE (gtk_tree_view_get_model ( - GTK_TREE_VIEW (dialog->treeview_servers))); - - servers = empathy_irc_network_get_servers (dialog->network); - for (l = servers; l != NULL; l = g_slist_next (l)) - { - EmpathyIrcServer *server = l->data; - GtkTreeIter iter; - - add_server_to_store (store, server, &iter); - } - - totem_subtitle_encoding_set (GTK_COMBO_BOX (dialog->combobox_charset), - charset); - - g_slist_foreach (servers, (GFunc) g_object_unref, NULL); - g_slist_free (servers); - g_free (name); - g_free (charset); -} - -static void -irc_network_dialog_address_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - EmpathyIrcNetworkDialog *dialog) -{ - EmpathyIrcServer *server; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_SRV_OBJ, &server, - -1); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_ADR, new_text, - -1); - - g_object_set (server, "address", new_text, NULL); - - gtk_tree_path_free (treepath); - g_object_unref (server); -} - -static void -irc_network_dialog_port_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - EmpathyIrcNetworkDialog *dialog) -{ - EmpathyIrcServer *server; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - guint port; - - port = strtoul (new_text, NULL, 10); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_SRV_OBJ, &server, - -1); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_PORT, port, - -1); - - g_object_set (server, "port", port, NULL); - - gtk_tree_path_free (treepath); - g_object_unref (server); -} - -static void -irc_network_dialog_ssl_toggled_cb (GtkCellRendererText *renderer, - gchar *path, - EmpathyIrcNetworkDialog *dialog) -{ - EmpathyIrcServer *server; - GtkTreeModel *model; - GtkTreePath *treepath; - GtkTreeIter iter; - gboolean ssl; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); - treepath = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, - COL_SRV_OBJ, &server, - COL_SSL, &ssl, - -1); - ssl = !ssl; - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_SSL, ssl, - -1); - - g_object_set (server, "ssl", ssl, NULL); - - gtk_tree_path_free (treepath); - g_object_unref (server); -} - -static gboolean -irc_network_dialog_network_focus_cb (GtkWidget *widget, - GdkEventFocus *event, - EmpathyIrcNetworkDialog *dialog) -{ - const gchar *str; - - str = gtk_entry_get_text (GTK_ENTRY (widget)); - - g_object_set (dialog->network, "name", str, NULL); - - return FALSE; -} - -static void -irc_network_dialog_network_update_buttons (EmpathyIrcNetworkDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - gboolean can_remove = FALSE, can_move_up = FALSE, can_move_down = FALSE; - int selected; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW ( - dialog->treeview_servers)); - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - { - path = gtk_tree_model_get_path (model, &iter); - - selected = gtk_tree_path_get_indices (path)[0]; - - can_remove = TRUE; - can_move_up = selected > 0; - can_move_down = - selected < gtk_tree_model_iter_n_children (model, NULL) - 1; - - gtk_tree_path_free (path); - } - - gtk_widget_set_sensitive (dialog->button_remove, can_remove); - gtk_widget_set_sensitive (dialog->button_up, can_move_up); - gtk_widget_set_sensitive (dialog->button_down, can_move_down); -} - -static void -irc_network_dialog_button_add_clicked_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - EmpathyIrcServer *server; - GtkListStore *store; - GtkTreeIter iter; - GtkTreePath *path; - GtkTreeViewColumn *column; - - store = GTK_LIST_STORE (gtk_tree_view_get_model ( - GTK_TREE_VIEW (dialog->treeview_servers))); - - server = empathy_irc_server_new (_("new server"), 6667, FALSE); - empathy_irc_network_append_server (dialog->network, server); - add_server_to_store (store, server, &iter); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); - column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), - 0); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->treeview_servers), path, - column, TRUE); - - irc_network_dialog_network_update_buttons (dialog); - - gtk_tree_path_free (path); - g_object_unref (server); -} - -static void -irc_network_dialog_button_remove_clicked_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - EmpathyIrcServer *server; - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (dialog->treeview_servers)); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); - - gtk_list_store_remove (GTK_LIST_STORE (model), &iter); - empathy_irc_network_remove_server (dialog->network, server); - - irc_network_dialog_network_update_buttons (dialog); - - g_object_unref (server); -} - -static void -irc_network_dialog_button_up_clicked_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter, iter_prev; - GtkTreePath *path; - gint *pos; - EmpathyIrcServer *server; - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (dialog->treeview_servers)); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - path = gtk_tree_model_get_path (model, &iter); - - if (!gtk_tree_path_prev (path)) - { - gtk_tree_path_free (path); - return; - } - - gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); - - gtk_tree_model_get_iter (model, &iter_prev, path); - gtk_list_store_swap (GTK_LIST_STORE (model), &iter_prev, &iter); - - pos = gtk_tree_path_get_indices (path); - empathy_irc_network_set_server_position (dialog->network, server, *pos); - - irc_network_dialog_network_update_buttons (dialog); - - g_object_unref (server); - gtk_tree_path_free (path); -} - -static void -irc_network_dialog_button_down_clicked_cb (GtkWidget *widget, - EmpathyIrcNetworkDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter, iter_prev; - GtkTreePath *path; - EmpathyIrcServer *server; - gint *pos; - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (dialog->treeview_servers)); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - path = gtk_tree_model_get_path (model, &iter); - - gtk_tree_path_next (path); - if (!gtk_tree_model_get_iter (model, &iter_prev, path)) - { - gtk_tree_path_free (path); - return; - } - - gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); - - gtk_list_store_swap (GTK_LIST_STORE (model), &iter_prev, &iter); - - pos = gtk_tree_path_get_indices (path); - empathy_irc_network_set_server_position (dialog->network, server, *pos); - - irc_network_dialog_network_update_buttons (dialog); - - gtk_tree_path_free (path); -} - -static void -irc_network_dialog_selection_changed_cb (GtkTreeSelection *treeselection, - EmpathyIrcNetworkDialog *dialog) -{ - irc_network_dialog_network_update_buttons (dialog); -} - -static void -irc_network_dialog_combobox_charset_changed_cb (GtkWidget *combobox, - EmpathyIrcNetworkDialog *dialog) -{ - const gchar *charset; - - charset = totem_subtitle_encoding_get_selected (GTK_COMBO_BOX (combobox)); - g_object_set (dialog->network, "charset", charset, NULL); -} - -static void -change_network (EmpathyIrcNetworkDialog *dialog, - EmpathyIrcNetwork *network) -{ - GtkListStore *store; - - if (dialog->network == network) - /* No need to change */ - return; - - if (dialog->network != NULL) - { - g_object_unref (dialog->network); - } - - dialog->network = network; - g_object_ref (network); - - store = GTK_LIST_STORE (gtk_tree_view_get_model ( - GTK_TREE_VIEW (dialog->treeview_servers))); - gtk_list_store_clear (store); - - irc_network_dialog_setup (dialog); -} - -/** - * empathy_irc_network_dialog_show: - * @network: the #EmpathyIrcNetwork to configure - * @parent: the parent of this dialog - * - * Display a dialog to configure a given #EmpathyIrcNetwork. - * This function is a singleton so if a configuration dialog already - * exists we use this one to edit the network. - * - * Returns: The displayed #GtkDialog - */ -GtkWidget * -empathy_irc_network_dialog_show (EmpathyIrcNetwork *network, - GtkWidget *parent) -{ - static EmpathyIrcNetworkDialog *dialog = NULL; - GtkBuilder *gui; - GtkListStore *store; - GtkCellRenderer *renderer; - GtkAdjustment *adjustment; - GtkTreeSelection *selection; - GtkTreeViewColumn *column; - GtkWidget *sw, *toolbar; - GtkStyleContext *context; - - g_return_val_if_fail (network != NULL, NULL); - - if (dialog != NULL) - { - change_network (dialog, network); - gtk_window_present (GTK_WINDOW (dialog->dialog)); - - return dialog->dialog; - } - - dialog = g_slice_new0 (EmpathyIrcNetworkDialog); - - dialog->network = network; - g_object_ref (dialog->network); - - gui = empathy_builder_get_resource (ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-irc.ui", - "irc_network_dialog", &dialog->dialog, - "button_close", &dialog->button_close, - "entry_network", &dialog->entry_network, - "combobox_charset", &dialog->combobox_charset, - "treeview_servers", &dialog->treeview_servers, - "button_add", &dialog->button_add, - "button_remove", &dialog->button_remove, - "button_up", &dialog->button_up, - "button_down", &dialog->button_down, - "scrolledwindow_network_server", &sw, - "toolbar_network_server", &toolbar, - NULL); - - store = gtk_list_store_new (4, G_TYPE_OBJECT, G_TYPE_STRING, - G_TYPE_UINT, G_TYPE_BOOLEAN); - gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview_servers), - GTK_TREE_MODEL (store)); - g_object_unref (store); - - /* address */ - renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, "editable", TRUE, NULL); - g_signal_connect (renderer, "edited", - G_CALLBACK (irc_network_dialog_address_edited_cb), dialog); - gtk_tree_view_insert_column_with_attributes ( - GTK_TREE_VIEW (dialog->treeview_servers), - -1, _("Server"), renderer, "text", COL_ADR, - NULL); - column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), - 0); - - gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_column_set_expand (column, TRUE); - - /* port */ - adjustment = (GtkAdjustment *) gtk_adjustment_new (6667, 1, G_MAXUINT16, - 1, 10, 0); - renderer = gtk_cell_renderer_spin_new (); - g_object_set (renderer, - "editable", TRUE, - "adjustment", adjustment, - NULL); - g_signal_connect (renderer, "edited", - G_CALLBACK (irc_network_dialog_port_edited_cb), dialog); - - gtk_tree_view_insert_column_with_attributes ( - GTK_TREE_VIEW (dialog->treeview_servers), - -1, _("Port"), renderer, "text", COL_PORT, - NULL); - - column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), - 1); - gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_column_set_expand (column, TRUE); - - /* SSL */ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (renderer, "activatable", TRUE, NULL); - g_signal_connect (renderer, "toggled", - G_CALLBACK (irc_network_dialog_ssl_toggled_cb), dialog); - gtk_tree_view_insert_column_with_attributes ( - GTK_TREE_VIEW (dialog->treeview_servers), - -1, _("SSL"), renderer, "active", COL_SSL, - NULL); - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (dialog->treeview_servers)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - - column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), - 2); - gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - - gtk_tree_view_column_set_expand (column, TRUE); - /* charset */ - totem_subtitle_encoding_init (GTK_COMBO_BOX (dialog->combobox_charset)); - - irc_network_dialog_setup (dialog); - - empathy_builder_connect (gui, dialog, - "irc_network_dialog", "destroy", irc_network_dialog_destroy_cb, - "button_close", "clicked", irc_network_dialog_close_clicked_cb, - "entry_network", "focus-out-event", irc_network_dialog_network_focus_cb, - "button_add", "clicked", irc_network_dialog_button_add_clicked_cb, - "button_remove", "clicked", irc_network_dialog_button_remove_clicked_cb, - "button_up", "clicked", irc_network_dialog_button_up_clicked_cb, - "button_down", "clicked", irc_network_dialog_button_down_clicked_cb, - "combobox_charset", "changed", irc_network_dialog_combobox_charset_changed_cb, - NULL); - - g_object_unref (gui); - - g_object_add_weak_pointer (G_OBJECT (dialog->dialog), - (gpointer) &dialog); - - g_signal_connect (selection, "changed", - G_CALLBACK (irc_network_dialog_selection_changed_cb), - dialog); - - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), - GTK_WINDOW (parent)); - gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); - - /* join the add/remove toolbar to the treeview */ - context = gtk_widget_get_style_context (sw); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); - - context = gtk_widget_get_style_context (toolbar); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); - - irc_network_dialog_network_update_buttons (dialog); - gtk_widget_show_all (dialog->dialog); - - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - - return dialog->dialog; -} diff --git a/libempathy-gtk/empathy-irc-network-dialog.h b/libempathy-gtk/empathy-irc-network-dialog.h deleted file mode 100644 index a49c63da9..000000000 --- a/libempathy-gtk/empathy-irc-network-dialog.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007-2008 Guillaume Desmottes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Guillaume Desmottes - */ - -#ifndef __EMPATHY_IRC_NETWORK_DIALOG_H__ -#define __EMPATHY_IRC_NETWORK_DIALOG_H__ - -#include - -#include "empathy-irc-network.h" - -G_BEGIN_DECLS - -GtkWidget * empathy_irc_network_dialog_show (EmpathyIrcNetwork *network, - GtkWidget *parent); - -G_END_DECLS - -#endif /* __EMPATHY_IRC_NETWORK_DIALOG_H__ */ diff --git a/libempathy-gtk/totem-subtitle-encoding.c b/libempathy-gtk/totem-subtitle-encoding.c deleted file mode 100644 index 2db1c23c0..000000000 --- a/libempathy-gtk/totem-subtitle-encoding.c +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Copyright (C) 2001-2006 Bastien Nocera - * - * encoding list copied from gnome-terminal/encoding.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * The Totem project hereby grant permission for non-gpl compatible GStreamer - * plugins to be used and distributed together with GStreamer and Totem. This - * permission are above and beyond the permissions granted by the GPL license - * Totem is covered by. - * - * Monday 7th February 2005: Christian Schaller: Add exception clause. - * See license_change file for details. - * - */ - -#include "config.h" -#include -#include "totem-subtitle-encoding.h" - -typedef enum -{ - SUBTITLE_ENCODING_CURRENT_LOCALE, - - SUBTITLE_ENCODING_ISO_8859_6, - SUBTITLE_ENCODING_IBM_864, - SUBTITLE_ENCODING_MAC_ARABIC, - SUBTITLE_ENCODING_WINDOWS_1256, - - SUBTITLE_ENCODING_ARMSCII_8, - - SUBTITLE_ENCODING_ISO_8859_4, - SUBTITLE_ENCODING_ISO_8859_13, - SUBTITLE_ENCODING_WINDOWS_1257, - - SUBTITLE_ENCODING_ISO_8859_14, - - SUBTITLE_ENCODING_ISO_8859_2, - SUBTITLE_ENCODING_IBM_852, - SUBTITLE_ENCODING_MAC_CE, - SUBTITLE_ENCODING_WINDOWS_1250, - - SUBTITLE_ENCODING_GB18030, - SUBTITLE_ENCODING_GB2312, - SUBTITLE_ENCODING_GBK, - SUBTITLE_ENCODING_HZ, - - SUBTITLE_ENCODING_BIG5, - SUBTITLE_ENCODING_BIG5_HKSCS, - SUBTITLE_ENCODING_EUC_TW, - - SUBTITLE_ENCODING_MAC_CROATIAN, - - SUBTITLE_ENCODING_ISO_8859_5, - SUBTITLE_ENCODING_IBM_855, - SUBTITLE_ENCODING_ISO_IR_111, - SUBTITLE_ENCODING_KOI8_R, - SUBTITLE_ENCODING_MAC_CYRILLIC, - SUBTITLE_ENCODING_WINDOWS_1251, - - SUBTITLE_ENCODING_CP_866, - - SUBTITLE_ENCODING_MAC_UKRAINIAN, - SUBTITLE_ENCODING_KOI8_U, - - SUBTITLE_ENCODING_GEOSTD8, - - SUBTITLE_ENCODING_ISO_8859_7, - SUBTITLE_ENCODING_MAC_GREEK, - SUBTITLE_ENCODING_WINDOWS_1253, - - SUBTITLE_ENCODING_MAC_GUJARATI, - - SUBTITLE_ENCODING_MAC_GURMUKHI, - - SUBTITLE_ENCODING_ISO_8859_8_I, - SUBTITLE_ENCODING_IBM_862, - SUBTITLE_ENCODING_MAC_HEBREW, - SUBTITLE_ENCODING_WINDOWS_1255, - - SUBTITLE_ENCODING_ISO_8859_8, - - SUBTITLE_ENCODING_MAC_DEVANAGARI, - - SUBTITLE_ENCODING_MAC_ICELANDIC, - - SUBTITLE_ENCODING_EUC_JP, - SUBTITLE_ENCODING_ISO_2022_JP, - SUBTITLE_ENCODING_SHIFT_JIS, - - SUBTITLE_ENCODING_EUC_KR, - SUBTITLE_ENCODING_ISO_2022_KR, - SUBTITLE_ENCODING_JOHAB, - SUBTITLE_ENCODING_UHC, - - SUBTITLE_ENCODING_ISO_8859_10, - - SUBTITLE_ENCODING_MAC_FARSI, - - SUBTITLE_ENCODING_ISO_8859_16, - SUBTITLE_ENCODING_MAC_ROMANIAN, - - SUBTITLE_ENCODING_ISO_8859_3, - - SUBTITLE_ENCODING_TIS_620, - - SUBTITLE_ENCODING_ISO_8859_9, - SUBTITLE_ENCODING_IBM_857, - SUBTITLE_ENCODING_MAC_TURKISH, - SUBTITLE_ENCODING_WINDOWS_1254, - - SUBTITLE_ENCODING_UTF_7, - SUBTITLE_ENCODING_UTF_8, - SUBTITLE_ENCODING_UTF_16, - SUBTITLE_ENCODING_UCS_2, - SUBTITLE_ENCODING_UCS_4, - - SUBTITLE_ENCODING_ISO_8859_1, - SUBTITLE_ENCODING_ISO_8859_15, - SUBTITLE_ENCODING_IBM_850, - SUBTITLE_ENCODING_MAC_ROMAN, - SUBTITLE_ENCODING_WINDOWS_1252, - - SUBTITLE_ENCODING_TCVN, - SUBTITLE_ENCODING_VISCII, - SUBTITLE_ENCODING_WINDOWS_1258, - - SUBTITLE_ENCODING_LAST -} SubtitleEncodingIndex; - - -typedef struct -{ - int index; - gboolean valid; - const char *charset; - const char *name; -} SubtitleEncoding; - - -static SubtitleEncoding encodings[] = { - - {SUBTITLE_ENCODING_CURRENT_LOCALE, TRUE, - NULL, N_("Current Locale")}, - - {SUBTITLE_ENCODING_ISO_8859_6, FALSE, - "ISO-8859-6", N_("Arabic")}, - {SUBTITLE_ENCODING_IBM_864, FALSE, - "IBM864", N_("Arabic")}, - {SUBTITLE_ENCODING_MAC_ARABIC, FALSE, - "MAC_ARABIC", N_("Arabic")}, - {SUBTITLE_ENCODING_WINDOWS_1256, FALSE, - "WINDOWS-1256", N_("Arabic")}, - - {SUBTITLE_ENCODING_ARMSCII_8, FALSE, - "ARMSCII-8", N_("Armenian")}, - - {SUBTITLE_ENCODING_ISO_8859_4, FALSE, - "ISO-8859-4", N_("Baltic")}, - {SUBTITLE_ENCODING_ISO_8859_13, FALSE, - "ISO-8859-13", N_("Baltic")}, - {SUBTITLE_ENCODING_WINDOWS_1257, FALSE, - "WINDOWS-1257", N_("Baltic")}, - - {SUBTITLE_ENCODING_ISO_8859_14, FALSE, - "ISO-8859-14", N_("Celtic")}, - - {SUBTITLE_ENCODING_ISO_8859_2, FALSE, - "ISO-8859-2", N_("Central European")}, - {SUBTITLE_ENCODING_IBM_852, FALSE, - "IBM852", N_("Central European")}, - {SUBTITLE_ENCODING_MAC_CE, FALSE, - "MAC_CE", N_("Central European")}, - {SUBTITLE_ENCODING_WINDOWS_1250, FALSE, - "WINDOWS-1250", N_("Central European")}, - - {SUBTITLE_ENCODING_GB18030, FALSE, - "GB18030", N_("Chinese Simplified")}, - {SUBTITLE_ENCODING_GB2312, FALSE, - "GB2312", N_("Chinese Simplified")}, - {SUBTITLE_ENCODING_GBK, FALSE, - "GBK", N_("Chinese Simplified")}, - {SUBTITLE_ENCODING_HZ, FALSE, - "HZ", N_("Chinese Simplified")}, - - {SUBTITLE_ENCODING_BIG5, FALSE, - "BIG5", N_("Chinese Traditional")}, - {SUBTITLE_ENCODING_BIG5_HKSCS, FALSE, - "BIG5-HKSCS", N_("Chinese Traditional")}, - {SUBTITLE_ENCODING_EUC_TW, FALSE, - "EUC-TW", N_("Chinese Traditional")}, - - {SUBTITLE_ENCODING_MAC_CROATIAN, FALSE, - "MAC_CROATIAN", N_("Croatian")}, - - {SUBTITLE_ENCODING_ISO_8859_5, FALSE, - "ISO-8859-5", N_("Cyrillic")}, - {SUBTITLE_ENCODING_IBM_855, FALSE, - "IBM855", N_("Cyrillic")}, - {SUBTITLE_ENCODING_ISO_IR_111, FALSE, - "ISO-IR-111", N_("Cyrillic")}, - {SUBTITLE_ENCODING_KOI8_R, FALSE, - "KOI8-R", N_("Cyrillic")}, - {SUBTITLE_ENCODING_MAC_CYRILLIC, FALSE, - "MAC-CYRILLIC", N_("Cyrillic")}, - {SUBTITLE_ENCODING_WINDOWS_1251, FALSE, - "WINDOWS-1251", N_("Cyrillic")}, - - {SUBTITLE_ENCODING_CP_866, FALSE, - "CP866", N_("Cyrillic/Russian")}, - - {SUBTITLE_ENCODING_MAC_UKRAINIAN, FALSE, - "MAC_UKRAINIAN", N_("Cyrillic/Ukrainian")}, - {SUBTITLE_ENCODING_KOI8_U, FALSE, - "KOI8-U", N_("Cyrillic/Ukrainian")}, - - {SUBTITLE_ENCODING_GEOSTD8, FALSE, - "GEORGIAN-PS", N_("Georgian")}, - - {SUBTITLE_ENCODING_ISO_8859_7, FALSE, - "ISO-8859-7", N_("Greek")}, - {SUBTITLE_ENCODING_MAC_GREEK, FALSE, - "MAC_GREEK", N_("Greek")}, - {SUBTITLE_ENCODING_WINDOWS_1253, FALSE, - "WINDOWS-1253", N_("Greek")}, - - {SUBTITLE_ENCODING_MAC_GUJARATI, FALSE, - "MAC_GUJARATI", N_("Gujarati")}, - - {SUBTITLE_ENCODING_MAC_GURMUKHI, FALSE, - "MAC_GURMUKHI", N_("Gurmukhi")}, - - {SUBTITLE_ENCODING_ISO_8859_8_I, FALSE, - "ISO-8859-8-I", N_("Hebrew")}, - {SUBTITLE_ENCODING_IBM_862, FALSE, - "IBM862", N_("Hebrew")}, - {SUBTITLE_ENCODING_MAC_HEBREW, FALSE, - "MAC_HEBREW", N_("Hebrew")}, - {SUBTITLE_ENCODING_WINDOWS_1255, FALSE, - "WINDOWS-1255", N_("Hebrew")}, - - {SUBTITLE_ENCODING_ISO_8859_8, FALSE, - "ISO-8859-8", N_("Hebrew Visual")}, - - {SUBTITLE_ENCODING_MAC_DEVANAGARI, FALSE, - "MAC_DEVANAGARI", N_("Hindi")}, - - {SUBTITLE_ENCODING_MAC_ICELANDIC, FALSE, - "MAC_ICELANDIC", N_("Icelandic")}, - - {SUBTITLE_ENCODING_EUC_JP, FALSE, - "EUC-JP", N_("Japanese")}, - {SUBTITLE_ENCODING_ISO_2022_JP, FALSE, - "ISO2022JP", N_("Japanese")}, - {SUBTITLE_ENCODING_SHIFT_JIS, FALSE, - "SHIFT-JIS", N_("Japanese")}, - - {SUBTITLE_ENCODING_EUC_KR, FALSE, - "EUC-KR", N_("Korean")}, - {SUBTITLE_ENCODING_ISO_2022_KR, FALSE, - "ISO2022KR", N_("Korean")}, - {SUBTITLE_ENCODING_JOHAB, FALSE, - "JOHAB", N_("Korean")}, - {SUBTITLE_ENCODING_UHC, FALSE, - "UHC", N_("Korean")}, - - {SUBTITLE_ENCODING_ISO_8859_10, FALSE, - "ISO-8859-10", N_("Nordic")}, - - {SUBTITLE_ENCODING_MAC_FARSI, FALSE, - "MAC_FARSI", N_("Persian")}, - - {SUBTITLE_ENCODING_ISO_8859_16, FALSE, - "ISO-8859-16", N_("Romanian")}, - {SUBTITLE_ENCODING_MAC_ROMANIAN, FALSE, - "MAC_ROMANIAN", N_("Romanian")}, - - {SUBTITLE_ENCODING_ISO_8859_3, FALSE, - "ISO-8859-3", N_("South European")}, - - {SUBTITLE_ENCODING_TIS_620, FALSE, - "TIS-620", N_("Thai")}, - - {SUBTITLE_ENCODING_ISO_8859_9, FALSE, - "ISO-8859-9", N_("Turkish")}, - {SUBTITLE_ENCODING_IBM_857, FALSE, - "IBM857", N_("Turkish")}, - {SUBTITLE_ENCODING_MAC_TURKISH, FALSE, - "MAC_TURKISH", N_("Turkish")}, - {SUBTITLE_ENCODING_WINDOWS_1254, FALSE, - "WINDOWS-1254", N_("Turkish")}, - - {SUBTITLE_ENCODING_UTF_7, FALSE, - "UTF-7", N_("Unicode")}, - {SUBTITLE_ENCODING_UTF_8, FALSE, - "UTF-8", N_("Unicode")}, - {SUBTITLE_ENCODING_UTF_16, FALSE, - "UTF-16", N_("Unicode")}, - {SUBTITLE_ENCODING_UCS_2, FALSE, - "UCS-2", N_("Unicode")}, - {SUBTITLE_ENCODING_UCS_4, FALSE, - "UCS-4", N_("Unicode")}, - - {SUBTITLE_ENCODING_ISO_8859_1, FALSE, - "ISO-8859-1", N_("Western")}, - {SUBTITLE_ENCODING_ISO_8859_15, FALSE, - "ISO-8859-15", N_("Western")}, - {SUBTITLE_ENCODING_IBM_850, FALSE, - "IBM850", N_("Western")}, - {SUBTITLE_ENCODING_MAC_ROMAN, FALSE, - "MAC_ROMAN", N_("Western")}, - {SUBTITLE_ENCODING_WINDOWS_1252, FALSE, - "WINDOWS-1252", N_("Western")}, - - {SUBTITLE_ENCODING_TCVN, FALSE, - "TCVN", N_("Vietnamese")}, - {SUBTITLE_ENCODING_VISCII, FALSE, - "VISCII", N_("Vietnamese")}, - {SUBTITLE_ENCODING_WINDOWS_1258, FALSE, - "WINDOWS-1258", N_("Vietnamese")} -}; - -static const SubtitleEncoding * -find_encoding_by_charset (const char *charset) -{ - int i; - - i = 1; /* skip current locale */ - while (i < SUBTITLE_ENCODING_LAST) { - if (strcasecmp (charset, encodings[i].charset) == 0) - return &encodings[i]; - - ++i; - } - - if (strcasecmp (charset, - encodings[SUBTITLE_ENCODING_CURRENT_LOCALE].charset) == 0) - return &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; - - return NULL; -} - -static void -subtitle_encoding_init (void) -{ - int i; - gsize bytes_read, bytes_written; - gchar *converted; - gchar ascii_sample[96]; - - g_get_charset ((const char **) - &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE].charset); - - g_assert (G_N_ELEMENTS (encodings) == SUBTITLE_ENCODING_LAST); - - /* Initialize the sample text with all of the printing ASCII characters - * from space (32) to the tilde (126), 95 in all. */ - for (i = 0; i < (int) sizeof (ascii_sample); i++) - ascii_sample[i] = i + 32; - - ascii_sample[sizeof (ascii_sample) - 1] = '\0'; - - i = 0; - while (i < SUBTITLE_ENCODING_LAST) { - bytes_read = 0; - bytes_written = 0; - - g_assert (encodings[i].index == i); - - /* Translate the names */ - encodings[i].name = _(encodings[i].name); - - /* Test that the encoding is a proper superset of ASCII (which naive - * apps are going to use anyway) by attempting to validate the text - * using the current encoding. This also flushes out any encodings - * which the underlying GIConv implementation can't support. - */ - converted = g_convert (ascii_sample, sizeof (ascii_sample) - 1, - encodings[i].charset, encodings[i].charset, - &bytes_read, &bytes_written, NULL); - - /* The encoding is only valid if ASCII passes through cleanly. */ - if (i == SUBTITLE_ENCODING_CURRENT_LOCALE) - encodings[i].valid = TRUE; - else - encodings[i].valid = - (bytes_read == (sizeof (ascii_sample) - 1)) && - (converted != NULL) && (strcmp (converted, ascii_sample) == 0); - -#ifdef DEBUG_ENCODINGS - if (!encodings[i].valid) { - g_print ("Rejecting encoding %s as invalid:\n", encodings[i].charset); - g_print (" input \"%s\"\n", ascii_sample); - g_print (" output \"%s\"\n\n", converted ? converted : "(null)"); - } -#endif - - /* Discard the converted string. */ - g_free (converted); - - ++i; - } -} - -static int -subtitle_encoding_get_index (const char *charset) -{ - const SubtitleEncoding *e; - - e = find_encoding_by_charset (charset); - if (e != NULL) - return e->index; - else - return SUBTITLE_ENCODING_CURRENT_LOCALE; -} - -static const char * -subtitle_encoding_get_charset (int index_) -{ - const SubtitleEncoding *e; - - if (index_ >= SUBTITLE_ENCODING_LAST) - e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; - else if (index_ < SUBTITLE_ENCODING_CURRENT_LOCALE) - e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; - else if (!encodings[index_].valid) - e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; - else - e = &encodings[index_]; - return e->charset; -} - -enum -{ - INDEX_COL, - NAME_COL -}; - -static gint -compare (GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer data) -{ - gchar *str_a, *str_b; - gint result; - - gtk_tree_model_get (model, a, NAME_COL, &str_a, -1); - gtk_tree_model_get (model, b, NAME_COL, &str_b, -1); - - result = strcmp (str_a, str_b); - - g_free (str_a); - g_free (str_b); - - return result; -} - -static void -is_encoding_sensitive (GtkCellLayout * cell_layout, - GtkCellRenderer * cell, - GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data) -{ - - gboolean sensitive; - - sensitive = !gtk_tree_model_iter_has_child (tree_model, iter); - g_object_set (cell, "sensitive", sensitive, NULL); -} - -static GtkTreeModel * -subtitle_encoding_create_store (void) -{ - gchar *label; - const gchar *lastlang = ""; - GtkTreeIter iter, iter2; - GtkTreeStore *store; - int i; - - store = gtk_tree_store_new (2, G_TYPE_INT, G_TYPE_STRING); - - for (i = 0; i < SUBTITLE_ENCODING_LAST; i++) { - if (encodings[i].valid) { - if (strcmp (lastlang, encodings[i].name)) { - lastlang = encodings[i].name; - gtk_tree_store_append (store, &iter, NULL); - gtk_tree_store_set (store, &iter, INDEX_COL, - -1, NAME_COL, lastlang, -1); - } - label = g_strdup_printf("%s (%s)", lastlang, encodings[i].charset); - gtk_tree_store_append (store, &iter2, &iter); - gtk_tree_store_set (store, &iter2, INDEX_COL, - encodings[i].index, NAME_COL, label, -1); - g_free(label); - } - } - gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), - compare, NULL, NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - NAME_COL, GTK_SORT_ASCENDING); - return GTK_TREE_MODEL (store); -} - -static void -subtitle_encoding_combo_render (GtkComboBox * combo) -{ - GtkCellRenderer *renderer; - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, - "text", NAME_COL, NULL); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), - renderer, is_encoding_sensitive, NULL, NULL); -} - -const char * -totem_subtitle_encoding_get_selected (GtkComboBox * combo) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gint index_ = -1; - - model = gtk_combo_box_get_model (combo); - if (gtk_combo_box_get_active_iter (combo, &iter)) { - gtk_tree_model_get (model, &iter, INDEX_COL, &index_, -1); - } - if (index_ == -1) - return NULL; - return subtitle_encoding_get_charset (index_); -} - -void -totem_subtitle_encoding_set (GtkComboBox * combo, const char *encoding) -{ - GtkTreeModel *model; - GtkTreeIter iter, iter2; - gint index_, i; - - g_return_if_fail (encoding != NULL); - - model = gtk_combo_box_get_model (combo); - index_ = subtitle_encoding_get_index (encoding); - gtk_tree_model_get_iter_first (model, &iter); - do { - if (!gtk_tree_model_iter_has_child (model, &iter)) - continue; - if (!gtk_tree_model_iter_children (model, &iter2, &iter)) - continue; - do { - gtk_tree_model_get (model, &iter2, INDEX_COL, &i, -1); - if (i == index_) - break; - } while (gtk_tree_model_iter_next (model, &iter2)); - if (i == index_) - break; - } while (gtk_tree_model_iter_next (model, &iter)); - gtk_combo_box_set_active_iter (combo, &iter2); -} - -void -totem_subtitle_encoding_init (GtkComboBox *combo) -{ - GtkTreeModel *model; - subtitle_encoding_init (); - model = subtitle_encoding_create_store (); - gtk_combo_box_set_model (combo, model); - g_object_unref (model); - subtitle_encoding_combo_render (combo); -} - -/* - * vim: sw=2 ts=8 cindent noai bs=2 - */ diff --git a/libempathy-gtk/totem-subtitle-encoding.h b/libempathy-gtk/totem-subtitle-encoding.h deleted file mode 100644 index 656c0dec5..000000000 --- a/libempathy-gtk/totem-subtitle-encoding.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2001-2006 Bastien Nocera - * - * encoding list copied from gnome-terminal/encoding.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * The Totem project hereby grant permission for non-gpl compatible GStreamer - * plugins to be used and distributed together with GStreamer and Totem. This - * permission are above and beyond the permissions granted by the GPL license - * Totem is covered by. - * - * Monday 7th February 2005: Christian Schaller: Add exception clause. - * See license_change file for details. - * - */ - -/* Encoding stuff */ - -#ifndef TOTEM_SUBTITLE_ENCODING_H -#define TOTEM_SUBTITLE_ENCODING_H - -#include - -void totem_subtitle_encoding_init (GtkComboBox *combo); -void totem_subtitle_encoding_set (GtkComboBox *combo, const char *encoding); -const char * totem_subtitle_encoding_get_selected (GtkComboBox *combo); - -#endif /* SUBTITLE_ENCODING_H */ diff --git a/src/Makefile.am b/src/Makefile.am index db30af3f2..fdc95844d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,7 @@ include $(top_srcdir)/tools/flymake.mk CPPFLAGS_COMMON = \ $(EMPATHY_CFLAGS) \ $(ERROR_CFLAGS) \ + -I$(top_srcdir)/tp-account-widgets \ -I$(top_srcdir)/libempathy-gtk \ -I$(top_srcdir)/libempathy \ -I$(top_srcdir)/extensions \ @@ -22,6 +23,7 @@ AM_CPPFLAGS = \ $(NULL) LDADD = \ + $(top_builddir)/tp-account-widgets/libtp-account-widgets.la \ $(top_builddir)/libempathy-gtk/libempathy-gtk.la \ $(top_builddir)/libempathy/libempathy.la \ $(top_builddir)/extensions/libemp-extensions.la \ diff --git a/tp-account-widgets/.gitignore b/tp-account-widgets/.gitignore new file mode 100644 index 000000000..3c37f3d0c --- /dev/null +++ b/tp-account-widgets/.gitignore @@ -0,0 +1 @@ +empathy-account-widgets-resources.[ch] diff --git a/tp-account-widgets/Makefile.am b/tp-account-widgets/Makefile.am new file mode 100644 index 000000000..c3a23a009 --- /dev/null +++ b/tp-account-widgets/Makefile.am @@ -0,0 +1,94 @@ +include $(top_srcdir)/tools/flymake.mk + +AM_CPPFLAGS = \ + $(ERROR_CFLAGS) \ + -I$(top_srcdir)/libempathy \ + -I$(top_srcdir)/libempathy-gtk \ + -DDATADIR=\""$(datadir)"\" \ + -DPKGDATADIR=\""$(pkgdatadir)"\" \ + -DG_LOG_DOMAIN=\"empathy\" \ + -DGCR_API_SUBJECT_TO_CHANGE \ + $(EMPATHY_CFLAGS) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) + +BUILT_SOURCES = \ + empathy-account-widgets-resources.c \ + empathy-account-widgets-resources.h \ + $(NULL) + +libtp_account_widgets_sources = \ + empathy-account-widget.c \ + empathy-account-widget-irc.c \ + empathy-account-widget-private.h \ + empathy-account-widget-sip.c \ + empathy-irc-network-chooser.c \ + empathy-irc-network-chooser-dialog.c \ + empathy-irc-network-dialog.c \ + totem-subtitle-encoding.c \ + $(NULL) + +libtp_account_widgets_headers = \ + empathy-account-widget.h \ + empathy-account-widget-irc.h \ + empathy-account-widget-sip.h \ + empathy-irc-network-chooser-dialog.h \ + empathy-irc-network-chooser.h \ + empathy-irc-network-dialog.h \ + totem-subtitle-encoding.h \ + $(NULL) + +pkglib_LTLIBRARIES = libtp-account-widgets.la + +# libtp-account-widgets's API is not stable and will never be, so use -release to make the +# SONAME of the plugin library change with every Empathy release. +libtp_account_widgets_la_LDFLAGS = \ + -no-undefined \ + -release $(VERSION) \ + $(NULL) + +libtp_account_widgets_la_SOURCES = \ + $(libtp_account_widgets_sources) \ + $(libtp_account_widgets_headers) \ + $(NULL) + +# do not distribute generated files +nodist_libtp_account_widgets_la_SOURCES = \ + $(BUILT_SOURCES) + +check_c_sources = \ + $(libtp_account_widgets_sources) \ + $(libtp_account_widgets_headers) \ + $(NULL) +include $(top_srcdir)/tools/check-coding-style.mk +check-local: check-coding-style + +account_widgets_ui_files = \ + empathy-account-widget-generic.ui \ + empathy-account-widget-jabber.ui \ + empathy-account-widget-msn.ui \ + empathy-account-widget-sip.ui \ + empathy-account-widget-local-xmpp.ui \ + empathy-account-widget-irc.ui \ + empathy-account-widget-icq.ui \ + empathy-account-widget-yahoo.ui \ + empathy-account-widget-groupwise.ui \ + empathy-account-widget-aim.ui \ + $(NULL) + +account_widgets_resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) $(srcdir)/empathy-account-widgets.gresource.xml) + +empathy-account-widgets-resources.c: empathy-account-widgets.gresource.xml $(account_widgets_resource_files) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $< + +empathy-account-widgets-resources.h: empathy-account-widgets.gresource.xml $(account_widgets_resource_files) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-header $< + +EXTRA_DIST = \ + empathy-account-widgets.gresource.xml \ + $(account_widgets_ui_files) \ + $(NULL) + +CLEANFILES = \ + $(BUILT_SOURCES) \ + $(NULL) diff --git a/tp-account-widgets/empathy-account-widget-aim.ui b/tp-account-widgets/empathy-account-widget-aim.ui new file mode 100644 index 000000000..8ceacbf47 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-aim.ui @@ -0,0 +1,299 @@ + + + + + + 5222 + 65555 + 1 + 10 + + + True + vertical + 6 + + + True + 12 + 6 + + + True + 1 + Pass_word + True + entry_password + + + + 2 + + + + + True + 1 + Screen _Name + True + entry_screenname + + + + + + + + True + True + + + 1 + + + + + True + True + False + + + 1 + 2 + + + + + True + 0 + 3 + <b>Example:</b> MyScreenName + True + + + + + + 1 + 1 + + + + + Remember password + True + True + False + True + True + + + 1 + 3 + + + + + + + + + + + False + False + 0 + + + + + True + True + + + True + 12 + 6 + + + True + True + adjustment1 + 1 + True + True + + + 1 + 1 + + + + + True + 1 + _Port + True + spinbutton_port + + + + 0 + 1 + + + + + True + True + True + + + 1 + 0 + + + + + True + 1 + _Server + True + entry_server + + + + 0 + 0 + + + + + + + True + Advanced + + + + + + + + False + False + 1 + + + + + True + vertical + 6 + + + True + 0 + What is your AIM screen name? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + vertical + 4 + + + True + True + + + 0 + + + + + True + 0.10000000149011612 + <b>Example:</b> MyScreenName + True + + + + + + 1 + + + + + + + 1 + + + + + True + 0 + What is your AIM password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + 3 + + + + + Remember Password + True + True + False + True + True + + + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget-generic.ui b/tp-account-widgets/empathy-account-widget-generic.ui new file mode 100644 index 000000000..c37da5e01 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-generic.ui @@ -0,0 +1,122 @@ + + + + + True + False + 6 + + + True + False + 6 + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + False + 0 + + + + + True + True + + + 150 + True + True + never + in + + + True + False + 6 + queue + + + True + False + 6 + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + False + Advanced + + + + + + + + True + True + 1 + + + + diff --git a/tp-account-widgets/empathy-account-widget-groupwise.ui b/tp-account-widgets/empathy-account-widget-groupwise.ui new file mode 100644 index 000000000..cfca2e345 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-groupwise.ui @@ -0,0 +1,292 @@ + + + + + + 65535 + 1 + 10 + + + True + vertical + 6 + + + True + 12 + 6 + + + True + 1 + Pass_word + True + + + + 2 + + + + + True + 1 + Login I_D + True + entry_id + + + + + + + + True + True + + + 1 + + + + + True + 0 + 3 + <b>Example:</b> username + True + + + + + + 1 + 1 + + + + + True + True + False + + + 1 + 2 + + + + + Remember password + True + True + False + True + True + + + 1 + 3 + + + + + + + + + + + False + 0 + + + + + True + True + + + True + 6 + 6 + + + True + 1 + _Port + True + spinbutton_port + + + + 1 + + + + + True + 1 + _Server + True + entry_server + + + + 0 + + + + + True + True + + + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + adjustment1 + 1 + True + + + 1 + 1 + + + + + + + True + Advanced + + + + + + + + False + False + 1 + + + + + True + vertical + 6 + + + True + 0 + What is your GroupWise User ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + vertical + 4 + + + True + True + + + 0 + + + + + True + 0.10000000149011612 + <b>Example:</b> username + True + + + + + + 1 + + + + + + + 1 + + + + + True + 0 + What is your GroupWise password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + 3 + + + + + Remember Password + True + True + False + True + True + + + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget-icq.ui b/tp-account-widgets/empathy-account-widget-icq.ui new file mode 100644 index 000000000..865a33c08 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-icq.ui @@ -0,0 +1,320 @@ + + + + + + 5222 + 65555 + 1 + 10 + + + True + vertical + 6 + + + True + 12 + 6 + + + True + 1 + Pass_word + True + entry_password + + + + 2 + + + + + True + 1 + ICQ _UIN + True + entry_uin + + + + + + + + True + True + + + 1 + + + + + True + True + False + + + 1 + 2 + + + + + True + 0 + 3 + <b>Example:</b> 123456789 + True + + + + + + 1 + 1 + + + + + Remember password + True + True + False + True + True + + + 1 + 3 + + + + + + + + + + + False + False + 0 + + + + + True + True + + + True + 12 + 6 + + + True + 1 + Ch_aracter set + True + entry_charset + + + + + + + + True + True + adjustment1 + 1 + True + + + 1 + 2 + + + + + True + True + + + 1 + 1 + + + + + True + 1 + _Port + True + spinbutton_port + + + + 2 + 0 + + + + + True + 1 + _Server + True + entry_server + + + + 1 + 0 + + + + + True + True + + + 1 + + + + + + + True + Advanced + + + + + + + + False + False + 1 + + + + + True + vertical + 6 + + + True + 0 + What is your ICQ UIN? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + vertical + 4 + + + True + True + + + 0 + + + + + True + 0.10000000149011612 + <b>Example:</b> 123456789 + True + + + + + + 1 + + + + + + + 1 + + + + + True + 0 + What is your ICQ password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + 3 + + + + + Remember Password + True + True + False + True + True + + + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget-irc.c b/tp-account-widgets/empathy-account-widget-irc.c new file mode 100644 index 000000000..e86cec417 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-irc.c @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#include "config.h" +#include "empathy-account-widget-irc.h" + +#include "empathy-account-widget-private.h" +#include "empathy-ui-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC +#include "empathy-debug.h" + +typedef struct { + EmpathyAccountWidget *self; + + GtkWidget *vbox_settings; + + GtkWidget *network_chooser; +} EmpathyAccountWidgetIrc; + +static void +account_widget_irc_destroy_cb (GtkWidget *widget, + EmpathyAccountWidgetIrc *settings) +{ + g_slice_free (EmpathyAccountWidgetIrc, settings); +} + +static void +account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) +{ + gchar *nick = NULL; + gchar *fullname = NULL; + EmpathyAccountSettings *ac_settings; + + g_object_get (settings->self, "settings", &ac_settings, NULL); + + nick = empathy_account_settings_dup_string (ac_settings, "account"); + fullname = empathy_account_settings_dup_string (ac_settings, + "fullname"); + + if (nick == NULL) + { + nick = g_strdup (g_get_user_name ()); + + empathy_account_settings_set (ac_settings, + "account", g_variant_new_string (nick)); + } + + if (fullname == NULL) + { + fullname = g_strdup (g_get_real_name ()); + + if (fullname == NULL) + fullname = g_strdup (nick); + + empathy_account_settings_set (ac_settings, + "fullname", g_variant_new_string (fullname)); + } + + g_free (nick); + g_free (fullname); +} + +static void +network_changed_cb (EmpathyIrcNetworkChooser *chooser, + EmpathyAccountWidgetIrc *settings) +{ + empathy_account_widget_changed (settings->self); +} + +/** + * set_password_prompt_if_needed: + * + * If @password is not empty, this function sets the 'password-prompt' param + * on @ac_settings. This will ensure that Idle actually asks for the password + * when connecting. + * + * Return: %TRUE if the password-prompt param has been changed + */ +static gboolean +set_password_prompt_if_needed (EmpathyAccountSettings *ac_settings, + const gchar *password) +{ + gboolean prompt; + + prompt = !tp_str_empty (password); + + if (prompt == empathy_account_settings_get_boolean (ac_settings, + "password-prompt")) + return FALSE; + + empathy_account_settings_set (ac_settings, "password-prompt", + g_variant_new_boolean (prompt)); + + return TRUE; +} + +static void +entry_password_changed_cb (GtkEntry *entry, + EmpathyAccountWidgetIrc *settings) +{ + const gchar *password; + EmpathyAccountSettings *ac_settings; + + g_object_get (settings->self, "settings", &ac_settings, NULL); + + password = gtk_entry_get_text (entry); + + set_password_prompt_if_needed (ac_settings, password); + + g_object_unref (ac_settings); +} + +EmpathyIrcNetworkChooser * +empathy_account_widget_irc_build (EmpathyAccountWidget *self, + const char *filename, + GtkWidget **table_common_settings, + GtkWidget **box) +{ + EmpathyAccountWidgetIrc *settings; + EmpathyAccountSettings *ac_settings; + GtkWidget *entry_password; + gchar *password; + + settings = g_slice_new0 (EmpathyAccountWidgetIrc); + settings->self = self; + + self->ui_details->gui = empathy_builder_get_resource (filename, + "table_irc_settings", table_common_settings, + "vbox_irc", box, + "table_irc_settings", &settings->vbox_settings, + "entry_password", &entry_password, + NULL); + + /* Add network chooser button */ + g_object_get (settings->self, "settings", &ac_settings, NULL); + + settings->network_chooser = empathy_irc_network_chooser_new (ac_settings); + + g_signal_connect (settings->network_chooser, "changed", + G_CALLBACK (network_changed_cb), settings); + + gtk_grid_attach (GTK_GRID (*table_common_settings), + settings->network_chooser, 1, 0, 1, 1); + + gtk_widget_show (settings->network_chooser); + + account_widget_irc_setup (settings); + + empathy_account_widget_handle_params (self, + "entry_nick", "account", + "entry_fullname", "fullname", + "entry_password", "password", + "entry_quit_message", "quit-message", + "entry_username", "username", + NULL); + + empathy_builder_connect (self->ui_details->gui, settings, + "table_irc_settings", "destroy", account_widget_irc_destroy_cb, + NULL); + + self->ui_details->default_focus = g_strdup ("entry_nick"); + + g_object_unref (ac_settings); + + /* Automatically set password-prompt when needed */ + password = empathy_account_settings_dup_string (ac_settings, "password"); + + if (set_password_prompt_if_needed (ac_settings, password)) + { + /* Apply right now to save password-prompt */ + empathy_account_settings_apply_async (ac_settings, NULL, NULL); + } + + g_free (password); + + g_signal_connect (entry_password, "changed", + G_CALLBACK (entry_password_changed_cb), settings); + + return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser); +} + +EmpathyIrcNetworkChooser * +empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self, + const char *filename, + GtkWidget **box) +{ + EmpathyAccountWidgetIrc *settings; + EmpathyAccountSettings *ac_settings; + GtkAlignment *alignment; + + settings = g_slice_new0 (EmpathyAccountWidgetIrc); + settings->self = self; + + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_irc_simple", box, + "alignment_network_simple", &alignment, + NULL); + + /* Add network chooser button */ + g_object_get (settings->self, "settings", &ac_settings, NULL); + + settings->network_chooser = empathy_irc_network_chooser_new (ac_settings); + + g_signal_connect (settings->network_chooser, "changed", + G_CALLBACK (network_changed_cb), settings); + + gtk_container_add (GTK_CONTAINER (alignment), settings->network_chooser); + + gtk_widget_show (settings->network_chooser); + + empathy_account_widget_handle_params (self, + "entry_nick_simple", "account", + NULL); + + empathy_builder_connect (self->ui_details->gui, settings, + "vbox_irc_simple", "destroy", account_widget_irc_destroy_cb, + NULL); + + self->ui_details->default_focus = g_strdup ("entry_nick_simple"); + + g_object_unref (ac_settings); + + return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser); +} diff --git a/tp-account-widgets/empathy-account-widget-irc.h b/tp-account-widgets/empathy-account-widget-irc.h new file mode 100644 index 000000000..c102d6ea6 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-irc.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#ifndef __EMPATHY_ACCOUNT_WIDGET_IRC_H__ +#define __EMPATHY_ACCOUNT_WIDGET_IRC_H__ + +#include "empathy-account-widget.h" +#include "empathy-irc-network-chooser.h" + +G_BEGIN_DECLS + +EmpathyIrcNetworkChooser * empathy_account_widget_irc_build ( + EmpathyAccountWidget *self, + const char *filename, + GtkWidget **table_common_settings, + GtkWidget **box); + +EmpathyIrcNetworkChooser * empathy_account_widget_irc_build_simple ( + EmpathyAccountWidget *self, + const char *filename, + GtkWidget **box); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_WIDGET_IRC_H__ */ diff --git a/tp-account-widgets/empathy-account-widget-irc.ui b/tp-account-widgets/empathy-account-widget-irc.ui new file mode 100644 index 000000000..fc72974b3 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-irc.ui @@ -0,0 +1,603 @@ + + + + + False + 5 + Network + center-on-parent + gtk-edit + dialog + True + True + + + True + False + 2 + + + True + False + end + + + gtk-close + True + True + True + False + False + True + + + False + False + 0 + + + + + False + True + end + 0 + + + + + True + False + 0 + none + + + True + False + 6 + 12 + + + True + False + 6 + 12 + + + True + False + 1 + Network + + + + 0 + 0 + 1 + 1 + + + + + True + False + 1 + Character set + + + + 0 + 1 + 1 + 1 + + + + + True + True + + + 1 + 0 + 1 + 1 + + + + + True + False + + + 1 + 1 + 1 + 1 + + + + + + + + + True + False + Network + + + + + + + + False + True + 1 + + + + + True + False + 0 + none + + + True + False + 6 + 12 + + + True + False + 6 + 6 + + + True + 0 + + + 120 + True + True + never + in + True + + + True + True + False + + + + + + + + True + True + 0 + + + + + True + 1 + + + + Add… + True + True + True + list-add-symbolic + True + + + + + + + Remove + True + True + True + list-remove-symbolic + True + + + + + + + Up + True + True + True + go-up-symbolic + True + + + + + + + Down + True + True + True + go-down-symbolic + True + + + + + + + False + True + 1 + + + + + + + + + + + True + False + Servers + + + + + + + + False + True + 2 + + + + + + button_close + + + + True + False + + + True + False + 6 + 12 + + + True + True + False + + + 1 + 2 + 1 + 1 + + + + + True + True + + + 1 + 1 + 1 + 1 + + + + + True + True + 0 + 0 + 3 + Most IRC servers don't need a password, so if you're not sure, don't enter a password. + True + True + + + + + + 1 + 3 + 1 + 1 + + + + + True + False + 1 + Network + TrueA + + + + 0 + 0 + 1 + 1 + + + + + True + False + 1 + Nickname + True + entry_nick + + + + 0 + 1 + 1 + 1 + + + + + True + False + 1 + Password + + + + 0 + 2 + 1 + 1 + + + + + False + False + 0 + + + + + True + True + + + True + False + 6 + 12 + + + True + True + + + 1 + 2 + 1 + 1 + + + + + True + False + 1 + Quit message + + + + 0 + 2 + 1 + 1 + + + + + True + True + + + 1 + 1 + 1 + 1 + + + + + True + False + 1 + Real name + True + entry_nick + + + + 0 + 1 + 1 + 1 + + + + + True + False + 1 + Username + True + + + + 0 + 0 + 1 + 1 + + + + + True + True + + + 1 + 0 + 1 + 1 + + + + + + + True + False + Advanced + + + + + + + + True + True + 1 + + + + + True + False + + + True + False + 0 + Which IRC network? + + + True + True + 0 + + + + + True + False + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 6 + 3 + 12 + + + + + + True + True + 1 + + + + + True + False + 0 + What is your IRC nickname? + + + True + True + 2 + + + + + True + False + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 6 + 3 + 12 + + + True + True + + + + + True + True + 3 + + + + + + + + + + + + + + diff --git a/tp-account-widgets/empathy-account-widget-jabber.ui b/tp-account-widgets/empathy-account-widget-jabber.ui new file mode 100644 index 000000000..8422daa0c --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-jabber.ui @@ -0,0 +1,792 @@ + + + + + 127 + 1 + 10 + + + 65555 + 5222 + 1 + 10 + + + True + False + + + True + False + 0 + What is your Facebook username? + + + False + False + 0 + + + + + True + False + 12 + + + True + True + + + False + False + 0 + + + + + True + False + 4 + 0.10000000149011612 + This is your username, not your normal Facebook login. +If you are facebook.com/<b>badger</b>, enter <b>badger</b>. +Use <a href="http://www.facebook.com/username/">this page</a> to choose a Facebook username if you don't have one. + True + + + + + + True + True + 1 + + + + + False + False + 1 + + + + + True + False + 0 + 6 + What is your Facebook password? + + + False + False + 2 + + + + + True + True + 12 + False + + + False + True + 3 + + + + + Remember Password + True + True + False + False + 0 + True + True + + + False + True + 4 + + + + + True + False + + + True + False + 0 + What is your Google ID? + + + False + True + 0 + + + + + True + False + 12 + 4 + + + True + True + + + True + True + 0 + + + + + True + False + 0.10000000149011612 + <b>Example:</b> user@gmail.com + True + + + + + + True + True + 1 + + + + + False + True + 1 + + + + + True + False + 0 + 6 + What is your Google password? + + + False + True + 2 + + + + + True + True + 12 + False + + + False + True + 3 + + + + + Remember Password + True + True + False + False + True + True + + + False + True + 4 + + + + + True + False + 6 + + + True + False + True + 6 + 12 + + + True + True + start + True + False + + + 1 + 2 + 1 + 1 + + + + + True + True + True + + + 1 + 0 + 1 + 1 + + + + + True + False + start + + + False + start + True + 0 + 3 + <b>Example:</b> user@jabber.org + True + + + + + + 0 + 0 + 1 + 1 + + + + + False + start + True + 0 + 3 + <b>Example:</b> user@gmail.com + True + + + + + + 0 + 1 + 1 + 1 + + + + + False + start + True + 0 + 3 + This is your username, not your normal Facebook login. +If you are facebook.com/<b>badger</b>, enter <b>badger</b>. +Use <a href="http://www.facebook.com/username/">this page</a> to choose a Facebook username if you don't have one. + True + True + + + + + + 0 + 2 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + 1 + 1 + 1 + 1 + + + + + Remember password + True + True + False + True + False + True + True + + + 1 + 3 + 1 + 1 + + + + + True + False + 1 + Login I_D + True + entry_id + + + + 0 + 0 + 1 + 1 + + + + + True + False + 1 + Pass_word + True + right + entry_password + + + + 0 + 2 + 1 + 1 + + + + + + + + + + + + + + + + + False + False + 0 + + + + + True + True + + + 200 + True + True + never + in + + + True + False + none + + + True + False + 6 + 6 + 12 + + + True + True + + + 1 + 2 + 1 + 1 + + + + + True + True + adjustment1 + 1 + + + 1 + 3 + 1 + 1 + + + + + I_gnore SSL certificate errors + True + True + False + False + True + 0 + True + + + 0 + 1 + 2 + 1 + + + + + True + False + 1 + Priori_ty + True + spinbutton_priority + + + 0 + 3 + 1 + 1 + + + + + True + False + 1 + Reso_urce + True + entry_resource + + + 0 + 2 + 1 + 1 + + + + + Encr_yption required (TLS/SSL) + True + True + False + False + True + 0 + True + + + 0 + 0 + 2 + 1 + + + + + True + False + 0 + Override server settings + + + + + + 0 + 4 + 2 + 1 + + + + + True + False + 1 + _Server + True + entry_server + + + 0 + 5 + 1 + 1 + + + + + True + False + 1 + _Port + True + spinbutton_port + + + 0 + 6 + 1 + 1 + + + + + Use old SS_L + True + True + False + False + True + 0 + True + + + 0 + 7 + 2 + 1 + + + + + True + True + + + + 1 + 5 + 1 + 1 + + + + + True + True + + adjustment2 + 1 + True + + + 1 + 6 + 1 + 1 + + + + + + + + + + + True + False + Advanced + + + + + + + + True + True + 1 + + + + + True + False + + + True + False + 0 + What is your Jabber ID? + + + False + True + 0 + + + + + False + 0 + What is your desired Jabber ID? + + + False + True + 1 + + + + + True + False + 12 + 4 + + + True + True + + + True + True + 0 + + + + + True + False + 0.10000000149011612 + <b>Example:</b> user@jabber.org + True + + + + + + True + True + 1 + + + + + False + True + 2 + + + + + True + False + 0 + 6 + What is your Jabber password? + + + False + True + 3 + + + + + False + 0 + 6 + What is your desired Jabber password? + + + False + True + 4 + + + + + True + True + 12 + False + + + False + True + 5 + + + + + Remember Password + True + True + False + False + True + True + + + False + True + 6 + + + + diff --git a/tp-account-widgets/empathy-account-widget-local-xmpp.ui b/tp-account-widgets/empathy-account-widget-local-xmpp.ui new file mode 100644 index 000000000..460c41cbf --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-local-xmpp.ui @@ -0,0 +1,217 @@ + + + + + + True + vertical + 6 + + + True + 12 + 6 + + + True + True + True + + + 1 + 2 + + + + + True + True + True + + + 1 + 1 + + + + + True + True + True + + + 1 + + + + + True + 1 + Nic_kname + True + entry_nickname + + + + 2 + 0 + + + + + True + 1 + _Last Name + True + entry_last_name + + + + 1 + 0 + + + + + True + 1 + _First Name + True + entry_first_name + + + + 0 + + + + + False + False + 0 + + + + + True + True + + + True + 12 + 6 + + + True + True + True + + + 1 + + + + + True + 1 + _Published Name + True + entry_published + + + + 0 + + + + + True + True + True + + + 1 + 2 + + + + + True + True + True + + + 1 + 1 + + + + + True + 1 + _Jabber ID + True + entry_jid + + + + 2 + 0 + + + + + True + 1 + E-_mail address + True + entry_email + + + + 1 + 0 + + + + + + + True + Advanced + + + + + + + + False + False + 1 + + + + + + + + + + + + + + diff --git a/tp-account-widgets/empathy-account-widget-msn.ui b/tp-account-widgets/empathy-account-widget-msn.ui new file mode 100644 index 000000000..4b0614f33 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-msn.ui @@ -0,0 +1,292 @@ + + + + + + 65535 + 1 + 10 + + + True + vertical + 6 + + + True + 12 + 6 + + + True + 1 + Pass_word + True + + + + 2 + + + + + True + 1 + Login I_D + True + entry_id + + + + + + + + True + True + + + 1 + + + + + True + 0 + 3 + <b>Example:</b> user@hotmail.com + True + + + + + + 1 + 1 + + + + + True + True + False + + + 1 + 2 + + + + + Remember password + True + True + False + True + True + + + 1 + 3 + + + + + + + + + + + False + 0 + + + + + True + True + + + True + 6 + 6 + + + True + 1 + _Port + True + spinbutton_port + + + + 1 + + + + + True + 1 + _Server + True + entry_server + + + + 0 + + + + + True + True + + + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + adjustment1 + 1 + True + + + 1 + 1 + + + + + + + True + Advanced + + + + + + + + True + True + 1 + + + + + True + vertical + 6 + + + True + 0 + What is your Windows Live ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + vertical + 4 + + + True + True + + + 0 + + + + + True + 0.10000000149011612 + <b>Example:</b> user@hotmail.com + True + + + + + + 1 + + + + + + + 1 + + + + + True + 0 + What is your Windows Live password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + 3 + + + + + Remember Password + True + True + False + True + True + + + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget-private.h b/tp-account-widgets/empathy-account-widget-private.h new file mode 100644 index 000000000..044e3a991 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-private.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Cosimo Cecchi + */ + +#ifndef __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ +#define __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ + +#include "empathy-account-widget.h" + +G_BEGIN_DECLS + +struct _EmpathyAccountWidgetUIDetails { + GtkBuilder *gui; + + char *default_focus; +}; + + +void empathy_account_widget_handle_params (EmpathyAccountWidget *self, + const gchar *first_widget, + ...); + +void empathy_account_widget_setup_widget (EmpathyAccountWidget *self, + GtkWidget *widget, + const gchar *param_name); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_WIDGET_PRIVATE_H__ */ diff --git a/tp-account-widgets/empathy-account-widget-sip.c b/tp-account-widgets/empathy-account-widget-sip.c new file mode 100644 index 000000000..b76078d5c --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-sip.c @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + * Frederic Peters + */ + +#include "config.h" +#include "empathy-account-widget-sip.h" + +#include + +#include "empathy-account-widget-private.h" +#include "empathy-ui-utils.h" + +typedef struct { + EmpathyAccountWidget *self; + GtkWidget *vbox_settings; + + GtkWidget *label_stun_server; + GtkWidget *entry_stun_server; + GtkWidget *label_stun_port; + GtkWidget *spinbutton_stun_port; + GtkWidget *checkbutton_discover_stun; + GtkWidget *combobox_transport; + GtkWidget *combobox_keep_alive_mechanism; + GtkWidget *spinbutton_keepalive_interval; +} EmpathyAccountWidgetSip; + +static void +account_widget_sip_destroy_cb (GtkWidget *widget, + EmpathyAccountWidgetSip *settings) +{ + g_slice_free (EmpathyAccountWidgetSip, settings); +} + +static void +account_widget_sip_discover_stun_toggled_cb ( + GtkWidget *checkbox, + EmpathyAccountWidgetSip *settings) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)); + gtk_widget_set_sensitive (settings->label_stun_server, !active); + gtk_widget_set_sensitive (settings->entry_stun_server, !active); + gtk_widget_set_sensitive (settings->label_stun_port, !active); + gtk_widget_set_sensitive (settings->spinbutton_stun_port, !active); +} + +static void +keep_alive_mechanism_combobox_change_cb (GtkWidget *widget, + EmpathyAccountWidgetSip *self) +{ + GtkTreeIter iter; + GtkTreeModel *model; + gchar *mechanism; + gboolean enabled; + + /* Unsensitive the keep-alive spin button if keep-alive is disabled */ + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) + return; + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); + gtk_tree_model_get (model, &iter, 0, &mechanism, -1); + + enabled = tp_strdiff (mechanism, "none"); + + gtk_widget_set_sensitive (self->spinbutton_keepalive_interval, enabled); + g_free (mechanism); +} + +static void +checkbutton_tel_toggled ( + GtkWidget *checkbox, + EmpathyAccountWidgetSip *sip_settings) +{ + EmpathyAccountSettings *settings; + + settings = empathy_account_widget_get_settings (sip_settings->self); + + empathy_account_settings_set_uri_scheme_tel (settings, + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))); + + empathy_account_widget_changed (sip_settings->self); +} + +GtkWidget * +empathy_account_widget_sip_build (EmpathyAccountWidget *self, + const char *filename, + GtkWidget **grid_common_settings) +{ + EmpathyAccountWidgetSip *settings; + GtkWidget *vbox_settings; + gboolean is_simple; + GtkWidget *grid_advanced; + + g_object_get (self, "simple", &is_simple, NULL); + + if (is_simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_sip_simple", &vbox_settings, + NULL); + + empathy_account_widget_handle_params (self, + "entry_userid_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_userid_simple"); + } + else + { + GtkListStore *store; + GtkCellRenderer *renderer; + GtkToggleButton *checkbutton_tel; + + settings = g_slice_new0 (EmpathyAccountWidgetSip); + settings->self = self; + + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", grid_common_settings, + "grid_advanced_sip_settings", &grid_advanced, + "vbox_sip_settings", &vbox_settings, + "label_stun-server", &settings->label_stun_server, + "entry_stun-server", &settings->entry_stun_server, + "label_stun-port", &settings->label_stun_port, + "spinbutton_stun-port", &settings->spinbutton_stun_port, + "checkbutton_discover-stun", &settings->checkbutton_discover_stun, + "spinbutton_keepalive-interval", + &settings->spinbutton_keepalive_interval, + "checkbutton_tel", &checkbutton_tel, + NULL); + settings->vbox_settings = vbox_settings; + + gtk_toggle_button_set_active (checkbutton_tel, + empathy_account_settings_has_uri_scheme_tel ( + empathy_account_widget_get_settings (self))); + + empathy_account_widget_handle_params (self, + "entry_userid", "account", + "entry_password", "password", + "checkbutton_discover-stun", "discover-stun", + "entry_stun-server", "stun-server", + "spinbutton_stun-port", "stun-port", + "entry_auth-user", "auth-user", + "entry_proxy-host", "proxy-host", + "spinbutton_port", "port", + "checkbutton_loose-routing", "loose-routing", + "checkbutton_discover-binding", "discover-binding", + "spinbutton_keepalive-interval", "keepalive-interval", + "checkbutton_ignore-tls-errors", "ignore-tls-errors", + "entry_local-ip-address", "local-ip-address", + "spinbutton_local-port", "local-port", + NULL); + + account_widget_sip_discover_stun_toggled_cb ( + settings->checkbutton_discover_stun, + settings); + + empathy_builder_connect (self->ui_details->gui, settings, + "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, + "checkbutton_discover-stun", "toggled", + account_widget_sip_discover_stun_toggled_cb, + "checkbutton_tel", "toggled", checkbutton_tel_toggled, + NULL); + + self->ui_details->default_focus = g_strdup ("entry_userid"); + + /* Create the 'transport' combo box. The first column has to contain the + * value of the param. */ + store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); + settings->combobox_transport = gtk_combo_box_new_with_model ( + GTK_TREE_MODEL (store)); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start ( + GTK_CELL_LAYOUT (settings->combobox_transport), renderer, TRUE); + gtk_cell_layout_add_attribute ( + GTK_CELL_LAYOUT (settings->combobox_transport), renderer, "text", 1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "auto", 1, _("Auto"), -1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "udp", 1, _("UDP"), -1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "tcp", 1, _("TCP"), -1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "tls", 1, _("TLS"), -1); + + empathy_account_widget_setup_widget (self, settings->combobox_transport, + "transport"); + + gtk_grid_attach (GTK_GRID (grid_advanced), settings->combobox_transport, + 1, 11, 3, 1); + + gtk_widget_show (settings->combobox_transport); + + /* Create the 'keep-alive mechanism' combo box */ + store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); + settings->combobox_keep_alive_mechanism = gtk_combo_box_new_with_model ( + GTK_TREE_MODEL (store)); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start ( + GTK_CELL_LAYOUT (settings->combobox_keep_alive_mechanism), renderer, + TRUE); + gtk_cell_layout_add_attribute ( + GTK_CELL_LAYOUT (settings->combobox_keep_alive_mechanism), renderer, + "text", 1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "auto", 1, _("Auto"), -1); + + /* translators: this string is very specific to SIP's internal; maybe + * best to keep the English version. */ + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "register", 1, _("Register"), -1); + + /* translators: this string is very specific to SIP's internal; maybe + * best to keep the English version. */ + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "options", 1, _("Options"), -1); + + gtk_list_store_insert_with_values (store, NULL, -1, + 0, "none", 1, _("None"), -1); + + g_signal_connect (settings->combobox_keep_alive_mechanism, "changed", + G_CALLBACK (keep_alive_mechanism_combobox_change_cb), settings); + + empathy_account_widget_setup_widget (self, + settings->combobox_keep_alive_mechanism, "keepalive-mechanism"); + + gtk_grid_attach (GTK_GRID (grid_advanced), + settings->combobox_keep_alive_mechanism, + 1, 7, 3, 1); + + gtk_widget_show (settings->combobox_keep_alive_mechanism); + } + + return vbox_settings; +} diff --git a/tp-account-widgets/empathy-account-widget-sip.h b/tp-account-widgets/empathy-account-widget-sip.h new file mode 100644 index 000000000..4fed35ec9 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-sip.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Frederic Peters + */ + +#ifndef __EMPATHY_ACCOUNT_WIDGET_SIP_H__ +#define __EMPATHY_ACCOUNT_WIDGET_SIP_H__ + +#include "empathy-account-widget.h" + +G_BEGIN_DECLS + +GtkWidget * empathy_account_widget_sip_build (EmpathyAccountWidget *self, + const char *filename, + GtkWidget **grid_common_settings); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_WIDGET_SIP_H__ */ diff --git a/tp-account-widgets/empathy-account-widget-sip.ui b/tp-account-widgets/empathy-account-widget-sip.ui new file mode 100644 index 000000000..7caa7cad6 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-sip.ui @@ -0,0 +1,731 @@ + + + + + 65535 + 1 + 10 + + + 65535 + 1 + 10 + + + 10000 + 1 + 10 + + + 65535 + 1 + 10 + + + True + False + + + True + False + 12 + 6 + + + True + False + 1 + Pass_word + True + entry_password + + + + 2 + + + + + True + True + + + 1 + + + + + True + False + 1 + _Username + True + entry_userid + + + + 0 + + + + + True + False + 0 + 3 + <b>Example:</b> user@my.sip.server + True + + + + + + 1 + 1 + + + + + True + True + + + 1 + 2 + + + + + Remember password + True + True + False + False + True + True + + + 1 + 3 + + + + + Use this account to call _landlines and mobile phones + True + True + False + False + True + 0 + True + + + 4 + 0 + 4 + + + + + + + + + + + False + False + 0 + + + + + True + True + + + 200 + True + True + never + in + + + True + False + queue + none + + + True + False + 0 + 6 + + + True + False + 6 + 6 + + + True + True + + + 1 + 2 + + + + + True + True + + + 1 + 10 + 3 + + + + + True + True + + + 1 + 5 + + + + + True + True + adjustment3 + + + 1 + 8 + 3 + + + + + True + True + + + 1 + 14 + + + + + True + False + 0 + NAT Traversal Options + + + + + + + + + + True + False + 0 + Proxy Options + + + + + + 4 + 0 + + + + + True + False + 0 + Miscellaneous Options + + + + + + 9 + 0 + + + + + True + False + 24 + + + True + False + 0 + STUN Server + entry_stun-server + + + + + 2 + 0 + + + + + True + False + 12 + + + Discover the STUN server automatically + True + True + False + False + True + True + + + + + 1 + 0 + 4 + + + + + True + False + 12 + + + Discover Binding + True + True + False + False + True + + + + + 3 + 0 + 4 + + + + + True + False + 12 + + + True + False + 0 + Server + + + + + 5 + 0 + + + + + True + False + 0 + Keep-Alive Options + + + + + + 6 + 0 + + + + + True + False + 12 + + + True + False + 0 + Mechanism + + + + + 7 + 0 + + + + + True + False + 12 + + + True + False + 0 + Interval (seconds) + + + + + 8 + 0 + + + + + True + False + 12 + + + True + False + 0 + Authentication username + + + + + 10 + 0 + + + + + True + False + 12 + + + True + False + 0 + Transport + + + + + 11 + 0 + + + + + True + False + 12 + + + Loose Routing + True + True + False + False + True + + + + + 12 + 0 + 4 + + + + + True + False + 12 + + + Ignore TLS Errors + True + True + False + False + True + + + + + 13 + 0 + 4 + + + + + True + False + 0 + Port + spinbutton_stun-port + + + 2 + 2 + + + + + True + True + adjustment1 + 1 + + + 3 + 2 + + + + + True + False + 0 + Port + + + 2 + 5 + + + + + True + True + adjustment2 + 1 + + + 3 + 5 + + + + + True + False + 12 + + + True + False + 0 + Local IP Address + entry_local-ip-address + + + + + 0 + 14 + + + + + True + False + 0 + Port + spinbutton_local-port + + + 2 + 14 + + + + + True + True + adjustment4 + + + 3 + 14 + + + + + + + + + + + + + True + False + Advanced + + + + + + + + True + True + 1 + + + + + True + False + 6 + + + True + False + 0 + What is your SIP login ID? + + + True + True + 0 + + + + + True + False + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + False + 4 + + + True + True + + + True + True + 0 + + + + + True + False + 0.10000000149011612 + <b>Example:</b> user@my.sip.server + True + + + + + + True + True + 1 + + + + + + + True + True + 1 + + + + + True + False + 0 + What is your SIP account password? + + + True + True + 2 + + + + + True + False + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + True + True + 3 + + + + + Remember Password + True + True + False + False + True + True + + + True + True + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget-yahoo.ui b/tp-account-widgets/empathy-account-widget-yahoo.ui new file mode 100644 index 000000000..9d002538c --- /dev/null +++ b/tp-account-widgets/empathy-account-widget-yahoo.ui @@ -0,0 +1,330 @@ + + + + + + 5050 + 1 + 65555 + 1 + 10 + + + True + vertical + 6 + + + True + 12 + 6 + + + True + 0 + Pass_word: + True + entry_password + + + 2 + + + + + True + 0 + Yahoo! I_D: + True + entry_id + + + + + + + True + True + + + 1 + + + + + True + True + False + + + 1 + 2 + + + + + True + 0 + 3 + <b>Example:</b> username + True + + + + + + 1 + 1 + + + + + Remember password + True + True + False + True + True + + + 1 + 3 + + + + + + + + + + + False + False + 0 + + + + + True + True + + + True + + + True + 12 + 6 + + + I_gnore conference and chat room invitations + True + True + False + True + True + + + 2 + + + + + True + 0 + _Room List locale: + True + entry_locale + + + 1 + 0 + + + + + True + 0 + Ch_aracter set: + True + entry_charset + + + 2 + 0 + + + + + True + True + + + 1 + 1 + + + + + True + True + + + 1 + 2 + + + + + True + 0 + _Port: + True + spinbutton_port + + + 3 + 0 + + + + + True + True + adjustment1 + 1 + True + + + 1 + 3 + + + + + 0 + + + + + + + True + Advanced + + + + + + + + True + True + 1 + + + + + True + vertical + 6 + + + True + 0 + What is your Yahoo! ID? + + + 0 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 3 + 12 + + + True + vertical + 4 + + + True + True + + + 0 + + + + + True + 0.10000000149011612 + <b>Example:</b> username + True + + + + + + 1 + + + + + + + 1 + + + + + True + 0 + What is your Yahoo! password? + + + 2 + + + + + True + 0 + 0 + 0.34999999403953552 + 0.34999999403953552 + 12 + + + True + True + False + + + + + 3 + + + + + Remember password + True + True + False + True + True + + + 4 + + + + diff --git a/tp-account-widgets/empathy-account-widget.c b/tp-account-widgets/empathy-account-widget.c new file mode 100644 index 000000000..0751b24a4 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget.c @@ -0,0 +1,2331 @@ +/* + * Copyright (C) 2006-2007 Imendio AB + * Copyright (C) 2007-2009 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Martyn Russell + * Cosimo Cecchi + * Jonathan Tellier + * Danielle Madeley + */ + +#include "config.h" +#include "empathy-account-widget.h" +#include "empathy-account-widget-private.h" + +#include +#include + +#include "empathy-account-widget-irc.h" +#include "empathy-account-widget-private.h" +#include "empathy-account-widget-sip.h" +#include "empathy-ui-utils.h" +#include "empathy-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT +#include "empathy-debug.h" + +G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, GTK_TYPE_BOX) + +typedef enum +{ + NO_SERVICE = 0, + GTALK_SERVICE, + FACEBOOK_SERVICE, + N_SERVICES +} Service; + +typedef struct +{ + const gchar *label_username_example; + gboolean show_advanced; +} ServiceInfo; + +static ServiceInfo services_infos[N_SERVICES] = { + { "label_username_example", TRUE }, + { "label_username_g_example", FALSE }, + { "label_username_f_example", FALSE }, +}; + +struct _EmpathyAccountWidgetPriv { + EmpathyAccountSettings *settings; + + GtkWidget *grid_common_settings; + GtkWidget *apply_button; + GtkWidget *cancel_button; + GtkWidget *entry_password; + GtkWidget *spinbutton_port; + GtkWidget *radiobutton_reuse; + GtkWidget *hbox_buttons; + + gboolean simple; + + gboolean contains_pending_changes; + + /* 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; + + /* 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; + + gboolean automatic_change; + GtkWidget *remember_password_widget; + + /* Used only for IRC accounts */ + EmpathyIrcNetworkChooser *irc_network_chooser; + + /* Used for 'special' XMPP account having a service associated ensuring that + * JIDs have a specific suffix; such as Facebook for example */ + gchar *jid_suffix; +}; + +enum { + PROP_PROTOCOL = 1, + PROP_SETTINGS, + PROP_SIMPLE, + PROP_CREATING_ACCOUNT, + PROP_OTHER_ACCOUNTS_EXIST, +}; + +enum { + HANDLE_APPLY, + ACCOUNT_CREATED, + CANCELLED, + CLOSE, + LAST_SIGNAL +}; + +enum { + RESPONSE_LAUNCH +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +#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 minimum according to http://en.wikipedia.org/wiki/ICQ#UIN + * According to an user, we can also provide an email address instead of the + * ICQ UIN. */ +#define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")" + +/* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */ +#define IRC_SPECIAL "_\\[\\]{}\\\\|`^" +#define IRC_NICK_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 + * Looks like an email address can be used as well (bgo #655959) + * */ +#define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")" + +#define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$" +#define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$" +#define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@[^@/]+" +#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) +{ + /* we hit this case because of the 'other-accounts-exist' property handler + * being called during init (before constructed()) */ + if (self->priv->apply_button == NULL || self->priv->cancel_button == NULL) + return; + + gtk_widget_set_sensitive (self->priv->apply_button, sensitive); + + if (sensitive) + { + /* We can't grab default if the widget hasn't be packed in a + * window */ + GtkWidget *window; + + window = gtk_widget_get_toplevel (self->priv->apply_button); + if (window != NULL && + gtk_widget_is_toplevel (window)) + { + gtk_widget_set_can_default (self->priv->apply_button, TRUE); + gtk_widget_grab_default (self->priv->apply_button); + } + } +} + +static void +account_widget_set_entry_highlighting (GtkEntry *entry, + gboolean highlight) +{ + g_return_if_fail (GTK_IS_ENTRY (entry)); + + if (highlight) + { + GtkStyleContext *style; + GdkRGBA color; + + style = gtk_widget_get_style_context (GTK_WIDGET (entry)); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, + &color); + + /* 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. + */ + empathy_make_color_whiter (&color); + + gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color); + } + else + { + gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL); + } +} + +static void +account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self) +{ + gboolean is_valid; + + is_valid = empathy_account_settings_is_valid (self->priv->settings); + + account_widget_set_control_buttons_sensitivity (self, is_valid); + + g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid); +} + +static void +account_widget_entry_changed_common (EmpathyAccountWidget *self, + GtkEntry *entry, gboolean focus) +{ + const gchar *str; + const gchar *param_name; + 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 ( + self->priv->settings, param_name); + + if (EMP_STR_EMPTY (str)) + { + empathy_account_settings_unset (self->priv->settings, param_name); + + if (focus) + { + gchar *value; + + value = empathy_account_settings_dup_string (self->priv->settings, + param_name); + + DEBUG ("Unset %s and restore to %s", param_name, value); + gtk_entry_set_text (entry, value ? value : ""); + g_free (value); + } + } + else + { + DEBUG ("Setting %s to %s", param_name, + tp_strdiff (param_name, "password") ? str : "***"); + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_string (str)); + } + + curr_status = empathy_account_settings_parameter_is_valid ( + self->priv->settings, param_name); + + if (curr_status != prev_status) + account_widget_set_entry_highlighting (entry, !curr_status); +} + +static void +account_widget_entry_changed_cb (GtkEditable *entry, + EmpathyAccountWidget *self) +{ + if (self->priv->automatic_change) + return; + + account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); + empathy_account_widget_changed (self); +} + +static void +account_widget_entry_map_cb (GtkEntry *entry, + EmpathyAccountWidget *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 (self->priv->settings, + param_name); + account_widget_set_entry_highlighting (entry, !is_valid); +} + +static void +account_widget_int_changed_cb (GtkWidget *widget, + EmpathyAccountWidget *self) +{ + const gchar *param_name; + gint value; + const gchar *signature; + + value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); + param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + + signature = empathy_account_settings_get_dbus_signature (self->priv->settings, + param_name); + g_return_if_fail (signature != NULL); + + DEBUG ("Setting %s to %d", param_name, value); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_int32 (value)); + break; + case DBUS_TYPE_INT64: + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_int64 (value)); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_uint32 (value)); + break; + case DBUS_TYPE_UINT64: + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_uint64 (value)); + break; + default: + g_return_if_reached (); + } + + empathy_account_widget_changed (self); +} + +static void +account_widget_checkbutton_toggled_cb (GtkWidget *widget, + EmpathyAccountWidget *self) +{ + gboolean value; + gboolean default_value; + const gchar *param_name; + + value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + param_name = g_object_get_data (G_OBJECT (widget), "param_name"); + + /* FIXME: This is ugly! checkbox don't have a "not-set" value so we + * always unset the param and set the value if different from the + * default value. */ + empathy_account_settings_unset (self->priv->settings, param_name); + default_value = empathy_account_settings_get_boolean (self->priv->settings, + param_name); + + if (default_value == value) + { + DEBUG ("Unset %s and restore to %d", param_name, default_value); + } + else + { + DEBUG ("Setting %s to %d", param_name, value); + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_boolean (value)); + } + + empathy_account_widget_changed (self); +} + +static void +account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, + EmpathyAccountWidget *self) +{ + gboolean value; + gint32 port = 0; + + value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); + port = empathy_account_settings_get_uint32 (self->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 (self->priv->spinbutton_port), + port); + + self->priv->contains_pending_changes = TRUE; +} + +static void +account_widget_combobox_changed_cb (GtkWidget *widget, + EmpathyAccountWidget *self) +{ + GtkTreeIter iter; + GtkTreeModel *model; + const gchar *value; + GVariant *v; + const gchar *default_value = NULL; + const gchar *param_name; + + 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_dup_default (self->priv->settings, param_name); + if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) + default_value = g_variant_get_string (v, NULL); + + if (!tp_strdiff (value, default_value)) + { + DEBUG ("Unset %s and restore to %s", param_name, default_value); + empathy_account_settings_unset (self->priv->settings, param_name); + } + else + { + DEBUG ("Setting %s to %s", param_name, value); + empathy_account_settings_set (self->priv->settings, param_name, + g_variant_new_string (value)); + } + + empathy_account_widget_changed (self); + + tp_clear_pointer (&v, g_variant_unref); +} + +static void +clear_icon_released_cb (GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + EmpathyAccountWidget *self) +{ + const gchar *param_name; + + param_name = g_object_get_data (G_OBJECT (entry), "param_name"); + + DEBUG ("Unset %s", param_name); + empathy_account_settings_unset (self->priv->settings, param_name); + gtk_entry_set_text (entry, ""); + + empathy_account_widget_changed (self); +} + +static void +password_entry_changed_cb (GtkEditable *entry, + EmpathyAccountWidget *self) +{ + const gchar *str; + + str = gtk_entry_get_text (GTK_ENTRY (entry)); + + gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), + GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str)); +} + +static void +password_entry_activated_cb (GtkEntry *entry, + EmpathyAccountWidget *self) +{ + if (gtk_widget_get_sensitive (self->priv->apply_button)) + empathy_account_widget_apply_and_log_in (self); +} + +static void +account_entry_activated_cb (GtkEntry *entry, + EmpathyAccountWidget *self) +{ + if (gtk_widget_get_sensitive (self->priv->apply_button)) + empathy_account_widget_apply_and_log_in (self); +} + +void +empathy_account_widget_setup_widget (EmpathyAccountWidget *self, + GtkWidget *widget, + const gchar *param_name) +{ + g_object_set_data_full (G_OBJECT (widget), "param_name", + g_strdup (param_name), g_free); + + if (GTK_IS_SPIN_BUTTON (widget)) + { + gint value = 0; + const gchar *signature; + + signature = empathy_account_settings_get_dbus_signature ( + self->priv->settings, param_name); + g_return_if_fail (signature != NULL); + + switch ((int)*signature) + { + case DBUS_TYPE_INT16: + case DBUS_TYPE_INT32: + value = empathy_account_settings_get_int32 (self->priv->settings, + param_name); + break; + case DBUS_TYPE_INT64: + value = empathy_account_settings_get_int64 (self->priv->settings, + param_name); + break; + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + value = empathy_account_settings_get_uint32 (self->priv->settings, + param_name); + break; + case DBUS_TYPE_UINT64: + value = empathy_account_settings_get_uint64 (self->priv->settings, + param_name); + break; + default: + g_return_if_reached (); + } + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); + + g_signal_connect (widget, "value-changed", + G_CALLBACK (account_widget_int_changed_cb), + self); + } + else if (GTK_IS_ENTRY (widget)) + { + gchar *str; + + str = empathy_account_settings_dup_string (self->priv->settings, + param_name); + gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); + + if (!tp_strdiff (param_name, "account")) + self->priv->param_account_widget = widget; + else if (!tp_strdiff (param_name, "password")) + self->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); + + g_free (str); + } + else if (GTK_IS_TOGGLE_BUTTON (widget)) + { + gboolean value = FALSE; + + value = empathy_account_settings_get_boolean (self->priv->settings, + param_name); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); + + g_signal_connect (widget, "toggled", + 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) */ + gchar *str; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean valid; + + str = empathy_account_settings_dup_string (self->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_free (str); + + g_signal_connect (widget, "changed", + G_CALLBACK (account_widget_combobox_changed_cb), + self); + } + else + { + DEBUG ("Unknown type of widget for param %s", param_name); + } + + gtk_widget_set_sensitive (widget, + empathy_account_settings_param_is_supported (self->priv->settings, + 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; + + g_return_val_if_fail (param_name != NULL, 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); + + if (str && g_ascii_isalpha (str[0])) + str[0] = g_ascii_toupper (str[0]); + + while ((p = strchr (str, '-')) != NULL) + { + if (p[1] != '\0' && g_ascii_isalpha (p[1])) + { + p[0] = ' '; + p[1] = g_ascii_toupper (p[1]); + } + + p++; + } + + return str; +} + +static void +accounts_widget_generic_setup (EmpathyAccountWidget *self, + GtkWidget *grid_common_settings, + GtkWidget *grid_advanced_settings) +{ + GList *params, *l; + guint row_common = 0, row_advanced = 0; + + params = empathy_account_settings_dup_tp_params (self->priv->settings); + + for (l = params; l != NULL; l = g_list_next (l)) + { + TpConnectionManagerParam *param = l->data; + GtkWidget *grid_settings; + guint row; + GtkWidget *widget = NULL; + gchar *param_name_formatted; + const gchar *dbus_signature; + + if (tp_connection_manager_param_is_required (param)) + { + grid_settings = grid_common_settings; + row = row_common++; + } + else if (self->priv->simple) + { + continue; + } + else + { + grid_settings = grid_advanced_settings; + row = row_advanced++; + } + + param_name_formatted = account_widget_generic_format_param_name ( + tp_connection_manager_param_get_name (param)); + + dbus_signature = tp_connection_manager_param_get_dbus_signature (param); + + if (dbus_signature[0] == 's') + { + gchar *str; + + str = g_strdup_printf (_("%s"), param_name_formatted); + widget = gtk_label_new (str); + gtk_misc_set_alignment (GTK_MISC (widget), 1., 0.5); + gtk_style_context_add_class (gtk_widget_get_style_context (widget), + GTK_STYLE_CLASS_DIM_LABEL); + g_free (str); + + gtk_grid_attach (GTK_GRID (grid_settings), + widget, 0, row, 1, 1); + + gtk_widget_show (widget); + + widget = gtk_entry_new (); + if (strcmp (tp_connection_manager_param_get_name (param), + "account") == 0) + { + g_signal_connect (widget, "realize", + G_CALLBACK (gtk_widget_grab_focus), + NULL); + } + + gtk_grid_attach (GTK_GRID (grid_settings), + widget, 1, row, 1, 1); + + gtk_widget_show (widget); + } + /* int types: ynqiuxt. double type is 'd' */ + else if (dbus_signature[0] == 'y' || + dbus_signature[0] == 'n' || + dbus_signature[0] == 'q' || + dbus_signature[0] == 'i' || + dbus_signature[0] == 'u' || + dbus_signature[0] == 'x' || + dbus_signature[0] == 't' || + dbus_signature[0] == 'd') + { + gchar *str = NULL; + gdouble minint = 0; + gdouble maxint = 0; + gdouble step = 1; + + switch (dbus_signature[0]) + { + case 'y': minint = G_MININT8; maxint = G_MAXINT8; break; + case 'n': minint = G_MININT16; maxint = G_MAXINT16; break; + case 'q': minint = 0; maxint = G_MAXUINT16; break; + case 'i': minint = G_MININT32; maxint = G_MAXINT32; break; + case 'u': minint = 0; maxint = G_MAXUINT32; break; + case 'x': minint = G_MININT64; maxint = G_MAXINT64; break; + 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); + widget = gtk_label_new (str); + gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5); + g_free (str); + + gtk_grid_attach (GTK_GRID (grid_settings), + widget, 0, row, 1, 1); + gtk_widget_show (widget); + + widget = gtk_spin_button_new_with_range (minint, maxint, step); + gtk_grid_attach (GTK_GRID (grid_settings), + widget, 1, row, 1, 1); + gtk_widget_show (widget); + } + else if (dbus_signature[0] == 'b') + { + widget = gtk_check_button_new_with_label (param_name_formatted); + gtk_grid_attach (GTK_GRID (grid_settings), + widget, 0, row, 2, 1); + gtk_widget_show (widget); + } + else + { + DEBUG ("Unknown signature for param %s: %s", + param_name_formatted, dbus_signature); + } + + if (widget) + empathy_account_widget_setup_widget (self, widget, + tp_connection_manager_param_get_name (param)); + + g_free (param_name_formatted); + } + + g_list_free_full (params, (GDestroyNotify) tp_connection_manager_param_free); +} + +static void +account_widget_handle_params_valist (EmpathyAccountWidget *self, + const gchar *first_widget, + va_list args) +{ + GObject *object; + const gchar *name; + + for (name = first_widget; name; name = va_arg (args, const gchar *)) + { + const gchar *param_name; + + param_name = va_arg (args, const gchar *); + object = gtk_builder_get_object (self->ui_details->gui, name); + + if (!object) + { + g_warning ("Builder is missing object '%s'.", name); + continue; + } + + empathy_account_widget_setup_widget (self, GTK_WIDGET (object), + param_name); + } +} + +static void +account_widget_cancel_clicked_cb (GtkWidget *button, + EmpathyAccountWidget *self) +{ + g_signal_emit (self, signals[CANCELLED], 0); + g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_CANCEL); +} + +static void +account_widget_account_enabled_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + TpAccount *account = TP_ACCOUNT (source_object); + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data); + + tp_account_set_enabled_finish (account, res, &error); + + if (error != NULL) + { + DEBUG ("Could not enable the account: %s", error->message); + g_error_free (error); + } + else + { + empathy_connect_new_account (account, self->priv->account_manager); + } + + g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY); + + /* unref self - part of the workaround */ + g_object_unref (self); +} + +static void +account_widget_applied_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + TpAccount *account; + EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object); + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data); + gboolean reconnect_required; + gboolean fire_close = TRUE; + + empathy_account_settings_apply_finish (settings, res, &reconnect_required, + &error); + + if (error != NULL) + { + DEBUG ("Could not apply changes to account: %s", error->message); + g_error_free (error); + return; + } + + account = empathy_account_settings_get_account (self->priv->settings); + + if (account != NULL) + { + if (self->priv->creating_account) + { + /* By default, when an account is created, we enable it. */ + + /* workaround to keep self alive during async call */ + g_object_ref (self); + + tp_account_set_enabled_async (account, TRUE, + account_widget_account_enabled_cb, self); + g_signal_emit (self, signals[ACCOUNT_CREATED], 0, account); + + /* Will be fired in account_widget_account_enabled_cb */ + fire_close = FALSE; + } + else + { + /* If the account was offline, we always want to try reconnecting, + * to give it a chance to connect if the previous params were wrong. + * tp_account_reconnect_async() won't do anything if the requested + * presence is offline anyway. */ + if (tp_account_get_connection_status (account, NULL) == + TP_CONNECTION_STATUS_DISCONNECTED) + reconnect_required = TRUE; + + if (reconnect_required && tp_account_is_enabled (account) + && tp_account_is_enabled (account)) + { + /* After having applied changes to a user account, we + * reconnect it if needed. This is done so the new + * information entered by the user is validated on the server. */ + tp_account_reconnect_async (account, NULL, NULL); + } + } + } + + if (!self->priv->destroyed) + account_widget_set_control_buttons_sensitivity (self, FALSE); + + self->priv->contains_pending_changes = FALSE; + + if (fire_close) + { + /* announce the widget can be closed */ + g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY); + } + + /* unref the widget - part of the workaround */ + g_object_unref (self); +} + +void +empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self) +{ + gboolean display_name_overridden; + + if (self->priv->radiobutton_reuse != NULL) + { + gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ( + self->priv->radiobutton_reuse)); + + DEBUG ("Set register param: %d", !reuse); + empathy_account_settings_set (self->priv->settings, "register", + g_variant_new_boolean (!reuse)); + } + + g_object_get (self->priv->settings, + "display-name-overridden", &display_name_overridden, NULL); + + if (self->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 (self->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 (self->priv->settings, + account_widget_applied_cb, self); +} + +static void +account_widget_apply_clicked_cb (GtkWidget *button, + EmpathyAccountWidget *self) +{ + empathy_account_widget_apply_and_log_in (self); +} + +static void +account_widget_setup_generic (EmpathyAccountWidget *self) +{ + GtkWidget *grid_common_settings; + GtkWidget *grid_advanced_settings; + + grid_common_settings = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "grid_common_settings")); + grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object + (self->ui_details->gui, "grid_advanced_settings")); + + accounts_widget_generic_setup (self, grid_common_settings, + grid_advanced_settings); + + g_object_unref (self->ui_details->gui); +} + +static void +account_widget_settings_ready_cb (EmpathyAccountSettings *settings, + GParamSpec *pspec, + gpointer user_data) +{ + EmpathyAccountWidget *self = user_data; + + if (empathy_account_settings_is_ready (self->priv->settings)) + account_widget_setup_generic (self); +} + +static GtkWidget * +account_widget_build_generic (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *expander_advanced, *box; + + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_generic_settings", &box, + "expander_advanced_settings", &expander_advanced, + NULL); + + if (self->priv->simple) + gtk_widget_hide (expander_advanced); + + g_object_ref (self->ui_details->gui); + + if (empathy_account_settings_is_ready (self->priv->settings)) + account_widget_setup_generic (self); + else + g_signal_connect (self->priv->settings, "notify::ready", + G_CALLBACK (account_widget_settings_ready_cb), self); + + return box; +} + +static GtkWidget * +account_widget_build_salut (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *expander_advanced, *box; + + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_salut_settings", &box, + "expander_advanced_settings", &expander_advanced, + NULL); + + empathy_account_widget_handle_params (self, + "entry_published", "published-name", + "entry_nickname", "nickname", + "entry_first_name", "first-name", + "entry_last_name", "last-name", + "entry_email", "email", + "entry_jid", "jid", + NULL); + + if (self->priv->simple) + gtk_widget_hide (expander_advanced); + + self->ui_details->default_focus = g_strdup ("entry_first_name"); + + return box; +} + +static GtkWidget * +account_widget_build_irc (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *box; + + empathy_account_settings_set_regex (self->priv->settings, "account", + ACCOUNT_REGEX_IRC); + + if (self->priv->simple) + { + self->priv->irc_network_chooser = empathy_account_widget_irc_build_simple + (self, filename, &box); + } + else + { + self->priv->irc_network_chooser = empathy_account_widget_irc_build (self, + filename, &self->priv->grid_common_settings, &box); + } + + return box; +} + +static GtkWidget * +account_widget_build_sip (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *box; + + box = empathy_account_widget_sip_build (self, filename, + &self->priv->grid_common_settings); + + if (self->priv->simple) + { + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +static GtkWidget * +account_widget_build_msn (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *box; + + empathy_account_settings_set_regex (self->priv->settings, "account", + ACCOUNT_REGEX_MSN); + + if (self->priv->simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_msn_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_msn_settings", &self->priv->grid_common_settings, + "vbox_msn_settings", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +static void +suffix_id_widget_changed_cb (GtkWidget *entry, + EmpathyAccountWidget *self) +{ + gchar *account; + + g_assert (self->priv->jid_suffix != NULL); + + account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); + + account = empathy_account_settings_dup_string (self->priv->settings, + "account"); + + if (!EMP_STR_EMPTY (account) && + !g_str_has_suffix (account, self->priv->jid_suffix)) + { + gchar *tmp; + + tmp = g_strdup_printf ("%s%s", account, self->priv->jid_suffix); + + DEBUG ("Change account from '%s' to '%s'", account, tmp); + + empathy_account_settings_set (self->priv->settings, "account", + g_variant_new_string (tmp)); + g_free (tmp); + } + + empathy_account_widget_changed (self); + + g_free (account); +} + +static gchar * +remove_jid_suffix (EmpathyAccountWidget *self, + const gchar *str) +{ + g_assert (self->priv->jid_suffix != NULL); + + if (!g_str_has_suffix (str, self->priv->jid_suffix)) + return g_strdup (str); + + return g_strndup (str, strlen (str) - strlen (self->priv->jid_suffix)); +} + +static void +setup_id_widget_with_suffix (EmpathyAccountWidget *self, + GtkWidget *widget, + const gchar *suffix) +{ + gchar *str = NULL; + + g_object_set_data_full (G_OBJECT (widget), "param_name", + g_strdup ("account"), g_free); + + g_assert (self->priv->jid_suffix == NULL); + self->priv->jid_suffix = g_strdup (suffix); + + str = empathy_account_settings_dup_string (self->priv->settings, "account"); + if (str != NULL) + { + gchar *tmp; + + tmp = remove_jid_suffix (self, str); + gtk_entry_set_text (GTK_ENTRY (widget), tmp); + g_free (tmp); + g_free (str); + } + + self->priv->param_account_widget = widget; + + g_signal_connect (widget, "changed", + G_CALLBACK (suffix_id_widget_changed_cb), self); +} + +static Service +account_widget_get_service (EmpathyAccountWidget *self) +{ + const gchar *icon_name, *service; + + icon_name = empathy_account_settings_get_icon_name (self->priv->settings); + service = empathy_account_settings_get_service (self->priv->settings); + + /* Previous versions of Empathy didn't set the Service property on Facebook + * and gtalk accounts, so we check using the icon name as well. */ + if (!tp_strdiff (icon_name, "im-google-talk") || + !tp_strdiff (service, "google-talk")) + return GTALK_SERVICE; + + if (!tp_strdiff (icon_name, "im-facebook") || + !tp_strdiff (service, "facebook")) + return FACEBOOK_SERVICE; + + return NO_SERVICE; +} + +static GtkWidget * +account_widget_build_jabber (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *spinbutton_port; + GtkWidget *checkbutton_ssl; + GtkWidget *label_id, *label_password; + GtkWidget *label_id_create, *label_password_create; + GtkWidget *label_example_fb; + GtkWidget *label_example; + GtkWidget *expander_advanced; + GtkWidget *entry_id; + GtkWidget *box; + Service service; + + service = account_widget_get_service (self); + + empathy_account_settings_set_regex (self->priv->settings, "account", + ACCOUNT_REGEX_JABBER); + + if (self->priv->simple && service == NO_SERVICE) + { + /* Simple widget for XMPP */ + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_jabber_simple", &box, + "label_id_simple", &label_id, + "label_id_create", &label_id_create, + "label_password_simple", &label_password, + "label_password_create", &label_password_create, + NULL); + + if (empathy_account_settings_get_boolean (self->priv->settings, + "register")) + { + gtk_widget_hide (label_id); + gtk_widget_hide (label_password); + gtk_widget_show (label_id_create); + gtk_widget_show (label_password_create); + } + + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else if (self->priv->simple && service == GTALK_SERVICE) + { + /* Simple widget for Google Talk */ + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_gtalk_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id_g_simple", "account", + "entry_password_g_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_g_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_g_simple")); + } + else if (self->priv->simple && service == FACEBOOK_SERVICE) + { + /* Simple widget for Facebook */ + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_fb_simple", &box, + "entry_id_fb_simple", &entry_id, + NULL); + + empathy_account_widget_handle_params (self, + "entry_password_fb_simple", "password", + NULL); + + setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com"); + + self->ui_details->default_focus = g_strdup ("entry_id_fb_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_fb_simple")); + } + else + { + ServiceInfo info = services_infos[service]; + + /* Full widget for XMPP, Google Talk and Facebook*/ + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_jabber_settings", &box, + "spinbutton_port", &spinbutton_port, + "checkbutton_ssl", &checkbutton_ssl, + "label_username_f_example", &label_example_fb, + info.label_username_example, &label_example, + "expander_advanced", &expander_advanced, + "entry_id", &entry_id, + "label_id", &label_id, + NULL); + + empathy_account_widget_handle_params (self, + "entry_password", "password", + "entry_resource", "resource", + "entry_server", "server", + "spinbutton_port", "port", + "spinbutton_priority", "priority", + "checkbutton_ssl", "old-ssl", + "checkbutton_ignore_ssl_errors", "ignore-ssl-errors", + "checkbutton_encryption", "require-encryption", + NULL); + + if (service == FACEBOOK_SERVICE) + { + gtk_label_set_label (GTK_LABEL (label_id), _("Username:")); + + /* Facebook special case the entry ID widget to hide the + * "@chat.facebook.com" part */ + setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com"); + } + else + { + empathy_account_widget_setup_widget (self, entry_id, "account"); + } + + self->ui_details->default_focus = g_strdup ("entry_id"); + self->priv->spinbutton_port = spinbutton_port; + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + + g_signal_connect (checkbutton_ssl, "toggled", + G_CALLBACK (account_widget_jabber_ssl_toggled_cb), + self); + + if (service == FACEBOOK_SERVICE) + { + GtkContainer *parent; + GList *children; + + /* 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); + + if (!info.show_advanced) + gtk_widget_hide (expander_advanced); + } + + return box; +} + +static GtkWidget * +account_widget_build_icq (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *spinbutton_port; + GtkWidget *box; + + empathy_account_settings_set_regex (self->priv->settings, "account", + ACCOUNT_REGEX_ICQ); + + if (self->priv->simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_icq_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_uin_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_uin_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_icq_settings", &box, + "spinbutton_port", &spinbutton_port, + NULL); + + empathy_account_widget_handle_params (self, + "entry_uin", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + "entry_charset", "charset", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_uin"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +static GtkWidget * +account_widget_build_aim (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *spinbutton_port, *box; + + if (self->priv->simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_aim_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_screenname_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_screenname_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_aim_settings", &box, + "spinbutton_port", &spinbutton_port, + NULL); + + empathy_account_widget_handle_params (self, + "entry_screenname", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_screenname"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +static GtkWidget * +account_widget_build_yahoo (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *box; + + empathy_account_settings_set_regex (self->priv->settings, "account", + ACCOUNT_REGEX_YAHOO); + + if (self->priv->simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_yahoo_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_settings", &self->priv->grid_common_settings, + "vbox_yahoo_settings", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_locale", "room-list-locale", + "entry_charset", "charset", + "spinbutton_port", "port", + "checkbutton_ignore_invites", "ignore-invites", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +static GtkWidget * +account_widget_build_groupwise (EmpathyAccountWidget *self, + const char *filename) +{ + GtkWidget *box; + + if (self->priv->simple) + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "vbox_groupwise_simple", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id_simple", "account", + "entry_password_simple", "password", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id_simple"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, + "remember_password_simple")); + } + else + { + self->ui_details->gui = empathy_builder_get_resource (filename, + "grid_common_groupwise_settings", &self->priv->grid_common_settings, + "vbox_groupwise_settings", &box, + NULL); + + empathy_account_widget_handle_params (self, + "entry_id", "account", + "entry_password", "password", + "entry_server", "server", + "spinbutton_port", "port", + NULL); + + self->ui_details->default_focus = g_strdup ("entry_id"); + + self->priv->remember_password_widget = GTK_WIDGET ( + gtk_builder_get_object (self->ui_details->gui, "remember_password")); + } + + return box; +} + +void +empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self, + gboolean others_exist) +{ + self->priv->other_accounts_exist = others_exist; + + if (self->priv->creating_account) + account_widget_handle_control_buttons_sensitivity (self); +} + +static void +do_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object); + + switch (prop_id) + { + case PROP_SETTINGS: + self->priv->settings = g_value_dup_object (value); + break; + case PROP_SIMPLE: + self->priv->simple = g_value_get_boolean (value); + break; + case PROP_CREATING_ACCOUNT: + self->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); + } +} + +static void +do_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object); + + switch (prop_id) + { + case PROP_PROTOCOL: + g_value_set_string (value, + empathy_account_settings_get_protocol (self->priv->settings)); + break; + case PROP_SETTINGS: + g_value_set_object (value, self->priv->settings); + break; + case PROP_SIMPLE: + g_value_set_boolean (value, self->priv->simple); + break; + case PROP_CREATING_ACCOUNT: + g_value_set_boolean (value, self->priv->creating_account); + break; + case PROP_OTHER_ACCOUNTS_EXIST: + g_value_set_boolean (value, self->priv->other_accounts_exist); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +set_apply_button (EmpathyAccountWidget *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 (self->priv->apply_button), FALSE); + + gtk_button_set_label (GTK_BUTTON (self->priv->apply_button), _("A_pply")); + gtk_button_set_use_underline (GTK_BUTTON (self->priv->apply_button), TRUE); + + image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image); +} + +static void +presence_changed_cb (TpAccountManager *manager, + TpConnectionPresenceType state, + const gchar *status, + const gchar *message, + EmpathyAccountWidget *self) +{ + if (self->priv->destroyed) + return; + + if (self->priv->apply_button == NULL) + /* This button doesn't exist in 'simple' mode */ + return; + + if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE && + self->priv->creating_account) + { + /* We are online and creating a new account, display a Login button */ + GtkWidget *image; + + gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE); + gtk_button_set_label (GTK_BUTTON (self->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 (self->priv->apply_button), image); + } + else + { + /* 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_proxy_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, ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-"#proto".ui", \ + account_widget_build_##proto } + +static void +add_register_buttons (EmpathyAccountWidget *self, + TpAccount *account) +{ + TpProtocol *protocol; + GtkWidget *radiobutton_register; + + if (!self->priv->creating_account) + return; + + protocol = empathy_account_settings_get_tp_protocol (self->priv->settings); + if (protocol == NULL) + return; + + if (!tp_protocol_can_register (protocol)) + return; + + if (account_widget_get_service (self) != NO_SERVICE) + return; + + if (self->priv->simple) + return; + + self->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 (self->priv->radiobutton_reuse)), + _("Create a new account on the server")); + + gtk_box_pack_start (GTK_BOX (self), self->priv->radiobutton_reuse, FALSE, + FALSE, 0); + gtk_box_pack_start (GTK_BOX (self), radiobutton_register, FALSE, FALSE, 0); + gtk_box_reorder_child (GTK_BOX (self), self->priv->radiobutton_reuse, 0); + gtk_box_reorder_child (GTK_BOX (self), radiobutton_register, 1); + gtk_widget_show (self->priv->radiobutton_reuse); + gtk_widget_show (radiobutton_register); +} + +static void +remember_password_toggled_cb (GtkToggleButton *button, + EmpathyAccountWidget *self) +{ + empathy_account_settings_set_remember_password (self->priv->settings, + gtk_toggle_button_get_active (button)); + + if (!self->priv->automatic_change) + empathy_account_widget_changed (self); +} + +static void +account_settings_password_retrieved_cb (GObject *object, + gpointer user_data) +{ + EmpathyAccountWidget *self = user_data; + gchar *password; + + password = empathy_account_settings_dup_string ( + self->priv->settings, "password"); + + /* We have to do this so that when we call gtk_entry_set_text, + * the ::changed callback doesn't think the user made the + * change. This is also used in remember_password_toggled_cb. */ + self->priv->automatic_change = TRUE; + + if (password != NULL) + { + gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), + password); + } + + gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), + !EMP_STR_EMPTY (password)); + + self->priv->automatic_change = FALSE; + + g_free (password); +} + +static void +do_constructed (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + TpAccount *account; + const gchar *display_name, *default_display_name; + guint i = 0; + struct { + const gchar *cm_name; + const gchar *protocol; + const char *file; + GtkWidget * (*func)(EmpathyAccountWidget *self, const gchar *filename); + } widgets [] = { + { "salut", "local-xmpp", ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-local-xmpp.ui", + account_widget_build_salut }, + WIDGET (gabble, jabber), + WIDGET (haze, msn), + WIDGET (haze, icq), + WIDGET (haze, aim), + WIDGET (haze, yahoo), + WIDGET (haze, groupwise), + WIDGET (idle, irc), + WIDGET (sofiasip, sip), + }; + const gchar *protocol, *cm_name; + GtkWidget *box; + + account = empathy_account_settings_get_account (self->priv->settings); + + cm_name = empathy_account_settings_get_cm (self->priv->settings); + protocol = empathy_account_settings_get_protocol (self->priv->settings); + + for (i = 0 ; i < G_N_ELEMENTS (widgets); i++) + { + if (!tp_strdiff (widgets[i].cm_name, cm_name) && + !tp_strdiff (widgets[i].protocol, protocol)) + { + box = widgets[i].func (self, widgets[i].file); + break; + } + } + + if (i == G_N_ELEMENTS (widgets)) + { + gchar *filename = ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-generic.ui"; + box = account_widget_build_generic (self, filename); + } + + gtk_container_add (GTK_CONTAINER (self), box); + + /* handle default focus */ + if (self->ui_details->default_focus != NULL) + { + GObject *default_focus_entry; + + default_focus_entry = gtk_builder_get_object + (self->ui_details->gui, self->ui_details->default_focus); + g_signal_connect (default_focus_entry, "realize", + G_CALLBACK (gtk_widget_grab_focus), + NULL); + } + + /* remember password */ + if (self->priv->param_password_widget != NULL + && self->priv->remember_password_widget != NULL + && empathy_account_settings_supports_sasl (self->priv->settings)) + { + if (self->priv->simple) + { + gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), TRUE); + } + else + { + gchar *password; + + password = empathy_account_settings_dup_string (self->priv->settings, + "password"); + + /* FIXME: we should enable this checkbox only if the password is + * stored for good in the password storage, not only for the session + * (bgo #683571) */ + gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), + !EMP_STR_EMPTY (password)); + + /* The password might not have been retrieved from the + * keyring yet. We should update the remember password + * toggle button and the password entry when/if it is. */ + tp_g_signal_connect_object (self->priv->settings, + "password-retrieved", + G_CALLBACK (account_settings_password_retrieved_cb), self, 0); + + g_free (password); + } + + g_signal_connect (self->priv->remember_password_widget, "toggled", + G_CALLBACK (remember_password_toggled_cb), self); + + self->priv->automatic_change = TRUE; + remember_password_toggled_cb ( + GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), self); + self->priv->automatic_change = FALSE; + } + else if (self->priv->remember_password_widget != NULL + && !empathy_account_settings_supports_sasl (self->priv->settings)) + { + gtk_widget_set_visible (self->priv->remember_password_widget, FALSE); + empathy_account_settings_set_remember_password (self->priv->settings, + TRUE); + } + + /* dup and init the account-manager */ + self->priv->account_manager = tp_account_manager_dup (); + + g_object_ref (self); + tp_proxy_prepare_async (self->priv->account_manager, NULL, + account_manager_ready_cb, self); + + /* handle apply and cancel button */ + self->priv->hbox_buttons = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); + + gtk_box_set_homogeneous (GTK_BOX (self->priv->hbox_buttons), TRUE); + + self->priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + + self->priv->apply_button = gtk_button_new (); + set_apply_button (self); + + /* 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 (self->priv->account_manager, + "most-available-presence-changed", + G_CALLBACK (presence_changed_cb), obj, 0); + + gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons), + self->priv->apply_button, TRUE, TRUE, 3); + gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons), + self->priv->cancel_button, TRUE, TRUE, 3); + + gtk_box_pack_end (GTK_BOX (self), self->priv->hbox_buttons, FALSE, + FALSE, 3); + + g_signal_connect (self->priv->cancel_button, "clicked", + G_CALLBACK (account_widget_cancel_clicked_cb), + self); + g_signal_connect (self->priv->apply_button, "clicked", + G_CALLBACK (account_widget_apply_clicked_cb), + self); + gtk_widget_show_all (self->priv->hbox_buttons); + + if (self->priv->creating_account) + /* When creating an account, the user might have nothing to enter. + * That means that no control interaction might occur, + * so we update the control button sensitivity manually. + */ + account_widget_handle_control_buttons_sensitivity (self); + else + account_widget_set_control_buttons_sensitivity (self, FALSE); + + add_register_buttons (self, account); + + g_clear_object (&self->ui_details->gui); + + display_name = empathy_account_settings_get_display_name ( + self->priv->settings); + default_display_name = empathy_account_widget_get_default_display_name (self); + + if (tp_strdiff (display_name, default_display_name) && + !self->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 (self->priv->settings, "display-name-overridden", TRUE, + NULL); + } +} + +static void +do_dispose (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + + g_clear_object (&self->priv->settings); + g_clear_object (&self->priv->account_manager); + + if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL) + G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj); +} + +static void +do_finalize (GObject *obj) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj); + + g_free (self->ui_details->default_focus); + g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details); + + g_free (self->priv->jid_suffix); + + if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL) + G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj); +} + +static void +empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + oclass->get_property = do_get_property; + oclass->set_property = do_set_property; + oclass->constructed = do_constructed; + oclass->dispose = do_dispose; + oclass->finalize = do_finalize; + + param_spec = g_param_spec_string ("protocol", + "protocol", "The protocol of the account", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec); + + param_spec = g_param_spec_object ("settings", + "settings", "The settings of the account", + EMPATHY_TYPE_ACCOUNT_SETTINGS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SETTINGS, param_spec); + + param_spec = g_param_spec_boolean ("simple", + "simple", "Whether the account widget is a simple or an advanced one", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (oclass, PROP_SIMPLE, param_spec); + + param_spec = g_param_spec_boolean ("creating-account", + "creating-account", + "TRUE if we're creating an account, FALSE if we're modifying it", + FALSE, + 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, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 1, G_TYPE_BOOLEAN); + + /* This signal is emitted when an account has been created and enabled. */ + signals[ACCOUNT_CREATED] = + g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 1, G_TYPE_OBJECT); + + signals[CANCELLED] = + g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 0); + + signals[CLOSE] = + g_signal_new ("close", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, + 1, G_TYPE_INT); + + g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv)); +} + +static void +empathy_account_widget_init (EmpathyAccountWidget *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET, + EmpathyAccountWidgetPriv); + + self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails); +} + +/* public methods */ + +void +empathy_account_widget_discard_pending_changes (EmpathyAccountWidget *self) +{ + empathy_account_settings_discard_changes (self->priv->settings); + self->priv->contains_pending_changes = FALSE; +} + +gboolean +empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *self) +{ + return self->priv->contains_pending_changes; +} + +void +empathy_account_widget_handle_params (EmpathyAccountWidget *self, + const gchar *first_widget, + ...) +{ + va_list args; + + va_start (args, first_widget); + account_widget_handle_params_valist (self, first_widget, args); + va_end (args); +} + +EmpathyAccountWidget * +empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings, + gboolean simple) +{ + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL); + + return g_object_new (EMPATHY_TYPE_ACCOUNT_WIDGET, + "orientation", GTK_ORIENTATION_VERTICAL, + "settings", settings, + "simple", simple, + "creating-account", + empathy_account_settings_get_account (settings) == NULL, + NULL); +} + +gchar * +empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self) +{ + gchar *login_id; + const gchar *protocol, *p; + gchar *default_display_name; + Service service; + + login_id = empathy_account_settings_dup_string (self->priv->settings, + "account"); + protocol = empathy_account_settings_get_protocol (self->priv->settings); + service = account_widget_get_service (self); + + if (login_id != NULL) + { + /* TODO: this should be done in empathy-account-widget-irc */ + if (!tp_strdiff (protocol, "irc")) + { + EmpathyIrcNetwork *network; + + network = empathy_irc_network_chooser_get_network ( + self->priv->irc_network_chooser); + g_assert (network != NULL); + + /* To translators: The first parameter is the login id and the + * 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, empathy_irc_network_get_name (network)); + } + else if (service == FACEBOOK_SERVICE && self->priv->jid_suffix != NULL) + { + gchar *tmp; + + tmp = remove_jid_suffix (self, login_id); + default_display_name = g_strdup_printf ("Facebook (%s)", tmp); + g_free (tmp); + } + else + { + default_display_name = g_strdup (login_id); + } + + return default_display_name; + } + + if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL) + protocol = p; + + if (protocol != NULL) + { + /* To translators: The parameter is the protocol name. The resulting + * string will be something like: "Jabber Account" */ + default_display_name = g_strdup_printf (_("%s Account"), protocol); + } + else + { + default_display_name = g_strdup (_("New account")); + } + + g_free (login_id); + + return default_display_name; +} + +/* Used by subclass to indicate that widget contains pending changes */ +void +empathy_account_widget_changed (EmpathyAccountWidget *self) +{ + account_widget_handle_control_buttons_sensitivity (self); + self->priv->contains_pending_changes = TRUE; +} + +void +empathy_account_widget_set_account_param (EmpathyAccountWidget *self, + const gchar *account) +{ + if (self->priv->param_account_widget == NULL) + return; + + gtk_entry_set_text (GTK_ENTRY (self->priv->param_account_widget), account); +} + +void +empathy_account_widget_set_password_param (EmpathyAccountWidget *self, + const gchar *account) +{ + if (self->priv->param_password_widget == NULL) + return; + + gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), account); +} + +EmpathyAccountSettings * +empathy_account_widget_get_settings (EmpathyAccountWidget *self) +{ + return self->priv->settings; +} + +void +empathy_account_widget_hide_buttons (EmpathyAccountWidget *self) +{ + gtk_widget_hide (self->priv->hbox_buttons); +} diff --git a/tp-account-widgets/empathy-account-widget.h b/tp-account-widgets/empathy-account-widget.h new file mode 100644 index 000000000..65de952c7 --- /dev/null +++ b/tp-account-widgets/empathy-account-widget.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2006-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Martyn Russell + */ + +#ifndef __EMPATHY_ACCOUNT_WIDGET_H__ +#define __EMPATHY_ACCOUNT_WIDGET_H__ + +#include + +#include "empathy-account-settings.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_ACCOUNT_WIDGET empathy_account_widget_get_type() +#define EMPATHY_ACCOUNT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidget)) +#define EMPATHY_ACCOUNT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) +#define EMPATHY_IS_ACCOUNT_WIDGET(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET)) +#define EMPATHY_IS_ACCOUNT_WIDGET_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_ACCOUNT_WIDGET)) +#define EMPATHY_ACCOUNT_WIDGET_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ACCOUNT_WIDGET, EmpathyAccountWidgetClass)) + +typedef struct _EmpathyAccountWidgetPriv EmpathyAccountWidgetPriv; +typedef struct _EmpathyAccountWidgetUIDetails EmpathyAccountWidgetUIDetails; + +typedef struct { + GtkBox parent; + + EmpathyAccountWidgetUIDetails *ui_details; + + EmpathyAccountWidgetPriv *priv; +} EmpathyAccountWidget; + +typedef struct { + GtkBoxClass parent_class; +} EmpathyAccountWidgetClass; + +GType empathy_account_widget_get_type (void); + +EmpathyAccountWidget * empathy_account_widget_new_for_protocol ( + EmpathyAccountSettings *settings, + gboolean simple); + +gboolean empathy_account_widget_contains_pending_changes + (EmpathyAccountWidget *widget); +void empathy_account_widget_discard_pending_changes + (EmpathyAccountWidget *widget); + +gchar * empathy_account_widget_get_default_display_name ( + EmpathyAccountWidget *widget); + +void empathy_account_widget_set_account_param (EmpathyAccountWidget *widget, + const gchar *account); + +void empathy_account_widget_set_password_param (EmpathyAccountWidget *self, + const gchar *password); + +void empathy_account_widget_set_other_accounts_exist ( + EmpathyAccountWidget *self, gboolean others_exist); + +void empathy_account_widget_hide_buttons (EmpathyAccountWidget *self); + +void empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self); + +/* protected methods */ +void empathy_account_widget_changed (EmpathyAccountWidget *widget); + +EmpathyAccountSettings * empathy_account_widget_get_settings ( + EmpathyAccountWidget *self); + +G_END_DECLS + +#endif /* __EMPATHY_ACCOUNT_WIDGET_H__ */ diff --git a/tp-account-widgets/empathy-account-widgets.gresource.xml b/tp-account-widgets/empathy-account-widgets.gresource.xml new file mode 100644 index 000000000..093cb2a93 --- /dev/null +++ b/tp-account-widgets/empathy-account-widgets.gresource.xml @@ -0,0 +1,16 @@ + + + + empathy-account-widget-generic.ui + empathy-account-widget-jabber.ui + empathy-account-widget-msn.ui + empathy-account-widget-sip.ui + empathy-account-widget-local-xmpp.ui + empathy-account-widget-irc.ui + empathy-account-widget-icq.ui + empathy-account-widget-yahoo.ui + empathy-account-widget-groupwise.ui + empathy-account-widget-aim.ui + + + diff --git a/tp-account-widgets/empathy-irc-network-chooser-dialog.c b/tp-account-widgets/empathy-irc-network-chooser-dialog.c new file mode 100644 index 000000000..60945aed6 --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-chooser-dialog.c @@ -0,0 +1,740 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#include "config.h" +#include "empathy-irc-network-chooser-dialog.h" + +#include + +#include "empathy-irc-network-dialog.h" +#include "empathy-irc-network-manager.h" +#include "empathy-live-search.h" +#include "empathy-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC +#include "empathy-debug.h" + +#include "empathy-irc-network-chooser-dialog.h" + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkChooserDialog) + +enum { + PROP_SETTINGS = 1, + PROP_NETWORK +}; + +enum { + RESPONSE_RESET = 0 +}; + +typedef struct { + EmpathyAccountSettings *settings; + EmpathyIrcNetwork *network; + + EmpathyIrcNetworkManager *network_manager; + gboolean changed; + + GtkWidget *treeview; + GtkListStore *store; + GtkTreeModelFilter *filter; + GtkWidget *search; + GtkWidget *select_button; + + gulong search_sig; + gulong activate_sig; +} EmpathyIrcNetworkChooserDialogPriv; + +enum { + COL_NETWORK_OBJ, + COL_NETWORK_NAME, +}; + +G_DEFINE_TYPE (EmpathyIrcNetworkChooserDialog, empathy_irc_network_chooser_dialog, + GTK_TYPE_DIALOG); + +static void +empathy_irc_network_chooser_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_SETTINGS: + priv->settings = g_value_dup_object (value); + break; + case PROP_NETWORK: + priv->network = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +empathy_irc_network_chooser_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_SETTINGS: + g_value_set_object (value, priv->settings); + break; + case PROP_NETWORK: + g_value_set_object (value, priv->network); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* The iter returned by *it is a priv->store iter (not a filter one) */ +static EmpathyIrcNetwork * +dup_selected_network (EmpathyIrcNetworkChooserDialog *self, + GtkTreeIter *it) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + EmpathyIrcNetwork *network; + GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeModel *model; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + if (selection == NULL) + return NULL; + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return NULL; + + gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1); + g_assert (network != NULL); + + if (it != NULL) + { + gtk_tree_model_filter_convert_iter_to_child_iter (priv->filter, it, + &iter); + } + + return network; +} + +static void +treeview_changed_cb (GtkTreeView *treeview, + EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + EmpathyIrcNetwork *network; + + network = dup_selected_network (self, NULL); + if (network == priv->network) + { + g_clear_object (&network); + return; + } + + tp_clear_object (&priv->network); + /* Transfer the reference */ + priv->network = network; + + priv->changed = TRUE; +} + +/* Take a filter iterator as argument */ +static void +scroll_to_iter (EmpathyIrcNetworkChooserDialog *self, + GtkTreeIter *filter_iter) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GtkTreePath *path; + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), filter_iter); + + if (path != NULL) + { + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), + path, NULL, FALSE, 0, 0); + + gtk_tree_path_free (path); + } +} + +/* Take a filter iterator as argument */ +static void +select_iter (EmpathyIrcNetworkChooserDialog *self, + GtkTreeIter *filter_iter, + gboolean emulate_changed) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GtkTreeSelection *selection; + GtkTreePath *path; + + /* Select the network */ + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (priv->treeview)); + + gtk_tree_selection_select_iter (selection, filter_iter); + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), filter_iter); + if (path != NULL) + { + gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path, + NULL, FALSE); + + gtk_tree_path_free (path); + } + + /* Scroll to the selected network */ + scroll_to_iter (self, filter_iter); + + if (emulate_changed) + { + /* gtk_tree_selection_select_iter doesn't fire the 'cursor-changed' signal + * so we call the callback manually. */ + treeview_changed_cb (GTK_TREE_VIEW (priv->treeview), self); + } +} + +static GtkTreeIter +iter_to_filter_iter (EmpathyIrcNetworkChooserDialog *self, + GtkTreeIter *iter) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GtkTreeIter filter_iter; + + g_assert (gtk_tree_model_filter_convert_child_iter_to_iter (priv->filter, + &filter_iter, iter)); + + return filter_iter; +} + +static void +fill_store (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GSList *networks, *l; + + networks = empathy_irc_network_manager_get_networks ( + priv->network_manager); + + for (l = networks; l != NULL; l = g_slist_next (l)) + { + EmpathyIrcNetwork *network = l->data; + GtkTreeIter iter; + + gtk_list_store_insert_with_values (priv->store, &iter, -1, + COL_NETWORK_OBJ, network, + COL_NETWORK_NAME, empathy_irc_network_get_name (network), + -1); + + if (network == priv->network) + { + GtkTreeIter filter_iter = iter_to_filter_iter (self, &iter); + + select_iter (self, &filter_iter, FALSE); + } + + g_object_unref (network); + } + + g_slist_free (networks); +} + +static void +irc_network_dialog_destroy_cb (GtkWidget *widget, + EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + EmpathyIrcNetwork *network; + GtkTreeIter iter, filter_iter; + + priv->changed = TRUE; + + network = dup_selected_network (self, &iter); + if (network == NULL) + return; + + /* name could be changed */ + gtk_list_store_set (GTK_LIST_STORE (priv->store), &iter, + COL_NETWORK_NAME, empathy_irc_network_get_name (network), -1); + + filter_iter = iter_to_filter_iter (self, &iter); + scroll_to_iter (self, &filter_iter); + + gtk_widget_grab_focus (priv->treeview); + + g_object_unref (network); +} + +static void +display_irc_network_dialog (EmpathyIrcNetworkChooserDialog *self, + EmpathyIrcNetwork *network) +{ + GtkWidget *dialog; + + dialog = empathy_irc_network_dialog_show (network, GTK_WIDGET (self)); + + g_signal_connect (dialog, "destroy", + G_CALLBACK (irc_network_dialog_destroy_cb), self); +} + +static void +edit_network (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetwork *network; + + network = dup_selected_network (self, NULL); + if (network == NULL) + return; + + display_irc_network_dialog (self, network); + + g_object_unref (network); +} + +static void +add_network (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + EmpathyIrcNetwork *network; + GtkTreeIter iter, filter_iter; + + gtk_widget_hide (priv->search); + + network = empathy_irc_network_new (_("New Network")); + empathy_irc_network_manager_add (priv->network_manager, network); + + gtk_list_store_insert_with_values (priv->store, &iter, -1, + COL_NETWORK_OBJ, network, + COL_NETWORK_NAME, empathy_irc_network_get_name (network), + -1); + + filter_iter = iter_to_filter_iter (self, &iter); + select_iter (self, &filter_iter, TRUE); + + display_irc_network_dialog (self, network); + + g_object_unref (network); +} + +static void +remove_network (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + EmpathyIrcNetwork *network; + GtkTreeIter iter; + + network = dup_selected_network (self, &iter); + if (network == NULL) + return; + + /* Hide the search after picking the network to get the right one */ + gtk_widget_hide (priv->search); + + DEBUG ("Remove network %s", empathy_irc_network_get_name (network)); + + /* Delete network and select next network */ + if (gtk_list_store_remove (priv->store, &iter)) + { + GtkTreeIter filter_iter = iter_to_filter_iter (self, &iter); + + select_iter (self, &filter_iter, TRUE); + } + else + { + /* this should only happen if the last network was deleted */ + GtkTreeIter last, filter_iter; + gint n_elements; + + n_elements = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), + NULL); + + if (n_elements > 0) + { + gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store), &last, + NULL, (n_elements-1)); + filter_iter = iter_to_filter_iter (self, &last); + + select_iter (self, &filter_iter, TRUE); + } + } + + empathy_irc_network_manager_remove (priv->network_manager, network); + gtk_widget_grab_focus (priv->treeview); + + g_object_unref (network); +} + +static void +reset_networks (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GSList *networks, *l; + + networks = empathy_irc_network_manager_get_dropped_networks ( + priv->network_manager); + + for (l = networks; l != NULL; l = g_slist_next (l)) + { + EmpathyIrcNetwork *network; + GtkTreeIter iter; + + network = EMPATHY_IRC_NETWORK (l->data); + empathy_irc_network_activate (network); + + gtk_list_store_insert_with_values (priv->store, &iter, -1, + COL_NETWORK_OBJ, network, + COL_NETWORK_NAME, empathy_irc_network_get_name (network), + -1); + } + + g_slist_foreach (networks, (GFunc) g_object_unref, NULL); +} + +static void +dialog_response_cb (GtkDialog *dialog, + gint response, + EmpathyIrcNetworkChooserDialog *self) +{ + if (response == RESPONSE_RESET) + reset_networks (self); +} + +static gboolean +filter_visible_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer user_data) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (user_data); + EmpathyIrcNetwork *network; + gboolean visible; + + gtk_tree_model_get (model, iter, COL_NETWORK_OBJ, &network, -1); + + visible = empathy_live_search_match (EMPATHY_LIVE_SEARCH (priv->search), + empathy_irc_network_get_name (network)); + + g_object_unref (network); + return visible; +} + +static void +search_activate_cb (GtkWidget *search, + EmpathyIrcNetworkChooserDialog *self) +{ + gtk_widget_hide (search); + gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CLOSE); +} + +static void +search_text_notify_cb (EmpathyLiveSearch *search, + GParamSpec *pspec, + EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GtkTreeIter filter_iter; + gboolean sensitive = FALSE; + + gtk_tree_model_filter_refilter (priv->filter); + + /* Is there at least one network in the view ? */ + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), + &filter_iter)) + { + const gchar *text; + + text = empathy_live_search_get_text (EMPATHY_LIVE_SEARCH (priv->search)); + if (!EMP_STR_EMPTY (text)) + { + /* We are doing a search, select the first matching network */ + select_iter (self, &filter_iter, TRUE); + } + else + { + /* Search has been cancelled. Scroll to the selected network */ + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (priv->treeview)); + + if (gtk_tree_selection_get_selected (selection, NULL, &filter_iter)) + scroll_to_iter (self, &filter_iter); + } + + sensitive = TRUE; + } + + gtk_widget_set_sensitive (priv->select_button, sensitive); +} + +static void +add_clicked_cb (GtkToolButton *button, + EmpathyIrcNetworkChooserDialog *self) +{ + add_network (self); +} + +static void +remove_clicked_cb (GtkToolButton *button, + EmpathyIrcNetworkChooserDialog *self) +{ + remove_network (self); +} + +static void +edit_clicked_cb (GtkToolButton *button, + EmpathyIrcNetworkChooserDialog *self) +{ + edit_network (self); +} + +static void +empathy_irc_network_chooser_dialog_constructed (GObject *object) +{ + EmpathyIrcNetworkChooserDialog *self = (EmpathyIrcNetworkChooserDialog *) object; + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GtkDialog *dialog = GTK_DIALOG (self); + GtkCellRenderer *renderer; + GtkWidget *vbox; + GtkTreeViewColumn *column; + GtkWidget *scroll; + GtkWidget *toolbar; + GtkToolItem *item; + GtkStyleContext *context; + + g_assert (priv->settings != NULL); + + gtk_window_set_title (GTK_WINDOW (self), _("Choose an IRC network")); + + /* Create store and treeview */ + priv->store = gtk_list_store_new (2, G_TYPE_OBJECT, G_TYPE_STRING); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), + COL_NETWORK_NAME, + GTK_SORT_ASCENDING); + + priv->treeview = gtk_tree_view_new (); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE); + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE); + + column = gtk_tree_view_column_new (); + gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), + renderer, + "text", COL_NETWORK_NAME, + NULL); + + /* add the treeview in a GtkScrolledWindow */ + vbox = gtk_dialog_get_content_area (dialog); + + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + + gtk_container_add (GTK_CONTAINER (scroll), priv->treeview); + gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 6); + + /* Treeview toolbar */ + toolbar = gtk_toolbar_new (); + gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0); + + item = gtk_tool_button_new (NULL, ""); + gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "list-add-symbolic"); + g_signal_connect (item, "clicked", G_CALLBACK (add_clicked_cb), self); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + item = gtk_tool_button_new (NULL, ""); + gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), + "list-remove-symbolic"); + g_signal_connect (item, "clicked", G_CALLBACK (remove_clicked_cb), self); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + item = gtk_tool_button_new (NULL, ""); + gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), + "preferences-system-symbolic"); + g_signal_connect (item, "clicked", G_CALLBACK (edit_clicked_cb), self); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + context = gtk_widget_get_style_context (scroll); + gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); + + context = gtk_widget_get_style_context (toolbar); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR); + gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); + + /* Live search */ + priv->search = empathy_live_search_new (priv->treeview); + + gtk_box_pack_start (GTK_BOX (vbox), priv->search, FALSE, TRUE, 0); + + priv->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new ( + GTK_TREE_MODEL (priv->store), NULL)); + gtk_tree_model_filter_set_visible_func (priv->filter, + filter_visible_func, self, NULL); + + gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), + GTK_TREE_MODEL (priv->filter)); + + priv->search_sig = g_signal_connect (priv->search, "notify::text", + G_CALLBACK (search_text_notify_cb), self); + + priv->activate_sig = g_signal_connect (priv->search, "activate", + G_CALLBACK (search_activate_cb), self); + + /* Add buttons */ + gtk_dialog_add_buttons (dialog, + _("Reset _Networks List"), RESPONSE_RESET, + NULL); + + priv->select_button = gtk_dialog_add_button (dialog, + C_("verb displayed on a button to select an IRC network", "Select"), + GTK_RESPONSE_CLOSE); + + fill_store (self); + + g_signal_connect (priv->treeview, "cursor-changed", + G_CALLBACK (treeview_changed_cb), self); + + g_signal_connect (self, "response", + G_CALLBACK (dialog_response_cb), self); + + /* Request a side ensuring to display at least some networks */ + gtk_widget_set_size_request (GTK_WIDGET (self), -1, 300); + + gtk_window_set_modal (GTK_WINDOW (self), TRUE); +} + +static void +empathy_irc_network_chooser_dialog_dispose (GObject *object) +{ + EmpathyIrcNetworkManager *self = (EmpathyIrcNetworkManager *) object; + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + + if (priv->search_sig != 0) + { + g_signal_handler_disconnect (priv->search, priv->search_sig); + priv->search_sig = 0; + } + + if (priv->activate_sig != 0) + { + g_signal_handler_disconnect (priv->search, priv->activate_sig); + priv->activate_sig = 0; + } + + if (priv->search != NULL) + { + empathy_live_search_set_hook_widget (EMPATHY_LIVE_SEARCH (priv->search), + NULL); + + priv->search = NULL; + } + + tp_clear_object (&priv->settings); + tp_clear_object (&priv->network); + tp_clear_object (&priv->network_manager); + tp_clear_object (&priv->store); + tp_clear_object (&priv->filter); + + if (G_OBJECT_CLASS (empathy_irc_network_chooser_dialog_parent_class)->dispose) + G_OBJECT_CLASS (empathy_irc_network_chooser_dialog_parent_class)->dispose (object); +} + +static void +empathy_irc_network_chooser_dialog_class_init (EmpathyIrcNetworkChooserDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = empathy_irc_network_chooser_dialog_get_property; + object_class->set_property = empathy_irc_network_chooser_dialog_set_property; + object_class->constructed = empathy_irc_network_chooser_dialog_constructed; + object_class->dispose = empathy_irc_network_chooser_dialog_dispose; + + g_object_class_install_property (object_class, PROP_SETTINGS, + g_param_spec_object ("settings", + "Settings", + "The EmpathyAccountSettings to show and edit", + EMPATHY_TYPE_ACCOUNT_SETTINGS, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_NETWORK, + g_param_spec_object ("network", + "Network", + "The EmpathyIrcNetwork selected in the treeview", + EMPATHY_TYPE_IRC_NETWORK, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (object_class, + sizeof (EmpathyIrcNetworkChooserDialogPriv)); +} + +static void +empathy_irc_network_chooser_dialog_init (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialogPriv); + self->priv = priv; + + priv->network_manager = empathy_irc_network_manager_dup_default (); +} + +GtkWidget * +empathy_irc_network_chooser_dialog_new (EmpathyAccountSettings *settings, + EmpathyIrcNetwork *network, + GtkWindow *parent) +{ + return g_object_new (EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, + "settings", settings, + "network", network, + "transient-for", parent, + NULL); +} + +EmpathyIrcNetwork * +empathy_irc_network_chooser_dialog_get_network ( + EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + + return priv->network; +} + +gboolean +empathy_irc_network_chooser_dialog_get_changed ( + EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + + return priv->changed; +} diff --git a/tp-account-widgets/empathy-irc-network-chooser-dialog.h b/tp-account-widgets/empathy-irc-network-chooser-dialog.h new file mode 100644 index 000000000..1e4654916 --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-chooser-dialog.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#ifndef __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ +#define __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ + +#include + +#include "empathy-account-settings.h" +#include "empathy-irc-network.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG (empathy_irc_network_chooser_dialog_get_type ()) +#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialog)) +#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, EmpathyIrcNetworkChooserDialogClass)) +#define EMPATHY_IS_IRC_NETWORK_CHOOSER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG)) +#define EMPATHY_IS_IRC_NETWORK_CHOOSER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG)) +#define EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_GET_CLASS(o) ( \ + G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK_CHOOSER_DIALOG, \ + EmpathyIrcNetworkChooserDialogClass)) + +typedef struct { + GtkDialog parent; + + /**/ + gpointer priv; +} EmpathyIrcNetworkChooserDialog; + +typedef struct { + GtkDialogClass parent_class; +} EmpathyIrcNetworkChooserDialogClass; + +GType empathy_irc_network_chooser_dialog_get_type (void) G_GNUC_CONST; + +GtkWidget * empathy_irc_network_chooser_dialog_new ( + EmpathyAccountSettings *settings, + EmpathyIrcNetwork *network, + GtkWindow *parent); + +EmpathyIrcNetwork * empathy_irc_network_chooser_dialog_get_network ( + EmpathyIrcNetworkChooserDialog *self); + +gboolean empathy_irc_network_chooser_dialog_get_changed ( + EmpathyIrcNetworkChooserDialog *self); + +G_END_DECLS + +#endif /* __EMPATHY_IRC_NETWORK_CHOOSER_DIALOG_H__ */ diff --git a/tp-account-widgets/empathy-irc-network-chooser.c b/tp-account-widgets/empathy-irc-network-chooser.c new file mode 100644 index 000000000..fab6a3a3f --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-chooser.c @@ -0,0 +1,421 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#include "config.h" +#include "empathy-irc-network-chooser.h" + +#include "empathy-irc-network-chooser-dialog.h" +#include "empathy-irc-network-manager.h" +#include "empathy-ui-utils.h" +#include "empathy-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC +#include "empathy-debug.h" + +#define DEFAULT_IRC_NETWORK "irc.gimp.org" +#define DEFAULT_IRC_PORT 6667 +#define DEFAULT_IRC_SSL FALSE + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkChooser) + +enum { + PROP_SETTINGS = 1 +}; + +enum { + SIG_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +typedef struct { + EmpathyAccountSettings *settings; + + EmpathyIrcNetworkManager *network_manager; + GtkWidget *dialog; + /* Displayed network */ + EmpathyIrcNetwork *network; +} EmpathyIrcNetworkChooserPriv; + +G_DEFINE_TYPE (EmpathyIrcNetworkChooser, empathy_irc_network_chooser, + GTK_TYPE_BUTTON); + +static void +empathy_irc_network_chooser_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_SETTINGS: + priv->settings = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +empathy_irc_network_chooser_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (object); + + switch (prop_id) + { + case PROP_SETTINGS: + g_value_set_object (value, priv->settings); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +unset_server_params (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + + DEBUG ("Unset server, port and use-ssl"); + empathy_account_settings_unset (priv->settings, "server"); + empathy_account_settings_unset (priv->settings, "port"); + empathy_account_settings_unset (priv->settings, "use-ssl"); +} + +static gchar * +dup_network_service (EmpathyIrcNetwork *network) +{ + /* Account.Service has to be a lower case alphanumeric string which may + * also contain '-' but not start with it. */ +#define VALID G_CSET_a_2_z G_CSET_DIGITS "-" + gchar *service, *tmp; + + service = g_strdup (empathy_irc_network_get_name (network)); + service = g_strstrip (service); + + if (tp_str_empty (service)) + { + g_free (service); + return NULL; + } + + tmp = service; + service = g_ascii_strdown (service, -1); + g_free (tmp); + + service = g_strcanon (service, VALID, '-'); + + if (service[0] == '-') + { + tmp = service; + service = g_strdup (service + 1); + + g_free (tmp); + } + + return service; +} + +static void +update_server_params (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + GSList *servers; + const gchar *charset; + + g_assert (priv->network != NULL); + + charset = empathy_irc_network_get_charset (priv->network); + DEBUG ("Setting charset to %s", charset); + empathy_account_settings_set (priv->settings, "charset", + g_variant_new_string (charset)); + + servers = empathy_irc_network_get_servers (priv->network); + if (g_slist_length (servers) > 0) + { + /* set the first server as CM server */ + EmpathyIrcServer *server = servers->data; + gchar *address; + guint port; + gboolean ssl; + gchar *service; + + g_object_get (server, + "address", &address, + "port", &port, + "ssl", &ssl, + NULL); + + DEBUG ("Setting server to %s", address); + empathy_account_settings_set (priv->settings, "server", + g_variant_new_string (address)); + DEBUG ("Setting port to %u", port); + empathy_account_settings_set (priv->settings, "port", + g_variant_new_uint32 (port)); + DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" ); + empathy_account_settings_set (priv->settings, "use-ssl", + g_variant_new_boolean (ssl)); + + /* Set Account.Service */ + service = dup_network_service (priv->network); + DEBUG ("Setting Service to %s", service); + empathy_account_settings_set_service (priv->settings, service); + + g_free (address); + g_free (service); + } + else + { + /* No server. Unset values */ + unset_server_params (self); + } + + g_slist_foreach (servers, (GFunc) g_object_unref, NULL); + g_slist_free (servers); +} + +static void +set_label (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + + g_assert (priv->network != NULL); + + gtk_button_set_label (GTK_BUTTON (self), + empathy_irc_network_get_name (priv->network)); +} + +static void +set_label_from_settings (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + gchar *server; + + tp_clear_object (&priv->network); + + server = empathy_account_settings_dup_string (priv->settings, "server"); + + if (server != NULL) + { + EmpathyIrcServer *srv; + gint port; + gboolean ssl; + + priv->network = empathy_irc_network_manager_find_network_by_address ( + priv->network_manager, server); + + if (priv->network != NULL) + { + /* The network is known */ + g_object_ref (priv->network); + set_label (self); + return; + } + + /* We don't have this network. Let's create it */ + port = empathy_account_settings_get_uint32 (priv->settings, "port"); + ssl = empathy_account_settings_get_boolean (priv->settings, + "use-ssl"); + + DEBUG ("Create a network %s", server); + priv->network = empathy_irc_network_new (server); + srv = empathy_irc_server_new (server, port, ssl); + + empathy_irc_network_append_server (priv->network, srv); + empathy_irc_network_manager_add (priv->network_manager, priv->network); + + set_label (self); + + g_object_unref (srv); + g_free (server); + return; + } + + /* Set default network */ + priv->network = empathy_irc_network_manager_find_network_by_address ( + priv->network_manager, DEFAULT_IRC_NETWORK); + + if (priv->network == NULL) + { + /* Default network is not known, recreate it */ + EmpathyIrcServer *srv; + + priv->network = empathy_irc_network_new (DEFAULT_IRC_NETWORK); + + srv = empathy_irc_server_new (DEFAULT_IRC_NETWORK, DEFAULT_IRC_PORT, + DEFAULT_IRC_SSL); + + empathy_irc_network_append_server (priv->network, srv); + empathy_irc_network_manager_add (priv->network_manager, priv->network); + + g_object_unref (srv); + } + + set_label (self); + update_server_params (self); + g_object_ref (priv->network); +} + +static void +dialog_response_cb (GtkDialog *dialog, + gint response, + EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + EmpathyIrcNetworkChooserDialog *chooser = + EMPATHY_IRC_NETWORK_CHOOSER_DIALOG (priv->dialog); + + if (response != GTK_RESPONSE_CLOSE && + response != GTK_RESPONSE_DELETE_EVENT) + return; + + if (empathy_irc_network_chooser_dialog_get_changed (chooser)) + { + tp_clear_object (&priv->network); + + priv->network = g_object_ref ( + empathy_irc_network_chooser_dialog_get_network (chooser)); + + update_server_params (self); + set_label (self); + + g_signal_emit (self, signals[SIG_CHANGED], 0); + } + + gtk_widget_destroy (priv->dialog); + priv->dialog = NULL; +} + +static void +clicked_cb (GtkButton *button, + gpointer user_data) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (button); + GtkWindow *window; + + if (priv->dialog != NULL) + goto out; + + window = empathy_get_toplevel_window (GTK_WIDGET (button)); + + priv->dialog = empathy_irc_network_chooser_dialog_new (priv->settings, + priv->network, window); + gtk_widget_show_all (priv->dialog); + + tp_g_signal_connect_object (priv->dialog, "response", + G_CALLBACK (dialog_response_cb), button, 0); + +out: + empathy_window_present (GTK_WINDOW (priv->dialog)); +} + +static void +empathy_irc_network_chooser_constructed (GObject *object) +{ + EmpathyIrcNetworkChooser *self = (EmpathyIrcNetworkChooser *) object; + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + + g_assert (priv->settings != NULL); + + set_label_from_settings (self); + + g_signal_connect (self, "clicked", G_CALLBACK (clicked_cb), self); +} + +static void +empathy_irc_network_chooser_dispose (GObject *object) +{ + EmpathyIrcNetworkManager *self = (EmpathyIrcNetworkManager *) object; + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + + tp_clear_object (&priv->settings); + tp_clear_object (&priv->network_manager); + tp_clear_object (&priv->network); + + if (G_OBJECT_CLASS (empathy_irc_network_chooser_parent_class)->dispose) + G_OBJECT_CLASS (empathy_irc_network_chooser_parent_class)->dispose (object); +} + +static void +empathy_irc_network_chooser_class_init (EmpathyIrcNetworkChooserClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = empathy_irc_network_chooser_get_property; + object_class->set_property = empathy_irc_network_chooser_set_property; + object_class->constructed = empathy_irc_network_chooser_constructed; + object_class->dispose = empathy_irc_network_chooser_dispose; + + g_object_class_install_property (object_class, PROP_SETTINGS, + g_param_spec_object ("settings", + "Settings", + "The EmpathyAccountSettings to show and edit", + EMPATHY_TYPE_ACCOUNT_SETTINGS, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + signals[SIG_CHANGED] = g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 0); + + g_type_class_add_private (object_class, + sizeof (EmpathyIrcNetworkChooserPriv)); +} + +static void +empathy_irc_network_chooser_init (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooserPriv); + self->priv = priv; + + priv->network_manager = empathy_irc_network_manager_dup_default (); +} + +GtkWidget * +empathy_irc_network_chooser_new (EmpathyAccountSettings *settings) +{ + return g_object_new (EMPATHY_TYPE_IRC_NETWORK_CHOOSER, + "settings", settings, + NULL); +} + +EmpathyIrcNetwork * +empathy_irc_network_chooser_get_network (EmpathyIrcNetworkChooser *self) +{ + EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); + + return priv->network; +} diff --git a/tp-account-widgets/empathy-irc-network-chooser.h b/tp-account-widgets/empathy-irc-network-chooser.h new file mode 100644 index 000000000..f4c603288 --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-chooser.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#ifndef __EMPATHY_IRC_NETWORK_CHOOSER_H__ +#define __EMPATHY_IRC_NETWORK_CHOOSER_H__ + +#include + +#include "empathy-account-settings.h" +#include "empathy-irc-network.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_IRC_NETWORK_CHOOSER (empathy_irc_network_chooser_get_type ()) +#define EMPATHY_IRC_NETWORK_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooser)) +#define EMPATHY_IRC_NETWORK_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER, EmpathyIrcNetworkChooserClass)) +#define EMPATHY_IS_IRC_NETWORK_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER)) +#define EMPATHY_IS_IRC_NETWORK_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ + EMPATHY_TYPE_IRC_NETWORK_CHOOSER)) +#define EMPATHY_IRC_NETWORK_CHOOSER_GET_CLASS(o) ( \ + G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK_CHOOSER, \ + EmpathyIrcNetworkChooserClass)) + +typedef struct { + GtkButton parent; + + /**/ + gpointer priv; +} EmpathyIrcNetworkChooser; + +typedef struct { + GtkButtonClass parent_class; +} EmpathyIrcNetworkChooserClass; + +GType empathy_irc_network_chooser_get_type (void) G_GNUC_CONST; + +GtkWidget * empathy_irc_network_chooser_new (EmpathyAccountSettings *settings); + +EmpathyIrcNetwork * empathy_irc_network_chooser_get_network ( + EmpathyIrcNetworkChooser *self); + +G_END_DECLS + +#endif /* __EMPATHY_IRC_NETWORK_CHOOSER_H__ */ diff --git a/tp-account-widgets/empathy-irc-network-dialog.c b/tp-account-widgets/empathy-irc-network-dialog.c new file mode 100644 index 000000000..35457f592 --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-dialog.c @@ -0,0 +1,588 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#include "config.h" +#include "empathy-irc-network-dialog.h" + +#include + +#include "empathy-ui-utils.h" +#include "totem-subtitle-encoding.h" + +typedef struct { + EmpathyIrcNetwork *network; + + GtkWidget *dialog; + GtkWidget *button_close; + + GtkWidget *entry_network; + GtkWidget *combobox_charset; + + GtkWidget *treeview_servers; + GtkWidget *button_add; + GtkWidget *button_remove; + GtkWidget *button_up; + GtkWidget *button_down; +} EmpathyIrcNetworkDialog; + +static void +irc_network_dialog_destroy_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + g_object_unref (dialog->network); + + g_slice_free (EmpathyIrcNetworkDialog, dialog); +} + +static void +irc_network_dialog_close_clicked_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + gtk_widget_destroy (dialog->dialog); +} + +enum { + COL_SRV_OBJ, + COL_ADR, + COL_PORT, + COL_SSL +}; + +static void +add_server_to_store (GtkListStore *store, + EmpathyIrcServer *server, + GtkTreeIter *iter) +{ + gchar *address; + guint port; + gboolean ssl; + + g_object_get (server, + "address", &address, + "port", &port, + "ssl", &ssl, + NULL); + + gtk_list_store_insert_with_values (store, iter, -1, + COL_SRV_OBJ, server, + COL_ADR, address, + COL_PORT, port, + COL_SSL, ssl, + -1); + + g_free (address); +} + +static void +irc_network_dialog_setup (EmpathyIrcNetworkDialog *dialog) +{ + gchar *name, *charset; + GSList *servers, *l; + GtkListStore *store; + + g_object_get (dialog->network, + "name", &name, + "charset", &charset, + NULL); + gtk_entry_set_text (GTK_ENTRY (dialog->entry_network), name); + + store = GTK_LIST_STORE (gtk_tree_view_get_model ( + GTK_TREE_VIEW (dialog->treeview_servers))); + + servers = empathy_irc_network_get_servers (dialog->network); + for (l = servers; l != NULL; l = g_slist_next (l)) + { + EmpathyIrcServer *server = l->data; + GtkTreeIter iter; + + add_server_to_store (store, server, &iter); + } + + totem_subtitle_encoding_set (GTK_COMBO_BOX (dialog->combobox_charset), + charset); + + g_slist_foreach (servers, (GFunc) g_object_unref, NULL); + g_slist_free (servers); + g_free (name); + g_free (charset); +} + +static void +irc_network_dialog_address_edited_cb (GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + EmpathyIrcNetworkDialog *dialog) +{ + EmpathyIrcServer *server; + GtkTreeModel *model; + GtkTreePath *treepath; + GtkTreeIter iter; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); + treepath = gtk_tree_path_new_from_string (path); + gtk_tree_model_get_iter (model, &iter, treepath); + gtk_tree_model_get (model, &iter, + COL_SRV_OBJ, &server, + -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_ADR, new_text, + -1); + + g_object_set (server, "address", new_text, NULL); + + gtk_tree_path_free (treepath); + g_object_unref (server); +} + +static void +irc_network_dialog_port_edited_cb (GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + EmpathyIrcNetworkDialog *dialog) +{ + EmpathyIrcServer *server; + GtkTreeModel *model; + GtkTreePath *treepath; + GtkTreeIter iter; + guint port; + + port = strtoul (new_text, NULL, 10); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); + treepath = gtk_tree_path_new_from_string (path); + gtk_tree_model_get_iter (model, &iter, treepath); + gtk_tree_model_get (model, &iter, + COL_SRV_OBJ, &server, + -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_PORT, port, + -1); + + g_object_set (server, "port", port, NULL); + + gtk_tree_path_free (treepath); + g_object_unref (server); +} + +static void +irc_network_dialog_ssl_toggled_cb (GtkCellRendererText *renderer, + gchar *path, + EmpathyIrcNetworkDialog *dialog) +{ + EmpathyIrcServer *server; + GtkTreeModel *model; + GtkTreePath *treepath; + GtkTreeIter iter; + gboolean ssl; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_servers)); + treepath = gtk_tree_path_new_from_string (path); + gtk_tree_model_get_iter (model, &iter, treepath); + gtk_tree_model_get (model, &iter, + COL_SRV_OBJ, &server, + COL_SSL, &ssl, + -1); + ssl = !ssl; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_SSL, ssl, + -1); + + g_object_set (server, "ssl", ssl, NULL); + + gtk_tree_path_free (treepath); + g_object_unref (server); +} + +static gboolean +irc_network_dialog_network_focus_cb (GtkWidget *widget, + GdkEventFocus *event, + EmpathyIrcNetworkDialog *dialog) +{ + const gchar *str; + + str = gtk_entry_get_text (GTK_ENTRY (widget)); + + g_object_set (dialog->network, "name", str, NULL); + + return FALSE; +} + +static void +irc_network_dialog_network_update_buttons (EmpathyIrcNetworkDialog *dialog) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + gboolean can_remove = FALSE, can_move_up = FALSE, can_move_down = FALSE; + int selected; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW ( + dialog->treeview_servers)); + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + { + path = gtk_tree_model_get_path (model, &iter); + + selected = gtk_tree_path_get_indices (path)[0]; + + can_remove = TRUE; + can_move_up = selected > 0; + can_move_down = + selected < gtk_tree_model_iter_n_children (model, NULL) - 1; + + gtk_tree_path_free (path); + } + + gtk_widget_set_sensitive (dialog->button_remove, can_remove); + gtk_widget_set_sensitive (dialog->button_up, can_move_up); + gtk_widget_set_sensitive (dialog->button_down, can_move_down); +} + +static void +irc_network_dialog_button_add_clicked_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + EmpathyIrcServer *server; + GtkListStore *store; + GtkTreeIter iter; + GtkTreePath *path; + GtkTreeViewColumn *column; + + store = GTK_LIST_STORE (gtk_tree_view_get_model ( + GTK_TREE_VIEW (dialog->treeview_servers))); + + server = empathy_irc_server_new (_("new server"), 6667, FALSE); + empathy_irc_network_append_server (dialog->network, server); + add_server_to_store (store, server, &iter); + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); + column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), + 0); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->treeview_servers), path, + column, TRUE); + + irc_network_dialog_network_update_buttons (dialog); + + gtk_tree_path_free (path); + g_object_unref (server); +} + +static void +irc_network_dialog_button_remove_clicked_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + EmpathyIrcServer *server; + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (dialog->treeview_servers)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); + + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + empathy_irc_network_remove_server (dialog->network, server); + + irc_network_dialog_network_update_buttons (dialog); + + g_object_unref (server); +} + +static void +irc_network_dialog_button_up_clicked_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter, iter_prev; + GtkTreePath *path; + gint *pos; + EmpathyIrcServer *server; + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (dialog->treeview_servers)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + path = gtk_tree_model_get_path (model, &iter); + + if (!gtk_tree_path_prev (path)) + { + gtk_tree_path_free (path); + return; + } + + gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); + + gtk_tree_model_get_iter (model, &iter_prev, path); + gtk_list_store_swap (GTK_LIST_STORE (model), &iter_prev, &iter); + + pos = gtk_tree_path_get_indices (path); + empathy_irc_network_set_server_position (dialog->network, server, *pos); + + irc_network_dialog_network_update_buttons (dialog); + + g_object_unref (server); + gtk_tree_path_free (path); +} + +static void +irc_network_dialog_button_down_clicked_cb (GtkWidget *widget, + EmpathyIrcNetworkDialog *dialog) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter, iter_prev; + GtkTreePath *path; + EmpathyIrcServer *server; + gint *pos; + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (dialog->treeview_servers)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; + + path = gtk_tree_model_get_path (model, &iter); + + gtk_tree_path_next (path); + if (!gtk_tree_model_get_iter (model, &iter_prev, path)) + { + gtk_tree_path_free (path); + return; + } + + gtk_tree_model_get (model, &iter, COL_SRV_OBJ, &server, -1); + + gtk_list_store_swap (GTK_LIST_STORE (model), &iter_prev, &iter); + + pos = gtk_tree_path_get_indices (path); + empathy_irc_network_set_server_position (dialog->network, server, *pos); + + irc_network_dialog_network_update_buttons (dialog); + + gtk_tree_path_free (path); +} + +static void +irc_network_dialog_selection_changed_cb (GtkTreeSelection *treeselection, + EmpathyIrcNetworkDialog *dialog) +{ + irc_network_dialog_network_update_buttons (dialog); +} + +static void +irc_network_dialog_combobox_charset_changed_cb (GtkWidget *combobox, + EmpathyIrcNetworkDialog *dialog) +{ + const gchar *charset; + + charset = totem_subtitle_encoding_get_selected (GTK_COMBO_BOX (combobox)); + g_object_set (dialog->network, "charset", charset, NULL); +} + +static void +change_network (EmpathyIrcNetworkDialog *dialog, + EmpathyIrcNetwork *network) +{ + GtkListStore *store; + + if (dialog->network == network) + /* No need to change */ + return; + + if (dialog->network != NULL) + { + g_object_unref (dialog->network); + } + + dialog->network = network; + g_object_ref (network); + + store = GTK_LIST_STORE (gtk_tree_view_get_model ( + GTK_TREE_VIEW (dialog->treeview_servers))); + gtk_list_store_clear (store); + + irc_network_dialog_setup (dialog); +} + +/** + * empathy_irc_network_dialog_show: + * @network: the #EmpathyIrcNetwork to configure + * @parent: the parent of this dialog + * + * Display a dialog to configure a given #EmpathyIrcNetwork. + * This function is a singleton so if a configuration dialog already + * exists we use this one to edit the network. + * + * Returns: The displayed #GtkDialog + */ +GtkWidget * +empathy_irc_network_dialog_show (EmpathyIrcNetwork *network, + GtkWidget *parent) +{ + static EmpathyIrcNetworkDialog *dialog = NULL; + GtkBuilder *gui; + GtkListStore *store; + GtkCellRenderer *renderer; + GtkAdjustment *adjustment; + GtkTreeSelection *selection; + GtkTreeViewColumn *column; + GtkWidget *sw, *toolbar; + GtkStyleContext *context; + + g_return_val_if_fail (network != NULL, NULL); + + if (dialog != NULL) + { + change_network (dialog, network); + gtk_window_present (GTK_WINDOW (dialog->dialog)); + + return dialog->dialog; + } + + dialog = g_slice_new0 (EmpathyIrcNetworkDialog); + + dialog->network = network; + g_object_ref (dialog->network); + + gui = empathy_builder_get_resource (ACCOUNT_WIDGETS_RESOURCES_PREFIX "/empathy-account-widget-irc.ui", + "irc_network_dialog", &dialog->dialog, + "button_close", &dialog->button_close, + "entry_network", &dialog->entry_network, + "combobox_charset", &dialog->combobox_charset, + "treeview_servers", &dialog->treeview_servers, + "button_add", &dialog->button_add, + "button_remove", &dialog->button_remove, + "button_up", &dialog->button_up, + "button_down", &dialog->button_down, + "scrolledwindow_network_server", &sw, + "toolbar_network_server", &toolbar, + NULL); + + store = gtk_list_store_new (4, G_TYPE_OBJECT, G_TYPE_STRING, + G_TYPE_UINT, G_TYPE_BOOLEAN); + gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview_servers), + GTK_TREE_MODEL (store)); + g_object_unref (store); + + /* address */ + renderer = gtk_cell_renderer_text_new (); + g_object_set (renderer, "editable", TRUE, NULL); + g_signal_connect (renderer, "edited", + G_CALLBACK (irc_network_dialog_address_edited_cb), dialog); + gtk_tree_view_insert_column_with_attributes ( + GTK_TREE_VIEW (dialog->treeview_servers), + -1, _("Server"), renderer, "text", COL_ADR, + NULL); + column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), + 0); + + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_column_set_expand (column, TRUE); + + /* port */ + adjustment = (GtkAdjustment *) gtk_adjustment_new (6667, 1, G_MAXUINT16, + 1, 10, 0); + renderer = gtk_cell_renderer_spin_new (); + g_object_set (renderer, + "editable", TRUE, + "adjustment", adjustment, + NULL); + g_signal_connect (renderer, "edited", + G_CALLBACK (irc_network_dialog_port_edited_cb), dialog); + + gtk_tree_view_insert_column_with_attributes ( + GTK_TREE_VIEW (dialog->treeview_servers), + -1, _("Port"), renderer, "text", COL_PORT, + NULL); + + column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), + 1); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_column_set_expand (column, TRUE); + + /* SSL */ + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (renderer, "activatable", TRUE, NULL); + g_signal_connect (renderer, "toggled", + G_CALLBACK (irc_network_dialog_ssl_toggled_cb), dialog); + gtk_tree_view_insert_column_with_attributes ( + GTK_TREE_VIEW (dialog->treeview_servers), + -1, _("SSL"), renderer, "active", COL_SSL, + NULL); + + selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (dialog->treeview_servers)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); + + column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_servers), + 2); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + + gtk_tree_view_column_set_expand (column, TRUE); + /* charset */ + totem_subtitle_encoding_init (GTK_COMBO_BOX (dialog->combobox_charset)); + + irc_network_dialog_setup (dialog); + + empathy_builder_connect (gui, dialog, + "irc_network_dialog", "destroy", irc_network_dialog_destroy_cb, + "button_close", "clicked", irc_network_dialog_close_clicked_cb, + "entry_network", "focus-out-event", irc_network_dialog_network_focus_cb, + "button_add", "clicked", irc_network_dialog_button_add_clicked_cb, + "button_remove", "clicked", irc_network_dialog_button_remove_clicked_cb, + "button_up", "clicked", irc_network_dialog_button_up_clicked_cb, + "button_down", "clicked", irc_network_dialog_button_down_clicked_cb, + "combobox_charset", "changed", irc_network_dialog_combobox_charset_changed_cb, + NULL); + + g_object_unref (gui); + + g_object_add_weak_pointer (G_OBJECT (dialog->dialog), + (gpointer) &dialog); + + g_signal_connect (selection, "changed", + G_CALLBACK (irc_network_dialog_selection_changed_cb), + dialog); + + gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), + GTK_WINDOW (parent)); + gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); + + /* join the add/remove toolbar to the treeview */ + context = gtk_widget_get_style_context (sw); + gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); + + context = gtk_widget_get_style_context (toolbar); + gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); + + irc_network_dialog_network_update_buttons (dialog); + gtk_widget_show_all (dialog->dialog); + + gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); + + return dialog->dialog; +} diff --git a/tp-account-widgets/empathy-irc-network-dialog.h b/tp-account-widgets/empathy-irc-network-dialog.h new file mode 100644 index 000000000..a49c63da9 --- /dev/null +++ b/tp-account-widgets/empathy-irc-network-dialog.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007-2008 Guillaume Desmottes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Guillaume Desmottes + */ + +#ifndef __EMPATHY_IRC_NETWORK_DIALOG_H__ +#define __EMPATHY_IRC_NETWORK_DIALOG_H__ + +#include + +#include "empathy-irc-network.h" + +G_BEGIN_DECLS + +GtkWidget * empathy_irc_network_dialog_show (EmpathyIrcNetwork *network, + GtkWidget *parent); + +G_END_DECLS + +#endif /* __EMPATHY_IRC_NETWORK_DIALOG_H__ */ diff --git a/tp-account-widgets/totem-subtitle-encoding.c b/tp-account-widgets/totem-subtitle-encoding.c new file mode 100644 index 000000000..2db1c23c0 --- /dev/null +++ b/tp-account-widgets/totem-subtitle-encoding.c @@ -0,0 +1,584 @@ +/* + * Copyright (C) 2001-2006 Bastien Nocera + * + * encoding list copied from gnome-terminal/encoding.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The Totem project hereby grant permission for non-gpl compatible GStreamer + * plugins to be used and distributed together with GStreamer and Totem. This + * permission are above and beyond the permissions granted by the GPL license + * Totem is covered by. + * + * Monday 7th February 2005: Christian Schaller: Add exception clause. + * See license_change file for details. + * + */ + +#include "config.h" +#include +#include "totem-subtitle-encoding.h" + +typedef enum +{ + SUBTITLE_ENCODING_CURRENT_LOCALE, + + SUBTITLE_ENCODING_ISO_8859_6, + SUBTITLE_ENCODING_IBM_864, + SUBTITLE_ENCODING_MAC_ARABIC, + SUBTITLE_ENCODING_WINDOWS_1256, + + SUBTITLE_ENCODING_ARMSCII_8, + + SUBTITLE_ENCODING_ISO_8859_4, + SUBTITLE_ENCODING_ISO_8859_13, + SUBTITLE_ENCODING_WINDOWS_1257, + + SUBTITLE_ENCODING_ISO_8859_14, + + SUBTITLE_ENCODING_ISO_8859_2, + SUBTITLE_ENCODING_IBM_852, + SUBTITLE_ENCODING_MAC_CE, + SUBTITLE_ENCODING_WINDOWS_1250, + + SUBTITLE_ENCODING_GB18030, + SUBTITLE_ENCODING_GB2312, + SUBTITLE_ENCODING_GBK, + SUBTITLE_ENCODING_HZ, + + SUBTITLE_ENCODING_BIG5, + SUBTITLE_ENCODING_BIG5_HKSCS, + SUBTITLE_ENCODING_EUC_TW, + + SUBTITLE_ENCODING_MAC_CROATIAN, + + SUBTITLE_ENCODING_ISO_8859_5, + SUBTITLE_ENCODING_IBM_855, + SUBTITLE_ENCODING_ISO_IR_111, + SUBTITLE_ENCODING_KOI8_R, + SUBTITLE_ENCODING_MAC_CYRILLIC, + SUBTITLE_ENCODING_WINDOWS_1251, + + SUBTITLE_ENCODING_CP_866, + + SUBTITLE_ENCODING_MAC_UKRAINIAN, + SUBTITLE_ENCODING_KOI8_U, + + SUBTITLE_ENCODING_GEOSTD8, + + SUBTITLE_ENCODING_ISO_8859_7, + SUBTITLE_ENCODING_MAC_GREEK, + SUBTITLE_ENCODING_WINDOWS_1253, + + SUBTITLE_ENCODING_MAC_GUJARATI, + + SUBTITLE_ENCODING_MAC_GURMUKHI, + + SUBTITLE_ENCODING_ISO_8859_8_I, + SUBTITLE_ENCODING_IBM_862, + SUBTITLE_ENCODING_MAC_HEBREW, + SUBTITLE_ENCODING_WINDOWS_1255, + + SUBTITLE_ENCODING_ISO_8859_8, + + SUBTITLE_ENCODING_MAC_DEVANAGARI, + + SUBTITLE_ENCODING_MAC_ICELANDIC, + + SUBTITLE_ENCODING_EUC_JP, + SUBTITLE_ENCODING_ISO_2022_JP, + SUBTITLE_ENCODING_SHIFT_JIS, + + SUBTITLE_ENCODING_EUC_KR, + SUBTITLE_ENCODING_ISO_2022_KR, + SUBTITLE_ENCODING_JOHAB, + SUBTITLE_ENCODING_UHC, + + SUBTITLE_ENCODING_ISO_8859_10, + + SUBTITLE_ENCODING_MAC_FARSI, + + SUBTITLE_ENCODING_ISO_8859_16, + SUBTITLE_ENCODING_MAC_ROMANIAN, + + SUBTITLE_ENCODING_ISO_8859_3, + + SUBTITLE_ENCODING_TIS_620, + + SUBTITLE_ENCODING_ISO_8859_9, + SUBTITLE_ENCODING_IBM_857, + SUBTITLE_ENCODING_MAC_TURKISH, + SUBTITLE_ENCODING_WINDOWS_1254, + + SUBTITLE_ENCODING_UTF_7, + SUBTITLE_ENCODING_UTF_8, + SUBTITLE_ENCODING_UTF_16, + SUBTITLE_ENCODING_UCS_2, + SUBTITLE_ENCODING_UCS_4, + + SUBTITLE_ENCODING_ISO_8859_1, + SUBTITLE_ENCODING_ISO_8859_15, + SUBTITLE_ENCODING_IBM_850, + SUBTITLE_ENCODING_MAC_ROMAN, + SUBTITLE_ENCODING_WINDOWS_1252, + + SUBTITLE_ENCODING_TCVN, + SUBTITLE_ENCODING_VISCII, + SUBTITLE_ENCODING_WINDOWS_1258, + + SUBTITLE_ENCODING_LAST +} SubtitleEncodingIndex; + + +typedef struct +{ + int index; + gboolean valid; + const char *charset; + const char *name; +} SubtitleEncoding; + + +static SubtitleEncoding encodings[] = { + + {SUBTITLE_ENCODING_CURRENT_LOCALE, TRUE, + NULL, N_("Current Locale")}, + + {SUBTITLE_ENCODING_ISO_8859_6, FALSE, + "ISO-8859-6", N_("Arabic")}, + {SUBTITLE_ENCODING_IBM_864, FALSE, + "IBM864", N_("Arabic")}, + {SUBTITLE_ENCODING_MAC_ARABIC, FALSE, + "MAC_ARABIC", N_("Arabic")}, + {SUBTITLE_ENCODING_WINDOWS_1256, FALSE, + "WINDOWS-1256", N_("Arabic")}, + + {SUBTITLE_ENCODING_ARMSCII_8, FALSE, + "ARMSCII-8", N_("Armenian")}, + + {SUBTITLE_ENCODING_ISO_8859_4, FALSE, + "ISO-8859-4", N_("Baltic")}, + {SUBTITLE_ENCODING_ISO_8859_13, FALSE, + "ISO-8859-13", N_("Baltic")}, + {SUBTITLE_ENCODING_WINDOWS_1257, FALSE, + "WINDOWS-1257", N_("Baltic")}, + + {SUBTITLE_ENCODING_ISO_8859_14, FALSE, + "ISO-8859-14", N_("Celtic")}, + + {SUBTITLE_ENCODING_ISO_8859_2, FALSE, + "ISO-8859-2", N_("Central European")}, + {SUBTITLE_ENCODING_IBM_852, FALSE, + "IBM852", N_("Central European")}, + {SUBTITLE_ENCODING_MAC_CE, FALSE, + "MAC_CE", N_("Central European")}, + {SUBTITLE_ENCODING_WINDOWS_1250, FALSE, + "WINDOWS-1250", N_("Central European")}, + + {SUBTITLE_ENCODING_GB18030, FALSE, + "GB18030", N_("Chinese Simplified")}, + {SUBTITLE_ENCODING_GB2312, FALSE, + "GB2312", N_("Chinese Simplified")}, + {SUBTITLE_ENCODING_GBK, FALSE, + "GBK", N_("Chinese Simplified")}, + {SUBTITLE_ENCODING_HZ, FALSE, + "HZ", N_("Chinese Simplified")}, + + {SUBTITLE_ENCODING_BIG5, FALSE, + "BIG5", N_("Chinese Traditional")}, + {SUBTITLE_ENCODING_BIG5_HKSCS, FALSE, + "BIG5-HKSCS", N_("Chinese Traditional")}, + {SUBTITLE_ENCODING_EUC_TW, FALSE, + "EUC-TW", N_("Chinese Traditional")}, + + {SUBTITLE_ENCODING_MAC_CROATIAN, FALSE, + "MAC_CROATIAN", N_("Croatian")}, + + {SUBTITLE_ENCODING_ISO_8859_5, FALSE, + "ISO-8859-5", N_("Cyrillic")}, + {SUBTITLE_ENCODING_IBM_855, FALSE, + "IBM855", N_("Cyrillic")}, + {SUBTITLE_ENCODING_ISO_IR_111, FALSE, + "ISO-IR-111", N_("Cyrillic")}, + {SUBTITLE_ENCODING_KOI8_R, FALSE, + "KOI8-R", N_("Cyrillic")}, + {SUBTITLE_ENCODING_MAC_CYRILLIC, FALSE, + "MAC-CYRILLIC", N_("Cyrillic")}, + {SUBTITLE_ENCODING_WINDOWS_1251, FALSE, + "WINDOWS-1251", N_("Cyrillic")}, + + {SUBTITLE_ENCODING_CP_866, FALSE, + "CP866", N_("Cyrillic/Russian")}, + + {SUBTITLE_ENCODING_MAC_UKRAINIAN, FALSE, + "MAC_UKRAINIAN", N_("Cyrillic/Ukrainian")}, + {SUBTITLE_ENCODING_KOI8_U, FALSE, + "KOI8-U", N_("Cyrillic/Ukrainian")}, + + {SUBTITLE_ENCODING_GEOSTD8, FALSE, + "GEORGIAN-PS", N_("Georgian")}, + + {SUBTITLE_ENCODING_ISO_8859_7, FALSE, + "ISO-8859-7", N_("Greek")}, + {SUBTITLE_ENCODING_MAC_GREEK, FALSE, + "MAC_GREEK", N_("Greek")}, + {SUBTITLE_ENCODING_WINDOWS_1253, FALSE, + "WINDOWS-1253", N_("Greek")}, + + {SUBTITLE_ENCODING_MAC_GUJARATI, FALSE, + "MAC_GUJARATI", N_("Gujarati")}, + + {SUBTITLE_ENCODING_MAC_GURMUKHI, FALSE, + "MAC_GURMUKHI", N_("Gurmukhi")}, + + {SUBTITLE_ENCODING_ISO_8859_8_I, FALSE, + "ISO-8859-8-I", N_("Hebrew")}, + {SUBTITLE_ENCODING_IBM_862, FALSE, + "IBM862", N_("Hebrew")}, + {SUBTITLE_ENCODING_MAC_HEBREW, FALSE, + "MAC_HEBREW", N_("Hebrew")}, + {SUBTITLE_ENCODING_WINDOWS_1255, FALSE, + "WINDOWS-1255", N_("Hebrew")}, + + {SUBTITLE_ENCODING_ISO_8859_8, FALSE, + "ISO-8859-8", N_("Hebrew Visual")}, + + {SUBTITLE_ENCODING_MAC_DEVANAGARI, FALSE, + "MAC_DEVANAGARI", N_("Hindi")}, + + {SUBTITLE_ENCODING_MAC_ICELANDIC, FALSE, + "MAC_ICELANDIC", N_("Icelandic")}, + + {SUBTITLE_ENCODING_EUC_JP, FALSE, + "EUC-JP", N_("Japanese")}, + {SUBTITLE_ENCODING_ISO_2022_JP, FALSE, + "ISO2022JP", N_("Japanese")}, + {SUBTITLE_ENCODING_SHIFT_JIS, FALSE, + "SHIFT-JIS", N_("Japanese")}, + + {SUBTITLE_ENCODING_EUC_KR, FALSE, + "EUC-KR", N_("Korean")}, + {SUBTITLE_ENCODING_ISO_2022_KR, FALSE, + "ISO2022KR", N_("Korean")}, + {SUBTITLE_ENCODING_JOHAB, FALSE, + "JOHAB", N_("Korean")}, + {SUBTITLE_ENCODING_UHC, FALSE, + "UHC", N_("Korean")}, + + {SUBTITLE_ENCODING_ISO_8859_10, FALSE, + "ISO-8859-10", N_("Nordic")}, + + {SUBTITLE_ENCODING_MAC_FARSI, FALSE, + "MAC_FARSI", N_("Persian")}, + + {SUBTITLE_ENCODING_ISO_8859_16, FALSE, + "ISO-8859-16", N_("Romanian")}, + {SUBTITLE_ENCODING_MAC_ROMANIAN, FALSE, + "MAC_ROMANIAN", N_("Romanian")}, + + {SUBTITLE_ENCODING_ISO_8859_3, FALSE, + "ISO-8859-3", N_("South European")}, + + {SUBTITLE_ENCODING_TIS_620, FALSE, + "TIS-620", N_("Thai")}, + + {SUBTITLE_ENCODING_ISO_8859_9, FALSE, + "ISO-8859-9", N_("Turkish")}, + {SUBTITLE_ENCODING_IBM_857, FALSE, + "IBM857", N_("Turkish")}, + {SUBTITLE_ENCODING_MAC_TURKISH, FALSE, + "MAC_TURKISH", N_("Turkish")}, + {SUBTITLE_ENCODING_WINDOWS_1254, FALSE, + "WINDOWS-1254", N_("Turkish")}, + + {SUBTITLE_ENCODING_UTF_7, FALSE, + "UTF-7", N_("Unicode")}, + {SUBTITLE_ENCODING_UTF_8, FALSE, + "UTF-8", N_("Unicode")}, + {SUBTITLE_ENCODING_UTF_16, FALSE, + "UTF-16", N_("Unicode")}, + {SUBTITLE_ENCODING_UCS_2, FALSE, + "UCS-2", N_("Unicode")}, + {SUBTITLE_ENCODING_UCS_4, FALSE, + "UCS-4", N_("Unicode")}, + + {SUBTITLE_ENCODING_ISO_8859_1, FALSE, + "ISO-8859-1", N_("Western")}, + {SUBTITLE_ENCODING_ISO_8859_15, FALSE, + "ISO-8859-15", N_("Western")}, + {SUBTITLE_ENCODING_IBM_850, FALSE, + "IBM850", N_("Western")}, + {SUBTITLE_ENCODING_MAC_ROMAN, FALSE, + "MAC_ROMAN", N_("Western")}, + {SUBTITLE_ENCODING_WINDOWS_1252, FALSE, + "WINDOWS-1252", N_("Western")}, + + {SUBTITLE_ENCODING_TCVN, FALSE, + "TCVN", N_("Vietnamese")}, + {SUBTITLE_ENCODING_VISCII, FALSE, + "VISCII", N_("Vietnamese")}, + {SUBTITLE_ENCODING_WINDOWS_1258, FALSE, + "WINDOWS-1258", N_("Vietnamese")} +}; + +static const SubtitleEncoding * +find_encoding_by_charset (const char *charset) +{ + int i; + + i = 1; /* skip current locale */ + while (i < SUBTITLE_ENCODING_LAST) { + if (strcasecmp (charset, encodings[i].charset) == 0) + return &encodings[i]; + + ++i; + } + + if (strcasecmp (charset, + encodings[SUBTITLE_ENCODING_CURRENT_LOCALE].charset) == 0) + return &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; + + return NULL; +} + +static void +subtitle_encoding_init (void) +{ + int i; + gsize bytes_read, bytes_written; + gchar *converted; + gchar ascii_sample[96]; + + g_get_charset ((const char **) + &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE].charset); + + g_assert (G_N_ELEMENTS (encodings) == SUBTITLE_ENCODING_LAST); + + /* Initialize the sample text with all of the printing ASCII characters + * from space (32) to the tilde (126), 95 in all. */ + for (i = 0; i < (int) sizeof (ascii_sample); i++) + ascii_sample[i] = i + 32; + + ascii_sample[sizeof (ascii_sample) - 1] = '\0'; + + i = 0; + while (i < SUBTITLE_ENCODING_LAST) { + bytes_read = 0; + bytes_written = 0; + + g_assert (encodings[i].index == i); + + /* Translate the names */ + encodings[i].name = _(encodings[i].name); + + /* Test that the encoding is a proper superset of ASCII (which naive + * apps are going to use anyway) by attempting to validate the text + * using the current encoding. This also flushes out any encodings + * which the underlying GIConv implementation can't support. + */ + converted = g_convert (ascii_sample, sizeof (ascii_sample) - 1, + encodings[i].charset, encodings[i].charset, + &bytes_read, &bytes_written, NULL); + + /* The encoding is only valid if ASCII passes through cleanly. */ + if (i == SUBTITLE_ENCODING_CURRENT_LOCALE) + encodings[i].valid = TRUE; + else + encodings[i].valid = + (bytes_read == (sizeof (ascii_sample) - 1)) && + (converted != NULL) && (strcmp (converted, ascii_sample) == 0); + +#ifdef DEBUG_ENCODINGS + if (!encodings[i].valid) { + g_print ("Rejecting encoding %s as invalid:\n", encodings[i].charset); + g_print (" input \"%s\"\n", ascii_sample); + g_print (" output \"%s\"\n\n", converted ? converted : "(null)"); + } +#endif + + /* Discard the converted string. */ + g_free (converted); + + ++i; + } +} + +static int +subtitle_encoding_get_index (const char *charset) +{ + const SubtitleEncoding *e; + + e = find_encoding_by_charset (charset); + if (e != NULL) + return e->index; + else + return SUBTITLE_ENCODING_CURRENT_LOCALE; +} + +static const char * +subtitle_encoding_get_charset (int index_) +{ + const SubtitleEncoding *e; + + if (index_ >= SUBTITLE_ENCODING_LAST) + e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; + else if (index_ < SUBTITLE_ENCODING_CURRENT_LOCALE) + e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; + else if (!encodings[index_].valid) + e = &encodings[SUBTITLE_ENCODING_CURRENT_LOCALE]; + else + e = &encodings[index_]; + return e->charset; +} + +enum +{ + INDEX_COL, + NAME_COL +}; + +static gint +compare (GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer data) +{ + gchar *str_a, *str_b; + gint result; + + gtk_tree_model_get (model, a, NAME_COL, &str_a, -1); + gtk_tree_model_get (model, b, NAME_COL, &str_b, -1); + + result = strcmp (str_a, str_b); + + g_free (str_a); + g_free (str_b); + + return result; +} + +static void +is_encoding_sensitive (GtkCellLayout * cell_layout, + GtkCellRenderer * cell, + GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data) +{ + + gboolean sensitive; + + sensitive = !gtk_tree_model_iter_has_child (tree_model, iter); + g_object_set (cell, "sensitive", sensitive, NULL); +} + +static GtkTreeModel * +subtitle_encoding_create_store (void) +{ + gchar *label; + const gchar *lastlang = ""; + GtkTreeIter iter, iter2; + GtkTreeStore *store; + int i; + + store = gtk_tree_store_new (2, G_TYPE_INT, G_TYPE_STRING); + + for (i = 0; i < SUBTITLE_ENCODING_LAST; i++) { + if (encodings[i].valid) { + if (strcmp (lastlang, encodings[i].name)) { + lastlang = encodings[i].name; + gtk_tree_store_append (store, &iter, NULL); + gtk_tree_store_set (store, &iter, INDEX_COL, + -1, NAME_COL, lastlang, -1); + } + label = g_strdup_printf("%s (%s)", lastlang, encodings[i].charset); + gtk_tree_store_append (store, &iter2, &iter); + gtk_tree_store_set (store, &iter2, INDEX_COL, + encodings[i].index, NAME_COL, label, -1); + g_free(label); + } + } + gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), + compare, NULL, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), + NAME_COL, GTK_SORT_ASCENDING); + return GTK_TREE_MODEL (store); +} + +static void +subtitle_encoding_combo_render (GtkComboBox * combo) +{ + GtkCellRenderer *renderer; + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, + "text", NAME_COL, NULL); + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), + renderer, is_encoding_sensitive, NULL, NULL); +} + +const char * +totem_subtitle_encoding_get_selected (GtkComboBox * combo) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint index_ = -1; + + model = gtk_combo_box_get_model (combo); + if (gtk_combo_box_get_active_iter (combo, &iter)) { + gtk_tree_model_get (model, &iter, INDEX_COL, &index_, -1); + } + if (index_ == -1) + return NULL; + return subtitle_encoding_get_charset (index_); +} + +void +totem_subtitle_encoding_set (GtkComboBox * combo, const char *encoding) +{ + GtkTreeModel *model; + GtkTreeIter iter, iter2; + gint index_, i; + + g_return_if_fail (encoding != NULL); + + model = gtk_combo_box_get_model (combo); + index_ = subtitle_encoding_get_index (encoding); + gtk_tree_model_get_iter_first (model, &iter); + do { + if (!gtk_tree_model_iter_has_child (model, &iter)) + continue; + if (!gtk_tree_model_iter_children (model, &iter2, &iter)) + continue; + do { + gtk_tree_model_get (model, &iter2, INDEX_COL, &i, -1); + if (i == index_) + break; + } while (gtk_tree_model_iter_next (model, &iter2)); + if (i == index_) + break; + } while (gtk_tree_model_iter_next (model, &iter)); + gtk_combo_box_set_active_iter (combo, &iter2); +} + +void +totem_subtitle_encoding_init (GtkComboBox *combo) +{ + GtkTreeModel *model; + subtitle_encoding_init (); + model = subtitle_encoding_create_store (); + gtk_combo_box_set_model (combo, model); + g_object_unref (model); + subtitle_encoding_combo_render (combo); +} + +/* + * vim: sw=2 ts=8 cindent noai bs=2 + */ diff --git a/tp-account-widgets/totem-subtitle-encoding.h b/tp-account-widgets/totem-subtitle-encoding.h new file mode 100644 index 000000000..656c0dec5 --- /dev/null +++ b/tp-account-widgets/totem-subtitle-encoding.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2001-2006 Bastien Nocera + * + * encoding list copied from gnome-terminal/encoding.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The Totem project hereby grant permission for non-gpl compatible GStreamer + * plugins to be used and distributed together with GStreamer and Totem. This + * permission are above and beyond the permissions granted by the GPL license + * Totem is covered by. + * + * Monday 7th February 2005: Christian Schaller: Add exception clause. + * See license_change file for details. + * + */ + +/* Encoding stuff */ + +#ifndef TOTEM_SUBTITLE_ENCODING_H +#define TOTEM_SUBTITLE_ENCODING_H + +#include + +void totem_subtitle_encoding_init (GtkComboBox *combo); +void totem_subtitle_encoding_set (GtkComboBox *combo, const char *encoding); +const char * totem_subtitle_encoding_get_selected (GtkComboBox *combo); + +#endif /* SUBTITLE_ENCODING_H */ -- cgit v1.2.3