Skip to content

Commit

Permalink
fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain M committed Sep 17, 2019
1 parent 0e61b23 commit ba7d1b5
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 189 deletions.
11 changes: 2 additions & 9 deletions data/com.github.alainm23.byte.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
<enum id="com.github.alainm23.byte.theme">
<value nick="Byte" value="1" />
<value nick="Black" value="2" />
<value nick="Blueberry" value="3" />
<value nick="Turquoise" value="4" />
<value nick="Turquoise" value="3" />
</enum>

<schema path="/com/github/alainm23/byte/" id="com.github.alainm23.byte" gettext-domain="com.github.alainm23.byte">
Expand Down Expand Up @@ -108,13 +107,7 @@
<summary>Most recent window position (x, y)</summary>
<description>Most recent window position (x, y)</description>
</key>

<key name="dark-mode" type="b">
<default>false</default>
<summary>If the dark Gtk stylesheet should be used</summary>
<description>If the dark Gtk stylesheet should be used</description>
</key>


<key name="sync-files" type="b">
<default>true</default>
<summary>Look for new music files on start up.</summary>
Expand Down
53 changes: 7 additions & 46 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -108,57 +108,18 @@ public class Byte : Gtk.Application {
add_action (quit_action);
add_action (toggle_playing_action);
add_action (search_action);

// Default Icon Theme
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
default_theme.add_resource_path ("/com/github/alainm23/byte");


// Stylesheet
var provider = new Gtk.CssProvider ();
provider.load_from_resource ("/com/github/alainm23/byte/stylesheet.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.get_boolean ("dark-mode");

if (settings.get_boolean ("dark-mode")) {
var dark_mode_provider = new Gtk.CssProvider ();
var colored_css = """
@define-color colorPrimary %s;
@define-color textColorPrimary %s;
""".printf ("@base_color", "#fe2851");

try {
dark_mode_provider.load_from_data (colored_css, colored_css.length);

Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), dark_mode_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
return;
}
}

// Default Icon Theme
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
default_theme.add_resource_path ("/com/github/alainm23/byte");

if (Byte.settings.get_boolean ("dark-mode")) {
var provider_theme = new Gtk.CssProvider ();

var colored_css = """
@define-color colorPrimary %s;
@define-color textColorPrimary %s;
""";

colored_css = colored_css.printf (
"@base_color",
"@text_color"
);

try {
provider_theme.load_from_data (colored_css, colored_css.length);

Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider_theme, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
return;
}
} else {
Byte.utils.apply_theme (Byte.settings.get_enum ("theme"));
}

utils.apply_theme (Byte.settings.get_enum ("theme"));
}

public void toggle_playing_action_enabled (bool b) {
Expand Down
174 changes: 62 additions & 112 deletions src/Dialogs/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ public class Dialogs.Settings : Gtk.Dialog {
general_label.margin_start = 6;

/*
Dark Mode
*/

Dark Mode
var settings_01_icon = new Gtk.Image ();
settings_01_icon.gicon = new ThemedIcon ("weather-clear-night-symbolic");
settings_01_icon.pixel_size = 16;
settings_01_icon.get_style_context ().add_class ("settings-icon");
settings_01_icon.valign = Gtk.Align.CENTER;
var settings_01_label = new Gtk.Label (_("Dark mode"));
//settings_01_label.get_style_context ().add_class ("h3");
settings_01_label.get_style_context ().add_class ("h3");
var settings_01_switch = new Gtk.Switch ();
settings_01_switch.get_style_context ().add_class ("active-switch");
Expand All @@ -52,14 +51,70 @@ public class Dialogs.Settings : Gtk.Dialog {
var gtk_settings = Gtk.Settings.get_default ();
settings_01_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme");
Byte.settings.bind ("dark-mode", settings_01_switch, "active", GLib.SettingsBindFlags.DEFAULT);

var settings_01_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
settings_01_box.hexpand = true;
settings_01_box.margin = 6;
settings_01_box.pack_start (settings_01_icon, false, false, 0);
settings_01_box.pack_start (settings_01_label, false, false, 6);
settings_01_box.pack_end (settings_01_switch, false, false, 0);
/*
Theme
*/

var settings_01_icon = new Gtk.Image ();
settings_01_icon.gicon = new ThemedIcon ("applications-graphics-symbolic");
settings_01_icon.pixel_size = 16;
settings_01_icon.get_style_context ().add_class ("settings-icon");
settings_01_icon.valign = Gtk.Align.CENTER;

var settings_01_label = new Gtk.Label (_("Theme"));

var theme_01 = new Gtk.RadioButton (null);
theme_01.valign = Gtk.Align.START;
theme_01.halign = Gtk.Align.START;
theme_01.tooltip_text = _("Byte");
apply_styles ("01", "#fe2851", theme_01);

var theme_02 = new Gtk.RadioButton.from_widget (theme_01);
theme_02.valign = Gtk.Align.START;
theme_02.halign = Gtk.Align.START;
theme_02.tooltip_text = _("Black");
apply_styles ("02", "#333333", theme_02);

var theme_03 = new Gtk.RadioButton.from_widget (theme_01);
theme_03.valign = Gtk.Align.START;
theme_03.halign = Gtk.Align.START;
theme_03.tooltip_text = _("Turquoise");
apply_styles ("04", "#36E683", theme_03);

var theme_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
theme_box.pack_start (theme_01, false, false, 6);
theme_box.pack_start (theme_02, false, false, 6);
theme_box.pack_start (theme_03, false, false, 6);

// I think switch most better here (redian23)
switch (Byte.settings.get_enum ("theme")) {
case 1 :
theme_01.active = true;
break;
case 2 :
theme_02.active = true;
break;
case 3 :
theme_03.active = true;
break;
}

var settings_01_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
settings_01_box.hexpand = true;
settings_01_box.margin = 6;
settings_01_box.margin_end = 0;
settings_01_box.pack_start (settings_01_icon, false, false, 0);
settings_01_box.pack_start (settings_01_label, false, false, 6);
settings_01_box.pack_end (theme_box, false, false, 0);

/*
Notifications
*/
Expand Down Expand Up @@ -108,72 +163,6 @@ public class Dialogs.Settings : Gtk.Dialog {
settings_03_box.pack_start (settings_03_label, false, false, 6);
settings_03_box.pack_end (settings_03_switch, false, false, 0);

/*
Theme
*/

var settings_09_icon = new Gtk.Image ();
settings_09_icon.gicon = new ThemedIcon ("applications-graphics-symbolic");
settings_09_icon.pixel_size = 16;
settings_09_icon.get_style_context ().add_class ("settings-icon");
settings_09_icon.valign = Gtk.Align.CENTER;

var settings_09_label = new Gtk.Label (_("Theme"));

var theme_01 = new Gtk.RadioButton (null);
theme_01.valign = Gtk.Align.START;
theme_01.halign = Gtk.Align.START;
theme_01.tooltip_text = _("Byte");
apply_styles ("01", "#fe2851", theme_01);

var theme_02 = new Gtk.RadioButton.from_widget (theme_01);
theme_02.valign = Gtk.Align.START;
theme_02.halign = Gtk.Align.START;
theme_02.tooltip_text = _("Black");
apply_styles ("02", "#333333", theme_02);

var theme_03 = new Gtk.RadioButton.from_widget (theme_01);
theme_03.valign = Gtk.Align.START;
theme_03.halign = Gtk.Align.START;
theme_03.tooltip_text = _("Blueberry");
apply_styles ("03", "#3689e6", theme_03);

var theme_04 = new Gtk.RadioButton.from_widget (theme_01);
theme_04.valign = Gtk.Align.START;
theme_04.halign = Gtk.Align.START;
theme_04.tooltip_text = _("Turquoise");
apply_styles ("04", "#36E683", theme_04);

var theme_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
theme_box.pack_start (theme_01, false, false, 6);
theme_box.pack_start (theme_02, false, false, 6);
theme_box.pack_start (theme_03, false, false, 6);
theme_box.pack_start (theme_04, false, false, 6);

// I think switch most better here (redian23)
switch (Byte.settings.get_enum ("theme")) {
case 1 :
theme_01.active = true;
break;
case 2 :
theme_02.active = true;
break;
case 3 :
theme_03.active = true;
break;
case 4 :
theme_04.active = true;
break;
}

var settings_09_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
settings_09_box.hexpand = true;
settings_09_box.margin = 6;
settings_09_box.margin_end = 0;
settings_09_box.pack_start (settings_09_icon, false, false, 0);
settings_09_box.pack_start (settings_09_label, false, false, 6);
settings_09_box.pack_end (theme_box, false, false, 0);

var general_grid = new Gtk.Grid ();
general_grid.get_style_context ().add_class ("view");
general_grid.orientation = Gtk.Orientation.VERTICAL;
Expand All @@ -185,8 +174,8 @@ public class Dialogs.Settings : Gtk.Dialog {
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
general_grid.add (settings_03_box);
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
general_grid.add (settings_09_box);
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
//general_grid.add (settings_09_box);
//general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));

var library_label = new Gtk.Label (_("Library"));
library_label.halign = Gtk.Align.START;
Expand Down Expand Up @@ -351,40 +340,6 @@ public class Dialogs.Settings : Gtk.Dialog {
get_action_area ().visible = false;
get_action_area ().no_show_all = true;

//add_button (_("Close"), Gtk.ResponseType.CLOSE);
/*
response.connect ((response_id) => {
destroy ();
});
*/

settings_01_switch.notify["active"].connect (() => {
theme_box.sensitive = !settings_01_switch.active;

var provider = new Gtk.CssProvider ();
var colored_css = """
@define-color colorPrimary %s;
@define-color textColorPrimary %s;
""";

if (settings_01_switch.active) {
colored_css = colored_css.printf (
"@base_color",
"@text_color"
);
} else {
Byte.utils.apply_theme (Byte.settings.get_enum ("theme"));
}

try {
provider.load_from_data (colored_css, colored_css.length);

Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
return;
}
});

settings_02_switch.notify["active"].connect (() => {
Byte.settings.set_boolean ("notifications-enabled", settings_02_switch.active);
});
Expand Down Expand Up @@ -463,11 +418,6 @@ public class Dialogs.Settings : Gtk.Dialog {
Byte.settings.set_enum ("theme", 3);
Byte.utils.apply_theme (3);
});

theme_04.toggled.connect (() => {
Byte.settings.set_enum ("theme", 4);
Byte.utils.apply_theme (4);
});
}

private void apply_styles (string id, string color, Gtk.RadioButton radio) {
Expand Down
43 changes: 26 additions & 17 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class Utils : GLib.Object {

public string MAIN_FOLDER;
public string COVER_FOLDER;

bool dark_mode;
string colorPrimary;
string colorAccent;
string textColorPrimary;

public Utils () {
MAIN_FOLDER = Environment.get_home_dir () + "/.local/share/com.github.alainm23.byte";
COVER_FOLDER = GLib.Path.build_filename (MAIN_FOLDER, "covers");
Expand Down Expand Up @@ -340,6 +346,25 @@ public class Utils : GLib.Object {
}

public void apply_theme (int id) {
if (id == 1) {
dark_mode = false;
colorPrimary = "#fe2851";
colorAccent = "#fe2851";
textColorPrimary = "#fff";
} else if (id == 2) {
dark_mode = true;
colorPrimary = "#fe2851";
colorAccent = "#fe2851";
textColorPrimary = "#fff";
} else if (id == 3) {
dark_mode = true;
colorPrimary = "#36E683";
colorAccent = "#36E683";
textColorPrimary = "#333";
}

Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = dark_mode;

string THEME_CSS = """
@define-color colorPrimary %s;
@define-color colorAccent %s;
Expand All @@ -349,26 +374,10 @@ public class Utils : GLib.Object {
var provider = new Gtk.CssProvider ();

try {
string colorPrimary = "";
string colorAccent = "";
if (id == 1) {
colorPrimary = "#fe2851";
colorAccent = "#fe2851";
} else if (id == 2) {
colorPrimary = "#4d4d4d";
colorAccent = "@text_color";
} else if (id == 3) {
colorPrimary = "#3689e6";
colorAccent = "#3689e6";
}else {
colorPrimary = "#36E683";
colorAccent = "#36E683";
}

var theme_css = THEME_CSS.printf (
colorPrimary,
colorAccent,
"@base_color"
textColorPrimary
);

provider.load_from_data (theme_css, theme_css.length);
Expand Down
Loading

0 comments on commit ba7d1b5

Please sign in to comment.