Debian Codegraph @

src/topbar.vala

raw
1 /* topbar.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/topbar.ui")]
24 private class Topbar : Gtk.Stack {
25 [GtkChild]
26 private unowned Hdy.HeaderBar collection_toolbar;
27 [GtkChild]
28 public unowned Gtk.Button search_button;
29 [GtkChild]
30 private unowned Gtk.HeaderBar display_toolbar;
31 [GtkChild]
32 public unowned Connections.Assistant assistant;
33
34 private weak Connections.Connection connection;
35 private const GLib.ActionEntry[] action_entries = {
36 {"take_screenshot", take_screenshot_activated},
37 {"fullscreen", fullscreen_activated},
38 {"properties", properties_activated},
39 };
40
41 private const GLib.ActionEntry[] key_input_action_entries = {
42 {"ctrl+alt+backspace", ctrl_alt_backspace_activated},
43 {"ctrl+alt+del", ctrl_alt_del_activated},
44 {"ctrl+alt+f1", ctrl_alt_fn_activated},
45 {"ctrl+alt+f2", ctrl_alt_fn_activated},
46 {"ctrl+alt+f3", ctrl_alt_fn_activated},
47 {"ctrl+alt+f7", ctrl_alt_fn_activated},
48 };
49
50 construct {
51 var action_group = new GLib.SimpleActionGroup ();
52 action_group.add_action_entries (action_entries, this);
53 this.insert_action_group ("display", action_group);
54
55 var menu = new GLib.Menu ();
56 var section = new GLib.Menu ();
57
58 section.append (_("Take Screenshot"), "display.take_screenshot");
59 var action = action_group.lookup_action ("take_screenshot") as GLib.SimpleAction;
60 action.set_enabled (true);
61
62 section.append (_("Fullscreen"), "display.fullscreen");
63 action = action_group.lookup_action ("fullscreen") as GLib.SimpleAction;
64 action.set_enabled (true);
65
66 section.append (_("Properties"), "display.properties");
67 action = action_group.lookup_action ("properties") as GLib.SimpleAction;
68 action.set_enabled (true);
69
70 var key_input_action_group = new GLib.SimpleActionGroup ();
71 key_input_action_group.add_action_entries (key_input_action_entries, this);
72 this.insert_action_group ("key", key_input_action_group);
73 }
74
75 private void properties_activated () {
76 Application.application.main_window.show_preferences_window (connection);
77 }
78
79 private void take_screenshot_activated () {
80 if (connection != null)
81 connection.take_screenshot.begin ();
82 }
83
84 private void fullscreen_activated () {
85 Application.application.main_window.fullscreened =
86 !Application.application.main_window.fullscreened;
87 }
88
89 [GtkCallback]
90 private void back_button_clicked () {
91 Application.application.main_window.show_collection_view ();
92 set_visible_child (collection_toolbar);
93 }
94
95 [GtkCallback]
96 public void disconnect_button_clicked () {
97 connection.disconnect_it ();
98
99 back_button_clicked ();
100 }
101
102 public void show_collection_view () {
103 this.connection = null;
104
105 set_visible_child (collection_toolbar);
106 }
107
108 public void show_display_view (Connection connection) {
109 this.connection = connection;
110
111 set_visible_child (display_toolbar);
112
113 display_toolbar.set_title (connection.get_visible_name ());
114 }
115
116 public void set_title (string title) {
117 collection_toolbar.set_title (title);
118 }
119
120 private void ctrl_alt_backspace_activated () {
121 uint[] keyvals = { Gdk.Key.Control_L, Gdk.Key.Alt_L, Gdk.Key.BackSpace };
122
123 send_keys (keyvals);
124 }
125
126 private void ctrl_alt_del_activated () {
127 uint[] keyvals = { Gdk.Key.Control_L, Gdk.Key.Alt_L, Gdk.Key.Delete };
128
129 send_keys (keyvals);
130 }
131
132 private void ctrl_alt_fn_activated (GLib.SimpleAction action) {
133 uint[] keyvals = { Gdk.Key.Control_L, Gdk.Key.Alt_L, 0 };
134
135 if (action.name[action.name.length - 1] == '1')
136 keyvals[2] = Gdk.Key.F1;
137 else if (action.name[action.name.length - 1] == '2')
138 keyvals[2] = Gdk.Key.F2;
139 else if (action.name[action.name.length - 1] == '3')
140 keyvals[3] = Gdk.Key.F3;
141 else if (action.name[action.name.length - 1] == '7')
142 keyvals[2] = Gdk.Key.F7;
143 else {
144 warn_if_reached ();
145
146 return;
147 }
148
149 send_keys (keyvals);
150 }
151
152 private void send_keys (uint[] keyvals) {
153 connection.send_keys (keyvals);
154 }
155 }
156 }