audrey/src/application.vala
2024-10-09 19:47:37 +00:00

96 lines
3.2 KiB
Vala

/* application.vala
*
* Copyright 2024 Erica Z
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
Sqlite.Database config_db;
public class Wavelet.Application : Adw.Application {
public Application () {
Object (
application_id: "eu.callcc.Wavelet",
flags: ApplicationFlags.DEFAULT_FLAGS
);
var app_config_dir = Path.build_filename (Environment.get_user_config_dir (), "wavelet");
try {
File.new_build_filename (app_config_dir).make_directory_with_parents ();
} catch (Error e) {
// just ignore if the directory already existed
}
int ec = Sqlite.Database.open (Path.build_filename (app_config_dir, "config.db"), out config_db);
assert (ec == Sqlite.OK);
ec = config_db.exec ("""
CREATE TABLE IF NOT EXISTS Setup (key UNIQUE, value);
""", null, null);
assert (ec == Sqlite.OK);
}
construct {
ActionEntry[] action_entries = {
{ "about", this.on_about_action },
{ "preferences", this.on_preferences_action },
{ "quit", this.quit }
};
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", {"<primary>q"});
}
public override void activate () {
base.activate ();
// FIXME edit back if issues var win = this.active_window ?? new Wavelet.Window (this);
var win = new Wavelet.Window (this);
win.present ();
win.artist_list.set_loading ();
win.song_list.set_loading ();
win.setup.connected.connect ((api) => {
win.artist_list.model = api.artist_list;
win.song_list.model = api.song_list;
api.done_reloading.connect (() => {
win.artist_list.set_ready ();
win.song_list.set_ready ();
});
//api.reload.begin ();
});
win.setup.load (config_db);
}
private void on_about_action () {
string[] developers = { "Erica Z" };
var about = new Adw.AboutDialog () {
application_name = "wavelet",
application_icon = "eu.callcc.Wavelet",
developer_name = "Erica Z",
translator_credits = _("translator-credits"),
version = "0.1.0",
developers = developers,
copyright = "© 2024 Erica Z",
};
about.present (this.active_window);
}
private void on_preferences_action () {
message ("app.preferences action activated");
}
}