config-data.c 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/* Evolution calendar - Configuration values for the alarm notification daemon
 *
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Authors: Federico Mena-Quintero <federico@ximian.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "config-data.h"
#include "save.h"



/* Whether we have initied ourselves by reading the data from the configuration engine */
static gboolean inited;

/* Configuration values */
static icaltimezone *local_timezone;
static gboolean use_24_hour_format;



/* Copied from ../calendar-config.c; returns whether the locale has 'am' and
 * 'pm' strings defined.
 */
static gboolean
locale_supports_12_hour_format (void)
{  
	char s[16];
	time_t t = 0;

	strftime (s, sizeof s, "%p", gmtime (&t));
	return s[0] != '\0';
}

/* Ensures that the configuration values have been read */
static void
ensure_inited (void)
{
	Bonobo_ConfigDatabase db;
	char *location;

	if (inited)
		return;

	inited = TRUE;

	db = get_config_db ();
	if (db == CORBA_OBJECT_NIL) {
		/* This sucks */
		local_timezone = icaltimezone_get_utc_timezone ();

		/* This sucks as well */
		use_24_hour_format = TRUE;

		return;
	}

	location = bonobo_config_get_string (db, "/Calendar/Display/Timezone", NULL);
	if (location) {
		local_timezone = icaltimezone_get_builtin_timezone (location);
		g_free (location);
	} else
		local_timezone = icaltimezone_get_utc_timezone ();

	if (locale_supports_12_hour_format ()) {
		/* Wasn't the whole point of a configuration engine *NOT* to
		 * have apps specify their own stupid defaults everywhere, but
		 * just in a schema file?
		 */
		use_24_hour_format = bonobo_config_get_boolean_with_default (
			db,
			"/Calendar/Display/Use24HourFormat", FALSE, NULL);
	} else
		use_24_hour_format = TRUE;

	discard_config_db (db);
}

icaltimezone *
config_data_get_timezone (void)
{
	ensure_inited ();

	return local_timezone;
}

gboolean
config_data_get_24_hour_format (void)
{
	ensure_inited ();

	return use_24_hour_format;
}