private void BuildWidgets()
        {
            var hbox = new HBox()
            {
                Spacing = 12
            };

            // Left box - cover art, title, etc
            var left_box = new VBox()
            {
                BorderWidth = 12, Spacing = 12
            };

            // Cover art
            cover = new BookCover(this)
            {
                WidthRequest  = 256,
                HeightRequest = 256
            };

            var editable_cover = CoverArtEditor.For(
                cover, (x, y) => true,
                () => library.TrackModel[0],
                UpdateCover
                );

            // Title
            title_label = new WrapLabel();

            resume_button = new ImageButton("", null, IconSize.LargeToolbar);
            resume_button.ImageWidget.Stock  = Stock.MediaPlay;
            resume_button.LabelWidget.Xalign = 0;
            resume_button.Spacing            = 6;

            // FIXME the left padding on this is not right
            rating_entry = new RatingEntry()
            {
                AlwaysShowEmptyStars = true,
                HasFrame             = false
            };
            var rating = new HBox();

            rating.PackStart(rating_entry, false, false, 0);

            // Packing
            left_box.PackStart(editable_cover, false, false, 0);
            left_box.PackStart(title_label, false, false, 0);
            left_box.PackStart(resume_button, false, false, 0);
            //left_box.PackStart (rating, false, false,  0);

            hbox.PackStart(left_box, false, false, 0);

            // Right box - track list
            track_list = new BaseTrackListView()
            {
                HeaderVisible     = true,
                IsEverReorderable = false
            };

            var columns      = new DefaultColumnController();
            var file_columns = new ColumnController();
            var disc_column  = DefaultColumnController.Create(
                BansheeQuery.DiscNumberField, 0.02, false, new ColumnCellPositiveInt(null, false, 2, 2));

            file_columns.AddRange(
                columns.IndicatorColumn,
                disc_column,
                columns.TitleColumn,
                columns.DurationColumn
                );
            file_columns.SortColumn = columns.DiscNumberAndCountColumn;

            foreach (var col in file_columns)
            {
                col.Visible = true;
            }

            var track_sw = new Gtk.ScrolledWindow()
            {
                Child      = track_list,
                ShadowType = ShadowType.None
            };

            track_list.ColumnController = file_columns;

            hbox.PackEnd(track_sw, true, true, 0);

            Child = hbox;
        }
Exemplo n.º 2
0
        private void BuildFilesBox()
        {
            var vbox = new VBox();

            vbox.Spacing = 6;

            var file_list = new BaseTrackListView()
            {
                HeaderVisible     = true,
                IsEverReorderable = false
            };

            var files_model = source.TrackModel as MemoryTrackListModel;
            var columns     = new DefaultColumnController();

            columns.TrackColumn.Title = "#";
            var file_columns = new ColumnController();

            file_columns.AddRange(
                columns.IndicatorColumn,
                columns.TrackColumn,
                columns.TitleColumn,
                columns.DurationColumn,
                columns.FileSizeColumn
                );

            foreach (var col in file_columns)
            {
                col.Visible = true;
            }

            var file_sw = new Gtk.ScrolledWindow();

            file_sw.Child = file_list;

            var tracks = new List <TrackInfo> ();

            var files = new List <IA.DetailsFile> (details.Files);

            string [] format_blacklist = new string [] { "metadata", "fingerprint", "checksums", "xml", "m3u", "dublin core", "unknown" };
            var       formats          = new List <string> ();

            foreach (var f in files)
            {
                var track = new TrackInfo()
                {
                    Uri         = new SafeUri(f.Location),
                    FileSize    = f.Size,
                    TrackNumber = f.Track,
                    ArtistName  = f.Creator ?? details.Creator,
                    AlbumTitle  = item.Title,
                    TrackTitle  = f.Title,
                    BitRate     = f.BitRate,
                    MimeType    = f.Format,
                    Duration    = f.Length
                };

                // Fix up duration/track#/title
                if ((f.Length == TimeSpan.Zero || f.Title == null || f.Track == 0) && !f.Location.Contains("zip") && !f.Location.EndsWith("m3u"))
                {
                    foreach (var b in files)
                    {
                        if ((f.Title != null && f.Title == b.Title) ||
                            (f.OriginalFile != null && b.Location != null && b.Location.EndsWith(f.OriginalFile)) ||
                            (f.OriginalFile != null && f.OriginalFile == b.OriginalFile))
                        {
                            if (track.Duration == TimeSpan.Zero)
                            {
                                track.Duration = b.Length;
                            }

                            if (track.TrackTitle == null)
                            {
                                track.TrackTitle = b.Title;
                            }

                            if (track.TrackNumber == 0)
                            {
                                track.TrackNumber = b.Track;
                            }

                            if (track.Duration != TimeSpan.Zero && track.TrackTitle != null && track.TrackNumber != 0)
                            {
                                break;
                            }
                        }
                    }
                }

                track.TrackTitle = track.TrackTitle ?? System.IO.Path.GetFileName(f.Location);

                tracks.Add(track);

                if (f.Format != null && !formats.Contains(f.Format))
                {
                    if (!format_blacklist.Any(fmt => f.Format.ToLower().Contains(fmt)))
                    {
                        formats.Add(f.Format);
                    }
                }
            }

            // Order the formats according to the preferences
            string format_order = String.Format(", {0}, {1}, {2},", HomeSource.VideoTypes.Get(), HomeSource.AudioTypes.Get(), HomeSource.TextTypes.Get()).ToLower();

            var sorted_formats = formats.Select(f => new { Format = f, Order = Math.Max(format_order.IndexOf(", " + f.ToLower() + ","), format_order.IndexOf(f.ToLower())) })
                                 .OrderBy(o => o.Order == -1 ? Int32.MaxValue : o.Order);

            // See if all the files contain their track #
            bool all_tracks_have_num_in_title = tracks.All(t => t.TrackNumber == 0 || t.TrackTitle.Contains(t.TrackNumber.ToString()));

            // Make these columns snugly fix their data
            if (tracks.Count > 0)
            {
                // Mono in openSUSE 11.0 doesn't like this
                //SetWidth (columns.TrackColumn,    all_tracks_have_num_in_title ? 0 : tracks.Max (f => f.TrackNumber), 0);
                int  max_track = 0;
                long max_size  = 0;
                foreach (var t in tracks)
                {
                    max_track = Math.Max(max_track, t.TrackNumber);
                    max_size  = Math.Max(max_size, t.FileSize);
                }
                SetWidth(columns.TrackColumn, all_tracks_have_num_in_title ? 0 : max_track, 0);

                // Mono in openSUSE 11.0 doesn't like this
                //SetWidth (columns.FileSizeColumn, tracks.Max (f => f.FileSize), 0);
                SetWidth(columns.FileSizeColumn, max_size, 0);
                SetWidth(columns.DurationColumn, tracks.Max(f => f.Duration), TimeSpan.Zero);
            }

            string max_title = "     ";

            if (tracks.Count > 0)
            {
                var sorted_by_title = files.Where(t => !t.Location.Contains("zip"))
                                      .OrderBy(f => f.Title == null ? 0 : f.Title.Length)
                                      .ToList();
                string nine_tenths = sorted_by_title[(int)Math.Floor(.90 * sorted_by_title.Count)].Title ?? "";
                string max         = sorted_by_title[sorted_by_title.Count - 1].Title ?? "";
                max_title = ((double)max.Length >= (double)(1.6 * (double)nine_tenths.Length)) ? nine_tenths : max;
            }
            (columns.TitleColumn.GetCell(0) as ColumnCellText).SetMinMaxStrings(max_title);

            file_list.ColumnController = file_columns;
            file_list.SetModel(files_model);

            var format_list = new ComboBoxText();

            format_list.RowSeparatorFunc = (model, iter) => {
                return((string)model.GetValue(iter, 0) == "---");
            };

            bool have_sep      = false;
            int  active_format = 0;

            foreach (var fmt in sorted_formats)
            {
                if (fmt.Order == -1 && !have_sep)
                {
                    have_sep = true;
                    if (format_list.Model.IterNChildren() > 0)
                    {
                        format_list.AppendText("---");
                    }
                }

                format_list.AppendText(fmt.Format);

                if (active_format == 0 && fmt.Format == item.SelectedFormat)
                {
                    active_format = format_list.Model.IterNChildren() - 1;
                }
            }

            format_list.Changed += (o, a) => {
                files_model.Clear();

                var selected_fmt = format_list.ActiveText;
                foreach (var track in tracks)
                {
                    if (track.MimeType == selected_fmt)
                    {
                        files_model.Add(track);
                    }
                }

                files_model.Reload();

                item.SelectedFormat = selected_fmt;
                item.Save();
            };

            if (formats.Count > 0)
            {
                format_list.Active = active_format;
            }

            vbox.PackStart(file_sw, true, true, 0);
            vbox.PackStart(format_list, false, false, 0);

            file_list.SizeAllocated += (o, a) => {
                int target_list_width = file_list.MaxWidth;
                if (file_sw.VScrollbar != null && file_sw.VScrollbar.IsMapped)
                {
                    target_list_width += file_sw.VScrollbar.Allocation.Width + 2;
                }

                // Don't let the track list be too wide
                target_list_width = Math.Min(target_list_width, (int)(0.5 * (double)Allocation.Width));

                if (a.Allocation.Width != target_list_width && target_list_width > 0)
                {
                    file_sw.SetSizeRequest(target_list_width, -1);
                }
            };

            PackStart(vbox, false, false, 0);
        }