Commit 9b7cc54d authored by Chris Toshok's avatar Chris Toshok Committed by Chris Toshok

fix memory leaks.

2002-04-18  Chris Toshok  <toshok@ximian.com>

	* backend/pas/pas-backend-ldap.c (get_ldap_library_info): fix
	memory leaks.

	* gui/component/GNOME_Evolution_Addressbook.oaf.in: remove the
	Addressbook_ConfigControl stuff to LDAP_ConfigControl.

	* gui/component/Makefile.am (evolution_addressbook_SOURCES):
	remove addressbook-config.* and add ldap-config.*
	(glade_DATA): same.
	(evolution_addressbook_LDADD): add LDAP_LIBS.

	* gui/component/addressbook-component.c (owner_set_cb):
	addressbook_config_register_factory =>
	ldap_config_register_factory.

	* gui/component/addressbook.c (book_open_cb): remove source->type
	check - they're always LDAP.
	(load_uri_cb): same.

	* gui/component/addressbook-storage.c (ldap_unparse_ssl): new
	function.
	(ldap_parse_ssl): new function.
	(addressbook_storage_init_source_uri): use a more flexible scheme
	to build up the uri's, and add in the ssl parameter.
	(load_source_data): fill in source->ssl, and remove source->type
	assignment.
	(addressbook_source_copy): copy source->ssl, and remove
	source->type copy.
	(create_ldap_folder): addressbook_create_new_source =>
	ldap_config_create_new_source.

	* gui/component/addressbook-storage.h: remove
	AddressbookSourceType (it was always LDAP), and add
	AddressbookLDAPSSLType.

svn path=/trunk/; revision=16524
parent 0c7e55e7
2002-04-18 Chris Toshok <toshok@ximian.com>
* backend/pas/pas-backend-ldap.c (get_ldap_library_info): fix
memory leaks.
* gui/component/GNOME_Evolution_Addressbook.oaf.in: remove the
Addressbook_ConfigControl stuff to LDAP_ConfigControl.
* gui/component/Makefile.am (evolution_addressbook_SOURCES):
remove addressbook-config.* and add ldap-config.*
(glade_DATA): same.
(evolution_addressbook_LDADD): add LDAP_LIBS.
* gui/component/addressbook-component.c (owner_set_cb):
addressbook_config_register_factory =>
ldap_config_register_factory.
* gui/component/addressbook.c (book_open_cb): remove source->type
check - they're always LDAP.
(load_uri_cb): same.
* gui/component/addressbook-storage.c (ldap_unparse_ssl): new
function.
(ldap_parse_ssl): new function.
(addressbook_storage_init_source_uri): use a more flexible scheme
to build up the uri's, and add in the ssl parameter.
(load_source_data): fill in source->ssl, and remove source->type
assignment.
(addressbook_source_copy): copy source->ssl, and remove
source->type copy.
(create_ldap_folder): addressbook_create_new_source =>
ldap_config_create_new_source.
* gui/component/addressbook-storage.h: remove
AddressbookSourceType (it was always LDAP), and add
AddressbookLDAPSSLType.
2002-04-18 Dan Winship <danw@ximian.com> 2002-04-18 Dan Winship <danw@ximian.com>
* backend/ebook/e-book-util.c (e_book_load_default_book): Append * backend/ebook/e-book-util.c (e_book_load_default_book): Append
......
...@@ -448,12 +448,14 @@ get_ldap_library_info () ...@@ -448,12 +448,14 @@ get_ldap_library_info ()
info.ldapai_vendor_version % 1000); info.ldapai_vendor_version % 1000);
g_message ("extensions present:"); g_message ("extensions present:");
/* yuck. we have to free these? */
for (i = 0; info.ldapai_extensions[i]; i++) { for (i = 0; info.ldapai_extensions[i]; i++) {
char *extension = info.ldapai_extensions[i]; char *extension = info.ldapai_extensions[i];
g_message (extension); g_message (extension);
/* yuck. we have to free this? */
ldap_memfree (extension); ldap_memfree (extension);
} }
ldap_memfree (info.ldapai_extensions);
ldap_memfree (info.ldapai_vendor_name);
} }
ldap_unbind_ext_s (ldap, NULL, NULL); ldap_unbind_ext_s (ldap, NULL, NULL);
......
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
</oaf_server> </oaf_server>
<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_ConfigControlFactory" <oaf_server iid="OAFIID:GNOME_Evolution_LDAPStorage_ConfigControlFactory"
type="exe" type="exe"
location="evolution-addressbook"> location="evolution-addressbook">
...@@ -144,9 +144,9 @@ ...@@ -144,9 +144,9 @@
</oaf_server> </oaf_server>
<oaf_server iid="OAFIID:GNOME_Evolution_Addresbook_ConfigControl" <oaf_server iid="OAFIID:GNOME_Evolution_LDAPStorage_ConfigControl"
type="factory" type="factory"
location="OAFIID:GNOME_Evolution_Addressbook_ConfigControlFactory"> location="OAFIID:GNOME_Evolution_LDAPStorage_ConfigControlFactory">
<oaf_attribute name="repo_ids" type="stringv"> <oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/Evolution/ConfigControl:1.0"/> <item value="IDL:GNOME/Evolution/ConfigControl:1.0"/>
...@@ -161,11 +161,6 @@ ...@@ -161,11 +161,6 @@
<oaf_attribute name="evolution:config_item:icon_name" type="string" <oaf_attribute name="evolution:config_item:icon_name" type="string"
value="evolution-contacts.png"/> value="evolution-contacts.png"/>
<oaf_attribute name="evolution:config_item:type" type="stringv">
<item value="contacts"/>
<item value="ldap-contacts"/>
</oaf_attribute>
<oaf_attribute name="evolution:config_item:priority" type="string" value="-6"/> <oaf_attribute name="evolution:config_item:priority" type="string" value="-6"/>
<oaf_attribute name="description" type="string" <oaf_attribute name="description" type="string"
......
...@@ -27,8 +27,6 @@ bin_PROGRAMS = \ ...@@ -27,8 +27,6 @@ bin_PROGRAMS = \
evolution_addressbook_SOURCES = \ evolution_addressbook_SOURCES = \
addressbook-component.c \ addressbook-component.c \
addressbook-component.h \ addressbook-component.h \
addressbook-config.c \
addressbook-config.h \
addressbook-factory.c \ addressbook-factory.c \
addressbook-storage.c \ addressbook-storage.c \
addressbook-storage.h \ addressbook-storage.h \
...@@ -39,7 +37,9 @@ evolution_addressbook_SOURCES = \ ...@@ -39,7 +37,9 @@ evolution_addressbook_SOURCES = \
e-address-widget.h \ e-address-widget.h \
e-address-widget.c \ e-address-widget.c \
e-address-popup.h \ e-address-popup.h \
e-address-popup.c e-address-popup.c \
ldap-config.c \
ldap-config.h
evolution_addressbook_LDADD = \ evolution_addressbook_LDADD = \
select-names/libeselectnames.la \ select-names/libeselectnames.la \
...@@ -59,7 +59,7 @@ evolution_addressbook_LDADD = \ ...@@ -59,7 +59,7 @@ evolution_addressbook_LDADD = \
$(top_builddir)/filter/libfilter.la \ $(top_builddir)/filter/libfilter.la \
$(top_builddir)/e-util/libeutil.la \ $(top_builddir)/e-util/libeutil.la \
$(top_builddir)/widgets/menus/libmenus.la \ $(top_builddir)/widgets/menus/libmenus.la \
$(EVOLUTION_ADDRESSBOOK_LIBS) $(EVOLUTION_ADDRESSBOOK_LIBS) $(LDAP_LIBS)
evolution_addressbook_LDFLAGS = `gnome-config --libs gdk_pixbuf` -export-dynamic evolution_addressbook_LDFLAGS = `gnome-config --libs gdk_pixbuf` -export-dynamic
...@@ -70,14 +70,14 @@ oaf_in_files = GNOME_Evolution_Addressbook.oaf.in ...@@ -70,14 +70,14 @@ oaf_in_files = GNOME_Evolution_Addressbook.oaf.in
oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) oaf_DATA = $(oaf_in_files:.oaf.in=.oaf)
gladedir = $(datadir)/evolution/glade gladedir = $(datadir)/evolution/glade
glade_DATA = addressbook-config.glade glade_DATA = ldap-config.glade
iconsdir = $(datadir)/images/evolution iconsdir = $(datadir)/images/evolution
EXTRA_DIST = \ extra_dist = \
$(glade_DATA) \ $(glade_data) \
$(oaf_DATA) \ $(oaf_data) \
addressbook-config.glade \ ldap-config.glade \
$(oaf_in_files) $(oaf_in_files)
if ENABLE_PURIFY if ENABLE_PURIFY
......
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
#include "ebook/e-card.h" #include "ebook/e-card.h"
#include "ebook/e-book-util.h" #include "ebook/e-book-util.h"
#include "ldap-config.h"
#include "addressbook-storage.h" #include "addressbook-storage.h"
#include "addressbook-component.h" #include "addressbook-component.h"
#include "addressbook-config.h"
#include "addressbook.h" #include "addressbook.h"
#include "addressbook/gui/merging/e-card-merging.h" #include "addressbook/gui/merging/e-card-merging.h"
#include "addressbook/gui/widgets/e-addressbook-util.h" #include "addressbook/gui/widgets/e-addressbook-util.h"
...@@ -369,7 +369,7 @@ owner_set_cb (EvolutionShellComponent *shell_component, ...@@ -369,7 +369,7 @@ owner_set_cb (EvolutionShellComponent *shell_component,
if (global_shell_client == NULL) if (global_shell_client == NULL)
global_shell_client = shell_client; global_shell_client = shell_client;
addressbook_config_register_factory (bonobo_object_corba_objref (BONOBO_OBJECT (shell_client))); ldap_config_register_factory (bonobo_object_corba_objref (BONOBO_OBJECT (shell_client)));
addressbook_storage_setup (shell_component, evolution_homedir); addressbook_storage_setup (shell_component, evolution_homedir);
} }
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <config.h>
#include "addressbook-config.h"
#include "addressbook-storage.h"
#include "evolution-config-control.h"
#include <gal/widgets/e-unicode.h>
#include <e-util/e-html-utils.h>
#include <gtkhtml/gtkhtml.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-stock.h>
#include <bonobo/bonobo-generic-factory.h>
#include <glade/glade.h>
#include <stdlib.h>
#define CONFIG_CONTROL_FACTORY_ID "OAFIID:GNOME_Evolution_Addressbook_ConfigControlFactory"
typedef struct _AddressbookSourceDialog AddressbookSourceDialog;
typedef struct _AddressbookSourcePageItem AddressbookSourcePageItem;
struct _AddressbookSourceDialog {
GladeXML *gui;
GtkWidget *dialog;
GtkWidget *notebook;
GtkWidget *basic_notebook;
GtkWidget *advanced_notebook;
GtkWidget *name;
GtkWidget *host;
GtkWidget *auth_checkbutton;
GtkWidget *auth_optionmenu;
GtkWidget *auth_notebook;
GtkWidget *email;
GtkWidget *binddn;
int auth;
GtkWidget *port;
GtkWidget *rootdn;
GtkWidget *limit;
GtkWidget *scope_optionmenu;
AddressbookLDAPScopeType ldap_scope;
gint id; /* button we closed the dialog with */
AddressbookSource *source; /* our result if the Ok button was clicked */
};
static void
addressbook_source_edit_changed (GtkWidget *item, AddressbookSourceDialog *dialog)
{
char *data;
gboolean complete = TRUE;
if (complete) {
data = e_utf8_gtk_editable_get_chars (GTK_EDITABLE (dialog->name), 0, -1);
if (!data || !*data)
complete = FALSE;
g_free (data);
}
if (complete) {
if (complete) {
data = e_utf8_gtk_editable_get_chars (GTK_EDITABLE (dialog->host), 0, -1);
if (!data || !*data)
complete = FALSE;
g_free (data);
}
if (complete) {
data = e_utf8_gtk_editable_get_chars (GTK_EDITABLE (dialog->port), 0, -1);
if (!data || !*data)
complete = FALSE;
/* XXX more validation on port here */
g_free (data);
}
}
gnome_dialog_set_sensitive (GNOME_DIALOG (dialog->dialog), 0, complete);
}
static void
auth_checkbutton_changed (GtkWidget *item, AddressbookSourceDialog *dialog)
{
/* make sure the change is reflected by the state of the dialog's OK button */
addressbook_source_edit_changed (item, dialog);
gtk_widget_set_sensitive (dialog->auth_optionmenu,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dialog->auth_checkbutton)));
gtk_widget_set_sensitive (dialog->auth_notebook,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dialog->auth_checkbutton)));
}
static void
scope_optionmenu_activated (GtkWidget *item, AddressbookSourceDialog *dialog)
{
/* make sure the change is reflected by the state of the dialog's OK button */
addressbook_source_edit_changed (item, dialog);
dialog->ldap_scope = g_list_index (gtk_container_children (GTK_CONTAINER (item->parent)),
item);
}
static void
auth_optionmenu_activated (GtkWidget *item, AddressbookSourceDialog *dialog)
{
/* make sure the change is reflected by the state of the dialog's OK button */
addressbook_source_edit_changed (item, dialog);
dialog->auth = g_list_index (gtk_container_children (GTK_CONTAINER (item->parent)),
item) + 1;
gtk_notebook_set_page (GTK_NOTEBOOK(dialog->auth_notebook), dialog->auth - 1);
}
typedef struct {
GtkWidget *notebook;
int page_num;
} FocusHelpClosure;
static void
focus_help (GtkWidget *w, GdkEventFocus *event, FocusHelpClosure *closure)
{
gtk_notebook_set_page (GTK_NOTEBOOK(closure->notebook), closure->page_num);
}
static void
add_focus_handler (GtkWidget *widget, GtkWidget *notebook, int page_num)
{
FocusHelpClosure *focus_closure = g_new0 (FocusHelpClosure, 1);
focus_closure->notebook = notebook;
focus_closure->page_num = page_num;
gtk_signal_connect_full (GTK_OBJECT (widget),
"focus_in_event" /* XXX */,
(GtkSignalFunc) focus_help, NULL,
focus_closure,
(GtkDestroyNotify) g_free,
FALSE, FALSE);
}
static void
addressbook_source_dialog_set_source (AddressbookSourceDialog *dialog, AddressbookSource *source)
{
char *string;
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->name), source ? source->name : "");
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->host), source ? source->host : "");
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->email), source ? source->email_addr : "");
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->binddn), source ? source->binddn : "");
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->port), source ? source->port : "389");
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->rootdn), source ? source->rootdn : "");
string = g_strdup_printf ("%d", source ? source->limit : 100);
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->limit), string);
g_free (string);
dialog->auth = source ? source->auth : ADDRESSBOOK_LDAP_AUTH_NONE;
if (dialog->auth != ADDRESSBOOK_LDAP_AUTH_NONE) {
gtk_option_menu_set_history (GTK_OPTION_MENU(dialog->auth_optionmenu), dialog->auth - 1);
gtk_notebook_set_page (GTK_NOTEBOOK(dialog->auth_notebook), dialog->auth - 1);
}
dialog->ldap_scope = source ? source->scope : ADDRESSBOOK_LDAP_SCOPE_ONELEVEL;
gtk_option_menu_set_history (GTK_OPTION_MENU(dialog->scope_optionmenu), dialog->ldap_scope);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dialog->auth_checkbutton), source && source->auth != ADDRESSBOOK_LDAP_AUTH_NONE);
gtk_widget_set_sensitive (dialog->auth_optionmenu, source && source->auth != ADDRESSBOOK_LDAP_AUTH_NONE);
gtk_widget_set_sensitive (dialog->auth_notebook, source && source->auth != ADDRESSBOOK_LDAP_AUTH_NONE);
}
static AddressbookSource *
addressbook_source_dialog_get_source (AddressbookSourceDialog *dialog)
{
AddressbookSource *source = g_new0 (AddressbookSource, 1);
source->name = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->name));
source->host = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->host));
source->email_addr = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->email));
source->binddn = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->binddn));
source->port = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->port));
source->rootdn = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->rootdn));
source->limit = atoi(e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->limit)));
source->scope = dialog->ldap_scope;
source->auth = dialog->auth;
addressbook_storage_init_source_uri (source);
return source;
}
static void
addressbook_source_dialog_ok_clicked (GtkWidget *widget, AddressbookSourceDialog *dialog)
{
dialog->source = addressbook_source_dialog_get_source (dialog);
}
static void
add_scope_activate_cb (GtkWidget *item, AddressbookSourceDialog *dialog)
{
gtk_signal_connect (GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (scope_optionmenu_activated), dialog);
}
static void
add_auth_activate_cb (GtkWidget *item, AddressbookSourceDialog *dialog)
{
gtk_signal_connect (GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (auth_optionmenu_activated), dialog);
}
static AddressbookSourceDialog*
addressbook_source_dialog (GladeXML *gui, AddressbookSource *source, GtkWidget *parent)
{
AddressbookSourceDialog *dialog = g_new0 (AddressbookSourceDialog, 1);
GtkWidget *menu;
dialog->gui = gui;
dialog->dialog = glade_xml_get_widget (gui, "add_addressbook");
if (source)
gtk_window_set_title (GTK_WINDOW (dialog->dialog), _("Edit Addressbook"));
gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE);
gtk_window_set_policy (GTK_WINDOW (dialog->dialog),
FALSE, TRUE, FALSE);
gnome_dialog_set_parent (GNOME_DIALOG (dialog->dialog),
GTK_WINDOW (parent));
dialog->notebook = glade_xml_get_widget (gui, "add-addressbook-notebook");
dialog->basic_notebook = glade_xml_get_widget (gui, "basic-notebook");
dialog->advanced_notebook = glade_xml_get_widget (gui, "advanced-notebook");
/* BASIC STUFF */
dialog->name = glade_xml_get_widget (gui, "account-name-entry");
gtk_signal_connect (GTK_OBJECT (dialog->name), "changed",
GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog);
add_focus_handler (dialog->name, dialog->basic_notebook, 0);
dialog->host = glade_xml_get_widget (gui, "server-name-entry");
gtk_signal_connect (GTK_OBJECT (dialog->host), "changed",
GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog);
add_focus_handler (dialog->host, dialog->basic_notebook, 1);
/* BASIC -> AUTH STUFF */
dialog->auth_notebook = glade_xml_get_widget (gui, "auth-notebook");
dialog->auth_checkbutton = glade_xml_get_widget (gui, "auth-checkbutton");
add_focus_handler (dialog->auth_checkbutton, dialog->basic_notebook, 2);
gtk_signal_connect (GTK_OBJECT (dialog->auth_checkbutton), "toggled",
GTK_SIGNAL_FUNC (auth_checkbutton_changed), dialog);
dialog->auth_optionmenu = glade_xml_get_widget (gui, "auth-optionmenu");
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU(dialog->auth_optionmenu));
gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback)add_auth_activate_cb, dialog);
add_focus_handler (dialog->auth_optionmenu, dialog->basic_notebook, 3);
dialog->email = glade_xml_get_widget (gui, "email-entry");
add_focus_handler (dialog->email, dialog->basic_notebook, 4);
dialog->binddn = glade_xml_get_widget (gui, "dn-entry");
add_focus_handler (dialog->binddn, dialog->basic_notebook, 5);
/* ADVANCED STUFF */
dialog->port = glade_xml_get_widget (gui, "port-entry");
gtk_signal_connect (GTK_OBJECT (dialog->port), "changed",
GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog);
add_focus_handler (dialog->port, dialog->advanced_notebook, 0);
dialog->rootdn = glade_xml_get_widget (gui, "rootdn-entry");
gtk_signal_connect (GTK_OBJECT (dialog->rootdn), "changed",
GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog);
add_focus_handler (dialog->rootdn, dialog->advanced_notebook, 1);
dialog->scope_optionmenu = glade_xml_get_widget (gui, "scope-optionmenu");
add_focus_handler (dialog->scope_optionmenu, dialog->advanced_notebook, 2);
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU(dialog->scope_optionmenu));
gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback)add_scope_activate_cb, dialog);
dialog->limit = glade_xml_get_widget (gui, "limit-entry");
gtk_signal_connect (GTK_OBJECT (dialog->limit), "changed",
GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog);
add_focus_handler (dialog->limit, dialog->advanced_notebook, 3);
/* fill in source info if there is some */
addressbook_source_dialog_set_source (dialog, source);
/* always start out on the first page. */
gtk_notebook_set_page (GTK_NOTEBOOK (dialog->notebook), 0);
gnome_dialog_set_sensitive (GNOME_DIALOG (dialog->dialog), 0, FALSE);
gnome_dialog_button_connect( GNOME_DIALOG (dialog->dialog), 0,
GTK_SIGNAL_FUNC (addressbook_source_dialog_ok_clicked),
dialog);
/* and set focus to be the Account field (the first editable
field on the first page) */
gtk_widget_grab_focus (dialog->name);
return dialog;
}
static AddressbookSourceDialog *
addressbook_config_source_with_gui (GladeXML *gui, AddressbookSource *source, GtkWidget *parent)
{
AddressbookSourceDialog* dialog;
dialog = addressbook_source_dialog (gui, source, parent);
gnome_dialog_close_hides (GNOME_DIALOG(dialog->dialog), TRUE);
dialog->id = gnome_dialog_run_and_close (GNOME_DIALOG (dialog->dialog));
return dialog;
}
void
addressbook_create_new_source (const char *new_source, GtkWidget *parent)
{
AddressbookSourceDialog *dialog;
GladeXML *gui;
gui = glade_xml_new (EVOLUTION_GLADEDIR "/addressbook-config.glade", NULL);
dialog = addressbook_source_dialog (gui, NULL, parent);
e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->name), new_source);
gnome_dialog_close_hides (GNOME_DIALOG(dialog->dialog), TRUE);
dialog->id = gnome_dialog_run_and_close (GNOME_DIALOG (dialog->dialog));
gtk_object_unref (GTK_OBJECT (dialog->gui));
if (dialog->id == 0) {
/* Ok was clicked */
addressbook_storage_add_source (addressbook_source_copy(dialog->source));
addressbook_storage_write_sources();
}
}
typedef struct {
EvolutionConfigControl *config_control;
GtkWidget *page;
GladeXML *gui;
GNOME_Evolution_Shell shell;
GtkWidget *clistSources;
GtkWidget *addSource;
GtkWidget *editSource;
GtkWidget *deleteSource;
gint source_row;
} AddressbookDialog;
static void
update_sensitivity (AddressbookDialog *dialog)
{
gboolean sensitive = dialog->source_row != -1;
gtk_widget_set_sensitive (dialog->editSource, sensitive);
gtk_widget_set_sensitive (dialog->deleteSource, sensitive);
}
static void
add_source_clicked (GtkWidget *widget, AddressbookDialog *dialog)
{
AddressbookSourceDialog *sdialog;
sdialog = addressbook_config_source_with_gui (dialog->gui, NULL, dialog->page);
if (sdialog->id == 0) {
/* Ok was clicked */
AddressbookSource *source = addressbook_source_copy(sdialog->source);
gint row;
gchar *text[2];
text[0] = source->name;
text[1] = source->host;
row = e_utf8_gtk_clist_append (GTK_CLIST(dialog->clistSources), text);
gtk_clist_set_row_data_full (GTK_CLIST(dialog->clistSources), row, source, (GtkDestroyNotify) addressbook_source_free);
evolution_config_control_changed (dialog->config_control);
update_sensitivity (dialog);
}
}
static void
edit_source_clicked (GtkWidget *widget, AddressbookDialog *dialog)
{
AddressbookSource *source;
AddressbookSourceDialog *sdialog;
source = gtk_clist_get_row_data (GTK_CLIST (dialog->clistSources), dialog->source_row);
sdialog = addressbook_config_source_with_gui (dialog->gui, source, dialog->page);
if (sdialog->id == 0) {
/* Ok was clicked */
source = addressbook_source_copy(sdialog->source);
e_utf8_gtk_clist_set_text (GTK_CLIST (dialog->clistSources), dialog->source_row, 0, source->name);
e_utf8_gtk_clist_set_text (GTK_CLIST (dialog->clistSources), dialog->source_row, 1, source->host);
gtk_clist_set_row_data (GTK_CLIST (dialog->clistSources), dialog->source_row, source);
evolution_config_control_changed (dialog->config_control);
update_sensitivity (dialog);
}
}
static void
delete_source_clicked (GtkWidget *widget, AddressbookDialog *dialog)
{
gtk_clist_remove (GTK_CLIST (dialog->clistSources), dialog->source_row);
dialog->source_row = -1;
evolution_config_control_changed (dialog->config_control);
update_sensitivity (dialog);
}
static void
sources_select_row (GtkWidget *widget, gint row, gint column,
GdkEventButton *event, AddressbookDialog *dialog)
{
dialog->source_row = row;
update_sensitivity (dialog);
}
static void
config_control_destroy_callback (EvolutionConfigControl *config_control,
void *data)
{
AddressbookDialog *dialog;
dialog = (AddressbookDialog *) data;
gtk_object_unref (GTK_OBJECT (dialog->gui));
g_free (dialog);
}
static void
config_control_apply_callback (EvolutionConfigControl *config_control,
void *data)
{
AddressbookDialog *dialog;
int i;
dialog = (AddressbookDialog *) data;
addressbook_storage_clear_sources();
for (i = 0; i < GTK_CLIST(dialog->clistSources)->rows; i ++) {
AddressbookSource *source = (AddressbookSource*)gtk_clist_get_row_data (GTK_CLIST (dialog->clistSources), i);
addressbook_storage_add_source (addressbook_source_copy (source));
}
addressbook_storage_write_sources();
}
static EvolutionConfigControl *
config_control_new (GNOME_Evolution_Shell shell)
{
AddressbookDialog *dialog;
GladeXML *gui;
GtkWidget *clist;
GList *l;
dialog = g_new0 (AddressbookDialog, 1);
dialog->source_row = -1;
gui = glade_xml_new (EVOLUTION_GLADEDIR "/addressbook-config.glade", NULL);
dialog->gui = gui;
dialog->shell = shell;
dialog->page = glade_xml_get_widget (gui, "addressbook_sources_main_hbox");
gtk_widget_ref (dialog->page);
gtk_container_remove (GTK_CONTAINER (dialog->page->parent), dialog->page);
dialog->config_control = evolution_config_control_new (dialog->page);
gtk_signal_connect (GTK_OBJECT (dialog->config_control), "apply",
GTK_SIGNAL_FUNC (config_control_apply_callback), dialog);