/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
*
- * Copyright (C) 2000-2006 by Alfons Hoogervorst & The Sylpheed Claws Team.
+ * Copyright (C) 2000-2012 by Alfons Hoogervorst & The Claws Mail Team.
*
* 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
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#include "defs.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkeditable.h>
-#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtktreeview.h>
-#include <gtk/gtktreemodel.h>
-#include <gtk/gtkliststore.h>
+#include <gtk/gtk.h>
#include <string.h>
#include <ctype.h>
# include <wctype.h>
#endif
-#include "addrindex.h"
#include "addr_compl.h"
+#include "addritem.h"
#include "utils.h"
#include "prefs_common.h"
-#include "sylpheed.h"
+#include "claws.h"
+#include "hooks.h"
+#include "gtkutils.h"
+#include "stock_pixmap.h"
#include <pthread.h>
+#ifndef USE_NEW_ADDRBOOK
+ #include "addrindex.h"
+#else
+ #include "addressbook-dbus.h"
+#endif
+
/*!
*\brief For the GtkListStore
*/
enum {
+ ADDR_COMPL_ICON,
ADDR_COMPL_ADDRESS,
+ ADDR_COMPL_ISGROUP,
+ ADDR_COMPL_GROUPLIST,
N_ADDR_COMPL_COLUMNS
};
* addresses a little more (e.g. break up alfons@proteus.demon.nl into
* something like alfons, proteus, demon, nl; and then completing on
* any of those words).
- */
-
-/**
- * address_entry - structure which refers to the original address entry in the
- * address book .
*/
-typedef struct
-{
- gchar *name;
- gchar *address;
-} address_entry;
/**
* completion_entry - structure used to complete addresses, with a reference
/*******************************************************************************/
static gint g_ref_count; /* list ref count */
-static GList *g_completion_list; /* list of strings to be checked */
-static GList *g_address_list; /* address storage */
+static GList *g_completion_list = NULL; /* list of strings to be checked */
+static GList *g_address_list = NULL; /* address storage */
static GCompletion *g_completion; /* completion object */
+static GHashTable *_groupAddresses_ = NULL;
+static gboolean _allowCommas_ = TRUE;
+
/* To allow for continuing completion we have to keep track of the state
* using the following variables. No need to create a context object. */
completion cache. */
static gchar *g_completion_prefix; /* last prefix. (this is cached here
* because the prefix passed to g_completion
- * is g_strdown()'ed */
+ * is g_utf8_strdown()'ed */
+
+static gchar *completion_folder_path = NULL;
/*******************************************************************************/
*/
static gchar *completion_func(gpointer data)
{
- g_return_val_if_fail(data != NULL, NULL);
+ cm_return_val_if_fail(data != NULL, NULL);
return ((completion_entry *)data)->string;
}
+static gint addr_completion_func(const gchar *needle, const gchar *haystack,
+ gsize n)
+{
+ if (needle == NULL || haystack == NULL)
+ return 1;
+
+ return (strcasestr(haystack, needle) != NULL ? 0 : 1);
+}
+
+/**
+ * Function used by GTK to compare elements for sorting
+ * name match beginning > name match after space > email address
+ * match beginning and full match before @ > email adress
+ * match beginning. Otherwise match position in string.
+ * \param a first element in comparsion
+ * \param b second element in comparison
+ */
+static gint weight_addr_match(const address_entry* addr)
+{
+ gint n_weight = addr->name ? strlen(addr->name): 0;
+ gint a_weight = addr->address ? strlen(addr->address) : n_weight;
+ gchar* match = NULL;
+
+ if (addr->name)
+ match = strcasestr(addr->name, g_completion_prefix);
+
+ if (match != NULL) {
+ if (match == addr->name)
+ n_weight = -4;
+ else if (match > addr->name && *(match - 1) == ' ')
+ n_weight = -3;
+ else
+ n_weight = match - addr->name;
+ }
+
+ if (addr->address) {
+ match = strcasestr(addr->address, g_completion_prefix);
+ if (match != NULL) {
+ if (match == addr->address)
+ a_weight = -1;
+ else
+ a_weight = match - addr->address;
+
+ if (strlen(match) > strlen(g_completion_prefix)
+ && *(match + strlen(g_completion_prefix)) == '@')
+ a_weight--;
+ }
+ }
+
+ if (n_weight == -4 && a_weight < 0)
+ n_weight = -5;
+
+ return MIN(a_weight, n_weight);
+}
+
+static gint addr_comparison_func(gconstpointer a, gconstpointer b)
+{
+ const address_entry* a_ref = (const address_entry*)a;
+ const address_entry* b_ref = (const address_entry*)b;
+ gint a_weight = weight_addr_match(a_ref);
+ gint b_weight = weight_addr_match(b_ref);
+ gint cmp;
+
+ if (a_weight < b_weight)
+ return -1;
+ else if (a_weight > b_weight)
+ return 1;
+ else {
+ cmp = strcmp(a_ref->name, b_ref->name);
+ return cmp ? cmp : g_strcmp0(a_ref->address, b_ref->address);
+ }
+}
+
/**
* Initialize all completion index data.
*/
static void init_all(void)
{
g_completion = g_completion_new(completion_func);
- g_return_if_fail(g_completion != NULL);
+ cm_return_if_fail(g_completion != NULL);
}
/**
- * Free up all completion index data.
+ * set the compare function (default is strncmp)
*/
-static void free_all(void)
+static void set_match_any_part(const gboolean any_part)
+{
+ if (any_part && prefs_common.address_search_wildcard)
+ g_completion_set_compare(g_completion, addr_completion_func);
+ else
+ g_completion_set_compare(g_completion, strncmp);
+}
+
+static void free_all_addresses(void)
{
GList *walk;
-
- walk = g_list_first(g_completion_list);
- for (; walk != NULL; walk = g_list_next(walk)) {
- completion_entry *ce = (completion_entry *) walk->data;
- g_free(ce->string);
- g_free(walk->data);
- }
- g_list_free(g_completion_list);
- g_completion_list = NULL;
-
+ if (!g_address_list)
+ return;
walk = g_address_list;
for (; walk != NULL; walk = g_list_next(walk)) {
address_entry *ae = (address_entry *) walk->data;
g_free(ae->name);
g_free(ae->address);
+ g_list_free(ae->grp_emails);
g_free(walk->data);
}
g_list_free(g_address_list);
g_address_list = NULL;
+ if (_groupAddresses_)
+ g_hash_table_destroy(_groupAddresses_);
+ _groupAddresses_ = NULL;
+}
+
+static void clear_completion_cache(void);
+static void free_completion_list(void)
+{
+ GList *walk;
+ if (!g_completion_list)
+ return;
+ clear_completion_cache();
+ if (g_completion)
+ g_completion_clear_items(g_completion);
+
+ walk = g_list_first(g_completion_list);
+ for (; walk != NULL; walk = g_list_next(walk)) {
+ completion_entry *ce = (completion_entry *) walk->data;
+ g_free(ce->string);
+ g_free(walk->data);
+ }
+ g_list_free(g_completion_list);
+ g_completion_list = NULL;
+}
+/**
+ * Free up all completion index data.
+ */
+static void free_all(void)
+{
+ free_completion_list();
+ free_all_addresses();
g_completion_free(g_completion);
g_completion = NULL;
}
* \param str Index string value.
* \param ae Entry containing address data.
*/
-static void add_address1(const char *str, address_entry *ae)
+void addr_compl_add_address1(const char *str, address_entry *ae)
{
completion_entry *ce1;
ce1 = g_new0(completion_entry, 1),
* \param name Recipient name.
* \param address EMail address.
* \param alias Alias to append.
+ * \param grp_emails the emails in case of a group. List should be freed later,
+ * but not its strings
* \return <code>0</code> if entry appended successfully, or <code>-1</code>
* if failure.
*/
static gint add_address(const gchar *name, const gchar *address,
- const gchar *nick, const gchar *alias)
+ const gchar *nick, const gchar *alias, GList *grp_emails)
{
- address_entry *ae;
+ address_entry *ae;
+
+ if (!address && !grp_emails)
+ return -1;
- if (!name || !address) return -1;
+ if (!name)
+ name = "";
ae = g_new0(address_entry, 1);
+ cm_return_val_if_fail(ae != NULL, -1);
- g_return_val_if_fail(ae != NULL, -1);
+ ae->name = g_strdup(name);
+ ae->address = g_strdup(address);
+ ae->grp_emails = grp_emails;
+ g_address_list = g_list_prepend(g_address_list, ae);
- ae->name = g_strdup(name);
- ae->address = g_strdup(address);
+ addr_compl_add_address1(name, ae);
- g_address_list = g_list_prepend(g_address_list, ae);
+ if (address != NULL && *address != '\0')
+ addr_compl_add_address1(address, ae);
- add_address1(name, ae);
- add_address1(address, ae);
-
- if (nick != NULL)
- add_address1(nick, ae);
-
- if ( alias != NULL ) {
- add_address1(alias, ae);
- }
+ if (nick != NULL && *nick != '\0')
+ addr_compl_add_address1(nick, ae);
+
+ if (alias != NULL && *alias != '\0')
+ addr_compl_add_address1(alias, ae);
return 0;
}
/**
* Read address book, creating all entries in the completion index.
*/
-static void read_address_book(void) {
- addrindex_load_completion( add_address );
+static void read_address_book(gchar *folderpath) {
+ free_all_addresses();
+ free_completion_list();
+
+#ifndef USE_NEW_ADDRBOOK
+ addrindex_load_completion( add_address, folderpath );
+#else
+ GError* error = NULL;
+
+ addrcompl_initialize();
+ if (! addrindex_dbus_load_completion(add_address, &error)) {
+ g_warning("Failed to populate address completion list");
+ g_error_free(error);
+ return;
+ }
+#endif
+ /* plugins may hook in here to modify/extend the completion list */
+ if(!folderpath) {
+ hooks_invoke(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, &g_address_list);
+ }
+
g_address_list = g_list_reverse(g_address_list);
g_completion_list = g_list_reverse(g_completion_list);
+ /* merge the completion entry list into g_completion */
+ if (g_completion_list) {
+ g_completion_add_items(g_completion, g_completion_list);
+ if (debug_get_mode())
+ debug_print("read %d items in %s\n",
+ g_list_length(g_completion_list),
+ folderpath?folderpath:"(null)");
+ }
}
/**
static void clear_completion_cache(void)
{
if (is_completion_pending()) {
- if (g_completion_prefix)
- g_free(g_completion_prefix);
+ g_free(g_completion_prefix);
if (g_completion_addresses) {
g_slist_free(g_completion_addresses);
* address completion.
* \return The number of addresses in the completion list.
*/
-gint start_address_completion(void)
+gint start_address_completion(gchar *folderpath)
{
+ gboolean different_book = FALSE;
clear_completion_cache();
+
+ if (strcmp2(completion_folder_path,folderpath))
+ different_book = TRUE;
+
+ g_free(completion_folder_path);
+ if (folderpath != NULL)
+ completion_folder_path = g_strdup(folderpath);
+ else
+ completion_folder_path = NULL;
+
if (!g_ref_count) {
init_all();
/* open the address book */
- read_address_book();
- /* merge the completion entry list into g_completion */
- if (g_completion_list)
- g_completion_add_items(g_completion, g_completion_list);
- }
+ read_address_book(folderpath);
+ } else if (different_book)
+ read_address_book(folderpath);
+
g_ref_count++;
- debug_print("start_address_completion ref count %d\n", g_ref_count);
+ debug_print("start_address_completion(%s) ref count %d\n",
+ folderpath?folderpath:"(null)", g_ref_count);
return g_list_length(g_completion_list);
}
return str;
}
+static gchar *get_complete_address_from_name_email(const gchar *name, const gchar *email)
+{
+ gchar *address = NULL;
+ if (!name || name[0] == '\0')
+ address = g_strdup_printf("<%s>", email);
+ else if (strchr_with_skip_quote(name, '"', ','))
+ address = g_strdup_printf
+ ("\"%s\" <%s>", name, email);
+ else
+ address = g_strdup_printf
+ ("%s <%s>", name, email);
+ return address;
+}
+
/**
* Replace an incompleted address with a completed one.
* \param entry Address entry field.
* \param start_pos Insertion point in entry field.
*/
static void replace_address_in_edit(GtkEntry *entry, const gchar *newtext,
- gint start_pos)
+ gint start_pos, gboolean is_group, GList *grp_emails)
{
if (!newtext) return;
gtk_editable_delete_text(GTK_EDITABLE(entry), start_pos, -1);
- gtk_editable_insert_text(GTK_EDITABLE(entry), newtext, strlen(newtext),
+ if (!is_group) {
+ gtk_editable_insert_text(GTK_EDITABLE(entry), newtext, strlen(newtext),
+ &start_pos);
+ } else {
+ gchar *addresses = NULL;
+ GList *cur = grp_emails;
+ for (; cur; cur = cur->next) {
+ gchar *tmp;
+ ItemEMail *email = (ItemEMail *)cur->data;
+ ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(email);
+
+ gchar *addr = get_complete_address_from_name_email(
+ ADDRITEM_NAME(person), email->address);
+ if (addresses)
+ tmp = g_strdup_printf("%s, %s", addresses, addr);
+ else
+ tmp = g_strdup_printf("%s", addr);
+ g_free(addr);
+ g_free(addresses);
+ addresses = tmp;
+ }
+ gtk_editable_insert_text(GTK_EDITABLE(entry), addresses, strlen(addresses),
&start_pos);
+ g_free(addresses);
+ }
gtk_editable_set_position(GTK_EDITABLE(entry), -1);
}
*/
guint complete_address(const gchar *str)
{
- GList *result;
- gchar *d;
- guint count, cpl;
- completion_entry *ce;
+ GList *result = NULL;
+ gchar *d = NULL;
+ guint count = 0;
+ guint cpl = 0;
+ completion_entry *ce = NULL;
- g_return_val_if_fail(str != NULL, 0);
+ cm_return_val_if_fail(str != NULL, 0);
/* g_completion is case sensitive */
d = g_utf8_strdown(str, -1);
}
count = cpl + 1; /* index 0 is the original prefix */
g_completion_next = 1; /* we start at the first completed one */
+ if (prefs_common.address_search_wildcard)
+ g_completion_addresses = g_slist_sort(g_completion_addresses,
+ addr_comparison_func);
} else {
g_free(g_completion_prefix);
g_completion_prefix = NULL;
return count;
}
+/**
+ * complete_matches_found() returns the number of matched addresses according
+ * to the completion mechanism. Unlike complete_address(), the returned value
+ * doesn't count str itself. If there's no match, it returns 0.
+ * To get a list of completion matches, see complete_address() instead.
+ */
+guint complete_matches_found(const gchar *str)
+{
+ GList *result = NULL;
+ gchar *d = NULL;
+
+ cm_return_val_if_fail(str != NULL, 0);
+
+ /* g_completion is case sensitive */
+ d = g_utf8_strdown(str, -1);
+
+ clear_completion_cache();
+ g_completion_prefix = g_strdup(str);
+
+ result = g_completion_complete(g_completion, d, NULL);
+
+ g_free(g_completion_prefix);
+ g_free(d);
+
+ return g_list_length(result);
+}
+
/**
* Return a complete address from the index.
* \param index Index of entry that was found (by the previous call to
/* get something from the unique addresses */
p = (address_entry *)g_slist_nth_data
(g_completion_addresses, index - 1);
- if (p != NULL) {
- if (!p->name || p->name[0] == '\0')
- address = g_strdup_printf(p->address);
- else if (strchr_with_skip_quote(p->name, '"', ','))
- address = g_strdup_printf
- ("\"%s\" <%s>", p->name, p->address);
- else
- address = g_strdup_printf
- ("%s <%s>", p->name, p->address);
+ if (p != NULL && p->address != NULL) {
+ address = get_complete_address_from_name_email(p->name, p->address);
+ } else if (p != NULL && p->address == NULL && p->name != NULL) {
+ /* that's a group */
+ address = g_strdup_printf("%s (%s) <!--___group___-->", p->name, _("Group"));
+ if (!_groupAddresses_) {
+ _groupAddresses_ = g_hash_table_new(NULL, g_direct_equal);
+ }
+ if (!g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)))) {
+ g_hash_table_insert(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)), p->grp_emails);
+
+ }
}
}
}
if (g_ref_count) {
/* simply the same as start_address_completion() */
debug_print("Invalidation request for address completion\n");
- free_all();
- init_all();
- read_address_book();
- g_completion_add_items(g_completion, g_completion_list);
+ read_address_book(completion_folder_path);
clear_completion_cache();
}
*/
gint end_address_completion(void)
{
+ gboolean different_folder = FALSE;
clear_completion_cache();
+ /* reset the folderpath to NULL */
+ if (completion_folder_path) {
+ g_free(completion_folder_path);
+ completion_folder_path = NULL;
+ different_folder = TRUE;
+ }
if (0 == --g_ref_count)
free_all();
debug_print("end_address_completion ref count %d\n", g_ref_count);
+ if (g_ref_count && different_folder) {
+ debug_print("still ref'd, different folder\n");
+ invalidate_address_completion();
+ }
return g_ref_count;
}
* Completion queue list.
*/
static GList *_displayQueue_ = NULL;
-
/**
* Current query ID.
*/
/*
* address completion entry ui. the ui (completion list was inspired by galeon's
- * auto completion list). remaining things powered by sylpheed's completion engine.
+ * auto completion list). remaining things powered by claws's completion engine.
*/
#define ENTRY_DATA_TAB_HOOK "tab_hook" /* used to lookup entry */
+#define ENTRY_DATA_ALLOW_COMMAS "allowcommas" /* used to know whether to present groups */
static void address_completion_mainwindow_set_focus (GtkWindow *window,
GtkWidget *widget,
*/
static void addrcompl_destroy_window( CompletionWindow *cw ) {
/* Stop all searches currently in progress */
+#ifndef USE_NEW_ADDRBOOK
addrindex_stop_search( _queryID_ );
-
+#endif
/* Remove idler function... or application may not terminate */
if( _completionIdleID_ != 0 ) {
- gtk_idle_remove( _completionIdleID_ );
+ g_source_remove( _completionIdleID_ );
_completionIdleID_ = 0;
}
GtkTreeIter iter;
GtkTreeModel *model;
- g_return_if_fail(list_view != NULL);
+ cm_return_if_fail(list_view != NULL);
selection = gtk_tree_view_get_selection(list_view);
if (!gtk_tree_selection_get_selected(selection, &model, &iter))
gint x, y, width, height, depth;
/* Get current geometry of window */
- gdk_window_get_geometry( cw->window->window, &x, &y, &width, &height, &depth );
+#if !GTK_CHECK_VERSION(3, 0, 0)
+ gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height, &depth );
+#else
+ gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height );
+#endif
- gtk_widget_hide_all( cw->window );
- gtk_widget_show_all( cw->window );
+ gtk_widget_queue_resize_no_redraw(cw->list_view);
gtk_widget_size_request( cw->list_view, &r );
/* Adjust window height to available screen space */
- if( ( y + r.height ) > gdk_screen_height() ) {
- gtk_window_set_resizable(GTK_WINDOW(cw->window), FALSE);
- gtk_widget_set_size_request( cw->window, width, gdk_screen_height() - y );
- } else
- gtk_widget_set_size_request(cw->window, width, r.height);
+ if( y + r.height > gdk_screen_height())
+ r.height = gdk_screen_height() - y;
+
+ gtk_widget_set_size_request(cw->window, width, r.height);
+
+ gdk_pointer_grab(gtk_widget_get_window(cw->window), TRUE,
+ GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK,
+ NULL, NULL, GDK_CURRENT_TIME);
+ gdk_keyboard_grab(gtk_widget_get_window(cw->window), FALSE, GDK_CURRENT_TIME);
+ gtk_grab_add(cw->window);
+
}
+static GdkPixbuf *group_pixbuf = NULL;
+static GdkPixbuf *email_pixbuf = NULL;
+
/**
* Add an address the completion window address list.
* \param cw Completion window.
GtkListStore *store;
GtkTreeIter iter;
GtkTreeSelection *selection;
-
+ gboolean is_group = FALSE;
+ GList *grp_emails = NULL;
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cw->list_view)));
+ GdkPixbuf *pixbuf;
+
+ if (!group_pixbuf) {
+ stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_TWO, &group_pixbuf);
+ g_object_ref(G_OBJECT(group_pixbuf));
+ }
+ if (!email_pixbuf) {
+ stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_ONE, &email_pixbuf);
+ g_object_ref(G_OBJECT(email_pixbuf));
+ }
+ /* g_print( "\t\tAdding :%s\n", address ); */
+ if (strstr(address, " <!--___group___-->")) {
+ is_group = TRUE;
+ if (_groupAddresses_)
+ grp_emails = g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)));
+ *(strstr(address, " <!--___group___-->")) = '\0';
+ pixbuf = group_pixbuf;
+ } else if (strchr(address, '@') && strchr(address, '<') &&
+ strchr(address, '>')) {
+ pixbuf = email_pixbuf;
+ } else
+ pixbuf = NULL;
+
+ if (is_group && !_allowCommas_)
+ return;
gtk_list_store_append(store, &iter);
-
- /* printf( "\t\tAdding :%s\n", address ); */
- gtk_list_store_set(store, &iter, ADDR_COMPL_ADDRESS, address, -1);
+ gtk_list_store_set(store, &iter,
+ ADDR_COMPL_ICON, pixbuf,
+ ADDR_COMPL_ADDRESS, address,
+ ADDR_COMPL_ISGROUP, is_group,
+ ADDR_COMPL_GROUPLIST, grp_emails,
+ -1);
cw->listCount++;
/* Resize window */
/* Select first row for now */
gtk_tree_selection_select_iter(selection, &iter);
}
+#ifndef GENERIC_UMPC
else if( cw->listCount == 2 ) {
- gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
- /* Move off first row */
- gtk_tree_selection_select_iter(selection, &iter);
+ if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)) {
+ /* Move off first row */
+ gtk_tree_selection_select_iter(selection, &iter);
+ }
+ }
+#endif
+}
+
+void addrcompl_reflect_prefs_pixmap_theme(void) {
+ if (group_pixbuf) {
+ g_object_unref(G_OBJECT(group_pixbuf));
+ group_pixbuf = NULL;
+ }
+ if (email_pixbuf) {
+ g_object_unref(G_OBJECT(email_pixbuf));
+ email_pixbuf = NULL;
}
}
node = _displayQueue_;
while( node ) {
address = node->data;
- /* printf( "address ::: %s :::\n", address ); */
+ /* g_print( "address ::: %s :::\n", address ); */
addrcompl_add_entry( _compWindow_, address );
g_free( address );
node = g_list_next( node );
_displayQueue_ = NULL;
}
pthread_mutex_unlock( & _completionMutex_ );
- sylpheed_do_idle();
+ claws_do_idle();
return TRUE;
}
* criteria.
* \param data Query data.
*/
+#ifndef USE_NEW_ADDRBOOK
static gint addrcompl_callback_entry(
gpointer sender, gint queryID, GList *listEMail, gpointer data )
{
GList *node;
gchar *address;
- /* printf( "addrcompl_callback_entry::queryID=%d\n", queryID ); */
+ /* g_print( "addrcompl_callback_entry::queryID=%d\n", queryID ); */
pthread_mutex_lock( & _completionMutex_ );
if( queryID == _queryID_ ) {
/* Append contents to end of display queue */
ItemEMail *email = node->data;
address = addritem_format_email( email );
- /* printf( "\temail/address ::%s::\n", address ); */
+ /* g_print( "\temail/address ::%s::\n", address ); */
_displayQueue_ = g_list_append( _displayQueue_, address );
node = g_list_next( node );
}
return 0;
}
+#endif
/**
* Clear the display queue.
gchar *address;
address = get_complete_address( count );
- /* printf( "\taddress ::%s::\n", address ); */
+ /* g_print( "\taddress ::%s::\n", address ); */
/* Append contents to end of display queue */
addrcompl_add_queue( address );
* Start the search.
*/
static void addrcompl_start_search( void ) {
+#ifndef USE_NEW_ADDRBOOK
gchar *searchTerm;
searchTerm = g_strdup( _compWindow_->searchTerm );
_queryID_ = addrindex_setup_search(
searchTerm, NULL, addrcompl_callback_entry );
g_free( searchTerm );
- /* printf( "addrcompl_start_search::queryID=%d\n", _queryID_ ); */
+#endif
+ /* g_print( "addrcompl_start_search::queryID=%d\n", _queryID_ ); */
/* Load local stuff */
addrcompl_load_local();
/* Sit back and wait until something happens */
_completionIdleID_ =
- gtk_idle_add( ( GtkFunction ) addrcompl_idle, NULL );
- /* printf( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
+ g_idle_add( (GSourceFunc) addrcompl_idle, NULL );
+ /* g_print( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
+#ifndef USE_NEW_ADDRBOOK
addrindex_start_search( _queryID_ );
+#else
+
+#endif
}
/**
* moved to the next widget so that Tab key works correctly.
* \param list_view List to process.
* \param entry Address entry field.
+ * \param move_focus Move focus to the next widget ?
*/
-static void completion_window_apply_selection(GtkTreeView *list_view, GtkEntry *entry)
+static void completion_window_apply_selection(GtkTreeView *list_view,
+ GtkEntry *entry,
+ gboolean move_focus)
{
gchar *address = NULL, *text = NULL;
gint cursor_pos;
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
-
- g_return_if_fail(list_view != NULL);
- g_return_if_fail(entry != NULL);
+ gboolean is_group = FALSE;
+ cm_return_if_fail(list_view != NULL);
+ cm_return_if_fail(entry != NULL);
+ GList *grp_emails = NULL;
selection = gtk_tree_view_get_selection(list_view);
if (! gtk_tree_selection_get_selected(selection, &model, &iter))
/* First remove the idler */
if( _completionIdleID_ != 0 ) {
- gtk_idle_remove( _completionIdleID_ );
+ g_source_remove( _completionIdleID_ );
_completionIdleID_ = 0;
}
/* Process selected item */
- gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text, -1);
+ gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text,
+ ADDR_COMPL_ISGROUP, &is_group,
+ ADDR_COMPL_GROUPLIST, &grp_emails,
+ -1);
address = get_address_from_edit(entry, &cursor_pos);
g_free(address);
- replace_address_in_edit(entry, text, cursor_pos);
+ replace_address_in_edit(entry, text, cursor_pos, is_group, grp_emails);
g_free(text);
/* Move focus to next widget */
- parent = GTK_WIDGET(entry)->parent;
- if( parent ) {
+ parent = gtk_widget_get_parent(GTK_WIDGET(entry));
+ if( parent && move_focus) {
gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
}
}
*/
void address_completion_start(GtkWidget *mainwindow)
{
- start_address_completion();
+ start_address_completion(NULL);
+ set_match_any_part(TRUE);
/* register focus change hook */
g_signal_connect(G_OBJECT(mainwindow), "set_focus",
* Register specified entry widget for address completion.
* \param entry Address entry field.
*/
-void address_completion_register_entry(GtkEntry *entry)
+void address_completion_register_entry(GtkEntry *entry, gboolean allow_commas)
{
- g_return_if_fail(entry != NULL);
- g_return_if_fail(GTK_IS_ENTRY(entry));
+ cm_return_if_fail(entry != NULL);
+ cm_return_if_fail(GTK_IS_ENTRY(entry));
/* add hooked property */
g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, entry);
+ g_object_set_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS, GINT_TO_POINTER(allow_commas));
/* add keypress event */
g_signal_connect_closure
*/
void address_completion_unregister_entry(GtkEntry *entry)
{
- GtkObject *entry_obj;
+ GObject *entry_obj;
- g_return_if_fail(entry != NULL);
- g_return_if_fail(GTK_IS_ENTRY(entry));
+ cm_return_if_fail(entry != NULL);
+ cm_return_if_fail(GTK_IS_ENTRY(entry));
entry_obj = g_object_get_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
- g_return_if_fail(entry_obj);
- g_return_if_fail(G_OBJECT(entry_obj) == G_OBJECT(entry));
+ cm_return_if_fail(entry_obj);
+ cm_return_if_fail(G_OBJECT(entry_obj) == G_OBJECT(entry));
/* has the hooked property? */
g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
if (widget && GTK_IS_ENTRY(widget) &&
g_object_get_data(G_OBJECT(widget), ENTRY_DATA_TAB_HOOK)) {
+ _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), ENTRY_DATA_ALLOW_COMMAS));
clear_completion_cache();
}
}
GdkEventKey *ev,
gpointer data)
{
- if (ev->keyval == GDK_Tab) {
+ if (ev->keyval == GDK_KEY_Tab) {
addrcompl_clear_queue();
-
+ _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
if( address_completion_complete_address_in_entry( entry, TRUE ) ) {
/* route a void character to the default handler */
/* this is a dirty hack; we're actually changing a key
* reported by the system. */
- ev->keyval = GDK_AudibleBell_Enable;
+ ev->keyval = GDK_KEY_AudibleBell_Enable;
ev->state &= ~GDK_SHIFT_MASK;
/* Create window */
else {
/* old behaviour */
}
- } else if (ev->keyval == GDK_Shift_L
- || ev->keyval == GDK_Shift_R
- || ev->keyval == GDK_Control_L
- || ev->keyval == GDK_Control_R
- || ev->keyval == GDK_Caps_Lock
- || ev->keyval == GDK_Shift_Lock
- || ev->keyval == GDK_Meta_L
- || ev->keyval == GDK_Meta_R
- || ev->keyval == GDK_Alt_L
- || ev->keyval == GDK_Alt_R) {
+ } else if (ev->keyval == GDK_KEY_Shift_L
+ || ev->keyval == GDK_KEY_Shift_R
+ || ev->keyval == GDK_KEY_Control_L
+ || ev->keyval == GDK_KEY_Control_R
+ || ev->keyval == GDK_KEY_Caps_Lock
+ || ev->keyval == GDK_KEY_Shift_Lock
+ || ev->keyval == GDK_KEY_Meta_L
+ || ev->keyval == GDK_KEY_Meta_R
+ || ev->keyval == GDK_KEY_Alt_L
+ || ev->keyval == GDK_KEY_Alt_R) {
/* these buttons should not clear the cache... */
} else
clear_completion_cache();
gint ncount, cursor_pos;
gchar *searchTerm, *new = NULL;
- g_return_val_if_fail(entry != NULL, FALSE);
+ cm_return_val_if_fail(entry != NULL, FALSE);
- if (!GTK_WIDGET_HAS_FOCUS(entry)) return FALSE;
+ if (!gtk_widget_has_focus(GTK_WIDGET(entry))) return FALSE;
/* get an address component from the cursor */
searchTerm = get_address_from_edit( entry, &cursor_pos );
if( ! searchTerm ) return FALSE;
- /* printf( "search for :::%s:::\n", searchTerm ); */
+ /* g_print( "search for :::%s:::\n", searchTerm ); */
/* Clear any existing search */
- if( _compWindow_->searchTerm ) {
- g_free( _compWindow_->searchTerm );
- }
+ g_free( _compWindow_->searchTerm );
_compWindow_->searchTerm = g_strdup( searchTerm );
/* Perform search on local completion index */
new = get_next_complete_address();
g_free( new );
}
-
-#ifndef USE_LDAP
+#if (!defined(USE_LDAP) && !defined(GENERIC_UMPC))
/* Select the address if there is only one match */
if (ncount == 2) {
/* Display selected address in entry field */
gchar *addr = get_complete_address(1);
-
- if (addr) {
- replace_address_in_edit(entry, addr, cursor_pos);
- g_free(addr);
- }
-
- /* Discard the window */
- clear_completion_cache();
+ if (addr && !strstr(addr, " <!--___group___-->")) {
+ replace_address_in_edit(entry, addr, cursor_pos, FALSE, NULL);
+ /* Discard the window */
+ clear_completion_cache();
+ }
+ g_free(addr);
}
/* Make sure that drop-down appears uniform! */
else
GtkRequisition r;
GtkWidget *window;
GtkWidget *entry = GTK_WIDGET(entry_);
+ GdkWindow *gdkwin;
/* Create new window and list */
window = gtk_window_new(GTK_WINDOW_POPUP);
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(window), scroll);
gtk_container_add(GTK_CONTAINER(scroll), list_view);
-
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
+ GTK_SHADOW_OUT);
/* Use entry widget to create initial window */
- gdk_window_get_geometry(entry->window, &x, &y, &width, &height, &depth);
- gdk_window_get_deskrelative_origin (entry->window, &x, &y);
+ gdkwin = gtk_widget_get_window(entry),
+#if !GTK_CHECK_VERSION(3, 0, 0)
+ gdk_window_get_geometry(gdkwin, &x, &y, &width, &height, &depth);
+#else
+ gdk_window_get_geometry(gdkwin, &x, &y, &width, &height);
+#endif
+ gdk_window_get_origin (gdkwin, &x, &y);
y += height;
gtk_window_move(GTK_WINDOW(window), x, y);
"key-press-event",
G_CALLBACK(completion_window_key_press),
_compWindow_ );
- gdk_pointer_grab(window->window, TRUE,
+ gdk_pointer_grab(gtk_widget_get_window(window), TRUE,
GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, GDK_CURRENT_TIME);
+ gdk_keyboard_grab(gtk_widget_get_window(window), FALSE, GDK_CURRENT_TIME);
gtk_grab_add( window );
-
- /* XXX: GTK2 too???
- *
- * GTK1: this gets rid of the irritating focus rectangle that doesn't
- * follow the selection */
- GTK_WIDGET_UNSET_FLAGS(list_view, GTK_CAN_FOCUS);
}
/**
gint cursor_pos;
gboolean restore = TRUE;
- g_return_val_if_fail(compWin != NULL, FALSE);
+ cm_return_val_if_fail(compWin != NULL, FALSE);
entry = compWin->entry;
- g_return_val_if_fail(entry != NULL, FALSE);
+ cm_return_val_if_fail(entry != NULL, FALSE);
/* Test where mouse was clicked */
event_widget = gtk_get_event_widget((GdkEvent *)event);
restore = FALSE;
break;
}
- event_widget = event_widget->parent;
+ event_widget = gtk_widget_get_parent(event_widget);
}
}
/* Clicked outside of completion window - restore */
searchTerm = _compWindow_->searchTerm;
g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
- replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos);
+ replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
}
clear_completion_cache();
gint cursor_pos;
GtkWidget *list_view;
GtkWidget *parent;
-
- g_return_val_if_fail(compWin != NULL, FALSE);
+ cm_return_val_if_fail(compWin != NULL, FALSE);
entry = compWin->entry;
list_view = compWin->list_view;
- g_return_val_if_fail(entry != NULL, FALSE);
+ cm_return_val_if_fail(entry != NULL, FALSE);
/* allow keyboard navigation in the alternatives tree view */
- if (event->keyval == GDK_Up || event->keyval == GDK_Down ||
- event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down) {
+ if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down ||
+ event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down) {
completion_window_advance_selection
(GTK_TREE_VIEW(list_view),
- event->keyval == GDK_Down ||
- event->keyval == GDK_Page_Down ? TRUE : FALSE);
- return FALSE;
+ event->keyval == GDK_KEY_Down ||
+ event->keyval == GDK_KEY_Page_Down ? TRUE : FALSE);
+ return TRUE;
}
-#if 0
- /* also make tab / shift tab go to next previous completion entry. we're
- * changing the key value */
- if (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab) {
- event->keyval = (event->state & GDK_SHIFT_MASK)
- ? GDK_Up : GDK_Down;
- /* need to reset shift state if going up */
- if (event->state & GDK_SHIFT_MASK)
- event->state &= ~GDK_SHIFT_MASK;
- completion_window_advance_selection(GTK_CLIST(clist),
- event->keyval == GDK_Down ? TRUE : FALSE);
- return FALSE;
- }
-#endif
-
/* make tab move to next field */
- if( event->keyval == GDK_Tab ) {
+ if( event->keyval == GDK_KEY_Tab ) {
/* Reference to parent */
- parent = GTK_WIDGET(entry)->parent;
+ parent = gtk_widget_get_parent(GTK_WIDGET(entry));
/* Discard the window */
clear_completion_cache();
}
/* make backtab move to previous field */
- if( event->keyval == GDK_ISO_Left_Tab ) {
+ if( event->keyval == GDK_KEY_ISO_Left_Tab ) {
/* Reference to parent */
- parent = GTK_WIDGET(entry)->parent;
+ parent = gtk_widget_get_parent(GTK_WIDGET(entry));
/* Discard the window */
clear_completion_cache();
}
return FALSE;
}
+ _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
/* look for presses that accept the selection */
- if (event->keyval == GDK_Return || event->keyval == GDK_space) {
+ if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_space ||
+ event->keyval == GDK_KEY_KP_Enter ||
+ (_allowCommas_ && event->keyval == GDK_KEY_comma)) {
/* User selected address with a key press */
/* Display selected address in entry field */
completion_window_apply_selection(
- GTK_TREE_VIEW(list_view), GTK_ENTRY(entry) );
+ GTK_TREE_VIEW(list_view), GTK_ENTRY(entry),
+ event->keyval != GDK_KEY_comma);
+
+ if (event->keyval == GDK_KEY_comma) {
+ gint pos = gtk_editable_get_position(GTK_EDITABLE(entry));
+ gtk_editable_insert_text(GTK_EDITABLE(entry), ", ", 2, &pos);
+ gtk_editable_set_position(GTK_EDITABLE(entry), pos + 1);
+ }
/* Discard the window */
clear_completion_cache();
}
/* key state keys should never be handled */
- if (event->keyval == GDK_Shift_L
- || event->keyval == GDK_Shift_R
- || event->keyval == GDK_Control_L
- || event->keyval == GDK_Control_R
- || event->keyval == GDK_Caps_Lock
- || event->keyval == GDK_Shift_Lock
- || event->keyval == GDK_Meta_L
- || event->keyval == GDK_Meta_R
- || event->keyval == GDK_Alt_L
- || event->keyval == GDK_Alt_R) {
+ if (event->keyval == GDK_KEY_Shift_L
+ || event->keyval == GDK_KEY_Shift_R
+ || event->keyval == GDK_KEY_Control_L
+ || event->keyval == GDK_KEY_Control_R
+ || event->keyval == GDK_KEY_Caps_Lock
+ || event->keyval == GDK_KEY_Shift_Lock
+ || event->keyval == GDK_KEY_Meta_L
+ || event->keyval == GDK_KEY_Meta_R
+ || event->keyval == GDK_KEY_Alt_L
+ || event->keyval == GDK_KEY_Alt_R) {
return FALSE;
}
/* some other key, let's restore the searchTerm (orignal text) */
searchTerm = _compWindow_->searchTerm;
g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
- replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos);
+ replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
/* make sure anything we typed comes in the edit box */
tmp_event.type = event->type;
- tmp_event.window = entry->window;
+ tmp_event.window = gtk_widget_get_window(GTK_WIDGET(entry));
tmp_event.send_event = TRUE;
tmp_event.time = event->time;
tmp_event.state = event->state;
* Setup completion object.
*/
void addrcompl_initialize( void ) {
- /* printf( "addrcompl_initialize...\n" ); */
+ /* g_print( "addrcompl_initialize...\n" ); */
if( ! _compWindow_ ) {
_compWindow_ = addrcompl_create_window();
}
_queryID_ = 0;
_completionIdleID_ = 0;
- /* printf( "addrcompl_initialize...done\n" ); */
+ /* g_print( "addrcompl_initialize...done\n" ); */
}
/**
* Teardown completion object.
*/
void addrcompl_teardown( void ) {
- /* printf( "addrcompl_teardown...\n" ); */
+ /* g_print( "addrcompl_teardown...\n" ); */
addrcompl_free_window( _compWindow_ );
_compWindow_ = NULL;
- if( _displayQueue_ ) {
- g_list_free( _displayQueue_ );
- }
- _displayQueue_ = NULL;
+
+ addrcompl_clear_queue();
+
_completionIdleID_ = 0;
- /* printf( "addrcompl_teardown...done\n" ); */
+ /* g_print( "addrcompl_teardown...done\n" ); */
}
/*
static GtkListStore *addr_compl_create_store(void)
{
return gtk_list_store_new(N_ADDR_COMPL_COLUMNS,
+ GDK_TYPE_PIXBUF,
G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
+ G_TYPE_POINTER,
-1);
}
list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
g_object_unref(model);
- gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
+ gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
gtk_tree_view_set_headers_visible(list_view, FALSE);
selector = gtk_tree_view_get_selection(list_view);
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
+ renderer = gtk_cell_renderer_pixbuf_new();
+ column = gtk_tree_view_column_new_with_attributes
+ ("", renderer,
+ "pixbuf", ADDR_COMPL_ICON, 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
("", renderer, "text", ADDR_COMPL_ADDRESS, NULL);
* not using a time out would result in a crash. if this doesn't work
* safely, maybe we should set variables when receiving button presses
* in the tree view. */
- if (!window->destroying) {
- window->destroying = TRUE;
+ if (!window->destroying) {
+ window->destroying = TRUE;
g_idle_add((GSourceFunc) addr_compl_defer_select_destruct, data);
- }
-
+ }
+
return TRUE;
}
GtkEntry *entry = GTK_ENTRY(window->entry);
completion_window_apply_selection(GTK_TREE_VIEW(window->list_view),
- entry);
+ entry, TRUE);
clear_completion_cache();