evolution-3.6.4/calendar/gui/e-meeting-utils.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-meeting-utils.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-meeting-utils.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		JP Rosevear <jpr@novell.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include <string.h>
 29 #include <libedataserver/libedataserver.h>
 30 
 31 #include "e-meeting-utils.h"
 32 
 33 gint
 34 e_meeting_time_compare_times (EMeetingTime *time1,
 35                               EMeetingTime *time2)
 36 {
 37 	gint day_comparison;
 38 
 39 	day_comparison = g_date_compare (&time1->date, &time2->date);
 40 
 41 	if (day_comparison != 0)
 42 		return day_comparison;
 43 
 44 	if (time1->hour < time2->hour)
 45 		return -1;
 46 	if (time1->hour > time2->hour)
 47 		return 1;
 48 
 49 	if (time1->minute < time2->minute)
 50 		return -1;
 51 	if (time1->minute > time2->minute)
 52 		return 1;
 53 
 54 	/* The start times are exactly the same. */
 55 	return 0;
 56 }
 57 
 58 void
 59 e_meeting_xfb_data_init (EMeetingXfbData *xfb)
 60 {
 61 	g_return_if_fail (xfb != NULL);
 62 
 63 	xfb->summary = NULL;
 64 	xfb->location = NULL;
 65 }
 66 
 67 void
 68 e_meeting_xfb_data_set (EMeetingXfbData *xfb,
 69                         const gchar *summary,
 70                         const gchar *location)
 71 {
 72 	g_return_if_fail (xfb != NULL);
 73 
 74 	e_meeting_xfb_data_clear (xfb);
 75 	xfb->summary = g_strdup (summary);
 76 	xfb->location = g_strdup (location);
 77 }
 78 
 79 void
 80 e_meeting_xfb_data_clear (EMeetingXfbData *xfb)
 81 {
 82 	g_return_if_fail (xfb != NULL);
 83 
 84 	/* clearing the contents of xfb,
 85 	 * but not the xfb structure itself
 86 	 */
 87 
 88 	if (xfb->summary != NULL) {
 89 		g_free (xfb->summary);
 90 		xfb->summary = NULL;
 91 	}
 92 	if (xfb->location != NULL) {
 93 		g_free (xfb->location);
 94 		xfb->location = NULL;
 95 	}
 96 }
 97 
 98 /* Creates an XFB string from a string property of a vfreebusy
 99  * icalproperty. The ical string we read may be base64 encoded, but
100  * we get no reliable indication whether it really is. So we
101  * try to base64-decode, and failing that, assume the string
102  * is plain. The result is validated for UTF-8. We try to convert
103  * to UTF-8 from locale if the input is no valid UTF-8, and failing
104  * that, force the result into valid UTF-8. We also limit the
105  * length of the resulting string, since it gets displayed as a
106  * tooltip text in the meeting time selector.
107  */
108 gchar*
109 e_meeting_xfb_utf8_string_new_from_ical (const gchar *icalstring,
110                                          gsize max_len)
111 {
112 	gchar *tmp = NULL;
113 	gchar *utf8s = NULL;
114 	gsize in_len = 0;
115 	gsize out_len = 0;
116 	GError *tmp_err = NULL;
117 
118 	g_return_val_if_fail (max_len > 4, NULL);
119 
120 	if (icalstring == NULL)
121 		return NULL;
122 
123 	/* ical does not carry charset hints, so we
124 	 * try UTF-8 first, then conversion using
125 	 * system locale info.
126 	 */
127 
128 	/* if we have valid UTF-8, we're done converting */
129 	if (g_utf8_validate (icalstring, -1, NULL))
130 		goto valid;
131 
132 	/* no valid UTF-8, trying to convert to it
133 	 * according to system locale
134 	 */
135 	tmp = g_locale_to_utf8 (icalstring,
136 	                        -1,
137 	                        &in_len,
138 	                        &out_len,
139 	                        &tmp_err);
140 
141 	if (tmp_err == NULL)
142 		goto valid;
143 
144 	g_warning ("%s: %s", G_STRFUNC, tmp_err->message);
145 	g_error_free (tmp_err);
146 	g_free (tmp);
147 
148 	/* still no success, forcing it into UTF-8, using
149 	 * replacement chars to replace invalid ones
150 	 */
151 	tmp = e_util_utf8_data_make_valid (icalstring,
152 	                                   strlen (icalstring));
153  valid:
154 	if (tmp == NULL)
155 		tmp = g_strdup (icalstring);
156 
157 	/* now that we're (forcibly) valid UTF-8, we can
158 	 * limit the size of the UTF-8 string for display
159 	 */
160 
161 	if (g_utf8_strlen (tmp, -1) > (glong) max_len) {
162 		/* insert NULL termination to where we want to
163 		 * clip, take care to hit UTF-8 character boundary
164 		 */
165 		utf8s = g_utf8_offset_to_pointer (tmp, (glong) max_len - 4);
166 		*utf8s = '\0';
167 		/* create shortened UTF-8 string */
168 		utf8s = g_strdup_printf ("%s ...", tmp);
169 		g_free (tmp);
170 	} else {
171 		utf8s = tmp;
172 	}
173 
174 	return utf8s;
175 }