aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-account-widget-irc.c405
-rw-r--r--libempathy-gtk/empathy-account-widget-irc.ui78
2 files changed, 24 insertions, 459 deletions
diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c
index f98d54bbd..4b41c6e47 100644
--- a/libempathy-gtk/empathy-account-widget-irc.c
+++ b/libempathy-gtk/empathy-account-widget-irc.c
@@ -28,9 +28,9 @@
#include <gtk/gtk.h>
#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-irc-network-manager.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"
@@ -39,304 +39,29 @@
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC
#include <libempathy/empathy-debug.h>
-#define IRC_NETWORKS_FILENAME "irc-networks.xml"
-#define DEFAULT_IRC_NETWORK "irc.gimp.org"
-
typedef struct {
EmpathyAccountWidget *self;
- EmpathyIrcNetworkManager *network_manager;
GtkWidget *vbox_settings;
- GtkWidget *combobox_network;
+ GtkWidget *network_chooser;
} EmpathyAccountWidgetIrc;
-enum {
- COL_NETWORK_OBJ,
- COL_NETWORK_NAME,
-};
-
static void
account_widget_irc_destroy_cb (GtkWidget *widget,
EmpathyAccountWidgetIrc *settings)
{
- g_object_unref (settings->network_manager);
g_slice_free (EmpathyAccountWidgetIrc, settings);
}
static void
-unset_server_params (EmpathyAccountWidgetIrc *settings)
-{
- EmpathyAccountSettings *ac_settings;
-
- g_object_get (settings->self, "settings", &ac_settings, NULL);
- DEBUG ("Unset server, port and use-ssl");
- empathy_account_settings_unset (ac_settings, "server");
- empathy_account_settings_unset (ac_settings, "port");
- empathy_account_settings_unset (ac_settings, "use-ssl");
-}
-
-static void
-update_server_params (EmpathyAccountWidgetIrc *settings)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- EmpathyIrcNetwork *network;
- GSList *servers;
- gchar *charset;
- EmpathyAccountSettings *ac_settings;
-
- g_object_get (settings->self, "settings", &ac_settings, NULL);
-
- if (!gtk_combo_box_get_active_iter (
- GTK_COMBO_BOX (settings->combobox_network), &iter))
- {
- unset_server_params (settings);
- return;
- }
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1);
-
- g_assert (network != NULL);
-
- g_object_get (network, "charset", &charset, NULL);
- DEBUG ("Setting charset to %s", charset);
- empathy_account_settings_set_string (ac_settings, "charset", charset);
- g_free (charset);
-
- servers = empathy_irc_network_get_servers (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 (ac_settings, "server", address);
- DEBUG ("Setting port to %u", port);
- empathy_account_settings_set_uint32 (ac_settings, "port", port);
- DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" );
- empathy_account_settings_set_boolean (ac_settings, "use-ssl", ssl);
-
- g_free (address);
- }
- else
- {
- /* No server. Unset values */
- unset_server_params (settings);
- }
-
- g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
- g_slist_free (servers);
- g_object_unref (network);
-}
-
-static void
-irc_network_dialog_destroy_cb (GtkWidget *widget,
- EmpathyAccountWidgetIrc *settings)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- EmpathyIrcNetwork *network;
- gchar *name;
-
- /* name could be changed */
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (settings->combobox_network),
- &iter);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1);
-
- g_object_get (network, "name", &name, NULL);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- COL_NETWORK_NAME, name, -1);
-
- update_server_params (settings);
- empathy_account_widget_changed (settings->self);
-
- g_object_unref (network);
- g_free (name);
-}
-
-static void
-display_irc_network_dialog (EmpathyAccountWidgetIrc *settings,
- EmpathyIrcNetwork *network)
-{
- GtkWindow *window;
- GtkWidget *dialog;
-
- window = empathy_get_toplevel_window (settings->vbox_settings);
- dialog = empathy_irc_network_dialog_show (network, GTK_WIDGET (window));
- g_signal_connect (dialog, "destroy",
- G_CALLBACK (irc_network_dialog_destroy_cb), settings);
-}
-
-static void
-account_widget_irc_button_edit_network_clicked_cb (
- GtkWidget *button,
- EmpathyAccountWidgetIrc *settings)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- EmpathyIrcNetwork *network;
-
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (settings->combobox_network),
- &iter);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1);
-
- g_assert (network != NULL);
-
- display_irc_network_dialog (settings, network);
-
- g_object_unref (network);
-}
-
-static void
-account_widget_irc_button_remove_clicked_cb (GtkWidget *button,
- EmpathyAccountWidgetIrc *settings)
-{
- EmpathyIrcNetwork *network;
- GtkTreeIter iter;
- GtkTreeModel *model;
- gchar *name;
-
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (settings->combobox_network),
- &iter);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- gtk_tree_model_get (model, &iter, COL_NETWORK_OBJ, &network, -1);
-
- g_assert (network != NULL);
-
- g_object_get (network, "name", &name, NULL);
- DEBUG ("Remove network %s", name);
-
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
- empathy_irc_network_manager_remove (settings->network_manager, network);
-
- /* Select the first network */
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- gtk_combo_box_set_active_iter (
- GTK_COMBO_BOX (settings->combobox_network), &iter);
- }
-
- g_free (name);
- g_object_unref (network);
-}
-
-static void
-account_widget_irc_button_add_network_clicked_cb (GtkWidget *button,
- EmpathyAccountWidgetIrc *settings)
-{
- EmpathyIrcNetwork *network;
- GtkTreeModel *model;
- GtkListStore *store;
- gchar *name;
- GtkTreeIter iter;
-
- network = empathy_irc_network_new (_("New Network"));
- empathy_irc_network_manager_add (settings->network_manager, network);
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- store = GTK_LIST_STORE (model);
-
- g_object_get (network, "name", &name, NULL);
-
- gtk_list_store_insert_with_values (store, &iter, -1,
- COL_NETWORK_OBJ, network,
- COL_NETWORK_NAME, name,
- -1);
-
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (settings->combobox_network),
- &iter);
-
- display_irc_network_dialog (settings, network);
-
- g_free (name);
- g_object_unref (network);
-}
-
-static void
-account_widget_irc_combobox_network_changed_cb (GtkWidget *combobox,
- EmpathyAccountWidgetIrc *settings)
-{
- update_server_params (settings);
- empathy_account_widget_changed (settings->self);
-}
-
-static void
-fill_networks_model (EmpathyAccountWidgetIrc *settings,
- EmpathyIrcNetwork *network_to_select)
-{
- GSList *networks, *l;
- GtkTreeModel *model;
- GtkListStore *store;
-
- networks = empathy_irc_network_manager_get_networks (
- settings->network_manager);
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (settings->combobox_network));
- store = GTK_LIST_STORE (model);
-
- for (l = networks; l != NULL; l = g_slist_next (l))
- {
- gchar *name;
- EmpathyIrcNetwork *network = l->data;
- GtkTreeIter iter;
-
- g_object_get (network, "name", &name, NULL);
-
- gtk_list_store_insert_with_values (store, &iter, -1,
- COL_NETWORK_OBJ, network,
- COL_NETWORK_NAME, name,
- -1);
-
- if (network == network_to_select)
- {
- gtk_combo_box_set_active_iter (
- GTK_COMBO_BOX (settings->combobox_network), &iter);
- }
-
- g_free (name);
- g_object_unref (network);
- }
-
- if (network_to_select == NULL)
- {
- /* Select the first network */
- GtkTreeIter iter;
-
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- gtk_combo_box_set_active_iter (
- GTK_COMBO_BOX (settings->combobox_network), &iter);
-
- update_server_params (settings);
- }
- }
-
- g_slist_free (networks);
-}
-
-static void
account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
{
const gchar *nick = NULL;
const gchar *fullname = NULL;
- const gchar *server = NULL;
gint port = 6667;
const gchar *charset;
gboolean ssl = FALSE;
- EmpathyIrcNetwork *network = NULL;
EmpathyAccountSettings *ac_settings;
g_object_get (settings->self, "settings", &ac_settings, NULL);
@@ -344,7 +69,6 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
nick = empathy_account_settings_get_string (ac_settings, "account");
fullname = empathy_account_settings_get_string (ac_settings,
"fullname");
- server = empathy_account_settings_get_string (ac_settings, "server");
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");
@@ -366,63 +90,13 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
empathy_account_settings_set_string (ac_settings,
"fullname", fullname);
}
+}
- if (server != NULL)
- {
- GtkListStore *store;
-
- network = empathy_irc_network_manager_find_network_by_address (
- settings->network_manager, server);
-
-
- store = GTK_LIST_STORE (gtk_combo_box_get_model (
- GTK_COMBO_BOX (settings->combobox_network)));
-
- if (network != NULL)
- {
- gchar *name;
-
- g_object_set (network, "charset", charset, NULL);
-
- g_object_get (network, "name", &name, NULL);
- DEBUG ("Account use network %s", name);
-
- g_free (name);
- }
- else
- {
- /* We don't have this network. Let's create it */
- EmpathyIrcServer *srv;
- GtkTreeIter iter;
-
- DEBUG ("Create a network %s", server);
- network = empathy_irc_network_new (server);
- srv = empathy_irc_server_new (server, port, ssl);
-
- empathy_irc_network_append_server (network, srv);
- empathy_irc_network_manager_add (settings->network_manager, network);
-
- gtk_list_store_insert_with_values (store, &iter, -1,
- COL_NETWORK_OBJ, network,
- COL_NETWORK_NAME, server,
- -1);
-
- gtk_combo_box_set_active_iter (
- GTK_COMBO_BOX (settings->combobox_network), &iter);
-
- g_object_unref (srv);
- g_object_unref (network);
- }
- }
-
- if (network == NULL)
- {
- network = empathy_irc_network_manager_find_network_by_address (
- settings->network_manager, DEFAULT_IRC_NETWORK);
- }
-
- fill_networks_model (settings, network);
- update_server_params (settings);
+static void
+network_changed_cb (EmpathyIrcNetworkChooser *chooser,
+ EmpathyAccountWidgetIrc *settings)
+{
+ empathy_account_widget_changed (settings->self);
}
void
@@ -431,60 +105,29 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self,
GtkWidget **table_common_settings)
{
EmpathyAccountWidgetIrc *settings;
- gchar *dir, *user_file_with_path, *global_file_with_path;
- GtkListStore *store;
- GtkCellRenderer *renderer;
+ EmpathyAccountSettings *ac_settings;
settings = g_slice_new0 (EmpathyAccountWidgetIrc);
settings->self = self;
- dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
- g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
- user_file_with_path = g_build_filename (dir, IRC_NETWORKS_FILENAME, NULL);
- g_free (dir);
-
- global_file_with_path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"),
- "libempathy", IRC_NETWORKS_FILENAME, NULL);
- if (!g_file_test (global_file_with_path, G_FILE_TEST_EXISTS))
- {
- g_free (global_file_with_path);
- global_file_with_path = g_build_filename (DATADIR, "empathy",
- IRC_NETWORKS_FILENAME, NULL);
- }
-
- settings->network_manager = empathy_irc_network_manager_new (
- global_file_with_path,
- user_file_with_path);
-
- g_free (global_file_with_path);
- g_free (user_file_with_path);
-
self->ui_details->gui = empathy_builder_get_file (filename,
- "table_irc_settings", table_common_settings,
+ "table_irc_settings", &table_common_settings,
"vbox_irc", &self->ui_details->widget,
"table_irc_settings", &settings->vbox_settings,
- "combobox_network", &settings->combobox_network,
NULL);
- /* Fill the networks combobox */
- store = gtk_list_store_new (2, G_TYPE_OBJECT, G_TYPE_STRING);
+ /* Add network chooser button */
+ g_object_get (settings->self, "settings", &ac_settings, NULL);
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (settings->combobox_network));
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (settings->combobox_network),
- renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (settings->combobox_network),
- renderer,
- "text", COL_NETWORK_NAME,
- NULL);
+ settings->network_chooser = empathy_irc_network_chooser_new (ac_settings);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
- COL_NETWORK_NAME,
- GTK_SORT_ASCENDING);
+ g_signal_connect (settings->network_chooser, "changed",
+ G_CALLBACK (network_changed_cb), settings);
- gtk_combo_box_set_model (GTK_COMBO_BOX (settings->combobox_network),
- GTK_TREE_MODEL (store));
- g_object_unref (store);
+ gtk_table_attach (GTK_TABLE (table_common_settings),
+ settings->network_chooser, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
+
+ gtk_widget_show (settings->network_chooser);
account_widget_irc_setup (settings);
@@ -497,15 +140,9 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self,
empathy_builder_connect (self->ui_details->gui, settings,
"table_irc_settings", "destroy", account_widget_irc_destroy_cb,
- "button_network", "clicked",
- account_widget_irc_button_edit_network_clicked_cb,
- "button_add_network", "clicked",
- account_widget_irc_button_add_network_clicked_cb,
- "button_remove_network", "clicked",
- account_widget_irc_button_remove_clicked_cb,
- "combobox_network", "changed",
- account_widget_irc_combobox_network_changed_cb,
NULL);
self->ui_details->default_focus = g_strdup ("entry_nick");
+
+ g_object_unref (ac_settings);
}
diff --git a/libempathy-gtk/empathy-account-widget-irc.ui b/libempathy-gtk/empathy-account-widget-irc.ui
index af733fb95..de0aa00cd 100644
--- a/libempathy-gtk/empathy-account-widget-irc.ui
+++ b/libempathy-gtk/empathy-account-widget-irc.ui
@@ -257,7 +257,6 @@
</object>
<object class="GtkVBox" id="vbox_irc">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table_irc_settings">
<property name="visible">True</property>
@@ -373,80 +372,6 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox174">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkComboBox" id="combobox_network">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button_add_network">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkImage" id="image2">
- <property name="visible">True</property>
- <property name="stock">gtk-add</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button_network">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkImage" id="image834">
- <property name="visible">True</property>
- <property name="stock">gtk-edit</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button_remove_network">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkImage" id="image835">
- <property name="visible">True</property>
- <property name="stock">gtk-remove</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
<object class="GtkLabel" id="label_network2">
<property name="visible">True</property>
<property name="xalign">0</property>
@@ -458,6 +383,9 @@
<property name="y_options"></property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
</object>
<packing>
<property name="position">0</property>