PageRenderTime 68ms CodeModel.GetById 11ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 1ms

/Application/Core/SettingsManager.cs

http://yet-another-music-application.googlecode.com/
C# | 1742 lines | 1186 code | 166 blank | 390 comment | 51 complexity | 74035fbbcacc701ba0931287a1453647 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/**
   2 * SettingsManager.cs
   3 * 
   4 * Takes care of initializing settings during first run.
   5 * The file also contains all data structures used to store
   6 * data of Stoffi.
   7 * 
   8 * * * * * * * * *
   9 * 
  10 * Copyright 2012 Simplare
  11 * 
  12 * This code is part of the Stoffi Music Player Project.
  13 * Visit our website at: stoffiplayer.com
  14 *
  15 * This program is free software; you can redistribute it and/or
  16 * modify it under the terms of the GNU General Public License
  17 * as published by the Free Software Foundation; either version
  18 * 3 of the License, or (at your option) any later version.
  19 * 
  20 * See stoffiplayer.com/license for more information.
  21 **/
  22
  23using System;
  24using System.Collections.Specialized;
  25using System.Collections.Generic;
  26using System.Collections.ObjectModel;
  27using System.ComponentModel;
  28using System.IO;
  29using System.Linq;
  30using System.Text;
  31using System.Threading;
  32using System.Globalization;
  33using System.Xml;
  34using System.Xml.Serialization;
  35
  36namespace Stoffi
  37{
  38	/// <summary>
  39	/// Represents a manager that takes care of all
  40	/// application settings.
  41	/// </summary>
  42	public static class SettingsManager
  43	{
  44		#region Members
  45
  46		private static double bufferSize = 0;
  47		private static bool isInitialized = false;
  48
  49		#endregion
  50
  51		#region Properties
  52
  53		/// <summary>
  54		/// Gets whether the manager has been initialized or not.
  55		/// </summary>
  56		public static bool IsInitialized { get { return isInitialized; } private set { isInitialized = value; } }
  57
  58		/// <summary>
  59		/// Gets the culture corresponding to Language.
  60		/// </summary>
  61		public static CultureInfo Culture
  62		{
  63			get { return CultureInfo.GetCultureInfo(Language); }
  64		}
  65
  66		#region GUI
  67
  68		/// <summary>
  69		/// Gets or sets the width of the main window
  70		/// </summary>
  71		public static double WinWidth
  72		{
  73			get { return Properties.Settings.Default.WinWidth; }
  74			set
  75			{
  76				object old = Properties.Settings.Default.WinWidth;
  77				Properties.Settings.Default.WinWidth = value;
  78				DispatchPropertyChanged("WinWidth", old, value);
  79			}
  80		}
  81
  82		/// <summary>
  83		/// Gets or sets the height of the main window
  84		/// </summary>
  85		public static double WinHeight
  86		{
  87			get { return Properties.Settings.Default.WinHeight; }
  88			set
  89			{
  90				object old = Properties.Settings.Default.WinHeight;
  91				Properties.Settings.Default.WinHeight = value;
  92				DispatchPropertyChanged("WinHeight", old, value);
  93			}
  94		}
  95
  96		/// <summary>
  97		/// Gets or sets the left position of the main window
  98		/// </summary>
  99		public static double WinLeft
 100		{
 101			get { return Properties.Settings.Default.WinLeft; }
 102			set
 103			{
 104				object old = Properties.Settings.Default.WinLeft;
 105				Properties.Settings.Default.WinLeft = value;
 106				DispatchPropertyChanged("WinLeft", old, value);
 107			}
 108		}
 109
 110		/// <summary>
 111		/// Gets or sets the top position of the main window
 112		/// </summary>
 113		public static double WinTop
 114		{
 115			get { return Properties.Settings.Default.WinTop; }
 116			set
 117			{
 118				object old = Properties.Settings.Default.WinTop;
 119				Properties.Settings.Default.WinTop = value;
 120				DispatchPropertyChanged("WinTop", old, value);
 121			}
 122		}
 123
 124		/// <summary>
 125		/// Gets or sets the state of the main window
 126		/// </summary>
 127		public static string WinState
 128		{
 129			get { return Properties.Settings.Default.WinState; }
 130			set
 131			{
 132				object old = Properties.Settings.Default.WinState;
 133				Properties.Settings.Default.WinState = value;
 134				DispatchPropertyChanged("WinState", old, value);
 135			}
 136		}
 137
 138		/// <summary>
 139		/// Gets or sets the height of the equalizer window
 140		/// </summary>
 141		public static double EqualizerHeight
 142		{
 143			get { return Properties.Settings.Default.EqualizerHeight; }
 144			set
 145			{
 146				object old = Properties.Settings.Default.EqualizerHeight;
 147				Properties.Settings.Default.EqualizerHeight = value;
 148				DispatchPropertyChanged("EqualizerHeight", old, value);
 149			}
 150		}
 151
 152		/// <summary>
 153		/// Gets or sets the width of the equalizer window
 154		/// </summary>
 155		public static double EqualizerWidth
 156		{
 157			get { return Properties.Settings.Default.EqualizerWidth; }
 158			set
 159			{
 160				object old = Properties.Settings.Default.EqualizerWidth;
 161				Properties.Settings.Default.EqualizerWidth = value;
 162				DispatchPropertyChanged("EqualizerWidth", old, value);
 163			}
 164		}
 165
 166		/// <summary>
 167		/// Gets or sets the left position of the equalizer window
 168		/// </summary>
 169		public static double EqualizerLeft
 170		{
 171			get { return Properties.Settings.Default.EqualizerLeft; }
 172			set
 173			{
 174				object old = Properties.Settings.Default.EqualizerLeft;
 175				Properties.Settings.Default.EqualizerLeft = value;
 176				DispatchPropertyChanged("EqualizerLeft", old, value);
 177			}
 178		}
 179
 180		/// <summary>
 181		/// Gets or sets the top position of the equalizer window
 182		/// </summary>
 183		public static double EqualizerTop
 184		{
 185			get { return Properties.Settings.Default.EqualizerTop; }
 186			set
 187			{
 188				object old = Properties.Settings.Default.EqualizerTop;
 189				Properties.Settings.Default.EqualizerTop = value;
 190				DispatchPropertyChanged("EqualizerTop", old, value);
 191			}
 192		}
 193
 194		/// <summary>
 195		/// Gets or sets the currently selected navigation
 196		/// </summary>
 197		public static string CurrentSelectedNavigation
 198		{
 199			get { return Properties.Settings.Default.CurrentSelectedNavigation; }
 200			set
 201			{
 202				object old = Properties.Settings.Default.CurrentSelectedNavigation;
 203				Properties.Settings.Default.CurrentSelectedNavigation = value;
 204				DispatchPropertyChanged("CurrentSelectedNavigation", old, value);
 205			}
 206		}
 207
 208		/// <summary>
 209		/// Gets or sets the width of the navigation pane
 210		/// </summary>
 211		public static double NavigationPaneWidth
 212		{
 213			get { return Properties.Settings.Default.NavigationPaneWidth; }
 214			set
 215			{
 216				object old = Properties.Settings.Default.NavigationPaneWidth;
 217				Properties.Settings.Default.NavigationPaneWidth = value;
 218				DispatchPropertyChanged("NavigationPaneWidth", old, value);
 219			}
 220		}
 221
 222		/// <summary>
 223		/// Gets or sets the height of the details pane
 224		/// </summary>
 225		public static double DetailsPaneHeight
 226		{
 227			get { return Properties.Settings.Default.DetailsPaneHeight; }
 228			set
 229			{
 230				object old = Properties.Settings.Default.DetailsPaneHeight;
 231				Properties.Settings.Default.DetailsPaneHeight = value;
 232				DispatchPropertyChanged("DetailsPaneHeight", old, value);
 233			}
 234		}
 235
 236		/// <summary>
 237		/// Gets or sets whether the details pane is visible
 238		/// </summary>
 239		public static bool DetailsPaneVisible
 240		{
 241			get { return Properties.Settings.Default.DetailsPaneVisibile; }
 242			set
 243			{
 244				bool same = value == Properties.Settings.Default.DetailsPaneVisibile;
 245				Properties.Settings.Default.DetailsPaneVisibile = value;
 246				object newValue = (object)value;
 247				object oldValue = same ? newValue : (object)Properties.Settings.Default.DetailsPaneVisibile;
 248				DispatchPropertyChanged("DetailsPaneVisibile", oldValue, newValue);
 249			}
 250		}
 251
 252		/// <summary>
 253		/// Gets or sets whether the menu bar is visible
 254		/// </summary>
 255		public static bool MenuBarVisibile
 256		{
 257			get { return Properties.Settings.Default.MenuBarVisibile; }
 258			set
 259			{
 260				bool same = value == Properties.Settings.Default.MenuBarVisibile;
 261				Properties.Settings.Default.MenuBarVisibile = value;
 262				object newValue = (object)value;
 263				object oldValue = same ? newValue : (object)Properties.Settings.Default.MenuBarVisibile;
 264				DispatchPropertyChanged("MenuBarVisibile", oldValue, newValue);
 265			}
 266		}
 267
 268		/// <summary>
 269		/// Gets or sets the language of the application
 270		/// </summary>
 271		public static string Language
 272		{
 273			get { return Properties.Settings.Default.Language; }
 274			set
 275			{
 276				object old = Properties.Settings.Default.Language;
 277				Properties.Settings.Default.Language = value;
 278				DispatchPropertyChanged("Language", old, value);
 279			}
 280		}
 281
 282		#endregion
 283
 284		#region Lists
 285
 286		/// <summary>
 287		/// Gets or sets the configuration of the history list
 288		/// </summary>
 289		public static ViewDetailsConfig HistoryListConfig
 290		{
 291			get { return Properties.Settings.Default.HistoryListConfig; }
 292			set
 293			{
 294				object old = Properties.Settings.Default.HistoryListConfig;
 295				Properties.Settings.Default.HistoryListConfig = value;
 296				DispatchPropertyChanged("HistoryListConfig", old, value);
 297			}
 298		}
 299
 300		/// <summary>
 301		/// Gets or sets the history tracks
 302		/// </summary>
 303		public static ObservableCollection<TrackData> HistoryTracks
 304		{
 305			get { return Properties.Settings.Default.HistoryTracks; }
 306			set
 307			{
 308				object old = Properties.Settings.Default.HistoryTracks;
 309				Properties.Settings.Default.HistoryTracks = value;
 310				DispatchPropertyChanged("HistoryTracks", old, value);
 311			}
 312		}
 313
 314		/// <summary>
 315		/// Gets or sets the configuration of the file list
 316		/// </summary>
 317		public static ViewDetailsConfig FileListConfig
 318		{
 319			get { return Properties.Settings.Default.LibraryListConfig; }
 320			set
 321			{
 322				object old = Properties.Settings.Default.LibraryListConfig;
 323				Properties.Settings.Default.LibraryListConfig = value;
 324				DispatchPropertyChanged("FileListConfig", old, value);
 325			}
 326		}
 327
 328		/// <summary>
 329		/// Gets or sets the file tracks
 330		/// </summary>
 331		public static ObservableCollection<TrackData> FileTracks
 332		{
 333			get { return Properties.Settings.Default.LibraryTracks; }
 334			set
 335			{
 336				object old = Properties.Settings.Default.LibraryTracks;
 337				Properties.Settings.Default.LibraryTracks = value;
 338				DispatchPropertyChanged("FileTracks", old, value);
 339			}
 340		}
 341
 342		/// <summary>
 343		/// Gets or sets the configuration of the queue list
 344		/// </summary>
 345		public static ViewDetailsConfig QueueListConfig
 346		{
 347			get { return Properties.Settings.Default.QueueListConfig; }
 348			set
 349			{
 350				object old = Properties.Settings.Default.QueueListConfig;
 351				Properties.Settings.Default.QueueListConfig = value;
 352				DispatchPropertyChanged("QueueListConfig", old, value);
 353			}
 354		}
 355
 356		/// <summary>
 357		/// Gets or sets the queue tracks
 358		/// </summary>
 359		public static ObservableCollection<TrackData> QueueTracks
 360		{
 361			get { return Properties.Settings.Default.QueueTracks; }
 362			set
 363			{
 364				object old = Properties.Settings.Default.QueueTracks;
 365				Properties.Settings.Default.QueueTracks = value;
 366				DispatchPropertyChanged("QueueTracks", old, value);
 367			}
 368		}
 369       
 370		/// <summary>
 371		/// Gets or sets the configuration of the source list
 372		/// </summary>
 373		public static ViewDetailsConfig SourceListConfig
 374		{
 375			get { return Properties.Settings.Default.SourceListConfig; }
 376			set
 377			{
 378				object old = Properties.Settings.Default.SourceListConfig;
 379				Properties.Settings.Default.SourceListConfig = value;
 380				DispatchPropertyChanged("SourceListConfig", old, value);
 381			}
 382		}
 383
 384		/// <summary>
 385		/// Gets or sets the sources where Stoffi looks for music
 386		/// </summary>
 387		public static ObservableCollection<SourceData> Sources
 388		{
 389			get { return Properties.Settings.Default.Sources; }
 390			set
 391			{
 392				object old = Properties.Settings.Default.Sources;
 393				Properties.Settings.Default.Sources = value;
 394				DispatchPropertyChanged("Sources", old, value);
 395			}
 396		}
 397
 398		/// <summary>
 399		/// Gets or sets the configuration of the youtube list
 400		/// </summary>
 401		public static ViewDetailsConfig YouTubeListConfig
 402		{
 403			get { return Properties.Settings.Default.YouTubeListConfig; }
 404			set
 405			{
 406				object old = Properties.Settings.Default.YouTubeListConfig;
 407				Properties.Settings.Default.YouTubeListConfig = value;
 408				DispatchPropertyChanged("YouTubeListConfig", old, value);
 409			}
 410		}
 411
 412		#endregion
 413
 414		#region Application parameters
 415
 416		/// <summary>
 417		/// Gets the architecture of the application.
 418		/// </summary>
 419		public static string Architecture
 420		{
 421			get { return Properties.Settings.Default.Architecture; }
 422		}
 423
 424		/// <summary>
 425		/// Gets the channel of the application (Alpha, Beta or Stable).
 426		/// </summary>
 427		public static string Channel
 428		{
 429			get { return Properties.Settings.Default.Channel; }
 430		}
 431
 432		/// <summary>
 433		/// Gets or sets the ID of the application
 434		/// </summary>
 435		public static int ID
 436		{
 437			get { return Properties.Settings.Default.ID; }
 438			set
 439			{
 440				// it may be null, although C# say int can't be null... :)
 441				object old = null;
 442				try
 443				{
 444					old = Properties.Settings.Default.ID;
 445				}
 446				catch { }
 447
 448				Properties.Settings.Default.ID = value;
 449				DispatchPropertyChanged("ID", old, value);
 450			}
 451		}
 452
 453		/// <summary>
 454		/// Gets the version of the application
 455		/// </summary>
 456		public static long Version
 457		{
 458			get { return Properties.Settings.Default.Version; }
 459		}
 460
 461		/// <summary>
 462		/// Gets the release of the application
 463		/// </summary>
 464		public static string Release
 465		{
 466			get { return Properties.Settings.Default.Release; }
 467		}
 468
 469		#endregion
 470
 471		#region Settings
 472
 473		/// <summary>
 474		/// Gets or sets how the upgrades of the application should be performed
 475		/// </summary>
 476		public static UpgradePolicy UpgradePolicy
 477		{
 478			get { return Properties.Settings.Default.UpgradePolicy; }
 479			set
 480			{
 481				object old = Properties.Settings.Default.UpgradePolicy;
 482				Properties.Settings.Default.UpgradePolicy = value;
 483				DispatchPropertyChanged("UpgradePolicy", old, value);
 484			}
 485		}
 486
 487		/// <summary>
 488		/// Gets or sets how different list should share search filters
 489		/// </summary>
 490		public static SearchPolicy SearchPolicy
 491		{
 492			get { return Properties.Settings.Default.SearchPolicy; }
 493			set
 494			{
 495				object old = Properties.Settings.Default.SearchPolicy;
 496				Properties.Settings.Default.SearchPolicy = value;
 497				DispatchPropertyChanged("SearchPolicy", old, value);
 498			}
 499		}
 500
 501		/// <summary>
 502		/// Gets or sets how to add a track when it's opened with the application
 503		/// </summary>
 504		public static OpenAddPolicy OpenAddPolicy
 505		{
 506			get { return Properties.Settings.Default.OpenAddPolicy; }
 507			set
 508			{
 509				object old = Properties.Settings.Default.OpenAddPolicy;
 510				Properties.Settings.Default.OpenAddPolicy = value;
 511				DispatchPropertyChanged("OpenAddPolicy", old, value);
 512			}
 513		}
 514
 515		/// <summary>
 516		/// Gets or sets how to play a track when it's opened with the application
 517		/// </summary>
 518		public static OpenPlayPolicy OpenPlayPolicy
 519		{
 520			get { return Properties.Settings.Default.OpenPlayPolicy; }
 521			set
 522			{
 523				object old = Properties.Settings.Default.OpenPlayPolicy;
 524				Properties.Settings.Default.OpenPlayPolicy = value;
 525				DispatchPropertyChanged("OpenPlayPolicy", old, value);
 526			}
 527		}
 528
 529		/// <summary>
 530		/// Gets or sets whether the application should stay visible in the taskbar when it's minimized
 531		/// </summary>
 532		public static bool MinimizeToTray
 533		{
 534			get { return Properties.Settings.Default.MinimizeToTray; }
 535			set
 536			{
 537				bool same = value == Properties.Settings.Default.MinimizeToTray;
 538				Properties.Settings.Default.MinimizeToTray = value;
 539				object newValue = (object)value;
 540				object oldValue = same ? newValue : (object)Properties.Settings.Default.MinimizeToTray;
 541				DispatchPropertyChanged("MinimizeToTray", oldValue, newValue);
 542			}
 543		}
 544
 545		/// <summary>
 546		/// Gets or sets whether to show a notification when a new track is played
 547		/// </summary>
 548		public static bool ShowOSD
 549		{
 550			get { return Properties.Settings.Default.ShowOSD; }
 551			set
 552			{
 553				bool same = value == Properties.Settings.Default.ShowOSD;
 554				Properties.Settings.Default.ShowOSD = value;
 555				object newValue = (object)value;
 556				object oldValue = same ? newValue : (object)Properties.Settings.Default.ShowOSD;
 557				DispatchPropertyChanged("ShowOSD", oldValue, newValue);
 558			}
 559		}
 560
 561		/// <summary>
 562		/// Gets or sets whether to pause playback while computer is locked
 563		/// </summary>
 564		public static bool PauseWhileLocked
 565		{
 566			get { return Properties.Settings.Default.PauseWhileLocked; }
 567			set
 568			{
 569				object old = Properties.Settings.Default.PauseWhileLocked;
 570				Properties.Settings.Default.PauseWhileLocked = value;
 571				DispatchPropertyChanged("PauseWhileLocked", old, value);
 572			}
 573		}
 574
 575		/// <summary>
 576		/// Gets or sets whether to pause playback while user is logged out
 577		/// </summary>
 578		public static bool PauseWhileLoggedOut
 579		{
 580			get { return Properties.Settings.Default.PauseWhileLoggedOut; }
 581			set
 582			{
 583				object old = Properties.Settings.Default.PauseWhileLoggedOut;
 584				Properties.Settings.Default.PauseWhileLoggedOut = value;
 585				DispatchPropertyChanged("PauseWhileLoggedOut", old, value);
 586			}
 587		}
 588
 589		/// <summary>
 590		/// Gets or sets the currently used orofile of keyboard shortcuts
 591		/// </summary>
 592		public static string CurrentShortcutProfile
 593		{
 594			get { return Properties.Settings.Default.CurrentShortcutProfile; }
 595			set
 596			{
 597				object old = Properties.Settings.Default.CurrentShortcutProfile;
 598				Properties.Settings.Default.CurrentShortcutProfile = value;
 599				DispatchPropertyChanged("CurrentShortcutProfile", old, value);
 600			}
 601		}
 602
 603		/// <summary>
 604		/// Gets or sets the keyboard shortcut profiles
 605		/// </summary>
 606		public static List<KeyboardShortcutProfile> ShortcutProfiles
 607		{
 608			get { return Properties.Settings.Default.ShortcutProfiles; }
 609			set
 610			{
 611				object old = Properties.Settings.Default.ShortcutProfiles;
 612				Properties.Settings.Default.ShortcutProfiles = value;
 613				DispatchPropertyChanged("ShortcutProfiles", old, value);
 614			}
 615		}
 616
 617		#endregion
 618
 619		#region Playback
 620
 621		/// <summary>
 622		/// Gets or sets the navigation that the currently playing track belongs to
 623		/// </summary>
 624		public static string CurrentActiveNavigation
 625		{
 626			get { return Properties.Settings.Default.CurrentActiveNavigation; }
 627			set
 628			{
 629				object old = Properties.Settings.Default.CurrentActiveNavigation;
 630				Properties.Settings.Default.CurrentActiveNavigation = value;
 631				DispatchPropertyChanged("CurrentActiveNavigation", old, value);
 632			}
 633		}
 634
 635		/// <summary>
 636		/// Gets or sets the currently playing track
 637		/// </summary>
 638		public static TrackData CurrentTrack
 639		{
 640			get { return Properties.Settings.Default.CurrentTrack; }
 641			set
 642			{
 643				object old = Properties.Settings.Default.CurrentTrack;
 644				Properties.Settings.Default.CurrentTrack = value;
 645				DispatchPropertyChanged("CurrentTrack", old, value);
 646			}
 647		}
 648
 649		/// <summary>
 650		/// Gets or sets the current equalizer profile
 651		/// </summary>
 652		public static EqualizerProfile CurrentEqualizerProfile
 653		{
 654			get { return Properties.Settings.Default.CurrentEqualizerProfile; }
 655			set
 656			{
 657				object old = Properties.Settings.Default.CurrentEqualizerProfile;
 658				Properties.Settings.Default.CurrentEqualizerProfile = value;
 659				DispatchPropertyChanged("CurrentEqualizerProfile", old, value);
 660			}
 661		}
 662
 663		/// <summary>
 664		/// Gets or sets equalizer levels
 665		/// </summary>
 666		public static List<EqualizerProfile> EqualizerProfiles
 667		{
 668			get { return Properties.Settings.Default.EqualizerProfiles; }
 669			set
 670			{
 671				object old = Properties.Settings.Default.EqualizerProfiles;
 672				Properties.Settings.Default.EqualizerProfiles = value;
 673				DispatchPropertyChanged("EqualizerProfiles", old, value);
 674			}
 675		}
 676
 677		/// <summary>
 678		/// Gets or sets where in history the current playback is
 679		/// </summary>
 680		public static int HistoryIndex
 681		{
 682			get { return Properties.Settings.Default.HistoryIndex; }
 683			set
 684			{
 685				object old = Properties.Settings.Default.HistoryIndex;
 686				Properties.Settings.Default.HistoryIndex = value;
 687				DispatchPropertyChanged("HistoryIndex", old, value);
 688			}
 689		}
 690
 691		/// <summary>
 692		/// Gets or sets whether to use shuffle when selecting the next track
 693		/// </summary>
 694		public static bool Shuffle
 695		{
 696			get { return Properties.Settings.Default.Shuffle; }
 697			set
 698			{
 699				bool same = value == Properties.Settings.Default.Shuffle;
 700				Properties.Settings.Default.Shuffle = value;
 701				object newValue = (object)value;
 702				object oldValue = same ? newValue : (object)Properties.Settings.Default.Shuffle;
 703				DispatchPropertyChanged("Shuffle", oldValue, newValue);
 704			}
 705		}
 706
 707		/// <summary>
 708		/// Gets or sets whether to repeat the tracks or not
 709		/// </summary>
 710		public static RepeatState Repeat
 711		{
 712			get { return Properties.Settings.Default.Repeat; }
 713			set
 714			{
 715				object old = Properties.Settings.Default.Repeat;
 716				Properties.Settings.Default.Repeat = value;
 717				DispatchPropertyChanged("Repeat", old, value);
 718			}
 719		}
 720
 721		/// <summary>
 722		/// Gets or sets the volume in percent.
 723		/// </summary>
 724		public static double Volume
 725		{
 726			get { return Properties.Settings.Default.Volume; }
 727			set
 728			{
 729				object old = Properties.Settings.Default.Volume;
 730				Properties.Settings.Default.Volume = value;
 731				DispatchPropertyChanged("Volume", old, value);
 732			}
 733		}
 734
 735		/// <summary>
 736		/// Gets or sets current position of the currently playing
 737		/// track as a value between 0 and 10
 738		/// </summary>
 739		public static double Seek
 740		{
 741			get { return Properties.Settings.Default.Seek; }
 742			set
 743			{
 744				object old = Properties.Settings.Default.Seek;
 745				Properties.Settings.Default.Seek = value;
 746				DispatchPropertyChanged("Seek", old, value);
 747			}
 748		}
 749
 750		/// <summary>
 751		/// Gets or sets the buffer size as a value between 0 and 10
 752		/// </summary>
 753		public static double BufferSize
 754		{
 755			get { return bufferSize; }
 756			set
 757			{
 758				object old = bufferSize;
 759				bufferSize = value;
 760				DispatchPropertyChanged("BufferSize", old, value);
 761			}
 762		}
 763
 764		/// <summary>
 765		/// Gets or sets the state of the media player
 766		/// </summary>
 767		public static MediaState MediaState
 768		{
 769			get { return Properties.Settings.Default.MediaState; }
 770			set
 771			{
 772				object old = Properties.Settings.Default.MediaState;
 773				Properties.Settings.Default.MediaState = value;
 774				DispatchPropertyChanged("MediaState", old, value);
 775			}
 776		}
 777
 778		#endregion
 779
 780		#region Cloud
 781
 782		/// <summary>
 783		/// Gets or sets the Synchronization to an account
 784		/// </summary>
 785		public static List<CloudIdentity> CloudIdentities
 786		{
 787			get
 788			{
 789				if (Properties.Settings.Default.CloudIdentities == null)
 790					Properties.Settings.Default.CloudIdentities = new List<CloudIdentity>();
 791				return Properties.Settings.Default.CloudIdentities;
 792			}
 793			set
 794			{
 795				object old = Properties.Settings.Default.CloudIdentities;
 796				Properties.Settings.Default.CloudIdentities = value;
 797				DispatchPropertyChanged("CloudIdentities", old, value);
 798			}
 799		}
 800
 801		/// <summary>
 802		/// Gets or sets the submition of tracks
 803		/// </summary>
 804		public static bool SubmitSongs
 805		{
 806			get { return Properties.Settings.Default.SubmitSongs; }
 807			set
 808			{
 809				object old = Properties.Settings.Default.SubmitSongs;
 810				Properties.Settings.Default.SubmitSongs = value;
 811				DispatchPropertyChanged("SubmitSongs", old, value);
 812			}
 813		}
 814
 815		/// <summary>
 816		/// gets or sets the submition of playlists
 817		/// </summary>
 818		public static bool SubmitPlaylists
 819		{
 820			get { return Properties.Settings.Default.SubmitPlaylists; }
 821			set
 822			{
 823				object old = Properties.Settings.Default.SubmitPlaylists;
 824				Properties.Settings.Default.SubmitPlaylists = value;
 825				DispatchPropertyChanged("SubmitPlaylists", old, value);
 826			}
 827		}
 828		
 829		#endregion
 830
 831		#region Misc
 832
 833		/// <summary>
 834		/// Gets or sets whether the application has never been run before
 835		/// </summary>
 836		public static bool FirstRun
 837		{
 838			get { return Properties.Settings.Default.FirstRun; }
 839			set
 840			{
 841				object old = Properties.Settings.Default.FirstRun;
 842				Properties.Settings.Default.FirstRun = value;
 843				DispatchPropertyChanged("FirstRun", old, value);
 844			}
 845		}
 846
 847		/// <summary>
 848		/// Gets or sets the last time the application checked for an upgrade
 849		/// </summary>
 850		public static long UpgradeCheck
 851		{
 852			get { return Properties.Settings.Default.UpgradeCheck; }
 853			set
 854			{
 855				object old = Properties.Settings.Default.UpgradeCheck;
 856				Properties.Settings.Default.UpgradeCheck = value;
 857				DispatchPropertyChanged("UpgradeCheck", old, value);
 858			}
 859		}
 860
 861
 862
 863		/// <summary>
 864		/// Gets or sets the playlists
 865		/// </summary>
 866		public static List<PlaylistData> Playlists
 867		{
 868			get { return Properties.Settings.Default.Playlists; }
 869			set
 870			{
 871				object old = Properties.Settings.Default.Playlists;
 872				Properties.Settings.Default.Playlists = value;
 873				DispatchPropertyChanged("Playlists", old, value);
 874			}
 875		}
 876
 877		/// <summary>
 878		/// Gets or sets the OAuth secret
 879		/// </summary>
 880		public static string OAuthSecret
 881		{
 882			get { return Properties.Settings.Default.OAuthSecret; }
 883			set
 884			{
 885				object old = Properties.Settings.Default.OAuthSecret;
 886				Properties.Settings.Default.OAuthSecret = value;
 887				DispatchPropertyChanged("OAuthSecret", old, value);
 888			}
 889		}
 890
 891		/// <summary>
 892		/// Gets or sets the OAuth token
 893		/// </summary>
 894		public static string OAuthToken
 895		{
 896			get { return Properties.Settings.Default.OAuthToken; }
 897			set
 898			{
 899				object old = Properties.Settings.Default.OAuthToken;
 900				Properties.Settings.Default.OAuthToken = value;
 901				DispatchPropertyChanged("OAuthToken", old, value);
 902			}
 903		}
 904
 905		#endregion
 906
 907		#endregion
 908
 909		#region Methods
 910
 911		#region Public
 912
 913		/// <summary>
 914		/// Initializes the settings manager
 915		/// </summary>
 916		public static void Initialize()
 917		{
 918			if (FirstRun)
 919			{
 920				CurrentTrack = null;
 921
 922				Sources = new ObservableCollection<SourceData>();
 923				Playlists = new List<PlaylistData>();
 924
 925				// TODO: set default language according to system language
 926				//SettingsManager.Language = ???
 927
 928				#region Track collections
 929
 930				FileTracks = new ObservableCollection<TrackData>();
 931				HistoryTracks = new ObservableCollection<TrackData>();
 932				QueueTracks = new ObservableCollection<TrackData>();
 933
 934				#endregion
 935
 936				#region Equalizer
 937
 938				EqualizerProfiles = new List<EqualizerProfile>();
 939				EqualizerProfiles.Add(CreateEqualizerLevel(U.T("EqualizerProfileDefault"), new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, true));
 940				CurrentEqualizerProfile = EqualizerProfiles[0];
 941
 942				#endregion
 943
 944				#region Shortcuts
 945
 946				ShortcutProfiles = new List<KeyboardShortcutProfile>();
 947
 948				// Stoffi
 949				KeyboardShortcutProfile shortStoffi = new KeyboardShortcutProfile();
 950				InitShortcutProfile(shortStoffi, "Stoffi", true);
 951				ShortcutProfiles.Add(shortStoffi);
 952
 953				// Amarok
 954				KeyboardShortcutProfile shortAmarok = new KeyboardShortcutProfile();
 955				InitShortcutProfile(shortAmarok, "Amarok", true);
 956				SetKeyboardShortcut(shortAmarok, "Application", "Add track", "Win+A");
 957				SetKeyboardShortcut(shortAmarok, "Application", "Open playlist", "Space");
 958				SetKeyboardShortcut(shortAmarok, "MediaCommands", "Play or pause", "Win+X");
 959				SetKeyboardShortcut(shortAmarok, "MediaCommands", "Next", "Win+B");
 960				SetKeyboardShortcut(shortAmarok, "MediaCommands", "Previous", "Win+Z");
 961				SetKeyboardShortcut(shortAmarok, "MediaCommands", "Toggle shuffle", "Ctrl+H");
 962				ShortcutProfiles.Add(shortAmarok);
 963
 964				// Banshee
 965				KeyboardShortcutProfile shortBanshee = new KeyboardShortcutProfile();
 966				InitShortcutProfile(shortBanshee, "Banshee", true);
 967				SetKeyboardShortcut(shortBanshee, "Application", "Add track", "Ctrl+L");
 968				SetKeyboardShortcut(shortBanshee, "Application", "Close", "Ctrl+Q");
 969				SetKeyboardShortcut(shortBanshee, "MediaCommands", "Play or pause", "Space");
 970				SetKeyboardShortcut(shortBanshee, "MediaCommands", "Next", "N");
 971				SetKeyboardShortcut(shortBanshee, "MediaCommands", "Previous", "B");
 972				SetKeyboardShortcut(shortBanshee, "MainWindow", "Search", "/ (numpad)");
 973				ShortcutProfiles.Add(shortBanshee);
 974
 975				// Foobar2000
 976				KeyboardShortcutProfile shortFoobar2000 = new KeyboardShortcutProfile();
 977				InitShortcutProfile(shortFoobar2000, "Foobar2000", true);
 978				SetKeyboardShortcut(shortFoobar2000, "Application", "Add track", "Ctrl+O");
 979				SetKeyboardShortcut(shortFoobar2000, "Application", "Add folder", "Ctrl+A");
 980				SetKeyboardShortcut(shortFoobar2000, "Application", "Open playlist", "Ctrl+L");
 981				SetKeyboardShortcut(shortFoobar2000, "MainWindow", "Search", "Ctrl+F");
 982				SetKeyboardShortcut(shortFoobar2000, "MainWindow", "General preferences", "Ctrl+P");
 983				ShortcutProfiles.Add(shortFoobar2000);
 984
 985				// iTunes
 986				KeyboardShortcutProfile shortiTunes = new KeyboardShortcutProfile();
 987				InitShortcutProfile(shortiTunes, "iTunes", true);
 988				SetKeyboardShortcut(shortiTunes, "Application", "Add track", "Ctrl+O");
 989				SetKeyboardShortcut(shortiTunes, "Application", "Open playlist", "Ctrl+P");
 990				SetKeyboardShortcut(shortiTunes, "MainWindow", "General preferences", "Ctrl+,");
 991				SetKeyboardShortcut(shortiTunes, "MediaCommands", "Play or pause", "Space");
 992				SetKeyboardShortcut(shortiTunes, "MediaCommands", "Increase volume", "Ctrl+Up");
 993				SetKeyboardShortcut(shortiTunes, "MediaCommands", "Decrease volume", "Ctrl+Down");
 994				SetKeyboardShortcut(shortiTunes, "MediaCommands", "Previous", "Left");
 995				SetKeyboardShortcut(shortiTunes, "MediaCommands", "Next", "Right");
 996				SetKeyboardShortcut(shortiTunes, "Track", "View information", "Ctrl+J");
 997				ShortcutProfiles.Add(shortiTunes);
 998
 999				// MusicBee
1000				KeyboardShortcutProfile shortMusicBee = new KeyboardShortcutProfile();
1001				InitShortcutProfile(shortMusicBee, "MusicBee", true);
1002				SetKeyboardShortcut(shortMusicBee, "MainWindow", "Search", "Ctrl+F");
1003				SetKeyboardShortcut(shortMusicBee, "MainWindow", "General preferences", "Ctrl+O");
1004				SetKeyboardShortcut(shortMusicBee, "Application", "Open playlist", "Ctrl+L");
1005				SetKeyboardShortcut(shortMusicBee, "MainWindow", "Create playlist", "Ctrl+C");
1006				SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Play or pause", "Ctrl+P");
1007				SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Next", "Ctrl+N");
1008				SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Previous", "Ctrl+B");
1009				SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Increase volume", "Ctrl+Up");
1010				SetKeyboardShortcut(shortMusicBee, "MediaCommands", "Decrease volume", "Ctrl+Down");
1011				SetKeyboardShortcut(shortMusicBee, "Track", "Queue and dequeue", "Ctrl+Enter");
1012				SetKeyboardShortcut(shortMusicBee, "Track", "View information", "Alt+E");
1013				ShortcutProfiles.Add(shortMusicBee);
1014
1015				// Rythmbox
1016				KeyboardShortcutProfile shortRythmbox = new KeyboardShortcutProfile();
1017				InitShortcutProfile(shortRythmbox, "Rythmbox", true);
1018				SetKeyboardShortcut(shortRythmbox, "Application", "Close", "Ctrl+Q");
1019				SetKeyboardShortcut(shortRythmbox, "Application", "Add folder", "Ctrl+O");
1020				SetKeyboardShortcut(shortRythmbox, "Application", "Open playlist", "Ctrl+P");
1021				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Play or pause", "Ctrl+Space");
1022				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Previous", "Alt+Left");
1023				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Jump to previous bookmark", "Alt+,");
1024				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Next", "Alt+Right");
1025				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Jump to next bookmark", "Alt+.");
1026				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Increase volume", "Ctrl+Up");
1027				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Decrease volume", "Ctrl+Down");
1028				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Toggle shuffle", "Ctrl+U");
1029				SetKeyboardShortcut(shortRythmbox, "MediaCommands", "Toggle repeat", "Ctrl+R");
1030				SetKeyboardShortcut(shortRythmbox, "Track", "View information", "Alt+Enter");
1031				ShortcutProfiles.Add(shortRythmbox);
1032
1033				// Spotify
1034				KeyboardShortcutProfile shortSpotify = new KeyboardShortcutProfile();
1035				InitShortcutProfile(shortSpotify, "Spotify", true);
1036				SetKeyboardShortcut(shortSpotify, "MediaCommands", "Next", "Ctrl+Right");
1037				SetKeyboardShortcut(shortSpotify, "MediaCommands", "Previous", "Ctrl+Left");
1038				SetKeyboardShortcut(shortSpotify, "MediaCommands", "Increase volume", "Ctrl+Up");
1039				SetKeyboardShortcut(shortSpotify, "MediaCommands", "Decrease volume", "Ctrl+Down");
1040				SetKeyboardShortcut(shortSpotify, "MainWindow", "Library", "Ctrl+I");
1041				SetKeyboardShortcut(shortSpotify, "MainWindow", "Search", "Ctrl+L");
1042				SetKeyboardShortcut(shortSpotify, "MainWindow", "General preferences", "Ctrl+P");
1043				ShortcutProfiles.Add(shortSpotify);
1044
1045				// VLC
1046				KeyboardShortcutProfile shortVLC = new KeyboardShortcutProfile();
1047				InitShortcutProfile(shortVLC, "VLC", true);
1048				SetKeyboardShortcut(shortVLC, "Application", "Add track", "Ctrl+O");
1049				SetKeyboardShortcut(shortVLC, "Application", "Open playlist", "Ctrl+Y");
1050				SetKeyboardShortcut(shortVLC, "Application", "Close", "Ctrl+Q");
1051				SetKeyboardShortcut(shortVLC, "MainWindow", "Playlists", "Ctrl+L");
1052				SetKeyboardShortcut(shortVLC, "MainWindow", "Library", "Ctrl+I");
1053				SetKeyboardShortcut(shortVLC, "MainWindow", "General preferences", "Ctrl+P");
1054				SetKeyboardShortcut(shortVLC, "MediaCommands", "Next", "N");
1055				SetKeyboardShortcut(shortVLC, "MediaCommands", "Previous", "P");
1056				SetKeyboardShortcut(shortVLC, "MediaCommands", "Seek backward", "Ctrl+Left");
1057				SetKeyboardShortcut(shortVLC, "MediaCommands", "Seek forward", "Ctrl+Right");
1058				SetKeyboardShortcut(shortVLC, "MediaCommands", "Increase volume", "Ctrl+Up");
1059				SetKeyboardShortcut(shortVLC, "MediaCommands", "Decrease volume", "Ctrl+Down");
1060				SetKeyboardShortcut(shortVLC, "MediaCommands", "Toggle shuffle", "R");
1061				SetKeyboardShortcut(shortVLC, "MediaCommands", "Toggle repeat", "L");
1062				ShortcutProfiles.Add(shortVLC);
1063
1064				// Winamp
1065				KeyboardShortcutProfile shortWinamp = new KeyboardShortcutProfile();
1066				InitShortcutProfile(shortWinamp, "Winamp", true);
1067				SetKeyboardShortcut(shortWinamp, "Application", "Add track", "Ctrl+Alt+L");
1068				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Play or pause", "Ctrl+Alt+Insert", true);
1069				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Next", "Ctrl+Alt+PageDown", true);
1070				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Previous", "Ctrl+Alt+PageUp", true);
1071				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Increase volume", "Ctrl+Alt+Up", true);
1072				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Decrease volume", "Ctrl+Alt+Down", true);
1073				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Seek forward", "Ctrl+Alt+Right", true);
1074				SetKeyboardShortcut(shortWinamp, "MediaCommands", "Seek backward", "Ctrl+Alt+Left", true);
1075				ShortcutProfiles.Add(shortWinamp);
1076
1077				// Windows Media Player
1078				KeyboardShortcutProfile shortWMP = new KeyboardShortcutProfile();
1079				InitShortcutProfile(shortWMP, "Windows Media Player", true);
1080				SetKeyboardShortcut(shortWMP, "Application", "Add track", "Ctrl+O");
1081				SetKeyboardShortcut(shortWMP, "Application", "Open playlist", "Ctrl+L");
1082				SetKeyboardShortcut(shortWMP, "MainWindow", "Library", "Ctrl+1");
1083				SetKeyboardShortcut(shortWMP, "MediaCommands", "Play or pause", "Ctrl+P");
1084				SetKeyboardShortcut(shortWMP, "MediaCommands", "Next", "Ctrl+Right");
1085				SetKeyboardShortcut(shortWMP, "MediaCommands", "Previous", "Ctrl+Left");
1086				SetKeyboardShortcut(shortWMP, "MediaCommands", "Seek forward", "Ctrl+Shift+F");
1087				SetKeyboardShortcut(shortWMP, "MediaCommands", "Seek backward", "Ctrl+Shift+B");
1088				SetKeyboardShortcut(shortWMP, "MediaCommands", "Toggle shuffle", "Ctrl+H");
1089				SetKeyboardShortcut(shortWMP, "MediaCommands", "Toggle repeat", "Ctrl+T");
1090				SetKeyboardShortcut(shortWMP, "MediaCommands", "Increase volume", "F9");
1091				SetKeyboardShortcut(shortWMP, "MediaCommands", "Decrease volume", "F8");
1092				SetKeyboardShortcut(shortWMP, "MainWindow", "Search", "Ctrl+E");
1093				ShortcutProfiles.Add(shortWMP);
1094
1095				#endregion
1096
1097				#region ViewDetails lists
1098
1099				// sources list
1100				ViewDetailsConfig sourceConfig = CreateListConfig();
1101				sourceConfig.Columns.Add(CreateListColumn("Data", U.T("ColumnLocation"), "Data", 200));
1102				sourceConfig.Columns.Add(CreateListColumn("Type", U.T("ColumnType"), "HumanType", 150));
1103				SourceListConfig = sourceConfig;
1104
1105				// youtube list
1106				ViewDetailsConfig youtubeConfig = CreateListConfig();
1107				youtubeConfig.AcceptFileDrops = false;
1108				youtubeConfig.IsDragSortable = false;
1109				youtubeConfig.Columns.Add(CreateListColumn("Title", U.T("ColumnTitle"), "Title", 300));
1110				youtubeConfig.Columns.Add(CreateListColumn("Artist", U.T("ColumnArtist"), "Artist", 150));
1111				youtubeConfig.Columns.Add(CreateListColumn("Views", U.T("ColumnViews"), "Views", "RawViews", 170, System.Windows.HorizontalAlignment.Right));
1112				youtubeConfig.Columns.Add(CreateListColumn("Length", U.T("ColumnLength"), "Length", "RawLength", 150, System.Windows.HorizontalAlignment.Right));
1113				youtubeConfig.Columns.Add(CreateListColumn("Path", U.T("ColumnPath"), "Path", 200));
1114				YouTubeListConfig = youtubeConfig;
1115
1116				// library list
1117				ViewDetailsConfig libList = CreateListConfig();
1118				InitViewDetailsConfig(libList);
1119				FileListConfig = libList;
1120
1121				// queue list
1122				ViewDetailsConfig queueList = CreateListConfig();
1123				queueList.IsNumberVisible = true;
1124				InitViewDetailsConfig(queueList);
1125				QueueListConfig = queueList;
1126
1127				// history list
1128				ViewDetailsConfig historyList = CreateListConfig();
1129				historyList.Columns.Add(CreateListColumn("LastPlayed", U.T("ColumnPlayed"), "LastPlayed", 200));
1130				historyList.Columns.Add(CreateListColumn("Artist", U.T("ColumnArtist"), "Artist", 100));
1131				historyList.Columns.Add(CreateListColumn("Album", U.T("ColumnAlbum"), "Album", 100));
1132				historyList.Columns.Add(CreateListColumn("Title", U.T("ColumnTitle"), "Title", 100));
1133				historyList.Columns.Add(CreateListColumn("Genre", U.T("ColumnGenre"), "Genre", 100));
1134				historyList.Columns.Add(CreateListColumn("Length", U.T("ColumnLength"), "Length", "RawLength", 100, System.Windows.HorizontalAlignment.Right));
1135				historyList.Columns.Add(CreateListColumn("Year", U.T("ColumnYear"), "Year", "Year", 100, System.Windows.HorizontalAlignment.Right));
1136				historyList.Columns.Add(CreateListColumn("PlayCount", U.T("ColumnPlayCount"), "PlayCount", 100, System.Windows.HorizontalAlignment.Right));
1137				historyList.Columns.Add(CreateListColumn("Path", U.T("ColumnPath"), "Path", 200));
1138				historyList.Columns.Add(CreateListColumn("Track", U.T("ColumnTrack"), "Track", 100, System.Windows.HorizontalAlignment.Right));
1139				HistoryListConfig = historyList;
1140
1141				#endregion
1142
1143				//Save();
1144			}
1145			
1146			// fix source on all tracks
1147			foreach (TrackData t in SettingsManager.FileTracks)
1148				t.Source = "Library";
1149			foreach (PlaylistData p in SettingsManager.Playlists)
1150				foreach (TrackData t in p.Tracks)
1151					t.Source = "Playlist:" + p.Name;
1152
1153			DispatchInitialized();
1154		}
1155
1156		/// <summary>
1157		/// Saves the settings
1158		/// </summary>
1159		public static void Save()
1160		{
1161			Properties.Settings.Default.Save();
1162		}
1163
1164		/// <summary>
1165		/// Export the current configuration to an xml file
1166		/// </summary>
1167		/// <param name="filename">The path to the file</param>
1168		public static void Export(string filename)
1169		{
1170			Config c = new Config();
1171
1172			// tracks
1173			c.Collection = ExportTracks(SettingsManager.FileTracks);
1174			c.History = ExportTracks(SettingsManager.HistoryTracks);
1175			c.Queue = ExportTracks(SettingsManager.QueueTracks);
1176			c.Playlists = new List<ConfigPlaylist>();
1177			foreach (PlaylistData p in SettingsManager.Playlists)
1178			{
1179				ConfigPlaylist cp = new ConfigPlaylist();
1180				cp.Name = p.Name;
1181				cp.Tracks = ExportTracks(p.Tracks);
1182				cp.ListConfig = p.ListConfig;
1183				c.Playlists.Add(cp);
1184			}
1185
1186			c.CurrentActiveNavigation = SettingsManager.CurrentActiveNavigation;
1187			c.CurrentSelectedNavigation = SettingsManager.CurrentSelectedNavigation;
1188			c.CurrentShortcutProfile = SettingsManager.CurrentShortcutProfile;
1189			c.CurrentTrack = ExportTrack(SettingsManager.CurrentTrack);
1190			c.DetailsPaneVisible = SettingsManager.DetailsPaneVisible;
1191			c.FileListConfig = SettingsManager.FileListConfig;
1192			c.HistoryIndex = SettingsManager.HistoryIndex;
1193			c.HistoryListConfig = SettingsManager.HistoryListConfig;
1194			c.Language = SettingsManager.Language;
1195			c.MenuBarVisibile = SettingsManager.MenuBarVisibile;
1196			c.MinimizeToTray = SettingsManager.MinimizeToTray;
1197			c.OpenAddPolicy = SettingsManager.OpenAddPolicy;
1198			c.OpenPlayPolicy = SettingsManager.OpenPlayPolicy;
1199			c.QueueListConfig = SettingsManager.QueueListConfig;
1200			c.Repeat = SettingsManager.Repeat;
1201			c.SearchPolicy = SettingsManager.SearchPolicy;
1202			c.Seek = SettingsManager.Seek;
1203			c.Volume = SettingsManager.Volume;
1204			c.ShortcutProfiles = SettingsManager.ShortcutProfiles;
1205			c.ShowOSD = SettingsManager.ShowOSD;
1206			c.Shuffle = SettingsManager.Shuffle;
1207			c.SourceListConfig = SettingsManager.SourceListConfig;
1208			c.UpgradePolicy = SettingsManager.UpgradePolicy;
1209			c.YouTubeListConfig = SettingsManager.YouTubeListConfig;
1210
1211			// serialize to xml
1212			XmlSerializer ser = new XmlSerializer(typeof(Config));
1213			TextWriter w = new StreamWriter(filename);
1214			ser.Serialize(w, c);
1215			w.Close();
1216		}
1217
1218		/// <summary>
1219		/// Import and apply a configuration from an xml file
1220		/// </summary>
1221		/// <param name="filename">The path of the file</param>
1222		public static void Import(string filename)
1223		{
1224			XmlSerializer ser = new XmlSerializer(typeof(Config));
1225			FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
1226			Config c = (Config)ser.Deserialize(fs);
1227			fs.Close();
1228
1229			// tracks
1230			SettingsManager.FileTracks.Clear();
1231			SettingsManager.HistoryTracks.Clear();
1232			SettingsManager.QueueTracks.Clear();
1233			ImportTracks(c.Collection, SettingsManager.FileTracks, false);
1234			ImportTracks(c.History, SettingsManager.HistoryTracks);
1235			ImportTracks(c.Queue, SettingsManager.QueueTracks);
1236			SettingsManager.Playlists.Clear();
1237			foreach (ConfigPlaylist p in c.Playlists)
1238			{
1239				PlaylistData pl = PlaylistManager.FindPlaylist(p.Name);
1240				if (pl == null)
1241					pl = PlaylistManager.CreatePlaylist(p.Name);
1242				ImportTracks(p.Tracks, pl.Tracks);
1243				pl.ListConfig = p.ListConfig;
1244			}
1245
1246			SettingsManager.CurrentActiveNavigation = c.CurrentActiveNavigation;
1247			SettingsManager.CurrentSelectedNavigation = c.CurrentSelectedNavigation;
1248			SettingsManager.CurrentShortcutProfile = c.CurrentShortcutProfile;
1249			SettingsManager.CurrentTrack = ImportTrack(c.CurrentTrack);
1250			SettingsManager.DetailsPaneVisible = c.DetailsPaneVisible;
1251			SettingsManager.FileListConfig = c.FileListConfig;
1252			SettingsManager.HistoryIndex = c.HistoryIndex;
1253			SettingsManager.HistoryListConfig = c.HistoryListConfig;
1254			SettingsManager.Language = c.Language;
1255			SettingsManager.MenuBarVisibile = c.MenuBarVisibile;
1256			SettingsManager.MinimizeToTray = c.MinimizeToTray;
1257			SettingsManager.OpenAddPolicy = c.OpenAddPolicy;
1258			SettingsManager.OpenPlayPolicy = c.OpenPlayPolicy;
1259			SettingsManager.QueueListConfig = c.QueueListConfig;
1260			SettingsManager.Repeat = c.Repeat;
1261			SettingsManager.SearchPolicy = c.SearchPolicy;
1262			SettingsManager.Seek = c.Seek;
1263			SettingsManager.Volume = c.Volume;
1264			SettingsManager.ShortcutProfiles = c.ShortcutProfiles;
1265			SettingsManager.ShowOSD = c.ShowOSD;
1266			SettingsManager.Shuffle = c.Shuffle;
1267			SettingsManager.SourceListConfig = c.SourceListConfig;
1268			SettingsManager.UpgradePolicy = c.UpgradePolicy;
1269			SettingsManager.YouTubeListConfig = c.YouTubeListConfig;
1270		}
1271
1272		/// <summary>
1273		/// Retrieves the an equalizer profile given its name
1274		/// </summary>
1275		/// <param name="name">The name of the profile</param>
1276		/// <returns>The equalizer profile with the given name</returns>
1277		public static EqualizerProfile GetEqualizerProfile(string name)
1278		{
1279			foreach (EqualizerProfile p in EqualizerProfiles)
1280				if (p.IsProtected && U.T("EqualizerProfile" + p.Name) == name || p.Name == name)
1281					return p;
1282			return EqualizerProfiles[0];
1283		}
1284
1285		/// <summary>
1286		/// 
1287		/// </summary>
1288		/// <returns></returns>
1289		public static KeyboardShortcutProfile GetCurrentShortcutProfile()
1290		{
1291			try
1292			{
1293				foreach (KeyboardShortcutProfile p in ShortcutProfiles)
1294					if (p.Name == CurrentShortcutProfile)
1295						return p;
1296				return ShortcutProfiles[0];
1297			}
1298			catch { return null; }
1299		}
1300
1301		/// <summary>
1302		/// 
1303		/// </summary>
1304		/// <param name="profile"></param>
1305		/// <param name="keysAsText"></param>
1306		/// <returns></returns>
1307		public static KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String keysAsText)
1308		{
1309			if (profile != null)
1310				foreach (KeyboardShortcut s in profile.Shortcuts)
1311					if (s.Keys == keysAsText)
1312						return s;
1313			return null;
1314		}
1315
1316		/// <summary>
1317		/// 
1318		/// </summary>
1319		/// <param name="profile"></param>
1320		/// <param name="category"></param>
1321		/// <param name="name"></param>
1322		/// <returns></returns>
1323		public static KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name)
1324		{
1325			foreach (KeyboardShortcut s in profile.Shortcuts)
1326				if (s.Name == name && s.Category == category)
1327					return s;
1328			return null;
1329		}
1330
1331		/// <summary>
1332		/// 
1333		/// </summary>
1334		/// <param name="profile"></param>
1335		/// <param name="name"></param>
1336		/// <param name="isprotected"></param>
1337		public static void InitShortcutProfile(KeyboardShortcutProfile profile, String name, Boolean isprotected)
1338		{
1339			profile.Name = name;
1340			profile.IsProtected = isprotected;
1341			profile.Shortcuts = new List<KeyboardShortcut>();
1342
1343			// set the default shortcuts
1344			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add track", IsGlobal = false, Keys = "Ctrl+T" });
1345			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add folder", IsGlobal = false, Keys = "Ctrl+F" });
1346			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Open playlist", IsGlobal = false, Keys = "Ctrl+O" });
1347			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Minimize", IsGlobal = false, Keys = "Ctrl+M" });
1348			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Restore", IsGlobal = true, Keys = "Ctrl+Shift+R" });
1349			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Help", IsGlobal = false, Keys = "F1" });
1350			profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Close", IsGlobal = false, Keys = "Ctrl+W" });
1351
1352			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library", IsGlobal = false, Keys = "Alt+L" });
1353			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Queue", IsGlobal = false, Keys = "Alt+Q" });
1354			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "History", IsGlobal = false, Keys = "Alt+H" });
1355			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Playlists", IsGlobal = false, Keys = "Alt+P" });
1356			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Now playing", IsGlobal = false, Keys = "Alt+W" });
1357			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Tracklist", IsGlobal = false, Keys = "Alt+T" });
1358			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Search", IsGlobal = false, Keys = "Alt+F" });
1359			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "General preferences", IsGlobal = false, Keys = "Alt+G" });
1360			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library sources", IsGlobal = false, Keys = "Alt+S" });
1361			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Services", IsGlobal = false, Keys = "Alt+V" });
1362			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Keyboard shortcuts", IsGlobal = false, Keys = "Alt+K" });
1363			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "About", IsGlobal = false, Keys = "Alt+A" });
1364			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle details pane", IsGlobal = false, Keys = "Alt+D" });
1365			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle menu bar", IsGlobal = false, Keys = "Alt+M" });
1366			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Create playlist", IsGlobal = false, Keys = "Alt+N" });
1367
1368			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Play or pause", IsGlobal = false, Keys = "Alt+5 (numpad)" });
1369			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Next", IsGlobal = false, Keys = "Alt+6 (numpad)" });
1370			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Previous", IsGlobal = false, Keys = "Alt+4 (numpad)" });
1371			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle shuffle", IsGlobal = false, Keys = "Alt+9 (numpad)" });
1372			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle repeat", IsGlobal = false, Keys = "Alt+7 (numpad)" });
1373			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Increase volume", IsGlobal = false, Keys = "Alt+8 (numpad)" });
1374			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Decrease volume", IsGlobal = false, Keys = "Alt+2 (numpad)" });
1375			profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name =

Large files files are truncated, but you can click here to view the full file