Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
1.2.8 - port to GLib.Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Jan 27, 2020
1 parent 862bc79 commit 48ab450
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 159 deletions.
8 changes: 8 additions & 0 deletions data/com.github.lainsce.coin.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release version="1.2.8" date="2020-01-30">
<description>
<p>Release: Greek Drachma</p>
<ul>
<li>Minor backend fixes.</li>
</ul>
</description>
</release>
<release version="1.2.7" date="2020-01-15">
<description>
<p>Release: Italian Lire</p>
Expand Down
3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Name our project
project('com.github.lainsce.coin', ['vala', 'c'],
version: '1.2.7'
version: '1.2.8'
)

# Import main lib files
Expand Down Expand Up @@ -44,7 +44,6 @@ executable(
meson.project_name(),
'src/Application.vala',
'src/MainWindow.vala',
'src/Constants/AppSettings.vala',
asresources,
c_args: c_args,
dependencies: [
Expand Down
5 changes: 5 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
namespace Coin {
public class Application : Granite.Application {
public MainWindow app_window;
public static GLib.Settings gsettings;

public Application () {
Object (flags: ApplicationFlags.FLAGS_NONE,
application_id: "com.github.lainsce.coin");
}

static construct {
gsettings = new GLib.Settings ("com.github.lainsce.coin");
}

construct {
exec_name = "com.github.lainsce.coin";
app_launcher = "com.github.lainsce.coin";
Expand Down
38 changes: 0 additions & 38 deletions src/Constants/AppSettings.vala

This file was deleted.

186 changes: 67 additions & 119 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ namespace Coin {
var titlebar = new Gtk.HeaderBar ();
titlebar.has_subtitle = false;
titlebar.show_close_button = true;


var titlebar_style_context = titlebar.get_style_context ();
titlebar_style_context.add_class (Gtk.STYLE_CLASS_FLAT);
titlebar_style_context.add_class ("default-decoration");
titlebar_style_context.add_class ("coin-toolbar");

this.set_titlebar (titlebar);

var settings = AppSettings.get_default ();
this.get_style_context ().add_class ("rounded");

var icon = new Gtk.Image.from_icon_name ("com.github.lainsce.coin-symbolic", Gtk.IconSize.DIALOG);
Expand All @@ -82,43 +77,7 @@ namespace Coin {
base_currency.append_text(_("S. African Rand"));
base_currency.margin = 6;

if (settings.coin == 0) {
base_currency.set_active(0);
coin_iso = "USD";
} else if (settings.coin == 1) {
base_currency.set_active(1);
coin_iso = "EUR";
} else if (settings.coin == 2) {
base_currency.set_active(2);
coin_iso = "GBP";
} else if (settings.coin == 3) {
base_currency.set_active(3);
coin_iso = "AUD";
} else if (settings.coin == 4) {
base_currency.set_active(4);
coin_iso = "BRL";
} else if (settings.coin == 5) {
base_currency.set_active(5);
coin_iso = "CAD";
} else if (settings.coin == 6) {
base_currency.set_active(6);
coin_iso = "CNY";
} else if (settings.coin == 7) {
base_currency.set_active(7);
coin_iso = "INR";
} else if (settings.coin == 8) {
base_currency.set_active(8);
coin_iso = "JPY";
} else if (settings.coin == 9) {
base_currency.set_active(9);
coin_iso = "RUB";
} else if (settings.coin == 10) {
base_currency.set_active(10);
coin_iso = "ZAR";
} else {
base_currency.set_active(0);
coin_iso = "USD";
}
base_currency.set_active(Coin.Application.gsettings.get_int("coin"));

base_vcurrency = new Gtk.ComboBoxText();
base_vcurrency.append_text("Bitcoin");
Expand All @@ -134,43 +93,7 @@ namespace Coin {
base_vcurrency.append_text("Tezos");
base_vcurrency.margin = 6;

if (settings.virtualcoin == 0) {
base_vcurrency.set_active(0);
vcoin_iso = "BTC";
} else if (settings.virtualcoin == 1) {
base_vcurrency.set_active(1);
vcoin_iso = "DASH";
} else if (settings.virtualcoin == 2) {
base_vcurrency.set_active(2);
vcoin_iso = "ETH";
} else if (settings.virtualcoin == 3) {
base_vcurrency.set_active(3);
vcoin_iso = "LTC";
} else if (settings.virtualcoin == 4) {
base_vcurrency.set_active(4);
vcoin_iso = "PPC";
} else if (settings.virtualcoin == 5) {
base_vcurrency.set_active(5);
vcoin_iso = "XRP";
} else if (settings.virtualcoin == 6) {
base_vcurrency.set_active(6);
vcoin_iso = "ZEC";
} else if (settings.virtualcoin == 7) {
base_vcurrency.set_active(7);
vcoin_iso = "XMR";
} else if (settings.virtualcoin == 8) {
base_vcurrency.set_active(8);
vcoin_iso = "BCH";
} else if (settings.virtualcoin == 9) {
base_vcurrency.set_active(9);
vcoin_iso = "ADA";
} else if (settings.virtualcoin == 10) {
base_vcurrency.set_active(10);
vcoin_iso = "XTZ";
} else {
base_vcurrency.set_active(0);
vcoin_iso = "BTC";
}
base_currency.set_active(Coin.Application.gsettings.get_int("virtualcoin"));

label_result = new Gtk.Label ("");
label_result.set_halign (Gtk.Align.END);
Expand Down Expand Up @@ -224,10 +147,12 @@ namespace Coin {
stack.margin_top = 0;
stack.homogeneous = true;
stack.add_named (grid, "money");

this.add (stack);
stack.show_all ();

get_values ();
set_labels ();

base_currency.changed.connect (() => {
get_values ();
set_labels ();
Expand Down Expand Up @@ -279,12 +204,12 @@ namespace Coin {
}
});

int x = settings.window_x;
int y = settings.window_y;
int x = Coin.Application.gsettings.get_int("window-x");
int y = Coin.Application.gsettings.get_int("window-y");
int coin = base_currency.get_active();
coin = settings.coin;
coin = Coin.Application.gsettings.get_int("coin");
int vcoin = base_vcurrency.get_active();
vcoin = settings.virtualcoin;
vcoin = Coin.Application.gsettings.get_int("virtualcoin");

if (x != -1 && y != -1) {
move (x, y);
Expand All @@ -303,39 +228,48 @@ namespace Coin {
int x, y;
get_position (out x, out y);

var settings = AppSettings.get_default ();
settings.window_x = x;
settings.window_y = y;
settings.coin = base_currency.get_active();
settings.virtualcoin = base_vcurrency.get_active();
Coin.Application.gsettings.set_int("window-x", x);
Coin.Application.gsettings.set_int("window-y", y);
Coin.Application.gsettings.set_int("coin", base_currency.get_active());
Coin.Application.gsettings.set_int("virtualcoin", base_vcurrency.get_active());

return false;
}

public bool get_values () {
var settings = AppSettings.get_default ();
settings.coin = base_currency.get_active();
if (settings.coin == 0) {
Coin.Application.gsettings.set_int("coin", base_currency.get_active());
if (Coin.Application.gsettings.get_int("coin") == 0) {
base_currency.set_active(0);
coin_iso = "USD";
} else if (settings.coin == 1) {
} else if (Coin.Application.gsettings.get_int("coin") == 1) {
base_currency.set_active(1);
coin_iso = "EUR";
} else if (settings.coin == 2) {
} else if (Coin.Application.gsettings.get_int("coin") == 2) {
base_currency.set_active(2);
coin_iso = "GBP";
} else if (settings.coin == 3) {
} else if (Coin.Application.gsettings.get_int("coin") == 3) {
base_currency.set_active(3);
coin_iso = "AUD";
} else if (settings.coin == 4) {
} else if (Coin.Application.gsettings.get_int("coin") == 4) {
base_currency.set_active(4);
coin_iso = "BRL";
} else if (settings.coin == 5) {
} else if (Coin.Application.gsettings.get_int("coin") == 5) {
base_currency.set_active(5);
coin_iso = "CAD";
} else if (settings.coin == 6) {
} else if (Coin.Application.gsettings.get_int("coin") == 6) {
base_currency.set_active(6);
coin_iso = "CNY";
} else if (settings.coin == 7) {
} else if (Coin.Application.gsettings.get_int("coin") == 7) {
base_currency.set_active(7);
coin_iso = "INR";
} else if (settings.coin == 8) {
} else if (Coin.Application.gsettings.get_int("coin") == 8) {
base_currency.set_active(8);
coin_iso = "JPY";
} else if (settings.coin == 9) {
} else if (Coin.Application.gsettings.get_int("coin") == 9) {
base_currency.set_active(9);
coin_iso = "RUB";
} else if (settings.coin == 10) {
} else if (Coin.Application.gsettings.get_int("coin") == 10) {
base_currency.set_active(10);
coin_iso = "ZAR";
} else {
base_currency.set_active(0);
Expand All @@ -344,30 +278,45 @@ namespace Coin {

debug ("Chose %s".printf(coin_iso));

settings.virtualcoin = base_vcurrency.get_active();
if (settings.virtualcoin == 0) {
Coin.Application.gsettings.set_int("virtualcoin", base_vcurrency.get_active());
if (Coin.Application.gsettings.get_int("virtualcoin") == 0) {
base_vcurrency.set_active(0);
vcoin_iso = "BTC";
} else if (settings.virtualcoin == 1) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 1) {
base_vcurrency.set_active(1);
vcoin_iso = "DASH";
} else if (settings.virtualcoin == 2) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 2) {
base_vcurrency.set_active(2);
vcoin_iso = "ETH";
} else if (settings.virtualcoin == 3) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 3) {
base_vcurrency.set_active(3);
vcoin_iso = "LTC";
} else if (settings.virtualcoin == 4) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 4) {
base_vcurrency.set_active(4);
vcoin_iso = "PPC";
} else if (settings.virtualcoin == 5) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 5) {
base_vcurrency.set_active(5);
vcoin_iso = "XRP";
} else if (settings.virtualcoin == 6) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 6) {
base_vcurrency.set_active(6);
vcoin_iso = "ZEC";
} else if (settings.virtualcoin == 7) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 7) {
base_vcurrency.set_active(7);
vcoin_iso = "XMR";
} else if (settings.virtualcoin == 8) {
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 8) {
base_vcurrency.set_active(8);
vcoin_iso = "BCH";
} else if (settings.virtualcoin == 9){
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 9){
base_vcurrency.set_active(9);
vcoin_iso = "ADA";
} else if (settings.virtualcoin == 10){
} else if (Coin.Application.gsettings.get_int("virtualcoin") == 10){
base_vcurrency.set_active(10);
vcoin_iso = "XTZ";
} else {
base_vcurrency.set_active(0);
coin_iso = "BTC";
}

debug ("Chose %s".printf(vcoin_iso));

var uri = """https://min-api.cryptocompare.com/data/pricemultifull?fsyms=%s&tsyms=%s""".printf(vcoin_iso, coin_iso);
Expand All @@ -393,10 +342,9 @@ namespace Coin {
}

public void set_labels () {
var settings = AppSettings.get_default ();
var curr_symbol = "";
settings.coin = base_currency.get_active();
switch (settings.coin) {
Coin.Application.gsettings.set_int("coin", base_currency.get_active());
switch (Coin.Application.gsettings.get_int("coin")) {
case 4:
curr_symbol = "R$";
break;
Expand Down Expand Up @@ -430,8 +378,8 @@ namespace Coin {
}

var vcurr_symbol = "";
settings.virtualcoin = base_vcurrency.get_active();
switch (settings.virtualcoin) {
Coin.Application.gsettings.set_int("virtualcoin", base_vcurrency.get_active());
switch (Coin.Application.gsettings.get_int("virtualcoin")) {
case 0:
vcurr_symbol = "";
break;
Expand Down

0 comments on commit 48ab450

Please sign in to comment.