VirtualBox

Ignore:
Timestamp:
Feb 16, 2007 2:23:21 PM (18 years ago)
Author:
vboxsync
Message:

1758: Implement Shared Folders UI

Shared Folders List Dialog now can be invoked from working console menu. This dialog shows the list of Shared Folders available for current VM/Console and allows add/remove transient shared folders.

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

Legend:

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

    r809 r951  
    3131#include <qobjectlist.h>
    3232#include <qcolor.h>
     33#include <qdialog.h>
    3334
    3435#ifdef VBOX_WITH_DEBUGGER_GUI
     
    126127    void devicesUnmountDVD();
    127128    void devicesSwitchVrdp (bool);
     129    void devicesToggleSFDialog (bool);
    128130    void devicesInstallGuestAdditions();
    129131
     
    178180    QAction *devicesUnmountDVDAction;
    179181    QAction *devicesSwitchVrdpAction;
     182    QAction *devicesSFDialogAction;
    180183    QAction *devicesInstallGuestToolsAction;
    181184
     
    200203    int devicesUSBMenuSeparatorId;
    201204    int devicesVRDPMenuSeparatorId;
     205    int devicesSFMenuSeparatorId;
    202206
    203207#ifdef VBOX_WITH_DEBUGGER_GUI
     
    258262};
    259263
     264
     265class VBoxSharedFoldersSettings;
     266class VBoxSFDialog : public QDialog
     267{
     268    Q_OBJECT
     269
     270public:
     271
     272    VBoxSFDialog (QWidget*, CSession&, QAction*);
     273    ~VBoxSFDialog();
     274
     275protected slots:
     276
     277    virtual void accept();
     278    virtual void suicide (bool);
     279
     280protected:
     281
     282    void showEvent (QShowEvent*);
     283
     284private:
     285
     286    VBoxSharedFoldersSettings *mSettings;
     287    CSession &mSession;
     288    QAction *mAction;
     289};
     290
     291
    260292#endif // __VBoxConsoleWnd_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r933 r951  
    3131#include "VBoxTakeSnapshotDlg.h"
    3232#include "VBoxDiskImageManagerDlg.h"
     33#include "VBoxSharedFoldersSettings.h"
    3334#include "QIStateIndicator.h"
    3435#include "QIStatusBar.h"
     
    4647#include <qtooltip.h>
    4748#include <qdir.h>
     49#include <qpushbutton.h>
    4850
    4951#include <qeventloop.h>
     
    245247    devicesSwitchVrdpAction->setToggleAction (true);
    246248
     249    devicesSFDialogAction = new QAction (runningActions, "devicesSFDialogAction");
     250    devicesSFDialogAction->setToggleAction (true);
     251    devicesSFDialogAction->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
     252                                                                 "select_file_dis_16px.png"));
     253
    247254    devicesInstallGuestToolsAction = new QAction (runningActions, "devicesInstallGuestToolsAction");
    248255    devicesInstallGuestToolsAction->setIconSet (VBoxGlobal::iconSet ("guesttools_16px.png",
     
    328335    devicesSwitchVrdpAction->addTo (devicesMenu);
    329336    devicesVRDPMenuSeparatorId = devicesMenu->insertSeparator();
     337    devicesSFDialogAction->addTo (devicesMenu);
     338    devicesSFMenuSeparatorId = devicesMenu->insertSeparator();
    330339    devicesInstallGuestToolsAction->addTo (devicesMenu);
    331340    menuBar()->insertItem (QString::null, devicesMenu, devicesMenuId);
     
    456465    connect (devicesUnmountDVDAction, SIGNAL(activated()), this, SLOT(devicesUnmountDVD()));
    457466    connect (devicesSwitchVrdpAction, SIGNAL(toggled (bool)), this, SLOT(devicesSwitchVrdp (bool)));
     467    connect (devicesSFDialogAction, SIGNAL(toggled (bool)), this, SLOT(devicesToggleSFDialog (bool)));
    458468    connect (devicesInstallGuestToolsAction, SIGNAL(activated()), this, SLOT(devicesInstallGuestAdditions()));
    459469
     
    643653        devicesMenu->setItemVisible (devicesVRDPMenuSeparatorId, false);
    644654        vrdp_state->setHidden (true);
     655    }
     656
     657    /* initialize shared folders stuff */
     658    CSharedFolderCollection sfcoll = cconsole.GetSharedFolders();
     659    if (sfcoll.isNull())
     660    {
     661        /* hide shared folders menu action & sf_separator & sf_status_icon */
     662        devicesSFDialogAction->setVisible (false);
     663        devicesMenu->setItemVisible (devicesSFMenuSeparatorId, false);
     664        //vrdp_state->setHidden (true);
    645665    }
    646666
     
    11671187        tr ("Enable or disable remote desktop (RDP) connections to this machine"));
    11681188
     1189    devicesSFDialogAction->setMenuText (tr ("&Shared Folders List"));
     1190    devicesSFDialogAction->setStatusTip (
     1191        tr ("Open Shared Folders List"));
     1192
    11691193    devicesInstallGuestToolsAction->setMenuText (tr ("&Install Guest Additions..."));
    11701194    devicesInstallGuestToolsAction->setStatusTip (
     
    17621786}
    17631787
     1788void VBoxConsoleWnd::devicesToggleSFDialog (bool aOn)
     1789{
     1790    if (!console) return;
     1791
     1792    if (aOn)
     1793        (new VBoxSFDialog (console, csession, devicesSFDialogAction))->show();
     1794}
     1795
    17641796void VBoxConsoleWnd::devicesInstallGuestAdditions()
    17651797{
     
    22542286
    22552287#endif
     2288
     2289VBoxSFDialog::VBoxSFDialog (QWidget  *aParent, CSession &aSession, QAction *aAction)
     2290    : QDialog (aParent, "VBoxSFDialog", false /* modal */,
     2291               WStyle_Customize | WStyle_Title | WStyle_SysMenu |
     2292               WStyle_MinMax | WDestructiveClose)
     2293    , mSettings (0), mSession (aSession), mAction (aAction)
     2294{
     2295    /* Setup Dialog's title */
     2296    setCaption (tr ("Shared Folders List"));
     2297    setIcon (QPixmap::fromMimeSource ("select_file_16px.png"));
     2298
     2299    /* Setup main dialog's layout */
     2300    QVBoxLayout *mainLayout = new QVBoxLayout (this, 10, 10, "mainLayout");
     2301
     2302    /* Setup settings layout */
     2303    mSettings = new VBoxSharedFoldersSettings (this, "mSettings");
     2304    mSettings->setDialogType (VBoxSharedFoldersSettings::ConsoleType);
     2305    mSettings->getFromMachine (aSession.GetMachine());
     2306    mSettings->getFromConsole (aSession.GetConsole());
     2307    mainLayout->addWidget (mSettings);
     2308
     2309    /* Setup button's layout */
     2310    QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
     2311    QPushButton *pbOk = new QPushButton ("OK", this, "pbOk");
     2312    QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
     2313    QPushButton *pbCancel = new QPushButton ("Cancel", this, "pbCancel");
     2314    connect (pbOk, SIGNAL (clicked()), this, SLOT (accept()));
     2315    connect (pbCancel, SIGNAL (clicked()), this, SLOT (reject()));
     2316    buttonLayout->addWidget (pbOk);
     2317    buttonLayout->addItem (spacer);
     2318    buttonLayout->addWidget (pbCancel);
     2319
     2320    /* Setup destruction handler */
     2321    connect (mAction, SIGNAL (toggled (bool)), this, SLOT (suicide (bool)));
     2322}
     2323
     2324VBoxSFDialog::~VBoxSFDialog()
     2325{
     2326    mAction->setOn (false);
     2327}
     2328
     2329void VBoxSFDialog::accept()
     2330{
     2331    mSettings->putBackToConsole();
     2332    QDialog::accept();
     2333}
     2334
     2335void VBoxSFDialog::suicide (bool aNo)
     2336{
     2337    if (!aNo) close();
     2338}
     2339
     2340void VBoxSFDialog::showEvent (QShowEvent *aEvent)
     2341{
     2342    QDialog::showEvent (aEvent);
     2343    setMinimumWidth (400);
     2344    VBoxGlobal::centerWidget (this, parentWidget());
     2345}
     2346
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui

    r946 r951  
    186186    <variable access="private">bool mIsListViewChanged;</variable>
    187187    <variable access="private">SFDialogType mDialogType;</variable>
     188    <variable access="private">CMachine mMachine;</variable>
     189    <variable access="private">CConsole mConsole;</variable>
    188190</variables>
    189191<slots>
     
    196198    <function access="private">init()</function>
    197199    <function>setDialogType( VBoxSharedFoldersSettings::SFDialogType )</function>
    198     <function access="private" returnType="bool">isEditable( const QString &amp; )</function>
     200    <function access="private">removeSharedFolder( const QString &amp;, const QString &amp;, VBoxSharedFoldersSettings::SFDialogType )</function>
     201    <function access="private">createSharedFolder( const QString &amp;, const QString &amp;, VBoxSharedFoldersSettings::SFDialogType )</function>
    199202    <function>getFromGlobal()</function>
    200203    <function>getFromMachine( const CMachine &amp; )</function>
     
    202205    <function access="private">getFrom( const CSharedFolderEnumerator &amp;, QListViewItem* )</function>
    203206    <function>putBackToGlobal()</function>
    204     <function>putBackToMachine( CMachine &amp; )</function>
    205     <function>putBackToConsole( CConsole &amp; )</function>
     207    <function>putBackToMachine()</function>
     208    <function>putBackToConsole()</function>
     209    <function access="private">putBackTo( CSharedFolderEnumerator &amp;, QListViewItem* )</function>
     210    <function access="private" returnType="bool">isEditable( const QString &amp; )</function>
    206211</functions>
    207212<pixmapinproject/>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h

    r946 r951  
    274274
    275275
     276void VBoxSharedFoldersSettings::removeSharedFolder (const QString & aName,
     277                                                    const QString & aPath,
     278                                                    SFDialogType aType)
     279{
     280    switch (aType)
     281    {
     282        case GlobalType:
     283        {
     284            /* This feature is not implemented yet */
     285            AssertMsgFailed (("Global shared folders are not implemented yet\n"));
     286            break;
     287        }
     288        case MachineType:
     289        {
     290            Assert (!mMachine.isNull());
     291            mMachine.RemoveSharedFolder (aName);
     292            if (!mMachine.isOk())
     293                vboxProblem().cannotRemoveSharedFolder (this, mMachine,
     294                                                        aName, aPath);
     295            break;
     296        }
     297        case ConsoleType:
     298        {
     299            Assert (!mConsole.isNull());
     300            mConsole.RemoveSharedFolder (aName);
     301            if (!mConsole.isOk())
     302                vboxProblem().cannotRemoveSharedFolder (this, mConsole.GetMachine(),
     303                                                        aName, aPath);
     304            break;
     305        }
     306        default:
     307        {
     308            AssertMsgFailed (("Incorrect shared folder type\n"));
     309        }
     310    }
     311}
     312
     313void VBoxSharedFoldersSettings::createSharedFolder (const QString & aName,
     314                                                    const QString & aPath,
     315                                                    SFDialogType aType)
     316{
     317    switch (aType)
     318    {
     319        case GlobalType:
     320        {
     321            /* This feature is not implemented yet */
     322            AssertMsgFailed (("Global shared folders are not implemented yet\n"));
     323            break;
     324        }
     325        case MachineType:
     326        {
     327            Assert (!mMachine.isNull());
     328            mMachine.CreateSharedFolder (aName, aPath);
     329            if (!mMachine.isOk())
     330                vboxProblem().cannotCreateSharedFolder (this, mMachine,
     331                                                        aName, aPath);
     332            break;
     333        }
     334        case ConsoleType:
     335        {
     336            Assert (!mConsole.isNull());
     337            mConsole.CreateSharedFolder (aName, aPath);
     338            if (!mConsole.isOk())
     339                vboxProblem().cannotCreateSharedFolder (this, mConsole.GetMachine(),
     340                                                        aName, aPath);
     341            break;
     342        }
     343        default:
     344        {
     345            AssertMsgFailed (("Incorrect shared folder type\n"));
     346        }
     347    }
     348}
     349
     350
    276351void VBoxSharedFoldersSettings::getFromGlobal()
    277352{
     353    /* This feature is not implemented yet */
     354    AssertMsgFailed (("Global shared folders are not implemented yet\n"));
     355
     356    /*
    278357    QString name = tr (" Global Shared Folders");
    279     QString key ("1");
     358    QString key (QString::number (GlobalType));
    280359    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
    281360                                                   listView, name, QString::null, key);
    282361    getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate(), root);
     362    */
    283363}
    284364
    285365void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine)
    286366{
     367    mMachine = aMachine;
    287368    QString name = tr (" Machine Shared Folders");
    288     QString key ("2");
     369    QString key (QString::number (MachineType));
    289370    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
    290371                                                   listView, name, QString::null, key);
    291     getFrom (aMachine.GetSharedFolders().Enumerate(), root);
     372    getFrom (mMachine.GetSharedFolders().Enumerate(), root);
    292373}
    293374
    294375void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole)
    295376{
     377    mConsole = aConsole;
    296378    QString name = tr (" Transient Shared Folders");
    297     QString key ("3");
     379    QString key (QString::number (ConsoleType));
    298380    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
    299381                                                   listView, name, QString::null, key);
    300     getFrom (aConsole.GetSharedFolders().Enumerate(), root);
     382    getFrom (mConsole.GetSharedFolders().Enumerate(), root);
    301383}
    302384
     
    312394    }
    313395    listView->setOpen (aRoot, true);
    314     listView->setCurrentItem (aRoot->firstChild());
    315     processCurrentChanged (aRoot->firstChild());
     396    listView->setCurrentItem (aRoot);
     397    processCurrentChanged (aRoot);
    316398}
    317399
     
    321403    /* This feature is not implemented yet */
    322404    AssertMsgFailed (("Global shared folders are not implemented yet\n"));
    323 }
    324 
    325 void VBoxSharedFoldersSettings::putBackToMachine (CMachine &aMachine)
    326 {
    327     /* first deleting all existing folders if the list is changed */
    328     if (mIsListViewChanged)
    329     {
    330         CSharedFolderEnumerator en = aMachine.GetSharedFolders().Enumerate();
    331         while (en.HasMore())
    332         {
    333             CSharedFolder sf = en.GetNext();
    334             const QString &name = sf.GetName();
    335             const QString &path = sf.GetHostPath();
    336             aMachine.RemoveSharedFolder (name);
    337             if (!aMachine.isOk())
    338                 vboxProblem().cannotRemoveSharedFolder (this, aMachine,
    339                                                         name, path);
    340         }
    341     }
    342     else return;
     405
     406    /*
     407    if (!mIsListViewChanged) return;
     408    // This function is only available for GlobalType dialog
     409    Assert (mDialogType == GlobalType);
     410    // Searching for GlobalType item's root
     411    QListViewItem *root = listView->findItem (QString::number (GlobalType), 2);
     412    Assert (root);
     413    CSharedFolderEnumerator en = vboxGlobal().virtualBox().GetSharedFolders().Enumerate();
     414    putBackTo (en, root);
     415    */
     416}
     417
     418void VBoxSharedFoldersSettings::putBackToMachine()
     419{
     420    if (!mIsListViewChanged)
     421        return;
     422
     423    /* This function is only available for MachineType dialog */
     424    Assert (mDialogType == MachineType);
     425    /* Searching for MachineType item's root */
     426    QListViewItem *root = listView->findItem (QString::number (MachineType), 2);
     427    Assert (root);
     428    CSharedFolderEnumerator en = mMachine.GetSharedFolders().Enumerate();
     429    putBackTo (en, root);
     430}
     431
     432void VBoxSharedFoldersSettings::putBackToConsole()
     433{
     434    if (!mIsListViewChanged)
     435        return;
     436
     437    /* This function is only available for ConsoleType dialog */
     438    Assert (mDialogType == ConsoleType);
     439    /* Searching for ConsoleType item's root */
     440    QListViewItem *root = listView->findItem (QString::number (ConsoleType), 2);
     441    Assert (root);
     442    CSharedFolderEnumerator en = mConsole.GetSharedFolders().Enumerate();
     443    putBackTo (en, root);
     444}
     445
     446void VBoxSharedFoldersSettings::putBackTo (CSharedFolderEnumerator &aEn,
     447                                           QListViewItem *aRoot)
     448{
     449    SFDialogType type = (SFDialogType)aRoot->text (2).toInt();
     450    Assert (type);
     451
     452    /* deleting all existing folders if the list */
     453    while (aEn.HasMore())
     454    {
     455        CSharedFolder sf = aEn.GetNext();
     456        removeSharedFolder (sf.GetName(), sf.GetHostPath(), type);
     457    }
    343458
    344459    /* saving all machine related list view items */
    345         Assert (mDialogType == 2);
    346     QListViewItem *root = listView->findItem (QString::number (mDialogType), 2);
    347     Assert (root);
    348     QListViewItem *iterator = root->firstChild();
     460    QListViewItem *iterator = aRoot->firstChild();
    349461    while (iterator)
    350462    {
     
    353465            item = static_cast<VBoxRichListItem*> (iterator);
    354466        if (item)
    355         {
    356             aMachine.CreateSharedFolder (item->getText (0), item->getText (1));
    357             if (!aMachine.isOk())
    358                 vboxProblem().cannotCreateSharedFolder (this, aMachine,
    359                                                         item->getText (0),
    360                                                         item->getText (1));
    361         }
     467            createSharedFolder (item->getText (0), item->getText (1), type);
    362468        else
    363469            AssertMsgFailed (("Incorrect listview item type\n"));
    364470        iterator = iterator->nextSibling();
    365471    }
    366 }
    367 
    368 void VBoxSharedFoldersSettings::putBackToConsole (CConsole &/*aConsole*/)
    369 {
    370     /* This feature is not implemented yet */
    371     AssertMsgFailed (("Transient shared folders are not implemented yet\n"));
    372472}
    373473
     
    422522    if (aItem && listView->selectedItem() != aItem)
    423523        listView->setSelected (aItem, true);
    424     bool removeEnabled = aItem && aItem->parent();
     524    bool removeEnabled = aItem && aItem->parent() &&
     525                         isEditable (aItem->parent()->text (2));
    425526    bool addEnabled = aItem &&
    426527                      (isEditable (aItem->text (2)) ||
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r946 r951  
    15351535    /* shared folders */
    15361536    {
    1537         mSharedFolders->putBackToMachine (cmachine);
     1537        mSharedFolders->putBackToMachine();
    15381538    }
    15391539
Note: See TracChangeset for help on using the changeset viewer.

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