claws-mail/src/account.c

1694 lines
44 KiB
C
Raw Normal View History

2001-04-19 14:21:46 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
2006-01-13 [paul] 1.9.100cvs142 * 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/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.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.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/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/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/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/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/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/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/colorlabel.c * 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/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/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.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 update copyright header
2006-01-13 18:24:38 +01:00
* Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
2001-04-19 14:21:46 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2005-09-21 [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 <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <errno.h>
#include "main.h"
#include "mainwindow.h"
#include "folderview.h"
#include "folder.h"
#include "account.h"
#include "prefs_gtk.h"
2001-04-19 14:21:46 +02:00
#include "prefs_account.h"
#include "prefs_common.h"
#include "folder_item_prefs.h"
2001-04-19 14:21:46 +02:00
#include "compose.h"
#include "manage_window.h"
2001-12-22 01:30:32 +01:00
#include "stock_pixmap.h"
2001-05-06 22:06:56 +02:00
#include "inc.h"
2001-04-19 14:21:46 +02:00
#include "gtkutils.h"
#include "utils.h"
#include "alertpanel.h"
#include "procheader.h"
2004-01-12 22:28:31 +01:00
#include "customheader.h"
#include "remotefolder.h"
2001-04-19 14:21:46 +02:00
enum {
ACCOUNT_IS_DEFAULT, /* GDK_TYPE_PIXMAP! */
ACCOUNT_ENABLE_GET_ALL,
ACCOUNT_NAME,
ACCOUNT_PROTOCOL,
ACCOUNT_SERVER,
ACCOUNT_DATA,
N_ACCOUNT_COLUMNS
};
2001-04-19 14:21:46 +02:00
typedef enum
{
COL_DEFAULT = 0,
2001-08-15 09:27:18 +02:00
COL_GETALL = 1,
COL_NAME = 2,
COL_PROTOCOL = 3,
COL_SERVER = 4
2001-04-19 14:21:46 +02:00
} EditAccountColumnPos;
# define N_EDIT_ACCOUNT_COLS 5
2001-04-19 14:21:46 +02:00
#define PREFSBUFSIZE 1024
PrefsAccount *cur_account;
static GList *account_list = NULL;
static struct EditAccount {
GtkWidget *window;
GtkWidget *list_view;
2001-04-19 14:21:46 +02:00
GtkWidget *close_btn;
} edit_account;
static GdkPixbuf *mark_pixbuf;
2001-08-15 09:27:18 +02:00
2001-04-19 14:21:46 +02:00
static void account_edit_create (void);
static void account_edit_prefs (GtkWidget *widget, gpointer data);
static void account_delete (GtkWidget *widget, gpointer data);
static void account_clone (GtkWidget *widget, gpointer data);
2001-04-19 14:21:46 +02:00
static void account_up (GtkWidget *widget, gpointer data);
static void account_down (GtkWidget *widget, gpointer data);
2001-04-19 14:21:46 +02:00
static void account_set_default (GtkWidget *widget, gpointer data);
2001-04-19 14:21:46 +02:00
static void account_edit_close (GtkWidget *widget, gpointer data);
2004-01-12 22:28:31 +01:00
2001-05-08 00:13:03 +02:00
static gint account_delete_event (GtkWidget *widget,
GdkEventAny *event,
gpointer data);
static void account_size_allocate_cb(GtkWidget *widget,
GtkAllocation *allocation);
2003-10-05 12:10:30 +02:00
static gboolean account_key_pressed (GtkWidget *widget,
2001-04-19 14:21:46 +02:00
GdkEventKey *event,
gpointer data);
static void account_list_view_add (PrefsAccount *ac_prefs);
static void account_list_view_set (void);
2001-04-19 14:21:46 +02:00
static void account_list_set (void);
typedef struct FindAccountInStore {
gint account_id;
GtkTreePath *path;
GtkTreeIter iter;
} FindAccountInStore;
static GtkListStore* account_create_data_store (void);
static void account_list_view_insert_account_item (GtkListStore *list_store,
const gchar *account_name,
const gchar *protocol,
const gchar *server_name,
gboolean is_default,
gboolean is_get_all,
PrefsAccount *account_data);
static GtkWidget *account_list_view_create (void);
static void account_create_list_view_images (GtkWidget *list_view);
static void account_create_list_view_columns (GtkWidget *list_view);
static gint account_list_view_get_selected_account_id (GtkWidget *list_view);
GtkTreePath *account_list_view_get_selected_account_path (GtkWidget *list_view);
PrefsAccount *account_list_view_get_selected_account (GtkWidget *list_view);
gboolean account_list_view_select_account (GtkWidget *list_view,
gint account_id);
static void account_list_view_set_default_by_id(GtkWidget *list_view,
gint account_id);
static gboolean set_new_default_account (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gint *account_id);
static gboolean find_account_in_store (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
FindAccountInStore *data);
static void account_get_all_toggled (GtkCellRendererToggle *widget,
gchar *path,
GtkWidget *list_view);
static void account_double_clicked (GtkTreeView *list_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer data);
static void drag_begin (GtkTreeView *list_view,
GdkDragContext *context,
gpointer data);
static void drag_end (GtkTreeView *list_view,
GdkDragContext *context,
gpointer data);
static void account_row_changed_while_drag_drop (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer arg3,
GtkTreeView *list_view);
2001-04-19 14:21:46 +02:00
void account_read_config_all(void)
{
GSList *ac_label_list = NULL, *cur;
gchar *rcpath;
FILE *fp;
gchar buf[PREFSBUFSIZE];
PrefsAccount *ac_prefs;
2002-08-15 09:38:17 +02:00
debug_print("Reading all config for each account...\n");
2001-04-19 14:21:46 +02:00
rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
if ((fp = g_fopen(rcpath, "rb")) == NULL) {
2001-04-19 14:21:46 +02:00
if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
g_free(rcpath);
return;
}
g_free(rcpath);
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (!strncmp(buf, "[Account: ", 10)) {
strretchomp(buf);
memmove(buf, buf + 1, strlen(buf));
buf[strlen(buf) - 1] = '\0';
2002-08-15 09:38:17 +02:00
debug_print("Found label: %s\n", buf);
2001-04-19 14:21:46 +02:00
ac_label_list = g_slist_append(ac_label_list,
g_strdup(buf));
}
}
fclose(fp);
/* read config data from file */
cur_account = NULL;
for (cur = ac_label_list; cur != NULL; cur = cur->next) {
2002-09-26 09:32:06 +02:00
ac_prefs = prefs_account_new();
2001-04-19 14:21:46 +02:00
prefs_account_read_config(ac_prefs, (gchar *)cur->data);
account_list = g_list_append(account_list, ac_prefs);
if (ac_prefs->is_default)
cur_account = ac_prefs;
}
/* if default is not set, assume first account as default */
if (!cur_account && account_list) {
ac_prefs = (PrefsAccount *)account_list->data;
account_set_as_default(ac_prefs);
cur_account = ac_prefs;
}
account_set_menu();
main_window_reflect_prefs_all();
while (ac_label_list) {
g_free(ac_label_list->data);
ac_label_list = g_slist_remove(ac_label_list,
ac_label_list->data);
}
}
2004-07-16 13:12:46 +02:00
void account_write_config_all(void)
2001-04-19 14:21:46 +02:00
{
2004-07-16 13:12:46 +02:00
prefs_account_write_config_all(account_list);
2001-04-19 14:21:46 +02:00
}
/*
* account_find_all_from_address:
* @ac_list: initial list of accounts. NULL to create a new one.
* Accounts found in the @address will be appended to this list.
* @address: Email address string.
*
* Find all the mail (not news) accounts within the specified address.
*
* Return value: the original accounts list with the found accounts appended.
*/
GList *account_find_all_from_address(GList *ac_list, const gchar *address)
{
GList *cur;
PrefsAccount *ac;
if (address == NULL)
return ac_list;
for (cur = account_list; cur != NULL; cur = cur->next) {
ac = (PrefsAccount *)cur->data;
if (ac->protocol != A_NNTP && ac->address &&
strcasestr(address, ac->address) != NULL)
ac_list = g_list_append(ac_list, ac);
}
return ac_list;
}
2001-04-19 14:21:46 +02:00
PrefsAccount *account_find_from_smtp_server(const gchar *address,
const gchar *smtp_server)
{
GList *cur;
PrefsAccount *ac;
2001-12-22 01:30:32 +01:00
g_return_val_if_fail(address != NULL, NULL);
g_return_val_if_fail(smtp_server != NULL, NULL);
2001-04-19 14:21:46 +02:00
for (cur = account_list; cur != NULL; cur = cur->next) {
ac = (PrefsAccount *)cur->data;
if (!strcmp2(address, ac->address) &&
!strcmp2(smtp_server, ac->smtp_server))
return ac;
}
return NULL;
}
2001-07-26 00:13:17 +02:00
/*
2001-07-27 20:04:08 +02:00
* account_find_from_address:
* @address: Email address string.
2001-07-26 00:13:17 +02:00
*
* Find a mail (not news) account with the specified email address.
2001-07-26 00:13:17 +02:00
*
* Return value: The found account, or NULL if not found.
2001-07-26 00:13:17 +02:00
*/
2001-07-27 20:04:08 +02:00
PrefsAccount *account_find_from_address(const gchar *address)
{
GList *cur;
PrefsAccount *ac;
2001-12-22 01:30:32 +01:00
g_return_val_if_fail(address != NULL, NULL);
for (cur = account_list; cur != NULL; cur = cur->next) {
ac = (PrefsAccount *)cur->data;
2001-12-22 01:30:32 +01:00
if (ac->protocol != A_NNTP && ac->address &&
g_ascii_strcasecmp(address, ac->address) == 0)
return ac;
2001-04-19 14:21:46 +02:00
}
return NULL;
}
PrefsAccount *account_find_from_id(gint id)
{
GList *cur;
PrefsAccount *ac;
for (cur = account_list; cur != NULL; cur = cur->next) {
ac = (PrefsAccount *)cur->data;
if (id == ac->account_id)
return ac;
}
return NULL;
}
PrefsAccount *account_find_from_item(FolderItem *item)
{
PrefsAccount *ac;
g_return_val_if_fail(item != NULL, NULL);
ac = item->account;
if (!ac) {
2004-02-21 12:01:01 +01:00
FolderItem *cur_item = folder_item_parent(item);
while (cur_item != NULL) {
if (cur_item->account && cur_item->apply_sub) {
ac = cur_item->account;
break;
}
2004-02-21 12:01:01 +01:00
cur_item = folder_item_parent(cur_item);
}
}
if (!ac)
ac = item->folder->account;
return ac;
}
2001-04-19 14:21:46 +02:00
void account_set_menu(void)
{
main_window_set_account_menu(account_list);
}
void account_set_menu_only_toolbar(void)
{
main_window_set_account_menu_only_toolbar(account_list);
}
2001-04-19 14:21:46 +02:00
void account_foreach(AccountFunc func, gpointer user_data)
{
GList *cur;
for (cur = account_list; cur != NULL; cur = cur->next)
if (func((PrefsAccount *)cur->data, user_data) != 0)
return;
}
GList *account_get_list(void)
{
return account_list;
}
void account_edit_open(void)
{
2001-09-02 17:07:05 +02:00
inc_lock();
2001-06-09 12:49:52 +02:00
2001-04-19 14:21:46 +02:00
if (compose_get_compose_list()) {
2004-07-28 10:07:08 +02:00
alertpanel_error(_("Some composing windows are open.\n"
"Please close all the composing "
"windows before editing the accounts."));
2001-09-02 17:07:05 +02:00
inc_unlock();
2001-04-19 14:21:46 +02:00
return;
}
2002-08-15 09:38:17 +02:00
debug_print("Opening account edit window...\n");
2001-04-19 14:21:46 +02:00
if (!edit_account.window)
account_edit_create();
account_list_view_set();
2001-04-19 14:21:46 +02:00
manage_window_set_transient(GTK_WINDOW(edit_account.window));
gtk_widget_grab_focus(edit_account.close_btn);
gtk_widget_show(edit_account.window);
manage_window_focus_in(edit_account.window, NULL, NULL);
}
void account_add(void)
{
PrefsAccount *ac_prefs;
ac_prefs = prefs_account_open(NULL);
if (!ac_prefs) return;
account_list = g_list_append(account_list, ac_prefs);
if (ac_prefs->is_default)
account_set_as_default(ac_prefs);
account_list_view_set();
2001-04-19 14:21:46 +02:00
if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
Folder *folder;
if (ac_prefs->protocol == A_IMAP4) {
folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
2001-04-19 14:21:46 +02:00
ac_prefs->recv_server);
} else {
folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
2001-04-19 14:21:46 +02:00
ac_prefs->nntp_server);
}
if (folder == NULL) {
alertpanel_error(_("Can't create folder."));
return;
}
2001-04-19 14:21:46 +02:00
folder->account = ac_prefs;
2004-01-12 22:28:31 +01:00
ac_prefs->folder = folder;
2001-04-19 14:21:46 +02:00
folder_add(folder);
2001-07-15 15:42:30 +02:00
if (ac_prefs->protocol == A_IMAP4)
folder->klass->create_tree(folder);
2001-07-15 15:42:30 +02:00
folderview_set_all();
2001-04-19 14:21:46 +02:00
}
}
2002-10-13 17:43:22 +02:00
void account_open(PrefsAccount *ac_prefs)
{
gboolean prev_default;
gchar *ac_name;
g_return_if_fail(ac_prefs != NULL);
prev_default = ac_prefs->is_default;
Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
return);
prefs_account_open(ac_prefs);
if (!prev_default && ac_prefs->is_default)
account_set_as_default(ac_prefs);
if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
folder_set_name(FOLDER(ac_prefs->folder),
ac_prefs->account_name);
folderview_set_all();
}
2004-07-16 13:12:46 +02:00
account_write_config_all();
2002-10-13 17:43:22 +02:00
account_set_menu();
main_window_reflect_prefs_all();
}
2001-04-19 14:21:46 +02:00
void account_set_as_default(PrefsAccount *ac_prefs)
{
PrefsAccount *ap;
GList *cur;
for (cur = account_list; cur != NULL; cur = cur->next) {
ap = (PrefsAccount *)cur->data;
if (ap->is_default)
ap->is_default = FALSE;
}
ac_prefs->is_default = TRUE;
}
PrefsAccount *account_get_default(void)
{
PrefsAccount *ap;
GList *cur;
for (cur = account_list; cur != NULL; cur = cur->next) {
ap = (PrefsAccount *)cur->data;
if (ap->is_default)
return ap;
}
return NULL;
}
void account_set_missing_folder(void)
{
PrefsAccount *ap;
GList *cur;
for (cur = account_list; cur != NULL; cur = cur->next) {
ap = (PrefsAccount *)cur->data;
if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
!ap->folder) {
Folder *folder;
if (ap->protocol == A_IMAP4) {
folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
2001-04-19 14:21:46 +02:00
ap->recv_server);
} else {
folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
2001-04-19 14:21:46 +02:00
ap->nntp_server);
}
if (folder == NULL)
return;
2001-04-19 14:21:46 +02:00
folder->account = ap;
2004-01-12 22:28:31 +01:00
ap->folder = folder;
2001-04-19 14:21:46 +02:00
folder_add(folder);
2001-06-15 12:29:27 +02:00
if (ap->protocol == A_IMAP4)
folder->klass->create_tree(folder);
2001-04-19 14:21:46 +02:00
}
}
}
#define CHECK_CHANGE_FOLDER(folder) { \
if (folder && !strncmp(folder, old_id, strlen(old_id))) { \
if (strlen(folder) == strlen(old_id)) { \
g_free(folder); \
folder = g_strdup(new_id); \
} else if (strlen(folder) > strlen(old_id) \
&& folder[strlen(old_id)] == G_DIR_SEPARATOR) { \
gchar *new_path = g_strdup_printf("%s%s", \
new_id, (folder + strlen(old_id))); \
g_free(folder); \
folder = new_path; \
} \
} \
}
void account_rename_path(const gchar *old_id, const gchar *new_id)
{
GList *cur = account_list;
for (; cur != NULL; cur = g_list_next(cur)) {
PrefsAccount *ap = (PrefsAccount *)cur->data;
CHECK_CHANGE_FOLDER(ap->inbox);
CHECK_CHANGE_FOLDER(ap->local_inbox);
CHECK_CHANGE_FOLDER(ap->queue_folder);
CHECK_CHANGE_FOLDER(ap->sent_folder);
CHECK_CHANGE_FOLDER(ap->draft_folder);
CHECK_CHANGE_FOLDER(ap->trash_folder);
}
}
#undef CHECK_CHANGE_FOLDER
FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
SpecialFolderItemType type)
{
FolderItem *item = NULL;
g_return_val_if_fail(ac_prefs != NULL, NULL);
2002-11-06 10:46:42 +01:00
switch (type) {
case F_INBOX:
if (ac_prefs->folder)
item = FOLDER(ac_prefs->folder)->inbox;
if (!item)
item = folder_get_default_inbox();
break;
case F_OUTBOX:
if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
item = folder_find_item_from_identifier
(ac_prefs->sent_folder);
}
if (!item) {
if (ac_prefs->folder)
item = FOLDER(ac_prefs->folder)->outbox;
if (!item)
item = folder_get_default_outbox();
}
2002-11-06 10:46:42 +01:00
break;
case F_DRAFT:
if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
item = folder_find_item_from_identifier
(ac_prefs->draft_folder);
}
if (!item) {
if (ac_prefs->folder)
item = FOLDER(ac_prefs->folder)->draft;
if (!item)
item = folder_get_default_draft();
}
2002-11-06 10:46:42 +01:00
break;
case F_QUEUE:
if (ac_prefs->set_queue_folder && ac_prefs->queue_folder) {
item = folder_find_item_from_identifier
(ac_prefs->queue_folder);
}
if (!item) {
if (ac_prefs->folder)
item = FOLDER(ac_prefs->folder)->queue;
if (!item)
item = folder_get_default_queue();
}
2002-11-06 10:46:42 +01:00
break;
case F_TRASH:
if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
item = folder_find_item_from_identifier
(ac_prefs->trash_folder);
}
if (!item) {
if (ac_prefs->folder)
item = FOLDER(ac_prefs->folder)->trash;
if (!item)
item = folder_get_default_trash();
}
2002-11-06 10:46:42 +01:00
break;
default:
break;
}
return item;
}
2001-04-19 14:21:46 +02:00
void account_destroy(PrefsAccount *ac_prefs)
{
g_return_if_fail(ac_prefs != NULL);
2002-10-13 17:43:22 +02:00
folder_unref_account_all(ac_prefs);
2001-04-19 14:21:46 +02:00
prefs_account_free(ac_prefs);
account_list = g_list_remove(account_list, ac_prefs);
if (cur_account == ac_prefs) cur_account = NULL;
if (!cur_account && account_list) {
cur_account = account_get_default();
if (!cur_account) {
ac_prefs = (PrefsAccount *)account_list->data;
account_set_as_default(ac_prefs);
cur_account = ac_prefs;
}
}
}
/*!
*\brief Save Gtk object size to prefs dataset
*/
static void account_size_allocate_cb(GtkWidget *widget,
GtkAllocation *allocation)
{
g_return_if_fail(allocation != NULL);
prefs_common.accountswin_width = allocation->width;
prefs_common.accountswin_height = allocation->height;
}
2001-04-19 14:21:46 +02:00
static void account_edit_create(void)
{
GtkWidget *window;
GtkWidget *vbox;
2001-10-30 11:25:49 +01:00
GtkWidget *label;
2001-04-19 14:21:46 +02:00
GtkWidget *hbox;
GtkWidget *scrolledwin;
GtkWidget *list_view;
2001-04-19 14:21:46 +02:00
GtkWidget *vbox2;
GtkWidget *add_btn;
GtkWidget *edit_btn;
GtkWidget *del_btn;
2004-01-12 22:28:31 +01:00
GtkWidget *clone_btn;
2001-04-19 14:21:46 +02:00
GtkWidget *up_btn;
GtkWidget *down_btn;
GtkWidget *default_btn;
GtkWidget *hbbox;
GtkWidget *close_btn;
static GdkGeometry geometry;
2002-08-15 09:38:17 +02:00
debug_print("Creating account edit window...\n");
2001-04-19 14:21:46 +02:00
2003-10-05 12:10:30 +02:00
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2001-04-19 14:21:46 +02:00
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (account_delete_event), NULL);
g_signal_connect (G_OBJECT (window), "key_press_event",
G_CALLBACK (account_key_pressed), NULL);
2002-02-23 11:52:54 +01:00
MANAGE_WINDOW_SIGNALS_CONNECT (window);
2001-08-15 09:27:18 +02:00
gtk_widget_realize(window);
2001-04-19 14:21:46 +02:00
2001-10-30 11:25:49 +01:00
vbox = gtk_vbox_new (FALSE, 10);
2001-04-19 14:21:46 +02:00
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (window), vbox);
2001-10-30 11:25:49 +01:00
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new
2001-11-07 11:29:45 +01:00
(_("New messages will be checked in this order. Check the boxes\n"
"on the 'G' column to enable message retrieval by 'Get Mail'."));
2001-10-30 11:25:49 +01:00
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
2001-04-19 14:21:46 +02:00
hbox = gtk_hbox_new (FALSE, 8);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
scrolledwin = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwin);
gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
list_view = account_list_view_create();
gtk_widget_show(list_view);
gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
2001-07-01 10:37:50 +02:00
2001-04-19 14:21:46 +02:00
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox2);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
add_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
2001-04-19 14:21:46 +02:00
gtk_widget_show (add_btn);
gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(add_btn), "clicked",
G_CALLBACK (account_add), NULL);
2001-04-19 14:21:46 +02:00
#if GTK_CHECK_VERSION(2, 6, 0)
edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
#else
edit_btn = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES);
#endif
2001-04-19 14:21:46 +02:00
gtk_widget_show (edit_btn);
gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(edit_btn), "clicked",
G_CALLBACK (account_edit_prefs), NULL);
2001-04-19 14:21:46 +02:00
del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
2001-04-19 14:21:46 +02:00
gtk_widget_show (del_btn);
gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(del_btn), "clicked",
G_CALLBACK (account_delete), NULL);
2001-04-19 14:21:46 +02:00
clone_btn = gtk_button_new_from_stock(GTK_STOCK_COPY);
2004-01-12 22:28:31 +01:00
gtk_widget_show (clone_btn);
gtk_box_pack_start (GTK_BOX (vbox2), clone_btn, FALSE, FALSE, 4);
g_signal_connect(G_OBJECT(clone_btn), "clicked",
G_CALLBACK(account_clone), NULL);
2004-01-12 22:28:31 +01:00
down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
2001-04-19 14:21:46 +02:00
gtk_widget_show (down_btn);
gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(down_btn), "clicked",
G_CALLBACK (account_down), NULL);
2001-04-19 14:21:46 +02:00
up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
2001-04-19 14:21:46 +02:00
gtk_widget_show (up_btn);
gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(up_btn), "clicked",
G_CALLBACK (account_up), NULL);
2001-04-19 14:21:46 +02:00
hbox = gtk_hbox_new (FALSE, 8);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
vbox2 = gtk_vbox_new(FALSE, 0);
gtk_widget_show (vbox2);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
default_btn = gtk_button_new_with_mnemonic
(_(" _Set as default account "));
2001-04-19 14:21:46 +02:00
gtk_widget_show (default_btn);
gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT(default_btn), "clicked",
G_CALLBACK (account_set_default), NULL);
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), 5);
gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE,
NULL, NULL, NULL, NULL);
2001-04-19 14:21:46 +02:00
gtk_widget_show(hbbox);
2001-04-19 14:21:46 +02:00
gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
gtk_widget_grab_default (close_btn);
2003-10-05 12:10:30 +02:00
g_signal_connect (G_OBJECT (close_btn), "clicked",
G_CALLBACK (account_edit_close),
NULL);
2001-04-19 14:21:46 +02:00
account_create_list_view_images(list_view);
2001-08-15 09:27:18 +02:00
g_signal_connect(G_OBJECT(window), "size_allocate",
G_CALLBACK(account_size_allocate_cb), NULL);
if (!geometry.min_height) {
geometry.min_width = 500;
geometry.min_height = 350;
}
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
GDK_HINT_MIN_SIZE);
gtk_widget_set_size_request(window, prefs_common.accountswin_width,
prefs_common.accountswin_height);
2001-04-19 14:21:46 +02:00
edit_account.window = window;
edit_account.list_view = list_view;
2001-04-19 14:21:46 +02:00
edit_account.close_btn = close_btn;
}
static void account_edit_prefs(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
PrefsAccount *ac_prefs;
ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
2002-10-13 17:43:22 +02:00
if (ac_prefs) {
account_open(ac_prefs);
account_list_view_set();
}
2001-04-19 14:21:46 +02:00
}
static gboolean account_delete_references_func(GNode *node, gpointer data)
{
FolderItem *item;
gint account;
g_return_val_if_fail(node->data != NULL, FALSE);
item = FOLDER_ITEM(node->data);
account = GPOINTER_TO_INT(data);
if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
return FALSE;
if(item->prefs->default_account != account)
return FALSE;
item->prefs->enable_default_account = FALSE;
item->prefs->default_account = 0;
folder_item_prefs_save_config(item);
return FALSE;
}
2004-01-12 22:28:31 +01:00
#define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
g_strdup(ac_prefs->fld): NULL
#define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
static void account_clone(GtkWidget *widget, gpointer data)
2004-01-12 22:28:31 +01:00
{
PrefsAccount *ac_prefs, *ac_clon;
GSList *hdrs = NULL;
CustomHeader *cch = NULL, *ch = NULL;
ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
if (ac_prefs == NULL)
return;
2004-01-12 22:28:31 +01:00
if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
alertpanel_error(_("Accounts with remote folders cannot be copied."));
2004-01-12 22:28:31 +01:00
return;
}
ac_clon = prefs_account_new();
/* copy fields */
ac_clon->account_name = g_strdup_printf(_("Copy of %s"),
2004-01-12 22:28:31 +01:00
ac_prefs->account_name);
/* personal */
ACP_FDUP(name);
ACP_FDUP(address);
ACP_FDUP(organization);
/* server */
ACP_FASSIGN(protocol);
ACP_FDUP(recv_server);
ACP_FDUP(smtp_server);
ACP_FDUP(nntp_server);
ACP_FASSIGN(use_nntp_auth);
ACP_FASSIGN(use_nntp_auth_onconnect);
ACP_FDUP(userid);
ACP_FDUP(passwd);
ACP_FDUP(local_mbox);
ACP_FASSIGN(use_mail_command);
ACP_FDUP(mail_command);
#if USE_OPENSSL
ACP_FASSIGN(ssl_pop);
ACP_FASSIGN(ssl_imap);
ACP_FASSIGN(ssl_nntp);
ACP_FASSIGN(ssl_smtp);
ACP_FASSIGN(use_nonblocking_ssl);
#endif /* USE_OPENSSL */
ac_clon->tmp_pass = NULL;
/* receive */
ACP_FASSIGN(rmmail);
ACP_FASSIGN(msg_leave_time);
ACP_FASSIGN(getall);
ACP_FASSIGN(recv_at_getall);
ACP_FASSIGN(sd_rmmail_on_download);
ACP_FASSIGN(sd_filter_on_recv);
ACP_FASSIGN(enable_size_limit);
ACP_FASSIGN(size_limit);
ACP_FASSIGN(filter_on_recv);
ACP_FDUP(inbox);
ACP_FASSIGN(max_articles);
ACP_FASSIGN(imap_auth_type);
/* send */
ACP_FASSIGN(add_date);
ACP_FASSIGN(gen_msgid);
ACP_FASSIGN(add_customhdr);
ACP_FASSIGN(use_smtp_auth);
ACP_FASSIGN(smtp_auth_type);
ACP_FDUP(smtp_userid);
ACP_FDUP(smtp_passwd);
ac_clon->tmp_smtp_pass = NULL;
ACP_FASSIGN(pop_before_smtp);
ACP_FASSIGN(pop_before_smtp_timeout);
ACP_FASSIGN(last_pop_login_time);
ac_clon->customhdr_list = NULL;
hdrs = ac_prefs->customhdr_list;
while (hdrs != NULL) {
ch = (CustomHeader *)hdrs->data;
cch = g_new0(CustomHeader, 1);
cch->account_id = ac_clon->account_id;
cch->name = (ch->name != NULL) ? g_strdup(ch->name) : NULL;
cch->value = (ch->value != NULL) ? g_strdup(ch->value) : NULL;
ac_clon->customhdr_list = g_slist_append(ac_clon->customhdr_list, cch);
hdrs = g_slist_next(hdrs);
}
/* compose */
ACP_FASSIGN(sig_type);
ACP_FDUP(sig_path);
ACP_FASSIGN(auto_sig);
ACP_FDUP(sig_sep);
ACP_FASSIGN(set_autocc);
ACP_FDUP(auto_cc);
ACP_FASSIGN(set_autobcc);
ACP_FDUP(auto_bcc);
ACP_FASSIGN(set_autoreplyto);
ACP_FDUP(auto_replyto);
/* privacy */
ACP_FASSIGN(default_encrypt);
ACP_FASSIGN(default_sign);
/* advanced */
ACP_FASSIGN(set_smtpport);
ACP_FASSIGN(smtpport);
ACP_FASSIGN(set_popport);
ACP_FASSIGN(popport);
ACP_FASSIGN(set_imapport);
ACP_FASSIGN(imapport);
ACP_FASSIGN(set_nntpport);
ACP_FASSIGN(nntpport);
ACP_FASSIGN(set_domain);
ACP_FDUP(domain);
ACP_FASSIGN(mark_crosspost_read);
ACP_FASSIGN(crosspost_col);
ACP_FASSIGN(set_tunnelcmd);
ACP_FDUP(tunnelcmd);
ACP_FDUP(imap_dir);
ACP_FASSIGN(set_sent_folder);
ACP_FDUP(sent_folder);
ACP_FASSIGN(set_draft_folder);
ACP_FDUP(draft_folder);
ACP_FASSIGN(set_trash_folder);
ACP_FDUP(trash_folder);
/* don't want two default accounts */
ac_clon->is_default = FALSE;
ACP_FASSIGN(folder);
account_list = g_list_append(account_list, ac_clon);
account_list_view_set();
2004-01-12 22:28:31 +01:00
}
#undef ACP_FDUP
#undef ACP_FASSIGN
static void account_delete(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
PrefsAccount *ac_prefs;
gchar buf[BUFFSIZE];
GList *list;
Folder *folder;
ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
if (ac_prefs == NULL)
return;
2001-04-19 14:21:46 +02:00
g_snprintf(buf, sizeof(buf),
_("Do you really want to delete the account '%s'?"),
ac_prefs->account_name ? ac_prefs->account_name :
_("(Untitled)"));
if (alertpanel_full(_("Delete account"), buf,
GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE)
2001-04-19 14:21:46 +02:00
return;
if (ac_prefs->folder) {
FolderItem *item;
item = mainwindow_get_mainwindow()->summaryview->folder_item;
if (item && item->folder == FOLDER(ac_prefs->folder))
summary_clear_all(mainwindow_get_mainwindow()->summaryview);
2001-04-19 14:21:46 +02:00
folder_destroy(FOLDER(ac_prefs->folder));
2002-08-16 11:34:01 +02:00
folderview_set_all();
2001-04-19 14:21:46 +02:00
}
account_destroy(ac_prefs);
account_list_view_set();
2002-08-15 09:38:17 +02:00
debug_print("Removing deleted account references for all the folders...\n");
list = folder_get_list();
for (; list != NULL; list = list->next) {
folder = FOLDER(list->data);
if (folder->node) /* && folder->type == F_? */
g_node_traverse(folder->node, G_PRE_ORDER,
G_TRAVERSE_ALL, -1,
account_delete_references_func,
GINT_TO_POINTER(ac_prefs->account_id));
}
2001-04-19 14:21:46 +02:00
}
static void account_up(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
GtkTreePath *sel = account_list_view_get_selected_account_path
(edit_account.list_view),
*up;
GtkTreeIter isel, iup;
GtkTreeModel *model = gtk_tree_view_get_model
(GTK_TREE_VIEW(edit_account.list_view));
if (!sel)
return;
up = gtk_tree_path_copy(sel);
if (!up) {
gtk_tree_path_free(sel);
return;
}
2001-04-19 14:21:46 +02:00
if (!gtk_tree_path_prev(up)) {
gtk_tree_path_free(up);
gtk_tree_path_free(sel);
return;
}
2001-04-19 14:21:46 +02:00
if (!gtk_tree_model_get_iter(model, &isel, sel)
|| !gtk_tree_model_get_iter(model, &iup, up)) {
gtk_tree_path_free(up);
gtk_tree_path_free(sel);
return;
}
gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &iup);
account_list_set();
gtk_tree_path_free(up);
gtk_tree_path_free(sel);
2001-04-19 14:21:46 +02:00
}
static void account_down(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
GtkTreePath *sel = account_list_view_get_selected_account_path
(edit_account.list_view),
*dn;
GtkTreeIter isel, idn;
GtkTreeModel *model = gtk_tree_view_get_model
(GTK_TREE_VIEW(edit_account.list_view));
if (!sel)
return;
dn = gtk_tree_path_copy(sel);
if (!dn) {
gtk_tree_path_free(sel);
return;
}
2001-04-19 14:21:46 +02:00
/* XXX no check possible??? however, if down but at bottom, then
* nothing seems to happen much anyway, so the following seems to
* be okay */
gtk_tree_path_next(dn);
2001-04-19 14:21:46 +02:00
if (!gtk_tree_model_get_iter(model, &isel, sel)
|| !gtk_tree_model_get_iter(model, &idn, dn)) {
gtk_tree_path_free(dn);
gtk_tree_path_free(sel);
return;
}
gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &idn);
account_list_set();
gtk_tree_path_free(dn);
gtk_tree_path_free(sel);
2001-04-19 14:21:46 +02:00
}
static void account_set_default(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
PrefsAccount *ac_prefs;
if (NULL == (ac_prefs = account_list_view_get_selected_account
(edit_account.list_view)))
return;
2001-04-19 14:21:46 +02:00
/* we need to change the store variables by resetting everything
* and setting the new default one */
account_list_view_set_default_by_id(edit_account.list_view,
ac_prefs->account_id);
2001-04-19 14:21:46 +02:00
account_set_as_default(ac_prefs);
account_list_view_set();
2001-04-19 14:21:46 +02:00
cur_account = ac_prefs;
account_set_menu();
main_window_reflect_prefs_all();
}
static void account_edit_close(GtkWidget *widget, gpointer data)
2001-04-19 14:21:46 +02:00
{
account_list_set();
2004-07-16 13:12:46 +02:00
account_write_config_all();
2001-04-19 14:21:46 +02:00
if (!cur_account && account_list) {
PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
account_set_as_default(ac_prefs);
cur_account = ac_prefs;
}
account_set_menu();
main_window_reflect_prefs_all();
gtk_widget_hide(edit_account.window);
2001-05-06 22:06:56 +02:00
2001-09-02 17:07:05 +02:00
inc_unlock();
2001-04-19 14:21:46 +02:00
}
2001-05-08 00:13:03 +02:00
static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
gpointer data)
{
account_edit_close(NULL, NULL);
2001-05-08 00:13:03 +02:00
return TRUE;
}
2003-10-05 12:10:30 +02:00
static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
gpointer data)
2001-04-19 14:21:46 +02:00
{
if (event && event->keyval == GDK_Escape)
account_edit_close(NULL, NULL);
2003-10-05 12:10:30 +02:00
return FALSE;
2001-04-19 14:21:46 +02:00
}
static void account_list_view_add(PrefsAccount *ac_prefs)
2001-04-19 14:21:46 +02:00
{
GtkTreeView *list_view = GTK_TREE_VIEW(edit_account.list_view);
GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
gchar *name, *protocol, *server;
2001-11-07 11:29:45 +01:00
gboolean has_getallbox;
gboolean getall;
2001-04-19 14:21:46 +02:00
name = ac_prefs->account_name;
#if USE_OPENSSL
protocol = ac_prefs->protocol == A_POP3 ?
(ac_prefs->ssl_pop == SSL_TUNNEL ?
"POP3 (SSL)" :
ac_prefs->ssl_pop == SSL_STARTTLS ?
"POP3 (TLS)" : "POP3") :
ac_prefs->protocol == A_IMAP4 ?
(ac_prefs->ssl_imap == SSL_TUNNEL ?
"IMAP4 (SSL)" :
ac_prefs->ssl_imap == SSL_STARTTLS ?
"IMAP4 (TLS)" : "IMAP4") :
ac_prefs->protocol == A_NNTP ?
(ac_prefs->ssl_nntp == SSL_TUNNEL ?
"NNTP (SSL)" : "NNTP") :
"";
#else
protocol = ac_prefs->protocol == A_POP3 ? "POP3" :
ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
ac_prefs->protocol == A_LOCAL ? "Local" :
ac_prefs->protocol == A_NNTP ? "NNTP" : "";
#endif
server= ac_prefs->protocol == A_NNTP
2001-04-19 14:21:46 +02:00
? ac_prefs->nntp_server : ac_prefs->recv_server;
2002-02-21 15:56:09 +01:00
has_getallbox = (ac_prefs->protocol == A_POP3 ||
ac_prefs->protocol == A_IMAP4 ||
ac_prefs->protocol == A_NNTP ||
2002-03-10 15:09:59 +01:00
ac_prefs->protocol == A_LOCAL);
2001-11-07 11:29:45 +01:00
getall = has_getallbox && ac_prefs->recv_at_getall;
account_list_view_insert_account_item(list_store,
name, protocol, server,
ac_prefs->is_default,
getall, ac_prefs);
return;
2001-04-19 14:21:46 +02:00
}
static void account_list_view_set(void)
2001-04-19 14:21:46 +02:00
{
GList *cur;
gint prev_sel_account;
GtkListStore *store;
store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(edit_account.list_view)));
2001-04-19 14:21:46 +02:00
prev_sel_account = account_list_view_get_selected_account_id
(edit_account.list_view);
2001-04-19 14:21:46 +02:00
gtk_list_store_clear(store);
2001-04-19 14:21:46 +02:00
for (cur = account_list; cur != NULL; cur = cur->next) {
account_list_view_add((PrefsAccount *)cur->data);
if ((PrefsAccount *)cur->data == cur_account)
account_list_view_select_account
(edit_account.list_view,
cur_account->account_id);
2001-04-19 14:21:46 +02:00
}
if (prev_sel_account >= 0)
account_list_view_select_account(edit_account.list_view,
prev_sel_account);
2001-04-19 14:21:46 +02:00
}
/* set account list from CList */
static void account_list_set(void)
{
/* want to make sure we iterate *IN ORDER*, so therefore using
* gtk_tree_model_XXXX_nth_child() */
gint row, n_rows;
2001-04-19 14:21:46 +02:00
PrefsAccount *ac_prefs;
GtkTreeModel *model = gtk_tree_view_get_model
(GTK_TREE_VIEW(edit_account.list_view));
2001-04-19 14:21:46 +02:00
while (account_list)
account_list = g_list_remove(account_list, account_list->data);
n_rows = gtk_tree_model_iter_n_children(model, NULL);
for (row = 0; row < n_rows; row++) {
GtkTreeIter iter;
if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
g_warning("%s(%d) - no iter found???\n", __FILE__, __LINE__);
continue;
}
ac_prefs = NULL;
gtk_tree_model_get(model, &iter,
ACCOUNT_DATA, &ac_prefs,
-1);
if (ac_prefs)
account_list = g_list_append(account_list, ac_prefs);
}
2001-04-19 14:21:46 +02:00
}
2003-01-05 18:33:08 +01:00
/*!
*\brief finds the PrefsAccounts which should be used to answer a mail
*
*\param msginfo The message to be answered
*\param reply_autosel Indicates whether reply account autoselection is on
*
*\return PrefsAccount * the correct account, NULL if not found
*/
PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
{
PrefsAccount *account = NULL;
/* select the account set in folderitem's property (if enabled) */
if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
account = account_find_from_id(msginfo->folder->prefs->default_account);
/* select account by to: and cc: header if enabled */
if (reply_autosel) {
gchar * field = NULL;
int fieldno = 0;
for (field = msginfo->to; fieldno++ < 2; field = msginfo->cc) {
if (!account && field) {
gchar *to = NULL;
if (!strchr(field, ',')) {
Xstrdup_a(to, field, return NULL);
extract_address(to);
account = account_find_from_address(to);
} else {
gchar **split = g_strsplit(field, ",", -1);
int i = -1;
do {
i++;
if (!split[i])
break;
Xstrdup_a(to, split[i], return NULL);
extract_address(to);
account = account_find_from_address(to);
} while (!account);
g_strfreev(split);
}
}
2003-01-05 18:33:08 +01:00
}
}
2004-07-12 12:39:50 +02:00
/* select the account for the whole folder (IMAP / NNTP) */
if (!account)
/* FIXME: this is not right, because folder may be nested. we should
* ascend the tree until we find a parent with proper account
* information */
account = msginfo->folder->folder->account;
2003-01-05 18:33:08 +01:00
/* select current account */
if (!account) account = cur_account;
return account;
}
/*!
*\brief Create data store
*/
static GtkListStore* account_create_data_store(void)
{
return gtk_list_store_new(N_ACCOUNT_COLUMNS,
GDK_TYPE_PIXBUF, /* ACCOUNT_IS_DEFAULT */
G_TYPE_BOOLEAN, /* ACCOUNT_ENABLE_GET_ALL */
G_TYPE_STRING, /* ACCOUNT_NAME */
G_TYPE_STRING, /* ACCOUNT_PROTOCOL */
G_TYPE_STRING, /* ACCOUNT_SERVER */
G_TYPE_POINTER, /* ACCOUNT_DATA */
-1);
}
/*!
*\brief Insert an account item in the list.
*
*\return GtkTreeRowReference * A tree row reference, which is guaranteed to
* stable whatever operations are performed on the list.
*/
static void account_list_view_insert_account_item(GtkListStore *list_store,
const gchar *account_name,
const gchar *protocol,
const gchar *server_name,
gboolean is_default,
gboolean is_get_all,
PrefsAccount *account_data)
{
GtkTreeIter iter;
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,
ACCOUNT_IS_DEFAULT, is_default ? mark_pixbuf : NULL,
ACCOUNT_ENABLE_GET_ALL, is_get_all,
ACCOUNT_NAME, account_name,
ACCOUNT_PROTOCOL, protocol,
ACCOUNT_SERVER, server_name,
ACCOUNT_DATA, account_data,
-1);
}
/*!
*\brief Create and set up account list view, including tasks like
* creating the data store (\ref account_create_data_store()),
* creating images for the list view (\ref account_create_list_view_images()),
* and setting up the account list's individual columns (\ref
* account_create_list_view_columns()).
*
*\return GtkWidget * The created list view widget.
*/
static GtkWidget *account_list_view_create(void)
{
GtkTreeView *list_view;
GtkTreeSelection *selector;
GtkListStore *store = account_create_data_store();
list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
g_object_unref(G_OBJECT(store));
gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
gtk_tree_view_set_reorderable(list_view, TRUE);
selector = gtk_tree_view_get_selection(list_view);
gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
/* create the columns */
account_create_list_view_columns(GTK_WIDGET(list_view));
/* set a double click listener */
g_signal_connect(G_OBJECT(list_view), "row_activated",
G_CALLBACK(account_double_clicked),
list_view);
g_signal_connect(G_OBJECT(list_view), "drag_begin",
G_CALLBACK(drag_begin),
list_view);
g_signal_connect(G_OBJECT(list_view), "drag_end",
G_CALLBACK(drag_end),
list_view);
gtk_tree_view_set_reorderable(list_view, TRUE);
return GTK_WIDGET(list_view);
}
static void account_create_list_view_images(GtkWidget *list_view)
{
stock_pixbuf_gdk(list_view, STOCK_PIXMAP_MARK, &mark_pixbuf);
}
static void account_create_list_view_columns(GtkWidget *list_view)
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_pixbuf_new();
column = gtk_tree_view_column_new_with_attributes
("D", renderer,
"pixbuf", ACCOUNT_IS_DEFAULT,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
renderer = gtk_cell_renderer_toggle_new();
g_object_set(renderer,
"radio", FALSE,
"activatable", TRUE,
NULL);
column = gtk_tree_view_column_new_with_attributes
("G", renderer,
"active", ACCOUNT_ENABLE_GET_ALL,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
g_signal_connect(G_OBJECT(renderer), "toggled",
G_CALLBACK(account_get_all_toggled),
list_view);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Name"), renderer,
"text", ACCOUNT_NAME,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Protocol"), renderer,
"text", ACCOUNT_PROTOCOL,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(_("Server"), renderer,
"text", ACCOUNT_SERVER,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
}
/*!
*\brief Get currently selected account (by its unique ID)
*/
static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
{
GtkTreeSelection *selector;
GtkTreeModel *model;
GtkTreeIter iter;
PrefsAccount *res = NULL;
selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
if (!gtk_tree_selection_get_selected(selector, &model, &iter))
return -1;
gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
return res->account_id;
}
/*!
*\brief Get the tree path of the currently selected account
*/
GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_view)
{
GtkTreeSelection *selector;
GtkTreeModel *model;
GtkTreeIter iter;
selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
if (!gtk_tree_selection_get_selected(selector, &model, &iter))
return NULL;
return gtk_tree_model_get_path(gtk_tree_view_get_model
(GTK_TREE_VIEW(list_view)), &iter);
}
/*!
*\brief Get the account data of the currently selected account
*/
PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
{
GtkTreeSelection *selector;
GtkTreeModel *model;
GtkTreeIter iter;
PrefsAccount *res = NULL;
selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
if (!gtk_tree_selection_get_selected(selector, &model, &iter))
return NULL;
gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
return res;
}
/*!
*\brief Select a row by the account it represents
*
*\return gboolean TRUE if found and selected, FALSE if not.
*/
gboolean account_list_view_select_account(GtkWidget *list_view, gint account_id)
{
FindAccountInStore fis;
GtkTreeModel *model;
fis.account_id = account_id;
fis.path = NULL;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc) find_account_in_store,
&fis);
if (fis.path) {
GtkTreeSelection *selection;
GtkTreePath* path;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
gtk_tree_selection_select_iter(selection, &fis.iter);
path = gtk_tree_model_get_path(model, &fis.iter);
/* XXX returned path may not be valid??? create new one to be sure */
gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view), path, NULL, FALSE);
gtk_tree_path_free(path);
}
return fis.path != NULL;
}
/*!
*\brief Set a new default account by its ID. (There is only one
* default account.)
*/
static void account_list_view_set_default_by_id(GtkWidget *list_view,
gint account_id)
{
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
gtk_tree_model_foreach
(model, (GtkTreeModelForeachFunc) set_new_default_account,
&account_id);
}
static gboolean set_new_default_account(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gint *account_id)
{
PrefsAccount *account = NULL;
GdkPixbuf *pixbuf;
gtk_tree_model_get(model, iter,
ACCOUNT_DATA, &account,
-1);
if (*account_id == account->account_id)
pixbuf = NULL;
else
pixbuf = mark_pixbuf;
gtk_list_store_set(GTK_LIST_STORE(model), iter,
ACCOUNT_IS_DEFAULT, pixbuf,
-1);
return FALSE;
}
static gboolean find_account_in_store(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
FindAccountInStore *data)
{
PrefsAccount *account = NULL;
gtk_tree_model_get(model, iter, ACCOUNT_DATA, &account, -1);
if (data->account_id == account->account_id) {
data->path = path; /* signal we found it */
data->iter = *iter;
return TRUE;
}
return FALSE;
}
/*!
*\brief Triggered when "get all" column is activated or de-activated
*/
static void account_get_all_toggled(GtkCellRendererToggle *widget,
gchar *path,
GtkWidget *list_view)
{
GtkTreeIter iter;
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
PrefsAccount *ac = NULL;
gboolean get_all;
if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
return;
gtk_tree_model_get(model, &iter,
ACCOUNT_DATA, &ac,
ACCOUNT_ENABLE_GET_ALL, &get_all,
-1);
/* check if the account has a selectable get all checkbox anyway... */
if (!(ac->protocol == A_POP3 ||
ac->protocol == A_IMAP4 ||
ac->protocol == A_NNTP ||
ac->protocol == A_LOCAL))
return;
/* set value in store */
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
ACCOUNT_ENABLE_GET_ALL, !get_all,
-1);
/* set value in account */
ac->recv_at_getall ^= TRUE;
}
static void account_double_clicked(GtkTreeView *list_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer data)
{
account_edit_prefs(NULL, NULL);
}
static void drag_begin(GtkTreeView *list_view,
GdkDragContext *context,
gpointer data)
{
/* XXX unfortunately a completed drag & drop does not emit
* a "rows_reordered" signal, but a "row_changed" signal.
* So during drag and drop, listen to "row_changed", and
* update the account list accordingly */
GtkTreeModel *model = gtk_tree_view_get_model(list_view);
g_signal_connect(G_OBJECT(model), "row_changed",
G_CALLBACK(account_row_changed_while_drag_drop),
list_view);
}
static void drag_end(GtkTreeView *list_view,
GdkDragContext *context,
gpointer data)
{
GtkTreeModel *model = gtk_tree_view_get_model(list_view);
g_signal_handlers_disconnect_by_func(G_OBJECT(model),
G_CALLBACK(account_row_changed_while_drag_drop),
list_view);
}
static void account_row_changed_while_drag_drop(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer arg3,
GtkTreeView *list_view)
{
account_list_set();
}