aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/Makefile.am2
-rw-r--r--libempathy-gtk/empathy-irc-network-chooser.c299
-rw-r--r--libempathy-gtk/empathy-irc-network-chooser.h61
3 files changed, 362 insertions, 0 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index de6cba2f1..15e187c07 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -63,6 +63,7 @@ libempathy_gtk_handwritten_source = \
empathy-individual-store.c \
empathy-individual-view.c \
empathy-individual-widget.c \
+ empathy-irc-network-chooser.c \
empathy-irc-network-dialog.c \
empathy-kludge-label.c \
empathy-log-window.c \
@@ -123,6 +124,7 @@ libempathy_gtk_headers = \
empathy-individual-store.h \
empathy-individual-view.h \
empathy-individual-widget.h \
+ empathy-irc-network-chooser.h \
empathy-irc-network-dialog.h \
empathy-kludge-label.h \
empathy-log-window.h \
diff --git a/libempathy-gtk/empathy-irc-network-chooser.c b/libempathy-gtk/empathy-irc-network-chooser.c
new file mode 100644
index 000000000..768abe2d6
--- /dev/null
+++ b/libempathy-gtk/empathy-irc-network-chooser.c
@@ -0,0 +1,299 @@
+/*
+ * 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 <gdesmott@gnome.org>
+ */
+
+#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 <libempathy/empathy-irc-network-manager.h>
+
+#include "empathy-irc-network-dialog.h"
+#include "empathy-ui-utils.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC
+#include <libempathy/empathy-debug.h>
+
+#include "empathy-irc-network-chooser.h"
+
+#define DEFAULT_IRC_NETWORK "irc.gimp.org"
+
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkChooser)
+
+enum {
+ PROP_SETTINGS = 1
+};
+
+typedef struct {
+ EmpathyAccountSettings *settings;
+
+ EmpathyIrcNetworkManager *network_manager;
+ /* 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 void
+update_server_params (EmpathyIrcNetworkChooser *self)
+{
+ EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self);
+ GSList *servers;
+ gchar *charset;
+
+ g_assert (priv->network != NULL);
+
+ g_object_get (priv->network, "charset", &charset, NULL);
+ DEBUG ("Setting charset to %s", charset);
+ empathy_account_settings_set_string (priv->settings, "charset", charset);
+ g_free (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;
+
+ g_object_get (server,
+ "address", &address,
+ "port", &port,
+ "ssl", &ssl,
+ NULL);
+
+ DEBUG ("Setting server to %s", address);
+ empathy_account_settings_set_string (priv->settings, "server", address);
+ DEBUG ("Setting port to %u", port);
+ empathy_account_settings_set_uint32 (priv->settings, "port", port);
+ DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" );
+ empathy_account_settings_set_boolean (priv->settings, "use-ssl", ssl);
+
+ g_free (address);
+ }
+ 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);
+ gchar *name;
+
+ g_assert (priv->network != NULL);
+ g_object_get (priv->network, "name", &name, NULL);
+
+ gtk_button_set_label (GTK_BUTTON (self), name);
+ g_free (name);
+}
+
+static void
+set_label_from_settings (EmpathyIrcNetworkChooser *self)
+{
+ EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self);
+ const gchar *server;
+
+ tp_clear_object (&priv->network);
+
+ server = empathy_account_settings_get_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);
+ return;
+ }
+
+ /* Set default network */
+ priv->network = empathy_irc_network_manager_find_network_by_address (
+ priv->network_manager, DEFAULT_IRC_NETWORK);
+ g_assert (priv->network != NULL);
+
+ set_label (self);
+ update_server_params (self);
+ g_object_ref (priv->network);
+}
+
+static void
+clicked_cb (GtkButton *button,
+ gpointer user_data)
+{
+ /* TODO: open edit 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));
+
+ 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);
+}
diff --git a/libempathy-gtk/empathy-irc-network-chooser.h b/libempathy-gtk/empathy-irc-network-chooser.h
new file mode 100644
index 000000000..442ac2d53
--- /dev/null
+++ b/libempathy-gtk/empathy-irc-network-chooser.h
@@ -0,0 +1,61 @@
+/*
+ * 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 <gdesmott@gnome.org>
+ */
+
+#ifndef __EMPATHY_IRC_NETWORK_CHOOSER_H__
+#define __EMPATHY_IRC_NETWORK_CHOOSER_H__
+
+#include <gtk/gtk.h>
+
+#include <libempathy/empathy-account-settings.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;
+
+ /*<private>*/
+ 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);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_IRC_NETWORK_CHOOSER_H__ */