Debian Codegraph @

src/actions-popover.vala

raw
1 /* actions-popover.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 private class ActionsPopover : Gtk.Popover {
24 private GLib.SimpleActionGroup action_group;
25 private const GLib.ActionEntry[] action_entries = {
26 {"delete", delete_activated},
27 {"properties", properties_activated}
28 };
29
30 private Connections.Connection connection;
31
32 construct {
33 action_group = new GLib.SimpleActionGroup ();
34 action_group.add_action_entries (action_entries, this);
35 this.insert_action_group ("connection", action_group);
36 }
37
38 public void update_for_item (Connection connection) {
39 this.connection = connection;
40
41 var menu = new GLib.Menu ();
42
43 var action = action_group.lookup_action ("delete") as GLib.SimpleAction;
44 menu.append (_("Delete"), "connection.delete");
45 action.set_enabled (true);
46
47 action = action_group.lookup_action ("properties") as GLib.SimpleAction;
48 menu.append (_("Properties"), "connection.properties");
49 action.set_enabled (true);
50
51 bind_model (menu, null);
52 }
53
54 private void delete_activated () {
55 debug ("Deleting %s", connection.uri);
56
57 Application.application.remove_connection (connection);
58 }
59
60 private void properties_activated () {
61 debug ("Launch properties for %s", connection.uri);
62
63 Application.application.main_window.show_preferences_window (connection);
64 }
65 }
66 }