Advertisement
Guest User

GrooveShark

a guest
Feb 21st, 2011
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.  
  3. 'The LoadPlaylist ID click function. As you can see it parses the playlist integer entered into the textbox, then calls @h@'some functions that I refactored to make it easier to write.
  4.  
  5. Private Sub btnLoadPlaylistId_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
  6.         If Not String.IsNullOrWhiteSpace(txtPlaylistID.Text) Then
  7.             Try
  8.                 ClearDownloadList()
  9.                 Dim i As Integer = Integer.Parse(txtPlaylistID.Text)
  10.                 SearchPlaylistID(i)
  11.                 SelectAllResults()
  12.                 AddResults()
  13.             Catch ex As Exception
  14.  
  15.             End Try
  16.         End If
  17.  
  18.     End Sub
  19.  
  20. 'As you can see the clear downloaded list is just a function taken from your menu call
  21. Private Sub mniClearDownloadList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  22.         ClearDownloadList()
  23.     End Sub
  24.  
  25. 'The refactored function
  26. Private Sub ClearDownloadList()
  27.  
  28.         If Not DownloadEnabled Then
  29.             dagDownload.ItemsSource = Nothing
  30.  
  31.             DownloadResultsTable.Rows.Clear()
  32.             DownloadResults.Clear()
  33.  
  34.             DownloadResults = Nothing
  35.             DownloadResultsTable = Nothing
  36.  
  37.             DownloadResults = New List(Of ResultGrid)()
  38.             DownloadResultsTable = ResultGrid.ReturnBaseTable
  39.  
  40.             dagDownload.ItemsSource = DownloadResultsTable.AsDataView
  41.             SetDownloadTableColumnNames()
  42.         End If
  43.     End Sub
  44.  
  45. 'My playlist searching function, again copied from yours.
  46.    Private Sub SearchPlaylistID(ByVal PlaylistID As Integer)
  47.  
  48.         Call DoSearch(grooveClient.GetPlaylistSongs(PlaylistID).result.Songs)
  49.         tabMain.SelectedIndex = 0
  50.     End Sub
  51.  
  52. 'You will probably need to update it a bit, to make it fit yours, but as a quick test it works for me :
  53. Private Sub btnFetchPlaylists_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  54.  
  55.         Dim PlaylistID As Integer = cmbFetchPlaylists.SelectedIndex
  56.         Try
  57.             BlockSearchButtons(Skin.getLanguageText("LangFetchingPlaylist", "Fetching Playlist") & " (" & PlaylistID & ")...")
  58.             Call DoSearch(grooveClient.GetPlaylistSongs(playlistResponse.result.Playlists(PlaylistID).playlistID).result.Songs)
  59.         Catch ex As Exception
  60.             AddDebug("Error: " & ex.GetType.ToString & " - " & ex.Message & " - " & "Playlist Song fetching error")
  61.         End Try
  62.  
  63.         tabMain.SelectedIndex = 0
  64.  
  65.     End Sub
  66.  
  67. 'Again, I refactored the select all button_click method for ease of use
  68.  
  69.     Private Sub btnSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  70.         SelectAllResults()
  71.     End Sub
  72.  
  73.     Private Sub SelectAllResults()
  74.  
  75.         For i = 0 To FoundResults.Count - 1
  76.             FoundResults(i).Load = True
  77.             FoundResultsTable.Rows(i).Item("Load") = True
  78.         Next
  79.     End Sub
  80.  
  81. 'And last of all the Add to download list funciton
  82. Private Sub btnAddToDownloadList_Click(ByVal sender As Object, ByVal e As EventArgs)
  83.         AddResults()
  84.     End Sub
  85.  
  86.     Private Sub AddResults()
  87.         Try
  88.             For I = 0 To FoundResults.Count - 1
  89.                 Dim AddResult As ResultGrid = New ResultGrid(FoundResults(I).Result)
  90.                 If FoundResultsTable.Rows(I).Field(Of Boolean)("Load") And Not DownloadResults.Contains(AddResult) Then
  91.                     DownloadResults.Add(AddResult)
  92.                     DownloadResultsTable.Rows.Add(ResultGrid.CreateBaseTableRow(DownloadResultsTable, DownloadResults.Last))
  93.                 End If
  94.                 If myConfig.Settings.UncheckAfterAdd Then FoundResultsTable.Rows(I).Item("Load") = False
  95.             Next
  96.         Catch
  97.         End Try
  98.         dagDownload.ItemsSource = DownloadResultsTable.AsDataView
  99.         SetDownloadTableColumnNames()
  100.  
  101.         Call ExportAllDownloadResults()
  102.     End Sub
  103.  
  104. 'And I also added a textbox for the playlist ID and a button to load it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement