Updating branch refs/heads/master
         to bd4d460ed7ecf50362696ac9b723ad880a1d52cd (commit)
       from 88ed9186ea9a35a241ebf068ac953df5e5f8219b (commit)

commit bd4d460ed7ecf50362696ac9b723ad880a1d52cd
Author: Juha <j...@xfce.org>
Date:   Tue Feb 12 14:58:52 2013 +0200

    4.9.5.0 Enhancement 9011 improve tooltip behaviour
    
    Limited note text tooltip size to fixed 50 x 10 chars (= 10 lines max
    and each line max length is 50).
    Also changed orage_message timestamp location. And added formatted
    tooltip to day view.

 configure.in.in |    2 +-
 src/day-view.c  |   30 +++++++++++------
 src/functions.c |   94 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/functions.h |    5 ++-
 src/mainbox.c   |    3 +-
 src/reminder.c  |    7 +++-
 6 files changed, 116 insertions(+), 25 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index d314ba0..95683c4 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <j...@xfce.org>
 dnl
 
 dnl Version information
-m4_define([orage_version], [4.9.4.1-git])
+m4_define([orage_version], [4.9.5.0-git])
 
 m4_define([gtk_minimum_version], [2.14.0])
 m4_define([xfce_minimum_version], [4.8.0])
diff --git a/src/day-view.c b/src/day-view.c
index 46ae886..5cd2f03 100644
--- a/src/day-view.c
+++ b/src/day-view.c
@@ -511,10 +511,12 @@ static void add_row(day_win *dw, xfical_appt *appt)
     gint row, start_row, end_row, days;
     gint col, start_col, end_col, first_col, last_col;
     gint height, start_height, end_height;
-    gchar *tip, *start_date, *end_date, *tmp_title, *tmp_note;
+    gchar *tip, *start_date, *end_date, *tmp_title, *tip_title;
+    gchar *tmp_note, *tip_note;
     GtkWidget *ev, *lab, *hb;
     struct tm tm_start, tm_end, tm_first;
     GdkColor *color;
+    gchar *format_bold = "<b> %s </b>";
 
     /* First clarify timings */
     tm_start = orage_icaltime_to_tm_time(appt->starttimecur, FALSE);
@@ -545,7 +547,12 @@ static void add_row(day_win *dw, xfical_appt *appt)
     /* then add the appointment */
     tmp_title = orage_process_text_commands(
             appt->title ? appt->title : _("Unknown"));
-    tmp_note = orage_process_text_commands(appt->note);
+    tip_title = g_markup_printf_escaped(format_bold, tmp_title);
+    tmp_note = orage_process_text_commands(
+            appt->note ? appt->note : "");
+    tmp_note = orage_limit_text(tmp_note, 50, 10);
+    tip_note = g_markup_escape_text(tmp_note, strlen(tmp_note));
+    g_free(tmp_note);
     ev = gtk_event_box_new();
     lab = gtk_label_new(tmp_title);
     gtk_container_add(GTK_CONTAINER(ev), lab);
@@ -568,13 +575,13 @@ static void add_row(day_win *dw, xfical_appt *appt)
         start_date = g_strdup(orage_tm_date_to_i18_date(&tm_start));
         if (days == 0)
             tip = g_strdup_printf("%s\n%s\n%s"
-                    , tmp_title, start_date, tmp_note);
+                    , tip_title, start_date, tip_note);
         else {
             tm_end.tm_year -= 1900;
             tm_end.tm_mon -= 1;
             end_date = g_strdup(orage_tm_date_to_i18_date(&tm_end));
             tip = g_strdup_printf("%s\n%s - %s\n%s"
-                    , tmp_title, start_date, end_date, tmp_note);
+                    , tip_title, start_date, end_date, tip_note);
             g_free(end_date);
         }
         g_free(start_date);
@@ -596,8 +603,8 @@ static void add_row(day_win *dw, xfical_appt *appt)
         }
         if (days == 0)
             tip = g_strdup_printf("%s\n%02d:%02d-%02d:%02d\n%s"
-                    , tmp_title, tm_start.tm_hour, tm_start.tm_min
-                    , tm_end.tm_hour, tm_end.tm_min, tmp_note);
+                    , tip_title, tm_start.tm_hour, tm_start.tm_min
+                    , tm_end.tm_hour, tm_end.tm_min, tip_note);
         else {
     /* we took the date in unnormalized format, so we need to do that now */
             tm_start.tm_year -= 1900;
@@ -607,14 +614,14 @@ static void add_row(day_win *dw, xfical_appt *appt)
             start_date = g_strdup(orage_tm_date_to_i18_date(&tm_start));
             end_date = g_strdup(orage_tm_date_to_i18_date(&tm_end));
             tip = g_strdup_printf("%s\n%s %02d:%02d - %s %02d:%02d\n%s"
-                    , tmp_title
+                    , tip_title
                     , start_date, tm_start.tm_hour, tm_start.tm_min
-                    , end_date, tm_end.tm_hour, tm_end.tm_min, tmp_note);
+                    , end_date, tm_end.tm_hour, tm_end.tm_min, tip_note);
             g_free(start_date);
             g_free(end_date);
         }
     }
-    gtk_widget_set_tooltip_text(ev, tip);
+    gtk_widget_set_tooltip_markup(ev, tip);
     /*
     gtk_box_pack_start(GTK_BOX(hb2), ev, FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(hb), hb2, TRUE, TRUE, 0);
@@ -623,9 +630,10 @@ static void add_row(day_win *dw, xfical_appt *appt)
     g_object_set_data_full(G_OBJECT(ev), "UID", g_strdup(appt->uid), g_free);
     g_signal_connect((gpointer)ev, "button-press-event"
             , G_CALLBACK(on_button_press_event_cb), dw);
-    g_free(tip);
     g_free(tmp_title);
-    g_free(tmp_note);
+    g_free(tip);
+    g_free(tip_title);
+    g_free(tip_note);
 
     /* and finally draw the line to show how long the appointment is,
      * but only if it is Busy type event (=availability != 0) 
diff --git a/src/functions.c b/src/functions.c
index b70e7e3..e32ea2b 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -1,6 +1,6 @@
 /*      Orage - Calendar and alarm handler
  *
- * Copyright (c) 2005-2011 Juha Kautto  (juha at xfce.org)
+ * Copyright (c) 2005-2013 Juha Kautto  (juha at xfce.org)
  * Copyright (c) 2003-2005 Mickael Graf (korbinus at xfce.org)
  *
  * This program is free software; you can redistribute it and/or modify
@@ -89,7 +89,7 @@ void program_log (const char *format, ...)
 void orage_message(gint level, const char *format, ...)
 {
     va_list args;
-    char *formatted;
+    char *formatted, time_stamp[10];
     struct tm *t = orage_localtime();
 
     if (level < g_log_level)
@@ -98,17 +98,17 @@ void orage_message(gint level, const char *format, ...)
     formatted = g_strdup_vprintf(format, args);
     va_end(args);
 
-    g_print("%02d:%02d:%02d ", t->tm_hour, t->tm_min, t->tm_sec);
+    g_sprintf(time_stamp, "%02d:%02d:%02d ", t->tm_hour, t->tm_min, t->tm_sec);
     if (level < 0)
-        g_debug("%s", formatted);
+        g_debug("%s%s", time_stamp, formatted);
     else if (level < 100) 
-        g_message("Orage **: %s", formatted);
+        g_message("Orage **: %s %s", time_stamp, formatted);
     else if (level < 200) 
-        g_warning("%s", formatted);
+        g_warning("%s%s", time_stamp, formatted);
     else if (level < 300) 
-        g_critical("%s", formatted);
+        g_critical("%s%s", time_stamp, formatted);
     else
-        g_error("Orage **: %s", formatted);
+        g_error("Orage **: %s%s", time_stamp, formatted);
     g_free(formatted);
 }
 
@@ -334,7 +334,7 @@ char *orage_replace_text(char *text, char *old, char *new)
 {
 #undef P_N
 #define P_N "orage_replace_text: "
-    /* these point to the original string and travel it until no more commands 
+    /* these point to the original string and travel it until no more olds 
      * are found:
      * cur points to the current head (after each old if any found)
      * cmd points to the start of next old in text */
@@ -370,6 +370,82 @@ char *orage_replace_text(char *text, char *old, char *new)
     return(beq);
 }
 
+/* This is helper function for orage_limit_text. It takes char pointer
+   to string start and length and adds that "line" to the beginning of 
+   old_result and returns the new_result.
+*/
+static char* add_line(char *old_result, char *start, int line_len
+        , int max_line_len)
+{
+    char *tmp;
+    char *line;          /* new line to add */
+    char *new_result;
+
+    if (line_len > max_line_len) {
+        tmp = g_strndup(start, max_line_len-3);
+        if (*(start+line_len-1) == '\n') { /* need to add line change */
+            line = g_strjoin("", tmp, "...\n", NULL);
+        }
+        else {
+            line = g_strjoin("", tmp, "...", NULL);
+        }
+        g_free(tmp);
+    }
+    else {
+        line = g_strndup(start, line_len);
+    }
+    /* note that old_result can be NULL */
+    new_result = g_strjoin("", line, old_result, NULL);
+    g_free(line);
+    g_free(old_result);
+    return(new_result);
+}
+
+/* cuts text to fit in a box defined with max_line_len and max_lines.
+   This is usefull for example in tooltips to avoid too broad and too may lines
+   to be visible.
+   You can always use this like 
+   str=orage_limit_text(str, max_line_len, max_lines);
+   but it may point to new place.
+*/
+char *orage_limit_text(char *text, int max_line_len, int max_lines)
+{
+#undef P_N
+#define P_N "orage_limit_text: "
+    /* these point to the original string and travel it until no more cuts 
+     * are needed:
+     * cur points to the current end of text character.
+     * eol is pointing to the end of current line */
+    char *cur, *eol;
+    char *result=NULL;   /* end result is collected to this */
+    int text_len=strlen(text);
+    int line_cnt=0;
+
+    if (text_len < 2) /* nothing to do */
+        return(text);
+    /* we start from the end and collect upto max_lines to a new buffer, but
+     * cut them to max_line_len before accepting */
+    for (cur = text+text_len-2, eol = text+text_len-1;
+         (cur > text) && (line_cnt < max_lines); cur--) {
+        if (*cur == '\n') {
+            /* line found, collect the line */
+            result = add_line(result, cur+1, eol-cur, max_line_len);
+            line_cnt++;
+            eol = cur;
+        }
+    }
+    /* Need to process first line also as it does not start with line end */
+    if ((cur == text) && (line_cnt < max_lines)) {
+        result = add_line(result, cur, eol-cur+1, max_line_len);
+    }
+    if (result) {
+        g_free(text);
+        return(result);
+    }
+    else 
+        return(text);
+}
+
 /* this will change <&Xnnn> type commands to numbers or text as defined.
  * Currently the only command is 
  * <&Ynnnn> which calculates years between current year and nnnn */
diff --git a/src/functions.h b/src/functions.h
index fe59350..e2ac50d 100644
--- a/src/functions.h
+++ b/src/functions.h
@@ -1,6 +1,6 @@
 /*      Orage - Calendar and alarm handler
  *
- * Copyright (c) 2006-2011 Juha Kautto  (juha at xfce.org)
+ * Copyright (c) 2006-2013 Juha Kautto  (juha at xfce.org)
  * Copyright (c) 2005-2006 Mickael Graf (korbinus at xfce.org)
  *
  * This program is free software; you can redistribute it and/or modify
@@ -84,8 +84,11 @@ GtkWidget *orage_image_menu_item_new_from_stock(const gchar 
*stock_id
 GtkWidget *orage_separator_menu_item_new(GtkWidget *menu);
 GtkWidget *orage_menu_item_new_with_mnemonic(const gchar *label
         , GtkWidget *menu);
+
 char *orage_replace_text(char *text, char *old, char *new);
+char *orage_limit_text(char *text, int max_line_len, int max_lines);
 char *orage_process_text_commands(char *text);
+
 GtkWidget *orage_period_hbox_new(gboolean head_space, gboolean tail_space
         , GtkWidget *spin_dd, GtkWidget *dd_label
         , GtkWidget *spin_hh, GtkWidget *hh_label
diff --git a/src/mainbox.c b/src/mainbox.c
index 85ca122..ca82d5b 100644
--- a/src/mainbox.c
+++ b/src/mainbox.c
@@ -381,7 +381,7 @@ static void add_info_row(xfical_appt *appt, GtkBox 
*parentBox, gboolean todo)
     CalWin *cal = (CalWin *)g_par.xfcal;
     gchar *tip, *tmp, *tmp_title, *tmp_note;
     gchar *tip_title, *tip_location, *tip_note;
-    gchar *format_bold = "<span weight=\"bold\"> %s </span>";
+    gchar *format_bold = "<b> %s </b>";
     struct tm *t;
     char  *l_time, *s_time, *s_timeonly, *e_time, *c_time, *na, *today;
     gint  len;
@@ -458,6 +458,7 @@ static void add_info_row(xfical_appt *appt, GtkBox 
*parentBox, gboolean todo)
     }
     if (appt->note) {
         tmp_note = orage_process_text_commands(appt->note);
+        tmp_note = orage_limit_text(tmp_note, 50, 10);
         tmp = g_markup_escape_text(tmp_note, strlen(tmp_note));
         tip_note = g_strdup_printf(_("\n Note:\n%s"), tmp);
         g_free(tmp);
diff --git a/src/reminder.c b/src/reminder.c
index eeb6934..980cb5b 100644
--- a/src/reminder.c
+++ b/src/reminder.c
@@ -1078,6 +1078,7 @@ static gboolean orage_tooltip_update(gpointer user_data)
     gint year, month, day, hour, minute, second;
     gint dd, hh, min;
     GDate *g_now, *g_alarm;
+    gchar *tmp;
 
 #ifdef ORAGE_DEBUG
     orage_message(-100, P_N);
@@ -1132,8 +1133,10 @@ static gboolean orage_tooltip_update(gpointer user_data)
             if (cur_alarm->temporary) { /* let's add a small mark */
                 g_string_append_c(tooltip_highlight_helper, '[');
             }
-            g_string_append_printf(tooltip_highlight_helper, 
-                    "%s", cur_alarm->title);
+            tmp = g_markup_escape_text(cur_alarm->title
+                    , strlen(cur_alarm->title));
+            g_string_append_printf(tooltip_highlight_helper, "%s", tmp);
+            g_free(tmp);
             if (cur_alarm->temporary) { /* let's add a small mark */
                 g_string_append_c(tooltip_highlight_helper, ']');
             }
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to