Esempio n. 1
0
 protected override void PruneArtistsAlbums()
 {
     ServiceManager.DbConnection.Execute(prune_artists_albums_command);
     base.PruneArtistsAlbums();
     DatabaseAlbumInfo.Reset();
     DatabaseArtistInfo.Reset();
 }
        protected void AssertNameLowered(string name, string expected)
        {
            DatabaseArtistInfo info = new DatabaseArtistInfo();

            info.Name = name;
            Assert.AreEqual(expected, info.NameLowered);
        }
        protected void AssertNameSort(string name, string name_sort, byte[] expected)
        {
            DatabaseArtistInfo info = new DatabaseArtistInfo();

            info.Name     = name;
            info.NameSort = name_sort;
            Assert.AreEqual(expected, info.NameSortKey);
        }
Esempio n. 4
0
 /// <summary>
 /// Checks if we are in PartyMode & if a new song started playing
 /// Called from OnPlaybackControllerTrackStarted
 /// </summary>
 private void CheckForSwitch()
 {
     ThreadAssist.ProxyToMain(delegate {
         TrackInfo current_track = ServiceManager.PlaybackController.CurrentTrack;
         if (current_track != null && transitioned_track != current_track)
         {
             if (IsActiveSource)
             {
                 FilterView.LabelTrack.SetValueWithAnim(current_track.TrackNumber + " - " + current_track.TrackTitle);
             }
             if (InPartyMode)
             {
                 DatabaseAlbumInfo album = DatabaseAlbumInfo.FindOrCreate(
                     DatabaseArtistInfo.FindOrCreate(current_track.AlbumArtist, current_track.AlbumArtistSort),
                     current_track.AlbumTitle, current_track.AlbumTitleSort, current_track.IsCompilation);
                 FilterView.ScrollTo(album);
             }
             transitioned_track = ServiceManager.PlayerEngine.CurrentTrack;
         }
     });
 }
Esempio n. 5
0
        private void LoadDiscMetadata(object state)
        {
            try {
                LocalDisc mb_disc = (LocalDisc)state;

                OnMetadataQueryStarted(mb_disc);

                Release release = Release.Query(mb_disc).First();

                if (release == null || release.Score < 100)
                {
                    OnMetadataQueryFinished(false);
                    return;
                }

                var tracks = release.GetTracks();
                if (tracks.Count != Count)
                {
                    OnMetadataQueryFinished(false);
                    return;
                }

                disc_title = release.GetTitle();

                int disc_number = 1;
                int i           = 0;

                foreach (Disc disc in release.GetDiscs())
                {
                    i++;
                    if (disc.Id == mb_disc.Id)
                    {
                        disc_number = i;
                    }
                }

                DateTime release_date = DateTime.MaxValue;

                foreach (Event release_event in release.GetEvents())
                {
                    if (release_event.Date != null)
                    {
                        try {
                            // Handle "YYYY" dates
                            var      date_str = release_event.Date;
                            DateTime date     = DateTime.Parse(
                                date_str.Length > 4 ? date_str : date_str + "-01",
                                ApplicationContext.InternalCultureInfo
                                );

                            if (date < release_date)
                            {
                                release_date = date;
                            }
                        } catch {
                        }
                    }
                }

                DatabaseArtistInfo artist = new DatabaseArtistInfo();
                var mb_artist             = release.GetArtist();
                artist.Name          = mb_artist.GetName();
                artist.NameSort      = mb_artist.GetSortName();
                artist.MusicBrainzId = mb_artist.Id;
                bool is_compilation = false;

                DatabaseAlbumInfo album = new DatabaseAlbumInfo();
                album.Title         = disc_title;
                album.ArtistName    = artist.Name;
                album.MusicBrainzId = release.Id;
                album.ReleaseDate   = release_date == DateTime.MaxValue ? DateTime.MinValue : release_date;

                i = 0;
                foreach (Track track in tracks)
                {
                    AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i++];
                    var mb_track_artist          = track.GetArtist();

                    model_track.MusicBrainzId = track.Id;
                    model_track.TrackTitle    = track.GetTitle();
                    model_track.ArtistName    = mb_track_artist.GetName();
                    model_track.AlbumTitle    = disc_title;
                    model_track.DiscNumber    = disc_number;
                    model_track.Album         = album;

                    model_track.Artist               = new DatabaseArtistInfo();
                    model_track.Artist.Name          = model_track.ArtistName;
                    model_track.Artist.NameSort      = mb_track_artist.GetSortName();
                    model_track.Artist.MusicBrainzId = mb_track_artist.Id;

                    if (release_date != DateTime.MinValue)
                    {
                        model_track.Year = release_date.Year;
                    }

                    if (!is_compilation && mb_track_artist.Id != artist.MusicBrainzId)
                    {
                        is_compilation = true;
                    }
                }

                if (is_compilation)
                {
                    album.IsCompilation = true;
                    for (i = 0; i < tracks.Count; i++)
                    {
                        AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i];
                        model_track.IsCompilation   = true;
                        model_track.AlbumArtist     = artist.Name;
                        model_track.AlbumArtistSort = artist.NameSort;
                    }
                }

                OnMetadataQueryFinished(true);
            } catch (Exception ex) {
                Log.DebugException(ex);
                OnMetadataQueryFinished(false);
            }
        }
        private void OnMerge(object o, EventArgs a)
        {
            var discs  = library.BooksModel.SelectedItems.OrderBy(d => d.Title).ToList();
            var author = DatabaseArtistInfo.Provider.FetchSingle((discs[0] as DatabaseAlbumInfo).ArtistId);

            var dialog = new HigMessageDialog(
                ServiceManager.Get <GtkElementsService> ().PrimaryWindow,
                DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.OkCancel,

                String.Format(Catalog.GetPluralString(
                                  "Merge the {0} selected discs into one book?",
                                  "Merge the {0} selected discs into one book?",
                                  discs.Count), discs.Count),

                Catalog.GetString(
                    "This will ensure the disc numbers are all " +
                    "set properly, and then set the author and book title for all tracks " +
                    "on all these discs to the values below")
                );

            var table = new SimpleTable <int> ();

            var author_entry = new Entry()
            {
                Text = discs[0].ArtistName
            };

            table.AddRow(0,
                         new Label(Catalog.GetString("Author:"))
            {
                Xalign = 0
            },
                         author_entry
                         );

            var trimmings   = new char [] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', '-' };
            var title_entry = new Entry()
            {
                Text = discs[0].Title.Trim(trimmings)
            };

            table.AddRow(1,
                         new Label(Catalog.GetString("Book Title:"))
            {
                Xalign = 0
            },
                         title_entry
                         );

            dialog.LabelVBox.PackStart(table, false, false, 0);

            dialog.ShowAll();
            var    response    = dialog.Run();
            string title       = title_entry.Text;
            string author_name = author_entry.Text;

            dialog.Destroy();

            if (response == (int)Gtk.ResponseType.Ok && !String.IsNullOrEmpty(title))
            {
                if (author_name != author.Name)
                {
                    author = DatabaseArtistInfo.FindOrCreate(author_name, null);
                }
                var book = DatabaseAlbumInfo.FindOrCreate(author, title, null, false);

                int disc_num = 1;
                foreach (DatabaseAlbumInfo disc in discs)
                {
                    // Update the disc num/count field for all tracks on this 'book' (actually just one disc of a book)
                    ServiceManager.DbConnection.Execute(
                        @"UPDATE CoreTracks SET AlbumID = ?, Disc = ?, DiscCount = ?, DateUpdatedStamp = ?
                            WHERE PrimarySourceID = ? AND AlbumID = ?",
                        book.DbId, disc_num++, discs.Count, DateTime.Now,
                        library.DbId, disc.DbId
                        );
                }

                // Update the MetadataHash for all those tracks
                DatabaseTrackInfo.UpdateMetadataHash(
                    book.Title, author.Name,
                    String.Format("PrimarySourceId = {0} AND AlbumID = {1}", library.DbId, book.DbId)
                    );

                library.NotifyTracksChanged();
            }
        }
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            if (!artwork_initialized)
            {
                artwork_manager = ServiceManager.Get <ArtworkManager> ();

                if (!artwork_manager.IsCachedSize(image_size))
                {
                    artwork_manager.AddCachedSize(image_size);
                }
                if (artwork_manager != null)
                {
                    artwork_manager.ChangeCacheSize(ImageSize, GetAllAlbumsCount() + 3);
                }

                artwork_initialized = true;
            }

            bool is_queryalble_source = ServiceManager.SourceManager.ActiveSource is PrimarySource;

            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is PlaylistSource;
            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is SmartPlaylistSource;

            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is ArtistInfo))
            {
                throw new InvalidCastException("ColumnCellArtist can only bind to ArtistInfo objects");
            }
            var artist = (ArtistInfo)BoundObject;

            DatabaseArtistInfo db_artist = DatabaseArtistInfo.FindOrCreate(artist.Name, artist.NameSort);

            AlbumInfo[] albums      = GetAlbums(db_artist.DbId);
            int         album_count = albums.Length;

            string pattern = Catalog.GetString("All Artists ({0})")
                             .Replace("(", "\\(")
                             .Replace(")", "\\)")
                             .Replace("{0}", "[0-9]+");

            if (!String.IsNullOrEmpty(artist.Name) && System.Text.RegularExpressions.Regex.IsMatch(artist.Name, pattern))
            {
                album_count = GetAllAlbumsCount();
            }

            ImageSurface image  = null;
            var          images = new List <ImageSurface> ();

            int non_empty = 0;

            for (int i = 0; i < albums.Length && non_empty < 3; i++)
            {
                if (artwork_manager != null)
                {
                    ImageSurface sur = artwork_manager.LookupScaleSurface(albums [i].ArtworkId, image_size, true);
                    images.Add(sur);
                    if (sur != null)
                    {
                        non_empty++;
                    }
                }
            }

            //bringing non-empty images to the front
            images.Sort(delegate(ImageSurface a, ImageSurface b) {
                if (a == null && b != null)
                {
                    return(-1);
                }
                if (a != null && b == null)
                {
                    return(1);
                }
                return(0);
            });

            if (images.Count > 3)
            {
                images.RemoveRange(3, images.Count - 3);
            }

            bool is_default = false;

            if (images.Count == 0)
            {
                image      = default_cover_image;
                is_default = true;
            }
            else
            {
                image = images[images.Count - 1];
            }

            int image_render_size = image_size;
            int x = image_spacing;
            int y = image_spacing;

            if (use_small_images)
            {
                x = image_spacing / 2;
                y = image_spacing / 2;
            }

            const int y_image_spacing = 1;
            int       x_offset        = (use_small_images ? album_spacing_small : album_spacing_normal);

            if (images.Count > 1)
            {
                x_offset *= 2;
            }
            int y_offset = (images.Count > 1) ? y_image_spacing * 2 : y_image_spacing;

            for (int i = 0; i < images.Count - 1; i++)
            {
                int move_x = x + ((i) * (use_small_images ? album_spacing_small : album_spacing_normal));
                int move_y = y + ((i) * y_image_spacing);
                ArtworkRenderer.RenderThumbnail(context.Context, images[i], false, move_x, move_y,
                                                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color(1.0, 1.0, 1.0, 1.0));
            }

            if (images.Count > 0)
            {
                ArtworkRenderer.RenderThumbnail(context.Context, image, false, x + x_offset, y + y_offset,
                                                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color(1.0, 1.0, 1.0, 1.0));
            }
            else
            {
                ArtworkRenderer.RenderThumbnail(context.Context, image, false, x + x_offset, y + y_offset,
                                                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);
            }

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;

            context.Widget.StyleContext.Save();
            context.Widget.StyleContext.AddClass("entry");
            Color text_color = CairoExtensions.GdkRGBAToCairoColor(context.Widget.StyleContext.GetColor(context.State));

            context.Widget.StyleContext.Restore();
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width     = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText(artist.DisplayName);
            layout.GetPixelSize(out fl_width, out fl_height);

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.FontDescription.Size   = (int)(old_size * Pango.Scale.Small);
            layout.FontDescription.Style  = Pango.Style.Italic;

            string album_string_singular = Catalog.GetString("Album");
            string album_string_plural   = Catalog.GetString("Albums");

            layout.SetText(album_count + " " + ((album_count == 1) ? album_string_singular : album_string_plural));
            layout.GetPixelSize(out sl_width, out sl_height);

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + (use_small_images ? album_spacing_small : album_spacing_normal) + 8;
            y = use_small_images ? (int)((cellHeight - (fl_height)) / 2) : (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (album_count > 0 && is_queryalble_source)
            {
                if (use_small_images)
                {
                    context.Context.MoveTo(cellWidth - sl_width - image_spacing, y + image_spacing / 2);
                }
                else
                {
                    context.Context.MoveTo(x, y + fl_height);
                }
                context.Context.SetSourceColor(text_color);
                if (!use_small_images || fl_width + x + sl_width <= cellWidth)
                {
                    Pango.CairoHelper.ShowLayout(context.Context, layout);
                }
            }

            // Render the first line, resetting the state
            layout.SetText(artist.DisplayName);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size   = old_size;
            layout.FontDescription.Style  = Pango.Style.Normal;

            layout.SetText(artist.DisplayName);

            context.Context.MoveTo(x, y);
            text_color.A = 1;
            context.Context.SetSourceColor(text_color);
            Pango.CairoHelper.ShowLayout(context.Context, layout);
        }