public void SetList(LastfmData <RecentTrack> tracks)
            {
                tile_view.ClearWidgets();

                foreach (RecentTrack track in tracks)
                {
                    MenuTile tile = new MenuTile();
                    widget_track_map [tile] = track;
                    tile.PrimaryText        = track.Name;
                    tile.SecondaryText      = track.Artist;
                    tile.ButtonPressEvent  += OnTileActivated;

                    // Unfortunately the recently loved list doesn't include what album the song is on
                    if (!String.IsNullOrEmpty(track.Album))
                    {
                        AlbumInfo album = new AlbumInfo(track.Album);
                        album.ArtistName = track.Artist;

                        Gdk.Pixbuf pb = artwork_manager == null ? null : artwork_manager.LookupScalePixbuf(album.ArtworkId, 40);
                        if (pb != null)
                        {
                            tile.Pixbuf = pb;
                        }
                    }

                    tile_view.AddNumberedWidget(tile);
                }

                tile_view.ShowAll();
            }
Ejemplo n.º 2
0
        public AlbumArtActor(AlbumInfo album, double textureSize) : base()
        {
            if (artwork_manager == null && ServiceManager.Contains <ArtworkManager> ())
            {
                artwork_manager = ServiceManager.Get <ArtworkManager> ();
            }

            var image = artwork_manager.LookupScalePixbuf(album.ArtworkId, (int)textureSize);

            if (image != null)
            {
                var img = (Image)Image.New();
                img.SetData(image.Pixels, image.HasAlpha ? Cogl.PixelFormat.Rgba8888 : Cogl.PixelFormat.Rgb888,
                            (uint)image.Width, (uint)image.Height, (uint)image.Rowstride);
                Content = img;
            }

            this.album = album;
        }
Ejemplo n.º 3
0
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            foreach (var window in elements_service.ContentWindows)
            {
                if (window.HasToplevelFocus)
                {
                    return;
                }
            }

            bool is_notification_daemon = false;

            try {
                var name = Notifications.Global.ServerInformation.Name;
                is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon";
            } catch {
                // This will be reached if no notification daemon is running
                return;
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            string image = null;

            image = is_notification_daemon
                ? CoverArtSpec.GetPathForSize(current_track.ArtworkId, icon_size)
                : CoverArtSpec.GetPath(current_track.ArtworkId);

            if (!File.Exists(new SafeUri(image)))
            {
                if (artwork_manager_service != null)
                {
                    // artwork does not exist, try looking up the pixbuf to trigger scaling or conversion
                    Gdk.Pixbuf tmp_pixbuf = is_notification_daemon
                        ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, icon_size)
                        : artwork_manager_service.LookupPixbuf(current_track.ArtworkId);

                    if (tmp_pixbuf == null)
                    {
                        image = "audio-x-generic";
                    }
                    else
                    {
                        tmp_pixbuf.Dispose();
                    }
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, image, notif_area.Widget);
                }
                else
                {
                    current_nf.Summary  = current_track.DisplayTrackTitle;
                    current_nf.Body     = message;
                    current_nf.IconName = image;
                    current_nf.AttachToWidget(notif_area.Widget);
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;
                if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive)
                {
                    current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped);
                }
                current_nf.Show();
            } catch (Exception e) {
                Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false);
            }
        }
Ejemplo n.º 4
0
        protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri)
        {
            if (track.PrimarySourceId == DbId)
            {
                return;
            }

            lock (mtp_device) {
                Track  mtp_track = TrackInfoToMtpTrack(track, fromUri);
                bool   video     = track.HasAttribute(TrackMediaAttributes.VideoStream);
                Folder folder    = GetFolderForTrack(track);
                mtp_device.UploadTrack(fromUri.LocalPath, mtp_track, folder, OnUploadProgress);

                // Add/update album art
                if (!video)
                {
                    string key = MakeAlbumKey(track);
                    if (!album_cache.ContainsKey(key))
                    {
                        // LIBMTP 1.0.3 BUG WORKAROUND
                        // In libmtp.c the 'LIBMTP_Create_New_Album' function invokes 'create_new_abstract_list'.
                        // The latter calls strlen on the 'name' parameter without null checking. If AlbumTitle is
                        // null, this causes a sigsegv. Lets be safe and always pass non-null values.
                        Album album = new Album(mtp_device, track.AlbumTitle ?? "", track.AlbumArtist ?? "", track.Genre ?? "", track.Composer ?? "");
                        album.AddTrack(mtp_track);

                        if (supports_jpegs && can_sync_albumart)
                        {
                            ArtworkManager art = ServiceManager.Get <ArtworkManager> ();
                            Exception      ex = null;
                            Gdk.Pixbuf     pic = null;
                            byte[]         bytes = null;
                            uint           width = 0, height = 0;
                            ThreadAssist.BlockingProxyToMain(() => {
                                try {
                                    pic = art.LookupScalePixbuf(track.ArtworkId, thumb_width);
                                    if (pic != null)
                                    {
                                        bytes  = pic.SaveToBuffer("jpeg");
                                        width  = (uint)pic.Width;
                                        height = (uint)pic.Height;
                                    }
                                } catch (Exception e) {
                                    ex = e;
                                }
                            });

                            try {
                                if (ex != null)
                                {
                                    throw ex;
                                }
                                if (bytes != null)
                                {
                                    ArtworkManager.DisposePixbuf(pic);
                                    album.Save(bytes, width, height);
                                    album_cache [key] = Tuple.Create(album, folder);
                                }
                            } catch (Exception e) {
                                Log.Debug("Failed to create MTP Album", e.Message);
                            }
                        }
                        else
                        {
                            album.Save();
                            album_cache[key] = Tuple.Create(album, folder);
                        }
                    }
                    else
                    {
                        Album album = album_cache[key].Item1;
                        album.AddTrack(mtp_track);
                        album.Save();
                    }
                }

                MtpTrackInfo new_track = new MtpTrackInfo(mtp_device, mtp_track);
                new_track.PrimarySource = this;
                new_track.Save(false);
                track_map[new_track.TrackId] = mtp_track;
            }
        }
Ejemplo n.º 5
0
        public void LoadTrackToEditor()
        {
            TrackInfo       current_track = null;
            EditorTrackInfo editor_track  = LoadTrack(current_track_index, out current_track);

            if (editor_track == null)
            {
                return;
            }

            // Update the Header
            header_title_label.Text  = current_track.DisplayTrackTitle;
            header_artist_label.Text = current_track.DisplayArtistName;
            header_album_label.Text  = current_track.DisplayAlbumTitle;

            if (edit_notif_label != null)
            {
                edit_notif_label.Markup = String.Format(Catalog.GetString("<i>Editing {0} of {1} items</i>"),
                                                        CurrentTrackIndex + 1, TrackCount);
            }

            ArtworkManager artwork = ServiceManager.Get <ArtworkManager> ();

            Gdk.Pixbuf cover_art = artwork.LookupScalePixbuf(current_track.ArtworkId, 64);
            header_image.Pixbuf = cover_art;
            if (cover_art == null)
            {
                header_image.IconName         = "media-optical";
                header_image.PixelSize        = 64;
                header_image_frame.ShadowType = ShadowType.None;
            }
            else
            {
                header_image_frame.ShadowType = ShadowType.In;
            }

            // Disconnect all the undo adapters
            ForeachWidget <ICanUndo> (delegate(ICanUndo undoable) {
                undoable.DisconnectUndo();
            });

            foreach (ITrackEditorPage page in pages)
            {
                page.LoadTrack(editor_track);
            }

            // Connect all the undo adapters
            ForeachWidget <ICanUndo> (delegate(ICanUndo undoable) {
                undoable.ConnectUndo(editor_track);
            });

            // Update Navigation
            if (TrackCount > 0 && nav_backward_button != null && nav_forward_button != null)
            {
                nav_backward_button.Sensitive = CanGoBackward;
                nav_forward_button.Sensitive  = CanGoForward;
            }

            // If there was a widget focused already (eg the Title entry), GrabFocus on it,
            // which causes its text to be selected, ready for editing.
            Widget child = FocusChild;

            while (child != null)
            {
                Container container = child as Container;
                if (container != null)
                {
                    child = container.FocusChild;
                }
                else if (child != null)
                {
                    child.GrabFocus();
                    child = null;
                }
            }
        }
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            foreach (var window in elements_service.ContentWindows)
            {
                if (window.HasToplevelFocus)
                {
                    return;
                }
            }

            bool is_notification_daemon = false;

            try {
                var name = Notifications.Global.ServerInformation.Name;
                is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon";
            } catch {
                // This will be reached if no notification daemon is running
                return;
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            if (artwork_manager_service == null)
            {
                artwork_manager_service = ServiceManager.Get <ArtworkManager> ();
            }

            Gdk.Pixbuf image = null;

            if (artwork_manager_service != null)
            {
                image = is_notification_daemon
                    ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, 42)
                    : artwork_manager_service.LookupPixbuf(current_track.ArtworkId);
            }

            if (image == null)
            {
                image = IconThemeUtils.LoadIcon(48, "audio-x-generic");
                if (image != null)
                {
                    image.ScaleSimple(42, 42, Gdk.InterpType.Bilinear);
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, image, notif_area.Widget);
                }
                else
                {
                    current_nf.Summary = current_track.DisplayTrackTitle;
                    current_nf.Body    = message;
                    current_nf.Icon    = image;
                    current_nf.AttachToWidget(notif_area.Widget);
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;
                if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive)
                {
                    current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped);
                }
                current_nf.Show();
            } catch (Exception e) {
                Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false);
            }
        }