Changeset 71145 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 28, 2018 8:43:44 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlConsole.cpp
r71135 r71145 40 40 setWordWrapMode(QTextOption::NoWrap); 41 41 reset(); 42 43 m_tabDictinary.insert("username", 0); 44 m_tabDictinary.insert("createsession", 0); 45 m_tabDictinary.insert("exe", 0); 46 m_tabDictinary.insert("sessionid", 0); 47 m_tabDictinary.insert("sessionname", 0); 48 m_tabDictinary.insert("timeout", 0); 49 m_tabDictinary.insert("password", 0); 50 m_tabDictinary.insert("start", 0); 51 m_tabDictinary.insert("ls", 0); 52 m_tabDictinary.insert("stat", 0); 42 53 } 43 54 … … 137 148 break; 138 149 } 150 case Qt::Key_Tab: 151 completeByTab(); 152 break; 139 153 default: 140 154 { … … 225 239 return m_tCommandHistory.at(m_uCommandHistoryIndex); 226 240 } 241 242 void UIGuestControlConsole::completeByTab() 243 { 244 bool lastLine = blockCount() == (textCursor().blockNumber() +1); 245 if (!lastLine) 246 return; 247 /* Save whatever we have currently on this line: */ 248 QString currentCommand = getCommandString(); 249 250 QTextCursor cursor = textCursor(); 251 /* Save the cursor's position within the line */ 252 int cursorBlockPosition = cursor.positionInBlock(); 253 254 /* Find out on which word the cursor is. This is the word we will 255 complete: */ 256 cursor.select(QTextCursor::WordUnderCursor); 257 QString currentWord = cursor.selectedText(); 258 259 const QList<QString> &matches = matchedWords(currentWord); 260 /* If there are no matches do nothing: */ 261 if(matches.empty()) 262 return; 263 /* if there are more than one match list them all and 264 reprint the line: */ 265 if(matches.size() > 1) 266 { 267 moveCursor(QTextCursor::End); 268 QString strMatches; 269 for(int i = 0; i < matches.size(); ++i) 270 { 271 strMatches.append(matches.at(i)); 272 strMatches.append(" "); 273 } 274 appendPlainText(strMatches); 275 insertPlainText(QString("\n").append(m_strPrompt)); 276 insertPlainText(currentCommand); 277 /* Put the cursor in its previous position within the line: */ 278 int blockPosition = textCursor().block().position(); 279 QTextCursor nCursor = textCursor(); 280 nCursor.setPosition(blockPosition + cursorBlockPosition); 281 setTextCursor(nCursor); 282 return; 283 } 284 /* if there is only one word just complete: */ 285 /* some sanity checks */ 286 if(matches.at(0).length() > currentWord.length()) 287 insertPlainText(matches.at(0).right(matches.at(0).length() - currentWord.length())); 288 } 289 290 291 QList<QString> UIGuestControlConsole::matchedWords(const QString &strSearch) const 292 { 293 QList<QString> list; 294 /* Go thru the map and find which of its elements start with @pstrSearch: */ 295 for(TabDictionary::const_iterator iterator = m_tabDictinary.begin(); 296 iterator != m_tabDictinary.end(); ++iterator) 297 { 298 const QString &strMap = iterator.key(); 299 if(strMap.startsWith(strSearch)) 300 list.push_back(strMap); 301 } 302 return list; 303 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlConsole.h
r71049 r71145 51 51 52 52 typedef QVector<QString> CommandHistory; 53 void reset(); 54 void startNextLine(); 53 typedef QMap<QString, int> TabDictionary; 54 55 void reset(); 56 void startNextLine(); 55 57 /** Return the text of the curent line */ 56 QString getCommandString();58 QString getCommandString(); 57 59 /** Replaces the content of the last line with m_strPromt + @p stringNewContent */ 58 void replaceLineContent(const QString &stringNewContent);60 void replaceLineContent(const QString &stringNewContent); 59 61 /** Get next/prev command from history. Return @p originalString if history is empty. */ 60 QString getNextCommandFromHistory(const QString &originalString = QString()); 61 QString getPreviousCommandFromHistory(const QString &originalString = QString()); 62 62 QString getNextCommandFromHistory(const QString &originalString = QString()); 63 QString getPreviousCommandFromHistory(const QString &originalString = QString()); 64 void completeByTab(); 65 /* Return a list of words that start with @p strSearch */ 66 QList<QString> matchedWords(const QString &strSearch) const; 63 67 const QString m_strGreet; 64 68 const QString m_strPrompt; 65 69 TabDictionary m_tabDictinary; 66 70 /* A vector of entered commands */ 67 71 CommandHistory m_tCommandHistory; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.cpp
r71133 r71145 354 354 { 355 355 356 // printf("/lk %d c:/users %d\n", m_comGuestSession.DirectoryExists("/lk", true),357 // m_comGuestSession.DirectoryExists("c:/users", true));358 356 QVector<KDirectoryOpenFlag> flag; 359 357 flag.push_back(KDirectoryOpenFlag_None); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp
r71138 r71145 533 533 void UIGuestControlInterface::putCommand(const QString &strCommand) 534 534 { 535 if (!isGuestAdditionsAvaible()) 536 { 537 emit sigOutputString("No guest addtions detected. Guest control needs guest additions"); 538 return; 539 } 535 540 536 541 char **argv; … … 651 656 strInfo.append(QString("%1 \t").arg(fsObjectInfo.GetBirthTime())); 652 657 strInfo.append(QString("%1 ").arg(fsObjectInfo.GetChangeTime())); 653 654 658 return strInfo; 655 659 } 660 661 bool UIGuestControlInterface::isGuestAdditionsAvaible() 662 { 663 if (!m_comGuest.isOk()) 664 return false; 665 return m_comGuest.GetAdditionsStatus(m_comGuest.GetAdditionsRunLevel()); 666 667 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.h
r71138 r71145 80 80 81 81 QString getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const; 82 82 bool isGuestAdditionsAvaible(); 83 83 CGuest m_comGuest; 84 84 const QString m_strHelp; 85 QString m_strStatus;85 QString m_strStatus; 86 86 /* A map of function pointers to handleXXXX functions */ 87 87 QMap<QString, HandleFuncPtr> m_subCommandHandlers;
Note:
See TracChangeset
for help on using the changeset viewer.