tracker-0.16.2/src/miners/fs/tracker-miner-locale.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found tracker-miner-locale.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
  1 /*
  2  * Copyright (C) 2010 Nokia <ivan.frade@nokia.com>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 #include <string.h>
 22 
 23 #include <libtracker-common/tracker-locale.h>
 24 
 25 #include "tracker-miner-locale.h"
 26 #ifdef HAVE_MEEGOTOUCH
 27 #include "tracker-miner-meego.h"
 28 #endif
 29 
 30 /* NOTE: This applies to more miners than just the application miner,
 31  * it's kept this way to avoid breaking things.
 32  */
 33 #define TRACKER_MINER_LOCALE_FILE "miner-applications-locale.txt"
 34 
 35 static gchar *
 36 miner_locale_get_filename (void)
 37 {
 38 	gchar *data_dir;
 39 	gchar *filename;
 40 
 41 	/* Locate locale file */
 42 	data_dir = g_build_filename (g_get_user_cache_dir (),
 43 	                             "tracker",
 44 	                             NULL);
 45 	filename = g_build_filename (data_dir, TRACKER_MINER_LOCALE_FILE, NULL);
 46 
 47 	g_free (data_dir);
 48 
 49 	return filename;
 50 }
 51 
 52 static gchar *
 53 miner_locale_get_previous (void)
 54 {
 55 	gchar *locale_file, *locale = NULL;
 56 
 57 	locale_file = miner_locale_get_filename ();
 58 
 59 	if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) {
 60 		gchar *contents;
 61 
 62 		/* Check locale is correct */
 63 		if (G_LIKELY (g_file_get_contents (locale_file, &contents, NULL, NULL))) {
 64 			if (contents &&
 65 			    contents[0] == '\0') {
 66 				g_critical ("  Empty locale file found at '%s'", locale_file);
 67 				g_free (contents);
 68 			} else {
 69 				/* Re-use contents */
 70 				locale = contents;
 71 			}
 72 		} else {
 73 			g_critical ("  Could not get content of file '%s'", locale_file);
 74 		}
 75 	} else {
 76 		g_message ("  Could not find locale file:'%s'", locale_file);
 77 	}
 78 
 79 	g_free (locale_file);
 80 
 81 	return locale;
 82 }
 83 
 84 static gchar *
 85 miner_locale_get_current (void)
 86 {
 87 	gchar *current_locale;
 88 
 89 #ifdef HAVE_MEEGOTOUCH
 90 	/* If we have meegotouch enabled, take the correct locale as the one from
 91 	 * meegotouch. */
 92 	current_locale = tracker_miner_meego_get_locale ();
 93 #else
 94 	/* Get current tracker LANG locale */
 95 	current_locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE);
 96 #endif
 97 
 98 	return current_locale;
 99 }
100 
101 void
102 tracker_miner_locale_set_current (void)
103 {
104 	GError *error = NULL;
105 	gchar *locale_file, *locale = NULL;
106 
107 	locale_file = miner_locale_get_filename ();
108 
109 	g_message ("  Creating locale file '%s'", locale_file);
110 
111 	locale = miner_locale_get_current ();
112 
113 	if (locale == NULL) {
114 		locale = g_strdup ("");
115 	}
116 
117 	if (!g_file_set_contents (locale_file, locale, -1, &error)) {
118 		g_message ("  Could not set file contents, %s",
119 		           error ? error->message : "no error given");
120 		g_clear_error (&error);
121 	}
122 
123 	g_free (locale);
124 	g_free (locale_file);
125 }
126 
127 gboolean
128 tracker_miner_locale_changed (void)
129 {
130 	gchar *previous_locale;
131 	gchar *current_locale;
132 	gboolean changed;
133 
134 	current_locale = miner_locale_get_current ();
135 
136 	/* Get previous locale */
137 	previous_locale = miner_locale_get_previous ();
138 
139 	/* Note that having both to NULL is actually valid, they would default
140 	 * to the unicode collation without locale-specific stuff. */
141 	if (g_strcmp0 (previous_locale, current_locale) != 0) {
142 		g_message ("Locale change detected from '%s' to '%s'...",
143 		           previous_locale, current_locale);
144 		changed = TRUE;
145 	} else {
146 		g_message ("Current and previous locales match: '%s'", previous_locale);
147 		changed = FALSE;
148 	}
149 
150 	g_free (previous_locale);
151 	g_free (current_locale);
152 	return changed;
153 }