Example #1
0
        /// <summary>
        /// Initializes the video control.
        /// </summary>
        private void InitVideo()
        {
            if (VideoContainer != null) return;

            VideoContainer = new Video();
            Grid.SetRow(VideoContainer, 1);
            ContentContainer.Children.Add(VideoContainer);

            // WebBrowser will not load if it's not visible
            try
            {
                // warning for fugliness
                VideoContainer.Children.Remove(VideoContainer.Browser);
                ContentContainer.Children.Add(VideoContainer.Browser);
                ContentContainer.Children.Remove(VideoContainer.Browser);
                VideoContainer.Browser.Visibility = System.Windows.Visibility.Collapsed;

            }
            catch (Exception exc)
            {
                U.L(LogLevel.Error, "MAIN", "There was a problem moving browsers into view for loading");
                U.L(LogLevel.Error, "MAIN", exc.Message);
            }

            YouTubePlayerInterface ypi = new YouTubePlayerInterface();
            ypi.ErrorOccured += new Core.ErrorEventHandler(YouTube_ErrorOccured);
            ypi.NoFlashDetected += new EventHandler(YouTube_NoFlashDetected);
            ypi.PlayerReady += new EventHandler(YouTube_PlayerReady);

            VideoContainer.Browser.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            VideoContainer.Browser.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            VideoContainer.Browser.Width = double.NaN;
            VideoContainer.Browser.Height = double.NaN;
            VideoContainer.Browser.ObjectForScripting = ypi;
            VideoContainer.NoVideoMessage.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            VideoContainer.NoVideoMessage.Visibility = System.Windows.Visibility.Visible;

            if (YouTubeManager.IsYouTube(SettingsManager.CurrentTrack))
            {
                VideoContainer.BrowserVisibility = Visibility.Visible;
            }
        }
Example #2
0
        /// <summary>
        /// Initializes the GUI
        /// </summary>
        private void InitGUI()
        {
            Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
            {
                // TODO: remove all these lines
                //FileTracks.ParentWindow = this;
                //QueueTracks.ParentWindow = this;
                //HistoryTracks.ParentWindow = this;
                ControlPanel.ParentWindow = this;
                //NavigationPane.ParentWindow = this;
                //PlaybackControls.ParentWindow = this;

                NavigationPane.GotFocus += new RoutedEventHandler(NavigationPane_GotFocus);

                #region Track info

                ComboBoxItem ytFilter = FilterMusic;
                ComboBoxItem ytQuality = QualityDefault;
                foreach (ComboBoxItem cbi in YouTubeFilter.Items)
                {
                    if ((string)cbi.Tag == SettingsManager.YouTubeFilter)
                    {
                        ytFilter = cbi;
                        break;
                    }
                }
                foreach (ComboBoxItem cbi in YouTubeQuality.Items)
                {
                    if ((string)cbi.Tag == SettingsManager.YouTubeQuality)
                    {
                        ytQuality = cbi;
                        break;
                    }
                }
                YouTubeFilter.SelectedItem = ytFilter;
                YouTubeQuality.SelectedItem = ytQuality;

                #endregion

                #region List config events

                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.QueueListConfig != null)
                    SettingsManager.QueueListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged);
                if (SettingsManager.HistoryListConfig != null)
                    SettingsManager.HistoryListConfig.PropertyChanged += new PropertyChangedEventHandler(ViewDetailsConfig_PropertyChanged);

                #endregion

                #region Context menus

                addMenu = new ContextMenu();
                showMenu = new ContextMenu();
                toolsMenu = new ContextMenu();

                addMenuFile = new MenuItem();
                addMenuFile.Header = U.T("ToolbarAddTrack");
                addMenuFile.Click += AddFile_Clicked;

                addMenuFolder = new MenuItem();
                addMenuFolder.Header = U.T("ToolbarAddFolder");
                addMenuFolder.Click += AddFolder_Clicked;

                addMenuPlaylist = new MenuItem();
                addMenuPlaylist.Header = U.T("ToolbarAddPlaylist");
                addMenuPlaylist.Click += AddPlaylist_Clicked;

                addMenuRadioStation = new MenuItem();
                addMenuRadioStation.Header = U.T("ToolbarAddRadioStation");
                addMenuRadioStation.Click += OpenURL_Clicked;

                addMenuPlugin = new MenuItem();
                addMenuPlugin.Header = U.T("ToolbarAddApp");
                addMenuPlugin.Click += AddPlugin_Clicked;

                showMenuDetailsPane = new MenuItem();
                showMenuDetailsPane.Header = U.T("ToolbarDetailsPane");
                showMenuDetailsPane.IsCheckable = true;
                showMenuDetailsPane.Click += ToggleDetailsPane;

                showMenuMenuBar = new MenuItem();
                showMenuMenuBar.Header = U.T("ToolbarMenuBar");
                showMenuMenuBar.IsCheckable = true;
                showMenuMenuBar.Click += ToggleMenuBar;

                toolsMenuImporter = new MenuItem();
                toolsMenuImporter.Header = U.T("ToolbarImporter");
                toolsMenuImporter.Click += Importer_Clicked;

                toolsMenuExporter = new MenuItem();
                toolsMenuExporter.Header = U.T("ToolbarExporter");
                toolsMenuExporter.Click += Exporter_Clicked;

                toolsMenuGenerate = new MenuItem();
                toolsMenuGenerate.Header = U.T("ToolbarGeneratePlaylist");
                toolsMenuGenerate.Click += GeneratePlaylist_Clicked;

                addMenu.Items.Add(addMenuFile);
                addMenu.Items.Add(addMenuFolder);
                addMenu.Items.Add(addMenuPlaylist);
                addMenu.Items.Add(addMenuRadioStation);
                addMenu.Items.Add(addMenuPlugin);
                showMenu.Items.Add(showMenuMenuBar);
                showMenu.Items.Add(showMenuDetailsPane);
                toolsMenu.Items.Add(toolsMenuImporter);
                toolsMenu.Items.Add(toolsMenuExporter);
                toolsMenu.Items.Add(toolsMenuGenerate);
                addMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
                showMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
                toolsMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;

                listMenuAddToPlaylist.Header = U.T("MenuAddToPlaylist", "Header");
                listMenuDelete.Header = U.T("MenuDelete");
                listMenuDelete.Click += new RoutedEventHandler(listMenuDelete_Click);
                listMenuInfo.Header = U.T("MenuInfo");
                listMenuInfo.Click += new RoutedEventHandler(listMenuInfo_Click);
                listMenuPlay.Header = U.T("MenuPlay");
                listMenuPlay.Click += new RoutedEventHandler(listMenuPlay_Click);
                listMenuPlay.FontWeight = FontWeights.Bold;
                listMenuWatchOnYouTube.Header = U.T("MenuWatchOnYouTube");
                listMenuWatchOnYouTube.Click += new RoutedEventHandler(listMenuWatchOnYouTube_Click);
                listMenuListenOnSoundCloud.Header = U.T("MenuListenOnSoundCloud");
                listMenuListenOnSoundCloud.Click += new RoutedEventHandler(listMenuListenOnSoundCloud_Click);
                listMenuOpenFolder.Header = U.T("MenuOpenFolder");
                listMenuOpenFolder.Click += new RoutedEventHandler(listMenuOpenFolder_Click);
                listMenuShareSong.Header = U.T("MenuShareSong");
                listMenuShareSong.Click += new RoutedEventHandler(listMenuShareSong_Click);
                listMenuVisitWebsite.Header = U.T("MenuVisitWebsite", "Header");
                listMenuVisitWebsite.Click += new RoutedEventHandler(listMenuVisitWebsite_Click);
                listMenuQueue.Header = U.T("MenuQueue");
                listMenuQueue.Click += new RoutedEventHandler(listMenuQueue_Click);
                listMenuCopy.Header = U.T("MenuCopy");
                listMenuCopy.Click += new RoutedEventHandler(listMenuCopyMove_Click);
                listMenuMove.Header = U.T("MenuMove");
                listMenuMove.Click += new RoutedEventHandler(listMenuCopyMove_Click);
                listMenuRemove.Header = U.T("MenuRemove");
                listMenuRemove.Click += new RoutedEventHandler(listMenuRemove_Click);
                listMenuRemoveFromPlaylist.Header = U.T("MenuRemoveFromPlaylist", "Header");
                listMenuRemoveFromPlaylist.Visibility = System.Windows.Visibility.Collapsed;

                listMenuAddToNew = new MenuItem();
                listMenuAddToNew.Header = U.T("MenuCreateNew", "Header");
                listMenuAddToNew.FontStyle = FontStyles.Italic;
                listMenuAddToNew.Click += new RoutedEventHandler(listMenuAddToPlaylist_Click);
                listMenuAddToPlaylist.Items.Add(listMenuAddToNew);

                listMenu.Items.Add(listMenuPlay);
                listMenu.Items.Add(listMenuQueue);
                listMenu.Items.Add(new Separator());
                listMenu.Items.Add(listMenuAddToPlaylist);
                listMenu.Items.Add(listMenuRemoveFromPlaylist);
                listMenu.Items.Add(new Separator());
                listMenu.Items.Add(listMenuOpenFolder);
                listMenu.Items.Add(listMenuCopy);
                listMenu.Items.Add(listMenuMove);
                listMenu.Items.Add(listMenuRemove);
                listMenu.Items.Add(listMenuDelete);
                listMenu.Items.Add(listMenuFilesystemSeparator);
                listMenu.Items.Add(listMenuWatchOnYouTube);
                listMenu.Items.Add(listMenuListenOnSoundCloud);
                listMenu.Items.Add(listMenuVisitWebsite);
                listMenu.Items.Add(listMenuShareSong);
                listMenu.Items.Add(listMenuInfo);

                FileTracks.ContextMenu = listMenu;
                HistoryTracks.ContextMenu = listMenu;
                QueueTracks.ContextMenu = listMenu;
                RadioTracks.ContextMenu = listMenu;
                YouTubeTracks.ContextMenu = listMenu;
                SoundCloudTracks.ContextMenu = listMenu;

                #endregion

                #region List events

                PlaylistTrackLists = new Hashtable();

                YouTubeTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                YouTubeTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                YouTubeTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                YouTubeTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                YouTubeTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);

                SoundCloudTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                SoundCloudTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                SoundCloudTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                SoundCloudTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                SoundCloudTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);

                FileTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                FileTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                FileTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                FileTracks.FilesDropped += new FileDropEventHandler(TrackList_FilesDropped);
                FileTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);
                FileTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                FileTracks.FilterMatch = TrackList_SearchMatch;

                RadioTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                RadioTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                RadioTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                RadioTracks.FilesDropped += new FileDropEventHandler(TrackList_FilesDropped);
                RadioTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);
                RadioTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                RadioTracks.FilterMatch = TrackList_SearchMatch;

                DiscTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                DiscTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                DiscTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                DiscTracks.FilesDropped += new FileDropEventHandler(TrackList_FilesDropped);
                DiscTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);
                DiscTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                DiscTracks.FilterMatch = TrackList_SearchMatch;

                HistoryTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                HistoryTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                HistoryTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                HistoryTracks.FilesDropped += new FileDropEventHandler(TrackList_FilesDropped);
                HistoryTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);
                HistoryTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                HistoryTracks.FilterMatch = TrackList_SearchMatch;

                QueueTracks.SelectionChanged += new SelectionChangedEventHandler(TrackList_SelectionChanged);
                QueueTracks.MouseDoubleClick += new MouseButtonEventHandler(TrackList_MouseDoubleClick);
                QueueTracks.ContextMenuOpening += new ContextMenuEventHandler(TrackList_ContextMenuOpening);
                QueueTracks.FilesDropped += new FileDropEventHandler(TrackList_FilesDropped);
                QueueTracks.MoveItem += new MoveItemEventHandler(TrackList_MoveItem);
                QueueTracks.GotFocus += new RoutedEventHandler(TrackList_GotFocus);
                QueueTracks.FilterMatch = TrackList_SearchMatch;

                YouTubePlayerInterface ypi = new YouTubePlayerInterface();
                ypi.ErrorOccured += new ErrorEventHandler(YouTube_ErrorOccured);
                ypi.NoFlashDetected += new EventHandler(YouTube_NoFlashDetected);
                ypi.PlayerReady += new EventHandler(YouTube_PlayerReady);

                #endregion

                sourceModifiedDelay.Tick += new EventHandler(SourceModifiedDelay_Tick);
                sourceModifiedDelay.Interval = new TimeSpan(0, 0, 0, 1, 500);

                SettingsManager.PropertyChanged += new PropertyChangedWithValuesEventHandler(SettingsManager_PropertyChanged);
                ServiceManager.ModifyTracks += new EventHandler<ModifiedEventArgs>(ServiceManager_ModifyTracks);

                NavigationPane.CreateNewPlaylistETB.EnteredEditMode += new EventHandler(EditableTextBlock_EnteredEditMode);

                U.ListenForShortcut = true;

                SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);

                #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;
                    VerticalSplitter.Margin = new Thickness(-4,0,-4,0);
                    HorizontalSplitter.Background = SystemColors.ControlBrush;

                    InfoPaneBorder.BorderThickness = new Thickness(0);
                    TopToolbar.Style = null;
                    AddButton.Style = (Style)FindResource("ClassicToolbarButtonStyle");
                    ShowButton.Style = (Style)FindResource("ClassicToolbarButtonStyle");
                    ToolsButton.Style = (Style)FindResource("ClassicToolbarButtonStyle");
                    EqualizerButton.Style = (Style)FindResource("ClassicToolbarButtonStyle");
                    PreferencesButton.Style = (Style)FindResource("ClassicToolbarButtonStyle");
                    HelpButton.Style = (Style)FindResource("ClassicToolbarSmallButtonStyle");
                    DetailsPane.Style = (Style)FindResource("ClassicDetailsPaneStyle");

                    OuterBottomRight.BorderBrush = SystemColors.ControlLightLightBrush;
                    OuterTopLeft.BorderBrush = SystemColors.ControlDarkBrush;
                    InnerBottomRight.BorderBrush = SystemColors.ControlDarkBrush;
                    InnerTopLeft.BorderBrush = SystemColors.ControlLightLightBrush;

                    ControlPanel.SourceTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle");
                    ControlPanel.AboutTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle");
                    ControlPanel.ShortcutTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle");
                    ControlPanel.GeneralTitle.Style = (Style)FindResource("ClassicControlPanelTitleStyle");

                    YouTubeQuality.Style = (Style)FindResource("ClassicComboBoxStyle");
                    YouTubeFilter.Style = (Style)FindResource("ClassicComboBoxStyle");
                    VisualizerList.Style = (Style)FindResource("ClassicComboBoxStyle");

                    Utilities.DefaultAlbumArt = "/Platform/Windows 7/GUI/Images/AlbumArt/Classic.jpg";
                }

                #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

                // create glass effect
                RefreshGlassEffect();

                System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal);

                resortDelay.Interval = new TimeSpan(0, 0, 0, 0, 500);
                resortDelay.Tick += new EventHandler(ResortDelay_Tick);

                #region Manager events

                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 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);

                #endregion

                #region Web browser magic

                // WebBrowser will not load if it's not visible
                try
                {
                    // warning for fugliness
                    VideoContainer.Children.Remove(VideoContainer.Browser);
                    ControlPanel.Services.BrowserBorder.Child = null;
                    ContentContainer.Children.Add(VideoContainer.Browser);
                    ContentContainer.Children.Add(ControlPanel.Services.Browser);
                    ContentContainer.Children.Remove(VideoContainer.Browser);
                    ContentContainer.Children.Remove(ControlPanel.Services.Browser);
                    ControlPanel.Services.BrowserBorder.Child = ControlPanel.Services.Browser;
                    VideoContainer.Browser.Visibility = System.Windows.Visibility.Collapsed;
                }
                catch (Exception exc)
                {
                    U.L(LogLevel.Error, "MAIN", "There was a problem moving browsers into view for loading");
                    U.L(LogLevel.Error, "MAIN", exc.Message);
                }

                VideoContainer.Browser.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                VideoContainer.Browser.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                VideoContainer.Browser.Width = double.NaN;
                VideoContainer.Browser.Height = double.NaN;
                VideoContainer.Browser.ObjectForScripting = ypi;
                VideoContainer.NoVideoMessage.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                VideoContainer.NoVideoMessage.Visibility = System.Windows.Visibility.Visible;

                if (YouTubeManager.IsYouTube(SettingsManager.CurrentTrack))
                {
                    VideoContainer.BrowserVisibility = Visibility.Visible;
                }

                #endregion
            }));

            U.L(LogLevel.Debug, "MAIN", "Init settings manager");
            SettingsManager.Initialize();

            U.L(LogLevel.Debug, "MAIN", "Init service manager");
            ServiceManager.Initialize();

            #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, true);
                                Process.Start(assProcInfo);
                                break;

                            case TaskDialogResult.CustomButtonClicked:
                            case TaskDialogResult.No: // CustomButtonClicked doesn't work for some unknown reason
                                assProcInfo.Arguments = String.Format(assProcArgs, false);
                                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 Create playlists

            ThreadStart PlaylistThread = delegate()
            {
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
                {
                    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 == "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();

                    // fix null tracks
                    for (int i = 0; i < SettingsManager.Playlists.Count; i++)
                    {
                        var playlist = SettingsManager.Playlists[i];
                        bool allTracksNull = true;
                        foreach (TrackData t in playlist.Tracks)
                            if (t != null)
                            {
                                allTracksNull = false;
                                break;
                            }
                        if (allTracksNull) playlist.Tracks.Clear();
                    }

                    // create playlists
                    PlaylistManager.Initialize();

                    for (int i = 0; i < SettingsManager.Playlists.Count; i++)
                        CreatePlaylist(SettingsManager.Playlists[i], false);

                    PlaylistManager.PlaylistModified += new ModifiedEventHandler(PlaylistManager_PlaylistModified);
                    PlaylistManager.PlaylistRenamed += new RenamedEventHandler(PlaylistManager_PlaylistRenamed);

                    // if csn == playlist: select
                    if (SettingsManager.CurrentSelectedNavigation.StartsWith("Playlist:"))
                    {
                        string name = SettingsManager.CurrentSelectedNavigation.Split(new[] { ':' }, 2)[1];
                        foreach (TreeViewItem tvi in NavigationPane.Playlists.Items)
                        {
                            if ((string)tvi.Tag == name)
                            {
                                tvi.Focus();
                                break;
                            }
                        }
                    }
                }));
            };

            #endregion

            ThreadStart GUIThread = delegate()
            {
                // init media manager
                ThreadStart MediaManagerThread = delegate()
                {
                    Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
                    {
                        MediaManager.Initialize();
                        MediaManager.FetchCollectionCallback = FetchActiveTrackCollection;

                        // check if we have any command line arguments
                        U.L(LogLevel.Debug, "main", "Send any app arguments to media manager");
                        String[] arguments = Environment.GetCommandLineArgs();
                        if (arguments.Length > 1)
                        {
                            if (arguments[1] == "/play") MediaManager.Play();
                            else if (arguments[1] == "/pause") MediaManager.Pause();
                            else if (arguments[1] == "/stop") MediaManager.Stop();
                            else if (arguments[1] == "/next") MediaManager.Next(true);
                            else if (arguments[1] == "/previous") MediaManager.Previous();

                            else if (MediaManager.IsSupported(arguments[1]))
                                Open(arguments[1], true);

                            else if (PlaylistManager.IsSupported(arguments[1]))
                            {
                                PlaylistData pl = PlaylistManager.LoadPlaylist(arguments[1]);
                                if (pl != null)
                                {
                                    SettingsManager.CurrentSelectedNavigation = "Playlist:" + pl.Name;
                                    if (pl.Tracks.Count > 0)
                                    {
                                        MediaManager.Load(pl.Tracks[0]);
                                        MediaManager.Play();
                                    }
                                }
                            }
                        }
                    }));

                    SettingsManager.Sources.CollectionChanged +=
                        new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ControlPanel.SourceList.ItemsSource_CollectionChanged);
                };

                // init upgrade manager
                ThreadStart UpgradeManagerThread = delegate()
                {
                    UpgradeManager.Initialize(new TimeSpan(1, 0, 0));
                };

                // init filesystem manager
                ThreadStart FilesystemManagerThread = delegate()
                {
                    FilesystemManager.Initialize();
                    FilesystemManager.AddSystemFolders(true);
                };

                // calculate play time
                ThreadStart PTThread = delegate()
                {
                    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;
                };

                Thread mm_thread = new Thread(MediaManagerThread);
                Thread um_thread = new Thread(UpgradeManagerThread);
                Thread fm_thread = new Thread(FilesystemManagerThread);
                Thread pt_thread = new Thread(PTThread);
                mm_thread.Name = "Init Media Manager";
                um_thread.Name = "Init Upgrade Manager";
                fm_thread.Name = "Init Filesystem Manager";
                pt_thread.Name = "Playing Time Thread";
                mm_thread.Priority = ThreadPriority.BelowNormal;
                um_thread.Priority = ThreadPriority.BelowNormal;
                fm_thread.Priority = ThreadPriority.BelowNormal;
                pt_thread.Priority = ThreadPriority.BelowNormal;
                mm_thread.Start();
                um_thread.Start();
                fm_thread.Start();
                pt_thread.Start();

                #region Assign list configs

                Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
                {
                    FileTracks.Config = SettingsManager.FileListConfig;
                    RadioTracks.Config = SettingsManager.RadioListConfig;
                    DiscTracks.Config = SettingsManager.DiscListConfig;
                    HistoryTracks.Config = SettingsManager.HistoryListConfig;
                    QueueTracks.Config = SettingsManager.QueueListConfig;
                    YouTubeTracks.Config = SettingsManager.YouTubeListConfig;
                    SoundCloudTracks.Config = SettingsManager.SoundCloudListConfig;
                    ControlPanel.SourceList.Config = SettingsManager.SourceListConfig;
                    ControlPanel.Plugins.PluginList.Config = SettingsManager.PluginListConfig;

                    FileTracks.ItemsSource = SettingsManager.FileTracks;
                    RadioTracks.ItemsSource = SettingsManager.RadioTracks;
                    QueueTracks.ItemsSource = SettingsManager.QueueTracks;
                    HistoryTracks.ItemsSource = SettingsManager.HistoryTracks;
                    ControlPanel.SourceList.ItemsSource = SettingsManager.Sources;
                    ControlPanel.Plugins.PluginList.ItemsSource = SettingsManager.Plugins;
                    YouTubeTracks.Search(SettingsManager.YouTubeListConfig.Filter);
                    SoundCloudTracks.Search(SettingsManager.SoundCloudListConfig.Filter);

                    FileTracks.SelectIndices(SettingsManager.FileListConfig.SelectedIndices);
                    RadioTracks.SelectIndices(SettingsManager.RadioListConfig.SelectedIndices);
                    QueueTracks.SelectIndices(SettingsManager.QueueListConfig.SelectedIndices);
                    HistoryTracks.SelectIndices(SettingsManager.HistoryListConfig.SelectedIndices);
                    ControlPanel.SourceList.SelectIndices(SettingsManager.SourceListConfig.SelectedIndices);
                    YouTubeTracks.SelectIndices(SettingsManager.YouTubeListConfig.SelectedIndices);
                    SoundCloudTracks.SelectIndices(SettingsManager.SoundCloudListConfig.SelectedIndices);
                    for (int i = 0; i < SettingsManager.Playlists.Count; i++)
                    {
                        var p = SettingsManager.Playlists[i];
                        var vd = PlaylistTrackLists[p.Name] as ViewDetails;
                        if (vd != null)
                            vd.SelectIndices(p.ListConfig.SelectedIndices);
                    }
                }));

                SettingsManager.FileTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(FileTracks.ItemsSource_CollectionChanged);
                SettingsManager.RadioTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(RadioTracks.ItemsSource_CollectionChanged);
                SettingsManager.QueueTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(QueueTracks.ItemsSource_CollectionChanged);
                SettingsManager.HistoryTracks.CollectionChanged += new NotifyCollectionChangedEventHandler(HistoryTracks.ItemsSource_CollectionChanged);
                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);

                #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;

                #endregion

                Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
                {
                    PlaybackControls.VolumeSlide.Value = SettingsManager.Volume;

                    NavigationColumn.Width = new GridLength(SettingsManager.NavigationPaneWidth);
                    double h = SettingsManager.DetailsPaneHeight;
                    DetailsRow.Height = new GridLength(h);

                    UpdateVisibility("menubar");
                    UpdateVisibility("details");

                    ControlPanel.InitShortcuts();
                    System.Windows.Shell.JumpList.SetJumpList(Application.Current, jumpList);

                    RefreshStrings();
                }));

                PluginManager.Initialize();

                Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate()
                {
                    VisualizerList.ItemsSource = PluginManager.VisualizerSelector;
                    UpdateSelectedVisualizer();
                }));
            };

            Thread pl_thread = new Thread(PlaylistThread);
            Thread gui_thread = new Thread(GUIThread);
            pl_thread.Name = "Init Playlist Manager";
            gui_thread.Name = "Init managers and GUI";
            pl_thread.Priority = ThreadPriority.BelowNormal;
            gui_thread.Priority = ThreadPriority.BelowNormal;
            pl_thread.Start();
            gui_thread.Start();
        }