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