VirtualBox

Changeset 24055 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Oct 24, 2009 3:55:47 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53914
Message:

FE/Qt4: VM Settings: Shared Folders Page: columns size-hint issue fixed, code restyled according GUI coding-style.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsSF.h

    r16966 r24055  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#define __VBoxVMSettingsSF_h__
    2525
     26/* Local includes */
    2627#include "VBoxSettingsPage.h"
    2728#include "VBoxVMSettingsSF.gen.h"
    2829
     30/* Local forwards */
    2931class SFTreeViewItem;
    3032
     
    3638    ConsoleType = 0x04
    3739};
    38 typedef QPair<QString, SFDialogType> SFolderName;
    39 typedef QList<SFolderName> SFoldersNameList;
     40typedef QPair <QString, SFDialogType> SFolderName;
     41typedef QList <SFolderName> SFoldersNameList;
    4042
    41 class VBoxVMSettingsSF : public VBoxSettingsPage,
    42                          public Ui::VBoxVMSettingsSF
     43class VBoxVMSettingsSF : public VBoxSettingsPage, public Ui::VBoxVMSettingsSF
    4344{
    4445    Q_OBJECT;
     
    5657    void putBackToConsole();
    5758
    58     int dialogType() { return mDialogType; }
     59    int dialogType() const;
    5960
    6061protected:
     
    7374    void delTriggered();
    7475
    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);
    7878    void showContextMenu (const QPoint &aPos);
    7979
     
    8585    void showEvent (QShowEvent *aEvent);
    8686
    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);
    9289
    9390    void getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aItem);
    94     void putBackTo     (CSharedFolderVector &aVec, SFTreeViewItem *aItem);
     91    void putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aItem);
    9592
    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);
    9995    SFoldersNameList usedList (bool aIncludeSelected);
    10096
    10197    int       mDialogType;
    102     QMenu    *mMenu;
    10398    QAction  *mNewAction;
    10499    QAction  *mEdtAction;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsSF.cpp

    r16966 r24055  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
     23/* Global includes */
     24#include <QHeaderView>
     25#include <QTimer>
     26
     27/* Local includes */
    2328#include "VBoxVMSettingsSF.h"
    2429#include "VBoxVMSettingsSFDetails.h"
     
    2631#include "VBoxProblemReporter.h"
    2732#include "VBoxUtils.h"
    28 #include "VBoxToolBar.h"
    29 
    30 /* Qt includes */
    31 #include <QHeaderView>
    32 #include <QTimer>
    3333
    3434class SFTreeViewItem : public QTreeWidgetItem
     
    3636public:
    3737
    38     enum { SFTreeViewItemId = 1001 };
     38    enum { SFTreeViewItemType = QTreeWidgetItem::UserType + 1 };
    3939
    4040    enum FormatType
     
    4747    };
    4848
    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)
    5352    {
    5453        setFirstColumnSpanned (true);
     
    5655    }
    5756
    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)
    6260    {
    6361        updateText (aFields);
     
    7472    {
    7573        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;
    7875    }
    7976
    8077    QString getText (int aIndex) const
    8178    {
    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;
    8480    }
    8581
     
    104100        if (oneString.isNull())
    105101            return;
    106         int oldSize = treeWidget()->fontMetrics().width (oneString);
    107         int indentSize = treeWidget()->fontMetrics().width ("x...x");
    108         int itemIndent = parent() ? treeWidget()->indentation() * 2 :
    109                                     treeWidget()->indentation();
     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();
    110106        if (aColumn == 0)
    111107            indentSize += itemIndent;
    112108        int cWidth = treeWidget()->columnWidth (aColumn);
    113109
    114         /* compress text */
     110        /* Compress text */
    115111        int start = 0;
    116112        int finish = 0;
    117113        int position = 0;
    118114        int textWidth = 0;
    119         do {
    120             textWidth = treeWidget()->fontMetrics().width (oneString);
     115        do
     116        {
     117            textWidth = fm.width (oneString);
    121118            if (textWidth + indentSize > cWidth)
    122119            {
     
    124121                finish = oneString.length();
    125122
    126                 /* selecting remove position */
     123                /* Selecting remove position */
    127124                switch (mFormat)
    128125                {
     
    154151                oneString.remove (position, 1);
    155152            }
    156         } while (textWidth + indentSize > cWidth);
     153        }
     154        while (textWidth + indentSize > cWidth);
    157155
    158156        if (position || mFormat == EllipsisFile) oneString.insert (position, "...");
    159         int newSize = treeWidget()->fontMetrics().width (oneString);
     157        int newSize = fm.width (oneString);
    160158        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));
    163163    }
    164164
     
    166166    QStringList mTextList;
    167167};
    168 
    169168
    170169VBoxVMSettingsSF::VBoxVMSettingsSF (int aType, QWidget *aParent)
     
    177176
    178177    /* 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);
    186181
    187182    mNewAction->setShortcut (QKeySequence ("Ins"));
    188183    mEdtAction->setShortcut (QKeySequence ("Ctrl+Space"));
    189184    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."));
    201185
    202186    mNewAction->setIcon (VBoxGlobal::iconSet (":/add_shared_folder_16px.png",
     
    207191                                              ":/revome_shared_folder_disabled_16px.png"));
    208192
    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 
    216193    /* 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);
    225200
    226201    /* Setup connections */
    227     mTreeView->header()->setMovable (false);
     202    mTwFolders->header()->setMovable (false);
    228203    connect (mNewAction, SIGNAL (triggered (bool)), this, SLOT (addTriggered()));
    229204    connect (mEdtAction, SIGNAL (triggered (bool)), this, SLOT (edtTriggered()));
    230205    connect (mDelAction, SIGNAL (triggered (bool)), this, SLOT (delTriggered()));
    231     connect (mTreeView, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
    232              this, SLOT (processCurrentChanged (QTreeWidgetItem*, QTreeWidgetItem*)));
    233     connect (mTreeView, SIGNAL (itemDoubleClicked (QTreeWidgetItem*, int)),
    234              this, SLOT (processDoubleClick (QTreeWidgetItem*, int)));
    235     connect (mTreeView, 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 &)),
    236211             this, SLOT (showContextMenu (const QPoint &)));
    237212
    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
    249222    if (aType & MachineType)
    250223    {
    251224        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);
    255227    }
    256228    if (aType & ConsoleType)
    257229    {
    258230        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);
    264235
    265236    retranslateUi();
    266237}
    267238
    268 
    269239void VBoxVMSettingsSF::getFromGlobal()
    270240{
    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
    275247}
    276248
     
    291263}
    292264
    293 
    294265void VBoxVMSettingsSF::putBackToGlobal()
    295266{
    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
    312269    if (!mIsListViewChanged)
    313270        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
     281void VBoxVMSettingsSF::putBackToMachine()
     282{
     283    if (!mIsListViewChanged)
     284        return;
    315285    /* This function is only available for MachineType dialog */
    316286    Assert (mDialogType & MachineType);
     
    326296    if (!mIsListViewChanged)
    327297        return;
    328 
    329298    /* This function is only available for ConsoleType dialog */
    330299    Assert (mDialogType & ConsoleType);
     
    336305}
    337306
     307int VBoxVMSettingsSF::dialogType() const
     308{
     309     return mDialogType;
     310}
    338311
    339312void VBoxVMSettingsSF::getFrom (const CMachine &aMachine)
     
    349322void VBoxVMSettingsSF::setOrderAfter (QWidget *aWidget)
    350323{
    351     setTabOrder (aWidget, mTreeView);
     324    setTabOrder (aWidget, mTwFolders);
    352325}
    353326
     
    357330    Ui::VBoxVMSettingsSF::retranslateUi (this);
    358331
     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
    359347    mTrFull = tr ("Full");
    360348    mTrReadOnly = tr ("Read-only");
    361349}
    362350
    363 
    364351void VBoxVMSettingsSF::addTriggered()
    365352{
    366353    /* 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);
    371355    if (dlg.exec() == QDialog::Accepted)
    372356    {
     
    382366        QStringList fields;
    383367        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);
    391374        processCurrentChanged (item);
    392         mTreeView->setFocus();
     375        mTwFolders->setFocus();
    393376        adjustList();
    394377
     
    400383{
    401384    /* 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;
    407388    Assert (item);
    408389    Assert (item->parent());
    409390
    410391    /* 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);
    415393    dlg.setPath (item->getText (1));
    416394    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);
    419396    dlg.setWriteable (item->getText (2) == mTrFull);
    420397    if (dlg.exec() == QDialog::Accepted)
     
    431408        QStringList fields;
    432409        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 */;
    435412        item->updateText (fields);
    436         mTreeView->sortItems (0, Qt::AscendingOrder);
     413        mTwFolders->sortItems (0, Qt::AscendingOrder);
    437414        if (item->parent() != root)
    438415        {
     
    440417            item->parent()->takeChild (item->parent()->indexOfChild (item));
    441418            root->insertChild (root->childCount(), item);
    442             mTreeView->scrollToItem (item);
    443             mTreeView->setCurrentItem (item);
     419            mTwFolders->scrollToItem (item);
     420            mTwFolders->setCurrentItem (item);
    444421            processCurrentChanged (item);
    445             mTreeView->setFocus();
     422            mTwFolders->setFocus();
    446423        }
    447424        adjustList();
     
    453430void VBoxVMSettingsSF::delTriggered()
    454431{
    455     QTreeWidgetItem *selectedItem = mTreeView->selectedItems().size() == 1 ?
    456                                     mTreeView->selectedItems() [0] : 0;
     432    QTreeWidgetItem *selectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems() [0] : 0;
    457433    Assert (selectedItem);
    458434    delete selectedItem;
     
    461437}
    462438
    463 
    464 void VBoxVMSettingsSF::processCurrentChanged (
    465     QTreeWidgetItem *aCurrentItem, QTreeWidgetItem* /* aPreviousItem */)
     439void VBoxVMSettingsSF::processCurrentChanged (QTreeWidgetItem *aCurrentItem)
    466440{
    467441    if (aCurrentItem && aCurrentItem->parent() && !aCurrentItem->isSelected())
    468442        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);
    472445    bool addEnabled = aCurrentItem && isEditable (key);
    473446    bool removeEnabled = addEnabled && aCurrentItem->parent();
     
    477450}
    478451
    479 void VBoxVMSettingsSF::processDoubleClick (QTreeWidgetItem *aItem,
    480                                            int /* aColumn */)
    481 {
    482     bool editEnabled = aItem && aItem->parent() &&
    483         isEditable (aItem->parent()->text (1));
     452void VBoxVMSettingsSF::processDoubleClick (QTreeWidgetItem *aItem)
     453{
     454    bool editEnabled = aItem && aItem->parent() && isEditable (aItem->parent()->text (1));
    484455    if (editEnabled)
    485456        edtTriggered();
     
    488459void VBoxVMSettingsSF::showContextMenu (const QPoint &aPos)
    489460{
    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}
    493474
    494475void VBoxVMSettingsSF::adjustList()
    495476{
    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);
    514490}
    515491
    516492void VBoxVMSettingsSF::adjustFields()
    517493{
    518     QTreeWidgetItem *mainRoot = mTreeView->invisibleRootItem();
     494    QTreeWidgetItem *mainRoot = mTwFolders->invisibleRootItem();
    519495    for (int i = 0; i < mainRoot->childCount(); ++ i)
    520496    {
     
    523499        {
    524500            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;
    527503            if (item)
    528504                item->adjustText();
     
    531507}
    532508
    533 
    534509void VBoxVMSettingsSF::showEvent (QShowEvent *aEvent)
    535510{
    536511    QWidget::showEvent (aEvent);
    537512
    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()));
    542515
    543516    /* Adjusting size after all pending show events are processed. */
     
    545518}
    546519
    547 
    548 void VBoxVMSettingsSF::removeSharedFolder (const QString & aName,
    549                                            const QString & aPath,
    550                                            SFDialogType aType)
     520void VBoxVMSettingsSF::createSharedFolder (const QString &aName, const QString &aPath, bool aWritable, SFDialogType aType)
    551521{
    552522    switch (aType)
     
    554524        case GlobalType:
    555525        {
    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
     553void 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"));
    558561            break;
    559562        }
     
    563566            mMachine.RemoveSharedFolder (aName);
    564567            if (!mMachine.isOk())
    565                 vboxProblem().cannotRemoveSharedFolder (this, mMachine,
    566                                                         aName, aPath);
     568                vboxProblem().cannotRemoveSharedFolder (this, mMachine, aName, aPath);
    567569            break;
    568570        }
     
    572574            mConsole.RemoveSharedFolder (aName);
    573575            if (!mConsole.isOk())
    574                 vboxProblem().cannotRemoveSharedFolder (this, mConsole,
    575                                                         aName, aPath);
     576                vboxProblem().cannotRemoveSharedFolder (this, mConsole, aName, aPath);
    576577            break;
    577578        }
     
    583584}
    584585
    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];
     586void VBoxVMSettingsSF::getFrom (const CSharedFolderVector &aVec, SFTreeViewItem *aRoot)
     587{
     588    for (int i = 0; i < aVec.size(); ++ i)
     589    {
     590        CSharedFolder sf = aVec [i];
    630591        QStringList fields;
    631         fields << sf.GetName() /* name */
    632                << sf.GetHostPath() /* path */
     592        fields << sf.GetName() /* name */ << sf.GetHostPath() /* path */
    633593               << (sf.GetWritable() ? mTrFull : mTrReadOnly /* writable? */)
    634594               << "not edited" /* initially not edited */;
     
    636596    }
    637597    aRoot->setExpanded (true);
    638     mTreeView->sortItems (0, Qt::AscendingOrder);
    639     mTreeView->setCurrentItem (aRoot->childCount() ? aRoot->child (0) : aRoot);
     598    mTwFolders->sortItems (0, Qt::AscendingOrder);
     599    mTwFolders->setCurrentItem (aRoot->childCount() ? aRoot->child (0) : aRoot);
    640600    processCurrentChanged (aRoot->childCount() ? aRoot->child (0) : aRoot);
    641601}
    642602
    643 void VBoxVMSettingsSF::putBackTo (CSharedFolderVector &aVec,
    644                                   SFTreeViewItem *aRoot)
     603void VBoxVMSettingsSF::putBackTo (CSharedFolderVector &aVec, SFTreeViewItem *aRoot)
    645604{
    646605    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];
    653612
    654613        /* Iterate through this root's children */
     
    657616        {
    658617            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")
    661619                break;
    662620        }
     
    666624    }
    667625
    668     /* save all edited tree widget items as folders */
     626    /* Save all edited tree widget items as folders */
    669627    for (int i = 0; i < aRoot->childCount(); ++ i)
    670628    {
    671629        SFTreeViewItem *item = aRoot->child (i);
    672630
    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
     636SFTreeViewItem* 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();
    689641
    690642    int i = 0;
     
    696648
    697649    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;
    701652}
    702653
     
    706657    Assert (mDialogType);
    707658
    708     SFDialogType type = (SFDialogType)aKey.toInt();
     659    SFDialogType type = (SFDialogType) aKey.toInt();
    709660    if (!type) return false;
    710661    return mDialogType & type;
     
    715666    /* Make the used names list: */
    716667    SFoldersNameList list;
    717     QTreeWidgetItemIterator it (mTreeView);
     668    QTreeWidgetItemIterator it (mTwFolders);
    718669    while (*it)
    719670    {
    720671        if ((*it)->parent() && (aIncludeSelected || !(*it)->isSelected()) &&
    721             (*it)->type() == SFTreeViewItem::SFTreeViewItemId)
    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();
    725676            list << qMakePair (item->getText (0), type);
    726677        }
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsSF.ui

    r23333 r24055  
    1 <ui version="4.0" >
     1<ui version="4.0">
    22 <comment>
    33 VBox frontends: Qt4 GUI ("VirtualBox"):
    44
    5  Copyright (C) 2008 Sun Microsystems, Inc.
     5 Copyright (C) 2008-2009 Sun Microsystems, Inc.
    66
    77 This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 </comment>
    1919 <class>VBoxVMSettingsSF</class>
    20  <widget class="QWidget" name="VBoxVMSettingsSF" >
    21   <property name="geometry" >
     20 <widget class="QWidget" name="VBoxVMSettingsSF">
     21  <property name="geometry">
    2222   <rect>
    2323    <x>0</x>
    2424    <y>0</y>
    25     <width>294</width>
    26     <height>218</height>
     25    <width>300</width>
     26    <height>220</height>
    2727   </rect>
    2828  </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>&amp;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 &lt;i>share&lt;/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>
    5874        </property>
    59         <property name="contextMenuPolicy" >
    60          <enum>Qt::CustomContextMenu</enum>
     75       </column>
     76       <column>
     77        <property name="text">
     78         <string>Path</string>
    6179        </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 &lt;i>share&lt;/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>
    6484        </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>
    9092   </item>
    9193  </layout>
    9294 </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>
    97109 <resources/>
    98110 <connections/>
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette