Ejemplo n.º 1
0
        /// <summary>
        /// Add track to playlist.
        /// </summary>
        /// <param name="playlistId">
        /// ID of playlist (1 and 2 supported only).
        /// </param>
        /// <param name="trackId">
        /// Track ID of track to add.
        /// </param>
        /// <param name="allowTwice">
        /// True if track should be added although it's already in available in the playlist.
        /// </param>
        /// <returns>
        /// True if track successfully added to playlist.
        /// </returns>
        public static bool AddTrackToPlayList(int playlistId, int trackId, bool allowTwice)
        {
            if (!allowTwice)
            {
                TrackListModel m = (playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist).TrackModel;

                for (int i = 0; i < m.Count; i++)
                {
                    object t = m.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        return(false);
                    }
                }
            }

            switch (playlistId)
            {
            case 1: {
                Selection          selection = null;
                MusicLibrarySource source    = MusicLibrary;

                for (int i = 0; i < source.TrackModel.Count; i++)
                {
                    object t = source.TrackModel.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        selection = new Hyena.Collections.Selection();
                        selection.Select(i);
                        break;
                    }
                }

                if (selection != null)
                {
                    RemotePlaylist.AddSelectedTracks(source, selection);
                    return(true);
                }

                break;
            }

            case 2: {
                DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>(
                    ServiceManager.DbConnection).FetchSingle(trackId);

                if (track != null)
                {
                    PlayQueuePlaylist.EnqueueTrack(track, false);
                    return(true);
                }

                break;
            }
            }

            return(false);
        }
 public void SetModels (TrackListModel track, IListModel<ArtistInfo> artist, IListModel<AlbumInfo> album, IListModel<QueryFilterInfo<string>> genre)
 {
     SetModel (track);
     SetModel (artist);
     SetModel (album);
     // SetModel (genre);
 }
Ejemplo n.º 3
0
 public IActionResult Post(string name, string author)
 {
     try
     {
         Regex reg = new Regex(@"[A-ZА-Я0-9]?[a-zа-я0-9]+ ?[A-ZА-Я0-9]?[a-zа-я0-9]*");
         if (reg.IsMatch(author) == true)
         {
             List <TrackListModel> tracks = _db.Get <TrackListModel>().ToList().Values.ToList();
             TrackListModel        check  = tracks.FirstOrDefault(u => u.Author == author);
             if (check.Name == "....." && check != null)
             {
                 _db.Remove <TrackListModel>(check.Id);
             }
             TrackListModel track = new TrackListModel()
             {
                 Name = name, Author = author
             };
             _db.Insert <TrackListModel>(track);
             return(View("TrackList"));
         }
         else
         {
             return(ServerError());
         }
     }
     catch
     {
         Console.WriteLine("Invalid input");
         return(ServerError());
     }
 }
 public void SetModels(TrackListModel track, IListModel <ArtistInfo> artist, IListModel <AlbumInfo> album, IListModel <QueryFilterInfo <string> > genre)
 {
     SetModel(track);
     SetModel(artist);
     SetModel(album);
     SetModel(genre);
 }
Ejemplo n.º 5
0
        private void OnActiveSourceChanged(SourceEventArgs args)
        {
            ThreadAssist.ProxyToMain(delegate {
                Source source = ServiceManager.SourceManager.ActiveSource;

                search_entry_align.Visible = view_container.SearchSensitive = source != null && source.CanSearch;

                if (source == null)
                {
                    return;
                }

                view_container.SearchEntry.Ready = false;
                view_container.SearchEntry.CancelSearch();

                /* Translators: this is a verb (command), not a noun (things) */
                var msg = source.Properties.Get <string> ("SearchEntryDescription") ?? Catalog.GetString("Search");
                view_container.SearchEntry.EmptyMessage = msg;
                view_container.SearchEntry.TooltipText  = msg;

                if (source.FilterQuery != null)
                {
                    view_container.SearchEntry.Query = source.FilterQuery;
                    view_container.SearchEntry.ActivateFilter((int)source.FilterType);
                }

                if (view_container.Content != null)
                {
                    view_container.Content.ResetSource();
                }

                if (previous_track_model != null)
                {
                    previous_track_model.Reloaded -= HandleTrackModelReloaded;
                    previous_track_model           = null;
                }

                if (source is ITrackModelSource)
                {
                    previous_track_model           = (source as ITrackModelSource).TrackModel;
                    previous_track_model.Reloaded += HandleTrackModelReloaded;
                }

                if (previous_source != null)
                {
                    previous_source.Properties.PropertyChanged -= OnSourcePropertyChanged;
                }

                previous_source = source;
                previous_source.Properties.PropertyChanged += OnSourcePropertyChanged;

                UpdateSourceContents(source);

                UpdateSourceInformation();
                view_container.SearchEntry.Ready = true;

                SetSimple(source.Properties.Get <bool> ("Nereid.SimpleUI"));
            });
        }
Ejemplo n.º 6
0
 public AmpacheSource () : base ("Ampache", "Ampache", 90, "Ampache")
 {
     _trackModel = new MemoryTrackListModel();
     Pixbuf icon = new Pixbuf (System.Reflection.Assembly.GetExecutingAssembly ()
                               .GetManifestResourceStream ("ampache.png"));
     Properties.Set<Pixbuf> ("Icon.Pixbuf_16", icon.ScaleSimple (16, 16, InterpType.Bilinear));
     ServiceManager.SourceManager.AddSource(this);
     preferences = new AmpachePreferences(this);
 }
Ejemplo n.º 7
0
        public AmpacheSource() : base("Ampache", "Ampache", "Ampache", 90)
        {
            _trackModel = new MemoryTrackListModel();
            Pixbuf icon = new Pixbuf(System.Reflection.Assembly.GetExecutingAssembly()
                                     .GetManifestResourceStream("ampache.png"));

            Properties.Set <Pixbuf> ("Icon.Pixbuf_16", icon.ScaleSimple(16, 16, InterpType.Bilinear));
            ServiceManager.SourceManager.AddSource(this);
            preferences = new AmpachePreferences(this);
        }
Ejemplo n.º 8
0
        private void OnActiveSourceChanged(SourceEventArgs args)
        {
            Banshee.ServiceStack.Application.Invoke(delegate {
                Source source = ServiceManager.SourceManager.ActiveSource;

                header.SearchEntry.SearchSensitive = source != null && source.CanSearch;

                if (source == null)
                {
                    return;
                }

                header.SearchEntry.Entry.Ready = false;
                header.SearchEntry.Entry.CancelSearch();

                if (source.FilterQuery != null)
                {
                    header.SearchEntry.Entry.Query = source.FilterQuery;
                    header.SearchEntry.Entry.ActivateFilter((int)source.FilterType);
                }

                if (view_container.Content != null)
                {
                    view_container.Content.ResetSource();
                }

                if (previous_track_model != null)
                {
                    previous_track_model.Reloaded -= HandleTrackModelReloaded;
                    previous_track_model           = null;
                }

                if (source is ITrackModelSource)
                {
                    previous_track_model           = (source as ITrackModelSource).TrackModel;
                    previous_track_model.Reloaded += HandleTrackModelReloaded;
                }

                if (previous_source != null)
                {
                    previous_source.Properties.PropertyChanged -= OnSourcePropertyChanged;
                }

                UpdateSourceHistory(previous_source, source);

                previous_source = source;
                previous_source.Properties.PropertyChanged += OnSourcePropertyChanged;

                UpdateSourceContents(source);

                UpdateSourceInformation();
                header.SearchEntry.Entry.Ready = true;
            });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Set track to play (immediately).
        /// </summary>
        /// <param name="playlistId">
        /// ID of playlsit in which the requested track is located (0 for no playlist).
        /// </param>
        /// <param name="trackId">
        /// ID of track in database.
        /// </param>
        /// <returns>
        /// Returns true if track is available and is plaing now.
        /// </returns>
        public static byte PlayTrack(int playlistId, long trackId)
        {
            if (trackId < 1)
            {
                return(0);
            }

            DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>(
                ServiceManager.DbConnection).FetchSingle(trackId);

            if (track == null)
            {
                return(0);
            }

            Source         source          = Helper.GetPlaylistSource(playlistId);
            Source         requestedSource = source;
            TrackListModel model           = null;

            if (source == null)
            {
                source = MusicLibrary;
            }

            model = ((ITrackModelSource)source).TrackModel;

            if (model != null)
            {
                int i = 0;

                for (i = 0; i < model.Count; i++)
                {
                    TrackInfo t = (TrackInfo)model.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == track.TrackId)
                    {
                        break;
                    }
                }

                if (i != model.Count)
                {
                    ServiceManager.PlaybackController.Source = (ITrackModelSource)source;
                    ServiceManager.PlayerEngine.OpenPlay((TrackInfo)model.GetItem(i));
                    _playTimeout = Timestamp();
                    return((byte)(source == requestedSource ? 2 : 1));
                }
            }

            ServiceManager.PlayerEngine.OpenPlay(track);
            _playTimeout = Timestamp();
            return(1);
        }
Ejemplo n.º 10
0
        private void OnActiveSourceChanged(SourceEventArgs args)
        {
            Banshee.Base.ThreadAssist.ProxyToMain(delegate {
                Source source = ServiceManager.SourceManager.ActiveSource;

                view_container.SearchSensitive = source != null && source.CanSearch;

                if (source == null)
                {
                    return;
                }

                view_container.Title             = source.Name;
                view_container.SearchEntry.Ready = false;
                view_container.SearchEntry.CancelSearch();

                if (source.FilterQuery != null)
                {
                    view_container.SearchEntry.Query = source.FilterQuery;
                    view_container.SearchEntry.ActivateFilter((int)source.FilterType);
                }

                if (view_container.Content != null)
                {
                    view_container.Content.ResetSource();
                }

                if (previous_track_model != null)
                {
                    previous_track_model.Reloaded -= HandleTrackModelReloaded;
                    previous_track_model           = null;
                }

                if (source is ITrackModelSource)
                {
                    previous_track_model           = (source as ITrackModelSource).TrackModel;
                    previous_track_model.Reloaded += HandleTrackModelReloaded;
                }

                if (previous_source != null)
                {
                    previous_source.Properties.PropertyChanged -= OnSourcePropertyChanged;
                }

                previous_source = source;
                previous_source.Properties.PropertyChanged += OnSourcePropertyChanged;

                UpdateSourceContents(source);

                UpdateSourceInformation();
                view_container.SearchEntry.Ready = true;
            });
        }
Ejemplo n.º 11
0
        private TrackEditorDialog(TrackListModel model, Selection selection, EditorMode mode, bool readonlyTabs) : base(
                mode == EditorMode.Edit ? Catalog.GetString("Track Editor") : Catalog.GetString("Track Properties"))
        {
            readonly_tabs = readonlyTabs;
            this.mode     = mode;

            LoadTrackModel(model, selection);

            if (mode == EditorMode.Edit || readonly_tabs)
            {
                WidthRequest = 525;
                if (mode == EditorMode.Edit)
                {
                    AddStockButton(Stock.Cancel, ResponseType.Cancel);
                    AddStockButton(Stock.Save, ResponseType.Ok);
                }
            }
            else
            {
                SetSizeRequest(400, 500);
            }

            if (mode == EditorMode.View)
            {
                AddStockButton(Stock.Close, ResponseType.Close, true);
            }

            tooltip_host = TooltipSetter.CreateHost();

            AddNavigationButtons();

            main_vbox             = new VBox();
            main_vbox.Spacing     = 12;
            main_vbox.BorderWidth = 0;
            main_vbox.Show();
            VBox.PackStart(main_vbox, true, true, 0);

            BuildHeader();
            BuildNotebook();
            BuildFooter();

            LoadModifiers();

            LoadTrackToEditor();

            HideSingleTab();
        }
Ejemplo n.º 12
0
        protected void LoadTrackModel(TrackListModel model)
        {
            DatabaseTrackListModel db_model = model as DatabaseTrackListModel;

            if (db_model != null)
            {
                db_selection = CachedList <DatabaseTrackInfo> .CreateFromModelSelection(db_model);
            }
            else
            {
                memory_selection = new List <TrackInfo> ();
                foreach (TrackInfo track in model.SelectedItems)
                {
                    memory_selection.Add(track);
                }
            }
        }
Ejemplo n.º 13
0
        private TrackEditorDialog(TrackListModel model, EditorMode mode) : base(
                mode == EditorMode.Edit ? Catalog.GetString("Track Editor") : Catalog.GetString("Track Properties"))
        {
            this.mode = mode;

            LoadTrackModel(model);

            BorderWidth = 6;

            if (mode == EditorMode.Edit)
            {
                WidthRequest = 525;
                AddStockButton(Stock.Cancel, ResponseType.Cancel);
                AddStockButton(Stock.Save, ResponseType.Ok);
            }
            else
            {
                AddStockButton(Stock.Close, ResponseType.Close, true);
                SetSizeRequest(400, 500);
            }

            tooltip_host = TooltipSetter.CreateHost();

            AddNavigationButtons();

            main_vbox             = new VBox();
            main_vbox.Spacing     = 10;
            main_vbox.BorderWidth = 6;
            main_vbox.Show();
            VBox.PackStart(main_vbox, true, true, 0);

            BuildHeader();
            BuildNotebook();
            BuildFooter();

            LoadModifiers();

            LoadTrackToEditor();
        }
Ejemplo n.º 14
0
 public IActionResult Post(string author)
 {
     try
     {
         Regex reg = new Regex(@"[A-ZА-Я0-9]?[a-zа-я0-9]+ ?[A-ZА-Я0-9]?[a-zа-я0-9]*");
         if (reg.IsMatch(author) == true)
         {
             TrackListModel track = new TrackListModel()
             {
                 Name = ".....", Author = author
             };
             _db.Insert <TrackListModel>(track);
             return(View("GroupList"));
         }
         return(ServerError());
     }
     catch
     {
         Console.WriteLine("Invalid input");
         return(ServerError());
     }
 }
Ejemplo n.º 15
0
        private async void CaregiverlvBinding_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //disable monitor progress
            TrackListModel model = (TrackListModel)e.AddedItems[0];

            if (model != null)
            {
                MessageDialog md = new MessageDialog("Are you sure to cancel monitor by caregiver " + model.caregiverid.userfullname);

                md.Commands.Add(new UICommand {
                    Label = "Yes", Id = 0
                });
                md.Commands.Add(new UICommand {
                    Label = "No", Id = 1
                });
                var res = await md.ShowAsync();

                if ((int)res.Id == 0)
                {
                    cancelMonitor(model._id);
                }
            }
        }
Ejemplo n.º 16
0
 public static void RunView(TrackListModel model)
 {
     Run(model, EditorMode.View);
 }
Ejemplo n.º 17
0
 public static void RunEdit(TrackListModel model, Selection selection)
 {
     Run(model, selection, EditorMode.Edit);
 }
Ejemplo n.º 18
0
        private async void LoadElderly(String tracklist_id)
        {
            load_elderly_progressbar.Visibility = Visibility.Visible;

            object api = settings.Values["api"];
            object id  = settings.Values["userid"];

            if (api != null && id != null)
            {
                try
                {
                    var httpClient = new HttpClient();
                    var response   = await httpClient.GetAsync(common.getIP() + "api/tracklist/" + api.ToString() + "/" + id.ToString() + "/" + tracklist_id);

                    load_elderly_progressbar.Visibility = Visibility.Collapsed;
                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();

                        TrackListModel trackListModel = JsonConvert.DeserializeObject <TrackListModel>(content);

                        Title.Text       = trackListModel.elderlyid.userfullname;
                        ElderlyName.Text = trackListModel.elderlyid.userfullname;

                        LoadLocationList(trackListModel.elderlyid._id);
                        ElderlyId = trackListModel.elderlyid._id;

                        int c = 0;

                        if (trackListModel.outdoor == null)
                        {
                            if (trackListModel.indoor != null)
                            {
                                c = 1;
                            }
                            else
                            {
                                c = 0;
                            }
                        }
                        else
                        {
                            if (trackListModel.indoor != null)
                            {
                                c = 3;
                            }
                            else
                            {
                                c = 2;
                            }
                        }


                        switch (c)
                        {
                        case 0:
                            ElderlyCoverage.Text         = "-";
                            ElderlyLocationBtn.IsEnabled = false;

                            break;

                        case 1:

                            ElderlyCoverage.Text = "INDOOR";

                            ElderlyLocation.Text         = trackListModel.indoor.zoneid.locationname;
                            LatestLocationTime.Text      = trackListModel.indoor.timestamp.ToLocalTime().ToString();
                            ElderlyLocationBtn.IsEnabled = false;

                            break;

                        case 2:

                            lastestOutdoorLat = trackListModel.outdoor.latitude;
                            lastestOutdoorLng = trackListModel.outdoor.longitude;
                            FindAddress(trackListModel.outdoor.latitude, trackListModel.outdoor.longitude);
                            ElderlyCoverage.Text         = "OUTDOOR";
                            LatestLocationTime.Text      = trackListModel.outdoor.timestamp.ToLocalTime().ToString();
                            ElderlyLocationBtn.IsEnabled = true;

                            break;

                        case 3:

                            if (trackListModel.indoor.timestamp > trackListModel.outdoor.timestamp)
                            {
                                ElderlyCoverage.Text = "INDOOR";

                                ElderlyLocation.Text         = trackListModel.indoor.zoneid.locationname;
                                LatestLocationTime.Text      = trackListModel.indoor.timestamp.ToLocalTime().ToString();
                                ElderlyLocationBtn.IsEnabled = false;
                            }
                            else
                            {
                                lastestOutdoorLat = trackListModel.outdoor.latitude;
                                lastestOutdoorLng = trackListModel.outdoor.longitude;
                                FindAddress(trackListModel.outdoor.latitude, trackListModel.outdoor.longitude);
                                ElderlyCoverage.Text         = "OUTDOOR";
                                LatestLocationTime.Text      = trackListModel.outdoor.timestamp.ToLocalTime().ToString();
                                ElderlyLocationBtn.IsEnabled = true;
                            }

                            break;
                        }


                        if (trackListModel.elderlyid.alert == true)
                        {
                            AlertStatus.Visibility = Visibility.Visible;

                            MessageDialog md = new MessageDialog("You want cancel elderly alert status?");

                            md.Commands.Add(new UICommand {
                                Label = "Yes", Id = 0
                            });
                            md.Commands.Add(new UICommand {
                                Label = "No", Id = 1
                            });
                            var res = await md.ShowAsync();

                            if ((int)res.Id == 0)
                            {
                                DisableAlertElderly(trackListModel.elderlyid._id);
                            }
                        }
                        else
                        {
                            AlertStatus.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        showDialog();
                    }
                }
                catch (Exception ex)
                {
                    load_elderly_progressbar.Visibility = Visibility.Collapsed;

                    Debug.WriteLine(ex);
                    showDialog();
                }
            }
            else
            {
                load_elderly_progressbar.Visibility = Visibility.Collapsed;

                MessageDialog md = new MessageDialog("Api error occur. Relogin application.");
                await md.ShowAsync();

                settings.Values["login_status"] = false;
                Application.Current.Exit();
            }
        }
Ejemplo n.º 19
0
        public static void Run(TrackListModel model, EditorMode mode)
        {
            TrackEditorDialog track_editor = new TrackEditorDialog(model, mode);

            track_editor.Response += delegate(object o, ResponseArgs args) {
                if (args.ResponseId == ResponseType.Ok)
                {
                    track_editor.Save();
                }
                else
                {
                    int changed_count = 0;
                    for (int i = 0; i < track_editor.TrackCount; i++)
                    {
                        EditorTrackInfo track = track_editor.LoadTrack(i, false);
                        if (track != null)
                        {
                            track.GenerateDiff();
                            if (track.DiffCount > 0)
                            {
                                changed_count++;
                            }
                        }
                    }

                    if (changed_count == 0)
                    {
                        track_editor.Destroy();
                        return;
                    }

                    HigMessageDialog message_dialog = new HigMessageDialog(
                        track_editor, DialogFlags.Modal, MessageType.Warning, ButtonsType.None,

                        String.Format(Catalog.GetPluralString(
                                          "Save the changes made to the open track?",
                                          "Save the changes made to {0} of {1} open tracks?",
                                          track_editor.TrackCount), changed_count, track_editor.TrackCount),

                        String.Empty
                        );

                    UpdateCancelMessage(track_editor, message_dialog);
                    uint timeout = 0;
                    timeout = GLib.Timeout.Add(1000, delegate {
                        bool result = UpdateCancelMessage(track_editor, message_dialog);
                        if (!result)
                        {
                            timeout = 0;
                        }
                        return(result);
                    });

                    message_dialog.AddButton(Catalog.GetString("Close _without Saving"), ResponseType.Close, false);
                    message_dialog.AddButton(Stock.Cancel, ResponseType.Cancel, false);
                    message_dialog.AddButton(Stock.Save, ResponseType.Ok, true);

                    try {
                        switch ((ResponseType)message_dialog.Run())
                        {
                        case ResponseType.Ok:
                            track_editor.Save();
                            break;

                        case ResponseType.Close:
                            break;

                        case ResponseType.Cancel:
                        case ResponseType.DeleteEvent:
                            return;
                        }
                    } finally {
                        if (timeout > 0)
                        {
                            GLib.Source.Remove(timeout);
                        }
                        message_dialog.Destroy();
                    }
                }

                track_editor.Destroy();
            };

            track_editor.Run();
        }
Ejemplo n.º 20
0
 private TrackEditorDialog(TrackListModel model, Selection selection, EditorMode mode)
     : this(model, selection, mode, false)
 {
 }
Ejemplo n.º 21
0
 private static void Run(TrackListModel model, Selection selection, EditorMode mode, bool readonlyTabs)
 {
     Run(new TrackEditorDialog(model, selection, mode, readonlyTabs));
 }
Ejemplo n.º 22
0
 public static void Run(TrackListModel model, Selection selection, EditorMode mode)
 {
     Run(new TrackEditorDialog(model, selection, mode));
 }
Ejemplo n.º 23
0
 public static void RunEdit(TrackListModel model)
 {
     Run(model, EditorMode.Edit);
 }
Ejemplo n.º 24
0
        public static int AddArtistOrAlbumToPlayList(int playlistId, int id, bool allowTwice, bool isAlbum)
        {
            if (playlistId != 1 && playlistId != 2)
            {
                return(0);
            }

            int count = 0;
            MusicLibrarySource lib       = MusicLibrary;
            DatabaseSource     dest      = playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist;
            TrackListModel     model     = lib.TrackModel;
            Selection          selection = new Selection();

            if (allowTwice)
            {
                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        selection.Select(i);
                        count++;
                    }
                }
            }
            else
            {
                List <SortEntry> ids       = new List <SortEntry>();
                List <int>       doubleIds = new List <int>();

                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        SortEntry e = new SortEntry();
                        e.pos      = i;
                        e.selected = true;
                        e.id       = (t as DatabaseTrackInfo).TrackId;
                        ids.Add(e);
                    }
                }

                ids.Sort();
                dest.Reload();
                model = dest.TrackModel;

                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        doubleIds.Add((t as DatabaseTrackInfo).TrackId);
                    }
                }

                doubleIds.Sort();

                int si = 0, di = 0;

                while (si < ids.Count && di < doubleIds.Count)
                {
                    if (ids[si].id == doubleIds[di])
                    {
                        ids[si].selected = false;
                        si++;
                    }
                    else if (ids[si].id < doubleIds[di])
                    {
                        si++;
                    }
                    else
                    {
                        di++;
                    }
                }

                for (int i = 0; i < ids.Count; i++)
                {
                    if (ids[i].selected)
                    {
                        selection.Select(ids[i].pos);
                        count++;
                    }
                }
            }

            if (count != 0)
            {
                if (dest != PlayQueuePlaylist)
                {
                    dest.AddSelectedTracks(lib, selection);
                }
                else
                {
                    foreach (int s in selection)
                    {
                        ((PlayQueueSource)dest).EnqueueTrack(lib.TrackModel.GetItem(s) as TrackInfo, false);
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 25
0
        private void OnActiveSourceChanged(SourceEventArgs args)
        {
            Banshee.Base.ThreadAssist.ProxyToMain (delegate {
                Source source = ServiceManager.SourceManager.ActiveSource;

                header.SearchEntry.SearchSensitive = source != null && source.CanSearch;

                if (source == null) {
                    return;
                }

                header.SearchEntry.Entry.Ready = false;
                header.SearchEntry.Entry.CancelSearch ();

                if (source.FilterQuery != null) {
                    header.SearchEntry.Entry.Query = source.FilterQuery;
                    header.SearchEntry.Entry.ActivateFilter ((int)source.FilterType);
                }

                if (view_container.Content != null) {
                    view_container.Content.ResetSource ();
                }

                if (previous_track_model != null) {
                    previous_track_model.Reloaded -= HandleTrackModelReloaded;
                    previous_track_model = null;
                }

                if (source is ITrackModelSource) {
                    previous_track_model = (source as ITrackModelSource).TrackModel;
                    previous_track_model.Reloaded += HandleTrackModelReloaded;
                }

                if (previous_source != null) {
                    previous_source.Properties.PropertyChanged -= OnSourcePropertyChanged;
                }

                UpdateSourceHistory (previous_source, source);

                previous_source = source;
                previous_source.Properties.PropertyChanged += OnSourcePropertyChanged;

                UpdateSourceContents (source);

                UpdateSourceInformation ();
                header.SearchEntry.Entry.Ready = true;
            });
        }
Ejemplo n.º 26
0
 public static void RunView(TrackListModel model, Selection selection, bool readonlyTabs)
 {
     Run(model, selection, EditorMode.View, readonlyTabs);
 }
Ejemplo n.º 27
0
        private void OnActiveSourceChanged (SourceEventArgs args)
        {
            ThreadAssist.ProxyToMain (delegate {
                Source source = ServiceManager.SourceManager.ActiveSource;

                search_entry_align.Visible = view_container.SearchSensitive = source != null && source.CanSearch;

                if (source == null) {
                    return;
                }

                view_container.SearchEntry.Ready = false;
                view_container.SearchEntry.CancelSearch ();

                /* Translators: this is a verb (command), not a noun (things) */
                var msg = source.Properties.Get<string> ("SearchEntryDescription") ?? Catalog.GetString ("Search");
                view_container.SearchEntry.EmptyMessage = msg;
                view_container.SearchEntry.TooltipText = msg;

                if (source.FilterQuery != null) {
                    view_container.SearchEntry.Query = source.FilterQuery;
                    view_container.SearchEntry.ActivateFilter ((int)source.FilterType);
                }

                if (view_container.Content != null) {
                    view_container.Content.ResetSource ();
                }

                if (previous_track_model != null) {
                    previous_track_model.Reloaded -= HandleTrackModelReloaded;
                    previous_track_model = null;
                }

                if (source is ITrackModelSource) {
                    previous_track_model = (source as ITrackModelSource).TrackModel;
                    previous_track_model.Reloaded += HandleTrackModelReloaded;
                }

                if (previous_source != null) {
                    previous_source.Properties.PropertyChanged -= OnSourcePropertyChanged;
                }

                previous_source = source;
                previous_source.Properties.PropertyChanged += OnSourcePropertyChanged;

                UpdateSourceContents (source);

                UpdateSourceInformation ();
                view_container.SearchEntry.Ready = true;

                SetSimple (source.Properties.Get<bool> ("Nereid.SimpleUI"));
            });
        }
Ejemplo n.º 28
0
        public static byte [] Playlist(int readBytes)
        {
            byte request = 0;

            if (readBytes > 0)
            {
                request = Helper.Buffer[0];
            }

            switch (request)
            {
            case 1: {
                // requested playlist names
                Source remotePlaylist = Helper.RemotePlaylist;
                ((DatabaseSource)remotePlaylist).Reload();
                Source musicLibrary = ServiceManager.SourceManager.MusicLibrary;

                ushort count = 0;
                bool   remotePlaylistAdded = false;
                int    index = 4;

                Helper.Buffer[0] = Helper.Buffer[1] = 0;

                // - we're going to fill the buffer with all playlists which are not empty (expect remote playlist)
                // - we'll use the request buffer because it's big enough and we don't know the final size
                // - the remote playlist won't be listed if it's fresh created, so we do that manually
                //   we just fit it into position where the source enumaration would contain it
                List <DatabaseSource> sources = new List <DatabaseSource>();

                // we have to catch the sources first because we refresh the while iterating and this crashes on
                // in older banshee versions
                foreach (Source s in ServiceManager.SourceManager.Sources)
                {
                    if (s is DatabaseSource && s != remotePlaylist && s.Parent == musicLibrary ||
                        s == musicLibrary || s is PlayQueueSource)
                    {
                        sources.Add(s as DatabaseSource);
                    }
                }

                foreach (Source s in sources)
                {
                    DatabaseSource so = s as DatabaseSource;
                    Helper.ClearSourceFilters(so);

                    if (so.TrackModel.Count > 0 || s == Helper.PlayQueuePlaylist)
                    {
                        if (!remotePlaylistAdded && String.Compare(s.Name, remotePlaylist.Name) >= 0)
                        {
                            count++;
                            index = Helper.SourceAsPlaylistToBuffer(index, remotePlaylist);
                            remotePlaylistAdded = true;
                        }

                        count++;
                        index = Helper.SourceAsPlaylistToBuffer(index, s);
                    }
                }

                // remote playlist would be at the end so it's still not added to return - do it
                if (!remotePlaylistAdded)
                {
                    count++;
                    index = Helper.SourceAsPlaylistToBuffer(index, remotePlaylist);
                }

                // write playlist count to buffer
                Array.Copy(Helper.ShortToByte(count), 0, Helper.Buffer, 2, 2);

                // get needed bytes from buffer so we can return it
                byte [] result = new byte [index];
                Array.Copy(Helper.Buffer, 0, result, 0, index);

                return(result);
            }

            case 2: {
                // requested tracks from playlist
                ushort playlistId    = 0;
                int    maxReturn     = 0;
                uint   startPosition = 0;

                // get parameters if given
                if (readBytes > 2)
                {
                    playlistId = Helper.ShortFromBuffer(1);
                }
                if (readBytes > 6)
                {
                    maxReturn = (int)Helper.IntFromBuffer(3);
                }
                if (readBytes > 10)
                {
                    startPosition = Helper.IntFromBuffer(7) & 0xffffffff;
                }

                // search for the playlist which was requested
                Source         source = Helper.GetPlaylistSource(playlistId);
                TrackListModel model  = null;

                if (source != null)
                {
                    model = ((ITrackModelSource)source).TrackModel;
                }

                if (model != null)
                {
                    // playlist exists, return the requested amount of track IDs

                    int count   = model.Count;
                    int toCount = count;

                    // request wants a return from the current track position
                    // let's see if this model contains the currently played track
                    if ((startPosition & 0x80000000) != 0)
                    {
                        int pos = model.IndexOf(ServiceManager.PlayerEngine.CurrentTrack);
                        startPosition = startPosition & 0x7fffffff;

                        if (pos < 0 || startPosition > 100)
                        {
                            startPosition = 0;
                        }
                        else
                        {
                            int newStart = (int)(pos - startPosition);
                            startPosition = newStart < 0 ? 0 : (uint)newStart;
                        }
                    }

                    int returned = count - (int)startPosition;

                    // correct te amount of returned tracks
                    if (returned < 0)
                    {
                        returned = 0;
                    }
                    else if (maxReturn != 0 && returned > maxReturn)
                    {
                        returned = maxReturn;
                        toCount  = (int)startPosition + maxReturn;
                    }

                    // get requested tracks and write it in the result buffer
                    byte [] result = new byte [12 + 4 * returned];
                    Array.Copy(Helper.IntToByte((uint)count), 0, result, 0, 4);
                    Array.Copy(Helper.IntToByte((uint)returned), 0, result, 4, 4);
                    Array.Copy(Helper.IntToByte((uint)startPosition), 0, result, 8, 4);
                    byte [] zeroId = new byte [] { 0, 0, 0, 0 };

                    for (int i = (int)startPosition; i < toCount; i++)
                    {
                        TrackInfo track = (TrackInfo)model.GetItem(i);
                        Array.Copy(track is DatabaseTrackInfo
                                                        ? Helper.IntToByte((uint)((DatabaseTrackInfo)track).TrackId) : zeroId,
                                   0, result, (i - startPosition) * 4 + 12, 4);
                    }

                    return(result);
                }
                else
                {
                    // count = returned = startPosition = 0
                    return(new byte [] {
                            0, 0, 0, 0,
                            0, 0, 0, 0,
                            0, 0, 0, 0
                        });
                }
            }

            case 3: {
                // requested to play tracks
                int  playlistId = 0;
                long trackId    = 0;

                // get parameters if given
                if (readBytes > 6)
                {
                    playlistId = Helper.ShortFromBuffer(1);
                    trackId    = Helper.IntFromBuffer(3);
                }

                return(new byte [] { Helper.PlayTrack(playlistId, trackId) });
            }

            case 4:
                if (readBytes > 7 && Helper.AddTrackToPlayList(
                        Helper.ShortFromBuffer(2),
                        (int)Helper.IntFromBuffer(4),
                        (Helper.Buffer[1] & 0x1) != 0))
                {
                    return(Helper.ShortToByte(1));
                }

                return(Helper.ShortToByte(0));

            case 5:
            case 6:
                if (readBytes > 7)
                {
                    return(Helper.ShortToByte((ushort)Helper.AddArtistOrAlbumToPlayList(
                                                  Helper.ShortFromBuffer(2),
                                                  (int)Helper.IntFromBuffer(4),
                                                  (Helper.Buffer[1] & 0x1) != 0,
                                                  request == 6)));
                }

                return(Helper.ShortToByte(0));

            case 7:
                if (readBytes > 6 && Helper.RemoveTrackFromPlaylist(
                        Helper.ShortFromBuffer(1), (int)Helper.IntFromBuffer(3)))
                {
                    return(Helper.ShortToByte(1));
                }

                return(Helper.ShortToByte(0));

            case 8:
            case 9:
                if (readBytes > 6)
                {
                    return(Helper.ShortToByte((ushort)Helper.RemoveArtistOrAlbumFromPlaylist(
                                                  Helper.ShortFromBuffer(1), (int)Helper.IntFromBuffer(3), request == 9)));
                }

                return(Helper.ShortToByte(0));
            }

            return(new byte [] { 0 });
        }