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