/// <summary> /// Updates the view and shows a new navigation according to /// SettingsManager.CurrentSelectedNavigation. /// Assumes that the navigation pane already is up-to-date. /// </summary> public void SwitchNavigation() { FrameworkElement content = null; FrameworkElement info = null; ViewDetailsConfig vdc = null; string header, subtitle, tracks, time; header = subtitle = tracks = time = null; RefreshDetails(); switch (SettingsManager.CurrentSelectedNavigation) { case "Now playing": case "Music": case "Playlists": return; case "Video": if (VideoContainer == null) InitVideo(); content = VideoContainer; header = SettingsManager.CurrentTrack == null ? U.T("PlaybackEmpty") : SettingsManager.CurrentTrack.Title; subtitle = SettingsManager.CurrentTrack == null ? "" : SettingsManager.CurrentTrack.Artist; break; case "Visualizer": if (VisualizerContainer == null) { VisualizerContainer = new Platform.Windows7.GUI.Controls.Visualizer(); Grid.SetRow(VisualizerContainer, 1); ContentContainer.Children.Add(VisualizerContainer); UpdateSelectedVisualizer(); } content = VisualizerContainer; info = VisualizerList; header = VisualizerContainer.Title; subtitle = VisualizerContainer.Description; break; case "YouTube": vdc = SettingsManager.YouTubeListConfig; if (YouTubeTracks == null) YouTubeTracks = (YouTubeTracks)InitTrackList(new YouTubeTracks(), vdc); content = YouTubeTracks; header = U.T("NavigationYouTubeTitle"); subtitle = U.T("NavigationYouTubeDescription"); break; case "SoundCloud": vdc = SettingsManager.SoundCloudListConfig; if (SoundCloudTracks == null) SoundCloudTracks = (SoundCloudTracks)InitTrackList(new SoundCloudTracks(), vdc); content = SoundCloudTracks; header = U.T("NavigationSoundCloudTitle"); subtitle = U.T("NavigationSoundCloudDescription"); break; case "Jamendo": vdc = SettingsManager.JamendoListConfig; if (JamendoTracks == null) JamendoTracks = (JamendoTracks)InitTrackList(new JamendoTracks(), vdc); content = JamendoTracks; header = U.T("NavigationJamendoTitle"); subtitle = U.T("NavigationJamendoDescription"); break; case "Library": case "Files": vdc = SettingsManager.FileListConfig; if (FileTracks == null) FileTracks = InitTrackList(new ViewDetails(), vdc, SettingsManager.FileTracks); content = FileTracks; header = U.T("NavigationFilesTitle"); time = U.TimeSpanToLongString(new TimeSpan(0, 0, (int)LibraryTime)); tracks = String.Format(U.T("HeaderTracks"), SettingsManager.FileTracks.Count); break; case "Radio": vdc = SettingsManager.RadioListConfig; if (RadioTracks == null) RadioTracks = InitTrackList(new ViewDetails(), vdc, SettingsManager.RadioTracks); content = RadioTracks; header = U.T("NavigationRadioTitle"); time = ""; tracks = String.Format(U.T("HeaderStations"), SettingsManager.RadioTracks.Count); break; case "Disc": vdc = SettingsManager.DiscListConfig; if (DiscTracks == null) DiscTracks = InitTrackList(new ViewDetails(), vdc); content = DiscTracks; header = U.T("NavigationDiscTitle"); time = U.TimeSpanToLongString(new TimeSpan(0, 0, 0)); tracks = String.Format(U.T("HeaderTracks"), 0); break; case "History": vdc = SettingsManager.HistoryListConfig; if (HistoryTracks == null) HistoryTracks = InitTrackList(new ViewDetails(), vdc, SettingsManager.HistoryTracks); content = HistoryTracks; header = U.T("NavigationHistoryTitle"); time = U.TimeSpanToLongString(new TimeSpan(0, 0, (int)HistoryTime)); tracks = String.Format(U.T("HeaderTracks"), SettingsManager.HistoryTracks.Count); break; case "Queue": vdc = SettingsManager.QueueListConfig; if (QueueTracks == null) QueueTracks = InitTrackList(new ViewDetails(), vdc, SettingsManager.QueueTracks); content = QueueTracks; header = U.T("NavigationQueueTitle"); time = U.TimeSpanToLongString(new TimeSpan(0, 0, (int)QueueTime)); tracks = String.Format(U.T("HeaderTracks"), SettingsManager.QueueTracks.Count); break; // playlist default: foreach (DictionaryEntry pltl in PlaylistTrackLists) { PlaylistData playlist = PlaylistManager.FindPlaylist((string)pltl.Key); if (playlist != null && SettingsManager.CurrentSelectedNavigation == "Playlist:"+playlist.Name) { vdc = playlist.ListConfig; if (pltl.Value == null) PlaylistTrackLists[pltl.Key] = InitTrackList(new ViewDetails(), vdc, playlist.Tracks); content = (ViewDetails)PlaylistTrackLists[pltl.Key]; header = U.T("NavigationPlaylistTitle") + " '" + playlist.Name + "'"; time = U.TimeSpanToLongString(new TimeSpan(0, 0, (int)playlist.Time)); tracks = String.Format(U.T("HeaderTracks"), playlist.Tracks.Count); break; } } break; } // switch back from ControlPanel if needed if (MainContainer.Children.Contains(ControlPanel)) MainContainer.Children.Remove(ControlPanel); PlaybackControls.Search.Box.IsEnabled = true; MusicPanel.Visibility = System.Windows.Visibility.Visible; // set visibility of content elements var contentElements = new FrameworkElement[] { FileTracks, HistoryTracks, QueueTracks, RadioTracks, SoundCloudTracks, JamendoTracks, YouTubeTracks, VideoContainer, VisualizerContainer }; foreach (FrameworkElement e in contentElements) if (e != null) e.Visibility = e == content ? Visibility.Visible : Visibility.Collapsed; foreach (DictionaryEntry pltl in PlaylistTrackLists) if (pltl.Value != null) ((ViewDetails)pltl.Value).Visibility = ((ViewDetails)pltl.Value) == content ? Visibility.Visible : Visibility.Collapsed; // set visibility of info elements var infoElements = new FrameworkElement[] { VisualizerList }; foreach (FrameworkElement e in infoElements) e.Visibility = e == info ? Visibility.Visible : Visibility.Collapsed; // set info text InfoPaneTitle.Text = header; if (subtitle != null) { InfoPaneDuration.Visibility = Visibility.Collapsed; InfoPaneTracks.Visibility = Visibility.Collapsed; InfoPaneSubtitle.Visibility = Visibility.Visible; InfoPaneSubtitle.Text = subtitle; } else { InfoPaneDuration.Visibility = Visibility.Visible; InfoPaneTracks.Visibility = Visibility.Visible; InfoPaneSubtitle.Visibility = Visibility.Collapsed; InfoPaneDuration.Text = time; InfoPaneTracks.Text = tracks; } // set search text if (vdc == null || vdc.Filter == null || vdc.Filter == "" || vdc.Filter == U.T("PlaybackSearch")) PlaybackControls.Search.IsActive = false; else { PlaybackControls.Search.IsActive = true; PlaybackControls.Search.IsConnected = false; PlaybackControls.Search.Text = vdc.Filter; PlaybackControls.Search.IsConnected = true; } RefreshViewButton(); }
/// <summary> /// Initializes the GUI /// </summary> private void InitGUI() { // create glass effect RefreshGlassEffect(); #region Events handlers NavigationPane.GotFocus += new RoutedEventHandler(NavigationPane_GotFocus); SettingsManager.QueueTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(QueueTracks_CollectionChanged); SettingsManager.HistoryTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(HistoryTracks_CollectionChanged); SettingsManager.FileTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(LibraryTracks_CollectionChanged); SettingsManager.RadioTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(RadioTracks_CollectionChanged); if (SettingsManager.FileListConfig != null) SettingsManager.FileListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.YouTubeListConfig != null) SettingsManager.YouTubeListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.SoundCloudListConfig != null) SettingsManager.SoundCloudListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.RadioListConfig != null) SettingsManager.RadioListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.JamendoListConfig != null) SettingsManager.JamendoListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.QueueListConfig != null) SettingsManager.QueueListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); if (SettingsManager.HistoryListConfig != null) SettingsManager.HistoryListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged); FilesystemManager.SourceModified += new SourceModifiedEventHandler(FilesystemManager_SourceModified); FilesystemManager.TrackModified += new PropertyChangedEventHandler(FilesystemManager_TrackModified); FilesystemManager.PathModified += new PathModifiedEventHandler(FilesystemManager_PathModified); FilesystemManager.PathRenamed += new RenamedEventHandler(FilesystemManager_PathRenamed); FilesystemManager.ProgressChanged += new ProgressChangedEventHandler(FilesystemManager_ProgressChanged); FilesystemManager.SourceAdded += new SourcesModifiedEventHandler(FilesystemManager_SourceAdded); FilesystemManager.SourceRemoved += new SourcesModifiedEventHandler(FilesystemManager_SourceRemoved); MediaManager.TrackSwitched += new TrackSwitchedEventHandler(MediaManager_TrackSwitched); MediaManager.LoadedTrack += new LoadedTrackDelegate(MediaManager_LoadedTrack); MediaManager.Started += new EventHandler(MediaManager_Started); MediaManager.SearchMatch = TrackList_SearchMatch; UpgradeManager.Checked += new EventHandler(UpgradeManager_Checked); UpgradeManager.ErrorOccured += new Core.ErrorEventHandler(UpgradeManager_ErrorOccured); UpgradeManager.ProgressChanged += new ProgressChangedEventHandler(UpgradeManager_ProgressChanged); UpgradeManager.Upgraded += new EventHandler(UpgradeManager_Upgraded); UpgradeManager.UpgradeFound += new EventHandler(UpgradeManager_UpgradeFound); PluginManager.RefreshVisualizerSelector += new EventHandler(PluginManager_RefreshVisualizerSelector); PluginManager.Installed += new EventHandler<PluginEventArgs>(PluginManager_Installed); PluginManager.Uninstalled += new EventHandler<PluginEventArgs>(PluginManager_Uninstalled); PluginManager.Initialize(); SettingsManager.PropertyChanged += new PropertyChangedWithValuesEventHandler(SettingsManager_PropertyChanged); ServiceManager.ModifyTracks += new EventHandler<ModifiedEventArgs>(ServiceManager_ModifyTracks); NavigationPane.CreateNewPlaylistETB.EnteredEditMode += new EventHandler(EditableTextBlock_EnteredEditMode); SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch); resortDelay.Interval = new TimeSpan(0, 0, 0, 0, 500); resortDelay.Tick += new EventHandler(ResortDelay_Tick); sourceModifiedDelay.Tick += new EventHandler(SourceModifiedDelay_Tick); sourceModifiedDelay.Interval = new TimeSpan(0, 0, 0, 1, 500); #endregion #region Tray icon // create system tray icon trayIcon = (TaskbarIcon)FindResource("NotifyIcon"); trayIcon.TrayToolTip = new TrayToolTip(this); trayIcon.TrayLeftMouseUp += TaskbarClicked; trayMenu = new ContextMenu(); trayMenuShow = new MenuItem(); trayMenuExit = new MenuItem(); trayMenuPlay = new MenuItem(); trayMenuNext = new MenuItem(); trayMenuPrev = new MenuItem(); trayMenuShow.Header = U.T("TrayShow"); trayMenuExit.Header = U.T("TrayExit"); trayMenuPlay.Header = U.T("TrayPlay"); trayMenuNext.Header = U.T("TrayNext"); trayMenuPrev.Header = U.T("TrayPrev"); trayMenuShow.Click += TrayShow_Clicked; trayMenuExit.Click += TrayExit_Clicked; trayMenuPlay.Click += TrayPlayPause_Clicked; trayMenuNext.Click += TrayNext_Clicked; trayMenuPrev.Click += TrayPrevious_Clicked; trayMenu.Items.Add(trayMenuShow); trayMenu.Items.Add(new Separator()); trayMenu.Items.Add(trayMenuPlay); trayMenu.Items.Add(trayMenuNext); trayMenu.Items.Add(trayMenuPrev); trayMenu.Items.Add(new Separator()); trayMenu.Items.Add(trayMenuExit); trayIcon.ContextMenu = trayMenu; #endregion #region Thumbnail buttons //// create thumbnail buttons taskbarPrev = new ThumbnailToolbarButton(Properties.Resources.Previous, U.T("TaskbarPrev")); taskbarPrev.Enabled = true; taskbarPrev.Click += TaskbarPrevious_Clicked; taskbarPlay = new ThumbnailToolbarButton(Properties.Resources.Play, U.T("TaskbarPlay")); taskbarPlay.Enabled = true; taskbarPlay.Click += TaskbarPlayPause_Clicked; taskbarNext = new ThumbnailToolbarButton(Properties.Resources.Next, U.T("TaskbarNext")); taskbarNext.Enabled = true; taskbarNext.Click += TaskbarNext_Clicked; TaskbarManager.Instance.ThumbnailToolbars.AddButtons( new WindowInteropHelper(this).Handle, new ThumbnailToolbarButton[] { taskbarPrev, taskbarPlay, taskbarNext } ); #endregion #region Jump lists jumpTaskPlay = new JumpTask() { Title = U.T("JumpPlay", "Title"), Arguments = "/play", Description = U.T("JumpPlay", "Description"), IconResourceIndex = -1, ApplicationPath = Assembly.GetEntryAssembly().CodeBase, }; jumpTaskNext = new JumpTask() { Title = U.T("JumpNext", "Title"), Arguments = "/next", Description = U.T("JumpNext", "Description"), IconResourceIndex = -1, ApplicationPath = Assembly.GetEntryAssembly().CodeBase, }; jumpTaskPrev = new JumpTask() { Title = U.T("JumpPrev", "Title"), Arguments = "/previous", Description = U.T("JumpPrev", "Description"), IconResourceIndex = -1, ApplicationPath = Assembly.GetEntryAssembly().CodeBase, }; jumpList = new System.Windows.Shell.JumpList(); jumpList.JumpItems.Add(jumpTaskPlay); jumpList.JumpItems.Add(jumpTaskNext); jumpList.JumpItems.Add(jumpTaskPrev); jumpList.ShowRecentCategory = true; jumpList.ShowFrequentCategory = true; System.Windows.Shell.JumpList.SetJumpList(Application.Current, jumpList); #endregion #region Style Utilities.DefaultAlbumArt = "/Platform/Windows 7/GUI/Images/AlbumArt/Default.jpg"; // rough detection of aero vs classic // you'll se a lot more of these around the code if (System.Windows.Forms.VisualStyles.VisualStyleInformation.DisplayName == "") { // applying classic theme SolidColorBrush scb = (SolidColorBrush)FindResource("DetailsPaneKey"); scb.Color = SystemColors.ControlTextColor; scb = (SolidColorBrush)FindResource("DetailsPaneValue"); scb.Color = SystemColors.ControlTextColor; scb = (SolidColorBrush)FindResource("InfoPaneTitle"); scb.Color = SystemColors.ControlTextColor; scb = (SolidColorBrush)FindResource("InfoPaneText"); scb.Color = SystemColors.ControlTextColor; MainFrame.BorderBrush = SystemColors.ControlBrush; MainFrame.Background = SystemColors.ControlBrush; MainContainer.Background = SystemColors.ControlBrush; InfoPane.Background = SystemColors.WindowBrush; VerticalSplitter.Background = SystemColors.ControlBrush; TopToolbar.Style = null; DetailsPane.Style = (Style)FindResource("ClassicDetailsPaneStyle"); OuterBottomRight.BorderBrush = SystemColors.ControlLightLightBrush; OuterTopLeft.BorderBrush = SystemColors.ControlDarkBrush; InnerBottomRight.BorderBrush = SystemColors.ControlDarkBrush; InnerTopLeft.BorderBrush = SystemColors.ControlLightLightBrush; ControlPanel.AboutTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle"); ControlPanel.ShortcutTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle"); ControlPanel.GeneralTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle"); Utilities.DefaultAlbumArt = "/Platform/Windows 7/GUI/Images/AlbumArt/Classic.jpg"; } #endregion VisualizerList.ItemsSource = PluginManager.VisualizerSelector; LibraryTime = 0; QueueTime = 0; HistoryTime = 0; if (SettingsManager.FileTracks != null) foreach (TrackData track in SettingsManager.FileTracks) LibraryTime += track.Length; if (SettingsManager.QueueTracks != null) foreach (TrackData track in SettingsManager.QueueTracks) QueueTime += track.Length; if (SettingsManager.HistoryTracks != null) foreach (TrackData track in SettingsManager.HistoryTracks) HistoryTime += track.Length; NavigationColumn.Width = new GridLength(SettingsManager.NavigationPaneWidth); double h = SettingsManager.DetailsPaneHeight; DetailsRow.Height = new GridLength(h); UpdateVisibility("menubar"); UpdateVisibility("details"); RefreshStrings(); U.ListenForShortcut = true; FilesystemManager.AddSystemFolders(true); #region Create playlists foreach (PlaylistData playlist in SettingsManager.Playlists) CreatePlaylist(playlist, false); PlaylistManager.PlaylistModified += new ModifiedEventHandler(PlaylistManager_PlaylistModified); PlaylistManager.PlaylistRenamed += new RenamedEventHandler(PlaylistManager_PlaylistRenamed); if (SettingsManager.CurrentSelectedNavigation == "YouTube") NavigationPane.Youtube.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "SoundCloud") NavigationPane.SoundCloud.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "Radio") NavigationPane.Radio.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "Jamendo") NavigationPane.Jamendo.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "Queue") NavigationPane.Queue.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "History") NavigationPane.History.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "Video") NavigationPane.Video.Focus(); else if (SettingsManager.CurrentSelectedNavigation == "Visualizer") NavigationPane.Visualizer.Focus(); else if (!SettingsManager.CurrentSelectedNavigation.StartsWith("Playlist:")) NavigationPane.Files.Focus(); else { string name = SettingsManager.CurrentSelectedNavigation.Split(new[] { ':' }, 2)[1]; foreach (TreeViewItem tvi in NavigationPane.Playlists.Items) { if ((string)tvi.Tag == name) { tvi.Focus(); break; } } } #endregion #region Load track lists U.L(LogLevel.Debug, "main", "Initialize track lists"); switch (SettingsManager.CurrentActiveNavigation) { case "Queue": if (FileTracks == null) FileTracks = InitTrackList(new ViewDetails(), SettingsManager.FileListConfig, SettingsManager.FileTracks); break; case "Radio": if (RadioTracks == null) RadioTracks = InitTrackList(new ViewDetails(), SettingsManager.RadioListConfig, SettingsManager.RadioTracks); break; case "YouTube": if (YouTubeTracks == null) YouTubeTracks = (YouTubeTracks)InitTrackList(new YouTubeTracks(), SettingsManager.YouTubeListConfig); break; case "SoundCloud": if (SoundCloudTracks == null) SoundCloudTracks = (SoundCloudTracks)InitTrackList(new SoundCloudTracks(), SettingsManager.SoundCloudListConfig); break; case "Jamendo": if (JamendoTracks == null) JamendoTracks = (JamendoTracks)InitTrackList(new JamendoTracks(), SettingsManager.JamendoListConfig); break; default: if (SettingsManager.CurrentActiveNavigation.StartsWith("Playlist:")) { string pname = SettingsManager.CurrentActiveNavigation.Split(new[] { ':' }, 2)[1]; PlaylistData p = PlaylistManager.FindPlaylist(pname); if (p != null) { ViewDetails vd = (ViewDetails)PlaylistTrackLists[pname]; if (vd == null) vd = InitTrackList(new ViewDetails(), p.ListConfig, p.Tracks); } } break; } if (FileTracks == null) FileTracks = InitTrackList(new ViewDetails(), SettingsManager.FileListConfig, SettingsManager.FileTracks); #endregion #region File association prompt if (SettingsManager.FirstRun) { Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate() { // Show welcome dialog TaskDialogResult tdr = Welcome.Show(new WindowInteropHelper(this).Handle); Associations a = new Associations(); ProcessStartInfo assProcInfo = new ProcessStartInfo(); assProcInfo.FileName = U.FullPath; assProcInfo.Verb = "runas"; string assProcArgs = "--associate {0}"; try { switch (tdr) { case TaskDialogResult.Yes: assProcInfo.Arguments = String.Format(assProcArgs, string.Join(",", a.FullFileList.ToArray())); Process.Start(assProcInfo); break; case TaskDialogResult.CustomButtonClicked: a.ShowDialog(); assProcInfo.Arguments = String.Format(assProcArgs, string.Join(",", a.FileList.ToArray())); Process.Start(assProcInfo); break; case TaskDialogResult.Cancel: break; } } catch (Exception e) { U.L(LogLevel.Warning, "MAIN", "Could not set associations: " + e.Message); } })); SettingsManager.FirstRun = false; } #endregion #region Commented //System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal); #endregion }