Author: juha Date: 2006-08-27 19:57:14 +0000 (Sun, 27 Aug 2006) New Revision: 22909
Modified: xfcalendar/trunk/src/reminder.c xfcalendar/trunk/src/reminder.h xfcalendar/trunk/src/xfce_trayicon.c Log: added two minor enhancements into reminder: 1) wait until audio alarm has ended before starting next repeat sound 2) show active alarm list in trayicon tooltip Modified: xfcalendar/trunk/src/reminder.c =================================================================== --- xfcalendar/trunk/src/reminder.c 2006-08-27 19:31:19 UTC (rev 22908) +++ xfcalendar/trunk/src/reminder.c 2006-08-27 19:57:14 UTC (rev 22909) @@ -1,7 +1,7 @@ /* reminder.c * - * (C) 2003-2005 Mickaël Graf - * (C) 2005 Juha Kautto + * (C) 2003-2006 Mickaël Graf + * (C) 2005-2006 Juha Kautto * * 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 @@ -21,6 +21,9 @@ #ifdef HAVE_CONFIG_H # include <config.h> #endif +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif #include <sys/types.h> #include <sys/stat.h> @@ -29,6 +32,8 @@ #include <stdio.h> #include <time.h> +#include <glib.h> +#include <glib/gprintf.h> #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include <libxfce4util/libxfce4util.h> @@ -47,7 +52,6 @@ extern GList *alarm_list; extern XfceTrayIcon *trayIcon; - static gchar *play_cmd = NULL; void set_play_command(gchar *cmd) @@ -57,6 +61,48 @@ play_cmd = g_strdup(cmd); } +static void +child_setup_async(gpointer user_data) +{ +#if defined(HAVE_SETSID) && !defined(G_OS_WIN32) + setsid(); +#endif +} + +static void +child_watch_cb(GPid pid, gint status, gpointer data) +{ + gboolean *sound_active = (gboolean *)data; + + waitpid(pid, NULL, 0); + g_spawn_close_pid(pid); + *sound_active = FALSE; +} + +gboolean +orage_exec(const char *cmd, gboolean *sound_active, GError **error) +{ + char **argv; + gboolean success; + int spawn_flags = G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD; + GPid pid; + + if (!g_shell_parse_argv(cmd, NULL, &argv, error)) + return FALSE; + + if (!argv || !argv[0]) + return FALSE; + + success = g_spawn_async(NULL, argv, NULL, spawn_flags + , child_setup_async, NULL, &pid, error); + if (success) + *sound_active = TRUE; + g_child_watch_add(pid, child_watch_cb, sound_active); + g_strfreev(argv); + + return success; +} + gboolean orage_sound_alarm(gpointer data) { @@ -68,7 +114,14 @@ /* note: -1 loops forever */ if (audio_alarm->cnt != 0) { + /* status = xfce_exec(audio_alarm->play_cmd, FALSE, FALSE, &error); + */ + if (audio_alarm->sound_active) { + return(TRUE); + } + status = orage_exec(audio_alarm->play_cmd, &audio_alarm->sound_active + , &error); if (!status) { g_warning("reminder: play failed (%si)", audio_alarm->play_cmd); audio_alarm->cnt = 0; /* one warning is enough */ @@ -98,6 +151,7 @@ audio_alarm = g_new(xfce_audio_alarm_type, 1); audio_alarm->play_cmd = g_strconcat(play_cmd, " \"", alarm->sound->str, "\"", NULL); audio_alarm->delay = alarm->repeat_delay; + audio_alarm->sound_active = FALSE; if ((audio_alarm->cnt = alarm->repeat_cnt) == 0) { audio_alarm->cnt++; audio_alarm->wReminder = NULL; @@ -249,6 +303,44 @@ gtk_widget_show(wReminder); } +void +build_tray_tooltip() +{ + gint alarm_cnt=0; + gint tooltip_alarm_limit=5; + gint dd, hh, min; + GString *tooltip=NULL; + GList *alarm_l; + alarm_struct *cur_alarm; + /* GtkTooltipsData *cur_tooltip; */ + + tooltip = g_string_new(_("Next active alarms:")); + alarm_l = alarm_list; + for (alarm_l = g_list_first(alarm_l); + alarm_l != NULL && (alarm_cnt < tooltip_alarm_limit); + alarm_l = g_list_next(alarm_l)) { + cur_alarm = (alarm_struct *)alarm_l->data; + if (xfical_duration(cur_alarm->alarm_time->str, &dd, &hh, &min)) { + g_string_append_printf(tooltip, + _("\n%02d d %02d h %02d min to: %s"), + dd, hh, min, cur_alarm->title->str); + alarm_cnt++; + } + } + if (alarm_cnt == 0) + g_string_append_printf(tooltip, _("\nNo active alarms found")); + + /* would this check save CPU or not?? + cur_tooltip = gtk_tooltips_data_get(trayIcon->tray); + if (cur_tooltip == NULL) + || (strcmp(tooltip->str, cur_tooltip->tip_text) != 0) { + xfce_tray_icon_set_tooltip(trayIcon, tooltip->str, NULL); + } + */ + xfce_tray_icon_set_tooltip(trayIcon, tooltip->str, NULL); + g_string_free(tooltip, TRUE); +} + gboolean orage_alarm_clock(gpointer user_data) { @@ -276,13 +368,15 @@ && selected_day == previous_day) { /* previous day was indeed selected, keep it current automatically */ - xfcalendar_select_date(GTK_CALENDAR (xfcal->mCalendar), current_year, current_month, current_day); + xfcalendar_select_date(GTK_CALENDAR(xfcal->mCalendar) + , current_year, current_month, current_day); } previous_year = current_year; previous_month = current_month; previous_day = current_day; xfical_alarm_build_list(TRUE); /* new alarm list when date changed */ - if (NETK_IS_TRAY_ICON(trayIcon->tray)) { + if (NETK_IS_TRAY_ICON(trayIcon->tray)) { + /* refresh date in tray icon */ xfce_tray_icon_disconnect(trayIcon); destroy_TrayIcon(trayIcon); trayIcon = create_TrayIcon(xfcal); @@ -291,7 +385,7 @@ } /* Check if there are any alarms to show */ - alarm_l=alarm_list; + alarm_l = alarm_list; for (alarm_l = g_list_first(alarm_l); alarm_l != NULL && more_alarms; alarm_l = g_list_next(alarm_l)) { @@ -306,6 +400,9 @@ if (alarm_raised) /* at least one alarm processed, need new list */ xfical_alarm_build_list(FALSE); + if (NETK_IS_TRAY_ICON(trayIcon->tray)) { + build_tray_tooltip(); + } return TRUE; } Modified: xfcalendar/trunk/src/reminder.h =================================================================== --- xfcalendar/trunk/src/reminder.h 2006-08-27 19:31:19 UTC (rev 22908) +++ xfcalendar/trunk/src/reminder.h 2006-08-27 19:57:14 UTC (rev 22909) @@ -38,6 +38,7 @@ gint cnt; gint delay; GtkWidget *wReminder; /* needed for callbacks when stopping timer */ + gboolean sound_active; } xfce_audio_alarm_type; Modified: xfcalendar/trunk/src/xfce_trayicon.c =================================================================== --- xfcalendar/trunk/src/xfce_trayicon.c 2006-08-27 19:31:19 UTC (rev 22908) +++ xfcalendar/trunk/src/xfce_trayicon.c 2006-08-27 19:57:14 UTC (rev 22909) @@ -212,6 +212,21 @@ } /* + * Show new balloon message + * Does not seem to work! commented out + */ +/* +void +xfce_tray_icon_message(XfceTrayIcon *icon, glong timeout, const gchar *text) +{ + g_return_if_fail(XFCE_IS_TRAY_ICON(icon)); + g_return_if_fail(NETK_IS_TRAY_ICON(icon->tray)); + + netk_tray_icon_message_new(NETK_TRAY_ICON(icon->tray), timeout, text); +} +*/ + +/* * The tray just disappeared */ static void @@ -360,6 +375,9 @@ { g_return_if_fail(XFCE_IS_TRAY_ICON(icon)); + /* remove these to save cpu for mem allocations + * since orage uses tooltips a lot! */ + /* if (icon->tip_text != NULL) { g_free(icon->tip_text); icon->tip_text = NULL; @@ -369,14 +387,17 @@ g_free(icon->tip_private); icon->tip_private = NULL; } + */ if (NETK_IS_TRAY_ICON(icon->tray)) gtk_tooltips_set_tip(icon->tooltips, icon->tray, text, private); + /* if (text != NULL) icon->tip_text = g_strdup(text); if (private != NULL) icon->tip_private = g_strdup(private); + */ } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits