Ejemplo n.º 1
0
        /// <summary>
        /// Show a select dialog in MediaPortal. After that, send the result to the sender.
        /// </summary>
        /// <param name="dialogId">Id of dialog</param>
        /// <param name="title">Dialog title</param>
        /// <param name="text">Dialog text</param>
        /// <param name="options">Options for the user to choose from</param>
        /// <param name="socketServer">Server</param>
        /// <param name="sender">Sender of the request</param>
        internal static void ShowSelectDialog(string dialogId, string title,  List<string> options, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                       MessageDialogResult result = new MessageDialogResult();
            result.DialogId = dialogId;
            result.YesNoResult = false;

            if (dlgMenu != null)
            {
                dlgMenu.Reset();
                dlgMenu.SetHeading(title);

                if (options != null)
                {
                    foreach (string o in options)
                    {
                        dlgMenu.Add(o);
                    }
                }

                dlgMenu.DoModal(GUIWindowManager.ActiveWindow);

                if (dlgMenu.SelectedId != -1)
                {
                    result.YesNoResult = true;
                    result.SelectedOption = dlgMenu.SelectedLabelText;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle a "showdialog" message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandleShowDialogMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            String dialogType = (String)message["DialogType"];
            String dialogId = (String)message["DialogId"];

            if (dialogType != null)
            {
                String title = (String)message["Title"];
                String text = (String)message["Text"];

                if (dialogType.Equals("yesno"))
                {
                    //show dialog in new thread so we don't block the tcp thread
                    new Thread(new ParameterizedThreadStart(ShowYesNoThreaded)).Start(new object[] { dialogId, title, text, socketServer, sender });
                }
                else if (dialogType.Equals("ok"))
                {
                    new Thread(new ParameterizedThreadStart(ShowOkDialogThreaded)).Start(new object[] { title, text });
                }
                else if (dialogType.Equals("yesnoselect"))
                {
                    List<String> options = new List<String>();
                    JArray array = (JArray)message["Options"];
                    if (array != null)
                    {
                        foreach (JValue v in array)
                        {
                            options.Add((string)v.Value);
                        }
                    }

                    //show dialog in new thread so we don't block the tcp thread
                    new Thread(new ParameterizedThreadStart(ShowYesNoThenSelectThreaded)).Start(new object[] { dialogId, title, text, options, socketServer, sender });
                }
                else if (dialogType.Equals("select"))
                {
                    List<String> options = new List<String>();
                    JArray array = (JArray)message["Options"];
                    if (array != null)
                    {
                        foreach (JValue v in array)
                        {
                            options.Add((string)v.Value);
                        }
                    }

                    //show dialog in new thread so we don't block the tcp thread
                    new Thread(new ParameterizedThreadStart(ShowSelectThreaded)).Start(new object[] { dialogId, title, options, socketServer, sender });
                }
                else
                {
                    WifiRemote.LogMessage("Dialog type " + dialogType + " not supported yet", WifiRemote.LogType.Warn);
                }
            }
            else
            {
                WifiRemote.LogMessage("No dialog type specified", WifiRemote.LogType.Warn);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Show a yes no dialog in MediaPortal and send the result to the sender
        /// </summary>
        /// <param name="dialogId">Id of dialog</param>
        /// <param name="title">Dialog title</param>
        /// <param name="text">Dialog text</param>
        /// <param name="socketServer">Server</param>
        /// <param name="sender">Sender of the request</param>
        internal static void ShowYesNoDialog(string dialogId, string title, string text, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(title);
                dlg.SetLine(1, text);
                dlg.DoModal(GUIWindowManager.ActiveWindow);

                MessageDialogResult result = new MessageDialogResult();
                result.YesNoResult = dlg.IsConfirmed;
                result.DialogId = dialogId;

                socketServer.SendMessageToClient(result, sender);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle an MpExtended message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandleMpExtendedMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            string itemId = (string)message["ItemId"];
            int itemType = (int)message["MediaType"];
            int providerId = (int)message["ProviderId"];
            String action = (String)message["Action"];
            Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(message["PlayInfo"].ToString());
            int startPos = (message["StartPosition"] != null) ? (int)message["StartPosition"] : 0;

            if (action != null)
            {
                if (action.Equals("play"))
                {
                    //play the item in MediaPortal
                    WifiRemote.LogMessage("play mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);
                    MpExtendedHelper.PlayMediaItem(itemId, itemType, providerId, values, startPos);
                }
                else if (action.Equals("show"))
                {
                    //show the item details in mediaportal (without starting playback)
                    WifiRemote.LogMessage("play mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);

                    MpExtendedHelper.ShowMediaItem(itemId, itemType, providerId, values);
                }
                else if (action.Equals("enqueue"))
                {
                    //enqueue the mpextended item to the currently active playlist
                    WifiRemote.LogMessage("enqueue mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);

                    int startIndex = (message["StartIndex"] != null) ? (int)message["StartIndex"] : -1;

                    PlayListType playlistType = PlayListType.PLAYLIST_VIDEO;
                    List<PlayListItem> items = MpExtendedHelper.CreatePlayListItemItem(itemId, itemType, providerId, values, out playlistType);

                    PlaylistHelper.AddPlaylistItems(playlistType, items, startIndex);
                }
            }
            else
            {
                WifiRemote.LogMessage("No MpExtended action defined", WifiRemote.LogType.Warn);
            }
        }
        /// <summary>
        /// Handle an MovingPictures message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandleMovingPicturesMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            string action = (string)message["Action"];

            if (!string.IsNullOrEmpty(action))
            {
                // Show movie details for this movie
                if (action == "moviedetails")
                {
                    string movieName = (string)message["MovieName"];
                    if (!string.IsNullOrEmpty(movieName))
                    {
                        int movieId = MovingPicturesHelper.GetMovieIdByName(movieName);
                        MovingPicturesHelper.ShowMovieDetails(movieId);
                    }
                }
                // Play a movie with MovingPictures
                else if (action == "playmovie")
                {
                    int movieId = (message["MovieId"] != null) ? (int)message["MovieId"] : -1;
                    string movieName = (string)message["MovieName"];
                    bool resume = (message["AskToResume"] != null) ? (bool)message["AskToResume"] : true;
                    int startPos = (message["StartPosition"] != null) ? (int)message["StartPosition"] : 0;

                    // Play by movie id
                    if (movieId != -1)
                    {
                        MovingPicturesHelper.PlayMovie(movieId, resume, startPos);
                    }
                    else if (!string.IsNullOrEmpty(movieName))
                    {
                        // Play by name
                        MovingPicturesHelper.PlayMovie(movieName, resume, startPos);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Show a yes/no dialog and if the user accepts, show a select dialog. After that, send the result to the sender.
        /// </summary>
        /// <param name="dialogId">Id of dialog</param>
        /// <param name="title">Dialog title</param>
        /// <param name="text">Dialog text</param>
        /// <param name="options">Options for the user to choose from</param>
        /// <param name="socketServer">Server</param>
        /// <param name="sender">Sender of the request</param>
        internal static void ShowYesNoThenSelectDialog(string dialogId, string title, string text, List<string> options, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
            MessageDialogResult result = new MessageDialogResult();
            result.DialogId = dialogId;
            result.YesNoResult = false;

            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(title);
                dlg.SetLine(1, text);
                dlg.DoModal(GUIWindowManager.ActiveWindow);
            }

            if (dlg.IsConfirmed && options != null && options.Count > 0)
            {
                if (options.Count == 1)
                {
                    //only one option, no need to show select dialog
                    result.SelectedOption = options[0];
                    result.YesNoResult = true;
                }
                else
                {
                    //multiple options available, show select menu to user
                    GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                    if (dlgMenu != null)
                    {
                        dlgMenu.Reset();

                        dlgMenu.SetHeading(title);

                        if (options != null)
                        {
                            foreach (string o in options)
                            {
                                dlgMenu.Add(o);
                            }
                        }

                        //dlg.SetLine(1, text);
                        dlgMenu.DoModal(GUIWindowManager.ActiveWindow);

                        if (dlgMenu.SelectedId != -1)
                        {
                            result.YesNoResult = true;
                            result.SelectedOption = dlgMenu.SelectedLabelText;
                        }
                    }
                }
            }

            socketServer.SendMessageToClient(result, sender);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handle an Playlist message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandlePlaylistMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            String action = (string)message["PlaylistAction"];
            String playlistType = (message["PlaylistType"] != null) ? (string)message["PlaylistType"] : "music";
            bool shuffle = (message["Shuffle"] != null) ? (bool)message["Shuffle"] : false;
            bool autoPlay = (message["AutoPlay"] != null) ? (bool)message["AutoPlay"] : false;
            bool showPlaylist = (message["ShowPlaylist"] != null) ? (bool)message["ShowPlaylist"] : true;

            if (action.Equals("new") || action.Equals("append"))
            {
                //new playlist or append to playlist
                int insertIndex = 0;
                if (message["InsertIndex"] != null)
                {
                    insertIndex = (int)message["InsertIndex"];
                }

                // Add items from JSON or SQL
                JArray array = (message["PlaylistItems"] != null) ? (JArray)message["PlaylistItems"] : null;
                JObject sql = (message["PlayListSQL"] != null) ? (JObject)message["PlayListSQL"] : null;
                if (array != null || sql != null)
                {
                    if (action.Equals("new"))
                    {
                        PlaylistHelper.ClearPlaylist(playlistType, false);
                    }

                    int index = insertIndex;

                    if (array != null)
                    {
                        // Add items from JSON
                        foreach (JObject o in array)
                        {
                            PlaylistEntry entry = new PlaylistEntry();
                            entry.FileName = (o["FileName"] != null) ? (string)o["FileName"] : null;
                            entry.Name = (o["Name"] != null) ? (string)o["Name"] : null;
                            entry.Duration = (o["Duration"] != null) ? (int)o["Duration"] : 0;
                            PlaylistHelper.AddItemToPlaylist(playlistType, entry, index, false);
                            index++;
                        }
                        PlaylistHelper.RefreshPlaylistIfVisible();

                        if (shuffle)
                        {
                            PlaylistHelper.Shuffle(playlistType);
                        }
                    }
                    else
                    {
                        // Add items with SQL
                        string where = (sql["Where"] != null) ? (string)sql["Where"] : String.Empty;
                        int limit = (sql["Limit"] != null) ? (int)sql["Limit"] : 0;

                        PlaylistHelper.AddSongsToPlaylistWithSQL(playlistType, where, limit, shuffle, insertIndex);
                    }

                    if (autoPlay)
                    {
                        if (message["StartPosition"] != null)
                        {
                            int startPos = (int)message["StartPosition"];
                            insertIndex += startPos;
                        }
                        PlaylistHelper.StartPlayingPlaylist(playlistType, insertIndex, showPlaylist);
                    }
                }
            }
            else if (action.Equals("load"))
            {
                //load a playlist
                string playlistName = (string)message["PlayListName"];
                string playlistPath = (string)message["PlaylistPath"];

                if (!string.IsNullOrEmpty(playlistName) || !string.IsNullOrEmpty(playlistPath))
                {
                    PlaylistHelper.LoadPlaylist(playlistType, (!string.IsNullOrEmpty(playlistName)) ? playlistName : playlistPath, shuffle);
                    if (autoPlay)
                    {
                        PlaylistHelper.StartPlayingPlaylist(playlistType, 0, showPlaylist);
                    }
                }
            }
            else if (action.Equals("get"))
            {
                //get all playlist items of the currently active playlist
                List<PlaylistEntry> items = PlaylistHelper.GetPlaylistItems(playlistType);

                MessagePlaylistDetails returnPlaylist = new MessagePlaylistDetails();
                returnPlaylist.PlaylistType = playlistType;
                returnPlaylist.PlaylistItems = items;

                socketServer.SendMessageToClient(returnPlaylist, sender);
            }
            else if (action.Equals("remove"))
            {
                //remove an item from the playlist
                int indexToRemove = (message["Index"] != null) ? (int)message["Index"] : 0;

                PlaylistHelper.RemoveItemFromPlaylist(playlistType, indexToRemove);
            }
            else if (action.Equals("move"))
            {
                //move a playlist item to a new index
                int oldIndex = (message["OldIndex"] != null) ? (int)message["OldIndex"] : 0;
                int newIndex = (message["NewIndex"] != null) ? (int)message["NewIndex"] : 0;
                PlaylistHelper.ChangePlaylistItemPosition(playlistType, oldIndex, newIndex);
            }
            else if (action.Equals("play"))
            {
                //start playback of a playlist item
                int index = (message["Index"] != null) ? (int)message["Index"] : 0;
                PlaylistHelper.StartPlayingPlaylist(playlistType, index, showPlaylist);
            }
            else if (action.Equals("clear"))
            {
                //clear the playlist
                PlaylistHelper.ClearPlaylist(playlistType, true);
            }
            else if (action.Equals("list"))
            {
                //get a list of all available playlists
                MessagePlaylists returnList = new MessagePlaylists();
                returnList.PlayLists = PlaylistHelper.GetPlaylists();
                socketServer.SendMessageToClient(returnList, sender);
            }
            else if (action.Equals("save"))
            {
                //save the current playlist to file
                String name = (message["Name"] != null) ? (String)message["Name"] : null;
                if (name != null)
                {
                    PlaylistHelper.SaveCurrentPlaylist(name);
                }
                else
                {
                    WifiRemote.LogMessage("Must specify a name to save a playlist", WifiRemote.LogType.Warn);
                }

            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handle an MPTvSeries message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandleTvSeriesMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            string action = (string)message["Action"];

            if (!string.IsNullOrEmpty(action))
            {
                // A series id is needed for the following actions.
                // If a series id was supplied we use this, otherwise we
                // try to get an id by the series name.
                //
                // If this isn't successful we do nothing.
                int? seriesId = (int?)message["SeriesId"];
                string seriesName = (string)message["SeriesName"];
                bool resume = (message["AskToResume"] != null) ? (bool)message["AskToResume"] : true;

                // Get series id by show name if no id supplied
                if (seriesId == null && !string.IsNullOrEmpty(seriesName))
                {
                    seriesId = TVSeriesHelper.GetSeriesIdByName(seriesName);
                }

                if (seriesId != null)
                {
                    // Play specific episode of series
                    if (action == "playepisode")
                    {
                        int? season = (int?)message["SeasonNumber"];
                        int? episode = (int?)message["EpisodeNumber"];
                        int startPos = (message["StartPosition"] != null) ? (int)message["StartPosition"] : 0;

                        if (season != null && episode != null)
                        {
                            TVSeriesHelper.Play((int)seriesId, (int)season, (int)episode, resume, startPos);
                        }
                    }
                    // Show movie details for this movie
                    else if (action == "seriesdetails")
                    {
                        TVSeriesHelper.ShowSeriesDetails((int)seriesId);
                    }
                    // Play first unwatched or last added episode of a series
                    else if (action == "playunwatchedepisode")
                    {
                        TVSeriesHelper.PlayFirstUnwatchedEpisode((int)seriesId, resume);
                    }
                    // Play random episode of a series
                    else if (action == "playrandomepisode")
                    {
                        TVSeriesHelper.PlayRandomEpisode((int)seriesId, resume);
                    }
                    // Play all episodes of a season
                    else if (action == "playseason")
                    {
                        int? season = (int?)message["SeasonNumber"];
                        bool onlyUnwatched = (message["OnlyUnwatchedEpisodes"] != null) ? (bool)message["OnlyUnwatchedEpisodes"] : false;
                        int startIndex = (message["StartIndex"] != null) ? (int)message["StartIndex"] : 0;
                        bool switchToPlaylistView = (message["SwitchToPlaylist"] != null) ? (bool)message["SwitchToPlaylist"] : true;
                        bool startAutomatically = (message["AutoStart"] != null) ? (bool)message["AutoStart"] : true;
                        if (season != null)
                        {
                            TVSeriesHelper.PlaySeason((int)seriesId, (int)season, startAutomatically, startIndex, onlyUnwatched, switchToPlaylistView);
                        }
                    }
                    // Play all episodes of a series
                    else if (action == "playseries")
                    {
                        bool onlyUnwatched = (message["OnlyUnwatchedEpisodes"] != null) ? (bool)message["OnlyUnwatchedEpisodes"] : false;
                        int startIndex = (message["StartIndex"] != null) ? (int)message["StartIndex"] : 0;
                        bool switchToPlaylistView = (message["SwitchToPlaylist"] != null) ? (bool)message["SwitchToPlaylist"] : true;
                        bool startAutomatically = (message["AutoStart"] != null) ? (bool)message["AutoStart"] : true;

                        TVSeriesHelper.PlaySeries((int)seriesId, startAutomatically, startIndex, onlyUnwatched, switchToPlaylistView);
                    }
                }
            }
        }