Skip to content

Commit

Permalink
Merge pull request #105 from colinkiama/zero-startup-option
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu authored Oct 21, 2024
2 parents 5e5e455 + 0e4faae commit ad1726a
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 279 deletions.
5 changes: 5 additions & 0 deletions data/com.github.subhadeepjasu.pebbles.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,10 @@
<summary>Saved history</summary>
<description>History Table saved in csv format</description>
</key>
<key name="load-last-session" type="b">
<default>true</default>
<summary>Load Last Session on Startup</summary>
<description>Load last values from previous session on startup</description>
</key>
</schema>
</schemalist>
54 changes: 35 additions & 19 deletions src/PreferencesOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* 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
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Subhadeep Jasu <[email protected]>
* Saunak Biswas <[email protected]>
*/


namespace Pebbles {
namespace Pebbles {
public class PreferencesOverlay : Gtk.Window {
Pebbles.Settings settings;
Gtk.SpinButton precision_entry;
Expand All @@ -29,15 +29,24 @@ namespace Pebbles {
Gtk.ComboBoxText constants_select_1;
Gtk.ComboBoxText constants_select_2;
Gtk.Scale accuracy_scale;
Gtk.Switch load_last_session_switch;

public signal void update_settings ();

public PreferencesOverlay () {
settings = Pebbles.Settings.get_default ();

var scrolled_window = new Gtk.ScrolledWindow (null, null);

var main_grid = new Gtk.Grid ();
main_grid.halign = Gtk.Align.CENTER;
main_grid.row_spacing = 8;


var load_last_session_label = new Gtk.Label (_("Load Last Session on Startup:"));
load_last_session_label.halign = Gtk.Align.START;
load_last_session_label.get_style_context ().add_class ("h4");
load_last_session_switch = new Gtk.Switch ();
load_last_session_switch.halign = Gtk.Align.START;

var precision_label = new Gtk.Label (_("Number of decimal places:"));
precision_label.get_style_context ().add_class ("h4");
Expand Down Expand Up @@ -95,15 +104,17 @@ namespace Pebbles {
return false;
});

main_grid.attach (precision_label, 0, 0, 1, 1);
main_grid.attach (precision_entry, 0, 1, 1, 1);
main_grid.attach (accuracy_label, 0, 2, 1, 1);
main_grid.attach (accuracy_scale, 0, 3, 1, 1);
main_grid.attach (constant_button_label, 0, 4, 1, 1);
main_grid.attach (constant_label1, 0, 5, 1, 1);
main_grid.attach (constants_select_1, 0, 6, 1, 1);
main_grid.attach (constant_label2, 0, 7, 1, 1);
main_grid.attach (constants_select_2, 0, 8, 1, 1);
main_grid.attach (load_last_session_label, 0, 0, 1, 1);
main_grid.attach (load_last_session_switch, 0, 1, 1,1);
main_grid.attach (precision_label, 0, 2, 1, 1);
main_grid.attach (precision_entry, 0, 3, 1, 1);
main_grid.attach (accuracy_label, 0, 4, 1, 1);
main_grid.attach (accuracy_scale, 0, 5, 1, 1);
main_grid.attach (constant_button_label, 0, 6, 1, 1);
main_grid.attach (constant_label1, 0, 7, 1, 1);
main_grid.attach (constants_select_1, 0, 8, 1, 1);
main_grid.attach (constant_label2, 0, 9, 1, 1);
main_grid.attach (constants_select_2, 0, 10, 1, 1);

var forex_label = new Gtk.Label (_("Currency Converter API Key"));
forex_label.halign = Gtk.Align.START;
Expand All @@ -113,13 +124,15 @@ namespace Pebbles {
forex_api_key.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY,"edit-undo-symbolic");
forex_api_key.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, _("Reset"));
forex_api_key.placeholder_text = "03eb97e97cbf3fa3e228";

main_grid.attach (forex_label, 0, 9, 1, 1);
main_grid.attach (forex_api_key, 0, 10, 1, 1);
main_grid.attach (forex_api_link, 0, 11, 1, 1);

this.add (main_grid);
main_grid.margin_bottom = 8;
main_grid.attach (forex_label, 0, 11, 1, 1);
main_grid.attach (forex_api_key, 0, 12, 1, 1);
main_grid.attach (forex_api_link, 0, 13, 1, 1);

scrolled_window.add (main_grid);

this.add (scrolled_window);
main_grid.margin_bottom = 16;

var headerbar = new Gtk.HeaderBar ();
headerbar.has_subtitle = false;
Expand All @@ -145,6 +158,7 @@ namespace Pebbles {
}

private void save_settings () {
settings.load_last_session = load_last_session_switch.get_active ();
if (precision_entry.get_value_as_int () != 0) {
settings.decimal_places = precision_entry.get_value_as_int ();
}
Expand All @@ -155,12 +169,13 @@ namespace Pebbles {
settings.forex_api_key = forex_api_key.get_text ();
else
settings.forex_api_key = "03eb97e97cbf3fa3e228";

settings.integration_accuracy = (int)(accuracy_scale.get_value ());
this.update_settings ();
}

private void load_settings () {
load_last_session_switch.set_active (settings.load_last_session);
precision_entry.set_value ((double)settings.decimal_places);
load_constant_button_settings ();
forex_api_key.set_text (settings.forex_api_key);
Expand Down Expand Up @@ -240,6 +255,7 @@ namespace Pebbles {
}
return false;
});

this.forex_api_key.icon_release.connect ((pos, event) => {
settings.forex_api_key = "03eb97e97cbf3fa3e228";
this.forex_api_key.set_text ("03eb97e97cbf3fa3e228");
Expand Down
11 changes: 6 additions & 5 deletions src/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* 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
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Subhadeep Jasu <[email protected]>
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace Pebbles {
public int integration_accuracy {get; set;}
public string sci_input_text {get; set;}
public string sci_output_text {get; set;}
public string sci_memory_value {get; set;}
public string sci_memory_value {get; set;}
public string prog_input_text {get; set;}
public string prog_output_text {get; set;}
public string cal_input_text {get; set;}
Expand Down Expand Up @@ -132,11 +132,12 @@ namespace Pebbles {
public string date_year_entry {get; set;}
public string forex_api_key {get; set;}
public string saved_history {get; set;}

public bool load_last_session {get; set;}

private Settings () {
base ("com.github.subhadeepjasu.pebbles");
}

public void switch_angle_unit () {
switch (settings.global_angle_unit) {
case GlobalAngleUnit.RAD:
Expand All @@ -150,7 +151,7 @@ namespace Pebbles {
break;
}
}

public void switch_word_length () {
switch (settings.global_word_length) {
case GlobalWordLength.DWD:
Expand Down
24 changes: 12 additions & 12 deletions src/Views/ConvAngleView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* 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
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Subhadeep Jasu <[email protected]>
Expand Down Expand Up @@ -57,17 +57,17 @@ namespace Pebbles {

conv = new Converter (unit_multipliers);
keypad = new CommonKeyPadConverter ();

// Make Header Label
var header_title = new Gtk.Label (_("Angle"));
header_title.get_style_context ().add_class ("h2");
header_title.set_justify (Gtk.Justification.LEFT);
header_title.halign = Gtk.Align.START;
header_title.margin_start = 8;

// Make Upper Unit Box
from_entry = new Gtk.Entry ();
from_entry.set_text (settings.conv_angle_from_entry);
from_entry.set_text (settings.load_last_session ? settings.conv_angle_from_entry : "0");
from_entry.get_style_context ().add_class ("Pebbles_Conversion_Text_Box");
from_entry.max_width_chars = 35;
from_unit = new Gtk.ComboBoxText ();
Expand All @@ -78,15 +78,15 @@ namespace Pebbles {

// Make Lower Unit Box
to_entry = new Gtk.Entry ();
to_entry.set_text (settings.conv_angle_to_entry);
to_entry.set_text (settings.load_last_session ? settings.conv_angle_to_entry : "0");
to_entry.get_style_context ().add_class ("Pebbles_Conversion_Text_Box");
to_entry.max_width_chars = 35;
to_unit = new Gtk.ComboBoxText ();
for (int i = 0; i < units.length; i++) {
to_unit.append_text (units [i]);
}
to_unit.active = 1;

// Create Conversion active section
interchange_button = new Gtk.Button ();
var up_button = new Gtk.Image.from_icon_name ("go-up-symbolic", Gtk.IconSize.BUTTON);
Expand All @@ -101,7 +101,7 @@ namespace Pebbles {
interchange_button.margin_bottom = 8;
interchange_button.margin_start = 100;
interchange_button.margin_end = 100;

Gtk.Grid conversion_grid = new Gtk.Grid ();
conversion_grid.attach (from_unit, 0, 0, 1, 1);
conversion_grid.attach (from_entry, 0, 1, 1, 1);
Expand All @@ -116,12 +116,12 @@ namespace Pebbles {
conversion_grid.margin_end = 8;
conversion_grid.valign = Gtk.Align.CENTER;
conversion_grid.row_spacing = 8;

ResponsiveBox wrapbox = new ResponsiveBox (8);
wrapbox.margin_bottom = 8;
wrapbox.pack_end (keypad, true, true, 0);
wrapbox.pack_start (conversion_grid, true, true, 0);

halign = Gtk.Align.FILL;
valign = Gtk.Align.CENTER;
attach (header_title, 0, 0, 1, 1);
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace Pebbles {
interchange_button.clicked.connect (() => {
interchange_entries ();
});

keypad.button_clicked.connect ((val) => {
if (from_to == 0) {
if (val == "C") {
Expand Down Expand Up @@ -280,7 +280,7 @@ namespace Pebbles {

public void grab_focus_on_view_switch () {
switch (from_to) {
case 0:
case 0:
this.from_entry.grab_focus_without_selecting ();
break;
case 1:
Expand All @@ -302,7 +302,7 @@ namespace Pebbles {
} else {
string last_answer = from_entry.get_text().replace(Utils.get_local_separator_symbol(), "");
clipboard.set_text (last_answer, -1);
}
}
}
}
}
26 changes: 13 additions & 13 deletions src/Views/ConvAreaView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* 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
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Subhadeep Jasu <[email protected]>
Expand Down Expand Up @@ -65,17 +65,17 @@ namespace Pebbles {

conv = new Converter (unit_multipliers);
keypad = new CommonKeyPadConverter ();

// Make Header Label
var header_title = new Gtk.Label (_("Area"));
header_title.get_style_context ().add_class ("h2");
header_title.set_justify (Gtk.Justification.LEFT);
header_title.halign = Gtk.Align.START;
header_title.margin_start = 8;

// Make Upper Unit Box
from_entry = new Gtk.Entry ();
from_entry.set_text (settings.conv_area_from_entry);
from_entry.set_text (settings.load_last_session ? settings.conv_area_from_entry : "0");
from_entry.get_style_context ().add_class ("Pebbles_Conversion_Text_Box");
from_entry.max_width_chars = 35;
from_unit = new Gtk.ComboBoxText ();
Expand All @@ -86,15 +86,15 @@ namespace Pebbles {

// Make Lower Unit Box
to_entry = new Gtk.Entry ();
to_entry.set_text (settings.conv_area_to_entry);
to_entry.set_text (settings.load_last_session ? settings.conv_area_to_entry : "0");
to_entry.get_style_context ().add_class ("Pebbles_Conversion_Text_Box");
to_entry.max_width_chars = 35;
to_unit = new Gtk.ComboBoxText ();
for (int i = 0; i < units.length; i++) {
to_unit.append_text (units [i]);
}
to_unit.active = 1;

// Create Conversion active section
interchange_button = new Gtk.Button ();
var up_button = new Gtk.Image.from_icon_name ("go-up-symbolic", Gtk.IconSize.BUTTON);
Expand All @@ -109,7 +109,7 @@ namespace Pebbles {
interchange_button.margin_bottom = 8;
interchange_button.margin_start = 100;
interchange_button.margin_end = 100;

Gtk.Grid conversion_grid = new Gtk.Grid ();
conversion_grid.attach (from_unit, 0, 0, 1, 1);
conversion_grid.attach (from_entry, 0, 1, 1, 1);
Expand All @@ -124,12 +124,12 @@ namespace Pebbles {
conversion_grid.margin_end = 8;
conversion_grid.valign = Gtk.Align.CENTER;
conversion_grid.row_spacing = 8;

ResponsiveBox wrapbox = new ResponsiveBox (8);
wrapbox.margin_bottom = 8;
wrapbox.pack_end (keypad, true, true, 0);
wrapbox.pack_start (conversion_grid, true, true, 0);

halign = Gtk.Align.FILL;
valign = Gtk.Align.CENTER;
attach (header_title, 0, 0, 1, 1);
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace Pebbles {
to_entry.set_text (result);
allow_change = true;
});

keypad.button_clicked.connect ((val) => {
if (from_to == 0) {
if (val == "C") {
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace Pebbles {

public void grab_focus_on_view_switch () {
switch (from_to) {
case 0:
case 0:
this.from_entry.grab_focus_without_selecting ();
break;
case 1:
Expand All @@ -307,7 +307,7 @@ namespace Pebbles {
settings.conv_area_from_entry = from_entry.get_text ();
settings.conv_area_to_entry = to_entry.get_text ();
}

public void write_answer_to_clipboard () {
Gdk.Display display = this.get_display ();
Gtk.Clipboard clipboard = Gtk.Clipboard.get_for_display (display, Gdk.SELECTION_CLIPBOARD);
Expand All @@ -317,7 +317,7 @@ namespace Pebbles {
} else {
string last_answer = from_entry.get_text().replace(Utils.get_local_separator_symbol(), "");
clipboard.set_text (last_answer, -1);
}
}
}
}
}
Loading

0 comments on commit ad1726a

Please sign in to comment.