From 1b94b4f587069f944ab344e76fb50aad3af810f8 Mon Sep 17 00:00:00 2001 From: ppvan Date: Thu, 3 Aug 2023 07:11:22 +0700 Subject: [PATCH] Add test connection btn --- res/gtk/connection-form.blp | 5 +++++ src/ui/connection/connection_form.vala | 26 ++++++++++++++++++++++++ src/ui/connection/connection_recent.vala | 14 ++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/res/gtk/connection-form.blp b/res/gtk/connection-form.blp index 3bab371..ad56f07 100644 --- a/res/gtk/connection-form.blp +++ b/res/gtk/connection-form.blp @@ -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; diff --git a/src/ui/connection/connection_form.vala b/src/ui/connection/connection_form.vala index b9e3b7e..04bc435 100644 --- a/src/ui/connection/connection_form.vala +++ b/src/ui/connection/connection_form.vala @@ -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) { @@ -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 (); diff --git a/src/ui/connection/connection_recent.vala b/src/ui/connection/connection_recent.vala index d7070bf..3c9629f 100644 --- a/src/ui/connection/connection_recent.vala +++ b/src/ui/connection/connection_recent.vala @@ -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"); } @@ -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; }