Esempio n. 1
0
        public UPnPServerSource(Device device) :  base(Catalog.GetString("UPnP Share"), device.FriendlyName, 300)
        {
            Properties.SetStringList("Icon.Name", "computer", "network-server");
            TypeUniqueId    = "upnp-container";
            expanded_schema = new SchemaEntry <bool> ("plugins.upnp." + device.Udn, "expanded", true,
                                                      "UPnP Share expanded", "UPnP Share expanded");
            udn = device.Udn;

            ContentDirectoryController content_directory = null;

            foreach (Service service in device.Services)
            {
                Log.Debug("UPnPService \"" + device.FriendlyName + "\" Implements " + service.Type);
                if (service.Type.Type == "ContentDirectory")
                {
                    content_directory = new ContentDirectoryController(service.GetController());
                }
            }

            if (content_directory == null)
            {
                throw new ArgumentNullException("content_directory");
            }

            ThreadAssist.Spawn(delegate {
                Parse(device, content_directory);
            });
        }
Esempio n. 2
0
        protected override void OnResponse(ResponseType response)
        {
            if (response == ResponseType.Ok)
            {
                string      name = SourceName;
                StationType type = StationType.FindByLabel(type_combo.ActiveText);
                string      arg  = Arg;

                ThreadAssist.Spawn(delegate {
                    if (source == null)
                    {
                        source = new StationSource(lastfm, name, type.Name, arg);
                        lastfm.AddChildSource(source);
                        //LastFMPlugin.Instance.Source.AddChildSource (source);
                        //ServiceManager.SourceManager.AddSource (source);
                    }
                    else
                    {
                        source.Rename(name);
                        source.Type = type;
                        source.Arg  = arg;
                        source.Save();
                        //source.Refresh ();
                    }
                });
            }
        }
Esempio n. 3
0
        public override ResponseType Run()
        {
            Dialog.ShowAll();

            ResponseType response = (ResponseType)Dialog.Run();

            if (response == ResponseType.Ok)
            {
                string      name = SourceName;
                StationType type = Type;
                string      arg  = Arg;

                ThreadAssist.Spawn(delegate {
                    if (source == null)
                    {
                        source = new StationSource(lastfm, name, type.Name, arg);
                        lastfm.AddChildSource(source);
                        //LastFMPlugin.Instance.Source.AddChildSource (source);
                        //ServiceManager.SourceManager.AddSource (source);
                    }
                    else
                    {
                        source.Rename(name);
                        source.Type = type;
                        source.Arg  = arg;
                        source.Save();
                        //source.Refresh ();
                    }
                });
            }

            return(response);
        }
 public override void Activate()
 {
     if (locker == null && !is_activating)
     {
         is_activating = true;
         ThreadAssist.Spawn(delegate {
             try
             {
                 locker = new MP3tunes.Locker(String.Empty);
                 locker.Login(this.plugin.Username, this.plugin.Password);
                 ArrayList trs  = locker.GetTracks();
                 IEnumerator en = trs.GetEnumerator();
                 while (en.MoveNext())
                 {
                     LockerTrackInfo lti = new LockerTrackInfo((MP3tunes.Track)en.Current);
                     tracks.Add(lti);
                 }
                 OnUpdated();
             }
             catch (Exception e)
             {
                 LogCore.Instance.PushError(Catalog.GetString("Could not load Music Locker"), e.Message);
             }
             is_activating = false;
         });
     }
 }
        public void Refresh()
        {
            lock (this) {
                if (refreshing || lastfm.Connection.Station != Station)
                {
                    return;
                }
                refreshing = true;
            }

            if (TracksLeft == 0)
            {
                SetStatus(Catalog.GetString("Getting new songs for {0}."), false);
            }

            ThreadAssist.Spawn(delegate {
                Media.Playlists.Xspf.Playlist playlist = lastfm.Connection.LoadPlaylistFor(Station);
                if (playlist != null)
                {
                    if (playlist.TrackCount == 0)
                    {
                        SetStatus(Catalog.GetString("No new songs available for {0}."), true);
                    }
                    else
                    {
                        List <TrackInfo> new_tracks = new List <TrackInfo> ();
                        foreach (Media.Playlists.Xspf.Track track in playlist.Tracks)
                        {
                            TrackInfo ti = new LastfmTrackInfo(track, this, track.GetExtendedValue("trackauth"));
                            new_tracks.Add(ti);
                            lock (track_model) {
                                track_model.Add(ti);
                            }
                        }
                        HideStatus();

                        ThreadAssist.ProxyToMain(delegate {
                            //OnTrackAdded (null, new_tracks);
                            track_model.Reload();
                            OnUpdated();

                            if (playback_requested)
                            {
                                if (this == ServiceManager.PlaybackController.Source)
                                {
                                    ((IBasicPlaybackController)this).Next(false, true);
                                }
                                playback_requested = false;
                            }
                        });
                    }
                }
                else
                {
                    SetStatus(Catalog.GetString("Failed to get new songs for {0}."), true);
                }

                refreshing = false;
            });
        }
Esempio n. 6
0
        private void PerformLookUp()
        {
            ThreadAssist.Spawn(delegate {
                ThreadAssist.ProxyToMain(delegate {
                    wh.Component = this.wp;
                    wf.Component = wh;
                    this.Pane.Browser.Render(wf);
                });
                Page p = null;
                if (wq.Find())
                {
                    p = wq.GetResult();
                }
                else                     //show error page or hide pane
                {
                    p = new ErrorPage(Catalog.GetString("Error:"), Catalog.GetString("Information not found"));
                }
                wh.Component = p;
                wf.Component = wh;

                ThreadAssist.ProxyToMain(delegate {
                    this.Pane.Browser.Render(wf);
                });
            });
        }
Esempio n. 7
0
        public override void Queue()
        {
            IContactSource source = ServiceManager.SourceManager.ActiveSource as IContactSource;

            if (!source.IsDownloadingAllowed)
            {
                return;
            }

            DBusActivity activity = Contact.DispatchManager.Get <DBusActivity> (Contact, MetadataProviderService.BusName);

            if (activity != null)
            {
                IMetadataProviderService service = activity.GetDBusObject <IMetadataProviderService> (MetadataProviderService.BusName, MetadataProviderService.ObjectPath);
                if (service != null)
                {
                    base.Queue();
                    ThreadAssist.Spawn(delegate {
                        lock (sync) {
                            try {
                                service.DownloadFile(long.Parse(Key.Name), "audio/mpeg");
                            }
                            catch (Exception e) {
                                Log.Warning(e);
                            }
                        }
                    });
                }
            }
        }
        public void Play()
        {
            if (!loaded)
            {
                OnParsingPlaylistStarted();
                ThreadAssist.Spawn(delegate {
                    LoadStreamUris();
                });
                return;
            }

            Title            = track.Title;
            Artist           = track.Creator;
            Album            = null;
            Duration         = TimeSpan.Zero;
            CoverArtFileName = null;

            lock (((ICollection)stream_uris).SyncRoot) {
                if (stream_uris.Count > 0)
                {
                    Uri = stream_uris[stream_index];
                    PlayerEngineCore.OpenPlay(this);
                }
            }
        }
        private void DoUpdate(ICollection feeds, bool queue_if_busy)
        {
            lock (update_sync)
            {
                if (!updating)
                {
                    updating = true;

                    QueueAdd(feeds, false);

                    currentFeed = 0;
                    totalFeeds  = update_queue.Count;

                    ThreadAssist.ProxyToMain(delegate {
                        try
                        {
                            CreateUserEvent();
                            ThreadAssist.Spawn(new ThreadStart(UpdateThread));
                        }
                        catch {
                            EndUpdate();
                            return;
                        }
                    });
                }
                else if (queue_if_busy && !userEvent.IsCancelRequested)
                {
                    QueueAdd(feeds, true);
                }
            }
        }
Esempio n. 10
0
        private void Play(SafeUri uri)
        {
            PlayerEngineCore.Open(uri);

            ThreadAssist.Spawn(delegate {
                PlayerEngineCore.Play();
            });
        }
Esempio n. 11
0
        public void StartImport()
        {
            if (ImportThread != null)
            {
                throw new Exception("Import already running!");
            }

            ImportThread = ThreadAssist.Spawn(DoImport);
        }
        public void Import()
        {
            if (query != null || thread != null)
            {
                Console.WriteLine("Another Beagle query is already running");
                return;
            }

            thread = ThreadAssist.Spawn(ThreadedImport);
        }
Esempio n. 13
0
        public void StartImport()
        {
            if (importThread != null)
            {
                throw new Exception("Import already running!");
            }

            importTokenSource = new CancellationTokenSource();
            importThread      = ThreadAssist.Spawn(() => DoImport(importTokenSource.Token));
        }
Esempio n. 14
0
        public void StartPhotoScan(bool recurseSubdirectories, bool mergeRawAndJpeg)
        {
            if (PhotoScanner != null)
            {
                run_photoscanner = false;
                PhotoScanner.Join();
            }

            run_photoscanner = true;
            PhotoScanner     = ThreadAssist.Spawn(() => ScanPhotos(recurseSubdirectories, mergeRawAndJpeg));
        }
Esempio n. 15
0
        public void StartPhotoScan(ImportController controller, PhotoList photo_list)
        {
            if (PhotoScanner != null)
            {
                run_photoscanner = false;
                PhotoScanner.Join();
            }

            run_photoscanner = true;
            PhotoScanner     = ThreadAssist.Spawn(() => ScanPhotos(controller, photo_list));
        }
Esempio n. 16
0
 public void Love()
 {
     loved = true; hated = false;
     ThreadAssist.Spawn(delegate {
         try {
             station.LastfmSource.Connection.Love(ArtistName, TrackTitle);
         } catch (System.Net.WebException e) {
             Hyena.Log.Warning("Got Exception Trying to Love Song", e.ToString(), false);
         }
     });
 }
Esempio n. 17
0
 public void ReloadStations(bool forceUpdate)
 {
     if (forceUpdate)
     {
         ThreadAssist.Spawn(ForceReloadStations);
     }
     else
     {
         ThreadAssist.Spawn(ReloadStationsIfNeeded);
     }
 }
Esempio n. 18
0
        public void ProcessIncomingPayloads(PayloadHandler handler)
        {
            if (processing)
            {
                throw new InvalidOperationException("Already processing.");
            }

            payload_handler = handler;
            processing      = true;

            ThreadAssist.Spawn(Process);
        }
Esempio n. 19
0
 private void AuthenticatedLogin(string username, string password)
 {
     ThreadAssist.Spawn(delegate {
         try {
             client.Login(username, password);
         } catch (DAAP.AuthenticationException) {
             ThreadAssist.ProxyToMain(delegate {
                 ShowErrorView(DaapErrorType.InvalidAuthentication);
             });
         }
     });
 }
        internal static void SubscribeToPodcastFeed(string uri, SyncPreference sync)
        {
            PodcastFeedInfo feed = new PodcastFeedInfo(uri, sync);

            feed.UpdateFinished += InitialFeedUpdateHandler;

            if (feed != null)
            {
                ThreadAssist.Spawn(delegate {
                    FeedFetcher.Update(feed, true);
                });
            }
        }
        private static void OnUserEventCancelRequestedHandlerProxy(object o, EventArgs args)
        {
            if (userEvent != null)
            {
                userEvent.CancelRequested -= OnUserEventCancelRequestedHandler;
                cancel_requested           = true;
                userEvent.CanCancel        = false;
                userEvent.Progress         = 0.0;
                userEvent.Header           = Catalog.GetString("Canceling Downloads");
                userEvent.Message          = Catalog.GetString("Waiting for downloads to terminate");

                ThreadAssist.Spawn(new ThreadStart(CancelAll));
            }
        }
Esempio n. 22
0
        void StartScan()
        {
            if (scanThread != null)
            {
                CancelScan();
            }
            if (activeSource == null)
            {
                return;
            }

            var source = activeSource.GetFileImportSource(
                App.Instance.Container.Resolve <IImageFileFactory> (),
                App.Instance.Container.Resolve <IFileSystem> ());

            Photos.Clear();

            scanTokenSource = new CancellationTokenSource();
            scanThread      = ThreadAssist.Spawn(() => DoScan(source, recurseSubdirectories, mergeRawAndJpeg, scanTokenSource.Token));
        }
Esempio n. 23
0
        public override void Activate()
        {
            if (client != null || is_activating)
            {
                return;
            }

            ClearErrorView();

            is_activating = true;
            base.Activate();

            SetStatus(String.Format(Catalog.GetString("Connecting to {0}"), service.Name), false);

            ThreadAssist.Spawn(delegate {
                try {
                    client          = new DAAP.Client(service);
                    client.Updated += OnClientUpdated;

                    if (client.AuthenticationMethod == DAAP.AuthenticationMethod.None)
                    {
                        client.Login();
                    }
                    else
                    {
                        ThreadAssist.ProxyToMain(PromptLogin);
                    }
                } catch (Exception e) {
                    ThreadAssist.ProxyToMain(delegate {
                        ShowErrorView(DaapErrorType.BrokenAuthentication);
                    });
                    Hyena.Log.Exception(e);
                }

                is_activating = false;
            });
        }
        public void ShowRecommendations(string artist)
        {
            if (current_artist == artist)
            {
                Show();
                return;
            }

            Hide();

            ThreadAssist.Spawn(delegate {
                XmlNodeList artists, tracks, albums;
                try {
                    if (QueryRecommendationData(artist, out artists, out tracks, out albums))
                    {
                        ThreadAssist.ProxyToMain(delegate {
                            RenderRecommendationData(artist, artists, tracks, albums);
                        });
                    }
                } catch (Exception e) {
                    Console.Error.WriteLine("Could not fetch recommendations: {0}", e.Message);
                }
            });
        }
Esempio n. 25
0
        public void RunDialog()
        {
            ResponseType response = (ResponseType)dialog.Run();

            //int w = -1, h = -1;
            //dialog.GetSize (out w, out h);
            //Console.WriteLine ("w = {0}, h = {1}", w, h);

            if (response == ResponseType.Ok)
            {
                string name         = Name;
                string condition    = Condition;
                string order_by     = OrderBy;
                string limit_number = LimitNumber;

                ThreadAssist.Spawn(delegate {
                    //Console.WriteLine ("Name = {0}, Cond = {1}, OrderAndLimit = {2}", name, condition, order_by, limit_number);
                    if (playlist == null)
                    {
                        playlist = new SmartPlaylist(name, condition, order_by, limit_number);
                        playlist.Source.Commit();
                        SourceManager.AddSource(playlist.Source);
                    }
                    else
                    {
                        playlist.Name        = name;
                        playlist.Condition   = condition;
                        playlist.OrderBy     = order_by;
                        playlist.LimitNumber = limit_number;
                        playlist.Commit();
                    }
                });
            }

            dialog.Destroy();
        }
Esempio n. 26
0
        public void ShowRecommendations(string artist)
        {
            if (current_artist == artist)
            {
                Visible = true;
                return;
            }

            // FIXME: Error handling
            ThreadAssist.Spawn(delegate {
                // Fetch data for "similar" artists.
                XmlDocument artists_xml_data = new XmlDocument();
                artists_xml_data.LoadXml(RequestContent(String.Format(AUDIOSCROBBLER_SIMILAR_URL, artist)));
                XmlNodeList artists_xml_list = artists_xml_data.SelectNodes("/similarartists/artist");

                // Cache artists images (here in the spawned thread)
                for (int i = 0; i < artists_xml_list.Count && i < NUM_MAX_ARTISTS; i++)
                {
                    string url = artists_xml_list [i].SelectSingleNode("image_small").InnerText;
                    DownloadContent(url, GetCachedPathFromUrl(url), true);
                }

                // Fetch data for top tracks
                XmlDocument tracks_xml_data = new XmlDocument();
                tracks_xml_data.LoadXml(RequestContent(String.Format(AUDIOSCROBBLER_TOP_TRACKS_URL, artist)));
                XmlNodeList tracks_xml_list = tracks_xml_data.SelectNodes("/mostknowntracks/track");

                // Try to match top tracks with the users's library
                for (int i = 0; i < tracks_xml_list.Count && i < NUM_TRACKS; i++)
                {
                    string track_name = tracks_xml_list [i].SelectSingleNode("name").InnerText;
                    int track_id      = GetTrackId(artist, track_name);

                    if (track_id == -1)
                    {
                        continue;
                    }

                    XmlNode track_id_node   = tracks_xml_list [i].OwnerDocument.CreateNode(XmlNodeType.Element, "track_id", null);
                    track_id_node.InnerText = track_id.ToString();

                    tracks_xml_list [i].AppendChild(track_id_node);
                }

                // Fetch data for top albums
                XmlDocument albums_xml_data = new XmlDocument();
                albums_xml_data.LoadXml(RequestContent(String.Format(AUDIOSCROBBLER_TOP_ALBUMS_URL, artist)));
                XmlNodeList albums_xml_list = albums_xml_data.SelectNodes("/topalbums/album");

                if (artists_xml_list.Count < 1 && tracks_xml_list.Count < 1 && albums_xml_list.Count < 1)
                {
                    return;
                }

                ThreadAssist.ProxyToMain(delegate {
                    // Wipe the old recommendations here, we keep them around in case
                    // where the the artist is the same as the last song.
                    foreach (Widget child in similar_items_table.Children)
                    {
                        similar_items_table.Remove(child);
                    }
                    foreach (Widget child in tracks_items_box.Children)
                    {
                        tracks_items_box.Remove(child);
                    }
                    foreach (Widget child in albums_items_box.Children)
                    {
                        albums_items_box.Remove(child);
                    }

                    // Display recommendations and artist information
                    current_artist       = artist;
                    tracks_header.Markup = String.Format("<b>{0} {1}</b>", Catalog.GetString("Top Tracks by"), artist);
                    albums_header.Markup = String.Format("<b>{0} {1}</b>", Catalog.GetString("Top Albums by"), artist);

                    artists_widgets_list.Clear();
                    if (artists_xml_list != null)
                    {
                        for (int i = 0; i < artists_xml_list.Count && i < NUM_MAX_ARTISTS; i++)
                        {
                            artists_widgets_list.Add(RenderSimilarArtist(artists_xml_list [i]));
                        }

                        RenderSimilarArtists();
                    }

                    if (tracks_xml_list != null)
                    {
                        for (int i = 0; i < tracks_xml_list.Count && i < NUM_TRACKS; i++)
                        {
                            tracks_items_box.PackStart(RenderTrack(tracks_xml_list [i], i + 1), false, true, 0);
                        }
                    }

                    if (albums_xml_list != null)
                    {
                        for (int i = 0; i < albums_xml_list.Count && i < NUM_ALBUMS; i++)
                        {
                            albums_items_box.PackStart(RenderAlbum(albums_xml_list [i], i + 1), false, true, 0);
                        }
                    }

                    Visible = true;
                    ShowAll();
                });
            });
        }
Esempio n. 27
0
 public void LoadDeviceContents()
 {
     load_thread = ThreadAssist.Spawn(ThreadedLoadDeviceContents);
 }
Esempio n. 28
0
        protected override void OnResponse(ResponseType response)
        {
            //int w = -1, h = -1;
            //dialog.GetSize (out w, out h);
            //Console.WriteLine ("w = {0}, h = {1}", w, h);

            QueryNode node = builder.QueryNode;

            if (node == null)
            {
                //Console.WriteLine ("Editor query is null");
            }
            else
            {
                //Console.WriteLine ("Editor query is: {0}", node.ToXml (BansheeQuery.FieldSet, true));
            }

            if (response == ResponseType.Ok)
            {
                string            name           = PlaylistName;
                QueryNode         condition_tree = Condition;
                QueryLimit        limit          = Limit;
                QueryOrder        order          = Order;
                IntegerQueryValue limit_value    = LimitValue;

                ThreadAssist.Spawn(delegate {
                    //Console.WriteLine ("Name = {0}, Cond = {1}, OrderAndLimit = {2}", name, condition, order_by, limit_number);
                    if (playlist == null)
                    {
                        playlist = new SmartPlaylistSource(name, primary_source);

                        playlist.ConditionTree = condition_tree;
                        playlist.QueryOrder    = order;
                        playlist.Limit         = limit;
                        playlist.LimitValue    = limit_value;

                        playlist.Save();
                        primary_source.AddChildSource(playlist);
                        playlist.RefreshAndReload();
                        //SmartPlaylistCore.Instance.StartTimer (playlist);
                    }
                    else
                    {
                        playlist.ConditionTree = condition_tree;
                        playlist.QueryOrder    = order;
                        playlist.LimitValue    = limit_value;
                        playlist.Limit         = limit;

                        playlist.Name = name;
                        playlist.Save();
                        playlist.RefreshAndReload();

                        /*if (playlist.TimeDependent)
                         *  SmartPlaylistCore.Instance.StartTimer (playlist);
                         * else
                         *  SmartPlaylistCore.Instance.StopTimer ();*/

                        //playlist.ListenToPlaylists ();
                        //SmartPlaylistCore.Instance.SortPlaylists ();
                    }
                });
            }

            currently_editing = null;
        }