Re: [evolution-patches] patch for camel groupwise provider and config listener



> 
> From: 	Siva <snallagatla novell com>
> To: 	evolution-patches ximian com
> Subject: 	[evolution-patches] patch for camel groupwise provider and
config listener
> Date: 	 Thu, 08 Jan 2004 19:07:07 +0530  (Fri, 00:07 CST)
> 
> Hi,
> I am attaching a patch which has a camel provider for groupwise.
> groupwise camel provider juset uses IMAP for it provider store and
SMTP
> for its transport. 

So as discussed earlier, this is totally the wrong place to put this
code.

A camel provider is the lowest-level camel remote object, it shouldn't
be managing other stuff.  If you want meta-accounts, it should be
managed elsewhere, although I don't know where it would fit, it
doesn't even fit in the mailer as such.  e.g. its no different from
having a ldap configuration controlling mail + calendar for you.

Anyway i'll comment on the patch itself, since it has bugs anyway.

> groupwise_config_listner is class implemented for adding e-sources for
> calender and tasks whenever a groupwise acount is created from mail
> account setup gui. It also deletes or modifies e-sources when 
> a groupwise account is deleted or modified. 
> 
> Thanks, 
> Sivaiah
> 
> 			source code patch attachment (groupwise_provider_patch.diff)
> 
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/ChangeLog,v
> retrieving revision 1.1282
> diff -u -r1.1282 ChangeLog
> --- ChangeLog   8 Jan 2004 07:51:14 -0000       1.1282
> +++ ChangeLog   8 Jan 2004 12:43:40 -0000
> @@ -1,3 +1,7 @@
> +2004-01-08 Sivaiah Nallagatla <snallagatla novell com>
> +       
> +       * configure.in : add camel/providers/groupwise/Makefile to
AC_OUTPUT section    
> +
>  2004-01-08  Robert Sedak  <robert sedak sk htnet hr>
>  
>          * configure.in: Added "hr" (Croatian) to ALL_LINGUAS.
> Index: configure.in
> ===================================================================
> RCS file: /cvs/gnome/evolution/configure.in,v
> retrieving revision 1.642
> diff -u -r1.642 configure.in
> --- configure.in        8 Jan 2004 07:51:14 -0000       1.642
> +++ configure.in        8 Jan 2004 12:44:10 -0000
> @@ -1276,6 +1276,7 @@
>  camel/providers/Makefile
>  camel/providers/imap/Makefile
>  camel/providers/imapp/Makefile
> +camel/providers/groupwise/Makefile
>  camel/providers/local/Makefile
>  camel/providers/nntp/Makefile
>  camel/providers/pop3/Makefile
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
> retrieving revision 1.1949
> diff -u -r1.1949 ChangeLog
> --- ChangeLog   5 Jan 2004 20:55:27 -0000       1.1949
> +++ ChangeLog   8 Jan 2004 12:44:36 -0000
> @@ -1,3 +1,11 @@
> +2004-01-08 Sivaiah Nallagatla <snallagatla novell com>
> +
> +       * providers/Makefile.am : add groupwise to SUBDIRS 
> +       * providers/groupwise/camel-groupwise-provider.c: new camel
provider for groupwise 
> +       * providers/groupwise/groupwise-config-listener.[ch] : new
class to add e-sources for groupwise calender and tasks 
> +       * providers/groupwise/Makefile.am 
> +       * providers/groupwise/libcamelgroupwise.urls 
> +
>  2004-01-05  JP Rosevear <jpr ximian com>
>  
>         * camel-utf8.c: include sys/types.h for freebsd
> Index: Makefile.am
> ===================================================================
> RCS file: /cvs/gnome/evolution/camel/providers/Makefile.am,v
> retrieving revision 1.27
> diff -u -r1.27 Makefile.am
> --- Makefile.am 1 Aug 2003 21:08:03 -0000       1.27
> +++ Makefile.am 8 Jan 2004 12:45:05 -0000
> @@ -8,5 +8,5 @@
>  IMAPP_DIR=imapp
>  endif
>  
> -SUBDIRS = pop3 sendmail smtp imap $(NNTP_DIR) local $(IMAPP_DIR)
> +SUBDIRS = pop3 sendmail smtp imap $(NNTP_DIR) local $(IMAPP_DIR)
groupwise
>  
> --- Makefile.am.orig    2004-01-08 17:50:37.000000000 +0530
> +++ Makefile.am 2004-01-08 16:32:40.000000000 +0530
> @@ -0,0 +1,31 @@
> +## Process this file with automake to produce Makefile.in
> +
> +libcamelimapincludedir = $(privincludedir)/camel
> +
> +camel_provider_LTLIBRARIES = libcamelgroupwise.la
> +camel_provider_DATA = libcamelgroupwise.urls
> +
> +INCLUDES = -I.. \
> +       -I$(srcdir)/..                                  \
> +       -I$(top_srcdir)/camel                           \
> +       -I$(top_srcdir)/intl                            \
> +       -I$(top_srcdir)/e-util                          \
> +       -I$(top_srcdir)                                 \
> +       -I$(top_srcdir)/camel/providers/imap            \
> +       -I$(top_srcdir)/camel/providers/smtp            \
> +       $(EVOLUTION_CALENDAR_CFLAGS)                  \
> +       $(CAMEL_CFLAGS)                                 \
> +       $(GNOME_INCLUDEDIR)                             \
> +       $(E_UTIL_CFLAGS)                                \
> +       $(GTK_INCLUDEDIR)                               \
> +       -DCAMEL_PROVIDERDIR=\"$(camel_providerdir)\"    \
> +       -DG_LOG_DOMAIN=\"camel-groupwise-provider\"
> +
> +libcamelgroupwise_la_SOURCES =                         \
> +       camel-groupwise-provider.c              \
> +       groupwise-config-listener.c             \
> +       groupwise-config-listener.h             
> +
> +libcamelgroupwise_la_LDFLAGS = -avoid-version -module
> +
> +EXTRA_DIST = libcamelimap.urls
> --- libcamelgroupwise.urls.orig 2004-01-08 18:13:43.000000000 +0530
> +++ libcamelgroupwise.urls      2003-12-30 11:48:49.000000000 +0530
> @@ -0,0 +1 @@
> +groupwise
> --- camel-groupwise-provider.c.orig     2004-01-08 17:50:24.000000000
+0530
> +++ camel-groupwise-provider.c  2004-01-08 15:25:06.000000000 +0530
> @@ -0,0 +1,194 @@
> +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8
-*- */
> +/* camel-groupwise-provider.c: Groupwise provider registration code
*/
> +
> +/*
> + *  Authors: Jeffrey Stedfast <fejj ximian com>
> + *           Sivaiah Nallagatla <snallagatla novell com>
> + *           Rodrigo Moya <rodrigo ximian com>
> + *
> + *  Copyright 2003 Novell, Inc. (www.novell.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program 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
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; if not, write to the
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> + * Boston, MA 02111-1307, USA.
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <string.h>
> +#include <gmodule.h>
> +#include "camel-imap-store.h"
> +#include "camel-provider.h"
> +#include "camel-session.h"
> +#include "camel-smtp-transport.h"
> +#include "camel-url.h"
> +#include "camel-sasl.h"
> +#include "groupwise-config-listener.h"
> +
> +static void add_hash (guint *hash, char *s);
> +static guint groupwise_url_hash (gconstpointer key);
> +static gint check_equal (char *s1, char *s2);
> +static gint groupwise_url_equal (gconstpointer a, gconstpointer b);
> +static void free_groupwise_listener ( void );
> +
> +static GroupwiseConfigListener *config_listener = NULL;
> +
> +CamelProviderConfEntry groupwise_conf_entries[] = {
> +       /* override the labels/defaults of the standard settings */
> +
> +       { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
> +         N_("Checking for new mail") },
> +       { CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
> +         N_("Check for new messages in all folders"), "1" },
> +       { CAMEL_PROVIDER_CONF_SECTION_END },
> +
> +       /* extra Groupwise  configuration settings */
> +       /*CAMEL_PROVIDER_CONF_SECTION_START, "ldapserver", NULL,
> +         N_("Address Book") },
> +
> +       { CAMEL_PROVIDER_CONF_ENTRY, "ldap_server", NULL,
> +         N_("LDAP Server Name:") },
> +
> +       { CAMEL_PROVIDER_CONF_CHECKSPIN, "ldap_download_limit", NULL,
> +         N_("LDAP Download limit: %s"), "y:1:500:10000" },
> +
> +         { CAMEL_PROVIDER_CONF_SECTION_END }, */
> +
> +       { CAMEL_PROVIDER_CONF_CHECKBOX, "filter", NULL,
> +         N_("Apply filters to new messages in Inbox on this server"),
"0" },
> +
> +       { CAMEL_PROVIDER_CONF_CHECKBOX, "offline_sync", NULL,
> +         N_("Automatically synchronize remote mail locally"), "0" },
> +
> +       { CAMEL_PROVIDER_CONF_END }
> +};

^^ you've hardcoded the configuraiton options, neglecting any which
may be added/removed from the imap code.

> +
> +static CamelProvider groupwise_provider = {
> +       "groupwise",
> +       N_("Novell GroupWise"),
> +
> +       N_("For accesing Novell Groupwise servers"),
> +
> +       "mail",
> +
> +       CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
> +       CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL,
> +
> +       CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST |
CAMEL_URL_ALLOW_AUTH,
> +
> +       groupwise_conf_entries,
> +
> +       /* ... */
> +};
> +
> +CamelServiceAuthType camel_groupwise_password_authtype = {
> +       N_("Password"),
> +       
> +       N_("This option will connect to the IMAP server using a "
> +          "plaintext password."),
> +       
> +       "",
> +       TRUE
> +};
> +
> +void
> +camel_provider_module_init (CamelSession *session)
> +{
> +
> +
> +       CamelProvider *imap_provider;
> +       CamelProvider *smtp_provider;
> +       CamelSession *temp_session;
> +
> +       temp_session = CAMEL_SESSION ( camel_object_new
( CAMEL_SESSION_TYPE));
> +       imap_provider =  camel_session_get_provider (temp_session,
"imap://", NULL);
> +       smtp_provider = camel_session_get_provider (temp_session,
"smtp://", NULL);
> +
> +       groupwise_provider.url_hash = groupwise_url_hash;
> +       groupwise_provider.url_equal = groupwise_url_equal;
> +       groupwise_provider.authtypes = g_list_prepend
(groupwise_provider.authtypes,  &camel_groupwise_password_authtype);
> +
> +       if (imap_provider != NULL && smtp_provider != NULL) {
> +
> +               groupwise_provider.object_types[CAMEL_PROVIDER_STORE]
=  imap_provider->object_types [CAMEL_PROVIDER_STORE];
> +               groupwise_provider.object_types
[CAMEL_PROVIDER_TRANSPORT] = smtp_provider->object_types
[CAMEL_PROVIDER_TRANSPORT];
> +               camel_session_register_provider (session,
&groupwise_provider);
> +       }
> +
> +
> +       if (!config_listener)   {
> +
> +               config_listener = groupwise_config_listener_new
(gconf_client_get_default ()); 
> +               g_atexit ( free_groupwise_listener );
> +       }
> +       
> +       g_object_unref (temp_session);

this is a CamelObject object not a GObject.

> +
> +}
> +
> +void free_groupwise_listener ( void )
> +{
> +       g_object_unref (config_listener);
> +}
> +
> +static void
> +add_hash (guint *hash, char *s)
> +{
> +       if (s)
> +               *hash ^= g_str_hash(s);
> +}
> +
> +static guint
> +groupwise_url_hash (gconstpointer key)
> +{
> +       const CamelURL *u = (CamelURL *)key;
> +       guint hash = 0;
> +
> +       add_hash (&hash, u->user);
> +       add_hash (&hash, u->authmech);
> +       add_hash (&hash, u->host);
> +       hash ^= u->port;
> +       
> +       return hash;
> +}
> +
> +static gint
> +check_equal (char *s1, char *s2)
> +{
> +       if (s1 == NULL) {
> +               if (s2 == NULL)
> +                       return TRUE;
> +               else
> +                       return FALSE;
> +       }
> +       
> +       if (s2 == NULL)
> +               return FALSE;
> +
> +       return strcmp (s1, s2) == 0;
> +}
> +
> +static gint
> +groupwise_url_equal (gconstpointer a, gconstpointer b)
> +{
> +       const CamelURL *u1 = a, *u2 = b;
> +       
> +       return check_equal (u1->user, u2->user)
> +               && check_equal (u1->authmech, u2->authmech)
> +               && check_equal (u1->host, u2->host)
> +               && u1->port == u2->port;
> +}
> --- groupwise-config-listener.h.orig    2004-01-08 17:50:06.000000000
+0530
> +++ groupwise-config-listener.h 2004-01-06 16:08:20.000000000 +0530

It should start with camel-

camel-gw-listener might be a decent name.

> @@ -0,0 +1,63 @@
> +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8
-*- */
> +/*
> + * Authors :
> + *  
> + *  Sivaiah Nallagatla <snallagatla novell com>
> + *
> + * Copyright 2003, Novell, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
1307
> + * USA
> + */
> +
>
+                                                                                                                             
> +#ifndef GROUPWISE_CONFIG_LISTENER_H
> +#define GROUPWISE_CONFIG_LISTENER_H
>
+                                                                                                                             
> +
> +#include <e-util/e-account-list.h>
> +#include<libedataserver/e-source.h>
> +#include<libedataserver/e-source-list.h>
> +#include<e-util/e-url.h>
> +                         
> +G_BEGIN_DECLS
>
+                                                                                                                             
> +#define GROUPWISE_TYPE_CONFIG_LISTENER
(groupwise_config_listener_get_type ())
> +#define GROUPWISE_CONFIG_LISTENER(obj)
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GROUPWISE_TYPE_CONFIG_LISTENER,
GroupwiseConfigListener))
> +#define GROUPWISE_CONFIG_LISTENER_CLASS(klass)
(G_TYPE_CHECK_CLASS_CAST ((klass), GROUPWISE_TYPE_CONFIG_LISTENER,
GroupwiseConfigListenerClass))
> +#define GROUPWISE_IS_CONFIG_LISTENER(obj)
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GROUPWISE_TYPE_CONFIG_LISTENER))
> +#define GROUPWISE_IS_CONFIG_LISTENER_CLASS(klass)
(G_TYPE_CHECK_CLASS_TYPE ((obj), GROUPWISE_TYPE_CONFIG_LISTENER))
> +
> +typedef struct _GroupwiseConfigListener GroupwiseConfigListener;
> +typedef struct _GroupwiseConfigListenerClass
GroupwiseConfigListenerClass;
> +typedef struct _GroupwiseConfigListenerPrivate
GroupwiseConfigListenerPrivate;
> +struct _GroupwiseConfigListener {
> +       GObject parent;
>
+                                                                                                                        
> +       GroupwiseConfigListenerPrivate *priv;
> +};
>
+                                                                                                                             
> +struct _GroupwiseConfigListenerClass {
> +       GObjectClass parent_class;
>
+                                                                                                                             
> +       
> +};
>
+                                                                                                                             
> +GType                   groupwise_config_listener_get_type (void);
> +GroupwiseConfigListener *groupwise_config_listener_new
(GConfClient *gconf);
>
+                                                                                                                             
> +G_END_DECLS
>
+                                                                                                                             
> +#endif 
> +
> --- groupwise-config-listener.c.orig    2004-01-08 16:59:06.000000000
+0530
> +++ groupwise-config-listener.c 2004-01-08 15:53:31.000000000 +0530
> @@ -0,0 +1,478 @@
> +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8
-*- */
> +/*
> + * Authors :
> + *  
> + *  Sivaiah Nallagatla <snallagatla novell com>
> + *
> + * Copyright 2003, Novell, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
1307
> + * USA
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
>
+                                                                                                                             
> +#include "groupwise-config-listener.h"
> +#include <string.h>
> +
> +/*stores some info about all currently existing groupwise accounts 
> +  list of GwAccountInfo structures */
> +
> +static         GList *groupwise_accounts = NULL;
> +
> +struct _GroupwiseConfigListenerPrivate {
> +       GConfClient *gconf_client;
> +       /* we get notification about mail account changes form this
object */
> +       EAccountList *account_list;
> +                  
> +};
> +
> +struct _GwAccountInfo {
> +       char *uid;
> +       char *name;
> +       char *source_url;
> +};
> +
> +typedef struct _GwAccountInfo GwAccountInfo;
> +
> +#define GROUPWISE_URI_PREFIX   "groupwise://" 
> +#define GROUPWISE_PREFIX_LENGTH 12
> +
> +#define PARENT_TYPE G_TYPE_OBJECT
> +
> +static GObjectClass *parent_class = NULL;
>
+                                                                                                                             
> +static void dispose (GObject *object);
> +static void finalize (GObject *object);
>
+                                                                                                                             
> +
> +static void 
> +groupwise_config_listener_class_init (GroupwiseConfigListenerClass
*class)
> +{
> +       GObjectClass *object_class;
> +       
> +       parent_class =  g_type_class_ref (PARENT_TYPE);
> +       object_class = G_OBJECT_CLASS (class);
> +       
> +       /* virtual method override */
> +       object_class->dispose = dispose;
> +       object_class->finalize = finalize;
> +
> +}
> +
> +static void 
> +groupwise_config_listener_init (GroupwiseConfigListener
*config_listener,  GroupwiseConfigListenerClass *class)
> +{
> +       config_listener->priv = g_new0
(GroupwiseConfigListenerPrivate, 1);
> +       
> +}
> +
> +static void 
> +dispose (GObject *object)
> +{
> +       GroupwiseConfigListener *config_listener =
GROUPWISE_CONFIG_LISTENER (object);
> +       
> +       g_object_unref (config_listener->priv->gconf_client);
> +       g_object_unref (config_listener->priv->account_list);
> +
> +       G_OBJECT_CLASS (parent_class)->dispose (object);
> +
> +}
> +
> +static void 
> +finalize (GObject *object)
> +{
> +       GroupwiseConfigListener *config_listener =
GROUPWISE_CONFIG_LISTENER (object);
> +       GList *list;
> +       GwAccountInfo *info;
> +
> +       if (config_listener->priv) {
> +               g_free (config_listener->priv);
> +       }
> +
> +       for ( list = g_list_first (groupwise_accounts); list ; list =
g_list_next (list) ) {
> +              
> +               info = (GwAccountInfo *) (list->data);
> +
> +               if (info) {
> +                       
> +                       g_free (info->uid);
> +                       g_free (info->name);
> +                       g_free (info->source_url);
> +                       g_free (info);
> +               }
> +       }
> +       
> +       g_list_free (groupwise_accounts);
> +
> +}
> +
> +/*determines whehter the passed in account is groupwise or not by
looking at source url */
> +
> +static gboolean
> +is_groupwise_account (EAccount *account)
> +{
> +       return (strncmp (account->source->url,  GROUPWISE_URI_PREFIX,
GROUPWISE_PREFIX_LENGTH ) == 0);
> +}
> +
> +
> +/* looks up for an existing groupwise account info in the
groupwise_accounts list based on uid */
> +
> +static GwAccountInfo* 
> +lookup_account_info (const char *key)
> +{
> +       GList *list;
> +        GwAccountInfo *info ;
> +       int found = 0;
>
+                                                                      
> +        if (!key)
> +                return NULL;
> +
> +       info = NULL;
> +
> +        for (list = g_list_first (groupwise_accounts);  list;  list =
g_list_next (list)) {
>
+                                                                                                                                      
> +                info = (GwAccountInfo *) (list->data);
> +                found = strcmp (info->uid, key) == 0;
> +               if (found)
> +                       break;
>
+                                                                                                                       
> +       }
>
+                                                                                                                                    
> +       return info;
> +}
> +
> +
> +static void
> +add_esource (const char *conf_key, const char *group_name,  const
char* source_name, const char* relative_uri)
> +{
> +       ESourceList *source_list;
> +       ESourceGroup *group;
> +       ESource *source;
> +       
> +       source_list = e_source_list_new_for_gconf
(gconf_client_get_default (), conf_key);
> +
> +       group = e_source_group_new (group_name,
GROUPWISE_URI_PREFIX);
> +       if ( !e_source_list_add_group (source_list, group, -1))
> +               return;
> +
> +       source = e_source_new (source_name, relative_uri);
> +       e_source_group_add_source (group, source, -1);
> +
> +       e_source_list_sync (source_list, NULL);
> +
> +       g_object_unref (source);
> +       g_object_unref (group);
> +       g_object_unref (source_list);
> +}
> +
> +
> +static void 
> +remove_esource (const char *conf_key, const char *group_name, char*
source_name, const char* relative_uri)
> +{
> +       ESourceList *list;
> +        ESourceGroup *group;
> +        ESource *source;
> +        GSList *groups;
> +        GSList *sources;
> +       gboolean found_group;
> +
> +        list = e_source_list_new_for_gconf (gconf_client_get_default
(), conf_key);
> +       groups = e_source_list_peek_groups (list); 
> +       
> +       found_group = FALSE;
> +       
> +       for ( ; groups != NULL && !found_group; groups = g_slist_next
(groups)) {
> +
> +               group = E_SOURCE_GROUP (groups->data);
> +               
> +               if (strcmp (e_source_group_peek_name (group),
group_name) == 0 && 
> +                  strcmp (e_source_group_peek_base_uri (group),
GROUPWISE_URI_PREFIX ) == 0) {
> +
> +                       sources = e_source_group_peek_sources (group);
> +                       
> +                       for( ; sources != NULL; sources = g_slist_next
(sources)) {
> +                               
> +                               source = E_SOURCE (sources->data);
> +                               
> +                               if (strcmp (e_source_peek_relative_uri
(source), relative_uri) == 0) {
> +                                       
> +                                       e_source_list_remove_group
(list, group);
> +                                       e_source_list_sync (list,
NULL);        
> +                                       found_group = TRUE;
> +                                       break;
> +                                       
> +                               }
> +                       }
> +
> +               }
> +               
> +             
> +       }
> +
> +       g_object_unref (list);
> +                       
> +       
> +}
> +
> +/* looks up for e-source with having same info as old_account_info
and changes its values passed in new values */
> +
> +static void 
> +modify_esource (const char* conf_key, GwAccountInfo
*old_account_info, const char* new_group_name, const char*
new_relative_uri)
> +{
> +       ESourceList *list;
> +        ESourceGroup *group;
> +        ESource *source;
> +        GSList *groups;
> +       GSList *sources;
> +       char *old_relative_uri;
> +       EUri *uri;
> +       gboolean found_group;
> +
> +       uri = e_uri_new (old_account_info->source_url);
> +       old_relative_uri =  g_strdup_printf ("%s %s", uri->user, uri-
>host);
> +       
> +        list = e_source_list_new_for_gconf (gconf_client_get_default
(), conf_key);
> +       groups = e_source_list_peek_groups (list); 
> +
> +       found_group = FALSE;
> +
> +       for ( ; groups != NULL &&  !found_group; groups = g_slist_next
(groups)) {
> +
> +               group = E_SOURCE_GROUP (groups->data);
> +               
> +               if (strcmp (e_source_group_peek_name (group),
old_account_info->name) == 0 && 
> +                  strcmp (e_source_group_peek_base_uri (group),
GROUPWISE_URI_PREFIX) == 0) {
> +                       
> +                       sources = e_source_group_peek_sources (group);
> +                       
> +                       for ( ; sources != NULL; sources =
g_slist_next (sources)) {
> +                               
> +                               source = E_SOURCE (sources->data);
> +                               
> +                               if (strcmp (e_source_peek_relative_uri
(source), old_relative_uri) == 0) {
> +                                       
> +                                       e_source_group_set_name
(group, new_group_name);
> +                                       e_source_set_relative_uri
(source, new_relative_uri);
> +                                       e_source_list_sync (list,
NULL);
> +                                       found_group = TRUE;
> +                                       break;
> +                               }
> +                       }
> +               }
> +       }
> +
> +       g_object_unref (list);
> +       e_uri_free (uri);
> +       g_free (old_relative_uri);
> +       
> +}
> +/* add sources for calendar and tasks if the account added is
groupwise account
> +   adds the new account info to  groupwise_accounts list */
> +
> +static void 
> +add_calendar_tasks_sources (GwAccountInfo *info)
> +{
> +       EUri *uri;
> +       char *relative_uri;
> +       
> +       uri = e_uri_new (info->source_url);

camel should use camel_url's.

> +       relative_uri =  g_strdup_printf ("%s %s", uri->user, uri-
>host);
> +       add_esource ("/apps/evolution/calendar/sources", info->name,
"Default", relative_uri);
> +       add_esource ("/apps/evolution/tasks/sources", info->name,
"Default", relative_uri);
> +       
> +       groupwise_accounts = g_list_append (groupwise_accounts, info);
> +       
> +       e_uri_free (uri);
> +       g_free (relative_uri);
> +
> +}
> +
> +/* removes calendar and tasks sources if the account removed is
groupwise account 
> +   removes the the account info from groupwise_account list */
> +
> +static void 
> +remove_calendar_tasks_sources (GwAccountInfo *info)
> +{
> +       EUri *uri;
> +       char *relative_uri;
> +       
> +       uri = e_uri_new (info->source_url);

ditto.

> +       relative_uri =  g_strdup_printf ("%s %s", uri->user, uri-
>host);
> +
> +       remove_esource ("/apps/evolution/calendar/sources", info-
>name,  "Default", relative_uri);
> +       remove_esource ("/apps/evolution/tasks/sources", info->name,
"Default", relative_uri);
> +       
> +       g_free (info->uid);
> +       g_free (info->name);
> +       g_free (info->source_url);
> +       groupwise_accounts = g_list_remove (groupwise_accounts, info);
> +       g_free (info);
> +       e_uri_free (uri);
> +       g_free (relative_uri);
> +
> +}
> +
> +static void 
> +account_added (EAccountList *account_listener, EAccount *account)
> +{
> +       EUri *uri;
> +       GwAccountInfo *info;
> +
> +       if (!is_groupwise_account (account))
> +               return;
> +
> +       uri = e_uri_new (account->source->url);

ditto.

you also leak the uri here.

> +       info = g_new0 (GwAccountInfo, 1);
> +       info->uid = g_strdup (account->uid);
> +       info->name = g_strdup (account->name);
> +       info->source_url = g_strdup (account->source->url);
> +       
> +       add_calendar_tasks_sources (info);
> +       
> +}
> +
> +
> +
> +static void
> +account_changed (EAccountList *account_listener, EAccount *account)
> +{
> +       gboolean is_gw_account;
> +       EUri *uri;
> +       char *relative_uri;
> +
> +       GwAccountInfo *existing_account_info;
> +       is_gw_account = is_groupwise_account (account);
> +       existing_account_info = lookup_account_info (account->uid);
> +               
> +       if (existing_account_info == NULL && is_gw_account) {
> +               /* some account of other type is changed to Groupwise
*/
> +               account_added (account_listener, account);
> +
> +       } else if ( existing_account_info != NULL && !is_gw_account) {
> +
> +               /*Groupwise account is changed to some other type */
> +
> +               remove_calendar_tasks_sources
( existing_account_info);
> +
> +       } else if ( existing_account_info != NULL && is_gw_account ) {
> +
> +               /* some info of groupwise account is changed . update
the sources with new info if required */
> + 
> +               if (strcmp (existing_account_info->name, account-
>name) != 0 || strcmp (existing_account_info->source_url, account-
>source->url) != 0) {
> +                       
> +                       uri = e_uri_new (account->source->url);
> +                       relative_uri =  g_strdup_printf ("%s %s", uri-
>user, uri->host);
> +                       modify_esource ("/apps/evolution/calendar/
sources", existing_account_info, account->name, relative_uri);
> +                       modify_esource ("/apps/evolution/tasks/
sources", existing_account_info, account->name, relative_uri);
> +                       g_free (existing_account_info->name);
> +                       g_free (existing_account_info->source_url);
> +                       existing_account_info->name = g_strdup
(account->name);
> +                       existing_account_info->source_url = g_strdup
(account->source->url);
> +                       e_uri_free (uri);
> +               }
> +               
> +       }
> +               
> +       
> +} 
> +
> +static void 
> +account_removed (EAccountList *account_listener, EAccount *account)
> +{
> +               GwAccountInfo *info;
> +       
> +       if (!is_groupwise_account (account))
> +               return;
> +       
> +       info = lookup_account_info (account->uid);
> +       if (info == NULL) {
> +               return;
> +       }
> +
> +       remove_calendar_tasks_sources (info);
> +
> +}
> +
> +static void
> +groupwise_config_listener_construct (GroupwiseConfigListener *
config_listener)
> +{
> +       EIterator *iter;
> +       EAccount *account;
> +       GwAccountInfo *info ;
> +       
> +               config_listener->priv->account_list =
e_account_list_new (config_listener->priv->gconf_client);
> +
> +       for ( iter = e_list_get_iterator (E_LIST ( config_listener-
>priv->account_list) ) ; e_iterator_is_valid (iter); e_iterator_next
(iter) ) {
> +               
> +               account = E_ACCOUNT (e_iterator_get (iter));
> +               if ( is_groupwise_account (account)) {
> +                       
> +                       info = g_new0 (GwAccountInfo, 1);
> +                       info->uid = g_strdup (account->uid);
> +                       info->name = g_strdup (account->name);
> +                       info->source_url = g_strdup (account->source-
>url);
> +                       groupwise_accounts = g_list_append
(groupwise_accounts, info);
> +                       
> +               }
> +                       
> +       }
> +       g_signal_connect (config_listener->priv->account_list,
"account_added", G_CALLBACK (account_added), NULL);
> +       g_signal_connect (config_listener->priv->account_list,
"account_changed", G_CALLBACK (account_changed), NULL);
> +       g_signal_connect (config_listener->priv->account_list,
"account_removed", G_CALLBACK (account_removed), NULL);
> +       
> +       
> +}
> +
> +GType
> +groupwise_config_listener_get_type (void)
> +{
> +       static GType groupwise_config_listener_type  = 0;
> +
> +       if (!groupwise_config_listener_type) {
> +               static GTypeInfo info = {
> +                        sizeof (GroupwiseConfigListenerClass),
> +                        (GBaseInitFunc) NULL,
> +                        (GBaseFinalizeFunc) NULL,
> +                        (GClassInitFunc)
groupwise_config_listener_class_init,
> +                        NULL, NULL,
> +                        sizeof (GroupwiseConfigListener),
> +                        0,
> +                        (GInstanceInitFunc)
groupwise_config_listener_init
> +                };
> +               groupwise_config_listener_type =
g_type_register_static (PARENT_TYPE, "GroupwiseConfigListener", &info,
0);
> +       }
> +
> +       return groupwise_config_listener_type;
> +}

Things in camel need to be thread-safe, are GObjects thread safe enough
now?

> +GroupwiseConfigListener*
> +groupwise_config_listener_new (GConfClient * client)
> +{
> +       GroupwiseConfigListener *config_listener;
> +       
> +       config_listener = g_object_new
(GROUPWISE_TYPE_CONFIG_LISTENER, NULL);
> +       config_listener->priv->gconf_client = client;
> +       g_object_ref (client);
> +       
> +       groupwise_config_listener_construct (config_listener);
> +
> +       return config_listener;
> +
> +}
> +
> +
On Thu, 2004-01-08 at 19:07 +0530, Siva wrote:
> Hi,
> I am attaching a patch which has a camel provider for groupwise.
> groupwise camel provider juset uses IMAP for it provider store and SMTP
> for its transport. 
> 
> groupwise_config_listner is class implemented for adding e-sources for
> calender and tasks whenever a groupwise acount is created from mail
> account setup gui. It also deletes or modifies e-sources when 
> a groupwise account is deleted or modified. 
> 
> Thanks, 
> Sivaiah




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]