Skip to content

Commit

Permalink
Add user settings (#8)
Browse files Browse the repository at this point in the history
* Refactor MainWindow and create new HeaderBar class

* Add refactored classes to meson.build

* Remove old main window

* Pass players object by constructor injection

* Improve dark theme handling

* Remove obsolete function build_button_from_icon

* Initial implementation of Settings menu and popover

* Add new options to gschema

* add choices to keep window on top
* add option to disable low opacity when lose focus
* add download location to lyrics

* Fix summaries on gschemas

* Remove default value from download location on gschema

* Binds default location to settings menu

* Bind rest of settings

* Add funcionality to 'keep window above' settings

* Check nullability of players in headerbar

* Add functionality to window opacity settings

* Improve readability on SettingsPopover's code

* Add default lyrics directory path

* Add reset button and revert readability improvements

- Add a reset button that restore default settings
- Remove comments referencing each setting
- Move application setting calls back to end of constructor due to
  problems making them syncronized

* Make possible to change lyrics download folder

* Initialize download location if it's null

* Make items align to left, except restore settings button

* Print debug messages when setting the local storage path

* Fix light theme not being translucid
  • Loading branch information
naaando authored Jan 8, 2019
1 parent 03d6f9f commit be2943a
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 274 deletions.
8 changes: 4 additions & 4 deletions data/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
}

/* Window and titlebar inactive */
.lyrics:backdrop,
.lyrics:backdrop .titlebar {
.lyrics:backdrop.translucid-backdrop,
.lyrics:backdrop.translucid-backdrop .titlebar {
color: #0c0c0c;
background: rgba(255, 255, 255, 0.25);
}

.lyrics.dark:backdrop,
.lyrics.dark:backdrop .titlebar {
.lyrics.dark:backdrop.translucid-backdrop,
.lyrics.dark:backdrop.translucid-backdrop .titlebar {
color: #fff;
background: rgba(0, 0, 0, 0.5);
}
Expand Down
17 changes: 17 additions & 0 deletions data/com.github.naaando.lyrics.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,22 @@
<summary>Most recent y position</summary>
<description>Most recent y position</description>
</key>
<key name="window-keep-above" type="s">
<choices>
<choice value='Always'/>
<choice value='When playing'/>
<choice value='Never keep above'/>
</choices>
<default>'When playing'</default>
<summary>Keep the window on the top</summary>
</key>
<key name="window-out-of-focus-translucid" type="b">
<default>true</default>
<summary>Set window's opacity low when it goes out of focus</summary>
</key>
<key name="download-location" type="s">
<default>''</default>
<summary>Location to download and search for lyrics</summary>
</key>
</schema>
</schemalist>
7 changes: 5 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ executable(
meson.project_name (),
asresources,
'src/Controller/DisplayController.vala',
'src/Controller/StackController.vala',
'src/Core/Factory/MetasongFactory.vala',
'src/Core/Lyric.vala',
'src/Core/Metasong.vala',
Expand All @@ -35,14 +34,18 @@ executable(
'src/Mpris/MprisPlayer.vala',
'src/Mpris/MprisService.vala',
'src/Parser/LRC-Parser.vala',
'src/View/HeaderBar.vala',
'src/View/MainStack.vala',
'src/View/MainWindow.vala',
'src/View/SettingsPopover.vala',
'src/Widgets/Displays/IDisplay.vala',
'src/Widgets/Displays/SimpleDisplay.vala',
'src/Widgets/Displays/ScrolledDisplay.vala',
'src/Widgets/Download.vala',
'src/Widgets/FileChooserButton.vala',
'src/Widgets/ModeSwitch.vala',
'src/Widgets/SearchLyric.vala',
'src/Application.vala',
'src/MainWindow.vala',
'src/SimplePlayer.vala',
dependencies: [
dependency ('glib-2.0'),
Expand Down
15 changes: 6 additions & 9 deletions src/Application.vala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

public class Lyrics.Application : Gtk.Application {
public static GLib.Settings settings;
public static string DEFAULT_LYRICS_DIR = Environment.get_home_dir ()+"/.lyrics/";
public static GLib.Settings settings = new Settings ("com.github.naaando.lyrics");

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

static construct {
settings = new Settings ("com.github.naaando.lyrics");
if (settings.get_string ("download-location") == "") {
settings.set_string ("download-location", DEFAULT_LYRICS_DIR);
}
}

protected override void activate () {
Expand All @@ -19,15 +19,12 @@ public class Lyrics.Application : Gtk.Application {

var players = new Players ();

var stack_controller = new Controller.StackController (players);

var scanner = new Mpris.Service ();
scanner.found.connect ((player) => players.add (player));
scanner.lost.connect (players.remove_by_busname);
scanner.setup_dbus ();

var main_window = new MainWindow (this, stack_controller.get_stack ());
main_window.players = players;
var main_window = new MainWindow (this, players, new MainStack (players));

var window_x = settings.get_int ("window-x");
var window_y = settings.get_int ("window-y");
Expand Down
102 changes: 0 additions & 102 deletions src/Controller/StackController.vala

This file was deleted.

156 changes: 0 additions & 156 deletions src/MainWindow.vala

This file was deleted.

2 changes: 1 addition & 1 deletion src/Repository/Local/LocalRepository.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

public class Lyrics.LocalRepository : IRepository, Object {
string local_storage = Environment.get_home_dir ()+"/.lyrics/";
public string local_storage { get; set; default = Environment.get_home_dir ()+"/.lyrics/"; }

public bool save (Metasong song, ILyricFile lyric_file) {
var file = File.new_for_path (local_storage+get_filename_for_song (song));
Expand Down
9 changes: 9 additions & 0 deletions src/Repository/Repository.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class Lyrics.Repository : IRepository, Object {

public Repository () {
lyricsources["viewlyrics"] = new LyricSources.Repository (viewlyrics_dbus[0], viewlyrics_dbus[1]);

Application.settings.changed["download-location"].connect (configure_download_local);
configure_download_local ();
}

public ILyricFile? find_first (Metasong song) {
Expand All @@ -31,4 +34,10 @@ public class Lyrics.Repository : IRepository, Object {
collection.add_all (lyricsources["viewlyrics"].find (song));
return collection;
}

void configure_download_local () {
var settings_location = Application.settings.get_string ("download-location");
local_repository.local_storage = settings_location == "" ? Environment.get_home_dir ()+"/.lyrics/" : settings_location+"/";
debug ("Setting local storage to " + local_repository.local_storage);
}
}
Loading

0 comments on commit be2943a

Please sign in to comment.