PageRenderTime 75ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Source Code/PowerSong/GlobalContext.vb

#
Visual Basic | 124 lines | 84 code | 33 blank | 7 comment | 0 complexity | 125299c293b4d7780316a10deee52e19 MD5 | raw file
  1. Imports System.IO
  2. Imports PowerSong.SongDatabase
  3. Imports PowerSong.SongDatabase.Bibles
  4. Imports PowerSong.SongDatabase.Items
  5. Public Module GlobalContext
  6. Private FMainForm As frmMain = Nothing
  7. Public Property MainForm() As frmMain
  8. Get
  9. Return FMainForm
  10. End Get
  11. Friend Set(ByVal value As frmMain)
  12. FMainForm = value
  13. End Set
  14. End Property
  15. Private FBibleIndex As BibleIndex = Nothing
  16. Public ReadOnly Property BibleIndex() As BibleIndex
  17. Get
  18. Return FBibleIndex
  19. End Get
  20. End Property
  21. Private FDatabaseLocation As String = String.Empty
  22. Public Property DatabaseLocation() As String
  23. Get
  24. Return FDatabaseLocation
  25. End Get
  26. Set(ByVal value As String)
  27. FDatabaseLocation = value
  28. End Set
  29. End Property
  30. Private FDatabase As Database = Nothing
  31. Friend Property Database() As Database
  32. Get
  33. Return FDatabase
  34. End Get
  35. Set(ByVal value As Database)
  36. FDatabase = value
  37. End Set
  38. End Property
  39. Public Sub LoadBible(ByVal translation As String)
  40. Try
  41. ' Close old index if one is already open
  42. If FBibleIndex IsNot Nothing Then FBibleIndex.Close()
  43. ' Load new index
  44. Dim BibleFileName As String = Database.InitialContentFolder + "\" + translation + ".Bible"
  45. Dim BibleIndexFileName As String = Database.InitialContentFolder + "\" + translation + ".Index"
  46. FBibleIndex = BibleIndex.Load(BibleFileName, BibleIndexFileName)
  47. Catch ex As Exception
  48. MsgBox("Bible translation '" + translation + "' could not be loaded." + Environment.NewLine + _
  49. "Bible functionality will not be available until you select a different translation." + Environment.NewLine + Environment.NewLine + _
  50. "Reason: " + ex.Message, MsgBoxStyle.Exclamation)
  51. FBibleIndex = Nothing
  52. End Try
  53. End Sub
  54. Public Sub LoadExternalFile(ByVal fileName As String)
  55. Select Case Path.GetExtension(fileName).ToUpper
  56. Case ".POWERSONG"
  57. Call New frmImportDatabase(Database, fileName).ShowDialog()
  58. Case ".PLAYLIST"
  59. LoadPlayList(fileName)
  60. Case ".PSDB"
  61. ' TODO: Close and open new database
  62. MsgBox("PowerSong is already running. Please close PowerSong before attempting to open the referenced database.", MsgBoxStyle.Exclamation)
  63. Case Else
  64. MsgBox("PowerSong cannot open the file '" + Path.GetFileName(fileName) + "' because it is not recognised.")
  65. End Select
  66. End Sub
  67. Public Sub LoadPlayList(ByVal fileName As String)
  68. Try
  69. If FDatabase Is Nothing Then Throw New Exception("A database has not been loaded.")
  70. ' Ask the user if they want to append songs to the current list
  71. Dim RemoveSongsFirst As Boolean = False
  72. If MainForm.lstPlaylist.ItemCount > 0 Then
  73. RemoveSongsFirst = Not MsgBox("Do you wish to append these songs to the list?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
  74. End If
  75. ' Load the play list
  76. Dim AllSongsFound As Boolean = True
  77. Dim List As PlayList = PlayList.Load(Database, fileName, AllSongsFound)
  78. ' Show a friendly message box if some or all of the songs are not present
  79. If Not AllSongsFound Then
  80. MsgBox("Some or all of the referenced songs in the file do not exist in the database.", MsgBoxStyle.Information)
  81. End If
  82. ' Insert items into the play list
  83. If RemoveSongsFirst Then MainForm.lstPlaylist.Clear()
  84. For Each Item As PlayListItem In List
  85. MainForm.lstPlaylist.AddItem(New SongsListItem(Item.Item, Item.Style, Item.OverrideBackground))
  86. Next
  87. Catch ex As Exception
  88. MsgBox("Could not load the play list:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
  89. End Try
  90. End Sub
  91. End Module