Changeset 71269 in vbox
- Timestamp:
- Mar 8, 2018 10:50:12 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp
r71258 r71269 27 27 # include <QItemDelegate> 28 28 # include <QGridLayout> 29 # include <QPushButton> 29 30 30 31 /* GUI includes: */ 32 # include "QIDialog.h" 33 # include "QIDialogButtonBox.h" 31 34 # include "QILabel.h" 32 35 # include "QILineEdit.h" … … 44 47 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 45 48 49 50 /********************************************************************************************************************************* 51 * UIFileDelegate definition. * 52 *********************************************************************************************************************************/ 53 /** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */ 46 54 class UIFileDelegate : public QItemDelegate 47 55 { … … 52 60 virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {} 53 61 }; 62 63 64 /********************************************************************************************************************************* 65 * UIFileStringInputDialog definition. * 66 *********************************************************************************************************************************/ 67 /** A QIDialog child including a line edit whose text exposed when the dialog is accepted */ 68 class UIStringInputDialog : public QIDialog 69 { 70 71 Q_OBJECT; 72 73 public: 74 75 UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0); 76 QString getString() const; 77 78 private: 79 80 QILineEdit *m_pLineEdit; 81 82 // virtual void accept() /* override */; 83 // virtual void reject() /* override */; 84 85 }; 86 54 87 55 88 … … 106 139 107 140 141 /********************************************************************************************************************************* 142 * UIFileStringInputDialog implementation. * 143 *********************************************************************************************************************************/ 144 UIStringInputDialog::UIStringInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */) 145 :QIDialog(pParent, flags) 146 { 147 QVBoxLayout *layout = new QVBoxLayout(this); 148 m_pLineEdit = new QILineEdit(this); 149 layout->addWidget(m_pLineEdit); 150 151 QIDialogButtonBox *pButtonBox = 152 new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 153 layout->addWidget(pButtonBox); 154 // { 155 // /* Configure button-box: */ 156 connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept); 157 connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject); 158 159 } 160 161 QString UIStringInputDialog::getString() const 162 { 163 if (!m_pLineEdit) 164 return QString(); 165 return m_pLineEdit->text(); 166 } 167 168 169 /********************************************************************************************************************************* 170 * UIFileTableItem implementation. * 171 *********************************************************************************************************************************/ 172 173 108 174 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, bool isDirectory, UIFileTableItem *parent) 109 175 : m_itemData(data) … … 306 372 if (item->isUpDirectory() && index.column() != 0) 307 373 return QVariant(); 374 /* Format date/time column: */ 375 if (item->data(index.column()).canConvert(QMetaType::QDateTime)) 376 { 377 QDateTime dateTime = item->data(index.column()).toDateTime(); 378 if (dateTime.isValid()) 379 return dateTime.toString("dd.MM.yyyy hh:mm:ss"); 380 } 308 381 return item->data(index.column()); 309 382 } … … 430 503 { 431 504 endResetModel(); 505 } 506 507 bool UIGuestControlFileModel::insertRows(int position, int rows, const QModelIndex &parent) 508 { 509 UIFileTableItem *parentItem = static_cast<UIFileTableItem*>(parent.internalPointer()); 510 511 if (!parentItem) 512 return false; 513 beginInsertRows(parent, position, position + rows -1); 514 515 QList<QVariant> data; 516 data << "New Item" << 0 << QDateTime::currentDateTime(); 517 UIFileTableItem *newItem = new UIFileTableItem(data, true, parentItem); 518 parentItem->appendChild(newItem); 519 endInsertRows(); 520 521 return true; 432 522 } 433 523 … … 452 542 , m_pDelete(0) 453 543 , m_pRename(0) 454 , m_p NewFolder(0)544 , m_pCreateNewDirectory(0) 455 545 , m_pCopy(0) 456 546 , m_pCut(0) … … 586 676 } 587 677 588 m_p NewFolder= new QAction(this);589 if (m_p NewFolder)590 { 591 m_pNewFolder->setIcon(UIIconPool::iconSet(QString(":/sf_32px.png")));592 m_p ToolBar->addAction(m_pNewFolder);593 m_p NewFolder->setEnabled(false);678 m_pCreateNewDirectory = new QAction(this); 679 if (m_pCreateNewDirectory) 680 { 681 connect(m_pCreateNewDirectory, &QAction::triggered, this, &UIGuestControlFileTable::sltCreateNewDirectory); 682 m_pCreateNewDirectory->setIcon(UIIconPool::iconSet(QString(":/sf_32px.png"))); 683 m_pToolBar->addAction(m_pCreateNewDirectory); 594 684 } 595 685 … … 812 902 deleteByIndex(selectedItemIndices.at(i)); 813 903 } 904 /** @todo dont refresh here, just delete the rows and update the table view: */ 814 905 refresh(); 815 906 } … … 830 921 return; 831 922 m_pView->edit(selectedItemIndices.at(0)); 832 833 } 923 } 924 925 void UIGuestControlFileTable::sltCreateNewDirectory() 926 { 927 if (!m_pModel || !m_pView) 928 return; 929 QModelIndex currentIndex = m_pView->rootIndex(); 930 if (!currentIndex.isValid()) 931 return; 932 UIFileTableItem *item = static_cast<UIFileTableItem*>(currentIndex.internalPointer()); 933 if (!item) 934 return; 935 936 QString newDirectoryName = getNewDirectoryName(); 937 if (newDirectoryName.isEmpty()) 938 return; 939 940 if (createDirectory(item->path(), newDirectoryName)) 941 { 942 /** @todo instead of refreshing here (an overkill) just add the 943 rows and update the tabel view: */ 944 sltRefresh(); 945 } 946 947 } 948 834 949 835 950 void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex) … … 852 967 if (m_pGoHome) 853 968 { 854 m_pGoHome->setText(UIVMInformationDialog::tr("Go to home folder"));855 m_pGoHome->setToolTip(UIVMInformationDialog::tr("Go to home folder"));856 m_pGoHome->setStatusTip(UIVMInformationDialog::tr("Go to home folder"));969 m_pGoHome->setText(UIVMInformationDialog::tr("Go to home directory")); 970 m_pGoHome->setToolTip(UIVMInformationDialog::tr("Go to home directory")); 971 m_pGoHome->setStatusTip(UIVMInformationDialog::tr("Go to home directory")); 857 972 } 858 973 … … 877 992 } 878 993 879 if (m_p NewFolder)880 { 881 m_p NewFolder->setText(UIVMInformationDialog::tr("Create a new folder"));882 m_p NewFolder->setToolTip(UIVMInformationDialog::tr("Create a new folder"));883 m_p NewFolder->setStatusTip(UIVMInformationDialog::tr("Create a new folder"));994 if (m_pCreateNewDirectory) 995 { 996 m_pCreateNewDirectory->setText(UIVMInformationDialog::tr("Create a new directory")); 997 m_pCreateNewDirectory->setToolTip(UIVMInformationDialog::tr("Create a new directory")); 998 m_pCreateNewDirectory->setStatusTip(UIVMInformationDialog::tr("Create a new directory")); 884 999 885 1000 } … … 927 1042 } 928 1043 } 929 else if (pEvent->key() == Qt::Key_Delete)1044 else if (pEvent->key() == Qt::Key_Delete) 930 1045 { 931 1046 sltDelete(); … … 958 1073 } 959 1074 1075 QString UIGuestControlFileTable::mergePaths(const QString &path, const QString &baseName) 1076 { 1077 QString newPath(path); 1078 /* make sure we have a trailing '/': */ 1079 if (newPath.at(newPath.length() - 1) != QChar('/')) 1080 newPath += QChar('/'); 1081 newPath += baseName; 1082 return newPath; 1083 } 1084 1085 QString UIGuestControlFileTable::getNewDirectoryName() 1086 { 1087 UIStringInputDialog *dialog = new UIStringInputDialog(); 1088 if (dialog->execute()) 1089 { 1090 QString strDialog = dialog->getString(); 1091 delete dialog; 1092 return strDialog; 1093 } 1094 delete dialog; 1095 return QString(); 1096 } 1097 960 1098 961 1099 /********************************************************************************************************************************* … … 1012 1150 { 1013 1151 QList<QVariant> data; 1014 QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/1000); 1152 QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/1000000); 1153 1015 1154 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize()) << changeTime; 1016 1155 bool isDirectory = (fsInfo.GetType() == KFsObjType_Directory); … … 1081 1220 } 1082 1221 1222 bool UIGuestFileTable::createDirectory(const QString &path, const QString &directoryName) 1223 { 1224 if (!m_comGuestSession.isOk()) 1225 return false; 1226 1227 QString newDirectoryPath = mergePaths(path, directoryName); 1228 QVector<KDirectoryCreateFlag> flags(KDirectoryCreateFlag_None); 1229 1230 m_comGuestSession.DirectoryCreate(newDirectoryPath, 777/*aMode*/, flags); 1231 if (!m_comGuestSession.isOk()) 1232 { 1233 emit sigLogOutput(newDirectoryPath.append(" could not be created")); 1234 return false; 1235 } 1236 emit sigLogOutput(newDirectoryPath.append(" has been created")); 1237 return true; 1238 } 1239 1083 1240 1084 1241 /********************************************************************************************************************************* … … 1160 1317 void UIHostFileTable::goToHomeDirectory() 1161 1318 { 1162 if (!m_pRootItem || m_pRootItem->childCount() <= 0)1319 if (!m_pRootItem || m_pRootItem->childCount() <= 0) 1163 1320 return; 1164 1321 UIFileTableItem *startDirItem = m_pRootItem->child(0); … … 1187 1344 } 1188 1345 1346 bool UIHostFileTable::createDirectory(const QString &path, const QString &directoryName) 1347 { 1348 QDir parentDir(path); 1349 if (!parentDir.mkdir(directoryName)) 1350 { 1351 emit sigLogOutput(mergePaths(path, directoryName).append(" could not be created")); 1352 return false; 1353 } 1354 1355 return true; 1356 } 1189 1357 1190 1358 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.h
r71258 r71269 72 72 void beginReset(); 73 73 void endReset(); 74 bool insertRows(int position, int rows, const QModelIndex &parent); 74 75 75 76 private: … … 115 116 virtual void goToHomeDirectory() = 0; 116 117 virtual bool renameItem(UIFileTableItem *item, QString newBaseName) = 0; 118 virtual bool createDirectory(const QString &path, const QString &directoryName) = 0; 117 119 void goIntoDirectory(const QModelIndex &itemIndex); 118 120 /** Follow the path trail, open directories as we go and descend */ … … 125 127 /** Replace the last part of the @p previusPath with newBaseName */ 126 128 QString constructNewItemPath(const QString &previousPath, const QString &newBaseName); 129 QString mergePaths(const QString &Path, const QString &baseName); 127 130 128 131 UIFileTableItem *m_pRootItem; … … 144 147 void sltDelete(); 145 148 void sltRename(); 149 void sltCreateNewDirectory(); 146 150 147 151 private: … … 152 156 /** Return the UIFileTableItem for path / which is a direct (and single) child of m_pRootItem */ 153 157 UIFileTableItem *getStartDirectoryItem(); 154 158 /** Shows a modal dialog with a line edit for user to enter a new directory name and return the entered string*/ 159 QString getNewDirectoryName(); 155 160 QGridLayout *m_pMainLayout; 156 161 QILineEdit *m_pCurrentLocationEdit; … … 161 166 QAction *m_pDelete; 162 167 QAction *m_pRename; 163 QAction *m_p NewFolder;168 QAction *m_pCreateNewDirectory; 164 169 165 170 QAction *m_pCopy; … … 188 193 virtual void goToHomeDirectory() /* override */; 189 194 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 195 virtual bool createDirectory(const QString &path, const QString &directoryName); 190 196 191 197 private: … … 213 219 virtual void goToHomeDirectory() /* override */; 214 220 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 221 virtual bool createDirectory(const QString &path, const QString &directoryName); 215 222 }; 216 223
Note:
See TracChangeset
for help on using the changeset viewer.