Skip to content

Commit

Permalink
Bind preferences dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu committed Jan 12, 2025
1 parent 8068b9b commit 19b1ec7
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 7 deletions.
17 changes: 17 additions & 0 deletions data/com.github.subhadeepjasu.pebbles.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,22 @@
<summary>Choose Constant 2</summary>
<description>Choose constant value for the button when shift is ON.</description>
</key>
<key name="decimal-places" type="u">
<range min="0" max="10"/>
<default>7</default>
<summary>Number of decimal places after radix</summary>
<description>Number of decimal places after radix point.</description>
</key>
<key name="integration-resolution" type="u">
<range min="500" max="100000"/>
<default>10000</default>
<summary>Accuracy of integratal caculus evaluation</summary>
<description>Number of cycles of Simpson's 3/8 evaluation</description>
</key>
<key name="forex-api-key" type="s">
<default>""</default>
<summary>Currency Converter API key</summary>
<description>Get your own API key from https://free.currencyconverterapi.com/</description>
</key>
</schema>
</schemalist>
24 changes: 17 additions & 7 deletions data/ui/preferences_dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
subtitle: _("Load last session on startup");
focus-on-click: false;
focusable: false;
active: bind template.settings as <$PebblesSettings>.load_last_session;
notify::active => $load_session_notify_active_cb();
}

Adw.ActionRow float_accuracy {
title: _("Precision");
subtitle: _("Number of decimal places");
Adw.ActionRow decimal_places {
title: _("Decimal Places");
subtitle: _("Number of decimal places afte radix symbol");
focus-on-click: false;
focusable: false;

Expand All @@ -32,6 +34,8 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
focus-on-click: false;
focusable: false;
can-focus: false;
value: bind template.settings as <$PebblesSettings>.decimal_places;
notify::value => $precision_notify_active_cb();
}
}

Expand All @@ -48,6 +52,8 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
model: bind template.constant_button_model;
focus-on-click: false;
focusable: false;
selected: bind template.settings as <$PebblesSettings>.constant_key_value1 as <$PebblesConstantKeyIndex>;
notify::selected => $constant_button_1_cb();
}

Adw.ComboRow constants_select_2 {
Expand All @@ -56,6 +62,8 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
model: bind template.constant_button_model;
focus-on-click: false;
focusable: false;
selected: bind template.settings as <$PebblesSettings>.constant_key_value2 as <$PebblesConstantKeyIndex>;
notify::selected => $constant_button_2_cb();
}
}
}
Expand All @@ -70,12 +78,12 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
focus-on-click: false;
focusable: false;

Scale {
Scale integration_resolution_scale {
width-request: 200;
adjustment: Adjustment {
lower: 0;
upper: 9;
step-increment: 1;
lower: 500;
upper: 100000;
step-increment: 100;
};
focus-on-click: false;
focusable: false;
Expand All @@ -91,6 +99,8 @@ template $PebblesPreferencesDialog: Adw.PreferencesDialog {
title: _("Currency Converter API Key");
focus-on-click: false;
focusable: false;
text: bind template.settings as <$PebblesSettings>.forex_api_key;
notify::text => $forex_api_key_cb();
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,25 @@ namespace Pebbles {
get { return get_enum ("constant-key-value2"); }
set { set_enum ("constant-key-value2", value); }
}

public uint decimal_places {
get { return get_uint ("decimal-places"); }
set { set_uint ("decimal-places", value); }
}

public bool use_exponential_form {
get { return get_boolean ("use-exponential-form"); }
set { set_boolean ("use-exponential-form", value); }
}

public uint integration_resolution {
get { return get_uint ("integration-resolution"); }
set { set_uint ("integration-resolution", value); }
}

public string forex_api_key {
owned get { return get_string ("forex-api-key"); }
set { set_string ("forex-api-key", value); }
}
}
}
83 changes: 83 additions & 0 deletions src/shell/dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ namespace Pebbles {
protected Gtk.StringList constant_button_model { get; private set; }
protected List<string> constants_list;

// Settings
public Pebbles.Settings settings { get; set construct; }

[GtkChild]
private Adw.ComboRow constants_select_1;
[GtkChild]
private Adw.ComboRow constants_select_2;
[GtkChild]
private unowned Gtk.Scale integration_resolution_scale;

private bool loaded = false;

construct {
settings = Pebbles.Settings.get_default ();

// TRANSLATORS: The left quotation mark symbol
var laquo = _("");
// TRANSLATORS: The right quotation mark symbol
Expand All @@ -27,6 +41,75 @@ namespace Pebbles {
}

constant_button_model = new Gtk.StringList (constants_array);

realize.connect (load_settings);
closed.connect (() => {
loaded = false;
});
}

[GtkCallback]
protected void load_session_notify_active_cb (Object obj, ParamSpec params) {
settings.load_last_session = (obj as Adw.SwitchRow)?.active;
}

[GtkCallback]
protected void precision_notify_active_cb (Object obj, ParamSpec params) {
settings.decimal_places = (uint) ((obj as Gtk.SpinButton)?.value);
}

[GtkCallback]
protected void forex_api_key_cb (Object obj, ParamSpec params) {
settings.forex_api_key = (obj as Adw.EntryRow)?.text;
}

[GtkCallback]
protected void constant_button_1_cb (Object obj, ParamSpec params) {
if (loaded)
settings.constant_key_value1 = uint_to_constant_key ((obj as Adw.ComboRow)?.selected);
}

[GtkCallback]
protected void constant_button_2_cb (Object obj, ParamSpec params) {
if (loaded)
settings.constant_key_value2 = uint_to_constant_key ((obj as Adw.ComboRow)?.selected);
}

private ConstantKeyIndex uint_to_constant_key (uint index) {
switch (index) {
case 0:
default:
return EULER;
case 1:
return ARCHIMEDES;
case 2:
return GOLDEN_RATIO;
case 3:
return IMAGINARY;
case 4:
return EULER_MASCH;
case 5:
return CONWAY;
case 6:
return KHINCHIN;
case 7:
return FEIGEN_ALPHA;
case 8:
return FEIGEN_DELTA;
case 9:
return APERY;

}

}

private void load_settings () {
Idle.add (() => {
integration_resolution_scale.set_value (settings.integration_resolution);
loaded = true;
return false;
});

}
}
}
5 changes: 5 additions & 0 deletions src/shell/views/ScientificView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ namespace Pebbles {
construct {
display.on_input.connect (evaluate);
load_constant_button ();
Settings.get_default ().changed.connect ((key) => {
if (key == "constant-key-value1" || key == "constant-key-value2") {
load_constant_button ();
}
});
}

[GtkCallback]
Expand Down

0 comments on commit 19b1ec7

Please sign in to comment.