3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * JP Rosevear <jpr@novell.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #include "evolution-config.h"
26 #include <libedataserver/libedataserver.h>
28 #include "e-meeting-utils.h"
31 e_meeting_time_compare_times (EMeetingTime
*time1
,
36 day_comparison
= g_date_compare (&time1
->date
, &time2
->date
);
38 if (day_comparison
!= 0)
39 return day_comparison
;
41 if (time1
->hour
< time2
->hour
)
43 if (time1
->hour
> time2
->hour
)
46 if (time1
->minute
< time2
->minute
)
48 if (time1
->minute
> time2
->minute
)
51 /* The start times are exactly the same. */
56 e_meeting_xfb_data_init (EMeetingXfbData
*xfb
)
58 g_return_if_fail (xfb
!= NULL
);
65 e_meeting_xfb_data_set (EMeetingXfbData
*xfb
,
67 const gchar
*location
)
69 g_return_if_fail (xfb
!= NULL
);
71 e_meeting_xfb_data_clear (xfb
);
72 xfb
->summary
= g_strdup (summary
);
73 xfb
->location
= g_strdup (location
);
77 e_meeting_xfb_data_clear (EMeetingXfbData
*xfb
)
79 g_return_if_fail (xfb
!= NULL
);
81 /* clearing the contents of xfb,
82 * but not the xfb structure itself
85 if (xfb
->summary
!= NULL
) {
86 g_free (xfb
->summary
);
89 if (xfb
->location
!= NULL
) {
90 g_free (xfb
->location
);
95 /* Creates an XFB string from a string property of a vfreebusy
96 * icalproperty. The ical string we read may be base64 encoded, but
97 * we get no reliable indication whether it really is. So we
98 * try to base64-decode, and failing that, assume the string
99 * is plain. The result is validated for UTF-8. We try to convert
100 * to UTF-8 from locale if the input is no valid UTF-8, and failing
101 * that, force the result into valid UTF-8. We also limit the
102 * length of the resulting string, since it gets displayed as a
103 * tooltip text in the meeting time selector.
106 e_meeting_xfb_utf8_string_new_from_ical (const gchar
*icalstring
,
113 GError
*tmp_err
= NULL
;
115 g_return_val_if_fail (max_len
> 4, NULL
);
117 if (icalstring
== NULL
)
120 /* ical does not carry charset hints, so we
121 * try UTF-8 first, then conversion using
122 * system locale info.
125 /* if we have valid UTF-8, we're done converting */
126 if (g_utf8_validate (icalstring
, -1, NULL
))
129 /* no valid UTF-8, trying to convert to it
130 * according to system locale
132 tmp
= g_locale_to_utf8 (
133 icalstring
, -1, &in_len
, &out_len
, &tmp_err
);
138 g_warning ("%s: %s", G_STRFUNC
, tmp_err
->message
);
139 g_error_free (tmp_err
);
142 /* still no success, forcing it into UTF-8, using
143 * replacement chars to replace invalid ones
145 tmp
= e_util_utf8_data_make_valid (
146 icalstring
, strlen (icalstring
));
149 tmp
= g_strdup (icalstring
);
151 /* now that we're (forcibly) valid UTF-8, we can
152 * limit the size of the UTF-8 string for display
155 if (g_utf8_strlen (tmp
, -1) > (glong
) max_len
) {
156 /* insert NULL termination to where we want to
157 * clip, take care to hit UTF-8 character boundary
159 utf8s
= g_utf8_offset_to_pointer (tmp
, (glong
) max_len
- 4);
161 /* create shortened UTF-8 string */
162 utf8s
= g_strdup_printf ("%s ...", tmp
);