Update Romanian translation
[evolution.git] / src / calendar / gui / e-meeting-utils.c
blobe7df2f89fa3d0c2ef1cc32965b17891d3e5a433a
1 /*
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
10 * for more details.
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/>.
16 * Authors:
17 * JP Rosevear <jpr@novell.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #include "evolution-config.h"
25 #include <string.h>
26 #include <libedataserver/libedataserver.h>
28 #include "e-meeting-utils.h"
30 gint
31 e_meeting_time_compare_times (EMeetingTime *time1,
32 EMeetingTime *time2)
34 gint day_comparison;
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)
42 return -1;
43 if (time1->hour > time2->hour)
44 return 1;
46 if (time1->minute < time2->minute)
47 return -1;
48 if (time1->minute > time2->minute)
49 return 1;
51 /* The start times are exactly the same. */
52 return 0;
55 void
56 e_meeting_xfb_data_init (EMeetingXfbData *xfb)
58 g_return_if_fail (xfb != NULL);
60 xfb->summary = NULL;
61 xfb->location = NULL;
64 void
65 e_meeting_xfb_data_set (EMeetingXfbData *xfb,
66 const gchar *summary,
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);
76 void
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);
87 xfb->summary = NULL;
89 if (xfb->location != NULL) {
90 g_free (xfb->location);
91 xfb->location = NULL;
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.
105 gchar *
106 e_meeting_xfb_utf8_string_new_from_ical (const gchar *icalstring,
107 gsize max_len)
109 gchar *tmp = NULL;
110 gchar *utf8s = NULL;
111 gsize in_len = 0;
112 gsize out_len = 0;
113 GError *tmp_err = NULL;
115 g_return_val_if_fail (max_len > 4, NULL);
117 if (icalstring == NULL)
118 return 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))
127 goto valid;
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);
135 if (tmp_err == NULL)
136 goto valid;
138 g_warning ("%s: %s", G_STRFUNC, tmp_err->message);
139 g_error_free (tmp_err);
140 g_free (tmp);
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));
147 valid:
148 if (tmp == NULL)
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);
160 *utf8s = '\0';
161 /* create shortened UTF-8 string */
162 utf8s = g_strdup_printf ("%s ...", tmp);
163 g_free (tmp);
164 } else {
165 utf8s = tmp;
168 return utf8s;