From 8a5757919f7b5f751b5bad1464be01bd1a7f2b33 Mon Sep 17 00:00:00 2001 From: Andrey Lipatkin Date: Sun, 2 Aug 2015 21:29:54 +0300 Subject: [PATCH] Added checkbox for enabling/disabling "remote control" --- Elpis/Config.cs | 30 ++++--- Elpis/MainWindow.xaml.cs | 102 +++++++++++------------ Elpis/Pages/Settings.xaml | 58 +++++++------ Elpis/Pages/Settings.xaml.cs | 33 ++++---- Elpis/WebInterface.cs | 87 +++++++++---------- Libs/Util/MapConfig.cs | 28 +++---- PandoraSharpTest/PandoraSharpTest.csproj | 3 +- RequestDecrypter/MainWindow.xaml.cs | 13 +-- RequestDecrypter/RequestDecrypter.csproj | 3 +- 9 files changed, 174 insertions(+), 183 deletions(-) diff --git a/Elpis/Config.cs b/Elpis/Config.cs index cafe94f..421fd70 100644 --- a/Elpis/Config.cs +++ b/Elpis/Config.cs @@ -3,17 +3,17 @@ * http://adamhaile.net * * This file is part of Elpis. - * Elpis is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or + * Elpis is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * - * Elpis is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * Elpis is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License + * + * You should have received a copy of the GNU General Public License * along with Elpis. If not, see http://www.gnu.org/licenses/. */ @@ -107,6 +107,7 @@ public struct ConfigItems public static MapConfigEntry Elpis_InstallID = new MapConfigEntry("Elpis_InstallID", Guid.NewGuid().ToString()); public static MapConfigEntry Elpis_CheckUpdates = new MapConfigEntry("Elpis_CheckUpdates", true); public static MapConfigEntry Elpis_CheckBetaUpdates = new MapConfigEntry("Elpis_CheckBetaUpdates", false); + public static MapConfigEntry Elpis_RemoteControlEnabled = new MapConfigEntry("Elpis_RemoteControlEnabled", true); public static MapConfigEntry Elpis_MinimizeToTray = new MapConfigEntry("Elpis_MinimizeToTray", false); public static MapConfigEntry Elpis_ShowTrayNotifications = new MapConfigEntry("Elpis_ShowTrayNotifications", true); public static MapConfigEntry Elpis_StartupLocation = new MapConfigEntry("Elpis_StartupLocation", ""); @@ -154,6 +155,7 @@ public struct ConfigFields public string Elpis_InstallID { get; internal set; } public bool Elpis_CheckUpdates { get; set; } public bool Elpis_CheckBetaUpdates { get; set; } + public bool Elpis_RemoteControlEnabled { get; set; } public bool Elpis_MinimizeToTray { get; set; } public bool Elpis_ShowTrayNotifications { get; set; } @@ -182,7 +184,7 @@ public class Config private readonly MapConfig _c; public ConfigFields Fields; - private string _configFile = "elpis.config"; + private readonly string _configFile = "elpis.config"; public Config(string configSuffix = "") { @@ -248,6 +250,7 @@ public bool LoadConfig() Fields.Elpis_InstallID = (string) _c.GetValue(ConfigItems.Elpis_InstallID); Fields.Elpis_CheckUpdates = (bool) _c.GetValue(ConfigItems.Elpis_CheckUpdates); Fields.Elpis_CheckBetaUpdates = (bool)_c.GetValue(ConfigItems.Elpis_CheckBetaUpdates); + Fields.Elpis_RemoteControlEnabled = (bool)_c.GetValue(ConfigItems.Elpis_RemoteControlEnabled); Fields.Elpis_MinimizeToTray = (bool) _c.GetValue(ConfigItems.Elpis_MinimizeToTray); Fields.Elpis_ShowTrayNotifications = (bool) _c.GetValue(ConfigItems.Elpis_ShowTrayNotifications); Fields.Elpis_Volume = (int) _c.GetValue(ConfigItems.Elpis_Volume); @@ -278,7 +281,7 @@ public bool LoadConfig() } var list = _c.GetValue(ConfigItems.HotKeysList) as Dictionary; - + if (list != null){ foreach (KeyValuePair pair in list) { @@ -327,6 +330,7 @@ public bool SaveConfig() _c.SetValue(ConfigItems.Elpis_Version, Fields.Elpis_Version.ToString()); _c.SetValue(ConfigItems.Elpis_CheckUpdates, Fields.Elpis_CheckUpdates); _c.SetValue(ConfigItems.Elpis_CheckBetaUpdates, Fields.Elpis_CheckBetaUpdates); + _c.SetValue(ConfigItems.Elpis_RemoteControlEnabled, Fields.Elpis_RemoteControlEnabled); _c.SetValue(ConfigItems.Elpis_MinimizeToTray, Fields.Elpis_MinimizeToTray); _c.SetValue(ConfigItems.Elpis_ShowTrayNotifications, Fields.Elpis_ShowTrayNotifications); _c.SetValue(ConfigItems.Elpis_PauseOnLock, Fields.Elpis_PauseOnLock); @@ -334,13 +338,13 @@ public bool SaveConfig() _c.SetValue(ConfigItems.LastFM_Scrobble, Fields.LastFM_Scrobble); _c.SetEncryptedString(ConfigItems.LastFM_SessionKey, Fields.LastFM_SessionKey); - + _c.SetValue(ConfigItems.Elpis_StartupLocation, Fields.Elpis_StartupLocation.ToString()); _c.SetValue(ConfigItems.Elpis_StartupSize, Fields.Elpis_StartupSize.ToString()); _c.SetValue(ConfigItems.Elpis_Volume, Fields.Elpis_Volume); - + Dictionary hotkeysFlattened = new Dictionary(); foreach(KeyValuePair pair in Fields.Elpis_HotKeys) { diff --git a/Elpis/MainWindow.xaml.cs b/Elpis/MainWindow.xaml.cs index ff2587f..02e4f36 100644 --- a/Elpis/MainWindow.xaml.cs +++ b/Elpis/MainWindow.xaml.cs @@ -1,21 +1,21 @@ /* - * + * * * Copyright 2012 - Adam Haile * http://adamhaile.net * * This file is part of Elpis. - * Elpis is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or + * Elpis is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * - * Elpis is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * Elpis is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License + * + * You should have received a copy of the GNU General Public License * along with Elpis. If not, see http://www.gnu.org/licenses/. */ @@ -25,13 +25,11 @@ using System.Diagnostics; using System.IO; using System.Reflection; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Input; -using System.Windows.Shell; using BassPlayer; using Elpis.Hotkeys; using Elpis.UpdateSystem; @@ -44,15 +42,6 @@ using Log = Util.Log; using UserControl = System.Windows.Controls.UserControl; using PandoraSharp.Plugins; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Net; -using System.Text; -using Kayak; -using Kayak.Http; -using System.Windows.Threading; namespace Elpis { @@ -71,7 +60,7 @@ public partial class MainWindow : Window private string _configLocation; - private Config _config; + private readonly Config _config; private bool _finalComplete = false; private bool _initComplete; @@ -101,13 +90,13 @@ public partial class MainWindow : Window private SearchMode _searchMode = SearchMode.NewStation; - private bool _configError = false; + private readonly bool _configError = false; private bool _forceClose = false; private StationList _stationPage; private QuickMixPage _quickMixPage; - private UpdateCheck _update; + private readonly UpdateCheck _update; private UpdatePage _updatePage; private RestartPage _restartPage; private LastFMAuthPage _lastFMPage; @@ -119,11 +108,11 @@ public partial class MainWindow : Window private bool _isActiveWindow; - public static DateTime lastTimeSkipped; + private static DateTime lastTimeSkipped; - private WebInterface webInterfaceObject; + private WebInterface _webInterfaceObject; - private bool restarting = false; + private bool _restarting = false; private const int PLAY = 1; private const int PAUSE = 2; @@ -361,8 +350,7 @@ void _settingsPage_Restart() void DoRestart() { - System.Collections.Generic.List args = - new System.Collections.Generic.List(); + List args = new List(); var cmds = System.Environment.GetCommandLineArgs(); foreach (string a in cmds) args.Add(a); @@ -383,7 +371,7 @@ void _restartPage_RestartSelectionEvent(bool status) { if (status) { - restarting = true; + _restarting = true; DoRestart(); Close(); } @@ -474,7 +462,7 @@ private void SetupUIEvents() mainBar.CreateStationClick += mainBar_searchPageClick; mainBar.ErrorClicked += mainBar_ErrorClicked; mainBar.VolumeChanged += mainBar_VolumeChanged; - + _loginPage.Loaded += _loginPage_Loaded; _aboutPage.Loaded += _aboutPage_Loaded; _settingsPage.Loaded += _settingsPage_Loaded; @@ -560,10 +548,10 @@ private void LoadNotifyMenu() _notifyMenu_Title.Visible = _notifyMenu_Artist.Visible = _notifyMenu_Album.Visible = - _notifyMenu_BreakSong.Visible = + _notifyMenu_BreakSong.Visible = _notifyMenu_DownVote.Visible = _notifyMenu_UpVote.Visible = - _notifyMenu_Tired.Visible = + _notifyMenu_Tired.Visible = _notifyMenu_BreakVote.Visible = showSongInfo; _notifyMenu_PlayPause.Enabled = @@ -622,7 +610,7 @@ private void SetupNotifyIcon() _notifyMenu_UpVote = new ToolStripMenuItem("Like Song"); _notifyMenu_UpVote.Click += ((o, e) => _playlistPage.ThumbUpCurrent() ); - + _notifyMenu_Exit = new ToolStripMenuItem("Exit Elpis"); _notifyMenu_Exit.Click += ((o, e) => { _forceClose = true; Close(); }); @@ -710,7 +698,7 @@ private void FinalLoad() try { - post.Send(); + post.Send(); } catch(Exception ex) { @@ -723,7 +711,7 @@ private void FinalLoad() try { _player = new Player(); - _player.Initialize(_bassRegEmail, _bassRegKey); //TODO - put this in the login sequence? + _player.Initialize(_bassRegEmail, _bassRegKey); //TODO - put this in the login sequence? if(_config.Fields.Proxy_Address != string.Empty) _player.SetProxy(_config.Fields.Proxy_Address, _config.Fields.Proxy_Port, _config.Fields.Proxy_User, _config.Fields.Proxy_Password); @@ -754,7 +742,10 @@ private void FinalLoad() _loadingPage.UpdateStatus("Starting Web Server..."); - startWebServer(); + if (_config.Fields.Elpis_RemoteControlEnabled) + { + StartWebServer(); + } _loadingPage.UpdateStatus("Setting up UI..."); @@ -764,7 +755,7 @@ private void FinalLoad() }); //this.Dispatch(SetupJumpList); - + this.Dispatch(SetupNotifyIcon); this.Dispatch(() => mainBar.DataContext = _player); //To bind playstate @@ -789,17 +780,20 @@ private void FinalLoad() _finalComplete = true; } - private void startWebServer() + private void StartWebServer() { - webInterfaceObject = new WebInterface(); - Thread webInterfaceThread = new Thread(new ThreadStart(webInterfaceObject.startInterface)); - webInterfaceThread.Start(); + _webInterfaceObject = new WebInterface(); + Thread webInterfaceThread = new Thread(new ThreadStart(_webInterfaceObject.StartInterface)); + webInterfaceThread.Start(); lastTimeSkipped = DateTime.Now; } - public void stopWebServer() + private void StopWebServer() { - webInterfaceObject.stopInterface(); + if (_webInterfaceObject != null) + { + _webInterfaceObject.StopInterface(); + } } public static bool Next() @@ -844,7 +838,7 @@ public static void PlayPauseToggle() { _mainWindow.showBalloon(PAUSE); } - _player.PlayPause(); + _player.PlayPause(); })); } public static void Like() @@ -854,7 +848,7 @@ public static void Like() _mainWindow.showBalloon(LIKE); _playlistPage.ThumbUpCurrent(); })); - + } public static void Dislike() { @@ -895,7 +889,7 @@ private void LoadLastFM() "In order to use it while in Debug mode, edit apiKey and apiSecret in LoadLastFM() in MainWindow.xaml.cs"); } #endif - + if (_config.Fields.Proxy_Address != string.Empty) _scrobbler.SetProxy(_config.Fields.Proxy_Address, _config.Fields.Proxy_Port, @@ -1163,7 +1157,7 @@ private void _player_PlaybackStart(object sender, double duration) string tipText = _player.CurrentSong.SongTitle; _notify.BalloonTipTitle = tipText; _notify.BalloonTipText = " by " + _player.CurrentSong.Artist; - + _notify.ShowBalloonTip(5000); } }); @@ -1329,7 +1323,7 @@ private void mainBar_NextClick() //if (transitionControl.CurrentPage == _playlistPage) _player.Next(); - transitionControl.ShowPage(_playlistPage); + transitionControl.ShowPage(_playlistPage); } private void mainBar_PlayPauseClick() @@ -1337,7 +1331,7 @@ private void mainBar_PlayPauseClick() //if (transitionControl.CurrentPage == _playlistPage) _player.PlayPause(); - transitionControl.ShowPage(_playlistPage); + transitionControl.ShowPage(_playlistPage); } private void _player_StationLoaded(object sender, Station station) @@ -1410,7 +1404,7 @@ private void transitionControl_CurrentPageSet(UserControl page) private void Window_Closing(object sender, CancelEventArgs e) { - if (!_forceClose && _config.Fields.Elpis_MinimizeToTray && !restarting) + if (!_forceClose && _config.Fields.Elpis_MinimizeToTray && !_restarting) { WindowState = WindowState.Minimized; this.Hide(); @@ -1434,7 +1428,7 @@ private void Window_Closing(object sender, CancelEventArgs e) _config.Fields.Elpis_Volume = _player.Volume; _config.SaveConfig(); } - stopWebServer(); + StopWebServer(); } private void Window_StateChanged(object sender, EventArgs e) @@ -1479,7 +1473,7 @@ public void SkipTrack(object sender, ExecutedRoutedEventArgs e) showBalloon(SKIP); _player.Next(); } - + private void showBalloon(int option) { if (_config.Fields.Elpis_ShowTrayNotifications) @@ -1530,7 +1524,7 @@ private void showBalloon(int option) } _notify.ShowBalloonTip(3000); } - } + } } private void CanExecutePlayPauseSkip(object sender, CanExecuteRoutedEventArgs e) diff --git a/Elpis/Pages/Settings.xaml b/Elpis/Pages/Settings.xaml index 23806f0..2066ae2 100644 --- a/Elpis/Pages/Settings.xaml +++ b/Elpis/Pages/Settings.xaml @@ -114,9 +114,13 @@ IsChecked="True" ToolTip="Exit option in tray menu must be used to fully close." Content="Minimize / Close to Tray" /> + IsChecked="True" + Content="Show Notifications" + ToolTip="Display notificationsin toolbar on each new song"/> + @@ -161,21 +165,21 @@ - - - Only set Alphanumeric or Space keys as Global - - if you know what you're doing. - - Otherwise, these keys won't work on programs - - other than Elpis until you either remove the - + Only set Alphanumeric or Space keys as Global + + if you know what you're doing. + + Otherwise, these keys won't work on programs + + other than Elpis until you either remove the + hotkey or close Elpis. @@ -183,14 +187,14 @@ - Only set Alphanumeric or Space keys as Global - - if you know what you're doing. - - Otherwise, these keys won't work on programs - - other than Elpis until you either remove the - + Only set Alphanumeric or Space keys as Global + + if you know what you're doing. + + Otherwise, these keys won't work on programs + + other than Elpis until you either remove the + hotkey or close Elpis. @@ -216,7 +220,7 @@ - @@ -238,7 +242,7 @@ Name="txtProxyAddress"/>