/Source Code/PowerSong/GlobalContext.vb
Visual Basic | 124 lines | 84 code | 33 blank | 7 comment | 0 complexity | 125299c293b4d7780316a10deee52e19 MD5 | raw file
- Imports System.IO
- Imports PowerSong.SongDatabase
- Imports PowerSong.SongDatabase.Bibles
- Imports PowerSong.SongDatabase.Items
-
- Public Module GlobalContext
-
- Private FMainForm As frmMain = Nothing
-
- Public Property MainForm() As frmMain
- Get
- Return FMainForm
- End Get
- Friend Set(ByVal value As frmMain)
- FMainForm = value
- End Set
- End Property
-
- Private FBibleIndex As BibleIndex = Nothing
-
- Public ReadOnly Property BibleIndex() As BibleIndex
- Get
- Return FBibleIndex
- End Get
- End Property
-
- Private FDatabaseLocation As String = String.Empty
-
- Public Property DatabaseLocation() As String
- Get
- Return FDatabaseLocation
- End Get
- Set(ByVal value As String)
- FDatabaseLocation = value
- End Set
- End Property
-
- Private FDatabase As Database = Nothing
-
- Friend Property Database() As Database
- Get
- Return FDatabase
- End Get
- Set(ByVal value As Database)
- FDatabase = value
- End Set
- End Property
-
- Public Sub LoadBible(ByVal translation As String)
-
- Try
-
- ' Close old index if one is already open
- If FBibleIndex IsNot Nothing Then FBibleIndex.Close()
-
- ' Load new index
- Dim BibleFileName As String = Database.InitialContentFolder + "\" + translation + ".Bible"
- Dim BibleIndexFileName As String = Database.InitialContentFolder + "\" + translation + ".Index"
- FBibleIndex = BibleIndex.Load(BibleFileName, BibleIndexFileName)
-
- Catch ex As Exception
- MsgBox("Bible translation '" + translation + "' could not be loaded." + Environment.NewLine + _
- "Bible functionality will not be available until you select a different translation." + Environment.NewLine + Environment.NewLine + _
- "Reason: " + ex.Message, MsgBoxStyle.Exclamation)
- FBibleIndex = Nothing
- End Try
-
- End Sub
-
- Public Sub LoadExternalFile(ByVal fileName As String)
-
- Select Case Path.GetExtension(fileName).ToUpper
-
- Case ".POWERSONG"
- Call New frmImportDatabase(Database, fileName).ShowDialog()
-
- Case ".PLAYLIST"
- LoadPlayList(fileName)
-
- Case ".PSDB"
- ' TODO: Close and open new database
- MsgBox("PowerSong is already running. Please close PowerSong before attempting to open the referenced database.", MsgBoxStyle.Exclamation)
-
- Case Else
- MsgBox("PowerSong cannot open the file '" + Path.GetFileName(fileName) + "' because it is not recognised.")
-
- End Select
-
- End Sub
-
- Public Sub LoadPlayList(ByVal fileName As String)
-
- Try
-
- If FDatabase Is Nothing Then Throw New Exception("A database has not been loaded.")
-
- ' Ask the user if they want to append songs to the current list
- Dim RemoveSongsFirst As Boolean = False
- If MainForm.lstPlaylist.ItemCount > 0 Then
- RemoveSongsFirst = Not MsgBox("Do you wish to append these songs to the list?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
- End If
-
- ' Load the play list
- Dim AllSongsFound As Boolean = True
- Dim List As PlayList = PlayList.Load(Database, fileName, AllSongsFound)
-
- ' Show a friendly message box if some or all of the songs are not present
- If Not AllSongsFound Then
- MsgBox("Some or all of the referenced songs in the file do not exist in the database.", MsgBoxStyle.Information)
- End If
-
- ' Insert items into the play list
- If RemoveSongsFirst Then MainForm.lstPlaylist.Clear()
- For Each Item As PlayListItem In List
- MainForm.lstPlaylist.AddItem(New SongsListItem(Item.Item, Item.Style, Item.OverrideBackground))
- Next
-
- Catch ex As Exception
- MsgBox("Could not load the play list:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- End Sub
-
- End Module