- Timestamp:
- Mar 2, 2018 10:39:37 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp
r71169 r71181 21 21 22 22 /* Qt includes: */ 23 // # include <QAbstractItemModel>24 // # include <QHBoxLayout>25 // # include <QPlainTextEdit>26 // # include <QPushButton>27 // # include <QSplitter>28 23 # include <QHeaderView> 29 24 # include <QVBoxLayout> 30 25 31 26 /* GUI includes: */ 32 // # include "QILabel.h" 33 // # include "QILineEdit.h" 34 // # include "QIWithRetranslateUI.h" 35 // # include "UIExtraDataManager.h" 27 # include "QILineEdit.h" 36 28 # include "UIGuestControlFileTable.h" 37 // # include "UIVMInformationDialog.h"38 // # include "VBoxGlobal.h"39 29 40 30 /* COM includes: */ 41 // # include "CGuest.h"42 31 # include "CFsObjInfo.h" 43 32 # include "CGuestDirectory.h" 44 // # include "CGuestSessionStateChangedEvent.h"45 33 46 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 47 35 48 36 37 /********************************************************************************************************************************* 38 * UIFileTableItem definition. * 39 *********************************************************************************************************************************/ 49 40 50 41 class UIFileTableItem … … 63 54 UIFileTableItem *parentItem(); 64 55 56 bool isDirectory() const; 57 bool isOpened() const; 58 59 void setIsDirectory(bool flag); 60 void setIsOpened(bool flag); 61 62 const QString &path() const; 63 void setPath(const QString &path); 64 65 /** True if this is directory and name is ".." */ 66 bool isUpDirectory() const; 67 65 68 private: 66 69 QList<UIFileTableItem*> m_childItems; 67 QList<QVariant> m_itemData;70 QList<QVariant> m_itemData; 68 71 UIFileTableItem *m_parentItem; 72 bool m_bIsDirectory; 73 bool m_bIsOpened; 74 QString m_strPath; 69 75 }; 70 76 71 77 72 78 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, UIFileTableItem *parent) 73 { 74 m_parentItem = parent; 75 m_itemData = data; 79 : m_itemData(data) 80 , m_parentItem(parent) 81 , m_bIsDirectory(false) 82 , m_bIsOpened(false) 83 { 84 76 85 } 77 86 … … 119 128 } 120 129 121 130 bool UIFileTableItem::isDirectory() const 131 { 132 return m_bIsDirectory; 133 } 134 135 bool UIFileTableItem::isOpened() const 136 { 137 return m_bIsOpened; 138 } 139 140 void UIFileTableItem::setIsDirectory(bool flag) 141 { 142 m_bIsDirectory = flag; 143 } 144 145 void UIFileTableItem::setIsOpened(bool flag) 146 { 147 m_bIsOpened = flag; 148 } 149 150 const QString &UIFileTableItem::path() const 151 { 152 return m_strPath; 153 } 154 155 void UIFileTableItem::setPath(const QString &path) 156 { 157 m_strPath = path; 158 } 159 160 bool UIFileTableItem::isUpDirectory() const 161 { 162 if (!m_bIsDirectory) 163 return false; 164 if (data(0) == QString("..")) 165 return true; 166 return false; 167 } 168 169 170 /********************************************************************************************************************************* 171 * UIGuestControlFileModel implementation. * 172 *********************************************************************************************************************************/ 122 173 123 174 UIGuestControlFileModel::UIGuestControlFileModel(QObject *parent) … … 159 210 if (!index.isValid()) 160 211 return QVariant(); 161 162 if ( role != Qt::DisplayRole)212 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 213 if (!item) 163 214 return QVariant(); 164 215 165 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 166 167 return item->data(index.column()); 216 if (role == Qt::DisplayRole) 217 { 218 /* dont show anything but the name for up directories: */ 219 if (item->isUpDirectory() && index.column() != 0) 220 return QVariant(); 221 return item->data(index.column()); 222 } 223 224 if (role == Qt::DecorationRole && index.column() == 0) 225 { 226 if (item->isDirectory() && !item->isUpDirectory()) 227 return QIcon(":/sf_32px.png"); 228 if (!item->isDirectory()) 229 return QIcon(":/vm_open_filemanager_16px"); 230 } 231 232 return QVariant(); 168 233 } 169 234 … … 210 275 return QModelIndex(); 211 276 } 277 212 278 213 279 QModelIndex UIGuestControlFileModel::parent(const QModelIndex &index) const … … 244 310 } 245 311 246 UIGuestControlFileView::UIGuestControlFileView(QWidget *pParent /*= 0*/) 247 :QTableView(pParent) 248 { 249 setShowGrid(false); 250 setSelectionBehavior(QAbstractItemView::SelectRows); 251 verticalHeader()->setVisible(false); 252 } 312 QModelIndex UIGuestControlFileModel::rootIndex() const 313 { 314 if (!rootItem()) 315 return QModelIndex(); 316 return createIndex(rootItem()->child(0)->row(), 0, 317 rootItem()->child(0)); 318 } 319 320 321 /********************************************************************************************************************************* 322 * UIGuestControlFileTable implementation. * 323 *********************************************************************************************************************************/ 253 324 254 325 UIGuestControlFileTable::UIGuestControlFileTable(QWidget *pParent /* = 0 */) … … 257 328 , m_pView(0) 258 329 , m_pModel(0) 330 , m_pTree(0) 259 331 , m_pMainLayout(0) 332 , m_pCurrentLocationEdit(0) 333 260 334 { 261 335 prepareObjects(); … … 276 350 setLayout(m_pMainLayout); 277 351 352 m_pCurrentLocationEdit = new QILineEdit; 353 if(m_pCurrentLocationEdit) 354 { 355 m_pMainLayout->addWidget(m_pCurrentLocationEdit); 356 m_pCurrentLocationEdit->setReadOnly(true); 357 } 358 278 359 m_pModel = new UIGuestControlFileModel(this); 279 360 if (!m_pModel) 280 361 return; 281 m_pView = new UIGuestControlFileView; 362 363 364 m_pView = new QTableView; 282 365 if (m_pView) 283 366 { 367 m_pView->setShowGrid(false); 368 m_pView->setSelectionBehavior(QAbstractItemView::SelectRows); 369 m_pView->verticalHeader()->setVisible(false); 370 284 371 m_pMainLayout->addWidget(m_pView); 285 372 m_pView->setModel(m_pModel); … … 287 374 } 288 375 376 void UIGuestControlFileTable::updateCurrentLocationEdit(const QString& strLocation) 377 { 378 if (!m_pCurrentLocationEdit) 379 return; 380 m_pCurrentLocationEdit->setText(strLocation); 381 } 382 383 void UIGuestControlFileTable::changeLocation(const QModelIndex &index) 384 { 385 if(!index.isValid() || !m_pView) 386 return; 387 m_pView->setRootIndex(index); 388 m_pView->clearSelection(); 389 390 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 391 if(item) 392 { 393 updateCurrentLocationEdit(item->path()); 394 } 395 m_pModel->signalUpdate(); 396 } 397 398 399 /********************************************************************************************************************************* 400 * UIGuestFileTable implementation. * 401 *********************************************************************************************************************************/ 402 289 403 UIGuestFileTable::UIGuestFileTable(QWidget *pParent /*= 0*/) 290 404 :UIGuestControlFileTable(pParent) 291 405 { 406 connect(m_pView, &QTableView::doubleClicked, 407 this, &UIGuestFileTable::sltItemDoubleClicked); 292 408 } 293 409 … … 303 419 delete m_pRootItem; 304 420 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 421 QList<QVariant> headData; 422 headData << "Name" << "Size"; 423 m_pRootItem = new UIFileTableItem(headData); 424 425 QList<QVariant> startDirData; 426 startDirData << "/" << 4096; 427 UIFileTableItem* startItem = new UIFileTableItem(startDirData, m_pRootItem); 428 startItem->setPath("/"); 429 m_pRootItem->appendChild(startItem); 430 431 startItem->setIsDirectory(true); 432 startItem->setIsOpened(false); 319 433 /* Read the root directory and get the list: */ 320 readDirectory("/", m_pRootItem); 434 435 readDirectory("/", startItem); 436 m_pView->setRootIndex(m_pModel->rootIndex()); 321 437 m_pModel->signalUpdate(); 322 438 } … … 326 442 327 443 { 444 if (!parent) 445 return; 328 446 CGuestDirectory directory; 329 447 QVector<KDirectoryOpenFlag> flag; … … 331 449 332 450 directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag); 451 parent->setIsOpened(true); 452 333 453 if (directory.isOk()) 334 454 { … … 341 461 QList<QVariant> data; 342 462 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize()); 343 UIFileTableItem *item = new UIFileTableItem(data, m_pRootItem);344 //parent->appendChild(item);463 UIFileTableItem *item = new UIFileTableItem(data, parent); 464 item->setPath(QString("%1%3%2").arg(strPath).arg("/").arg(fsInfo.GetName())); 345 465 if (fsInfo.GetType() == KFsObjType_Directory) 466 { 346 467 directories.insert(fsInfo.GetName(), item); 468 item->setIsDirectory(true); 469 item->setIsOpened(false); 470 } 347 471 else 472 { 348 473 files.insert(fsInfo.GetName(), item); 474 item->setIsDirectory(false); 475 item->setIsOpened(false); 476 } 349 477 fsInfo = directory.Read(); 350 478 } 351 479 insertToTree(directories, parent); 352 480 insertToTree(files, parent); 481 updateCurrentLocationEdit(strPath); 353 482 } 354 483 } … … 363 492 } 364 493 } 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 // } 494 495 void UIGuestFileTable::sltItemDoubleClicked(const QModelIndex &index) 496 { 497 if (!index.isValid() || !m_pModel || !m_pView) 498 return; 499 500 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 501 if (!item) 502 return; 503 /* check if we need to go up: */ 504 if (item->isUpDirectory()) 505 { 506 QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index)); 507 if (parentIndex.isValid()) 508 changeLocation(parentIndex); 509 // else 510 // changeLocation(m_pModel->rootIndex()); 511 return; 512 } 513 514 if (!item->isDirectory()) 515 return; 516 if(!item->isOpened()) 517 readDirectory(item->path(),item); 518 519 changeLocation(index); 520 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.h
r71170 r71181 21 21 /* Qt includes: */ 22 22 #include <QAbstractItemModel> 23 #include <QTreeView> 23 24 #include <QWidget> 24 25 25 26 /* COM includes: */ 26 27 #include "COMEnums.h" 27 // #include "CEventListener.h"28 // #include "CEventSource.h"29 // #include "CGuest.h"30 28 #include "CGuestSession.h" 31 29 … … 34 32 35 33 /* Forward declarations: */ 34 class QILineEdit; 36 35 class QVBoxLayout; 37 36 class UIFileTableItem; 38 37 class UIGuestControlFileTable; 39 38 40 39 /** UIGuestControlFileModel serves as the model for a file structure. 40 it supports a tree level hierarchy which can be displayed with 41 QTableView and/or QTreeView */ 41 42 class UIGuestControlFileModel : public QAbstractItemModel 42 43 { … … 59 60 int columnCount(const QModelIndex &parent = QModelIndex()) const /* override */; 60 61 void signalUpdate(); 62 QModelIndex rootIndex() const; 61 63 62 64 private: … … 65 67 void setupModelData(const QStringList &lines, UIFileTableItem *parent); 66 68 UIGuestControlFileTable* m_pParent; 69 UIFileTableItem *m_pRootItem; 67 70 }; 68 71 69 70 class UIGuestControlFileView : public QTableView 71 { 72 Q_OBJECT; 73 74 public: 75 76 UIGuestControlFileView(QWidget *pParent = 0); 77 78 private: 79 80 }; 81 72 /** This serves a base class for file table. Currently a guest version 73 and a host version are derived from this base. Each of these children 74 populates the UIGuestControlFileModel by scanning the file system 75 differently. */ 82 76 class UIGuestControlFileTable : public QWidget 83 77 { … … 91 85 protected: 92 86 87 void updateCurrentLocationEdit(const QString& strLocation); 88 void changeLocation(const QModelIndex &index); 93 89 UIFileTableItem *m_pRootItem; 94 UIGuestControlFileView *m_pView; 90 91 /** Using QITableView causes the following problem when I click on the table items 92 Qt WARNING: Cannot creat accessible child interface for object: UIGuestControlFileView..... 93 so for now subclass QTableView */ 94 QTableView *m_pView; 95 95 UIGuestControlFileModel *m_pModel; 96 QTreeView *m_pTree; 97 96 98 97 99 private: … … 99 101 void prepareObjects(); 100 102 QVBoxLayout *m_pMainLayout; 103 QILineEdit *m_pCurrentLocationEdit; 104 101 105 friend class UIGuestControlFileModel; 102 106 }; 103 107 104 108 /** This class scans the guest file system by using the VBox API 109 and populates the UIGuestControlFileModel*/ 105 110 class UIGuestFileTable : public UIGuestControlFileTable 106 111 { … … 112 117 void initGuestFileTable(const CGuestSession &session); 113 118 119 private slots: 120 121 void sltItemDoubleClicked(const QModelIndex &index); 122 114 123 private: 115 124 void readDirectory(const QString& strPath, -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlInterface.cpp
r71169 r71181 346 346 if (directory.isOk()) 347 347 { 348 //printf("directory opened\n");349 //CGuestFsObjInfo directoryInfo = static_cast<CGuestFsObjInfo>(directory.Read());350 348 CFsObjInfo directoryInfo = directory.Read(); 351 349 while (directoryInfo.isOk())
Note:
See TracChangeset
for help on using the changeset viewer.