Verified Commit 2104c569 authored by Alexander Downey's avatar Alexander Downey Committed by Zander Brown
Browse files

prefrences: add language selector

parent 8221cdbe
Pipeline #178778 passed with stage
in 54 minutes and 49 seconds
......@@ -20,9 +20,22 @@
#include "app_procs.h"
#include "interface.h"
#include "persistence.h"
int main(int argc, char *argv[])
{
char *lang;
char *val;
persistence_load();
lang = persistence_register_string ("lang_lang", "");
val = getenv ("LANG");
if (val == NULL || lang != NULL && lang[0] != NULL && strcmp(val, lang) != 0) {
#ifdef G_OS_WIN32
_putenv_s("LANG", lang);
#else
setenv("LANG", lang, 1);
#endif
}
app_init(argc, argv);
if (!app_is_interactive())
......
......@@ -65,6 +65,83 @@ struct _DiaPreferencesDialog {
G_DEFINE_TYPE (DiaPreferencesDialog, dia_preferences_dialog, GTK_TYPE_DIALOG)
static const char *langs[] = {
"en_US",
"am",
"ar",
"ast",
"az",
"be",
"bg",
"bs",
"ca",
"ca@valencia",
"cs",
"da",
"de",
"dz",
"el",
"en_CA",
"en_GB",
"eo",
"es",
"eu",
"fa",
"fi",
"fr",
"ga",
"gl",
"gu",
"he",
"hr",
"hu",
"id",
"is",
"it",
"ja",
"kk",
"kn",
"ko",
"lt",
"lv",
"mk",
"ml",
"mn",
"mr",
"ms",
"nb",
"ne",
"nl",
"nn",
"oc",
"pa",
"pl",
"pt",
"pt_BR",
"ro",
"ru",
"rw",
"sk",
"sl",
"sq",
"sr",
"sr@latin",
"sv",
"th",
"tr",
"uk",
"vi",
"zh_CN",
"zh_HK",
"zh_TW",
NULL
};
static const char * dia_lang_get_name(int i) {
return langs[i];
}
static void
dia_preferences_dialog_response (GtkDialog *dialog, int response)
{
......@@ -279,6 +356,26 @@ dd_type_changed (GtkComboBox *combo,
}
}
static void
lang_changed (GtkComboBox *combo,
gpointer data)
{
GtkTreeIter iter;
GtkTreeModel *model;
char *lang;
model = gtk_combo_box_get_model (combo);
if (gtk_combo_box_get_active_iter (combo, &iter)) {
gtk_tree_model_get (model, &iter, COL_NAME, &lang, -1);
g_clear_pointer (&prefs.lang.lang, g_free);
prefs.lang.lang = lang;
persistence_set_string ("lang_lang", lang);
}
}
static void
dd_background_changed (DiaColorSelector *selector,
......@@ -348,6 +445,40 @@ set_current_paper (GtkTreeModel *model,
}
struct SetCurrentLang {
const char *to_set;
GtkWidget *combo;
};
static gboolean
set_current_lang (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
{
struct SetCurrentLang *find = data;
char *lang;
gtk_tree_model_get (model, iter, COL_NAME, &lang, -1);
if (g_strcmp0 (lang, find->to_set) == 0) {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(find->combo), iter);
g_clear_pointer (&lang, g_free);
return TRUE;
}
g_clear_pointer (&lang, g_free);
return FALSE;
}
static void
vd_width_value_changed (GtkSpinButton *spin,
gpointer data)
......@@ -709,6 +840,7 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
struct SetCurrentUnit find_unit;
struct SetCurrentPaper find_paper;
struct SetCurrentFilter find_filter;
struct SetCurrentLang find_lang;
GtkWidget *dialog_vbox;
DiaBuilder *builder;
GtkWidget *content;
......@@ -719,6 +851,7 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
GtkListStore *pss;
GtkListStore *wmfs;
GtkListStore *emfs;
GtkListStore *langStore;
GtkWidget *ui_reset_tools;
GtkAdjustment *ui_undo_spin_adj;
GtkWidget *ui_reverse_drag;
......@@ -758,9 +891,9 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
GtkAdjustment *gl_man_cvs_adj;
GtkAdjustment *gl_man_rvs_adj;
GtkAdjustment *gl_hex_size_adj;
GtkWidget *cbLanguages;
int j = 0;
const char *name;
gtk_dialog_add_buttons (GTK_DIALOG (self),
_("_Done"), GTK_RESPONSE_OK,
NULL);
......@@ -831,8 +964,9 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
"gl_hex", &self->gl_hex,
"gl_hex_size", &self->gl_hex_size,
"gl_hex_size_adj", &gl_hex_size_adj,
"cbLanguages", &cbLanguages,
"langStore", &langStore,
NULL);
for (DiaUnit unit = 0; unit < DIA_LAST_UNIT; unit++) {
GtkTreeIter iter;
......@@ -855,6 +989,22 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
j++;
}
j = 0;
while ((name = dia_lang_get_name (j))) {
GtkTreeIter iter;
gtk_list_store_append (langStore, &iter);
gtk_list_store_set (langStore, &iter,
COL_NAME, name,
COL_UNIT, j,
-1);
j++;
}
fill_exporter_list (pngs, "PNG");
fill_exporter_list (svgs, "SVG");
fill_exporter_list (pss, "PS");
......@@ -888,6 +1038,14 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
gtk_tree_model_foreach (GTK_TREE_MODEL (paper),
set_current_paper,
&find_paper);
find_lang.combo = cbLanguages;
find_lang.to_set = prefs.lang.lang;
gtk_tree_model_foreach (GTK_TREE_MODEL (langStore),
set_current_lang,
&find_lang);
dia_color_selector_set_color (dd_background, &prefs.new_diagram.bg_color);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dd_compress),
prefs.new_diagram.compress_save);
......@@ -1014,6 +1172,8 @@ dia_preferences_dialog_init (DiaPreferencesDialog *self)
"gl_man_rvs_value_changed", G_CALLBACK (gl_man_rvs_value_changed),
"gl_hex_size_value_changed", G_CALLBACK (gl_hex_size_value_changed),
"gl_update_sensitive", G_CALLBACK (gl_update_sensitive),
/* Languages */
"lang_changed", G_CALLBACK (lang_changed),
NULL);
gtk_container_add (GTK_CONTAINER (dialog_vbox), content);
......@@ -1044,6 +1204,7 @@ dia_preferences_dialog_show (void)
void
dia_preferences_init (void)
{
char* val;
GEnumClass *unit_class = g_type_class_ref (DIA_TYPE_UNIT);
Color default_bg = { 1.0, 1.0, 1.0, 1.0 };
Color break_bg = { 0.0, 0.0, 0.6, 1.0 };
......@@ -1096,4 +1257,14 @@ dia_preferences_init (void)
prefs.grid.vis_y = persistence_register_real ("grid_vis_y", 1);
prefs.grid.hex = persistence_register_boolean ("grid_hex", FALSE);
prefs.grid.hex_size = persistence_register_real ("grid_hex_size", 1);
prefs.lang.lang = persistence_register_string ("lang_lang", dia_lang_get_name(0));
val = getenv ("LANG");
if (val == NULL || strcmp(val, prefs.lang.lang) != 0) {
#ifdef G_OS_WIN32
_putenv_s("LANG", prefs.lang.lang);
#else
setenv("LANG", prefs.lang.lang, 1);
#endif
}
}
......@@ -79,6 +79,9 @@ struct DiaPreferences {
int guides_visible; /** Whether guides are visible. */
int guides_snap; /** Whether to snap to guides. */
guint snap_distance; /** The snapping distance for guides. */
struct {
char *lang;
} lang;
};
extern struct DiaPreferences prefs;
......
......@@ -46,6 +46,14 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkListStore" id="langStore">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name language -->
<column type="gint"/>
</columns>
</object>
<object class="GtkListStore" id="paper">
<columns>
<!-- column-name name -->
......@@ -1586,6 +1594,69 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTable" id="table7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_columns">2</property>
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Languages</property>
</object>
<packing>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="cbLanguages">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">langStore</property>
<signal name="changed" handler="lang_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext9"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">5</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Languages</property>
</object>
<packing>
<property name="position">5</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<object class="GtkSizeGroup" id="sizegroup1">
<property name="mode">both</property>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment