Changeset 24055 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Oct 24, 2009 3:55:47 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53914
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsSF.h
r16966 r24055 6 6 7 7 /* 8 * Copyright (C) 200 6-2008Sun Microsystems, Inc.8 * Copyright (C) 2008-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 #define __VBoxVMSettingsSF_h__ 25 25 26 /* Local includes */ 26 27 #include "VBoxSettingsPage.h" 27 28 #include "VBoxVMSettingsSF.gen.h" 28 29 30 /* Local forwards */ 29 31 class SFTreeViewItem; 30 32 … … 36 38 ConsoleType = 0x04 37 39 }; 38 typedef QPair <QString, SFDialogType> SFolderName;39 typedef QList <SFolderName> SFoldersNameList;40 typedef QPair <QString, SFDialogType> SFolderName; 41 typedef QList <SFolderName> SFoldersNameList; 40 42 41 class VBoxVMSettingsSF : public VBoxSettingsPage, 42 public Ui::VBoxVMSettingsSF 43 class VBoxVMSettingsSF : public VBoxSettingsPage, public Ui::VBoxVMSettingsSF 43 44 { 44 45 Q_OBJECT; … … 56 57 void putBackToConsole(); 57 58 58 int dialogType() { return mDialogType; }59 int dialogType() const; 59 60 60 61 protected: … … 73 74 void delTriggered(); 74 75 75 void processCurrentChanged (QTreeWidgetItem *aCurrentItem, 76 QTreeWidgetItem *aPreviousItem = 0); 77 void processDoubleClick (QTreeWidgetItem *aItem, int aColumn); 76 void processCurrentChanged (QTreeWidgetItem *aCurrentItem); 77 void processDoubleClick (QTreeWidgetItem *aItem); 78 78 void showContextMenu (const QPoint &aPos); 79 79 … … 85 85 void showEvent (QShowEvent *aEvent); 86 86 87 void removeSharedFolder (const QString &aName, const QString &aPath, 88 SFDialogType aType); 89 void createSharedFolder (const QString &aName, const QString &aPath, 90 bool aWritable, 91 SFDialogType aType); 87 void createSharedFolder (const QString &aName, const QString &aPath, bool aWritable, SFDialogType aType); 88 void removeSharedFolder (const QString &aName, const QString &aPath, SFDialogType aType); 92 89 93 90 void getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aItem); 94 void putBackTo 91 void putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aItem); 95 92 96 SFTreeViewItem* searchRoot (bool aIsPermanent, 97 SFDialogType aType = WrongType); 98 bool isEditable (const QString &); 93 SFTreeViewItem* searchRoot (bool aIsPermanent, SFDialogType aType = WrongType); 94 bool isEditable (const QString &aKey); 99 95 SFoldersNameList usedList (bool aIncludeSelected); 100 96 101 97 int mDialogType; 102 QMenu *mMenu;103 98 QAction *mNewAction; 104 99 QAction *mEdtAction; -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsSF.cpp
r16966 r24055 6 6 7 7 /* 8 * Copyright (C) 200 6-2008Sun Microsystems, Inc.8 * Copyright (C) 2008-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 */ 22 22 23 /* Global includes */ 24 #include <QHeaderView> 25 #include <QTimer> 26 27 /* Local includes */ 23 28 #include "VBoxVMSettingsSF.h" 24 29 #include "VBoxVMSettingsSFDetails.h" … … 26 31 #include "VBoxProblemReporter.h" 27 32 #include "VBoxUtils.h" 28 #include "VBoxToolBar.h"29 30 /* Qt includes */31 #include <QHeaderView>32 #include <QTimer>33 33 34 34 class SFTreeViewItem : public QTreeWidgetItem … … 36 36 public: 37 37 38 enum { SFTreeViewItem Id = 1001 };38 enum { SFTreeViewItemType = QTreeWidgetItem::UserType + 1 }; 39 39 40 40 enum FormatType … … 47 47 }; 48 48 49 /* root item */ 50 SFTreeViewItem (QTreeWidget *aParent, const QStringList &aFields, 51 FormatType aFormat) : 52 QTreeWidgetItem (aParent, aFields, SFTreeViewItemId), mFormat (aFormat) 49 /* Root Item */ 50 SFTreeViewItem (QTreeWidget *aParent, const QStringList &aFields, FormatType aFormat) 51 : QTreeWidgetItem (aParent, aFields, SFTreeViewItemType), mFormat (aFormat) 53 52 { 54 53 setFirstColumnSpanned (true); … … 56 55 } 57 56 58 /* child item */ 59 SFTreeViewItem (SFTreeViewItem *aParent, const QStringList &aFields, 60 FormatType aFormat) : 61 QTreeWidgetItem (aParent, aFields, SFTreeViewItemId), mFormat (aFormat) 57 /* Child Item */ 58 SFTreeViewItem (SFTreeViewItem *aParent, const QStringList &aFields, FormatType aFormat) 59 : QTreeWidgetItem (aParent, aFields, SFTreeViewItemType), mFormat (aFormat) 62 60 { 63 61 updateText (aFields); … … 74 72 { 75 73 QTreeWidgetItem *item = QTreeWidgetItem::child (aIndex); 76 return item && item->type() == SFTreeViewItemId ? 77 static_cast<SFTreeViewItem*> (item) : 0; 74 return item && item->type() == SFTreeViewItemType ? static_cast <SFTreeViewItem*> (item) : 0; 78 75 } 79 76 80 77 QString getText (int aIndex) const 81 78 { 82 return aIndex >= 0 && aIndex < (int)mTextList.size() ? 83 mTextList [aIndex] : QString::null; 79 return aIndex >= 0 && aIndex < (int)mTextList.size() ? mTextList [aIndex] : QString::null; 84 80 } 85 81 … … 104 100 if (oneString.isNull()) 105 101 return; 106 int oldSize = treeWidget()->fontMetrics().width (oneString);107 int indentSize = treeWidget()->fontMetrics().width ("x...x");108 int i temIndent = parent() ? treeWidget()->indentation() * 2 :109 102 QFontMetrics fm = treeWidget()->fontMetrics(); 103 int oldSize = fm.width (oneString); 104 int indentSize = fm.width (" ... "); 105 int itemIndent = parent() ? treeWidget()->indentation() * 2 : treeWidget()->indentation(); 110 106 if (aColumn == 0) 111 107 indentSize += itemIndent; 112 108 int cWidth = treeWidget()->columnWidth (aColumn); 113 109 114 /* compress text */110 /* Compress text */ 115 111 int start = 0; 116 112 int finish = 0; 117 113 int position = 0; 118 114 int textWidth = 0; 119 do { 120 textWidth = treeWidget()->fontMetrics().width (oneString); 115 do 116 { 117 textWidth = fm.width (oneString); 121 118 if (textWidth + indentSize > cWidth) 122 119 { … … 124 121 finish = oneString.length(); 125 122 126 /* selecting remove position */123 /* Selecting remove position */ 127 124 switch (mFormat) 128 125 { … … 154 151 oneString.remove (position, 1); 155 152 } 156 } while (textWidth + indentSize > cWidth); 153 } 154 while (textWidth + indentSize > cWidth); 157 155 158 156 if (position || mFormat == EllipsisFile) oneString.insert (position, "..."); 159 int newSize = treeWidget()->fontMetrics().width (oneString);157 int newSize = fm.width (oneString); 160 158 setText (aColumn, newSize < oldSize ? oneString : mTextList [aColumn]); 161 setToolTip (aColumn, text (aColumn) == getText (aColumn) ? 162 QString::null : getText (aColumn)); 159 setToolTip (aColumn, text (aColumn) == getText (aColumn) ? QString::null : getText (aColumn)); 160 161 /* Calculate item's size-hint */ 162 setSizeHint (aColumn, QSize (fm.width (QString (" %1 ").arg (getText (aColumn))), 100)); 163 163 } 164 164 … … 166 166 QStringList mTextList; 167 167 }; 168 169 168 170 169 VBoxVMSettingsSF::VBoxVMSettingsSF (int aType, QWidget *aParent) … … 177 176 178 177 /* Prepare actions */ 179 mNewAction = new QAction (mTreeView); 180 mEdtAction = new QAction (mTreeView); 181 mDelAction = new QAction (mTreeView); 182 183 mNewAction->setText (tr ("&Add New Shared Folder")); 184 mEdtAction->setText (tr ("&Edit Selected Shared Folder")); 185 mDelAction->setText (tr ("&Remove Selected Shared Folder")); 178 mNewAction = new QAction (this); 179 mEdtAction = new QAction (this); 180 mDelAction = new QAction (this); 186 181 187 182 mNewAction->setShortcut (QKeySequence ("Ins")); 188 183 mEdtAction->setShortcut (QKeySequence ("Ctrl+Space")); 189 184 mDelAction->setShortcut (QKeySequence ("Del")); 190 191 mNewAction->setToolTip (mNewAction->text().remove ('&') +192 QString (" (%1)").arg (mNewAction->shortcut().toString()));193 mEdtAction->setToolTip (mEdtAction->text().remove ('&') +194 QString (" (%1)").arg (mEdtAction->shortcut().toString()));195 mDelAction->setToolTip (mDelAction->text().remove ('&') +196 QString (" (%1)").arg (mDelAction->shortcut().toString()));197 198 mNewAction->setWhatsThis (tr ("Adds a new shared folder definition."));199 mEdtAction->setWhatsThis (tr ("Edits the selected shared folder definition."));200 mDelAction->setWhatsThis (tr ("Removes the selected shared folder definition."));201 185 202 186 mNewAction->setIcon (VBoxGlobal::iconSet (":/add_shared_folder_16px.png", … … 207 191 ":/revome_shared_folder_disabled_16px.png")); 208 192 209 /* Prepare menu and toolbar */210 mMenu = new QMenu (mTreeView);211 mMenu->addAction (mNewAction);212 mMenu->addAction (mEdtAction);213 mMenu->addSeparator();214 mMenu->addAction (mDelAction);215 216 193 /* Prepare toolbar */ 217 VBoxToolBar *toolBar = new VBoxToolBar (mGbSharedFolders); 218 toolBar->setUsesTextLabel (false); 219 toolBar->setIconSize (QSize (16, 16)); 220 toolBar->setOrientation (Qt::Vertical); 221 toolBar->addAction (mNewAction); 222 toolBar->addAction (mEdtAction); 223 toolBar->addAction (mDelAction); 224 mGbSharedFolders->layout()->addWidget (toolBar); 194 mTbFolders->setUsesTextLabel (false); 195 mTbFolders->setIconSize (QSize (16, 16)); 196 mTbFolders->setOrientation (Qt::Vertical); 197 mTbFolders->addAction (mNewAction); 198 mTbFolders->addAction (mEdtAction); 199 mTbFolders->addAction (mDelAction); 225 200 226 201 /* Setup connections */ 227 mT reeView->header()->setMovable (false);202 mTwFolders->header()->setMovable (false); 228 203 connect (mNewAction, SIGNAL (triggered (bool)), this, SLOT (addTriggered())); 229 204 connect (mEdtAction, SIGNAL (triggered (bool)), this, SLOT (edtTriggered())); 230 205 connect (mDelAction, SIGNAL (triggered (bool)), this, SLOT (delTriggered())); 231 connect (mT reeView, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),232 this, SLOT (processCurrentChanged (QTreeWidgetItem *, QTreeWidgetItem*)));233 connect (mT reeView, SIGNAL (itemDoubleClicked (QTreeWidgetItem*, int)),234 this, SLOT (processDoubleClick (QTreeWidgetItem *, int)));235 connect (mT reeView, SIGNAL (customContextMenuRequested (const QPoint &)),206 connect (mTwFolders, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)), 207 this, SLOT (processCurrentChanged (QTreeWidgetItem *))); 208 connect (mTwFolders, SIGNAL (itemDoubleClicked (QTreeWidgetItem *, int)), 209 this, SLOT (processDoubleClick (QTreeWidgetItem *))); 210 connect (mTwFolders, SIGNAL (customContextMenuRequested (const QPoint &)), 236 211 this, SLOT (showContextMenu (const QPoint &))); 237 212 238 /* Set mTreeView as the focus proxy for the mGbSharedFolders */ 239 new QIFocusProxy (mGbSharedFolders, mTreeView); 240 241 /* Create mTreeView root items */ 242 //if (aType == GlobalType) 243 //{ 244 // QStringList fields; 245 // fields << tr (" Global Folders") /* name */ 246 // << QString::number (GlobalType) /* key */; 247 // new SFTreeViewItem (mTreeView, fields, SFTreeViewItem::EllipsisEnd); 248 //} 213 /* Create mTwFolders root items */ 214 #if 0 215 if (aType == GlobalType) 216 { 217 QStringList fields; 218 fields << tr (" Global Folders") /* name */ << QString::number (GlobalType) /* key */; 219 new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd); 220 } 221 #endif 249 222 if (aType & MachineType) 250 223 { 251 224 QStringList fields; 252 fields << tr (" Machine Folders") /* name */ 253 << QString::number (MachineType) /* key */; 254 new SFTreeViewItem (mTreeView, fields, SFTreeViewItem::EllipsisEnd); 225 fields << tr (" Machine Folders") /* name */ << QString::number (MachineType) /* key */; 226 new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd); 255 227 } 256 228 if (aType & ConsoleType) 257 229 { 258 230 QStringList fields; 259 fields << tr (" Transient Folders") /* name */ 260 << QString::number (ConsoleType) /* key */; 261 new SFTreeViewItem (mTreeView, fields, SFTreeViewItem::EllipsisEnd); 262 } 263 mTreeView->sortItems (0, Qt::AscendingOrder); 231 fields << tr (" Transient Folders") /* name */ << QString::number (ConsoleType) /* key */; 232 new SFTreeViewItem (mTwFolders, fields, SFTreeViewItem::EllipsisEnd); 233 } 234 mTwFolders->sortItems (0, Qt::AscendingOrder); 264 235 265 236 retranslateUi(); 266 237 } 267 238 268 269 239 void VBoxVMSettingsSF::getFromGlobal() 270 240 { 271 AssertMsgFailed (("Global shared folders are not implemented yet\n")); 272 //SFTreeViewItem *root = searchRoot (true, GlobalType); 273 //root->setHidden (false); 274 //getFrom (vboxGlobal().virtualBox().GetSharedFolders(), root); 241 AssertMsgFailed (("Global shared folders are not supported now!\n")); 242 #if 0 243 SFTreeViewItem *root = searchRoot (true, GlobalType); 244 root->setHidden (false); 245 getFrom (vboxGlobal().virtualBox().GetSharedFolders(), root); 246 #endif 275 247 } 276 248 … … 291 263 } 292 264 293 294 265 void VBoxVMSettingsSF::putBackToGlobal() 295 266 { 296 AssertMsgFailed (("Global shared folders are not implemented yet\n")); 297 //if (!mIsListViewChanged) 298 // return; 299 // 300 ///* This function is only available for GlobalType dialog */ 301 //Assert (mDialogType == GlobalType); 302 ///* Searching for GlobalType item's root */ 303 //SFTreeViewItem *root = searchRoot (true, GlobalType); 304 //Assert (root); 305 //CSharedFolderVector vec = 306 // vboxGlobal().virtualBox().GetSharedFolders(); 307 //putBackTo (vec, root); 308 } 309 310 void VBoxVMSettingsSF::putBackToMachine() 311 { 267 AssertMsgFailed (("Global shared folders are not supported now!\n")); 268 #if 0 312 269 if (!mIsListViewChanged) 313 270 return; 314 271 /* This function is only available for GlobalType dialog */ 272 Assert (mDialogType == GlobalType); 273 /* Searching for GlobalType item's root */ 274 SFTreeViewItem *root = searchRoot (true, GlobalType); 275 Assert (root); 276 CSharedFolderVector vec = vboxGlobal().virtualBox().GetSharedFolders(); 277 putBackTo (vec, root); 278 #endif 279 } 280 281 void VBoxVMSettingsSF::putBackToMachine() 282 { 283 if (!mIsListViewChanged) 284 return; 315 285 /* This function is only available for MachineType dialog */ 316 286 Assert (mDialogType & MachineType); … … 326 296 if (!mIsListViewChanged) 327 297 return; 328 329 298 /* This function is only available for ConsoleType dialog */ 330 299 Assert (mDialogType & ConsoleType); … … 336 305 } 337 306 307 int VBoxVMSettingsSF::dialogType() const 308 { 309 return mDialogType; 310 } 338 311 339 312 void VBoxVMSettingsSF::getFrom (const CMachine &aMachine) … … 349 322 void VBoxVMSettingsSF::setOrderAfter (QWidget *aWidget) 350 323 { 351 setTabOrder (aWidget, mT reeView);324 setTabOrder (aWidget, mTwFolders); 352 325 } 353 326 … … 357 330 Ui::VBoxVMSettingsSF::retranslateUi (this); 358 331 332 mNewAction->setText (tr ("&Add Shared Folder")); 333 mEdtAction->setText (tr ("&Edit Shared Folder")); 334 mDelAction->setText (tr ("&Remove Shared Folder")); 335 336 mNewAction->setToolTip (mNewAction->text().remove ('&') + 337 QString (" (%1)").arg (mNewAction->shortcut().toString())); 338 mEdtAction->setToolTip (mEdtAction->text().remove ('&') + 339 QString (" (%1)").arg (mEdtAction->shortcut().toString())); 340 mDelAction->setToolTip (mDelAction->text().remove ('&') + 341 QString (" (%1)").arg (mDelAction->shortcut().toString())); 342 343 mNewAction->setWhatsThis (tr ("Adds a new shared folder definition.")); 344 mEdtAction->setWhatsThis (tr ("Edits the selected shared folder definition.")); 345 mDelAction->setWhatsThis (tr ("Removes the selected shared folder definition.")); 346 359 347 mTrFull = tr ("Full"); 360 348 mTrReadOnly = tr ("Read-only"); 361 349 } 362 350 363 364 351 void VBoxVMSettingsSF::addTriggered() 365 352 { 366 353 /* Invoke Add-Box Dialog */ 367 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::AddType, 368 mDialogType & ConsoleType, 369 usedList (true), 370 this); 354 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::AddType, mDialogType & ConsoleType, usedList (true), this); 371 355 if (dlg.exec() == QDialog::Accepted) 372 356 { … … 382 366 QStringList fields; 383 367 fields << name /* name */ << path /* path */ 384 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */) 385 << "edited" /* mark item as edited */; 386 SFTreeViewItem *item = new SFTreeViewItem (root, fields, 387 SFTreeViewItem::EllipsisFile); 388 mTreeView->sortItems (0, Qt::AscendingOrder); 389 mTreeView->scrollToItem (item); 390 mTreeView->setCurrentItem (item); 368 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */) 369 << "edited" /* mark item as edited */; 370 SFTreeViewItem *item = new SFTreeViewItem (root, fields, SFTreeViewItem::EllipsisFile); 371 mTwFolders->sortItems (0, Qt::AscendingOrder); 372 mTwFolders->scrollToItem (item); 373 mTwFolders->setCurrentItem (item); 391 374 processCurrentChanged (item); 392 mT reeView->setFocus();375 mTwFolders->setFocus(); 393 376 adjustList(); 394 377 … … 400 383 { 401 384 /* Check selected item */ 402 QTreeWidgetItem *selectedItem = mTreeView->selectedItems().size() == 1 ? 403 mTreeView->selectedItems() [0] : 0; 404 SFTreeViewItem *item = selectedItem && 405 selectedItem->type() == SFTreeViewItem::SFTreeViewItemId ? 406 static_cast<SFTreeViewItem*> (selectedItem) : 0; 385 QTreeWidgetItem *selectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems() [0] : 0; 386 SFTreeViewItem *item = selectedItem && selectedItem->type() == SFTreeViewItem::SFTreeViewItemType ? 387 static_cast <SFTreeViewItem*> (selectedItem) : 0; 407 388 Assert (item); 408 389 Assert (item->parent()); 409 390 410 391 /* Invoke Edit-Box Dialog */ 411 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::EditType, 412 mDialogType & ConsoleType, 413 usedList (false), 414 this); 392 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::EditType, mDialogType & ConsoleType, usedList (false), this); 415 393 dlg.setPath (item->getText (1)); 416 394 dlg.setName (item->getText (0)); 417 dlg.setPermanent ((SFDialogType)item->parent()->text (1).toInt() 418 != ConsoleType); 395 dlg.setPermanent ((SFDialogType)item->parent()->text (1).toInt() != ConsoleType); 419 396 dlg.setWriteable (item->getText (2) == mTrFull); 420 397 if (dlg.exec() == QDialog::Accepted) … … 431 408 QStringList fields; 432 409 fields << name /* name */ << path /* path */ 433 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */)434 << "edited" /* mark item as edited */;410 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */) 411 << "edited" /* mark item as edited */; 435 412 item->updateText (fields); 436 mT reeView->sortItems (0, Qt::AscendingOrder);413 mTwFolders->sortItems (0, Qt::AscendingOrder); 437 414 if (item->parent() != root) 438 415 { … … 440 417 item->parent()->takeChild (item->parent()->indexOfChild (item)); 441 418 root->insertChild (root->childCount(), item); 442 mT reeView->scrollToItem (item);443 mT reeView->setCurrentItem (item);419 mTwFolders->scrollToItem (item); 420 mTwFolders->setCurrentItem (item); 444 421 processCurrentChanged (item); 445 mT reeView->setFocus();422 mTwFolders->setFocus(); 446 423 } 447 424 adjustList(); … … 453 430 void VBoxVMSettingsSF::delTriggered() 454 431 { 455 QTreeWidgetItem *selectedItem = mTreeView->selectedItems().size() == 1 ? 456 mTreeView->selectedItems() [0] : 0; 432 QTreeWidgetItem *selectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems() [0] : 0; 457 433 Assert (selectedItem); 458 434 delete selectedItem; … … 461 437 } 462 438 463 464 void VBoxVMSettingsSF::processCurrentChanged ( 465 QTreeWidgetItem *aCurrentItem, QTreeWidgetItem* /* aPreviousItem */) 439 void VBoxVMSettingsSF::processCurrentChanged (QTreeWidgetItem *aCurrentItem) 466 440 { 467 441 if (aCurrentItem && aCurrentItem->parent() && !aCurrentItem->isSelected()) 468 442 aCurrentItem->setSelected (true); 469 QString key = !aCurrentItem ? QString::null : 470 aCurrentItem->parent() ? aCurrentItem->parent()->text (1) : 471 aCurrentItem->text (1); 443 QString key = !aCurrentItem ? QString::null : aCurrentItem->parent() ? 444 aCurrentItem->parent()->text (1) : aCurrentItem->text (1); 472 445 bool addEnabled = aCurrentItem && isEditable (key); 473 446 bool removeEnabled = addEnabled && aCurrentItem->parent(); … … 477 450 } 478 451 479 void VBoxVMSettingsSF::processDoubleClick (QTreeWidgetItem *aItem, 480 int /* aColumn */) 481 { 482 bool editEnabled = aItem && aItem->parent() && 483 isEditable (aItem->parent()->text (1)); 452 void VBoxVMSettingsSF::processDoubleClick (QTreeWidgetItem *aItem) 453 { 454 bool editEnabled = aItem && aItem->parent() && isEditable (aItem->parent()->text (1)); 484 455 if (editEnabled) 485 456 edtTriggered(); … … 488 459 void VBoxVMSettingsSF::showContextMenu (const QPoint &aPos) 489 460 { 490 mMenu->exec (mTreeView->mapToGlobal (aPos)); 491 } 492 461 QMenu menu; 462 QTreeWidgetItem *item = mTwFolders->itemAt (aPos); 463 if (item && item->flags() & Qt::ItemIsSelectable) 464 { 465 menu.addAction (mEdtAction); 466 menu.addAction (mDelAction); 467 } 468 else 469 { 470 menu.addAction (mNewAction); 471 } 472 menu.exec (mTwFolders->viewport()->mapToGlobal (aPos)); 473 } 493 474 494 475 void VBoxVMSettingsSF::adjustList() 495 476 { 496 /* Adjust two columns size. 497 * Watching columns 0&2 to feat 1/3 of total width. */ 498 int total = mTreeView->viewport()->width(); 499 500 mTreeView->resizeColumnToContents (0); 501 int w0 = mTreeView->columnWidth (0) < total / 3 ? 502 mTreeView->columnWidth (0) : total / 3; 503 504 mTreeView->resizeColumnToContents (2); 505 int w2 = mTreeView->columnWidth (2) < total / 3 ? 506 mTreeView->columnWidth (2) : total / 3; 507 508 /* We are adjusting columns 0 and 2 and resizing column 1 to feat 509 * visible mTreeView' width according two adjusted columns. Due to 510 * adjusting column 2 influent column 0 restoring all widths. */ 511 mTreeView->setColumnWidth (0, w0); 512 mTreeView->setColumnWidth (1, total - w0 - w2); 513 mTreeView->setColumnWidth (2, w2); 477 /* Calculating required columns size & watching those columns (0 and 2) to feat 1/3 of total width. */ 478 QAbstractItemView *itemView = mTwFolders; 479 QHeaderView *itemHeader = mTwFolders->header(); 480 int total = mTwFolders->viewport()->width(); 481 int mw0 = qMax (itemView->sizeHintForColumn (0), itemHeader->sectionSizeHint (0)); 482 int mw2 = qMax (itemView->sizeHintForColumn (2), itemHeader->sectionSizeHint (2)); 483 int w0 = mw0 < total / 3 ? mw0 : total / 3; 484 int w2 = mw2 < total / 3 ? mw2 : total / 3; 485 486 /* Giving 1st column all the available space. */ 487 mTwFolders->setColumnWidth (0, w0); 488 mTwFolders->setColumnWidth (1, total - w0 - w2); 489 mTwFolders->setColumnWidth (2, w2); 514 490 } 515 491 516 492 void VBoxVMSettingsSF::adjustFields() 517 493 { 518 QTreeWidgetItem *mainRoot = mT reeView->invisibleRootItem();494 QTreeWidgetItem *mainRoot = mTwFolders->invisibleRootItem(); 519 495 for (int i = 0; i < mainRoot->childCount(); ++ i) 520 496 { … … 523 499 { 524 500 SFTreeViewItem *item = subRoot->child (j) && 525 subRoot->child (j)->type() == SFTreeViewItem::SFTreeViewItemId?526 static_cast<SFTreeViewItem*> (subRoot->child (j)) : 0;501 subRoot->child (j)->type() == SFTreeViewItem::SFTreeViewItemType ? 502 static_cast <SFTreeViewItem*> (subRoot->child (j)) : 0; 527 503 if (item) 528 504 item->adjustText(); … … 531 507 } 532 508 533 534 509 void VBoxVMSettingsSF::showEvent (QShowEvent *aEvent) 535 510 { 536 511 QWidget::showEvent (aEvent); 537 512 538 /* Connect header-resize signal just before widget is shown 539 * after all the items properly loaded and initialized. */ 540 connect (mTreeView->header(), SIGNAL (sectionResized (int, int, int)), 541 this, SLOT (adjustFields())); 513 /* Connect header-resize signal just before widget is shown after all the items properly loaded and initialized. */ 514 connect (mTwFolders->header(), SIGNAL (sectionResized (int, int, int)), this, SLOT (adjustFields())); 542 515 543 516 /* Adjusting size after all pending show events are processed. */ … … 545 518 } 546 519 547 548 void VBoxVMSettingsSF::removeSharedFolder (const QString & aName, 549 const QString & aPath, 550 SFDialogType aType) 520 void VBoxVMSettingsSF::createSharedFolder (const QString &aName, const QString &aPath, bool aWritable, SFDialogType aType) 551 521 { 552 522 switch (aType) … … 554 524 case GlobalType: 555 525 { 556 /* This feature is not implemented yet */ 557 AssertMsgFailed (("Global shared folders are not implemented yet\n")); 526 /* This feature is not supported now */ 527 AssertMsgFailed (("Global shared folders are not supported now!\n")); 528 break; 529 } 530 case MachineType: 531 { 532 Assert (!mMachine.isNull()); 533 mMachine.CreateSharedFolder (aName, aPath, aWritable); 534 if (!mMachine.isOk()) 535 vboxProblem().cannotCreateSharedFolder (this, mMachine, aName, aPath); 536 break; 537 } 538 case ConsoleType: 539 { 540 Assert (!mConsole.isNull()); 541 mConsole.CreateSharedFolder (aName, aPath, aWritable); 542 if (!mConsole.isOk()) 543 vboxProblem().cannotCreateSharedFolder (this, mConsole, aName, aPath); 544 break; 545 } 546 default: 547 { 548 AssertMsgFailed (("Incorrect shared folder type\n")); 549 } 550 } 551 } 552 553 void VBoxVMSettingsSF::removeSharedFolder (const QString &aName, const QString &aPath, SFDialogType aType) 554 { 555 switch (aType) 556 { 557 case GlobalType: 558 { 559 /* This feature is not supported now */ 560 AssertMsgFailed (("Global shared folders are not supported now!\n")); 558 561 break; 559 562 } … … 563 566 mMachine.RemoveSharedFolder (aName); 564 567 if (!mMachine.isOk()) 565 vboxProblem().cannotRemoveSharedFolder (this, mMachine, 566 aName, aPath); 568 vboxProblem().cannotRemoveSharedFolder (this, mMachine, aName, aPath); 567 569 break; 568 570 } … … 572 574 mConsole.RemoveSharedFolder (aName); 573 575 if (!mConsole.isOk()) 574 vboxProblem().cannotRemoveSharedFolder (this, mConsole, 575 aName, aPath); 576 vboxProblem().cannotRemoveSharedFolder (this, mConsole, aName, aPath); 576 577 break; 577 578 } … … 583 584 } 584 585 585 void VBoxVMSettingsSF::createSharedFolder (const QString & aName, 586 const QString & aPath, 587 bool aWritable, 588 SFDialogType aType) 589 { 590 switch (aType) 591 { 592 case GlobalType: 593 { 594 /* This feature is not implemented yet */ 595 AssertMsgFailed (("Global shared folders are not implemented yet\n")); 596 break; 597 } 598 case MachineType: 599 { 600 Assert (!mMachine.isNull()); 601 mMachine.CreateSharedFolder (aName, aPath, aWritable); 602 if (!mMachine.isOk()) 603 vboxProblem().cannotCreateSharedFolder (this, mMachine, 604 aName, aPath); 605 break; 606 } 607 case ConsoleType: 608 { 609 Assert (!mConsole.isNull()); 610 mConsole.CreateSharedFolder (aName, aPath, aWritable); 611 if (!mConsole.isOk()) 612 vboxProblem().cannotCreateSharedFolder (this, mConsole, 613 aName, aPath); 614 break; 615 } 616 default: 617 { 618 AssertMsgFailed (("Incorrect shared folder type\n")); 619 } 620 } 621 } 622 623 624 void VBoxVMSettingsSF::getFrom (const CSharedFolderVector &aVec, 625 SFTreeViewItem *aRoot) 626 { 627 for (int i = 0; i < aVec.size(); ++i) 628 { 629 CSharedFolder sf = aVec[i]; 586 void VBoxVMSettingsSF::getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aRoot) 587 { 588 for (int i = 0; i < aVec.size(); ++ i) 589 { 590 CSharedFolder sf = aVec [i]; 630 591 QStringList fields; 631 fields << sf.GetName() /* name */ 632 << sf.GetHostPath() /* path */ 592 fields << sf.GetName() /* name */ << sf.GetHostPath() /* path */ 633 593 << (sf.GetWritable() ? mTrFull : mTrReadOnly /* writable? */) 634 594 << "not edited" /* initially not edited */; … … 636 596 } 637 597 aRoot->setExpanded (true); 638 mT reeView->sortItems (0, Qt::AscendingOrder);639 mT reeView->setCurrentItem (aRoot->childCount() ? aRoot->child (0) : aRoot);598 mTwFolders->sortItems (0, Qt::AscendingOrder); 599 mTwFolders->setCurrentItem (aRoot->childCount() ? aRoot->child (0) : aRoot); 640 600 processCurrentChanged (aRoot->childCount() ? aRoot->child (0) : aRoot); 641 601 } 642 602 643 void VBoxVMSettingsSF::putBackTo (CSharedFolderVector &aVec, 644 SFTreeViewItem *aRoot) 603 void VBoxVMSettingsSF::putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aRoot) 645 604 { 646 605 Assert (!aRoot->text (1).isNull()); 647 SFDialogType type = (SFDialogType) aRoot->text (1).toInt();648 649 /* delete all changed folders from vm */650 for (int idx = 0; idx < aVec.size(); ++ idx)651 { 652 CSharedFolder sf = aVec [idx];606 SFDialogType type = (SFDialogType) aRoot->text (1).toInt(); 607 608 /* Delete all changed folders from vm */ 609 for (int idx = 0; idx < aVec.size(); ++ idx) 610 { 611 CSharedFolder sf = aVec [idx]; 653 612 654 613 /* Iterate through this root's children */ … … 657 616 { 658 617 SFTreeViewItem *item = aRoot->child (i); 659 if (item->getText (0) == sf.GetName() && 660 item->getText (3) == "not edited") 618 if (item->getText (0) == sf.GetName() && item->getText (3) == "not edited") 661 619 break; 662 620 } … … 666 624 } 667 625 668 /* save all edited tree widget items as folders */626 /* Save all edited tree widget items as folders */ 669 627 for (int i = 0; i < aRoot->childCount(); ++ i) 670 628 { 671 629 SFTreeViewItem *item = aRoot->child (i); 672 630 673 if (!item->getText (0).isNull() && !item->getText (1).isNull() && 674 item->getText (3) == "edited") 675 createSharedFolder (item->getText (0), item->getText (1), 676 item->getText (2) == mTrFull ? true : false, type); 677 } 678 } 679 680 681 SFTreeViewItem* VBoxVMSettingsSF::searchRoot (bool aIsPermanent, 682 SFDialogType aType) 683 { 684 QString type = aType != WrongType ? QString::number (aType) : 685 !aIsPermanent ? QString::number (ConsoleType) : 686 mDialogType & MachineType ? QString::number (MachineType) : 687 QString::number (GlobalType); 688 QTreeWidgetItem *mainRoot = mTreeView->invisibleRootItem(); 631 if (!item->getText (0).isNull() && !item->getText (1).isNull() && item->getText (3) == "edited") 632 createSharedFolder (item->getText (0), item->getText (1), item->getText (2) == mTrFull ? true : false, type); 633 } 634 } 635 636 SFTreeViewItem* VBoxVMSettingsSF::searchRoot (bool aIsPermanent, SFDialogType aType) 637 { 638 QString type = aType != WrongType ? QString::number (aType) : !aIsPermanent ? QString::number (ConsoleType) : 639 mDialogType & MachineType ? QString::number (MachineType) : QString::number (GlobalType); 640 QTreeWidgetItem *mainRoot = mTwFolders->invisibleRootItem(); 689 641 690 642 int i = 0; … … 696 648 697 649 Assert (i < mainRoot->childCount()); 698 return i < mainRoot->childCount() && 699 mainRoot->child (i)->type() == SFTreeViewItem::SFTreeViewItemId ? 700 static_cast<SFTreeViewItem*> (mainRoot->child (i)) : 0; 650 return i < mainRoot->childCount() && mainRoot->child (i)->type() == SFTreeViewItem::SFTreeViewItemType ? 651 static_cast <SFTreeViewItem*> (mainRoot->child (i)) : 0; 701 652 } 702 653 … … 706 657 Assert (mDialogType); 707 658 708 SFDialogType type = (SFDialogType) aKey.toInt();659 SFDialogType type = (SFDialogType) aKey.toInt(); 709 660 if (!type) return false; 710 661 return mDialogType & type; … … 715 666 /* Make the used names list: */ 716 667 SFoldersNameList list; 717 QTreeWidgetItemIterator it (mT reeView);668 QTreeWidgetItemIterator it (mTwFolders); 718 669 while (*it) 719 670 { 720 671 if ((*it)->parent() && (aIncludeSelected || !(*it)->isSelected()) && 721 (*it)->type() == SFTreeViewItem::SFTreeViewItem Id)722 { 723 SFTreeViewItem *item = static_cast <SFTreeViewItem*> (*it);724 SFDialogType type = (SFDialogType) item->parent()->text (1).toInt();672 (*it)->type() == SFTreeViewItem::SFTreeViewItemType) 673 { 674 SFTreeViewItem *item = static_cast <SFTreeViewItem*> (*it); 675 SFDialogType type = (SFDialogType) item->parent()->text (1).toInt(); 725 676 list << qMakePair (item->getText (0), type); 726 677 } -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsSF.ui
r23333 r24055 1 <ui version="4.0" 1 <ui version="4.0"> 2 2 <comment> 3 3 VBox frontends: Qt4 GUI ("VirtualBox"): 4 4 5 Copyright (C) 2008 Sun Microsystems, Inc.5 Copyright (C) 2008-2009 Sun Microsystems, Inc. 6 6 7 7 This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 </comment> 19 19 <class>VBoxVMSettingsSF</class> 20 <widget class="QWidget" name="VBoxVMSettingsSF" 21 <property name="geometry" 20 <widget class="QWidget" name="VBoxVMSettingsSF"> 21 <property name="geometry"> 22 22 <rect> 23 23 <x>0</x> 24 24 <y>0</y> 25 <width> 294</width>26 <height>2 18</height>25 <width>300</width> 26 <height>220</height> 27 27 </rect> 28 28 </property> 29 <property name="sizePolicy" > 30 <sizepolicy vsizetype="Expanding" hsizetype="Expanding" > 31 <horstretch>0</horstretch> 32 <verstretch>0</verstretch> 33 </sizepolicy> 34 </property> 35 <layout class="QGridLayout" > 36 <item row="0" column="0" > 37 <widget class="QWidget" native="1" name="mGbSharedFolders" > 38 <layout class="QHBoxLayout" > 39 <property name="leftMargin" > 40 <number>0</number> 41 </property> 42 <property name="topMargin" > 43 <number>0</number> 44 </property> 45 <property name="rightMargin" > 46 <number>0</number> 47 </property> 48 <property name="bottomMargin" > 49 <number>0</number> 50 </property> 51 <item> 52 <widget class="QTreeWidget" name="mTreeView" > 53 <property name="minimumSize" > 54 <size> 55 <width>0</width> 56 <height>200</height> 57 </size> 29 <layout class="QVBoxLayout"> 30 <property name="margin"> 31 <number>0</number> 32 </property> 33 <item> 34 <widget class="QILabelSeparator" native="1" name="mNameSeparator"> 35 <property name="text"> 36 <string>&Folders List</string> 37 </property> 38 <property name="buddy"> 39 <cstring>mTwFolders</cstring> 40 </property> 41 </widget> 42 </item> 43 <item> 44 <layout class="QHBoxLayout" name="mLtFolders"> 45 <property name="margin"> 46 <number>0</number> 47 </property> 48 <property name="spacing"> 49 <number>0</number> 50 </property> 51 <item> 52 <widget class="QTreeWidget" name="mTwFolders"> 53 <property name="minimumSize"> 54 <size> 55 <width>0</width> 56 <height>200</height> 57 </size> 58 </property> 59 <property name="contextMenuPolicy"> 60 <enum>Qt::CustomContextMenu</enum> 61 </property> 62 <property name="whatsThis"> 63 <string>Lists all shared folders accessible to this machine. Use 'net use x: \\vboxsvr\share' to access a shared folder named <i>share</i> from a DOS-like OS, or 'mount -t vboxsf share mount_point' to access it from a Linux OS. This feature requires Guest Additions.</string> 64 </property> 65 <property name="uniformRowHeights"> 66 <bool>true</bool> 67 </property> 68 <property name="allColumnsShowFocus"> 69 <bool>true</bool> 70 </property> 71 <column> 72 <property name="text"> 73 <string>Name</string> 58 74 </property> 59 <property name="contextMenuPolicy" > 60 <enum>Qt::CustomContextMenu</enum> 75 </column> 76 <column> 77 <property name="text"> 78 <string>Path</string> 61 79 </property> 62 <property name="whatsThis" > 63 <string>Lists all shared folders accessible to this machine. Use 'net use x: \\vboxsvr\share' to access a shared folder named <i>share</i> from a DOS-like OS, or 'mount -t vboxsf share mount_point' to access it from a Linux OS. This feature requires Guest Additions.</string> 80 </column> 81 <column> 82 <property name="text"> 83 <string>Access</string> 64 84 </property> 65 <property name="uniformRowHeights" > 66 <bool>true</bool> 67 </property> 68 <property name="allColumnsShowFocus" > 69 <bool>true</bool> 70 </property> 71 <column> 72 <property name="text" > 73 <string>Name</string> 74 </property> 75 </column> 76 <column> 77 <property name="text" > 78 <string>Path</string> 79 </property> 80 </column> 81 <column> 82 <property name="text" > 83 <string>Access</string> 84 </property> 85 </column> 86 </widget> 87 </item> 88 </layout> 89 </widget> 85 </column> 86 </widget> 87 </item> 88 <item> 89 <widget class="VBoxToolBar" native="1" name="mTbFolders"/> 90 </item> 91 </layout> 90 92 </item> 91 93 </layout> 92 94 </widget> 93 <layoutdefault spacing="6" margin="11" /> 94 <includes> 95 <include location="local" >VBoxGlobal.h</include> 96 </includes> 95 <customwidgets> 96 <customwidget> 97 <class>QILabelSeparator</class> 98 <extends>QLabel</extends> 99 <header>QILabelSeparator.h</header> 100 <container>1</container> 101 </customwidget> 102 <customwidget> 103 <class>VBoxToolBar</class> 104 <extends>QWidget</extends> 105 <header>VBoxToolBar.h</header> 106 <container>1</container> 107 </customwidget> 108 </customwidgets> 97 109 <resources/> 98 110 <connections/>
Note:
See TracChangeset
for help on using the changeset viewer.