VirtualBox

Ignore:
Timestamp:
Feb 28, 2018 8:43:44 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:6699 Add a simple command complation to the guest control console

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  
    4040    setWordWrapMode(QTextOption::NoWrap);
    4141    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);
    4253}
    4354
     
    137148            break;
    138149        }
     150        case Qt::Key_Tab:
     151            completeByTab();
     152            break;
    139153        default:
    140154        {
     
    225239    return m_tCommandHistory.at(m_uCommandHistoryIndex);
    226240}
     241
     242void 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
     291QList<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  
    5151
    5252    typedef QVector<QString> CommandHistory;
    53     void        reset();
    54     void        startNextLine();
     53    typedef QMap<QString, int> TabDictionary;
     54
     55    void           reset();
     56    void           startNextLine();
    5557    /** Return the text of the curent line */
    56     QString     getCommandString();
     58    QString        getCommandString();
    5759    /** Replaces the content of the last line with m_strPromt + @p stringNewContent */
    58     void        replaceLineContent(const QString &stringNewContent);
     60    void           replaceLineContent(const QString &stringNewContent);
    5961    /** 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;
    6367    const QString  m_strGreet;
    6468    const QString  m_strPrompt;
    65 
     69    TabDictionary  m_tabDictinary;
    6670    /* A vector of entered commands */
    6771    CommandHistory m_tCommandHistory;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.cpp

    r71133 r71145  
    354354    {
    355355
    356         // printf("/lk %d c:/users %d\n", m_comGuestSession.DirectoryExists("/lk", true),
    357         //        m_comGuestSession.DirectoryExists("c:/users", true));
    358356        QVector<KDirectoryOpenFlag> flag;
    359357        flag.push_back(KDirectoryOpenFlag_None);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp

    r71138 r71145  
    533533void UIGuestControlInterface::putCommand(const QString &strCommand)
    534534{
     535    if (!isGuestAdditionsAvaible())
     536    {
     537        emit sigOutputString("No guest addtions detected. Guest control needs guest additions");
     538        return;
     539    }
    535540
    536541    char **argv;
     
    651656    strInfo.append(QString("%1 \t").arg(fsObjectInfo.GetBirthTime()));
    652657    strInfo.append(QString("%1 ").arg(fsObjectInfo.GetChangeTime()));
    653 
    654658    return strInfo;
    655659}
     660
     661bool 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  
    8080
    8181    QString getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const;
    82 
     82    bool    isGuestAdditionsAvaible();
    8383    CGuest        m_comGuest;
    8484    const QString m_strHelp;
    85     QString  m_strStatus;
     85    QString       m_strStatus;
    8686    /* A map of function pointers to handleXXXX functions */
    8787    QMap<QString, HandleFuncPtr> m_subCommandHandlers;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette