aboutsummaryrefslogtreecommitdiffstats
path: root/tp-account-widgets/empathy-account-widget-irc.c
diff options
context:
space:
mode:
authorEmanuele Aina <emanuele.aina@collabora.com>2013-03-25 23:38:16 +0800
committerMarco Barisione <marco.barisione@collabora.co.uk>2013-08-20 18:03:04 +0800
commit5cbc27ef0f4373175af5725d1a0b78d464bb23b3 (patch)
tree377bc6c4903fc0d159a75d7b5d1facc2f53a7308 /tp-account-widgets/empathy-account-widget-irc.c
parent80a78928abd6a5c581e6c0e6036d3e7aea31d7ad (diff)
downloadgsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar.gz
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar.bz2
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar.lz
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar.xz
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.tar.zst
gsoc2013-empathy-5cbc27ef0f4373175af5725d1a0b78d464bb23b3.zip
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
Diffstat (limited to 'tp-account-widgets/empathy-account-widget-irc.c')
-rw-r--r--tp-account-widgets/empathy-account-widget-irc.c242
1 files changed, 242 insertions, 0 deletions
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 <gdesmott@gnome.org>
+ */
+
+#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);
+}