Skip to content

Commit

Permalink
Added "Add Variety to Station" option
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 9, 2012
1 parent 87b63a1 commit 8156667
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 8 deletions.
1 change: 1 addition & 0 deletions Elpis/Elpis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
</Page>
<Compile Include="Controls\ImageButton.cs" />
<Compile Include="Controls\TextBlockUtils.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Errors.cs" />
<Compile Include="KeyboardHook.cs" />
<Compile Include="Pages\About.xaml.cs">
Expand Down
13 changes: 13 additions & 0 deletions Elpis/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elpis
{
public enum SearchMode
{
NewStation,
AddVariety
}
}
26 changes: 24 additions & 2 deletions Elpis/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public partial class MainWindow : Window
private bool _showingError;
private bool _stationLoaded;

private SearchMode _searchMode = SearchMode.NewStation;

private bool _configError = false;

private StationList _stationPage;
Expand Down Expand Up @@ -195,6 +197,7 @@ private void SetupPageEvents()
_aboutPage.Close += RestorePrevPage;

_searchPage.Cancel += _searchPage_Cancel;
_searchPage.AddVariety += _searchPage_AddVariety;
_loginPage.ConnectingEvent += _loginPage_ConnectingEvent;
}

Expand Down Expand Up @@ -226,6 +229,7 @@ private void SetupUIEvents()
_searchPage.Loaded += _searchPage_Loaded;
_stationPage.Loaded += _stationPage_Loaded;
_stationPage.EditQuickMixEvent += _stationPage_EditQuickMixEvent;
_stationPage.AddVarietyEvent += _stationPage_AddVarietyEvent;
_quickMixPage.CancelEvent += _quickMixPage_CancelEvent;
_quickMixPage.CloseEvent += _quickMixPage_CloseEvent;
_playlistPage.Loaded += _playlistPage_Loaded;
Expand Down Expand Up @@ -757,14 +761,24 @@ private void _searchPage_Cancel(object sender)
{
this.BeginDispatch(() =>
{
if (_prevPage == _stationPage)
if (_searchMode == SearchMode.AddVariety)
ShowStationList();
else
RestorePrevPage();
{
if (_prevPage == _stationPage)
ShowStationList();
else
RestorePrevPage();
//transitionControl.ShowPage(_playlistPage);
}
});
}

void _searchPage_AddVariety(object sender)
{
ShowStationList();
}

private void _player_PlaybackStart(object sender, double duration)
{
this.BeginDispatch(() =>
Expand Down Expand Up @@ -823,6 +837,13 @@ void _stationPage_EditQuickMixEvent()
transitionControl.ShowPage(_quickMixPage);
}

void _stationPage_AddVarietyEvent(Station station)
{
_searchPage.SearchMode = _searchMode = SearchMode.AddVariety;
_searchPage.VarietyStation = station;
transitionControl.ShowPage(_searchPage);
}

void _quickMixPage_CloseEvent()
{
ShowStationList();
Expand Down Expand Up @@ -892,6 +913,7 @@ private void mainBar_stationPageClick()
private void mainBar_searchPageClick()
{
_prevPage = transitionControl.CurrentPage;
_searchPage.SearchMode = _searchMode = SearchMode.NewStation;
transitionControl.ShowPage(_searchPage, PageTransitionType.Previous);
}

Expand Down
25 changes: 20 additions & 5 deletions Elpis/Pages/Search.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ public partial class Search : UserControl

public delegate void CancelHandler(object sender);

public delegate void StationCreatedHandler(object sender, Station station);
public delegate void AddVarietyHandler(object sender);

#endregion

private readonly Player _player;
private const string initialSearchText = "Enter Artist, Track or Composer";

public SearchMode SearchMode { get; set; }
public Station VarietyStation { get; set; }

public Search(Player player)
{
_player = player;
InitializeComponent();

_player.SearchResult += _player_SearchResult;
//_player.StationCreated += _player_StationCreated;
_player.ExceptionEvent += _player_ExceptionEvent;
}

public event CancelHandler Cancel;
public event StationCreatedHandler StationCreated;
public event AddVarietyHandler AddVariety;

void _player_ExceptionEvent(object sender, string code, System.Exception ex)
{
Expand Down Expand Up @@ -107,8 +109,21 @@ private void btnCancel_Click(object sender, RoutedEventArgs e)
private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var result = (SearchResult) ((Grid) sender).DataContext;
ShowWait(true);
_player.CreateStation(result);

if (SearchMode == Elpis.SearchMode.NewStation)
{
ShowWait(true);
_player.CreateStation(result);
}
else
{
if (VarietyStation != null)
VarietyStation.AddVariety(result);

if (AddVariety != null)
AddVariety(this);
}

}

private void txtSearch_KeyDown(object sender, KeyEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions Elpis/Pages/StationList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<MenuItem Name="mnuRename" Click="mnuRename_Click" Header="Rename"/>
<MenuItem Name="mnuDelete" Click="mnuDelete_Click" Header="Delete"/>
<MenuItem Name="mnuEditQuickMix" Click="mnuEditQuickMix_Click" Header="Edit QuickMix"/>
<MenuItem Name="mnuAddVariety" Click="mnuAddVariety_Click" Header="Add Variety"/>
<MenuItem Name="mnuInfo" Click="mnuInfo_Click" Header="Station Info"/>
</ContextMenu>
</ResourceDictionary>
Expand Down
17 changes: 16 additions & 1 deletion Elpis/Pages/StationList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ public partial class StationList : UserControl
public delegate void EditQuickMixEventHandler();
public event EditQuickMixEventHandler EditQuickMixEvent;

public delegate void AddVarietyEventHandler(Station station);
public event AddVarietyEventHandler AddVarietyEvent;

private readonly Player _player;

private ContextMenu _stationMenu;
private MenuItem _mnuRename;
private MenuItem _mnuDelete;
private MenuItem _mnuEditQuickMix;
private MenuItem _mnuAddVariety;
private MenuItem _mnuInfo;
private Station _currMenuStation = null;
private Control _currStationItem = null;
Expand All @@ -60,7 +64,8 @@ public StationList(Player player)
_mnuRename = _stationMenu.Items[0] as MenuItem; //mnuRename
_mnuDelete = _stationMenu.Items[1] as MenuItem; //mnuDelete
_mnuEditQuickMix = _stationMenu.Items[2] as MenuItem; //mnuEditQuickMix
_mnuInfo = _stationMenu.Items[3] as MenuItem; //mnuInfo
_mnuAddVariety = _stationMenu.Items[3] as MenuItem; //mnuAddVariety
_mnuInfo = _stationMenu.Items[4] as MenuItem; //mnuInfo
}

public List<Station> Stations
Expand Down Expand Up @@ -172,6 +177,7 @@ private void ShowMenu(object sender)
{
_mnuRename.Visibility = _currMenuStation.IsQuickMix ? Visibility.Collapsed : Visibility.Visible;
_mnuDelete.Visibility = _currMenuStation.IsQuickMix ? Visibility.Collapsed : Visibility.Visible;
_mnuAddVariety.Visibility = _currMenuStation.IsQuickMix ? Visibility.Collapsed : Visibility.Visible;
_mnuEditQuickMix.Visibility = _currMenuStation.IsQuickMix ? Visibility.Visible : Visibility.Collapsed;
}

Expand Down Expand Up @@ -240,5 +246,14 @@ private void mnuInfo_Click(object sender, RoutedEventArgs e)
if (_currMenuStation != null && _currMenuStation.InfoUrl.StartsWith("http"))
Process.Start(_currMenuStation.InfoUrl);
}

private void mnuAddVariety_Click(object sender, RoutedEventArgs e)
{
if (_currMenuStation != null)
{
if (AddVarietyEvent != null)
AddVarietyEvent(_currMenuStation);
}
}
}
}
6 changes: 6 additions & 0 deletions Libs/PandoraSharp/Crypt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class PandoraCrypt
{
private static readonly BlowFish bf_enc = new BlowFish(CryptType.Encrypt);
private static readonly BlowFish bf_dec = new BlowFish(CryptType.Decrypt);
private static readonly BlowFish bf_dec_req = new BlowFish(CryptType.Encrypt);

public static string Encrypt(string s)
{
Expand All @@ -74,6 +75,11 @@ public static string Decrypt(string s)
{
return bf_dec.Decrypt_ECB(s).TrimEnd('\b');
}

public static string DecryptRPCRequest(string s)
{
return bf_dec_req.Decrypt_ECB(s).TrimEnd('\b');
}
}

public enum CryptType
Expand Down
12 changes: 12 additions & 0 deletions Libs/PandoraSharp/Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ public List<Song> GetPlaylist()
}
}

public void AddVariety(SearchResult item)
{
Log.O("Pandora: Adding {0} to {1}", item.DisplayName, this.Name);

try
{
_pandora.CallRPC("station.addSeed",
new object[] { this.ID, item.MusicID });
}
catch{} // eventually do something with this
}

public void Rename(string newName)
{
if (newName == Name)
Expand Down
8 changes: 8 additions & 0 deletions RequestDecrypter/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="RequestDecrypter.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
16 changes: 16 additions & 0 deletions RequestDecrypter/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace RequestDecrypter
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
17 changes: 17 additions & 0 deletions RequestDecrypter/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="RequestDecrypter.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Pandora Request Decrypter" Height="506" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Name="txtEncrypted" Grid.Row="0" TextWrapping="Wrap" />
<Button Name="btnDecrypt" Grid.Row="1"
Click="btnDecrypt_Click"
Content="Decrypt Request String" />
<TextBox Name="txtDecrypted" Grid.Row="2" TextWrapping="Wrap" />
</Grid>
</Window>
32 changes: 32 additions & 0 deletions RequestDecrypter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RequestDecrypter
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void btnDecrypt_Click(object sender, RoutedEventArgs e)
{
txtDecrypted.Text = PandoraSharp.PandoraCrypt.DecryptRPCRequest(txtEncrypted.Text);
}
}
}
55 changes: 55 additions & 0 deletions RequestDecrypter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RequestDecrypter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RequestDecrypter")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 8156667

Please sign in to comment.