Debian Codegraph @

src/collection-view-child.vala

raw
1 /* collection-view-child.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/collection-view-child.ui")]
24 private class CollectionViewChild : Gtk.Box {
25 public Connection connection;
26
27 [GtkChild]
28 private unowned Gtk.Label connection_name;
29
30 [GtkChild]
31 public unowned Gtk.Image thumbnail;
32 private string default_thumbnail_icon {
33 owned get {
34 return ("%s-symbolic").printf (Application.application.application_id);
35 }
36 }
37
38 private uint thumbnail_id = 0;
39
40 public CollectionViewChild (Connection connection) {
41 this.connection = connection;
42
43 update_display_name ();
44 connection.notify["display-name"].connect (update_display_name);
45
46 thumbnail.icon_name = default_thumbnail_icon;
47 connection.show.connect (update_thumbnail);
48 }
49
50 private void update_display_name () {
51 connection_name.set_text (connection.get_visible_name ());
52 }
53
54 private void update_thumbnail () {
55 thumbnail_id = Timeout.add_seconds (3, () => {
56 thumbnail_id = 0;
57
58 if (!connection.connected) {
59 thumbnail.set_from_icon_name (default_thumbnail_icon,
60 Gtk.IconSize.LARGE_TOOLBAR);
61 return Source.REMOVE;
62 }
63
64 if (connection.thumbnail == null)
65 return Source.REMOVE;
66
67 var pixbuf = connection.thumbnail.scale_simple (180, 134,
68 Gdk.InterpType.BILINEAR);
69 thumbnail.set_from_pixbuf (pixbuf);
70
71 return Source.CONTINUE;
72 });
73 }
74
75 ~CollectionViewChild () {
76 if (thumbnail_id != 0)
77 Source.remove (thumbnail_id);
78 thumbnail_id = 0;
79 }
80 }
81 }