[PATCH] "Re-Import" button not needed for VCARD address books
- From: "W. Michael Petullo" <mike flyn org>
- To: balsa-list gnome org
- Subject: [PATCH] "Re-Import" button not needed for VCARD address books
- Date: Sun, 25 Jan 2004 16:09:33 -0600
Balsa's address book contains a "Re-Import" button that causes the source
of the address book (filesystem, LDAP, etc.) to be re-read and the display
of addresses to be updated. This is not needed for address books that
store their data using the local filesystem. Instead, FAM, dnotify or a
similar facility should be used to automatically update the display of
addresses when the the data files change.
For example, if ~/.gnome2/GnomeCard.gcrd is modified by gnomecard, then
balsa should update its address book display automatically.
This ability would greatly reduce potential user confusion resulting from
balsa and gnomecard getting out of sync.
Enclosed are two proof of concept patches (vs. 2.1.0) that implement this
behavior using Linux's dnotify feature. The patches are against
src/ab-window.h and ab-window.c. The patches are not ready for mainstream
use and are only meant to be a catalyst for discussion at this point.
See also GNOME Bugzilla bug #132506.
--
Mike
:wq
--- balsa-2.1.0-vanilla/src/ab-window.c 2003-08-30 17:51:40.000000000 -0500
+++ balsa-2.1.0/src/ab-window.c 2004-01-25 15:54:55.583305000 -0600
@@ -21,12 +21,27 @@
#include "config.h"
+#define FLYNCOMPUTING
+#ifdef FLYNCOMPUTING
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <libgen.h>
+#endif
+
#include <gnome.h>
#include <string.h>
#include "balsa-app.h"
#include "sendmsg-window.h"
#include "ab-window.h"
+#ifdef FLYNCOMPUTING
+/* how to get around global for signal handler? */
+static volatile BalsaAbWindow *_ab;
+#endif
+
enum {
LIST_COLUMN_NAME,
LIST_COLUMN_ADDRESS_STRING,
@@ -44,7 +59,11 @@
LibBalsaAddress *address,
BalsaAbWindow *ab);
static void balsa_ab_window_load(BalsaAbWindow *ab);
+#ifdef FLYNCOMPUTING /* use dnotify signals or reload button */
+static void balsa_ab_window_reload(int sig, siginfo_t *si, void *data);
+#else
static void balsa_ab_window_reload(GtkWidget *w, BalsaAbWindow *av);
+#endif
/* Callbacks ... */
static void balsa_ab_window_dist_mode_toggled(GtkWidget * w,
@@ -188,6 +207,24 @@
return tree;
}
+/*
+ Handle a dnotify event or click on the reload button.
+ */
+#ifdef FLYNCOMPUTING
+static void
+balsa_ab_window_reload(int sig, siginfo_t *si, void *data)
+{
+printf("reloading ab...\n"); /* FIXME */
+ balsa_ab_window_load(_ab);
+}
+#else
+static void
+balsa_ab_window_reload(GtkWidget *w, BalsaAbWindow *ab)
+{
+ balsa_ab_window_load(ab);
+}
+#endif
+
static void
balsa_ab_window_init(BalsaAbWindow *ab)
{
@@ -202,6 +239,9 @@
GList *ab_list;
LibBalsaAddressBook *address_book;
guint default_offset = 0;
+#ifdef FLYNCOMPUTING
+ ab->dnotify_fd = -1;
+#endif
ab->current_address_book = NULL;
gtk_window_set_title(GTK_WINDOW(ab), _("Address Book"));
@@ -348,13 +388,44 @@
gtk_container_add(GTK_CONTAINER(hbox), w);
gtk_widget_show(GTK_WIDGET(w));
- w = balsa_stock_button_with_label(GTK_STOCK_ADD,
- _("_Re-Import"));
- g_signal_connect(G_OBJECT(w), "clicked",
- G_CALLBACK(balsa_ab_window_reload),
- ab);
- gtk_container_add(GTK_CONTAINER(hbox), w);
- gtk_widget_show(w);
+#ifdef FLYNCOMPUTING
+ if(LIBBALSA_IS_ADDRESS_BOOK_VCARD(address_book)) {
+ gchar *ab_dir;
+ struct sigaction act;
+ LibBalsaAddressBookVcard *vc;
+ vc = LIBBALSA_ADDRESS_BOOK_VCARD(address_book);
+printf("ab %s path is %s\n", address_book->name, vc->path); /* FIXME */
+ ab_dir = dirname(strdup(vc->path)); /* FIXME: test result/use glib version */
+
+printf("vcard\n"); /* FIXME */
+
+ act.sa_sigaction = balsa_ab_window_reload;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_SIGINFO;
+ _ab = ab; /* FIXME */
+ sigaction(SIGRTMIN + 3, &act, NULL); /* + 1 does not work (used elsewhere? */
+
+ ab->dnotify_fd = open(ab_dir, O_RDONLY);
+printf("%d\n", ab->dnotify_fd); /* FIXME */
+ fcntl(ab->dnotify_fd, F_SETSIG, SIGRTMIN + 3);
+ fcntl(ab->dnotify_fd, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_MULTISHOT);
+ /* we will now be notified if any of the files
+ in ab_dir is modified or new files are created */
+printf("watching %s\n", ab_dir); /* FIXME */
+ free(ab_dir);
+ } else {
+printf("not a vcard\n"); /* FIXME */
+#endif
+ w = balsa_stock_button_with_label(GTK_STOCK_ADD,
+ _("_Re-Import"));
+ g_signal_connect(G_OBJECT(w), "clicked",
+ G_CALLBACK(balsa_ab_window_reload),
+ ab);
+ gtk_container_add(GTK_CONTAINER(hbox), w);
+ gtk_widget_show(w);
+#ifdef FLYNCOMPUTING
+ }
+#endif
balsa_ab_window_load(ab);
@@ -637,15 +708,6 @@
GTK_TREE_VIEW(ab->address_list));
}
-/*
- Handle a click on the reload button.
- */
-static void
-balsa_ab_window_reload(GtkWidget *w, BalsaAbWindow *ab)
-{
- balsa_ab_window_load(ab);
-}
-
/*
* Loads the addressbooks into a clist.
@@ -864,6 +926,10 @@
static void
balsa_ab_window_response_cb(BalsaAbWindow *ab, gint response)
{
+#ifdef FLYNCOMPUTING
+ if(ab->dnotify_fd >= 0)
+ close(ab->dnotify_fd);
+#endif
switch(response) {
case GTK_RESPONSE_CLOSE:
if ( !ab->composing )
--- balsa-2.1.0-vanilla/src/ab-window.h 2003-08-10 16:09:48.000000000 -0500
+++ balsa-2.1.0/src/ab-window.h 2004-01-25 15:24:42.000000000 -0600
@@ -59,6 +59,10 @@
/* Stuff to hide when not in compose mode */
GtkWidget *send_to_box;
GtkWidget *arrow_box;
+
+#ifdef FLYNCOMPUTING
+ int dnotify_fd;
+#endif
};
GtkType balsa_ab_window_get_type(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]