From da4c46c126c59356c64030c1f05ddc2a3f72cad0 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Fri, 1 Jul 2005 10:06:24 +0000 Subject: Added new file entries for calendar , contacts and change-password enabled 2005-07-01 Praveen Kumar * Makefile.am : Added new file entries for calendar , contacts and change-password * exchange-account-setup.c (btn_chpass_clicked) : enabled the code * exchange-operations.c (exchange_operations_cta_add_node_to_tree) : This now stores the relative uri of the node to the model (exchange_operations_cta_select_node_from_tree) : Added new. This selects the node for a given relative uri. * exchange-operations.h : Similar * org-gnome-exchange-operations.eplug.in : Added commit hook action for calendar and contacts * exchange-change-password.c : Added new * exchange-calendar.c : Added new * exchange-contacts.c : Added new svn path=/trunk/; revision=29610 --- plugins/exchange-operations/ChangeLog | 16 + plugins/exchange-operations/Makefile.am | 4 + .../exchange-operations/exchange-account-setup.c | 27 +- plugins/exchange-operations/exchange-calendar.c | 332 +++++++++++++++++++++ .../exchange-operations/exchange-change-password.c | 135 +++++++++ plugins/exchange-operations/exchange-contacts.c | 327 ++++++++++++++++++++ plugins/exchange-operations/exchange-operations.c | 116 +++++-- plugins/exchange-operations/exchange-operations.h | 38 ++- 8 files changed, 941 insertions(+), 54 deletions(-) create mode 100644 plugins/exchange-operations/exchange-calendar.c create mode 100644 plugins/exchange-operations/exchange-change-password.c create mode 100644 plugins/exchange-operations/exchange-contacts.c (limited to 'plugins') diff --git a/plugins/exchange-operations/ChangeLog b/plugins/exchange-operations/ChangeLog index e00832f25d..154d3d4595 100644 --- a/plugins/exchange-operations/ChangeLog +++ b/plugins/exchange-operations/ChangeLog @@ -1,3 +1,19 @@ +2005-07-01 Praveen Kumar + + * Makefile.am : Added new file entries for calendar , contacts + and change-password + * exchange-account-setup.c (btn_chpass_clicked) : enabled the code + * exchange-operations.c (exchange_operations_cta_add_node_to_tree) : + This now stores the relative uri of the node to the model + (exchange_operations_cta_select_node_from_tree) : Added new. This + selects the node for a given relative uri. + * exchange-operations.h : Similar + * org-gnome-exchange-operations.eplug.in : Added commit hook action + for calendar and contacts + * exchange-change-password.c : Added new + * exchange-calendar.c : Added new + * exchange-contacts.c : Added new + 2005-07-01 Sarfraaz Ahmed * exchange-account-setup.c(print_error) : Added new. This prints the diff --git a/plugins/exchange-operations/Makefile.am b/plugins/exchange-operations/Makefile.am index 470316b750..2bd1f119c8 100644 --- a/plugins/exchange-operations/Makefile.am +++ b/plugins/exchange-operations/Makefile.am @@ -18,6 +18,10 @@ liborg_gnome_exchange_operations_la_SOURCES = \ exchange-operations.h \ exchange-config-listener.c \ exchange-config-listener.h \ + exchange-calendar.c \ + exchange-contacts.c \ + exchange-change-password.c \ + exchange-change-password.h \ exchange-account-setup.c liborg_gnome_exchange_operations_la_LIBADD = \ diff --git a/plugins/exchange-operations/exchange-account-setup.c b/plugins/exchange-operations/exchange-account-setup.c index daae054a2f..84e08e5d4e 100644 --- a/plugins/exchange-operations/exchange-account-setup.c +++ b/plugins/exchange-operations/exchange-account-setup.c @@ -113,38 +113,21 @@ static void btn_chpass_clicked (GtkButton *button, gpointer data) { ExchangeAccount *account; - GSList *acclist; char *old_password, *new_password; -#if 0 - if (!exchange_global_config_listener) { - g_print ("FATAL: Exchange global config listener is not initialized.\n"); - return; - } - else { - g_print ("Exchange global config listener is initialized sucessfully.\n"); - } -#endif - acclist = exchange_config_listener_get_accounts (exchange_global_config_listener); - /* FIXME: For now, we have only one account in the list. - Find a way to handle multiple accounts. - */ - if (!acclist) - return; - account = acclist->data; + account = exchange_operations_get_exchange_account (); old_password = exchange_account_get_password (account); if (!old_password) { - printf ("could not fetch old password\n"); + g_print ("Could not fetch old password\n"); return; } - + new_password = exchange_get_new_password (old_password, TRUE); g_print ("Current password is \"%s\"\n", old_password); - //new_password = exchange_get_new_password (old_password, TRUE); exchange_account_set_password (account, old_password, new_password); -// g_free (old_password); -// g_free (new_password); + g_free (old_password); + g_free (new_password); } static void diff --git a/plugins/exchange-operations/exchange-calendar.c b/plugins/exchange-operations/exchange-calendar.c new file mode 100644 index 0000000000..6e4c50aa28 --- /dev/null +++ b/plugins/exchange-operations/exchange-calendar.c @@ -0,0 +1,332 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Praveen Kumar + * Copyright (C) 2005 Novell, Inc. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "calendar/gui/dialogs/calendar-setup.h" +#include "mail/em-account-editor.h" +#include "mail/em-config.h" +#include "e-util/e-account.h" +#include "e-util/e-error.h" + +#include "exchange-operations.h" + +enum { + CALENDARNAME_COL, + CALENDARRURI_COL, + NUM_COLS +}; + +GPtrArray *e_exchange_calendar_get_calendars (ECalSourceType *ftype); +void e_exchange_calendar_pcalendar_on_change (GtkTreeView *treeview, ESource *source); +GtkWidget *e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data); +gboolean e_exchange_calendar_check (EPlugin *epl, EConfigHookPageCheckData *data); +void e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target); + +/* FIXME: Reconsider the prototype of this function */ +GPtrArray * +e_exchange_calendar_get_calendars (ECalSourceType *ftype) +{ + ExchangeAccount *account; + GPtrArray *folder_array; + GPtrArray *calendar_list; + + EFolder *folder; + int i, prefix_len; + gchar *type; + gchar *uri_prefix; + gchar *tmp, *ruri; + gchar *tstring; + + /* FIXME: Compiler warns here; review needed */ + if (GPOINTER_TO_INT (ftype) == E_CAL_SOURCE_TYPE_EVENT) { /* Calendars */ + tstring = g_strdup ("calendar"); + } + else if (GPOINTER_TO_INT (ftype) == E_CAL_SOURCE_TYPE_TODO) { /* Tasks */ + tstring = g_strdup ("tasks"); + } + else { + /* FIXME: Would this ever happen? If so, handle it wisely */ + tstring = NULL; + } + + account = exchange_operations_get_exchange_account (); + + /* FIXME: Reconsider this hardcoding */ + uri_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + prefix_len = strlen (uri_prefix); + + calendar_list = g_ptr_array_new (); + + folder_array = exchange_account_get_folders (account); + + for (i=0; ilen; ++i) { + folder = g_ptr_array_index (folder_array, i); + type = (gchar *)e_folder_get_type_string (folder); + + if (!strcmp (type, tstring)) { + tmp = (gchar *)e_folder_get_physical_uri (folder); + if (g_str_has_prefix (tmp, uri_prefix)) { + ruri = g_strdup (tmp+prefix_len); /* ATTN: Shouldn't free this explictly */ + g_ptr_array_add (calendar_list, (gpointer)ruri); + } + } + } + + g_free (uri_prefix); + g_free (tstring); + return calendar_list; +} + +void +e_exchange_calendar_pcalendar_on_change (GtkTreeView *treeview, ESource *source) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + ExchangeAccount *account; + gchar *es_ruri, *ruri; + + account = exchange_operations_get_exchange_account (); + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_get_selected(selection, &model, &iter); + + gtk_tree_model_get (model, &iter, CALENDARRURI_COL, &ruri, -1); + es_ruri = g_strconcat (account->account_filename, "/", ruri, NULL); + e_source_set_relative_uri (source, es_ruri); + g_free (ruri); + g_free (es_ruri); +} + +GtkWidget * +e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data) +{ + static GtkWidget *lbl_pcalendar, *scrw_pcalendar, *tv_pcalendar; + GtkWidget *parent; + GtkTreeStore *ts_pcalendar; + GtkCellRenderer *cr_calendar; + GtkTreeViewColumn *tvc_calendar; + GPtrArray *callist; + gchar *ruri; + ExchangeAccount *account; + gchar *account_name; + ECalSourceType *type; + int row, i; + ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; + EUri *uri; + gchar *uri_text; + gboolean src_exists = TRUE; + static GtkWidget *hidden = NULL; + + if (!hidden) + hidden = gtk_label_new (""); + + if (data->old) { + /* FIXME: Review this */ + gtk_widget_destroy (lbl_pcalendar); + gtk_widget_destroy (scrw_pcalendar); + gtk_widget_destroy (tv_pcalendar); + } + + uri_text = e_source_get_uri (t->source); + uri = e_uri_new (uri_text); + + if (strcmp (uri->protocol, "exchange")) { + e_uri_free (uri); + g_free (uri_text); + return hidden; + } + + e_uri_free (uri); + g_free (uri_text); + + if (!strlen (e_source_peek_relative_uri (t->source))) { + src_exists = FALSE; + } + + parent = data->parent; + row = ((GtkTable*)parent)->nrows; + + /* REVIEW: Should this handle be freed? - Attn: surf */ + account = exchange_operations_get_exchange_account (); + account_name = account->account_name; + + /* FIXME: Take care of i18n */ + lbl_pcalendar = gtk_label_new_with_mnemonic (_("_Location:")); + gtk_widget_show (lbl_pcalendar); + gtk_misc_set_alignment (GTK_MISC (lbl_pcalendar), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (parent), lbl_pcalendar, 0, 2, row, row+1, GTK_FILL|GTK_EXPAND, 0, 0, 0); + + ts_pcalendar = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING); + + callist = e_exchange_calendar_get_calendars (t->source_type); + + for (i=0; ilen; ++i) { + ruri = g_ptr_array_index (callist, i); + exchange_operations_cta_add_node_to_tree (ts_pcalendar, NULL, ruri); + } + + cr_calendar = gtk_cell_renderer_text_new (); + tvc_calendar = gtk_tree_view_column_new_with_attributes (account_name, cr_calendar, "text", CALENDARNAME_COL, NULL); + tv_pcalendar = gtk_tree_view_new_with_model (GTK_TREE_MODEL (ts_pcalendar)); + gtk_tree_view_append_column (GTK_TREE_VIEW (tv_pcalendar), tvc_calendar); + g_object_set (tv_pcalendar, "expander-column", tvc_calendar, "headers-visible", TRUE, NULL); + gtk_tree_view_expand_all (GTK_TREE_VIEW (tv_pcalendar)); + + scrw_pcalendar = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrw_pcalendar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrw_pcalendar), GTK_SHADOW_IN); + g_object_set (scrw_pcalendar, "height-request", 150, NULL); + gtk_container_add (GTK_CONTAINER (scrw_pcalendar), tv_pcalendar); + gtk_label_set_mnemonic_widget (GTK_LABEL (lbl_pcalendar), tv_pcalendar); + g_signal_connect (G_OBJECT (tv_pcalendar), "cursor-changed", G_CALLBACK (e_exchange_calendar_pcalendar_on_change), t->source); + + gtk_table_attach (GTK_TABLE (parent), scrw_pcalendar, 0, 2, row+1, row+2, GTK_EXPAND|GTK_FILL, 0, 0, 0); + gtk_widget_show_all (scrw_pcalendar); + + if (src_exists) { + gchar *uri_prefix, *sruri, *tmpruri; + int prefix_len; + GtkTreeSelection *selection; + + uri_prefix = g_strconcat (account->account_filename, "/", NULL); + prefix_len = strlen (uri_prefix); + + tmpruri = (gchar*) e_source_peek_relative_uri (t->source); + + if (g_str_has_prefix (tmpruri, uri_prefix)) { + sruri = g_strdup (tmpruri+prefix_len); + } + else { + sruri = NULL; + } + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv_pcalendar)); + exchange_operations_cta_select_node_from_tree (ts_pcalendar, NULL, sruri, sruri, selection); + gtk_widget_set_sensitive (tv_pcalendar, FALSE); + g_free (uri_prefix); + g_free (sruri); + } + + g_ptr_array_free (callist, TRUE); + return tv_pcalendar; +} + +gboolean +e_exchange_calendar_check (EPlugin *epl, EConfigHookPageCheckData *data) +{ + /* FIXME - check pageid */ + ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; + ESourceGroup *group = e_source_peek_group (t->source); + + if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) { + if (!strlen (e_source_peek_relative_uri (t->source))) { + return FALSE; + } + } + + return TRUE; +} + +void +e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target) +{ + ECalConfigTargetSource *t = (ECalConfigTargetSource *) target; + ESource *source = t->source; + gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix; + int prefix_len; + + ExchangeAccount *account; + ExchangeAccountFolderResult result; + + uri_text = e_source_get_uri (source); + if (strncmp (uri_text, "exchange", 8)) { + g_free (uri_text); + return ; + } + + account = exchange_operations_get_exchange_account (); + path_prefix = g_strconcat (account->account_filename, "/", NULL); + prefix_len = strlen (path_prefix); + g_free (path_prefix); + + /* FIXME: Compiler gives a warning here; review needed */ + if (GPOINTER_TO_INT (t->source_type) == E_CAL_SOURCE_TYPE_EVENT) { + ftype = g_strdup ("calendar"); + } + else if (GPOINTER_TO_INT (t->source_type) == E_CAL_SOURCE_TYPE_TODO) { + ftype = g_strdup ("tasks"); + } + else { + /* FIXME: This one would ever occur? */ + ftype = g_strdup ("mail"); + } + + gname = (gchar*) e_source_peek_name (source); + gruri = (gchar*) e_source_peek_relative_uri (source); + ruri = g_strconcat (gruri, "/", gname, NULL); + e_source_set_relative_uri (source, ruri); + path = g_strdup_printf ("/%s", ruri+prefix_len); + + result = exchange_account_create_folder (account, path, ftype); + + switch (result) { + /* TODO: Modify all these error messages using e_error */ + case EXCHANGE_ACCOUNT_FOLDER_OK: + g_print ("Folder created\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_ALREADY_EXISTS: + g_print ("Already exists\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_DOES_NOT_EXIST: + g_print ("Doesn't exists\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_UNKNOWN_TYPE: + g_print ("Unknown type\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED: + g_print ("Permission denied\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_OFFLINE: + g_print ("Folder offline\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_UNSUPPORTED_OPERATION: + g_print ("Unsupported operation\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR: + g_print ("Generic error\n"); + break; + } + + g_free (uri_text); + g_free (ruri); + g_free (path); + g_free (ftype); +} diff --git a/plugins/exchange-operations/exchange-change-password.c b/plugins/exchange-operations/exchange-change-password.c new file mode 100644 index 0000000000..283ad46236 --- /dev/null +++ b/plugins/exchange-operations/exchange-change-password.c @@ -0,0 +1,135 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* Copyright (C) 2004 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. + */ + +/* exchange-change-password: Change Password code */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "exchange-change-password.h" + +#include +#include + +#include +#include +#include +#include + +#define FILENAME EVOLUTION_GLADEDIR "/exchange-change-password.glade" +#define ROOTNODE "pass_dialog" +#define STARTNODE "pass_vbox" + +static void +entry_changed (GtkEntry *entry, gpointer user_data) +{ + GladeXML *xml = user_data; + GtkEntry *new_entry, *confirm_entry; + GtkWidget *ok_button; + const char *text; + + new_entry = GTK_ENTRY (glade_xml_get_widget (xml, "new_pass_entry")); + confirm_entry = GTK_ENTRY (glade_xml_get_widget (xml, "confirm_pass_entry")); + ok_button = glade_xml_get_widget (xml, "okbutton1"); + + text = gtk_entry_get_text (new_entry); + if (!text || !*text) { + gtk_widget_set_sensitive (ok_button, FALSE); + return; + } + + text = gtk_entry_get_text (confirm_entry); + if (!text || !*text) { + gtk_widget_set_sensitive (ok_button, FALSE); + return; + } + + gtk_widget_set_sensitive (ok_button, TRUE); +} + +/** + * exchange_get_new_password: + * @existing_password: The user's current password + * @voluntary: %TRUE if the user has chosen "Change Password", + * %FALSE if their old password has expired. + * + * Prompt the user for a new password. + */ +char * +exchange_get_new_password (const char *existing_password, gboolean voluntary) +{ + GladeXML *xml; + GtkWidget *top_widget; + GtkEntry *cur_entry, *new_entry, *confirm_entry; + GtkResponseType response; + GtkLabel *top_label; + char *new_pass; + + xml = glade_xml_new (FILENAME, ROOTNODE, NULL); + top_widget = glade_xml_get_widget (xml, ROOTNODE); + + cur_entry = GTK_ENTRY (glade_xml_get_widget (xml, "current_pass_entry")); + new_entry = GTK_ENTRY (glade_xml_get_widget (xml, "new_pass_entry")); + g_signal_connect (new_entry, "changed", + G_CALLBACK (entry_changed), xml); + confirm_entry = GTK_ENTRY (glade_xml_get_widget (xml, "confirm_pass_entry")); + g_signal_connect (confirm_entry, "changed", + G_CALLBACK (entry_changed), xml); + entry_changed (NULL, xml); + + top_label = GTK_LABEL (glade_xml_get_widget (xml, "pass_label")); + if (voluntary) + gtk_widget_hide (GTK_WIDGET (top_label)); + +run_dialog_again: + response = gtk_dialog_run (GTK_DIALOG (top_widget)); + if (response == GTK_RESPONSE_OK) { + const char *cur_pass, *new_pass1, *new_pass2; + + cur_pass = gtk_entry_get_text (cur_entry); + new_pass1 = gtk_entry_get_text (new_entry); + new_pass2 = gtk_entry_get_text (confirm_entry); + + if (existing_password) { + if (strcmp (cur_pass, existing_password) != 0) { + /* User entered a wrong existing + * password. Prompt him again. + */ + gtk_label_set_text (top_label, _("The current password does not match the existing password for your account. Please enter the correct password")); + gtk_widget_show (GTK_WIDGET (top_label)); + goto run_dialog_again; + } + } + + if (strcmp (new_pass1, new_pass2) != 0) { + gtk_label_set_text (top_label, _("The two passwords do not match. Please re-enter the passwords.")); + gtk_widget_show (GTK_WIDGET (top_label)); + goto run_dialog_again; + } + + new_pass = g_strdup (new_pass1); + } else + new_pass = NULL; + + gtk_widget_destroy (top_widget); + g_object_unref (xml); + + return new_pass; +} diff --git a/plugins/exchange-operations/exchange-contacts.c b/plugins/exchange-operations/exchange-contacts.c new file mode 100644 index 0000000000..623699a31c --- /dev/null +++ b/plugins/exchange-operations/exchange-contacts.c @@ -0,0 +1,327 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Praveen Kumar + * Copyright (C) 2005 Novell, Inc. + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mail/em-account-editor.h" +#include "mail/em-config.h" +#include "e-util/e-account.h" +#include "e-util/e-error.h" + +#include "exchange-operations.h" + +enum { + CONTACTSNAME_COL, + CONTACTSRURI_COL, + NUM_COLS +}; + +gchar *contacts_uri=NULL; + +GPtrArray *e_exchange_contacts_get_contacts (void); +void e_exchange_contacts_pcontacts_on_change (GtkTreeView *treeview, ESource *source); +GtkWidget *e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data); +gboolean e_exchange_contacts_check (EPlugin *epl, EConfigHookPageCheckData *data); +void e_exchange_contacts_commit (EPlugin *epl, EConfigTarget *target); + +/* FIXME: Reconsider the prototype of this function */ +GPtrArray * +e_exchange_contacts_get_contacts (void) +{ + ExchangeAccount *account; + GPtrArray *folder_array; + GPtrArray *contacts_list; + EFolder *folder; + + int i, prefix_len; + gchar *uri_prefix, *ruri; + + account = exchange_operations_get_exchange_account (); + + uri_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + prefix_len = strlen (uri_prefix); + + contacts_list = g_ptr_array_new (); + folder_array = exchange_account_get_folders (account); + + for (i=0; ilen; ++i) { + gchar *type, *tmp; + folder = g_ptr_array_index (folder_array, i); + type = (gchar*) e_folder_get_type_string (folder); + if (!strcmp (type, "contacts")) { + tmp = (gchar*) e_folder_get_physical_uri (folder); + if (g_str_has_prefix (tmp, uri_prefix)) { + ruri = g_strdup (tmp+prefix_len); /* ATTN: Should not free this explicitly */ + g_ptr_array_add (contacts_list, (gpointer)ruri); + } + } + } + + g_free (uri_prefix); + return contacts_list; +} + +void +e_exchange_contacts_pcontacts_on_change (GtkTreeView *treeview, ESource *source) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + ExchangeAccount *account; + gchar *es_ruri; + + account = exchange_operations_get_exchange_account (); + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_get_selected(selection, &model, &iter); + gchar *ruri; + + gtk_tree_model_get (model, &iter, CONTACTSRURI_COL, &ruri, -1); + es_ruri = g_strconcat ("exchange://", account->account_filename, "/", ruri, NULL); + e_source_set_relative_uri (source, es_ruri); + /* + if (contacts_uri) { + g_free (contacts_uri); + } + contacts_uri = g_strdup (es_ruri); + */ + g_free (ruri); + g_free (es_ruri); +} + +GtkWidget * +e_exchange_contacts_pcontacts (EPlugin *epl, EConfigHookItemFactoryData *data) +{ + static GtkWidget *lbl_pcontacts, *scrw_pcontacts, *tv_pcontacts, *vb_pcontacts; + GtkTreeStore *ts_pcontacts; + GtkCellRenderer *cr_contacts; + GtkTreeViewColumn *tvc_contacts; + GPtrArray *conlist; + gchar *ruri, *account_name, *uri_text; + ExchangeAccount *account; + + int i; + gboolean src_exists=FALSE; + + EABConfigTargetSource *t = (EABConfigTargetSource *) data->target; + ESource *source = t->source; + + if (data->old) { + /* FIXME: Review this */ + /* + gtk_widget_destroy (lbl_pcontacts); + gtk_widget_destroy (scrw_pcontacts); + gtk_widget_destroy (tv_pcontacts); + */ + } + + uri_text = e_source_get_uri (source); + if (strncmp (uri_text, "exchange", 8)) { + g_free (uri_text); + return NULL; + } + + g_free (uri_text); + + if (e_source_peek_absolute_uri (source)) { + src_exists = TRUE; + } + else { + e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */ + /* + if (contacts_uri) { + g_free (contacts_uri); + contacts_uri = NULL; + } + */ + } + + account = exchange_operations_get_exchange_account (); + account_name = account->account_name; + + vb_pcontacts = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (data->parent), vb_pcontacts); + + /* FIXME: Take care of i18n */ + lbl_pcontacts = gtk_label_new_with_mnemonic (_("_Location:")); + gtk_widget_show (lbl_pcontacts); + gtk_misc_set_alignment (GTK_MISC (lbl_pcontacts), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (vb_pcontacts), lbl_pcontacts, FALSE, FALSE, 0); + + ts_pcontacts = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING); + + conlist = e_exchange_contacts_get_contacts (); + + for (i=0; ilen; ++i) { + ruri = g_ptr_array_index (conlist, i); + exchange_operations_cta_add_node_to_tree (ts_pcontacts, NULL, ruri); + } + + cr_contacts = gtk_cell_renderer_text_new (); + tvc_contacts = gtk_tree_view_column_new_with_attributes (account_name, cr_contacts, "text", CONTACTSNAME_COL, NULL); + tv_pcontacts = gtk_tree_view_new_with_model (GTK_TREE_MODEL (ts_pcontacts)); + gtk_tree_view_append_column (GTK_TREE_VIEW (tv_pcontacts), tvc_contacts); + g_object_set (tv_pcontacts,"expander-column", tvc_contacts, "headers-visible", TRUE, NULL); + gtk_tree_view_expand_all (GTK_TREE_VIEW (tv_pcontacts)); + + scrw_pcontacts = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrw_pcontacts), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrw_pcontacts), GTK_SHADOW_IN); + g_object_set (scrw_pcontacts, "height-request", 150, NULL); + gtk_container_add (GTK_CONTAINER (scrw_pcontacts), tv_pcontacts); + gtk_label_set_mnemonic_widget (GTK_LABEL (lbl_pcontacts), tv_pcontacts); + g_signal_connect (G_OBJECT (tv_pcontacts), "cursor-changed", G_CALLBACK (e_exchange_contacts_pcontacts_on_change), t->source); + gtk_widget_show_all (scrw_pcontacts); + + gtk_box_pack_start (GTK_BOX (vb_pcontacts), scrw_pcontacts, FALSE, FALSE, 0); + gtk_widget_show_all (vb_pcontacts); + + if (src_exists) { + gchar *uri_prefix, *sruri, *tmpruri; + int prefix_len; + GtkTreeSelection *selection; + + uri_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + prefix_len = strlen (uri_prefix); + + tmpruri = (gchar*)e_source_peek_absolute_uri (t->source); + + if (g_str_has_prefix (tmpruri, uri_prefix)) { + sruri = g_strdup (tmpruri+prefix_len); + } + else { + sruri = NULL; + } + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv_pcontacts)); + exchange_operations_cta_select_node_from_tree (ts_pcontacts, NULL, sruri, sruri, selection); + gtk_widget_set_sensitive (tv_pcontacts, FALSE); + + g_free (uri_prefix); + g_free (sruri); + } + + g_ptr_array_free (conlist, TRUE); + return vb_pcontacts; +} + +gboolean +e_exchange_contacts_check (EPlugin *epl, EConfigHookPageCheckData *data) +{ + /* FIXME - check pageid */ + EABConfigTargetSource *t = (EABConfigTargetSource *) data->target; + ESourceGroup *group = e_source_peek_group (t->source); + + if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) { + if (!strlen (e_source_peek_relative_uri (t->source))) { + //if (!contacts_uri) { + return FALSE; + } + } + + return TRUE; +} + +void +e_exchange_contacts_commit (EPlugin *epl, EConfigTarget *target) +{ + EABConfigTargetSource *t = (EABConfigTargetSource *) target; + ESource *source = t->source; + gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix; + int prefix_len; + + ExchangeAccount *account; + ExchangeAccountFolderResult result; + + uri_text = e_source_get_uri (source); + if (strncmp (uri_text, "exchange", 8)) { + g_free (uri_text); + return ; + } + + g_free (uri_text); + + account = exchange_operations_get_exchange_account (); + path_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL); + prefix_len = strlen (path_prefix); + + gname = (gchar*) e_source_peek_name (source); + gruri = (gchar*) e_source_peek_relative_uri (source); + ruri = g_strconcat (gruri, "/", gname, NULL); + //ruri = g_strconcat (contacts_uri, "/", gname, NULL); + + g_print ("Setting absolute URI to %s\n", ruri); + + e_source_set_absolute_uri (source, ruri); + + g_print ("Read absolute URI as %s\n", e_source_peek_absolute_uri(source)); + + /* FIXME: This creates some problem. Identify the cause */ + //e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */ + + path = g_strdup_printf ("/%s", ruri+prefix_len); + result = exchange_account_create_folder (account, path, "contacts"); + + switch (result) { + /* TODO: Modify all these error messages using e_error */ + case EXCHANGE_ACCOUNT_FOLDER_OK: + g_print ("Folder created\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_ALREADY_EXISTS: + g_print ("Already exists\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_DOES_NOT_EXIST: + g_print ("Doesn't exists\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_UNKNOWN_TYPE: + g_print ("Unknown type\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED: + g_print ("Permission denied\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_OFFLINE: + g_print ("Folder offline\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_UNSUPPORTED_OPERATION: + g_print ("Unsupported operation\n"); + break; + case EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR: + g_print ("Generic error\n"); + break; + } + /* + g_free (contacts_uri); + contacts_uri = NULL; + */ + g_free (ruri); + g_free (path); +} diff --git a/plugins/exchange-operations/exchange-operations.c b/plugins/exchange-operations/exchange-operations.c index fcee3902d5..d5f479cebc 100644 --- a/plugins/exchange-operations/exchange-operations.c +++ b/plugins/exchange-operations/exchange-operations.c @@ -1,3 +1,24 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Praveen Kumar + * Copyright (C) 2005 Novell, Inc. + * + * 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 #include "exchange-operations.h" @@ -17,10 +38,10 @@ e_plugin_lib_enable (EPluginLib *eplib, int enable) exchange_global_config_listener = exchange_config_listener_new (); g_atexit (free_exchange_listener); } - g_print ("*** DEBUG: Exchange config listener is initialized ***\n"); return 0; } +/* FIXME: See if a GLib variant of this function available */ gboolean exchange_operations_tokenize_string (char **string, char *token, char delimit) { @@ -39,55 +60,108 @@ exchange_operations_tokenize_string (char **string, char *token, char delimit) } gboolean -exchange_operations_cta_add_node_to_tree (GtkTreeStore *store, GtkTreeIter *parent, const char *nuri, const char *ruri) +exchange_operations_cta_add_node_to_tree (GtkTreeStore *store, GtkTreeIter *parent, const char *ruri) { GtkTreeIter iter; - char *luri=(char *)nuri; + char *luri=(char *)ruri; char nodename[80]; - gchar *readname; + gchar *uri; gboolean status, found; - g_print ("TOKENIZER: String passed to tokenizer %s\n", luri); exchange_operations_tokenize_string (&luri, nodename, '/'); - g_print ("TOKENIZER: Token - %s Residue - %s\n", nodename, luri); + if (!nodename[0]) { return TRUE; } + + if (!parent) { + uri = g_strdup (nodename); + } + else { + gchar *tmpuri; + gtk_tree_model_get (GTK_TREE_MODEL (store), parent, 1, &tmpuri, -1); + uri = g_strconcat (tmpuri, "/", nodename, NULL); + g_free (tmpuri); + } + if (!strcmp (nodename, "personal") && !parent) { + /* FIXME: Don't hardcode this */ strcpy (nodename, "Personal Folders"); } found = FALSE; status = gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &iter, parent); while (status) { - g_print ("Reading name...\n"); + gchar *readname; + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &readname, -1); + if (!strcmp (nodename, readname)) { + found = TRUE; + exchange_operations_cta_add_node_to_tree (store, &iter, luri); + g_free (readname); + break; + } + status = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); + } + + if (!found) { + gtk_tree_store_append (store, &iter, parent); + gtk_tree_store_set (store, &iter, 0, nodename, 1, uri, -1); + exchange_operations_cta_add_node_to_tree (store, &iter, luri); + } + + g_free (uri); + return TRUE; +} + +void +exchange_operations_cta_select_node_from_tree (GtkTreeStore *store, GtkTreeIter *parent, const char *nuri, const char *ruri, GtkTreeSelection *selection) +{ + char *luri=(char *)nuri; + char nodename[80]; + GtkTreeIter iter; + gboolean status; + + exchange_operations_tokenize_string (&luri, nodename, '/'); + + if (!nodename[0]) { + return; + } + + if (!strcmp (nodename, "personal") && !parent) { + /* FIXME: Don't hardcode this */ + strcpy (nodename, "Personal Folders"); + } + + status = gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &iter, parent); + while (status) { + gchar *readname; gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &readname, -1); - g_print ("Name read - %s\n", readname); if (!strcmp (nodename, readname)) { - g_print ("Found. Inserting as child.\n"); - found = TRUE; - exchange_operations_cta_add_node_to_tree (store, &iter, luri, ruri); + gchar *readruri; + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 1, &readruri, -1); + if (!strcmp (ruri, readruri)) { + gtk_tree_selection_select_iter (selection, &iter); + return; + } + g_free (readname); + g_free (readruri); + exchange_operations_cta_select_node_from_tree (store, &iter, luri, ruri, selection); break; } - g_free (readname); status = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); } - if (!found) { - g_print ("Not found. Inserting node %s\n", nodename); - gtk_tree_store_append (store, &iter, parent); - gtk_tree_store_set (store, &iter, 0, nodename, 1, ruri, -1); - exchange_operations_cta_add_node_to_tree (store, &iter, luri, ruri); - } - return TRUE; + return; } ExchangeAccount * -exchange_operations_get_exchange_account (void) { +exchange_operations_get_exchange_account (void) +{ ExchangeAccount *account; GSList *acclist; acclist = exchange_config_listener_get_accounts (exchange_global_config_listener); - account = acclist->data; /* FIXME: Need to be changed for handling multiple accounts */ + /* FIXME: Need to be changed for handling multiple accounts */ + account = acclist->data; return account; } diff --git a/plugins/exchange-operations/exchange-operations.h b/plugins/exchange-operations/exchange-operations.h index 0ac81d9a94..5b4fe3a577 100644 --- a/plugins/exchange-operations/exchange-operations.h +++ b/plugins/exchange-operations/exchange-operations.h @@ -1,5 +1,23 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* Copyright (C) 2001-2004 Novell, Inc. */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Praveen Kumar + * Copyright (C) 2005 Novell, Inc. + * + * 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. + * + */ #ifndef __EXCHANGE_OPERATIONS_H__ #define __EXCHANGE_OPERATIONS_H__ @@ -14,19 +32,17 @@ extern "C" { #pragma } #endif /* __cplusplus */ - extern ExchangeConfigListener *exchange_global_config_listener; -int e_plugin_lib_enable (EPluginLib *eplib, int enable); -gboolean exchange_operations_tokenize_string (char **string, - char *token, - char delimit); -gboolean exchange_operations_cta_add_node_to_tree (GtkTreeStore *store, - GtkTreeIter *parent, - const char *nuri, - const char *ruri); +int e_plugin_lib_enable (EPluginLib *eplib, int enable); + ExchangeAccount *exchange_operations_get_exchange_account (void); +gboolean exchange_operations_tokenize_string (char **string, char *token, char delimit); + +gboolean exchange_operations_cta_add_node_to_tree (GtkTreeStore *store, GtkTreeIter *parent, const char *nuri); +void exchange_operations_cta_select_node_from_tree (GtkTreeStore *store, GtkTreeIter *parent, const char *nuri, const char *ruri, GtkTreeSelection *selection) ; + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3