internal bool Disconnect(bool logout)
{
// Stop currently playing track if its from us.
try {
if (ServiceManager.PlayerEngine.CurrentState == Banshee.MediaEngine.PlayerState.Playing)
{
DatabaseTrackInfo track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;
if (track != null && track.PrimarySource == this)
{
ServiceManager.PlayerEngine.Close();
}
}
} catch {}
connected = false;
// Remove tracks associated with this source, since we don't want
// them after we unmap - we'll refetch.
PurgeTracks();
if (client != null)
{
if (logout)
{
client.Logout();
}
client.Dispose();
client = null;
database = null;
}
if (database != null)
{
try {
DaapService.ProxyServer.UnregisterDatabase(database);
} catch {}
database.TrackAdded -= OnDatabaseTrackAdded;
database.TrackRemoved -= OnDatabaseTrackRemoved;
database = null;
}
List <Source> children = new List <Source> (Children);
foreach (Source child in children)
{
if (child is Banshee.Sources.IUnmapableSource)
{
(child as Banshee.Sources.IUnmapableSource).Unmap();
}
}
ClearChildSources();
return(true);
}