* fetching the 12/24 Hours switch from config over and over is expansive. (gprof...
authorWilfried Göesgens <willi@citadel.org>
Thu, 6 Sep 2007 21:31:49 +0000 (21:31 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 6 Sep 2007 21:31:49 +0000 (21:31 +0000)
webcit/calendar_tools.c
webcit/calendar_view.c
webcit/configure.ac
webcit/fmt_date.c
webcit/preferences.c
webcit/webcit.h

index 304530f784d080ab8b913c26acfa392d86f0a84a..edb17de924caf8ce698331de81e47f5e36331894 100644 (file)
@@ -52,9 +52,9 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        time_t monthselect_time;
        struct tm monthselect_tm;
        char monthselect_str[32];
-       char calhourformat[16];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
        now = time(NULL);
        localtime_r(&now, &tm_now);
@@ -116,7 +116,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=23; ++i) {
 
-               if (!strcasecmp(calhourformat, "24")) {
+       if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
                                ((tm.tm_hour == i) ? "SELECTED" : ""),
                                i, i
index a3b28320a948200bf6ee0afbf4f6857317f6af28..76be44c05775ea12e0df67c8fd7d3cc7b2e15ba6 100644 (file)
@@ -220,11 +220,12 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        struct icaltimetype t;
        int month, day, year;
        int all_day_event = 0;
-       char calhourformat[16];
        char *timeformat;
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
-       if (!strcasecmp(calhourformat, "24"))   timeformat="%k:%M";
+       if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
        else timeformat="%I:%M %p";
 
        localtime_r(&thetime, &today_tm);
@@ -710,14 +711,14 @@ void calendar_day_view_display_events(int year, int month,
 void calendar_day_view(int year, int month, int day) {
        int hour;
        struct icaltimetype today, yesterday, tomorrow;
-       char calhourformat[16];
        int daystart = 8;
        int dayend = 17;
        char daystart_str[16], dayend_str[16];
        struct tm d_tm;
        char d_str[128];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
+       int time_format;
+       
+       time_format = get_time_format_cached ();
        get_preference("daystart", daystart_str, sizeof daystart_str);
        if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
        get_preference("dayend", dayend_str, sizeof dayend_str);
@@ -773,7 +774,7 @@ void calendar_day_view(int year, int month, int day) {
                        year, month, day, hour
                );
 
-               if (!strcasecmp(calhourformat, "24")) {
+               if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("%2d:00</a> ", hour);
                }
                else {
index 861089b5e928ab0278140a0f5e323178d879d383..4efbb6412b3cf49998920de6dc24c7d48ab869e3 100644 (file)
@@ -363,7 +363,6 @@ AC_ARG_WITH(backtrace,
                          fi
                        ]
 )
-echo "$CFLAGS $LDFLAGS"
 
 if test "$prefix" = NONE; then
        LOCALEDIR=$ac_default_prefix
index 2c7c9f6fd237b82981375bf8b9d8a50d7dc235d0..3c8210f9ae100a47e3419b0c01f035863da54f98 100644 (file)
@@ -50,10 +50,10 @@ void fmt_date(char *buf, time_t thetime, int brief)
        struct tm today_tm;
        time_t today_timet;
        int hour;
-       char calhourformat[16];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
-
+       int time_format;
+       
+       time_format = get_time_format_cached ();
+/// TODO: what about the time format?
        today_timet = time(NULL);
        localtime_r(&today_timet, &today_tm);
 
@@ -90,6 +90,25 @@ void fmt_date(char *buf, time_t thetime, int brief)
 }
 
 
+/**
+ * \brief learn the users timeformat preference.
+ */
+int get_time_format_cached (void)
+{
+       char calhourformat[16];
+       int *time_format_cache;
+       time_format_cache = &(WC->time_format_cache);
+       if (*time_format_cache == WC_TIMEFORMAT_NONE)
+       {
+               get_preference("calhourformat", calhourformat, sizeof calhourformat);
+               if (!strcasecmp(calhourformat, "24")) 
+                       *time_format_cache = WC_TIMEFORMAT_24;
+               else
+                       *time_format_cache = WC_TIMEFORMAT_AMPM;
+       }
+       return *time_format_cache;
+}
+
 /**
  * \brief Format TIME ONLY for output 
  * \param buf the output buffer
@@ -99,10 +118,9 @@ void fmt_time(char *buf, time_t thetime)
 {
        struct tm *tm;
        int hour;
-       char calhourformat[16];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
-
+       int time_format;
+       
+       time_format = get_time_format_cached ();
        buf[0] = 0;
        tm = localtime(&thetime);
        hour = tm->tm_hour;
@@ -111,7 +129,7 @@ void fmt_time(char *buf, time_t thetime)
        else if (hour > 12)
                hour = hour - 12;
 
-       if (!strcasecmp(calhourformat, "24")) {
+       if (time_format == WC_TIMEFORMAT_24) {
                sprintf(buf, "%2d:%02d",
                        tm->tm_hour, tm->tm_min
                );
index 02d410749f5b51382e5718a2e04339fa32451d21..279dac08583a16c3dbffc0585ec575d1143054c0 100644 (file)
@@ -195,8 +195,10 @@ void display_preferences(void)
        output_headers(1, 1, 1, 0, 0, 0);
        char ebuf[300];
        char buf[256];
-       char calhourformat[16];
        int i;
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
         wprintf("<div class=\"box\">\n");
         wprintf("<div class=\"boxlabel\">");
@@ -238,20 +240,21 @@ void display_preferences(void)
        /**
         * Calendar hour format
         */
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
-       if (calhourformat[0] == 0) strcpy(calhourformat, "12");
+
        wprintf("<tr class=\"odd\"><td>");
        wprintf(_("Calendar hour format"));
        wprintf("</td><td>");
 
        wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
-       if (!strcasecmp(calhourformat, "12")) wprintf(" checked");
+       if (time_format == WC_TIMEFORMAT_AMPM) 
+               wprintf(" checked");
        wprintf(">");
        wprintf(_("12 hour (am/pm)"));
        wprintf("</input>&nbsp;&nbsp;&nbsp;");
 
        wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
-       if (!strcasecmp(calhourformat, "24")) wprintf(" checked");
+       if (time_format == WC_TIMEFORMAT_24)
+               wprintf(" checked");
        wprintf(">");
        wprintf(_("24 hour"));
        wprintf("</input>\n");
@@ -270,7 +273,7 @@ void display_preferences(void)
        wprintf("<select name=\"daystart\" size=\"1\">\n");
        for (i=0; i<=23; ++i) {
 
-               if (!strcasecmp(calhourformat, "24")) {
+               if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("<option %s value=\"%d\">%d:00</option>\n",
                                ((atoi(buf) == i) ? "selected" : ""),
                                i, i
@@ -299,7 +302,7 @@ void display_preferences(void)
        wprintf("<select name=\"dayend\" size=\"1\">\n");
        for (i=0; i<=23; ++i) {
 
-               if (!strcasecmp(calhourformat, "24")) {
+               if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("<option %s value=\"%d\">%d:00</option>\n",
                                ((atoi(buf) == i) ? "selected" : ""),
                                i, i
@@ -401,7 +404,11 @@ void display_preferences(void)
  */
 void set_preferences(void)
 {
+       char *fmt;
        char ebuf[300];
+       int *time_format_cache;
+       
+       time_format_cache = &(WC->time_format_cache);
 
        if (IsEmptyStr(bstr("change_button"))) {
                safestrncpy(WC->ImportantMessage, 
@@ -416,7 +423,13 @@ void set_preferences(void)
         * we don't send the prefs file to the server repeatedly
         */
        set_preference("roomlistview", bstr("roomlistview"), 0);
-       set_preference("calhourformat", bstr("calhourformat"), 0);
+       fmt = bstr("calhourformat");
+       set_preference("calhourformat", fmt, 0);
+       if (!strcasecmp(fmt, "24")) 
+               *time_format_cache = WC_TIMEFORMAT_24;
+       else
+               *time_format_cache = WC_TIMEFORMAT_AMPM;
+
        set_preference("use_sig", bstr("use_sig"), 0);
        set_preference("daystart", bstr("daystart"), 0);
        set_preference("dayend", bstr("dayend"), 0);
index 1fff20e76a79f0ddb8b959e2dc19235f16b5f971..4636e4f3146fd6e8c033a14bd078748af20d9be9 100644 (file)
@@ -404,6 +404,7 @@ struct wcsession {
        int selected_language;                  /**< Language selected by user */
        time_t last_pager_check;                /**< last time we polled for instant msgs */
        int nonce;                              /**< session nonce (to prevent session riding) */
+       int time_format_cache;                  /**< which timeformat does our user like? */
 };
 
 /** values for WC->current_iconbar */
@@ -717,6 +718,7 @@ void end_tab(int tabnum, int num_tabs);
 void str_wiki_index(char *s);
 void display_wiki_page(void);
 char *bmstrcasestr(char *text, char *pattern);
+int get_time_format_cached (void);
 
 #ifdef HAVE_ICONV
 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);
@@ -780,3 +782,10 @@ void http_datestring(char *buf, size_t n, time_t xtime);
  */
 #define WC_EXIT_BIND           101     /* Can't bind to the port */
 #define WC_EXIT_SSL            102     /* Can't initialize SSL */
+
+
+#define WC_TIMEFORMAT_NONE 0
+#define WC_TIMEFORMAT_AMPM 1
+#define WC_TIMEFORMAT_24 2
+
+