Exemplo n.º 1
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            string name = textBoxName.Text.Trim();

            if (name.Length == 0)
            {
                MessageBox.Show(this, "You must supply a name for this Macro", "Name missing", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                textBoxName.Focus();
                return;
            }

            if (!IrssUtils.Common.IsValidFileName(name))
            {
                MessageBox.Show(this, "You must supply a valid name for this Macro", "Invalid name", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                textBoxName.Focus();
                return;
            }

            try
            {
                string fileName = Path.Combine(MPControlPlugin.FolderMacros, name + IrssUtils.Common.FileExtensionMacro);
                WriteToFile(fileName);

                MPControlPlugin.ProcessCommand(IrssUtils.Common.CmdPrefixMacro + name, false);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void buttonTestMacro_Click(object sender, EventArgs e)
        {
            if (listViewMacro.SelectedItems.Count != 1)
            {
                return;
            }

            try
            {
                MPControlPlugin.ProcessCommand(IrssUtils.Common.CmdPrefixMacro + listViewMacro.SelectedItems[0].Text, false);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
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);
        }