/Application/Core/SettingsManager.cs
C# | 1742 lines | 1186 code | 166 blank | 390 comment | 51 complexity | 74035fbbcacc701ba0931287a1453647 MD5 | raw file
- /**
- * SettingsManager.cs
- *
- * Takes care of initializing settings during first run.
- * The file also contains all data structures used to store
- * data of Stoffi.
- *
- * * * * * * * * *
- *
- * Copyright 2012 Simplare
- *
- * This code is part of the Stoffi Music Player Project.
- * Visit our website at: stoffiplayer.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 3 of the License, or (at your option) any later version.
- *
- * See stoffiplayer.com/license for more information.
- **/
-
- using System;
- using System.Collections.Specialized;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Globalization;
- using System.Xml;
- using System.Xml.Serialization;
-
- namespace Stoffi
- {
- /// <summary>
- /// Represents a manager that takes care of all
- /// application settings.
- /// </summary>
- public static class SettingsManager
- {
- #region Members
-
- private static double bufferSize = 0;
- private static bool isInitialized = false;
-
- #endregion
-
- #region Properties
-
- /// <summary>
- /// Gets whether the manager has been initialized or not.
- /// </summary>
- public static bool IsInitialized { get { return isInitialized; } private set { isInitialized = value; } }
-
- /// <summary>
- /// Gets the culture corresponding to Language.
- /// </summary>
- public static CultureInfo Culture
- {
- get { return CultureInfo.GetCultureInfo(Language); }
- }
-
- #region GUI
-
- /// <summary>
- /// Gets or sets the width of the main window
- /// </summary>
- public static double WinWidth
- {
- get { return Properties.Settings.Default.WinWidth; }
- set
- {
- object old = Properties.Settings.Default.WinWidth;
- Properties.Settings.Default.WinWidth = value;
- DispatchPropertyChanged("WinWidth", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the height of the main window
- /// </summary>
- public static double WinHeight
- {
- get { return Properties.Settings.Default.WinHeight; }
- set
- {
- object old = Properties.Settings.Default.WinHeight;
- Properties.Settings.Default.WinHeight = value;
- DispatchPropertyChanged("WinHeight", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the left position of the main window
- /// </summary>
- public static double WinLeft
- {
- get { return Properties.Settings.Default.WinLeft; }
- set
- {
- object old = Properties.Settings.Default.WinLeft;
- Properties.Settings.Default.WinLeft = value;
- DispatchPropertyChanged("WinLeft", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the top position of the main window
- /// </summary>
- public static double WinTop
- {
- get { return Properties.Settings.Default.WinTop; }
- set
- {
- object old = Properties.Settings.Default.WinTop;
- Properties.Settings.Default.WinTop = value;
- DispatchPropertyChanged("WinTop", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the state of the main window
- /// </summary>
- public static string WinState
- {
- get { return Properties.Settings.Default.WinState; }
- set
- {
- object old = Properties.Settings.Default.WinState;
- Properties.Settings.Default.WinState = value;
- DispatchPropertyChanged("WinState", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the height of the equalizer window
- /// </summary>
- public static double EqualizerHeight
- {
- get { return Properties.Settings.Default.EqualizerHeight; }
- set
- {
- object old = Properties.Settings.Default.EqualizerHeight;
- Properties.Settings.Default.EqualizerHeight = value;
- DispatchPropertyChanged("EqualizerHeight", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the width of the equalizer window
- /// </summary>
- public static double EqualizerWidth
- {
- get { return Properties.Settings.Default.EqualizerWidth; }
- set
- {
- object old = Properties.Settings.Default.EqualizerWidth;
- Properties.Settings.Default.EqualizerWidth = value;
- DispatchPropertyChanged("EqualizerWidth", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the left position of the equalizer window
- /// </summary>
- public static double EqualizerLeft
- {
- get { return Properties.Settings.Default.EqualizerLeft; }
- set
- {
- object old = Properties.Settings.Default.EqualizerLeft;
- Properties.Settings.Default.EqualizerLeft = value;
- DispatchPropertyChanged("EqualizerLeft", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the top position of the equalizer window
- /// </summary>
- public static double EqualizerTop
- {
- get { return Properties.Settings.Default.EqualizerTop; }
- set
- {
- object old = Properties.Settings.Default.EqualizerTop;
- Properties.Settings.Default.EqualizerTop = value;
- DispatchPropertyChanged("EqualizerTop", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the currently selected navigation
- /// </summary>
- public static string CurrentSelectedNavigation
- {
- get { return Properties.Settings.Default.CurrentSelectedNavigation; }
- set
- {
- object old = Properties.Settings.Default.CurrentSelectedNavigation;
- Properties.Settings.Default.CurrentSelectedNavigation = value;
- DispatchPropertyChanged("CurrentSelectedNavigation", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the width of the navigation pane
- /// </summary>
- public static double NavigationPaneWidth
- {
- get { return Properties.Settings.Default.NavigationPaneWidth; }
- set
- {
- object old = Properties.Settings.Default.NavigationPaneWidth;
- Properties.Settings.Default.NavigationPaneWidth = value;
- DispatchPropertyChanged("NavigationPaneWidth", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the height of the details pane
- /// </summary>
- public static double DetailsPaneHeight
- {
- get { return Properties.Settings.Default.DetailsPaneHeight; }
- set
- {
- object old = Properties.Settings.Default.DetailsPaneHeight;
- Properties.Settings.Default.DetailsPaneHeight = value;
- DispatchPropertyChanged("DetailsPaneHeight", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets whether the details pane is visible
- /// </summary>
- public static bool DetailsPaneVisible
- {
- get { return Properties.Settings.Default.DetailsPaneVisibile; }
- set
- {
- bool same = value == Properties.Settings.Default.DetailsPaneVisibile;
- Properties.Settings.Default.DetailsPaneVisibile = value;
- object newValue = (object)value;
- object oldValue = same ? newValue : (object)Properties.Settings.Default.DetailsPaneVisibile;
- DispatchPropertyChanged("DetailsPaneVisibile", oldValue, newValue);
- }
- }
-
- /// <summary>
- /// Gets or sets whether the menu bar is visible
- /// </summary>
- public static bool MenuBarVisibile
- {
- get { return Properties.Settings.Default.MenuBarVisibile; }
- set
- {
- bool same = value == Properties.Settings.Default.MenuBarVisibile;
- Properties.Settings.Default.MenuBarVisibile = value;
- object newValue = (object)value;
- object oldValue = same ? newValue : (object)Properties.Settings.Default.MenuBarVisibile;
- DispatchPropertyChanged("MenuBarVisibile", oldValue, newValue);
- }
- }
-
- /// <summary>
- /// Gets or sets the language of the application
- /// </summary>
- public static string Language
- {
- get { return Properties.Settings.Default.Language; }
- set
- {
- object old = Properties.Settings.Default.Language;
- Properties.Settings.Default.Language = value;
- DispatchPropertyChanged("Language", old, value);
- }
- }
-
- #endregion
-
- #region Lists
-
- /// <summary>
- /// Gets or sets the configuration of the history list
- /// </summary>
- public static ViewDetailsConfig HistoryListConfig
- {
- get { return Properties.Settings.Default.HistoryListConfig; }
- set
- {
- object old = Properties.Settings.Default.HistoryListConfig;
- Properties.Settings.Default.HistoryListConfig = value;
- DispatchPropertyChanged("HistoryListConfig", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the history tracks
- /// </summary>
- public static ObservableCollection<TrackData> HistoryTracks
- {
- get { return Properties.Settings.Default.HistoryTracks; }
- set
- {
- object old = Properties.Settings.Default.HistoryTracks;
- Properties.Settings.Default.HistoryTracks = value;
- DispatchPropertyChanged("HistoryTracks", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the configuration of the file list
- /// </summary>
- public static ViewDetailsConfig FileListConfig
- {
- get { return Properties.Settings.Default.LibraryListConfig; }
- set
- {
- object old = Properties.Settings.Default.LibraryListConfig;
- Properties.Settings.Default.LibraryListConfig = value;
- DispatchPropertyChanged("FileListConfig", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the file tracks
- /// </summary>
- public static ObservableCollection<TrackData> FileTracks
- {
- get { return Properties.Settings.Default.LibraryTracks; }
- set
- {
- object old = Properties.Settings.Default.LibraryTracks;
- Properties.Settings.Default.LibraryTracks = value;
- DispatchPropertyChanged("FileTracks", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the configuration of the queue list
- /// </summary>
- public static ViewDetailsConfig QueueListConfig
- {
- get { return Properties.Settings.Default.QueueListConfig; }
- set
- {
- object old = Properties.Settings.Default.QueueListConfig;
- Properties.Settings.Default.QueueListConfig = value;
- DispatchPropertyChanged("QueueListConfig", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the queue tracks
- /// </summary>
- public static ObservableCollection<TrackData> QueueTracks
- {
- get { return Properties.Settings.Default.QueueTracks; }
- set
- {
- object old = Properties.Settings.Default.QueueTracks;
- Properties.Settings.Default.QueueTracks = value;
- DispatchPropertyChanged("QueueTracks", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the configuration of the source list
- /// </summary>
- public static ViewDetailsConfig SourceListConfig
- {
- get { return Properties.Settings.Default.SourceListConfig; }
- set
- {
- object old = Properties.Settings.Default.SourceListConfig;
- Properties.Settings.Default.SourceListConfig = value;
- DispatchPropertyChanged("SourceListConfig", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the sources where Stoffi looks for music
- /// </summary>
- public static ObservableCollection<SourceData> Sources
- {
- get { return Properties.Settings.Default.Sources; }
- set
- {
- object old = Properties.Settings.Default.Sources;
- Properties.Settings.Default.Sources = value;
- DispatchPropertyChanged("Sources", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the configuration of the youtube list
- /// </summary>
- public static ViewDetailsConfig YouTubeListConfig
- {
- get { return Properties.Settings.Default.YouTubeListConfig; }
- set
- {
- object old = Properties.Settings.Default.YouTubeListConfig;
- Properties.Settings.Default.YouTubeListConfig = value;
- DispatchPropertyChanged("YouTubeListConfig", old, value);
- }
- }
-
- #endregion
-
- #region Application parameters
-
- /// <summary>
- /// Gets the architecture of the application.
- /// </summary>
- public static string Architecture
- {
- get { return Properties.Settings.Default.Architecture; }
- }
-
- /// <summary>
- /// Gets the channel of the application (Alpha, Beta or Stable).
- /// </summary>
- public static string Channel
- {
- get { return Properties.Settings.Default.Channel; }
- }
-
- /// <summary>
- /// Gets or sets the ID of the application
- /// </summary>
- public static int ID
- {
- get { return Properties.Settings.Default.ID; }
- set
- {
- // it may be null, although C# say int can't be null... :)
- object old = null;
- try
- {
- old = Properties.Settings.Default.ID;
- }
- catch { }
-
- Properties.Settings.Default.ID = value;
- DispatchPropertyChanged("ID", old, value);
- }
- }
-
- /// <summary>
- /// Gets the version of the application
- /// </summary>
- public static long Version
- {
- get { return Properties.Settings.Default.Version; }
- }
-
- /// <summary>
- /// Gets the release of the application
- /// </summary>
- public static string Release
- {
- get { return Properties.Settings.Default.Release; }
- }
-
- #endregion
-
- #region Settings
-
- /// <summary>
- /// Gets or sets how the upgrades of the application should be performed
- /// </summary>
- public static UpgradePolicy UpgradePolicy
- {
- get { return Properties.Settings.Default.UpgradePolicy; }
- set
- {
- object old = Properties.Settings.Default.UpgradePolicy;
- Properties.Settings.Default.UpgradePolicy = value;
- DispatchPropertyChanged("UpgradePolicy", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets how different list should share search filters
- /// </summary>
- public static SearchPolicy SearchPolicy
- {
- get { return Properties.Settings.Default.SearchPolicy; }
- set
- {
- object old = Properties.Settings.Default.SearchPolicy;
- Properties.Settings.Default.SearchPolicy = value;
- DispatchPropertyChanged("SearchPolicy", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets how to add a track when it's opened with the application
- /// </summary>
- public static OpenAddPolicy OpenAddPolicy
- {
- get { return Properties.Settings.Default.OpenAddPolicy; }
- set
- {
- object old = Properties.Settings.Default.OpenAddPolicy;
- Properties.Settings.Default.OpenAddPolicy = value;
- DispatchPropertyChanged("OpenAddPolicy", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets how to play a track when it's opened with the application
- /// </summary>
- public static OpenPlayPolicy OpenPlayPolicy
- {
- get { return Properties.Settings.Default.OpenPlayPolicy; }
- set
- {
- object old = Properties.Settings.Default.OpenPlayPolicy;
- Properties.Settings.Default.OpenPlayPolicy = value;
- DispatchPropertyChanged("OpenPlayPolicy", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets whether the application should stay visible in the taskbar when it's minimized
- /// </summary>
- public static bool MinimizeToTray
- {
- get { return Properties.Settings.Default.MinimizeToTray; }
- set
- {
- bool same = value == Properties.Settings.Default.MinimizeToTray;
- Properties.Settings.Default.MinimizeToTray = value;
- object newValue = (object)value;
- object oldValue = same ? newValue : (object)Properties.Settings.Default.MinimizeToTray;
- DispatchPropertyChanged("MinimizeToTray", oldValue, newValue);
- }
- }
-
- /// <summary>
- /// Gets or sets whether to show a notification when a new track is played
- /// </summary>
- public static bool ShowOSD
- {
- get { return Properties.Settings.Default.ShowOSD; }
- set
- {
- bool same = value == Properties.Settings.Default.ShowOSD;
- Properties.Settings.Default.ShowOSD = value;
- object newValue = (object)value;
- object oldValue = same ? newValue : (object)Properties.Settings.Default.ShowOSD;
- DispatchPropertyChanged("ShowOSD", oldValue, newValue);
- }
- }
-
- /// <summary>
- /// Gets or sets whether to pause playback while computer is locked
- /// </summary>
- public static bool PauseWhileLocked
- {
- get { return Properties.Settings.Default.PauseWhileLocked; }
- set
- {
- object old = Properties.Settings.Default.PauseWhileLocked;
- Properties.Settings.Default.PauseWhileLocked = value;
- DispatchPropertyChanged("PauseWhileLocked", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets whether to pause playback while user is logged out
- /// </summary>
- public static bool PauseWhileLoggedOut
- {
- get { return Properties.Settings.Default.PauseWhileLoggedOut; }
- set
- {
- object old = Properties.Settings.Default.PauseWhileLoggedOut;
- Properties.Settings.Default.PauseWhileLoggedOut = value;
- DispatchPropertyChanged("PauseWhileLoggedOut", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the currently used orofile of keyboard shortcuts
- /// </summary>
- public static string CurrentShortcutProfile
- {
- get { return Properties.Settings.Default.CurrentShortcutProfile; }
- set
- {
- object old = Properties.Settings.Default.CurrentShortcutProfile;
- Properties.Settings.Default.CurrentShortcutProfile = value;
- DispatchPropertyChanged("CurrentShortcutProfile", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the keyboard shortcut profiles
- /// </summary>
- public static List<KeyboardShortcutProfile> ShortcutProfiles
- {
- get { return Properties.Settings.Default.ShortcutProfiles; }
- set
- {
- object old = Properties.Settings.Default.ShortcutProfiles;
- Properties.Settings.Default.ShortcutProfiles = value;
- DispatchPropertyChanged("ShortcutProfiles", old, value);
- }
- }
-
- #endregion
-
- #region Playback
-
- /// <summary>
- /// Gets or sets the navigation that the currently playing track belongs to
- /// </summary>
- public static string CurrentActiveNavigation
- {
- get { return Properties.Settings.Default.CurrentActiveNavigation; }
- set
- {
- object old = Properties.Settings.Default.CurrentActiveNavigation;
- Properties.Settings.Default.CurrentActiveNavigation = value;
- DispatchPropertyChanged("CurrentActiveNavigation", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the currently playing track
- /// </summary>
- public static TrackData CurrentTrack
- {
- get { return Properties.Settings.Default.CurrentTrack; }
- set
- {
- object old = Properties.Settings.Default.CurrentTrack;
- Properties.Settings.Default.CurrentTrack = value;
- DispatchPropertyChanged("CurrentTrack", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the current equalizer profile
- /// </summary>
- public static EqualizerProfile CurrentEqualizerProfile
- {
- get { return Properties.Settings.Default.CurrentEqualizerProfile; }
- set
- {
- object old = Properties.Settings.Default.CurrentEqualizerProfile;
- Properties.Settings.Default.CurrentEqualizerProfile = value;
- DispatchPropertyChanged("CurrentEqualizerProfile", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets equalizer levels
- /// </summary>
- public static List<EqualizerProfile> EqualizerProfiles
- {
- get { return Properties.Settings.Default.EqualizerProfiles; }
- set
- {
- object old = Properties.Settings.Default.EqualizerProfiles;
- Properties.Settings.Default.EqualizerProfiles = value;
- DispatchPropertyChanged("EqualizerProfiles", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets where in history the current playback is
- /// </summary>
- public static int HistoryIndex
- {
- get { return Properties.Settings.Default.HistoryIndex; }
- set
- {
- object old = Properties.Settings.Default.HistoryIndex;
- Properties.Settings.Default.HistoryIndex = value;
- DispatchPropertyChanged("HistoryIndex", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets whether to use shuffle when selecting the next track
- /// </summary>
- public static bool Shuffle
- {
- get { return Properties.Settings.Default.Shuffle; }
- set
- {
- bool same = value == Properties.Settings.Default.Shuffle;
- Properties.Settings.Default.Shuffle = value;
- object newValue = (object)value;
- object oldValue = same ? newValue : (object)Properties.Settings.Default.Shuffle;
- DispatchPropertyChanged("Shuffle", oldValue, newValue);
- }
- }
-
- /// <summary>
- /// Gets or sets whether to repeat the tracks or not
- /// </summary>
- public static RepeatState Repeat
- {
- get { return Properties.Settings.Default.Repeat; }
- set
- {
- object old = Properties.Settings.Default.Repeat;
- Properties.Settings.Default.Repeat = value;
- DispatchPropertyChanged("Repeat", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the volume in percent.
- /// </summary>
- public static double Volume
- {
- get { return Properties.Settings.Default.Volume; }
- set
- {
- object old = Properties.Settings.Default.Volume;
- Properties.Settings.Default.Volume = value;
- DispatchPropertyChanged("Volume", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets current position of the currently playing
- /// track as a value between 0 and 10
- /// </summary>
- public static double Seek
- {
- get { return Properties.Settings.Default.Seek; }
- set
- {
- object old = Properties.Settings.Default.Seek;
- Properties.Settings.Default.Seek = value;
- DispatchPropertyChanged("Seek", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the buffer size as a value between 0 and 10
- /// </summary>
- public static double BufferSize
- {
- get { return bufferSize; }
- set
- {
- object old = bufferSize;
- bufferSize = value;
- DispatchPropertyChanged("BufferSize", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the state of the media player
- /// </summary>
- public static MediaState MediaState
- {
- get { return Properties.Settings.Default.MediaState; }
- set
- {
- object old = Properties.Settings.Default.MediaState;
- Properties.Settings.Default.MediaState = value;
- DispatchPropertyChanged("MediaState", old, value);
- }
- }
-
- #endregion
-
- #region Cloud
-
- /// <summary>
- /// Gets or sets the Synchronization to an account
- /// </summary>
- public static List<CloudIdentity> CloudIdentities
- {
- get
- {
- if (Properties.Settings.Default.CloudIdentities == null)
- Properties.Settings.Default.CloudIdentities = new List<CloudIdentity>();
- return Properties.Settings.Default.CloudIdentities;
- }
- set
- {
- object old = Properties.Settings.Default.CloudIdentities;
- Properties.Settings.Default.CloudIdentities = value;
- DispatchPropertyChanged("CloudIdentities", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the submition of tracks
- /// </summary>
- public static bool SubmitSongs
- {
- get { return Properties.Settings.Default.SubmitSongs; }
- set
- {
- object old = Properties.Settings.Default.SubmitSongs;
- Properties.Settings.Default.SubmitSongs = value;
- DispatchPropertyChanged("SubmitSongs", old, value);
- }
- }
-
- /// <summary>
- /// gets or sets the submition of playlists
- /// </summary>
- public static bool SubmitPlaylists
- {
- get { return Properties.Settings.Default.SubmitPlaylists; }
- set
- {
- object old = Properties.Settings.Default.SubmitPlaylists;
- Properties.Settings.Default.SubmitPlaylists = value;
- DispatchPropertyChanged("SubmitPlaylists", old, value);
- }
- }
-
- #endregion
-
- #region Misc
-
- /// <summary>
- /// Gets or sets whether the application has never been run before
- /// </summary>
- public static bool FirstRun
- {
- get { return Properties.Settings.Default.FirstRun; }
- set
- {
- object old = Properties.Settings.Default.FirstRun;
- Properties.Settings.Default.FirstRun = value;
- DispatchPropertyChanged("FirstRun", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the last time the application checked for an upgrade
- /// </summary>
- public static long UpgradeCheck
- {
- get { return Properties.Settings.Default.UpgradeCheck; }
- set
- {
- object old = Properties.Settings.Default.UpgradeCheck;
- Properties.Settings.Default.UpgradeCheck = value;
- DispatchPropertyChanged("UpgradeCheck", old, value);
- }
- }
-
-
-
- /// <summary>
- /// Gets or sets the playlists
- /// </summary>
- public static List<PlaylistData> Playlists
- {
- get { return Properties.Settings.Default.Playlists; }
- set
- {
- object old = Properties.Settings.Default.Playlists;
- Properties.Settings.Default.Playlists = value;
- DispatchPropertyChanged("Playlists", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the OAuth secret
- /// </summary>
- public static string OAuthSecret
- {
- get { return Properties.Settings.Default.OAuthSecret; }
- set
- {
- object old = Properties.Settings.Default.OAuthSecret;
- Properties.Settings.Default.OAuthSecret = value;
- DispatchPropertyChanged("OAuthSecret", old, value);
- }
- }
-
- /// <summary>
- /// Gets or sets the OAuth token
- /// </summary>
- public static string OAuthToken
- {
- get { return Properties.Settings.Default.OAuthToken; }
- set
- {
- object old = Properties.Settings.Default.OAuthToken;
- Properties.Settings.Default.OAuthToken = value;
- DispatchPropertyChanged("OAuthToken", old, value);
- }
- }
-
- #endregion
-
- #endregion
-
- #region Methods
-
- #region Public
-
- /// <summary>
- /// Initializes the settings manager
- /// </summary>
- public static void Initialize()
- {
- if (FirstRun)
- {
- CurrentTrack = null;
-
- Sources = new ObservableCollection<SourceData>();
- Playlists = new List<PlaylistData>();
-
- // TODO: set default language according to system language
- //SettingsManager.Language = ???
-
- #region Track collections
-
- FileTracks = new ObservableCollection<TrackData>();
- HistoryTracks = new ObservableCollection<TrackData>();
- QueueTracks = new ObservableCollection<TrackData>();
-
- #endregion
-
- #region Equalizer
-
- EqualizerProfiles = new List<EqualizerProfile>();
- EqualizerProfiles.Add(CreateEqualizerLevel(U.T("EqualizerProfileDefault"), new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, true));
- CurrentEqualizerProfile = EqualizerProfiles[0];
-
- #endregion
-
- #region Shortcuts
-
- ShortcutProfiles = new List<KeyboardShortcutProfile>();
-
- // Stoffi
- KeyboardShortcutProfile shortStoffi = new KeyboardShortcutProfile();
- InitShortcutProfile(shortStoffi, "Stoffi", true);
- ShortcutProfiles.Add(shortStoffi);
-
- // Amarok
- KeyboardShortcutProfile shortAmarok = new KeyboardShortcutProfile();
- InitShortcutProfile(shortAmarok, "Amarok", true);
- SetKeyboardShortcut(shortAmarok, "Application", "Add track", "Win+A");
- SetKeyboardShortcut(shortAmarok, "Application", "Open playlist", "Space");
- SetKeyboardShortcut(shortAmarok, "MediaCommands", "Play or pause", "Win+X");
- SetKeyboardShortcut(shortAmarok, "MediaCommands", "Next", "Win+B");
- SetKeyboardShortcut(shortAmarok, "MediaCommands", "Previous", "Win+Z");
- SetKeyboardShortcut(shortAmarok, "MediaCommands", "Toggle shuffle", "Ctrl+H");
- ShortcutProfiles.Add(shortAmarok);
-
- // Banshee
- KeyboardShortcutProfile shortBanshee = new KeyboardShortcutProfile();
- InitShortcutProfile(shortBanshee, "Banshee", true);
- SetKeyboardShortcut(shortBanshee, "Application", "Add track", "Ctrl+L");
- SetKeyboardShortcut(shortBanshee, "Application", "Close", "Ctrl+Q");
- SetKeyboardShortcut(shortBanshee, "MediaCommands", "Play or pause", "Space");
- SetKeyboardShortcut(shortBanshee, "MediaCommands", "Next", "N");
- SetKeyboardShortcut(shortBanshee, "MediaCommands", "Previous", "B");
- SetKeyboardShortcut(shortBanshee, "MainWindow", "Search", "/ (numpad)");
- ShortcutProfiles.Add(shortBanshee);
-
- // Foobar2000
- KeyboardShortcutProfile shortFoobar2000 = new KeyboardShortcutProfile();
- InitShortcutProfile(shortFoobar2000, "Foobar2000", true);
- SetKeyboardShortcut(shortFoobar2000, "Application", "Add track", "Ctrl+O");
- SetKeyboardShortcut(shortFoobar2000, "Application", "Add folder", "Ctrl+A");
- SetKeyboardShortcut(shortFoobar2000, "Application", "Open playlist", "Ctrl+L");
- SetKeyboardShortcut(shortFoobar2000, "MainWindow", "Search", "Ctrl+F");
- SetKeyboardShortcut(shortFoobar2000, "MainWindow", "General preferences", "Ctrl+P");
- ShortcutProfiles.Add(shortFoobar2000);
-
- // iTunes
- KeyboardShortcutProfile shortiTunes = new KeyboardShortcutProfile();
- InitShortcutProfile(shortiTunes, "iTunes", true);
- SetKeyboardShortcut(shortiTunes, "Application", "Add track", "Ctrl+O");
- SetKeyboardShortcut(shortiTunes, "Application", "Open playlist", "Ctrl+P");
- SetKeyboardShortcut(shortiTunes, "MainWindow", "General preferences", "Ctrl+,");
- SetKeyboardShortcut(shortiTunes, "MediaCommands", "Play or pause", "Space");
- SetKeyboardShortcut(shortiTunes, "MediaCommands", "Increase volume", "Ctrl+Up");
- SetKeyboardShortcut(shortiTunes, "MediaCommands", "Decrease volume", "Ctrl+Down");
- SetKeyboardShortcut(shortiTunes, "MediaCommands", "Previous", "Left");
- SetKeyboardShortcut(shortiTunes, "MediaCommands", "Next", "Right");
- SetKeyboardShortcut(shortiTunes, "Track", "View information", "Ctrl+J");
- ShortcutProfiles.Add(shortiTunes);
-
- // MusicBee
- KeyboardShortcutProfile shortMusicBee = new KeyboardShortcutProfile();
- InitShortcutProfile(shortMusicBee, "MusicBee", true);
- SetKeyboardShortcut(shortMusicBee, "MainWindow", "Search", "Ctrl+F");
- SetKeyboardShortcut(shortMusicBee, "MainWindow", "General preferences", "Ctrl+O");
- SetKeyboardShortcut(shortMusicBee, "Application", "Open playlist", "Ctrl+L");
- SetKeyboardShortcut(shortMusicBee, "MainWindow", "Create playlist", "Ctrl+C");
- SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Play or pause", "Ctrl+P");
- SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Next", "Ctrl+N");
- SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Previous", "Ctrl+B");
- SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Increase volume", "Ctrl+Up");
- SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Decrease volume", "Ctrl+Down");
- SetKeyboardShortcut(shortMusicBee, "Track", "Queue and dequeue", "Ctrl+Enter");
- SetKeyboardShortcut(shortMusicBee, "Track", "View information", "Alt+E");
- ShortcutProfiles.Add(shortMusicBee);
-
- // Rythmbox
- KeyboardShortcutProfile shortRythmbox = new KeyboardShortcutProfile();
- InitShortcutProfile(shortRythmbox, "Rythmbox", true);
- SetKeyboardShortcut(shortRythmbox, "Application", "Close", "Ctrl+Q");
- SetKeyboardShortcut(shortRythmbox, "Application", "Add folder", "Ctrl+O");
- SetKeyboardShortcut(shortRythmbox, "Application", "Open playlist", "Ctrl+P");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Play or pause", "Ctrl+Space");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Previous", "Alt+Left");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Jump to previous bookmark", "Alt+,");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Next", "Alt+Right");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Jump to next bookmark", "Alt+.");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Increase volume", "Ctrl+Up");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Decrease volume", "Ctrl+Down");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Toggle shuffle", "Ctrl+U");
- SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Toggle repeat", "Ctrl+R");
- SetKeyboardShortcut(shortRythmbox, "Track", "View information", "Alt+Enter");
- ShortcutProfiles.Add(shortRythmbox);
-
- // Spotify
- KeyboardShortcutProfile shortSpotify = new KeyboardShortcutProfile();
- InitShortcutProfile(shortSpotify, "Spotify", true);
- SetKeyboardShortcut(shortSpotify, "MediaCommands", "Next", "Ctrl+Right");
- SetKeyboardShortcut(shortSpotify, "MediaCommands", "Previous", "Ctrl+Left");
- SetKeyboardShortcut(shortSpotify, "MediaCommands", "Increase volume", "Ctrl+Up");
- SetKeyboardShortcut(shortSpotify, "MediaCommands", "Decrease volume", "Ctrl+Down");
- SetKeyboardShortcut(shortSpotify, "MainWindow", "Library", "Ctrl+I");
- SetKeyboardShortcut(shortSpotify, "MainWindow", "Search", "Ctrl+L");
- SetKeyboardShortcut(shortSpotify, "MainWindow", "General preferences", "Ctrl+P");
- ShortcutProfiles.Add(shortSpotify);
-
- // VLC
- KeyboardShortcutProfile shortVLC = new KeyboardShortcutProfile();
- InitShortcutProfile(shortVLC, "VLC", true);
- SetKeyboardShortcut(shortVLC, "Application", "Add track", "Ctrl+O");
- SetKeyboardShortcut(shortVLC, "Application", "Open playlist", "Ctrl+Y");
- SetKeyboardShortcut(shortVLC, "Application", "Close", "Ctrl+Q");
- SetKeyboardShortcut(shortVLC, "MainWindow", "Playlists", "Ctrl+L");
- SetKeyboardShortcut(shortVLC, "MainWindow", "Library", "Ctrl+I");
- SetKeyboardShortcut(shortVLC, "MainWindow", "General preferences", "Ctrl+P");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Next", "N");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Previous", "P");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Seek backward", "Ctrl+Left");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Seek forward", "Ctrl+Right");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Increase volume", "Ctrl+Up");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Decrease volume", "Ctrl+Down");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Toggle shuffle", "R");
- SetKeyboardShortcut(shortVLC, "MediaCommands", "Toggle repeat", "L");
- ShortcutProfiles.Add(shortVLC);
-
- // Winamp
- KeyboardShortcutProfile shortWinamp = new KeyboardShortcutProfile();
- InitShortcutProfile(shortWinamp, "Winamp", true);
- SetKeyboardShortcut(shortWinamp, "Application", "Add track", "Ctrl+Alt+L");
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Play or pause", "Ctrl+Alt+Insert", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Next", "Ctrl+Alt+PageDown", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Previous", "Ctrl+Alt+PageUp", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Increase volume", "Ctrl+Alt+Up", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Decrease volume", "Ctrl+Alt+Down", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Seek forward", "Ctrl+Alt+Right", true);
- SetKeyboardShortcut(shortWinamp, "MediaCommands", "Seek backward", "Ctrl+Alt+Left", true);
- ShortcutProfiles.Add(shortWinamp);
-
- // Windows Media Player
- KeyboardShortcutProfile shortWMP = new KeyboardShortcutProfile();
- InitShortcutProfile(shortWMP, "Windows Media Player", true);
- SetKeyboardShortcut(shortWMP, "Application", "Add track", "Ctrl+O");
- SetKeyboardShortcut(shortWMP, "Application", "Open playlist", "Ctrl+L");
- SetKeyboardShortcut(shortWMP, "MainWindow", "Library", "Ctrl+1");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Play or pause", "Ctrl+P");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Next", "Ctrl+Right");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Previous", "Ctrl+Left");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Seek forward", "Ctrl+Shift+F");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Seek backward", "Ctrl+Shift+B");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Toggle shuffle", "Ctrl+H");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Toggle repeat", "Ctrl+T");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Increase volume", "F9");
- SetKeyboardShortcut(shortWMP, "MediaCommands", "Decrease volume", "F8");
- SetKeyboardShortcut(shortWMP, "MainWindow", "Search", "Ctrl+E");
- ShortcutProfiles.Add(shortWMP);
-
- #endregion
-
- #region ViewDetails lists
-
- // sources list
- ViewDetailsConfig sourceConfig = CreateListConfig();
- sourceConfig.Columns.Add(CreateListColumn("Data", U.T("ColumnLocation"), "Data", 200));
- sourceConfig.Columns.Add(CreateListColumn("Type", U.T("ColumnType"), "HumanType", 150));
- SourceListConfig = sourceConfig;
-
- // youtube list
- ViewDetailsConfig youtubeConfig = CreateListConfig();
- youtubeConfig.AcceptFileDrops = false;
- youtubeConfig.IsDragSortable = false;
- youtubeConfig.Columns.Add(CreateListColumn("Title", U.T("ColumnTitle"), "Title", 300));
- youtubeConfig.Columns.Add(CreateListColumn("Artist", U.T("ColumnArtist"), "Artist", 150));
- youtubeConfig.Columns.Add(CreateListColumn("Views", U.T("ColumnViews"), "Views", "RawViews", 170, System.Windows.HorizontalAlignment.Right));
- youtubeConfig.Columns.Add(CreateListColumn("Length", U.T("ColumnLength"), "Length", "RawLength", 150, System.Windows.HorizontalAlignment.Right));
- youtubeConfig.Columns.Add(CreateListColumn("Path", U.T("ColumnPath"), "Path", 200));
- YouTubeListConfig = youtubeConfig;
-
- // library list
- ViewDetailsConfig libList = CreateListConfig();
- InitViewDetailsConfig(libList);
- FileListConfig = libList;
-
- // queue list
- ViewDetailsConfig queueList = CreateListConfig();
- queueList.IsNumberVisible = true;
- InitViewDetailsConfig(queueList);
- QueueListConfig = queueList;
-
- // history list
- ViewDetailsConfig historyList = CreateListConfig();
- historyList.Columns.Add(CreateListColumn("LastPlayed", U.T("ColumnPlayed"), "LastPlayed", 200));
- historyList.Columns.Add(CreateListColumn("Artist", U.T("ColumnArtist"), "Artist", 100));
- historyList.Columns.Add(CreateListColumn("Album", U.T("ColumnAlbum"), "Album", 100));
- historyList.Columns.Add(CreateListColumn("Title", U.T("ColumnTitle"), "Title", 100));
- historyList.Columns.Add(CreateListColumn("Genre", U.T("ColumnGenre"), "Genre", 100));
- historyList.Columns.Add(CreateListColumn("Length", U.T("ColumnLength"), "Length", "RawLength", 100, System.Windows.HorizontalAlignment.Right));
- historyList.Columns.Add(CreateListColumn("Year", U.T("ColumnYear"), "Year", "Year", 100, System.Windows.HorizontalAlignment.Right));
- historyList.Columns.Add(CreateListColumn("PlayCount", U.T("ColumnPlayCount"), "PlayCount", 100, System.Windows.HorizontalAlignment.Right));
- historyList.Columns.Add(CreateListColumn("Path", U.T("ColumnPath"), "Path", 200));
- historyList.Columns.Add(CreateListColumn("Track", U.T("ColumnTrack"), "Track", 100, System.Windows.HorizontalAlignment.Right));
- HistoryListConfig = historyList;
-
- #endregion
-
- //Save();
- }
-
- // fix source on all tracks
- foreach (TrackData t in SettingsManager.FileTracks)
- t.Source = "Library";
- foreach (PlaylistData p in SettingsManager.Playlists)
- foreach (TrackData t in p.Tracks)
- t.Source = "Playlist:" + p.Name;
-
- DispatchInitialized();
- }
-
- /// <summary>
- /// Saves the settings
- /// </summary>
- public static void Save()
- {
- Properties.Settings.Default.Save();
- }
-
- /// <summary>
- /// Export the current configuration to an xml file
- /// </summary>
- /// <param name="filename">The path to the file</param>
- public static void Export(string filename)
- {
- Config c = new Config();
-
- // tracks
- c.Collection = ExportTracks(SettingsManager.FileTracks);
- c.History = ExportTracks(SettingsManager.HistoryTracks);
- c.Queue = ExportTracks(SettingsManager.QueueTracks);
- c.Playlists = new List<ConfigPlaylist>();
- foreach (PlaylistData p in SettingsManager.Playlists)
- {
- ConfigPlaylist cp = new ConfigPlaylist();
- cp.Name = p.Name;
- cp.Tracks = ExportTracks(p.Tracks);
- cp.ListConfig = p.ListConfig;
- c.Playlists.Add(cp);
- }
-
- c.CurrentActiveNavigation = SettingsManager.CurrentActiveNavigation;
- c.CurrentSelectedNavigation = SettingsManager.CurrentSelectedNavigation;
- c.CurrentShortcutProfile = SettingsManager.CurrentShortcutProfile;
- c.CurrentTrack = ExportTrack(SettingsManager.CurrentTrack);
- c.DetailsPaneVisible = SettingsManager.DetailsPaneVisible;
- c.FileListConfig = SettingsManager.FileListConfig;
- c.HistoryIndex = SettingsManager.HistoryIndex;
- c.HistoryListConfig = SettingsManager.HistoryListConfig;
- c.Language = SettingsManager.Language;
- c.MenuBarVisibile = SettingsManager.MenuBarVisibile;
- c.MinimizeToTray = SettingsManager.MinimizeToTray;
- c.OpenAddPolicy = SettingsManager.OpenAddPolicy;
- c.OpenPlayPolicy = SettingsManager.OpenPlayPolicy;
- c.QueueListConfig = SettingsManager.QueueListConfig;
- c.Repeat = SettingsManager.Repeat;
- c.SearchPolicy = SettingsManager.SearchPolicy;
- c.Seek = SettingsManager.Seek;
- c.Volume = SettingsManager.Volume;
- c.ShortcutProfiles = SettingsManager.ShortcutProfiles;
- c.ShowOSD = SettingsManager.ShowOSD;
- c.Shuffle = SettingsManager.Shuffle;
- c.SourceListConfig = SettingsManager.SourceListConfig;
- c.UpgradePolicy = SettingsManager.UpgradePolicy;
- c.YouTubeListConfig = SettingsManager.YouTubeListConfig;
-
- // serialize to xml
- XmlSerializer ser = new XmlSerializer(typeof(Config));
- TextWriter w = new StreamWriter(filename);
- ser.Serialize(w, c);
- w.Close();
- }
-
- /// <summary>
- /// Import and apply a configuration from an xml file
- /// </summary>
- /// <param name="filename">The path of the file</param>
- public static void Import(string filename)
- {
- XmlSerializer ser = new XmlSerializer(typeof(Config));
- FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
- Config c = (Config)ser.Deserialize(fs);
- fs.Close();
-
- // tracks
- SettingsManager.FileTracks.Clear();
- SettingsManager.HistoryTracks.Clear();
- SettingsManager.QueueTracks.Clear();
- ImportTracks(c.Collection, SettingsManager.FileTracks, false);
- ImportTracks(c.History, SettingsManager.HistoryTracks);
- ImportTracks(c.Queue, SettingsManager.QueueTracks);
- SettingsManager.Playlists.Clear();
- foreach (ConfigPlaylist p in c.Playlists)
- {
- PlaylistData pl = PlaylistManager.FindPlaylist(p.Name);
- if (pl == null)
- pl = PlaylistManager.CreatePlaylist(p.Name);
- ImportTracks(p.Tracks, pl.Tracks);
- pl.ListConfig = p.ListConfig;
- }
-
- SettingsManager.CurrentActiveNavigation = c.CurrentActiveNavigation;
- SettingsManager.CurrentSelectedNavigation = c.CurrentSelectedNavigation;
- SettingsManager.CurrentShortcutProfile = c.CurrentShortcutProfile;
- SettingsManager.CurrentTrack = ImportTrack(c.CurrentTrack);
- SettingsManager.DetailsPaneVisible = c.DetailsPaneVisible;
- SettingsManager.FileListConfig = c.FileListConfig;
- SettingsManager.HistoryIndex = c.HistoryIndex;
- SettingsManager.HistoryListConfig = c.HistoryListConfig;
- SettingsManager.Language = c.Language;
- SettingsManager.MenuBarVisibile = c.MenuBarVisibile;
- SettingsManager.MinimizeToTray = c.MinimizeToTray;
- SettingsManager.OpenAddPolicy = c.OpenAddPolicy;
- SettingsManager.OpenPlayPolicy = c.OpenPlayPolicy;
- SettingsManager.QueueListConfig = c.QueueListConfig;
- SettingsManager.Repeat = c.Repeat;
- SettingsManager.SearchPolicy = c.SearchPolicy;
- SettingsManager.Seek = c.Seek;
- SettingsManager.Volume = c.Volume;
- SettingsManager.ShortcutProfiles = c.ShortcutProfiles;
- SettingsManager.ShowOSD = c.ShowOSD;
- SettingsManager.Shuffle = c.Shuffle;
- SettingsManager.SourceListConfig = c.SourceListConfig;
- SettingsManager.UpgradePolicy = c.UpgradePolicy;
- SettingsManager.YouTubeListConfig = c.YouTubeListConfig;
- }
-
- /// <summary>
- /// Retrieves the an equalizer profile given its name
- /// </summary>
- /// <param name="name">The name of the profile</param>
- /// <returns>The equalizer profile with the given name</returns>
- public static EqualizerProfile GetEqualizerProfile(string name)
- {
- foreach (EqualizerProfile p in EqualizerProfiles)
- if (p.IsProtected && U.T("EqualizerProfile" + p.Name) == name || p.Name == name)
- return p;
- return EqualizerProfiles[0];
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public static KeyboardShortcutProfile GetCurrentShortcutProfile()
- {
- try
- {
- foreach (KeyboardShortcutProfile p in ShortcutProfiles)
- if (p.Name == CurrentShortcutProfile)
- return p;
- return ShortcutProfiles[0];
- }
- catch { return null; }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="profile"></param>
- /// <param name="keysAsText"></param>
- /// <returns></returns>
- public static KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String keysAsText)
- {
- if (profile != null)
- foreach (KeyboardShortcut s in profile.Shortcuts)
- if (s.Keys == keysAsText)
- return s;
- return null;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="profile"></param>
- /// <param name="category"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name)
- {
- foreach (KeyboardShortcut s in profile.Shortcuts)
- if (s.Name == name && s.Category == category)
- return s;
- return null;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="profile"></param>
- /// <param name="name"></param>
- /// <param name="isprotected"></param>
- public static void InitShortcutProfile(KeyboardShortcutProfile profile, String name, Boolean isprotected)
- {
- profile.Name = name;
- profile.IsProtected = isprotected;
- profile.Shortcuts = new List<KeyboardShortcut>();
-
- // set the default shortcuts
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add track", IsGlobal = false, Keys = "Ctrl+T" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add folder", IsGlobal = false, Keys = "Ctrl+F" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Open playlist", IsGlobal = false, Keys = "Ctrl+O" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Minimize", IsGlobal = false, Keys = "Ctrl+M" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Restore", IsGlobal = true, Keys = "Ctrl+Shift+R" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Help", IsGlobal = false, Keys = "F1" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Close", IsGlobal = false, Keys = "Ctrl+W" });
-
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library", IsGlobal = false, Keys = "Alt+L" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Queue", IsGlobal = false, Keys = "Alt+Q" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "History", IsGlobal = false, Keys = "Alt+H" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Playlists", IsGlobal = false, Keys = "Alt+P" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Now playing", IsGlobal = false, Keys = "Alt+W" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Tracklist", IsGlobal = false, Keys = "Alt+T" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Search", IsGlobal = false, Keys = "Alt+F" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "General preferences", IsGlobal = false, Keys = "Alt+G" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library sources", IsGlobal = false, Keys = "Alt+S" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Services", IsGlobal = false, Keys = "Alt+V" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Keyboard shortcuts", IsGlobal = false, Keys = "Alt+K" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "About", IsGlobal = false, Keys = "Alt+A" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle details pane", IsGlobal = false, Keys = "Alt+D" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle menu bar", IsGlobal = false, Keys = "Alt+M" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Create playlist", IsGlobal = false, Keys = "Alt+N" });
-
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Play or pause", IsGlobal = false, Keys = "Alt+5 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Next", IsGlobal = false, Keys = "Alt+6 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Previous", IsGlobal = false, Keys = "Alt+4 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle shuffle", IsGlobal = false, Keys = "Alt+9 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle repeat", IsGlobal = false, Keys = "Alt+7 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Increase volume", IsGlobal = false, Keys = "Alt+8 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Decrease volume", IsGlobal = false, Keys = "Alt+2 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Seek forward", IsGlobal = false, Keys = "Alt+3 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Seek backward", IsGlobal = false, Keys = "Alt+1 (numpad)" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Add bookmark", IsGlobal = false, Keys = "Alt+B" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to previous bookmark", IsGlobal = false, Keys = "Alt+Left" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to next bookmark", IsGlobal = false, Keys = "Alt+Right" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to first bookmark", IsGlobal = false, Keys = "Alt+Home" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to last bookmark", IsGlobal = false, Keys = "Alt+End" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 1", IsGlobal = false, Keys = "Alt+1" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 2", IsGlobal = false, Keys = "Alt+2" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 3", IsGlobal = false, Keys = "Alt+3" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 4", IsGlobal = false, Keys = "Alt+4" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 5", IsGlobal = false, Keys = "Alt+5" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 6", IsGlobal = false, Keys = "Alt+6" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 7", IsGlobal = false, Keys = "Alt+7" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 8", IsGlobal = false, Keys = "Alt+8" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 9", IsGlobal = false, Keys = "Alt+9" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 10", IsGlobal = false, Keys = "Alt+0" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to current track", IsGlobal = false, Keys = "Alt+C" });
-
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Queue and dequeue", IsGlobal = false, Keys = "Shift+Q" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Remove track", IsGlobal = false, Keys = "Delete" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Play track", IsGlobal = false, Keys = "Enter" });
- profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "View information", IsGlobal = false, Keys = "Shift+I" });
- }
-
- /// <summary>
- /// Initializes a configuration of a ViewDetails list.
- /// </summary>
- /// <param name="config">The configuration to initialize</param>
- public static void InitViewDetailsConfig(ViewDetailsConfig config)
- {
- config.Columns.Add(CreateListColumn("Artist", U.T("ColumnArtist"), "Artist", 150));
- config.Columns.Add(CreateListColumn("Album", U.T("ColumnAlbum"), "Album", 150));
- config.Columns.Add(CreateListColumn("Title", U.T("ColumnTitle"), "Title", 150));
- config.Columns.Add(CreateListColumn("Genre", U.T("ColumnGenre"), "Genre", 100));
- config.Columns.Add(CreateListColumn("Length", U.T("ColumnLength"), "Length", "RawLength", 100, System.Windows.HorizontalAlignment.Right));
- config.Columns.Add(CreateListColumn("Year", U.T("ColumnYear"), "Year", "Year", 100, System.Windows.HorizontalAlignment.Right));
- config.Columns.Add(CreateListColumn("LastPlayed", U.T("ColumnLastPlayed"), "LastPlayed", 150));
- config.Columns.Add(CreateListColumn("PlayCount", U.T("ColumnPlayCount"), "PlayCount", 100, System.Windows.HorizontalAlignment.Right));
- config.Columns.Add(CreateListColumn("Track", U.T("ColumnTrack"), "Track", 100, System.Windows.HorizontalAlignment.Right));
- config.Columns.Add(CreateListColumn("Path", U.T("ColumnPath"), "Path", 300));
- }
-
- /// <summary>
- /// Creates an EqualizerLevel with some given values.
- /// Works as a constructor for the data structure.
- /// </summary>
- /// <param name="name">The name of the profile</param>
- /// <param name="levels">The 10 levels (ranging from 0 to 10)</param>
- /// <param name="echo">The echo level (ranging from 0 to 10)</param>
- /// <param name="isProtected">Whether or not the user can edit the profile</param>
- public static EqualizerProfile CreateEqualizerLevel(string name, float[] levels, float echo, bool isProtected = false)
- {
- return new EqualizerProfile() { EchoLevel = echo, IsProtected = isProtected, Levels = levels, Name = name };
- }
-
- /// <summary>
- /// Creates a ViewDetailsConfig with default values
- /// </summary>
- /// <returns>The newly created config</returns>
- public static ViewDetailsConfig CreateListConfig()
- {
- Stoffi.ViewDetailsConfig config = new Stoffi.ViewDetailsConfig();
- config.HasNumber = true;
- config.IsNumberVisible = false;
- config.Filter = "";
- config.IsClickSortable = true;
- config.IsDragSortable = true;
- config.LockSortOnNumber = false;
- config.SelectedIndices = new List<int>();
- config.UseIcons = true;
- config.AcceptFileDrops = true;
- config.Columns = new ObservableCollection<Stoffi.ViewDetailsColumn>();
- config.NumberColumn = CreateListColumn("#", "#", "Number", "Number", 60, System.Windows.HorizontalAlignment.Right, false);
- return config;
- }
-
- /// <summary>
- /// Creates a ViewDetailsColumn
- /// </summary>
- /// <param name="name">The name of the column</param>
- /// <param name="text">The displayed text</param>
- /// <param name="binding">The value to bind to</param>
- /// <param name="width">The width</param>
- /// <param name="isVisible">Whether the column is visible</param>
- /// <param name="alignment">The alignment of the text</param>
- /// <param name="isAlwaysVisible">Whether the column is always visible</param>
- /// <param name="isSortable">Whether the column is sortable</param>
- /// <returns>The newly created column</returns>
- public static ViewDetailsColumn CreateListColumn(string name, string text, string binding, int width,
- System.Windows.HorizontalAlignment alignment = System.Windows.HorizontalAlignment.Left,
- bool isVisible = true,
- bool isAlwaysVisible = false,
- bool isSortable = true)
- {
-
- ViewDetailsColumn column = new ViewDetailsColumn();
- column.Name = name;
- column.Text = text;
- column.Binding = binding;
- column.Width = width;
- column.Alignment = alignment;
- column.IsAlwaysVisible = isAlwaysVisible;
- column.IsSortable = isSortable;
- column.IsVisible = isVisible;
- column.SortField = binding;
- return column;
- }
-
- /// <summary>
- /// Creates a ViewDetailsColumn
- /// </summary>
- /// <param name="name">The name of the column</param>
- /// <param name="text">The displayed text</param>
- /// <param name="binding">The value to bind to</param>
- /// <param name="sortField">The column to sort on</param>
- /// <param name="width">The width</param>
- /// <param name="isVisible">Whether the column is visible</param>
- /// <param name="alignment">The alignment of the text</param>
- /// <param name="isAlwaysVisible">Whether the column is always visible</param>
- /// <param name="isSortable">Whether the column is sortable</param>
- /// <returns>The newly created column</returns>
- public static ViewDetailsColumn CreateListColumn(string name, string text, string binding, string sortField, int width,
- System.Windows.HorizontalAlignment alignment = System.Windows.HorizontalAlignment.Left,
- bool isVisible = true,
- bool isAlwaysVisible = false,
- bool isSortable = true)
- {
-
- ViewDetailsColumn column = new ViewDetailsColumn();
- column.Name = name;
- column.Text = text;
- column.Binding = binding;
- column.Width = width;
- column.Alignment = alignment;
- column.IsAlwaysVisible = isAlwaysVisible;
- column.IsSortable = isSortable;
- column.IsVisible = isVisible;
- column.SortField = sortField;
- return column;
- }
-
- /// <summary>
- /// Looks for the cloud identity with a given user ID.
- /// </summary>
- /// <param name="userID">The user ID to look for.</param>
- /// <returns>The corresponding cloud identity or null if not found.</returns>
- public static CloudIdentity GetCloudIdentity(int userID)
- {
- foreach (CloudIdentity i in CloudIdentities)
- {
- if (i.UserID == userID)
- return i;
- }
- return null;
- }
-
- /// <summary>
- /// Checks if there exists a cloud identity with a given user ID.
- /// </summary>
- /// <param name="userID">The user ID to look for.</param>
- /// <returns>True if an identity was found, otherwise false.</returns>
- public static bool HasCloudIdentity(int userID)
- {
- return GetCloudIdentity(userID) != null;
- }
-
- #endregion
-
- #region Private
-
- /// <summary>
- /// Copies an observable collection of TrackData to a list of ConfigTrack
- /// </summary>
- /// <param name="tracks">The tracks to be copied</param>
- /// <returns>The tracks as configuration structures</returns>
- private static List<ConfigTrack> ExportTracks(ObservableCollection<TrackData> tracks)
- {
- List<ConfigTrack> l = new List<ConfigTrack>();
- foreach (TrackData t in tracks)
- l.Add(ExportTrack(t));
- return l;
- }
-
- /// <summary>
- /// Copies a TrackData into a ConfigTrack
- /// </summary>
- /// <param name="track">The track to be copied</param>
- /// <returns>The track as a configuration structure</returns>
- private static ConfigTrack ExportTrack(TrackData track)
- {
- return new ConfigTrack() { Path = track.Path, PlayCount = track.PlayCount, LastPlayed = track.RawLastPlayed };
- }
-
- /// <summary>
- /// Copies a list of ConfigTrack to an observable collection of TrackData
- /// </summary>
- /// <param name="tracks">The tracks to be copied</param>
- /// <returns>The tracks as an observable collection of TrackData</returns>
- private static ObservableCollection<TrackData> ImportTracks(List<ConfigTrack> tracks)
- {
- ObservableCollection<TrackData> c = new ObservableCollection<TrackData>();
- foreach (ConfigTrack t in tracks)
- {
- TrackData track = ImportTrack(t);
- if (track != null)
- c.Add(track);
- }
- return c;
- }
-
- /// <summary>
- /// Reads from a confguration structure of tracks and imports the tracks into
- /// an observable collection.
- /// </summary>
- /// <param name="source">The tracks to be copied</param>
- /// <param name="destination">The collection to copy the tracks into</param>
- /// <param name="addToList">Whether or not to also add the track to the destination (this may be done elsewhere)</param>
- private static void ImportTracks(List<ConfigTrack> source, ObservableCollection<TrackData> destination, bool addToList = true)
- {
- foreach (ConfigTrack t in source)
- {
- TrackData dest = null;
- foreach (TrackData track in destination)
- {
- if (track.Path == t.Path)
- {
- dest = track;
- break;
- }
- }
- if (dest == null)
- {
- TrackData track = ImportTrack(t, addToList);
- if (track != null && addToList)
- destination.Add(track);
- }
- else
- {
- dest.LastPlayed = t.LastPlayed;
- dest.PlayCount = t.PlayCount;
- }
- }
- }
-
- /// <summary>
- /// Copies a ConfigTrack into a TrackData
- /// </summary>
- /// <param name="track">The track to be copied</param>
- /// <param name="addManually">Whether or not the track has to be added manually (this may be done elsewhere)</param>
- /// <returns>The track as a TrackData</returns>
- private static TrackData ImportTrack(ConfigTrack track, bool addManually = true)
- {
- if (YouTubeManager.IsYouTube(track.Path))
- {
- return YouTubeManager.CreateTrack(YouTubeManager.GetYouTubeID(track.Path));
- }
- else if (File.Exists(track.Path))
- {
- TrackData t = FilesystemManager.CreateTrack(track.Path, !addManually);
- if (addManually)
- FilesystemManager.UpdateTrack(t);
- t.LastPlayed = track.LastPlayed;
- t.PlayCount = track.PlayCount;
- return t;
- }
- return null;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="profiles"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- private static KeyboardShortcutProfile GetKeyboardShortcutProfile(List<KeyboardShortcutProfile> profiles, String name)
- {
- foreach (KeyboardShortcutProfile profile in profiles)
- if (profile.Name == name)
- return profile;
- return null;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="sc"></param>
- /// <param name="keysAsText"></param>
- /// <param name="isGlobal"></param>
- private static void SetKeyboardShortcut(KeyboardShortcut sc, String keysAsText, bool isGlobal = false)
- {
- sc.Keys = keysAsText;
- sc.IsGlobal = isGlobal;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="profile"></param>
- /// <param name="category"></param>
- /// <param name="name"></param>
- /// <param name="keysAsText"></param>
- /// <param name="isGlobal"></param>
- private static void SetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name, String keysAsText, bool isGlobal = false)
- {
- KeyboardShortcut sc = GetKeyboardShortcut(profile, category, name);
- if (sc == null)
- {
- sc = new KeyboardShortcut();
- sc.Category = category;
- sc.Name = name;
- profile.Shortcuts.Add(sc);
- }
- SetKeyboardShortcut(sc, keysAsText, isGlobal);
- }
-
- #endregion
-
- #region Dispatchers
-
- /// <summary>
- /// Trigger the PropertyChanged event
- /// </summary>
- /// <param name="name">The name of the property that was changed</param>
- /// <param name="oldValue">The value of the property before the change</param>
- /// <param name="newValue">The value of the property after the change</param>
- public static void DispatchPropertyChanged(string name, object oldValue, object newValue)
- {
- if (PropertyChanged != null && oldValue != newValue)
- PropertyChanged(null, new PropertyChangedWithValuesEventArgs(name, oldValue, newValue));
- }
-
- /// <summary>
- /// Trigger the Initialized event
- /// </summary>
- public static void DispatchInitialized()
- {
- U.L(LogLevel.Debug, "SETTINGS", "Dispatching initialized");
- IsInitialized = true;
- if (Initialized != null)
- Initialized(null, new EventArgs());
- }
-
- #endregion
-
- #endregion
-
- #region Events
-
- /// <summary>
- /// Occurs when a property has been changed
- /// </summary>
- public static event PropertyChangedWithValuesEventHandler PropertyChanged;
-
- /// <summary>
- /// Occurs when the manager has been fully initialized
- /// </summary>
- public static event EventHandler Initialized;
-
- #endregion
- }
-
- #region Delegates
-
- /// <summary>
- /// Represents the method that will be called with the PropertyChanged event occurs
- /// </summary>
- /