Exemple #1
0
        public CollectionPlaylistsViewModel(IContainerProvider container, IDialogService dialogService,
                                            IPlaybackService playbackService, IPlaylistService playlistService,
                                            IFileService fileService, IEventAggregator eventAggregator) : base(container)
        {
            this.dialogService   = dialogService;
            this.playlistService = playlistService;
            this.playbackService = playbackService;
            this.fileService     = fileService;
            this.eventAggregator = eventAggregator;
            this.dialogService   = dialogService;

            // Events
            this.playlistService.PlaylistFolderChanged += PlaylistService_PlaylistFolderChanged;
            this.playlistService.TracksAdded           += PlaylistService_TracksAdded;
            this.playlistService.TracksDeleted         += PlaylistService_TracksDeleted;

            // Commands
            this.RenameSelectedPlaylistCommand  = new DelegateCommand(async() => await this.RenameSelectedPlaylistAsync());
            this.DeletePlaylistCommand          = new DelegateCommand <PlaylistViewModel>(async(playlist) => await this.ConfirmDeletePlaylistAsync(playlist));
            this.ImportPlaylistsCommand         = new DelegateCommand(async() => await this.ImportPlaylistsAsync());
            this.AddPlaylistToNowPlayingCommand = new DelegateCommand(async() => await this.AddPlaylistToNowPlayingAsync());
            this.ShuffleSelectedPlaylistCommand = new DelegateCommand(async() => await this.ShuffleSelectedPlaylistAsync());
            this.LoadedCommand               = new DelegateCommand(async() => await this.LoadedCommandAsync());
            this.NewPlaylistCommand          = new DelegateCommand(async() => await this.ConfirmCreateNewPlaylistAsync());
            this.RemoveSelectedTracksCommand = new DelegateCommand(async() => await this.DeleteTracksFromPlaylistsAsync());

            this.DeleteSelectedPlaylistCommand = new DelegateCommand(async() =>
            {
                if (this.IsPlaylistSelected)
                {
                    await this.ConfirmDeletePlaylistAsync(this.SelectedPlaylist);
                }
            });

            // Settings changed
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableRating"))
                {
                    this.EnableRating = (bool)e.SettingValue;
                }

                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableLove"))
                {
                    this.EnableLove = (bool)e.SettingValue;
                }
            };

            // Load settings
            this.LeftPaneWidthPercent = SettingsClient.Get <int>("ColumnWidths", "PlaylistsLeftPaneWidthPercent");
        }
        public async Task <EqualizerPreset> GetSelectedPresetAsync()
        {
            var presets = await this.GetPresetsAsync();

            string          selectedPresetName = SettingsClient.Get <string>("Equalizer", "SelectedPreset");
            EqualizerPreset selectedPreset     = presets.Select((p) => p).Where((p) => p.Name == selectedPresetName).FirstOrDefault();

            if (selectedPreset == null)
            {
                selectedPreset = new EqualizerPreset(Defaults.ManualPresetName, false);
            }

            return(selectedPreset);
        }
Exemple #3
0
        private async void Initialize()
        {
            // PlayerFactory
            this.playerFactory = new PlayerFactory();

            // Settings
            this.SetPlaybackSettings();

            // Equalizer
            await this.SetIsEqualizerEnabledAsync(SettingsClient.Get <bool>("Equalizer", "IsEnabled"));

            // Queued tracks
            this.GetSavedQueuedTracks();
        }
        public CommonViewModelBase(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.container         = container;
            this.eventAggregator   = container.Resolve <IEventAggregator>();
            this.indexingService   = container.Resolve <IIndexingService>();
            this.playbackService   = container.Resolve <IPlaybackService>();
            this.searchService     = container.Resolve <ISearchService>();
            this.dialogService     = container.Resolve <IDialogService>();
            this.collectionService = container.Resolve <ICollectionService>();
            this.metadataService   = container.Resolve <IMetadataService>();
            this.i18nService       = container.Resolve <II18nService>();
            this.playlistService   = container.Resolve <IPlaylistService>();
            this.foldersService    = container.Resolve <IFoldersService>();

            // Commands
            this.ShowSelectedTrackInformationCommand = new DelegateCommand(() => this.ShowSelectedTrackInformation());
            this.SelectedTracksCommand = new DelegateCommand <object>((parameter) => this.SelectedTracksHandler(parameter));
            this.EditTracksCommand     = new DelegateCommand(() => this.EditSelectedTracks(), () => !this.IsIndexing);
            this.LoadedCommand         = new DelegateCommand(async() => await this.LoadedCommandAsync());
            this.UnloadedCommand       = new DelegateCommand(async() => await this.UnloadedCommandAsync());
            this.ShuffleAllCommand     = new DelegateCommand(() => this.playbackService.EnqueueAsync(true, false));

            // Events
            this.playbackService.PlaybackFailed      += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackPaused      += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackResumed     += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackStopped     += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackSuccess     += (_, __) => this.ShowPlayingTrackAsync();
            this.collectionService.CollectionChanged += async(_, __) => await this.FillListsAsync(); // Refreshes the lists when the Collection has changed

            this.foldersService.FoldersChanged += async(_, __) => await this.FillListsAsync();       // Refreshes the lists when marked folders have changed

            this.indexingService.RefreshLists += async(_, __) => await this.FillListsAsync();        // Refreshes the lists when the indexer has finished indexing

            this.indexingService.IndexingStarted += (_, __) => this.SetEditCommands();
            this.indexingService.IndexingStopped += (_, __) => this.SetEditCommands();
            this.searchService.DoSearch          += (searchText) => this.FilterLists();
            this.metadataService.RatingChanged   += MetadataService_RatingChangedAsync;
            this.metadataService.LoveChanged     += MetadataService_LoveChangedAsync;

            // Flags
            this.EnableRating = SettingsClient.Get <bool>("Behaviour", "EnableRating");
            this.EnableLove   = SettingsClient.Get <bool>("Behaviour", "EnableLove");

            // This makes sure the IsIndexing is correct even when this ViewModel is
            // created after the Indexer is started, and thus after triggering the
            // IndexingService.IndexerStarted event.
            this.SetEditCommands();
        }
Exemple #5
0
 private async void GetCheckBoxesAsync()
 {
     await Task.Run(() =>
     {
         this.checkBoxShowTrayIconChecked           = SettingsClient.Get <bool>("Behaviour", "ShowTrayIcon");
         this.checkBoxMinimizeToTrayChecked         = SettingsClient.Get <bool>("Behaviour", "MinimizeToTray");
         this.checkBoxCloseToTrayChecked            = SettingsClient.Get <bool>("Behaviour", "CloseToTray");
         this.checkBoxFollowTrackChecked            = SettingsClient.Get <bool>("Behaviour", "FollowTrack");
         this.checkBoxEnableRatingChecked           = SettingsClient.Get <bool>("Behaviour", "EnableRating");
         this.checkBoxEnableLoveChecked             = SettingsClient.Get <bool>("Behaviour", "EnableLove");
         this.checkBoxShowRemoveFromDiskChecked     = SettingsClient.Get <bool>("Behaviour", "ShowRemoveFromDisk");
         this.checkBoxSaveRatingInAudioFilesChecked = SettingsClient.Get <bool>("Behaviour", "SaveRatingToAudioFiles");
     });
 }
        private async void GetCheckBoxesAsync()
        {
            await Task.Run(() =>
            {
                this.checkBoxThemeChecked = SettingsClient.Get <bool>("Appearance", "EnableLightTheme");
                this.RaisePropertyChanged(nameof(this.CheckBoxThemeChecked));

                this.checkBoxWindowsColorChecked = SettingsClient.Get <bool>("Appearance", "FollowWindowsColor");
                this.RaisePropertyChanged(nameof(this.CheckBoxWindowsColorChecked));

                this.checkBoxAlbumCoverColorChecked = SettingsClient.Get <bool>("Appearance", "FollowAlbumCoverColor");
                this.RaisePropertyChanged(nameof(this.CheckBoxAlbumCoverColorChecked));
            });
        }
Exemple #7
0
        private void Window_StateChanged(object sender, System.EventArgs e)
        {
            if (this.WindowState == WindowState.Minimized)
            {
                if (SettingsClient.Get <bool>("Behaviour", "ShowTrayIcon") &
                    SettingsClient.Get <bool>("Behaviour", "MinimizeToTray"))
                {
                    // When minimizing to tray, hide this window from Taskbar and ALT-TAB menu.
                    this.ShowInTaskbar = false;

                    try
                    {
                        WindowUtils.HideWindowFromAltTab(this);
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not hide main window from ALT-TAB menu. Exception: {0}", ex.Message);
                    }
                }
            }
            else
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    try
                    {
                        WindowUtils.RemoveWindowCaption(this);
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not remove window caption. Exception: {0}", ex.Message);
                    }
                }

                // When restored, show this window in Taskbar and ALT-TAB menu.
                this.ShowInTaskbar = true;

                try
                {
                    WindowUtils.ShowWindowInAltTab(this);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not show main window in ALT-TAB menu. Exception: {0}", ex.Message);
                }
            }

            this.SetWindowBorder();
            this.shellService.SaveWindowState(this.WindowState);
        }
        protected void SetTrackOrder(string settingName)
        {
            TrackOrder savedTrackOrder = (TrackOrder)SettingsClient.Get<int>("Ordering", settingName);

            if ((!this.EnableRating & savedTrackOrder == TrackOrder.ByRating) | (!this.CanOrderByAlbum & savedTrackOrder == TrackOrder.ByAlbum))
            {
                this.TrackOrder = TrackOrder.Alphabetical;
            }
            else
            {
                // Only change the TrackOrder if it is not correct
                if (this.TrackOrder != savedTrackOrder) this.TrackOrder = savedTrackOrder;
            }
        }
Exemple #9
0
        public PlaylistViewModelBase(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.container       = container;
            this.playbackService = container.Resolve <IPlaybackService>();
            this.eventAggregator = container.Resolve <IEventAggregator>();
            this.searchService   = container.Resolve <ISearchService>();
            this.dialogService   = container.Resolve <IDialogService>();
            this.providerService = container.Resolve <IProviderService>();
            this.i18nService     = container.Resolve <II18nService>();

            // Commands
            this.PlaySelectedCommand          = new DelegateCommand(async() => await this.PlaySelectedAsync());
            this.PlayNextCommand              = new DelegateCommand(async() => await this.PlayNextAsync());
            this.AddTracksToNowPlayingCommand = new DelegateCommand(async() => await this.AddTracksToNowPlayingAsync());
            this.UpdateShowTrackArtCommand    = new DelegateCommand <bool?>((showTrackArt) =>
            {
                SettingsClient.Set <bool>("Appearance", "ShowTrackArtOnPlaylists", showTrackArt.Value, true);
            });

            // Settings
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableRating"))
                {
                    this.EnableRating = (bool)e.SettingValue;
                }

                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableLove"))
                {
                    this.EnableLove = (bool)e.SettingValue;
                }
            };

            // Events
            this.i18nService.LanguageChanged += (_, __) => this.RefreshLanguage();

            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Appearance", "ShowTrackArtOnPlaylists"))
                {
                    this.ShowTrackArt = (bool)e.SettingValue;
                    this.UpdateShowTrackArtAsync();
                }
            };

            // Settings
            this.ShowTrackArt = SettingsClient.Get <bool>("Appearance", "ShowTrackArtOnPlaylists");
        }
Exemple #10
0
        public TaskbarService(IPlaybackService playbackService)
        {
            this.playbackService = playbackService;

            this.ShowTaskBarItemInfoPause(false);  // When starting, we're not playing yet.

            this.playbackService.PlaybackFailed += (_, __) =>
            {
                this.Description = ProductInformation.ApplicationName;
                this.SetTaskbarProgressState(SettingsClient.Get <bool>("Playback", "ShowProgressInTaskbar"), this.playbackService.IsPlaying);
                this.ShowTaskBarItemInfoPause(false);
            };

            this.playbackService.PlaybackPaused += (_, __) =>
            {
                this.SetTaskbarProgressState(SettingsClient.Get <bool>("Playback", "ShowProgressInTaskbar"), this.playbackService.IsPlaying);
                this.ShowTaskBarItemInfoPause(false);
            };

            this.playbackService.PlaybackResumed += (_, __) =>
            {
                this.SetTaskbarProgressState(SettingsClient.Get <bool>("Playback", "ShowProgressInTaskbar"), this.playbackService.IsPlaying);
                this.ShowTaskBarItemInfoPause(true);
            };

            this.playbackService.PlaybackStopped += (_, __) =>
            {
                this.Description = ProductInformation.ApplicationName;
                this.SetTaskbarProgressState(false, false);
                this.ShowTaskBarItemInfoPause(false);
            };

            this.playbackService.PlaybackSuccess += (_, __) =>
            {
                if (!string.IsNullOrWhiteSpace(this.playbackService.CurrentTrack.Value.ArtistName) && !string.IsNullOrWhiteSpace(this.playbackService.CurrentTrack.Value.TrackTitle))
                {
                    this.Description = this.playbackService.CurrentTrack.Value.ArtistName + " - " + this.playbackService.CurrentTrack.Value.TrackTitle;
                }
                else
                {
                    this.Description = this.playbackService.CurrentTrack.Value.FileName;
                }

                this.SetTaskbarProgressState(SettingsClient.Get <bool>("Playback", "ShowProgressInTaskbar"), this.playbackService.IsPlaying);
                this.ShowTaskBarItemInfoPause(true);
            };

            this.playbackService.PlaybackProgressChanged += (_, __) => { this.ProgressValue = this.playbackService.Progress; };
        }
Exemple #11
0
        private async void AddArtworkInBackgroundAsync()
        {
            // First, add artwork from file.
            await this.AddArtworkInBackgroundAsync(1);

            // Next, add artwork from the Internet, if the user has chosen to do so.
            if (SettingsClient.Get <bool>("Covers", "DownloadMissingAlbumCovers"))
            {
                // Add artwork from the Internet.
                await this.AddArtworkInBackgroundAsync(2);
            }

            // We don't need to scan for artwork anymore
            await this.trackRepository.DisableNeedsAlbumArtworkIndexingForAllTracksAsync();
        }
 private void SetPlaybackSettings()
 {
     this.isLoadingSettings       = true;
     this.UseAllAvailableChannels = SettingsClient.Get <bool>("Playback", "WasapiUseAllAvailableChannels");
     this.LoopMode  = (LoopMode)SettingsClient.Get <int>("Playback", "LoopMode");
     this.Latency   = SettingsClient.Get <int>("Playback", "AudioLatency");
     this.Volume    = SettingsClient.Get <float>("Playback", "Volume");
     this.mute      = SettingsClient.Get <bool>("Playback", "Mute");
     this.shuffle   = SettingsClient.Get <bool>("Playback", "Shuffle");
     this.EventMode = false;
     //this.EventMode = SettingsClient.Get<bool>("Playback", "WasapiEventMode");
     //this.ExclusiveMode = false;
     this.ExclusiveMode     = SettingsClient.Get <bool>("Playback", "WasapiExclusiveMode");
     this.isLoadingSettings = false;
 }
        public TracksViewModelBaseWithTrackArt(IContainerProvider container) : base(container)
        {
            // Settings changed
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Appearance", "ShowTrackArtOnPlaylists"))
                {
                    this.ShowTrackArt = (bool)e.SettingValue;
                    this.UpdateShowTrackArtAsync();
                }
            };

            // Load settings
            this.ShowTrackArt = SettingsClient.Get <bool>("Appearance", "ShowTrackArtOnPlaylists");
        }
Exemple #14
0
        public CollectionAlbumsViewModel(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.indexingService   = container.Resolve <IIndexingService>();
            this.collectionService = container.Resolve <ICollectionService>();
            this.metadataService   = container.Resolve <IMetadataService>();
            this.eventAggregator   = container.Resolve <IEventAggregator>();

            // Settings
            SettingsClient.SettingChanged += async(_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableRating"))
                {
                    this.EnableRating = (bool)e.SettingValue;
                    this.SetTrackOrder("AlbumsTrackOrder");
                    await this.GetTracksAsync(null, null, this.SelectedAlbumIds, this.TrackOrder);
                }

                if (SettingsClient.IsSettingChanged(e, "Behaviour", "EnableLove"))
                {
                    this.EnableLove = (bool)e.SettingValue;
                    this.SetTrackOrder("AlbumsTrackOrder");
                    await this.GetTracksAsync(null, null, this.SelectedAlbumIds, this.TrackOrder);
                }
            };

            // Events
            this.metadataService.MetadataChanged   += MetadataChangedHandlerAsync;
            this.indexingService.AlbumArtworkAdded += async(_, e) => await this.RefreshArtworkAsync(e.AlbumIds);

            //  Commands
            this.ToggleAlbumOrderCommand             = new DelegateCommand(async() => await this.ToggleAlbumOrderAsync());
            this.ToggleTrackOrderCommand             = new DelegateCommand(async() => await this.ToggleTrackOrderAsync());
            this.RemoveSelectedTracksCommand         = new DelegateCommand(async() => await this.RemoveTracksFromCollectionAsync(this.SelectedTracks), () => !this.IsIndexing);
            this.RemoveSelectedTracksFromDiskCommand = new DelegateCommand(async() => await this.RemoveTracksFromDiskAsync(this.SelectedTracks), () => !this.IsIndexing);

            // Set the initial AlbumOrder
            this.AlbumOrder = (AlbumOrder)SettingsClient.Get <int>("Ordering", "AlbumsAlbumOrder");

            // Set the initial TrackOrder
            this.SetTrackOrder("AlbumsTrackOrder");

            // Set width of the panels
            this.LeftPaneWidthPercent = SettingsClient.Get <int>("ColumnWidths", "AlbumsLeftPaneWidthPercent");

            // Cover size
            this.SetCoversizeAsync((CoverSizeType)SettingsClient.Get <int>("CoverSizes", "AlbumsCoverSize"));
        }
        protected override void InitializeShell(Window shell)
        {
            LogClient.Info($"### STARTING {ProductInformation.ApplicationName}, version {ProcessExecutable.AssemblyVersion()}, IsPortable = {SettingsClient.BaseGet<bool>("Configuration", "IsPortable")}, Windows version = {EnvironmentUtils.GetFriendlyWindowsVersion()} ({EnvironmentUtils.GetInternalWindowsVersion()}), IsWindows10 = {Core.Base.Constants.IsWindows10} ###");

            // Handler for unhandled AppDomain exceptions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            this.InitializeWcfServices();

            Current.MainWindow = shell;

            bool showOobe = SettingsClient.Get <bool>("General", "ShowOobe");

            if (showOobe)
            {
                var oobeWin = Container.Resolve <Oobe>();

                // These 2 lines are required to set the RegionManager of the child window.
                // If we don't do this, regions on child windows are never known by the Shell
                // RegionManager and navigation doesn't work
                RegionManager.SetRegionManager(oobeWin, Container.Resolve <IRegionManager>());
                RegionManager.UpdateRegions();

                // Show the OOBE window. Don't tell the Indexer to start.
                // It will get a signal to start when the OOBE window closes.
                LogClient.Info("Showing Oobe screen");

                // Disable shutdown when the dialogs close
                Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

                // Show as a dialog. This prevents further code execution until the dialog is closed.
                oobeWin.ShowDialog();
                oobeWin.ForceActivate();
            }

            // Re-enable normal shutdown mode
            Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

            // Show the main window
            LogClient.Info("Showing Main screen");
            shell.Show();

            // We're not showing the OOBE screen, tell the IndexingService to start.
            if (!showOobe)
            {
                Container.Resolve <IIndexingService>().RefreshCollectionAsync();
            }
        }
Exemple #16
0
        public void CheckIfTabletMode(bool isInitializing)
        {
            if (this.windowsIntegrationService.IsTabletModeEnabled)
            {
                // Always revert to full player when tablet mode is enabled. Maximizing will be done by Windows.
                this.SetPlayer(false, (MiniPlayerType)SettingsClient.Get <int>("General", "MiniPlayerType"), isInitializing);
            }
            else
            {
                bool isMiniPlayer = SettingsClient.Get <bool>("General", "IsMiniPlayer");
                bool isMaximized  = SettingsClient.Get <bool>("FullPlayer", "IsMaximized");
                this.WindowStateChangeRequested(this, new WindowStateChangeRequestedEventArgs(isMaximized & !isMiniPlayer ? WindowState.Maximized : WindowState.Normal));

                this.SetPlayer(isMiniPlayer, (MiniPlayerType)SettingsClient.Get <int>("General", "MiniPlayerType"), isInitializing);
            }
        }
        public async Task <AudioDevice> GetSavedAudioDeviceAsync()
        {
            string savedAudioDeviceId = SettingsClient.Get <string>("Playback", "AudioDevice");

            IList <AudioDevice> audioDevices = await this.GetAllAudioDevicesAsync();

            AudioDevice savedDevice = audioDevices.Where(x => x.DeviceId.Equals(savedAudioDeviceId)).FirstOrDefault();

            if (savedDevice == null)
            {
                LogClient.Warning($"Audio device with deviceId={savedAudioDeviceId} could not be found. Using default device instead.");
                savedDevice = this.CreateDefaultAudioDevice();
            }

            return(savedDevice);
        }
        private async void GetCheckBoxesAsync()
        {
            await Task.Run(() =>
            {
                // Change the backing field, not the property. Otherwise the confirmation popup is shown when the screen is constructed.
                this.checkBoxWasapiExclusiveModeChecked = SettingsClient.Get <bool>("Playback", "WasapiExclusiveMode");
                OnPropertyChanged(() => this.CheckBoxWasapiExclusiveModeChecked);

                this.CheckBoxShowNotificationWhenPlayingChecked              = SettingsClient.Get <bool>("Behaviour", "ShowNotificationWhenPlaying");
                this.CheckBoxShowNotificationWhenPausingChecked              = SettingsClient.Get <bool>("Behaviour", "ShowNotificationWhenPausing");
                this.CheckBoxShowNotificationWhenResumingChecked             = SettingsClient.Get <bool>("Behaviour", "ShowNotificationWhenResuming");
                this.CheckBoxShowNotificationControlsChecked                 = SettingsClient.Get <bool>("Behaviour", "ShowNotificationControls");
                this.CheckBoxShowProgressInTaskbarChecked                    = SettingsClient.Get <bool>("Playback", "ShowProgressInTaskbar");
                this.CheckBoxShowNotificationOnlyWhenPlayerNotVisibleChecked = SettingsClient.Get <bool>("Behaviour", "ShowNotificationOnlyWhenPlayerNotVisible");
            });
        }
        private async void GetCheckBoxesAsync()
        {
            await Task.Run(() =>
            {
                this.checkBoxDownloadArtistInformationChecked = SettingsClient.Get <bool>("Lastfm", "DownloadArtistInformation");
                this.checkBoxDownloadLyricsChecked            = SettingsClient.Get <bool>("Lyrics", "DownloadLyrics");

                string lyricsProviders = SettingsClient.Get <string>("Lyrics", "Providers");

                this.checkBoxChartLyricsChecked   = lyricsProviders.ToLower().Contains("chartlyrics");
                this.checkBoxLoloLyricsChecked    = lyricsProviders.ToLower().Contains("lololyrics");
                this.checkBoxMetroLyricsChecked   = lyricsProviders.ToLower().Contains("metrolyrics");
                this.checkBoxXiamiLyricsChecked   = lyricsProviders.ToLower().Contains("xiamilyrics");
                this.checkBoxNeteaseLyricsChecked = lyricsProviders.ToLower().Contains("neteaselyrics");
            });
        }
Exemple #20
0
        private void CheckIfTabletMode()
        {
            if (this.windowsIntegrationService.IsTabletModeEnabled)
            {
                // Always revert to full player when tablet mode is enabled. Maximizing will be done by Windows.
                this.SetPlayer(false, (MiniPlayerType)SettingsClient.Get <int>("General", "MiniPlayerType"));
            }
            else
            {
                bool isMiniPlayer = SettingsClient.Get <bool>("General", "IsMiniPlayer");
                bool isMaximized  = SettingsClient.Get <bool>("FullPlayer", "IsMaximized");
                this.WindowState = isMaximized & !isMiniPlayer ? WindowState.Maximized : WindowState.Normal;

                this.SetPlayer(isMiniPlayer, (MiniPlayerType)SettingsClient.Get <int>("General", "MiniPlayerType"));
            }
        }
Exemple #21
0
 private void SaveWindowLocation()
 {
     if (this.canSaveWindowGeometry)
     {
         if (SettingsClient.Get <bool>("General", "IsMiniPlayer"))
         {
             SettingsClient.Set <int>("MiniPlayer", "Top", Convert.ToInt32(this.Top));
             SettingsClient.Set <int>("MiniPlayer", "Left", Convert.ToInt32(this.Left));
         }
         else if (!SettingsClient.Get <bool>("General", "IsMiniPlayer") & !(this.WindowState == WindowState.Maximized))
         {
             SettingsClient.Set <int>("FullPlayer", "Top", Convert.ToInt32(this.Top));
             SettingsClient.Set <int>("FullPlayer", "Left", Convert.ToInt32(this.Left));
         }
     }
 }
        private void Initialize()
        {
            // Commands
            this.ShowSelectedTrackInformationCommand = new DelegateCommand(() => this.ShowSelectedTrackInformation());
            this.SelectedTracksCommand = new DelegateCommand <object>((parameter) => this.SelectedTracksHandler(parameter));
            this.EditTracksCommand     = new DelegateCommand(() => this.EditSelectedTracks(), () => !this.IsIndexing);
            this.LoadedCommand         = new DelegateCommand(async() => await this.LoadedCommandAsync());
            this.ShuffleAllCommand     = new DelegateCommand(() => this.playbackService.ShuffleAllAsync());

            // Events
            this.playbackService.PlaybackFailed  += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackPaused  += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackResumed += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackStopped += (_, __) => this.ShowPlayingTrackAsync();
            this.playbackService.PlaybackSuccess += (_) => this.ShowPlayingTrackAsync();

            this.collectionService.CollectionChanged += async(_, __) => await this.FillListsAsync();  // Refreshes the lists when the Collection has changed

            this.playlistService.PlaylistAdded    += (_) => this.GetContextMenuPlaylistsAsync();
            this.playlistService.PlaylistsDeleted += (_) => this.GetContextMenuPlaylistsAsync();

            this.indexingService.RefreshLists += async(_, __) => await this.FillListsAsync();  // Refreshes the lists when the indexer has finished indexing

            this.indexingService.IndexingStarted += (_, __) => this.SetEditCommands();
            this.indexingService.IndexingStopped += (_, __) => this.SetEditCommands();

            this.searchService.DoSearch += (searchText) => { if (this.IsActive)
                                                             {
                                                                 this.FilterLists();
                                                             }
            };

            this.metadataService.RatingChanged += MetadataService_RatingChangedAsync;
            this.metadataService.LoveChanged   += MetadataService_LoveChangedAsync;

            // Flags
            this.EnableRating = SettingsClient.Get <bool>("Behaviour", "EnableRating");
            this.EnableLove   = SettingsClient.Get <bool>("Behaviour", "EnableLove");

            // This makes sure the IsIndexing is correct even when this ViewModel is
            // created after the Indexer is started, and thus after triggering the
            // IndexingService.IndexerStarted event.
            this.SetEditCommands();

            // Initialize the playlists in the ContextMenu
            this.GetContextMenuPlaylistsAsync();
        }
        public CollectionAlbumsViewModel(IUnityContainer container) : base(container)
        {
            // Dependency injection
            this.indexingService   = container.Resolve <IIndexingService>();
            this.collectionService = container.Resolve <ICollectionService>();
            this.metadataService   = container.Resolve <IMetadataService>();
            this.eventAggregator   = container.Resolve <IEventAggregator>();

            // Events
            this.metadataService.MetadataChanged += MetadataChangedHandlerAsync;
            this.indexingService.RefreshArtwork  += async(_, __) => await this.collectionService.RefreshArtworkAsync(this.Albums);

            this.eventAggregator.GetEvent <SettingEnableRatingChanged>().Subscribe(async(enableRating) =>
            {
                this.EnableRating = enableRating;
                this.SetTrackOrder("AlbumsTrackOrder");
                await this.GetTracksAsync(null, null, this.SelectedAlbums, this.TrackOrder);
            });

            this.eventAggregator.GetEvent <SettingEnableLoveChanged>().Subscribe(async(enableLove) =>
            {
                this.EnableLove = enableLove;
                this.SetTrackOrder("AlbumsTrackOrder");
                await this.GetTracksAsync(null, null, this.SelectedAlbums, this.TrackOrder);
            });

            //  Commands
            this.ToggleAlbumOrderCommand             = new DelegateCommand(async() => await this.ToggleAlbumOrderAsync());
            this.ToggleTrackOrderCommand             = new DelegateCommand(async() => await this.ToggleTrackOrderAsync());
            this.RemoveSelectedTracksCommand         = new DelegateCommand(async() => await this.RemoveTracksFromCollectionAsync(this.SelectedTracks), () => !this.IsIndexing);
            this.RemoveSelectedTracksFromDiskCommand = new DelegateCommand(async() => await this.RemoveTracksFromDiskAsync(this.SelectedTracks), () => !this.IsIndexing);

            // Set the initial AlbumOrder
            this.AlbumOrder = (AlbumOrder)SettingsClient.Get <int>("Ordering", "AlbumsAlbumOrder");

            // Set the initial TrackOrder
            this.SetTrackOrder("AlbumsTrackOrder");

            // Subscribe to Events and Commands on creation
            this.Subscribe();

            // Set width of the panels
            this.LeftPaneWidthPercent = SettingsClient.Get <int>("ColumnWidths", "AlbumsLeftPaneWidthPercent");

            // Cover size
            this.SetCoversizeAsync((CoverSizeType)SettingsClient.Get <int>("CoverSizes", "AlbumsCoverSize"));
        }
        public NowPlayingScreenViewModel(IRegionManager regionManager, IPlaybackService playbackService)
        {
            this.regionManager   = regionManager;
            this.playbackService = playbackService;

            if (SettingsClient.Get <bool>("Startup", "ShowLastSelectedPage"))
            {
                SelectedNowPlayingPage page = (SelectedNowPlayingPage)SettingsClient.Get <int>("FullPlayer", "SelectedNowPlayingPage");

                switch (page)
                {
                case SelectedNowPlayingPage.ShowCase:
                    this.isShowCaseVisible = true;
                    break;

                case SelectedNowPlayingPage.Playlist:
                    this.isPlaylistVisible = true;
                    break;

                case SelectedNowPlayingPage.Lyrics:
                    this.isLyricsVisible = true;
                    break;

                case SelectedNowPlayingPage.ArtistInformation:
                    this.isArtistInformationVisible = true;
                    break;
                }
            }
            else
            {
                this.isPlaylistVisible = true;
            }

            this.playbackService.PlaybackSuccess += (_) => this.SetNowPlaying();

            this.NowPlayingScreenShowcaseButtonCommand          = new DelegateCommand(() => this.SetShowCase());
            this.NowPlayingScreenPlaylistButtonCommand          = new DelegateCommand(() => this.SetPlaylist());
            this.NowPlayingScreenLyricsButtonCommand            = new DelegateCommand(() => this.SetLyrics());
            this.NowPlayingScreenArtistInformationButtonCommand = new DelegateCommand(() => this.SetArtistInformation());

            this.LoadedCommand = new DelegateCommand(() => this.SetNowPlaying());

            ApplicationCommands.NowPlayingScreenShowcaseButtonCommand.RegisterCommand(this.NowPlayingScreenShowcaseButtonCommand);
            ApplicationCommands.NowPlayingScreenPlaylistButtonCommand.RegisterCommand(this.NowPlayingScreenPlaylistButtonCommand);
            ApplicationCommands.NowPlayingScreenLyricsButtonCommand.RegisterCommand(this.NowPlayingScreenLyricsButtonCommand);
            ApplicationCommands.NowPlayingScreenArtistInformationButtonCommand.RegisterCommand(this.NowPlayingScreenArtistInformationButtonCommand);
        }
Exemple #25
0
 private void Shell_Restored(object sender, EventArgs e)
 {
     // This workaround is needed because when executing the following
     // sequence, the window is restored to the Restore Position of
     // the Mini Player: Maximize, Mini Player, Full Player, Restore.
     // That's because the property RestoreBounds of this window is updated
     // with the coordinates of the Mini Player when switching to the Mini
     // Player. Returning to the full player doesn't update RestoreBounds,
     // because the full player is still maximized at that point.
     this.SetGeometry(
         SettingsClient.Get <int>("FullPlayer", "Top"),
         SettingsClient.Get <int>("FullPlayer", "Left"),
         SettingsClient.Get <int>("FullPlayer", "Width"),
         SettingsClient.Get <int>("FullPlayer", "Height"),
         Constants.DefaultShellTop,
         Constants.DefaultShellLeft);
 }
        public async Task ShowNotificationAsync()
        {
            if (this.notification != null)
            {
                this.notification.DoubleClicked -= ShowMainWindow;
            }

            try
            {
                if (this.notification != null)
                {
                    this.notification.Disable();
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Error while trying to disable the notification. Exception: {0}", ex.Message);
            }

            try
            {
                byte[] artworkData = null;

                if (this.playbackService.HasCurrentTrack)
                {
                    artworkData = await this.metadataService.GetArtworkAsync(this.playbackService.CurrentTrack.Value.Path);
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    this.notification = new NotificationWindow(this.playbackService.CurrentTrack.Value,
                                                               artworkData,
                                                               (NotificationPosition)SettingsClient.Get <int>("Behaviour", "NotificationPosition"),
                                                               SettingsClient.Get <bool>("Behaviour", "ShowNotificationControls"),
                                                               SettingsClient.Get <int>("Behaviour", "NotificationAutoCloseSeconds"));

                    this.notification.DoubleClicked += ShowMainWindow;

                    this.notification.Show();
                });
            }
            catch (Exception ex)
            {
                LogClient.Error("Error while trying to show the notification. Exception: {0}", ex.Message);
            }
        }
Exemple #27
0
        public void RefreshNotes()
        {
            this.Notes = new ObservableCollection <NoteViewModel>();

            string formatDate = "D";
            string text       = "";

            if (this.searchService.SearchText != null)
            {
                text = this.searchService.SearchText.Trim();
            }

            // Make sure there is a notebook selected
            if (this.SelectedNotebook == null)
            {
                this.SetDefaultSelectedNotebook();
            }

            this.Notes.Clear();

            foreach (Note note in this.noteService.GetNotes(new Notebook
            {
                Id = SelectedNotebook.Id,
                Title = SelectedNotebook.Title,
                CreationDate = SelectedNotebook.CreationDate.Ticks
            }, text, ref this.total, SettingsClient.Get <bool>("Appearance", "SortByModificationDate"), this.NoteFilter))
            {
                this.Notes.Add(new NoteViewModel
                {
                    Title                      = note.Title,
                    Id                         = note.Id,
                    NotebookId                 = note.NotebookId,
                    OpenDate                   = new DateTime(note.OpenDate),
                    OpenDateText               = DateUtils.DateDifference(new DateTime(note.OpenDate), DateTime.Now, formatDate, false),
                    ModificationDate           = new DateTime(note.ModificationDate),
                    Flagged                    = note.Flagged == 1 ? true : false,
                    ModificationDateText       = DateUtils.DateDifference(new DateTime(note.ModificationDate), DateTime.Now, formatDate, false),
                    ModificationDateTextSimple = DateUtils.DateDifference(new DateTime(note.ModificationDate), DateTime.Now, formatDate, true)
                });
            }

            // Because we cannot pass Property "Total" by reference, we need to force a refresh.
            OnPropertyChanged <int>(() => this.Total);

            this.eventAggregator.GetEvent <CountNotesEvent>().Publish("");
        }
        private async void AddArtworkInBackgroundAsync()
        {
            // First, add artwork from file.
            await this.AddArtworkInBackgroundAsync(1);

            // Next, add artwork from the Internet, if the user has chosen to do so.
            if (SettingsClient.Get <bool>("Covers", "DownloadMissingAlbumCovers"))
            {
                // Add artwork from the Internet.
                await this.AddArtworkInBackgroundAsync(2);
            }
            else
            {
                // Don't add artwork from the Internet. Mark all albums as indexed.
                await this.MarkAllAlbumsAsIndexed();
            }
        }
Exemple #29
0
        private void SetFullPlayer()
        {
            this.isMiniPlayerActive = false;

            this.PlaylistVisibilityChanged(this, new PlaylistVisibilityChangedEventArgs()
            {
                IsPlaylistVisible = false
            });

            this.ResizeModeChanged(this, new ResizeModeChangedEventArgs()
            {
                ResizeMode = ResizeMode.CanResize
            });
            this.ShowWindowControlsChanged(this, new ShowWindowControlsChangedEventArgs()
            {
                ShowWindowControls = true
            });

            if (SettingsClient.Get <bool>("FullPlayer", "IsMaximized"))
            {
                this.WindowStateChanged(this, new WindowStateChangedEventArgs()
                {
                    WindowState = WindowState.Maximized
                });
            }
            else
            {
                this.WindowStateChanged(this, new WindowStateChangedEventArgs()
                {
                    WindowState = WindowState.Normal
                });
                this.GeometryChanged(this, new GeometryChangedEventArgs()
                {
                    Top  = SettingsClient.Get <int>("FullPlayer", "Top"),
                    Left = SettingsClient.Get <int>("FullPlayer", "Left"),
                    Size = new Size(SettingsClient.Get <int>("FullPlayer", "Width"), SettingsClient.Get <int>("FullPlayer", "Height"))
                });
            }

            // Set MinWidth and MinHeight AFTER SetGeometry(). This prevents flicker.
            this.MinimumSizeChanged(this, new MinimumSizeChangedEventArgs()
            {
                MinimumSize = new Size(0, 0)
            });
        }
Exemple #30
0
 private void SetWindowPositionLockedFromSettings()
 {
     // Only lock position when the mini player is active
     if (this.isMiniPlayerActive)
     {
         this.IsMovableChanged(this, new IsMovableChangedEventArgs()
         {
             IsMovable = !SettingsClient.Get <bool>("Behaviour", "MiniPlayerPositionLocked")
         });
     }
     else
     {
         this.IsMovableChanged(this, new IsMovableChangedEventArgs()
         {
             IsMovable = true
         });
     }
 }