Ejemplo n.º 1
0
        //called from EpisodeResultsWidget when an episode is selected
        //it shows a loading screen and then starts a task to load the sources
        //when its done loading it clears the container and adds the new embeddedWidget
        public void episodeSelected(Episode episode)
        {
            showLoadingScreen("Loading Episode " + episode.num.ToString() + ". " + episode.title);

            //make a new CancellationSource for a new task
            loadingResultsCancellationSource = new CancellationTokenSource();
            var cancelToken = loadingResultsCancellationSource.Token;

            //Create the task that gets the results from guidebox
            Task task = new Task(() => {
                cancelToken.ThrowIfCancellationRequested();

                //get the results from guidebox
                Dictionary <string, List <string> > sources = GuideBoxAPIWrapper.getEpisodeLinks(episode.id);

                cancelToken.ThrowIfCancellationRequested();

                //show the results
                Gtk.Application.Invoke(delegate {
                    embeddedWidget = new SourcesWidget(this, episode.desc, episode.thumb, sources, activeSource);

                    addEmbeddedWidgetToContainer();
                });
            }, cancelToken);

            //create the delegate to handle exceptions
            task.ContinueWith((t) => {
                Gtk.Application.Invoke(delegate {
                    outputError(t.Exception.InnerException.Message);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Ejemplo n.º 2
0
        //called from SeasonResultsWidget when a season is selected
        //it shows a loading screen and then starts a task to load the episodes
        //when its done loading it clears the container and adds the new embeddedWidget
        public void seasonSelected(Show show, int s)
        {
            showLoadingScreen("Loading Season " + (s + 1).ToString() + " of " + show.title);

            //make a new CancellationSource for a new task
            loadingResultsCancellationSource = new CancellationTokenSource();
            var cancelToken = loadingResultsCancellationSource.Token;

            //Create the task that gets the results from guidebox
            Task task = new Task(() => {
                cancelToken.ThrowIfCancellationRequested();

                //get the results from guidebox
                Season season   = new Season(s.ToString());
                season.episodes = GuideBoxAPIWrapper.getTVShowEpisodes(show.id, (s + 1).ToString());

                cancelToken.ThrowIfCancellationRequested();

                //populate the thumbnails
                foreach (var ep in season.episodes)
                {
                    byte[] thumbNail = getThumbNail(ep.thumbURL);
                    if (thumbNail != null)
                    {
                        ep.thumb = new Gdk.Pixbuf(thumbNail);
                    }
                }

                cancelToken.ThrowIfCancellationRequested();

                //show the results
                Gtk.Application.Invoke(delegate {
                    if (season.episodes.Count == 0)
                    {
                        outputError("No available episodes");
                        return;
                    }
                    embeddedWidget = new EpisodeResultsWidget(this, season, 0);
                    addEmbeddedWidgetToContainer();
                });
            }, cancelToken);

            //create the delegate to handle exceptions
            task.ContinueWith((t) => {
                Gtk.Application.Invoke(delegate {
                    outputError(t.Exception.InnerException.Message);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Ejemplo n.º 3
0
        //called from ShowResultsWidget when a show is selected
        //it shows a loading screen and then starts a task to load the seasons (or sources if its a movie)
        //when its done loading it clears the container and adds the new embeddedWidget
        public void showSelected(Show show)
        {
            showLoadingScreen("Loading " + show.title);

            //make a new CancellationSource for a new task
            loadingResultsCancellationSource = new CancellationTokenSource();
            var cancelToken = loadingResultsCancellationSource.Token;

            //Create the task that gets the results from guidebox
            Task task = new Task(() => {
                cancelToken.ThrowIfCancellationRequested();
                if (show.isMovie)
                {
                    //get the results from guidebox
                    Dictionary <string, List <string> > sources = GuideBoxAPIWrapper.getMovieLinks(show.id);

                    cancelToken.ThrowIfCancellationRequested();

                    //show the results
                    Gtk.Application.Invoke(delegate {
                        embeddedWidget = new SourcesWidget(this, show.desc, show.thumb, sources, activeSource);
                        addEmbeddedWidgetToContainer();
                    });
                }
                else
                {
                    //get the results from guidebox
                    show.numOfSeasons = GuideBoxAPIWrapper.getTVShowSeasons(show.id);

                    cancelToken.ThrowIfCancellationRequested();

                    //show the results
                    Gtk.Application.Invoke(delegate {
                        embeddedWidget = new SeasonResultsWidget(this, show, 0);
                        addEmbeddedWidgetToContainer();
                    });
                }
            }, cancelToken);

            //create the delegate to handle exceptions
            task.ContinueWith((t) => {
                Gtk.Application.Invoke(delegate {
                    outputError(t.Exception.InnerException.Message);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Ejemplo n.º 4
0
        //Event handler for clicking the back button
        //first it cancels any task that might be running
        //then it removes whatever is in the container
        //and pops from the stack and adds it to the container
        protected void OnBackButtonClicked(object sender, EventArgs e)
        {
            //cancel any task that might be running
            loadingResultsCancellationSource.Cancel();

            if (previousWidgets.Count != 0)
            {
                if (container.Children.Length == 3)
                {
                    container.Remove(container.Children[2]);
                }

                embeddedWidget = previousWidgets.Pop();

                updateBackButton();

                container.PackStart(embeddedWidget);
            }
        }
Ejemplo n.º 5
0
        //Event handler for clicking the search button
        //shows a loading screen and then creates a task to load the results
        //and display them
        protected void OnSearchButtonClicked(object sender, EventArgs e)
        {
            string searchText = searchEntry.Text.Trim();

            if (searchText == null || searchText == "")
            {
                return;
            }

            //cancel any task that might be running
            loadingResultsCancellationSource.Cancel();

            string msg = "";

            if (showRadioButton.Active)
            {
                msg = "Searching Shows for " + searchText;
            }
            else
            {
                msg = "Searching Movies for " + searchText;
            }
            showLoadingScreen(msg);

            //make a new CancellationSource for a new task
            loadingResultsCancellationSource = new CancellationTokenSource();
            var cancelToken = loadingResultsCancellationSource.Token;

            //Create the task that gets the results from guidebox
            Task task = new Task(() => {
                cancelToken.ThrowIfCancellationRequested();
                List <Show> shows = new List <Show>();

                //tv
                if (showRadioButton.Active)
                {
                    //get the results from guidebox
                    shows = GuideBoxAPIWrapper.getTVShowIds(searchText);

                    cancelToken.ThrowIfCancellationRequested();

                    //populate the thumbnails
                    foreach (var show in shows)
                    {
                        byte[] thumbNail = getThumbNail(show.thumbURL);
                        if (thumbNail != null)
                        {
                            show.thumb = new Gdk.Pixbuf(thumbNail);
                        }
                    }
                }

                //movies
                else
                {
                    //get the results from guidebox
                    shows = GuideBoxAPIWrapper.getMovieIds(searchText);

                    cancelToken.ThrowIfCancellationRequested();

                    //populate the thumbnails
                    foreach (var show in shows)
                    {
                        byte[] thumbNail = getThumbNail(show.thumbURL);
                        if (thumbNail != null)
                        {
                            show.thumb = new Gdk.Pixbuf(thumbNail);
                        }
                    }
                }

                cancelToken.ThrowIfCancellationRequested();

                //show the results
                Gtk.Application.Invoke(delegate {
                    embeddedWidget = new ShowResultsWidget(this, shows, 0, true);
                    addEmbeddedWidgetToContainer();
                });
            }, cancelToken);


            //create the delegate to handle exceptions
            task.ContinueWith((t) => {
                Gtk.Application.Invoke(delegate {
                    outputError(t.Exception.InnerException.Message);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Ejemplo n.º 6
0
        //starts a task to load most popular shows or movies from guidebox
        //then it loads the embeddedWidget
        protected void getPopShows(int start)
        {
            //make a new CancellationSource for a new task
            loadingResultsCancellationSource = new CancellationTokenSource();
            var cancelToken = loadingResultsCancellationSource.Token;

            //Create the task that gets the results from guidebox
            Task task = new Task(() => {
                cancelToken.ThrowIfCancellationRequested();
                List <Show> shows = new List <Show>();

                //tv
                if (showRadioButton.Active)
                {
                    //get the results from guidebox
                    shows = GuideBoxAPIWrapper.getTVShowIds(start, maxShowsInEmbeddedWidget, activeSource);

                    cancelToken.ThrowIfCancellationRequested();

                    //populate the thumbnails
                    foreach (var show in shows)
                    {
                        byte[] thumbNail = getThumbNail(show.thumbURL);
                        if (thumbNail != null)
                        {
                            show.thumb = new Gdk.Pixbuf(thumbNail);
                        }
                    }
                }

                //movies
                else
                {
                    //get the results from guidebox
                    shows = GuideBoxAPIWrapper.getMovieIds(start, maxShowsInEmbeddedWidget, activeSource);

                    cancelToken.ThrowIfCancellationRequested();

                    //populate the thumbnails
                    foreach (var show in shows)
                    {
                        byte[] thumbNail = getThumbNail(show.thumbURL);
                        if (thumbNail != null)
                        {
                            show.thumb = new Gdk.Pixbuf(thumbNail);
                        }
                    }
                }
                cancelToken.ThrowIfCancellationRequested();

                //show the results
                Gtk.Application.Invoke(delegate {
                    embeddedWidget = new ShowResultsWidget(this, shows, start, false);
                    addEmbeddedWidgetToContainer();
                });
            }, cancelToken);

            //create the delegate to handle exceptions
            task.ContinueWith((t) => {
                Gtk.Application.Invoke(delegate {
                    outputError(t.Exception.InnerException.Message);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Ejemplo n.º 7
0
 //called from the embeddedWidget whenever the loadmore button is clicked
 public void loadMoreResults(EmbeddedWidget result)
 {
     clearContainer();
     embeddedWidget = result;
     this.container.PackStart(embeddedWidget);
 }