Changeset 71169 in vbox
- Timestamp:
- Mar 2, 2018 9:54:36 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r71133 r71169 378 378 src/runtime/information/guestctrl/UIGuestControlConsole.h \ 379 379 src/runtime/information/guestctrl/UIGuestControlFileManager.h \ 380 src/runtime/information/guestctrl/UIGuestControlFileTable.h \ 380 381 src/runtime/information/guestctrl/UIGuestControlFileTree.h \ 381 382 src/runtime/information/guestctrl/UIGuestControlInterface.h \ … … 568 569 src/runtime/UIStatusBarEditorWindow.cpp \ 569 570 src/runtime/information/guestctrl/UIGuestControlFileManager.cpp \ 570 src/runtime/information/guestctrl/UIGuestControlFileTree.cpp \571 571 src/runtime/information/guestctrl/UIGuestControlWidget.cpp \ 572 572 src/selector/UIActionPoolSelector.cpp \ … … 712 712 src/runtime/information/guestctrl/UIGuestControlConsole.cpp \ 713 713 src/runtime/information/guestctrl/UIGuestControlFileManager.cpp \ 714 src/runtime/information/guestctrl/UIGuestControlFileTable.cpp \ 714 715 src/runtime/information/guestctrl/UIGuestControlFileTree.cpp \ 715 716 src/runtime/information/guestctrl/UIGuestControlInterface.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.cpp
r71145 r71169 23 23 # include <QAbstractItemModel> 24 24 # include <QHBoxLayout> 25 # include <QHeaderView> 25 26 # include <QPlainTextEdit> 26 27 # include <QPushButton> 27 28 # include <QSplitter> 28 # include <Q VBoxLayout>29 # include <QGridLayout> 29 30 30 31 /* GUI includes: */ … … 34 35 # include "UIExtraDataManager.h" 35 36 # include "UIGuestControlFileManager.h" 37 # include "UIGuestControlFileTable.h" 36 38 # include "UIGuestControlFileTree.h" 39 # include "UIGuestControlInterface.h" 37 40 # include "UIVMInformationDialog.h" 38 41 # include "VBoxGlobal.h" 39 42 40 43 /* COM includes: */ 44 # include "CFsObjInfo.h" 41 45 # include "CGuest.h" 42 46 # include "CGuestDirectory.h" 47 # include "CGuestFsObjInfo.h" 48 # include "CGuestProcess.h" 49 # include "CGuestSession.h" 43 50 # include "CGuestSessionStateChangedEvent.h" 51 52 53 54 55 44 56 45 57 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 206 218 UIGuestControlFileManager::UIGuestControlFileManager(QWidget *pParent, const CGuest &comGuest) 207 219 : QWidget(pParent) 220 , m_iMaxRecursionDepth(1) 208 221 , m_comGuest(comGuest) 209 222 , m_pMainLayout(0) 210 , m_pSplitter(0) 211 , m_pSessionCreateWidget(0) 223 , m_pVerticalSplitter(0) 212 224 , m_pLogOutput(0) 213 225 , m_pGuestFileTree(0) 226 , m_pSessionCreateWidget(0) 227 , m_pGuestFileTable(0) 214 228 { 215 229 prepareGuestListener(); … … 248 262 m_pMainLayout->setSpacing(0); 249 263 250 251 264 m_pSessionCreateWidget = new UIGuestSessionCreateWidget(); 252 265 if (m_pSessionCreateWidget) 253 266 { 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); 268 282 } 269 283 … … 271 285 if (m_pLogOutput) 272 286 { 287 //m_pLogOutput->setMaximumHeight(80); 273 288 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); 279 307 } 280 308 … … 293 321 this, &UIGuestControlFileManager::sltCloseSession); 294 322 } 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 336 void UIGuestControlFileManager::sltTreeItemEntered(QTreeWidgetItem * item, int column) 337 { 338 } 339 340 void 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 351 void 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 362 void UIGuestControlFileManager::sltTreeItemClicked(QTreeWidgetItem * item, int column) 363 { 295 364 } 296 365 … … 334 403 void UIGuestControlFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent) 335 404 { 336 //if (cEvent.isOk() && m_comGuestSession.isOk())// && m_comGuestProcess.GetStatus() == KProcessStatus_Error)405 if (cEvent.isOk() && m_comGuestSession.isOk())// && m_comGuestProcess.GetStatus() == KProcessStatus_Error) 337 406 { 338 407 CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError(); 339 408 if (cErrorInfo.isOk())// && cErrorInfo.GetResultCode() != S_OK) 340 409 { 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 // }349 410 m_pLogOutput->appendPlainText(cErrorInfo.GetText()); 350 411 } 351 412 } 352 353 413 if (m_comGuestSession.GetStatus() == KGuestSessionStatus_Started) 354 414 { 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 425 void 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 434 void 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 464 void 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()) 360 480 { 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(); 363 509 } 364 } 365 366 } 367 510 directory.Close(); 511 } 512 } 368 513 369 514 bool UIGuestControlFileManager::createSession(const QString& strUserName, const QString& strPassword, … … 453 598 } 454 599 600 template<typename T> 601 QStringList 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 455 618 #include "UIGuestControlFileManager.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.h
r71133 r71169 33 33 34 34 /* Forward declarations: */ 35 class CGuestSessionStateChangedEvent;36 class QITreeView;37 35 class QPlainTextEdit; 38 36 class QVBoxLayout; 39 37 class QSplitter; 40 class UIFileListModel; 38 class QTreeWidgetItem; 39 class CGuestSessionStateChangedEvent; 40 class QITreeView; 41 class UIGuestFileTable; 41 42 class UIGuestControlFileTree; 43 class UIGuestControlFileTreeItem; 42 44 class UIGuestSessionCreateWidget; 43 45 … … 60 62 void sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent); 61 63 64 void sltTreeItemEntered(QTreeWidgetItem *item, int column); 65 void sltTreeItemExpanded(QTreeWidgetItem *item); 66 void sltTreeItemClicked(QTreeWidgetItem *item, int column); 67 62 68 private: 63 69 … … 75 81 CEventListener &comEventListener, 76 82 CEventSource comEventSource); 83 void initFileTree(); 84 void initFileTable(); 85 void openSubTree(UIGuestControlFileTreeItem *item); 77 86 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; 78 97 CGuest m_comGuest; 79 98 CGuestSession m_comGuestSession; 80 99 81 100 QVBoxLayout *m_pMainLayout; 82 QSplitter *m_pSplitter; 83 UIGuestSessionCreateWidget *m_pSessionCreateWidget; 101 QSplitter *m_pVerticalSplitter; 84 102 QPlainTextEdit *m_pLogOutput; 85 UIGuestControlFileTree* m_pGuestFileTree; 103 104 UIGuestControlFileTree* m_pGuestFileTree; 105 UIGuestSessionCreateWidget *m_pSessionCreateWidget; 106 UIGuestFileTable *m_pGuestFileTable; 86 107 87 108 ComObjPtr<UIMainEventListenerImpl> m_pQtGuestListener; 88 CEventListener m_comGuestListener;89 90 109 ComObjPtr<UIMainEventListenerImpl> m_pQtSessionListener; 91 110 CEventListener m_comSessionListener; 92 111 CEventListener m_comGuestListener; 93 112 }; 94 113 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp
r71135 r71169 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIGuestControlFileT ree class implementation.3 * VBox Qt GUI - UIGuestControlFileTable class implementation. 4 4 */ 5 5 … … 26 26 // # include <QPushButton> 27 27 // # include <QSplitter> 28 // # include <QVBoxLayout> 28 # include <QHeaderView> 29 # include <QVBoxLayout> 29 30 30 31 /* GUI includes: */ … … 33 34 // # include "QIWithRetranslateUI.h" 34 35 // # include "UIExtraDataManager.h" 35 # include "UIGuestControlFileT ree.h"36 # include "UIGuestControlFileTable.h" 36 37 // # include "UIVMInformationDialog.h" 37 38 // # include "VBoxGlobal.h" … … 39 40 /* COM includes: */ 40 41 // # include "CGuest.h" 42 # include "CFsObjInfo.h" 43 # include "CGuestDirectory.h" 41 44 // # include "CGuestSessionStateChangedEvent.h" 42 45 43 46 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 44 47 45 class UIGuestControlFileTreeItem : public QITreeWidgetItem 46 { 47 Q_OBJECT; 48 48 49 50 class UIFileTableItem 51 { 49 52 public: 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 65 private: 66 QList<UIFileTableItem*> m_childItems; 67 QList<QVariant> m_itemData; 68 UIFileTableItem *m_parentItem; 54 69 }; 55 70 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 72 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, UIFileTableItem *parent) 73 { 74 m_parentItem = parent; 75 m_itemData = data; 76 } 77 78 UIFileTableItem::~UIFileTableItem() 79 { 80 qDeleteAll(m_childItems); 81 } 82 83 void UIFileTableItem::appendChild(UIFileTableItem *item) 84 { 85 m_childItems.append(item); 86 } 87 88 UIFileTableItem *UIFileTableItem::child(int row) 89 { 90 return m_childItems.value(row); 91 } 92 93 int UIFileTableItem::childCount() const 94 { 95 return m_childItems.count(); 96 } 97 98 int UIFileTableItem::columnCount() const 99 { 100 return m_itemData.count(); 101 } 102 103 QVariant UIFileTableItem::data(int column) const 104 { 105 return m_itemData.value(column); 106 } 107 108 UIFileTableItem *UIFileTableItem::parentItem() 109 { 110 return m_parentItem; 111 } 112 113 int 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 123 UIGuestControlFileModel::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 132 UIFileTableItem* UIGuestControlFileModel::rootItem() const 133 { 134 if (!m_pParent) 135 return 0; 136 return m_pParent->m_pRootItem; 137 } 138 139 UIGuestControlFileModel::~UIGuestControlFileModel() 140 { 141 //delete rootItem; 142 } 143 144 int 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 157 QVariant 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 170 Qt::ItemFlags UIGuestControlFileModel::flags(const QModelIndex &index) const 171 { 172 if (!index.isValid()) 173 return 0; 174 175 return QAbstractItemModel::flags(index); 176 } 177 178 QVariant 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 191 QModelIndex 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 213 QModelIndex 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 227 int 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 241 void UIGuestControlFileModel::signalUpdate() 242 { 243 emit layoutChanged(); 244 } 245 246 UIGuestControlFileView::UIGuestControlFileView(QWidget *pParent /*= 0*/) 247 :QTableView(pParent) 248 { 249 setShowGrid(false); 250 setSelectionBehavior(QAbstractItemView::SelectRows); 251 verticalHeader()->setVisible(false); 252 } 253 254 UIGuestControlFileTable::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 264 UIGuestControlFileTable::~UIGuestControlFileTable() 265 { 266 delete m_pRootItem; 267 } 268 269 void 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 289 UIGuestFileTable::UIGuestFileTable(QWidget *pParent /*= 0*/) 290 :UIGuestControlFileTable(pParent) 291 { 292 } 293 294 void 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 324 void 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 356 void 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 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIGuestControlFileT ree class declaration.3 * VBox Qt GUI - UIGuestControlFileTable class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ___UIGuestControlFileT ree_h___19 #define ___UIGuestControlFileT ree_h___18 #ifndef ___UIGuestControlFileTable_h___ 19 #define ___UIGuestControlFileTable_h___ 20 20 21 21 /* Qt includes: */ 22 #include <QAbstractItemModel> 22 23 #include <QWidget> 23 24 24 25 /* COM includes: */ 25 26 #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" 29 30 #include "CGuestSession.h" 30 31 31 32 /* GUI includes: */ 32 #include "QIT reeWidget.h"33 #include "QITableView.h" 33 34 34 35 /* Forward declarations: */ 36 class QVBoxLayout; 37 class UIFileTableItem; 38 class UIGuestControlFileTable; 35 39 36 40 37 class UIGuestControlFileTree : public QITreeWidget 41 class UIGuestControlFileModel : public QAbstractItemModel 42 { 43 44 Q_OBJECT; 45 46 public: 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 62 private: 63 64 UIFileTableItem* rootItem() const; 65 void setupModelData(const QStringList &lines, UIFileTableItem *parent); 66 UIGuestControlFileTable* m_pParent; 67 }; 68 69 70 class UIGuestControlFileView : public QTableView 38 71 { 39 72 Q_OBJECT; … … 41 74 public: 42 75 76 UIGuestControlFileView(QWidget *pParent = 0); 43 77 44 78 private: 45 79 46 47 80 }; 48 81 49 #endif /* !___UIGuestControlFileTree_h___ */ 82 class UIGuestControlFileTable : public QWidget 83 { 84 Q_OBJECT; 85 86 public: 87 88 UIGuestControlFileTable(QWidget *pParent = 0); 89 virtual ~UIGuestControlFileTable(); 90 91 protected: 92 93 UIFileTableItem *m_pRootItem; 94 UIGuestControlFileView *m_pView; 95 UIGuestControlFileModel *m_pModel; 96 97 private: 98 99 void prepareObjects(); 100 QVBoxLayout *m_pMainLayout; 101 friend class UIGuestControlFileModel; 102 }; 103 104 105 class UIGuestFileTable : public UIGuestControlFileTable 106 { 107 Q_OBJECT; 108 109 public: 110 111 UIGuestFileTable(QWidget *pParent = 0); 112 void initGuestFileTable(const CGuestSession &session); 113 114 private: 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 43 43 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 44 44 45 class UIGuestControlFileTreeItem : public QITreeWidgetItem 45 46 UIGuestControlFileTreeItem::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) 46 54 { 47 Q_OBJECT; 55 prepare(); 56 } 48 57 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 58 UIGuestControlFileTreeItem::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) 59 66 { 60 } 61 UIGuestControlFileTreeItem::UIGuestControlFileTreeItem(UIGuestControlFileTreeItem *pTreeWidgetItem, const QStringList &strings /*= QStringList() */) 62 :QITreeWidgetItem(pTreeWidgetItem, strings) 63 { 67 prepare(); 64 68 } 65 69 66 70 UIGuestControlFileTreeItem::~UIGuestControlFileTreeItem(){} 67 71 68 #include "UIGuestControlFileTree.moc" 72 void UIGuestControlFileTreeItem::prepare() 73 { 74 /* For debugging: */ 75 setBackground(1, Qt::red); 76 //QBrush::QBrush(Qt::GlobalColor 77 //Qt::red 78 } 79 80 QList<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 92 int UIGuestControlFileTreeItem::depth() const 93 { 94 return m_iDepth; 95 } 96 97 const QString& UIGuestControlFileTreeItem::path() const 98 { 99 return m_strPath; 100 } 101 102 bool UIGuestControlFileTreeItem::isOpened() const 103 { 104 return m_bIsOpened; 105 } 106 void UIGuestControlFileTreeItem::setIsOpened(bool flag) 107 { 108 m_bIsOpened = flag; 109 setBackground(1, Qt::green); 110 } 111 112 bool UIGuestControlFileTreeItem::isDirectory() const 113 { 114 return m_bIsDirectory; 115 } 116 void UIGuestControlFileTreeItem::setIsDirectory(bool flag) 117 { 118 m_bIsDirectory = flag; 119 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTree.h
r71133 r71169 35 35 36 36 37 37 38 class UIGuestControlFileTree : public QITreeWidget 38 39 { … … 47 48 }; 48 49 50 class UIGuestControlFileTreeItem : public QITreeWidgetItem 51 { 52 Q_OBJECT; 53 54 public: 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 74 private: 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 49 85 #endif /* !___UIGuestControlFileTree_h___ */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp
r71145 r71169 26 26 27 27 /* COM includes: */ 28 # include "CFsObjInfo.h" 29 # include "CGuestDirectory.h" 28 30 # include "CGuestProcess.h" 29 31 # include "CGuestSession.h" … … 71 73 break; 72 74 73 QString getFsObjTypeString(KFsObjType type)75 QString UIGuestControlInterface::getFsObjTypeString(KFsObjType type) 74 76 { 75 77 QString strType; … … 334 336 if (!fsObjectInfo.isOk()) 335 337 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 } 339 359 RETURN_MESSAGE(strObjectInfo); 340 360 } … … 533 553 void UIGuestControlInterface::putCommand(const QString &strCommand) 534 554 { 535 if (!isGuestAdditionsAvaible( ))555 if (!isGuestAdditionsAvaible(m_comGuest)) 536 556 { 537 557 emit sigOutputString("No guest addtions detected. Guest control needs guest additions"); … … 646 666 } 647 667 648 QString UIGuestControlInterface::getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const 649 { 650 QString strInfo; 668 bool UIGuestControlInterface::isGuestAdditionsAvaible(CGuest &guest) 669 { 670 if (!guest.isOk()) 671 return false; 672 return guest.GetAdditionsStatus(guest.GetAdditionsRunLevel()); 673 674 } 675 676 template<typename T> 677 QString UIGuestControlInterface::getFsObjInfoString(const T &fsObjectInfo) const 678 { 679 QString strObjectInfo; 651 680 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 50 50 void putCommand(const QString &strCommand); 51 51 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 52 61 private slots: 53 62 … … 59 68 to be returned or a new one to be created */ 60 69 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 */ 62 71 bool findAValidGuestSession(CGuestSession &outGuestSession); 63 72 bool findSession(const QString& strSessionName, CGuestSession& outSession); … … 69 78 bool createDirectory(const CommandData &commandData, CGuestSession &guestSession); 70 79 71 /* Handles the 'start' process command */80 /** Handles the 'start' process command */ 72 81 bool handleStart(int, char**); 73 82 /* Handles the 'help' process command */ 74 83 bool handleHelp(int, char**); 75 /* Handles the 'create' session command */84 /** Handles the 'create' session command */ 76 85 bool handleCreateSession(int, char**); 77 /* Handles the 'mkdir' session command to create guest directories */86 /** Handles the 'mkdir' session command to create guest directories */ 78 87 bool handleMkdir(int, char**); 79 88 bool handleStat(int, char**); 89 template<typename T> 90 QString getFsObjInfoString(const T &fsObjectInfo) const; 80 91 81 QString getFsObjInfoString(const CGuestFsObjInfo &fsObjectInfo) const; 82 bool isGuestAdditionsAvaible(); 92 83 93 CGuest m_comGuest; 84 94 const QString m_strHelp; 85 95 QString m_strStatus; 86 /* A map of function pointers to handleXXXX functions */96 /** A map of function pointers to handleXXXX functions */ 87 97 QMap<QString, HandleFuncPtr> m_subCommandHandlers; 88 98 };
Note:
See TracChangeset
for help on using the changeset viewer.