Пример #1
0
        protected virtual void StreamTrack(Socket client, DAAP.Database database, DAAP.Track song, long offset)
        {
            long   length;
            Stream stream = database.StreamTrack(song, offset, out length);

            WriteResponseStream(client, stream, length, song.FileName, offset < 0 ? 0 : offset);
            stream.Close();
            client.Close();
        }
Пример #2
0
        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);
        }
Пример #3
0
        private void OnClientUpdated(object o, EventArgs args)
        {
            try {
                if (database == null && client.Databases.Count > 0)
                {
                    database = client.Databases[0];
                    DaapService.ProxyServer.RegisterDatabase(database);
                    database.TrackAdded   += OnDatabaseTrackAdded;
                    database.TrackRemoved += OnDatabaseTrackRemoved;

                    SetStatus(String.Format(Catalog.GetPluralString(
                                                "Loading {0} track", "Loading {0} tracks", database.TrackCount),
                                            database.TrackCount), false
                              );

                    // Notify (eg reload the source before sync is done) at most 5 times
                    int notify_every = Math.Max(250, (database.Tracks.Count / 4));
                    notify_every -= notify_every % 250;

                    int           count      = 0;
                    DaapTrackInfo daap_track = null;

                    HyenaSqliteConnection conn = ServiceManager.DbConnection;
                    conn.BeginTransaction();
                    foreach (DAAP.Track track in database.Tracks)
                    {
                        daap_track = new DaapTrackInfo(track, this);

                        // Only notify once in a while because otherwise the source Reloading slows things way down
                        if (++count % notify_every == 0)
                        {
                            conn.CommitTransaction();
                            daap_track.Save(true);
                            conn.BeginTransaction();
                        }
                        else
                        {
                            daap_track.Save(false);
                        }
                    }
                    conn.CommitTransaction();

                    // Save the last track once more to trigger the NotifyTrackAdded
                    if (daap_track != null)
                    {
                        daap_track.Save();
                    }

                    SetStatus(Catalog.GetString("Loading playlists"), false);
                    AddPlaylistSources();
                    connected = true;
                    Reload();
                    HideStatus();
                }

                Name = client.Name;

                UpdateIcon();
                OnUpdated();
            } catch (Exception e) {
                Hyena.Log.Exception("Caught exception while loading daap share", e);
                ThreadAssist.ProxyToMain(delegate {
                    HideStatus();
                    ShowErrorView(DaapErrorType.UserDisconnect);
                });
            }
        }
Пример #4
0
 public void UnregisterDatabase(DAAP.Database database)
 {
     databases.Remove(database);
 }
Пример #5
0
 public void RegisterDatabase(DAAP.Database database)
 {
     databases.Add(database);
 }
Пример #6
0
        private Playlist ClonePlaylist(Database db, Playlist pl)
        {
            Playlist clonePl = new Playlist (pl.Name);
            clonePl.Id = pl.Id;

            IList<Track> pltracks = pl.Tracks;
            for (int i = 0; i < pltracks.Count; i++) {
                clonePl.AddTrack (db.LookupTrackById (pltracks[i].Id), pl.GetContainerId (i));
            }

            return clonePl;
        }
Пример #7
0
 protected void StreamTrack(Socket client, DAAP.Database database, DAAP.Track song)
 {
     StreamTrack(client, database, song, -1);
 }
Пример #8
0
        public object Clone()
        {
            Database db = new Database (this.name);
            db.id = id;
            db.persistentId = persistentId;

            List<Track> cloneTracks = new List<Track> ();
            foreach (Track track in tracks) {
                cloneTracks.Add ((Track) track.Clone ());
            }

            db.tracks = cloneTracks;

            List<Playlist> clonePlaylists = new List<Playlist> ();
            foreach (Playlist pl in playlists) {
                clonePlaylists.Add (ClonePlaylist (db, pl));
            }

            db.playlists = clonePlaylists;
            db.basePlaylist = ClonePlaylist (db, basePlaylist);
            return db;
        }
Пример #9
0
        private void OnClientUpdated(object o, EventArgs args)
        {
            try {
                if (database == null && client.Databases.Count > 0) {
                    database = client.Databases[0];
                    DaapService.ProxyServer.RegisterDatabase (database);
                    database.TrackAdded += OnDatabaseTrackAdded;
                    database.TrackRemoved += OnDatabaseTrackRemoved;

                    SetStatus (String.Format (Catalog.GetPluralString (
                        "Loading {0} track", "Loading {0} tracks", database.TrackCount),
                        database.TrackCount), false
                    );

                    // Notify (eg reload the source before sync is done) at most 5 times
                    int notify_every = Math.Max (250, (database.Tracks.Count / 4));
                    notify_every -= notify_every % 250;

                    int count = 0;
                    DaapTrackInfo daap_track = null;

                    HyenaSqliteConnection conn = ServiceManager.DbConnection;
                    conn.BeginTransaction ();
                    foreach (DAAP.Track track in database.Tracks) {
                        daap_track = new DaapTrackInfo (track, this);

                        // Only notify once in a while because otherwise the source Reloading slows things way down
                        if (++count % notify_every == 0) {
                            conn.CommitTransaction ();
                            daap_track.Save (true);
                            conn.BeginTransaction ();
                        } else {
                            daap_track.Save (false);
                        }
                    }
                    conn.CommitTransaction ();

                    // Save the last track once more to trigger the NotifyTrackAdded
                    if (daap_track != null) {
                        daap_track.Save ();
                    }

                    SetStatus (Catalog.GetString ("Loading playlists"), false);
                    AddPlaylistSources ();
                    connected = true;
                    Reload ();
                    HideStatus ();
                }

                Name = client.Name;

                UpdateIcon ();
                OnUpdated ();
            } catch (Exception e) {
                Log.Error ("Caught exception while loading daap share", e);
                ThreadAssist.ProxyToMain (delegate {
                    HideStatus ();
                    ShowErrorView (DaapErrorType.UserDisconnect);
                });
            }
        }
Пример #10
0
        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;
        }
Пример #11
0
        private void FetchDatabases()
        {
            ContentNode dbnode = ContentParser.Parse (bag, fetcher.Fetch ("/databases"));

            foreach (ContentNode child in (ContentNode[]) dbnode.Value) {
                if (child.Name != "dmap.listing")
                    continue;

                foreach (ContentNode item in (ContentNode[]) child.Value) {
                    Database db = new Database (this, item);
                    databases.Add (db);
                }
            }
        }
Пример #12
0
        internal static void FromPlaylistNode(Database db, ContentNode node, out Track track, out int containerId)
        {
            track = null;
            containerId = 0;

            foreach (ContentNode field in (ContentNode[]) node.Value) {
                switch (field.Name) {
                case "dmap.itemid":
                    track = db.LookupTrackById ((int) field.Value);
                    break;
                case "dmap.containeritemid":
                    containerId = (int) field.Value;
                    break;
                default:
                    break;
                }
            }
        }