예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (tbName.Text == "")
            {
                MessageBox.Show("Sie müssen der Smartlist einen Namen geben!", "Smartlist", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            if (tbWith1.Text == "")
            {
                MessageBox.Show("You have to specify at least the first query component!", "Smartlist", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            if ((tbWith1.Text != "" && (cbxMatch1.SelectedIndex == -1 || cbxOp1.SelectedIndex == -1)) ||
                (tbWith2.Text != "" && (cbxMatch2.SelectedIndex == -1 || cbxOp2.SelectedIndex == -1)) ||
                (tbWith3.Text != "" && (cbxMatch3.SelectedIndex == -1 || cbxOp3.SelectedIndex == -1)) ||
                (tbWith4.Text != "" && (cbxMatch4.SelectedIndex == -1 || cbxOp4.SelectedIndex == -1)) ||
                (tbWith5.Text != "" && (cbxMatch5.SelectedIndex == -1 || cbxOp5.SelectedIndex == -1)) ||
                (tbWith6.Text != "" && (cbxMatch6.SelectedIndex == -1 || cbxOp6.SelectedIndex == -1)))
            {
                MessageBox.Show("If you enter a right-hand-side, you have to select the match-target and the operator!", "Smartlist", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            List<Query.Match> matchList = new List<Query.Match>();

            Query.Match m1 = createMatch(tbWith1.Text, cbxMatch1.SelectedIndex, cbxOp1.SelectedIndex);
            Query.Match m2 = createMatch(tbWith2.Text, cbxMatch2.SelectedIndex, cbxOp2.SelectedIndex);
            Query.Match m3 = createMatch(tbWith3.Text, cbxMatch3.SelectedIndex, cbxOp3.SelectedIndex);
            Query.Match m4 = createMatch(tbWith4.Text, cbxMatch4.SelectedIndex, cbxOp4.SelectedIndex);
            Query.Match m5 = createMatch(tbWith5.Text, cbxMatch5.SelectedIndex, cbxOp5.SelectedIndex);
            Query.Match m6 = createMatch(tbWith6.Text, cbxMatch6.SelectedIndex, cbxOp6.SelectedIndex);

            if (m1 != null) matchList.Add(m1);
            if (m2 != null) matchList.Add(m2);
            if (m3 != null) matchList.Add(m3);
            if (m4 != null) matchList.Add(m4);
            if (m5 != null) matchList.Add(m5);
            if (m6 != null) matchList.Add(m6);

            Query q = new Query(matchList);

            q.name = tbName.Text;

            try
            {
                if (tbNumResults.Text == "")
                    q.numberOfResults = -1;
                else
                    q.numberOfResults = Convert.ToInt32(tbNumResults.Text);
            }
            catch (InvalidCastException)
            {
                MessageBox.Show("You have to enter a valid number in the 'Maximum number of results' field", "Smartlist", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            switch (cbxMethod.SelectedIndex)
            {
                case 0:
                    q.conj = Query.Conjunction.And;
                    break;
                case 1:
                    q.conj = Query.Conjunction.Or;
                    break;
            }

            switch (cbxSortBy.SelectedIndex)
            {
                case 0:
                    q.sort.by = Query.SortBy.Smart;
                    break;
                case 1:
                    q.sort.by = Query.SortBy.TrackNr;
                    break;
                case 2:
                    q.sort.by = Query.SortBy.Artist;
                    break;
                case 3:
                    q.sort.by = Query.SortBy.Album;
                    break;
                case 4:
                    q.sort.by = Query.SortBy.Title;
                    break;
                case 5:
                    q.sort.by = Query.SortBy.Year;
                    break;
            }

            switch (cbxSortOrder.SelectedIndex)
            {
                case 0:
                    q.sort.order = Query.SortOrder.Ascending;
                    break;
                case 1:
                    q.sort.order = Query.SortOrder.Descending;
                    break;
            }

            System.Diagnostics.Debug.Print("narf");
            MediaDB.Instance.smartlists.setSmartlist(q);
            MediaDB.Instance.commit();
            Program.gui.refreshPlayAndSmartlists();
            Close();
        }
예제 #2
0
        public void loadSmartlist(Query q)
        {
            tbName.Text = q.name;
            tbNumResults.Text = (q.numberOfResults == -1) ? "" : q.numberOfResults.ToString();

            switch (q.conj)
            {
                case Query.Conjunction.And:
                    cbxMethod.SelectedIndex = 0;
                    break;
                case Query.Conjunction.Or:
                    cbxMethod.SelectedIndex = 1;
                    break;
            }

            switch (q.sort.by)
            {
                case Query.SortBy.Smart:
                    cbxSortBy.SelectedIndex = 0;
                    break;
                case Query.SortBy.TrackNr:
                    cbxSortBy.SelectedIndex = 1;
                    break;
                case Query.SortBy.Artist:
                    cbxSortBy.SelectedIndex = 2;
                    break;
                case Query.SortBy.Album:
                    cbxSortBy.SelectedIndex = 3;
                    break;
                case Query.SortBy.Title:
                    cbxSortBy.SelectedIndex = 4;
                    break;
                case Query.SortBy.Year:
                    cbxSortBy.SelectedIndex = 5;
                    break;
            }

            switch (q.sort.order)
            {
                case Query.SortOrder.Ascending:
                    cbxSortOrder.SelectedIndex = 0;
                    break;
                case Query.SortOrder.Descending:
                    cbxSortOrder.SelectedIndex = 1;
                    break;
            }

            for (int i = 0; i < 6 && i < q.match.Count; i++)
            {
                Query.Match m = q.match[i];

                int lhs, op;

                switch (m.lhs)
                {
                    case Query.MatchLHS.All:
                        lhs = 0;
                        break;
                    case Query.MatchLHS.SHA1:
                        lhs = 1;
                        break;
                    case Query.MatchLHS.TrackNr:
                        lhs = 2;
                        break;
                    case Query.MatchLHS.Title:
                        lhs = 3;
                        break;
                    case Query.MatchLHS.Album:
                        lhs = 4;
                        break;
                    case Query.MatchLHS.Artist:
                        lhs = 5;
                        break;
                    case Query.MatchLHS.Rating:
                        lhs = 6;
                        break;
                    case Query.MatchLHS.Year:
                        lhs = 7;
                        break;
                    case Query.MatchLHS.Genre:
                        lhs = 8;
                        break;
                    case Query.MatchLHS.Comment:
                        lhs = 9;
                        break;
                    default:
                        lhs = 0;
                        break;
                }

                switch (m.op)
                {
                    case Query.MatchOp.Is:
                        op = 0;
                        break;
                    case Query.MatchOp.IsNot:
                        op = 1;
                        break;
                    case Query.MatchOp.Contains:
                        op = 2;
                        break;
                    default:
                        op = 0;
                        break;
                }

                switch (i)
                {
                    case 0:
                        cbxMatch1.SelectedIndex = lhs;
                        cbxOp1.SelectedIndex = op;
                        tbWith1.Text = m.rhs;
                        break;
                    case 1:
                        cbxMatch2.SelectedIndex = lhs;
                        cbxOp2.SelectedIndex = op;
                        tbWith2.Text = m.rhs;
                        break;
                    case 2:
                        cbxMatch3.SelectedIndex = lhs;
                        cbxOp3.SelectedIndex = op;
                        tbWith3.Text = m.rhs;
                        break;
                    case 3:
                        cbxMatch4.SelectedIndex = lhs;
                        cbxOp4.SelectedIndex = op;
                        tbWith4.Text = m.rhs;
                        break;
                    case 4:
                        cbxMatch5.SelectedIndex = lhs;
                        cbxOp5.SelectedIndex = op;
                        tbWith5.Text = m.rhs;
                        break;
                    case 5:
                        cbxMatch6.SelectedIndex = lhs;
                        cbxOp6.SelectedIndex = op;
                        tbWith6.Text = m.rhs;
                        break;
                }
            }
        }
예제 #3
0
파일: Media.cs 프로젝트: philwo/crossfade
 /**
  * Removes a smartlist from our container
  * \param query The smartlist which should get removed (only the name is checked for equivalence)
  * */
 public void removeSmartlist(Query query)
 {
     foreach (Query q in smartlists)
     {
         if (query.name == q.name)
         {
             System.Diagnostics.Debug.Print("Deleted query with name " + q.name);
             smartlists.Remove(q);
             break;
         }
     }
 }
예제 #4
0
파일: Media.cs 프로젝트: philwo/crossfade
        /**
         * Adds or updates a smartlist in our container
         * \param query The smartlist which should get saved
         * */
        public void setSmartlist(Query query)
        {
            foreach (Query q in smartlists)
            {
                if (query.name == q.name)
                {
                    System.Diagnostics.Debug.Print("Replaced query with name " + q.name + " with newer version");
                    smartlists.Remove(q);
                    break;
                }
            }

            smartlists.Add(query);
        }
예제 #5
0
파일: P2PDB.cs 프로젝트: philwo/crossfade
        /**
        *  FIXME
        */
        public Media[] query(IPAddress ip, Query q)
        {
            try
            {
                if (q == null)
                {
                    P2PDB_MediaDB mdb;

                    Uri uri = new Uri("http://" + ip.ToString() + ":21000/crossfade.xml");
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    Stream sr = response.GetResponseStream();
                    mdb = (P2PDB_MediaDB)(new XmlSerializer(typeof(P2PDB_MediaDB)).Deserialize(sr));
                    sr.Close();

                    List<Media> newList = new List<Media>();

                    foreach (Media m in mdb.mediaList)
                    {
                        if (m.uri.Scheme != Uri.UriSchemeFile) continue;
                        if (m.SHA1Sum == null) continue;

                        m.uri = new Uri("http://" + ip.ToString() + ":21000/" + m.SHA1Sum);
                        newList.Add(m);
                    }

                    return newList.ToArray();
                }
                else
                {
                    return null;
                }
            }
            catch (WebException)
            {
                return null;
            }
            catch (SocketException)
            {
                return null;
            }
        }
예제 #6
0
        private void queryPlaylist()
        {
            if (tbxSearch.Text != "")
            {
                if (mediaListBackup == null)
                {
                    mediaListBackup = new List<Media>();
                    mediaListBackup.AddRange((Media[])Playlist.Instance);
                }

                Query.Match match = new Query.Match();
                match.lhs = Query.MatchLHS.All;
                match.op = Query.MatchOp.Contains;
                match.rhs = tbxSearch.Text;

                List<Query.Match> matches = new List<Query.Match>();
                matches.Add(match);

                Query q = new Query(matches);
                q.conj = Query.Conjunction.And;
                q.sort.by = this.StandardQuery.sort.by;
                q.sort.order = this.StandardQuery.sort.order;
                q.numberOfResults = -1;

                queryEngine qe = new queryEngine();
                qe.Data = mediaListBackup.ToArray();
                Media[] result = qe.query(q);

                Playlist.Instance.clearPlaylist();
                Playlist.Instance.addMedia(result);

                lvPlaylist.SelectedIndices.Clear();
                if (lvPlaylist.VirtualListSize > 0) lvPlaylist.Items[0].EnsureVisible();
                lvPlaylist.VirtualListSize = Playlist.Instance.Count;
                lvPlaylist.Refresh();
            }
            else
            {
                if (mediaListBackup != null)
                {
                    StandardQuery.sort.by = Query.SortBy.Smart;
                    StandardQuery.sort.order = Query.SortOrder.Ascending;

                    Playlist.Instance.clearPlaylist();
                    Playlist.Instance.addMedia(mediaListBackup.ToArray());
                    mediaListBackup = null;
                    updatePlaylist();
                }
            }
        }
예제 #7
0
        private void gui_krypton_Load(object sender, EventArgs e)
        {
            gui_SplashScreen.SetStatus("Populating playlist ...");
            lvPlaylist.RowGetter = RowGetterDelegate;
            lvPlaylist.CustomSorter = SortDelegate;

            // Install aspect getters to optimize performance
            columnTrackNr.AspectGetter = delegate(object x)
            {
                if (x == null) return 0;
                return ((Media)x).TrackNr;
            };
            columnArtist.AspectGetter = delegate(object x)
            {
                if (x == null) return "";
                return ((Media)x).Artist;
            };
            columnTitle.AspectGetter = delegate(object x)
            {
                if (x == null) return "";
                return ((Media)x).Title;
            };
            columnAlbum.AspectGetter = delegate(object x)
            {
                if (x == null) return "";
                return ((Media)x).Album;
            };
            columnRating.AspectGetter = delegate(object x)
            {
                if (x == null) return 0;
                return ((Media)x).Rating;
            };
            columnLength.AspectGetter = delegate(object x)
            {
                if (x == null) return -1;
                return ((Media)x).Length;
            };
            columnTrackNr.AspectToStringConverter = delegate(object aspect)
            {
                int i = Convert.ToInt32(aspect);
                if (i == 0) return "";
                else return i.ToString();
            };
            columnLength.AspectToStringConverter = delegate(object aspect)
            {
                string lenStr;
                int length = ((int)aspect);

                if (length == -1)
                {
                    lenStr = "";
                }
                else
                {
                    lenStr = String.Format("{0:00}:{1:00}", length / 1000 / 60, (length / 1000) % 60);
                }

                return lenStr;
            };
            columnRating.Renderer = new BrightIdeasSoftware.MultiImageRenderer(Properties.Resources.star, 5, 0, 5);

            columnTrackNr.ImageGetter = delegate(object rowObject)
            {
                if (rowObject == null) return 4;

                Media m = (Media)rowObject;
                Media currentMedia = ((Media)Playlist.Instance[Playlist.Instance.Cursor]);

                if (currentMedia == null) return 4;

                if (m.uri == currentMedia.uri)
                    return 1;
                else
                    return 4;
            };

            StandardQuery = new Query(new List<Query.Match>());
            StandardQuery.sort.by = Query.SortBy.Smart;
            StandardQuery.sort.order = Query.SortOrder.Ascending;

            Media[] results = MediaDB.Instance.mediaList.ToArray();
            Playlist.Instance.clearPlaylist();
            Playlist.Instance.addMedia(results);
            updatePlaylist();

            setViewmode(Viewmode.Playlist);

            /* Populate Media Library TreeView */
            tnMediaLibrary = new TreeNode("Media Library", 0, 0);
            tnMediaLibrary.Tag = "media-lib";

            tnPlaylists = new TreeNode("My Playlists", 1, 1);
            tnSmartlists = new TreeNode("My Smartlists", 2, 2);
            tnPeer2Peer = new TreeNode("My Network", 4, 4);
            tnAudioCDs = new TreeNode("Audio CD", 3, 3);

            refreshPlayAndSmartlists();

            this.tvMediaLibrary.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { tnMediaLibrary, tnPlaylists, tnSmartlists, tnPeer2Peer, tnAudioCDs });
            m_DelegateAddMedia = new DelegateAddMedia(this.addMediaToPlaylist);

            timer1.Enabled = true;
            gui_SplashScreen.CloseForm();
            onMediaChanged();
        }
예제 #8
0
        private static bool checkMediaForMatch(Media m, Query.Match match)
        {
            bool valid = false;
            List<string> lhs = new List<string>(3);

            switch (match.lhs)
            {
                case Query.MatchLHS.All:
                    lhs.Add(m.Artist);
                    lhs.Add(m.Album);
                    lhs.Add(m.Title);
                    lhs.Add(m.uri.ToString());
                    break;
                case Query.MatchLHS.SHA1:
                    lhs.Add(m.SHA1Sum);
                    break;
                case Query.MatchLHS.TrackNr:
                    lhs.Add(m.TrackNr.ToString());
                    break;
                case Query.MatchLHS.Title:
                    lhs.Add(m.Title);
                    break;
                case Query.MatchLHS.Album:
                    lhs.Add(m.Album);
                    break;
                case Query.MatchLHS.Artist:
                    lhs.Add(m.Artist);
                    break;
                case Query.MatchLHS.Rating:
                    lhs.Add(m.Rating.ToString());
                    break;
                case Query.MatchLHS.Year:
                    lhs.Add(m.Year.ToString());
                    break;
                case Query.MatchLHS.Genre:
                    lhs.Add(m.Genre);
                    break;
                case Query.MatchLHS.Comment:
                    lhs.Add(m.Comment);
                    break;
                default:
                    throw new ArgumentException("Invalid matchLHS!");
            }

            foreach (string target in lhs)
            {
                try
                {
                    switch (match.op)
                    {
                        case Query.MatchOp.Contains:
                            valid = valid || target.ToUpper().Contains(match.rhs.ToUpper());
                            break;
                        case Query.MatchOp.Is:
                            valid = valid || (String.Compare(target, match.rhs, true) == 0);
                            break;
                        case Query.MatchOp.IsNot:
                            valid = valid || (String.Compare(target, match.rhs, true) != 0);
                            break;
                    }
                }
                catch (NullReferenceException)
                {
                    System.Diagnostics.Debug.Print("NullReferenceException in queryEngine, not matching target");
                }
            }

            return valid;
        }
예제 #9
0
        /**
        *  FIXME
        */
        public Media[] query(Query q)
        {
            List<Media> resultSet = new List<Media>();

            foreach (Media m in _mediaList)
            {
                bool matches;

                switch (q.conj)
                {
                    case Query.Conjunction.And:
                        matches = true;
                        break;
                    case Query.Conjunction.Or:
                        matches = false;
                        break;
                    default:
                        throw new ArgumentException("Invalid Query.Conjunction!");
                }

                foreach (Query.Match match in q.match)
                {
                    bool valid = checkMediaForMatch(m, match);

                    if (q.conj == Query.Conjunction.And)
                    {
                        if (!valid)
                        {
                            matches = false;
                            break;
                        }
                        else
                        {
                        }
                    }
                    else if (q.conj == Query.Conjunction.Or)
                    {
                        if (!valid)
                        {
                        }
                        else
                        {
                            matches = true;
                            break;
                        }
                    }
                }

                if (matches)
                    resultSet.Add(m);
            }

            // Sort
            switch (q.sort.by)
            {
                case Query.SortBy.Album:
                    resultSet.Sort(new ObjectComparer<Media>("Album"));
                    break;
                case Query.SortBy.Artist:
                    resultSet.Sort(new ObjectComparer<Media>("Artist"));
                    break;
                case Query.SortBy.Smart:
                    resultSet.Sort(new ObjectComparer<Media>("Artist ASC, Album ASC, TrackNr ASC", true));
                    break;
                case Query.SortBy.Title:
                    resultSet.Sort(new ObjectComparer<Media>("Title"));
                    break;
                case Query.SortBy.TrackNr:
                    resultSet.Sort(new ObjectComparer<Media>("TrackNr"));
                    break;
                case Query.SortBy.Year:
                    resultSet.Sort(new ObjectComparer<Media>("Year"));
                    break;
            }

            // Limit to numberOfResults
            if (q.numberOfResults > -1)
            {
                int numResults = Math.Min(q.numberOfResults, resultSet.Count);

                Media[] output = new Media[numResults];
                resultSet.CopyTo(0, output, 0, numResults);
                return output;
            }
            else
            {
                return resultSet.ToArray();
            }
        }