address completion in prefs_filtering dialog too
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 15 Jul 2001 17:03:12 +0000 (17:03 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 15 Jul 2001 17:03:12 +0000 (17:03 +0000)
ChangeLog.claws
src/addr_compl.c
src/addr_compl.h
src/prefs_filtering.c

index 391c7c6..de6ad8f 100644 (file)
@@ -1,5 +1,10 @@
 2001-07-15 [alfons]
 
+       * src/addr_compl.[ch], src/prefs_filtering.c
+               make "filtering pref dialog's destination entry" an
+               "address completable entry", if filter destination is 
+               an email address
+
        0.5.1claws2
        
        sync with Hiroyuki's 0.5.0cvs2-3
index f89ac9f..7aea906 100644 (file)
@@ -598,6 +598,10 @@ void address_completion_start(GtkWidget *mainwindow)
                           mainwindow);
 }
 
+/* Need unique data to make unregistering signal handler possible for the auto
+ * completed entry */
+#define COMPLETION_UNIQUE_DATA (GINT_TO_POINTER(0xfeefaa))
+
 void address_completion_register_entry(GtkEntry *entry)
 {
        g_return_if_fail(entry != NULL);
@@ -610,14 +614,36 @@ void address_completion_register_entry(GtkEntry *entry)
        gtk_signal_connect_full(GTK_OBJECT(entry), "key_press_event",
                                GTK_SIGNAL_FUNC(address_completion_entry_key_pressed),
                                NULL,
-                               NULL,
+                               COMPLETION_UNIQUE_DATA,
                                NULL,
                                0,
                                0); /* magic */
 }
 
+void address_completion_unregister_entry(GtkEntry *entry)
+{
+       GtkObject *entry_obj;
+
+       g_return_if_fail(entry != NULL);
+       g_return_if_fail(GTK_IS_ENTRY(entry));
+
+       entry_obj = gtk_object_get_data(GTK_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
+       g_return_if_fail(entry_obj);
+       g_return_if_fail(entry_obj == GTK_OBJECT(entry));
+
+       /* has the hooked property? */
+       gtk_object_set_data(GTK_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
+
+       /* remove the hook */
+       gtk_signal_disconnect_by_func(GTK_OBJECT(entry), 
+               GTK_SIGNAL_FUNC(address_completion_entry_key_pressed),
+               COMPLETION_UNIQUE_DATA);
+}
+
 /* should be called when main window with address completion entries
- * terminates */
+ * terminates.
+ * NOTE: this function assumes that it is called upon destruction of
+ * the window */
 void address_completion_end(GtkWidget *mainwindow)
 {
        /* if address_completion_end() is really called on closing the window,
index 95b2b73..b6ba7c6 100644 (file)
@@ -48,6 +48,7 @@ gint end_address_completion           (void);
 
 void address_completion_start  (GtkWidget *mainwindow);
 void address_completion_register_entry (GtkEntry *entry);
+void address_completion_unregister_entry (GtkEntry *entry);
 void address_completion_end    (GtkWidget *mainwindow);
 
 #endif /* __ADDR_COMPL_H__ */
index 87e4887..b13eeeb 100644 (file)
@@ -46,6 +46,7 @@
 #include "alertpanel.h"
 #include "folder.h"
 #include "filtering.h"
+#include "addr_compl.h"
 
 static struct Filtering {
        GtkWidget *window;
@@ -63,6 +64,9 @@ static struct Filtering {
        GtkWidget *exec_btn;
 
        GtkWidget *cond_clist;
+
+       /* need this to make address completion entry work */
+       gint current_action;
 } filtering;
 
 #define VSPACING               12
@@ -101,8 +105,11 @@ static void prefs_filtering_condition_define       (void);
 static gint prefs_filtering_clist_set_row(gint row, FilteringProp * prop);
 static void prefs_filtering_select_dest(void);
 static void prefs_filtering_action_select(GtkList *list,
-                                         GtkWidget *widget,
+                                         GtkWidget *widget, 
                                          gpointer user_data);
+static void prefs_filtering_action_selection_changed(GtkList *list,
+                                                    gpointer user_data);
+                                         
 static void prefs_filtering_reset_dialog(void);
 
 enum {
@@ -124,6 +131,9 @@ static gint get_sel_from_list(GtkList * list)
        void * sel;
        GList * child;
 
+       if (list->selection == NULL)
+               return -1;
+
        sel = list->selection->data;
        for(child = list->children ; child != NULL ;
            child = g_list_next(child)) {
@@ -217,6 +227,16 @@ void prefs_filtering_open(void)
        prefs_filtering_set_dialog();
 
        gtk_widget_show(filtering.window);
+
+       start_address_completion();
+}
+
+/* prefs_filtering_close() - just to have one common exit point */
+static void prefs_filtering_close(void)
+{
+       end_address_completion();
+       
+       gtk_widget_hide(filtering.window);
 }
 
 static void prefs_filtering_create(void)
@@ -362,6 +382,10 @@ static void prefs_filtering_create(void)
                            GTK_SIGNAL_FUNC (prefs_filtering_action_select),
                            NULL);
 
+       gtk_signal_connect(GTK_OBJECT(action_list), "selection-changed",
+                          GTK_SIGNAL_FUNC(prefs_filtering_action_selection_changed),
+                          NULL);
+
        /* accounts */
 
        hbox1 = gtk_hbox_new (FALSE, VSPACING);
@@ -912,6 +936,27 @@ static void prefs_filtering_select_dest(void)
        g_free(path);
 }
 
+static void prefs_filtering_action_selection_changed(GtkList *list,
+                                                    gpointer user_data)
+{
+       gint value;
+
+       value = get_sel_from_list(GTK_LIST(filtering.action_list));
+
+       if (filtering.current_action != value) {
+               if (filtering.current_action == ACTION_FORWARD 
+               ||  filtering.current_action == ACTION_FORWARD_AS_ATTACHMENT) {
+                       debug_print("unregistering address completion entry\n");
+                       address_completion_unregister_entry(GTK_ENTRY(filtering.dest_entry));
+               }
+               if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT) {
+                       debug_print("registering address completion entry\n");
+                       address_completion_register_entry(GTK_ENTRY(filtering.dest_entry));
+               }
+               filtering.current_action = value;
+       }
+}
+
 static void prefs_filtering_action_select(GtkList *list,
                                          GtkWidget *widget,
                                          gpointer user_data)
@@ -1022,11 +1067,11 @@ static void prefs_filtering_ok(void)
 {
        prefs_filtering_set_list();
        prefs_filtering_write_config();
-       gtk_widget_hide(filtering.window);
+       prefs_filtering_close();
 }
 
 static void prefs_filtering_cancel(void)
 {
        prefs_filtering_read_config();
-       gtk_widget_hide(filtering.window);
+       prefs_filtering_close();
 }