claws-mail/src/addressbook.c

3905 lines
114 KiB
C
Raw Normal View History

2001-04-19 14:21:46 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2002 Hiroyuki Yamamoto
2001-04-19 14:21:46 +02:00
*
* 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "defs.h"
#include <glib.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkhpaned.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkctree.h>
#include <gtk/gtkclist.h>
#include <gtk/gtktable.h>
#include <gtk/gtkhbbox.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkmenuitem.h>
#include <gtk/gtkitemfactory.h>
#include <string.h>
2001-05-02 20:26:06 +02:00
#include <setjmp.h>
2001-04-19 14:21:46 +02:00
#include "intl.h"
#include "main.h"
#include "addressbook.h"
#include "manage_window.h"
#include "prefs_common.h"
#include "alertpanel.h"
#include "inputdialog.h"
#include "menu.h"
2001-12-22 01:30:32 +01:00
#include "stock_pixmap.h"
2001-04-19 14:21:46 +02:00
#include "xml.h"
#include "prefs.h"
#include "procmime.h"
#include "utils.h"
#include "gtkutils.h"
#include "codeconv.h"
#include "about.h"
#include "addr_compl.h"
2001-09-02 01:48:06 +02:00
#include "mgutils.h"
#include "addressitem.h"
2001-09-02 01:48:06 +02:00
#include "addritem.h"
#include "addrcache.h"
#include "addrbook.h"
#include "addrindex.h"
2001-09-06 12:24:20 +02:00
#include "addressadd.h"
#include "vcard.h"
#include "editvcard.h"
2001-09-02 01:48:06 +02:00
#include "editgroup.h"
#include "editaddress.h"
#include "editbook.h"
2001-09-24 07:43:58 +02:00
#include "ldif.h"
#include "importldif.h"
#include "mutt.h"
#include "importmutt.h"
#ifdef USE_JPILOT
#include "jpilot.h"
#include "editjpilot.h"
#endif
#ifdef USE_LDAP
#include <pthread.h>
#include "syldap.h"
#include "editldap.h"
2001-09-02 01:48:06 +02:00
#define ADDRESSBOOK_LDAP_BUSYMSG "Busy"
#endif
#include "addrselect.h"
#include "addrclip.h"
/*
#include "pixmaps/dir-close.xpm"
#include "pixmaps/dir-open.xpm"
#include "pixmaps/group.xpm"
#include "pixmaps/interface.xpm"
#include "pixmaps/book.xpm"
#include "pixmaps/address.xpm"
#include "pixmaps/vcard.xpm"
#include "pixmaps/jpilot.xpm"
#include "pixmaps/category.xpm"
#include "pixmaps/ldap.xpm"
*/
2001-04-19 14:21:46 +02:00
typedef enum
{
COL_NAME = 0,
COL_ADDRESS = 1,
COL_REMARKS = 2
} AddressBookColumnPos;
#define N_COLS 3
2001-09-02 01:48:06 +02:00
#define COL_NAME_WIDTH 164
#define COL_ADDRESS_WIDTH 156
2001-04-19 14:21:46 +02:00
#define COL_FOLDER_WIDTH 170
#define ADDRESSBOOK_WIDTH 640
#define ADDRESSBOOK_HEIGHT 360
#define ADDRESSBOOK_MSGBUF_SIZE 2048
2001-04-19 14:21:46 +02:00
static GdkPixmap *folderxpm;
static GdkBitmap *folderxpmmask;
static GdkPixmap *folderopenxpm;
static GdkBitmap *folderopenxpmmask;
static GdkPixmap *groupxpm;
static GdkBitmap *groupxpmmask;
2001-09-02 01:48:06 +02:00
static GdkPixmap *interfacexpm;
static GdkBitmap *interfacexpmmask;
static GdkPixmap *bookxpm;
static GdkBitmap *bookxpmmask;
static GdkPixmap *addressxpm;
static GdkBitmap *addressxpmmask;
static GdkPixmap *vcardxpm;
static GdkBitmap *vcardxpmmask;
static GdkPixmap *jpilotxpm;
static GdkBitmap *jpilotxpmmask;
static GdkPixmap *categoryxpm;
static GdkBitmap *categoryxpmmask;
static GdkPixmap *ldapxpm;
static GdkBitmap *ldapxpmmask;
2001-09-13 15:38:32 +02:00
/* Message buffer */
static gchar addressbook_msgbuf[ ADDRESSBOOK_MSGBUF_SIZE ];
2001-04-19 14:21:46 +02:00
2001-09-13 15:38:32 +02:00
/* Address list selection */
static AddrSelectList *_addressSelect_ = NULL;
static AddressClipboard *_clipBoard_ = NULL;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Address index file and interfaces */
2001-09-02 01:48:06 +02:00
static AddressIndex *_addressIndex_ = NULL;
static GList *_addressInterfaceList_ = NULL;
static GList *_addressIFaceSelection_ = NULL;
#define ADDRESSBOOK_IFACE_SELECTION "1/y,3/y,4/y,2/n"
static AddressBook_win addrbook;
static GHashTable *_addressBookTypeHash_ = NULL;
static GList *_addressBookTypeList_ = NULL;
2001-09-13 15:38:32 +02:00
static void addressbook_create (void);
2001-04-19 14:21:46 +02:00
static gint addressbook_close (void);
static void addressbook_button_set_sensitive (void);
/* callback functions */
static void addressbook_del_clicked (GtkButton *button,
gpointer data);
static void addressbook_reg_clicked (GtkButton *button,
gpointer data);
static void addressbook_to_clicked (GtkButton *button,
gpointer data);
static void addressbook_lup_clicked (GtkButton *button,
gpointer data);
2001-04-19 14:21:46 +02:00
static void addressbook_tree_selected (GtkCTree *ctree,
GtkCTreeNode *node,
gint column,
gpointer data);
static void addressbook_list_selected (GtkCList *clist,
gint row,
gint column,
GdkEvent *event,
gpointer data);
2001-09-02 01:48:06 +02:00
static void addressbook_list_row_selected (GtkCTree *clist,
GtkCTreeNode *node,
gint column,
gpointer data);
static void addressbook_list_row_unselected (GtkCTree *clist,
GtkCTreeNode *node,
gint column,
gpointer data);
static void addressbook_person_expand_node (GtkCTree *ctree,
GList *node,
gpointer *data );
static void addressbook_person_collapse_node (GtkCTree *ctree,
GList *node,
gpointer *data );
static void addressbook_entry_gotfocus (GtkWidget *widget);
2001-04-19 14:21:46 +02:00
#if 0
static void addressbook_entry_changed (GtkWidget *widget);
#endif
static void addressbook_list_button_pressed (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
static void addressbook_list_button_released (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
static void addressbook_tree_button_pressed (GtkWidget *ctree,
GdkEventButton *event,
gpointer data);
static void addressbook_tree_button_released (GtkWidget *ctree,
GdkEventButton *event,
gpointer data);
static void addressbook_popup_close (GtkMenuShell *menu_shell,
gpointer data);
static void addressbook_new_folder_cb (gpointer data,
guint action,
GtkWidget *widget);
static void addressbook_new_group_cb (gpointer data,
guint action,
GtkWidget *widget);
2001-09-02 01:48:06 +02:00
static void addressbook_treenode_edit_cb (gpointer data,
2001-04-19 14:21:46 +02:00
guint action,
GtkWidget *widget);
2001-09-02 01:48:06 +02:00
static void addressbook_treenode_delete_cb (gpointer data,
2001-04-19 14:21:46 +02:00
guint action,
GtkWidget *widget);
static void addressbook_change_node_name (GtkCTreeNode *node,
const gchar *name);
static void addressbook_new_address_cb (gpointer data,
guint action,
GtkWidget *widget);
static void addressbook_edit_address_cb (gpointer data,
guint action,
GtkWidget *widget);
static void addressbook_delete_address_cb (gpointer data,
guint action,
GtkWidget *widget);
static void close_cb (gpointer data,
guint action,
GtkWidget *widget);
2001-09-02 01:48:06 +02:00
static void addressbook_file_save_cb (gpointer data,
guint action,
GtkWidget *widget);
2001-04-19 14:21:46 +02:00
2001-09-13 15:38:32 +02:00
/* Data source edit stuff */
static void addressbook_new_book_cb (gpointer data,
guint action,
GtkWidget *widget);
static void addressbook_new_vcard_cb (gpointer data,
guint action,
GtkWidget *widget);
#ifdef USE_JPILOT
2001-09-13 15:38:32 +02:00
static void addressbook_new_jpilot_cb (gpointer data,
guint action,
GtkWidget *widget);
#endif
#ifdef USE_LDAP
2001-09-13 15:38:32 +02:00
static void addressbook_new_ldap_cb (gpointer data,
guint action,
GtkWidget *widget);
#endif
2001-04-19 14:21:46 +02:00
static void addressbook_set_clist (AddressObject *obj);
2001-09-02 01:48:06 +02:00
static void addressbook_load_tree (void);
void addressbook_read_file (void);
2001-04-19 14:21:46 +02:00
static GtkCTreeNode *addressbook_add_object (GtkCTreeNode *node,
AddressObject *obj);
static void addressbook_treenode_remove_item ( void );
2001-09-02 01:48:06 +02:00
static AddressDataSource *addressbook_find_datasource
(GtkCTreeNode *node );
static AddressBookFile *addressbook_get_book_file(void);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_node_add_folder
2001-04-19 14:21:46 +02:00
(GtkCTreeNode *node,
2001-09-02 01:48:06 +02:00
AddressDataSource *ds,
ItemFolder *itemFolder,
2001-09-13 15:38:32 +02:00
AddressObjectType otype);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_node_add_group (GtkCTreeNode *node,
AddressDataSource *ds,
2001-09-13 15:38:32 +02:00
ItemGroup *itemGroup);
2001-09-02 01:48:06 +02:00
static void addressbook_tree_remove_children (GtkCTree *ctree,
2001-09-13 15:38:32 +02:00
GtkCTreeNode *parent);
2001-09-02 01:48:06 +02:00
static void addressbook_move_nodes_up (GtkCTree *ctree,
2001-09-13 15:38:32 +02:00
GtkCTreeNode *node);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_find_group_node (GtkCTreeNode *parent,
ItemGroup *group);
static GtkCTreeNode *addressbook_find_folder_node( GtkCTreeNode *parent,
ItemFolder *folder );
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_delete_object (AddressObject *obj);
2001-04-19 14:21:46 +02:00
static void key_pressed (GtkWidget *widget,
GdkEventKey *event,
gpointer data);
static gint addressbook_treenode_compare_func (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2);
2001-04-19 14:21:46 +02:00
static gint addressbook_list_compare_func (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2);
#ifdef USE_LDAP
2001-09-13 15:38:32 +02:00
static void addressbook_ldap_show_message (SyldapServer *server);
#endif
2001-09-13 15:38:32 +02:00
/* LUT's and IF stuff */
static void addressbook_free_treenode ( gpointer data );
2001-09-13 15:38:32 +02:00
AddressTypeControlItem *addrbookctl_lookup (gint ot);
AddressTypeControlItem *addrbookctl_lookup_iface(AddressIfType ifType);
2001-09-02 01:48:06 +02:00
2001-09-13 15:38:32 +02:00
void addrbookctl_build_map (GtkWidget *window);
void addrbookctl_build_iflist (void);
AdapterInterface *addrbookctl_find_interface (AddressIfType ifType);
void addrbookctl_build_ifselect (void);
2001-09-02 01:48:06 +02:00
2001-09-13 15:38:32 +02:00
static void addrbookctl_free_interface (AdapterInterface *adapter);
static void addrbookctl_free_datasource (AdapterDSource *adapter);
static void addrbookctl_free_folder (AdapterFolder *adapter);
static void addrbookctl_free_group (AdapterGroup *adapter);
2001-09-02 01:48:06 +02:00
static void addressbook_list_select_clear ( void );
static void addressbook_list_select_add ( AddrItemObject *aio,
AddressDataSource *ds );
static void addressbook_list_select_remove ( AddrItemObject *aio );
static void addressbook_import_ldif_cb ( void );
static void addressbook_import_mutt_cb ( void );
static void addressbook_clip_cut_cb ( void );
static void addressbook_clip_copy_cb ( void );
static void addressbook_clip_paste_cb ( void );
static void addressbook_clip_paste_address_cb ( void );
static void addressbook_treenode_cut_cb ( void );
static void addressbook_treenode_copy_cb ( void );
static void addressbook_treenode_paste_cb ( void );
2001-09-24 07:43:58 +02:00
2001-04-19 14:21:46 +02:00
static GtkItemFactoryEntry addressbook_entries[] =
{
2001-09-02 01:48:06 +02:00
{N_("/_File"), NULL, NULL, 0, "<Branch>"},
{N_("/_File/New _Book"), "<alt>B", addressbook_new_book_cb, 0, NULL},
{N_("/_File/New _vCard"), "<alt>D", addressbook_new_vcard_cb, 0, NULL},
#ifdef USE_JPILOT
2001-12-22 01:30:32 +01:00
{N_("/_File/New _JPilot"), "<alt>J", addressbook_new_jpilot_cb, 0, NULL},
#endif
#ifdef USE_LDAP
2001-09-02 01:48:06 +02:00
{N_("/_File/New _Server"), "<alt>S", addressbook_new_ldap_cb, 0, NULL},
#endif
{N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_File/_Edit"), NULL, addressbook_treenode_edit_cb, 0, NULL},
{N_("/_File/_Delete"), NULL, addressbook_treenode_delete_cb, 0, NULL},
{N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
2001-09-06 12:24:20 +02:00
{N_("/_File/_Save"), "<alt>S", addressbook_file_save_cb, 0, NULL},
{N_("/_File/_Close"), "<alt>W", close_cb, 0, NULL},
{N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
{N_("/_Edit/C_ut"), "<ctl>X", addressbook_clip_cut_cb, 0, NULL},
{N_("/_Edit/_Copy"), "<ctl>C", addressbook_clip_copy_cb, 0, NULL},
{N_("/_Edit/_Paste"), "<ctl>V", addressbook_clip_paste_cb, 0, NULL},
{N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Edit/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL},
2001-09-02 01:48:06 +02:00
{N_("/_Address"), NULL, NULL, 0, "<Branch>"},
{N_("/_Address/New _Address"), "<alt>N", addressbook_new_address_cb, 0, NULL},
{N_("/_Address/New _Group"), "<alt>G", addressbook_new_group_cb, 0, NULL},
{N_("/_Address/New _Folder"), "<alt>R", addressbook_new_folder_cb, 0, NULL},
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Address/_Edit"), "<alt>Return", addressbook_edit_address_cb, 0, NULL},
{N_("/_Address/_Delete"), NULL, addressbook_delete_address_cb, 0, NULL},
{N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Tools/Import _LDIF"), NULL, addressbook_import_ldif_cb, 0, NULL},
{N_("/_Tools/Import M_utt"), NULL, addressbook_import_mutt_cb, 0, NULL},
2001-09-02 01:48:06 +02:00
{N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
{N_("/_Help/_About"), NULL, about_show, 0, NULL}
2001-04-19 14:21:46 +02:00
};
2001-09-06 12:24:20 +02:00
/* New options to be added. */
2001-09-02 01:48:06 +02:00
/*
2001-09-30 13:07:34 +02:00
{N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
{N_("/_Tools/Import _Mozilla"), NULL, NULL, 0, NULL},
{N_("/_Tools/Import _vCard"), NULL, NULL, 0, NULL},
2001-09-30 13:07:34 +02:00
{N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Tools/Export _LDIF"), NULL, NULL, 0, NULL},
2001-12-22 01:30:32 +01:00
{N_("/_Tools/Export v_Card"), NULL, NULL, 0, NULL},
2001-09-02 01:48:06 +02:00
*/
2001-04-19 14:21:46 +02:00
static GtkItemFactoryEntry addressbook_tree_popup_entries[] =
{
{N_("/New _Address"), NULL, addressbook_new_address_cb, 0, NULL},
{N_("/New _Group"), NULL, addressbook_new_group_cb, 0, NULL},
{N_("/New _Folder"), NULL, addressbook_new_folder_cb, 0, NULL},
2001-04-19 14:21:46 +02:00
{N_("/---"), NULL, NULL, 0, "<Separator>"},
2001-09-02 01:48:06 +02:00
{N_("/_Edit"), NULL, addressbook_treenode_edit_cb, 0, NULL},
{N_("/_Delete"), NULL, addressbook_treenode_delete_cb, 0, NULL},
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/C_ut"), NULL, addressbook_treenode_cut_cb, 0, NULL},
{N_("/_Copy"), NULL, addressbook_treenode_copy_cb, 0, NULL},
{N_("/_Paste"), NULL, addressbook_treenode_paste_cb, 0, NULL}
2001-04-19 14:21:46 +02:00
};
static GtkItemFactoryEntry addressbook_list_popup_entries[] =
{
{N_("/New _Address"), NULL, addressbook_new_address_cb, 0, NULL},
{N_("/New _Group"), NULL, addressbook_new_group_cb, 0, NULL},
{N_("/New _Folder"), NULL, addressbook_new_folder_cb, 0, NULL},
2001-04-19 14:21:46 +02:00
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Edit"), NULL, addressbook_edit_address_cb, 0, NULL},
{N_("/_Delete"), NULL, addressbook_delete_address_cb, 0, NULL},
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/C_ut"), NULL, addressbook_clip_cut_cb, 0, NULL},
{N_("/_Copy"), NULL, addressbook_clip_copy_cb, 0, NULL},
{N_("/_Paste"), NULL, addressbook_clip_paste_cb, 0, NULL},
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL}
2001-04-19 14:21:46 +02:00
};
void addressbook_open(Compose *target)
{
/* Initialize all static members */
if( _clipBoard_ == NULL ) {
_clipBoard_ = addrclip_create();
}
if( _addressIndex_ != NULL ) {
addrclip_set_index( _clipBoard_, _addressIndex_ );
}
if( _addressSelect_ == NULL ) {
_addressSelect_ = addrselect_list_create();
}
2001-04-19 14:21:46 +02:00
if (!addrbook.window) {
addressbook_read_file();
2001-09-02 01:48:06 +02:00
addressbook_create();
addressbook_load_tree();
2001-04-19 14:21:46 +02:00
gtk_ctree_select(GTK_CTREE(addrbook.ctree),
GTK_CTREE_NODE(GTK_CLIST(addrbook.ctree)->row_list));
}
else {
2001-04-19 14:21:46 +02:00
gtk_widget_hide(addrbook.window);
}
2001-07-03 23:02:09 +02:00
gtk_widget_show_all(addrbook.window);
2001-04-19 14:21:46 +02:00
addressbook_set_target_compose(target);
}
void addressbook_set_target_compose(Compose *target)
{
addrbook.target_compose = target;
addressbook_button_set_sensitive();
}
Compose *addressbook_get_target_compose(void)
{
return addrbook.target_compose;
}
2001-09-13 15:38:32 +02:00
void addressbook_refresh(void)
{
if (addrbook.window) {
if (addrbook.treeSelected) {
gtk_ctree_select(GTK_CTREE(addrbook.ctree),
addrbook.treeSelected);
2001-09-02 01:48:06 +02:00
}
}
addressbook_export_to_file();
}
/*
* Create the address book widgets. The address book contains two CTree widgets: the
* address index tree on the left and the address list on the right.
*
* The address index tree displays a hierarchy of interfaces and groups. Each node in
* this tree is linked to an address Adapter. Adapters have been created for interfaces,
* data sources and folder objects.
*
* The address list displays group, person and email objects. These items are linked
* directly to ItemGroup, ItemPerson and ItemEMail objects inside the address book data
* sources.
*
* In the tradition of MVC architecture, the data stores have been separated from the
* GUI components. The addrindex.c file provides the interface to all data stores.
*/
2001-09-13 15:38:32 +02:00
static void addressbook_create(void)
{
2001-04-19 14:21:46 +02:00
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *vbox2;
GtkWidget *ctree_swin;
GtkWidget *ctree;
GtkWidget *clist_vbox;
GtkWidget *clist_swin;
GtkWidget *clist;
GtkWidget *paned;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *statusbar;
2001-04-19 14:21:46 +02:00
GtkWidget *hbbox;
GtkWidget *hsbox;
2001-04-19 14:21:46 +02:00
GtkWidget *del_btn;
GtkWidget *reg_btn;
GtkWidget *lup_btn;
GtkWidget *to_btn;
GtkWidget *cc_btn;
GtkWidget *bcc_btn;
GtkWidget *tree_popup;
GtkWidget *list_popup;
GtkItemFactory *tree_factory;
GtkItemFactory *list_factory;
GtkItemFactory *menu_factory;
2001-04-19 14:21:46 +02:00
gint n_entries;
2001-09-02 01:48:06 +02:00
GList *nodeIf;
2001-04-19 14:21:46 +02:00
gchar *titles[N_COLS] = {_("Name"), _("E-Mail address"), _("Remarks")};
gchar *text;
gint i;
debug_print("Creating addressbook window...\n");
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), _("Address book"));
gtk_widget_set_usize(window, ADDRESSBOOK_WIDTH, ADDRESSBOOK_HEIGHT);
gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
gtk_window_set_wmclass(GTK_WINDOW(window), "addressbook", "Sylpheed");
2001-04-19 14:21:46 +02:00
gtk_widget_realize(window);
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(addressbook_close), NULL);
gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
GTK_SIGNAL_FUNC(key_pressed), NULL);
gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
n_entries = sizeof(addressbook_entries) /
sizeof(addressbook_entries[0]);
menubar = menubar_create(window, addressbook_entries, n_entries,
"<AddressBook>", NULL);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
menu_factory = gtk_item_factory_from_widget(menubar);
2001-04-19 14:21:46 +02:00
vbox2 = gtk_vbox_new(FALSE, 4);
gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
ctree_swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ctree_swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_widget_set_usize(ctree_swin, COL_FOLDER_WIDTH + 40, -1);
2001-09-13 15:38:32 +02:00
/* Address index */
2001-04-19 14:21:46 +02:00
ctree = gtk_ctree_new(1, 0);
gtk_container_add(GTK_CONTAINER(ctree_swin), ctree);
gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
gtk_clist_set_column_width(GTK_CLIST(ctree), 0, COL_FOLDER_WIDTH);
gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_DOTTED);
gtk_ctree_set_expander_style(GTK_CTREE(ctree),
GTK_CTREE_EXPANDER_SQUARE);
gtk_ctree_set_indent(GTK_CTREE(ctree), CTREE_INDENT);
gtk_clist_set_compare_func(GTK_CLIST(ctree),
addressbook_treenode_compare_func);
2001-04-19 14:21:46 +02:00
gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
GTK_SIGNAL_FUNC(addressbook_tree_selected), NULL);
gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
GTK_SIGNAL_FUNC(addressbook_tree_button_pressed),
NULL);
gtk_signal_connect(GTK_OBJECT(ctree), "button_release_event",
GTK_SIGNAL_FUNC(addressbook_tree_button_released),
NULL);
clist_vbox = gtk_vbox_new(FALSE, 4);
clist_swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(clist_vbox), clist_swin, TRUE, TRUE, 0);
2001-09-13 15:38:32 +02:00
/* Address list */
2001-09-02 01:48:06 +02:00
clist = gtk_ctree_new_with_titles(N_COLS, 0, titles);
2001-04-19 14:21:46 +02:00
gtk_container_add(GTK_CONTAINER(clist_swin), clist);
gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_EXTENDED);
2001-09-18 11:36:32 +02:00
gtk_ctree_set_line_style(GTK_CTREE(clist), GTK_CTREE_LINES_NONE);
2001-09-02 01:48:06 +02:00
gtk_ctree_set_expander_style(GTK_CTREE(clist), GTK_CTREE_EXPANDER_SQUARE);
gtk_ctree_set_indent(GTK_CTREE(clist), CTREE_INDENT);
2001-04-19 14:21:46 +02:00
gtk_clist_set_column_width(GTK_CLIST(clist), COL_NAME,
COL_NAME_WIDTH);
gtk_clist_set_column_width(GTK_CLIST(clist), COL_ADDRESS,
COL_ADDRESS_WIDTH);
gtk_clist_set_compare_func(GTK_CLIST(clist),
addressbook_list_compare_func);
for (i = 0; i < N_COLS; i++)
GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
GTK_CAN_FOCUS);
2001-09-02 01:48:06 +02:00
gtk_signal_connect(GTK_OBJECT(clist), "tree_select_row",
GTK_SIGNAL_FUNC(addressbook_list_row_selected), NULL);
gtk_signal_connect(GTK_OBJECT(clist), "tree_unselect_row",
GTK_SIGNAL_FUNC(addressbook_list_row_unselected), NULL);
2001-04-19 14:21:46 +02:00
gtk_signal_connect(GTK_OBJECT(clist), "button_press_event",
GTK_SIGNAL_FUNC(addressbook_list_button_pressed),
NULL);
gtk_signal_connect(GTK_OBJECT(clist), "button_release_event",
GTK_SIGNAL_FUNC(addressbook_list_button_released),
NULL);
2001-09-02 01:48:06 +02:00
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(addressbook_list_selected), NULL);
gtk_signal_connect(GTK_OBJECT(clist), "tree_expand",
GTK_SIGNAL_FUNC(addressbook_person_expand_node), NULL );
gtk_signal_connect(GTK_OBJECT(clist), "tree_collapse",
GTK_SIGNAL_FUNC(addressbook_person_collapse_node), NULL );
2001-04-19 14:21:46 +02:00
hbox = gtk_hbox_new(FALSE, 4);
gtk_box_pack_start(GTK_BOX(clist_vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new(_("Name:"));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
address_completion_register_entry(GTK_ENTRY(entry));
gtk_signal_connect(GTK_OBJECT(entry), "focus_in_event",
GTK_SIGNAL_FUNC(addressbook_entry_gotfocus), NULL);
2001-04-19 14:21:46 +02:00
#if 0
gtk_signal_connect(GTK_OBJECT(entry), "changed",
GTK_SIGNAL_FUNC(addressbook_entry_changed), NULL);
#endif
paned = gtk_hpaned_new();
gtk_box_pack_start(GTK_BOX(vbox2), paned, TRUE, TRUE, 0);
gtk_paned_add1(GTK_PANED(paned), ctree_swin);
gtk_paned_add2(GTK_PANED(paned), clist_vbox);
2001-09-06 12:24:20 +02:00
/* Status bar */
hsbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
statusbar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
2001-09-06 12:24:20 +02:00
/* Button panel */
2001-04-19 14:21:46 +02:00
hbbox = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 2);
gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
del_btn = gtk_button_new_with_label(_("Delete"));
GTK_WIDGET_SET_FLAGS(del_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), del_btn, TRUE, TRUE, 0);
reg_btn = gtk_button_new_with_label(_("Add"));
GTK_WIDGET_SET_FLAGS(reg_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), reg_btn, TRUE, TRUE, 0);
lup_btn = gtk_button_new_with_label(_("Lookup"));
GTK_WIDGET_SET_FLAGS(lup_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), lup_btn, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_del_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_reg_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(lup_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_lup_clicked), NULL);
2001-04-19 14:21:46 +02:00
to_btn = gtk_button_new_with_label
(prefs_common.trans_hdr ? _("To:") : "To:");
GTK_WIDGET_SET_FLAGS(to_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), to_btn, TRUE, TRUE, 0);
cc_btn = gtk_button_new_with_label
(prefs_common.trans_hdr ? _("Cc:") : "Cc:");
GTK_WIDGET_SET_FLAGS(cc_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), cc_btn, TRUE, TRUE, 0);
bcc_btn = gtk_button_new_with_label
(prefs_common.trans_hdr ? _("Bcc:") : "Bcc:");
GTK_WIDGET_SET_FLAGS(bcc_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), bcc_btn, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(to_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_to_clicked),
GINT_TO_POINTER(COMPOSE_TO));
gtk_signal_connect(GTK_OBJECT(cc_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_to_clicked),
GINT_TO_POINTER(COMPOSE_CC));
gtk_signal_connect(GTK_OBJECT(bcc_btn), "clicked",
GTK_SIGNAL_FUNC(addressbook_to_clicked),
GINT_TO_POINTER(COMPOSE_BCC));
2001-09-13 15:38:32 +02:00
/* Build icons for interface */
2001-12-22 01:30:32 +01:00
stock_pixmap_gdk( window, STOCK_PIXMAP_INTERFACE,
&interfacexpm, &interfacexpmmask );
2001-09-02 01:48:06 +02:00
2001-09-06 12:24:20 +02:00
/* Build control tables */
2001-09-13 15:38:32 +02:00
addrbookctl_build_map(window);
2001-09-02 01:48:06 +02:00
addrbookctl_build_iflist();
addrbookctl_build_ifselect();
2001-09-13 15:38:32 +02:00
/* Add each interface into the tree as a root level folder */
2001-09-02 01:48:06 +02:00
nodeIf = _addressInterfaceList_;
while( nodeIf ) {
2001-09-13 15:38:32 +02:00
AdapterInterface *adapter = nodeIf->data;
AddressInterface *iface = adapter->interface;
nodeIf = g_list_next(nodeIf);
if(iface->useInterface) {
AddressTypeControlItem *atci = adapter->atci;
2001-09-02 03:09:09 +02:00
text = atci->displayName;
adapter->treeNode =
gtk_ctree_insert_node( GTK_CTREE(ctree),
NULL, NULL, &text, FOLDER_SPACING,
interfacexpm, interfacexpmmask,
interfacexpm, interfacexpmmask,
FALSE, FALSE );
menu_set_sensitive( menu_factory, atci->menuCommand, adapter->haveLibrary );
gtk_ctree_node_set_row_data_full(
GTK_CTREE(ctree), adapter->treeNode, adapter,
addressbook_free_treenode );
2001-09-02 03:09:09 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-09-06 12:24:20 +02:00
/* Popup menu */
2001-04-19 14:21:46 +02:00
n_entries = sizeof(addressbook_tree_popup_entries) /
sizeof(addressbook_tree_popup_entries[0]);
tree_popup = menu_create_items(addressbook_tree_popup_entries,
n_entries,
"<AddressBookTree>", &tree_factory,
NULL);
gtk_signal_connect(GTK_OBJECT(tree_popup), "selection_done",
GTK_SIGNAL_FUNC(addressbook_popup_close), NULL);
n_entries = sizeof(addressbook_list_popup_entries) /
sizeof(addressbook_list_popup_entries[0]);
list_popup = menu_create_items(addressbook_list_popup_entries,
n_entries,
"<AddressBookList>", &list_factory,
NULL);
addrbook.window = window;
addrbook.menubar = menubar;
addrbook.ctree = ctree;
addrbook.clist = clist;
addrbook.entry = entry;
addrbook.statusbar = statusbar;
addrbook.status_cid = gtk_statusbar_get_context_id(
GTK_STATUSBAR(statusbar), "Addressbook Window" );
2001-04-19 14:21:46 +02:00
addrbook.del_btn = del_btn;
addrbook.reg_btn = reg_btn;
addrbook.lup_btn = lup_btn;
addrbook.to_btn = to_btn;
addrbook.cc_btn = cc_btn;
addrbook.bcc_btn = bcc_btn;
addrbook.tree_popup = tree_popup;
addrbook.list_popup = list_popup;
addrbook.tree_factory = tree_factory;
addrbook.list_factory = list_factory;
addrbook.menu_factory = menu_factory;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
addrbook.listSelected = NULL;
2001-04-19 14:21:46 +02:00
address_completion_start(window);
2001-09-02 01:48:06 +02:00
gtk_widget_show_all(window);
2001-04-19 14:21:46 +02:00
}
static gint addressbook_close(void)
{
gtk_widget_hide(addrbook.window);
addressbook_export_to_file();
return TRUE;
}
static void addressbook_status_show( gchar *msg ) {
if( addrbook.statusbar != NULL ) {
gtk_statusbar_pop(
GTK_STATUSBAR(addrbook.statusbar),
addrbook.status_cid );
if( msg ) {
gtk_statusbar_push(
GTK_STATUSBAR(addrbook.statusbar),
addrbook.status_cid, msg );
}
}
}
static void addressbook_ds_status_message( AddressDataSource *ds, gchar *msg ) {
*addressbook_msgbuf = '\0';
if( ds ) {
gchar *name;
name = addrindex_ds_get_name( ds );
sprintf( addressbook_msgbuf, "%s: %s", name, msg );
}
else {
sprintf( addressbook_msgbuf, "%s", msg );
}
addressbook_status_show( addressbook_msgbuf );
}
2001-09-02 01:48:06 +02:00
static void addressbook_ds_show_message( AddressDataSource *ds ) {
gint retVal;
gchar *name;
*addressbook_msgbuf = '\0';
if( ds ) {
name = addrindex_ds_get_name( ds );
retVal = addrindex_ds_get_status_code( ds );
if( retVal == MGU_SUCCESS ) {
sprintf( addressbook_msgbuf, "%s", name );
2001-09-02 01:48:06 +02:00
}
else {
sprintf( addressbook_msgbuf, "%s: %s", name,
mgu_error2string( retVal ) );
2001-09-02 01:48:06 +02:00
}
}
addressbook_status_show( addressbook_msgbuf );
}
2001-04-19 14:21:46 +02:00
static void addressbook_button_set_sensitive(void)
{
gboolean to_sens = FALSE;
gboolean cc_sens = FALSE;
gboolean bcc_sens = FALSE;
if (!addrbook.window) return;
if (addrbook.target_compose) {
to_sens = TRUE;
cc_sens = TRUE;
#ifndef CLAWS
2001-04-19 14:21:46 +02:00
if (addrbook.target_compose->use_bcc)
#endif
2001-04-19 14:21:46 +02:00
bcc_sens = TRUE;
}
gtk_widget_set_sensitive(addrbook.to_btn, to_sens);
gtk_widget_set_sensitive(addrbook.cc_btn, cc_sens);
gtk_widget_set_sensitive(addrbook.bcc_btn, bcc_sens);
}
2001-09-02 01:48:06 +02:00
/*
* Delete one or more objects from address list.
*/
2001-04-19 14:21:46 +02:00
static void addressbook_del_clicked(GtkButton *button, gpointer data)
{
2001-09-02 01:48:06 +02:00
GtkCTree *clist = GTK_CTREE(addrbook.clist);
2001-04-19 14:21:46 +02:00
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
AddressObject *pobj;
2001-09-02 01:48:06 +02:00
AdapterDSource *ads = NULL;
GtkCTreeNode *nodeList;
2001-09-06 12:24:20 +02:00
gboolean procFlag;
2001-09-02 01:48:06 +02:00
AlertValue aval;
AddressBookFile *abf = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface;
AddrItemObject *aio;
AddrSelectItem *item;
GList *list, *node;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
pobj = gtk_ctree_node_get_row_data(ctree, addrbook.opened );
2001-04-19 14:21:46 +02:00
g_return_if_fail(pobj != NULL);
/* Test whether anything selected for deletion */
2001-09-02 01:48:06 +02:00
nodeList = addrbook.listSelected;
aio = gtk_ctree_node_get_row_data( clist, nodeList );
if( aio == NULL) return;
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
/* Test for read only */
iface = ds->interface;
if( iface->readOnly ) {
aval = alertpanel( _("Delete address(es)"),
_("This address data is readonly and cannot be deleted."),
_("Close"), NULL, NULL );
return;
}
/* Test whether Ok to proceed */
2001-09-02 01:48:06 +02:00
procFlag = FALSE;
if( pobj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(pobj);
if( ads->subType == ADDR_BOOK ) procFlag = TRUE;
}
else if( pobj->type == ADDR_ITEM_FOLDER ) {
procFlag = TRUE;
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
procFlag = TRUE;
}
if( ! procFlag ) return;
abf = ds->rawDataSource;
if( abf == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Confirm deletion */
2001-09-02 01:48:06 +02:00
aval = alertpanel( _("Delete address(es)"),
_("Really delete the address(es)?"),
_("Yes"), _("No"), NULL );
if( aval != G_ALERTDEFAULT ) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Process deletions */
2001-09-02 01:48:06 +02:00
if( pobj->type == ADDR_DATASOURCE || pobj->type == ADDR_ITEM_FOLDER ) {
2001-09-06 12:24:20 +02:00
/* Items inside folders */
list = addrselect_get_list( _addressSelect_ );
node = list;
2001-09-02 01:48:06 +02:00
while( node ) {
item = node->data;
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
2001-09-02 01:48:06 +02:00
if( aio->type == ADDR_ITEM_GROUP ) {
ItemGroup *item = ( ItemGroup * ) aio;
GtkCTreeNode *nd = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
nd = addressbook_find_group_node( addrbook.opened, item );
item = addrbook_remove_group( abf, item );
if( item ) {
addritem_free_item_group( item );
}
2001-09-30 13:07:34 +02:00
/* Remove group from parent node */
2001-09-02 01:48:06 +02:00
gtk_ctree_remove_node( ctree, nd );
}
2001-09-02 01:48:06 +02:00
else if( aio->type == ADDR_ITEM_PERSON ) {
ItemPerson *item = ( ItemPerson * ) aio;
item = addrbook_remove_person( abf, item );
if( item ) {
addritem_free_item_person( item );
}
}
2001-09-02 01:48:06 +02:00
else if( aio->type == ADDR_ITEM_EMAIL ) {
ItemEMail *item = ( ItemEMail * ) aio;
ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(item);
item = addrbook_person_remove_email( abf, person, item );
if( item ) {
addritem_free_item_email( item );
}
}
2001-09-02 01:48:06 +02:00
}
g_list_free( list );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
gtk_ctree_select( ctree, addrbook.opened);
return;
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
2001-09-06 12:24:20 +02:00
/* Items inside groups */
list = addrselect_get_list( _addressSelect_ );
node = list;
2001-09-02 01:48:06 +02:00
while( node ) {
item = node->data;
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
2001-09-02 01:48:06 +02:00
if( aio->type == ADDR_ITEM_EMAIL ) {
ItemEMail *item = ( ItemEMail * ) aio;
ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(item);
item = addrbook_person_remove_email( abf, person, item );
if( item ) {
addritem_free_item_email( item );
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
g_list_free( list );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
gtk_ctree_select( ctree, addrbook.opened);
return;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
gtk_ctree_node_set_row_data( clist, nodeList, NULL );
gtk_ctree_remove_node( clist, nodeList );
2001-04-19 14:21:46 +02:00
}
static void addressbook_reg_clicked(GtkButton *button, gpointer data)
{
2001-09-02 01:48:06 +02:00
addressbook_new_address_cb( NULL, 0, NULL );
}
2001-04-19 14:21:46 +02:00
gchar *addressbook_format_address( AddrItemObject * aio ) {
2001-09-02 01:48:06 +02:00
gchar *buf = NULL;
gchar *name = NULL;
gchar *address = NULL;
2001-04-19 14:21:46 +02:00
if( aio->type == ADDR_ITEM_EMAIL ) {
2001-09-02 01:48:06 +02:00
ItemPerson *person = NULL;
ItemEMail *email = ( ItemEMail * ) aio;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
person = ( ItemPerson * ) ADDRITEM_PARENT(email);
if( email->address ) {
if( ADDRITEM_NAME(email) ) {
name = ADDRITEM_NAME(email);
if( *name == '\0' ) {
name = ADDRITEM_NAME(person);
}
}
else if( ADDRITEM_NAME(person) ) {
name = ADDRITEM_NAME(person);
}
else {
buf = g_strdup( email->address );
}
address = email->address;
2001-04-19 14:21:46 +02:00
}
}
else if( aio->type == ADDR_ITEM_PERSON ) {
ItemPerson *person = ( ItemPerson * ) aio;
2001-09-02 01:48:06 +02:00
GList *node = person->listEMail;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
name = ADDRITEM_NAME(person);
if( node ) {
ItemEMail *email = ( ItemEMail * ) node->data;
address = email->address;
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
if( address ) {
if( name ) {
buf = g_strdup_printf( "%s <%s>", name, address );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else {
buf = g_strdup( address );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
return buf;
2001-04-19 14:21:46 +02:00
}
static void addressbook_to_clicked(GtkButton *button, gpointer data)
{
GList *list, *node;
Compose *compose;
AddrSelectItem *item;
AddrItemObject *aio;
gchar *addr;
compose = addrbook.target_compose;
if( ! compose ) return;
list = addrselect_get_list( _addressSelect_ );
node = list;
2001-09-02 01:48:06 +02:00
while( node ) {
item = node->data;
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
aio = item->addressItem;
if( aio->type == ADDR_ITEM_PERSON ||
aio->type == ADDR_ITEM_EMAIL ) {
addr = addressbook_format_address( aio );
compose_entry_append(
compose, addr, (ComposeEntryType) data );
2001-09-02 01:48:06 +02:00
g_free( addr );
}
else if( aio->type == ADDR_ITEM_GROUP ) {
ItemGroup *group = ( ItemGroup * ) aio;
2001-09-02 01:48:06 +02:00
GList *nodeMail = group->listEMail;
while( nodeMail ) {
ItemEMail *email = nodeMail->data;
addr = addressbook_format_address(
( AddrItemObject * ) email );
compose_entry_append(
compose, addr, (ComposeEntryType) data );
2001-09-02 01:48:06 +02:00
g_free( addr );
nodeMail = g_list_next( nodeMail );
2001-04-19 14:21:46 +02:00
}
}
}
g_list_free( list );
2001-04-19 14:21:46 +02:00
}
static void addressbook_menubar_set_sensitive( gboolean sensitive ) {
menu_set_sensitive( addrbook.menu_factory, "/File/Edit", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/File/Delete", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", sensitive );
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.menu_factory, "/Address/New Address", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Address/New Group", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Address/New Folder", sensitive );
gtk_widget_set_sensitive( addrbook.reg_btn, sensitive );
gtk_widget_set_sensitive( addrbook.del_btn, sensitive );
}
static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode *node ) {
2001-09-02 01:48:06 +02:00
gboolean canEdit = FALSE;
gboolean canAdd = FALSE;
gboolean canEditTr = TRUE;
gboolean editAddress = FALSE;
AddressTypeControlItem *atci = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface = NULL;
if( obj == NULL ) return;
if( obj->type == ADDR_INTERFACE ) {
AdapterInterface *adapter = ADAPTER_INTERFACE(obj);
iface = adapter->interface;
if( iface ) {
if( iface->haveLibrary ) {
2001-09-06 12:24:20 +02:00
/* Enable appropriate File / New command */
2001-09-02 01:48:06 +02:00
atci = adapter->atci;
menu_set_sensitive( addrbook.menu_factory, atci->menuCommand, TRUE );
}
}
2001-09-02 01:48:06 +02:00
canEditTr = FALSE;
}
else if( obj->type == ADDR_DATASOURCE ) {
AdapterDSource *ads = ADAPTER_DSOURCE(obj);
ds = ads->dataSource;
iface = ds->interface;
if( ! iface->readOnly ) {
canAdd = canEdit = editAddress = TRUE;
}
2001-09-02 01:48:06 +02:00
if( ! iface->haveLibrary ) {
canAdd = canEdit = editAddress = FALSE;
}
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_FOLDER ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds ) {
iface = ds->interface;
if( iface->readOnly ) {
canEditTr = FALSE;
}
else {
2001-09-02 01:48:06 +02:00
canAdd = editAddress = TRUE;
}
}
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_GROUP ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds ) {
iface = ds->interface;
if( ! iface->readOnly ) {
editAddress = TRUE;
}
}
}
2001-09-02 01:48:06 +02:00
if( addrbook.listSelected == NULL ) canEdit = FALSE;
2001-09-30 13:07:34 +02:00
/* Enable add */
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.menu_factory, "/Address/New Address", editAddress );
menu_set_sensitive( addrbook.menu_factory, "/Address/New Group", canAdd );
menu_set_sensitive( addrbook.menu_factory, "/Address/New Folder", canAdd );
gtk_widget_set_sensitive( addrbook.reg_btn, editAddress );
2001-09-06 12:24:20 +02:00
/* Enable edit */
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.menu_factory, "/Address/Edit", canEdit );
menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canEdit );
gtk_widget_set_sensitive( addrbook.del_btn, canEdit );
menu_set_sensitive( addrbook.menu_factory, "/File/Edit", canEditTr );
menu_set_sensitive( addrbook.menu_factory, "/File/Delete", canEditTr );
}
2001-04-19 14:21:46 +02:00
static void addressbook_tree_selected(GtkCTree *ctree, GtkCTreeNode *node,
gint column, gpointer data)
{
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL;
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
ItemFolder *rootFolder = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
addrbook.treeSelected = node;
addrbook.listSelected = NULL;
addressbook_status_show( "" );
2001-09-02 01:48:06 +02:00
if( addrbook.entry != NULL ) gtk_entry_set_text(GTK_ENTRY(addrbook.entry), "");
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( addrbook.clist ) gtk_clist_clear( GTK_CLIST(addrbook.clist) );
if( node ) obj = gtk_ctree_node_get_row_data( ctree, node );
if( obj == NULL ) return;
2001-04-19 14:21:46 +02:00
addrbook.opened = node;
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
2001-09-30 13:07:34 +02:00
/* Read from file */
2001-09-02 01:48:06 +02:00
static gboolean tVal = TRUE;
2001-09-02 01:48:06 +02:00
ads = ADAPTER_DSOURCE(obj);
if( ads == NULL ) return;
ds = ads->dataSource;
2001-09-13 15:38:32 +02:00
if( ds == NULL ) return;
2001-09-02 01:48:06 +02:00
if( addrindex_ds_get_modify_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
2001-09-02 01:48:06 +02:00
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
addressbook_ds_show_message( ds );
if( ! addrindex_ds_get_access_flag( ds ) ) {
2001-09-06 12:24:20 +02:00
/* Remove existing folders and groups */
2001-09-02 01:48:06 +02:00
gtk_clist_freeze( GTK_CLIST(ctree) );
addressbook_tree_remove_children( ctree, node );
gtk_clist_thaw( GTK_CLIST(ctree) );
2001-09-06 12:24:20 +02:00
/* Load folders into the tree */
2001-09-02 01:48:06 +02:00
rootFolder = addrindex_ds_get_root_folder( ds );
if( ds->type == ADDR_IF_JPILOT ) {
addressbook_node_add_folder( node, ds, rootFolder, ADDR_CATEGORY );
}
else {
2001-09-02 01:48:06 +02:00
addressbook_node_add_folder( node, ds, rootFolder, ADDR_ITEM_FOLDER );
}
2001-09-02 01:48:06 +02:00
addrindex_ds_set_access_flag( ds, &tVal );
gtk_ctree_expand( ctree, node );
}
}
2001-09-02 01:48:06 +02:00
2001-09-30 13:07:34 +02:00
/* Update address list */
2001-09-02 01:48:06 +02:00
addressbook_set_clist( obj );
2001-09-06 12:24:20 +02:00
/* Setup main menu selections */
addressbook_menubar_set_sensitive( FALSE );
addressbook_menuitem_set_sensitive( obj, node );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
2001-04-19 14:21:46 +02:00
}
/*
* Setup address list popup menu.
* Enter: pobj Parent address object in address tree.
* obj Address object in address list.
*/
static void addressbook_list_menu_setup( void ) {
GtkCTree *clist = NULL;
AddressObject *pobj = NULL;
AddressObject *obj = NULL;
AdapterDSource *ads = NULL;
AddressInterface *iface = NULL;
AddressDataSource *ds = NULL;
gboolean canEdit = FALSE;
gboolean canDelete = FALSE;
gboolean canCut = FALSE;
gboolean canCopy = FALSE;
gboolean canPaste = FALSE;
pobj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
if( pobj == NULL ) return;
clist = GTK_CTREE(addrbook.clist);
obj = gtk_ctree_node_get_row_data( clist, addrbook.listSelected );
if( obj == NULL ) canEdit = FALSE;
menu_set_insensitive_all( GTK_MENU_SHELL(addrbook.list_popup) );
if( pobj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(pobj);
ds = ads->dataSource;
iface = ds->interface;
if( ! iface->readOnly ) {
menu_set_sensitive( addrbook.list_factory, "/New Address", TRUE );
menu_set_sensitive( addrbook.list_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.list_factory, "/New Group", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
if( ! addrclip_is_empty( _clipBoard_ ) ) canPaste = TRUE;
if( ! addrselect_test_empty( _addressSelect_ ) ) canCut = TRUE;
if( obj ) canEdit = TRUE;
}
}
else if( pobj->type != ADDR_INTERFACE ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
iface = ds->interface;
if( ! iface->readOnly ) {
if( pobj->type == ADDR_ITEM_FOLDER || pobj->type == ADDR_ITEM_GROUP ) {
menu_set_sensitive( addrbook.list_factory, "/New Address", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
if( obj ) canEdit = TRUE;
}
if( pobj->type == ADDR_ITEM_FOLDER ) {
menu_set_sensitive( addrbook.list_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.list_factory, "/New Group", TRUE );
if( obj ) canEdit = TRUE;
}
if( ! addrclip_is_empty( _clipBoard_ ) ) canPaste = TRUE;
if( ! addrselect_test_empty( _addressSelect_ ) ) canCut = TRUE;
}
}
if( ! addrselect_test_empty( _addressSelect_ ) ) canCopy = TRUE;
canDelete = canEdit;
canDelete = canEdit;
/* Disable edit if more than one row selected */
if( GTK_CLIST(clist)->selection && GTK_CLIST(clist)->selection->next ) canEdit = FALSE;
menu_set_sensitive( addrbook.list_factory, "/Edit", canEdit );
menu_set_sensitive( addrbook.list_factory, "/Delete", canDelete );
menu_set_sensitive( addrbook.list_factory, "/Cut", canCut );
menu_set_sensitive( addrbook.list_factory, "/Copy", canCopy );
menu_set_sensitive( addrbook.list_factory, "/Paste", canPaste );
menu_set_sensitive( addrbook.list_factory, "/Paste Address", canPaste );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut", canCut );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy", canCopy );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste", canPaste );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );
menu_set_sensitive( addrbook.tree_factory, "/Cut", canCut );
menu_set_sensitive( addrbook.tree_factory, "/Copy", canCopy );
menu_set_sensitive( addrbook.tree_factory, "/Paste", canPaste );
menu_set_sensitive( addrbook.menu_factory, "/Address/Edit", canEdit );
menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canDelete );
gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
}
2001-04-19 14:21:46 +02:00
static void addressbook_list_selected(GtkCList *clist, gint row, gint column,
GdkEvent *event, gpointer data)
{
if (event && event->type == GDK_2BUTTON_PRESS) {
2001-09-06 12:24:20 +02:00
/* Handle double click */
2001-04-21 01:24:31 +02:00
if (prefs_common.add_address_by_click &&
addrbook.target_compose)
addressbook_to_clicked(NULL, NULL);
else
addressbook_edit_address_cb(NULL, 0, NULL);
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
/*
* Add list of items into tree node below specified tree node.
* Enter: treeNode Tree node.
* ds Data source.
* listItems List of items.
*/
static void addressbook_treenode_add_list(
GtkCTreeNode *treeNode, AddressDataSource *ds, GList *listItems )
{
GList *node;
node = listItems;
while( node ) {
AddrItemObject *aio;
GtkCTreeNode *nn;
aio = node->data;
if( ADDRESS_OBJECT_TYPE(aio) == ITEMTYPE_GROUP ) {
ItemGroup *group;
group = ( ItemGroup * ) aio;
nn = addressbook_node_add_group( treeNode, ds, group );
2001-04-19 14:21:46 +02:00
}
else if( ADDRESS_OBJECT_TYPE(aio) == ITEMTYPE_FOLDER ) {
ItemFolder *folder;
folder = ( ItemFolder * ) aio;
nn = addressbook_node_add_folder(
treeNode, ds, folder, ADDR_ITEM_FOLDER );
2001-09-02 01:48:06 +02:00
}
node = g_list_next( node );
2001-04-19 14:21:46 +02:00
}
}
/*
* Cut from address list widget.
*/
static void addressbook_clip_cut_cb( void ) {
_clipBoard_->cutFlag = TRUE;
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
/*
* Copy from address list widget.
*/
static void addressbook_clip_copy_cb( void ) {
_clipBoard_->cutFlag = FALSE;
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
/*
* Paste clipboard into address list widget.
*/
static void addressbook_clip_paste_cb( void ) {
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
AddressObject *pobj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
ItemFolder *folder = NULL;
GList *folderGroup = NULL;
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
if( addrindex_ds_get_readonly( ds ) ) {
addressbook_ds_status_message(
ds, _( "Cannot paste. Target address book is readonly." ) );
return;
}
pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( pobj ) {
if( pobj->type == ADDR_ITEM_FOLDER ) {
folder = ADAPTER_FOLDER(pobj)->itemFolder;
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
addressbook_ds_status_message(
ds, _( "Cannot paste into an address group." ) );
return;
}
}
/* Get an address book */
abf = addressbook_get_book_file();
if( abf == NULL ) return;
if( _clipBoard_->cutFlag ) {
/* Paste/Cut */
folderGroup = addrclip_paste_cut( _clipBoard_, abf, folder );
/* Remove all groups and folders in clipboard from tree node */
addressbook_treenode_remove_item();
/* Remove all "cut" items */
addrclip_delete_item( _clipBoard_ );
/* Clear clipboard - cut items??? */
addrclip_clear( _clipBoard_ );
2001-04-19 14:21:46 +02:00
}
else {
/* Paste/Copy */
folderGroup = addrclip_paste_copy( _clipBoard_, abf, folder );
}
/* addrclip_list_show( _clipBoard_, stdout ); */
if( folderGroup ) {
/* Update tree by inserting node for each folder or group */
addressbook_treenode_add_list(
addrbook.treeSelected, ds, folderGroup );
gtk_ctree_expand( ctree, addrbook.treeSelected );
g_list_free( folderGroup );
folderGroup = NULL;
}
/* Display items pasted */
gtk_ctree_select( ctree, addrbook.opened );
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
/*
* Paste clipboard email addresses only into address list widget.
*/
static void addressbook_clip_paste_address_cb( void ) {
GtkCTree *clist = GTK_CTREE(addrbook.clist);
GtkCTree *ctree;
AddressObject *pobj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
ItemFolder *folder = NULL;
AddrItemObject *aio;
gint cnt;
if( addrbook.listSelected == NULL ) return;
ctree = GTK_CTREE( addrbook.ctree );
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
if( addrindex_ds_get_readonly( ds ) ) {
addressbook_ds_status_message(
ds, _( "Cannot paste. Target address book is readonly." ) );
return;
}
pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( pobj ) {
if( pobj->type == ADDR_ITEM_FOLDER ) {
folder = ADAPTER_FOLDER(pobj)->itemFolder;
2001-04-19 14:21:46 +02:00
}
}
abf = addressbook_get_book_file();
if( abf == NULL ) return;
cnt = 0;
aio = gtk_ctree_node_get_row_data( clist, addrbook.listSelected );
if( aio->type == ADDR_ITEM_PERSON ) {
ItemPerson *person;
person = ( ItemPerson * ) aio;
if( _clipBoard_->cutFlag ) {
/* Paste/Cut */
cnt = addrclip_paste_person_cut( _clipBoard_, abf, person );
/* Remove all "cut" items */
addrclip_delete_address( _clipBoard_ );
/* Clear clipboard */
addrclip_clear( _clipBoard_ );
}
else {
/* Paste/Copy */
cnt = addrclip_paste_person_copy( _clipBoard_, abf, person );
}
if( cnt > 0 ) {
addritem_person_set_opened( person, TRUE );
}
}
/* Display items pasted */
if( cnt > 0 ) {
gtk_ctree_select( ctree, addrbook.opened );
}
2001-04-19 14:21:46 +02:00
}
/*
* Add current treenode object to clipboard. Note that widget only allows
* one entry from the tree list to be selected.
*/
static void addressbook_treenode_to_clipboard( void ) {
AddressObject *obj = NULL;
AddressDataSource *ds = NULL;
AddrSelectItem *item;
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
GtkCTreeNode *node;
node = addrbook.treeSelected;
if( node == NULL ) return;
obj = gtk_ctree_node_get_row_data( ctree, node );
2001-09-02 01:48:06 +02:00
if( obj == NULL ) return;
ds = addressbook_find_datasource( node );
if( ds == NULL ) return;
item = NULL;
if( obj->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
ItemFolder *folder = adapter->itemFolder;
item = addrselect_create_node( obj );
item->uid = g_strdup( ADDRITEM_ID(folder) );
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_GROUP ) {
AdapterGroup *adapter = ADAPTER_GROUP(obj);
ItemGroup *group = adapter->itemGroup;
item = addrselect_create_node( obj );
item->uid = g_strdup( ADDRITEM_ID(group) );
}
else if( obj->type == ADDR_DATASOURCE ) {
/* Data source */
item = addrselect_create_node( obj );
item->uid = NULL;
}
if( item ) {
/* Clear existing list and add item into list */
gchar *cacheID;
addressbook_list_select_clear();
cacheID = addrindex_get_cache_id( _addressIndex_, ds );
addrselect_list_add( _addressSelect_, item, cacheID );
g_free( cacheID );
}
}
/*
* Cut from tree widget.
*/
static void addressbook_treenode_cut_cb( void ) {
_clipBoard_->cutFlag = TRUE;
addressbook_treenode_to_clipboard();
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
/*
* Copy from tree widget.
*/
static void addressbook_treenode_copy_cb( void ) {
_clipBoard_->cutFlag = FALSE;
addressbook_treenode_to_clipboard();
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
/*
* Paste clipboard into address tree widget.
*/
static void addressbook_treenode_paste_cb( void ) {
addressbook_clip_paste_cb();
}
static void addressbook_list_select_clear( void ) {
addrselect_list_clear( _addressSelect_ );
}
static void addressbook_list_select_add( AddrItemObject *aio, AddressDataSource *ds ) {
gchar *cacheID;
if( ds == NULL ) return;
cacheID = addrindex_get_cache_id( _addressIndex_, ds );
addrselect_list_add_obj( _addressSelect_, aio, cacheID );
g_free( cacheID );
}
static void addressbook_list_select_remove( AddrItemObject *aio ) {
addrselect_list_remove( _addressSelect_, aio );
}
static void addressbook_list_row_selected( GtkCTree *clist,
GtkCTreeNode *node,
gint column,
gpointer data )
{
2001-09-02 01:48:06 +02:00
GtkEntry *entry = GTK_ENTRY(addrbook.entry);
AddrItemObject *aio = NULL;
2001-09-02 01:48:06 +02:00
AddressObject *pobj = NULL;
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
gtk_entry_set_text( entry, "" );
addrbook.listSelected = node;
pobj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
if( pobj == NULL ) return;
if( pobj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(pobj);
ds = ads->dataSource;
}
else if( pobj->type != ADDR_INTERFACE ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
}
2001-04-19 14:21:46 +02:00
aio = gtk_ctree_node_get_row_data( clist, node );
if( aio ) {
/* printf( "list select: %d : '%s'\n", aio->type, aio->name ); */
addressbook_list_select_add( aio, ds );
}
2001-04-19 14:21:46 +02:00
addressbook_list_menu_setup();
2001-09-02 01:48:06 +02:00
}
static void addressbook_list_row_unselected( GtkCTree *ctree,
GtkCTreeNode *node,
gint column,
gpointer data )
{
AddrItemObject *aio;
2001-09-02 01:48:06 +02:00
aio = gtk_ctree_node_get_row_data( ctree, node );
if( aio != NULL ) {
/* printf( "list unselect: %d : '%s'\n", aio->type, aio->name ); */
addressbook_list_select_remove( aio );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_entry_gotfocus( GtkWidget *widget ) {
gtk_editable_select_region( GTK_EDITABLE(addrbook.entry), 0, -1 );
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_list_button_pressed(GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
if( ! event ) return;
addressbook_list_menu_setup();
2001-09-02 01:48:06 +02:00
if( event->button == 3 ) {
gtk_menu_popup( GTK_MENU(addrbook.list_popup), NULL, NULL, NULL, NULL,
event->button, event->time );
}
2001-04-19 14:21:46 +02:00
}
static void addressbook_list_button_released(GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
}
static void addressbook_tree_button_pressed(GtkWidget *ctree,
GdkEventButton *event,
gpointer data)
{
GtkCList *clist = GTK_CLIST(ctree);
gint row, column;
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL;
AdapterDSource *ads = NULL;
AddressInterface *iface = NULL;
AddressDataSource *ds = NULL;
gboolean canEdit = FALSE;
gboolean canCut = FALSE;
gboolean canCopy = FALSE;
gboolean canPaste = FALSE;
gboolean canTreeCut = FALSE;
gboolean canTreeCopy = FALSE;
gboolean canTreePaste = FALSE;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( ! event ) return;
addressbook_menubar_set_sensitive( FALSE );
2001-09-02 01:48:06 +02:00
if( gtk_clist_get_selection_info( clist, event->x, event->y, &row, &column ) ) {
gtk_clist_select_row( clist, row, column );
gtkut_clist_set_focus_row(clist, row);
obj = gtk_clist_get_row_data( clist, row );
2001-04-19 14:21:46 +02:00
}
2001-04-19 14:21:46 +02:00
menu_set_insensitive_all(GTK_MENU_SHELL(addrbook.tree_popup));
2001-09-02 01:48:06 +02:00
if( obj == NULL ) return;
if( ! addrclip_is_empty( _clipBoard_ ) ) {
canTreePaste = TRUE;
}
2001-09-02 01:48:06 +02:00
if (obj->type == ADDR_DATASOURCE) {
ads = ADAPTER_DSOURCE(obj);
ds = ads->dataSource;
iface = ds->interface;
canEdit = TRUE;
if( iface->readOnly ) {
canTreePaste = FALSE;
}
else {
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
canTreeCopy = TRUE;
}
2001-09-02 01:48:06 +02:00
else if (obj->type == ADDR_ITEM_FOLDER) {
ds = addressbook_find_datasource( addrbook.treeSelected );
iface = ds->interface;
if( iface->readOnly ) {
canTreePaste = FALSE;
}
else {
2001-09-02 01:48:06 +02:00
canEdit = TRUE;
canTreeCut = TRUE;
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
canTreeCopy = TRUE;
}
2001-09-02 01:48:06 +02:00
else if (obj->type == ADDR_ITEM_GROUP) {
ds = addressbook_find_datasource( addrbook.treeSelected );
iface = ds->interface;
if( ! iface->readOnly ) {
canEdit = TRUE;
menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
}
else if (obj->type == ADDR_INTERFACE) {
canTreePaste = FALSE;
}
if( canEdit ) {
if( ! addrselect_test_empty( _addressSelect_ ) ) canCut = TRUE;
}
if( ! addrselect_test_empty( _addressSelect_ ) ) canCopy = TRUE;
if( ! addrclip_is_empty( _clipBoard_ ) ) canPaste = TRUE;
2001-09-02 01:48:06 +02:00
2001-09-06 12:24:20 +02:00
/* Enable edit */
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.tree_factory, "/Edit", canEdit );
menu_set_sensitive( addrbook.tree_factory, "/Delete", canEdit );
menu_set_sensitive( addrbook.tree_factory, "/Cut", canTreeCut );
menu_set_sensitive( addrbook.tree_factory, "/Copy", canTreeCopy );
menu_set_sensitive( addrbook.tree_factory, "/Paste", canTreePaste );
menu_set_sensitive( addrbook.menu_factory, "/File/Edit", canEdit );
menu_set_sensitive( addrbook.menu_factory, "/File/Delete", canEdit );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut", canCut );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy", canCopy );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste", canPaste );
menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );
2001-09-02 01:48:06 +02:00
if( event->button == 3 ) {
gtk_menu_popup(GTK_MENU(addrbook.tree_popup), NULL, NULL, NULL, NULL,
event->button, event->time);
}
2001-09-02 01:48:06 +02:00
2001-04-19 14:21:46 +02:00
}
static void addressbook_tree_button_released(GtkWidget *ctree,
GdkEventButton *event,
gpointer data)
{
gtk_ctree_select(GTK_CTREE(addrbook.ctree), addrbook.opened);
gtkut_ctree_set_focus_row(GTK_CTREE(addrbook.ctree), addrbook.opened);
}
static void addressbook_popup_close(GtkMenuShell *menu_shell, gpointer data)
{
if (!addrbook.opened) return;
gtk_ctree_select(GTK_CTREE(addrbook.ctree), addrbook.opened);
gtkut_ctree_set_focus_row(GTK_CTREE(addrbook.ctree),
addrbook.opened);
}
static void addressbook_new_folder_cb(gpointer data, guint action,
GtkWidget *widget)
{
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
ItemFolder *parentFolder = NULL;
ItemFolder *folder = NULL;
if( ! addrbook.treeSelected ) return;
obj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( obj == NULL ) return;
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
if( ADAPTER_DSOURCE(obj)->subType != ADDR_BOOK ) return;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_FOLDER ) {
parentFolder = ADAPTER_FOLDER(obj)->itemFolder;
}
else {
2001-04-19 14:21:46 +02:00
return;
}
2001-09-02 01:48:06 +02:00
abf = ds->rawDataSource;
if( abf == NULL ) return;
folder = addressbook_edit_folder( abf, parentFolder, NULL );
if( folder ) {
GtkCTreeNode *nn;
nn = addressbook_node_add_folder( addrbook.treeSelected, ds, folder, ADDR_ITEM_FOLDER );
gtk_ctree_expand( ctree, addrbook.treeSelected );
if( addrbook.treeSelected == addrbook.opened ) addressbook_set_clist(obj);
}
2001-04-19 14:21:46 +02:00
}
static void addressbook_new_group_cb(gpointer data, guint action,
GtkWidget *widget)
{
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
ItemFolder *parentFolder = NULL;
ItemGroup *group = NULL;
if( ! addrbook.treeSelected ) return;
obj = gtk_ctree_node_get_row_data(ctree, addrbook.treeSelected);
if( obj == NULL ) return;
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
if( ADAPTER_DSOURCE(obj)->subType != ADDR_BOOK ) return;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_FOLDER ) {
parentFolder = ADAPTER_FOLDER(obj)->itemFolder;
}
else {
2001-04-19 14:21:46 +02:00
return;
}
2001-09-02 01:48:06 +02:00
abf = ds->rawDataSource;
if( abf == NULL ) return;
group = addressbook_edit_group( abf, parentFolder, NULL );
if( group ) {
GtkCTreeNode *nn;
nn = addressbook_node_add_group( addrbook.treeSelected, ds, group );
gtk_ctree_expand( ctree, addrbook.treeSelected );
if( addrbook.treeSelected == addrbook.opened ) addressbook_set_clist(obj);
}
2001-04-19 14:21:46 +02:00
}
static void addressbook_change_node_name(GtkCTreeNode *node, const gchar *name)
{
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
gchar *text[1];
guint8 spacing;
GdkPixmap *pix_cl, *pix_op;
GdkBitmap *mask_cl, *mask_op;
gboolean is_leaf, expanded;
gtk_ctree_get_node_info(ctree, node, text, &spacing,
&pix_cl, &mask_cl, &pix_op, &mask_op,
&is_leaf, &expanded);
gtk_ctree_set_node_info(ctree, node, name, spacing,
pix_cl, mask_cl, pix_op, mask_op,
is_leaf, expanded);
}
2001-09-02 01:48:06 +02:00
/*
* Edit data source.
* Enter: obj Address object to edit.
* node Node in tree.
* Return: New name of data source.
*/
static gchar *addressbook_edit_datasource( AddressObject *obj, GtkCTreeNode *node ) {
gchar *newName = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface = NULL;
AdapterDSource *ads = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( node );
if( ds == NULL ) return NULL;
iface = ds->interface;
if( ! iface->haveLibrary ) return NULL;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Read data from data source */
2001-09-02 01:48:06 +02:00
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Handle edit */
2001-09-02 01:48:06 +02:00
ads = ADAPTER_DSOURCE(obj);
if( ads->subType == ADDR_BOOK ) {
if( addressbook_edit_book( _addressIndex_, ads ) == NULL ) return NULL;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else if( ads->subType == ADDR_VCARD ) {
if( addressbook_edit_vcard( _addressIndex_, ads ) == NULL ) return NULL;
}
#ifdef USE_JPILOT
else if( ads->subType == ADDR_JPILOT ) {
if( addressbook_edit_jpilot( _addressIndex_, ads ) == NULL ) return NULL;
}
#endif
#ifdef USE_LDAP
else if( ads->subType == ADDR_LDAP ) {
if( addressbook_edit_ldap( _addressIndex_, ads ) == NULL ) return NULL;
}
#endif
else {
return NULL;
}
newName = obj->name;
return newName;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Edit an object that is in the address tree area.
*/
static void addressbook_treenode_edit_cb(gpointer data, guint action,
2001-04-19 14:21:46 +02:00
GtkWidget *widget)
{
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
AddressObject *obj;
2001-09-02 01:48:06 +02:00
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
GtkCTreeNode *node = NULL, *parentNode = NULL;
2001-09-02 01:48:06 +02:00
gchar *name = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( ! addrbook.treeSelected ) return;
node = addrbook.treeSelected;
if( GTK_CTREE_ROW(node)->level == 1 ) return;
obj = gtk_ctree_node_get_row_data( ctree, node );
if( obj == NULL ) return;
parentNode = GTK_CTREE_ROW(node)->parent;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( node );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
name = addressbook_edit_datasource( obj, node );
if( name == NULL ) return;
}
2001-09-02 01:48:06 +02:00
else {
abf = ds->rawDataSource;
if( abf == NULL ) return;
if( obj->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
ItemFolder *item = adapter->itemFolder;
ItemFolder *parentFolder = NULL;
parentFolder = ( ItemFolder * ) ADDRITEM_PARENT(item);
if( addressbook_edit_folder( abf, parentFolder, item ) == NULL ) return;
name = ADDRITEM_NAME(item);
}
else if( obj->type == ADDR_ITEM_GROUP ) {
AdapterGroup *adapter = ADAPTER_GROUP(obj);
ItemGroup *item = adapter->itemGroup;
ItemFolder *parentFolder = NULL;
parentFolder = ( ItemFolder * ) ADDRITEM_PARENT(item);
if( addressbook_edit_group( abf, parentFolder, item ) == NULL ) return;
name = ADDRITEM_NAME(item);
}
}
if( name && parentNode ) {
2001-09-06 12:24:20 +02:00
/* Update node in tree view */
2001-09-02 01:48:06 +02:00
addressbook_change_node_name( node, name );
gtk_ctree_sort_node(ctree, parentNode);
2001-09-02 01:48:06 +02:00
gtk_ctree_expand( ctree, node );
gtk_ctree_select( ctree, node );
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Delete an item from the tree widget.
*/
static void addressbook_treenode_delete_cb(gpointer data, guint action,
2001-04-19 14:21:46 +02:00
GtkWidget *widget)
{
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
2001-09-02 01:48:06 +02:00
GtkCTreeNode *node = NULL;
AddressObject *obj;
2001-04-19 14:21:46 +02:00
gchar *message;
AlertValue aval;
2001-09-02 01:48:06 +02:00
AddressBookFile *abf = NULL;
AdapterDSource *ads = NULL;
AddressInterface *iface = NULL;
AddressDataSource *ds = NULL;
gboolean remFlag = FALSE;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( ! addrbook.treeSelected ) return;
node = addrbook.treeSelected;
if( GTK_CTREE_ROW(node)->level == 1 ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
obj = gtk_ctree_node_get_row_data( ctree, node );
2001-04-19 14:21:46 +02:00
g_return_if_fail(obj != NULL);
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(obj);
if( ads == NULL ) return;
ds = ads->dataSource;
if( ds == NULL ) return;
}
2001-09-02 01:48:06 +02:00
else {
2001-09-30 13:07:34 +02:00
/* Must be folder or something else */
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( node );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Only allow deletion from non-readOnly data sources */
2001-09-02 01:48:06 +02:00
iface = ds->interface;
if( iface->readOnly ) return;
}
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Confirm deletion */
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_ITEM_FOLDER ) {
message = g_strdup_printf( _(
"Do you want to delete the folder AND all addresses in `%s' ? \n" \
"If deleting the folder only, addresses will be moved into parent folder." ),
obj->name );
aval = alertpanel( _("Delete"), message,
_("Folder only"), _("Folder and Addresses"), _("Cancel") );
2001-09-02 01:48:06 +02:00
g_free(message);
if( aval == G_ALERTOTHER ) return;
}
else {
message = g_strdup_printf(_("Really delete `%s' ?"), obj->name);
aval = alertpanel(_("Delete"), message, _("Yes"), _("No"), NULL);
g_free(message);
if (aval != G_ALERTDEFAULT) return;
}
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Proceed with deletion */
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
2001-09-30 13:07:34 +02:00
/* Remove data source. */
2001-09-02 01:48:06 +02:00
if( addrindex_index_remove_datasource( _addressIndex_, ds ) ) {
addrindex_free_datasource( ds );
2001-09-02 01:48:06 +02:00
remFlag = TRUE;
}
}
else {
abf = addressbook_get_book_file();
if( abf == NULL ) return;
}
if( obj->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
ItemFolder *item = adapter->itemFolder;
if( aval == G_ALERTDEFAULT ) {
2001-09-06 12:24:20 +02:00
/* Remove folder only */
2001-09-02 01:48:06 +02:00
item = addrbook_remove_folder( abf, item );
if( item ) {
addritem_free_item_folder( item );
addressbook_move_nodes_up( ctree, node );
remFlag = TRUE;
}
}
else if( aval == G_ALERTALTERNATE ) {
2001-09-06 12:24:20 +02:00
/* Remove folder and addresses */
2001-09-02 01:48:06 +02:00
item = addrbook_remove_folder_delete( abf, item );
if( item ) {
addritem_free_item_folder( item );
remFlag = TRUE;
}
}
}
else if( obj->type == ADDR_ITEM_GROUP ) {
AdapterGroup *adapter = ADAPTER_GROUP(obj);
ItemGroup *item = adapter->itemGroup;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
item = addrbook_remove_group( abf, item );
if( item ) {
addritem_free_item_group( item );
remFlag = TRUE;
}
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( remFlag ) {
/* Remove node. */
2001-09-02 01:48:06 +02:00
gtk_ctree_remove_node(ctree, node );
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
static void addressbook_new_address_cb( gpointer data, guint action, GtkWidget *widget ) {
AddressObject *pobj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
pobj = gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree), addrbook.treeSelected);
if( pobj == NULL ) return;
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
abf = ds->rawDataSource;
if( abf == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( pobj->type == ADDR_DATASOURCE ) {
if( ADAPTER_DSOURCE(pobj)->subType == ADDR_BOOK ) {
2001-09-06 12:24:20 +02:00
/* New address */
2001-09-02 01:48:06 +02:00
ItemPerson *person = addressbook_edit_person( abf, NULL, NULL, FALSE );
if( person ) {
if( addrbook.treeSelected == addrbook.opened ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened );
}
}
}
}
else if( pobj->type == ADDR_ITEM_FOLDER ) {
2001-09-30 13:07:34 +02:00
/* New address */
2001-09-02 01:48:06 +02:00
ItemFolder *folder = ADAPTER_FOLDER(pobj)->itemFolder;
ItemPerson *person = addressbook_edit_person( abf, folder, NULL, FALSE );
if( person ) {
if (addrbook.treeSelected == addrbook.opened) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened );
}
}
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
2001-09-06 12:24:20 +02:00
/* New address in group */
2001-09-02 01:48:06 +02:00
ItemGroup *group = ADAPTER_GROUP(pobj)->itemGroup;
if( addressbook_edit_group( abf, NULL, group ) == NULL ) return;
if (addrbook.treeSelected == addrbook.opened) {
2001-09-06 12:24:20 +02:00
/* Change node name in tree. */
2001-09-02 01:48:06 +02:00
addressbook_change_node_name( addrbook.treeSelected, ADDRITEM_NAME(group) );
gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened );
}
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
/*
* Search for specified child group node in address index tree.
* Enter: parent Parent node.
* group Group to find.
2001-09-02 01:48:06 +02:00
*/
static GtkCTreeNode *addressbook_find_group_node( GtkCTreeNode *parent, ItemGroup *group ) {
GtkCTreeNode *node = NULL;
GtkCTreeRow *currRow;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
currRow = GTK_CTREE_ROW( parent );
if( currRow ) {
node = currRow->children;
while( node ) {
AddressObject *obj;
obj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), node );
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_ITEM_GROUP ) {
ItemGroup *g = ADAPTER_GROUP(obj)->itemGroup;
if( g == group ) return node;
}
currRow = GTK_CTREE_ROW(node);
node = currRow->sibling;
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
return NULL;
}
2001-04-19 14:21:46 +02:00
/*
* Search for specified child folder node in address index tree.
* Enter: parent Parent node.
* folder Folder to find.
*/
static GtkCTreeNode *addressbook_find_folder_node( GtkCTreeNode *parent, ItemFolder *folder ) {
GtkCTreeNode *node = NULL;
GtkCTreeRow *currRow;
currRow = GTK_CTREE_ROW( parent );
if( currRow ) {
node = currRow->children;
while( node ) {
AddressObject *obj;
obj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), node );
if( obj->type == ADDR_ITEM_FOLDER ) {
ItemFolder *f = ADAPTER_FOLDER(obj)->itemFolder;
if( f == folder ) return node;
}
currRow = GTK_CTREE_ROW(node);
node = currRow->sibling;
}
}
return NULL;
}
2001-09-02 01:48:06 +02:00
static AddressBookFile *addressbook_get_book_file() {
AddressBookFile *abf = NULL;
AddressDataSource *ds = NULL;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( addrbook.treeSelected );
2001-09-06 12:24:20 +02:00
if( ds == NULL ) return NULL;
2001-09-02 01:48:06 +02:00
if( ds->type == ADDR_IF_BOOK ) abf = ds->rawDataSource;
return abf;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_tree_remove_children( GtkCTree *ctree, GtkCTreeNode *parent ) {
GtkCTreeNode *node;
GtkCTreeRow *row;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Remove existing folders and groups */
2001-09-02 01:48:06 +02:00
row = GTK_CTREE_ROW( parent );
if( row ) {
2001-09-06 12:24:20 +02:00
while( (node = row->children) ) {
2001-09-02 01:48:06 +02:00
gtk_ctree_remove_node( ctree, node );
}
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
static void addressbook_move_nodes_up( GtkCTree *ctree, GtkCTreeNode *node ) {
GtkCTreeNode *parent, *child;
GtkCTreeRow *currRow;
currRow = GTK_CTREE_ROW( node );
if( currRow ) {
parent = currRow->parent;
2001-09-06 12:24:20 +02:00
while( (child = currRow->children) ) {
2001-09-02 01:48:06 +02:00
gtk_ctree_move( ctree, child, parent, node );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
gtk_ctree_sort_node( ctree, parent );
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
static void addressbook_edit_address_cb( gpointer data, guint action, GtkWidget *widget ) {
GtkCTree *clist = GTK_CTREE(addrbook.clist);
GtkCTree *ctree;
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL, *pobj = NULL;
AddressDataSource *ds = NULL;
GtkCTreeNode *node = NULL, *parentNode = NULL;
2001-09-02 01:48:06 +02:00
gchar *name = NULL;
AddressBookFile *abf = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( addrbook.listSelected == NULL ) return;
obj = gtk_ctree_node_get_row_data( clist, addrbook.listSelected );
2001-04-19 14:21:46 +02:00
g_return_if_fail(obj != NULL);
2001-09-02 01:48:06 +02:00
ctree = GTK_CTREE( addrbook.ctree );
pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
node = gtk_ctree_find_by_row_data( ctree, addrbook.treeSelected, obj );
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
abf = addressbook_get_book_file();
if( abf == NULL ) return;
if( obj->type == ADDR_ITEM_EMAIL ) {
ItemEMail *email = ( ItemEMail * ) obj;
if( email == NULL ) return;
if( pobj && pobj->type == ADDR_ITEM_GROUP ) {
2001-09-30 13:07:34 +02:00
/* Edit parent group */
2001-09-02 01:48:06 +02:00
AdapterGroup *adapter = ADAPTER_GROUP(pobj);
ItemGroup *itemGrp = adapter->itemGroup;
if( addressbook_edit_group( abf, NULL, itemGrp ) == NULL ) return;
name = ADDRITEM_NAME(itemGrp);
node = addrbook.treeSelected;
parentNode = GTK_CTREE_ROW(node)->parent;
}
else {
2001-09-06 12:24:20 +02:00
/* Edit person - email page */
ItemPerson *person;
2001-09-02 01:48:06 +02:00
person = ( ItemPerson * ) ADDRITEM_PARENT(email);
if( addressbook_edit_person( abf, NULL, person, TRUE ) == NULL ) return;
gtk_ctree_select( ctree, addrbook.opened );
2001-09-24 07:43:58 +02:00
invalidate_address_completion();
2001-09-02 01:48:06 +02:00
return;
}
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_PERSON ) {
2001-09-06 12:24:20 +02:00
/* Edit person - basic page */
2001-09-02 01:48:06 +02:00
ItemPerson *person = ( ItemPerson * ) obj;
if( addressbook_edit_person( abf, NULL, person, FALSE ) == NULL ) return;
gtk_ctree_select( ctree, addrbook.opened);
2001-09-24 07:43:58 +02:00
invalidate_address_completion();
2001-09-02 01:48:06 +02:00
return;
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_GROUP ) {
ItemGroup *itemGrp = ( ItemGroup * ) obj;
if( addressbook_edit_group( abf, NULL, itemGrp ) == NULL ) return;
parentNode = addrbook.treeSelected;
node = addressbook_find_group_node( parentNode, itemGrp );
name = ADDRITEM_NAME(itemGrp);
}
else {
return;
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Update tree node with node name */
2001-09-02 01:48:06 +02:00
if( node == NULL ) return;
addressbook_change_node_name( node, name );
gtk_ctree_sort_node( ctree, parentNode );
gtk_ctree_select( ctree, addrbook.opened );
2001-04-19 14:21:46 +02:00
}
static void addressbook_delete_address_cb(gpointer data, guint action,
GtkWidget *widget)
{
addressbook_del_clicked(NULL, NULL);
}
static void close_cb(gpointer data, guint action, GtkWidget *widget)
{
addressbook_close();
}
2001-09-02 01:48:06 +02:00
static void addressbook_file_save_cb( gpointer data, guint action, GtkWidget *widget ) {
addressbook_export_to_file();
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_person_expand_node( GtkCTree *ctree, GList *node, gpointer *data ) {
if( node ) {
ItemPerson *person = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(node) );
if( person ) addritem_person_set_opened( person, TRUE );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_person_collapse_node( GtkCTree *ctree, GList *node, gpointer *data ) {
if( node ) {
ItemPerson *person = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(node) );
if( person ) addritem_person_set_opened( person, FALSE );
}
2001-09-02 01:48:06 +02:00
}
static gchar *addressbook_format_item_clist( ItemPerson *person, ItemEMail *email ) {
gchar *str = NULL;
gchar *eMailAlias = ADDRITEM_NAME(email);
if( eMailAlias && *eMailAlias != '\0' ) {
if( person ) {
str = g_strdup_printf( "%s - %s", ADDRITEM_NAME(person), eMailAlias );
}
else {
str = g_strdup( eMailAlias );
}
}
2001-09-02 01:48:06 +02:00
return str;
}
static void addressbook_load_group( GtkCTree *clist, ItemGroup *itemGroup ) {
GList *items = itemGroup->listEMail;
AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_EMAIL );
for( ; items != NULL; items = g_list_next( items ) ) {
GtkCTreeNode *nodeEMail = NULL;
gchar *text[N_COLS];
ItemEMail *email = items->data;
ItemPerson *person;
gchar *str = NULL;
if( ! email ) continue;
person = ( ItemPerson * ) ADDRITEM_PARENT(email);
str = addressbook_format_item_clist( person, email );
if( str ) {
text[COL_NAME] = str;
}
else {
text[COL_NAME] = ADDRITEM_NAME(person);
}
text[COL_ADDRESS] = email->address;
text[COL_REMARKS] = email->remarks;
nodeEMail = gtk_ctree_insert_node(
clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, FALSE );
gtk_ctree_node_set_row_data( clist, nodeEMail, email );
g_free( str );
str = NULL;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_folder_load_person( GtkCTree *clist, ItemFolder *itemFolder ) {
GList *items;
AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_PERSON );
AddressTypeControlItem *atciMail = addrbookctl_lookup( ADDR_ITEM_EMAIL );
if( atci == NULL ) return;
if( atciMail == NULL ) return;
2001-09-30 13:07:34 +02:00
/* Load email addresses */
2001-09-02 01:48:06 +02:00
items = addritem_folder_get_person_list( itemFolder );
for( ; items != NULL; items = g_list_next( items ) ) {
GtkCTreeNode *nodePerson = NULL;
GtkCTreeNode *nodeEMail = NULL;
gchar *text[N_COLS];
gboolean flgFirst = TRUE, haveAddr = FALSE;
ItemPerson *person;
GList *node;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
person = ( ItemPerson * ) items->data;
if( person == NULL ) continue;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
text[COL_NAME] = NULL;
node = person->listEMail;
while( node ) {
ItemEMail *email = node->data;
gchar *eMailAddr = NULL;
node = g_list_next( node );
2001-09-02 01:48:06 +02:00
text[COL_ADDRESS] = email->address;
text[COL_REMARKS] = email->remarks;
eMailAddr = ADDRITEM_NAME(email);
2001-10-02 10:34:49 +02:00
if( eMailAddr && *eMailAddr == '\0' ) eMailAddr = NULL;
2001-09-02 01:48:06 +02:00
if( flgFirst ) {
2001-09-30 13:07:34 +02:00
/* First email belongs with person */
2001-09-02 01:48:06 +02:00
gchar *str = addressbook_format_item_clist( person, email );
if( str ) {
text[COL_NAME] = str;
}
else {
text[COL_NAME] = ADDRITEM_NAME(person);
}
nodePerson = gtk_ctree_insert_node(
clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, person->isOpened );
g_free( str );
str = NULL;
gtk_ctree_node_set_row_data(clist, nodePerson, person );
}
else {
2001-09-06 12:24:20 +02:00
/* Subsequent email is a child node of person */
2001-09-02 01:48:06 +02:00
text[COL_NAME] = ADDRITEM_NAME(email);
nodeEMail = gtk_ctree_insert_node(
clist, nodePerson, NULL,
text, FOLDER_SPACING,
atciMail->iconXpm, atciMail->maskXpm,
atciMail->iconXpmOpen, atciMail->maskXpmOpen,
FALSE, TRUE );
gtk_ctree_node_set_row_data(clist, nodeEMail, email );
}
flgFirst = FALSE;
haveAddr = TRUE;
}
if( ! haveAddr ) {
2001-09-06 12:24:20 +02:00
/* Have name without EMail */
2001-09-02 01:48:06 +02:00
text[COL_NAME] = ADDRITEM_NAME(person);
text[COL_ADDRESS] = NULL;
text[COL_REMARKS] = NULL;
2001-09-02 01:48:06 +02:00
nodePerson = gtk_ctree_insert_node(
clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, person->isOpened );
gtk_ctree_node_set_row_data(clist, nodePerson, person );
}
gtk_ctree_sort_node(GTK_CTREE(clist), NULL);
}
2001-09-06 12:24:20 +02:00
/* Free up the list */
2001-09-02 01:48:06 +02:00
mgu_clear_list( items );
g_list_free( items );
}
static void addressbook_folder_load_group( GtkCTree *clist, ItemFolder *itemFolder ) {
GList *items;
AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_GROUP );
2001-09-06 12:24:20 +02:00
/* Load any groups */
2001-09-02 01:48:06 +02:00
if( ! atci ) return;
items = addritem_folder_get_group_list( itemFolder );
for( ; items != NULL; items = g_list_next( items ) ) {
GtkCTreeNode *nodeGroup = NULL;
gchar *text[N_COLS];
ItemGroup *group = items->data;
if( group == NULL ) continue;
text[COL_NAME] = ADDRITEM_NAME(group);
text[COL_ADDRESS] = NULL;
text[COL_REMARKS] = NULL;
nodeGroup = gtk_ctree_insert_node(clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, FALSE);
gtk_ctree_node_set_row_data(clist, nodeGroup, group );
gtk_ctree_sort_node(clist, NULL);
}
2001-09-06 12:24:20 +02:00
/* Free up the list */
2001-09-02 01:48:06 +02:00
mgu_clear_list( items );
g_list_free( items );
}
/*
* Load data sources into list.
*/
static void addressbook_node_load_datasource( GtkCTree *clist, AddressObject *obj ) {
AdapterInterface *adapter;
AddressInterface *iface;
AddressTypeControlItem *atci = NULL;
GtkCTreeNode *newNode, *node;
GtkCTreeRow *row;
GtkCell *cell = NULL;
gchar *text[N_COLS];
adapter = ADAPTER_INTERFACE(obj);
if( adapter == NULL ) return;
iface = adapter->interface;
atci = adapter->atci;
if( atci == NULL ) return;
2001-09-30 13:07:34 +02:00
/* Create nodes in list copying values for data sources in tree */
2001-09-02 01:48:06 +02:00
row = GTK_CTREE_ROW( adapter->treeNode );
if( row ) {
node = row->children;
while( node ) {
gpointer data;
data = gtk_ctree_node_get_row_data( clist, node );
2001-09-02 01:48:06 +02:00
row = GTK_CTREE_ROW( node );
cell = ( ( GtkCListRow * )row )->cell;
text[COL_NAME] = cell->u.text;
text[COL_ADDRESS] = NULL;
text[COL_REMARKS] = NULL;
2001-09-02 01:48:06 +02:00
newNode = gtk_ctree_insert_node( clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, FALSE);
/*
2001-09-02 01:48:06 +02:00
gtk_ctree_node_set_row_data( clist, newNode, data );
gtk_ctree_node_set_row_data_full( clist, newNode, NULL, NULL );
*/
2001-09-02 01:48:06 +02:00
node = row->sibling;
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
gtk_ctree_sort_node( clist, NULL );
2001-04-19 14:21:46 +02:00
}
/*
* Search ctree widget callback function.
* Enter: pA Pointer to node.
* pB Pointer to data item being sought.
* Return: Zero (0) if group found.
*/
static int addressbook_treenode_find_group_cb( gconstpointer pA, gconstpointer pB ) {
AddressObject *aoA;
aoA = ( AddressObject * ) pA;
if( aoA->type == ADDR_ITEM_GROUP ) {
ItemGroup *group, *grp;
grp = ADAPTER_GROUP(aoA)->itemGroup;
group = ( ItemGroup * ) pB;
if( grp == group ) return 0; /* Found group */
}
return 1;
}
/*
* Search ctree widget callback function.
* Enter: pA Pointer to node.
* pB Pointer to data item being sought.
* Return: Zero (0) if folder found.
*/
static int addressbook_treenode_find_folder_cb( gconstpointer pA, gconstpointer pB ) {
AddressObject *aoA;
aoA = ( AddressObject * ) pA;
if( aoA->type == ADDR_ITEM_FOLDER ) {
ItemFolder *folder, *fld;
fld = ADAPTER_FOLDER(aoA)->itemFolder;
folder = ( ItemFolder * ) pB;
if( fld == folder ) return 0; /* Found folder */
}
return 1;
}
/*
* Remove folder and group nodes from tree widget for items contained ("cut")
* in clipboard.
*/
static void addressbook_treenode_remove_item( void ) {
GList *node;
AddrSelectItem *cutItem;
AddressCache *cache;
AddrItemObject *aio;
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
GtkCTreeNode *tn;
node = _clipBoard_->objectList;
while( node ) {
cutItem = node->data;
node = g_list_next( node );
cache = addrindex_get_cache(
_clipBoard_->addressIndex, cutItem->cacheID );
if( cache == NULL ) continue;
aio = addrcache_get_object( cache, cutItem->uid );
if( aio ) {
tn = NULL;
if( ADDRITEM_TYPE(aio) == ITEMTYPE_FOLDER ) {
ItemFolder *folder;
folder = ( ItemFolder * ) aio;
tn = gtk_ctree_find_by_row_data_custom(
ctree, NULL, folder,
addressbook_treenode_find_folder_cb );
}
else if( ADDRITEM_TYPE(aio) == ITEMTYPE_GROUP ) {
ItemGroup *group;
group = ( ItemGroup * ) aio;
tn = gtk_ctree_find_by_row_data_custom(
ctree, NULL, group,
addressbook_treenode_find_group_cb );
}
if( tn ) {
/* Free up adapter and remove node. */
gtk_ctree_remove_node( ctree, tn );
}
}
}
}
/*
* Find parent datasource for specified tree node.
* Enter: node Node to test.
* Return: Data source, or NULL if not found.
*/
2001-09-02 01:48:06 +02:00
static AddressDataSource *addressbook_find_datasource( GtkCTreeNode *node ) {
AddressDataSource *ds = NULL;
AddressObject *ao;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail(addrbook.ctree != NULL, NULL);
2001-09-02 01:48:06 +02:00
while( node ) {
if( GTK_CTREE_ROW(node)->level < 2 ) return NULL;
ao = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), node );
if( ao ) {
/* printf( "ao->type = %d\n", ao->type ); */
2001-09-02 01:48:06 +02:00
if( ao->type == ADDR_DATASOURCE ) {
AdapterDSource *ads = ADAPTER_DSOURCE(ao);
/* printf( "found it\n" ); */
2001-09-02 01:48:06 +02:00
ds = ads->dataSource;
break;
}
}
node = GTK_CTREE_ROW(node)->parent;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
return ds;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
/*
* Load address list widget with children of specified object.
* Enter: obj Parent object to be loaded.
*/
static void addressbook_set_clist( AddressObject *obj ) {
GtkCTree *ctreelist = GTK_CTREE(addrbook.clist);
GtkCList *clist = GTK_CLIST(addrbook.clist);
AddressDataSource *ds = NULL;
AdapterDSource *ads = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj == NULL ) {
gtk_clist_clear(clist);
2001-04-19 14:21:46 +02:00
return;
}
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_INTERFACE ) {
2001-09-30 13:07:34 +02:00
/* printf( "set_clist: loading datasource...\n" ); */
/* addressbook_node_load_datasource( GTK_CTREE(clist), obj ); */
2001-09-02 01:48:06 +02:00
return;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
gtk_clist_freeze(clist);
gtk_clist_clear(clist);
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(obj);
ds = ADAPTER_DSOURCE(obj)->dataSource;
if( ds ) {
2001-09-06 12:24:20 +02:00
/* Load root folder */
2001-09-02 01:48:06 +02:00
ItemFolder *rootFolder = NULL;
rootFolder = addrindex_ds_get_root_folder( ds );
addressbook_folder_load_person( ctreelist, addrindex_ds_get_root_folder( ds ) );
addressbook_folder_load_group( ctreelist, addrindex_ds_get_root_folder( ds ) );
}
}
else {
if( obj->type == ADDR_ITEM_GROUP ) {
2001-09-06 12:24:20 +02:00
/* Load groups */
2001-09-02 01:48:06 +02:00
ItemGroup *itemGroup = ADAPTER_GROUP(obj)->itemGroup;
addressbook_load_group( ctreelist, itemGroup );
}
else if( obj->type == ADDR_ITEM_FOLDER ) {
2001-09-30 13:07:34 +02:00
/* Load folders */
2001-09-02 01:48:06 +02:00
ItemFolder *itemFolder = ADAPTER_FOLDER(obj)->itemFolder;
addressbook_folder_load_person( ctreelist, itemFolder );
addressbook_folder_load_group( ctreelist, itemFolder );
2001-04-19 14:21:46 +02:00
}
}
/* gtk_clist_sort(clist); */
2001-09-02 01:48:06 +02:00
gtk_clist_thaw(clist);
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Call back function to free adaptor. Call back is setup by function
* gtk_ctree_node_set_row_data_full() when node is populated. This function is
* called when the address book tree widget node is removed by calling
* function gtk_ctree_remove_node().
* Enter: data Tree node's row data.
2001-09-02 01:48:06 +02:00
*/
static void addressbook_free_treenode( gpointer data ) {
2001-09-02 01:48:06 +02:00
AddressObject *ao;
ao = ( AddressObject * ) data;
if( ao == NULL ) return;
if( ao->type == ADDR_INTERFACE ) {
AdapterInterface *ai = ADAPTER_INTERFACE(ao);
addrbookctl_free_interface( ai );
}
else if( ao->type == ADDR_DATASOURCE ) {
AdapterDSource *ads = ADAPTER_DSOURCE(ao);
addrbookctl_free_datasource( ads );
}
else if( ao->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *af = ADAPTER_FOLDER(ao);
addrbookctl_free_folder( af );
}
else if( ao->type == ADDR_ITEM_GROUP ) {
AdapterGroup *ag = ADAPTER_GROUP(ao);
addrbookctl_free_group( ag );
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
/*
* Create new adaptor for specified data source.
2001-09-02 01:48:06 +02:00
*/
AdapterDSource *addressbook_create_ds_adapter( AddressDataSource *ds,
AddressObjectType otype, gchar *name )
{
AdapterDSource *adapter = g_new0( AdapterDSource, 1 );
ADDRESS_OBJECT(adapter)->type = ADDR_DATASOURCE;
ADDRESS_OBJECT_NAME(adapter) = g_strdup( name );
adapter->dataSource = ds;
adapter->subType = otype;
return adapter;
}
2001-09-02 01:48:06 +02:00
void addressbook_ads_set_name( AdapterDSource *adapter, gchar *value ) {
ADDRESS_OBJECT_NAME(adapter) = mgu_replace_string( ADDRESS_OBJECT_NAME(adapter), value );
}
2001-09-02 01:48:06 +02:00
/*
* Load tree from address index with the initial data.
*/
static void addressbook_load_tree( void ) {
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
GList *nodeIf, *nodeDS;
AdapterInterface *adapter;
AddressInterface *iface;
AddressTypeControlItem *atci;
AddressDataSource *ds;
AdapterDSource *ads;
GtkCTreeNode *node, *newNode;
gchar *name;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
nodeIf = _addressInterfaceList_;
while( nodeIf ) {
adapter = nodeIf->data;
node = adapter->treeNode;
iface = adapter->interface;
atci = adapter->atci;
if( iface ) {
2001-09-02 03:09:09 +02:00
if( iface->useInterface ) {
2001-09-30 13:07:34 +02:00
/* Load data sources below interface node */
2001-09-02 03:09:09 +02:00
nodeDS = iface->listSource;
while( nodeDS ) {
ds = nodeDS->data;
newNode = NULL;
name = addrindex_ds_get_name( ds );
ads = addressbook_create_ds_adapter( ds, atci->objectType, name );
newNode = addressbook_add_object( node, ADDRESS_OBJECT(ads) );
nodeDS = g_list_next( nodeDS );
}
gtk_ctree_expand( ctree, node );
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
nodeIf = g_list_next( nodeIf );
}
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
/*
* Convert the old address book to new format.
*/
static gboolean addressbook_convert( AddressIndex *addrIndex ) {
gboolean retVal = FALSE;
gboolean errFlag = TRUE;
gchar *msg = NULL;
2001-09-06 12:24:20 +02:00
/* Read old address book, performing conversion */
2001-09-02 01:48:06 +02:00
debug_print( "Reading and converting old address book...\n" );
addrindex_set_file_name( addrIndex, ADDRESSBOOK_OLD_FILE );
addrindex_read_data( addrIndex );
if( addrIndex->retVal == MGU_NO_FILE ) {
2001-09-06 12:24:20 +02:00
/* We do not have a file - new user */
2001-09-02 01:48:06 +02:00
debug_print( "New user... create new books...\n" );
addrindex_create_new_books( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
/* Save index file */
2001-09-02 01:48:06 +02:00
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_save_data( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
retVal = TRUE;
errFlag = FALSE;
}
else {
2001-09-06 12:24:20 +02:00
msg = _( "New user, could not save index file." );
2001-09-02 01:48:06 +02:00
}
}
else {
2001-09-06 12:24:20 +02:00
msg = _( "New user, could not save address book files." );
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
else {
2001-09-06 12:24:20 +02:00
/* We have an old file */
2001-09-02 01:48:06 +02:00
if( addrIndex->wasConverted ) {
2001-09-30 13:07:34 +02:00
/* Converted successfully - save address index */
2001-09-02 01:48:06 +02:00
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_save_data( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
msg = _( "Old address book converted successfully." );
2001-09-02 01:48:06 +02:00
retVal = TRUE;
errFlag = FALSE;
}
else {
2001-09-06 12:24:20 +02:00
msg = _("Old address book converted,\n"
"could not save new address index file" );
2001-09-02 01:48:06 +02:00
}
}
else {
2001-09-06 12:24:20 +02:00
/* File conversion failed - just create new books */
2001-09-02 01:48:06 +02:00
debug_print( "File conversion failed... just create new books...\n" );
addrindex_create_new_books( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
/* Save index */
2001-09-02 01:48:06 +02:00
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_save_data( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
msg = _("Could not convert address book,\n"
"but created empty new address book files." );
2001-09-02 01:48:06 +02:00
retVal = TRUE;
errFlag = FALSE;
}
else {
2001-09-06 12:24:20 +02:00
msg = _("Could not convert address book,\n"
"could not create new address book files." );
2001-09-02 01:48:06 +02:00
}
}
else {
2001-09-06 12:24:20 +02:00
msg = _("Could not convert address book\n"
"and could not create new address book files." );
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
if( errFlag ) {
debug_print( "Error\n%s\n", msg );
2001-09-06 12:24:20 +02:00
alertpanel( _( "Addressbook conversion error" ), msg, _( "Close" ), NULL, NULL );
2001-09-02 01:48:06 +02:00
}
2001-09-06 12:24:20 +02:00
else if( msg ) {
debug_print( "Warning\n%s\n", msg );
alertpanel( _( "Addressbook conversion" ), msg, _( "Close" ), NULL, NULL );
}
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
return retVal;
}
2001-09-02 01:48:06 +02:00
void addressbook_read_file( void ) {
AddressIndex *addrIndex = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
debug_print( "Reading address index...\n" );
if( _addressIndex_ ) {
debug_print( "address book already read!!!\n" );
return;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
addrIndex = addrindex_create_index();
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Use new address book index. */
2001-09-02 01:48:06 +02:00
addrindex_set_file_path( addrIndex, get_rc_dir() );
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_read_data( addrIndex );
if( addrIndex->retVal == MGU_NO_FILE ) {
2001-09-06 12:24:20 +02:00
/* Conversion required */
debug_print( "Converting...\n" );
2001-09-02 01:48:06 +02:00
if( addressbook_convert( addrIndex ) ) {
_addressIndex_ = addrIndex;
}
}
2001-09-02 01:48:06 +02:00
else if( addrIndex->retVal == MGU_SUCCESS ) {
_addressIndex_ = addrIndex;
}
2001-09-02 01:48:06 +02:00
else {
2001-09-06 12:24:20 +02:00
/* Error reading address book */
2001-09-02 01:48:06 +02:00
debug_print( "Could not read address index.\n" );
addrindex_print_index( addrIndex, stdout );
2001-09-06 12:24:20 +02:00
alertpanel( _( "Addressbook Error" ),
_( "Could not read address index" ),
_( "Close" ), NULL, NULL );
}
2001-09-02 01:48:06 +02:00
debug_print( "done.\n" );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Add object into the address index tree widget.
* Enter: node Parent node.
* obj Object to add.
* Return: Node that was added, or NULL if object not added.
*/
static GtkCTreeNode *addressbook_add_object(GtkCTreeNode *node,
AddressObject *obj)
2001-04-19 14:21:46 +02:00
{
2001-09-02 01:48:06 +02:00
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
GtkCTreeNode *added;
AddressObject *pobj;
AddressObjectType otype;
AddressTypeControlItem *atci = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
g_return_val_if_fail(node != NULL, NULL);
g_return_val_if_fail(obj != NULL, NULL);
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
pobj = gtk_ctree_node_get_row_data(ctree, node);
g_return_val_if_fail(pobj != NULL, NULL);
2001-04-19 14:21:46 +02:00
2001-09-30 13:07:34 +02:00
/* Determine object type to be displayed */
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
otype = ADAPTER_DSOURCE(obj)->subType;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else {
otype = obj->type;
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Handle any special conditions. */
2001-09-02 01:48:06 +02:00
added = node;
atci = addrbookctl_lookup( otype );
if( atci ) {
if( atci->showInTree ) {
2001-09-06 12:24:20 +02:00
/* Add object to tree */
2001-09-02 01:48:06 +02:00
gchar **name;
name = &obj->name;
added = gtk_ctree_insert_node( ctree, node, NULL, name, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm, atci->iconXpmOpen, atci->maskXpmOpen,
atci->treeLeaf, atci->treeExpand );
gtk_ctree_node_set_row_data_full( ctree, added, obj,
addressbook_free_treenode );
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
gtk_ctree_sort_node(ctree, node);
return added;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Add group into the address index tree.
* Enter: node Parent node.
* ds Data source.
* itemGroup Group to add.
* Return: Inserted node.
*/
static GtkCTreeNode *addressbook_node_add_group( GtkCTreeNode *node, AddressDataSource *ds, ItemGroup *itemGroup ) {
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
GtkCTreeNode *newNode;
AdapterGroup *adapter;
AddressTypeControlItem *atci = NULL;
gchar **name;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
if( ds == NULL ) return NULL;
if( node == NULL || itemGroup == NULL ) return NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
name = &itemGroup->obj.name;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
atci = addrbookctl_lookup( ADDR_ITEM_GROUP );
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
adapter = g_new0( AdapterGroup, 1 );
ADDRESS_OBJECT_TYPE(adapter) = ADDR_ITEM_GROUP;
ADDRESS_OBJECT_NAME(adapter) = g_strdup( ADDRITEM_NAME(itemGroup) );
adapter->itemGroup = itemGroup;
newNode = gtk_ctree_insert_node( ctree, node, NULL, name, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm, atci->iconXpm, atci->maskXpm,
atci->treeLeaf, atci->treeExpand );
gtk_ctree_node_set_row_data_full( ctree, newNode, adapter,
addressbook_free_treenode );
2001-09-02 01:48:06 +02:00
gtk_ctree_sort_node( ctree, node );
return newNode;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Add folder into the address index tree.
* Enter: node Parent node.
* ds Data source.
* itemFolder Folder to add.
* otype Object type to display.
* Return: Inserted node.
*/
static GtkCTreeNode *addressbook_node_add_folder(
GtkCTreeNode *node, AddressDataSource *ds, ItemFolder *itemFolder, AddressObjectType otype )
2001-04-19 14:21:46 +02:00
{
2001-09-02 01:48:06 +02:00
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
GtkCTreeNode *newNode = NULL;
AdapterFolder *adapter;
AddressTypeControlItem *atci = NULL;
GList *listItems = NULL;
gchar **name;
ItemFolder *rootFolder;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( ds == NULL ) return NULL;
if( node == NULL || itemFolder == NULL ) return NULL;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Determine object type */
2001-09-02 01:48:06 +02:00
atci = addrbookctl_lookup( otype );
if( atci == NULL ) return NULL;
rootFolder = addrindex_ds_get_root_folder( ds );
if( itemFolder == rootFolder ) {
newNode = node;
}
2001-09-02 01:48:06 +02:00
else {
name = &itemFolder->obj.name;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
adapter = g_new0( AdapterFolder, 1 );
ADDRESS_OBJECT_TYPE(adapter) = ADDR_ITEM_FOLDER;
ADDRESS_OBJECT_NAME(adapter) = g_strdup( ADDRITEM_NAME(itemFolder) );
adapter->itemFolder = itemFolder;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
newNode = gtk_ctree_insert_node( ctree, node, NULL, name, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm, atci->iconXpm, atci->maskXpm,
atci->treeLeaf, atci->treeExpand );
gtk_ctree_node_set_row_data_full( ctree, newNode, adapter,
addressbook_free_treenode );
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
listItems = itemFolder->listFolder;
while( listItems ) {
ItemFolder *item = listItems->data;
addressbook_node_add_folder( newNode, ds, item, otype );
listItems = g_list_next( listItems );
}
listItems = itemFolder->listGroup;
while( listItems ) {
ItemGroup *item = listItems->data;
addressbook_node_add_group( newNode, ds, item );
listItems = g_list_next( listItems );
}
gtk_ctree_sort_node( ctree, node );
return newNode;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
static void addressbook_delete_object(AddressObject *obj) {
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
if (!obj) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Remove data source. */
/* printf( "Delete obj type : %d\n", obj->type ); */
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
ads = ADAPTER_DSOURCE(obj);
if( ads == NULL ) return;
ds = ads->dataSource;
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Remove data source */
2001-09-02 01:48:06 +02:00
if( addrindex_index_remove_datasource( _addressIndex_, ds ) ) {
addrindex_free_datasource( ds );
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Free up Adapter object */
g_free( ads );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
void addressbook_export_to_file( void ) {
if( _addressIndex_ ) {
2001-09-06 12:24:20 +02:00
/* Save all new address book data */
2001-09-02 01:48:06 +02:00
debug_print( "Saving address books...\n" );
addrindex_save_all_books( _addressIndex_ );
debug_print( "Exporting addressbook to file...\n" );
addrindex_save_data( _addressIndex_ );
if( _addressIndex_->retVal != MGU_SUCCESS ) {
addrindex_print_index( _addressIndex_, stdout );
}
2001-04-19 14:21:46 +02:00
2001-09-30 13:07:34 +02:00
/* Notify address completion of new data */
2001-09-02 01:48:06 +02:00
invalidate_address_completion();
}
2001-04-19 14:21:46 +02:00
}
static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
if (event && event->keyval == GDK_Escape)
addressbook_close();
}
2001-09-02 01:48:06 +02:00
/*
* Comparison using cell contents (text in first column). Used for sort
* address index widget.
2001-09-02 01:48:06 +02:00
*/
static gint addressbook_treenode_compare_func(
GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
2001-04-19 14:21:46 +02:00
{
2001-09-02 01:48:06 +02:00
GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
gchar *name1 = NULL, *name2 = NULL;
if( cell1 ) name1 = cell1->u.text;
if( cell2 ) name2 = cell2->u.text;
if( ! name1 ) return ( name2 != NULL );
if( ! name2 ) return -1;
return strcasecmp( name1, name2 );
}
2001-04-19 14:21:46 +02:00
/*
* Comparison using object names and types.
*/
static gint addressbook_list_compare_func(
GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
2001-04-19 14:21:46 +02:00
{
AddrItemObject *aio1 = ((GtkCListRow *)ptr1)->data;
AddrItemObject *aio2 = ((GtkCListRow *)ptr2)->data;
gchar *name1 = NULL, *name2 = NULL;
2001-04-19 14:21:46 +02:00
/* Order by cell contents */
name1 = ADDRITEM_NAME( aio1 );
name2 = ADDRITEM_NAME( aio2 );
2001-05-02 20:26:06 +02:00
if( aio1->type == aio2->type ) {
/* Order by name */
if( ! name1 ) return ( name2 != NULL );
if( ! name2 ) return -1;
return strcasecmp( name1, name2 );
}
else {
/* Order groups before person */
if( aio1->type == ITEMTYPE_GROUP ) {
return -1;
}
else if( aio2->type == ITEMTYPE_GROUP ) {
return 1;
}
return 0;
}
}
2001-09-02 01:48:06 +02:00
static void addressbook_new_book_cb( gpointer data, guint action, GtkWidget *widget ) {
AdapterDSource *ads;
AdapterInterface *adapter;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
if( adapter == NULL ) return;
ads = addressbook_edit_book( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
static void addressbook_new_vcard_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_VCARD );
if( adapter == NULL ) return;
ads = addressbook_edit_vcard( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
#ifdef USE_JPILOT
static void addressbook_new_jpilot_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
AddressInterface *iface;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_JPILOT );
if( adapter == NULL ) return;
iface = adapter->interface;
if( ! iface->haveLibrary ) return;
ads = addressbook_edit_jpilot( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
#endif
#ifdef USE_LDAP
static void addressbook_new_ldap_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
AddressInterface *iface;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_LDAP );
if( adapter == NULL ) return;
iface = adapter->interface;
if( ! iface->haveLibrary ) return;
ads = addressbook_edit_ldap( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
static void addressbook_ldap_show_message( SyldapServer *svr ) {
gchar *name;
*addressbook_msgbuf = '\0';
if( svr ) {
name = syldap_get_name( svr );
if( svr->busyFlag ) {
sprintf( addressbook_msgbuf, "%s: %s", name, ADDRESSBOOK_LDAP_BUSYMSG );
}
else {
if( svr->retVal == MGU_SUCCESS ) {
sprintf( addressbook_msgbuf, "%s", name );
}
else {
sprintf( addressbook_msgbuf, "%s: %s", name, mgu_error2string( svr->retVal ) );
}
}
}
addressbook_status_show( addressbook_msgbuf );
}
2001-09-02 01:48:06 +02:00
static void ldapsearch_callback( SyldapServer *sls ) {
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
AddressObject *obj;
2001-09-02 01:48:06 +02:00
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface = NULL;
if( sls == NULL ) return;
2001-09-02 01:48:06 +02:00
if( ! addrbook.treeSelected ) return;
if( GTK_CTREE_ROW( addrbook.treeSelected )->level == 1 ) return;
2001-09-02 01:48:06 +02:00
obj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( obj == NULL ) return;
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(obj);
if( ads->subType == ADDR_LDAP ) {
SyldapServer *server;
ds = ads->dataSource;
if( ds == NULL ) return;
iface = ds->interface;
if( ! iface->haveLibrary ) return;
server = ds->rawDataSource;
if( server == sls ) {
2001-09-06 12:24:20 +02:00
/* Read from cache */
2001-09-02 01:48:06 +02:00
gtk_widget_show_all(addrbook.window);
addressbook_set_clist( obj );
addressbook_ldap_show_message( sls );
gtk_widget_show_all(addrbook.window);
gtk_entry_set_text( GTK_ENTRY(addrbook.entry), "" );
}
}
}
}
#endif
/*
* Lookup button handler.
*/
static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
AddressObject *obj;
2001-09-06 12:24:20 +02:00
#ifdef USE_LDAP
2001-09-02 01:48:06 +02:00
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface = NULL;
2001-09-06 12:24:20 +02:00
#endif
gchar *sLookup;
sLookup = gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 );
g_strchomp( sLookup );
2001-09-02 01:48:06 +02:00
if( ! addrbook.treeSelected ) return;
if( GTK_CTREE_ROW( addrbook.treeSelected )->level == 1 ) return;
2001-09-02 01:48:06 +02:00
obj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( obj == NULL ) return;
#ifdef USE_LDAP
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(obj);
if( ads->subType == ADDR_LDAP ) {
SyldapServer *server;
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
ds = ads->dataSource;
if( ds == NULL ) return;
iface = ds->interface;
if( ! iface->haveLibrary ) return;
server = ds->rawDataSource;
if( server ) {
syldap_cancel_read( server );
if( *sLookup == '\0' || strlen( sLookup ) < 1 ) return;
syldap_set_search_value( server, sLookup );
syldap_set_callback( server, ldapsearch_callback );
syldap_read_data_th( server );
addressbook_ldap_show_message( server );
}
2001-05-02 20:26:06 +02:00
}
}
2001-09-02 01:48:06 +02:00
#endif
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/* **********************************************************************
* Build lookup tables.
* ***********************************************************************
*/
2001-05-02 20:26:06 +02:00
/*
* Remap object types.
* Enter: abType AddressObjectType (used in tree node).
* Return: ItemObjectType (used in address cache data).
*/
ItemObjectType addressbook_type2item( AddressObjectType abType ) {
ItemObjectType ioType;
ioType = ITEMTYPE_NONE;
switch( abType ) {
case ADDR_ITEM_PERSON: ioType = ITEMTYPE_PERSON; break;
case ADDR_ITEM_EMAIL: ioType = ITEMTYPE_EMAIL; break;
case ADDR_ITEM_FOLDER: ioType = ITEMTYPE_FOLDER; break;
case ADDR_ITEM_GROUP: ioType = ITEMTYPE_GROUP; break;
case ADDR_DATASOURCE: ioType = ITEMTYPE_DATASOURCE; break;
}
return ioType;
}
2001-09-02 01:48:06 +02:00
/*
* Build table that controls the rendering of object types.
*/
void addrbookctl_build_map( GtkWidget *window ) {
AddressTypeControlItem *atci;
2001-05-02 20:26:06 +02:00
2001-09-30 13:07:34 +02:00
/* Build icons */
2001-12-22 01:30:32 +01:00
stock_pixmap_gdk(window, STOCK_PIXMAP_DIR_CLOSE, &folderxpm, &folderxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_DIR_OPEN, &folderopenxpm, &folderopenxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_GROUP, &groupxpm, &groupxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_VCARD, &vcardxpm, &vcardxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_BOOK, &bookxpm, &bookxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_ADDRESS, &addressxpm, &addressxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_JPILOT, &jpilotxpm, &jpilotxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_CATEGORY, &categoryxpm, &categoryxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_LDAP, &ldapxpm, &ldapxpmmask);
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
_addressBookTypeHash_ = g_hash_table_new( g_int_hash, g_int_equal );
_addressBookTypeList_ = NULL;
2001-09-06 12:24:20 +02:00
/* Interface */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_INTERFACE;
atci->interfaceType = ADDR_IF_NONE;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = FALSE;
atci->displayName = _( "Interface" );
atci->iconXpm = folderxpm;
atci->maskXpm = folderxpmmask;
atci->iconXpmOpen = folderopenxpm;
atci->maskXpmOpen = folderopenxpmmask;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-30 13:07:34 +02:00
/* Address book */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_BOOK;
atci->interfaceType = ADDR_IF_BOOK;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = FALSE;
atci->displayName = _( "Address Book" );
atci->iconXpm = bookxpm;
atci->maskXpm = bookxpmmask;
atci->iconXpmOpen = bookxpm;
atci->maskXpmOpen = bookxpmmask;
atci->menuCommand = "/File/New Book";
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* Item person */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_ITEM_PERSON;
atci->interfaceType = ADDR_IF_NONE;
atci->showInTree = FALSE;
atci->treeExpand = FALSE;
atci->treeLeaf = FALSE;
atci->displayName = _( "Person" );
atci->iconXpm = NULL;
atci->maskXpm = NULL;
atci->iconXpmOpen = NULL;
atci->maskXpmOpen = NULL;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* Item email */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_ITEM_EMAIL;
atci->interfaceType = ADDR_IF_NONE;
atci->showInTree = FALSE;
atci->treeExpand = FALSE;
atci->treeLeaf = TRUE;
atci->displayName = _( "EMail Address" );
atci->iconXpm = addressxpm;
atci->maskXpm = addressxpmmask;
atci->iconXpmOpen = addressxpm;
atci->maskXpmOpen = addressxpmmask;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* Item group */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_ITEM_GROUP;
atci->interfaceType = ADDR_IF_BOOK;
atci->showInTree = TRUE;
atci->treeExpand = FALSE;
atci->treeLeaf = FALSE;
atci->displayName = _( "Group" );
atci->iconXpm = groupxpm;
atci->maskXpm = groupxpmmask;
atci->iconXpmOpen = groupxpm;
atci->maskXpmOpen = groupxpmmask;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* Item folder */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_ITEM_FOLDER;
atci->interfaceType = ADDR_IF_BOOK;
atci->showInTree = TRUE;
atci->treeExpand = FALSE;
atci->treeLeaf = FALSE;
atci->displayName = _( "Folder" );
atci->iconXpm = folderxpm;
atci->maskXpm = folderxpmmask;
atci->iconXpmOpen = folderopenxpm;
atci->maskXpmOpen = folderopenxpmmask;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
/* vCard */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_VCARD;
atci->interfaceType = ADDR_IF_VCARD;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = TRUE;
atci->displayName = _( "vCard" );
2001-09-02 01:48:06 +02:00
atci->iconXpm = vcardxpm;
atci->maskXpm = vcardxpmmask;
atci->iconXpmOpen = vcardxpm;
atci->maskXpmOpen = vcardxpmmask;
atci->menuCommand = "/File/New vCard";
2001-09-02 01:48:06 +02:00
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
/* J-Pilot */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_JPILOT;
atci->interfaceType = ADDR_IF_JPILOT;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = FALSE;
2001-12-22 01:30:32 +01:00
atci->displayName = _( "JPilot" );
2001-09-02 01:48:06 +02:00
atci->iconXpm = jpilotxpm;
atci->maskXpm = jpilotxpmmask;
atci->iconXpmOpen = jpilotxpm;
atci->maskXpmOpen = jpilotxpmmask;
2001-12-22 01:30:32 +01:00
atci->menuCommand = "/File/New JPilot";
2001-09-02 01:48:06 +02:00
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* Category */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_CATEGORY;
atci->interfaceType = ADDR_IF_JPILOT;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = TRUE;
2001-12-22 01:30:32 +01:00
atci->displayName = _( "JPilot" );
2001-09-02 01:48:06 +02:00
atci->iconXpm = categoryxpm;
atci->maskXpm = categoryxpmmask;
atci->iconXpmOpen = categoryxpm;
atci->maskXpmOpen = categoryxpmmask;
atci->menuCommand = NULL;
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-09-06 12:24:20 +02:00
/* LDAP Server */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_LDAP;
atci->interfaceType = ADDR_IF_LDAP;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = TRUE;
atci->displayName = _( "LDAP Server" );
atci->iconXpm = ldapxpm;
atci->maskXpm = ldapxpmmask;
atci->iconXpmOpen = ldapxpm;
atci->maskXpmOpen = ldapxpmmask;
atci->menuCommand = "/File/New Server";
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Search for specified object type.
*/
AddressTypeControlItem *addrbookctl_lookup( gint ot ) {
gint objType = ot;
return ( AddressTypeControlItem * ) g_hash_table_lookup( _addressBookTypeHash_, &objType );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Search for specified interface type.
*/
AddressTypeControlItem *addrbookctl_lookup_iface( AddressIfType ifType ) {
GList *node = _addressBookTypeList_;
while( node ) {
AddressTypeControlItem *atci = node->data;
if( atci->interfaceType == ifType ) return atci;
node = g_list_next( node );
2001-05-02 20:26:06 +02:00
}
return NULL;
}
2001-09-02 01:48:06 +02:00
static void addrbookctl_free_address( AddressObject *obj ) {
g_free( obj->name );
obj->type = ADDR_NONE;
obj->name = NULL;
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
static void addrbookctl_free_interface( AdapterInterface *adapter ) {
addrbookctl_free_address( ADDRESS_OBJECT(adapter) );
adapter->interface = NULL;
adapter->interfaceType = ADDR_IF_NONE;
adapter->atci = NULL;
adapter->enabled = FALSE;
adapter->haveLibrary = FALSE;
adapter->treeNode = NULL;
g_free( adapter );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
static void addrbookctl_free_datasource( AdapterDSource *adapter ) {
addrbookctl_free_address( ADDRESS_OBJECT(adapter) );
adapter->dataSource = NULL;
adapter->subType = ADDR_NONE;
g_free( adapter );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
static void addrbookctl_free_folder( AdapterFolder *adapter ) {
addrbookctl_free_address( ADDRESS_OBJECT(adapter) );
adapter->itemFolder = NULL;
g_free( adapter );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
static void addrbookctl_free_group( AdapterGroup *adapter ) {
addrbookctl_free_address( ADDRESS_OBJECT(adapter) );
adapter->itemGroup = NULL;
g_free( adapter );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Build GUI interface list.
*/
void addrbookctl_build_iflist() {
AddressTypeControlItem *atci;
AdapterInterface *adapter;
GList *list = NULL;
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
if( _addressIndex_ == NULL ) {
_addressIndex_ = addrindex_create_index();
if( _clipBoard_ == NULL ) {
_clipBoard_ = addrclip_create();
}
addrclip_set_index( _clipBoard_, _addressIndex_ );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
_addressInterfaceList_ = NULL;
list = addrindex_get_interface_list( _addressIndex_ );
while( list ) {
AddressInterface *interface = list->data;
atci = addrbookctl_lookup_iface( interface->type );
if( atci ) {
adapter = g_new0( AdapterInterface, 1 );
adapter->interfaceType = interface->type;
adapter->atci = atci;
adapter->interface = interface;
adapter->treeNode = NULL;
adapter->enabled = TRUE;
adapter->haveLibrary = interface->haveLibrary;
ADDRESS_OBJECT(adapter)->type = ADDR_INTERFACE;
ADDRESS_OBJECT_NAME(adapter) = g_strdup( atci->displayName );
_addressInterfaceList_ = g_list_append( _addressInterfaceList_, adapter );
}
list = g_list_next( list );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
}
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
void addrbookctl_free_selection( GList *list ) {
GList *node = list;
while( node ) {
AdapterInterface *adapter = node->data;
adapter = NULL;
node = g_list_next( node );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
g_list_free( list );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Find GUI interface type specified interface type.
* Return: Interface item, or NULL if not found.
*/
AdapterInterface *addrbookctl_find_interface( AddressIfType ifType ) {
GList *node = _addressInterfaceList_;
while( node ) {
AdapterInterface *adapter = node->data;
if( adapter->interfaceType == ifType ) return adapter;
node = g_list_next( node );
}
return NULL;
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Build interface list selection.
*/
void addrbookctl_build_ifselect() {
GList *newList = NULL;
gchar *selectStr;
gchar **splitStr;
gint ifType;
gint i;
gchar *endptr = NULL;
gboolean enabled;
AdapterInterface *adapter;
2001-09-06 12:24:20 +02:00
/* GList *node; */
2001-09-02 01:48:06 +02:00
selectStr = g_strdup( ADDRESSBOOK_IFACE_SELECTION );
2001-09-06 12:24:20 +02:00
/* Parse string */
2001-09-02 01:48:06 +02:00
splitStr = g_strsplit( selectStr, ",", -1 );
for( i = 0; i < ADDRESSBOOK_MAX_IFACE; i++ ) {
if( splitStr[i] ) {
2001-09-06 12:24:20 +02:00
/* printf( "%d : %s\n", i, splitStr[i] ); */
2001-09-02 01:48:06 +02:00
ifType = strtol( splitStr[i], &endptr, 10 );
enabled = TRUE;
if( *endptr ) {
if( strcmp( endptr, "/n" ) == 0 ) {
enabled = FALSE;
}
}
2001-09-06 12:24:20 +02:00
/* printf( "\t%d : %s\n", ifType, enabled ? "yes" : "no" ); */
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ifType );
if( adapter ) {
newList = g_list_append( newList, adapter );
}
}
else {
break;
}
}
2001-09-06 12:24:20 +02:00
/* printf( "i=%d\n", i ); */
2001-09-02 01:48:06 +02:00
g_strfreev( splitStr );
g_free( selectStr );
2001-05-02 20:26:06 +02:00
2001-09-06 12:24:20 +02:00
/* Replace existing list */
2001-09-02 01:48:06 +02:00
mgu_clear_list( _addressIFaceSelection_ );
g_list_free( _addressIFaceSelection_ );
_addressIFaceSelection_ = newList;
newList = NULL;
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/* **********************************************************************
* Add sender to address book.
* ***********************************************************************
*/
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
/*
* This function is used by the Add sender to address book function.
*/
gboolean addressbook_add_contact( const gchar *name, const gchar *address, const gchar *remarks ) {
debug_print( "addressbook_add_contact: name/address: %s - %s\n", name, address );
if( addressadd_selection( _addressIndex_, name, address, remarks ) ) {
debug_print( "addressbook_add_contact - added\n" );
addressbook_refresh();
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
return TRUE;
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
/* **********************************************************************
* Address completion support.
* ***********************************************************************
*/
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
/*
* This function is used by the address completion function to load
* addresses.
* Enter: callBackFunc Function to be called when an address is
* to be loaded.
* Return: TRUE if data loaded, FALSE if address index not loaded.
*/
gboolean addressbook_load_completion( gint (*callBackFunc) ( const gchar *, const gchar * ) ) {
2001-09-06 12:24:20 +02:00
/* AddressInterface *interface; */
2001-09-02 01:48:06 +02:00
AddressDataSource *ds;
GList *nodeIf, *nodeDS;
GList *listP, *nodeP;
GList *nodeM;
gchar *sName, *sAddress, *sAlias, *sFriendly;
debug_print( "addressbook_load_completion\n" );
if( _addressIndex_ == NULL ) return FALSE;
nodeIf = addrindex_get_interface_list( _addressIndex_ );
while( nodeIf ) {
AddressInterface *interface = nodeIf->data;
nodeDS = interface->listSource;
while( nodeDS ) {
ds = nodeDS->data;
2001-09-06 12:24:20 +02:00
/* Read address book */
2001-09-02 01:48:06 +02:00
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
2001-05-02 20:26:06 +02:00
2001-09-06 12:24:20 +02:00
/* Get all persons */
2001-09-02 01:48:06 +02:00
listP = addrindex_ds_get_all_persons( ds );
nodeP = listP;
while( nodeP ) {
ItemPerson *person = nodeP->data;
nodeM = person->listEMail;
2001-09-06 12:24:20 +02:00
/* Figure out name to use */
2001-09-02 01:48:06 +02:00
sName = person->nickName;
if( sName == NULL || *sName == '\0' ) {
sName = ADDRITEM_NAME(person);
}
2001-05-02 20:26:06 +02:00
2001-09-06 12:24:20 +02:00
/* Process each E-Mail address */
2001-09-02 01:48:06 +02:00
while( nodeM ) {
ItemEMail *email = nodeM->data;
2001-09-06 12:24:20 +02:00
/* Have mail */
2001-09-02 01:48:06 +02:00
sFriendly = sName;
sAddress = email->address;
if( sAddress || *sAddress != '\0' ) {
sAlias = ADDRITEM_NAME(email);
if( sAlias && *sAlias != '\0' ) {
sFriendly = sAlias;
}
( callBackFunc ) ( sFriendly, sAddress );
}
2001-09-02 01:48:06 +02:00
nodeM = g_list_next( nodeM );
}
nodeP = g_list_next( nodeP );
}
2001-09-06 12:24:20 +02:00
/* Free up the list */
2001-09-02 01:48:06 +02:00
g_list_free( listP );
2001-05-02 20:26:06 +02:00
2001-09-02 01:48:06 +02:00
nodeDS = g_list_next( nodeDS );
}
2001-09-02 01:48:06 +02:00
nodeIf = g_list_next( nodeIf );
2001-05-02 20:26:06 +02:00
}
2001-09-02 01:48:06 +02:00
debug_print( "addressbook_load_completion... done\n" );
2001-05-02 20:26:06 +02:00
return TRUE;
}
2001-09-24 07:43:58 +02:00
/* **********************************************************************
* Address Import.
* ***********************************************************************
*/
/*
* Import LDIF file.
*/
static void addressbook_import_ldif_cb() {
AddressDataSource *ds = NULL;
AdapterDSource *ads = NULL;
AddressBookFile *abf = NULL;
AdapterInterface *adapter;
GtkCTreeNode *newNode;
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
if( adapter ) {
if( adapter->treeNode ) {
abf = addressbook_imp_ldif( _addressIndex_ );
if( abf ) {
ds = addrindex_index_add_datasource( _addressIndex_, ADDR_IF_BOOK, abf );
ads = addressbook_create_ds_adapter( ds, ADDR_BOOK, NULL );
addressbook_ads_set_name( ads, addrbook_get_name( abf ) );
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
/* Notify address completion */
invalidate_address_completion();
}
}
}
2001-09-24 07:43:58 +02:00
}
2001-10-20 09:04:54 +02:00
/*
* Import MUTT file.
*/
static void addressbook_import_mutt_cb() {
AddressDataSource *ds = NULL;
AdapterDSource *ads = NULL;
AddressBookFile *abf = NULL;
AdapterInterface *adapter;
GtkCTreeNode *newNode;
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
if( adapter ) {
if( adapter->treeNode ) {
abf = addressbook_imp_mutt( _addressIndex_ );
if( abf ) {
ds = addrindex_index_add_datasource( _addressIndex_, ADDR_IF_BOOK, abf );
ads = addressbook_create_ds_adapter( ds, ADDR_BOOK, NULL );
addressbook_ads_set_name( ads, addrbook_get_name( abf ) );
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
/* Notify address completion */
invalidate_address_completion();
}
}
2001-09-24 07:43:58 +02:00
}
}
/*
* End of Source.
*/