[Goodies-commits] r5265 - xfce4-mailwatch-plugin/trunk/libmailwatch-core
Brian Tarricone
kelnos at xfce.org
Sun Aug 17 10:15:46 CEST 2008
Author: kelnos
Date: 2008-08-17 08:15:45 +0000 (Sun, 17 Aug 2008)
New Revision: 5265
Modified:
xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-maildir.c
xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-mh.c
Log:
use new timeout model for mh-maildir plugin
Modified: xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-maildir.c
===================================================================
--- xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-maildir.c 2008-08-17 08:15:34 UTC (rev 5264)
+++ xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-maildir.c 2008-08-17 08:15:45 UTC (rev 5265)
@@ -174,7 +174,7 @@
if( g_atomic_pointer_get( &maildir->thread ) ) {
xfce_mailwatch_log_message( maildir->mailwatch,
- XFCE_MAILWATCH_MAILBOX(maildir),
+ XFCE_MAILWATCH_MAILBOX( maildir ),
XFCE_MAILWATCH_LOG_WARNING,
_( "Previous thread hasn't exited yet, not checking mail this time." ) );
return TRUE;
Modified: xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-mh.c
===================================================================
--- xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-mh.c 2008-08-17 08:15:34 UTC (rev 5264)
+++ xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-mh.c 2008-08-17 08:15:45 UTC (rev 5265)
@@ -1,6 +1,7 @@
/*
* xfce4-mailwatch-plugin - a mail notification applet for the xfce4 panel
* Copyright (c) 2005 Pasi Orovuo <pasi.ov at gmail.com>
+ * Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
*
* 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
@@ -61,14 +62,6 @@
#define MH_INBOX ( "inbox" )
#define MH_UNSEEN_SEQ ( "unseen" )
-typedef enum {
- MH_MSG_START = 1,
- MH_MSG_PAUSE,
- MH_MSG_FORCE_UPDATE,
- MH_MSG_TIMEOUT_CHANGED,
- MH_MSG_QUIT
-} XfceMailwatchMHMessage;
-
typedef struct {
XfceMailwatchMailbox *xfce_mailwatch_mailbox;
XfceMailwatch *mailwatch;
@@ -78,13 +71,13 @@
gchar *mh_sequences_fn;
time_t mh_sequences_ctime;
gchar *unseen_sequence; /* This should be a list as there can be multiple? */
- gboolean active;
guint timeout;
guint last_update;
- GThread *thread;
- GAsyncQueue *aqueue;
+ gint running;
+ gpointer thread; /* (GThread *) */
+ guint check_id;
} XfceMailwatchMHMailbox;
typedef struct {
@@ -470,51 +463,35 @@
mh_main_thread( gpointer data )
{
XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( data );
- GTimeVal tv;
- g_async_queue_ref( mh->aqueue );
+ while( !g_atomic_pointer_get( &mh->thread ) && g_atomic_int_get( &mh->running ) )
+ g_thread_yield();
- for ( ;; ) {
- XfceMailwatchMHMessage msg;
-
- g_get_current_time( &tv );
- g_time_val_add( &tv, G_USEC_PER_SEC * 5 );
+ if( g_atomic_int_get( &mh->running ) )
+ mh_check_mail( mh );
- msg = GPOINTER_TO_INT( g_async_queue_timed_pop( mh->aqueue, &tv ) );
+ g_atomic_pointer_set( &mh->thread, NULL );
+ return ( NULL );
+}
- if ( msg ) {
- switch ( msg ) {
- case MH_MSG_START:
- mh->active = TRUE;
- break;
+static gboolean
+mh_check_mail_timeout(gpointer data)
+{
+ XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( data );
+ GThread *th;
- case MH_MSG_PAUSE:
- mh->active = FALSE;
- break;
+ if( g_atomic_pointer_get( &mh->thread ) ) {
+ xfce_mailwatch_log_message( mh->mailwatch,
+ XFCE_MAILWATCH_MAILBOX( mh ),
+ XFCE_MAILWATCH_LOG_WARNING,
+ _( "Previous thread hasn't exited yet, not checking mail this time." ) );
+ return TRUE;
+ }
- case MH_MSG_TIMEOUT_CHANGED:
- mh->timeout = GPOINTER_TO_INT( g_async_queue_pop( mh->aqueue ) );
- break;
+ th = g_thread_create( mh_main_thread, mh, FALSE, NULL );
+ g_atomic_pointer_set( &mh->thread, th );
- case MH_MSG_FORCE_UPDATE:
- mh->last_update = 0;
- break;
-
- case MH_MSG_QUIT:
- g_async_queue_unref( mh->aqueue );
- g_thread_exit( NULL );
- break;
- }
- }
-
- if ( mh->active &&
- tv.tv_sec - mh->last_update > mh->timeout ) {
- mh_check_mail( mh );
- mh->last_update = tv.tv_sec;
- }
- }
-
- return ( NULL );
+ return TRUE;
}
static XfceMailwatchMailbox *
@@ -527,39 +504,12 @@
mh = g_new0( XfceMailwatchMHMailbox, 1 );
mh->mailwatch = mailwatch;
- mh->active = FALSE;
mh->timeout = XFCE_MAILWATCH_DEFAULT_TIMEOUT;
- mh->aqueue = g_async_queue_new();
- mh->thread = g_thread_create( mh_main_thread, mh, TRUE, NULL );
return ( XFCE_MAILWATCH_MAILBOX( mh ) );
}
static void
-mh_free( XfceMailwatchMailbox *mailbox )
-{
- XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( mailbox );
-
- DBG( "-->>" );
-
- g_async_queue_push( mh->aqueue, GINT_TO_POINTER( MH_MSG_QUIT ) );
- g_thread_join( mh->thread );
- g_async_queue_unref( mh->aqueue );
-
- if ( mh->mh_profile_fn ) {
- g_free( mh->mh_profile_fn );
- }
- if ( mh->mh_sequences_fn ) {
- g_free( mh->mh_sequences_fn );
- }
- if ( mh->unseen_sequence ) {
- g_free( mh->unseen_sequence );
- }
-
- g_free( mh );
-}
-
-static void
mh_restore_param_list( XfceMailwatchMailbox *mailbox, GList *params )
{
XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( mailbox );
@@ -596,10 +546,22 @@
static void
mh_timeout_changed_cb( GtkWidget *spinner, XfceMailwatchMHMailbox *mh )
{
+ gint value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spinner ) ) * 60;
+
DBG( "-->>" );
- g_async_queue_push( mh->aqueue, GINT_TO_POINTER( MH_MSG_TIMEOUT_CHANGED ) );
- g_async_queue_push( mh->aqueue,
- GINT_TO_POINTER( gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spinner ) ) * 60 ) );
+
+ if( value == mh->timeout )
+ return;
+
+ mh->timeout = value;
+
+ if( g_atomic_int_get( &mh->running ) ) {
+ if( mh->check_id )
+ g_source_remove( mh->check_id );
+ mh->check_id = g_timeout_add( mh->timeout * 1000,
+ mh_check_mail_timeout,
+ mh );
+ }
}
static GtkContainer *
@@ -650,20 +612,72 @@
static void
mh_force_update_cb( XfceMailwatchMailbox *mailbox )
{
+ XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( mailbox );
+
DBG( " " );
-
- g_async_queue_push( XFCE_MAILWATCH_MH_MAILBOX( mailbox )->aqueue, GINT_TO_POINTER( MH_MSG_FORCE_UPDATE ) );
+
+ if( !g_atomic_pointer_get( &mh->thread ) ) {
+ gboolean restart = FALSE;
+
+ if( mh->check_id ) {
+ g_source_remove( mh->check_id );
+ restart = TRUE;
+ }
+
+ mh_check_mail_timeout( mh );
+
+ if( restart ) {
+ mh->check_id = g_timeout_add( mh->timeout * 1000,
+ mh_check_mail_timeout,
+ mh );
+ }
+ }
}
static void
mh_set_activated_cb( XfceMailwatchMailbox *mailbox, gboolean activate )
{
+ XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( mailbox );
+
DBG( " " );
-
- g_async_queue_push( XFCE_MAILWATCH_MH_MAILBOX( mailbox )->aqueue,
- GINT_TO_POINTER( activate ? MH_MSG_START : MH_MSG_PAUSE ) );
+
+ if( activate == g_atomic_int_get( &mh->running ) )
+ return;
+
+ if( activate ) {
+ g_atomic_int_set( &mh->running, TRUE );
+ mh->check_id = g_timeout_add( mh->timeout * 1000, mh_check_mail_timeout, mh );
+ } else {
+ g_atomic_int_set( &mh->running, FALSE );
+ g_source_remove( mh->check_id );
+ mh->check_id = 0;
+ }
}
+static void
+mh_free( XfceMailwatchMailbox *mailbox )
+{
+ XfceMailwatchMHMailbox *mh = XFCE_MAILWATCH_MH_MAILBOX( mailbox );
+
+ DBG( "-->>" );
+
+ mh_set_activated_cb( mailbox, FALSE );
+ while( g_atomic_pointer_get( &mh->thread ) )
+ g_thread_yield();
+
+ if ( mh->mh_profile_fn ) {
+ g_free( mh->mh_profile_fn );
+ }
+ if ( mh->mh_sequences_fn ) {
+ g_free( mh->mh_sequences_fn );
+ }
+ if ( mh->unseen_sequence ) {
+ g_free( mh->unseen_sequence );
+ }
+
+ g_free( mh );
+}
+
XfceMailwatchMailboxType builtin_mailbox_type_mh = {
"mh-maildir",
N_( "Local MH mail folder" ),
More information about the Goodies-commits
mailing list