示例#1
0
static gint
load_categories (void)
{
	gchar *contents;
	gchar *filename;
	gsize length;
	gint n_added = 0;
	GError *error = NULL;

	contents = NULL;
	filename = build_categories_filename ();

	if (!g_file_test (filename, G_FILE_TEST_EXISTS))
		goto exit;

	g_debug ("Loading categories from \"%s\"", filename);

	if (!g_file_get_contents (filename, &contents, &length, &error)) {
		g_warning ("Unable to load categories: %s", error->message);
		g_error_free (error);
		goto exit;
	}

	n_added = parse_categories (contents, length);

exit:
	g_free (contents);
	g_free (filename);

	return n_added;
}
示例#2
0
static gboolean
migrate_old_categories (void)
{
	/* Try migrating old category settings from GConf to the new
         * category XML file.  If successful, unset the old GConf key
         * so that this is a one-time-only operation. */

	const gchar *key = "/apps/evolution/general/category_master_list";

	GConfClient *client;
	gchar *string;
	gint n_added = 0;

	client = gconf_client_get_default ();
	string = gconf_client_get_string (client, key, NULL);
	if (string == NULL || *string == '\0')
		goto exit;

	g_debug ("Loading categories from GConf key \"%s\"", key);

	n_added = parse_categories (string, strlen (string));
	if (n_added == 0)
		goto exit;

	/* default icon files are now in an unversioned directory */
	g_hash_table_foreach (categories_table, migrate_old_icon_file, NULL);

	gconf_client_unset (client, key, NULL);

exit:
	g_object_unref (client);
	g_free (string);

	return n_added;
}
示例#3
0
static void
parse_waypoint(void)
{
    char *str;
    int column = -1;
    waypoint *wpt;
    garmin_fs_p gmsd = NULL;

    bind_fields(waypt_header);

    wpt = waypt_new();
    gmsd = garmin_fs_alloc(-1);
    fs_chain_add(&wpt->fs, (format_specific_data *) gmsd);

    while ((str = csv_lineparse(NULL, "\t", "", column++)))
    {
        int i, dynamic;
        double d;
        int field_no = header_fields[waypt_header][column];

        switch(field_no) {
        case  1:
            wpt->shortname = DUPSTR(str);
            break;
        case  2:
            wpt->notes = DUPSTR(str);
            break;
        case  3:
            for (i = 0; i <= gt_waypt_class_map_line; i++) {
                if (case_ignore_strcmp(str, gt_waypt_class_names[i]) == 0) {
                    GMSD_SET(wpt_class, i);
                    break;
                }
            }
            break;
        case  4:
            parse_coordinates(str, datum_index, grid_index,
                              &wpt->latitude, &wpt->longitude, MYNAME);
            break;
        case  5:
            if (parse_distance(str, &d, 1, MYNAME)) wpt->altitude = d;
            break;
        case  6:
            if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, depth, d);
            break;
        case  7:
            if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, proximity, d);
            break;
        case  8:
            if (parse_temperature(str, &d)) WAYPT_SET(wpt, temperature, d);
            break;
        case  9:
            if (parse_display(str, &i)) GMSD_SET(display, i);
            break;
        case 10:
            break;	/* skip color */
        case 11:
            i = gt_find_icon_number_from_desc(str, GDB);
            GMSD_SET(icon, i);
            wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic);
            wpt->wpt_flags.icon_descr_is_dynamic = dynamic;
            break;
        case 12:
            GMSD_SETSTR(facility, str);
            break;
        case 13:
            GMSD_SETSTR(city, str);
            break;
        case 14:
            GMSD_SETSTR(state, str);
            break;
        case 15:
            GMSD_SETSTR(country, str);
            GMSD_SETSTR(cc, gt_get_icao_cc(str, wpt->shortname));
            break;
        case 16:
            parse_date_and_time(str, &wpt->creation_time);
            break;
        case 17:
            wpt->url = DUPSTR(str);
            break;
        case 18:
            GMSD_SET(category, parse_categories(str));
            break;
        default:
            break;
        }
    }
    waypt_add(wpt);
}