Changeset 71380 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 19, 2018 7:55:18 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r71363 r71380 27 27 # include <QItemDelegate> 28 28 # include <QGridLayout> 29 # include <QMenu> 30 # include <QTextEdit> 29 31 # include <QPushButton> 30 # include <QMenu>31 32 32 33 /* GUI includes: */ … … 35 36 # include "QILabel.h" 36 37 # include "QILineEdit.h" 38 # include "QIMessageBox.h" 37 39 # include "UIErrorString.h" 38 40 # include "UIIconPool.h" … … 86 88 class UIGuestControlFileView : public QTableView 87 89 { 90 88 91 Q_OBJECT; 92 89 93 signals: 90 94 … … 98 102 void sigCopy(); 99 103 void sigPaste(); 104 void sigShowProperties(); 105 106 void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); 100 107 101 108 public: … … 105 112 106 113 protected: 114 virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */; 107 115 void contextMenuEvent(QContextMenuEvent *pEvent); 108 116 }; … … 145 153 146 154 /********************************************************************************************************************************* 147 * UIPathOperations implementation. * 155 * UIPropertiesDialog definition. * 156 *********************************************************************************************************************************/ 157 158 /** A QIDialog child to display properties of a file object */ 159 class UIPropertiesDialog : public QIDialog 160 { 161 162 Q_OBJECT; 163 164 public: 165 166 UIPropertiesDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0); 167 void setPropertyText(const QString &strProperty); 168 169 private: 170 171 QVBoxLayout *m_pMainLayout; 172 QTextEdit *m_pInfoEdit; 173 174 }; 175 176 177 /********************************************************************************************************************************* 178 * UIPathOperations implementation. * 148 179 *********************************************************************************************************************************/ 149 180 … … 318 349 pActionPaste->setIcon(UIIconPool::iconSet(QString(":/shared_clipboard_16px.png"))); 319 350 connect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste); 351 } 352 353 menu->addSeparator(); 354 QAction *pActionShowProperties = menu->addAction(UIVMInformationDialog::tr("Properties")); 355 if (pActionShowProperties) 356 { 357 pActionShowProperties->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png"))); 358 pActionShowProperties->setEnabled(selectionAvaible); 359 connect(pActionShowProperties, &QAction::triggered, this, &UIGuestControlFileView::sigShowProperties); 320 360 } 321 361 … … 340 380 if (pActionPaste) 341 381 disconnect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste); 382 if (pActionShowProperties) 383 disconnect(pActionShowProperties, &QAction::triggered, this, &UIGuestControlFileView::sigShowProperties); 342 384 343 385 delete menu; … … 350 392 return false; 351 393 return pSelectionModel->hasSelection(); 394 } 395 396 void UIGuestControlFileView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) 397 { 398 emit sigSelectionChanged(selected, deselected); 399 QTableView::selectionChanged(selected, deselected); 352 400 } 353 401 … … 379 427 return QString(); 380 428 return m_pLineEdit->text(); 429 } 430 431 432 /********************************************************************************************************************************* 433 * UIPropertiesDialog implementation. * 434 *********************************************************************************************************************************/ 435 436 UIPropertiesDialog::UIPropertiesDialog(QWidget *pParent, Qt::WindowFlags flags) 437 :QIDialog(pParent, flags) 438 , m_pMainLayout(new QVBoxLayout) 439 , m_pInfoEdit(new QTextEdit) 440 { 441 setLayout(m_pMainLayout); 442 443 if (m_pMainLayout) 444 m_pMainLayout->addWidget(m_pInfoEdit); 445 if (m_pInfoEdit) 446 { 447 // m_pInfoEdit->setTextFormat(Qt::RichText); 448 m_pInfoEdit->setReadOnly(true); 449 m_pInfoEdit->setFrameStyle(QFrame::NoFrame); 450 // m_pInfoEdit->setText("Line 1\nLine 2\n\nLine 4"); 451 // m_pInfoEdit->setWordWrap(true); 452 } 453 QIDialogButtonBox *pButtonBox = 454 new QIDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, this); 455 m_pMainLayout->addWidget(pButtonBox); 456 connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept); 457 } 458 459 void UIPropertiesDialog::setPropertyText(const QString &strProperty) 460 { 461 if (!m_pInfoEdit) 462 return; 463 464 m_pInfoEdit->setText(strProperty); 381 465 } 382 466 … … 559 643 , m_pCut(0) 560 644 , m_pPaste(0) 645 , m_pShowProperties(0) 561 646 562 647 { … … 649 734 connect(m_pView, &UIGuestControlFileView::sigRename, 650 735 this, &UIGuestControlFileTable::sltRename); 651 652 736 connect(m_pView, &UIGuestControlFileView::sigCreateNewDirectory, 653 737 this, &UIGuestControlFileTable::sltCreateNewDirectory); 654 655 738 connect(m_pView, &UIGuestControlFileView::sigCopy, 656 739 this, &UIGuestControlFileTable::sltCopy); … … 659 742 connect(m_pView, &UIGuestControlFileView::sigPaste, 660 743 this, &UIGuestControlFileTable::sltPaste); 744 connect(m_pView, &UIGuestControlFileView::sigShowProperties, 745 this, &UIGuestControlFileTable::sltShowProperties); 746 connect(m_pView, &UIGuestControlFileView::sigSelectionChanged, 747 this, &UIGuestControlFileTable::sltSelectionChanged); 661 748 662 749 } … … 700 787 m_pDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png"))); 701 788 m_pToolBar->addAction(m_pDelete); 789 m_selectionDependentActions.push_back(m_pDelete); 702 790 } 703 791 … … 708 796 m_pRename->setIcon(UIIconPool::iconSet(QString(":/name_16px_x2.png"))); 709 797 m_pToolBar->addAction(m_pRename); 798 m_selectionDependentActions.push_back(m_pRename); 710 799 } 711 800 … … 724 813 m_pToolBar->addAction(m_pCopy); 725 814 connect(m_pCopy, &QAction::triggered, this, &UIGuestControlFileTable::sltCopy); 815 m_selectionDependentActions.push_back(m_pCopy); 726 816 } 727 817 … … 732 822 m_pToolBar->addAction(m_pCut); 733 823 connect(m_pCut, &QAction::triggered, this, &UIGuestControlFileTable::sltCut); 824 m_selectionDependentActions.push_back(m_pCut); 734 825 } 735 826 … … 740 831 m_pToolBar->addAction(m_pPaste); 741 832 connect(m_pPaste, &QAction::triggered, this, &UIGuestControlFileTable::sltPaste); 742 } 833 m_pPaste->setEnabled(false); 834 } 835 836 m_pToolBar->addSeparator(); 837 838 m_pShowProperties = new QAction(this); 839 { 840 m_pShowProperties->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png"))); 841 m_pToolBar->addAction(m_pShowProperties); 842 connect(m_pShowProperties, &QAction::triggered, this, &UIGuestControlFileTable::sltShowProperties); 843 m_selectionDependentActions.push_back(m_pShowProperties); 844 } 845 846 disableSelectionDependentActions(); 743 847 } 744 848 … … 990 1094 void UIGuestControlFileTable::sltCopy() 991 1095 { 1096 1097 m_copyCutBuffer = selectedItemPathList(); 1098 if (!m_copyCutBuffer.isEmpty()) 1099 m_pPaste->setEnabled(true); 1100 else 1101 m_pPaste->setEnabled(false); 992 1102 } 993 1103 994 1104 void UIGuestControlFileTable::sltCut() 995 1105 { 1106 m_copyCutBuffer = selectedItemPathList(); 1107 if (!m_copyCutBuffer.isEmpty()) 1108 m_pPaste->setEnabled(true); 1109 else 1110 m_pPaste->setEnabled(false); 996 1111 } 997 1112 998 1113 void UIGuestControlFileTable::sltPaste() 999 1114 { 1115 // paste them 1116 m_copyCutBuffer.clear(); 1117 m_pPaste->setEnabled(false); 1118 } 1119 1120 void UIGuestControlFileTable::sltShowProperties() 1121 { 1122 QString fsPropertyString = fsObjectPropertyString(); 1123 if (fsPropertyString.isEmpty()) 1124 return; 1125 1126 UIPropertiesDialog *dialog = new UIPropertiesDialog(); 1127 dialog->setPropertyText(fsPropertyString); 1128 dialog->execute(); 1129 1130 1131 1132 // QIMessageBox *pFsObjectPropertiesBox = new QIMessageBox("Properties", 1133 // fsPropertyString, 1134 // AlertIconType_Information, 1135 // AlertButton_Ok| AlertButtonOption_Escape, 0, 0, this); 1136 // pFsObjectPropertiesBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); 1137 1138 1139 // //pFsObjectPropertiesBox->setFixedWidth(300); 1140 // pFsObjectPropertiesBox->exec(); 1141 1142 // delete pFsObjectPropertiesBox; 1143 } 1144 1145 void UIGuestControlFileTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) 1146 { 1147 /* Disable all the action that operate on some selection: */ 1148 if (!deselected.isEmpty() && selected.isEmpty()) 1149 disableSelectionDependentActions(); 1150 1151 /* Enable all the action that operate on some selection: */ 1152 if (deselected.isEmpty() && !selected.isEmpty()) 1153 enableSelectionDependentActions(); 1000 1154 } 1001 1155 … … 1072 1226 m_pPaste->setToolTip(UIVMInformationDialog::tr("Paste the copied item(s)")); 1073 1227 m_pPaste->setStatusTip(UIVMInformationDialog::tr("Paste the copied item(s)")); 1228 } 1229 1230 if (m_pShowProperties) 1231 { 1232 m_pShowProperties->setText(UIVMInformationDialog::tr("Show the properties of the selected item(s)")); 1233 m_pShowProperties->setToolTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)")); 1234 m_pShowProperties->setStatusTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)")); 1074 1235 } 1075 1236 } … … 1167 1328 } 1168 1329 1330 void UIGuestControlFileTable::enableSelectionDependentActions() 1331 { 1332 for (int i = 0; i < m_selectionDependentActions.size(); ++i) 1333 { 1334 if (m_selectionDependentActions[i]) 1335 m_selectionDependentActions[i]->setEnabled(true); 1336 } 1337 } 1338 1339 void UIGuestControlFileTable::disableSelectionDependentActions() 1340 { 1341 /* Disable all the action that operate on some selection: */ 1342 for (int i = 0; i < m_selectionDependentActions.size(); ++i) 1343 { 1344 if (m_selectionDependentActions[i]) 1345 m_selectionDependentActions[i]->setEnabled(false); 1346 } 1347 } 1348 1349 QString UIGuestControlFileTable::fileTypeString(FileObjectType type) 1350 { 1351 QString strType("Unknown"); 1352 switch(type) 1353 { 1354 case FileObjectType_File: 1355 strType = "File"; 1356 break; 1357 case FileObjectType_Directory: 1358 strType = "Directory"; 1359 break; 1360 case FileObjectType_SymLink: 1361 strType = "Symbolic Link"; 1362 break; 1363 case FileObjectType_Other: 1364 strType = "Other"; 1365 break; 1366 1367 case FileObjectType_Unknown: 1368 default: 1369 break; 1370 } 1371 return strType; 1372 } 1373 1169 1374 1170 1375 /********************************************************************************************************************************* … … 1222 1427 1223 1428 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize()) << changeTime; 1224 FileObjectType f ileType = getFileType(fsInfo);1225 UIFileTableItem *item = new UIFileTableItem(data, parent, f ileType);1429 FileObjectType fsObjectType = fileType(fsInfo); 1430 UIFileTableItem *item = new UIFileTableItem(data, parent, fsObjectType); 1226 1431 item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName())); 1227 if (f ileType == FileObjectType_Directory)1432 if (fsObjectType == FileObjectType_Directory) 1228 1433 { 1229 1434 directories.insert(fsInfo.GetName(), item); 1230 1435 item->setIsOpened(false); 1231 1436 } 1232 else if(f ileType == FileObjectType_File)1437 else if(fsObjectType == FileObjectType_File) 1233 1438 { 1234 1439 files.insert(fsInfo.GetName(), item); … … 1236 1441 } 1237 1442 /** @todo Seems like our API is not able to detect symlinks: */ 1238 else if(f ileType == FileObjectType_SymLink)1443 else if(fsObjectType == FileObjectType_SymLink) 1239 1444 { 1240 1445 files.insert(fsInfo.GetName(), item); … … 1390 1595 } 1391 1596 1392 FileObjectType UIGuestFileTable:: getFileType(const CFsObjInfo &fsInfo)1597 FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo) 1393 1598 { 1394 1599 if (fsInfo.isNull() || !fsInfo.isOk()) … … 1404 1609 } 1405 1610 1611 QString UIGuestFileTable::fsObjectPropertyString() 1612 { 1613 return QString(); 1614 } 1615 1406 1616 1407 1617 /********************************************************************************************************************************* … … 1443 1653 QList<QVariant> data; 1444 1654 data << fileInfo.fileName() << fileInfo.size() << fileInfo.lastModified(); 1445 UIFileTableItem *item = new UIFileTableItem(data, parent, getFileType(fileInfo));1655 UIFileTableItem *item = new UIFileTableItem(data, parent, fileType(fileInfo)); 1446 1656 item->setPath(fileInfo.absoluteFilePath()); 1447 1657 /* if the item is a symlink set the target path and … … 1536 1746 } 1537 1747 1538 FileObjectType UIHostFileTable:: getFileType(const QFileInfo &fsInfo)1748 FileObjectType UIHostFileTable::fileType(const QFileInfo &fsInfo) 1539 1749 { 1540 1750 if (!fsInfo.exists()) … … 1552 1762 } 1553 1763 1764 QString UIHostFileTable::fsObjectPropertyString() 1765 { 1766 QStringList selectedObjects = selectedItemPathList(); 1767 if (selectedObjects.isEmpty()) 1768 return QString(); 1769 if (selectedObjects.size() == 1) 1770 { 1771 if (selectedObjects.at(0).isNull()) 1772 return QString(); 1773 QFileInfo fileInfo(selectedObjects.at(0)); 1774 if (!fileInfo.exists()) 1775 return QString(); 1776 QString propertyString; 1777 /* Name: */ 1778 propertyString += "<b>Name:</b> " + fileInfo.fileName() + "\n"; 1779 if (!fileInfo.suffix().isEmpty()) 1780 propertyString += "." + fileInfo.suffix(); 1781 propertyString += "<br/>"; 1782 /* Size: */ 1783 propertyString += "<b>Size:</b> " + QString::number(fileInfo.size()) + QString(" bytes"); 1784 propertyString += "<br/>"; 1785 /* Type: */ 1786 propertyString += "<b>Type:</b> " + fileTypeString(fileType(fileInfo)); 1787 propertyString += "<br/>"; 1788 /* Creation Date: */ 1789 propertyString += "<b>Created:</b> " + fileInfo.created().toString(); 1790 propertyString += "<br/>"; 1791 /* Last Modification Date: */ 1792 propertyString += "<b>Modified:</b> " + fileInfo.lastModified().toString(); 1793 propertyString += "<br/>"; 1794 /* Owner: */ 1795 propertyString += "<b>Owner:</b> " + fileInfo.owner(); 1796 1797 1798 return propertyString; 1799 } 1800 return QString(); 1801 } 1802 1554 1803 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71362 r71380 154 154 virtual bool renameItem(UIFileTableItem *item, QString newBaseName) = 0; 155 155 virtual bool createDirectory(const QString &path, const QString &directoryName) = 0; 156 virtual QString fsObjectPropertyString() = 0; 157 static QString fileTypeString(FileObjectType type); 156 158 void goIntoDirectory(const QModelIndex &itemIndex); 157 159 /** Follow the path trail, open directories as we go and descend */ … … 170 172 QILabel *m_pLocationLabel; 171 173 172 pr otectedslots:174 private slots: 173 175 174 176 void sltItemDoubleClicked(const QModelIndex &index); … … 181 183 void sltCut(); 182 184 void sltPaste(); 185 void sltShowProperties(); 183 186 void sltCreateNewDirectory(); 187 void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); 184 188 185 189 private: … … 192 196 /** Shows a modal dialog with a line edit for user to enter a new directory name and return the entered string*/ 193 197 QString getNewDirectoryName(); 198 void enableSelectionDependentActions(); 199 void disableSelectionDependentActions(); 194 200 QGridLayout *m_pMainLayout; 195 201 QILineEdit *m_pCurrentLocationEdit; … … 201 207 QAction *m_pRename; 202 208 QAction *m_pCreateNewDirectory; 203 204 205 209 QAction *m_pCopy; 206 210 QAction *m_pCut; 207 211 QAction *m_pPaste; 208 212 QAction *m_pShowProperties; 213 /** The vector of action which need some selection to work on like cut, copy etc. */ 214 QVector<QAction*> m_selectionDependentActions; 215 /** The absolue path list of the file objects which user has chosen to cut/copy. this 216 list will be cleaned after a paste operation or overwritten by a subsequent cut/copy */ 217 QStringList m_copyCutBuffer; 209 218 friend class UIGuestControlFileModel; 210 219 }; … … 231 240 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 232 241 virtual bool createDirectory(const QString &path, const QString &directoryName); 242 virtual QString fsObjectPropertyString() /* override */; 233 243 234 244 private: 235 245 236 static FileObjectType getFileType(const CFsObjInfo &fsInfo);246 static FileObjectType fileType(const CFsObjInfo &fsInfo); 237 247 bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath); 238 248 bool copyHostToGuest(const QString& hostSourcePath, const QString &guestDestinationPath); … … 254 264 protected: 255 265 256 static FileObjectType getFileType(const QFileInfo &fsInfo);266 static FileObjectType fileType(const QFileInfo &fsInfo); 257 267 void retranslateUi() /* override */; 258 268 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */; … … 261 271 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 262 272 virtual bool createDirectory(const QString &path, const QString &directoryName); 273 virtual QString fsObjectPropertyString() /* override */; 274 263 275 }; 264 276
Note:
See TracChangeset
for help on using the changeset viewer.