Debian Codegraph @

subprojects/gtk-frdp/examples/gtk-frdp-viewer.vala

raw
1 /* gtk-frdp-viewer.vala
2 *
3 * Copyright (C) 2018 Felipe Borges <[email protected]>
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
19 using Gtk;
20 using Frdp;
21
22 private class GtkRdpViewer.Application: Gtk.Application {
23 public const int DEFAULT_RDP_PORT = 3389;
24
25 private Gtk.ApplicationWindow window;
26 private Frdp.Display display;
27
28 static string option_connect_address;
29 const OptionEntry[] options = {
30 { "connect", 0, 0, OptionArg.STRING, ref option_connect_address, "Connect to address", null },
31 { null }
32 };
33
34 public Application () {
35 application_id = "org.gnome.GtkRdpViewer";
36 flags |= ApplicationFlags.HANDLES_COMMAND_LINE;
37 }
38
39 protected override void activate () {
40 if (window != null)
41 return;
42
43 window = new Gtk.ApplicationWindow (this);
44 display = new Frdp.Display();
45
46 window.add(display);
47 window.show_all ();
48 }
49
50 protected override int command_line (GLib.ApplicationCommandLine cmdline) {
51 option_connect_address = null;
52
53 var opt_context = new OptionContext ("A RDP Viewer");
54 opt_context.add_main_entries (options, null);
55 opt_context.set_help_enabled (true);
56
57 try {
58 string[] args1 = cmdline.get_arguments ();
59 unowned string[] args2 = args1;
60
61 opt_context.parse (ref args2);
62 } catch (OptionError error) {
63 cmdline.printerr ("%s\n", error.message);
64
65 return 1;
66 }
67
68 if (option_connect_address != null) {
69 connect_to (option_connect_address);
70 }
71
72 return 0;
73 }
74
75 private void connect_to (string address) {
76 activate ();
77
78 display.open_host (address, DEFAULT_RDP_PORT);
79 }
80 }
81
82 public int main (string[] args) {
83 var app = new GtkRdpViewer.Application ();
84
85 var exit_status = app.run (args);
86
87 return exit_status;
88 }