2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2006-01-13 18:24:38 +01:00
|
|
|
* Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
|
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
|
2005-09-21 20:22:51 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#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 "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"
|
2002-12-25 14:46:41 +01:00
|
|
|
#include "prefs_gtk.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#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"
|
2001-07-03 00:44:09 +02:00
|
|
|
#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"
|
2001-07-03 00:44:09 +02:00
|
|
|
#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 "importldif.h"
|
2001-10-29 07:59:14 +01:00
|
|
|
#include "importmutt.h"
|
2002-04-02 08:57:31 +02:00
|
|
|
#include "importpine.h"
|
2001-07-03 00:44:09 +02:00
|
|
|
|
|
|
|
#ifdef USE_JPILOT
|
|
|
|
#include "jpilot.h"
|
|
|
|
#include "editjpilot.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_LDAP
|
|
|
|
#include <pthread.h>
|
2003-06-21 08:23:00 +02:00
|
|
|
#include "ldapserver.h"
|
2001-07-03 00:44:09 +02:00
|
|
|
#include "editldap.h"
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
#define ADDRESSBOOK_LDAP_BUSYMSG "Busy"
|
2001-07-03 00:44:09 +02:00
|
|
|
#endif
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "addrquery.h"
|
2002-01-19 07:25:11 +01:00
|
|
|
#include "addrselect.h"
|
|
|
|
#include "addrclip.h"
|
2002-03-16 08:07:34 +01:00
|
|
|
#include "addrgather.h"
|
2002-05-06 08:27:11 +02:00
|
|
|
#include "adbookbase.h"
|
|
|
|
#include "exphtmldlg.h"
|
2003-08-05 06:14:35 +02:00
|
|
|
#include "expldifdlg.h"
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "browseldap.h"
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COL_SOURCES = 0,
|
|
|
|
N_INDEX_COLS = 1
|
|
|
|
} AddressIndexColumns;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COL_NAME = 0,
|
|
|
|
COL_ADDRESS = 1,
|
2005-09-14 09:47:38 +02:00
|
|
|
COL_REMARKS = 2,
|
|
|
|
N_LIST_COLS = 3
|
|
|
|
} AddressListColumns;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-03-19 09:06:08 +01:00
|
|
|
static gchar *list_titles[] = { N_("Name"),
|
|
|
|
N_("Email Address"),
|
|
|
|
N_("Remarks") };
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
#define COL_NAME_WIDTH 164
|
2001-07-03 00:44:09 +02:00
|
|
|
#define COL_ADDRESS_WIDTH 156
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#define COL_FOLDER_WIDTH 170
|
|
|
|
#define ADDRESSBOOK_WIDTH 640
|
2001-07-03 00:44:09 +02:00
|
|
|
#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;
|
2001-07-03 00:44:09 +02:00
|
|
|
static GdkPixmap *vcardxpm;
|
|
|
|
static GdkBitmap *vcardxpmmask;
|
|
|
|
static GdkPixmap *jpilotxpm;
|
|
|
|
static GdkBitmap *jpilotxpmmask;
|
|
|
|
static GdkPixmap *categoryxpm;
|
|
|
|
static GdkBitmap *categoryxpmmask;
|
|
|
|
static GdkPixmap *ldapxpm;
|
|
|
|
static GdkBitmap *ldapxpmmask;
|
2003-09-07 21:28:56 +02:00
|
|
|
static GdkPixmap *addrsearchxpm;
|
|
|
|
static GdkPixmap *addrsearchxpmmask;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2001-09-13 15:38:32 +02:00
|
|
|
/* Message buffer */
|
2001-07-03 00:44:09 +02:00
|
|
|
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 */
|
2002-01-19 07:25:11 +01:00
|
|
|
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);
|
2001-07-03 00:44:09 +02:00
|
|
|
static void addressbook_lup_clicked (GtkButton *button,
|
|
|
|
gpointer data);
|
2005-08-03 20:24:13 +02:00
|
|
|
static void addressbook_close_clicked (GtkButton *button,
|
|
|
|
gpointer data);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
static void addressbook_tree_selected (GtkCTree *ctree,
|
2001-04-19 14:21:46 +02:00
|
|
|
GtkCTreeNode *node,
|
|
|
|
gint column,
|
|
|
|
gpointer data);
|
2004-05-10 12:22:28 +02:00
|
|
|
static void addressbook_select_row_tree (GtkCTree *ctree,
|
|
|
|
GtkCTreeNode *node,
|
|
|
|
gint column,
|
|
|
|
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 );
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_list_button_pressed (GtkWidget *widget,
|
2001-04-19 14:21:46 +02:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_list_button_released(GtkWidget *widget,
|
2001-04-19 14:21:46 +02:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_tree_button_pressed (GtkWidget *ctree,
|
2001-04-19 14:21:46 +02:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_tree_button_released(GtkWidget *ctree,
|
2001-04-19 14:21:46 +02:00
|
|
|
GdkEventButton *event,
|
|
|
|
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);
|
2001-07-03 00:44:09 +02:00
|
|
|
|
|
|
|
#ifdef USE_JPILOT
|
2001-09-13 15:38:32 +02:00
|
|
|
static void addressbook_new_jpilot_cb (gpointer data,
|
|
|
|
guint action,
|
|
|
|
GtkWidget *widget);
|
2001-07-03 00:44:09 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_LDAP
|
2001-09-13 15:38:32 +02:00
|
|
|
static void addressbook_new_ldap_cb (gpointer data,
|
|
|
|
guint action,
|
|
|
|
GtkWidget *widget);
|
2001-07-03 00:44:09 +02:00
|
|
|
#endif
|
|
|
|
|
2005-10-16 14:55:18 +02:00
|
|
|
static void addressbook_set_clist (AddressObject *obj,
|
|
|
|
gboolean refresh);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
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);
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_treenode_remove_item ( void );
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
static AddressDataSource *addressbook_find_datasource
|
|
|
|
(GtkCTreeNode *node );
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
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,
|
2002-01-19 07:25:11 +01:00
|
|
|
ItemGroup *group);
|
2005-08-23 11:45:25 +02:00
|
|
|
static gboolean addressbook_entry_key_pressed (GtkWidget *widget,
|
2001-04-19 14:21:46 +02:00
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
2002-01-19 07:25:11 +01:00
|
|
|
static gint addressbook_treenode_compare_func (GtkCList *clist,
|
|
|
|
gconstpointer ptr1,
|
|
|
|
gconstpointer ptr2);
|
2003-02-16 21:58:50 +01:00
|
|
|
static void addressbook_folder_load_one_person (GtkCTree *clist,
|
|
|
|
ItemPerson *person,
|
|
|
|
AddressTypeControlItem *atci,
|
|
|
|
AddressTypeControlItem *atciMail);
|
|
|
|
static void addressbook_folder_refresh_one_person(GtkCTree *clist,
|
|
|
|
ItemPerson *person);
|
|
|
|
static void addressbook_folder_remove_one_person(GtkCTree *clist,
|
|
|
|
ItemPerson *person);
|
|
|
|
static void addressbook_folder_remove_node (GtkCTree *clist,
|
|
|
|
GtkCTreeNode *node);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-09-13 15:38:32 +02:00
|
|
|
/* LUT's and IF stuff */
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
|
2002-01-19 07:25:11 +01: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 );
|
2002-04-02 08:57:31 +02:00
|
|
|
static void addressbook_import_pine_cb ( void );
|
2002-05-06 08:27:11 +02:00
|
|
|
static void addressbook_export_html_cb ( void );
|
2003-08-05 06:14:35 +02:00
|
|
|
static void addressbook_export_ldif_cb ( void );
|
2005-11-21 18:39:59 +01:00
|
|
|
static void addressbook_select_all_cb ( void );
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_clip_cut_cb ( void );
|
|
|
|
static void addressbook_clip_copy_cb ( void );
|
|
|
|
static void addressbook_clip_paste_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
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
static void addressbook_mail_to_cb ( void );
|
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
#ifdef USE_LDAP
|
2004-01-12 22:28:31 +01:00
|
|
|
static void addressbook_browse_entry_cb ( void );
|
2004-06-25 10:05:09 +02:00
|
|
|
#endif
|
2005-08-17 11:29:17 +02:00
|
|
|
static void addressbook_edit_clicked(GtkButton *button, gpointer data);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
static void addressbook_start_drag(GtkWidget *widget, gint button,
|
|
|
|
GdkEvent *event,
|
|
|
|
void *data);
|
|
|
|
static void addressbook_drag_data_get(GtkWidget *widget,
|
|
|
|
GdkDragContext *drag_context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
void *data);
|
|
|
|
static gboolean addressbook_drag_motion_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint time,
|
|
|
|
void *data);
|
|
|
|
static void addressbook_drag_leave_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
guint time,
|
|
|
|
void *data);
|
|
|
|
static void addressbook_drag_received_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *drag_context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
void *pdata);
|
2005-09-19 19:53:13 +02:00
|
|
|
static void addressbook_list_menu_setup( void );
|
2004-09-06 11:53:05 +02:00
|
|
|
|
|
|
|
static GtkTargetEntry addressbook_drag_types[] =
|
|
|
|
{
|
2006-02-06 18:56:35 +01:00
|
|
|
{"sylpheed-claws/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY}
|
2004-09-06 11:53:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static GtkTargetList *addressbook_target_list = NULL;
|
|
|
|
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GtkItemFactoryEntry addressbook_entries[] =
|
|
|
|
{
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Book"), NULL, NULL, 0, "<Branch>"},
|
|
|
|
{N_("/_Book/New _Book"), "<control>B", addressbook_new_book_cb, 0, NULL},
|
|
|
|
{N_("/_Book/New _Folder"), "<control>R", addressbook_new_folder_cb, 0, NULL},
|
2005-08-03 20:24:13 +02:00
|
|
|
{N_("/_Book/New _vCard"), "<control><shift>D", addressbook_new_vcard_cb, 0, NULL},
|
2001-07-03 00:44:09 +02:00
|
|
|
#ifdef USE_JPILOT
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Book/New _JPilot"), "<control>J", addressbook_new_jpilot_cb, 0, NULL},
|
2001-07-03 00:44:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef USE_LDAP
|
2005-11-23 19:26:57 +01:00
|
|
|
{N_("/_Book/New LDAP _Server"), "<control><shift>S", addressbook_new_ldap_cb, 0, NULL},
|
2001-09-02 01:48:06 +02:00
|
|
|
#endif
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Book/---"), NULL, NULL, 0, "<Separator>"},
|
2005-08-23 14:20:48 +02:00
|
|
|
{N_("/_Book/_Edit book"), NULL, addressbook_treenode_edit_cb, 0, NULL},
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Book/_Delete book"), NULL, addressbook_treenode_delete_cb, 0, NULL},
|
|
|
|
{N_("/_Book/---"), NULL, NULL, 0, "<Separator>"},
|
|
|
|
{N_("/_Book/_Save"), "<control>S", addressbook_file_save_cb, 0, NULL},
|
|
|
|
{N_("/_Book/_Close"), "<control>W", close_cb, 0, NULL},
|
|
|
|
{N_("/_Address"), NULL, NULL, 0, "<Branch>"},
|
2005-11-21 18:39:59 +01:00
|
|
|
{N_("/_Address/_Select all"), "<control>A", addressbook_select_all_cb, 0, NULL},
|
|
|
|
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Address/C_ut"), "<control>X", addressbook_clip_cut_cb, 0, NULL},
|
|
|
|
{N_("/_Address/_Copy"), "<control>C", addressbook_clip_copy_cb, 0, NULL},
|
|
|
|
{N_("/_Address/_Paste"), "<control>V", addressbook_clip_paste_cb, 0, NULL},
|
2001-09-02 01:48:06 +02:00
|
|
|
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Address/_Edit"), "<control>Return",addressbook_edit_address_cb, 0, NULL},
|
2005-08-03 20:24:13 +02:00
|
|
|
{N_("/_Address/_Delete"), "<control>D", addressbook_delete_address_cb, 0, NULL},
|
2004-05-10 12:22:28 +02:00
|
|
|
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
|
2005-08-02 19:11:21 +02:00
|
|
|
{N_("/_Address/New _Address"), "<control>N", addressbook_new_address_cb, 0, NULL},
|
|
|
|
{N_("/_Address/New _Group"), "<control>G", addressbook_new_group_cb, 0, NULL},
|
|
|
|
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
|
2004-05-10 12:22:28 +02:00
|
|
|
{N_("/_Address/_Mail To"), NULL, addressbook_mail_to_cb, 0, NULL},
|
2005-09-14 09:47:38 +02:00
|
|
|
{N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
|
2002-05-06 08:27:11 +02:00
|
|
|
{N_("/_Tools/Import _LDIF file..."), NULL, addressbook_import_ldif_cb, 0, NULL},
|
|
|
|
{N_("/_Tools/Import M_utt file..."), NULL, addressbook_import_mutt_cb, 0, NULL},
|
|
|
|
{N_("/_Tools/Import _Pine file..."), NULL, addressbook_import_pine_cb, 0, NULL},
|
|
|
|
{N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
|
|
|
|
{N_("/_Tools/Export _HTML..."), NULL, addressbook_export_html_cb, 0, NULL},
|
2003-08-05 06:14:35 +02:00
|
|
|
{N_("/_Tools/Export LDI_F..."), NULL, addressbook_export_ldif_cb, 0, NULL},
|
2005-09-14 09:47:38 +02:00
|
|
|
{N_("/_Help"), NULL, NULL, 0, "<Branch>"},
|
2001-09-02 01:48:06 +02:00
|
|
|
{N_("/_Help/_About"), NULL, about_show, 0, NULL}
|
2001-04-19 14:21:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static GtkItemFactoryEntry addressbook_tree_popup_entries[] =
|
|
|
|
{
|
2001-09-02 01:48:06 +02:00
|
|
|
{N_("/_Edit"), NULL, addressbook_treenode_edit_cb, 0, NULL},
|
2002-01-19 07:25:11 +01:00
|
|
|
{N_("/_Delete"), NULL, addressbook_treenode_delete_cb, 0, NULL},
|
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
2004-05-10 12:22:28 +02:00
|
|
|
{N_("/New _Folder"), NULL, addressbook_new_folder_cb, 0, NULL},
|
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
2002-01-19 07:25:11 +01:00
|
|
|
{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[] =
|
|
|
|
{
|
2005-11-21 18:39:59 +01:00
|
|
|
{N_("/_Select all"), NULL, addressbook_select_all_cb, 0, NULL},
|
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
2004-05-10 12:22:28 +02:00
|
|
|
{N_("/_Edit"), NULL, addressbook_edit_address_cb, 0, NULL},
|
|
|
|
{N_("/_Delete"), NULL, addressbook_delete_address_cb, 0, NULL},
|
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
2002-01-19 07:25:11 +01:00
|
|
|
{N_("/New _Address"), NULL, addressbook_new_address_cb, 0, NULL},
|
|
|
|
{N_("/New _Group"), NULL, addressbook_new_group_cb, 0, NULL},
|
2001-04-19 14:21:46 +02:00
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
2002-01-19 07:25:11 +01:00
|
|
|
{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>"},
|
2005-08-02 19:11:21 +02:00
|
|
|
/* {N_("/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL},*/
|
2004-06-25 10:05:09 +02:00
|
|
|
{N_("/_Mail To"), NULL, addressbook_mail_to_cb, 0, NULL},
|
2004-05-10 12:22:28 +02:00
|
|
|
#ifdef USE_LDAP
|
2004-06-25 10:05:09 +02:00
|
|
|
{N_("/_Browse Entry"), NULL, addressbook_browse_entry_cb, 0, NULL},
|
2004-01-12 22:28:31 +01:00
|
|
|
#endif
|
2001-04-19 14:21:46 +02:00
|
|
|
};
|
|
|
|
|
2003-01-26 06:12:00 +01:00
|
|
|
/**
|
|
|
|
* Structure of error message table.
|
|
|
|
*/
|
|
|
|
typedef struct _ErrMsgTableEntry ErrMsgTableEntry;
|
|
|
|
struct _ErrMsgTableEntry {
|
|
|
|
gint code;
|
|
|
|
gchar *description;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *_errMsgUnknown_ = N_( "Unknown" );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table of error messages for general errors. Note that a NULL
|
|
|
|
* description signifies the end of the table.
|
|
|
|
*/
|
|
|
|
static ErrMsgTableEntry _lutErrorsGeneral_[] = {
|
|
|
|
{ MGU_SUCCESS, N_("Success") },
|
|
|
|
{ MGU_BAD_ARGS, N_("Bad arguments") },
|
|
|
|
{ MGU_NO_FILE, N_("File not specified") },
|
|
|
|
{ MGU_OPEN_FILE, N_("Error opening file") },
|
|
|
|
{ MGU_ERROR_READ, N_("Error reading file") },
|
|
|
|
{ MGU_EOF, N_("End of file encountered") },
|
|
|
|
{ MGU_OO_MEMORY, N_("Error allocating memory") },
|
|
|
|
{ MGU_BAD_FORMAT, N_("Bad file format") },
|
|
|
|
{ MGU_ERROR_WRITE, N_("Error writing to file") },
|
|
|
|
{ MGU_OPEN_DIRECTORY, N_("Error opening directory") },
|
|
|
|
{ MGU_NO_PATH, N_("No path specified") },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef USE_LDAP
|
|
|
|
/**
|
|
|
|
* Lookup table of error messages for LDAP errors.
|
|
|
|
*/
|
|
|
|
static ErrMsgTableEntry _lutErrorsLDAP_[] = {
|
2004-01-12 22:28:31 +01:00
|
|
|
{ LDAPRC_SUCCESS, N_("Success") },
|
|
|
|
{ LDAPRC_CONNECT, N_("Error connecting to LDAP server") },
|
|
|
|
{ LDAPRC_INIT, N_("Error initializing LDAP") },
|
|
|
|
{ LDAPRC_BIND, N_("Error binding to LDAP server") },
|
|
|
|
{ LDAPRC_SEARCH, N_("Error searching LDAP database") },
|
|
|
|
{ LDAPRC_TIMEOUT, N_("Timeout performing LDAP operation") },
|
|
|
|
{ LDAPRC_CRITERIA, N_("Error in LDAP search criteria") },
|
|
|
|
{ LDAPRC_NOENTRIES, N_("No LDAP entries found for search criteria") },
|
|
|
|
{ LDAPRC_STOP_FLAG, N_("LDAP search terminated on request") },
|
2004-05-10 12:22:28 +02:00
|
|
|
{ LDAPRC_TLS, N_("Error starting TLS connection") },
|
2003-01-26 06:12:00 +01:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup message for specified error code.
|
|
|
|
* \param lut Lookup table.
|
|
|
|
* \param code Code to lookup.
|
|
|
|
* \return Description associated to code.
|
|
|
|
*/
|
|
|
|
static gchar *addressbook_err2string( ErrMsgTableEntry lut[], gint code ) {
|
|
|
|
gchar *desc = NULL;
|
|
|
|
ErrMsgTableEntry entry;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for( i = 0; ; i++ ) {
|
|
|
|
entry = lut[ i ];
|
|
|
|
if( entry.description == NULL ) break;
|
|
|
|
if( entry.code == code ) {
|
|
|
|
desc = entry.description;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( ! desc ) {
|
|
|
|
desc = _errMsgUnknown_;
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2005-08-02 19:11:21 +02:00
|
|
|
static gboolean lastCanLookup = FALSE;
|
|
|
|
|
|
|
|
void addressbook_show_buttons(gboolean add_and_delete, gboolean lookup, gboolean mail_ops)
|
|
|
|
{
|
|
|
|
if (add_and_delete) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_widget_show(addrbook.edit_btn);
|
2005-08-02 19:11:21 +02:00
|
|
|
gtk_widget_show(addrbook.del_btn);
|
|
|
|
gtk_widget_show(addrbook.reg_btn);
|
|
|
|
} else {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_widget_hide(addrbook.edit_btn);
|
2005-08-02 19:11:21 +02:00
|
|
|
gtk_widget_hide(addrbook.del_btn);
|
|
|
|
gtk_widget_hide(addrbook.reg_btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookup) {
|
|
|
|
gtk_widget_show(addrbook.lup_btn);
|
|
|
|
gtk_widget_show(addrbook.entry);
|
|
|
|
gtk_widget_show(addrbook.label);
|
|
|
|
} else {
|
|
|
|
gtk_widget_hide(addrbook.lup_btn);
|
|
|
|
gtk_widget_hide(addrbook.entry);
|
|
|
|
gtk_widget_hide(addrbook.label);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastCanLookup = lookup;
|
|
|
|
|
|
|
|
if (mail_ops) {
|
|
|
|
gtk_widget_show(addrbook.to_btn);
|
|
|
|
gtk_widget_show(addrbook.cc_btn);
|
|
|
|
gtk_widget_show(addrbook.bcc_btn);
|
|
|
|
} else {
|
|
|
|
gtk_widget_hide(addrbook.to_btn);
|
|
|
|
gtk_widget_hide(addrbook.cc_btn);
|
|
|
|
gtk_widget_hide(addrbook.bcc_btn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void addressbook_open(Compose *target)
|
|
|
|
{
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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();
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
|
2001-04-19 14:21:46 +02:00
|
|
|
GTK_CTREE_NODE(GTK_CLIST(addrbook.ctree)->row_list));
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
else {
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_widget_hide(addrbook.window);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2001-07-03 23:02:09 +02:00
|
|
|
gtk_widget_show_all(addrbook.window);
|
2005-08-02 19:11:21 +02:00
|
|
|
addressbook_show_buttons(target == NULL, lastCanLookup, target != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
addressbook_set_target_compose(target);
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Destroy addressbook.
|
|
|
|
*/
|
|
|
|
void addressbook_destroy( void ) {
|
2002-03-16 07:10:46 +01:00
|
|
|
/* Free up address stuff */
|
|
|
|
if( _addressSelect_ != NULL ) {
|
|
|
|
addrselect_list_free( _addressSelect_ );
|
|
|
|
}
|
|
|
|
if( _clipBoard_ != NULL ) {
|
|
|
|
addrclip_free( _clipBoard_ );
|
|
|
|
}
|
|
|
|
if( _addressIndex_ != NULL ) {
|
2003-06-21 08:23:00 +02:00
|
|
|
addrindex_free_index( _addressIndex_ );
|
2004-01-12 22:28:31 +01:00
|
|
|
addrindex_teardown();
|
2002-03-16 07:10:46 +01:00
|
|
|
}
|
|
|
|
_addressSelect_ = NULL;
|
|
|
|
_clipBoard_ = NULL;
|
|
|
|
_addressIndex_ = NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Refresh addressbook and save to file(s).
|
|
|
|
*/
|
|
|
|
void addressbook_refresh( void )
|
2001-09-13 15:38:32 +02:00
|
|
|
{
|
|
|
|
if (addrbook.window) {
|
|
|
|
if (addrbook.treeSelected) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
|
2001-09-13 15:38:32 +02:00
|
|
|
addrbook.treeSelected);
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.treeSelected),
|
|
|
|
TRUE);
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
addressbook_export_to_file();
|
|
|
|
}
|
|
|
|
|
2005-08-23 11:45:25 +02:00
|
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|
|
|
{
|
|
|
|
if (event && event->keyval == GDK_Escape)
|
|
|
|
addressbook_close();
|
|
|
|
else if (event && event->keyval == GDK_Delete)
|
|
|
|
addressbook_del_clicked(NULL, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-16 14:23:20 +02:00
|
|
|
/*!
|
|
|
|
*\brief Save Gtk object size to prefs dataset
|
|
|
|
*/
|
|
|
|
static void addressbook_size_allocate_cb(GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
g_return_if_fail(allocation != NULL);
|
|
|
|
|
|
|
|
prefs_common.addressbookwin_width = allocation->width;
|
|
|
|
prefs_common.addressbookwin_height = allocation->height;
|
|
|
|
}
|
|
|
|
|
2006-03-19 11:31:30 +01:00
|
|
|
static gint sort_column_number = 0;
|
2006-03-19 11:37:21 +01:00
|
|
|
static GtkSortType sort_column_type = GTK_SORT_ASCENDING;
|
2006-03-19 11:31:30 +01:00
|
|
|
|
2006-03-19 11:20:05 +01:00
|
|
|
static gint list_case_sort(
|
|
|
|
GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
|
|
|
|
{
|
2006-03-19 11:31:30 +01:00
|
|
|
GtkCListRow *row1 = (GtkCListRow *) ptr1;
|
|
|
|
GtkCListRow *row2 = (GtkCListRow *) ptr2;
|
2006-03-19 11:20:05 +01:00
|
|
|
gchar *name1 = NULL, *name2 = NULL;
|
2006-03-19 11:31:30 +01:00
|
|
|
AddrItemObject *aio1 = ((GtkCListRow *)ptr1)->data;
|
|
|
|
AddrItemObject *aio2 = ((GtkCListRow *)ptr2)->data;
|
|
|
|
|
|
|
|
if( aio1->type == aio2->type ) {
|
|
|
|
if( row1 )
|
|
|
|
name1 = GTK_CELL_TEXT (row1->cell[sort_column_number])->text;
|
|
|
|
if( row2 )
|
|
|
|
name2 = GTK_CELL_TEXT (row2->cell[sort_column_number])->text;
|
|
|
|
if( ! name1 ) return ( name2 != NULL );
|
|
|
|
if( ! name2 ) return -1;
|
|
|
|
return strcasecmp( name1, name2 );
|
|
|
|
} else {
|
|
|
|
/* Order groups before person */
|
|
|
|
if( aio1->type == ITEMTYPE_GROUP ) {
|
2006-03-19 11:37:21 +01:00
|
|
|
return (sort_column_type==GTK_SORT_ASCENDING) ? -1:+1;
|
2006-03-19 11:31:30 +01:00
|
|
|
} else if( aio2->type == ITEMTYPE_GROUP ) {
|
2006-03-19 11:37:21 +01:00
|
|
|
return (sort_column_type==GTK_SORT_ASCENDING) ? +1:-1;
|
2006-03-19 11:31:30 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-19 11:20:05 +01:00
|
|
|
}
|
|
|
|
|
2006-03-19 09:06:08 +01:00
|
|
|
static void addressbook_sort_list(GtkCList *clist, const gint col,
|
|
|
|
const GtkSortType sort_type)
|
|
|
|
{
|
|
|
|
gint pos;
|
|
|
|
GtkWidget *hbox, *label, *arrow;
|
|
|
|
|
2006-03-19 11:31:30 +01:00
|
|
|
sort_column_number = col;
|
2006-03-19 11:37:21 +01:00
|
|
|
sort_column_type = sort_type;
|
2006-03-19 11:20:05 +01:00
|
|
|
gtk_clist_set_compare_func(clist, list_case_sort);
|
2006-03-19 09:06:08 +01:00
|
|
|
gtk_clist_set_sort_type(clist, sort_type);
|
|
|
|
gtk_clist_set_sort_column(clist, col);
|
|
|
|
|
|
|
|
gtk_clist_freeze(clist);
|
|
|
|
gtk_clist_sort(clist);
|
|
|
|
|
|
|
|
for(pos = 0 ; pos < N_LIST_COLS ; pos++) {
|
|
|
|
hbox = gtk_hbox_new(FALSE, 4);
|
2006-04-05 18:45:55 +02:00
|
|
|
label = gtk_label_new(gettext(list_titles[pos]));
|
2006-03-19 09:06:08 +01:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
if(pos == col) {
|
|
|
|
arrow = gtk_arrow_new(sort_type == GTK_SORT_ASCENDING ?
|
|
|
|
GTK_ARROW_DOWN : GTK_ARROW_UP, GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), arrow, FALSE, FALSE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show_all(hbox);
|
|
|
|
gtk_clist_set_column_widget(clist, pos, hbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_clist_thaw(clist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_name_clicked(GtkWidget *button, GtkCList *clist)
|
|
|
|
{
|
|
|
|
static GtkSortType sort_type = GTK_SORT_ASCENDING;
|
|
|
|
|
|
|
|
sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
|
|
|
|
GTK_SORT_ASCENDING;
|
|
|
|
addressbook_sort_list(clist, COL_NAME, sort_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_address_clicked(GtkWidget *button, GtkCList *clist)
|
|
|
|
{
|
|
|
|
static GtkSortType sort_type = GTK_SORT_ASCENDING;
|
|
|
|
|
|
|
|
sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
|
|
|
|
GTK_SORT_ASCENDING;
|
|
|
|
addressbook_sort_list(clist, COL_ADDRESS, sort_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_remarks_clicked(GtkWidget *button, GtkCList *clist)
|
|
|
|
{
|
|
|
|
static GtkSortType sort_type = GTK_SORT_ASCENDING;
|
|
|
|
|
|
|
|
sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
|
|
|
|
GTK_SORT_ASCENDING;
|
|
|
|
addressbook_sort_list(clist, COL_REMARKS, sort_type);
|
|
|
|
}
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
2001-07-03 00:44:09 +02:00
|
|
|
GtkWidget *statusbar;
|
2001-04-19 14:21:46 +02:00
|
|
|
GtkWidget *hbbox;
|
2001-07-03 00:44:09 +02:00
|
|
|
GtkWidget *hsbox;
|
2001-04-19 14:21:46 +02:00
|
|
|
GtkWidget *del_btn;
|
2005-08-17 11:29:17 +02:00
|
|
|
GtkWidget *edit_btn;
|
2001-04-19 14:21:46 +02:00
|
|
|
GtkWidget *reg_btn;
|
|
|
|
GtkWidget *lup_btn;
|
|
|
|
GtkWidget *to_btn;
|
|
|
|
GtkWidget *cc_btn;
|
|
|
|
GtkWidget *bcc_btn;
|
2005-08-03 20:24:13 +02:00
|
|
|
GtkWidget *close_btn;
|
2001-04-19 14:21:46 +02:00
|
|
|
GtkWidget *tree_popup;
|
|
|
|
GtkWidget *list_popup;
|
|
|
|
GtkItemFactory *tree_factory;
|
|
|
|
GtkItemFactory *list_factory;
|
2001-07-03 00:44:09 +02:00
|
|
|
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
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
gchar *index_titles[N_INDEX_COLS];
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar *text;
|
|
|
|
gint i;
|
|
|
|
|
2005-10-16 14:23:20 +02:00
|
|
|
static GdkGeometry geometry;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
debug_print("Creating addressbook window...\n");
|
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
index_titles[COL_SOURCES] = _("Sources");
|
2002-02-08 11:07:11 +01:00
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
/* Address book window */
|
2001-04-19 14:21:46 +02:00
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window), _("Address book"));
|
2004-07-28 09:57:21 +02:00
|
|
|
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_widget_realize(window);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(window), "delete_event",
|
|
|
|
G_CALLBACK(addressbook_close), NULL);
|
2005-10-16 14:23:20 +02:00
|
|
|
g_signal_connect(G_OBJECT(window), "size_allocate",
|
|
|
|
G_CALLBACK(addressbook_size_allocate_cb), NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(window), "key_press_event",
|
|
|
|
G_CALLBACK(key_pressed), NULL);
|
2002-02-23 11:52:54 +01:00
|
|
|
MANAGE_WINDOW_SIGNALS_CONNECT(window);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
/* Menu bar */
|
2001-04-19 14:21:46 +02:00
|
|
|
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);
|
2001-07-03 00:44:09 +02:00
|
|
|
menu_factory = gtk_item_factory_from_widget(menubar);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
vbox2 = gtk_vbox_new(FALSE, BORDER_WIDTH);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
|
2001-04-19 14:21:46 +02:00
|
|
|
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,
|
2004-08-03 10:46:10 +02:00
|
|
|
GTK_POLICY_AUTOMATIC);
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_widget_set_size_request(ctree_swin, COL_FOLDER_WIDTH + 40, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-09-13 15:38:32 +02:00
|
|
|
/* Address index */
|
2005-09-14 09:47:38 +02:00
|
|
|
ctree = gtk_sctree_new_with_titles(N_INDEX_COLS, 0, index_titles);
|
2001-04-19 14:21:46 +02:00
|
|
|
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),
|
2002-01-19 07:25:11 +01:00
|
|
|
addressbook_treenode_compare_func);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(ctree), "tree_select_row",
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "button_press_event",
|
|
|
|
G_CALLBACK(addressbook_tree_button_pressed),
|
|
|
|
NULL);
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "button_release_event",
|
|
|
|
G_CALLBACK(addressbook_tree_button_released),
|
|
|
|
NULL);
|
2004-05-10 12:22:28 +02:00
|
|
|
/* TEMPORARY */
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "select_row",
|
|
|
|
G_CALLBACK(addressbook_select_row_tree), NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL & ~GTK_DEST_DEFAULT_HIGHLIGHT,
|
|
|
|
addressbook_drag_types, 1,
|
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_DEFAULT);
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "drag_motion",
|
|
|
|
G_CALLBACK(addressbook_drag_motion_cb),
|
|
|
|
ctree);
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "drag_leave",
|
|
|
|
G_CALLBACK(addressbook_drag_leave_cb),
|
|
|
|
ctree);
|
|
|
|
g_signal_connect(G_OBJECT(ctree), "drag_data_received",
|
|
|
|
G_CALLBACK(addressbook_drag_received_cb),
|
|
|
|
ctree);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
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,
|
2004-08-03 10:46:10 +02:00
|
|
|
GTK_POLICY_AUTOMATIC);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(clist_vbox), clist_swin, TRUE, TRUE, 0);
|
|
|
|
|
2001-09-13 15:38:32 +02:00
|
|
|
/* Address list */
|
2005-09-14 09:47:38 +02:00
|
|
|
clist = gtk_sctree_new_with_titles(N_LIST_COLS, 0, list_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);
|
|
|
|
|
2006-03-26 21:36:04 +02:00
|
|
|
addressbook_sort_list(GTK_CLIST(clist), COL_NAME, GTK_SORT_ASCENDING);
|
2006-03-19 09:06:08 +01:00
|
|
|
g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_NAME].button),
|
|
|
|
"clicked", G_CALLBACK(addressbook_name_clicked), clist);
|
|
|
|
g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_ADDRESS].button),
|
|
|
|
"clicked", G_CALLBACK(addressbook_address_clicked), clist);
|
|
|
|
g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_REMARKS].button),
|
|
|
|
"clicked", G_CALLBACK(addressbook_remarks_clicked), clist);
|
|
|
|
|
2005-09-14 09:47:38 +02:00
|
|
|
for (i = 0; i < N_LIST_COLS; i++)
|
2001-04-19 14:21:46 +02:00
|
|
|
GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
|
|
|
|
GTK_CAN_FOCUS);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(clist), "tree_select_row",
|
|
|
|
G_CALLBACK(addressbook_list_row_selected), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(clist), "tree_unselect_row",
|
|
|
|
G_CALLBACK(addressbook_list_row_unselected), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(clist), "button_press_event",
|
|
|
|
G_CALLBACK(addressbook_list_button_pressed),
|
|
|
|
NULL);
|
|
|
|
g_signal_connect(G_OBJECT(clist), "button_release_event",
|
|
|
|
G_CALLBACK(addressbook_list_button_released),
|
|
|
|
NULL);
|
|
|
|
g_signal_connect(G_OBJECT(clist), "tree_expand",
|
|
|
|
G_CALLBACK(addressbook_person_expand_node), NULL );
|
|
|
|
g_signal_connect(G_OBJECT(clist), "tree_collapse",
|
|
|
|
G_CALLBACK(addressbook_person_collapse_node), NULL );
|
2004-09-06 11:53:05 +02:00
|
|
|
g_signal_connect(G_OBJECT(clist), "start_drag",
|
|
|
|
G_CALLBACK(addressbook_start_drag), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(clist), "drag_data_get",
|
|
|
|
G_CALLBACK(addressbook_drag_data_get), 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);
|
|
|
|
|
2005-08-02 19:11:21 +02:00
|
|
|
label = gtk_label_new(_("Lookup name:"));
|
2001-04-19 14:21:46 +02:00
|
|
|
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));
|
|
|
|
|
2005-08-23 11:45:25 +02:00
|
|
|
g_signal_connect(G_OBJECT(entry), "key_press_event",
|
|
|
|
G_CALLBACK(addressbook_entry_key_pressed),
|
|
|
|
NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
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 */
|
2001-07-03 00:44:09 +02:00
|
|
|
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);
|
2005-08-02 19:11:21 +02:00
|
|
|
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 2);
|
2005-10-16 12:40:11 +02:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(hbbox), 4);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
|
|
|
|
|
2005-08-17 16:08:29 +02:00
|
|
|
#if GTK_CHECK_VERSION(2, 6, 0)
|
2005-08-17 11:29:17 +02:00
|
|
|
edit_btn = gtk_button_new_from_stock(GTK_STOCK_EDIT);
|
2005-08-17 16:08:29 +02:00
|
|
|
#else
|
|
|
|
edit_btn = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES);
|
|
|
|
#endif
|
2005-08-17 11:29:17 +02:00
|
|
|
GTK_WIDGET_SET_FLAGS(edit_btn, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), edit_btn, TRUE, TRUE, 0);
|
2005-08-03 20:24:13 +02:00
|
|
|
del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
|
2001-04-19 14:21:46 +02:00
|
|
|
GTK_WIDGET_SET_FLAGS(del_btn, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), del_btn, TRUE, TRUE, 0);
|
2005-08-03 20:24:13 +02:00
|
|
|
reg_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
|
2001-04-19 14:21:46 +02:00
|
|
|
GTK_WIDGET_SET_FLAGS(reg_btn, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), reg_btn, TRUE, TRUE, 0);
|
2005-08-03 20:24:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
lup_btn = gtk_button_new_from_stock(GTK_STOCK_FIND);
|
2001-04-19 14:21:46 +02:00
|
|
|
GTK_WIDGET_SET_FLAGS(lup_btn, GTK_CAN_DEFAULT);
|
2005-08-02 19:11:21 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), lup_btn, TRUE, TRUE, 0);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-08-17 11:29:17 +02:00
|
|
|
g_signal_connect(G_OBJECT(edit_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_edit_clicked), NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(del_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_del_clicked), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(reg_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_reg_clicked), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(lup_btn), "clicked",
|
|
|
|
G_CALLBACK(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);
|
|
|
|
|
2005-08-03 20:24:13 +02:00
|
|
|
close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
|
|
|
|
GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), close_btn, TRUE, TRUE, 0);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(to_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_to_clicked),
|
|
|
|
GINT_TO_POINTER(COMPOSE_TO));
|
|
|
|
g_signal_connect(G_OBJECT(cc_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_to_clicked),
|
|
|
|
GINT_TO_POINTER(COMPOSE_CC));
|
|
|
|
g_signal_connect(G_OBJECT(bcc_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_to_clicked),
|
|
|
|
GINT_TO_POINTER(COMPOSE_BCC));
|
2005-08-03 20:24:13 +02:00
|
|
|
g_signal_connect(G_OBJECT(close_btn), "clicked",
|
|
|
|
G_CALLBACK(addressbook_close_clicked), NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
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();
|
|
|
|
|
2006-01-09 19:17:30 +01:00
|
|
|
addrbook.clist = NULL;
|
|
|
|
|
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 =
|
2005-10-18 19:15:44 +02:00
|
|
|
gtk_sctree_insert_node( GTK_CTREE(ctree),
|
2001-09-02 03:09:09 +02:00
|
|
|
NULL, NULL, &text, FOLDER_SPACING,
|
|
|
|
interfacexpm, interfacexpmmask,
|
|
|
|
interfacexpm, interfacexpmmask,
|
|
|
|
FALSE, FALSE );
|
|
|
|
menu_set_sensitive( menu_factory, atci->menuCommand, adapter->haveLibrary );
|
2002-01-19 07:25:11 +01:00
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
2001-07-03 00:44:09 +02:00
|
|
|
addrbook.window = window;
|
|
|
|
addrbook.menubar = menubar;
|
|
|
|
addrbook.ctree = ctree;
|
2004-09-06 11:53:05 +02:00
|
|
|
addrbook.ctree_swin
|
|
|
|
= ctree_swin;
|
2001-07-03 00:44:09 +02:00
|
|
|
addrbook.clist = clist;
|
2005-08-02 19:11:21 +02:00
|
|
|
addrbook.label = label;
|
2001-07-03 00:44:09 +02:00
|
|
|
addrbook.entry = entry;
|
|
|
|
addrbook.statusbar = statusbar;
|
2002-01-19 07:25:11 +01:00
|
|
|
addrbook.status_cid = gtk_statusbar_get_context_id(
|
|
|
|
GTK_STATUSBAR(statusbar), "Addressbook Window" );
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-08-17 11:29:17 +02:00
|
|
|
addrbook.edit_btn = edit_btn;
|
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;
|
2001-07-03 00:44:09 +02:00
|
|
|
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);
|
2005-10-16 14:23:20 +02:00
|
|
|
|
|
|
|
if (!geometry.min_height) {
|
|
|
|
geometry.min_width = ADDRESSBOOK_WIDTH;
|
|
|
|
geometry.min_height = ADDRESSBOOK_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
|
|
|
|
GDK_HINT_MIN_SIZE);
|
|
|
|
gtk_widget_set_size_request(window, prefs_common.addressbookwin_width,
|
|
|
|
prefs_common.addressbookwin_height);
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_widget_show_all(window);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Close address book window and save to file(s).
|
|
|
|
*/
|
2002-05-06 08:27:11 +02:00
|
|
|
static gint addressbook_close( void ) {
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_widget_hide(addrbook.window);
|
|
|
|
addressbook_export_to_file();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Display message in status line.
|
|
|
|
* \param msg Message to display.
|
|
|
|
*/
|
2001-07-03 00:44:09 +02:00
|
|
|
static void addressbook_status_show( gchar *msg ) {
|
|
|
|
if( addrbook.statusbar != NULL ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
gtk_statusbar_pop(
|
|
|
|
GTK_STATUSBAR(addrbook.statusbar),
|
|
|
|
addrbook.status_cid );
|
2001-07-03 00:44:09 +02:00
|
|
|
if( msg ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
gtk_statusbar_push(
|
|
|
|
GTK_STATUSBAR(addrbook.statusbar),
|
|
|
|
addrbook.status_cid, msg );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_ds_status_message( AddressDataSource *ds, gchar *msg ) {
|
|
|
|
*addressbook_msgbuf = '\0';
|
|
|
|
if( ds ) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = addrindex_ds_get_name( ds );
|
2002-07-13 13:20:49 +02:00
|
|
|
g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf),
|
|
|
|
"%s: %s", name, msg );
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
else {
|
2002-07-13 13:20:49 +02:00
|
|
|
g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf),
|
|
|
|
"%s", msg );
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
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;
|
2003-01-26 06:12:00 +01:00
|
|
|
gchar *desc;
|
2001-09-02 01:48:06 +02:00
|
|
|
*addressbook_msgbuf = '\0';
|
|
|
|
if( ds ) {
|
|
|
|
name = addrindex_ds_get_name( ds );
|
|
|
|
retVal = addrindex_ds_get_status_code( ds );
|
|
|
|
if( retVal == MGU_SUCCESS ) {
|
2002-07-13 13:20:49 +02:00
|
|
|
g_snprintf( addressbook_msgbuf,
|
|
|
|
sizeof(addressbook_msgbuf), "%s", name );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2003-01-26 06:12:00 +01:00
|
|
|
desc = addressbook_err2string( _lutErrorsGeneral_, retVal );
|
2002-07-13 13:20:49 +02:00
|
|
|
g_snprintf( addressbook_msgbuf,
|
2003-01-26 06:12:00 +01:00
|
|
|
sizeof(addressbook_msgbuf), "%s: %s", name, desc );
|
2003-02-16 21:58:50 +01:00
|
|
|
}
|
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;
|
2002-01-20 17:19:37 +01:00
|
|
|
#ifndef CLAWS
|
2001-04-19 14:21:46 +02:00
|
|
|
if (addrbook.target_compose->use_bcc)
|
2002-01-20 17:19:37 +01:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2005-08-17 11:29:17 +02:00
|
|
|
static void addressbook_edit_clicked(GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
addressbook_edit_address_cb(NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
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);
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
2002-01-19 07:25:11 +01:00
|
|
|
AddressInterface *iface;
|
|
|
|
AddrItemObject *aio;
|
|
|
|
AddrSelectItem *item;
|
|
|
|
GList *list, *node;
|
2003-02-16 21:58:50 +01:00
|
|
|
gboolean refreshList = FALSE;
|
|
|
|
|
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);
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
/* Test whether anything selected for deletion */
|
2001-09-02 01:48:06 +02:00
|
|
|
nodeList = addrbook.listSelected;
|
2005-08-23 14:20:48 +02:00
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
/* Test for read only */
|
|
|
|
iface = ds->interface;
|
|
|
|
if( iface->readOnly ) {
|
2002-05-06 08:27:11 +02:00
|
|
|
alertpanel( _("Delete address(es)"),
|
2002-01-19 07:25:11 +01:00
|
|
|
_("This address data is readonly and cannot be deleted."),
|
2005-01-29 17:53:23 +01:00
|
|
|
GTK_STOCK_CLOSE, NULL, NULL );
|
2002-01-19 07:25:11 +01:00
|
|
|
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)?"),
|
2006-01-15 20:15:59 +01:00
|
|
|
GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
|
2006-01-14 10:45:39 +01:00
|
|
|
if( aval != G_ALERTALTERNATE ) 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 */
|
2002-01-19 07:25:11 +01:00
|
|
|
list = addrselect_get_list( _addressSelect_ );
|
2005-08-23 14:20:48 +02:00
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
node = list;
|
2001-09-02 01:48:06 +02:00
|
|
|
while( node ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
item = node->data;
|
2001-09-02 01:48:06 +02:00
|
|
|
node = g_list_next( node );
|
2002-01-19 07:25:11 +01:00
|
|
|
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 );
|
2003-02-16 21:58:50 +01:00
|
|
|
refreshList = TRUE;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
else if( aio->type == ADDR_ITEM_PERSON ) {
|
|
|
|
ItemPerson *item = ( ItemPerson * ) aio;
|
2003-02-16 21:58:50 +01:00
|
|
|
addressbook_folder_remove_one_person( clist, item );
|
2005-07-15 18:39:12 +02:00
|
|
|
if (pobj->type == ADDR_ITEM_FOLDER)
|
2005-08-02 19:11:21 +02:00
|
|
|
addritem_folder_remove_person(ADAPTER_FOLDER(pobj)->itemFolder, item);
|
2001-09-02 01:48:06 +02:00
|
|
|
item = addrbook_remove_person( abf, item );
|
|
|
|
if( item ) {
|
|
|
|
addritem_free_item_person( item );
|
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
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 );
|
|
|
|
}
|
2003-02-16 21:58:50 +01:00
|
|
|
addressbook_folder_refresh_one_person( clist, person );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
g_list_free( list );
|
2001-09-02 01:48:06 +02:00
|
|
|
addressbook_list_select_clear();
|
2005-11-21 18:39:59 +01:00
|
|
|
if( refreshList ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
|
|
|
}
|
2005-07-15 18:39:12 +02:00
|
|
|
addrbook_set_dirty(abf, TRUE);
|
|
|
|
addressbook_export_to_file();
|
2005-09-19 19:53:13 +02:00
|
|
|
addressbook_list_menu_setup();
|
2001-09-02 01:48:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( pobj->type == ADDR_ITEM_GROUP ) {
|
2001-09-06 12:24:20 +02:00
|
|
|
/* Items inside groups */
|
2002-01-19 07:25:11 +01:00
|
|
|
list = addrselect_get_list( _addressSelect_ );
|
|
|
|
node = list;
|
2001-09-02 01:48:06 +02:00
|
|
|
while( node ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
item = node->data;
|
2001-09-02 01:48:06 +02:00
|
|
|
node = g_list_next( node );
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
g_list_free( list );
|
2001-09-02 01:48:06 +02:00
|
|
|
addressbook_list_select_clear();
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
|
|
|
|
2005-07-15 18:39:12 +02:00
|
|
|
addrbook_set_dirty(abf, TRUE);
|
|
|
|
addressbook_export_to_file();
|
2005-09-19 19:53:13 +02:00
|
|
|
addressbook_list_menu_setup();
|
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_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
|
|
|
|
2002-01-19 07:25:11 +01: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
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
if( aio->type == ADDR_ITEM_EMAIL ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
ItemPerson *person = NULL;
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2002-01-19 07:25:11 +01: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 ) {
|
2002-02-07 11:14:25 +01:00
|
|
|
if( name && name[0] != '\0' ) {
|
2003-06-21 08:23:00 +02:00
|
|
|
if( strchr_with_skip_quote( name, '"', ',' ) )
|
2002-02-06 11:17:44 +01:00
|
|
|
buf = g_strdup_printf( "\"%s\" <%s>", name, address );
|
|
|
|
else
|
|
|
|
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)
|
|
|
|
{
|
2002-01-19 07:25:11 +01:00
|
|
|
GList *list, *node;
|
|
|
|
Compose *compose;
|
|
|
|
AddrSelectItem *item;
|
|
|
|
AddrItemObject *aio;
|
2004-05-10 12:22:28 +02:00
|
|
|
gchar *addr;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
compose = addrbook.target_compose;
|
|
|
|
if( ! compose ) return;
|
|
|
|
|
2002-06-11 07:37:28 +02:00
|
|
|
/* Nothing selected, but maybe there is something in text entry */
|
2004-09-06 11:53:05 +02:00
|
|
|
addr = (char *)gtk_entry_get_text( GTK_ENTRY( addrbook.entry) );
|
2002-07-02 21:49:11 +02:00
|
|
|
if ( addr ) {
|
|
|
|
compose_entry_append(
|
|
|
|
compose, addr, (ComposeEntryType)data );
|
2002-06-11 07:37:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Select from address list */
|
2002-01-19 07:25:11 +01:00
|
|
|
list = addrselect_get_list( _addressSelect_ );
|
|
|
|
node = list;
|
2001-09-02 01:48:06 +02:00
|
|
|
while( node ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
item = node->data;
|
2001-09-02 01:48:06 +02:00
|
|
|
node = g_list_next( node );
|
2002-01-19 07:25:11 +01:00
|
|
|
aio = item->addressItem;
|
|
|
|
if( aio->type == ADDR_ITEM_PERSON ||
|
|
|
|
aio->type == ADDR_ITEM_EMAIL ) {
|
2004-05-10 12:22:28 +02:00
|
|
|
addr = addressbook_format_address( aio );
|
2002-01-19 07:25:11 +01:00
|
|
|
compose_entry_append(
|
2004-05-10 12:22:28 +02:00
|
|
|
compose, addr, (ComposeEntryType) data );
|
|
|
|
g_free( addr );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
else if( aio->type == ADDR_ITEM_GROUP ) {
|
|
|
|
ItemGroup *group = ( ItemGroup * ) aio;
|
2005-09-15 18:34:08 +02:00
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AddressBookFile *abf = NULL;
|
2001-09-02 01:48:06 +02:00
|
|
|
GList *nodeMail = group->listEMail;
|
2005-09-15 18:34:08 +02:00
|
|
|
if (nodeMail == NULL) {
|
|
|
|
if(addrbook.treeSelected ) {
|
|
|
|
ds = addressbook_find_datasource( addrbook.treeSelected );
|
|
|
|
abf = ds->rawDataSource;
|
|
|
|
if( abf != NULL )
|
|
|
|
nodeMail = addrbook_get_available_email_list( abf, group );
|
|
|
|
}
|
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
while( nodeMail ) {
|
|
|
|
ItemEMail *email = nodeMail->data;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
addr = addressbook_format_address(
|
2002-01-19 07:25:11 +01:00
|
|
|
( AddrItemObject * ) email );
|
|
|
|
compose_entry_append(
|
2004-05-10 12:22:28 +02:00
|
|
|
compose, addr, (ComposeEntryType) data );
|
|
|
|
g_free( addr );
|
2001-09-02 01:48:06 +02:00
|
|
|
nodeMail = g_list_next( nodeMail );
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
g_list_free( list );
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-07-03 00:44:09 +02:00
|
|
|
static void addressbook_menubar_set_sensitive( gboolean sensitive ) {
|
2005-08-23 14:20:48 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", sensitive );
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book", sensitive );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/New Folder", sensitive );
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Select all", TRUE );
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Cut", sensitive );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Copy", sensitive );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Paste", 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 );
|
2004-05-10 12:22:28 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Mail To", sensitive );
|
2001-07-03 00:44:09 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.reg_btn, sensitive );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.edit_btn, sensitive );
|
2001-07-03 00:44:09 +02:00
|
|
|
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;
|
2005-08-23 14:20:48 +02:00
|
|
|
gboolean canDelete = TRUE;
|
2001-09-02 01:48:06 +02:00
|
|
|
gboolean canAdd = FALSE;
|
|
|
|
gboolean canEditTr = TRUE;
|
|
|
|
gboolean editAddress = FALSE;
|
2002-05-06 08:27:11 +02:00
|
|
|
gboolean canExport = TRUE;
|
2001-09-02 01:48:06 +02:00
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
2002-05-06 08:27:11 +02:00
|
|
|
canEditTr = canExport = FALSE;
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
else if( obj->type == ADDR_DATASOURCE ) {
|
|
|
|
AdapterDSource *ads = ADAPTER_DSOURCE(obj);
|
|
|
|
ds = ads->dataSource;
|
|
|
|
iface = ds->interface;
|
|
|
|
if( ! iface->readOnly ) {
|
2005-08-23 14:20:48 +02:00
|
|
|
canAdd = canEdit = editAddress = canDelete = TRUE;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
if( ! iface->haveLibrary ) {
|
2005-08-23 14:20:48 +02:00
|
|
|
canAdd = canEdit = editAddress = canExport = canDelete = FALSE;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
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;
|
2002-01-19 07:25:11 +01:00
|
|
|
if( iface->readOnly ) {
|
|
|
|
canEditTr = FALSE;
|
2005-08-23 14:20:48 +02:00
|
|
|
canDelete = FALSE;
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
else {
|
2001-09-02 01:48:06 +02:00
|
|
|
canAdd = editAddress = TRUE;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 );
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/New Folder", canAdd );
|
2001-09-02 01:48:06 +02:00
|
|
|
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 );
|
2005-09-19 19:53:13 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canDelete );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
|
2005-08-23 14:20:48 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
|
2001-09-02 01:48:06 +02:00
|
|
|
|
2005-08-23 14:20:48 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", canEditTr );
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book", canEditTr );
|
2002-05-06 08:27:11 +02:00
|
|
|
|
|
|
|
/* Export data */
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Tools/Export HTML...", canExport );
|
2003-08-05 06:14:35 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Tools/Export LDIF...", canExport );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
|
2005-08-02 19:11:21 +02:00
|
|
|
static void addressbook_list_menu_setup( void );
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Address book tree callback function that responds to selection of tree
|
|
|
|
* items.
|
|
|
|
*
|
|
|
|
* \param ctree Tree widget.
|
|
|
|
* \param node Node that was selected.
|
|
|
|
* \param column Column number where selected occurred.
|
|
|
|
* \param data Pointer to user data.
|
|
|
|
*/
|
2005-10-16 14:33:48 +02:00
|
|
|
static void addressbook_tree_selected(GtkCTree *ctree, GtkCTreeNode *node,
|
2001-04-19 14:21:46 +02:00
|
|
|
gint column, gpointer data)
|
|
|
|
{
|
2001-09-02 01:48:06 +02:00
|
|
|
AddressObject *obj = NULL;
|
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
ItemFolder *rootFolder = NULL;
|
2003-09-07 21:28:56 +02:00
|
|
|
AddressObjectType aot;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
addrbook.treeSelected = node;
|
|
|
|
addrbook.listSelected = NULL;
|
2001-07-03 00:44:09 +02:00
|
|
|
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( node ) obj = gtk_ctree_node_get_row_data( ctree, node );
|
2005-10-16 14:55:18 +02:00
|
|
|
if( obj == NULL ) {
|
|
|
|
addressbook_set_clist(NULL, TRUE);
|
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
ads = ADAPTER_DSOURCE(obj);
|
2005-10-16 14:33:48 +02:00
|
|
|
if( ads == NULL ) return;
|
2001-09-02 01:48:06 +02:00
|
|
|
ds = ads->dataSource;
|
2005-10-16 14:33:48 +02:00
|
|
|
if( ds == NULL ) return;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
if( addrindex_ds_get_modify_flag( ds ) ) {
|
|
|
|
addrindex_ds_read_data( ds );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
|
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 ) {
|
2003-09-07 21:28:56 +02:00
|
|
|
aot = ADDR_CATEGORY;
|
|
|
|
}
|
|
|
|
else if( ds->type == ADDR_IF_LDAP ) {
|
|
|
|
aot = ADDR_LDAP_QUERY;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
else {
|
2003-09-07 21:28:56 +02:00
|
|
|
aot = ADDR_ITEM_FOLDER;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2003-09-07 21:28:56 +02:00
|
|
|
addressbook_node_add_folder( node, ds, rootFolder, aot );
|
2001-09-02 01:48:06 +02:00
|
|
|
addrindex_ds_set_access_flag( ds, &tVal );
|
|
|
|
gtk_ctree_expand( ctree, node );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2006-03-19 09:06:08 +01:00
|
|
|
} else {
|
|
|
|
addressbook_set_clist(NULL, TRUE);
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
|
2001-09-30 13:07:34 +02:00
|
|
|
/* Update address list */
|
2005-10-16 14:33:48 +02:00
|
|
|
g_signal_handlers_block_by_func
|
|
|
|
(G_OBJECT(ctree),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
2005-10-16 14:55:18 +02:00
|
|
|
addressbook_set_clist( obj, FALSE );
|
2005-10-16 14:33:48 +02:00
|
|
|
g_signal_handlers_unblock_by_func
|
|
|
|
(G_OBJECT(ctree),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2001-09-06 12:24:20 +02:00
|
|
|
/* Setup main menu selections */
|
2001-07-03 00:44:09 +02:00
|
|
|
addressbook_menubar_set_sensitive( FALSE );
|
2005-08-02 19:11:21 +02:00
|
|
|
addressbook_list_menu_setup();
|
2001-07-03 00:44:09 +02:00
|
|
|
addressbook_menuitem_set_sensitive( obj, node );
|
2001-09-02 01:48:06 +02:00
|
|
|
|
|
|
|
addressbook_list_select_clear();
|
2005-09-19 19:53:13 +02:00
|
|
|
addressbook_list_menu_setup();
|
2005-10-16 14:33:48 +02:00
|
|
|
return;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Setup address list popup menu items. Items are enabled or disabled as
|
|
|
|
* required.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
gboolean canBrowse = FALSE;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
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) );
|
2005-11-21 18:39:59 +01:00
|
|
|
menu_set_sensitive( addrbook.list_factory, "/Select all", TRUE );
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
if( pobj->type == ADDR_DATASOURCE ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Parent object is a data source */
|
2002-01-19 07:25:11 +01:00
|
|
|
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 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;
|
|
|
|
}
|
2005-08-23 14:20:48 +02:00
|
|
|
canDelete = canEdit;
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
else if( pobj->type != ADDR_INTERFACE ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Parent object is not an interface */
|
2002-01-19 07:25:11 +01:00
|
|
|
ds = addressbook_find_datasource( addrbook.treeSelected );
|
|
|
|
iface = ds->interface;
|
|
|
|
if( ! iface->readOnly ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Folder or group */
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Folder */
|
2002-01-19 07:25:11 +01:00
|
|
|
if( pobj->type == ADDR_ITEM_FOLDER ) {
|
|
|
|
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;
|
2005-08-23 14:20:48 +02:00
|
|
|
canDelete = canEdit;
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
if( iface->type == ADDR_IF_LDAP ) {
|
|
|
|
if( obj ) canBrowse = TRUE;
|
2005-08-23 14:20:48 +02:00
|
|
|
canEdit = TRUE;
|
|
|
|
canDelete = FALSE;
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
if( ! addrselect_test_empty( _addressSelect_ ) ) canCopy = TRUE;
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
/* Disable edit or browse if more than one row selected */
|
|
|
|
if( GTK_CLIST(clist)->selection && GTK_CLIST(clist)->selection->next ) {
|
|
|
|
canEdit = FALSE;
|
|
|
|
canBrowse = FALSE;
|
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Now go finalize menu items */
|
2002-01-19 07:25:11 +01:00
|
|
|
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 );
|
2005-08-02 19:11:21 +02:00
|
|
|
/* menu_set_sensitive( addrbook.list_factory, "/Paste Address", canPaste );*/
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
menu_set_sensitive( addrbook.list_factory, "/Mail To", canCopy );
|
|
|
|
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Cut", canCut );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Copy", canCopy );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Paste", canPaste );
|
|
|
|
/* menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );*/
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Cut", canCut );
|
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Copy", canCopy );
|
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Paste", canPaste );
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Edit", canEdit );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canDelete );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Mail To", canCopy );
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
|
2002-01-19 07:25:11 +01:00
|
|
|
gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
#ifdef USE_LDAP
|
2004-05-10 12:22:28 +02:00
|
|
|
menu_set_sensitive( addrbook.list_factory, "/Browse Entry", canBrowse );
|
2004-01-12 22:28:31 +01:00
|
|
|
#endif
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
static void addressbook_select_row_tree (GtkCTree *ctree,
|
|
|
|
GtkCTreeNode *node,
|
|
|
|
gint column,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
2002-01-19 07:25:11 +01:00
|
|
|
* Add list of items into tree node below specified tree node.
|
2004-01-12 22:28:31 +01:00
|
|
|
* \param treeNode Tree node.
|
|
|
|
* \param ds Data source.
|
|
|
|
* \param listItems List of items.
|
2002-01-19 07:25:11 +01:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
2002-01-19 07:25:11 +01: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
static void addressbook_select_all_cb( void ) {
|
|
|
|
gtk_clist_select_all(GTK_CLIST(addrbook.clist));
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Cut from address list widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_clip_cut_cb( void ) {
|
|
|
|
_clipBoard_->cutFlag = TRUE;
|
|
|
|
addrclip_clear( _clipBoard_ );
|
|
|
|
addrclip_add( _clipBoard_, _addressSelect_ );
|
|
|
|
/* addrclip_list_show( _clipBoard_, stdout ); */
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Copy from address list widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_clip_copy_cb( void ) {
|
|
|
|
_clipBoard_->cutFlag = FALSE;
|
|
|
|
addrclip_clear( _clipBoard_ );
|
|
|
|
addrclip_add( _clipBoard_, _addressSelect_ );
|
|
|
|
/* addrclip_list_show( _clipBoard_, stdout ); */
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Paste clipboard into address list widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
}
|
2002-01-19 07:25:11 +01: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 */
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Add current treenode object to clipboard. Note that widget only allows
|
|
|
|
* one entry from the tree list to be selected.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2002-01-19 07:25:11 +01: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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Cut from tree widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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 ); */
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Copy from tree widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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 ); */
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Paste clipboard into address tree widget.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_treenode_paste_cb( void ) {
|
|
|
|
addressbook_clip_paste_cb();
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Clear selected entries in clipboard.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_list_select_clear( void ) {
|
|
|
|
addrselect_list_clear( _addressSelect_ );
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
/**
|
|
|
|
* Add specified address item to selected address list.
|
|
|
|
* \param aio Address item object.
|
|
|
|
* \param ds Datasource.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
/**
|
|
|
|
* Remove specified address item from selected address list.
|
|
|
|
* \param aio Address item object.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_list_select_remove( AddrItemObject *aio ) {
|
|
|
|
addrselect_list_remove( _addressSelect_, aio );
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
/**
|
|
|
|
* Invoke EMail compose window with addresses in selected address list.
|
|
|
|
*/
|
|
|
|
static void addressbook_mail_to_cb( void ) {
|
|
|
|
GList *listAddress;
|
|
|
|
|
|
|
|
if( ! addrselect_test_empty( _addressSelect_ ) ) {
|
|
|
|
listAddress = addrselect_build_list( _addressSelect_ );
|
|
|
|
compose_new_with_list( NULL, listAddress );
|
|
|
|
mgu_free_dlist( listAddress );
|
|
|
|
listAddress = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
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);
|
2002-01-19 07:25:11 +01:00
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
aio = gtk_ctree_node_get_row_data( clist, node );
|
|
|
|
if( aio ) {
|
2005-08-02 19:11:21 +02:00
|
|
|
/* printf( "list select: %d : '%s'\n", aio->type, aio->name ); */
|
2002-01-19 07:25:11 +01:00
|
|
|
addressbook_list_select_add( aio, ds );
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
addressbook_list_menu_setup();
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
|
2002-01-19 07:25:11 +01: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
|
|
|
|
2002-01-19 07:25:11 +01: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
|
|
|
|
2004-09-28 10:25:18 +02:00
|
|
|
/* from gdkevents.c */
|
|
|
|
#define DOUBLE_CLICK_TIME 250
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_list_button_pressed(GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
2001-09-02 01:48:06 +02:00
|
|
|
{
|
2004-09-28 10:25:18 +02:00
|
|
|
static guint32 lasttime = 0;
|
2003-10-05 12:10:30 +02:00
|
|
|
if( ! event ) return FALSE;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
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 );
|
2004-09-28 10:25:18 +02:00
|
|
|
} else if (event->button == 1) {
|
|
|
|
if (event->time - lasttime < DOUBLE_CLICK_TIME) {
|
|
|
|
if (prefs_common.add_address_by_click &&
|
|
|
|
addrbook.target_compose)
|
|
|
|
addressbook_to_clicked(NULL, GINT_TO_POINTER(COMPOSE_TO));
|
|
|
|
else
|
|
|
|
addressbook_edit_address_cb(NULL, 0, NULL);
|
|
|
|
|
|
|
|
lasttime = 0;
|
|
|
|
} else
|
|
|
|
lasttime = event->time;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2004-09-28 10:25:18 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_list_button_released(GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-06-06 19:54:32 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
gboolean canDelete = FALSE;
|
2002-01-19 07:25:11 +01:00
|
|
|
gboolean canCut = FALSE;
|
|
|
|
gboolean canCopy = FALSE;
|
|
|
|
gboolean canPaste = FALSE;
|
|
|
|
gboolean canTreeCut = FALSE;
|
|
|
|
gboolean canTreeCopy = FALSE;
|
|
|
|
gboolean canTreePaste = FALSE;
|
2003-09-07 21:28:56 +02:00
|
|
|
gboolean canLookup = FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
if( ! event ) return FALSE;
|
2001-09-02 01:48:06 +02:00
|
|
|
addressbook_menubar_set_sensitive( FALSE );
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
if( gtk_clist_get_selection_info( clist, event->x, event->y, &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
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
menu_set_insensitive_all(GTK_MENU_SHELL(addrbook.tree_popup));
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
if( obj == NULL ) return FALSE;
|
2002-01-19 07:25:11 +01:00
|
|
|
|
|
|
|
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;
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!ds)
|
|
|
|
goto just_set_sens;
|
2001-09-02 01:48:06 +02:00
|
|
|
iface = ds->interface;
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!iface)
|
|
|
|
goto just_set_sens;
|
2001-09-02 01:48:06 +02:00
|
|
|
canEdit = TRUE;
|
2004-01-12 22:28:31 +01:00
|
|
|
canDelete = TRUE;
|
2002-01-19 07:25:11 +01:00
|
|
|
if( iface->readOnly ) {
|
|
|
|
canTreePaste = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2001-09-02 01:48:06 +02:00
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
|
2001-07-03 00:44:09 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
|
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
canTreeCopy = TRUE;
|
2003-09-07 21:28:56 +02:00
|
|
|
if( iface->externalQuery ) canLookup = TRUE;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
else if (obj->type == ADDR_ITEM_FOLDER) {
|
|
|
|
ds = addressbook_find_datasource( addrbook.treeSelected );
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!ds)
|
|
|
|
goto just_set_sens;
|
2001-09-02 01:48:06 +02:00
|
|
|
iface = ds->interface;
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!iface)
|
|
|
|
goto just_set_sens;
|
2002-01-19 07:25:11 +01:00
|
|
|
if( iface->readOnly ) {
|
|
|
|
canTreePaste = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2001-09-02 01:48:06 +02:00
|
|
|
canEdit = TRUE;
|
2004-01-12 22:28:31 +01:00
|
|
|
canDelete = TRUE;
|
2002-01-19 07:25:11 +01:00
|
|
|
canTreeCut = TRUE;
|
2001-09-02 01:48:06 +02:00
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
|
|
|
|
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
canTreeCopy = TRUE;
|
2005-11-23 19:26:57 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
if( iface->externalQuery ) {
|
|
|
|
/* Enable deletion of LDAP folder */
|
|
|
|
canLookup = TRUE;
|
|
|
|
canDelete = TRUE;
|
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
else if (obj->type == ADDR_ITEM_GROUP) {
|
|
|
|
ds = addressbook_find_datasource( addrbook.treeSelected );
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!ds)
|
|
|
|
goto just_set_sens;
|
2001-09-02 01:48:06 +02:00
|
|
|
iface = ds->interface;
|
2005-11-23 19:26:57 +01:00
|
|
|
if (!iface)
|
|
|
|
goto just_set_sens;
|
2001-09-02 01:48:06 +02:00
|
|
|
if( ! iface->readOnly ) {
|
|
|
|
canEdit = TRUE;
|
2004-01-12 22:28:31 +01:00
|
|
|
canDelete = TRUE;
|
2005-09-30 16:52:05 +02:00
|
|
|
menu_set_sensitive( addrbook.list_factory, "/New Address", TRUE );
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
|
2005-11-23 19:26:57 +01:00
|
|
|
just_set_sens:
|
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 );
|
2004-01-12 22:28:31 +01:00
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Delete", canDelete );
|
2002-01-19 07:25:11 +01:00
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Cut", canTreeCut );
|
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Copy", canTreeCopy );
|
|
|
|
menu_set_sensitive( addrbook.tree_factory, "/Paste", canTreePaste );
|
|
|
|
|
2005-08-23 14:20:48 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", canEdit );
|
2005-08-02 19:11:21 +02:00
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book", canEdit );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Cut", canCut );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Copy", canCopy );
|
|
|
|
menu_set_sensitive( addrbook.menu_factory, "/Address/Paste", canPaste );
|
|
|
|
/* menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );*/
|
2003-09-07 21:28:56 +02:00
|
|
|
|
2005-08-02 19:11:21 +02:00
|
|
|
addressbook_show_buttons(addrbook.target_compose == NULL, canLookup, addrbook.target_compose != NULL);
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean addressbook_tree_button_released(GtkWidget *ctree,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gtkut_ctree_set_focus_row(GTK_CTREE(addrbook.ctree), addrbook.opened);
|
2003-10-05 12:10:30 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
nn = addressbook_node_add_folder(
|
|
|
|
addrbook.treeSelected, ds, folder, ADDR_ITEM_FOLDER );
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_ctree_expand( ctree, addrbook.treeSelected );
|
2004-01-12 22:28:31 +01:00
|
|
|
if( addrbook.treeSelected == addrbook.opened )
|
2005-10-16 14:55:18 +02:00
|
|
|
addressbook_set_clist(obj, TRUE);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
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 );
|
2004-01-12 22:28:31 +01:00
|
|
|
if( addrbook.treeSelected == addrbook.opened )
|
2005-10-16 14:55:18 +02:00
|
|
|
addressbook_set_clist(obj, TRUE);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
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);
|
2005-10-18 19:15:44 +02:00
|
|
|
gtk_sctree_set_node_info(ctree, node, name, spacing,
|
2001-04-19 14:21:46 +02:00
|
|
|
pix_cl, mask_cl, pix_op, mask_op,
|
|
|
|
is_leaf, expanded);
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Edit data source.
|
|
|
|
* \param obj Address object to edit.
|
|
|
|
* \param node Node in tree.
|
|
|
|
* \return New name of data source.
|
|
|
|
*/
|
2001-09-02 01:48:06 +02:00
|
|
|
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 */
|
2002-03-16 07:10:46 +01: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 );
|
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;
|
2001-07-03 00:44:09 +02:00
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
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 );
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node(ctree, parentNode);
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_ctree_expand( ctree, node );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE( ctree), node );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
typedef enum {
|
|
|
|
ADDRTREE_DEL_NONE,
|
|
|
|
ADDRTREE_DEL_DATA,
|
|
|
|
ADDRTREE_DEL_FOLDER_ONLY,
|
|
|
|
ADDRTREE_DEL_FOLDER_ADDR
|
|
|
|
} TreeItemDelType ;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an item from the tree widget.
|
|
|
|
* \param data Data passed in.
|
|
|
|
* \param action Action.
|
|
|
|
* \param widget Widget issuing callback.
|
|
|
|
*/
|
|
|
|
static void addressbook_treenode_delete_cb(
|
|
|
|
gpointer data, guint action, GtkWidget *widget )
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
AddrBookBase *adbase;
|
|
|
|
AddressCache *cache;
|
2001-09-02 01:48:06 +02:00
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressInterface *iface = NULL;
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
gboolean remFlag = FALSE;
|
2004-01-12 22:28:31 +01:00
|
|
|
TreeItemDelType delType;
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
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
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Only allow deletion from non-readOnly */
|
2001-09-02 01:48:06 +02:00
|
|
|
iface = ds->interface;
|
2004-01-12 22:28:31 +01:00
|
|
|
if( iface->readOnly ) {
|
|
|
|
/* Allow deletion of query results */
|
|
|
|
if( ! iface->externalQuery ) return;
|
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-09-06 12:24:20 +02:00
|
|
|
/* Confirm deletion */
|
2004-01-12 22:28:31 +01:00
|
|
|
delType = ADDRTREE_DEL_NONE;
|
2001-09-02 01:48:06 +02:00
|
|
|
if( obj->type == ADDR_ITEM_FOLDER ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
if( iface->externalQuery ) {
|
|
|
|
message = g_strdup_printf( _(
|
|
|
|
"Do you want to delete the query " \
|
2005-07-17 09:30:07 +02:00
|
|
|
"results and addresses in '%s' ?" ),
|
2004-01-12 22:28:31 +01:00
|
|
|
obj->name );
|
|
|
|
aval = alertpanel( _("Delete"), message,
|
2006-01-15 20:15:59 +01:00
|
|
|
GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
|
2004-01-12 22:28:31 +01:00
|
|
|
g_free(message);
|
2006-01-14 10:45:39 +01:00
|
|
|
if( aval == G_ALERTALTERNATE ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
delType = ADDRTREE_DEL_FOLDER_ADDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2005-07-14 12:17:54 +02:00
|
|
|
message = g_strdup_printf
|
2006-01-14 15:25:48 +01:00
|
|
|
( _( "Do you want to delete '%s' ?"
|
|
|
|
"If you delete the folder only, the addresses it contains will be moved into the parent folder." ),
|
2005-07-14 12:17:54 +02:00
|
|
|
obj->name );
|
|
|
|
aval = alertpanel( _("Delete folder"), message,
|
2006-01-15 20:15:59 +01:00
|
|
|
GTK_STOCK_CANCEL, _("+Delete _folder only"), _("Delete folder and _addresses"));
|
2004-01-12 22:28:31 +01:00
|
|
|
g_free(message);
|
2006-01-14 15:25:48 +01:00
|
|
|
if( aval == G_ALERTALTERNATE ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
delType = ADDRTREE_DEL_FOLDER_ONLY;
|
|
|
|
}
|
2006-01-14 15:25:48 +01:00
|
|
|
else if( aval == G_ALERTOTHER ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
delType = ADDRTREE_DEL_FOLDER_ADDR;
|
|
|
|
}
|
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2006-01-14 15:25:48 +01:00
|
|
|
message = g_strdup_printf(_("Do you want to delete '%s'?\n"
|
|
|
|
"The addresses it contains will be lost."), obj->name);
|
2006-01-14 12:04:52 +01:00
|
|
|
aval = alertpanel(_("Delete"), message, GTK_STOCK_CANCEL,
|
2006-01-15 20:15:59 +01:00
|
|
|
"+" GTK_STOCK_DELETE, NULL);
|
2001-09-02 01:48:06 +02:00
|
|
|
g_free(message);
|
2006-01-14 10:45:39 +01:00
|
|
|
if( aval == G_ALERTALTERNATE ) delType = ADDRTREE_DEL_DATA;
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
if( delType == ADDRTREE_DEL_NONE ) 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 ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Remove node from tree */
|
|
|
|
gtk_ctree_remove_node( ctree, node );
|
|
|
|
|
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 ) ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
addrindex_free_datasource( ds );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
return;
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
/* Get reference to cache */
|
|
|
|
adbase = ( AddrBookBase * ) ds->rawDataSource;
|
|
|
|
if( adbase == NULL ) return;
|
|
|
|
cache = adbase->addressCache;
|
|
|
|
|
|
|
|
/* Remove query results folder */
|
|
|
|
if( iface->externalQuery ) {
|
|
|
|
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
|
|
|
|
ItemFolder *folder = adapter->itemFolder;
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
adapter->itemFolder = NULL;
|
|
|
|
/*
|
|
|
|
printf( "remove folder for ::%s::\n", obj->name );
|
|
|
|
printf( " folder name ::%s::\n", ADDRITEM_NAME(folder) );
|
|
|
|
printf( "-------------- remove results\n" );
|
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
addrindex_remove_results( ds, folder );
|
2004-05-10 12:22:28 +02:00
|
|
|
/* printf( "-------------- remove node\n" ); */
|
2004-01-12 22:28:31 +01:00
|
|
|
gtk_ctree_remove_node( ctree, node );
|
|
|
|
return;
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Code below is valid for regular address book deletion */
|
2001-09-02 01:48:06 +02:00
|
|
|
if( obj->type == ADDR_ITEM_FOLDER ) {
|
|
|
|
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
|
|
|
|
ItemFolder *item = adapter->itemFolder;
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
if( delType == ADDRTREE_DEL_FOLDER_ONLY ) {
|
2001-09-06 12:24:20 +02:00
|
|
|
/* Remove folder only */
|
2004-01-12 22:28:31 +01:00
|
|
|
item = addrcache_remove_folder( cache, item );
|
2001-09-02 01:48:06 +02:00
|
|
|
if( item ) {
|
|
|
|
addritem_free_item_folder( item );
|
|
|
|
addressbook_move_nodes_up( ctree, node );
|
|
|
|
remFlag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
else if( delType == ADDRTREE_DEL_FOLDER_ADDR ) {
|
2001-09-06 12:24:20 +02:00
|
|
|
/* Remove folder and addresses */
|
2004-01-12 22:28:31 +01:00
|
|
|
item = addrcache_remove_folder_delete( cache, item );
|
2001-09-02 01:48:06 +02:00
|
|
|
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
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
item = addrcache_remove_group( cache, item );
|
2001-09-02 01:48:06 +02:00
|
|
|
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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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 );
|
2003-02-16 21:58:50 +01:00
|
|
|
if( person && addrbook.treeSelected == addrbook.opened ) {
|
|
|
|
gtk_clist_unselect_all( GTK_CLIST(addrbook.clist) );
|
2004-01-12 22:28:31 +01:00
|
|
|
addressbook_folder_refresh_one_person(
|
|
|
|
GTK_CTREE(addrbook.clist), person );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Search for specified child group node in address index tree.
|
|
|
|
* \param parent Parent node.
|
|
|
|
* \param 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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
|
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
|
|
|
}
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_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);
|
2001-07-03 00:44:09 +02:00
|
|
|
GtkCTree *ctree;
|
2001-09-02 01:48:06 +02:00
|
|
|
AddressObject *obj = NULL, *pobj = NULL;
|
|
|
|
AddressDataSource *ds = NULL;
|
2001-07-03 00:44:09 +02:00
|
|
|
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();
|
2005-08-23 14:20:48 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
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;
|
2005-08-23 14:20:48 +02:00
|
|
|
if( abf == NULL ) return;
|
2001-09-02 01:48:06 +02:00
|
|
|
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 */
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
2003-02-16 21:58:50 +01:00
|
|
|
addressbook_folder_refresh_one_person( clist, person );
|
2003-05-02 15:20:50 +02:00
|
|
|
invalidate_address_completion();
|
2001-09-02 01:48:06 +02:00
|
|
|
return;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
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;
|
2003-05-02 15:20:50 +02:00
|
|
|
invalidate_address_completion();
|
2003-02-16 21:58:50 +01:00
|
|
|
addressbook_folder_refresh_one_person( clist, person );
|
2001-09-02 01:48:06 +02:00
|
|
|
return;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
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);
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2001-07-03 00:44:09 +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 );
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node( ctree, parentNode );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
|
2005-11-21 18:39:59 +01:00
|
|
|
addressbook_set_clist(
|
|
|
|
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
|
|
|
|
addrbook.opened),
|
|
|
|
TRUE);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_delete_address_cb(gpointer data, guint action,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
2005-11-21 18:39:59 +01:00
|
|
|
gtk_clist_freeze(GTK_CLIST(addrbook.clist));
|
2001-04-19 14:21:46 +02:00
|
|
|
addressbook_del_clicked(NULL, NULL);
|
2005-11-21 18:39:59 +01:00
|
|
|
gtk_clist_thaw(GTK_CLIST(addrbook.clist));
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
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;
|
2005-09-14 09:47:38 +02:00
|
|
|
gchar *text[N_LIST_COLS];
|
2001-09-02 01:48:06 +02:00
|
|
|
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;
|
2005-10-18 19:15:44 +02:00
|
|
|
nodeEMail = gtk_sctree_insert_node(
|
2001-09-02 01:48:06 +02:00
|
|
|
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
|
|
|
|
2003-06-21 08:23:00 +02:00
|
|
|
static void addressbook_folder_load_one_person(
|
|
|
|
GtkCTree *clist, ItemPerson *person,
|
|
|
|
AddressTypeControlItem *atci,
|
|
|
|
AddressTypeControlItem *atciMail )
|
|
|
|
{
|
2003-02-16 21:58:50 +01:00
|
|
|
GtkCTreeNode *nodePerson = NULL;
|
|
|
|
GtkCTreeNode *nodeEMail = NULL;
|
2005-09-14 09:47:38 +02:00
|
|
|
gchar *text[N_LIST_COLS];
|
2003-02-16 21:58:50 +01:00
|
|
|
gboolean flgFirst = TRUE, haveAddr = FALSE;
|
|
|
|
GList *node;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-02-16 21:58:50 +01:00
|
|
|
if( person == NULL ) return;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-02-16 21:58:50 +01:00
|
|
|
text[COL_NAME] = NULL;
|
|
|
|
node = person->listEMail;
|
|
|
|
while( node ) {
|
|
|
|
ItemEMail *email = node->data;
|
|
|
|
gchar *eMailAddr = NULL;
|
|
|
|
node = g_list_next( node );
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-02-16 21:58:50 +01:00
|
|
|
text[COL_ADDRESS] = email->address;
|
|
|
|
text[COL_REMARKS] = email->remarks;
|
|
|
|
eMailAddr = ADDRITEM_NAME(email);
|
|
|
|
if( eMailAddr && *eMailAddr == '\0' ) eMailAddr = NULL;
|
|
|
|
if( flgFirst ) {
|
|
|
|
/* First email belongs with person */
|
|
|
|
gchar *str = addressbook_format_item_clist( person, email );
|
|
|
|
if( str ) {
|
|
|
|
text[COL_NAME] = str;
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2003-02-16 21:58:50 +01:00
|
|
|
text[COL_NAME] = ADDRITEM_NAME(person);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2005-10-18 19:15:44 +02:00
|
|
|
nodePerson = gtk_sctree_insert_node(
|
2001-09-02 01:48:06 +02:00
|
|
|
clist, NULL, NULL,
|
|
|
|
text, FOLDER_SPACING,
|
|
|
|
atci->iconXpm, atci->maskXpm,
|
|
|
|
atci->iconXpmOpen, atci->maskXpmOpen,
|
|
|
|
FALSE, person->isOpened );
|
2003-02-16 21:58:50 +01:00
|
|
|
g_free( str );
|
|
|
|
str = NULL;
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_ctree_node_set_row_data(clist, nodePerson, person );
|
|
|
|
}
|
2003-02-16 21:58:50 +01:00
|
|
|
else {
|
|
|
|
/* Subsequent email is a child node of person */
|
|
|
|
text[COL_NAME] = ADDRITEM_NAME(email);
|
2005-10-18 19:15:44 +02:00
|
|
|
nodeEMail = gtk_sctree_insert_node(
|
2003-02-16 21:58:50 +01:00
|
|
|
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 ) {
|
|
|
|
/* Have name without EMail */
|
|
|
|
text[COL_NAME] = ADDRITEM_NAME(person);
|
|
|
|
text[COL_ADDRESS] = NULL;
|
|
|
|
text[COL_REMARKS] = NULL;
|
2005-10-18 19:15:44 +02:00
|
|
|
nodePerson = gtk_sctree_insert_node(
|
2003-02-16 21:58:50 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Load email addresses */
|
|
|
|
items = addritem_folder_get_person_list( itemFolder );
|
|
|
|
for( ; items != NULL; items = g_list_next( items ) ) {
|
|
|
|
addressbook_folder_load_one_person( clist, items->data, atci, atciMail );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
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 );
|
|
|
|
}
|
|
|
|
|
2003-02-16 21:58:50 +01:00
|
|
|
static void addressbook_folder_remove_node( GtkCTree *clist, GtkCTreeNode *node ) {
|
|
|
|
addrbook.listSelected = NULL;
|
|
|
|
gtk_ctree_remove_node( clist, node );
|
|
|
|
addressbook_menubar_set_sensitive( FALSE );
|
2003-06-21 08:23:00 +02:00
|
|
|
addressbook_menuitem_set_sensitive(
|
|
|
|
gtk_ctree_node_get_row_data(
|
|
|
|
GTK_CTREE(clist), addrbook.treeSelected ),
|
|
|
|
addrbook.treeSelected );
|
2003-02-16 21:58:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_folder_refresh_one_person( GtkCTree *clist, ItemPerson *person ) {
|
|
|
|
AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_PERSON );
|
|
|
|
AddressTypeControlItem *atciMail = addrbookctl_lookup( ADDR_ITEM_EMAIL );
|
|
|
|
GtkCTreeNode *node;
|
|
|
|
if( atci == NULL ) return;
|
|
|
|
if( atciMail == NULL ) return;
|
|
|
|
if( person == NULL ) return;
|
|
|
|
/* unload the person */
|
|
|
|
|
|
|
|
node = gtk_ctree_find_by_row_data( clist, NULL, person );
|
|
|
|
if( node )
|
|
|
|
addressbook_folder_remove_node( clist, node );
|
|
|
|
addressbook_folder_load_one_person( clist, person, atci, atciMail );
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_sort_node( clist, NULL );
|
2003-02-16 21:58:50 +01:00
|
|
|
node = gtk_ctree_find_by_row_data( clist, NULL, person );
|
|
|
|
if( node ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(clist), node );
|
2003-02-16 21:58:50 +01:00
|
|
|
if (!gtk_ctree_node_is_visible( clist, node ) )
|
|
|
|
gtk_ctree_node_moveto( clist, node, 0, 0, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_folder_remove_one_person( GtkCTree *clist, ItemPerson *person ) {
|
|
|
|
GtkCTreeNode *node;
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
if( person == NULL ) return;
|
|
|
|
node = gtk_ctree_find_by_row_data( clist, NULL, person );
|
|
|
|
row = gtk_clist_find_row_from_data( GTK_CLIST(clist), person );
|
|
|
|
if( node ) {
|
|
|
|
addressbook_folder_remove_node( clist, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
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;
|
2005-09-14 09:47:38 +02:00
|
|
|
gchar *text[N_LIST_COLS];
|
2001-09-02 01:48:06 +02:00
|
|
|
ItemGroup *group = items->data;
|
|
|
|
if( group == NULL ) continue;
|
|
|
|
text[COL_NAME] = ADDRITEM_NAME(group);
|
|
|
|
text[COL_ADDRESS] = NULL;
|
|
|
|
text[COL_REMARKS] = NULL;
|
2005-10-18 19:15:44 +02:00
|
|
|
nodeGroup = gtk_sctree_insert_node(clist, NULL, NULL,
|
2001-09-02 01:48:06 +02:00
|
|
|
text, FOLDER_SPACING,
|
|
|
|
atci->iconXpm, atci->maskXpm,
|
|
|
|
atci->iconXpmOpen, atci->maskXpmOpen,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gtk_ctree_node_set_row_data(clist, nodeGroup, group );
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node(clist, NULL);
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
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 );
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Search ctree widget callback function.
|
|
|
|
* \param pA Pointer to node.
|
|
|
|
* \param pB Pointer to data item being sought.
|
|
|
|
* \return Zero (0) if group found.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Search ctree widget callback function.
|
|
|
|
* \param pA Pointer to node.
|
|
|
|
* \param pB Pointer to data item being sought.
|
|
|
|
* \return Zero (0) if folder found.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Find parent datasource for specified tree node.
|
|
|
|
* \param 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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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);
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Load address list widget with children of specified object.
|
|
|
|
* \param obj Parent object to be loaded.
|
|
|
|
*/
|
2005-10-16 14:55:18 +02:00
|
|
|
static void addressbook_set_clist( AddressObject *obj, gboolean refresh ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
GtkCTree *ctreelist = GTK_CTREE(addrbook.clist);
|
|
|
|
GtkCList *clist = GTK_CLIST(addrbook.clist);
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AdapterDSource *ads = NULL;
|
2005-10-16 14:55:18 +02:00
|
|
|
static AddressObject *last_obj = NULL;
|
|
|
|
|
2006-01-09 19:17:30 +01:00
|
|
|
if (addrbook.clist == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2005-10-16 14:55:18 +02:00
|
|
|
if (obj == last_obj && !refresh)
|
|
|
|
return;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-10-16 14:55:18 +02:00
|
|
|
last_obj = obj;
|
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" ); */
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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 );
|
2003-06-21 08:23:00 +02:00
|
|
|
addressbook_folder_load_person(
|
|
|
|
ctreelist, addrindex_ds_get_root_folder( ds ) );
|
|
|
|
addressbook_folder_load_group(
|
|
|
|
ctreelist, addrindex_ds_get_root_folder( ds ) );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2005-06-30 18:45:18 +02:00
|
|
|
gtk_sctree_sort_node(GTK_CTREE(clist), NULL);
|
2001-09-02 01:48:06 +02:00
|
|
|
gtk_clist_thaw(clist);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01: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().
|
|
|
|
*
|
|
|
|
* \param data Tree node's row data.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
static void addressbook_free_treenode( gpointer data ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
AddressObject *ao;
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
/*
|
2002-01-19 07:25:11 +01: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-07-03 00:44:09 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
void addressbook_ads_set_name( AdapterDSource *adapter, gchar *value ) {
|
2003-06-21 08:23:00 +02:00
|
|
|
ADDRESS_OBJECT_NAME(adapter) =
|
|
|
|
mgu_replace_string( ADDRESS_OBJECT_NAME(adapter), value );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
|
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 );
|
2003-06-21 08:23:00 +02:00
|
|
|
ads = addressbook_create_ds_adapter(
|
|
|
|
ds, atci->objectType, name );
|
|
|
|
newNode = addressbook_add_object(
|
|
|
|
node, ADDRESS_OBJECT(ads) );
|
2001-09-02 03:09:09 +02:00
|
|
|
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"
|
2006-03-02 17:05:17 +01:00
|
|
|
"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"
|
2006-03-02 17:05:17 +01:00
|
|
|
"could not save new address index file." );
|
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 );
|
2005-07-17 14:14:10 +02:00
|
|
|
alertpanel_full(_("Addressbook conversion error"), msg,
|
|
|
|
GTK_STOCK_CLOSE, NULL, NULL, FALSE,
|
|
|
|
NULL, ALERT_ERROR, G_ALERTDEFAULT);
|
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 );
|
2005-07-17 14:14:10 +02:00
|
|
|
alertpanel_full(_("Addressbook conversion error"), msg,
|
|
|
|
GTK_STOCK_CLOSE, NULL, NULL, FALSE,
|
|
|
|
NULL, ALERT_WARNING, G_ALERTDEFAULT);
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-06 12:24:20 +02:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
return retVal;
|
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
|
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();
|
2004-01-12 22:28:31 +01:00
|
|
|
addrindex_initialize();
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
else if( addrIndex->retVal == MGU_SUCCESS ) {
|
|
|
|
_addressIndex_ = addrIndex;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
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 );
|
2005-07-17 14:14:10 +02:00
|
|
|
alertpanel_full(_("Addressbook Error"),
|
|
|
|
_("Could not read address index"),
|
|
|
|
GTK_STOCK_CLOSE, NULL, NULL, FALSE,
|
|
|
|
NULL, ALERT_ERROR, G_ALERTDEFAULT);
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
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;
|
2005-10-18 19:15:44 +02:00
|
|
|
added = gtk_sctree_insert_node( ctree, node, NULL, name, FOLDER_SPACING,
|
2001-09-02 01:48:06 +02:00
|
|
|
atci->iconXpm, atci->maskXpm, atci->iconXpmOpen, atci->maskXpmOpen,
|
|
|
|
atci->treeLeaf, atci->treeExpand );
|
2002-01-19 07:25:11 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node(ctree, node);
|
2001-09-02 01:48:06 +02:00
|
|
|
|
|
|
|
return added;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Add group into the address index tree.
|
|
|
|
* \param node Parent node.
|
|
|
|
* \param ds Data source.
|
|
|
|
* \param itemGroup Group to add.
|
|
|
|
* \return Inserted node.
|
|
|
|
*/
|
2003-09-07 21:28:56 +02:00
|
|
|
static GtkCTreeNode *addressbook_node_add_group(
|
|
|
|
GtkCTreeNode *node, AddressDataSource *ds,
|
|
|
|
ItemGroup *itemGroup )
|
|
|
|
{
|
2001-09-02 01:48:06 +02:00
|
|
|
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;
|
|
|
|
|
2005-10-18 19:15:44 +02:00
|
|
|
newNode = gtk_sctree_insert_node( ctree, node, NULL, name, FOLDER_SPACING,
|
2001-09-02 01:48:06 +02:00
|
|
|
atci->iconXpm, atci->maskXpm, atci->iconXpm, atci->maskXpm,
|
|
|
|
atci->treeLeaf, atci->treeExpand );
|
2002-01-19 07:25:11 +01:00
|
|
|
gtk_ctree_node_set_row_data_full( ctree, newNode, adapter,
|
|
|
|
addressbook_free_treenode );
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node( ctree, node );
|
2001-09-02 01:48:06 +02:00
|
|
|
return newNode;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Add folder into the address index tree. Only visible folders are loaded into
|
|
|
|
* the address index tree. Note that the root folder is not inserted into the
|
|
|
|
* tree.
|
|
|
|
*
|
|
|
|
* \param node Parent node.
|
|
|
|
* \param ds Data source.
|
|
|
|
* \param itemFolder Folder to add.
|
|
|
|
* \param otype Object type to display.
|
|
|
|
* \return Inserted node for the folder.
|
2001-09-02 01:48:06 +02:00
|
|
|
*/
|
|
|
|
static GtkCTreeNode *addressbook_node_add_folder(
|
2003-06-21 08:23:00 +02:00
|
|
|
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;
|
2003-09-07 21:28:56 +02:00
|
|
|
gchar *name;
|
2001-09-02 01:48:06 +02:00
|
|
|
ItemFolder *rootFolder;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/* Only visible folders */
|
|
|
|
if( itemFolder->isHidden ) return NULL;
|
|
|
|
|
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-07-03 00:44:09 +02:00
|
|
|
}
|
2001-09-02 01:48:06 +02:00
|
|
|
else {
|
|
|
|
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
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
name = ADDRITEM_NAME(itemFolder);
|
2005-10-18 19:15:44 +02:00
|
|
|
newNode = gtk_sctree_insert_node( ctree, node, NULL, &name, FOLDER_SPACING,
|
2001-09-02 01:48:06 +02:00
|
|
|
atci->iconXpm, atci->maskXpm, atci->iconXpm, atci->maskXpm,
|
|
|
|
atci->treeLeaf, atci->treeExpand );
|
2003-06-28 21:25:31 +02:00
|
|
|
if( newNode ) {
|
|
|
|
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 );
|
|
|
|
}
|
2002-07-09 11:57:45 +02:00
|
|
|
gtk_sctree_sort_node( ctree, node );
|
2001-09-02 01:48:06 +02:00
|
|
|
return newNode;
|
|
|
|
}
|
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 );
|
|
|
|
}
|
2003-05-02 15:20:50 +02:00
|
|
|
|
|
|
|
/* Notify address completion of new data */
|
|
|
|
invalidate_address_completion();
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2005-08-23 11:45:25 +02:00
|
|
|
static gboolean addressbook_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2005-08-23 11:45:25 +02:00
|
|
|
if (event && event->keyval == GDK_Return)
|
|
|
|
addressbook_lup_clicked(NULL, NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
/*
|
2002-01-19 07:25:11 +01:00
|
|
|
* Comparison using cell contents (text in first column). Used for sort
|
|
|
|
* address index widget.
|
2001-09-02 01:48:06 +02:00
|
|
|
*/
|
2002-01-19 07:25:11 +01: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;
|
2004-10-26 12:43:50 +02:00
|
|
|
return g_utf8_collate( name1, name2 );
|
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_new_book_cb( gpointer data, guint action, GtkWidget *widget ) {
|
|
|
|
AdapterDSource *ads;
|
|
|
|
AdapterInterface *adapter;
|
2002-01-19 07:25:11 +01:00
|
|
|
GtkCTreeNode *newNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
|
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
|
2002-01-19 07:25:11 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_new_vcard_cb( gpointer data, guint action, GtkWidget *widget ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
AdapterDSource *ads;
|
|
|
|
AdapterInterface *adapter;
|
2002-01-19 07:25:11 +01:00
|
|
|
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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
|
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
|
2002-01-19 07:25:11 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
2002-01-19 07:25:11 +01:00
|
|
|
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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
|
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
|
2002-01-19 07:25:11 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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;
|
2002-01-19 07:25:11 +01:00
|
|
|
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 ) {
|
2002-01-19 07:25:11 +01:00
|
|
|
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
|
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
|
2002-01-19 07:25:11 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-09-07 21:28:56 +02:00
|
|
|
#endif
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Display address search status message.
|
|
|
|
* \param queryType Query type.
|
|
|
|
* \param status Status/Error code.
|
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
static void addressbook_search_message( gint queryType, gint sts ) {
|
2003-09-07 21:28:56 +02:00
|
|
|
gchar *desc = NULL;
|
2001-07-03 00:44:09 +02:00
|
|
|
*addressbook_msgbuf = '\0';
|
2003-09-07 21:28:56 +02:00
|
|
|
|
|
|
|
if( sts != MGU_SUCCESS ) {
|
|
|
|
if( queryType == ADDRQUERY_LDAP ) {
|
|
|
|
#ifdef USE_LDAP
|
|
|
|
desc = addressbook_err2string( _lutErrorsLDAP_, sts );
|
|
|
|
#endif
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
if( desc ) {
|
2003-09-07 21:28:56 +02:00
|
|
|
g_snprintf( addressbook_msgbuf,
|
|
|
|
sizeof(addressbook_msgbuf), "%s", desc );
|
2004-01-12 22:28:31 +01:00
|
|
|
addressbook_status_show( addressbook_msgbuf );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addressbook_status_show( "" );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Refresh addressbook by forcing refresh of current selected object in
|
|
|
|
* tree.
|
|
|
|
*/
|
|
|
|
static void addressbook_refresh_current( void ) {
|
2001-07-03 00:44:09 +02:00
|
|
|
AddressObject *obj;
|
2003-09-07 21:28:56 +02:00
|
|
|
GtkCTree *ctree;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
ctree = GTK_CTREE(addrbook.ctree);
|
2001-09-02 01:48:06 +02:00
|
|
|
obj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
|
2001-07-03 00:44:09 +02:00
|
|
|
if( obj == NULL ) return;
|
2005-10-16 14:55:18 +02:00
|
|
|
addressbook_set_clist( obj, TRUE );
|
2001-07-03 00:44:09 +02:00
|
|
|
}
|
2002-12-29 06:13:00 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Message that is displayed whilst a query is executing in a background
|
|
|
|
* thread.
|
|
|
|
*/
|
|
|
|
static gchar *_tempMessage_ = N_( "Busy searching..." );
|
2003-06-21 08:23:00 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Address search idle function. This function is called during UI idle time
|
|
|
|
* while a search is in progress.
|
|
|
|
*
|
|
|
|
* \param data Idler data.
|
2002-12-29 06:13:00 +01:00
|
|
|
*/
|
2003-09-07 21:28:56 +02:00
|
|
|
static void addressbook_search_idle( gpointer data ) {
|
|
|
|
/*
|
|
|
|
gint queryID;
|
|
|
|
|
|
|
|
queryID = GPOINTER_TO_INT( data );
|
|
|
|
printf( "addressbook_ldap_idle... queryID=%d\n", queryID );
|
|
|
|
*/
|
2003-06-21 08:23:00 +02:00
|
|
|
}
|
2003-05-22 22:33:58 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
/**
|
|
|
|
* Search completion callback function. This removes the query from the idle
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
* \param queryID Query ID of search request.
|
|
|
|
*/
|
|
|
|
void addressbook_clear_idler( gint queryID ) {
|
|
|
|
gpointer ptrQID;
|
|
|
|
|
|
|
|
/* Remove idler function */
|
|
|
|
/* printf( "addressbook_clear_idler::%d::\n", queryID ); */
|
|
|
|
ptrQID = GINT_TO_POINTER( queryID );
|
|
|
|
if( ptrQID ) {
|
|
|
|
gtk_idle_remove_by_data( ptrQID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
2004-01-12 22:28:31 +01:00
|
|
|
* Search completion callback function. This removes the query from the idle
|
|
|
|
* list.
|
2003-09-07 21:28:56 +02:00
|
|
|
*
|
2004-01-12 22:28:31 +01:00
|
|
|
* \param sender Sender of query.
|
|
|
|
* \param queryID Query ID of search request.
|
|
|
|
* \param status Search status.
|
|
|
|
* \param data Query data.
|
2003-06-21 08:23:00 +02:00
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
static void addressbook_search_callback_end(
|
|
|
|
gpointer sender, gint queryID, gint status, gpointer data )
|
2003-09-07 21:28:56 +02:00
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
gpointer ptrQID;
|
|
|
|
QueryRequest *req;
|
|
|
|
AddrQueryObject *aqo;
|
2003-09-07 21:28:56 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Remove idler function */
|
|
|
|
ptrQID = GINT_TO_POINTER( queryID );
|
|
|
|
if( ptrQID ) {
|
|
|
|
gtk_idle_remove_by_data( ptrQID );
|
2002-12-29 06:13:00 +01:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
/* Refresh addressbook contents */
|
2003-09-07 21:28:56 +02:00
|
|
|
addressbook_refresh_current();
|
2004-01-12 22:28:31 +01:00
|
|
|
req = qrymgr_find_request( queryID );
|
|
|
|
if( req != NULL ) {
|
|
|
|
aqo = ( AddrQueryObject * ) req->queryList->data;
|
|
|
|
addressbook_search_message( aqo->queryType, status );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the search */
|
|
|
|
addrindex_stop_search( queryID );
|
2002-12-29 06:13:00 +01:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Label (a format string) that is used to name each folder.
|
|
|
|
*/
|
|
|
|
static gchar *_queryFolderLabel_ = N_( "Search '%s'" );
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Perform search.
|
|
|
|
*
|
|
|
|
* \param ds Data source to search.
|
|
|
|
* \param searchTerm String to lookup.
|
|
|
|
* \param pNode Parent data source node.
|
2002-12-29 06:13:00 +01:00
|
|
|
*/
|
2003-09-07 21:28:56 +02:00
|
|
|
static void addressbook_perform_search(
|
|
|
|
AddressDataSource *ds, gchar *searchTerm,
|
|
|
|
GtkCTreeNode *pNode )
|
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
AddrBookBase *adbase;
|
|
|
|
AddressCache *cache;
|
2003-09-07 21:28:56 +02:00
|
|
|
ItemFolder *folder;
|
|
|
|
GtkCTree *ctree;
|
|
|
|
GtkCTreeNode *nNode;
|
|
|
|
gchar *name;
|
|
|
|
gint queryID;
|
|
|
|
guint idleID;
|
2005-05-31 21:00:21 +02:00
|
|
|
AddressObjectType aoType = ADDR_NONE;
|
2003-09-07 21:28:56 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Setup a query */
|
|
|
|
if( *searchTerm == '\0' || strlen( searchTerm ) < 1 ) return;
|
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
if( ds->type == ADDR_IF_LDAP ) {
|
2004-01-12 22:28:31 +01:00
|
|
|
#if USE_LDAP
|
2003-09-07 21:28:56 +02:00
|
|
|
aoType = ADDR_LDAP_QUERY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2002-12-29 06:13:00 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* Get reference to address cache */
|
|
|
|
adbase = ( AddrBookBase * ) ds->rawDataSource;
|
|
|
|
cache = adbase->addressCache;
|
2003-06-21 08:23:00 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/* Create a folder for the search results */
|
2004-01-12 22:28:31 +01:00
|
|
|
folder = addrcache_add_new_folder( cache, NULL );
|
|
|
|
name = g_strdup_printf( _queryFolderLabel_, searchTerm );
|
2003-09-07 21:28:56 +02:00
|
|
|
addritem_folder_set_name( folder, name );
|
|
|
|
addritem_folder_set_remarks( folder, "" );
|
|
|
|
g_free( name );
|
2003-06-21 08:23:00 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/* Now let's see the folder */
|
|
|
|
ctree = GTK_CTREE(addrbook.ctree);
|
|
|
|
nNode = addressbook_node_add_folder( pNode, ds, folder, aoType );
|
|
|
|
gtk_ctree_expand( ctree, pNode );
|
|
|
|
if( nNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(ctree), nNode );
|
2003-09-07 21:28:56 +02:00
|
|
|
addrbook.treeSelected = nNode;
|
2002-12-29 06:13:00 +01:00
|
|
|
}
|
2003-09-07 21:28:56 +02:00
|
|
|
|
|
|
|
/* Setup the search */
|
2004-01-12 22:28:31 +01:00
|
|
|
queryID = addrindex_setup_explicit_search(
|
|
|
|
ds, searchTerm, folder, addressbook_search_callback_end, NULL );
|
2003-09-07 21:28:56 +02:00
|
|
|
if( queryID == 0 ) return;
|
|
|
|
|
|
|
|
/* Set up idler function */
|
|
|
|
idleID = gtk_idle_add(
|
|
|
|
( GtkFunction ) addressbook_search_idle,
|
|
|
|
GINT_TO_POINTER( queryID ) );
|
|
|
|
|
|
|
|
/* Start search, sit back and wait for something to happen */
|
2004-01-12 22:28:31 +01:00
|
|
|
addrindex_start_search( queryID );
|
2003-09-07 21:28:56 +02:00
|
|
|
|
|
|
|
addressbook_status_show( _tempMessage_ );
|
2002-12-29 06:13:00 +01:00
|
|
|
}
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/**
|
|
|
|
* Lookup button handler. Address search is only performed against
|
|
|
|
* address interfaces for external queries.
|
|
|
|
*
|
|
|
|
* \param button Lookup button widget.
|
|
|
|
* \param data Data object.
|
2001-07-03 00:44:09 +02:00
|
|
|
*/
|
|
|
|
static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
|
2003-09-07 21:28:56 +02:00
|
|
|
GtkCTree *ctree;
|
2001-07-03 00:44:09 +02:00
|
|
|
AddressObject *obj;
|
2003-09-07 21:28:56 +02:00
|
|
|
AddressDataSource *ds;
|
|
|
|
AddressInterface *iface;
|
|
|
|
gchar *searchTerm;
|
|
|
|
GtkCTreeNode *node, *parentNode;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
node = addrbook.treeSelected;
|
|
|
|
if( ! node ) return;
|
|
|
|
if( GTK_CTREE_ROW(node)->level == 1 ) return;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
ctree = GTK_CTREE(addrbook.ctree);
|
|
|
|
obj = gtk_ctree_node_get_row_data( ctree, node );
|
2001-07-03 00:44:09 +02:00
|
|
|
if( obj == NULL ) return;
|
2002-07-24 18:47:21 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
ds = addressbook_find_datasource( node );
|
|
|
|
if( ds == NULL ) return;
|
2001-07-03 00:44:09 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/* We must have a datasource that is an external interface */
|
|
|
|
iface = ds->interface;
|
|
|
|
if( ! iface->haveLibrary ) return;
|
|
|
|
if( ! iface->externalQuery ) return;
|
|
|
|
|
|
|
|
searchTerm =
|
|
|
|
gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 );
|
|
|
|
g_strchomp( searchTerm );
|
|
|
|
|
|
|
|
if( obj->type == ADDR_ITEM_FOLDER ) {
|
|
|
|
parentNode = GTK_CTREE_ROW(node)->parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parentNode = node;
|
2003-03-17 07:49:25 +01:00
|
|
|
}
|
2003-09-07 21:28:56 +02:00
|
|
|
addressbook_perform_search( ds, searchTerm, parentNode );
|
2005-08-23 14:20:48 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_widget_grab_focus( addrbook.entry );
|
2003-05-02 15:20:50 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
g_free( searchTerm );
|
2001-05-02 20:26:06 +02:00
|
|
|
}
|
|
|
|
|
2005-08-03 20:24:13 +02:00
|
|
|
static void addressbook_close_clicked( GtkButton *button, gpointer data ) {
|
|
|
|
addressbook_close();
|
|
|
|
}
|
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
#ifdef USE_LDAP
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Browse address entry for highlighted entry.
|
|
|
|
*/
|
|
|
|
static void addressbook_browse_entry_cb(void)
|
|
|
|
{
|
|
|
|
GtkCTree *clist = GTK_CTREE(addrbook.clist);
|
|
|
|
AddressObject *obj;
|
|
|
|
AddressDataSource *ds;
|
|
|
|
AddressInterface *iface;
|
|
|
|
ItemPerson *person;
|
|
|
|
ItemEMail *email;
|
|
|
|
|
|
|
|
if(addrbook.listSelected == NULL)
|
|
|
|
return;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
obj = gtk_ctree_node_get_row_data(clist, addrbook.listSelected);
|
|
|
|
if (obj == NULL)
|
|
|
|
return;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
ds = addressbook_find_datasource(GTK_CTREE_NODE(addrbook.treeSelected));
|
|
|
|
if(ds == NULL)
|
|
|
|
return;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
iface = ds->interface;
|
2004-05-10 12:22:28 +02:00
|
|
|
if(! iface->haveLibrary )
|
2004-01-12 22:28:31 +01:00
|
|
|
return;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
person = NULL;
|
|
|
|
if (obj->type == ADDR_ITEM_EMAIL) {
|
|
|
|
email = ( ItemEMail * ) obj;
|
|
|
|
if (email == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
person = (ItemPerson *) ADDRITEM_PARENT(email);
|
|
|
|
}
|
|
|
|
else if (obj->type == ADDR_ITEM_PERSON) {
|
|
|
|
person = (ItemPerson *) obj;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* None of these */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( iface->type == ADDR_IF_LDAP ) {
|
|
|
|
browseldap_entry(ds, person->externalID);
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 10:05:09 +02:00
|
|
|
#endif
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2001-09-02 01:48:06 +02:00
|
|
|
/* **********************************************************************
|
|
|
|
* Build lookup tables.
|
|
|
|
* ***********************************************************************
|
|
|
|
*/
|
2001-05-02 20:26:06 +02:00
|
|
|
|
2002-01-19 07:25:11 +01: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;
|
|
|
|
|
|
|
|
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;
|
2002-09-29 15:43:33 +02:00
|
|
|
default: ioType = ITEMTYPE_NONE; break;
|
2002-01-19 07:25:11 +01:00
|
|
|
}
|
|
|
|
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);
|
2003-09-07 21:28:56 +02:00
|
|
|
stock_pixmap_gdk(window, STOCK_PIXMAP_ADDRESS_SEARCH, &addrsearchxpm, &addrsearchxpmmask);
|
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;
|
2005-08-02 19:11:21 +02:00
|
|
|
atci->menuCommand = "/Book/New Book";
|
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
|
|
|
/* 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 );
|
|
|
|
|
2001-11-20 07:37:29 +01:00
|
|
|
/* 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;
|
2001-11-20 07:37:29 +01:00
|
|
|
atci->displayName = _( "vCard" );
|
2001-09-02 01:48:06 +02:00
|
|
|
atci->iconXpm = vcardxpm;
|
|
|
|
atci->maskXpm = vcardxpmmask;
|
|
|
|
atci->iconXpmOpen = vcardxpm;
|
|
|
|
atci->maskXpmOpen = vcardxpmmask;
|
2005-08-02 19:11:21 +02:00
|
|
|
atci->menuCommand = "/Book/New vCard";
|
2001-09-02 01:48:06 +02:00
|
|
|
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
|
|
|
|
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
|
|
|
|
|
2002-01-19 07:25:11 +01:00
|
|
|
/* 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;
|
2005-08-02 19:11:21 +02:00
|
|
|
atci->menuCommand = "/Book/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;
|
2003-09-07 21:28:56 +02:00
|
|
|
atci->treeLeaf = FALSE;
|
2006-03-21 18:54:25 +01:00
|
|
|
atci->displayName = _( "LDAP servers" );
|
2001-09-02 01:48:06 +02:00
|
|
|
atci->iconXpm = ldapxpm;
|
|
|
|
atci->maskXpm = ldapxpmmask;
|
|
|
|
atci->iconXpmOpen = ldapxpm;
|
|
|
|
atci->maskXpmOpen = ldapxpmmask;
|
2005-11-23 19:26:57 +01:00
|
|
|
atci->menuCommand = "/Book/New LDAP Server";
|
2001-09-02 01:48:06 +02:00
|
|
|
g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
|
|
|
|
_addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
|
2001-05-02 20:26:06 +02:00
|
|
|
|
2003-09-07 21:28:56 +02:00
|
|
|
/* LDAP Query */
|
|
|
|
atci = g_new0( AddressTypeControlItem, 1 );
|
|
|
|
atci->objectType = ADDR_LDAP_QUERY;
|
|
|
|
atci->interfaceType = ADDR_IF_LDAP;
|
|
|
|
atci->showInTree = TRUE;
|
|
|
|
atci->treeExpand = FALSE;
|
|
|
|
atci->treeLeaf = TRUE;
|
|
|
|
atci->displayName = _( "LDAP Query" );
|
|
|
|
atci->iconXpm = addrsearchxpm;
|
|
|
|
atci->maskXpm = addrsearchxpmmask;
|
|
|
|
atci->iconXpmOpen = addrsearchxpm;
|
|
|
|
atci->maskXpmOpen = addrsearchxpmmask;
|
|
|
|
atci->menuCommand = NULL;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
2001-09-02 01:48:06 +02:00
|
|
|
* Build GUI interface list.
|
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
void addrbookctl_build_iflist( void ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
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();
|
2002-01-19 07:25:11 +01:00
|
|
|
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 );
|
2004-01-12 22:28:31 +01:00
|
|
|
_addressInterfaceList_ =
|
|
|
|
g_list_append( _addressInterfaceList_, adapter );
|
2001-09-02 01:48:06 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Find GUI interface type specified interface type.
|
|
|
|
* \param ifType Interface type.
|
|
|
|
* \return Interface item, or NULL if not found.
|
|
|
|
*/
|
2001-09-02 01:48:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Build interface list selection.
|
|
|
|
*/
|
|
|
|
void addrbookctl_build_ifselect( void ) {
|
2001-09-02 01:48:06 +02:00
|
|
|
GList *newList = NULL;
|
|
|
|
gchar *selectStr;
|
|
|
|
gchar **splitStr;
|
|
|
|
gint ifType;
|
|
|
|
gint i;
|
|
|
|
gchar *endptr = NULL;
|
|
|
|
gboolean enabled;
|
|
|
|
AdapterInterface *adapter;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01: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.
|
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
gboolean addressbook_add_contact(
|
|
|
|
const gchar *name, const gchar *address, const gchar *remarks )
|
|
|
|
{
|
2001-09-02 01:48:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-05-02 15:20:50 +02:00
|
|
|
/* **********************************************************************
|
2004-01-12 22:28:31 +01:00
|
|
|
* Address Import.
|
|
|
|
* ***********************************************************************
|
|
|
|
*/
|
2001-09-24 07:43:58 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Import LDIF file.
|
|
|
|
*/
|
|
|
|
static void addressbook_import_ldif_cb( void ) {
|
2001-09-24 07:43:58 +02:00
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressBookFile *abf = NULL;
|
|
|
|
AdapterInterface *adapter;
|
|
|
|
GtkCTreeNode *newNode;
|
|
|
|
|
|
|
|
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
|
2001-10-29 07:59:14 +01:00
|
|
|
if( adapter ) {
|
|
|
|
if( adapter->treeNode ) {
|
|
|
|
abf = addressbook_imp_ldif( _addressIndex_ );
|
|
|
|
if( abf ) {
|
2002-03-16 07:10:46 +01:00
|
|
|
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) );
|
2001-10-29 07:59:14 +01:00
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
|
2002-03-16 07:10:46 +01:00
|
|
|
newNode );
|
2001-10-29 07:59:14 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
|
|
|
}
|
2003-05-02 15:20:50 +02:00
|
|
|
|
|
|
|
/* Notify address completion */
|
|
|
|
invalidate_address_completion();
|
2001-10-29 07:59:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-20 09:04:54 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Import MUTT file.
|
|
|
|
*/
|
|
|
|
static void addressbook_import_mutt_cb( void ) {
|
2001-10-29 07:59:14 +01:00
|
|
|
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 ) {
|
2002-03-16 07:10:46 +01:00
|
|
|
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) );
|
2001-10-29 07:59:14 +01:00
|
|
|
if( newNode ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
|
2002-04-02 08:57:31 +02:00
|
|
|
newNode );
|
|
|
|
addrbook.treeSelected = newNode;
|
|
|
|
}
|
2003-05-02 15:20:50 +02:00
|
|
|
|
|
|
|
/* Notify address completion */
|
|
|
|
invalidate_address_completion();
|
2002-04-02 08:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Import Pine file.
|
|
|
|
*/
|
|
|
|
static void addressbook_import_pine_cb( void ) {
|
2002-04-02 08:57:31 +02:00
|
|
|
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_pine( _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 ) {
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
|
2002-03-16 07:10:46 +01:00
|
|
|
newNode );
|
2001-10-29 07:59:14 +01:00
|
|
|
addrbook.treeSelected = newNode;
|
|
|
|
}
|
2003-05-02 15:20:50 +02:00
|
|
|
|
|
|
|
/* Notify address completion */
|
|
|
|
invalidate_address_completion();
|
2001-10-29 07:59:14 +01:00
|
|
|
}
|
|
|
|
}
|
2001-09-24 07:43:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
2002-04-20 05:35:55 +02:00
|
|
|
* Harvest addresses.
|
2004-01-12 22:28:31 +01:00
|
|
|
* \param folderItem Folder to import.
|
|
|
|
* \param sourceInd Source indicator: FALSE - Folder, TRUE - Messages.
|
|
|
|
* \param msgList List of message numbers, or NULL to process folder.
|
2002-04-08 05:51:28 +02:00
|
|
|
*/
|
2002-04-20 05:35:55 +02:00
|
|
|
void addressbook_harvest(
|
|
|
|
FolderItem *folderItem, gboolean sourceInd, GList *msgList )
|
|
|
|
{
|
2002-03-16 08:07:34 +01:00
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressBookFile *abf = NULL;
|
|
|
|
AdapterInterface *adapter;
|
|
|
|
GtkCTreeNode *newNode;
|
|
|
|
|
2002-04-20 05:35:55 +02:00
|
|
|
abf = addrgather_dlg_execute(
|
|
|
|
folderItem, _addressIndex_, sourceInd, msgList );
|
2002-03-16 08:07:34 +01:00
|
|
|
if( abf ) {
|
|
|
|
ds = addrindex_index_add_datasource(
|
|
|
|
_addressIndex_, ADDR_IF_BOOK, abf );
|
|
|
|
|
|
|
|
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
|
|
|
|
if( adapter ) {
|
|
|
|
if( adapter->treeNode ) {
|
|
|
|
ads = addressbook_create_ds_adapter(
|
|
|
|
ds, ADDR_BOOK, addrbook_get_name( abf ) );
|
|
|
|
newNode = addressbook_add_object(
|
|
|
|
adapter->treeNode,
|
|
|
|
ADDRESS_OBJECT(ads) );
|
|
|
|
}
|
|
|
|
}
|
2003-05-02 15:20:50 +02:00
|
|
|
|
|
|
|
/* Notify address completion */
|
|
|
|
invalidate_address_completion();
|
2002-03-16 08:07:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Export HTML file.
|
|
|
|
*/
|
2002-05-06 08:27:11 +02:00
|
|
|
static void addressbook_export_html_cb( void ) {
|
|
|
|
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
|
|
|
|
AddressObject *obj;
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AddrBookBase *adbase;
|
|
|
|
AddressCache *cache;
|
|
|
|
GtkCTreeNode *node = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ds = addressbook_find_datasource( node );
|
|
|
|
if( ds == NULL ) return;
|
|
|
|
adbase = ( AddrBookBase * ) ds->rawDataSource;
|
|
|
|
cache = adbase->addressCache;
|
|
|
|
addressbook_exp_html( cache );
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Export LDIF file.
|
|
|
|
*/
|
2003-08-05 06:14:35 +02:00
|
|
|
static void addressbook_export_ldif_cb( void ) {
|
|
|
|
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
|
|
|
|
AddressObject *obj;
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
AddrBookBase *adbase;
|
|
|
|
AddressCache *cache;
|
|
|
|
GtkCTreeNode *node = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ds = addressbook_find_datasource( node );
|
|
|
|
if( ds == NULL ) return;
|
|
|
|
adbase = ( AddrBookBase * ) ds->rawDataSource;
|
|
|
|
cache = adbase->addressCache;
|
|
|
|
addressbook_exp_ldif( cache );
|
|
|
|
}
|
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
static void addressbook_start_drag(GtkWidget *widget, gint button,
|
|
|
|
GdkEvent *event,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
GdkDragContext *context;
|
|
|
|
if (addressbook_target_list == NULL)
|
|
|
|
addressbook_target_list = gtk_target_list_new(
|
|
|
|
addressbook_drag_types, 1);
|
|
|
|
context = gtk_drag_begin(widget, addressbook_target_list,
|
|
|
|
GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event);
|
|
|
|
gtk_drag_set_icon_default(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_drag_data_get(GtkWidget *widget,
|
|
|
|
GdkDragContext *drag_context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
AddrItemObject *aio = NULL;
|
|
|
|
AddressObject *pobj = NULL;
|
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressDataSource *ds = NULL;
|
2005-07-15 18:39:12 +02:00
|
|
|
GList *cur;
|
2004-09-06 11:53:05 +02:00
|
|
|
|
|
|
|
pobj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
|
2005-11-21 18:39:59 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
if( pobj == NULL ) return;
|
|
|
|
|
|
|
|
if( pobj->type == ADDR_DATASOURCE ) {
|
|
|
|
ads = ADAPTER_DSOURCE(pobj);
|
|
|
|
ds = ads->dataSource;
|
|
|
|
} else if (pobj->type == ADDR_ITEM_GROUP) {
|
2005-11-21 18:39:59 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pobj->type != ADDR_INTERFACE ) {
|
|
|
|
ds = addressbook_find_datasource( addrbook.treeSelected );
|
2005-11-21 18:39:59 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
if (!ds)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-15 18:39:12 +02:00
|
|
|
for(cur = GTK_CLIST(addrbook.clist)->selection; cur; cur = cur->next) {
|
2005-11-21 18:39:59 +01:00
|
|
|
aio = (AddrItemObject *)gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.clist),
|
2005-07-15 18:39:12 +02:00
|
|
|
GTK_CTREE_NODE(cur->data));
|
|
|
|
while (aio && aio->type != ADDR_ITEM_PERSON) {
|
|
|
|
aio = aio->parent;
|
|
|
|
}
|
2005-11-21 18:39:59 +01:00
|
|
|
}
|
2004-09-06 11:53:05 +02:00
|
|
|
|
|
|
|
if (aio && aio->type == ADDR_ITEM_PERSON) {
|
2005-11-21 18:39:59 +01:00
|
|
|
if( ds && ds->interface && ds->interface->readOnly)
|
|
|
|
gtk_selection_data_set(selection_data,
|
2004-09-06 11:53:05 +02:00
|
|
|
selection_data->target, 8,
|
2005-11-21 18:39:59 +01:00
|
|
|
"Dummy_addr_copy", 15);
|
|
|
|
else
|
|
|
|
gtk_selection_data_set(selection_data,
|
|
|
|
selection_data->target, 8,
|
|
|
|
"Dummy_addr_move", 15);
|
|
|
|
}
|
2004-09-06 11:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean addressbook_drag_motion_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint time,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
gint row, column;
|
|
|
|
GtkCTreeNode *node = NULL;
|
|
|
|
gboolean acceptable = FALSE;
|
|
|
|
gint height = addrbook.ctree->allocation.height;
|
|
|
|
gint total_height = addrbook.ctree->requisition.height;
|
|
|
|
GtkAdjustment *pos = gtk_scrolled_window_get_vadjustment(
|
|
|
|
GTK_SCROLLED_WINDOW(addrbook.ctree_swin));
|
|
|
|
gfloat vpos = pos->value;
|
|
|
|
|
|
|
|
if (gtk_clist_get_selection_info
|
|
|
|
(GTK_CLIST(widget), x - 24, y - 24, &row, &column)) {
|
|
|
|
|
|
|
|
if (y > height - 24 && height + vpos < total_height)
|
|
|
|
gtk_adjustment_set_value(pos, (vpos+5 > height ? height : vpos+5));
|
|
|
|
|
|
|
|
if (y < 24 && y > 0)
|
|
|
|
gtk_adjustment_set_value(pos, (vpos-5 < 0 ? 0 : vpos-5));
|
|
|
|
|
|
|
|
node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
|
|
|
|
|
|
|
|
if (node != NULL) {
|
|
|
|
AddressObject *obj = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node );
|
|
|
|
if( obj->type == ADDR_ITEM_FOLDER
|
|
|
|
|| obj->type == ADDR_ITEM_GROUP)
|
|
|
|
acceptable = TRUE;
|
|
|
|
else {
|
|
|
|
AdapterDSource *ads = NULL;
|
|
|
|
AddressDataSource *ds = NULL;
|
|
|
|
ads = ADAPTER_DSOURCE(obj);
|
2005-11-21 18:39:59 +01:00
|
|
|
if (ads == NULL ){ return FALSE;}
|
2004-09-06 11:53:05 +02:00
|
|
|
ds = ads->dataSource;
|
2005-11-21 18:39:59 +01:00
|
|
|
if (ds == NULL ) { return FALSE;}
|
2004-09-06 11:53:05 +02:00
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
acceptable = TRUE;
|
2004-09-06 11:53:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acceptable) {
|
|
|
|
g_signal_handlers_block_by_func
|
|
|
|
(G_OBJECT(widget),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
2005-08-17 11:29:17 +02:00
|
|
|
gtk_sctree_select( GTK_SCTREE(widget), node);
|
2004-09-06 11:53:05 +02:00
|
|
|
g_signal_handlers_unblock_by_func
|
|
|
|
(G_OBJECT(widget),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
|
|
|
gdk_drag_status(context,
|
|
|
|
(context->actions == GDK_ACTION_COPY ?
|
|
|
|
GDK_ACTION_COPY : GDK_ACTION_MOVE) , time);
|
|
|
|
} else {
|
|
|
|
gdk_drag_status(context, 0, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return acceptable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_drag_leave_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
guint time,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
if (addrbook.treeSelected) {
|
|
|
|
g_signal_handlers_block_by_func
|
|
|
|
(G_OBJECT(widget),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
2005-11-21 18:39:59 +01:00
|
|
|
gtk_sctree_select( GTK_SCTREE(widget), addrbook.opened);
|
2004-09-06 11:53:05 +02:00
|
|
|
g_signal_handlers_unblock_by_func
|
|
|
|
(G_OBJECT(widget),
|
|
|
|
G_CALLBACK(addressbook_tree_selected), NULL);
|
|
|
|
}
|
2005-11-21 18:39:59 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addressbook_drag_received_cb(GtkWidget *widget,
|
|
|
|
GdkDragContext *drag_context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
void *pdata)
|
|
|
|
{
|
|
|
|
gint row, column;
|
|
|
|
GtkCTreeNode *node;
|
2005-11-21 18:39:59 +01:00
|
|
|
GtkCTreeNode *lastopened = addrbook.opened;
|
2005-07-15 18:39:12 +02:00
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
if (!strncmp(data->data, "Dummy_addr", 10)) {
|
2004-09-06 11:53:05 +02:00
|
|
|
if (gtk_clist_get_selection_info
|
|
|
|
(GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0) {
|
2005-11-21 18:39:59 +01:00
|
|
|
return;
|
2004-09-06 11:53:05 +02:00
|
|
|
}
|
2005-11-21 18:39:59 +01:00
|
|
|
|
2004-09-06 11:53:05 +02:00
|
|
|
node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
|
2005-11-21 18:39:59 +01:00
|
|
|
if( !node || !gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree), node))
|
|
|
|
return;
|
2004-09-06 11:53:05 +02:00
|
|
|
|
2005-11-21 18:39:59 +01:00
|
|
|
gtk_clist_freeze(GTK_CLIST(addrbook.clist));
|
|
|
|
if (drag_context->action == GDK_ACTION_COPY ||
|
|
|
|
!strcmp(data->data, "Dummy_addr_copy"))
|
|
|
|
addressbook_clip_copy_cb();
|
|
|
|
else
|
|
|
|
addressbook_clip_cut_cb();
|
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), node);
|
|
|
|
addressbook_clip_paste_cb();
|
|
|
|
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), lastopened);
|
|
|
|
gtk_clist_thaw(GTK_CLIST(addrbook.clist));
|
2004-09-06 11:53:05 +02:00
|
|
|
gtk_drag_finish(drag_context, TRUE, TRUE, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-03 00:44:09 +02:00
|
|
|
/*
|
|
|
|
* End of Source.
|
|
|
|
*/
|
2002-01-19 07:25:11 +01:00
|
|
|
|