]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-account-widget-irc.c
Use a flat namespace for internal includes
[empathy.git] / libempathy-gtk / empathy-account-widget-irc.c
index 6cb1e22ddaeb57fc1c4b616d2cb0a162f50719d7..e0647a9b850a43f7ec0d65116f9b3134c49ec135 100644 (file)
 
 #include "config.h"
 
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-
-#include <libempathy/empathy-utils.h>
-
-#include "empathy-irc-network-dialog.h"
-#include "empathy-irc-network-chooser.h"
-#include "empathy-account-widget.h"
 #include "empathy-account-widget-private.h"
 #include "empathy-account-widget-irc.h"
 #include "empathy-ui-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 typedef struct {
   EmpathyAccountWidget *self;
@@ -57,39 +45,37 @@ account_widget_irc_destroy_cb (GtkWidget *widget,
 static void
 account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
 {
-  const gchar *nick = NULL;
-  const gchar *fullname = NULL;
-  gint port = 6667;
-  const gchar *charset;
-  gboolean ssl = FALSE;
+  gchar *nick = NULL;
+  gchar *fullname = NULL;
   EmpathyAccountSettings *ac_settings;
 
   g_object_get (settings->self, "settings", &ac_settings, NULL);
 
-  nick = empathy_account_settings_get_string (ac_settings, "account");
-  fullname = empathy_account_settings_get_string (ac_settings,
+  nick = empathy_account_settings_dup_string (ac_settings, "account");
+  fullname = empathy_account_settings_dup_string (ac_settings,
       "fullname");
-  charset = empathy_account_settings_get_string (ac_settings, "charset");
-  port = empathy_account_settings_get_uint32 (ac_settings, "port");
-  ssl = empathy_account_settings_get_boolean (ac_settings, "use-ssl");
 
-  if (!nick)
+  if (nick == NULL)
     {
       nick = g_strdup (g_get_user_name ());
-      empathy_account_settings_set_string (ac_settings,
-        "account", nick);
+
+      empathy_account_settings_set (ac_settings,
+        "account", g_variant_new_string (nick));
     }
 
-  if (!fullname)
+  if (fullname == NULL)
     {
       fullname = g_strdup (g_get_real_name ());
-      if (!fullname)
-        {
+
+      if (fullname == NULL)
           fullname = g_strdup (nick);
-        }
-      empathy_account_settings_set_string (ac_settings,
-          "fullname", fullname);
+
+      empathy_account_settings_set (ac_settings,
+          "fullname", g_variant_new_string (fullname));
     }
+
+  g_free (nick);
+  g_free (fullname);
 }
 
 static void
@@ -99,21 +85,68 @@ network_changed_cb (EmpathyIrcNetworkChooser *chooser,
   empathy_account_widget_changed (settings->self);
 }
 
-void
+/**
+ * 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 **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_file (filename,
+  self->ui_details->gui = empathy_builder_get_resource (filename,
       "table_irc_settings", table_common_settings,
-      "vbox_irc", &self->ui_details->widget,
+      "vbox_irc", box,
       "table_irc_settings", &settings->vbox_settings,
+      "entry_password", &entry_password,
       NULL);
 
   /* Add network chooser button */
@@ -124,8 +157,8 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self,
   g_signal_connect (settings->network_chooser, "changed",
       G_CALLBACK (network_changed_cb), settings);
 
-  gtk_table_attach (GTK_TABLE (*table_common_settings),
-      settings->network_chooser, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
+  gtk_grid_attach (GTK_GRID (*table_common_settings),
+      settings->network_chooser, 1, 0, 1, 1);
 
   gtk_widget_show (settings->network_chooser);
 
@@ -136,6 +169,7 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self,
       "entry_fullname", "fullname",
       "entry_password", "password",
       "entry_quit_message", "quit-message",
+      "entry_username", "username",
       NULL);
 
   empathy_builder_connect (self->ui_details->gui, settings,
@@ -145,11 +179,28 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self,
   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);
 }
 
-void
+EmpathyIrcNetworkChooser *
 empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self,
-    const char *filename)
+    const char *filename,
+    GtkWidget **box)
 {
   EmpathyAccountWidgetIrc *settings;
   EmpathyAccountSettings *ac_settings;
@@ -158,8 +209,8 @@ empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self,
   settings = g_slice_new0 (EmpathyAccountWidgetIrc);
   settings->self = self;
 
-  self->ui_details->gui = empathy_builder_get_file (filename,
-      "vbox_irc_simple", &self->ui_details->widget,
+  self->ui_details->gui = empathy_builder_get_resource (filename,
+      "vbox_irc_simple", box,
       "alignment_network_simple", &alignment,
       NULL);
 
@@ -186,4 +237,6 @@ empathy_account_widget_irc_build_simple (EmpathyAccountWidget *self,
   self->ui_details->default_focus = g_strdup ("entry_nick_simple");
 
   g_object_unref (ac_settings);
+
+  return EMPATHY_IRC_NETWORK_CHOOSER (settings->network_chooser);
 }