/
WelcomePage.vala
119 lines (97 loc) · 4.55 KB
/
WelcomePage.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright 2013-2020 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class Audience.WelcomePage : Granite.Placeholder {
private string current_video;
private Gtk.Button replay_button;
private Gtk.Image replay_button_image;
private Gtk.Label replay_button_title;
private Gtk.Label replay_button_description;
public WelcomePage () {
Object (
title: _("No Videos Open"),
description: _("Select a source to begin playing.")
);
}
construct {
hexpand = true;
vexpand = true;
var open_button = append_button (new ThemedIcon ("document-open"), _("Open file"), _("Open a saved file."));
replay_button = append_button (new ThemedIcon ("media-playlist-repeat"), _("Replay last video"), "");
var disk_button = append_button (new ThemedIcon ("media-cdrom"), _("Play from Disc"), _("Watch a DVD or open a file from disc"));
var library_button = append_button (new ThemedIcon ("folder-videos"), _("Browse Library"), _("Watch a movie from your library"));
//A hacky way to update the labels and icon of the replay button
var replay_button_grid = (Gtk.Grid)replay_button.child;
replay_button_image = (Gtk.Image)replay_button_grid.get_first_child ();
replay_button_title = (Gtk.Label)replay_button_image.get_next_sibling ();
replay_button_description = (Gtk.Label)replay_button_title.get_next_sibling ();
var disk_manager = DiskManager.get_default ();
disk_button.visible = disk_manager.has_media_volumes ();
var library_manager = Services.LibraryManager.get_instance ();
library_button.visible = library_manager.library_items.get_n_items () > 0;
update_replay_button ();
update_replay_title ();
open_button.clicked.connect (() => {
var window = (Audience.Window)get_root ();
window.run_open_file ();
});
replay_button.clicked.connect (() => {
var window = (Audience.Window)get_root ();
PlaybackManager.get_default ().append_to_playlist ({ current_video });
window.resume_last_videos ();
});
disk_button.clicked.connect (() => {
var window = (Audience.Window)get_root ();
window.run_open_dvd ();
});
library_button.clicked.connect (() => {
var window = (Audience.Window)get_root ();
window.show_library ();
});
settings.changed["current-video"].connect (update_replay_button);
settings.changed["last-stopped"].connect (update_replay_title);
disk_manager.volume_found.connect ((vol) => {
disk_button.visible = disk_manager.has_media_volumes ();
});
disk_manager.volume_removed.connect ((vol) => {
disk_button.visible = disk_manager.has_media_volumes ();
});
library_manager.library_items.items_changed.connect (() => {
library_button.visible = library_manager.library_items.get_n_items () > 0;
});
}
private void update_replay_button () {
bool show_replay_button = false;
current_video = settings.get_string ("current-video");
if (current_video != "") {
var last_file = File.new_for_uri (current_video);
if (last_file.query_exists ()) {
replay_button_description.label = get_title (last_file.get_basename ());
show_replay_button = true;
}
}
replay_button.visible = show_replay_button;
}
private void update_replay_title () {
if (settings.get_int64 ("last-stopped") == 0) {
replay_button_title.label = _("Replay last video");
replay_button_image.set_from_icon_name ("media-playlist-repeat");
} else {
replay_button_title.label = _("Resume last video");
replay_button_image.set_from_icon_name ("media-playback-start");
}
}
}