Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test connection btn #22

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions res/gtk/connection-form.blp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ template $PsequelConnectionForm : Adw.Bin {
margin-top: 20;
margin-bottom: 10;

Button {
label: "Test";
clicked => $on_test_clicked();
}

Label status_label {
label: "";
halign: start;
Expand Down
26 changes: 26 additions & 0 deletions src/ui/connection/connection_form.vala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ namespace Psequel {
}
}

private async void test_database (QueryService service, Connection conn) {

try {
yield service.connect_db (conn);

var dialog = create_dialog ("", "Connection OK");
dialog.present ();

} catch (PsequelError err) {
var dialog = create_dialog ("Connection error", err.message);
dialog.present ();
}
}

[GtkCallback]
private void on_url_entry_changed (Gtk.Editable editable) {

Expand Down Expand Up @@ -134,6 +148,18 @@ namespace Psequel {
});
}

[GtkCallback]
private void on_test_clicked (Gtk.Button btn) {
if (this.mapped_conn == null) {
return;
}

btn.sensitive = false;
test_database.begin (this.query_service, this.mapped_conn, (obj, res) => {
btn.sensitive = true;
});
}

[GtkCallback]
private void on_entry_activated (Gtk.Entry entry) {
connect_btn.clicked ();
Expand Down
14 changes: 11 additions & 3 deletions src/ui/connection/connection_recent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ namespace Psequel {
// Bind the conns model to the list view.
conn_list.bind_model (model, row_factory);

// Auto select created row.
var first_row = conn_list.get_row_at_index (0);
conn_list.select_row (first_row);
debug ("Select first row");

Idle.add_once (() => {
// Auto select created row.
conn_list.unselect_all ();
var first_row = conn_list.get_row_at_index (0);
conn_list.select_row (first_row);
signals.selection_changed (model[0]);
});

debug ("setup bindings done");
}
Expand All @@ -81,9 +87,11 @@ namespace Psequel {
*/
[GtkCallback]
public void on_row_selected (Gtk.ListBoxRow? row) {
debug ("Row selection changed");

var conn_row = row as ConnectionRow;
if (conn_row == null) {
debug ("Null row?");
return;
}

Expand Down