VirtualBox

Changeset 71169 in vbox


Ignore:
Timestamp:
Mar 2, 2018 9:54:36 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:6699 Replace file tree with a file table

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
7 edited
2 copied

Legend:

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

    r71133 r71169  
    378378        src/runtime/information/guestctrl/UIGuestControlConsole.h \
    379379        src/runtime/information/guestctrl/UIGuestControlFileManager.h \
     380        src/runtime/information/guestctrl/UIGuestControlFileTable.h \
    380381        src/runtime/information/guestctrl/UIGuestControlFileTree.h \
    381382        src/runtime/information/guestctrl/UIGuestControlInterface.h \
     
    568569        src/runtime/UIStatusBarEditorWindow.cpp \
    569570        src/runtime/information/guestctrl/UIGuestControlFileManager.cpp \
    570         src/runtime/information/guestctrl/UIGuestControlFileTree.cpp \
    571571        src/runtime/information/guestctrl/UIGuestControlWidget.cpp \
    572572        src/selector/UIActionPoolSelector.cpp \
     
    712712        src/runtime/information/guestctrl/UIGuestControlConsole.cpp \
    713713        src/runtime/information/guestctrl/UIGuestControlFileManager.cpp \
     714        src/runtime/information/guestctrl/UIGuestControlFileTable.cpp \
    714715        src/runtime/information/guestctrl/UIGuestControlFileTree.cpp \
    715716        src/runtime/information/guestctrl/UIGuestControlInterface.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.cpp

    r71145 r71169  
    2323# include <QAbstractItemModel>
    2424# include <QHBoxLayout>
     25# include <QHeaderView>
    2526# include <QPlainTextEdit>
    2627# include <QPushButton>
    2728# include <QSplitter>
    28 # include <QVBoxLayout>
     29# include <QGridLayout>
    2930
    3031/* GUI includes: */
     
    3435# include "UIExtraDataManager.h"
    3536# include "UIGuestControlFileManager.h"
     37# include "UIGuestControlFileTable.h"
    3638# include "UIGuestControlFileTree.h"
     39# include "UIGuestControlInterface.h"
    3740# include "UIVMInformationDialog.h"
    3841# include "VBoxGlobal.h"
    3942
    4043/* COM includes: */
     44# include "CFsObjInfo.h"
    4145# include "CGuest.h"
    4246# include "CGuestDirectory.h"
     47# include "CGuestFsObjInfo.h"
     48# include "CGuestProcess.h"
     49# include "CGuestSession.h"
    4350# include "CGuestSessionStateChangedEvent.h"
     51
     52
     53
     54
     55
    4456
    4557#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    206218UIGuestControlFileManager::UIGuestControlFileManager(QWidget *pParent, const CGuest &comGuest)
    207219    : QWidget(pParent)
     220    , m_iMaxRecursionDepth(1)
    208221    , m_comGuest(comGuest)
    209222    , m_pMainLayout(0)
    210     , m_pSplitter(0)
    211     , m_pSessionCreateWidget(0)
     223    , m_pVerticalSplitter(0)
    212224    , m_pLogOutput(0)
    213225    , m_pGuestFileTree(0)
     226    , m_pSessionCreateWidget(0)
     227    , m_pGuestFileTable(0)
    214228{
    215229    prepareGuestListener();
     
    248262    m_pMainLayout->setSpacing(0);
    249263
    250 
    251264    m_pSessionCreateWidget = new UIGuestSessionCreateWidget();
    252265    if (m_pSessionCreateWidget)
    253266    {
    254         m_pMainLayout->addWidget(m_pSessionCreateWidget, 0, Qt::AlignTop);
    255     }
    256 
    257     m_pSplitter = new QSplitter;
    258     if (m_pSplitter)
    259     {
    260         m_pMainLayout->addWidget(m_pSplitter);
    261         m_pSplitter->setOrientation(Qt::Vertical);
    262     }
    263 
    264     m_pGuestFileTree = new UIGuestControlFileTree;
    265     if (m_pGuestFileTree)
    266     {
    267         m_pSplitter->addWidget(m_pGuestFileTree);
     267        m_pMainLayout->addWidget(m_pSessionCreateWidget);
     268    }
     269
     270    m_pVerticalSplitter = new QSplitter;
     271    if (m_pVerticalSplitter)
     272    {
     273        m_pMainLayout->addWidget(m_pVerticalSplitter);
     274        m_pVerticalSplitter->setOrientation(Qt::Vertical);
     275        m_pVerticalSplitter->setHandleWidth(1);
     276    }
     277
     278    m_pGuestFileTable = new UIGuestFileTable;
     279    if (m_pGuestFileTable)
     280    {
     281        m_pVerticalSplitter->addWidget(m_pGuestFileTable);
    268282    }
    269283
     
    271285    if (m_pLogOutput)
    272286    {
     287        //m_pLogOutput->setMaximumHeight(80);
    273288        m_pLogOutput->setReadOnly(true);
    274         m_pMainLayout->addWidget(m_pLogOutput, 0, Qt::AlignBottom);
    275     }
    276 
    277     // m_pSplitter->setStretchFactor(0, 9);
    278     // m_pSplitter->setStretchFactor(1, 4);
     289        m_pVerticalSplitter->addWidget(m_pLogOutput);
     290    }
     291
     292
     293    //m_pGuestFileTree = new UIGuestControlFileTree;
     294    if (m_pGuestFileTree)
     295    {
     296        //m_pMainLayout->addWidget(m_pGuestFileTree, 1, 0, 4 /*rowSpan*/, 1 /*columnSpan*/);
     297
     298        m_pGuestFileTree->setColumnCount(1);
     299
     300        m_pGuestFileTree->header()->hide();
     301    }
     302    //
     303
     304
     305    m_pVerticalSplitter->setStretchFactor(0, 9);
     306    m_pVerticalSplitter->setStretchFactor(1, 4);
    279307}
    280308
     
    293321                this, &UIGuestControlFileManager::sltCloseSession);
    294322    }
     323    if (m_pGuestFileTree)
     324    {
     325
     326        connect(m_pGuestFileTree, &UIGuestControlFileTree::itemEntered,
     327                this, &UIGuestControlFileManager::sltTreeItemEntered);
     328        connect(m_pGuestFileTree, &UIGuestControlFileTree::itemExpanded,
     329                this, &UIGuestControlFileManager::sltTreeItemExpanded);
     330        connect(m_pGuestFileTree, &UIGuestControlFileTree::itemClicked,
     331                this, &UIGuestControlFileManager::sltTreeItemClicked);
     332
     333    }
     334}
     335
     336void UIGuestControlFileManager::sltTreeItemEntered(QTreeWidgetItem * item, int column)
     337{
     338}
     339
     340void UIGuestControlFileManager::sltTreeItemExpanded(QTreeWidgetItem * item)
     341{
     342    UIGuestControlFileTreeItem *treeItem = dynamic_cast<UIGuestControlFileTreeItem*>(item);
     343    if(!treeItem)
     344        return;
     345    openSubTree(treeItem);
     346    const QList<UIGuestControlFileTreeItem*> children = treeItem->children();
     347    for(int i = 0; i < children.size(); ++i)
     348        openSubTree(children[i]);
     349}
     350
     351void UIGuestControlFileManager::openSubTree(UIGuestControlFileTreeItem*treeItem)
     352{
     353    /* Continue only for not-yet-opened directories: */
     354    if((treeItem->isDirectory() && treeItem->isOpened())
     355       || !treeItem->isDirectory())
     356        return;
     357    readDirectory(treeItem->path(), treeItem, treeItem->depth(), m_iMaxRecursionDepth);
     358    if(m_pGuestFileTree)
     359        m_pGuestFileTree->update();
     360}
     361
     362void UIGuestControlFileManager::sltTreeItemClicked(QTreeWidgetItem * item, int column)
     363{
    295364}
    296365
     
    334403void UIGuestControlFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
    335404{
    336     //if (cEvent.isOk() && m_comGuestSession.isOk())// && m_comGuestProcess.GetStatus() == KProcessStatus_Error)
     405    if (cEvent.isOk() && m_comGuestSession.isOk())// && m_comGuestProcess.GetStatus() == KProcessStatus_Error)
    337406    {
    338407        CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
    339408        if (cErrorInfo.isOk())// && cErrorInfo.GetResultCode() != S_OK)
    340409        {
    341     //         /* For some reason I am yet to find this emit is not working.
    342     //            Thus we are calling the parent's function directly: */
    343     //         //emit sigGuestProcessErrorText(cErrorInfo.GetText());
    344     //         UIGuestSessionTreeItem *sessionParent = dynamic_cast<UIGuestSessionTreeItem*>(QTreeWidgetItem::parent());
    345     //         if (sessionParent)
    346     //         {
    347     //             sessionParent->errorString(cErrorInfo.GetText().toStdString().c_str());
    348     //         }
    349410            m_pLogOutput->appendPlainText(cErrorInfo.GetText());
    350411        }
    351412    }
    352 
    353413    if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started)
    354414    {
    355 
    356         QVector<KDirectoryOpenFlag> flag;
    357         flag.push_back(KDirectoryOpenFlag_None);
    358         CGuestDirectory directory = m_comGuestSession.DirectoryOpen("c:/", "*", flag);
    359         if(directory.isOk())
     415        //initFileTree();
     416        initFileTable();
     417    }
     418    else
     419    {
     420        m_pGuestFileTree->clear();
     421        m_pLogOutput->appendPlainText("Session status has changed");
     422    }
     423}
     424
     425void UIGuestControlFileManager::initFileTable()
     426{
     427    if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
     428        return;
     429    if (!m_pGuestFileTable)
     430        return;
     431    m_pGuestFileTable->initGuestFileTable(m_comGuestSession);
     432}
     433
     434void UIGuestControlFileManager::initFileTree()
     435{
     436    if (!m_comGuestSession.isOk() || m_comGuestSession.GetStatus() != KGuestSessionStatus_Started)
     437        return;
     438    if (!m_pGuestFileTree)
     439        return;
     440    m_pGuestFileTree->clear();
     441    QString rootPath("/");
     442
     443
     444
     445    CGuestFsObjInfo fsObjectInfo = m_comGuestSession.FsObjQueryInfo(rootPath, false /*BOOL aFollowSymlinks*/);
     446    if (!fsObjectInfo.isOk())
     447    {
     448        m_pLogOutput->appendPlainText("Cannot get file object info");
     449        return;
     450    }
     451    const QStringList &strList = getFsObjInfoStringList<CGuestFsObjInfo>(fsObjectInfo);
     452
     453    UIGuestControlFileTreeItem *rootItem = new UIGuestControlFileTreeItem(m_pGuestFileTree, 0, rootPath, strList);
     454    rootItem->setIsDirectory(true);
     455    rootItem->setIcon(0, QIcon(":/sf_32px.png"));
     456    rootItem->setIsOpened(false);
     457    rootItem->setExpanded(true);
     458
     459    readDirectory(rootPath, rootItem, rootItem->depth(), m_iMaxRecursionDepth);
     460    if(m_pGuestFileTree)
     461        m_pGuestFileTree->update();
     462}
     463
     464void UIGuestControlFileManager::readDirectory(const QString& strPath,
     465                                              UIGuestControlFileTreeItem* treeParent,
     466                                              const int &startDepth,
     467                                              int iMaxDepth)
     468{
     469    if (!treeParent || treeParent->depth() - startDepth >= iMaxDepth || strPath.isEmpty())
     470        return;
     471    QVector<KDirectoryOpenFlag> flag;
     472    flag.push_back(KDirectoryOpenFlag_None);
     473    CGuestDirectory directory;
     474    directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag);
     475    treeParent->setIsOpened(true);
     476    if (directory.isOk())
     477    {
     478        CFsObjInfo fsInfo = directory.Read();
     479        while (fsInfo.isOk())
    360480        {
    361             m_pLogOutput->appendPlainText("Current Directory");
    362             m_pLogOutput->appendPlainText(directory.GetDirectoryName());
     481            if (fsInfo.GetName() != "."
     482                && fsInfo.GetName() != "..")
     483            {
     484                QString path(strPath);
     485                if (path.at(path.length() -1 ) != '/')
     486                    path.append(QString("/").append(fsInfo.GetName()));
     487                else
     488                    path.append(fsInfo.GetName());
     489                UIGuestControlFileTreeItem *treeItem =
     490                    new UIGuestControlFileTreeItem(treeParent, treeParent->depth() + 1 /*depth */,
     491                                                   path, getFsObjInfoStringList<CFsObjInfo>(fsInfo));
     492                if (fsInfo.GetType() == KFsObjType_Directory)
     493                {
     494                    treeItem->setIsDirectory(true);
     495                    treeItem->setIcon(0, QIcon(":/sf_32px.png"));
     496                    treeItem->setIsOpened(false);
     497                    readDirectory(path, treeItem, startDepth, iMaxDepth);
     498                }
     499                else
     500                {
     501                    treeItem->setIsDirectory(false);
     502                    treeItem->setIsOpened(false);
     503                    treeItem->setIcon(0, QIcon(":/vm_open_filemanager_16px"));
     504                    treeItem->setHidden(true);
     505                }
     506            }
     507
     508            fsInfo = directory.Read();
    363509        }
    364     }
    365 
    366 }
    367 
     510        directory.Close();
     511    }
     512}
    368513
    369514bool UIGuestControlFileManager::createSession(const QString& strUserName, const QString& strPassword,
     
    453598}
    454599
     600template<typename T>
     601QStringList   UIGuestControlFileManager::getFsObjInfoStringList(const T &fsObjectInfo) const
     602{
     603    QStringList objectInfo;
     604    if (!fsObjectInfo.isOk())
     605        return objectInfo;
     606
     607    //objectInfo << QString(UIGuestControlInterface::getFsObjTypeString(fsObjectInfo.GetType()).append("\t"));
     608    objectInfo << fsObjectInfo.GetName();
     609    //objectInfo << QString::number(fsObjectInfo.GetObjectSize());
     610
     611    /* Currently I dont know a way to convert these into a meaningful date/time: */
     612    // strObjectInfo.append("BirthTime", QString::number(fsObjectInfo.GetBirthTime()));
     613    // strObjectInfo.append("ChangeTime", QString::number(fsObjectInfo.GetChangeTime()));
     614
     615    return objectInfo;
     616}
     617
    455618#include "UIGuestControlFileManager.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.h

    r71133 r71169  
    3333
    3434/* Forward declarations: */
    35 class CGuestSessionStateChangedEvent;
    36 class QITreeView;
    3735class QPlainTextEdit;
    3836class QVBoxLayout;
    3937class QSplitter;
    40 class UIFileListModel;
     38class QTreeWidgetItem;
     39class CGuestSessionStateChangedEvent;
     40class QITreeView;
     41class UIGuestFileTable;
    4142class UIGuestControlFileTree;
     43class UIGuestControlFileTreeItem;
    4244class UIGuestSessionCreateWidget;
    4345
     
    6062    void sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent);
    6163
     64    void sltTreeItemEntered(QTreeWidgetItem *item, int column);
     65    void sltTreeItemExpanded(QTreeWidgetItem *item);
     66    void sltTreeItemClicked(QTreeWidgetItem *item, int column);
     67
    6268private:
    6369
     
    7581                         CEventListener &comEventListener,
    7682                         CEventSource comEventSource);
     83    void initFileTree();
     84    void initFileTable();
     85    void openSubTree(UIGuestControlFileTreeItem *item);
    7786
     87    template<typename T>
     88    QStringList   getFsObjInfoStringList(const T &fsObjectInfo) const;
     89
     90    void readDirectory(const QString& strPath,
     91                       UIGuestControlFileTreeItem* treeParent,
     92                       const int &startDepth,
     93                       int iMaxDepth);
     94
     95
     96    const int         m_iMaxRecursionDepth;
    7897    CGuest            m_comGuest;
    7998    CGuestSession     m_comGuestSession;
    8099
    81100    QVBoxLayout      *m_pMainLayout;
    82     QSplitter        *m_pSplitter;
    83     UIGuestSessionCreateWidget        *m_pSessionCreateWidget;
     101    QSplitter        *m_pVerticalSplitter;
    84102    QPlainTextEdit   *m_pLogOutput;
    85     UIGuestControlFileTree* m_pGuestFileTree;
     103
     104    UIGuestControlFileTree*     m_pGuestFileTree;
     105    UIGuestSessionCreateWidget *m_pSessionCreateWidget;
     106    UIGuestFileTable           *m_pGuestFileTable;
    86107
    87108    ComObjPtr<UIMainEventListenerImpl> m_pQtGuestListener;
    88     CEventListener m_comGuestListener;
    89 
    90109    ComObjPtr<UIMainEventListenerImpl> m_pQtSessionListener;
    91110    CEventListener m_comSessionListener;
    92 
     111    CEventListener m_comGuestListener;
    93112};
    94113
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp

    r71135 r71169  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIGuestControlFileTree class implementation.
     3 * VBox Qt GUI - UIGuestControlFileTable class implementation.
    44 */
    55
     
    2626// # include <QPushButton>
    2727// # include <QSplitter>
    28 // # include <QVBoxLayout>
     28# include <QHeaderView>
     29# include <QVBoxLayout>
    2930
    3031/* GUI includes: */
     
    3334// # include "QIWithRetranslateUI.h"
    3435// # include "UIExtraDataManager.h"
    35 # include "UIGuestControlFileTree.h"
     36# include "UIGuestControlFileTable.h"
    3637// # include "UIVMInformationDialog.h"
    3738// # include "VBoxGlobal.h"
     
    3940/* COM includes: */
    4041// # include "CGuest.h"
     42# include "CFsObjInfo.h"
     43# include "CGuestDirectory.h"
    4144// # include "CGuestSessionStateChangedEvent.h"
    4245
    4346#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4447
    45 class UIGuestControlFileTreeItem : public QITreeWidgetItem
    46 {
    47     Q_OBJECT;
    48 
     48
     49
     50class UIFileTableItem
     51{
    4952public:
    50     UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget, const QStringList &strings = QStringList());
    51     UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem, const QStringList &strings = QStringList());
    52     virtual ~UIGuestControlFileTreeItem();
    53 
     53    explicit UIFileTableItem(const QList<QVariant> &data, UIFileTableItem *parentItem = 0);
     54    ~UIFileTableItem();
     55
     56    void appendChild(UIFileTableItem *child);
     57
     58    UIFileTableItem *child(int row);
     59    int childCount() const;
     60    int columnCount() const;
     61    QVariant data(int column) const;
     62    int row() const;
     63    UIFileTableItem *parentItem();
     64
     65private:
     66    QList<UIFileTableItem*> m_childItems;
     67    QList<QVariant> m_itemData;
     68    UIFileTableItem *m_parentItem;
    5469};
    5570
    56 UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget, const QStringList &strings /* = QStringList() */)
    57     :QITreeWidgetItem(pTreeWidget, strings)
    58 
    59 {
    60 }
    61 UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem, const QStringList &strings /*= QStringList() */)
    62     :QITreeWidgetItem(pTreeWidgetItem, strings)
    63 {
    64 }
    65 
    66 UIGuestControlFileTreeItem::~UIGuestControlFileTreeItem(){}
    67 
    68 #include "UIGuestControlFileTree.moc"
     71
     72UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, UIFileTableItem *parent)
     73{
     74    m_parentItem = parent;
     75    m_itemData = data;
     76}
     77
     78UIFileTableItem::~UIFileTableItem()
     79{
     80    qDeleteAll(m_childItems);
     81}
     82
     83void UIFileTableItem::appendChild(UIFileTableItem *item)
     84{
     85    m_childItems.append(item);
     86}
     87
     88UIFileTableItem *UIFileTableItem::child(int row)
     89{
     90    return m_childItems.value(row);
     91}
     92
     93int UIFileTableItem::childCount() const
     94{
     95    return m_childItems.count();
     96}
     97
     98int UIFileTableItem::columnCount() const
     99{
     100    return m_itemData.count();
     101}
     102
     103QVariant UIFileTableItem::data(int column) const
     104{
     105    return m_itemData.value(column);
     106}
     107
     108UIFileTableItem *UIFileTableItem::parentItem()
     109{
     110    return m_parentItem;
     111}
     112
     113int UIFileTableItem::row() const
     114{
     115    if (m_parentItem)
     116        return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this));
     117
     118    return 0;
     119}
     120
     121
     122
     123UIGuestControlFileModel::UIGuestControlFileModel(QObject *parent)
     124    : QAbstractItemModel(parent)
     125    , m_pParent(qobject_cast<UIGuestControlFileTable*>(parent))
     126{
     127    QList<QVariant> rootData;
     128    // rootData << "Title" << "Summary";
     129    // rootItem = new UIFileTableItem(rootData);
     130}
     131
     132UIFileTableItem* UIGuestControlFileModel::rootItem() const
     133{
     134    if (!m_pParent)
     135        return 0;
     136    return m_pParent->m_pRootItem;
     137}
     138
     139UIGuestControlFileModel::~UIGuestControlFileModel()
     140{
     141    //delete rootItem;
     142}
     143
     144int UIGuestControlFileModel::columnCount(const QModelIndex &parent) const
     145{
     146    if (parent.isValid())
     147        return static_cast<UIFileTableItem*>(parent.internalPointer())->columnCount();
     148    else
     149    {
     150        if (!rootItem())
     151            return 0;
     152        else
     153            return rootItem()->columnCount();
     154    }
     155}
     156
     157QVariant UIGuestControlFileModel::data(const QModelIndex &index, int role) const
     158{
     159    if (!index.isValid())
     160        return QVariant();
     161
     162    if (role != Qt::DisplayRole)
     163        return QVariant();
     164
     165    UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     166
     167    return item->data(index.column());
     168}
     169
     170Qt::ItemFlags UIGuestControlFileModel::flags(const QModelIndex &index) const
     171{
     172    if (!index.isValid())
     173        return 0;
     174
     175    return QAbstractItemModel::flags(index);
     176}
     177
     178QVariant UIGuestControlFileModel::headerData(int section, Qt::Orientation orientation,
     179                               int role) const
     180{
     181    if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
     182    {
     183        if (!rootItem())
     184            return QVariant();
     185        else
     186            return rootItem()->data(section);
     187    }
     188    return QVariant();
     189}
     190
     191QModelIndex UIGuestControlFileModel::index(int row, int column, const QModelIndex &parent)
     192            const
     193{
     194    if (!hasIndex(row, column, parent))
     195        return QModelIndex();
     196
     197    UIFileTableItem *parentItem;
     198
     199    if (!parent.isValid())
     200        parentItem = rootItem();
     201    else
     202        parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
     203    if (!parentItem)
     204        return QModelIndex();
     205
     206    UIFileTableItem *childItem = parentItem->child(row);
     207    if (childItem)
     208        return createIndex(row, column, childItem);
     209    else
     210        return QModelIndex();
     211}
     212
     213QModelIndex UIGuestControlFileModel::parent(const QModelIndex &index) const
     214{
     215    if (!index.isValid())
     216        return QModelIndex();
     217
     218    UIFileTableItem *childItem = static_cast<UIFileTableItem*>(index.internalPointer());
     219    UIFileTableItem *parentItem = childItem->parentItem();
     220
     221    if (parentItem == rootItem())
     222        return QModelIndex();
     223
     224    return createIndex(parentItem->row(), 0, parentItem);
     225}
     226
     227int UIGuestControlFileModel::rowCount(const QModelIndex &parent) const
     228{
     229    if (parent.column() > 0)
     230        return 0;
     231    UIFileTableItem *parentItem = 0;
     232    if (!parent.isValid())
     233        parentItem = rootItem();
     234    else
     235        parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
     236    if (!parentItem)
     237        return 0;
     238    return parentItem->childCount();
     239}
     240
     241void UIGuestControlFileModel::signalUpdate()
     242{
     243    emit layoutChanged();
     244}
     245
     246UIGuestControlFileView::UIGuestControlFileView(QWidget *pParent /*= 0*/)
     247    :QTableView(pParent)
     248{
     249    setShowGrid(false);
     250    setSelectionBehavior(QAbstractItemView::SelectRows);
     251    verticalHeader()->setVisible(false);
     252}
     253
     254UIGuestControlFileTable::UIGuestControlFileTable(QWidget *pParent /* = 0 */)
     255    :QWidget(pParent)
     256    , m_pRootItem(0)
     257    , m_pView(0)
     258    , m_pModel(0)
     259    , m_pMainLayout(0)
     260{
     261    prepareObjects();
     262}
     263
     264UIGuestControlFileTable::~UIGuestControlFileTable()
     265{
     266    delete m_pRootItem;
     267}
     268
     269void UIGuestControlFileTable::prepareObjects()
     270{
     271    m_pMainLayout = new QVBoxLayout();
     272    if (!m_pMainLayout)
     273        return;
     274    m_pMainLayout->setSpacing(0);
     275    m_pMainLayout->setContentsMargins(0, 0, 0, 0);
     276    setLayout(m_pMainLayout);
     277
     278    m_pModel = new UIGuestControlFileModel(this);
     279    if (!m_pModel)
     280        return;
     281    m_pView = new UIGuestControlFileView;
     282    if (m_pView)
     283    {
     284        m_pMainLayout->addWidget(m_pView);
     285        m_pView->setModel(m_pModel);
     286    }
     287}
     288
     289UIGuestFileTable::UIGuestFileTable(QWidget *pParent /*= 0*/)
     290    :UIGuestControlFileTable(pParent)
     291{
     292}
     293
     294void UIGuestFileTable::initGuestFileTable(const CGuestSession &session)
     295{
     296    if (!session.isOk())
     297        return;
     298    if (session.GetStatus() != KGuestSessionStatus_Started)
     299        return;
     300    m_comGuestSession = session;
     301
     302    if(m_pRootItem)
     303        delete m_pRootItem;
     304
     305    QList<QVariant> rootData;
     306    rootData << "Name" << "Size";
     307    m_pRootItem = new UIFileTableItem(rootData);
     308
     309    // for(int i = 0; i < 10; ++i)
     310    // {
     311    //     QList<QVariant> data;
     312    //     data << "some name" << 23432;
     313    //     UIFieTableItem *item = new UIFileTableItem(data, m_pRootItem);
     314    //     m_pRootItem->appendChild(item);
     315    //     if (i == 4)
     316
     317    // }
     318
     319    /* Read the root directory and get the list: */
     320    readDirectory("/", m_pRootItem);
     321    m_pModel->signalUpdate();
     322}
     323
     324void UIGuestFileTable::readDirectory(const QString& strPath,
     325                                     UIFileTableItem *parent)
     326
     327{
     328    CGuestDirectory directory;
     329    QVector<KDirectoryOpenFlag> flag;
     330    flag.push_back(KDirectoryOpenFlag_None);
     331
     332    directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag);
     333    if (directory.isOk())
     334    {
     335        CFsObjInfo fsInfo = directory.Read();
     336        QMap<QString, UIFileTableItem*> directories;
     337        QMap<QString, UIFileTableItem*> files;
     338
     339        while (fsInfo.isOk())
     340        {
     341            QList<QVariant> data;
     342            data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize());
     343            UIFileTableItem *item = new UIFileTableItem(data, m_pRootItem);
     344            //parent->appendChild(item);
     345            if (fsInfo.GetType() == KFsObjType_Directory)
     346                directories.insert(fsInfo.GetName(), item);
     347            else
     348                files.insert(fsInfo.GetName(), item);
     349            fsInfo = directory.Read();
     350        }
     351        insertToTree(directories, parent);
     352        insertToTree(files, parent);
     353    }
     354}
     355
     356void UIGuestFileTable::insertToTree(const QMap<QString,UIFileTableItem*> &map, UIFileTableItem *parent)
     357{
     358    for(QMap<QString,UIFileTableItem*>::const_iterator iterator = map.begin();
     359        iterator != map.end(); ++iterator)
     360    {
     361        if(iterator.key() != ".")
     362            parent->appendChild(iterator.value());
     363    }
     364}
     365//     if (!treeParent || treeParent->depth() - startDepth >= iMaxDepth || strPath.isEmpty())
     366//         return;
     367//     QVector<KDirectoryOpenFlag> flag;
     368//     flag.push_back(KDirectoryOpenFlag_None);
     369//     CGuestDirectory directory;
     370//     directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag);
     371//     treeParent->setIsOpened(true);
     372//     if (directory.isOk())
     373//     {
     374//         CFsObjInfo fsInfo = directory.Read();
     375//         while (fsInfo.isOk())
     376//         {
     377//             if (fsInfo.GetName() != "."
     378//                 && fsInfo.GetName() != "..")
     379//             {
     380//                 QString path(strPath);
     381//                 if (path.at(path.length() -1 ) != '/')
     382//                     path.append(QString("/").append(fsInfo.GetName()));
     383//                 else
     384//                     path.append(fsInfo.GetName());
     385//                 UIGuestControlFileTreeItem *treeItem =
     386//                     new UIGuestControlFileTreeItem(treeParent, treeParent->depth() + 1 /*depth */,
     387//                                                    path, getFsObjInfoStringList<CFsObjInfo>(fsInfo));
     388//                 if (fsInfo.GetType() == KFsObjType_Directory)
     389//                 {
     390//                     treeItem->setIsDirectory(true);
     391//                     treeItem->setIcon(0, QIcon(":/sf_32px.png"));
     392//                     treeItem->setIsOpened(false);
     393//                     readDirectory(path, treeItem, startDepth, iMaxDepth);
     394//                 }
     395//                 else
     396//                 {
     397//                     treeItem->setIsDirectory(false);
     398//                     treeItem->setIsOpened(false);
     399//                     treeItem->setIcon(0, QIcon(":/vm_open_filemanager_16px"));
     400//                     treeItem->setHidden(true);
     401//                 }
     402//             }
     403
     404//             fsInfo = directory.Read();
     405//         }
     406//         directory.Close();
     407//     }
     408// }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.h

    r71135 r71169  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIGuestControlFileTree class declaration.
     3 * VBox Qt GUI - UIGuestControlFileTable class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___UIGuestControlFileTree_h___
    19 #define ___UIGuestControlFileTree_h___
     18#ifndef ___UIGuestControlFileTable_h___
     19#define ___UIGuestControlFileTable_h___
    2020
    2121/* Qt includes: */
     22#include <QAbstractItemModel>
    2223#include <QWidget>
    2324
    2425/* COM includes: */
    2526#include "COMEnums.h"
    26 #include "CEventListener.h"
    27 #include "CEventSource.h"
    28 #include "CGuest.h"
     27// #include "CEventListener.h"
     28// #include "CEventSource.h"
     29// #include "CGuest.h"
    2930#include "CGuestSession.h"
    3031
    3132/* GUI includes: */
    32 #include "QITreeWidget.h"
     33#include "QITableView.h"
    3334
    3435/* Forward declarations: */
     36class QVBoxLayout;
     37class UIFileTableItem;
     38class UIGuestControlFileTable;
    3539
    3640
    37 class UIGuestControlFileTree : public QITreeWidget
     41class UIGuestControlFileModel : public QAbstractItemModel
     42{
     43
     44    Q_OBJECT;
     45
     46public:
     47
     48    explicit UIGuestControlFileModel(QObject *parent = 0);
     49    ~UIGuestControlFileModel();
     50
     51    QVariant data(const QModelIndex &index, int role) const override;
     52    Qt::ItemFlags flags(const QModelIndex &index) const override;
     53    QVariant headerData(int section, Qt::Orientation orientation,
     54                        int role = Qt::DisplayRole) const override;
     55    QModelIndex index(int row, int column,
     56                      const QModelIndex &parent = QModelIndex()) const override;
     57    QModelIndex parent(const QModelIndex &index) const override;
     58    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
     59    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
     60    void signalUpdate();
     61
     62private:
     63
     64    UIFileTableItem* rootItem() const;
     65    void setupModelData(const QStringList &lines, UIFileTableItem *parent);
     66    UIGuestControlFileTable* m_pParent;
     67};
     68
     69
     70class UIGuestControlFileView : public QTableView
    3871{
    3972    Q_OBJECT;
     
    4174public:
    4275
     76    UIGuestControlFileView(QWidget *pParent = 0);
    4377
    4478private:
    4579
    46 
    4780};
    4881
    49 #endif /* !___UIGuestControlFileTree_h___ */
     82class UIGuestControlFileTable : public QWidget
     83{
     84    Q_OBJECT;
     85
     86public:
     87
     88    UIGuestControlFileTable(QWidget *pParent = 0);
     89    virtual ~UIGuestControlFileTable();
     90
     91protected:
     92
     93    UIFileTableItem         *m_pRootItem;
     94    UIGuestControlFileView  *m_pView;
     95    UIGuestControlFileModel *m_pModel;
     96
     97private:
     98
     99    void                    prepareObjects();
     100    QVBoxLayout             *m_pMainLayout;
     101    friend class UIGuestControlFileModel;
     102};
     103
     104
     105class UIGuestFileTable : public UIGuestControlFileTable
     106{
     107    Q_OBJECT;
     108
     109public:
     110
     111    UIGuestFileTable(QWidget *pParent = 0);
     112    void initGuestFileTable(const CGuestSession &session);
     113
     114private:
     115    void readDirectory(const QString& strPath,
     116                       UIFileTableItem *parent);
     117    void insertToTree(const QMap<QString,UIFileTableItem*> &map, UIFileTableItem *parent);
     118    CGuestSession m_comGuestSession;
     119};
     120
     121#endif /* !___UIGuestControlFileTable_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTree.cpp

    r71133 r71169  
    4343#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4444
    45 class UIGuestControlFileTreeItem : public QITreeWidgetItem
     45
     46UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget,
     47                                                       int depth, const QString &path,
     48                                                       const QStringList &strings /* = QStringList() */)
     49    :QITreeWidgetItem(pTreeWidget, strings)
     50    , m_iDepth(depth)
     51    , m_strPath(path)
     52    , m_bIsOpened(false)
     53    , m_bIsDirectory(false)
    4654{
    47     Q_OBJECT;
     55    prepare();
     56}
    4857
    49 public:
    50     UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget, const QStringList &strings = QStringList());
    51     UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem, const QStringList &strings = QStringList());
    52     virtual ~UIGuestControlFileTreeItem();
    53 
    54 };
    55 
    56 UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget, const QStringList &strings /* = QStringList() */)
    57     :QITreeWidgetItem(pTreeWidget, strings)
    58 
     58UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem,
     59                                                       int depth, const QString &path,
     60                                                       const QStringList &strings /*= QStringList() */)
     61    :QITreeWidgetItem(pTreeWidgetItem, strings)
     62    , m_iDepth(depth)
     63    , m_strPath(path)
     64    , m_bIsOpened(false)
     65    , m_bIsDirectory(false)
    5966{
    60 }
    61 UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem, const QStringList &strings /*= QStringList() */)
    62     :QITreeWidgetItem(pTreeWidgetItem, strings)
    63 {
     67    prepare();
    6468}
    6569
    6670UIGuestControlFileTreeItem::~UIGuestControlFileTreeItem(){}
    6771
    68 #include "UIGuestControlFileTree.moc"
     72void UIGuestControlFileTreeItem::prepare()
     73{
     74    /* For debugging: */
     75    setBackground(1, Qt::red);
     76    //QBrush::QBrush(Qt::GlobalColor
     77    //Qt::red
     78}
     79
     80QList<UIGuestControlFileTreeItem*>  UIGuestControlFileTreeItem::children()
     81{
     82    QList<UIGuestControlFileTreeItem*> children;
     83    for(int i = 0; i < childCount(); ++i)
     84    {
     85        UIGuestControlFileTreeItem* ch = dynamic_cast<UIGuestControlFileTreeItem*>(child(i));
     86        if(ch)
     87            children.push_back(ch);
     88    }
     89    return children;
     90}
     91
     92int UIGuestControlFileTreeItem::depth() const
     93{
     94    return m_iDepth;
     95}
     96
     97const QString& UIGuestControlFileTreeItem::path() const
     98{
     99    return m_strPath;
     100}
     101
     102bool UIGuestControlFileTreeItem::isOpened() const
     103{
     104    return m_bIsOpened;
     105}
     106void UIGuestControlFileTreeItem::setIsOpened(bool flag)
     107{
     108    m_bIsOpened = flag;
     109    setBackground(1, Qt::green);
     110}
     111
     112bool UIGuestControlFileTreeItem::isDirectory() const
     113{
     114    return m_bIsDirectory;
     115}
     116void UIGuestControlFileTreeItem::setIsDirectory(bool flag)
     117{
     118    m_bIsDirectory = flag;
     119}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTree.h

    r71133 r71169  
    3535
    3636
     37
    3738class UIGuestControlFileTree : public QITreeWidget
    3839{
     
    4748};
    4849
     50class UIGuestControlFileTreeItem : public QITreeWidgetItem
     51{
     52    Q_OBJECT;
     53
     54public:
     55    UIGuestControlFileTreeItem(UIGuestControlFileTree *pTreeWidget,
     56                               int depth, const QString &path,
     57                               const QStringList &strings = QStringList());
     58    UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem,
     59                               int depth, const QString &path,
     60                               const QStringList &strings = QStringList());
     61    virtual ~UIGuestControlFileTreeItem();
     62
     63    int depth() const;
     64    const QString& path() const;
     65
     66    bool    isOpened() const;
     67    void    setIsOpened(bool flag);
     68
     69    bool    isDirectory() const;
     70    void    setIsDirectory(bool flag);
     71
     72    QList<UIGuestControlFileTreeItem*> children();
     73
     74private:
     75
     76    void    prepare();
     77
     78    int     m_iDepth;
     79    QString m_strPath;
     80    /* Makes sense for directories. Used to not to descend unnecessarily: */
     81    bool    m_bIsOpened;
     82    bool    m_bIsDirectory;
     83};
     84
    4985#endif /* !___UIGuestControlFileTree_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp

    r71145 r71169  
    2626
    2727/* COM includes: */
     28# include "CFsObjInfo.h"
     29# include "CGuestDirectory.h"
    2830# include "CGuestProcess.h"
    2931# include "CGuestSession.h"
     
    7173        break;
    7274
    73 QString getFsObjTypeString(KFsObjType type)
     75QString UIGuestControlInterface::getFsObjTypeString(KFsObjType type)
    7476{
    7577    QString strType;
     
    334336    if (!fsObjectInfo.isOk())
    335337        RETURN_ERROR("Cannot get object info");
    336 
    337     QString strObjectInfo = getFsObjInfoString(fsObjectInfo);
    338 
     338    QString strObjectInfo = getFsObjInfoString<CGuestFsObjInfo>(fsObjectInfo);
     339
     340    /* In case it is a directory get a list of its content: */
     341    if (isADirectory)
     342    {
     343        QVector<KDirectoryOpenFlag> aFlags;
     344        aFlags.push_back(KDirectoryOpenFlag_None);
     345        CGuestDirectory directory = guestSession.DirectoryOpen(commandData.m_strPath, /*aFilter*/ "", aFlags);
     346        if (directory.isOk())
     347        {
     348            //printf("directory opened\n");
     349            //CGuestFsObjInfo directoryInfo = static_cast<CGuestFsObjInfo>(directory.Read());
     350            CFsObjInfo directoryInfo = directory.Read();
     351            while (directoryInfo.isOk())
     352            {
     353                strObjectInfo.append("\n");
     354                strObjectInfo.append(getFsObjInfoString<CFsObjInfo>(directoryInfo));
     355                directoryInfo = directory.Read();
     356            }
     357        }
     358    }
    339359    RETURN_MESSAGE(strObjectInfo);
    340360}
     
    533553void UIGuestControlInterface::putCommand(const QString &strCommand)
    534554{
    535     if (!isGuestAdditionsAvaible())
     555    if (!isGuestAdditionsAvaible(m_comGuest))
    536556    {
    537557        emit sigOutputString("No guest addtions detected. Guest control needs guest additions");
     
    646666}
    647667
    648 QString UIGuestControlInterface::getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const
    649 {
    650     QString strInfo;
     668bool UIGuestControlInterface::isGuestAdditionsAvaible(CGuest &guest)
     669{
     670    if (!guest.isOk())
     671        return false;
     672    return guest.GetAdditionsStatus(guest.GetAdditionsRunLevel());
     673
     674}
     675
     676template<typename T>
     677QString UIGuestControlInterface::getFsObjInfoString(const T &fsObjectInfo) const
     678{
     679    QString strObjectInfo;
    651680    if (!fsObjectInfo.isOk())
    652         return strInfo;
    653     strInfo.append(QString("%1 \t").arg(fsObjectInfo.GetName()));
    654     strInfo.append(QString("%1 \t").arg(getFsObjTypeString(fsObjectInfo.GetType())));
    655     strInfo.append(QString("%1 \t").arg(fsObjectInfo.GetObjectSize()));
    656     strInfo.append(QString("%1 \t").arg(fsObjectInfo.GetBirthTime()));
    657     strInfo.append(QString("%1 ").arg(fsObjectInfo.GetChangeTime()));
    658     return strInfo;
    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 }
     681        return strObjectInfo;
     682
     683    strObjectInfo.append(getFsObjTypeString(fsObjectInfo.GetType()).append("\t"));
     684    strObjectInfo.append(fsObjectInfo.GetName().append("\t"));
     685    strObjectInfo.append(QString::number(fsObjectInfo.GetObjectSize()).append("\t"));
     686
     687    /* Currently I dont know a way to convert these into a meaningful date/time: */
     688    // strObjectInfo.append("BirthTime", QString::number(fsObjectInfo.GetBirthTime()));
     689    // strObjectInfo.append("ChangeTime", QString::number(fsObjectInfo.GetChangeTime()));
     690
     691    return strObjectInfo;
     692}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.h

    r71145 r71169  
    5050    void putCommand(const QString &strCommand);
    5151
     52    /** @name Some utility functions
     53     * @{ */
     54        /** Pass a non-const ref since for some reason CGuest::GetAdditionsStatus
     55            is non-const?! */
     56       static bool    isGuestAdditionsAvaible(CGuest &guest);
     57       static QString getFsObjTypeString(KFsObjType type);
     58    /** @} */
     59
     60
    5261private slots:
    5362
     
    5968        to be returned or a new one to be created */
    6069    bool findOrCreateSession(const CommandData &commandData, CGuestSession &outGuestSession);
    61     /* Search a valid gurst session among existing ones, assign @p outGuestSession if found and return true */
     70    /** Search a valid gurst session among existing ones, assign @p outGuestSession if found and return true */
    6271    bool findAValidGuestSession(CGuestSession &outGuestSession);
    6372    bool findSession(const QString& strSessionName, CGuestSession& outSession);
     
    6978    bool createDirectory(const CommandData &commandData, CGuestSession &guestSession);
    7079
    71     /* Handles the 'start' process command */
     80    /** Handles the 'start' process command */
    7281    bool handleStart(int, char**);
    7382        /* Handles the 'help' process command */
    7483    bool handleHelp(int, char**);
    75     /* Handles the 'create' session command */
     84    /** Handles the 'create' session command */
    7685    bool handleCreateSession(int, char**);
    77     /* Handles the 'mkdir' session command to create guest directories */
     86    /** Handles the 'mkdir' session command to create guest directories */
    7887    bool handleMkdir(int, char**);
    7988    bool handleStat(int, char**);
     89    template<typename T>
     90    QString getFsObjInfoString(const T &fsObjectInfo) const;
    8091
    81     QString getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const;
    82     bool    isGuestAdditionsAvaible();
     92
    8393    CGuest        m_comGuest;
    8494    const QString m_strHelp;
    8595    QString       m_strStatus;
    86     /* A map of function pointers to handleXXXX functions */
     96    /** A map of function pointers to handleXXXX functions */
    8797    QMap<QString, HandleFuncPtr> m_subCommandHandlers;
    8898};
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