Exemplo n.º 1
0
        private void CreatePlaylist(object o, EventArgs args)
        {
            if (finished) {
                return;
            }

            finished = true;

            try {
                PlaylistSource playlist = new PlaylistSource (name, source);
                playlist.Save ();
                source.AddChildSource (playlist);

                HyenaSqliteCommand insert_command = new HyenaSqliteCommand (String.Format (
                    @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES ({0}, ?)", playlist.DbId));

                //ServiceManager.DbConnection.BeginTransaction ();
                foreach (string uri in uris) {
                    // FIXME: Does the following call work if the source is just a PrimarySource (not LibrarySource)?
                    long track_id = source.GetTrackIdForUri (uri);
                    if (track_id > 0) {
                        ServiceManager.DbConnection.Execute (insert_command, track_id);
                    }
                }

                playlist.Reload ();
                playlist.NotifyUser ();
            } catch (Exception e) {
                Hyena.Log.Exception (e);
            }
        }
        private void CreatePlaylist(object o, EventArgs args)
        {
            if (finished)
            {
                return;
            }

            finished = true;

            try {
                PlaylistSource playlist = new PlaylistSource(name, source);
                playlist.Save();
                source.AddChildSource(playlist);

                HyenaSqliteCommand insert_command = new HyenaSqliteCommand(String.Format(
                                                                               @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES ({0}, ?)", playlist.DbId));

                //ServiceManager.DbConnection.BeginTransaction ();
                foreach (string uri in uris)
                {
                    // FIXME: Does the following call work if the source is just a PrimarySource (not LibrarySource)?
                    int track_id = source.GetTrackIdForUri(uri);
                    if (track_id > 0)
                    {
                        ServiceManager.DbConnection.Execute(insert_command, track_id);
                    }
                }

                playlist.Reload();
                playlist.NotifyUser();
            } catch (Exception e) {
                Hyena.Log.Exception(e);
            }
        }
Exemplo n.º 3
0
        public BaseDialog(PlaylistSource queue, string title, WindowConfiguration windowConfig)
            : base(title)
        {
            this.queue = queue;
            VBox.Spacing = 6;

            HBox filter_box = new HBox ();
            filter_box.Spacing = 6;

            Label search_label = new Label ("_Search:");
            filter_box.PackStart (search_label, false, false, 0);

            search_entry = new MuinsheeSearchEntry ();
            search_entry.Show ();
            search_entry.Changed += OnFilterChanged;
            search_entry.Ready = true;
            OnFilterChanged (null, null);
            filter_box.PackStart (search_entry, true, true, 0);

            VBox.PackStart (filter_box, false, false, 0);

            Hyena.Widgets.ScrolledWindow sw = new Hyena.Widgets.ScrolledWindow ();
            sw.Add (GetItemWidget ());
            VBox.PackStart (sw, true, true, 0);

            AddDefaultCloseButton ();

            Button queue_button = new ImageButton (Catalog.GetString ("En_queue"), "gtk-add");
            AddActionWidget (queue_button, Gtk.ResponseType.Apply);

            Button play_button = new ImageButton (Catalog.GetString ("_Play"), "media-playback-start");
            AddButton (play_button, Gtk.ResponseType.Ok, true);

            window_controller = new PersistentWindowController (this, windowConfig, WindowPersistOptions.Size);
            window_controller.Restore ();
            ShowAll ();

            Response += OnResponse;
        }
Exemplo n.º 4
0
 private void AddToPlaylist (PlaylistSource playlist)
 {
     if (!FilterFocused) {
         playlist.AddSelectedTracks (ActiveSource);
     } else {
         playlist.AddAllTracks (ActiveSource);
     }
 }
        private void OnImportFinished (object o, EventArgs args)
        {
            importer.Finished -= OnImportFinished;

            if (CanSyncPlaylists) {
                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
                int [] psources = new int [] {DbId};
                foreach (string playlist_path in PlaylistFiles) {
                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (PlaylistsPath));
                    if (loaded_playlist == null)
                        continue;

                    PlaylistSource playlist = new PlaylistSource (System.IO.Path.GetFileNameWithoutExtension (playlist_path), this);
                    playlist.Save ();
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
                    foreach (Dictionary<string, object> element in loaded_playlist.Elements) {
                        string track_path = (element["uri"] as Uri).LocalPath;
                        int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), psources);
                        if (track_id == 0) {
                            Log.DebugFormat ("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
                        } else {
                            ServiceManager.DbConnection.Execute (insert_cmd, playlist.DbId, track_id);
                        }
                    }
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
                    playlist.UpdateCounts ();
                    AddChildSource (playlist);
                }
            }

            import_reset_event.Set ();
        }
Exemplo n.º 6
0
 private void OnNewPlaylist (object o, EventArgs args)
 {
     PlaylistSource playlist = new PlaylistSource (Catalog.GetString ("New Playlist"), ActivePrimarySource);
     playlist.Save ();
     playlist.PrimarySource.AddChildSource (playlist);
     playlist.NotifyUser ();
     SourceView.BeginRenameSource (playlist);
 }
Exemplo n.º 7
0
 public SongDialog (PlaylistSource queue) : base (queue, Catalog.GetString ("Play Song"), "song")
 {
 }
        protected override void OnDragDataReceived (Gdk.DragContext context, int x, int y,
            Gtk.SelectionData data, uint info, uint time)
        {
            try {
                if (final_drag_start_time != context.StartTime || final_drag_source == null) {
                    Gtk.Drag.Finish (context, false, false, time);
                    return;
                }

                Source drop_source = final_drag_source;

                if (final_drag_source == NewPlaylistSource) {
                    PlaylistSource playlist = new PlaylistSource (Catalog.GetString ("New Playlist"),
                        (new_playlist_parent as PrimarySource));
                    playlist.Save ();
                    playlist.PrimarySource.AddChildSource (playlist);
                    drop_source = playlist;
                }

                if (data.Target.Name == Banshee.Gui.DragDrop.DragDropTarget.Source.Target) {
                    DragDropList<Source> sources = data;
                    if (sources.Count > 0) {
                        drop_source.MergeSourceInput (sources[0], SourceMergeType.Source);
                    }
                } else if (data.Target.Name == DragDropTarget.UriList.Target) {
                    foreach (string uri in DragDropUtilities.SplitSelectionData (data)) {
                        // TODO if we dropped onto a playlist, add ourselves
                        // to it after importing (or if already imported, find
                        // and add to playlist)
                        ServiceManager.Get<Banshee.Library.LibraryImportManager> ().Enqueue (uri);
                    }
                } else if (data.Target.Name == Hyena.Data.Gui.ListViewDragDropTarget.ModelSelection.Target) {
                    // If the drag source is not the track list, it's a filter list, and instead of
                    // only merging the track model's selected tracks, we should merge all the tracks
                    // currently matching the active filters.
                    bool from_filter = !(Gtk.Drag.GetSourceWidget (context) is Banshee.Collection.Gui.BaseTrackListView);
                    drop_source.MergeSourceInput (
                        ServiceManager.SourceManager.ActiveSource,
                        from_filter ? SourceMergeType.Source : SourceMergeType.ModelSelection
                    );
                } else {
                    Hyena.Log.DebugFormat ("SourceView got unknown drag target type: {0}", data.Target.Name);
                }

                Gtk.Drag.Finish (context, true, false, time);
            } finally {
                HideNewPlaylistRow ();
            }
        }
Exemplo n.º 9
0
 private void OnAddToNewPlaylist(object o, EventArgs args)
 {
     // TODO generate name based on the track selection, or begin editing it
     PlaylistSource playlist = new PlaylistSource (Catalog.GetString ("New Playlist"), ActivePrimarySource);
     playlist.Save ();
     playlist.PrimarySource.AddChildSource (playlist);
     AddToPlaylist (playlist);
 }
        // Commented out for now - this method doesn't handle actually subscribing to the feeds
        // (the most important task in migrating podcasts), and it looks like it imports podcast files
        // into the Music Library.
        /*private void ImportPodcasts(LibraryImportManager manager, XmlNodeList podcasts)
        {
            foreach (XmlElement entry in podcasts) {
                if (CheckForCanceled ()) {
                    break;
                }

                processed++;

                string title = String.Empty, feed = String.Empty;
                SafeUri uri = null;

                foreach (XmlElement child in entry.ChildNodes) {
                    if (child == null || child.InnerText == null || child.InnerText == String.Empty) {
                        continue;
                    }

                    try {
                        switch (child.Name) {
                            case "title":
                                title = child.InnerText;
                                break;
                            case "album":
                                feed = child.InnerText;
                                break;
                            case "mountpoint":
                                uri = new SafeUri (child.InnerText);
                                break;
                        }
                    } catch (Exception) {
                        // parsing InnerText failed
                    }
                }

                if (uri == null) {
                    continue;
                }

                UpdateUserJob (processed, count, "", title);

                try {
                    DatabaseTrackInfo track = manager.ImportTrack (uri);

                    if (track == null) {
                        LogError (SafeUri.UriToFilename (uri), Catalog.GetString ("Unable to import podcast."));
                        continue;
                    }

                    track.TrackTitle = title;
                    track.AlbumTitle = feed;
                    track.Genre = "Podcast";

                    track.Save (false);
                } catch (Exception e) {
                    LogError (SafeUri.UriToFilename (uri), e);
                }
            }
        }*/

        private void ImportStaticPlaylists(XmlNodeList playlists)
        {
            foreach (XmlElement list in playlists) {
                if (CheckForCanceled ()) {
                    break;
                }

                processed++;

                try {
                    string title = String.Empty;
                    if (list.HasAttribute ("name")) {
                        title = list.GetAttribute ("name");
                    }

                    UpdateUserJob (processed, count, "", title);

                    PlaylistSource playlist = new PlaylistSource (title, ServiceManager.SourceManager.MusicLibrary);
                    playlist.Save ();
                    ServiceManager.SourceManager.MusicLibrary.AddChildSource (playlist);


                    HyenaSqliteCommand insert_command = new HyenaSqliteCommand (String.Format (
                        @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES ({0}, ?)", playlist.DbId));

                    foreach (XmlElement entry in list.ChildNodes) {
                        if (entry.Name != "location") {
                            continue;
                        }

                        int track_id = ServiceManager.SourceManager.MusicLibrary.GetTrackIdForUri (entry.InnerText);
                        if (track_id > 0) {
                            ServiceManager.DbConnection.Execute (insert_command, track_id);
                        }
                    }

                    playlist.Reload ();
                    playlist.NotifyUser ();
                } catch (Exception e) {
                    LogError ("", e);
                }
            }
        }
Exemplo n.º 11
0
 public AlbumDialog (PlaylistSource queue) : base (queue, Catalog.GetString ("Play Album"), "album")
 {
 }
        private void ProcessRegularPlaylist (string name, XmlReader xml_reader)
        {
            var playlist_source = new PlaylistSource (name, ServiceManager.SourceManager.MusicLibrary);
            playlist_source.Save ();
            ServiceManager.SourceManager.MusicLibrary.AddChildSource (playlist_source);

            // Get the songs in the playlists
            if (xml_reader != null) {
                while (xml_reader.ReadToFollowing ("integer") && !CheckForCanceled ()) {
                    xml_reader.Read ();
                    int itunes_id = Int32.Parse (xml_reader.ReadContentAsString ());
                    int track_id;
                    if (data.track_ids.TryGetValue (itunes_id, out track_id)) {
                        try {
                            ServiceManager.DbConnection.Execute (
                                "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)",
                                playlist_source.DbId, track_id);
                        } catch {
                        }
                    }
                }
                playlist_source.Reload ();
                playlist_source.NotifyUser ();
            }
        }
Exemplo n.º 13
0
        private void OnImportFinished(object o, EventArgs args)
        {
            importer.Finished -= OnImportFinished;

            if (CanSyncPlaylists) {
                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
                foreach (string playlist_path in PlaylistFiles) {
                    // playlist_path has a file:// prefix, and GetDirectoryName messes it up,
                    // so we need to convert it to a regular path
                    string base_folder = ms_device.RootPath != null ? BaseDirectory :
                        System.IO.Path.GetDirectoryName (SafeUri.UriToFilename (playlist_path));

                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path,
                                                                             new Uri (base_folder),
                                                                             ms_device.RootPath);
                    if (loaded_playlist == null)
                        continue;

                    string name = System.IO.Path.GetFileNameWithoutExtension (SafeUri.UriToFilename (playlist_path));
                    PlaylistSource playlist = new PlaylistSource (name, this);
                    playlist.Save ();
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
                    foreach (PlaylistElement element in loaded_playlist.Elements) {
                        string track_path = element.Uri.LocalPath;
                        long track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), DbId);
                        if (track_id == 0) {
                            Log.DebugFormat ("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
                        } else {
                            ServiceManager.DbConnection.Execute (insert_cmd, playlist.DbId, track_id);
                        }
                    }
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
                    playlist.UpdateCounts ();
                    AddChildSource (playlist);
                }
            }

            import_reset_event.Set ();
        }
        internal void Sync (bool force)
        {
            if (Enabled) {
                ThreadAssist.AssertNotInMainThread ();

                CalculateSync ();

                if (!force && to_remove.Count > MAX_NOWARN_TRACKS_REMOVAL) {
                    throw new PossibleUserErrorException (to_remove.Count);
                }

                sync.Dap.DeleteAllTracks (to_remove);
                sync.Dap.AddAllTracks (to_add);

                if (library.SupportsPlaylists && sync.Dap.SupportsPlaylists) {
                    // Now create the playlists, taking snapshots of smart playlists and saving them
                    // as normal playlists
                    IList<AbstractPlaylistSource> playlists = GetSyncPlaylists ();
                    foreach (AbstractPlaylistSource from in playlists) {
                        if (from.Count == 0) {
                            continue;
                        }
                        PlaylistSource to = new PlaylistSource (from.Name, sync.Dap);
                        to.Save ();

                        ServiceManager.DbConnection.Execute (
                            String.Format (
                                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                                    SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND MetadataHash IN
                                        (SELECT MetadataHash FROM {0} WHERE {1})",
                                from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition),
                            to.DbId, sync.Dap.DbId
                        );
                        to.UpdateCounts ();

                        if (to.Count == 0) {
                            // If it's empty, don't leave it on the device
                            to.Unmap ();
                        } else {
                            sync.Dap.AddChildSource (to);
                        }
                    }
                }

                CalculateSync ();
                sync.OnUpdated ();
            }
        }
Exemplo n.º 15
0
 public AlbumDialog(PlaylistSource queue)
     : base(queue, Catalog.GetString ("Play Album"),
           new WindowConfiguration (WidthSchema, HeightSchema, XPosSchema, YPosSchema, MaximizedSchema))
 {
 }
Exemplo n.º 16
0
        private void LoadFromDevice (bool refresh)
        {
            tracks_map.Clear ();
            if (refresh || MediaDatabase  == null) {
                if (MediaDatabase != null)
                    MediaDatabase.Dispose ();

                try {
                    MediaDatabase = new GPod.ITDB (Device.Mountpoint);
                } catch (GLib.GException e) {
                    Log.Exception ("iPod database could be loaded, creating a new one", e);
                    if (GPod.ITDB.InitIpod (Volume.MountPoint, null, Volume.Name)) {
                        // this may throw again. In the future we need to implement some kind of alert
                        // mechanism to let the user know that something more serious is wrong with their
                        // apple device a la the other iPod extension.
                        MediaDatabase = new GPod.ITDB (Device.Mountpoint);
                    } else {
                        Log.Error ("Failed to init iPod database");
                        return;
                    }
                }
            }

            if (MediaDatabase.MasterPlaylist == null) {
                MediaDatabase.Playlists.Add (new GPod.Playlist (Name) {
                    IsMaster = true
                });
            }

            if (SupportsPodcasts && MediaDatabase.PodcastsPlaylist == null) {
                MediaDatabase.Playlists.Add (new GPod.Playlist (Catalog.GetString ("Podcasts")) {
                    IsPodcast = true
                });
            }

            foreach (var ipod_track in MediaDatabase.Tracks) {
                try {
                    var track = new AppleDeviceTrackInfo (ipod_track);
                    if (!tracks_map.ContainsKey (track.TrackId)) {
                        track.PrimarySource = this;
                        track.Save (false);
                        tracks_map.Add (track.TrackId, track);
                    }
                } catch (Exception e) {
                    Log.Exception (e);
                }
            }

            Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                    SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
            foreach (var playlist in MediaDatabase.Playlists) {
                if (playlist.IsMaster || playlist.IsPodcast)
                    continue;

                PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
                pl_src.Save ();
                // We use the IPod.Track.Id here b/c we just shoved it into ExternalID above when we loaded
                // the tracks, however when we sync, the Track.Id values may/will change.
                foreach (var track in playlist.Tracks) {
                    ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, track.DBID);
                }
                pl_src.UpdateCounts ();
                AddChildSource (pl_src);
            }
        }
Exemplo n.º 17
0
 public PlaylistMenuItem(PlaylistSource playlist)
     : base(playlist.Name)
 {
     this.playlist = playlist;
 }
Exemplo n.º 18
0
 private void AddToPlaylist(PlaylistSource playlist)
 {
     if (!FilterFocused) {
         var track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;
         if (chosen_from_playing_track_submenu && track != null) {
             playlist.AddTrack (track);
         } else {
             playlist.AddSelectedTracks (ActiveSource);
         }
     } else {
         playlist.AddAllTracks (ActiveSource);
     }
 }
        private void LoadFromDevice (bool refresh)
        {
            // bool previous_database_supported = database_supported;

            if (refresh) {
                ipod_device.TrackDatabase.Reload ();
            }

            tracks_map.Clear ();

            if (database_supported || (ipod_device.HasTrackDatabase &&
                ipod_device.ModelInfo.DeviceClass == "shuffle")) {
                foreach (Track ipod_track in ipod_device.TrackDatabase.Tracks) {
                    try {
                        IpodTrackInfo track = new IpodTrackInfo (ipod_track);
                        track.PrimarySource = this;
                        track.Save (false);
                        tracks_map.Add (track.TrackId, track);
                    } catch (Exception e) {
                        Log.Exception (e);
                    }
                }

                Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                    @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                        SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
                foreach (IPod.Playlist playlist in ipod_device.TrackDatabase.Playlists) {
                    if (playlist.IsOnTheGo) { // || playlist.IsPodcast) {
                        continue;
                    }
                    PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
                    pl_src.Save ();
                    // We use the IPod.Track.Id here b/c we just shoved it into ExternalID above when we loaded
                    // the tracks, however when we sync, the Track.Id values may/will change.
                    foreach (IPod.Track track in playlist.Tracks) {
                        ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, track.Id);
                    }
                    pl_src.UpdateCounts ();
                    AddChildSource (pl_src);
                }
            }

            /*else {
                BuildDatabaseUnsupportedWidget ();
            }*/

            /*if(previous_database_supported != database_supported) {
                OnPropertiesChanged();
            }*/
        }
Exemplo n.º 20
0
        protected override void LoadFromDevice ()
        {
            track_map = new Dictionary<int, Track> ();
            try {
                List<Track> files = null;
                lock (mtp_device) {
                    files = mtp_device.GetAllTracks (delegate (ulong current, ulong total, IntPtr data) {
                        //user_event.Progress = (double)current / total;
                        // Translators: {0} is the name of the MTP audio device (eg Gabe's Zen Player), {1} is the
                        // track currently being loaded, and {2} is the total # of tracks that will be loaded.
                        SetStatus (String.Format (Catalog.GetString ("Loading {0} - {1} of {2}"), Name, current, total), false);
                        return 0;
                    });
                }

                /*if (user_event.IsCancelRequested) {
                    return;
                }*/

                // Delete any empty albums
                lock (mtp_device) {
                    foreach (Album album in mtp_device.GetAlbums ()) {
                        if (album.Count == 0) {
                            album.Remove ();
                        }
                    }
                }

                foreach (Track mtp_track in files) {
                    int track_id;
                    if ((track_id = DatabaseTrackInfo.GetTrackIdForUri (MtpTrackInfo.GetPathFromMtpTrack (mtp_track), DbId )) > 0) {
                        track_map[track_id] = mtp_track;
                    } else {
                        MtpTrackInfo track = new MtpTrackInfo (mtp_device, mtp_track);
                        track.PrimarySource = this;
                        track.Save (false);
                        track_map[track.TrackId] = mtp_track;
                    }
                }

                Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                    @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                        SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");

                lock (mtp_device) {
                    var playlists = mtp_device.GetPlaylists ();
                    if (playlists != null) {
                        foreach (MTP.Playlist playlist in playlists) {
                            PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
                            pl_src.Save ();
                            // TODO a transaction would make sense here (when the threading issue is fixed)
                            foreach (uint id in playlist.TrackIds) {
                                ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, id);
                            }
                            pl_src.UpdateCounts ();
                            AddChildSource (pl_src);
                        }
                    }
                }

            } catch (Exception e) {
                Log.Exception (e);
            }
            OnTracksAdded ();
        }
 private void OnAddToNewPlaylist (object o, EventArgs args)
 {
     // TODO generate name based on the track selection, or begin editing it
     PlaylistSource playlist = new PlaylistSource (Catalog.GetString ("New Playlist"), ActivePrimarySource);
     playlist.Save ();
     playlist.PrimarySource.AddChildSource (playlist);
     ThreadAssist.SpawnFromMain (delegate {
         playlist.AddSelectedTracks (ActiveSource);
     });
 }