| 1 |
/* assistant.vala |
| 2 |
* |
| 3 |
* Copyright (C) Red Hat, Inc |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Author: Felipe Borges <[email protected]> |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace Connections { |
| 23 |
[GtkTemplate (ui = "/org/gnome/Connections/ui/assistant.ui")] |
| 24 |
private class Assistant : Gtk.Popover { |
| 25 |
[GtkChild] |
| 26 |
private unowned Gtk.Entry url_entry; |
| 27 |
[GtkChild] |
| 28 |
private unowned Gtk.Button create_button; |
| 29 |
[GtkChild] |
| 30 |
private unowned Gtk.RadioButton rdp_radio_button; |
| 31 |
[GtkChild] |
| 32 |
private unowned Gtk.RadioButton vnc_radio_button; |
| 33 |
[GtkChild] |
| 34 |
private unowned Gtk.RadioButton spice_radio_button; |
| 35 |
|
| 36 |
construct { |
| 37 |
spice_radio_button.visible = Config.HAS_SPICE; |
| 38 |
} |
| 39 |
|
| 40 |
private bool uri_has_supported_scheme (string uri) { |
| 41 |
return uri.has_prefix ("rdp://") || uri.has_prefix ("vnc://") || uri.has_prefix ("spice://"); |
| 42 |
} |
| 43 |
|
| 44 |
[GtkCallback] |
| 45 |
private void on_url_entry_changed () { |
| 46 |
if (url_entry.text == "") { |
| 47 |
create_button.sensitive = false; |
| 48 |
|
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
var address = url_entry.text; |
| 53 |
if (!uri_has_supported_scheme (address)) { |
| 54 |
if (rdp_radio_button.get_active ()) |
| 55 |
address = "rdp://" + address; |
| 56 |
else if (spice_radio_button.get_active ()) |
| 57 |
address = "spice://" + address; |
| 58 |
else |
| 59 |
address = "vnc://" + address; |
| 60 |
} |
| 61 |
|
| 62 |
debug ("Attempting to add \"%s\"", address); |
| 63 |
var uri = Xml.URI.parse (address); |
| 64 |
if (uri == null) { |
| 65 |
create_button.sensitive = false; |
| 66 |
|
| 67 |
debug ("Address \"%s\" is invalid", address); |
| 68 |
|
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
rdp_radio_button.set_active (uri.scheme == "rdp"); |
| 73 |
vnc_radio_button.set_active (uri.scheme == "vnc"); |
| 74 |
spice_radio_button.set_active (uri.scheme == "spice"); |
| 75 |
|
| 76 |
create_button.sensitive = uri.server != null; |
| 77 |
} |
| 78 |
|
| 79 |
[GtkCallback] |
| 80 |
private void on_create_connection_button_clicked () { |
| 81 |
var uri = url_entry.get_text (); |
| 82 |
|
| 83 |
// Prefixes the uri string with the selected protocol (when protocol isn't explicit) |
| 84 |
if (!uri_has_supported_scheme (uri)) { |
| 85 |
var scheme = rdp_radio_button.get_active () ? "rdp://" : spice_radio_button.get_active () ? "spice://" : "vnc://"; |
| 86 |
uri = scheme + uri; |
| 87 |
} |
| 88 |
|
| 89 |
Application.application.add_connection (uri); |
| 90 |
|
| 91 |
url_entry.set_text (""); |
| 92 |
popdown (); |
| 93 |
} |
| 94 |
|
| 95 |
[GtkCallback] |
| 96 |
private void on_url_entry_activated () { |
| 97 |
if (create_button.sensitive) |
| 98 |
create_button.clicked (); |
| 99 |
} |
| 100 |
|
| 101 |
[GtkCallback] |
| 102 |
private void on_help_button_clicked () { |
| 103 |
try { |
| 104 |
Gtk.show_uri_on_window (Application.application.main_window, |
| 105 |
"help:gnome-connections/connect", |
| 106 |
Gtk.get_current_event_time ()); |
| 107 |
} catch (GLib.Error error) { |
| 108 |
warning ("Failed to display help: %s", error.message); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |