claws-mail/src/addressbook.c

5250 lines
153 KiB
C
Raw Normal View History

2001-04-19 14:21:46 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
2007-01-03 [paul] 2.6.1cvs96 * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addressbook_foldersel.c * src/addressbook_foldersel.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.c * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.c * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/mbox.c * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_quote.c * src/prefs_receive.c * src/prefs_send.c * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/stringtable.c * src/common/stringtable.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/combobox.c * src/gtk/combobox.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtksctree.c * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/bogofilter/bogofilter.c * src/plugins/bogofilter/bogofilter.h * src/plugins/bogofilter/bogofilter_gtk.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/pgp_viewer.c * src/plugins/pgpcore/pgp_viewer.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c it's 2007, update the year in the copyright headers
2007-01-03 06:42:43 +01:00
* Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail 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 [paul] 1.9.14cvs47 * README * README.jp * configure.ac * config/config.rpath * doc/manual/en/sylpheed-20.html * doc/manual/es/sylpheed-20.html * po/bg.po * po/ca.po * po/de.po * po/es.po * po/fr.po * po/it.po * po/pt_BR.po * po/sk.po * po/zh_TW.po * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrbook.h * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addressitem.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/crash.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/enriched.c * src/enriched.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.c * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/headerview.h * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.c * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/localfolder.c * src/localfolder.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/matcher.c * src/matcher.h * src/matcher_parser.h * src/matcher_parser_lex.l * src/matcher_parser_parse.y * src/mbox.c * src/mbox.h * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/noticeview.c * src/noticeview.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_ext_prog.c * src/prefs_ext_prog.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_message.h * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_other.h * src/prefs_quote.c * src/prefs_quote.h * src/prefs_receive.c * src/prefs_receive.h * src/prefs_send.c * src/prefs_send.h * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/simple-gettext.c * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/syldap.c * src/syldap.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/md5.c * src/common/md5.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/string_match.c * src/common/string_match.h * src/common/stringtable.c * src/common/sylpheed.c * src/common/sylpheed.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/uuencode.c * src/common/uuencode.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/about.c * src/gtk/about.h * src/gtk/colorlabel.c * src/gtk/colorlabel.h * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/quicksearch.c * src/gtk/quicksearch.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/prefs_gpg.c * src/plugins/pgpcore/prefs_gpg.h * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c * tools/OOo2sylpheed.pl * tools/acroread2sylpheed.pl * tools/asus_mailled.sh * tools/filter_conv.pl * tools/freshmeat_search.pl * tools/google_search.pl * tools/kmail2sylpheed.pl * tools/kmail2sylpheed_v2.pl * tools/maildir2sylpheed.pl * tools/multiwebsearch.pl * tools/newscache_clean.pl * tools/outlook2sylpheed.pl * tools/sylpheed-switcher * tools/update-po * tools/vcard2xml.py * tools/kdeservicemenu/sylpheed-kdeservicemenu.pl update FSF address
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 [paul] 1.0.1cvs3.2 * AUTHORS * Makefile.am * autogen.sh * configure.ac * config/mkinstalldirs * intl/.cvsignore * intl/ChangeLog * intl/VERSION * intl/bindtextdom.c * intl/config.charset * intl/dcgettext.c * intl/dcigettext.c * intl/dcngettext.c * intl/dgettext.c * intl/dngettext.c * intl/eval-plural.h * intl/explodename.c * intl/finddomain.c * intl/gettext.c * intl/gettextP.h * intl/gmo.h * intl/hash-string.h * intl/intl-compat.c * intl/l10nflist.c * intl/libgnuintl.h.in * intl/loadinfo.h * intl/loadmsgcat.c * intl/localcharset.c * intl/localcharset.h * intl/locale.alias * intl/localealias.c * intl/localename.c * intl/log.c * intl/ngettext.c * intl/os2compat.c * intl/os2compat.h * intl/osdep.c * intl/plural-exp.c * intl/plural-exp.h * intl/plural.c * intl/plural.y * intl/ref-add.sin * intl/ref-del.sin * intl/relocatable.c * intl/relocatable.h * intl/textdomain.c * m4/Makefile.am * po/Makefile.in.in * src/Makefile.am * src/account.c * src/action.c * src/addr_compl.c * src/addressadd.c * src/addressbook.c * src/addrgather.c * src/addrindex.c * src/alertpanel.c * src/browseldap.c * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/editaddress.c * src/editbook.c * src/editgroup.c * src/editjpilot.c * src/editldap.c * src/editldap_basedn.c * src/editvcard.c * src/exphtmldlg.c * src/expldifdlg.c * src/export.c * src/exporthtml.c * src/filtering.c * src/folder.c * src/folder_item_prefs.c * src/foldersel.c * src/folderview.c * src/grouplistdialog.c * src/headerview.c * src/imap.c * src/imap_gtk.c * src/import.c * src/importldif.c * src/importmutt.c * src/importpine.c * src/inc.c * src/ldif.c * src/main.c * src/mainwindow.c * src/matcher.c * src/mbox.c * src/message_search.c * src/messageview.c * src/mh.c * src/mh_gtk.c * src/mimeview.c * src/msgcache.c * src/news.c * src/news_gtk.c * src/noticeview.c * src/partial_download.c * src/pop.c * src/prefs_account.c * src/prefs_actions.c * src/prefs_common.c * src/prefs_customheader.c * src/prefs_display_header.c * src/prefs_ext_prog.c * src/prefs_filtering.c * src/prefs_filtering_action.c * src/prefs_folder_item.c * src/prefs_fonts.c * src/prefs_gtk.c * src/prefs_matcher.c * src/prefs_msg_colors.c * src/prefs_spelling.c * src/prefs_summary_column.c * src/prefs_template.c * src/prefs_themes.c * src/prefs_toolbar.c * src/prefs_wrapping.c * src/privacy.c * src/procheader.c * src/procmime.c * src/procmsg.c * src/quote_fmt.c * src/recv.c * src/send_message.c * src/setup.c * src/sourcewindow.c * src/ssl_manager.c * src/statusbar.c * src/summary_search.c * src/summaryview.c * src/textview.c * src/toolbar.c * src/wizard.c * src/common/nntp.c * src/common/plugin.c * src/common/smtp.c * src/common/ssl.c * src/common/ssl_certificate.c * src/common/string_match.c * src/common/sylpheed.c * src/common/template.c * src/common/utils.c * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/description_window.c * src/gtk/filesel.c * src/gtk/foldersort.c * src/gtk/gtkaspell.c * src/gtk/gtkutils.c * src/gtk/inputdialog.c * src/gtk/logwindow.c * src/gtk/menu.c * src/gtk/pluginwindow.c * src/gtk/prefswindow.c * src/gtk/progressdialog.c * src/gtk/quicksearch.c * src/gtk/sslcertwindow.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/image_viewer/plugin.c * src/plugins/image_viewer/viewer.c * src/plugins/image_viewer/viewerprefs.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpmime/passphrase.c * src/plugins/pgpmime/plugin.c * src/plugins/pgpmime/prefs_gpg.c * src/plugins/pgpmime/select-keys.c * src/plugins/pgpmime/sgpgme.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c sync with main (revision 104)
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"
#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"
#include "addressitem.h"
2001-09-02 01:48:06 +02:00
#include "addritem.h"
#include "addrcache.h"
#include "addrbook.h"
#include "addrindex.h"
2001-09-06 12:24:20 +02:00
#include "addressadd.h"
#include "addressbook_foldersel.h"
#include "vcard.h"
#include "editvcard.h"
2001-09-02 01:48:06 +02:00
#include "editgroup.h"
#include "editaddress.h"
#include "editbook.h"
2001-09-24 07:43:58 +02:00
#include "importldif.h"
#include "importmutt.h"
2002-04-02 08:57:31 +02:00
#include "importpine.h"
#include "manual.h"
#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"
#include "editldap.h"
2001-09-02 01:48:06 +02:00
#define ADDRESSBOOK_LDAP_BUSYMSG "Busy"
#endif
2004-01-12 22:28:31 +01:00
#include "addrquery.h"
#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"
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,
COL_REMARKS = 2,
N_LIST_COLS = 3
} AddressListColumns;
2001-04-19 14:21:46 +02:00
typedef struct {
AddressBookFile *book;
ItemFolder *folder;
} FolderInfo;
typedef struct {
gchar **folder_path;
gboolean matched;
gint index;
AddressDataSource *book;
ItemFolder *folder;
} FolderPathMatch;
static gchar *list_titles[] = { N_("Name"),
N_("Email Address"),
N_("Remarks") };
2001-09-02 01:48:06 +02:00
#define COL_NAME_WIDTH 164
#define COL_ADDRESS_WIDTH 156
2001-04-19 14:21:46 +02:00
#define COL_FOLDER_WIDTH 170
#define ADDRESSBOOK_WIDTH 640
#define ADDRESSBOOK_HEIGHT 360
#define ADDRESSBOOK_MSGBUF_SIZE 2048
2001-04-19 14:21:46 +02:00
static GdkPixmap *folderxpm;
static GdkBitmap *folderxpmmask;
static GdkPixmap *folderopenxpm;
static GdkBitmap *folderopenxpmmask;
static GdkPixmap *groupxpm;
static GdkBitmap *groupxpmmask;
2001-09-02 01:48:06 +02:00
static GdkPixmap *interfacexpm;
static GdkBitmap *interfacexpmmask;
static GdkPixmap *bookxpm;
static GdkBitmap *bookxpmmask;
static GdkPixmap *addressxpm;
static GdkBitmap *addressxpmmask;
static GdkPixmap *vcardxpm;
static GdkBitmap *vcardxpmmask;
static GdkPixmap *jpilotxpm;
static GdkBitmap *jpilotxpmmask;
static GdkPixmap *categoryxpm;
static GdkBitmap *categoryxpmmask;
static GdkPixmap *ldapxpm;
static GdkBitmap *ldapxpmmask;
2003-09-07 21:28:56 +02:00
static GdkPixmap *addrsearchxpm;
static GdkPixmap *addrsearchxpmmask;
2001-09-13 15:38:32 +02:00
/* Message buffer */
static gchar addressbook_msgbuf[ ADDRESSBOOK_MSGBUF_SIZE ];
2001-04-19 14:21:46 +02:00
2001-09-13 15:38:32 +02:00
/* Address list selection */
static AddrSelectList *_addressSelect_ = NULL;
static AddressClipboard *_clipBoard_ = NULL;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Address index file and interfaces */
2001-09-02 01:48:06 +02:00
static AddressIndex *_addressIndex_ = NULL;
static GList *_addressInterfaceList_ = NULL;
static GList *_addressIFaceSelection_ = NULL;
#define ADDRESSBOOK_IFACE_SELECTION "1/y,3/y,4/y,2/n"
static AddressBook_win addrbook;
static GHashTable *_addressBookTypeHash_ = NULL;
static GList *_addressBookTypeList_ = NULL;
2001-09-13 15:38:32 +02:00
static void addressbook_create (void);
2001-04-19 14:21:46 +02:00
static gint addressbook_close (void);
static void addressbook_button_set_sensitive (void);
static gboolean address_index_has_focus = FALSE;
static gboolean address_list_has_focus = FALSE;
2001-04-19 14:21:46 +02:00
/* callback functions */
static void addressbook_del_clicked (GtkButton *button,
gpointer data);
static void addressbook_reg_clicked (GtkButton *button,
gpointer data);
static void addressbook_to_clicked (GtkButton *button,
gpointer data);
static void addressbook_lup_clicked (GtkButton *button,
gpointer data);
static void addressbook_close_clicked (GtkButton *button,
gpointer data);
2001-04-19 14:21:46 +02: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 );
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);
#ifdef USE_JPILOT
2001-09-13 15:38:32 +02:00
static void addressbook_new_jpilot_cb (gpointer data,
guint action,
GtkWidget *widget);
#endif
#ifdef USE_LDAP
2001-09-13 15:38:32 +02:00
static void addressbook_new_ldap_cb (gpointer data,
guint action,
GtkWidget *widget);
#endif
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);
static void addressbook_treenode_remove_item ( void );
2001-09-02 01:48:06 +02:00
static AddressDataSource *addressbook_find_datasource
(GtkCTreeNode *node );
static AddressBookFile *addressbook_get_book_file(void);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_node_add_folder
2001-04-19 14:21:46 +02:00
(GtkCTreeNode *node,
2001-09-02 01:48:06 +02:00
AddressDataSource *ds,
ItemFolder *itemFolder,
2001-09-13 15:38:32 +02:00
AddressObjectType otype);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_node_add_group (GtkCTreeNode *node,
AddressDataSource *ds,
2001-09-13 15:38:32 +02:00
ItemGroup *itemGroup);
2001-09-02 01:48:06 +02:00
static void addressbook_tree_remove_children (GtkCTree *ctree,
2001-09-13 15:38:32 +02:00
GtkCTreeNode *parent);
2001-09-02 01:48:06 +02:00
static void addressbook_move_nodes_up (GtkCTree *ctree,
2001-09-13 15:38:32 +02:00
GtkCTreeNode *node);
2001-09-02 01:48:06 +02:00
static GtkCTreeNode *addressbook_find_group_node (GtkCTreeNode *parent,
ItemGroup *group);
static gboolean addressbook_entry_key_pressed (GtkWidget *widget,
2001-04-19 14:21:46 +02:00
GdkEventKey *event,
gpointer data);
static gint addressbook_treenode_compare_func (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2);
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
static void addressbook_edit_address( gpointer data, guint action, GtkWidget *widget,
gboolean force_focus );
2001-09-13 15:38:32 +02:00
/* LUT's and IF stuff */
static void addressbook_free_treenode ( gpointer data );
2001-09-13 15:38:32 +02:00
AddressTypeControlItem *addrbookctl_lookup (gint ot);
AddressTypeControlItem *addrbookctl_lookup_iface(AddressIfType ifType);
2001-09-02 01:48:06 +02:00
2001-09-13 15:38:32 +02:00
void addrbookctl_build_map (GtkWidget *window);
void addrbookctl_build_iflist (void);
AdapterInterface *addrbookctl_find_interface (AddressIfType ifType);
void addrbookctl_build_ifselect (void);
2001-09-02 01:48:06 +02:00
2001-09-13 15:38:32 +02:00
static void addrbookctl_free_interface (AdapterInterface *adapter);
static void addrbookctl_free_datasource (AdapterDSource *adapter);
static void addrbookctl_free_folder (AdapterFolder *adapter);
static void addrbookctl_free_group (AdapterGroup *adapter);
2001-09-02 01:48:06 +02:00
static void addressbook_list_select_clear ( void );
static void addressbook_list_select_add ( AddrItemObject *aio,
AddressDataSource *ds );
static void addressbook_list_select_remove ( AddrItemObject *aio );
static void addressbook_import_ldif_cb ( void );
static void addressbook_import_mutt_cb ( void );
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 );
static void addressbook_select_all_cb ( void );
static void addressbook_clip_cut_cb ( void );
static void addressbook_clip_copy_cb ( void );
static void addressbook_clip_paste_cb ( void );
static void addressbook_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
static void addressbook_edit_clicked(GtkButton *button, gpointer data);
2004-01-12 22:28:31 +01: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);
static void addressbook_list_menu_setup( void );
static GtkTargetEntry addressbook_drag_types[] =
{
2006-11-07 11:47:23 +01:00
{"claws-mail/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY}
};
static GtkTargetList *addressbook_target_list = NULL;
2001-04-19 14:21:46 +02:00
static GtkItemFactoryEntry addressbook_entries[] =
{
{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},
{N_("/_Book/New _vCard"), "<control><shift>D", addressbook_new_vcard_cb, 0, NULL},
#ifdef USE_JPILOT
{N_("/_Book/New _JPilot"), "<control>J", addressbook_new_jpilot_cb, 0, NULL},
#endif
#ifdef USE_LDAP
{N_("/_Book/New LDAP _Server"), "<control><shift>S", addressbook_new_ldap_cb, 0, NULL},
2001-09-02 01:48:06 +02:00
#endif
{N_("/_Book/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Book/_Edit book"), NULL, addressbook_treenode_edit_cb, 0, NULL},
{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>"},
{N_("/_Address/_Select all"), "<control>A", addressbook_select_all_cb, 0, NULL},
{N_("/_Address/---"), NULL, NULL, 0, "<Separator>"},
{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>"},
{N_("/_Address/_Edit"), "<control>Return",addressbook_edit_address_cb, 0, NULL},
{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>"},
{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},
{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},
{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},
{N_("/_Delete"), NULL, addressbook_treenode_delete_cb, 0, NULL},
{"/---", NULL, NULL, 0, "<Separator>"},
{N_("/New _Book"), NULL, addressbook_new_book_cb, 0, NULL},
2004-05-10 12:22:28 +02:00
{N_("/New _Folder"), NULL, addressbook_new_folder_cb, 0, NULL},
{N_("/New _Group"), NULL, addressbook_new_group_cb, 0, NULL},
{"/---", NULL, NULL, 0, "<Separator>"},
{N_("/C_ut"), NULL, addressbook_treenode_cut_cb, 0, NULL},
{N_("/_Copy"), NULL, addressbook_treenode_copy_cb, 0, NULL},
{N_("/_Paste"), NULL, addressbook_treenode_paste_cb, 0, NULL}
2001-04-19 14:21:46 +02:00
};
static GtkItemFactoryEntry addressbook_list_popup_entries[] =
{
{N_("/_Select all"), NULL, addressbook_select_all_cb, 0, NULL},
{"/---", 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},
{"/---", NULL, NULL, 0, "<Separator>"},
{N_("/New _Address"), NULL, addressbook_new_address_cb, 0, NULL},
{N_("/New _Group"), NULL, addressbook_new_group_cb, 0, NULL},
{"/---", NULL, NULL, 0, "<Separator>"},
{N_("/C_ut"), NULL, addressbook_clip_cut_cb, 0, NULL},
{N_("/_Copy"), NULL, addressbook_clip_copy_cb, 0, NULL},
{N_("/_Paste"), NULL, addressbook_clip_paste_cb, 0, NULL},
{"/---", NULL, NULL, 0, "<Separator>"},
/* {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;
}
static gboolean lastCanLookup = FALSE;
void addressbook_show_buttons(gboolean add_and_delete, gboolean lookup, gboolean mail_ops)
{
if (add_and_delete) {
gtk_widget_show(addrbook.edit_btn);
gtk_widget_show(addrbook.del_btn);
gtk_widget_show(addrbook.reg_btn);
} else {
gtk_widget_hide(addrbook.edit_btn);
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)
{
/* 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();
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 23:02:09 +02:00
gtk_widget_show_all(addrbook.window);
if (!prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_person_widgetset_hide();
address_completion_start(addrbook.window);
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) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
2001-09-13 15:38:32 +02:00
addrbook.treeSelected);
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();
}
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) {
/* TODO: enable deletion when focus is in ctree (needs implementation in _del_clicked() */
if ( /* address_index_has_focus || */ address_list_has_focus )
addressbook_del_clicked(NULL, NULL);
}
return FALSE;
}
/*!
*\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;
}
static gint sort_column_number = 0;
static GtkSortType sort_column_type = GTK_SORT_ASCENDING;
static gint list_case_sort(
GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
{
GtkCListRow *row1 = (GtkCListRow *) ptr1;
GtkCListRow *row2 = (GtkCListRow *) ptr2;
gchar *name1 = NULL, *name2 = NULL;
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 ) {
return (sort_column_type==GTK_SORT_ASCENDING) ? -1:+1;
} else if( aio2->type == ITEMTYPE_GROUP ) {
return (sort_column_type==GTK_SORT_ASCENDING) ? +1:-1;
}
return 0;
}
}
static void addressbook_sort_list(GtkCList *clist, const gint col,
const GtkSortType sort_type)
{
gint pos;
GtkWidget *hbox, *label, *arrow;
sort_column_number = col;
sort_column_type = sort_type;
gtk_clist_set_compare_func(clist, list_case_sort);
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);
label = gtk_label_new(gettext(list_titles[pos]));
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);
}
static gboolean addressbook_address_index_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
gpointer data)
{
address_index_has_focus = TRUE;
return FALSE;
}
static gboolean addressbook_address_index_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
gpointer data)
{
address_index_has_focus = FALSE;
return FALSE;
}
static gboolean addressbook_address_list_focus_evt_in(GtkWidget *widget, GdkEventFocus *event,
gpointer data)
{
address_list_has_focus = TRUE;
return FALSE;
}
static gboolean addressbook_address_list_focus_evt_out(GtkWidget *widget, GdkEventFocus *event,
gpointer data)
{
address_list_has_focus = FALSE;
return FALSE;
}
/* save hpane and vpane's handle position when it moves */
static void addressbook_pane_notify_position(GObject *gobject,
GParamSpec *arg1,
gpointer user_data)
{
prefs_common.addressbook_hpaned_pos = gtk_paned_get_position(GTK_PANED(addrbook.hpaned));
prefs_common.addressbook_vpaned_pos = gtk_paned_get_position(GTK_PANED(addrbook.vpaned));
}
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 *editaddress_vbox;
2001-04-19 14:21:46 +02:00
GtkWidget *clist_vbox;
GtkWidget *clist_swin;
GtkWidget *clist;
GtkWidget *hpaned;
GtkWidget *vpaned;
2001-04-19 14:21:46 +02:00
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *statusbar;
2001-04-19 14:21:46 +02:00
GtkWidget *hbbox;
GtkWidget *hsbox;
GtkWidget *help_btn;
2001-04-19 14:21:46 +02:00
GtkWidget *del_btn;
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;
GtkWidget *close_btn;
2001-04-19 14:21:46 +02:00
GtkWidget *tree_popup;
GtkWidget *list_popup;
GtkItemFactory *tree_factory;
GtkItemFactory *list_factory;
GtkItemFactory *menu_factory;
2001-04-19 14:21:46 +02:00
gint n_entries;
2001-09-02 01:48:06 +02:00
GList *nodeIf;
2001-04-19 14:21:46 +02:00
gchar *index_titles[N_INDEX_COLS];
2001-04-19 14:21:46 +02:00
gchar *text;
gint i;
static GdkGeometry geometry;
2001-04-19 14:21:46 +02:00
debug_print("Creating addressbook window...\n");
index_titles[COL_SOURCES] = _("Sources");
2002-02-08 11:07:11 +01: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"));
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);
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
vbox = gtk_vbox_new(FALSE, 0);
2001-04-19 14:21:46 +02:00
gtk_container_add(GTK_CONTAINER(window), vbox);
/* 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);
menu_factory = gtk_item_factory_from_widget(menubar);
2001-04-19 14:21:46 +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,
GTK_POLICY_AUTOMATIC);
gtk_widget_set_size_request(ctree_swin, COL_FOLDER_WIDTH + 20, -1);
2001-04-19 14:21:46 +02:00
2001-09-13 15:38:32 +02:00
/* Address index */
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),
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
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);
g_signal_connect(G_OBJECT(ctree), "focus_in_event",
G_CALLBACK(addressbook_address_index_focus_evt_in), NULL);
g_signal_connect(G_OBJECT(ctree), "focus_out_event",
G_CALLBACK(addressbook_address_index_focus_evt_out), NULL);
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,
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 */
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);
gtk_widget_set_size_request(clist, -1, 80);
2001-04-19 14:21:46 +02:00
addressbook_sort_list(GTK_CLIST(clist), COL_NAME, GTK_SORT_ASCENDING);
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);
g_signal_connect(G_OBJECT(clist), "focus_in_event",
G_CALLBACK(addressbook_address_list_focus_evt_in), NULL);
g_signal_connect(G_OBJECT(clist), "focus_out_event",
G_CALLBACK(addressbook_address_list_focus_evt_out), NULL);
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 );
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);
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), FALSE);
2001-04-19 14:21:46 +02:00
g_signal_connect(G_OBJECT(entry), "key_press_event",
G_CALLBACK(addressbook_entry_key_pressed),
NULL);
if (!prefs_common.addressbook_use_editaddress_dialog) {
editaddress_vbox = gtk_vbox_new(FALSE, 4);
vpaned = gtk_vpaned_new();
gtk_paned_pack1(GTK_PANED(vpaned), clist_vbox, FALSE, FALSE);
gtk_paned_pack2(GTK_PANED(vpaned), editaddress_vbox, TRUE, FALSE);
} else {
vpaned = NULL;
editaddress_vbox = NULL;
}
hpaned = gtk_hpaned_new();
gtk_box_pack_start(GTK_BOX(vbox2), hpaned, TRUE, TRUE, 0);
gtk_paned_pack1(GTK_PANED(hpaned), ctree_swin, FALSE, FALSE);
if (prefs_common.addressbook_use_editaddress_dialog)
gtk_paned_pack2(GTK_PANED(hpaned), clist_vbox, TRUE, FALSE);
else
gtk_paned_pack2(GTK_PANED(hpaned), vpaned, TRUE, FALSE);
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Status bar */
hsbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
statusbar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
2001-09-06 12:24:20 +02:00
/* Button panel */
2001-04-19 14:21:46 +02:00
hbbox = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(hbbox), 2);
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);
gtkut_stock_button_add_help(hbbox, &help_btn);
edit_btn = gtk_button_new_from_stock(GTK_STOCK_EDIT);
GTK_WIDGET_SET_FLAGS(edit_btn, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(hbbox), edit_btn, TRUE, TRUE, 0);
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);
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);
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);
gtk_box_pack_start(GTK_BOX(hbox), lup_btn, TRUE, TRUE, 0);
2001-04-19 14:21:46 +02:00
g_signal_connect(G_OBJECT(help_btn), "clicked",
G_CALLBACK(manual_open_with_anchor_cb),
MANUAL_ANCHOR_ADDRBOOK);
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);
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));
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();
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 =
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 );
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);
addrbook.window = window;
addrbook.hpaned = hpaned;
addrbook.vpaned = vpaned;
addrbook.menubar = menubar;
addrbook.ctree = ctree;
addrbook.ctree_swin
= ctree_swin;
addrbook.editaddress_vbox = editaddress_vbox;
addrbook.clist = clist;
addrbook.label = label;
addrbook.entry = entry;
addrbook.statusbar = statusbar;
addrbook.status_cid = gtk_statusbar_get_context_id(
GTK_STATUSBAR(statusbar), "Addressbook Window" );
2001-04-19 14:21:46 +02:00
addrbook.help_btn = help_btn;
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;
addrbook.menu_factory = menu_factory;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
addrbook.listSelected = NULL;
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);
if (!prefs_common.addressbook_use_editaddress_dialog) {
gtk_paned_set_position(GTK_PANED(vpaned), prefs_common.addressbook_vpaned_pos);
g_signal_connect(G_OBJECT(vpaned), "notify::position",
G_CALLBACK(addressbook_pane_notify_position), NULL);
}
gtk_paned_set_position(GTK_PANED(hpaned), prefs_common.addressbook_hpaned_pos);
g_signal_connect(G_OBJECT(hpaned), "notify::position",
G_CALLBACK(addressbook_pane_notify_position), NULL);
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 ) {
address_completion_end(addrbook.window);
if (!prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_person_invalidate(NULL, NULL, NULL);
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.
*/
static void addressbook_status_show( gchar *msg ) {
if( addrbook.statusbar != NULL ) {
gtk_statusbar_pop(
GTK_STATUSBAR(addrbook.statusbar),
addrbook.status_cid );
if( msg ) {
gtk_statusbar_push(
GTK_STATUSBAR(addrbook.statusbar),
addrbook.status_cid, msg );
}
}
}
static void addressbook_ds_status_message( AddressDataSource *ds, gchar *msg ) {
*addressbook_msgbuf = '\0';
if( ds ) {
gchar *name;
name = addrindex_ds_get_name( ds );
g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf),
"%s: %s", name, msg );
}
else {
g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf),
"%s", msg );
}
addressbook_status_show( addressbook_msgbuf );
}
2001-09-02 01:48:06 +02:00
static void addressbook_ds_show_message( AddressDataSource *ds ) {
gint retVal;
gchar *name;
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 ) {
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 );
g_snprintf( addressbook_msgbuf,
2003-01-26 06:12:00 +01:00
sizeof(addressbook_msgbuf), "%s: %s", name, desc );
}
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;
bcc_sens = TRUE;
2001-04-19 14:21:46 +02:00
}
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);
}
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);
AddressObject *pobj;
2001-09-02 01:48:06 +02:00
AdapterDSource *ads = NULL;
GtkCTreeNode *nodeList;
2001-09-06 12:24:20 +02:00
gboolean procFlag;
2001-09-02 01:48:06 +02:00
AlertValue aval;
AddressBookFile *abf = NULL;
AddressDataSource *ds = NULL;
AddressInterface *iface;
AddrItemObject *aio;
AddrSelectItem *item;
GList *list, *node;
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);
/* Test whether anything selected for deletion */
2001-09-02 01:48:06 +02:00
nodeList = addrbook.listSelected;
aio = gtk_ctree_node_get_row_data( clist, nodeList );
if( aio == NULL) return;
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
/* Test for read only */
iface = ds->interface;
if( iface->readOnly ) {
2002-05-06 08:27:11 +02:00
alertpanel( _("Delete address(es)"),
_("This address data is readonly and cannot be deleted."),
GTK_STOCK_CLOSE, NULL, NULL );
return;
}
/* Test whether Ok to proceed */
2001-09-02 01:48:06 +02:00
procFlag = FALSE;
if( pobj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(pobj);
if( ads->subType == ADDR_BOOK ) procFlag = TRUE;
}
else if( pobj->type == ADDR_ITEM_FOLDER ) {
procFlag = TRUE;
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
procFlag = TRUE;
}
if( ! procFlag ) return;
abf = ds->rawDataSource;
if( abf == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-06 12:24:20 +02:00
/* Process deletions */
2001-09-02 01:48:06 +02:00
if( pobj->type == ADDR_DATASOURCE || pobj->type == ADDR_ITEM_FOLDER ) {
gboolean group_delete = TRUE;
2001-09-06 12:24:20 +02:00
/* Items inside folders */
list = addrselect_get_list( _addressSelect_ );
/* Confirm deletion */
node = list;
while( node ) {
item = node->data;
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
if( aio->type == ADDR_ITEM_PERSON || aio->type == ADDR_ITEM_EMAIL ) {
group_delete = FALSE;
break;
}
}
if (group_delete) {
aval = alertpanel( _("Delete group"),
_("Really delete the group(s)?\n"
"The addresses it contains will not be lost."),
GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
if( aval != G_ALERTALTERNATE ) return;
} else {
aval = alertpanel( _("Delete address(es)"),
_("Really delete the address(es)?"),
GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
if( aval != G_ALERTALTERNATE ) return;
}
node = list;
2001-09-02 01:48:06 +02:00
while( node ) {
item = node->data;
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
2001-09-02 01:48:06 +02:00
if( aio->type == ADDR_ITEM_GROUP ) {
ItemGroup *item = ( ItemGroup * ) aio;
GtkCTreeNode *nd = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
nd = addressbook_find_group_node( addrbook.opened, item );
item = addrbook_remove_group( abf, item );
if( item ) {
addritem_free_item_group( item );
}
2001-09-30 13:07:34 +02:00
/* Remove group from parent node */
2001-09-02 01:48:06 +02:00
gtk_ctree_remove_node( ctree, nd );
refreshList = TRUE;
}
2001-09-02 01:48:06 +02:00
else if( aio->type == ADDR_ITEM_PERSON ) {
ItemPerson *item = ( ItemPerson * ) aio;
addressbook_folder_remove_one_person( clist, item );
if (pobj->type == ADDR_ITEM_FOLDER)
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-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 ) {
addrcache_remove_email(abf->addressCache, item);
2001-09-02 01:48:06 +02:00
addritem_free_item_email( item );
}
addressbook_folder_refresh_one_person( clist, person );
}
2001-09-02 01:48:06 +02:00
}
g_list_free( list );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
if( refreshList ) {
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
addressbook_set_clist(
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
addrbook.opened),
TRUE);
}
addrbook_set_dirty(abf, TRUE);
addressbook_export_to_file();
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 */
list = addrselect_get_list( _addressSelect_ );
node = list;
2001-09-02 01:48:06 +02:00
while( node ) {
item = node->data;
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
2001-09-02 01:48:06 +02:00
if( aio->type == ADDR_ITEM_EMAIL ) {
ItemEMail *item = ( ItemEMail * ) aio;
ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(item);
item = addrbook_person_remove_email( abf, person, item );
if( item ) {
addritem_free_item_email( item );
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
}
g_list_free( list );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
addressbook_set_clist(
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
addrbook.opened),
TRUE);
addrbook_set_dirty(abf, TRUE);
addressbook_export_to_file();
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
gchar *addressbook_format_address( AddrItemObject * aio ) {
2001-09-02 01:48:06 +02:00
gchar *buf = NULL;
gchar *name = NULL;
gchar *address = NULL;
2001-04-19 14:21:46 +02:00
if( aio->type == ADDR_ITEM_EMAIL ) {
2001-09-02 01:48:06 +02:00
ItemPerson *person = NULL;
ItemEMail *email = ( ItemEMail * ) aio;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
person = ( ItemPerson * ) ADDRITEM_PARENT(email);
if( email->address ) {
if( ADDRITEM_NAME(email) ) {
name = ADDRITEM_NAME(email);
if( *name == '\0' ) {
name = ADDRITEM_NAME(person);
}
}
else if( ADDRITEM_NAME(person) ) {
name = ADDRITEM_NAME(person);
}
else {
buf = g_strdup( email->address );
}
address = email->address;
2001-04-19 14:21:46 +02:00
}
}
else if( aio->type == ADDR_ITEM_PERSON ) {
ItemPerson *person = ( ItemPerson * ) aio;
2001-09-02 01:48:06 +02:00
GList *node = person->listEMail;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
name = ADDRITEM_NAME(person);
if( node ) {
ItemEMail *email = ( ItemEMail * ) node->data;
address = email->address;
}
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
if( address ) {
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)
{
GList *list, *node;
Compose *compose;
AddrSelectItem *item;
AddrItemObject *aio;
2004-05-10 12:22:28 +02:00
gchar *addr;
compose = addrbook.target_compose;
if( ! compose ) return;
/* Nothing selected, but maybe there is something in text entry */
addr = (char *)gtk_entry_get_text( GTK_ENTRY( addrbook.entry) );
if ( addr ) {
compose_entry_append(
compose, addr, (ComposeEntryType)data );
}
/* Select from address list */
list = addrselect_get_list( _addressSelect_ );
node = list;
if (node) {
while( node ) {
item = node->data;
node = g_list_next( node );
aio = item->addressItem;
if( aio->type == ADDR_ITEM_PERSON ||
aio->type == ADDR_ITEM_EMAIL ) {
addr = addressbook_format_address( aio );
compose_entry_append(
compose, addr, (ComposeEntryType) data );
g_free( addr );
}
else if( aio->type == ADDR_ITEM_GROUP ) {
ItemGroup *group = ( ItemGroup * ) aio;
GList *nodeMail = group->listEMail;
while( nodeMail ) {
ItemEMail *email = nodeMail->data;
addr = addressbook_format_address(
( AddrItemObject * ) email );
compose_entry_append(
compose, addr, (ComposeEntryType) data );
g_free( addr );
nodeMail = g_list_next( nodeMail );
}
}
2001-09-02 01:48:06 +02:00
}
} else {
AddressObject *obj = NULL;
obj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
if( obj && obj->type == ADDR_ITEM_GROUP ) {
ItemGroup *itemGroup = ADAPTER_GROUP(obj)->itemGroup;
GList *nodeMail = itemGroup->listEMail;
2001-09-02 01:48:06 +02:00
while( nodeMail ) {
ItemEMail *email = nodeMail->data;
2004-05-10 12:22:28 +02:00
addr = addressbook_format_address(
( 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
}
}
}
g_list_free( list );
2001-04-19 14:21:46 +02:00
}
static void addressbook_menubar_set_sensitive( gboolean sensitive ) {
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Book/New Folder", sensitive );
menu_set_sensitive( addrbook.menu_factory, "/Address/Select all", TRUE );
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 );
gtk_widget_set_sensitive( addrbook.reg_btn, sensitive );
gtk_widget_set_sensitive( addrbook.edit_btn, sensitive );
gtk_widget_set_sensitive( addrbook.del_btn, sensitive );
}
static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode *node ) {
2001-09-02 01:48:06 +02:00
gboolean canEdit = FALSE;
gboolean 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 );
}
}
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 ) {
canAdd = canEdit = editAddress = canDelete = TRUE;
}
2001-09-02 01:48:06 +02:00
if( ! iface->haveLibrary ) {
canAdd = canEdit = editAddress = canExport = canDelete = FALSE;
}
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_FOLDER ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds ) {
iface = ds->interface;
if( iface->readOnly ) {
canEditTr = FALSE;
canDelete = FALSE;
}
else {
2001-09-02 01:48:06 +02:00
canAdd = editAddress = TRUE;
}
}
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_GROUP ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
if( ds ) {
iface = ds->interface;
if( ! iface->readOnly ) {
editAddress = TRUE;
}
}
}
2001-09-02 01:48:06 +02:00
if( addrbook.listSelected == NULL ) canEdit = FALSE;
2001-09-30 13:07:34 +02:00
/* Enable add */
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.menu_factory, "/Address/New Address", editAddress );
menu_set_sensitive( addrbook.menu_factory, "/Address/New Group", canAdd );
menu_set_sensitive( addrbook.menu_factory, "/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 );
menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canDelete );
gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", canEditTr );
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 );
}
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.
*/
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;
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 );
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-09-02 01:48:06 +02:00
ads = ADAPTER_DSOURCE(obj);
if( ads == NULL ) return;
2001-09-02 01:48:06 +02:00
ds = ads->dataSource;
if( ds == NULL ) return;
2001-09-02 01:48:06 +02:00
if( addrindex_ds_get_modify_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
2001-09-02 01:48:06 +02:00
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
addressbook_ds_show_message( ds );
if( ! addrindex_ds_get_access_flag( ds ) ) {
2001-09-06 12:24:20 +02:00
/* Remove existing folders and groups */
2001-09-02 01:48:06 +02:00
gtk_clist_freeze( GTK_CLIST(ctree) );
addressbook_tree_remove_children( ctree, node );
gtk_clist_thaw( GTK_CLIST(ctree) );
2001-09-06 12:24:20 +02:00
/* Load folders into the tree */
2001-09-02 01:48:06 +02:00
rootFolder = addrindex_ds_get_root_folder( ds );
if( ds->type == ADDR_IF_JPILOT ) {
2003-09-07 21:28:56 +02:00
aot = ADDR_CATEGORY;
}
else if( ds->type == ADDR_IF_LDAP ) {
aot = ADDR_LDAP_QUERY;
}
else {
2003-09-07 21:28:56 +02:00
aot = ADDR_ITEM_FOLDER;
}
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 );
}
} else {
addressbook_set_clist(NULL, TRUE);
}
2001-09-02 01:48:06 +02:00
2001-09-30 13:07:34 +02:00
/* Update address list */
g_signal_handlers_block_by_func
(G_OBJECT(ctree),
G_CALLBACK(addressbook_tree_selected), NULL);
addressbook_set_clist( obj, FALSE );
g_signal_handlers_unblock_by_func
(G_OBJECT(ctree),
G_CALLBACK(addressbook_tree_selected), NULL);
if (!prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_person_invalidate(NULL, NULL, NULL);
2001-09-06 12:24:20 +02:00
/* Setup main menu selections */
addressbook_menubar_set_sensitive( FALSE );
addressbook_list_menu_setup();
addressbook_menuitem_set_sensitive( obj, node );
2001-09-02 01:48:06 +02:00
addressbook_list_select_clear();
addressbook_list_menu_setup();
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.
*/
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;
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) );
menu_set_sensitive( addrbook.list_factory, "/Select all", TRUE );
if( pobj->type == ADDR_DATASOURCE ) {
2004-01-12 22:28:31 +01:00
/* Parent object is a data source */
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;
}
canDelete = canEdit;
}
else if( pobj->type != ADDR_INTERFACE ) {
2004-01-12 22:28:31 +01:00
/* Parent object is not an interface */
ds = addressbook_find_datasource( addrbook.treeSelected );
iface = ds->interface;
if( ! iface->readOnly ) {
2004-01-12 22:28:31 +01:00
/* Folder or group */
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 */
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;
canDelete = canEdit;
}
2004-01-12 22:28:31 +01:00
if( iface->type == ADDR_IF_LDAP ) {
if( obj ) canBrowse = TRUE;
canEdit = TRUE;
canDelete = FALSE;
2004-01-12 22:28:31 +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;
}
2004-01-12 22:28:31 +01:00
/* Now go finalize menu items */
menu_set_sensitive( addrbook.list_factory, "/Edit", canEdit );
menu_set_sensitive( addrbook.list_factory, "/Delete", canDelete );
menu_set_sensitive( addrbook.list_factory, "/Cut", canCut );
menu_set_sensitive( addrbook.list_factory, "/Copy", canCopy );
menu_set_sensitive( addrbook.list_factory, "/Paste", canPaste );
/* menu_set_sensitive( addrbook.list_factory, "/Paste Address", canPaste );*/
2004-05-10 12:22:28 +02:00
menu_set_sensitive( addrbook.list_factory, "/Mail To", canCopy );
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 );*/
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 );
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 );
gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
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
}
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
/**
* 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.
*/
static void addressbook_treenode_add_list(
GtkCTreeNode *treeNode, AddressDataSource *ds, GList *listItems )
{
GList *node;
node = listItems;
while( node ) {
AddrItemObject *aio;
GtkCTreeNode *nn;
aio = node->data;
if( ADDRESS_OBJECT_TYPE(aio) == ITEMTYPE_GROUP ) {
ItemGroup *group;
group = ( ItemGroup * ) aio;
nn = addressbook_node_add_group( treeNode, ds, group );
2001-04-19 14:21:46 +02:00
}
else if( ADDRESS_OBJECT_TYPE(aio) == ITEMTYPE_FOLDER ) {
ItemFolder *folder;
folder = ( ItemFolder * ) aio;
nn = addressbook_node_add_folder(
treeNode, ds, folder, ADDR_ITEM_FOLDER );
2001-09-02 01:48:06 +02:00
}
node = g_list_next( node );
2001-04-19 14:21:46 +02:00
}
}
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.
*/
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.
*/
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.
*/
static void addressbook_clip_paste_cb( void ) {
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
AddressObject *pobj = NULL;
AddressDataSource *ds = NULL;
AddressBookFile *abf = NULL;
ItemFolder *folder = NULL;
GList *folderGroup = NULL;
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
if( addrindex_ds_get_readonly( ds ) ) {
addressbook_ds_status_message(
ds, _( "Cannot paste. Target address book is readonly." ) );
return;
}
pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
if( pobj ) {
if( pobj->type == ADDR_ITEM_FOLDER ) {
folder = ADAPTER_FOLDER(pobj)->itemFolder;
}
else if( pobj->type == ADDR_ITEM_GROUP ) {
addressbook_ds_status_message(
ds, _( "Cannot paste into an address group." ) );
return;
}
}
/* Get an address book */
abf = addressbook_get_book_file();
if( abf == NULL ) return;
if( _clipBoard_->cutFlag ) {
/* Paste/Cut */
folderGroup = addrclip_paste_cut( _clipBoard_, abf, folder );
/* Remove all groups and folders in clipboard from tree node */
addressbook_treenode_remove_item();
/* Remove all "cut" items */
addrclip_delete_item( _clipBoard_ );
/* Clear clipboard - cut items??? */
addrclip_clear( _clipBoard_ );
2001-04-19 14:21:46 +02:00
}
else {
/* Paste/Copy */
folderGroup = addrclip_paste_copy( _clipBoard_, abf, folder );
}
/* addrclip_list_show( _clipBoard_, stdout ); */
if( folderGroup ) {
/* Update tree by inserting node for each folder or group */
addressbook_treenode_add_list(
addrbook.treeSelected, ds, folderGroup );
gtk_ctree_expand( ctree, addrbook.treeSelected );
g_list_free( folderGroup );
folderGroup = NULL;
}
/* Display items pasted */
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
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
/**
* Add current treenode object to clipboard. Note that widget only allows
* one entry from the tree list to be selected.
*/
static void addressbook_treenode_to_clipboard( void ) {
AddressObject *obj = NULL;
AddressDataSource *ds = NULL;
AddrSelectItem *item;
GtkCTree *ctree = GTK_CTREE( addrbook.ctree );
GtkCTreeNode *node;
node = addrbook.treeSelected;
if( node == NULL ) return;
obj = gtk_ctree_node_get_row_data( ctree, node );
2001-09-02 01:48:06 +02:00
if( obj == NULL ) return;
ds = addressbook_find_datasource( node );
if( ds == NULL ) return;
item = NULL;
if( obj->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
ItemFolder *folder = adapter->itemFolder;
item = addrselect_create_node( obj );
item->uid = g_strdup( ADDRITEM_ID(folder) );
2001-09-02 01:48:06 +02:00
}
else if( obj->type == ADDR_ITEM_GROUP ) {
AdapterGroup *adapter = ADAPTER_GROUP(obj);
ItemGroup *group = adapter->itemGroup;
item = addrselect_create_node( obj );
item->uid = g_strdup( ADDRITEM_ID(group) );
}
else if( obj->type == ADDR_DATASOURCE ) {
/* Data source */
item = addrselect_create_node( obj );
item->uid = NULL;
}
if( item ) {
/* Clear existing list and add item into list */
gchar *cacheID;
addressbook_list_select_clear();
cacheID = addrindex_get_cache_id( _addressIndex_, ds );
addrselect_list_add( _addressSelect_, item, cacheID );
g_free( cacheID );
}
}
2004-01-12 22:28:31 +01:00
/**
* Cut from tree widget.
*/
static void addressbook_treenode_cut_cb( void ) {
_clipBoard_->cutFlag = TRUE;
addressbook_treenode_to_clipboard();
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
2004-01-12 22:28:31 +01:00
/**
* Copy from tree widget.
*/
static void addressbook_treenode_copy_cb( void ) {
_clipBoard_->cutFlag = FALSE;
addressbook_treenode_to_clipboard();
addrclip_clear( _clipBoard_ );
addrclip_add( _clipBoard_, _addressSelect_ );
/* addrclip_list_show( _clipBoard_, stdout ); */
}
2004-01-12 22:28:31 +01:00
/**
* Paste clipboard into address tree widget.
*/
static void addressbook_treenode_paste_cb( void ) {
addressbook_clip_paste_cb();
}
2004-01-12 22:28:31 +01:00
/**
* Clear selected entries in clipboard.
*/
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.
*/
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.
*/
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;
}
}
static void addressbook_list_row_selected( GtkCTree *clist,
GtkCTreeNode *node,
gint column,
gpointer data )
{
2001-09-02 01:48:06 +02:00
GtkEntry *entry = GTK_ENTRY(addrbook.entry);
AddrItemObject *aio = NULL;
2001-09-02 01:48:06 +02:00
AddressObject *pobj = NULL;
AdapterDSource *ads = NULL;
AddressDataSource *ds = NULL;
gtk_entry_set_text( entry, "" );
addrbook.listSelected = node;
pobj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
if( pobj == NULL ) return;
if( pobj->type == ADDR_DATASOURCE ) {
ads = ADAPTER_DSOURCE(pobj);
ds = ads->dataSource;
}
else if( pobj->type != ADDR_INTERFACE ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
}
2001-04-19 14:21:46 +02:00
aio = gtk_ctree_node_get_row_data( clist, node );
if( aio ) {
/* printf( "list select: %d : '%s'\n", aio->type, aio->name ); */
addressbook_list_select_add( aio, ds );
}
2001-04-19 14:21:46 +02:00
addressbook_list_menu_setup();
if (!addrbook.target_compose && !prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_address(NULL, 0, NULL, FALSE);
2001-09-02 01:48:06 +02:00
}
static void addressbook_list_row_unselected( GtkCTree *ctree,
GtkCTreeNode *node,
gint column,
gpointer data )
{
AddrItemObject *aio;
2001-09-02 01:48:06 +02:00
aio = gtk_ctree_node_get_row_data( ctree, node );
if( aio != NULL ) {
/* printf( "list unselect: %d : '%s'\n", aio->type, aio->name ); */
addressbook_list_select_remove( aio );
2001-04-19 14:21:46 +02:00
}
if (!prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_person_invalidate(NULL, NULL, NULL);
2001-09-02 01:48:06 +02:00
}
2001-04-19 14:21:46 +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
{
static guint32 lasttime = 0;
2003-10-05 12:10:30 +02:00
if( ! event ) return FALSE;
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 );
} 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
if (prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_address_cb(NULL, 0, NULL);
lasttime = 0;
} else
lasttime = event->time;
}
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;
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;
GtkCTreeNode *node = NULL;
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 );
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
}
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;
node = gtk_ctree_node_nth(GTK_CTREE(clist), row);
if( ! addrclip_is_empty( _clipBoard_ ) ) {
canTreePaste = TRUE;
}
if (obj->type == ADDR_INTERFACE) {
AdapterInterface *adapter = ADAPTER_INTERFACE(obj);
iface = adapter->interface;
canEdit = FALSE;
canDelete = FALSE;
canTreeCopy = FALSE;
if( iface->readOnly ) {
canTreePaste = FALSE;
}
else {
menu_set_sensitive( addrbook.tree_factory, "/New Book", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
if( iface->externalQuery ) canLookup = TRUE;
}
2001-09-02 01:48:06 +02:00
if (obj->type == ADDR_DATASOURCE) {
ads = ADAPTER_DSOURCE(obj);
ds = ads->dataSource;
if (!ds)
goto just_set_sens;
2001-09-02 01:48:06 +02:00
iface = ds->interface;
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;
if( iface->readOnly ) {
canTreePaste = FALSE;
}
else {
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
canTreeCopy = TRUE;
2003-09-07 21:28:56 +02:00
if( iface->externalQuery ) canLookup = TRUE;
}
2001-09-02 01:48:06 +02:00
else if (obj->type == ADDR_ITEM_FOLDER) {
ds = addressbook_find_datasource( node );
if (!ds) {
goto just_set_sens;
}
2001-09-02 01:48:06 +02:00
iface = ds->interface;
if (!iface)
goto just_set_sens;
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;
canTreeCut = TRUE;
2001-09-02 01:48:06 +02:00
menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
2001-09-02 01:48:06 +02:00
gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
}
canTreeCopy = TRUE;
2004-01-12 22:28:31 +01:00
if( iface->externalQuery ) {
/* Enable deletion of LDAP folder */
canLookup = TRUE;
canDelete = TRUE;
}
}
2001-09-02 01:48:06 +02:00
else if (obj->type == ADDR_ITEM_GROUP) {
ds = addressbook_find_datasource( node );
if (!ds)
goto just_set_sens;
2001-09-02 01:48:06 +02:00
iface = ds->interface;
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;
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 );
}
}
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
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 );
menu_set_sensitive( addrbook.tree_factory, "/Cut", canTreeCut );
menu_set_sensitive( addrbook.tree_factory, "/Copy", canTreeCopy );
menu_set_sensitive( addrbook.tree_factory, "/Paste", canTreePaste );
menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book", canEdit );
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
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-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 )
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 )
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);
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;
GtkCTreeNode *node = NULL, *parentNode = NULL;
2001-09-02 01:48:06 +02:00
gchar *name = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( ! addrbook.treeSelected ) return;
node = addrbook.treeSelected;
if( GTK_CTREE_ROW(node)->level == 1 ) return;
obj = gtk_ctree_node_get_row_data( ctree, node );
if( obj == NULL ) return;
parentNode = GTK_CTREE_ROW(node)->parent;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
ds = addressbook_find_datasource( node );
if( ds == NULL ) return;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
name = addressbook_edit_datasource( obj, node );
if( name == NULL ) return;
}
2001-09-02 01:48:06 +02:00
else {
abf = ds->rawDataSource;
if( abf == NULL ) return;
if( obj->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *adapter = ADAPTER_FOLDER(obj);
ItemFolder *item = adapter->itemFolder;
ItemFolder *parentFolder = NULL;
parentFolder = ( ItemFolder * ) ADDRITEM_PARENT(item);
if( addressbook_edit_folder( abf, parentFolder, item ) == NULL ) return;
name = ADDRITEM_NAME(item);
}
else if( obj->type == ADDR_ITEM_GROUP ) {
AdapterGroup *adapter = ADAPTER_GROUP(obj);
ItemGroup *item = adapter->itemGroup;
ItemFolder *parentFolder = NULL;
parentFolder = ( ItemFolder * ) ADDRITEM_PARENT(item);
if( addressbook_edit_group( abf, parentFolder, item ) == NULL ) return;
name = ADDRITEM_NAME(item);
}
}
if( name && parentNode ) {
2001-09-06 12:24:20 +02:00
/* Update node in tree view */
2001-09-02 01:48:06 +02:00
addressbook_change_node_name( node, name );
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 );
gtk_sctree_select( GTK_SCTREE( ctree), node );
}
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-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 " \
"results and addresses in '%s' ?" ),
2004-01-12 22:28:31 +01:00
obj->name );
aval = alertpanel( _("Delete"), message,
GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
2004-01-12 22:28:31 +01:00
g_free(message);
if( aval == G_ALERTALTERNATE ) {
2004-01-12 22:28:31 +01:00
delType = ADDRTREE_DEL_FOLDER_ADDR;
}
}
else {
message = g_strdup_printf
( _( "Do you want to delete '%s' ?"
"If you delete the folder only, the addresses it contains will be moved into the parent folder." ),
obj->name );
aval = alertpanel( _("Delete folder"), message,
GTK_STOCK_CANCEL, _("+Delete _folder only"), _("Delete folder and _addresses"));
2004-01-12 22:28:31 +01:00
g_free(message);
if( aval == G_ALERTALTERNATE ) {
2004-01-12 22:28:31 +01:00
delType = ADDRTREE_DEL_FOLDER_ONLY;
}
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 if( obj->type == ADDR_ITEM_GROUP ) {
message = g_strdup_printf(_("Do you want to delete '%s'?\n"
"The addresses it contains will not be lost."), obj->name);
aval = alertpanel(_("Delete"), message, GTK_STOCK_CANCEL,
"+" GTK_STOCK_DELETE, NULL);
g_free(message);
if( aval == G_ALERTALTERNATE ) delType = ADDRTREE_DEL_FOLDER_ONLY;
} else {
message = g_strdup_printf(_("Do you want to delete '%s'?\n"
"The addresses it contains will be lost."), obj->name);
aval = alertpanel(_("Delete"), message, GTK_STOCK_CANCEL,
"+" GTK_STOCK_DELETE, NULL);
2001-09-02 01:48:06 +02:00
g_free(message);
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 ) ) {
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 ) {
/* Remove node. */
2001-09-02 01:48:06 +02:00
gtk_ctree_remove_node(ctree, node );
}
2001-04-19 14:21:46 +02:00
}
void addressbook_new_address_from_book_post_cb( ItemPerson *person )
{
if( person && addrbook.treeSelected == addrbook.opened ) {
gtk_clist_unselect_all( GTK_CLIST(addrbook.clist) );
addressbook_folder_refresh_one_person(
GTK_CTREE(addrbook.clist), person );
}
addressbook_address_list_set_focus();
}
void addressbook_new_address_from_folder_post_cb( ItemPerson *person )
{
if( person && addrbook.treeSelected == addrbook.opened) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
addressbook_set_clist(
gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
addrbook.opened),
TRUE);
}
addressbook_address_list_set_focus();
}
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 */
ItemPerson *person = addressbook_edit_person( abf, NULL, NULL, FALSE,
addrbook.editaddress_vbox,
addressbook_new_address_from_book_post_cb,
TRUE );
if (prefs_common.addressbook_use_editaddress_dialog)
addressbook_new_address_from_book_post_cb( 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,
addrbook.editaddress_vbox,
addressbook_new_address_from_folder_post_cb,
TRUE );
if (prefs_common.addressbook_use_editaddress_dialog)
addressbook_new_address_from_folder_post_cb( person );
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) );
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
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 ) {
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
}
}
void addressbook_edit_address_post_cb( ItemPerson *person )
{
if( person ) {
addressbook_folder_refresh_one_person( GTK_CTREE(addrbook.clist), person );
invalidate_address_completion();
}
addressbook_address_list_set_focus();
}
void addressbook_address_list_set_focus( void )
{
if (!prefs_common.addressbook_use_editaddress_dialog) {
gtk_window_set_focus(GTK_WINDOW(addrbook.window), addrbook.clist);
fprintf(stderr, "addressbook_address_list_set_focus: %p\n", addrbook.listSelected );
}
}
2001-09-02 01:48:06 +02:00
static void addressbook_edit_address_cb( gpointer data, guint action, GtkWidget *widget ) {
addressbook_edit_address(data, action, widget, TRUE);
}
static void addressbook_edit_address( gpointer data, guint action, GtkWidget *widget,
gboolean force_focus ) {
2001-09-02 01:48:06 +02:00
GtkCTree *clist = GTK_CTREE(addrbook.clist);
GtkCTree *ctree;
2001-09-02 01:48:06 +02:00
AddressObject *obj = NULL, *pobj = NULL;
AddressDataSource *ds = NULL;
GtkCTreeNode *node = NULL, *parentNode = NULL;
2001-09-02 01:48:06 +02:00
gchar *name = NULL;
AddressBookFile *abf = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
if( addrbook.listSelected == NULL ) return;
obj = gtk_ctree_node_get_row_data( clist, addrbook.listSelected );
2001-04-19 14:21:46 +02:00
g_return_if_fail(obj != NULL);
2001-09-02 01:48:06 +02:00
ctree = GTK_CTREE( addrbook.ctree );
pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
node = gtk_ctree_find_by_row_data( ctree, addrbook.treeSelected, obj );
ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
if( ds == NULL ) return;
abf = addressbook_get_book_file();
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;
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 */
ItemPerson *person;
2001-09-02 01:48:06 +02:00
person = ( ItemPerson * ) ADDRITEM_PARENT(email);
if ( addressbook_edit_person( abf, NULL, person, TRUE, addrbook.editaddress_vbox,
addressbook_edit_address_post_cb,
(prefs_common.addressbook_use_editaddress_dialog||force_focus) )
!= NULL ) {
if (prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_address_post_cb( person );
}
2001-09-02 01:48:06 +02:00
return;
}
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_PERSON ) {
2001-09-06 12:24:20 +02:00
/* Edit person - basic page */
2001-09-02 01:48:06 +02:00
ItemPerson *person = ( ItemPerson * ) obj;
if( addressbook_edit_person( abf, NULL, person, FALSE, addrbook.editaddress_vbox,
addressbook_edit_address_post_cb,
(prefs_common.addressbook_use_editaddress_dialog||force_focus) )
!= NULL ) {
if (prefs_common.addressbook_use_editaddress_dialog)
addressbook_edit_address_post_cb( person );
}
2001-09-02 01:48:06 +02:00
return;
}
2001-09-02 01:48:06 +02:00
else if( obj->type == ADDR_ITEM_GROUP ) {
ItemGroup *itemGrp = ( ItemGroup * ) obj;
if( addressbook_edit_group( abf, NULL, itemGrp ) == NULL ) return;
parentNode = addrbook.treeSelected;
node = addressbook_find_group_node( parentNode, itemGrp );
name = ADDRITEM_NAME(itemGrp);
invalidate_address_completion();
}
else {
return;
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Update tree node with node name */
2001-09-02 01:48:06 +02:00
if( node == NULL ) return;
addressbook_change_node_name( node, name );
2002-07-09 11:57:45 +02:00
gtk_sctree_sort_node( ctree, parentNode );
gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
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)
{
gtk_clist_freeze(GTK_CLIST(addrbook.clist));
2001-04-19 14:21:46 +02:00
addressbook_del_clicked(NULL, NULL);
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-09-02 01:48:06 +02:00
}
static gchar *addressbook_format_item_clist( ItemPerson *person, ItemEMail *email ) {
gchar *str = NULL;
gchar *eMailAlias = ADDRITEM_NAME(email);
if( eMailAlias && *eMailAlias != '\0' ) {
if( person ) {
str = g_strdup_printf( "%s - %s", ADDRITEM_NAME(person), eMailAlias );
}
else {
str = g_strdup( eMailAlias );
}
}
2001-09-02 01:48:06 +02:00
return str;
}
static void addressbook_load_group( GtkCTree *clist, ItemGroup *itemGroup ) {
GList *items = itemGroup->listEMail;
AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_EMAIL );
for( ; items != NULL; items = g_list_next( items ) ) {
GtkCTreeNode *nodeEMail = NULL;
gchar *text[N_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;
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 )
{
GtkCTreeNode *nodePerson = NULL;
GtkCTreeNode *nodeEMail = NULL;
gchar *text[N_LIST_COLS];
gboolean flgFirst = TRUE, haveAddr = FALSE;
GList *node;
2001-04-19 14:21:46 +02:00
if( person == NULL ) return;
2001-04-19 14:21:46 +02:00
text[COL_NAME] = "";
node = person->listEMail;
while( node ) {
ItemEMail *email = node->data;
gchar *eMailAddr = NULL;
node = g_list_next( node );
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 {
text[COL_NAME] = ADDRITEM_NAME(person);
2001-09-02 01:48:06 +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 );
g_free( str );
str = NULL;
2001-09-02 01:48:06 +02:00
gtk_ctree_node_set_row_data(clist, nodePerson, person );
}
else {
/* Subsequent email is a child node of person */
text[COL_NAME] = ADDRITEM_NAME(email);
nodeEMail = gtk_sctree_insert_node(
clist, nodePerson, NULL,
text, FOLDER_SPACING,
atciMail->iconXpm, atciMail->maskXpm,
atciMail->iconXpmOpen, atciMail->maskXpmOpen,
FALSE, TRUE );
gtk_ctree_node_set_row_data(clist, nodeEMail, email );
}
flgFirst = FALSE;
haveAddr = TRUE;
}
if( ! haveAddr ) {
/* Have name without EMail */
text[COL_NAME] = ADDRITEM_NAME(person);
text[COL_ADDRESS] = "";
text[COL_REMARKS] = "";
nodePerson = gtk_sctree_insert_node(
clist, NULL, NULL,
text, FOLDER_SPACING,
atci->iconXpm, atci->maskXpm,
atci->iconXpmOpen, atci->maskXpmOpen,
FALSE, person->isOpened );
gtk_ctree_node_set_row_data(clist, nodePerson, person );
}
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 );
}
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 );
}
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 );
gtk_sctree_sort_node( clist, NULL );
node = gtk_ctree_find_by_row_data( clist, NULL, person );
if( node ) {
gtk_sctree_select( GTK_SCTREE(clist), node );
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;
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] = "";
text[COL_REMARKS] = "";
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.
*/
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.
*/
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 ) {
/* printf( "ao->type = %d\n", ao->type ); */
2001-09-02 01:48:06 +02:00
if( ao->type == ADDR_DATASOURCE ) {
AdapterDSource *ads = ADAPTER_DSOURCE(ao);
/* printf( "found it\n" ); */
2001-09-02 01:48:06 +02:00
ds = ads->dataSource;
break;
}
}
node = GTK_CTREE_ROW(node)->parent;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
return ds;
}
2001-04-19 14:21:46 +02:00
2004-01-12 22:28:31 +01:00
/**
* Load address list widget with children of specified object.
* \param obj Parent object to be loaded.
*/
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;
static AddressObject *last_obj = NULL;
if (addrbook.clist == NULL) {
return;
}
if (obj == last_obj && !refresh)
return;
2001-04-19 14:21:46 +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" ); */
/* 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
}
}
gtk_sctree_sort_recursive(GTK_CTREE(clist), NULL);
clist->focus_row = -1;
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.
*/
static void addressbook_free_treenode( gpointer data ) {
2001-09-02 01:48:06 +02:00
AddressObject *ao;
ao = ( AddressObject * ) data;
if( ao == NULL ) return;
if( ao->type == ADDR_INTERFACE ) {
AdapterInterface *ai = ADAPTER_INTERFACE(ao);
addrbookctl_free_interface( ai );
}
else if( ao->type == ADDR_DATASOURCE ) {
AdapterDSource *ads = ADAPTER_DSOURCE(ao);
addrbookctl_free_datasource( ads );
}
else if( ao->type == ADDR_ITEM_FOLDER ) {
AdapterFolder *af = ADAPTER_FOLDER(ao);
addrbookctl_free_folder( af );
}
else if( ao->type == ADDR_ITEM_GROUP ) {
AdapterGroup *ag = ADAPTER_GROUP(ao);
addrbookctl_free_group( ag );
2001-04-19 14:21:46 +02:00
}
}
2001-09-02 01:48:06 +02:00
/*
* Create new adaptor for specified data source.
2001-09-02 01:48:06 +02:00
*/
AdapterDSource *addressbook_create_ds_adapter( AddressDataSource *ds,
AddressObjectType otype, gchar *name )
{
AdapterDSource *adapter = g_new0( AdapterDSource, 1 );
ADDRESS_OBJECT(adapter)->type = ADDR_DATASOURCE;
ADDRESS_OBJECT_NAME(adapter) = g_strdup( name );
adapter->dataSource = ds;
adapter->subType = otype;
return adapter;
}
2001-09-02 01:48:06 +02:00
void addressbook_ads_set_name( AdapterDSource *adapter, gchar *value ) {
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-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"
"could not save new address index file." );
2001-09-02 01:48:06 +02:00
}
}
else {
2001-09-06 12:24:20 +02:00
/* File conversion failed - just create new books */
2001-09-02 01:48:06 +02:00
debug_print( "File conversion failed... just create new books...\n" );
addrindex_create_new_books( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
/* Save index */
2001-09-02 01:48:06 +02:00
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_save_data( addrIndex );
if( addrIndex->retVal == MGU_SUCCESS ) {
2001-09-06 12:24:20 +02:00
msg = _("Could not convert address book,\n"
"but created empty new address book files." );
2001-09-02 01:48:06 +02:00
retVal = TRUE;
errFlag = FALSE;
}
else {
2001-09-06 12:24:20 +02:00
msg = _("Could not convert address book,\n"
"could not 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 );
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 );
alertpanel_full(_("Addressbook conversion error"), msg,
GTK_STOCK_CLOSE, NULL, NULL, FALSE,
NULL, ALERT_WARNING, G_ALERTDEFAULT);
}
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
return retVal;
}
2001-09-02 01:48:06 +02:00
void addressbook_read_file( void ) {
AddressIndex *addrIndex = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
debug_print( "Reading address index...\n" );
if( _addressIndex_ ) {
debug_print( "address book already read!!!\n" );
return;
}
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
addrIndex = addrindex_create_index();
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-09-02 01:48:06 +02:00
else if( addrIndex->retVal == MGU_SUCCESS ) {
_addressIndex_ = addrIndex;
}
2001-09-02 01:48:06 +02:00
else {
2001-09-06 12:24:20 +02:00
/* Error reading address book */
2001-09-02 01:48:06 +02:00
debug_print( "Could not read address index.\n" );
addrindex_print_index( addrIndex, stdout );
alertpanel_full(_("Addressbook Error"),
_("Could not read address index"),
GTK_STOCK_CLOSE, NULL, NULL, FALSE,
NULL, ALERT_ERROR, G_ALERTDEFAULT);
}
2001-09-02 01:48:06 +02:00
debug_print( "done.\n" );
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
/*
* Add object into the address index tree widget.
* Enter: node Parent node.
* obj Object to add.
* Return: Node that was added, or NULL if object not added.
*/
static GtkCTreeNode *addressbook_add_object(GtkCTreeNode *node,
AddressObject *obj)
2001-04-19 14:21:46 +02:00
{
2001-09-02 01:48:06 +02:00
GtkCTree *ctree = GTK_CTREE(addrbook.ctree);
GtkCTreeNode *added;
AddressObject *pobj;
AddressObjectType otype;
AddressTypeControlItem *atci = NULL;
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
g_return_val_if_fail(node != NULL, NULL);
g_return_val_if_fail(obj != NULL, NULL);
2001-04-19 14:21:46 +02:00
2001-09-02 01:48:06 +02:00
pobj = gtk_ctree_node_get_row_data(ctree, node);
g_return_val_if_fail(pobj != NULL, NULL);
2001-04-19 14:21:46 +02:00
2001-09-30 13:07:34 +02:00
/* Determine object type to be displayed */
2001-09-02 01:48:06 +02:00
if( obj->type == ADDR_DATASOURCE ) {
otype = ADAPTER_DSOURCE(obj)->subType;
2001-04-19 14:21:46 +02:00
}
2001-09-02 01:48:06 +02:00
else {
otype = obj->type;
2001-04-19 14:21:46 +02:00
}
2001-09-06 12:24:20 +02:00
/* Handle any special conditions. */
2001-09-02 01:48:06 +02:00
added = node;
atci = addrbookctl_lookup( otype );
if( atci ) {
if( atci->showInTree ) {
2001-09-06 12:24:20 +02:00
/* Add object to tree */
2001-09-02 01:48:06 +02:00
gchar **name;
name = &obj->name;
added = gtk_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 );
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;
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 );
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-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);
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 );
}
/* 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
}
static gboolean addressbook_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
2001-04-19 14:21:46 +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
/*
* Comparison using cell contents (text in first column). Used for sort
* address index widget.
2001-09-02 01:48:06 +02:00
*/
static gint addressbook_treenode_compare_func(
GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
2001-04-19 14:21:46 +02:00
{
2001-09-02 01:48:06 +02:00
GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
gchar *name1 = NULL, *name2 = NULL;
if( cell1 ) name1 = cell1->u.text;
if( cell2 ) name2 = cell2->u.text;
if( ! name1 ) return ( name2 != NULL );
if( ! name2 ) return -1;
return 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;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_BOOK );
if( adapter == NULL ) return;
ads = addressbook_edit_book( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
static void addressbook_new_vcard_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_VCARD );
if( adapter == NULL ) return;
ads = addressbook_edit_vcard( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
#ifdef USE_JPILOT
static void addressbook_new_jpilot_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
AddressInterface *iface;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_JPILOT );
if( adapter == NULL ) return;
iface = adapter->interface;
if( ! iface->haveLibrary ) return;
ads = addressbook_edit_jpilot( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
#endif
#ifdef USE_LDAP
static void addressbook_new_ldap_cb( gpointer data, guint action, GtkWidget *widget ) {
2001-09-02 01:48:06 +02:00
AdapterDSource *ads;
AdapterInterface *adapter;
AddressInterface *iface;
GtkCTreeNode *newNode;
2001-09-02 01:48:06 +02:00
adapter = addrbookctl_find_interface( ADDR_IF_LDAP );
if( adapter == NULL ) return;
iface = adapter->interface;
if( ! iface->haveLibrary ) return;
ads = addressbook_edit_ldap( _addressIndex_, NULL );
if( ads ) {
newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
addrbook.treeSelected = newNode;
}
}
}
2003-09-07 21:28:56 +02:00
#endif
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;
*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
}
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( "" );
}
}
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 ) {
AddressObject *obj;
2003-09-07 21:28:56 +02:00
GtkCTree *ctree;
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 );
if( obj == NULL ) return;
addressbook_set_clist( obj, TRUE );
}
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
}
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 ) {
g_idle_remove_by_data( ptrQID );
2004-05-10 12:22:28 +02:00
}
}
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 ) {
g_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;
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 ) {
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 = g_idle_add(
2003-09-07 21:28:56 +02:00
( 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
}
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.
*/
static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
2003-09-07 21:28:56 +02:00
GtkCTree *ctree;
AddressObject *obj;
2003-09-07 21:28:56 +02:00
AddressDataSource *ds;
AddressInterface *iface;
gchar *searchTerm;
GtkCTreeNode *node, *parentNode;
2003-09-07 21:28:56 +02:00
node = addrbook.treeSelected;
if( ! node ) return;
if( GTK_CTREE_ROW(node)->level == 1 ) return;
2003-09-07 21:28:56 +02:00
ctree = GTK_CTREE(addrbook.ctree);
obj = gtk_ctree_node_get_row_data( ctree, node );
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;
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 );
2004-05-10 12:22:28 +02:00
gtk_widget_grab_focus( addrbook.entry );
2003-09-07 21:28:56 +02:00
g_free( searchTerm );
2001-05-02 20:26:06 +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
/*
* 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;
default: ioType = ITEMTYPE_NONE; break;
}
return ioType;
}
2001-09-02 01:48:06 +02:00
/*
* Build table that controls the rendering of object types.
*/
void addrbookctl_build_map( GtkWidget *window ) {
AddressTypeControlItem *atci;
2001-05-02 20:26:06 +02:00
2001-09-30 13:07:34 +02:00
/* Build icons */
2001-12-22 01:30:32 +01:00
stock_pixmap_gdk(window, STOCK_PIXMAP_DIR_CLOSE, &folderxpm, &folderxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_DIR_OPEN, &folderopenxpm, &folderopenxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_GROUP, &groupxpm, &groupxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_VCARD, &vcardxpm, &vcardxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_BOOK, &bookxpm, &bookxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_ADDRESS, &addressxpm, &addressxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_JPILOT, &jpilotxpm, &jpilotxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_CATEGORY, &categoryxpm, &categoryxpmmask);
stock_pixmap_gdk(window, STOCK_PIXMAP_LDAP, &ldapxpm, &ldapxpmmask);
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;
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 );
/* vCard */
2001-09-02 01:48:06 +02:00
atci = g_new0( AddressTypeControlItem, 1 );
atci->objectType = ADDR_VCARD;
atci->interfaceType = ADDR_IF_VCARD;
atci->showInTree = TRUE;
atci->treeExpand = TRUE;
atci->treeLeaf = TRUE;
atci->displayName = _( "vCard" );
2001-09-02 01:48:06 +02:00
atci->iconXpm = vcardxpm;
atci->maskXpm = vcardxpmmask;
atci->iconXpmOpen = vcardxpm;
atci->maskXpmOpen = vcardxpmmask;
atci->menuCommand = "/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 );
/* 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;
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;
atci->displayName = _( "LDAP servers" );
2001-09-02 01:48:06 +02:00
atci->iconXpm = ldapxpm;
atci->maskXpm = ldapxpmmask;
atci->iconXpmOpen = ldapxpm;
atci->maskXpmOpen = ldapxpmmask;
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();
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
}
/* ***********************************************************************
* Book/folder selection.
* ***********************************************************************
*/
/*
* This function is used by the matcher dialog to select a book/folder.
*/
gboolean addressbook_folder_selection( gchar **folderpath )
{
AddressBookFile *book = NULL;
ItemFolder *folder = NULL;
gchar *path;
g_return_val_if_fail( folderpath != NULL, FALSE);
path = *folderpath;
*folderpath = NULL;
if ( addressbook_foldersel_selection( _addressIndex_, &book, &folder, path )
&& book != NULL ) {
if ( folder != NULL) {
gchar *tmp = NULL;
gchar *oldtmp = NULL;
AddrItemObject *obj = NULL;
/* walk thru folder->parent to build the full folder path */
/* TODO: wwp: optimize this */
obj = &folder->obj;
tmp = g_strdup(obj->uid);
while ( obj->parent ) {
obj = obj->parent;
if ( obj->name != NULL ) {
oldtmp = g_strdup(tmp);
g_free(tmp);
tmp = g_strdup_printf("%s/%s", obj->uid, oldtmp);
g_free(oldtmp);
}
}
*folderpath = g_strdup_printf("%s/%s", book->fileName, tmp);
g_free(tmp);
} else {
*folderpath = g_strdup_printf("%s", book->fileName);
}
debug_print( "addressbook_foldersel: %s\n", *folderpath);
return (*folderpath != NULL);
}
return FALSE;
}
/* ***********************************************************************
* Book/folder checking.
* ***********************************************************************
*/
static FolderInfo *addressbook_peek_subfolder_exists_create_folderinfo( AddressBookFile *abf, ItemFolder *folder )
{
FolderInfo *fi = g_new0( FolderInfo, 1 );
fi->book = abf;
fi->folder = folder;
return fi;
}
static void addressbook_peek_subfolder_exists_load_folder( ItemFolder *parentFolder,
FolderInfo *fiParent, FolderPathMatch *match )
{
GList *list;
ItemFolder *folder;
gchar *fName;
FolderInfo *fi;
FolderPathMatch *nextmatch = NULL;
list = parentFolder->listFolder;
while ( list ) {
folder = list->data;
fName = g_strdup( ADDRITEM_NAME(folder) );
/* match folder name, match pointer will be set to NULL if next recursive call
doesn't need to match subfolder name */
if ( match != NULL &&
match->matched == FALSE ) {
if ( strcmp(match->folder_path[match->index], folder->obj.uid) == 0 ) {
/* folder name matches, prepare next subfolder match */
debug_print("matched folder name '%s'\n", fName);
match->index++;
if ( match->folder_path[match->index] == NULL ) {
/* we've matched all elements */
match->matched = TRUE;
match->folder = folder;
debug_print("book/folder path matched!\n");
} else {
/* keep on matching */
nextmatch = match;
}
}
}
g_free( fName );
fi = addressbook_peek_subfolder_exists_create_folderinfo( fiParent->book, folder );
addressbook_peek_subfolder_exists_load_folder( folder, fi, nextmatch );
list = g_list_next( list );
}
}
/*
* This function is used by to check if a matcher book/folder path corresponds to an
existing addressbook book/folder ("" or "Any" are considered as valid, NULL invalid).
*/
gboolean addressbook_peek_folder_exists( gchar *folderpath,
AddressDataSource **book,
ItemFolder **folder )
{
AddressDataSource *ds;
GList *list, *nodeDS;
ItemFolder *rootFolder;
AddressBookFile *abf;
FolderInfo *fi;
FolderPathMatch folder_path_match = { NULL, FALSE, 0, NULL, NULL };
FolderPathMatch *nextmatch;
if ( book )
*book = NULL;
if ( folder )
*folder = NULL;
if ( folderpath == NULL )
return FALSE;
if ( strcasecmp(folderpath, _("Any")) == 0 || *folderpath == '\0' )
return TRUE;
/* split the folder path we've received, we'll try to match this path, subpath by
subpath against the book/folder structure in order */
folder_path_match.folder_path = g_strsplit( folderpath, "/", 256 );
list = addrindex_get_interface_list( _addressIndex_ );
while ( list ) {
AddressInterface *interface = list->data;
if ( interface->type == ADDR_IF_BOOK ) {
nodeDS = interface->listSource;
while ( nodeDS ) {
ds = nodeDS->data;
/* Read address book */
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
}
/* Add node for address book */
abf = ds->rawDataSource;
/* try to match subfolders if this book is the right book
(and if there's smth to match, and not yet matched) */
nextmatch = NULL;
if ( folder_path_match.folder_path != NULL &&
folder_path_match.matched == FALSE &&
strcmp(folder_path_match.folder_path[0], abf->fileName) == 0 ) {
debug_print("matched book name '%s'\n", abf->fileName);
folder_path_match.index = 1;
if ( folder_path_match.folder_path[folder_path_match.index] == NULL ) {
/* we've matched all elements */
folder_path_match.matched = TRUE;
folder_path_match.book = ds;
debug_print("book path matched!\n");
} else {
/* keep on matching */
nextmatch = &folder_path_match;
}
}
fi = addressbook_peek_subfolder_exists_create_folderinfo( abf, NULL );
rootFolder = addrindex_ds_get_root_folder( ds );
addressbook_peek_subfolder_exists_load_folder( rootFolder, fi, nextmatch );
nodeDS = g_list_next( nodeDS );
}
}
list = g_list_next( list );
}
g_strfreev( folder_path_match.folder_path );
if ( book )
*book = folder_path_match.book;
if ( folder )
*folder = folder_path_match.folder;
return folder_path_match.matched;
}
/* **********************************************************************
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 );
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) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
2002-03-16 07:10:46 +01:00
newNode );
addrbook.treeSelected = newNode;
}
/* Notify address completion */
invalidate_address_completion();
}
}
}
}
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 ) {
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) );
if( newNode ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
2002-04-02 08:57:31 +02:00
newNode );
addrbook.treeSelected = newNode;
}
/* 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 ) {
gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
2002-03-16 07:10:46 +01:00
newNode );
addrbook.treeSelected = newNode;
}
/* Notify address completion */
invalidate_address_completion();
}
}
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) );
}
}
/* 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 );
}
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;
GList *cur;
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_ITEM_GROUP) {
return;
}
else if( pobj->type != ADDR_INTERFACE ) {
ds = addressbook_find_datasource( addrbook.treeSelected );
if (!ds)
return;
}
for(cur = GTK_CLIST(addrbook.clist)->selection; cur; cur = cur->next) {
aio = (AddrItemObject *)gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.clist),
GTK_CTREE_NODE(cur->data));
while (aio && aio->type != ADDR_ITEM_PERSON) {
aio = aio->parent;
}
}
if (aio && aio->type == ADDR_ITEM_PERSON) {
if( ds && ds->interface && ds->interface->readOnly)
gtk_selection_data_set(selection_data,
selection_data->target, 8,
"Dummy_addr_copy", 15);
else
gtk_selection_data_set(selection_data,
selection_data->target, 8,
"Dummy_addr_move", 15);
}
}
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);
if (ads == NULL ){ return FALSE;}
ds = ads->dataSource;
if (ds == NULL ) { return FALSE;}
acceptable = TRUE;
}
}
}
if (acceptable) {
g_signal_handlers_block_by_func
(G_OBJECT(widget),
G_CALLBACK(addressbook_tree_selected), NULL);
gtk_sctree_select( GTK_SCTREE(widget), node);
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);
gtk_sctree_select( GTK_SCTREE(widget), addrbook.opened);
g_signal_handlers_unblock_by_func
(G_OBJECT(widget),
G_CALLBACK(addressbook_tree_selected), NULL);
}
}
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;
GtkCTreeNode *lastopened = addrbook.opened;
if (!strncmp(data->data, "Dummy_addr", 10)) {
if (gtk_clist_get_selection_info
(GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0) {
return;
}
node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
if( !node || !gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree), node))
return;
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));
gtk_drag_finish(drag_context, TRUE, TRUE, time);
}
}
/*
* End of Source.
*/