Hi guys! This morning I have a first version of the e-d-s resource importer. For the moment, it let you select the Addressbook from which to import the resources, and import all the resources in the group to planner. It is a probe of concept and all the libraries seems to work together nicely. I have a build environment using "--enable-eds" flag and no problems at all. I attach a little screenshot of what I am doing right now. The GUI is in its first steps ;-) I am using GtkComboBox now that we have migrated to GTK+ 2.4. Maybe could be a good idea to fill bugs against all the places we use deprected widgets in Planner. What do you think? With this importer we can take resource data from evolution and LDAP servers. But be careful, we need more work to put the plugin in good shape and more important, we have to wait until evolution data server 1.0 is published and then, be sure we work nicely with it. I think I will continue working in the plugin next weeks. If someone if interested in see the code, I attach the main plugin file. If you want to compile it, please ask me in order to send you some more files (glade files) that you will need. Cheers -- Alvaro del Castillo San Félix Lambdaux Software Services S.R.L. Universidad Rey Juan Carlos Centro de Apoyo Tecnológico C/ Tulipán sn 28933 Mostoles, Madrid-Spain www.lambdaux.com acs lambdaux com
Attachment:
pantallazo-peq.png
Description: PNG image
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2004 Alvaro del Castillo <acs barrapunto com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * 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. */ #include <config.h> #include <glib.h> #include <string.h> #include <bonobo/bonobo-ui-component.h> #include <bonobo/bonobo-ui-util.h> #include <glade/glade.h> #include <gtk/gtklist.h> #include <gtk/gtkcombobox.h> #include <gtk/gtkbutton.h> #include <gtk/gtktreemodel.h> #include <gtk/gtkliststore.h> #include <gtk/gtkcellrenderertext.h> #include <gtk/gtkcellrenderertoggle.h> #include <gtk/gtkcellrendererpixbuf.h> #include <gtk/gtkcelllayout.h> #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-file-entry.h> #include <gconf/gconf-client.h> #include "planner-window.h" #include "planner-plugin.h" /* Evolution Data Server sources */ #include <libedataserver/e-source-list.h> #include <libedataserver/e-source-group.h> /* Calendar */ #include <libecal/e-cal.h> /* Addressbook */ #include <libebook/e-book.h> struct _PlannerPluginPriv { PlannerWindow *main_window; MrpProject *project; /* Manage groups of source from e-d-s */ ESourceList *source_list; GtkComboBox *select_group; GSList *groups; GtkTreeModel *groups_model; /* Manage resource from a group */ GtkTreeView *resources_tree_view; GtkTreeModel *resources_model; /* Main widgets */ GladeXML *glade; GtkWidget *dialog_get_resources; GtkWidget *dialog_load_resources; }; static void eds_plugin_import (BonoboUIComponent *component, gpointer user_data, const gchar *cname); static void eds_create_groups_model (GSList *groups, PlannerPlugin *plugin); static void eds_get_resources_ok_button_clicked (GtkButton *button, PlannerPlugin *plugin); static void eds_get_resources_cancel_button_clicked (GtkButton *button, PlannerPlugin *plugin); void plugin_init (PlannerPlugin *plugin, PlannerWindow *main_window); void plugin_exit (PlannerPlugin *plugin); static BonoboUIVerb verbs[] = { BONOBO_UI_VERB ("EDS Import", eds_plugin_import), BONOBO_UI_VERB_END }; static void eds_plugin_import (BonoboUIComponent *component, gpointer user_data, const gchar *cname) { PlannerPlugin *plugin; PlannerPluginPriv *priv; GtkWidget *ok_button; GtkWidget *cancel_button; GtkCellRenderer *renderer; GConfClient *gconf_client; ESourceList *source_list; GSList *groups; plugin = PLANNER_PLUGIN (user_data); priv = plugin->priv; priv->glade = glade_xml_new (GLADEDIR"/evolution-data-server.glade", NULL, NULL); priv->dialog_get_resources = glade_xml_get_widget (priv->glade, "resources_get"); gtk_window_set_transient_for (GTK_WINDOW (priv->dialog_get_resources), GTK_WINDOW (priv->main_window)); priv->select_group = (GtkComboBox *) glade_xml_get_widget (priv->glade, "select_group"); priv->resources_tree_view = (GtkTreeView *) glade_xml_get_widget (priv->glade, "resources"); ok_button = glade_xml_get_widget (priv->glade, "ok_button"); cancel_button = glade_xml_get_widget (priv->glade, "cancel_button"); g_signal_connect (ok_button, "clicked", G_CALLBACK (eds_get_resources_ok_button_clicked), user_data); g_signal_connect (cancel_button, "clicked", G_CALLBACK (eds_get_resources_cancel_button_clicked), user_data); gtk_widget_show (priv->dialog_get_resources); gconf_client = gconf_client_get_default (); source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/addressbook/sources"); /* List with addressbook groups */ groups = e_source_list_peek_groups (source_list); eds_create_groups_model (groups, plugin); gtk_combo_box_set_model (priv->select_group, priv->groups_model); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->select_group), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->select_group), renderer, "text", 0, NULL); g_slist_free (groups); } static void eds_create_groups_model (GSList *groups, PlannerPlugin *plugin) { GtkListStore *model; GtkTreeIter iter; GSList *sl; const gchar *name; if (groups == NULL) { return; } model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT); for (sl = groups; sl; sl = sl->next) { name = e_source_group_peek_name (sl->data); g_message ("Name for group: %s", name); gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, 0, name, 1, sl->data, -1); } plugin->priv->groups_model = (GtkTreeModel *) model; } /* For now we show all the sources from a group in a List. Later we will us a Tree to show them usings groups. */ static void eds_load_resources (ESourceGroup *group, PlannerPlugin *plugin) { GtkListStore *model; GtkTreeIter iter; GSList *sources, *sl; PlannerPluginPriv *priv; g_return_if_fail (E_IS_SOURCE_GROUP (group)); sources = e_source_group_peek_sources (group); if (sources == NULL) { return; } priv = plugin->priv; model = (GtkListStore *) priv->resources_model; /* We will show the only te resource name for now */ if (model) { gtk_list_store_clear (model); } else { model = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_OBJECT); priv->resources_model = (GtkTreeModel *) model; gtk_tree_view_set_model (priv->resources_tree_view, priv->resources_model); gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Name"), gtk_cell_renderer_text_new (), "text", 0, NULL); gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Import"), gtk_cell_renderer_toggle_new (), "active", 1, NULL); gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Photo"), gtk_cell_renderer_pixbuf_new (), "pixbuf", 2, NULL); } for (sl = sources; sl; sl = sl->next) { EBook *client; EBookQuery *query; GError *error = NULL; GList *l, *contacts; GdkPixbuf *pixbuf; g_message ("Open image: %s", IMAGEDIR"/resources.png"); pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR"/resources.png", NULL); client = e_book_new (sl->data, NULL); if (!e_book_open (client, TRUE, NULL)) { continue; } query = e_book_query_field_exists (E_CONTACT_FULL_NAME); e_book_get_contacts (client, query, &contacts, &error); for (l = contacts; l; l = l->next) { gchar *name; name = e_contact_get (l->data, E_CONTACT_GIVEN_NAME); g_message ("Name for contact: %s", name); gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, 0, name, 1, FALSE, 2, pixbuf, 3, l->data, -1); /* FIXME: Test */ if (1) { MrpResource *resource = mrp_resource_new (); mrp_object_set (resource, "name", name); mrp_project_add_resource (priv->project, resource); } } } } static void eds_get_resources_ok_button_clicked (GtkButton *button, PlannerPlugin *plugin) { GtkTreeIter iter; PlannerPluginPriv *priv = plugin->priv; ESourceGroup *group; if (gtk_combo_box_get_active_iter (priv->select_group, &iter)) { gtk_tree_model_get (priv->groups_model, &iter, 1, &group, -1); eds_load_resources (group, plugin); } } static void eds_get_resources_cancel_button_clicked (GtkButton *button, PlannerPlugin *plugin) { PlannerPluginPriv *priv = plugin->priv; gtk_widget_destroy (priv->dialog_get_resources); } G_MODULE_EXPORT void plugin_init (PlannerPlugin *plugin, PlannerWindow *main_window) { PlannerPluginPriv *priv; BonoboUIContainer *ui_container; BonoboUIComponent *ui_component; priv = g_new0 (PlannerPluginPriv, 1); plugin->priv = priv; priv->main_window = main_window; priv->project = planner_window_get_project (plugin->main_window); ui_container = planner_window_get_ui_container (main_window); ui_component = bonobo_ui_component_new_default (); bonobo_ui_component_set_container (ui_component, BONOBO_OBJREF (ui_container), NULL); bonobo_ui_component_freeze (ui_component, NULL); bonobo_ui_component_add_verb_list_with_data (ui_component, verbs, plugin); bonobo_ui_util_set_ui (ui_component, DATADIR, "/planner/ui/eds-plugin.ui", "edsplugin", NULL); bonobo_ui_component_thaw (ui_component, NULL); } G_MODULE_EXPORT void plugin_exit (PlannerPlugin *plugin) { /*g_message ("Test exit");*/ }