Exemplo n.º 1
0
 public PlaylistArgs(Playlist pl)
 {
     this.pl = pl;
 }
Exemplo n.º 2
0
        public void RemovePlaylist(Playlist pl)
        {
            playlists.Remove (pl);

            if (PlaylistRemoved != null)
                PlaylistRemoved (this, new PlaylistArgs (pl));
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        private void RefreshPlaylist(string plfile)
        {
            Playlist pl;

            if (playlists.ContainsKey (plfile)) {
                pl = playlists[plfile];
                pl.Clear ();
            } else {
                pl = new Playlist (Path.GetFileNameWithoutExtension (plfile));
                Daemon.DefaultDatabase.AddPlaylist (pl);
                playlists[plfile] = pl;
            }

            using (StreamReader reader = new StreamReader (File.OpenRead (plfile))) {
                string line;

                while ((line = reader.ReadLine ()) != null) {
                    if (!line.StartsWith ("/"))
                        continue;

                    if (tracks.ContainsKey (line)) {
                        pl.AddTrack (tracks[line]);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void AddPlaylist(Playlist pl)
        {
            playlists.Add (pl);

            if (PlaylistAdded != null)
                PlaylistAdded (this, new PlaylistArgs (pl));
        }
Exemplo n.º 6
0
        private void RefreshPlaylists()
        {
            if (!OpenConnection ())
                return;

            IDbCommand cmd = conn.CreateCommand ();
            cmd.CommandText = "SELECT PlaylistID, Name FROM Playlists";

            List<int> ids = new List<int> ();

            IDataReader reader = cmd.ExecuteReader ();
            while (reader.Read ()) {
                int id = (int) reader[0];
                ids.Add (id);

                if (playlists.ContainsKey (id))
                    continue;

                Playlist pl = new Playlist ((string) reader[1]);

                Daemon.DefaultDatabase.AddPlaylist (pl);
                playlists[id] = pl;
            }

            reader.Close ();

            // remove the deleted playlists, if any
            foreach (int id in new List<int> (playlists.Keys)) {
                if (!ids.Contains (id)) {
                    Daemon.DefaultDatabase.RemovePlaylist (playlists[id]);
                    playlists.Remove (id);
                }
            }

            // clear all the playlists
            foreach (Playlist pl in playlists.Values) {
                pl.Clear ();
            }

            cmd = conn.CreateCommand ();
            cmd.CommandText = "SELECT PlaylistID, TrackID FROM PlaylistEntries";
            reader = cmd.ExecuteReader ();

            while (reader.Read ()) {
                try {
                    Playlist pl = playlists[(int) reader[0]];
                    pl.AddTrack (tracks[(int) reader[1]]);
                } catch (KeyNotFoundException e) {
                    // something is not consistent, but nothing we can do about it
                }
            }

            reader.Close ();
        }
Exemplo n.º 7
0
        private void RefreshPlaylists()
        {
            ClearPlaylists ();

            if (!File.Exists (plpath)) {
                return;
            }

            XmlTextReader reader = new XmlTextReader (plpath);
            Playlist pl = null;

            int count = 0;
            while (reader.Read ()) {
                switch (reader.LocalName) {
                case "playlist":
                    if (reader.NodeType == XmlNodeType.EndElement && pl != null) {
                        Daemon.DefaultDatabase.AddPlaylist (pl);
                        playlists.Add (pl);
                        count++;
                    } else if (reader.NodeType == XmlNodeType.Element &&
                               reader["type"] == "static") {
                        pl = new Playlist (reader["name"]);
                    }
                    break;
                case "location":
                    if (pl != null) {
                        Uri uri = new Uri (reader.ReadString ());

                        if (uri.IsFile && tracks.ContainsKey (uri.LocalPath)) {
                            pl.AddTrack (tracks[uri.LocalPath]);
                        }
                    }

                    break;
                }
            }

            reader.Close ();

            Daemon.Log.DebugFormat ("Added {0} playlists", count);
        }
Exemplo n.º 8
0
        internal void Update(Playlist pl)
        {
            if (pl.Name == name)
                return;

            Name = pl.Name;
        }
Exemplo n.º 9
0
        internal static Playlist FromNode(ContentNode node)
        {
            Playlist pl = new Playlist ();

            foreach (ContentNode child in (ContentNode[]) node.Value) {
                switch (child.Name) {
                case  "daap.baseplaylist":
                    return null;
                case "dmap.itemid":
                    pl.Id = (int) child.Value;
                    break;
                case "dmap.itemname":
                    pl.Name = (string) child.Value;
                    break;
                default:
                    break;
                }
            }

            return pl;
        }
Exemplo n.º 10
0
        private Playlist AddPlaylist(IPod.Playlist ipl)
        {
            Playlist pl = new Playlist (ipl.Name);

            foreach (IPod.Track itrack in ipl.Tracks) {
                Track track = LookupTrack (itrack);
                if (track != null)
                    pl.AddTrack (track);
            }

            db.AddPlaylist (pl);
            return pl;
        }