Ejemplo n.º 1
0
        /// <summary>
        /// Shutdown/hibernate/reboot the htpc or exit mediaportal
        /// </summary>
        /// <param name="shutdownType">logoff|suspend|hibernate|reboot|shutdown|exit</param>
        public void SetPowerMode(String powerMode)
        {
            switch (powerMode.ToLower())
            {
            case "logoff":
                WindowsController.ExitWindows(RestartOptions.LogOff, true);
                break;

            case "suspend":
                WindowsController.ExitWindows(RestartOptions.Suspend, true);
                break;

            case "hibernate":
                WindowsController.ExitWindows(RestartOptions.Hibernate, true);
                break;

            case "reboot":
                WindowsController.ExitWindows(RestartOptions.Reboot, true);
                break;

            case "shutdown":
                WindowsController.ExitWindows(RestartOptions.ShutDown, true);
                break;

            case "exit":
                MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action(MediaPortal.GUI.Library.Action.ActionType.ACTION_EXIT, 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send a MediaPortal action.
        /// </summary>
        /// <param name="command">The command.</param>
        public static void ProcessSendMediaPortalAction(string[] command)
        {
            Action.ActionType type = (Action.ActionType)Enum.Parse(typeof(Action.ActionType), command[0], true);
            float             f1   = float.Parse(command[1]);
            float             f2   = float.Parse(command[2]);

            Action action = new Action(type, f1, f2);

            GUIGraphicsContext.OnAction(action);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute this command.
        /// </summary>
        /// <param name="variables">The variable list of the calling code.</param>
        public override void Execute(VariableList variables)
        {
            string[] processed = ProcessParameters(variables, Parameters);

            Action.ActionType type = (Action.ActionType)Enum.Parse(typeof(Action.ActionType), processed[0]);
            float             f1   = float.Parse(processed[1]);
            float             f2   = float.Parse(processed[2]);

            Action action = new Action(type, f1, f2);

            GUIGraphicsContext.OnAction(action);
        }
Ejemplo n.º 4
0
 void airplayServer_PlaybackRateChanged(object sender, PlaybackRateEventArgs e)
 {
     invoke(delegate()
     {
         if (isVideoPlaying)
         {
             if ((e.Rate > 0 && g_Player.Paused) || (e.Rate == 0 && !g_Player.Paused))
             {
                 MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action();
                 action.wID = g_Player.Paused ? MediaPortal.GUI.Library.Action.ActionType.ACTION_PLAY : MediaPortal.GUI.Library.Action.ActionType.ACTION_PAUSE;
                 GUIGraphicsContext.OnAction(action);
             }
         }
     }, false);
 }
Ejemplo n.º 5
0
        private void DoOnEnded(g_Player.MediaType type, string filename)
        {
            if (GUIWindowManager.ActiveWindow == GetID)
            {
                Log.Debug("GUIMusicPlayingNow: g_Player_PlayBackEnded for {0}", filename);

                if (!g_Player.Playing && NextTrackTag == null)
                {
                    Log.Debug("GUIMusicPlayingNow: All playlist items played - returning to previous window");
                    Action action = new Action();
                    action.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
                    GUIGraphicsContext.OnAction(action);
                }
            }
        }
Ejemplo n.º 6
0
        private void OnPlayBackStopped(g_Player.MediaType type, int stoptime, string filename)
        {
            if (!ControlsInitialized || type != g_Player.MediaType.Music)
            {
                return;
            }

            if (GUIWindowManager.ActiveWindow == GetID)
            {
                Log.Debug("GUIMusicPlayingNow: g_Player_PlayBackStopped for {0} - stoptime: {1}", filename, stoptime);
                Action action = new Action();
                action.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
                GUIGraphicsContext.OnAction(action);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Make MediaPortal take a screenshot, take that and delete it
        /// from disk. First we need to check if the screenshot folder already exists.
        /// See https://github.com/MediaPortal/MediaPortal-1/blob/cae80bd6dd2241bd7182c39418373bee545bf464/mediaportal/MediaPortal.Application/MediaPortal.cs#L3611
        /// </summary>
        public void TakeScreenshot()
        {
            // Only take one screenshot at a time, all requests
            // will be served from that screenshot.
            if (takingScreenshot)
            {
                return;
            }

            takingScreenshot = true;

            // MediaPortal doesn't output events for new screenshots so we 'manually'
            // watch the screenshot folder
            setupFileSystemWatcher();

            if (watcher == null)
            {
                // Something went wrong creating the filesystem watcher
                takingScreenshot = false;
                OnScreenshotFailed(new ImageHelperError(ImageHelperError.ImageHelperErrorType.WatcherCreate));
                return;
            }

            if (!watcher.EnableRaisingEvents)
            {
                try
                {
                    watcher.EnableRaisingEvents = true;
                }
                catch (Exception e)
                {
                    WifiRemote.LogMessage(String.Format("Could not watch the screenshots folder: {0}", e.Message), WifiRemote.LogType.Error);
                    watcher          = null;
                    takingScreenshot = false;
                    OnScreenshotFailed(new ImageHelperError(ImageHelperError.ImageHelperErrorType.WatcherEnable));
                    return;
                }
            }

            // Take the screenshot
            MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action(MediaPortal.GUI.Library.Action.ActionType.ACTION_TAKE_SCREENSHOT, 0, 0);
            GUIGraphicsContext.OnAction(action);
        }
Ejemplo n.º 8
0
        public override void OnAction(Action action)
        {
            base.OnAction(action);
            GUIMessage message;

            if (Focus)
            {
                if (action.wID == Action.ActionType.ACTION_MOUSE_CLICK || action.wID == Action.ActionType.ACTION_SELECT_ITEM)
                {
                    // If this button corresponds to an action generate that action.
                    if (ActionID >= 0)
                    {
                        Action newaction = new Action((Action.ActionType)ActionID, 0, 0);
                        GUIGraphicsContext.OnAction(newaction);
                        return;
                    }

                    message = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null);
                    GUIGraphicsContext.SendMessage(message);
                }
            }
        }
Ejemplo n.º 9
0
    public override void OnAction(Action action)
    {
      base.OnAction(action);
      switch (action.wID)
      {
          case Action.ActionType.ACTION_STOP:

          if (GUIWindowManager.ActiveWindow == GetID && !_isStopped)
          {
            _isStopped = true;
            Action act = new Action();
            act.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
            GUIGraphicsContext.OnAction(act);
          }
          break;
          // Since a ACTION_STOP action clears the player and CurrentPlaylistType type
          // we need a way to restart playback after an ACTION_STOP has been received
        case Action.ActionType.ACTION_MUSIC_PLAY:
        case Action.ActionType.ACTION_NEXT_ITEM:
        case Action.ActionType.ACTION_PAUSE:
        case Action.ActionType.ACTION_PREV_ITEM:
          if ((PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC) &&
              (PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_TEMP) &&
              (PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_LAST_FM))
          {
            LoadAndStartPlayList();
          }
          break;

        case Action.ActionType.ACTION_SHOW_INFO:
          FlipPictures();
          break;

        case Action.ActionType.ACTION_KEY_PRESSED:
          switch (action.m_key.KeyChar)
          {
            case (int)Keys.D0:
              UpdateCurrentTrackRating(0);
              break;
            case (int)Keys.D1:
              UpdateCurrentTrackRating(1);
              break;
            case (int)Keys.D2:
              UpdateCurrentTrackRating(2);
              break;
            case (int)Keys.D3:
              UpdateCurrentTrackRating(3);
              break;
            case (int)Keys.D4:
              UpdateCurrentTrackRating(4);
              break;
            case (int)Keys.D5:
              UpdateCurrentTrackRating(5);
              break;
              // do not act on _every_ key
              //default:
              //  UpdateCurrentTrackRating(-1);
              //  break;
          }
          break;
      }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// OnAction() method. This method gets called when there's a new action like a
        /// keypress or mousemove or... By overriding this method, the control can respond
        /// to any action
        /// </summary>
        /// <param name="action">action : contains the action</param>
        public override void OnAction(Action action)
        {
            base.OnAction(action);
            if (Focus)
            {
                if (action.wID == Action.ActionType.ACTION_MOUSE_CLICK || action.wID == Action.ActionType.ACTION_SELECT_ITEM)
                {
                    // If this button does not have a "selected" setting then toggle the value.  The value of _selected (when used) is
                    // determined and set in each render pass based on a condition (value of a property or skin setting).
                    if (_selected.Length == 0)
                    {
                        Selected = !Selected;
                    }

                    // send a message to anyone interested
                    var message = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null);
                    GUIGraphicsContext.SendMessage(message);

                    // If this button has a click setting then execute the setting.
                    if (_onclick.Length != 0)
                    {
                        GUIPropertyManager.Parse(_onclick, GUIExpressionManager.ExpressionOptions.EVALUATE_ALWAYS);
                    }

                    // If this button contains scriptactions call the scriptactions.
                    if (_application.Length != 0)
                    {
                        //button should start an external application, so start it
                        var proc = new Process();

                        string strWorkingDir = Path.GetFullPath(_application);
                        string strFileName   = Path.GetFileName(_application);
                        if (strFileName != null)
                        {
                            strWorkingDir           = strWorkingDir.Substring(0, strWorkingDir.Length - (strFileName.Length + 1));
                            proc.StartInfo.FileName = strFileName;
                        }
                        proc.StartInfo.WorkingDirectory = strWorkingDir;
                        proc.StartInfo.Arguments        = _arguments;
                        proc.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
                        proc.StartInfo.CreateNoWindow   = true;
                        proc.Start();
                        //proc.WaitForExit();
                    }

                    // If this links to another window go to the window.
                    if (_hyperLinkWindowId >= 0)
                    {
                        GUIWindowManager.ActivateWindow(_hyperLinkWindowId);
                        return;
                    }
                    // If this button corresponds to an action generate that action.
                    if (ActionID >= 0)
                    {
                        var newaction = new Action((Action.ActionType)ActionID, 0, 0);
                        GUIGraphicsContext.OnAction(newaction);
                        return;
                    }

                    // button selected.
                    if (SubItemCount > 0)
                    {
                        // if we got subitems, then change the label of the control to the next
                        //subitem
                        SelectedItem++;
                        if (SelectedItem >= SubItemCount)
                        {
                            SelectedItem = 0;
                        }
                        Label = (string)GetSubItem(SelectedItem);
                    }
                }
            }
        }
        public override void OnAction(Action action)
        {
            switch (action.wID)
            {
            case Action.ActionType.ACTION_MOVE_DOWN:
            case Action.ActionType.ACTION_MOVE_UP:
            {
                GUIPlayListButtonControl.SuppressActiveButtonReset = false;
                break;
            }

            case Action.ActionType.ACTION_MOUSE_CLICK:
            case Action.ActionType.ACTION_SELECT_ITEM:
            {
                GUIPlayListButtonControl btn = (GUIPlayListButtonControl)_listButtons[_cursorX];

                if (btn != null)
                {
                    Action newAction = new Action();

                    if (btn.CurrentActiveButton == GUIPlayListButtonControl.ActiveButton.Up)
                    {
                        if (btn.UpButtonEnabled)
                        {
                            newAction.wID = Action.ActionType.ACTION_MOVE_SELECTED_ITEM_UP;
                            GUIPlayListButtonControl.LastActiveButton          = GUIPlayListButtonControl.ActiveButton.Up;
                            GUIPlayListButtonControl.SuppressActiveButtonReset = true;
                        }

                        else
                        {
                            return;
                        }
                    }

                    else if (btn.CurrentActiveButton == GUIPlayListButtonControl.ActiveButton.Down)
                    {
                        if (btn.DownButtonEnabled)
                        {
                            newAction.wID = Action.ActionType.ACTION_MOVE_SELECTED_ITEM_DOWN;
                            GUIPlayListButtonControl.LastActiveButton          = GUIPlayListButtonControl.ActiveButton.Down;
                            GUIPlayListButtonControl.SuppressActiveButtonReset = true;
                        }

                        else
                        {
                            return;
                        }
                    }

                    else if (btn.CurrentActiveButton == GUIPlayListButtonControl.ActiveButton.Delete)
                    {
                        if (btn.DownButtonEnabled)
                        {
                            newAction.wID = Action.ActionType.ACTION_DELETE_SELECTED_ITEM;
                            GUIPlayListButtonControl.LastActiveButton          = GUIPlayListButtonControl.ActiveButton.Delete;
                            GUIPlayListButtonControl.SuppressActiveButtonReset = true;
                        }

                        else
                        {
                            return;
                        }
                    }

                    else if (btn.CurrentActiveButton == GUIPlayListButtonControl.ActiveButton.Main)
                    {
                        GUIPlayListButtonControl.LastActiveButton          = GUIPlayListButtonControl.ActiveButton.None;
                        GUIPlayListButtonControl.SuppressActiveButtonReset = false;
                        break;
                    }

                    else
                    {
                        break;
                    }

                    GUIGraphicsContext.OnAction(newAction);
                    Console.WriteLine("\t**action modified:{0}", (Action.ActionType)newAction.wID);
                    return;
                }
                break;
            }
            }

            base.OnAction(action);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Evaluates the button number, gets its mapping and executes the action
        /// </summary>
        /// <param name="btnCode">Button code (ref: XML file)</param>
        /// <param name="processID">Process-ID for close/kill commands</param>
        private bool DoMapAction(string btnCode, int processID)
        {
            if (!_isLoaded) // No mapping loaded
            {
                Log.Info("Map: No button mapping loaded");
                return(false);
            }
            Mapping map = null;

            map = GetMapping(btnCode);
            if (map == null)
            {
                return(false);
            }
#if DEBUG
            Log.Info("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty);
#endif
            Action action;
            if (map.Sound != string.Empty)
            {
                Util.Utils.PlaySound(map.Sound, false, true);
            }
            if (map.Focus && !GUIGraphicsContext.HasFocus)
            {
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
                //GUIWindowManager.SendThreadMessage(msg);
                GUIGraphicsContext.SendMessage(msg);
                return(true);
            }
            switch (map.Command)
            {
            case "ACTION": // execute Action x
                Key key = new Key(map.CmdKeyChar, map.CmdKeyCode);
#if DEBUG
                Log.Info("Executing: key {0} / {1} / Action: {2} / {3}", map.CmdKeyChar, map.CmdKeyCode, map.CmdProperty,
                         ((Action.ActionType)Convert.ToInt32(map.CmdProperty)).ToString());
#endif
                action = new Action(key, (Action.ActionType)Convert.ToInt32(map.CmdProperty), 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;

            case "KEY": // send Key x
                SendKeys.SendWait(map.CmdProperty);
                break;

            case "WINDOW": // activate Window x
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg;
                if ((Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
                    (Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
                {
                    if (_basicHome)
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
                    }
                    else
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_HOME, 0, null);
                    }
                }
                else
                {
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, Convert.ToInt32(map.CmdProperty),
                                         0, null);
                }

                GUIWindowManager.SendThreadMessage(msg);
                break;

            case "TOGGLE": // toggle Layer 1/2
                if (_currentLayer == 1)
                {
                    _currentLayer = 2;
                }
                else
                {
                    _currentLayer = 1;
                }
                break;

            case "POWER": // power down commands

                if ((map.CmdProperty == "STANDBY") || (map.CmdProperty == "HIBERNATE"))
                {
                    GUIGraphicsContext.ResetLastActivity();
                }

                switch (map.CmdProperty)
                {
                case "EXIT":
                    action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "REBOOT":
                    action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "SHUTDOWN":
                    action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "STANDBY":
                    action = new Action(Action.ActionType.ACTION_SUSPEND, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "HIBERNATE":
                    action = new Action(Action.ActionType.ACTION_HIBERNATE, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;
                }
                break;

            case "PROCESS":
            {
                GUIGraphicsContext.ResetLastActivity();
                if (processID > 0)
                {
                    Process proc = Process.GetProcessById(processID);
                    if (null != proc)
                    {
                        switch (map.CmdProperty)
                        {
                        case "CLOSE":
                            proc.CloseMainWindow();
                            break;

                        case "KILL":
                            proc.Kill();
                            break;
                        }
                    }
                }
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
Ejemplo n.º 13
0
        private void Listener_XplMessageReceived(object sender, XplListener.XplEventArgs e)
        {
            if (e.XplMsg.Schema.msgClass.ToLower().Equals("hbeat") && e.XplMsg.Schema.msgType.ToLower().Equals("app"))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received HEARTBEAT");
                }
                this._IsConnected = true;
            }
            else if (e.XplMsg.Schema.msgClass.ToLower().Equals("config"))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received CONFIG message");
                }
            }
            else if ((e.XplMsg.Source.Vendor.ToLower().Equals(this.mVendorID.ToLower()) &&
                      e.XplMsg.Source.Device.ToLower().Equals(this.mDeviceID.ToLower())) &&
                     e.XplMsg.Source.Instance.ToLower().Equals(this.mInstanceID.ToLower()))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received ECHO");
                }
            }
            else
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: {0} - {1} - {2}",
                             new object[] { e.XplMsg.Source.Vendor, e.XplMsg.Source.Device, e.XplMsg.Content });
                }
                string str   = e.XplMsg.Schema.msgClass.ToLower() + "." + e.XplMsg.Schema.msgType.ToLower();
                string str11 = str;
                if (str11 != null)
                {
                    if (!(str11 == "media.basic"))
                    {
                        if (!(str11 == "media.request"))
                        {
                            if (str11 == "remote.basic")
                            {
                                foreach (string str9 in e.XplMsg.GetParam(1, "keys").Split(new char[] { ',' }))
                                {
                                    if (this.DoDebug)
                                    {
                                        Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic \"{0}\"",
                                                 new object[] { str9 });
                                    }
                                    if (Enum.IsDefined(typeof(GUIWindow.Window), str9.ToUpper()))
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic window name",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        int num8 = (int)Enum.Parse(typeof(GUIWindow.Window), str9.ToUpper());
                                        if (!GUIWindowManager.ActiveWindow.Equals(num8))
                                        {
                                            GUIWindowManager.SendThreadCallbackAndWait(
                                                new GUIWindowManager.Callback(this.ThreadMessageCallback), 1, num8, null);
                                            return;
                                        }
                                        break;
                                    }
                                    if (Enum.IsDefined(typeof(Keys), str9))
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic key name",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        Key    key     = new Key(0, (int)Enum.Parse(typeof(Keys), str9));
                                        Action action3 = new Action();
                                        if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key, ref action3))
                                        {
                                            GUIWindowManager.OnAction(action3);
                                            return;
                                        }
                                    }
                                    foreach (string str10 in Enum.GetNames(typeof(RemoteButton)))
                                    {
                                        if (str10.ToLower().Equals(str9.ToLower()) || str9.ToLower().Equals("remote_" + str10.ToLower()))
                                        {
                                            if (this.DoDebug)
                                            {
                                                Log.Info(
                                                    "xPL_Connector.Listener_XplMessageReceived(): Received remote.basic remote key name \"{0}\"",
                                                    new object[] { str9 });
                                            }
                                            this.XPL_Send_Remote_Confirm_Message(e);
                                            if (!this.rHandler.MapAction((int)Enum.Parse(typeof(RemoteButton), str10)) && this.DoDebug)
                                            {
                                                Log.Info(
                                                    "xPL_Connector.Listener_XplMessageReceived(): COULD NOT FIRE REMOTE ACTION (isLoaded = {0})",
                                                    new object[] { this.rHandler.IsLoaded });
                                            }
                                            break;
                                        }
                                    }
                                    int result = 0;
                                    int.TryParse(str9, out result);
                                    if (result != 0)
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic raw keycode",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        Key    key2    = new Key(0, result);
                                        Action action4 = new Action();
                                        if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key2, ref action4))
                                        {
                                            GUIWindowManager.OnAction(action4);
                                            return;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            switch (e.XplMsg.GetParam(1, "request"))
                            {
                            case "devinfo":
                                this.XPL_SendDevInfo("xpl-stat");
                                return;

                            case "devstate":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerDevstate("xpl-stat");
                                }
                                return;

                            case "mpinfo":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerMediaPlayerInfo("xpl-stat");
                                    this.XPL_SendPlayerMediaPlayerInputInfo("xpl-stat");
                                }
                                return;

                            case "mptrnspt":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerTransportState("xpl-stat");
                                }
                                return;

                            case "mpmedia":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendMediaInfo("xpl-stat");
                                }
                                return;

                            case "mpconfig":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerMediaPlayerConfig("xpl-stat");
                                }
                                return;

                            case "mpqueue":
                                return;
                            }
                        }
                    }
                    else
                    {
                        int num;
                        switch (e.XplMsg.GetParam(1, "command").ToLower())
                        {
                        case "record":
                        case "position":
                        case "chapter":
                        case "power":
                        case "reboot":
                        case "input":
                        case "options":
                            return;

                        case "play":
                        {
                            string path = e.XplMsg.GetParam(1, "url").ToLower();
                            if (!(path.Equals(string.Empty) & g_Player.Paused))
                            {
                                if (path.Equals(g_Player.currentFileName) & g_Player.Paused)
                                {
                                    g_Player.Pause();
                                    if (this.DoDebug)
                                    {
                                        Log.Info(
                                            "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                                            new object[0]);
                                        return;
                                    }
                                    return;
                                }
                                if (File.Exists(path) && !g_Player.currentFileName.Equals(path))
                                {
                                    GUIMessage message = new GUIMessage();
                                    message.Message = GUIMessage.MessageType.GUI_MSG_PLAY_FILE;
                                    message.Label   = path;
                                    GUIWindowManager.SendThreadMessage(message);
                                    if (!this.DoDebug)
                                    {
                                        return;
                                    }
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play file command",
                                             new object[0]);
                                }
                                return;
                            }
                            g_Player.Pause();
                            if (this.DoDebug)
                            {
                                Log.Info(
                                    "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                                    new object[0]);
                            }
                            return;
                        }

                        case "stop":
                        {
                            GUIMessage message2 = new GUIMessage();
                            message2.Message = GUIMessage.MessageType.GUI_MSG_STOP_FILE;
                            GUIWindowManager.SendThreadMessage(message2);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic stop command",
                                         new object[0]);
                            }
                            return;
                        }

                        case "pause":
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic pause command",
                                         new object[0]);
                            }
                            if (!g_Player.Paused)
                            {
                                g_Player.Pause();
                            }
                            return;

                        case "forward":
                        {
                            string str4 = e.XplMsg.GetParam(1, "speed").ToLower();
                            num = 0;
                            if (!str4.Equals(string.Empty))
                            {
                                num = int.Parse(str4.Replace("x", ""));
                                break;
                            }
                            num = g_Player.Speed * 2;
                            break;
                        }

                        case "rewind":
                        {
                            string str5 = e.XplMsg.GetParam(1, "speed").ToLower();
                            int    num2 = 0;
                            if (!str5.Equals(string.Empty))
                            {
                                num2 = int.Parse(str5.Replace("x", ""));
                            }
                            else
                            {
                                num2 = Math.Abs(g_Player.Speed) * 2;
                            }
                            if (num2 > 0x20)
                            {
                                num2 = 0x20;
                            }
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic rewind ({0}x) command",
                                         new object[] { num2 });
                            }
                            g_Player.Speed = -num2;
                            return;
                        }

                        case "next":
                            Action action;
                            if (!g_Player.IsDVD)
                            {
                                action = new Action(Action.ActionType.ACTION_NEXT_ITEM, 0f, 0f);
                            }
                            else
                            {
                                action = new Action(Action.ActionType.ACTION_NEXT_CHAPTER, 0f, 0f);
                            }
                            GUIGraphicsContext.OnAction(action);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic next command",
                                         new object[0]);
                            }
                            return;

                        case "back":
                            Action action2;
                            if (!g_Player.IsDVD)
                            {
                                action2 = new Action(Action.ActionType.ACTION_PREV_ITEM, 0f, 0f);
                            }
                            else
                            {
                                action2 = new Action(Action.ActionType.ACTION_PREV_CHAPTER, 0f, 0f);
                            }
                            GUIGraphicsContext.OnAction(action2);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic back command",
                                         new object[0]);
                            }
                            return;

                        case "mute":
                            if (!(e.XplMsg.GetParam(1, "state").ToLower() == "on"))
                            {
                                if (this.DoDebug)
                                {
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute off command",
                                             new object[0]);
                                }
                                VolumeHandler.Instance.IsMuted = false;
                                return;
                            }
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute on command",
                                         new object[0]);
                            }
                            VolumeHandler.Instance.IsMuted = true;
                            return;

                        case "volume":
                        {
                            string str13;
                            string s = e.XplMsg.GetParam(1, "level").ToLower();
                            if (((str13 = s.Substring(0, 1)) == null) || (!(str13 == "+") && !(str13 == "-")))
                            {
                                int num7 = int.Parse(s);
                                VolumeHandler.Instance.Volume = (VolumeHandler.Instance.Maximum / 100) * num7;
                                if (this.DoDebug)
                                {
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic volume command",
                                             new object[0]);
                                }
                                return;
                            }
                            int volume = VolumeHandler.Instance.Volume;
                            int num5   = int.Parse(s) * 0x28f;
                            int num6   = volume + num5;
                            if (num6 < 0)
                            {
                                num6 = 0;
                            }
                            if (num6 > 0xffdc)
                            {
                                num6 = 0xffdc;
                            }
                            VolumeHandler.Instance.Volume = num6;
                            if (this.DoDebug)
                            {
                                Log.Info(
                                    "xPLConnector_Listener_XplMessageReceived: Received media.basic volume {0} command = orig = {1}, new = {2}, delta = {3}",
                                    new object[] { s, volume, num6, num5 });
                            }
                            return;
                        }

                        default:
                            return;
                        }
                        if (num > 0x20)
                        {
                            num = 0x20;
                        }
                        if (this.DoDebug)
                        {
                            Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play forward ({0}x) command",
                                     new object[] { num });
                        }
                        g_Player.Speed = num;
                    }
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Execute this command.
 /// </summary>
 /// <param name="variables">The variable list of the calling code.</param>
 public override void Execute(VariableList variables)
 {
     GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_EXIT, 0, 0));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Execute the given conditional action if needed.
        /// </summary>
        /// <param name="aAction">The action we want to conditionally execute.</param>
        /// <param name="aProcessId">Process-ID for close/kill commands.</param>
        /// <returns></returns>
        public bool ExecuteActionIfNeeded(ConditionalAction aAction, int aProcessId = -1)
        {
            if (aAction == null)
            {
                return(false);
            }

            HidListener.LogInfo("Action: {0} / {1} / {2} / {3}", aAction.Condition, aAction.ConProperty, aAction.Command, aAction.CmdProperty);

            Action action;

            if (aAction.Sound != string.Empty)
            {
                Util.Utils.PlaySound(aAction.Sound, false, true);
            }
            if (aAction.Focus && !GUIGraphicsContext.HasFocus)
            {
                GUIGraphicsContext.ResetLastActivity();
                var msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
                //GUIWindowManager.SendThreadMessage(msg);
                GUIGraphicsContext.SendMessage(msg);
                return(true);
            }
            switch (aAction.Command)
            {
            case "ACTION": // execute Action x
                var key = new Key(aAction.CmdKeyChar, aAction.CmdKeyCode);

                HidListener.LogInfo("Executing: key {0} / {1} / Action: {2} / {3}", aAction.CmdKeyChar, aAction.CmdKeyCode,
                                    aAction.CmdProperty,
                                    ((Action.ActionType)Convert.ToInt32(aAction.CmdProperty)).ToString());

                action = new Action(key, (Action.ActionType)Convert.ToInt32(aAction.CmdProperty), 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;

            case "KEY": // send Key x
                SendKeys.SendWait(aAction.CmdProperty);
                break;

            case "WINDOW": // activate Window x
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg;
                if ((Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
                    (Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
                {
                    GUIWindow.Window newHome = _basicHome ? GUIWindow.Window.WINDOW_SECOND_HOME : GUIWindow.Window.WINDOW_HOME;
                    // do we prefer to use only one home screen?
                    if (_useOnlyOneHome)
                    {
                        // skip if we are already in there
                        if (GUIWindowManager.ActiveWindow == (int)newHome)
                        {
                            break;
                        }
                    }
                    // we like both
                    else
                    {
                        // if already in one home switch to the other
                        switch (GUIWindowManager.ActiveWindow)
                        {
                        case (int)GUIWindow.Window.WINDOW_HOME:
                            newHome = GUIWindow.Window.WINDOW_SECOND_HOME;
                            break;

                        case (int)GUIWindow.Window.WINDOW_SECOND_HOME:
                            newHome = GUIWindow.Window.WINDOW_HOME;
                            break;
                        }
                    }
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)newHome, 0, null);
                }
                else
                {
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                         Convert.ToInt32(aAction.CmdProperty),
                                         0, null);
                }

                GUIWindowManager.SendThreadMessage(msg);
                break;

            case "TOGGLE": // toggle Layer 1/2
                if (_currentLayer == 1)
                {
                    _currentLayer = 2;
                }
                else
                {
                    _currentLayer = 1;
                }
                break;

            case "POWER": // power down commands

                if ((aAction.CmdProperty == "STANDBY") || (aAction.CmdProperty == "HIBERNATE"))
                {
                    GUIGraphicsContext.ResetLastActivity();
                }

                switch (aAction.CmdProperty)
                {
                case "EXIT":
                    action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "REBOOT":
                    action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "SHUTDOWN":
                    action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "STANDBY":
                    action = new Action(Action.ActionType.ACTION_SUSPEND, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "HIBERNATE":
                    action = new Action(Action.ActionType.ACTION_HIBERNATE, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;
                }
                break;

            case "PROCESS":
            {
                GUIGraphicsContext.ResetLastActivity();
                if (aProcessId > 0)
                {
                    var proc = Process.GetProcessById(aProcessId);
                    if (null != proc)
                    {
                        switch (aAction.CmdProperty)
                        {
                        case "CLOSE":
                            proc.CloseMainWindow();
                            break;

                        case "KILL":
                            proc.Kill();
                            break;
                        }
                    }
                }
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// OnAction() method. This method gets called when there's a new action like a
        /// keypress or mousemove or... By overriding this method, the control can respond
        /// to any action
        /// </summary>
        /// <param name="action">action : contains the action</param>
        public override void OnAction(Action action)
        {
            base.OnAction(action);
            GUIMessage message;

            if (Focus)
            {
                if (action.wID == Action.ActionType.ACTION_MOUSE_CLICK || action.wID == Action.ActionType.ACTION_SELECT_ITEM)
                {
                    // Send a message that the checkbox was clicked.
                    Selected = !Selected;

                    // send a message to anyone interested
                    message = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null);
                    GUIGraphicsContext.SendMessage(message);

                    // If this button contains scriptactions call the scriptactions.
                    if (_application.Length != 0)
                    {
                        //button should start an external application, so start it
                        Process proc = new Process();

                        string strWorkingDir = Path.GetFullPath(_application);
                        string strFileName   = Path.GetFileName(_application);
                        strWorkingDir                   = strWorkingDir.Substring(0, strWorkingDir.Length - (strFileName.Length + 1));
                        proc.StartInfo.FileName         = strFileName;
                        proc.StartInfo.WorkingDirectory = strWorkingDir;
                        proc.StartInfo.Arguments        = _arguments;
                        proc.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
                        proc.StartInfo.CreateNoWindow   = true;
                        proc.Start();
                        //proc.WaitForExit();
                    }

                    // If this links to another window go to the window.
                    if (_hyperLinkWindowId >= 0)
                    {
                        GUIWindowManager.ActivateWindow((int)_hyperLinkWindowId);
                        return;
                    }
                    // If this button corresponds to an action generate that action.
                    if (ActionID >= 0)
                    {
                        Action newaction = new Action((Action.ActionType)ActionID, 0, 0);
                        GUIGraphicsContext.OnAction(newaction);
                        return;
                    }

                    // button selected.
                    if (SubItemCount > 0)
                    {
                        // if we got subitems, then change the label of the control to the next
                        //subitem
                        SelectedItem++;
                        if (SelectedItem >= SubItemCount)
                        {
                            SelectedItem = 0;
                        }
                        Label = (string)GetSubItem(SelectedItem);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// this is actually loading a database view not a directory
        /// and this is done via view handler so parameter is not used
        /// but is needed to override method in base class
        /// </summary>
        /// <param name="strNotUsed">Used to implement method in base class but not used</param>
        protected override void LoadDirectory(string strNotUsed)
        {
            GUIWaitCursor.Show();
            GUIListItem SelectedItem = facadeLayout.SelectedListItem;

            int    previousLevel   = ((MusicViewHandler)handler).PreviousLevel;
            string strSelectedItem = string.Empty;

            if (SelectedItem != null)
            {
                // if there is an item selected and we are loading a new view
                // then store the existing value so when we navigate back up through
                // the view levels we can focus on the item we had selected
                // we can not use current level in the name for the directory history
                // as current level gets updated before LoadDirectory is called
                // therefore use previous level which is set by the music view handler
                // when that returns (ie. that will be level of the view user has
                // made selection from as it has not been cleared yet)
                if (SelectedItem.IsFolder && SelectedItem.Label != "..")
                {
                    m_history.Set(SelectedItem.Label, handler.LocalizedCurrentView + "." +
                                  previousLevel.ToString());
                }
            }

            List <Song> songs;

            if (!((MusicViewHandler)handler).Execute(out songs))
            {
                GUIWaitCursor.Hide();
                Action action = new Action();
                action.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
                GUIGraphicsContext.OnAction(action);
                return;
            }

            GUIControl.ClearControl(GetID, facadeLayout.GetID);
            SwitchLayout();

            List <GUIListItem> itemsToAdd = new List <GUIListItem>();

            TimeSpan totalPlayingTime = new TimeSpan();

            if (previousLevel > handler.CurrentLevel)
            {
                // only need to lookup values when navigating back up through the view
                strSelectedItem = m_history.Get(handler.LocalizedCurrentView + "." + handler.CurrentLevel.ToString());
            }

            #region handle pin protected share

            if (songs.Count > 0) // some songs in there?
            {
                Song song = songs[0];
                if (song.FileName.Length > 0) // does a filename exits
                {
                    foreach (Share share in _shareList)
                    {
                        if (song.FileName.Contains(share.Path)) // compare it with shares
                        {
                            if (share.Pincode != string.Empty)  // does it have a pincode?
                            {
                                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GET_PASSWORD, 0, 0, 0, 0, 0, 0);
                                GUIWindowManager.SendMessage(msg); // ask for the userinput

                                if (msg.Label != share.Pincode)
                                {
                                    songs.Clear();
                                }
                                break;
                            }
                        }
                    }
                }
            }

            #endregion

            if (handler.CurrentLevel > 0)
            {
                // add ".." folder item if not at bottom level of view
                GUIListItem pItem = new GUIListItem("..");
                pItem.Path     = string.Empty;
                pItem.IsFolder = true;
                Util.Utils.SetDefaultIcons(pItem);
                itemsToAdd.Add(pItem);
            }

            // Get current Filter used
            var currentFilter = (FilterDefinition)handler.View.Filters[handler.CurrentLevel];

            for (int i = 0; i < songs.Count; ++i)
            {
                Song        song = songs[i];
                GUIListItem item = new GUIListItem();

                MusicTag tag = new MusicTag();
                tag = song.ToMusicTag();
                item.AlbumInfoTag = song;
                item.MusicTag     = tag;

                if (handler.CurrentLevel + 1 < handler.MaxLevels)
                {
                    item.IsFolder = true;
                    item.Label    = MusicViewHandler.GetFieldValue(song, handler.CurrentLevelWhere);

                    // If we are grouping on a specific value, we have in the Duration field the number of items
                    // Use this in the sort field
                    if (currentFilter.SqlOperator == "group")
                    {
                        item.Label2 = tag.Duration.ToString();
                    }
                    else
                    {
                        SetSortLabel(ref item, CurrentSortMethod, handler.CurrentLevelWhere);
                    }
                }
                else
                {
                    item.IsFolder = false;
                    if (!GUIMusicBaseWindow.SetTrackLabels(ref item, CurrentSortMethod))
                    {
                        item.Label = song.Title;
                    }
                }

                if (tag != null)
                {
                    if (tag.Duration > 0)
                    {
                        totalPlayingTime = totalPlayingTime.Add(new TimeSpan(0, 0, tag.Duration));
                    }
                }

                item.Path = song.FileName;

                if (!string.IsNullOrEmpty(_currentPlaying) &&
                    item.Path.Equals(_currentPlaying, StringComparison.OrdinalIgnoreCase))
                {
                    item.Selected = true;
                }

                item.Duration        = song.Duration;
                tag.TimesPlayed      = song.TimesPlayed;
                item.Rating          = song.Rating;
                item.Year            = song.Year;
                item.OnRetrieveArt  += new GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt);
                item.OnItemSelected += new GUIListItem.ItemSelectedHandler(item_OnItemSelected);
                itemsToAdd.Add(item);
            }

            itemsToAdd.Sort(new MusicSort(CurrentSortMethod, CurrentSortAsc));

            int  iItem        = 0; // used to hold index of item to select
            bool itemSelected = false;
            for (int i = 0; i < itemsToAdd.Count; ++i)
            {
                if (!itemSelected && itemsToAdd[i].Label == strSelectedItem)
                {
                    iItem        = i;
                    itemSelected = true;
                }
                facadeLayout.Add(itemsToAdd[i]);
            }

            int iTotalItems = facadeLayout.Count;
            if (iTotalItems > 0)
            {
                GUIListItem rootItem = facadeLayout[0];
                if (rootItem.Label == "..")
                {
                    iTotalItems--;
                }
            }

            //set object count label, total duration
            GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetObjectCountLabel(iTotalItems));

            if (totalPlayingTime.TotalSeconds > 0)
            {
                GUIPropertyManager.SetProperty("#totalduration",
                                               Util.Utils.SecondsToHMSString((int)totalPlayingTime.TotalSeconds));
            }
            else
            {
                GUIPropertyManager.SetProperty("#totalduration", string.Empty);
            }

            if (itemSelected)
            {
                GUIControl.SelectItemControl(GetID, facadeLayout.GetID, iItem);
            }
            else if (m_iItemSelected >= 0)
            {
                GUIControl.SelectItemControl(GetID, facadeLayout.GetID, m_iItemSelected);
            }
            else
            {
                SelectCurrentItem();
            }

            UpdateButtonStates();
            GUIWaitCursor.Hide();
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Exits MediaPortal.
 /// </summary>
 public static void ExitMP()
 {
     GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_EXIT, 0, 0));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Shut Down the computer in a MediaPortal friendly way.
 /// </summary>
 public static void ShutDown()
 {
     GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Reboot the computer in a MediaPortal friendly way.
 /// </summary>
 public static void Reboot()
 {
     GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_REBOOT, 0, 0));
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Evaluates the button number, gets its mapping and executes the action
        /// </summary>
        /// <param name="btnCode">Button code (ref: XML file)</param>
        /// <param name="processID">Process-ID for close/kill commands</param>
        private bool DoMapAction(string btnCode, int processID)
        {
            if (!_isLoaded) // No mapping loaded
            {
                Log.Info("Map: No button mapping loaded");
                return(false);
            }
            Mapping map = null;

            map = GetMapping(btnCode);
            if (map == null)
            {
                return(false);
            }

            Log.Debug("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty);

            Action action;

            if (map.Sound != string.Empty) // && !g_Player.Playing)
            {
                Util.Utils.PlaySound(map.Sound, false, true);
            }
            if (map.Focus && !GUIGraphicsContext.HasFocus)
            {
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
                GUIWindowManager.SendThreadMessage(msg);
                return(true);
            }
            switch (map.Command)
            {
            case "ACTION": // execute Action x
                Key key = new Key(map.CmdKeyChar, map.CmdKeyCode);

                Log.Debug("Executing: key {0} / {1} / Action: {2} / {3}", map.CmdKeyChar, map.CmdKeyCode, map.CmdProperty,
                          ((Action.ActionType)Convert.ToInt32(map.CmdProperty)).ToString());

                action = new Action(key, (Action.ActionType)Convert.ToInt32(map.CmdProperty), 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;

            case "KEY": // send Key x
                SendKeys.SendWait(map.CmdProperty);
                break;

            case "WINDOW": // activate Window x
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg;
                if ((Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
                    (Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
                {
                    if (_basicHome)
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
                    }
                    else
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_HOME, 0, null);
                    }
                }
                else
                {
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, Convert.ToInt32(map.CmdProperty),
                                         0, null);
                }

                GUIWindowManager.SendThreadMessage(msg);
                break;

            case "TOGGLE": // toggle Layer 1/2
                if (_currentLayer == 1)
                {
                    _currentLayer = 2;
                }
                else
                {
                    _currentLayer = 1;
                }
                break;

            case "POWER": // power down commands

                if ((map.CmdProperty == "STANDBY") || (map.CmdProperty == "HIBERNATE"))
                {
                    GUIGraphicsContext.ResetLastActivity();

                    //Stop all media before suspending or hibernating
                    if (g_Player.Playing)
                    {
                        GUIWindowManager.SendThreadCallbackAndWait(StopPlayback, 0, 0, null);
                    }

                    // this is all handled in mediaportal.cs - OnSuspend

                    /*
                     * if (_basicHome)
                     * msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
                     * else
                     * msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null);
                     *
                     * GUIWindowManager.SendThreadMessage(msg);
                     */
                }

                switch (map.CmdProperty)
                {
                case "EXIT":
                    action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "REBOOT":
                    action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "SHUTDOWN":
                    action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "STANDBY":
                    // we need a slow standby (force=false), in order to have the onsuspend method being called on mediportal.cs
                    // this is needed in order to have "ShowLastActiveModule" working correctly.
                    // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
                    MPControlPlugin.OnSuspend();
                    WindowsController.ExitWindows(RestartOptions.Suspend, false);
                    break;

                case "HIBERNATE":
                    // we need a slow hibernation (force=false), in order to have the onsuspend method being called on mediportal.cs
                    // this is needed in order to have "ShowLastActiveModule" working correctly.
                    // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
                    MPControlPlugin.OnSuspend();
                    WindowsController.ExitWindows(RestartOptions.Hibernate, false);
                    break;
                }
                break;

            case "PROCESS":
            {
                GUIGraphicsContext.ResetLastActivity();
                if (processID > 0)
                {
                    Process proc = Process.GetProcessById(processID);
                    if (null != proc)
                    {
                        switch (map.CmdProperty)
                        {
                        case "CLOSE":
                            proc.CloseMainWindow();
                            break;

                        case "KILL":
                            proc.Kill();
                            break;
                        }
                    }
                }
            }
            break;

            case "BLAST":
                MPControlPlugin.ProcessCommand(map.CmdProperty, true);
                break;

            default:
                return(false);
            }
            return(true);
        }
Ejemplo n.º 22
0
        public override void OnAction(Action action)
        {
            base.OnAction(action);
            switch (action.wID)
            {
            case Action.ActionType.ACTION_STOP:

                if (GUIWindowManager.ActiveWindow == GetID && !_isStopped)
                {
                    _isStopped = true;
                    Action act = new Action();
                    act.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
                    GUIGraphicsContext.OnAction(act);
                }
                break;

            // Since a ACTION_STOP action clears the player and CurrentPlaylistType type
            // we need a way to restart playback after an ACTION_STOP has been received
            case Action.ActionType.ACTION_MUSIC_PLAY:
            case Action.ActionType.ACTION_NEXT_ITEM:
            case Action.ActionType.ACTION_PAUSE:
            case Action.ActionType.ACTION_PREV_ITEM:
                if ((PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC) &&
                    (PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_TEMP) &&
                    (PlaylistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_LAST_FM))
                {
                    LoadAndStartPlayList();
                }
                break;

            case Action.ActionType.ACTION_SHOW_INFO:
                FlipPictures();
                break;

            case Action.ActionType.ACTION_KEY_PRESSED:
                switch (action.m_key.KeyChar)
                {
                case (int)Keys.D0:
                    UpdateCurrentTrackRating(0);
                    break;

                case (int)Keys.D1:
                    UpdateCurrentTrackRating(1);
                    break;

                case (int)Keys.D2:
                    UpdateCurrentTrackRating(2);
                    break;

                case (int)Keys.D3:
                    UpdateCurrentTrackRating(3);
                    break;

                case (int)Keys.D4:
                    UpdateCurrentTrackRating(4);
                    break;

                case (int)Keys.D5:
                    UpdateCurrentTrackRating(5);
                    break;
                    // do not act on _every_ key
                    //default:
                    //  UpdateCurrentTrackRating(-1);
                    //  break;
                }
                break;

            case Action.ActionType.ACTION_NEXT_AUDIO:
            {
                if (g_Player.AudioStreams > 1)
                {
                    //_showStatus = true;
                    //_timeStatusShowTime = (DateTime.Now.Ticks / 10000);
                    GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0,
                                                    (int)ControlIDs.LABEL_ROW1, 0, 0, null);
                    g_Player.SwitchToNextAudio();

                    String language     = g_Player.AudioLanguage(g_Player.CurrentAudioStream);
                    String languageType = g_Player.AudioType(g_Player.CurrentAudioStream);
                    if (languageType == Strings.Unknown || string.IsNullOrEmpty(languageType))
                    {
                        msg.Label = string.Format("{0} ({1}/{2})", language,
                                                  g_Player.CurrentAudioStream + 1, g_Player.AudioStreams);
                    }
                    else
                    {
                        msg.Label = string.Format("{0} [{1}] ({2}/{3})", language, languageType.TrimEnd(),
                                                  g_Player.CurrentAudioStream + 1, g_Player.AudioStreams);
                    }

                    OnMessage(msg);
                    Log.Info("GUIMusicPlayingNow: switched audio to {0}", msg.Label);
                }
            }
            break;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// OnAction() method. This method gets called when there's a new action like a
        /// keypress or mousemove or... By overriding this method, the control can respond
        /// to any action
        /// </summary>
        /// <param name="action">action : contains the action</param>
        public override void OnAction(Action action)
        {
            if (Focus)
            {
                switch (action.wID)
                {
                case Action.ActionType.ACTION_MOVE_DOWN:
                    _keepLook = _keepLookOnDown;
                    break;

                case Action.ActionType.ACTION_MOVE_UP:
                    _keepLook = _keepLookOnUp;
                    break;

                case Action.ActionType.ACTION_MOVE_LEFT:
                    _keepLook = _keepLookOnLeft;
                    break;

                case Action.ActionType.ACTION_MOVE_RIGHT:
                    _keepLook = _keepLookOnRight;
                    break;
                }
            }

            base.OnAction(action);

            if (Focus)
            {
                if (action.wID == Action.ActionType.ACTION_MOUSE_CLICK || action.wID == Action.ActionType.ACTION_SELECT_ITEM)
                {
                    // If this button has a click setting then execute the setting.
                    if (_onclick.Length != 0)
                    {
                        GUIPropertyManager.Parse(_onclick, GUIExpressionManager.ExpressionOptions.EVALUATE_ALWAYS);
                    }

                    if (ContextMenu != null)
                    {
                        DoContextMenu();
                        return;
                    }

                    // If this button contains scriptactions call the scriptactions.
                    if (_application.Length != 0)
                    {
                        //button should start an external application, so start it
                        Process proc = new Process();

                        string workingFolder = Path.GetFullPath(_application);
                        string fileName      = Path.GetFileName(_application);
                        if (fileName != null)
                        {
                            workingFolder           = workingFolder.Substring(0, workingFolder.Length - (fileName.Length + 1));
                            proc.StartInfo.FileName = fileName;
                        }
                        proc.StartInfo.WorkingDirectory = workingFolder;
                        proc.StartInfo.Arguments        = _arguments;
                        proc.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
                        proc.StartInfo.CreateNoWindow   = true;
                        proc.Start();
                        //proc.WaitForExit();
                    }

                    // If this links to another window go to the window.
                    if (_hyperLinkWindowId >= 0)
                    {
                        if (_hyperLinkParameter != null && !_hyperLinkParameter.Equals(""))
                        {
                            // The link also contains a parameter that we want to pass to the plugin
                            GUIWindowManager.ActivateWindow(_hyperLinkWindowId, GUIPropertyManager.Parse(_hyperLinkParameter),
                                                            !_addToHistory);
                        }
                        else
                        {
                            GUIWindowManager.ActivateWindow(_hyperLinkWindowId, !_addToHistory);
                        }
                        return;
                    }
                    // If this button corresponds to an action generate that action.
                    if (ActionID >= 0)
                    {
                        Action newaction = new Action((Action.ActionType)ActionID, 0, 0);
                        GUIGraphicsContext.OnAction(newaction);
                        return;
                    }

                    // button selected.
                    if (SubItemCount > 0)
                    {
                        // if we got subitems, then change the label of the control to the next
                        //subitem
                        SelectedItem++;
                        if (SelectedItem >= SubItemCount)
                        {
                            SelectedItem = 0;
                        }
                        Label = (string)GetSubItem(SelectedItem);
                    }

                    // send a message to anyone interested
                    var message = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null);
                    GUIGraphicsContext.SendMessage(message);
                }
            }
        }