| 18086 | #endif |
| 18087 | |
| 18088 | ParsedRunCommand QKeyMapper_Worker::parseRunCommandUserInput(const QString &input) |
| 18089 | { |
| 18090 | #ifdef DEBUG_LOGOUT_ON |
| 18091 | qDebug() << "[parseRunCommandUserInput] Input ->" << input; |
| 18092 | #endif |
| 18093 | |
| 18094 | // System verbs for ShellExecute - based on Microsoft lpVerb documentation |
| 18095 | // edit: Launches an editor and opens the document for editing |
| 18096 | // explore: Explores the folder specified by lpFile |
| 18097 | // find: Initiates a search starting from the specified directory |
| 18098 | // open: Opens the file specified by the lpFile parameter |
| 18099 | // openas: Launches a picker UI allowing the user to select an app to open the file |
| 18100 | // print: Prints the document file specified by lpFile |
| 18101 | // properties: Displays the file or folder's properties |
| 18102 | // runas: Launches an application as Administrator (UAC prompt) |
| 18103 | static const QStringList systemVerbs{ |
| 18104 | "find", |
| 18105 | "explore", |
| 18106 | "open", |
| 18107 | "edit", |
| 18108 | "openas", |
| 18109 | "print", |
| 18110 | "properties", |
| 18111 | "runas" |
| 18112 | }; |
| 18113 | |
| 18114 | ParsedRunCommand result; |
| 18115 | QString str = input; |
| 18116 | static QRegularExpression simplified_regex(R"([\r\n]+)"); |
| 18117 | str.replace(simplified_regex, " "); |
| 18118 | str = str.trimmed(); |
| 18119 | |
| 18120 | // 1. Extract SystemVerb (find, explore, open, edit, openas, print, properties, runas) |
| 18121 | // Check if the input starts with a system verb followed by whitespace |
| 18122 | static QRegularExpression verbPattern(R"(^(\w+)(\s+.*|$))", QRegularExpression::CaseInsensitiveOption); |
| 18123 | QRegularExpressionMatch verbMatch = verbPattern.match(str); |
| 18124 | |
| 18125 | if (verbMatch.hasMatch()) { |
| 18126 | QString firstWord = verbMatch.captured(1); |
| 18127 | if (systemVerbs.contains(firstWord, Qt::CaseInsensitive)) { |
| 18128 | result.systemVerb = firstWord.toLower(); |
| 18129 | // Remove the verb and any following whitespace from the command line |
| 18130 | str = verbMatch.captured(2); // Everything after the verb |
| 18131 | #ifdef DEBUG_LOGOUT_ON |
| 18132 | qDebug() << "[parseRunCommandUserInput] SystemVerb extracted ->" << result.systemVerb << ", remaining str ->" << str; |
| 18133 | #endif |
| 18134 | } |
| 18135 | // If not a system verb, str remains unchanged (the whole original string) |
| 18136 | } |
| 18137 | |
| 18138 | // 2. Extract Wait=True|False from remaining string |
| 18139 | static QRegularExpression reRunWait( |
| 18140 | R"(Wait=(\w+))", |
| 18141 | QRegularExpression::CaseInsensitiveOption |
| 18142 | ); |
| 18143 | QRegularExpressionMatch mRunWait = reRunWait.match(str); |
| 18144 | if (mRunWait.hasMatch()) { |
| 18145 | QString wait_state = mRunWait.captured(1).toLower(); |