more progress
This commit is contained in:
parent
c25df9d61b
commit
4d3ddd1c41
3 changed files with 62 additions and 63 deletions
|
@ -18,7 +18,6 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Sqlite.Database config_db;
|
|
||||||
Gst.Element playbin;
|
Gst.Element playbin;
|
||||||
Wavelet.Subsonic public_api;
|
Wavelet.Subsonic public_api;
|
||||||
|
|
||||||
|
@ -28,21 +27,6 @@ public class Wavelet.Application : Adw.Application {
|
||||||
application_id: "eu.callcc.Wavelet",
|
application_id: "eu.callcc.Wavelet",
|
||||||
flags: ApplicationFlags.DEFAULT_FLAGS
|
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 {
|
construct {
|
||||||
|
@ -152,7 +136,7 @@ public class Wavelet.Application : Adw.Application {
|
||||||
win.song = song;
|
win.song = song;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
win.setup.load (config_db);
|
win.setup.load ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_about_action () {
|
private void on_about_action () {
|
||||||
|
|
|
@ -63,4 +63,3 @@ template $WaveletSetup: Adw.NavigationPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
106
src/setup.vala
106
src/setup.vala
|
@ -36,6 +36,34 @@ public class Wavelet.Setup : Adw.NavigationPage {
|
||||||
|
|
||||||
public signal void connected (Wavelet.Subsonic api);
|
public signal void connected (Wavelet.Subsonic api);
|
||||||
|
|
||||||
|
private Sqlite.Database db;
|
||||||
|
private Sqlite.Statement db_get;
|
||||||
|
private Sqlite.Statement db_set;
|
||||||
|
|
||||||
|
construct {
|
||||||
|
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 this.db);
|
||||||
|
assert (ec == Sqlite.OK);
|
||||||
|
|
||||||
|
ec = this.db.exec ("""
|
||||||
|
CREATE TABLE IF NOT EXISTS Setup (key UNIQUE, value);
|
||||||
|
""", null, null);
|
||||||
|
assert (ec == Sqlite.OK);
|
||||||
|
|
||||||
|
ec = this.db.prepare_v2 ("""SELECT value FROM Setup WHERE key IS ?1""", -1, out this.db_get);
|
||||||
|
assert (ec == Sqlite.OK);
|
||||||
|
|
||||||
|
ec = this.db.prepare_v2 ("""INSERT OR REPLACE INTO Setup VALUES (?1, ?2)""", -1, out this.db_set);
|
||||||
|
assert (ec == Sqlite.OK);
|
||||||
|
}
|
||||||
|
|
||||||
[GtkCallback] private void on_authn_changed () {
|
[GtkCallback] private void on_authn_changed () {
|
||||||
this.authn_can_validate = true;
|
this.authn_can_validate = true;
|
||||||
}
|
}
|
||||||
|
@ -76,44 +104,38 @@ public class Wavelet.Setup : Adw.NavigationPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load (Sqlite.Database db) {
|
public void load () {
|
||||||
Sqlite.Statement stmt;
|
this.db_get.bind_text (1, "server_url");
|
||||||
int rc;
|
if (this.db_get.step () == Sqlite.ROW) {
|
||||||
|
this.server_url = this.db_get.column_text (0);
|
||||||
rc = db.prepare_v2 ("""SELECT value FROM Setup WHERE key IS ?1""", -1, out stmt);
|
|
||||||
assert (rc == Sqlite.OK);
|
|
||||||
|
|
||||||
stmt.bind_text (1, "server_url");
|
|
||||||
if (stmt.step () == Sqlite.ROW) {
|
|
||||||
this.server_url = stmt.column_text (0);
|
|
||||||
} else {
|
} else {
|
||||||
this.server_url = "";
|
this.server_url = "";
|
||||||
}
|
}
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_get.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "username");
|
this.db_get.bind_text (1, "username");
|
||||||
if (stmt.step () == Sqlite.ROW) {
|
if (this.db_get.step () == Sqlite.ROW) {
|
||||||
this.username = stmt.column_text (0);
|
this.username = this.db_get.column_text (0);
|
||||||
} else {
|
} else {
|
||||||
this.username = "";
|
this.username = "";
|
||||||
}
|
}
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_get.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "token");
|
this.db_get.bind_text (1, "token");
|
||||||
if (stmt.step () == Sqlite.ROW) {
|
if (this.db_get.step () == Sqlite.ROW) {
|
||||||
this.token = stmt.column_text (0);
|
this.token = this.db_get.column_text (0);
|
||||||
} else {
|
} else {
|
||||||
this.token = "";
|
this.token = "";
|
||||||
}
|
}
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_get.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "salt");
|
this.db_get.bind_text (1, "salt");
|
||||||
if (stmt.step () == Sqlite.ROW) {
|
if (this.db_get.step () == Sqlite.ROW) {
|
||||||
this.salt = stmt.column_text (0);
|
this.salt = this.db_get.column_text (0);
|
||||||
} else {
|
} else {
|
||||||
this.salt = "";
|
this.salt = "";
|
||||||
}
|
}
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_get.reset () == Sqlite.OK);
|
||||||
|
|
||||||
this.password = "";
|
this.password = "";
|
||||||
|
|
||||||
|
@ -140,31 +162,25 @@ public class Wavelet.Setup : Adw.NavigationPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save () {
|
public void save () {
|
||||||
Sqlite.Statement stmt;
|
this.db_set.bind_text (1, "server_url");
|
||||||
int rc;
|
this.db_set.bind_text (2, this.server_url);
|
||||||
|
assert (this.db_set.step () == Sqlite.DONE);
|
||||||
|
assert (this.db_set.reset () == Sqlite.OK);
|
||||||
|
|
||||||
rc = config_db.prepare_v2 ("""INSERT OR REPLACE INTO Setup VALUES (?1, ?2)""", -1, out stmt);
|
this.db_set.bind_text (1, "username");
|
||||||
assert (rc == Sqlite.OK);
|
this.db_set.bind_text (2, this.username);
|
||||||
|
assert (this.db_set.step () == Sqlite.DONE);
|
||||||
|
assert (this.db_set.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "server_url");
|
this.db_set.bind_text (1, "token");
|
||||||
stmt.bind_text (2, this.server_url);
|
this.db_set.bind_text (2, this.token);
|
||||||
assert (stmt.step () == Sqlite.DONE);
|
assert (this.db_set.step () == Sqlite.DONE);
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_set.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "username");
|
this.db_set.bind_text (1, "salt");
|
||||||
stmt.bind_text (2, this.username);
|
this.db_set.bind_text (2, this.salt);
|
||||||
assert (stmt.step () == Sqlite.DONE);
|
assert (this.db_set.step () == Sqlite.DONE);
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
assert (this.db_set.reset () == Sqlite.OK);
|
||||||
|
|
||||||
stmt.bind_text (1, "token");
|
|
||||||
stmt.bind_text (2, this.token);
|
|
||||||
assert (stmt.step () == Sqlite.DONE);
|
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
stmt.bind_text (1, "salt");
|
|
||||||
stmt.bind_text (2, this.salt);
|
|
||||||
assert (stmt.step () == Sqlite.DONE);
|
|
||||||
assert (stmt.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
this.password = "";
|
this.password = "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue