~ubuntu-branches/ubuntu/oneiric/gnome-control-center/oneiric

« back to all changes in this revision

Viewing changes to panels/common/gdm-languages.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya, Rodrigo Moya, Gunnar Hjalmarsson
  • Date: 2011-08-30 12:24:44 UTC
  • mfrom: (1.1.50 upstream)
  • Revision ID: package-import@ubuntu.com-20110830122444-bmvakubeof8hgbhe
Tags: 1:3.1.90-0ubuntu1
[ Rodrigo Moya ]
* New upstream release
* debian/patches/03_dont_show_region_panel_in_unity.patch:
  - Remove upstreamed patch
* debian/patches/04_add_theme_selection.patch:
  - Set the metacity theme also

[ Gunnar Hjalmarsson ]
* debian/patches/52_ubuntu_language_list_mods.patch:
  - Change the list of options, when setting language from User
    Accounts, to items representing available translations, and with
    that make it similar to the language list in language-selector.
  - Make items representing language @variants be displayed as such.
* debian/control.in:
  - accountsservice (>= 0.6.13-1ubuntu2) added to dependency list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
static GHashTable *gdm_languages_map;
64
64
static GHashTable *gdm_territories_map;
65
65
static GHashTable *gdm_available_locales_map;
 
66
static GHashTable *gdm_language_count_map;
 
67
static GHashTable *gdm_territory_count_map;
66
68
 
67
69
static char * construct_language_name (const char *language,
68
70
                                       const char *territory,
614
616
}
615
617
 
616
618
static void
 
619
count_languages_and_territories (void)
 
620
{
 
621
        gpointer value;
 
622
        GHashTableIter iter;
 
623
        gint count;
 
624
 
 
625
        gdm_language_count_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
626
        gdm_territory_count_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
627
 
 
628
        g_hash_table_iter_init (&iter, gdm_available_locales_map);
 
629
        while (g_hash_table_iter_next (&iter, NULL, &value)) {
 
630
                GdmLocale *locale;
 
631
 
 
632
                locale = (GdmLocale *) value;
 
633
 
 
634
                count = GPOINTER_TO_INT (g_hash_table_lookup (gdm_language_count_map, locale->language_code));
 
635
                count++;
 
636
                g_hash_table_insert (gdm_language_count_map, g_strdup (locale->language_code), GINT_TO_POINTER (count));
 
637
 
 
638
                count = GPOINTER_TO_INT (g_hash_table_lookup (gdm_territory_count_map, locale->territory_code));
 
639
                count++;
 
640
                g_hash_table_insert (gdm_territory_count_map, g_strdup (locale->territory_code), GINT_TO_POINTER (count));
 
641
        }
 
642
}
 
643
 
 
644
static void
617
645
collect_locales (void)
618
646
{
619
647
 
631
659
                collect_locales_from_directory ();
632
660
        }
633
661
        collect_locales_from_locale_file (ALIASES_FILE);
 
662
 
 
663
        count_languages_and_territories ();
 
664
}
 
665
 
 
666
static gint
 
667
get_language_count (const char *language)
 
668
{
 
669
        if (gdm_language_count_map == NULL) {
 
670
                collect_locales ();
 
671
        }
 
672
 
 
673
        return GPOINTER_TO_INT (g_hash_table_lookup (gdm_language_count_map, language));
 
674
}
 
675
 
 
676
static gboolean
 
677
is_unique_language (const char *language)
 
678
{
 
679
  return get_language_count (language) == 1;
 
680
}
 
681
 
 
682
static gint
 
683
get_territory_count (const char *territory)
 
684
{
 
685
        if (gdm_territory_count_map == NULL) {
 
686
                collect_locales ();
 
687
        }
 
688
 
 
689
        return GPOINTER_TO_INT (g_hash_table_lookup (gdm_territory_count_map, territory));
 
690
}
 
691
 
 
692
static gboolean
 
693
is_unique_territory (const char *territory)
 
694
{
 
695
  return get_territory_count (territory) == 1;
634
696
}
635
697
 
636
698
static gboolean
1061
1123
        char *langinfo_codeset;
1062
1124
        char *translated_language;
1063
1125
        char *translated_territory;
 
1126
        char *modifier;
1064
1127
        gboolean is_utf8 = TRUE;
1065
1128
 
1066
1129
        g_return_val_if_fail (name != NULL, NULL);
1083
1146
        language_code = NULL;
1084
1147
        territory_code = NULL;
1085
1148
        codeset_code = NULL;
 
1149
        modifier = NULL;
1086
1150
 
1087
1151
        gdm_parse_language_name (name,
1088
1152
                                 &language_code,
1089
1153
                                 &territory_code,
1090
1154
                                 &codeset_code,
1091
 
                                 NULL);
 
1155
                                 &modifier);
1092
1156
 
1093
1157
        if (language_code == NULL) {
1094
1158
                goto out;
1101
1165
 
1102
1166
        full_language = g_string_append (full_language, translated_language);
1103
1167
 
 
1168
        if (is_unique_language (language_code)) {
 
1169
                goto out;
 
1170
        }
 
1171
 
1104
1172
        if (territory_code != NULL) {
1105
1173
                translated_territory = get_translated_territory (territory_code, locale);
1106
1174
        }
1122
1190
                                        codeset_code);
1123
1191
        }
1124
1192
 
 
1193
        if (modifier != NULL) {
 
1194
                g_string_append_printf (full_language, " - %s", modifier);
 
1195
        }
 
1196
 
1125
1197
out:
1126
1198
       g_free (language_code);
1127
1199
       g_free (territory_code);
1129
1201
       g_free (langinfo_codeset);
1130
1202
       g_free (translated_language);
1131
1203
       g_free (translated_territory);
 
1204
       g_free (modifier);
1132
1205
 
1133
1206
       if (full_language->len == 0) {
1134
1207
               g_string_free (full_language, TRUE);
1138
1211
       return g_string_free (full_language, FALSE);
1139
1212
}
1140
1213
 
 
1214
char *
 
1215
gdm_get_region_from_name (const char *name,
 
1216
                          const char *locale)
 
1217
{
 
1218
        GString *full_name;
 
1219
        char *language_code;
 
1220
        char *territory_code;
 
1221
        char *codeset_code;
 
1222
        char *langinfo_codeset;
 
1223
        char *translated_language;
 
1224
        char *translated_territory;
 
1225
        gboolean is_utf8 = TRUE;
 
1226
 
 
1227
        g_return_val_if_fail (name != NULL, NULL);
 
1228
        g_return_val_if_fail (*name != '\0', NULL);
 
1229
 
 
1230
        translated_territory = NULL;
 
1231
        translated_language = NULL;
 
1232
        langinfo_codeset = NULL;
 
1233
 
 
1234
        full_name = g_string_new (NULL);
 
1235
 
 
1236
        if (gdm_languages_map == NULL) {
 
1237
                languages_init ();
 
1238
        }
 
1239
 
 
1240
        if (gdm_territories_map == NULL) {
 
1241
                territories_init ();
 
1242
        }
 
1243
 
 
1244
        language_code = NULL;
 
1245
        territory_code = NULL;
 
1246
        codeset_code = NULL;
 
1247
 
 
1248
        gdm_parse_language_name (name,
 
1249
                                 &language_code,
 
1250
                                 &territory_code,
 
1251
                                 &codeset_code,
 
1252
                                 NULL);
 
1253
 
 
1254
        if (territory_code == NULL) {
 
1255
                goto out;
 
1256
        }
 
1257
 
 
1258
        translated_territory = get_translated_territory (territory_code, locale);
 
1259
        g_string_append (full_name, translated_territory);
 
1260
 
 
1261
        if (is_unique_territory (territory_code)) {
 
1262
                goto out;
 
1263
        }
 
1264
 
 
1265
        if (language_code != NULL) {
 
1266
                translated_language = get_translated_language (language_code, locale);
 
1267
        }
 
1268
        if (translated_language != NULL) {
 
1269
                g_string_append_printf (full_name,
 
1270
                                        " (%s)",
 
1271
                                        translated_language);
 
1272
        }
 
1273
 
 
1274
        language_name_get_codeset_details (name, &langinfo_codeset, &is_utf8);
 
1275
 
 
1276
        if (codeset_code == NULL && langinfo_codeset != NULL) {
 
1277
            codeset_code = g_strdup (langinfo_codeset);
 
1278
        }
 
1279
 
 
1280
        if (!is_utf8 && codeset_code) {
 
1281
                g_string_append_printf (full_name,
 
1282
                                        " [%s]",
 
1283
                                        codeset_code);
 
1284
        }
 
1285
 
 
1286
out:
 
1287
       g_free (language_code);
 
1288
       g_free (territory_code);
 
1289
       g_free (codeset_code);
 
1290
       g_free (langinfo_codeset);
 
1291
       g_free (translated_language);
 
1292
       g_free (translated_territory);
 
1293
 
 
1294
       if (full_name->len == 0) {
 
1295
               g_string_free (full_name, TRUE);
 
1296
               return NULL;
 
1297
       }
 
1298
 
 
1299
       return g_string_free (full_name, FALSE);
 
1300
}
 
1301
 
1141
1302
char **
1142
1303
gdm_get_all_language_names (void)
1143
1304
{