VirtualBox

Changeset 71049 in vbox


Ignore:
Timestamp:
Feb 19, 2018 12:16:09 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699 Adding a context menu to tree widget to close a session of terminate a process

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71039 r71049  
    565565        src/runtime/UIIndicatorsPool.cpp \
    566566        src/runtime/UIStatusBarEditorWindow.cpp \
     567        src/runtime/information/guestctrl/UIInformationGuestSession.cpp \
    567568        src/selector/UIActionPoolSelector.cpp \
    568569        src/selector/UIDesktopPane.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlConsole.cpp

    r71025 r71049  
    3232UIGuestControlConsole::UIGuestControlConsole(QWidget* parent /* = 0 */)
    3333    :QPlainTextEdit(parent)
    34     , m_uLineNumber(0)
    3534    , m_strGreet("Welcome to 'Guest Control Console'. Type 'help' for help\n")
    3635    , m_strPrompt("$>")
     
    4443void UIGuestControlConsole::reset()
    4544{
    46     m_uLineNumber = 0;
    4745    clear();
    4846    startNextLine();
     
    6159void UIGuestControlConsole::putOutput(const QString &strOutput)
    6260{
    63     if(strOutput.isNull() || strOutput.length() <= 0)
     61    if (strOutput.isNull() || strOutput.length() <= 0)
    6462        return;
    6563
     
    7270    moveCursor(QTextCursor::End);
    7371
    74     if(newLineNeeded)
     72    if (newLineNeeded)
    7573    {
    7674        insertPlainText("\n");
     
    9896        {
    9997            QTextCursor cursor = textCursor();
    100             if(cursor.positionInBlock() > m_strPrompt.length())
     98            if (cursor.positionInBlock() > m_strPrompt.length())
    10199                cursor.deletePreviousChar();
    102100            break;
     
    105103        case Qt::Key_Right:
    106104        {
    107             if(textCursor().positionInBlock() > m_strPrompt.length())
     105            if (textCursor().positionInBlock() > m_strPrompt.length())
    108106                QPlainTextEdit::keyPressEvent(pEvent);
    109107            break;
     
    113111        {
    114112            QString strCommand(getCommandString());
    115             if(!strCommand.isEmpty())
     113            if (!strCommand.isEmpty())
    116114            {
    117115                emit commandEntered(strCommand);
    118                 if(!m_tCommandHistory.contains(strCommand))
     116                if (!m_tCommandHistory.contains(strCommand))
    119117                    m_tCommandHistory.push_back(strCommand);
    120118                m_uCommandHistoryIndex = m_tCommandHistory.size()-1;
     
    139137}
    140138
    141 int UIGuestControlConsole::currentLineNumber() const
    142 {
    143     return textCursor().blockNumber();
    144 }
    145 
    146 
    147139void UIGuestControlConsole::mousePressEvent(QMouseEvent *pEvent)
    148140{
    149     Q_UNUSED(pEvent);
    150     setFocus();
     141    // Q_UNUSED(pEvent);
     142    // setFocus();
     143    QPlainTextEdit::mousePressEvent(pEvent);
    151144}
    152145
    153146void UIGuestControlConsole::mouseDoubleClickEvent(QMouseEvent *pEvent)
    154147{
    155     Q_UNUSED(pEvent);
     148    //Q_UNUSED(pEvent);
     149    QPlainTextEdit::mouseDoubleClickEvent(pEvent);
    156150}
    157151
    158152void UIGuestControlConsole::contextMenuEvent(QContextMenuEvent *pEvent)
    159153{
    160     Q_UNUSED(pEvent);
     154    //Q_UNUSED(pEvent);
     155    QPlainTextEdit::contextMenuEvent(pEvent);
    161156}
    162157
     
    164159{
    165160    QTextDocument* pDocument = document();
    166     if(!pDocument)
     161    if (!pDocument)
    167162        return QString();
    168163    QTextBlock block = pDocument->lastBlock();//findBlockByLineNumber(pDocument->lineCount()-1);
     
    170165        return QString();
    171166    QString lineStr = block.text();
    172     if(lineStr.isNull() || lineStr.length() <= 1)
     167    if (lineStr.isNull() || lineStr.length() <= 1)
    173168        return QString();
    174169    /* Remove m_strPrompt from the line string: */
     
    190185QString UIGuestControlConsole::getNextCommandFromHistory(const QString &originalString /* = QString() */)
    191186{
    192     if(m_tCommandHistory.empty())
     187    if (m_tCommandHistory.empty())
    193188        return originalString;
    194189
    195     if(m_uCommandHistoryIndex == (unsigned)(m_tCommandHistory.size() - 1))
     190    if (m_uCommandHistoryIndex == (unsigned)(m_tCommandHistory.size() - 1))
    196191        m_uCommandHistoryIndex = 0;
    197192    else
     
    204199QString UIGuestControlConsole::getPreviousCommandFromHistory(const QString &originalString /* = QString() */)
    205200{
    206     if(m_tCommandHistory.empty())
     201    if (m_tCommandHistory.empty())
    207202        return originalString;
    208     if(m_uCommandHistoryIndex == 0)
     203    if (m_uCommandHistoryIndex == 0)
    209204        m_uCommandHistoryIndex = m_tCommandHistory.size() - 1;
    210205    else
     
    213208    return m_tCommandHistory.at(m_uCommandHistoryIndex);
    214209}
    215 
    216 void UIGuestControlConsole::printCommandHistory() const
    217 {
    218     for(int i = 0; i < m_tCommandHistory.size(); ++i)
    219     {
    220         printf("%d -- %s\n", i, m_tCommandHistory.at(i).toStdString().c_str());
    221     }
    222 }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlConsole.h

    r71025 r71049  
    2222# include <QPlainTextEdit>
    2323
     24/** QPlainTextEdit extension to provide a simple terminal like widget. */
    2425class UIGuestControlConsole : public QPlainTextEdit
    2526{
     
    2829
    2930signals:
    30 
     31    /* This is emitted when return key is pressed */
    3132    void commandEntered(QString command);
    3233
     
    3435
    3536    UIGuestControlConsole(QWidget* parent = 0);
     37    /* @p strOutput is displayed in the console */
    3638    void putOutput(const QString &strOutput);
    3739
     
    4749
    4850private:
     51
    4952    typedef QVector<QString> CommandHistory;
    50     int      currentLineNumber() const;
    51     void     reset();
    52     void     startNextLine();
     53    void        reset();
     54    void        startNextLine();
    5355    /** Return the text of the curent line */
    54     QString  getCommandString();
     56    QString     getCommandString();
    5557    /** Replaces the content of the last line with m_strPromt + @p stringNewContent */
    56     void     replaceLineContent(const QString &stringNewContent);
     58    void        replaceLineContent(const QString &stringNewContent);
    5759    /** Get next/prev command from history. Return @p originalString if history is empty. */
    5860    QString     getNextCommandFromHistory(const QString &originalString = QString());
    5961    QString     getPreviousCommandFromHistory(const QString &originalString = QString());
    60     void        printCommandHistory() const;
    6162
    62     /** Stores the line number the edit cursor */
    63     unsigned m_uLineNumber;
    64     const QString m_strGreet;
    65     const QString m_strPrompt;
     63    const QString  m_strGreet;
     64    const QString  m_strPrompt;
    6665
    6766    /* A vector of entered commands */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp

    r71025 r71049  
    5858{
    5959    QString errorString;
    60     if(valueUnion.pDef)
    61     {
    62         if(valueUnion.pDef->pszLong)
    63         {
    64             errorString = QString(valueUnion.pDef->pszLong);
    65         }
    66     }
     60    // if (valueUnion.pDef)
     61    // {
     62    //     if (valueUnion.pDef->pszLong)
     63    //     {
     64    //         errorString = QString(valueUnion.pDef->pszLong);
     65    //     }
     66    // }
    6767
    6868    switch (getOptErrorCode)
     
    115115                "                                   [--ignore-operhaned-processes] [--profile]\n"
    116116                "                                   -- <program/arg0> [argument1] ... [argumentN]]\n"
    117                 "create                           [common-options]  [sessionname <name>]\n"
     117                "create                           [common-options]  [--sessionname <name>]\n"
    118118                )
    119119{
     
    246246    static const RTGETOPTDEF s_aOptions[] =
    247247    {
     248        GCTLCMD_COMMON_OPTION_DEFS()
    248249        { "--sessionname",      GCTLCMD_COMMON_OPT_SESSION_NAME,  RTGETOPT_REQ_STRING  }
    249250    };
     
    361362    if (sessionVector.isEmpty())
    362363        return false;
    363     for(int  i = 0; i < sessionVector.size(); ++i)
     364    for (int  i = 0; i < sessionVector.size(); ++i)
    364365    {
    365366        if (sessionVector.at(i).isOk() && sessionId == sessionVector.at(i).GetId())
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlTreeItem.cpp

    r71042 r71049  
    3030#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3131
    32 
     32QString sessionStatusString(KGuestSessionStatus status)
     33{
     34    QString statusString;
     35    switch (status)
     36    {
     37        case KGuestSessionStatus_Undefined:
     38            statusString = "Undefined";
     39            break;
     40        case KGuestSessionStatus_Starting:
     41            statusString = "Starting";
     42            break;
     43        case KGuestSessionStatus_Started:
     44            statusString = "Started";
     45            break;
     46        case KGuestSessionStatus_Terminating:
     47            statusString = "Terminating";
     48            break;
     49        case KGuestSessionStatus_Terminated:
     50            statusString = "Terminated";
     51            break;
     52        case KGuestSessionStatus_TimedOutKilled:
     53            statusString = "TimedOutKilled";
     54            break;
     55        case KGuestSessionStatus_TimedOutAbnormally:
     56            statusString = "TimedOutAbnormally";
     57            break;
     58        case KGuestSessionStatus_Down:
     59            statusString = "Down";
     60            break;
     61        case KGuestSessionStatus_Error:
     62            statusString = "Error";
     63            break;
     64        default:
     65            statusString = "Undefined";
     66            break;
     67    }
     68    return statusString;
     69}
     70
     71QString processStatusString(KProcessStatus status)
     72{
     73    QString statusString;
     74    switch (status)
     75    {
     76        case KProcessStatus_Undefined:
     77            statusString = "Undefined";
     78            break;
     79        case KProcessStatus_Starting:
     80            statusString = "Starting";
     81            break;
     82        case KProcessStatus_Started:
     83            statusString = "Started";
     84            break;
     85        case KProcessStatus_Paused:
     86            statusString = "Terminating";
     87            break;
     88        case KProcessStatus_Terminating:
     89            statusString = "Terminating";
     90            break;
     91        case KProcessStatus_TerminatedNormally:
     92            statusString = "TerminatedNormally";
     93            break;
     94        case KProcessStatus_TerminatedSignal:
     95            statusString = "TerminatedSignal";
     96            break;
     97        case KProcessStatus_TerminatedAbnormally:
     98            statusString = "TerminatedAbnormally";
     99            break;
     100        case KProcessStatus_TimedOutKilled:
     101            statusString = "TimedOutKilled";
     102            break;
     103        case KProcessStatus_TimedOutAbnormally:
     104            statusString = "TimedOutAbnormally";
     105            break;
     106        case KProcessStatus_Down:
     107            statusString = "Down";
     108            break;
     109        case KProcessStatus_Error:
     110            statusString = "Error";
     111            break;
     112        default:
     113            break;
     114    }
     115    return statusString;
     116}
    33117/*********************************************************************************************************************************
    34118*   UIGuestControlTreeItem implementation.                                                                                       *
     
    53137void UIGuestControlTreeItem::prepare()
    54138{
     139    prepareListener();
    55140    prepareConnections();
    56     prepareConnections();
     141    setColumnText();
    57142}
    58143
    59144void UIGuestControlTreeItem::prepareListener(CEventSource comEventSource, QVector<KVBoxEventType>& eventTypes)
    60145{
    61     AssertWrapperOk(comEventSource);
    62 
     146    if (!comEventSource.isOk())
     147        return;
    63148    /* Create event listener instance: */
    64149    m_pQtListener.createObject();
     
    69154    comEventSource.RegisterListener(m_comEventListener, eventTypes,
    70155        gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
    71     AssertWrapperOk(comEventSource);
    72156
    73157    /* If event listener registered as passive one: */
     
    81165void UIGuestControlTreeItem::cleanupListener(CEventSource comEventSource)
    82166{
    83     AssertWrapperOk(comEventSource);
     167    if (!comEventSource.isOk())
     168        return;
    84169    /* If event listener registered as passive one: */
    85170    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     
    116201{
    117202    prepare();
     203
    118204}
    119205
     
    123209}
    124210
     211const CGuestSession& UIGuestSessionTreeItem::guestSession() const
     212{
     213    return m_comGuestSession;
     214}
     215
    125216void UIGuestSessionTreeItem::prepareConnections()
    126217{
    127218    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
    128             this, &UIGuestSessionTreeItem::sltGuestSessionUpdated);
     219            this, &UIGuestSessionTreeItem::sltGuestSessionUpdated, Qt::DirectConnection);
    129220    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessRegistered,
    130             this, &UIGuestSessionTreeItem::sltGuestProcessRegistered);
     221            this, &UIGuestSessionTreeItem::sltGuestProcessRegistered, Qt::DirectConnection);
    131222    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessUnregistered,
    132             this, &UIGuestSessionTreeItem::sltGuestProcessUnregistered);
     223            this, &UIGuestSessionTreeItem::sltGuestProcessUnregistered, Qt::DirectConnection);
    133224}
    134225
     
    149240void UIGuestSessionTreeItem::sltGuestSessionUpdated()
    150241{
     242    setColumnText();
     243    emit sigGuessSessionUpdated();
    151244}
    152245
    153246void UIGuestSessionTreeItem::sltGuestProcessRegistered(CGuestProcess guestProcess)
    154247{
    155 
     248    if (!guestProcess.isOk())
     249        return;
     250    QStringList strList;
     251    strList
     252        << QString("PID: %1").arg(guestProcess.GetPID())
     253        << QString("Process Name: %1").arg(guestProcess.GetName())
     254        << QString("Process Status: %1").arg(processStatusString(guestProcess.GetStatus()));
     255    /*UIGuestProcessTreeItem *newItem = */new UIGuestProcessTreeItem(this, guestProcess, strList);
    156256}
    157257
    158258void UIGuestSessionTreeItem::sltGuestProcessUnregistered(CGuestProcess guestProcess)
    159259{
    160 }
    161 
     260    for (int i = 0; i < childCount(); ++i)
     261    {
     262        UIGuestProcessTreeItem* item = dynamic_cast<UIGuestProcessTreeItem*>(child(i));
     263        if (item && item->guestProcess() == guestProcess)
     264        {
     265            delete item;
     266            break;
     267        }
     268    }
     269}
     270
     271void UIGuestSessionTreeItem::setColumnText()
     272{
     273    if (!m_comGuestSession.isOk())
     274        return;
     275    setText(0, QString("Session Id: %1").arg(m_comGuestSession.GetId()));
     276    setText(1, QString("Session Name: %1").arg(m_comGuestSession.GetName()));
     277    setText(2, QString("Session Status: %1").arg(sessionStatusString(m_comGuestSession.GetStatus())));
     278}
    162279
    163280/*********************************************************************************************************************************
     
    183300{
    184301    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessStateChanged,
    185             this, &UIGuestProcessTreeItem::sltGuestProcessUpdated);
     302            this, &UIGuestProcessTreeItem::sltGuestProcessUpdated, Qt::DirectConnection);
    186303}
    187304
     
    208325void UIGuestProcessTreeItem::sltGuestProcessUpdated()
    209326{
    210 }
     327    setColumnText();
     328}
     329
     330 void UIGuestProcessTreeItem::setColumnText()
     331{
     332    if (!m_comGuestProcess.isOk())
     333        return;
     334    setText(0, QString("PID: %1").arg(m_comGuestProcess.GetPID()));
     335    setText(1, QString("Process Name: %1").arg(m_comGuestProcess.GetName()));
     336    setText(2, QString("Process Status: %1").arg(processStatusString(m_comGuestProcess.GetStatus())));
     337
     338}
     339
     340const CGuestProcess& UIGuestProcessTreeItem::guestProcess() const
     341{
     342    return m_comGuestProcess;
     343}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlTreeItem.h

    r71038 r71049  
    3737signals:
    3838
     39    void sigGuessSessionUpdated();
     40
    3941public:
    4042
     
    5961    virtual void prepareConnections() = 0;
    6062    virtual void cleanupListener() = 0;
     63    virtual void setColumnText() = 0;
    6164
    6265    /** Holds the COM event listener instance. */
     
    7477    UIGuestSessionTreeItem(UIGuestControlTreeItem *pTreeWidgetItem, CGuestSession& guestSession, const QStringList &strings = QStringList());
    7578    virtual ~UIGuestSessionTreeItem();
     79    const CGuestSession& guestSession() const;
    7680
    7781protected:
     
    9195    virtual void prepareConnections() /* override */;
    9296    virtual void cleanupListener()  /* override */;
     97    virtual void setColumnText()  /* override */;
    9398
    9499    CGuestSession m_comGuestSession;
     
    104109    UIGuestProcessTreeItem(QITreeWidget *pTreeWidget, CGuestProcess& guestProcess, const QStringList &strings = QStringList());
    105110    UIGuestProcessTreeItem(UIGuestControlTreeItem *pTreeWidgetItem, CGuestProcess& guestProcess, const QStringList &strings = QStringList());
     111    const CGuestProcess& guestProcess() const;
    106112    virtual ~UIGuestProcessTreeItem();
    107113
     
    121127    virtual void prepareConnections() /* override */;
    122128    virtual void cleanupListener()  /* override */;
     129    virtual void setColumnText()  /* override */;
    123130
    124131    CGuestProcess m_comGuestProcess;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIInformationGuestSession.cpp

    r71038 r71049  
    2222/* Qt includes: */
    2323# include <QApplication>
     24# include <QSplitter>
    2425# include <QVBoxLayout>
    25 # include <QSplitter>
     26
    2627
    2728/* GUI includes: */
     
    3233# include "UIGuestControlTreeItem.h"
    3334# include "UIInformationGuestSession.h"
    34 
     35# include "UIVMInformationDialog.h"
    3536# include "VBoxGlobal.h"
    3637
     
    4041
    4142#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     43
     44class UIGuestControlTreeWidget : public QITreeWidget
     45{
     46
     47    Q_OBJECT;
     48
     49signals:
     50
     51    void sigCloseSessionOrProcess();
     52
     53public:
     54
     55    UIGuestControlTreeWidget(QWidget *pParent = 0)
     56        :QITreeWidget(pParent)
     57    {
     58        setSelectionMode(QAbstractItemView::SingleSelection);
     59    }
     60
     61    UIGuestControlTreeItem *selectedItem()
     62    {
     63        QList<QTreeWidgetItem*> selectedList = selectedItems();
     64        if (selectedList.isEmpty())
     65            return 0;
     66        UIGuestControlTreeItem *item =
     67            dynamic_cast<UIGuestControlTreeItem*>(selectedList[0]);
     68        /* Return the firstof the selected items */
     69        return item;
     70    }
     71
     72protected:
     73
     74    void contextMenuEvent(QContextMenuEvent *pEvent) /* override */
     75    {
     76        QList<QTreeWidgetItem *> selectedList = selectedItems();
     77        if (selectedList.isEmpty())
     78            return;
     79        /* Always use the 0th item even if we have a multiple selection. */
     80        UIGuestSessionTreeItem *sessionTreeItem = dynamic_cast<UIGuestSessionTreeItem*>(selectedList[0]);
     81        /* Create a guest session related context menu */
     82        if (sessionTreeItem)
     83        {
     84            QMenu *menu = new QMenu(this);
     85            QAction *pAction = menu->addAction(UIVMInformationDialog::tr("Close Session"));
     86
     87            if (pAction)
     88                connect(pAction, &QAction::triggered,
     89                        this, &UIGuestControlTreeWidget::sigCloseSessionOrProcess);
     90
     91            menu->exec(pEvent->globalPos());
     92
     93            if (pAction)
     94                disconnect(pAction, &QAction::triggered,
     95                        this, &UIGuestControlTreeWidget::sigCloseSessionOrProcess);
     96
     97            delete menu;
     98            return;
     99        }
     100        UIGuestProcessTreeItem *processTreeItem = dynamic_cast<UIGuestProcessTreeItem*>(selectedList[0]);
     101        if (!processTreeItem)
     102            return;
     103        /* Create a guest process tree item */
     104        QMenu *menu = new QMenu(this);
     105        QAction *pAction = menu->addAction(UIVMInformationDialog::tr("Terminate Process"));
     106        if (pAction)
     107            connect(pAction, &QAction::triggered,
     108                    this, &UIGuestControlTreeWidget::sigCloseSessionOrProcess);
     109        menu->exec(pEvent->globalPos());
     110
     111        if (pAction)
     112            disconnect(pAction, &QAction::triggered,
     113                    this, &UIGuestControlTreeWidget::sigCloseSessionOrProcess);
     114        delete menu;
     115
     116    }
     117
     118};
    42119
    43120UIInformationGuestSession::UIInformationGuestSession(QWidget *pParent, const CGuest &comGuest)
     
    62139    /* Create layout: */
    63140    m_pMainLayout = new QVBoxLayout(this);
    64     if(!m_pMainLayout)
     141    if (!m_pMainLayout)
    65142        return;
    66143
     
    70147    m_pSplitter = new QSplitter;
    71148
    72     if(!m_pSplitter)
     149    if (!m_pSplitter)
    73150        return;
    74151
     
    78155
    79156
    80     m_pTreeWidget = new QITreeWidget;
     157    m_pTreeWidget = new UIGuestControlTreeWidget;
    81158
    82159    if (m_pTreeWidget)
     160    {
    83161        m_pSplitter->addWidget(m_pTreeWidget);
    84 
     162        m_pTreeWidget->setColumnCount(3);
     163    }
    85164    m_pConsole = new UIGuestControlConsole;
    86     if(m_pConsole)
     165    if (m_pConsole)
    87166    {
    88167        m_pSplitter->addWidget(m_pConsole);
     
    108187void UIInformationGuestSession::prepareConnections()
    109188{
     189    qRegisterMetaType<QVector<int> >();
    110190    connect(m_pControlInterface, &UIGuestControlInterface::sigOutputString,
    111191            this, &UIInformationGuestSession::sltConsoleOutputReceived);
    112192    connect(m_pConsole, &UIGuestControlConsole::commandEntered,
    113193            this, &UIInformationGuestSession::sltConsoleCommandEntered);
    114     if(m_pQtListener)
     194
     195    if (m_pTreeWidget)
     196        connect(m_pTreeWidget, &UIGuestControlTreeWidget::sigCloseSessionOrProcess,
     197                this, &UIInformationGuestSession::sltCloseSessionOrProcess);
     198
     199    if (m_pQtListener)
    115200    {
    116201        connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
     
    128213void UIInformationGuestSession::sltConsoleCommandEntered(const QString &strCommand)
    129214{
    130     if(m_pControlInterface)
     215    if (m_pControlInterface)
    131216    {
    132217        m_pControlInterface->putCommand(strCommand);
     
    136221void UIInformationGuestSession::sltConsoleOutputReceived(const QString &strOutput)
    137222{
    138     if(m_pConsole)
     223    if (m_pConsole)
    139224    {
    140225        m_pConsole->putOutput(strOutput);
    141226    }
     227}
     228
     229void UIInformationGuestSession::sltCloseSessionOrProcess()
     230{
     231    if (!m_pTreeWidget)
     232        return;
     233    UIGuestControlTreeItem *selectedTreeItem =
     234        m_pTreeWidget->selectedItem();
     235    if (!selectedTreeItem)
     236        return;
     237    UIGuestProcessTreeItem *processTreeItem =
     238        dynamic_cast<UIGuestProcessTreeItem*>(selectedTreeItem);
     239    if (processTreeItem)
     240    {
     241        CGuestProcess guestProcess = processTreeItem->guestProcess();
     242        if (guestProcess.isOk())
     243        {
     244            guestProcess.Terminate();
     245        }
     246        return;
     247    }
     248    UIGuestSessionTreeItem *sessionTreeItem =
     249        dynamic_cast<UIGuestSessionTreeItem*>(selectedTreeItem);
     250    if (!sessionTreeItem)
     251        return;
     252    CGuestSession guestSession = sessionTreeItem->guestSession();
     253    if (!guestSession.isOk())
     254        return;
     255    guestSession.Close();
    142256}
    143257
     
    198312        return;
    199313
    200     new UIGuestSessionTreeItem(m_pTreeWidget, guestSession);
    201     //printf("sltGuestSessionRegistered \n");
    202     // addGuestSession(guestSession);
    203     // emit sigGuestSessionUpdated();
     314    UIGuestSessionTreeItem* sessionTreeItem = new UIGuestSessionTreeItem(m_pTreeWidget, guestSession);
     315    connect(sessionTreeItem, &UIGuestSessionTreeItem::sigGuessSessionUpdated,
     316            this, &UIInformationGuestSession::sltTreeItemUpdated);
     317}
     318
     319void UIInformationGuestSession::sltTreeItemUpdated()
     320{
     321    if (m_pTreeWidget)
     322        m_pTreeWidget->update();
    204323}
    205324
     
    208327    if (!guestSession.isOk())
    209328        return;
    210     // removeGuestSession(guestSession);
    211     // emit sigGuestSessionUpdated();
    212 }
     329    if (!m_pTreeWidget)
     330        return;
     331
     332    UIGuestSessionTreeItem *selectedItem = NULL;
     333
     334
     335    for (int i = 0; i < m_pTreeWidget->topLevelItemCount(); ++i)
     336    {
     337        QTreeWidgetItem *item = m_pTreeWidget->topLevelItem( i );
     338
     339        UIGuestSessionTreeItem *treeItem = dynamic_cast<UIGuestSessionTreeItem*>(item);
     340        if (treeItem && treeItem->guestSession() == guestSession)
     341        {
     342            selectedItem = treeItem;
     343            break;
     344        }
     345    }
     346    delete selectedItem;
     347}
     348
     349#include "UIInformationGuestSession.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIInformationGuestSession.h

    r71038 r71049  
    3737class UIGuestControlInterface;
    3838class UIGuestSessionsEventHandler;
    39 
    40 
     39class UIGuestControlTreeWidget;
    4140
    4241/** QWidget extension
     
    4544{
    4645    Q_OBJECT;
    47 
    48 signals:
    4946
    5047public:
     
    6158    void sltGuestSessionUnregistered(CGuestSession guestSession);
    6259
     60    void sltTreeItemUpdated();
     61    void sltCloseSessionOrProcess();
     62
    6363private:
    6464
     
    6868    void updateTreeWidget();
    6969    void cleanupListener();
    70     CGuest                   m_comGuest;
    71     QVBoxLayout             *m_pMainLayout;
    72     QSplitter               *m_pSplitter;
    73     QITreeWidget            *m_pTreeWidget;
    74     UIGuestControlConsole   *m_pConsole;
    75     UIGuestControlInterface *m_pControlInterface;
     70    CGuest                    m_comGuest;
     71    QVBoxLayout              *m_pMainLayout;
     72    QSplitter                *m_pSplitter;
     73    UIGuestControlTreeWidget *m_pTreeWidget;
     74    UIGuestControlConsole    *m_pConsole;
     75    UIGuestControlInterface  *m_pControlInterface;
    7676
    7777    /** Holds the Qt event listener instance. */
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