[Xfce4-commits] <orage:master> 4.8.2.1: Fixed Bug 7939 - Dynamic icon of Orage not refreshed

Juha Kautto noreply at xfce.org
Fri Sep 23 08:22:02 CEST 2011


Updating branch refs/heads/master
         to 4ca0c47c5da87e6ed1edf4d5dc9269d3b60e0aaf (commit)
       from 0ec2c7b621124730e97ac0d74ee0271d2bd6cbcd (commit)

commit 4ca0c47c5da87e6ed1edf4d5dc9269d3b60e0aaf
Author: Juha Kautto <juha at xfce.org>
Date:   Fri Sep 23 09:17:00 2011 +0300

    4.8.2.1: Fixed Bug 7939 - Dynamic icon of Orage not refreshed
    
    Added timer to monitor time, so that we can recover fom suspend/hibernate
    if system is not handling it properly automatically.
    
    Also fixed timezone read routine to also read symbolic links since some
    systems now replaced all files with symbolic links to posix directory.

 configure.in.in        |    2 +-
 src/ical-expimp.c      |    2 +-
 src/main.c             |   34 ++++++++++++++++-
 src/parameters.c       |   83 ++++++++++++++++++++++++++++--------------
 src/parameters.h       |    6 +++
 src/reminder.c         |   16 +++++++-
 src/tz_zoneinfo_read.c |   95 +++++++++++++++++++++++++++++++-----------------
 7 files changed, 172 insertions(+), 66 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index 118dec4..e755c44 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <juha at xfce.org>
 dnl
 
 dnl Version information
-m4_define([orage_version], [4.8.2.0-git])
+m4_define([orage_version], [4.8.2.1-git])
 
 m4_define([gtk_minimum_version], [2.10.0])
 m4_define([xfce_minimum_version], [4.6.0])
diff --git a/src/ical-expimp.c b/src/ical-expimp.c
index f7b1a00..2db9fe3 100644
--- a/src/ical-expimp.c
+++ b/src/ical-expimp.c
@@ -145,7 +145,7 @@ static gboolean pre_format(char *file_name_in, char *file_name_out)
         g_error_free(error);
         return(FALSE);
     }
-    /***** Check utf8 coformtability *****/
+    /***** Check utf8 conformability *****/
     if (!g_utf8_validate(text, -1, NULL)) {
         orage_message(250, P_N "is not in utf8 format. Conversion needed.\n (Use iconv and convert it into UTF-8 and import it again.)\n");
         return(FALSE);
diff --git a/src/main.c b/src/main.c
index 1bed05a..8e21763 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,6 +64,36 @@ static SessionClient	*session_client = NULL;
 */
 static GdkAtom atom_alive;
 
+/* This function monitors that we do not loose time.  It checks if longer time
+   than expected wakeup time has passed and fixes timings if that is the case.
+   This is needed since sometimes hibernate and suspend does not do a good job
+   in firing Orage timers and timing gets wrong. 
+NOTE: called from parameters.c set_wakeup_timer
+*/
+gboolean check_wakeup(gpointer user_data)
+{
+    static time_t tt_prev=0;
+    time_t tt_new=0;
+
+    tt_new = time(NULL);
+    if (tt_new - tt_prev > ORAGE_WAKEUP_TIMER_PERIOD * 2) {
+        /* we very rarely come here. user_data is normally NULL, but 
+           first call it has some value, which means that this is init call */
+        if (!user_data) { /* normal timer call */
+            alarm_read();
+            /* It is quite possible that day did not change, 
+               but we need to reset timers */
+            orage_day_change(&tt_prev); 
+        }
+        /*
+        else {
+    g_print("wakeup timer init %d\n", tt_prev);
+        }
+        */
+    }
+    tt_prev = tt_new;
+    return(TRUE);
+}
 
 static void send_event(char *event)
 {
@@ -533,14 +563,14 @@ int main(int argc, char *argv[])
         gtk_widget_hide(((CalWin *)g_par.xfcal)->mWindow);
     }
     alarm_read();
-    orage_day_change(FALSE); /* first day change after we start */
+    orage_day_change(NULL); /* first day change after we start */
     mCalendar_month_changed_cb(
             (GtkCalendar *)((CalWin *)g_par.xfcal)->mCalendar, NULL);
 
     /* start monitoring foreign file updates if we have foreign files */
     if (g_par.foreign_count)
         g_timeout_add_seconds(30, (GtkFunction)orage_foreign_files_check, NULL);
-                                                        
+
     /* let's check if I got filename as a parameter */
     initialized = TRUE;
     process_args(argc, argv, running, initialized);
diff --git a/src/parameters.c b/src/parameters.c
index b3d4ffa..0730f26 100644
--- a/src/parameters.c
+++ b/src/parameters.c
@@ -49,7 +49,9 @@
 #include "parameters.h"
 #include "mainbox.h"
 
-extern int g_log_level;
+extern int g_log_level; /* in function.c */
+
+gboolean check_wakeup(gpointer user_data); /* in main.c*/
 
 static gboolean is_running = FALSE;
 
@@ -116,7 +118,7 @@ typedef struct _Itf
     GtkWidget *select_day_today_radiobutton;
     GtkWidget *select_day_old_radiobutton;
     /* icon size */
-    GtkWidget *icon_size_frame;
+    GtkWidget *use_dynamic_icon_frame;
     GtkWidget *use_dynamic_icon_checkbutton;
     /* show event/days window from main calendar */
     GtkWidget *click_to_show_frame;
@@ -130,6 +132,9 @@ typedef struct _Itf
     GtkWidget *close_button;
     GtkWidget *help_button;
     GtkWidget *dialog_action_area1;
+    /* icon size */
+    GtkWidget *use_wakeup_timer_frame;
+    GtkWidget *use_wakeup_timer_checkbutton;
 } Itf;
 
 /* Return the first day of the week, where 0=monday, 6=sunday.
@@ -481,6 +486,29 @@ static void el_extra_days_spin_changed(GtkSpinButton *sb, gpointer user_data)
     g_par.el_days = gtk_spin_button_get_value(sb);
 }
 
+/* start monitoring lost seconds due to hibernate or suspend */
+static void set_wakeup_timer()
+{
+    if (g_par.wakeup_timer) /* need to stop it if running */
+        g_source_remove(g_par.wakeup_timer);
+    if (g_par.use_wakeup_timer) {
+        check_wakeup(&g_par); /* init */
+        g_par.wakeup_timer = 
+                g_timeout_add_seconds(ORAGE_WAKEUP_TIMER_PERIOD
+                        , (GtkFunction)check_wakeup, NULL);
+    }
+}
+
+static void use_wakeup_timer_changed(GtkWidget *dialog, gpointer user_data)
+{
+    Itf *itf = (Itf *)user_data;
+    GdkPixbuf *orage_logo;
+
+    g_par.use_wakeup_timer = gtk_toggle_button_get_active(
+            GTK_TOGGLE_BUTTON(itf->use_wakeup_timer_checkbutton));
+    set_wakeup_timer();
+}
+
 static void create_parameter_dialog_main_setup_tab(Itf *dialog)
 {
     GtkWidget *hbox, *vbox, *label;
@@ -772,20 +800,6 @@ static void create_parameter_dialog_extra_setup_tab(Itf *dialog)
     gtk_box_pack_start(GTK_BOX(dialog->extra_vbox)
             , dialog->select_day_frame, FALSE, FALSE, 5);
 
-    /*
-    dialog->always_today_checkbutton = 
-            gtk_check_button_new_with_mnemonic(_("Select always today"));
-    gtk_box_pack_start(GTK_BOX(hbox)
-            , dialog->always_today_checkbutton, FALSE, FALSE, 5);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
-            dialog->always_today_checkbutton), g_par.select_always_today);
-    gtk_tooltips_set_tip(dialog->Tooltips, dialog->always_today_checkbutton
-            , _("When showing main calendar, set pointer to either previously selected day or always to current day.")
-            , NULL);
-    g_signal_connect(G_OBJECT(dialog->always_today_checkbutton), "toggled"
-            , G_CALLBACK(always_today_changed), dialog);
-            */
-
     dialog->select_day_today_radiobutton =
             gtk_radio_button_new_with_mnemonic(NULL, _("Select Today's Date"));
     gtk_box_pack_start(GTK_BOX(vbox)
@@ -816,10 +830,10 @@ static void create_parameter_dialog_extra_setup_tab(Itf *dialog)
 
     /***** use dynamic tray icon *****/
     hbox = gtk_vbox_new(FALSE, 0);
-    dialog->icon_size_frame = orage_create_framebox_with_content(
+    dialog->use_dynamic_icon_frame = orage_create_framebox_with_content(
             _("Use dynamic tray icon"), hbox);
     gtk_box_pack_start(GTK_BOX(dialog->extra_vbox)
-            , dialog->icon_size_frame, FALSE, FALSE, 5);
+            , dialog->use_dynamic_icon_frame, FALSE, FALSE, 5);
 
     dialog->use_dynamic_icon_checkbutton = 
             gtk_check_button_new_with_mnemonic(_("Use dynamic icon"));
@@ -882,15 +896,30 @@ static void create_parameter_dialog_extra_setup_tab(Itf *dialog)
             , dialog->el_extra_days_spin, FALSE, FALSE, 5);
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->el_extra_days_spin)
             , g_par.el_days);
-    /*
-    label = gtk_label_new(_("extra days"));
-    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
-    */
     gtk_tooltips_set_tip(dialog->Tooltips, dialog->el_extra_days_spin
             , _("This is just the default value, you can change it in the actual eventlist window.")
             , NULL);
     g_signal_connect(G_OBJECT(dialog->el_extra_days_spin), "value-changed"
             , G_CALLBACK(el_extra_days_spin_changed), dialog);
+
+    /***** use wakeup timer *****/
+    hbox = gtk_vbox_new(FALSE, 0);
+    dialog->use_wakeup_timer_frame = orage_create_framebox_with_content(
+            _("Use wakeup timer"), hbox);
+    gtk_box_pack_start(GTK_BOX(dialog->extra_vbox)
+            , dialog->use_wakeup_timer_frame, FALSE, FALSE, 5);
+
+    dialog->use_wakeup_timer_checkbutton = 
+            gtk_check_button_new_with_mnemonic(_("Use wakeup timer"));
+    gtk_box_pack_start(GTK_BOX(hbox)
+            , dialog->use_wakeup_timer_checkbutton, FALSE, FALSE, 5);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
+            dialog->use_wakeup_timer_checkbutton), g_par.use_dynamic_icon);
+    gtk_tooltips_set_tip(dialog->Tooltips, dialog->use_wakeup_timer_checkbutton
+            , _("Use this timer if Orage has problems waking up properly after suspend or hibernate. (For example tray icon not refreshed or alarms not firing.)")
+            , NULL);
+    g_signal_connect(G_OBJECT(dialog->use_wakeup_timer_checkbutton), "toggled"
+            , G_CALLBACK(use_wakeup_timer_changed), dialog);
 }
 
 static Itf *create_parameter_dialog(void)
@@ -912,9 +941,6 @@ static Itf *create_parameter_dialog(void)
     orage_logo = orage_create_icon(FALSE, 48);
     gtk_window_set_icon(GTK_WINDOW(dialog->orage_dialog), orage_logo);
     g_object_unref(orage_logo);
-    /*
-    gtk_window_set_icon_name(GTK_WINDOW(dialog->orage_dialog), "xfcalendar");
-    */
 
     gtk_dialog_set_has_separator(GTK_DIALOG(dialog->orage_dialog), FALSE);
 
@@ -1095,8 +1121,8 @@ void read_parameters(void)
     g_par.set_stick = orage_rc_get_bool(orc, "Set sticked", TRUE);
     g_par.set_ontop = orage_rc_get_bool(orc, "Set ontop", FALSE);
     g_par.use_dynamic_icon = orage_rc_get_bool(orc, "Use dynamic icon", TRUE);
-    g_par.use_own_dynamic_icon = orage_rc_get_bool(orc, "Use own dynamic icon"
-            , FALSE);
+    g_par.use_own_dynamic_icon = 
+            orage_rc_get_bool(orc, "Use own dynamic icon", FALSE);
     g_par.own_icon_file = orage_rc_get_str(orc, "Own icon file"
             , PACKAGE_DATA_DIR "/icons/hicolor/160x160/apps/orage.xpm");
     g_par.own_icon_row1_data = orage_rc_get_str(orc
@@ -1136,6 +1162,7 @@ void read_parameters(void)
     }
     g_log_level = orage_rc_get_int(orc, "Logging level", 0);
     g_par.priority_list_limit = orage_rc_get_int(orc, "Priority list limit", 8);
+    g_par.use_wakeup_timer = orage_rc_get_bool(orc, "Use wakeup timer", TRUE);
 
     orage_rc_file_close(orc);
 }
@@ -1229,6 +1256,7 @@ void write_parameters(void)
     }
     orage_rc_put_int(orc, "Logging level", g_log_level);
     orage_rc_put_int(orc, "Priority list limit", g_par.priority_list_limit);
+    orage_rc_put_bool(orc, "Use wakeup timer", g_par.use_wakeup_timer);
 
     orage_rc_file_close(orc);
 }
@@ -1258,5 +1286,6 @@ void set_parameters(void)
     */
     set_stick();
     set_ontop();
+    set_wakeup_timer();
     xfical_set_local_timezone(FALSE);
 }
diff --git a/src/parameters.h b/src/parameters.h
index f899c94..4808445 100644
--- a/src/parameters.h
+++ b/src/parameters.h
@@ -24,6 +24,7 @@
 #define __ORAGE_PARAMETERS_H__
 
 #define BORDER 5
+#define ORAGE_WAKEUP_TIMER_PERIOD 10
 typedef struct _foreign_file
 {
     char *file;
@@ -76,6 +77,7 @@ typedef struct _parameters
     guint alarm_timer; /* monitors next alarm */
     guint day_timer;   /* fires when day changes = every 24 hours */
     guint tooltip_timer; /* keeps tooltips upto date */
+    guint wakeup_timer;  /* controls wakeup after suspend/hibernate */
 
     /* main window */
     void *xfcal;     /* this is main calendar CalWin * */
@@ -114,6 +116,10 @@ typedef struct _parameters
 
     /* Controls which appointment priorities are shown in daylist */
     gint priority_list_limit;
+
+    /* some systems are not able to wake up properly from suspend/hibernate
+       and we need to monitor the status ourselves */
+    gboolean use_wakeup_timer;
 } global_parameters; /* global parameters */
 
 #ifdef ORAGE_MAIN
diff --git a/src/reminder.c b/src/reminder.c
index a5d641c..db5cfcb 100644
--- a/src/reminder.c
+++ b/src/reminder.c
@@ -343,6 +343,9 @@ void alarm_read(void)
     for (i = 0; alarm_groups[i] != NULL; i++) {
         orage_rc_set_group(orc, alarm_groups[i]);
         if ((new_alarm = alarm_read_next_alarm(orc, time_now)) != NULL) {
+            /*
+            g_print(P_N "time_now=%s alarm=%s\n", time_now, new_alarm->alarm_time);
+            */
             create_reminders(new_alarm);
             alarm_free(new_alarm);
         }
@@ -945,10 +948,16 @@ gboolean orage_day_change(gpointer user_data)
 #endif
     t = orage_localtime();
   /* See if the day just changed. 
-     Note that when we are called first time we always have day change. */
-    if (previous_day != t->tm_mday
+     Note that when we are called first time we always have day change. 
+     If user_data is not NULL, we also force day change. */
+    if (user_data
+    || previous_day != t->tm_mday
     || previous_month != t->tm_mon
     || previous_year != t->tm_year + 1900) {
+        if (user_data) {
+            if (g_par.day_timer) /* need to stop it if running */
+                g_source_remove(g_par.day_timer);
+        }
         current_year  = t->tm_year + 1900;
         current_month = t->tm_mon;
         current_day   = t->tm_mday;
@@ -1004,6 +1013,9 @@ static gboolean orage_alarm_clock(gpointer user_data)
         /* remember that it is sorted list */
         cur_alarm = (alarm_struct *)alarm_l->data;
         if (strcmp(time_now, cur_alarm->alarm_time) > 0) {
+            /*
+            g_print(P_N "time_now=%s alarm=%s\n", time_now, cur_alarm->alarm_time);
+            */
             create_reminders(cur_alarm);
             alarm_raised = TRUE;
         }
diff --git a/src/tz_zoneinfo_read.c b/src/tz_zoneinfo_read.c
index e7ea00f..cebd1da 100644
--- a/src/tz_zoneinfo_read.c
+++ b/src/tz_zoneinfo_read.c
@@ -87,7 +87,7 @@ orage_timezone_array tz_array={0, NULL, NULL, NULL, NULL, NULL, NULL};
 static char *zone_tab_buf = NULL, *country_buf = NULL, *zones_tab_buf = NULL;
 
 static int debug = 0; /* bigger number => more output */
-static char version[] = "1.4.4";
+static char version[] = "1.5.1";
 static int file_cnt = 0; /* number of processed files */
 
 static unsigned char *in_buf, *in_head, *in_tail;
@@ -533,6 +533,58 @@ static int write_ical_file(const char *in_file_name
     return(0);
 }
 
+static int file_call_process_file(const char *file_name
+        , const struct stat *sb, int flags)
+{
+    struct stat file_stat;
+
+    if (debug > 0) {
+        if (flags == FTW_SL)
+            printf("\t\tfile_call: processing symbolic link=(%s)\n", file_name);
+        else
+            printf("\t\tfile_call: processing file=(%s)\n", file_name);
+    }
+    in_timezone_name = strdup(&file_name[in_file_base_offset
+            + strlen("zoneinfo/")]);
+    timezone_name = strdup(in_timezone_name);
+    if (check_ical && !timezone_exists_in_ical()) {
+        if (debug > 0)
+            printf("\t\tfile_call: skipping file=(%s) as it does not exist in libical\n", file_name);
+        free(in_timezone_name);
+        free(timezone_name);
+        return(1);
+    }
+    if (flags == FTW_SL) {
+        read_file(file_name, sb);
+    /* we know it is symbolic link, so we actually need stat instead of lstat
+    which nftw gives us!
+    (lstat = information from the real file istead of the link) */ 
+        if (stat(file_name, &file_stat)) {
+            perror("\tstat");
+            free(in_timezone_name);
+            free(timezone_name);
+            return(1);
+        }
+        read_file(file_name, &file_stat);
+    }
+    else
+        read_file(file_name, sb);
+    if (process_file(file_name)) { /* we skipped this file */
+        free(in_timezone_name);
+        free(timezone_name);
+        free(in_buf);
+        return(1);
+    }
+    write_ical_file(file_name, sb);
+
+    free(in_buf);
+    free(out_file);
+    out_file = NULL;
+    free(in_timezone_name);
+    free(timezone_name);
+    return(0);
+}
+
 /* The main code. This is called once per each file found */
 static int file_call(const char *file_name, const struct stat *sb, int flags
         , struct FTW *f)
@@ -543,31 +595,9 @@ static int file_call(const char *file_name, const struct stat *sb, int flags
         printf("\nfile_call: start\n");
     file_cnt++;
     /* we are only interested about files and directories we can access */
-    if (flags == FTW_F) { /* we got file */
-        if (debug > 0)
-            printf("\t\tfile_call: processing file=(%s)\n", file_name);
-        in_timezone_name = strdup(&file_name[in_file_base_offset
-                + strlen("zoneinfo/")]);
-        timezone_name = strdup(in_timezone_name);
-        if (check_ical && !timezone_exists_in_ical()) {
-            free(in_timezone_name);
-            free(timezone_name);
-            return(FTW_CONTINUE);
-        }
-        read_file(file_name, sb);
-        if (process_file(file_name)) { /* we skipped this file */
-            free(in_timezone_name);
-            free(timezone_name);
-            free(in_buf);
-            return(FTW_CONTINUE);
-        }
-        write_ical_file(file_name, sb);
-
-        free(in_buf);
-        free(out_file);
-        out_file = NULL;
-        free(in_timezone_name);
-        free(timezone_name);
+    if (flags == FTW_F || flags == FTW_SL) { /* we got file */
+        if (file_call_process_file(file_name, sb, flags))
+            return(FTW_CONTINUE); /* skip this file */
     }
     else if (flags == FTW_D) { /* this is directory */
         if (debug > 0)
@@ -585,15 +615,10 @@ static int file_call(const char *file_name, const struct stat *sb, int flags
 #else
         /* not easy to do that in BSD, where we do not have FTW_ACTIONRETVAL
            features. It can be done by checking differently */
-    if (debug > 0)
-        printf("FIXME: this directory should be skipped\n");
+        if (debug > 0)
+            printf("FIXME: this directory should be skipped\n");
 #endif
     }
-    else if (flags == FTW_SL) {
-        if (debug > 0) {
-            printf("\t\tfile_call: skipping symbolic link=(%s)\n", file_name);
-        }
-    }
     else {
         if (debug > 0) {
             printf("\t\tfile_call: skipping inaccessible file=(%s)\n", file_name);
@@ -741,6 +766,10 @@ static int check_parameters(void)
 
 static void read_os_timezones(void)
 {
+#undef P_N
+#define P_N "read_os_timezones: "
+#define MAX_AREA_LENGTH 100
+
     char *tz_dir, *zone_tab_file_name;
     int zoneinfo_len=strlen("zoneinfo/");
     FILE *zone_tab_file;


More information about the Xfce4-commits mailing list