VirtualBox

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


Ignore:
Timestamp:
Feb 16, 2007 7:19:52 AM (18 years ago)
Author:
vboxsync
Message:

1758: Implement Shared Folders UI

  1. AddBox Dialog titled as "Add Share".
  2. If a root directory is selected, the default name on Win32 hosts will be X_DRIVE (where X is a drive letter), on Linux hosts - ROOT.
  3. Slash characters in paths are converted to native slashes after getting the selected directory from the file dialog.
  4. Errors from addSharedFolder/removeSharedFolder methods are handled normally, via dedicated VBoxProblemReporter methods.
  5. A tool-tip for a compressed path name in the list's column contains the name and full path of hovered shared folder.
Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
4 edited

Legend:

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

    r815 r945  
    144144
    145145    int confirmHardDiskUnregister (QWidget *parent, const QString &src);
    146    
     146
    147147    void cannotCreateHardDiskImage (
    148148        QWidget *parent, const CVirtualBox &vbox, const QString &src,
     
    164164    void cannotGetMediaAccessibility (const CUnknown &unk);
    165165
    166 /// @todo (r=dmik) later   
     166/// @todo (r=dmik) later
    167167//    void cannotMountMedia (const CUnknown &unk);
    168168//    void cannotUnmountMedia (const CUnknown &unk);
     
    183183    void cannotAttachUSBDevice (const CConsole &console, const QString &device);
    184184    void cannotDetachUSBDevice (const CConsole &console, const QString &device);
     185
     186    void cannotCreateSharedFolder (QWidget *, const CMachine &,
     187                                   const QString &, const QString &);
     188    void cannotRemoveSharedFolder (QWidget *, const CMachine &,
     189                                   const QString &, const QString &);
    185190
    186191    bool confirmReleaseImage (QWidget*, QString);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r815 r945  
    548548    /* preserve the current error info before calling the object again */
    549549    COMErrorInfo errInfo = machine.errorInfo();
    550      
     550
    551551    message (parent ? parent : mainWindowShown(), Error,
    552552             tr ("Failed to save the settings of the virtual machine <b>%1</b>.")
     
    823823    QString msg;
    824824    QString name;
    825    
     825
    826826    if (machine.GetAccessible())
    827827    {
     
    844844                  .arg (name);
    845845    }
    846    
     846
    847847    return messageYesNo (&vboxGlobal().selectorWnd(), Question, msg);
    848848}
     
    898898            "<nobr><b>%1</b>?</nobr></p>"
    899899            "<p>If you select <b>No</b> then the virtual hard disk will be "
    900             "unregistered and removed from the collection, but the image file " 
     900            "unregistered and removed from the collection, but the image file "
    901901            "will be left on your physical disk.</p>"
    902902            "<p>If you select <b>Yes</b> then the image file will be permanently "
     
    983983
    984984    Assert (!media.isNull());
    985    
     985
    986986    message (parent, Error,
    987987        tr ("Failed to register the %1 <nobr><b>%2</b></nobr>.")
     
    11411141            .arg (console.GetMachine().GetName()),
    11421142        formatErrorInfo (errInfo));
     1143}
     1144
     1145void VBoxProblemReporter::cannotCreateSharedFolder (QWidget        *aParent,
     1146                                                    const CMachine &aMachine,
     1147                                                    const QString  &aName,
     1148                                                    const QString  &aPath)
     1149{
     1150    /* preserve the current error info before calling the object again */
     1151    COMErrorInfo errInfo = aMachine.errorInfo();
     1152
     1153    message (aParent, Error,
     1154             tr ("Failed to create shared folder <b>%1</b> "
     1155                 "with path <b>%2</b> "
     1156                 "for the virtual machine <b>%3</b>.")
     1157                 .arg (aName)
     1158                 .arg (aPath)
     1159                 .arg (aMachine.GetName()),
     1160             formatErrorInfo (errInfo));
     1161}
     1162
     1163void VBoxProblemReporter::cannotRemoveSharedFolder (QWidget        *aParent,
     1164                                                    const CMachine &aMachine,
     1165                                                    const QString  &aName,
     1166                                                    const QString  &aPath)
     1167{
     1168    /* preserve the current error info before calling the object again */
     1169    COMErrorInfo errInfo = aMachine.errorInfo();
     1170
     1171    message (aParent, Error,
     1172             tr ("Failed to remove shared folder <b>%1</b> "
     1173                 "with path <b>%2</b> "
     1174                 "from the virtual machine <b>%3</b>.")
     1175                 .arg (aName)
     1176                 .arg (aPath)
     1177                 .arg (aMachine.GetName()),
     1178             formatErrorInfo (errInfo));
    11431179}
    11441180
     
    13391375        severity = tr ("<nobr>Warning</nobr>", "runtime error info");
    13401376    }
    1341    
     1377
    13421378    QString formatted;
    13431379
     
    13591395                              .arg (tr ("Severity: ", "runtime error info"),
    13601396                                    severity);
    1361    
     1397
    13621398    if (!formatted.isEmpty())
    13631399        formatted = "<qt>" + formatted + "</qt>";
    1364  
     1400
    13651401    int rc = 0;
    13661402
     
    13731409                "further examination:</p>"),
    13741410            formatted);
    1375        
     1411
    13761412        /* always power down after a fatal error */
    13771413        console.PowerDown();
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui

    r934 r945  
    176176    <include location="local" impldecl="in declaration">VBoxGlobal.h</include>
    177177    <include location="local" impldecl="in implementation">VBoxUtils.h</include>
     178    <include location="local" impldecl="in implementation">VBoxProblemReporter.h</include>
    178179    <include location="global" impldecl="in implementation">qfiledialog.h</include>
    179180    <include location="global" impldecl="in implementation">qlabel.h</include>
     
    182183</includes>
    183184<variables>
    184     <variable access="private">bool isListViewChanged;</variable>
     185    <variable access="private">bool mIsListViewChanged;</variable>
    185186</variables>
    186187<slots>
    187188    <slot>tbAddPressed()</slot>
    188189    <slot>tbRemovePressed()</slot>
    189     <slot>processCurrentChanged( QListViewItem * )</slot>
     190    <slot>processOnItem( QListViewItem* )</slot>
     191    <slot>processCurrentChanged( QListViewItem* )</slot>
    190192</slots>
    191193<functions>
     
    194196    <function>getFromMachine( const CMachine &amp; )</function>
    195197    <function>getFromConsole( const CConsole &amp; )</function>
    196     <function access="private">loadFrom( const CSharedFolderEnumerator &amp; )</function>
     198    <function access="private">getFrom( const CSharedFolderEnumerator &amp; )</function>
    197199    <function>putBackToGlobal()</function>
    198200    <function>putBackToMachine( CMachine &amp; )</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h

    r934 r945  
    101101                    case EllipsisFile:
    102102                    {
    103                         QRegExp regExp ("([\\/][^\\^/]+[\\/]?$)");
     103                        QRegExp regExp ("([\\\\/][^\\\\^/]+[\\\\/]?$)");
    104104                        int newFinish = regExp.search (oneString);
    105105                        if (newFinish != -1)
     
    196196    void showFileDialog()
    197197    {
    198         QString folderName = QFileDialog::getExistingDirectory (
    199                                           QDir::rootDirPath(),
    200                                           this, "AddSharedFolderDialog",
    201                                           tr ("Select a folder to share"),
    202                                           false /* show dir only */);
    203         /* compose folder path */
    204         mLePath->setText (folderName);
    205         /* compose folder name */
    206         QRegExp regExp ("[\\/]([^\\^/]+)[\\/]?$");
    207         int lastFolderPos = regExp.search (folderName);
    208         if (lastFolderPos != -1)
    209             mLeName->setText (regExp.cap (1));
     198        QFileDialog dlg (QDir::rootDirPath(), QString::null, this);
     199        dlg.setMode (QFileDialog::DirectoryOnly);
     200        dlg.setCaption (tr ("Add Share"));
     201        if (dlg.exec() == QDialog::Accepted)
     202        {
     203            QString folderName = QDir::convertSeparators (dlg.selectedFile());
     204            QRegExp commonRule ("[\\\\/]([^\\\\^/]+)[\\\\/]?$");
     205            QRegExp rootRule ("(([a-zA-Z])[^\\\\^/])?[\\\\/]$");
     206            if (commonRule.search (folderName) != -1)
     207            {
     208                /* processing non-root folder */
     209                mLePath->setText (folderName.remove (QRegExp ("[\\\\/]$")));
     210                mLeName->setText (commonRule.cap (1));
     211            }
     212            else if (rootRule.search (folderName) != -1)
     213            {
     214                /* processing root folder */
     215                mLePath->setText (folderName);
     216#if defined(Q_WS_WIN32)
     217                mLeName->setText (rootRule.cap (2) + "_DRIVE");
     218#elif defined(Q_WS_X11)
     219                mLeName->setText ("ROOT");
     220#endif
     221            }
     222            else
     223                return; /* hm, what type of folder it was? */
     224        }
    210225    }
    211226
     
    227242{
    228243    new QIListViewSelectionPreserver (this, listView);
     244    listView->setShowToolTips (false);
    229245    tbAdd->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
    230246                                            "select_file_dis_16px.png"));
     
    235251    connect (listView, SIGNAL (currentChanged (QListViewItem *)),
    236252             this, SLOT (processCurrentChanged (QListViewItem *)));
    237 
    238     isListViewChanged = false;
     253    connect (listView, SIGNAL (onItem (QListViewItem *)),
     254             this, SLOT (processOnItem (QListViewItem *)));
     255
     256    mIsListViewChanged = false;
    239257}
    240258
     
    242260void VBoxSharedFoldersSettings::getFromGlobal()
    243261{
    244     loadFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate());
     262    getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate());
    245263}
    246264
    247265void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine)
    248266{
    249     loadFrom (aMachine.GetSharedFolders().Enumerate());
     267    getFrom (aMachine.GetSharedFolders().Enumerate());
    250268}
    251269
    252270void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole)
    253271{
    254     loadFrom (aConsole.GetSharedFolders().Enumerate());
    255 }
    256 
    257 void VBoxSharedFoldersSettings::loadFrom (const CSharedFolderEnumerator &aEn)
     272    getFrom (aConsole.GetSharedFolders().Enumerate());
     273}
     274
     275void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn)
    258276{
    259277    while (aEn.HasMore())
     
    277295{
    278296    /* first deleting all existing folders if the list is changed */
    279     if (isListViewChanged)
     297    if (mIsListViewChanged)
    280298    {
    281299        CSharedFolderEnumerator en = aMachine.GetSharedFolders().Enumerate();
    282300        while (en.HasMore())
    283             aMachine.RemoveSharedFolder (en.GetNext().GetName());
     301        {
     302            CSharedFolder sf = en.GetNext();
     303            const QString &name = sf.GetName();
     304            const QString &path = sf.GetHostPath();
     305            aMachine.RemoveSharedFolder (name);
     306            if (!aMachine.isOk())
     307                vboxProblem().cannotRemoveSharedFolder (this, aMachine,
     308                                                        name, path);
     309        }
    284310    }
    285311    else return;
     
    293319            item = static_cast<VBoxRichListItem*> (it.current());
    294320        if (item)
     321        {
    295322            aMachine.CreateSharedFolder (item->getText (0), item->getText (1));
     323            if (!aMachine.isOk())
     324                vboxProblem().cannotCreateSharedFolder (this, aMachine,
     325                                                        item->getText (0),
     326                                                        item->getText (1));
     327        }
    296328        else
    297329            AssertMsgFailed (("Incorrect listview item type\n"));
     
    309341void VBoxSharedFoldersSettings::tbAddPressed()
    310342{
     343    /* Invoke Add-Box Dialog */
    311344    VBoxAddSFDialog dlg (this);
    312345    if (dlg.exec() != QDialog::Accepted)
     
    319352    VBoxRichListItem *item = new VBoxRichListItem (VBoxRichListItem::EllipsisFile,
    320353                                                   listView, name, path);
     354    listView->ensureItemVisible (item);
    321355    listView->setCurrentItem (item);
    322356    processCurrentChanged (item);
    323357    listView->setFocus();
    324     isListViewChanged = true;
     358    mIsListViewChanged = true;
    325359}
    326360
     
    329363    Assert (listView->selectedItem());
    330364    delete listView->selectedItem();
    331     isListViewChanged = true;
    332 }
    333 
     365    mIsListViewChanged = true;
     366}
     367
     368
     369void VBoxSharedFoldersSettings::processOnItem (QListViewItem *aItem)
     370{
     371    VBoxRichListItem *item = 0;
     372    if (aItem->rtti() == VBoxRichListItem::QIRichListItemId)
     373        item = static_cast<VBoxRichListItem*> (aItem);
     374    Assert (item);
     375    QString tip = tr ("<nobr>Name: %1</nobr><br><nobr>Path: %2</nobr>")
     376                      .arg (item->getText (0)).arg (item->getText (1));
     377    QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip);
     378}
    334379
    335380void VBoxSharedFoldersSettings::processCurrentChanged (QListViewItem *aItem)
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