VirtualBox

Ignore:
Timestamp:
Jul 3, 2018 9:55:30 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123359
Message:

FE/Qt: bugref:9083 Introducing a new dialog for floppy disk creation settings

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r72529 r72815  
    796796        src/logviewer/UIVMLogViewerTextEdit.h \
    797797        src/logviewer/UIVMLogViewerWidget.h \
     798        src/medium/UIFDCreationDialog.h \
    798799        src/medium/UIMediumEnumerator.h \
    799800        src/medium/UIMediumSelector.h \
     
    10681069        src/logviewer/UIVMLogViewerTextEdit.h \
    10691070        src/logviewer/UIVMLogViewerWidget.h \
     1071        src/medium/UIFDCreationDialog.h \
    10701072        src/medium/UIMediumEnumerator.h \
    10711073        src/medium/UIMediumSelector.h \
     
    14711473        src/logviewer/UIVMLogViewerTextEdit.cpp \
    14721474        src/logviewer/UIVMLogViewerWidget.cpp \
     1475        src/medium/UIFDCreationDialog.cpp \
    14731476        src/medium/UIMedium.cpp \
    14741477        src/medium/UIMediumDefs.cpp \
     
    18011804        src/logviewer/UIVMLogViewerTextEdit.cpp \
    18021805        src/logviewer/UIVMLogViewerWidget.cpp \
     1806        src/medium/UIFDCreationDialog.cpp \
    18031807        src/medium/UIMedium.cpp \
    18041808        src/medium/UIMediumDefs.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp

    r72810 r72815  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIMachineSettingsSFDetails class implementation.
     3 * VBox Qt GUI - UIFDCreationDialog class implementation.
    44 */
    55
     
    2121
    2222/* Qt includes */
    23 # include <QDir>
    24 # include <QPushButton>
     23# include<QVBoxLayout>
    2524
    2625/* Other includes */
    27 # include "UIMachineSettingsSFDetails.h"
     26# include "UIFDCreationDialog.h"
     27# include "UIFilePathSelector.h"
    2828# include "VBoxGlobal.h"
    2929
     
    3131
    3232
    33 UIMachineSettingsSFDetails::UIMachineSettingsSFDetails(DialogType type,
    34                                                        bool fEnableSelector, /* for "permanent" checkbox */
    35                                                        const QStringList &usedNames,
    36                                                        QWidget *pParent /* = 0 */)
    37    : QIWithRetranslateUI2<QIDialog>(pParent)
    38    , m_type(type)
    39    , m_fUsePermanent(fEnableSelector)
    40    , m_usedNames(usedNames)
     33UIFDCreationDialog::UIFDCreationDialog(QWidget *pParent /* = 0 */,
     34                                       const QString &strMachineName /* = QString() */,
     35                                       const QString &strMachineSettingsFilePath /* = QString() */)
     36   : QIWithRetranslateUI<QDialog>(pParent)
     37    , m_pFilePathselector(0)
     38    , m_strMachineName(strMachineName)
     39    , m_strMachineSettingsFilePath(strMachineSettingsFilePath)
    4140{
    42     /* Apply UI decorations: */
    43     Ui::UIMachineSettingsSFDetails::setupUi(this);
    4441
    45     /* Setup widgets: */
    46     mPsPath->setResetEnabled(false);
    47     mPsPath->setHomeDir(QDir::homePath());
    48     mCbPermanent->setHidden(!fEnableSelector);
    49 
    50     /* Setup connections: */
    51     connect(mPsPath, SIGNAL(currentIndexChanged(int)), this, SLOT(sltSelectPath()));
    52     connect(mPsPath, SIGNAL(pathChanged(const QString &)), this, SLOT(sltSelectPath()));
    53     connect(mLeName, SIGNAL(textChanged(const QString &)), this, SLOT(sltValidate()));
    54     if (fEnableSelector)
    55         connect(mCbPermanent, SIGNAL(toggled(bool)), this, SLOT(sltValidate()));
    56 
    57      /* Applying language settings: */
    58     retranslateUi();
    59 
    60     /* Validate the initial field values: */
    61     sltValidate();
    62 
     42    prepare();
    6343    /* Adjust dialog size: */
    6444    adjustSize();
     
    7050}
    7151
    72 void UIMachineSettingsSFDetails::setPath(const QString &strPath)
     52void UIFDCreationDialog::retranslateUi()
    7353{
    74     mPsPath->setPath(strPath);
     54
    7555}
    7656
    77 QString UIMachineSettingsSFDetails::path() const
     57void UIFDCreationDialog::prepare()
    7858{
    79     return mPsPath->path();
    80 }
     59    setWindowModality(Qt::WindowModal);
    8160
    82 void UIMachineSettingsSFDetails::setName(const QString &strName)
    83 {
    84     mLeName->setText(strName);
    85 }
     61    QVBoxLayout *pMainLayout = new QVBoxLayout;
     62    if (!pMainLayout)
     63        return;
     64    setLayout(pMainLayout);
    8665
    87 QString UIMachineSettingsSFDetails::name() const
    88 {
    89     return mLeName->text();
    90 }
    91 
    92 void UIMachineSettingsSFDetails::setWriteable(bool fWritable)
    93 {
    94     mCbReadonly->setChecked(!fWritable);
    95 }
    96 
    97 bool UIMachineSettingsSFDetails::isWriteable() const
    98 {
    99     return !mCbReadonly->isChecked();
    100 }
    101 
    102 void UIMachineSettingsSFDetails::setAutoMount(bool fAutoMount)
    103 {
    104     mCbAutoMount->setChecked(fAutoMount);
    105 }
    106 
    107 bool UIMachineSettingsSFDetails::isAutoMounted() const
    108 {
    109     return mCbAutoMount->isChecked();
    110 }
    111 
    112 void UIMachineSettingsSFDetails::setPermanent(bool fPermanent)
    113 {
    114     mCbPermanent->setChecked(fPermanent);
    115 }
    116 
    117 bool UIMachineSettingsSFDetails::isPermanent() const
    118 {
    119     return m_fUsePermanent ? mCbPermanent->isChecked() : true;
    120 }
    121 
    122 void UIMachineSettingsSFDetails::retranslateUi()
    123 {
    124     /* Translate uic generated strings: */
    125     Ui::UIMachineSettingsSFDetails::retranslateUi(this);
    126 
    127     switch (m_type)
     66    m_pFilePathselector = new UIFilePathSelector;
     67    if (m_pFilePathselector)
    12868    {
    129         case AddType:
    130             setWindowTitle(tr("Add Share"));
    131             break;
    132         case EditType:
    133             setWindowTitle(tr("Edit Share"));
    134             break;
    135         default:
    136             AssertMsgFailed(("Incorrect shared-folders dialog type: %d\n", m_type));
     69        pMainLayout->addWidget(m_pFilePathselector);
     70        m_pFilePathselector->setMode(UIFilePathSelector::Mode_File_Save);
    13771    }
    13872}
    139 
    140 void UIMachineSettingsSFDetails::sltValidate()
    141 {
    142     mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!mPsPath->path().isEmpty() &&
    143                                                          QDir(mPsPath->path()).exists() &&
    144                                                          !mLeName->text().trimmed().isEmpty() &&
    145                                                          !mLeName->text().contains(" ") &&
    146                                                          !m_usedNames.contains(mLeName->text()));
    147 }
    148 
    149 void UIMachineSettingsSFDetails::sltSelectPath()
    150 {
    151     if (!mPsPath->isPathSelected())
    152         return;
    153 
    154     QString strFolderName(mPsPath->path());
    155 #if defined (VBOX_WS_WIN) || defined (Q_OS_OS2)
    156     if (strFolderName[0].isLetter() && strFolderName[1] == ':' && strFolderName[2] == 0)
    157     {
    158         /* UIFilePathSelector returns root path as 'X:', which is invalid path.
    159          * Append the trailing backslash to get a valid root path 'X:\': */
    160         strFolderName += "\\";
    161         mPsPath->setPath(strFolderName);
    162     }
    163 #endif /* VBOX_WS_WIN || Q_OS_OS2 */
    164     QDir folder(strFolderName);
    165     if (!folder.isRoot())
    166     {
    167         /* Processing non-root folder */
    168         mLeName->setText(folder.dirName().replace(' ', '_'));
    169     }
    170     else
    171     {
    172         /* Processing root folder: */
    173 #if defined (VBOX_WS_WIN) || defined (Q_OS_OS2)
    174         mLeName->setText(strFolderName.toUpper()[0] + "_DRIVE");
    175 #elif defined (VBOX_WS_X11)
    176         mLeName->setText("ROOT");
    177 #endif
    178     }
    179     /* Validate the field values: */
    180     sltValidate();
    181 }
    182 
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.h

    r72810 r72815  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIMachineSettingsSFDetails class declaration.
     3 * VBox Qt GUI - UIFDCreationDialog class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef __UIMachineSettingsSFDetails_h__
    19 #define __UIMachineSettingsSFDetails_h__
     18#ifndef __UIFDCreationDialog_h__
     19#define __UIFDCreationDialog_h__
    2020
    21 /* Includes */
    22 #include "UIMachineSettingsSFDetails.gen.h"
    23 #include "QIDialog.h"
     21/* Qt includes: */
     22#include <QDialog>
     23
     24
     25/* GUI Includes */
    2426#include "QIWithRetranslateUI.h"
    25 #include "UIMachineSettingsSF.h"
    2627
    27 /* Shared folders details dialog: */
    28 class SHARED_LIBRARY_STUFF UIMachineSettingsSFDetails : public QIWithRetranslateUI2<QIDialog>,
    29                                                         public Ui::UIMachineSettingsSFDetails
     28/* Forward declarations: */
     29class UIFilePathSelector;
     30
     31/* A QDialog extension to get necessary setting from the user for floppy disk creation */
     32class SHARED_LIBRARY_STUFF UIFDCreationDialog : public QIWithRetranslateUI<QDialog>
     33
    3034{
    3135    Q_OBJECT;
    3236
     37
    3338public:
    3439
    35     enum DialogType
    36     {
    37         AddType,
    38         EditType
    39     };
    40 
    41     UIMachineSettingsSFDetails(DialogType type,
    42                                bool fEnableSelector, /* for "permanent" checkbox */
    43                                const QStringList &usedNames,
    44                                QWidget *pParent = 0);
    45 
    46     void setPath(const QString &strPath);
    47     QString path() const;
    48 
    49     void setName(const QString &strName);
    50     QString name() const;
    51 
    52     void setWriteable(bool fWriteable);
    53     bool isWriteable() const;
    54 
    55     void setAutoMount(bool fAutoMount);
    56     bool isAutoMounted() const;
    57 
    58     void setPermanent(bool fPermanent);
    59     bool isPermanent() const;
     40    UIFDCreationDialog(QWidget *pParent = 0,
     41                       const QString &strMachineName = QString(),
     42                       const QString &strMachineSettingsFilePath = QString()
     43                       );
    6044
    6145protected:
     
    6549private slots:
    6650
    67     void sltSelectPath();
    68     void sltValidate();
    6951
    7052private:
    7153
    72     DialogType   m_type;
    73     bool         m_fUsePermanent;
    74     QStringList  m_usedNames;
     54    void prepare();
     55
     56    UIFilePathSelector *m_pFilePathselector;
     57    QString             m_strMachineName;
     58    QString             m_strMachineSettingsFilePath;
    7559};
    7660
    77 #endif // __UIMachineSettingsSFDetails_h__
     61#endif // __UIFDCreationDialog_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r72698 r72815  
    2929# include "QIComboBox.h"
    3030# include "QIDialogButtonBox.h"
     31# include "QIFileDialog.h"
    3132# include "QILineEdit.h"
    3233# include "QIMessageBox.h"
     
    3637# include "UIDesktopWidgetWatchdog.h"
    3738# include "UIExtraDataManager.h"
     39# include "UIFDCreationDialog.h"
    3840# include "UIMediumSelector.h"
     41# include "UIMessageCenter.h"
    3942# include "UIIconPool.h"
    4043# include "UIMedium.h"
     
    146149
    147150
    148 UIMediumSelector::UIMediumSelector(UIMediumType enmMediumType, QWidget *pParent /* = 0 */)
     151UIMediumSelector::UIMediumSelector(UIMediumType enmMediumType, const QString &machineName /* = QString() */,
     152                                   const QString &machineSettigFilePath /* = QString() */, QWidget *pParent /* = 0 */)
    149153    :QIWithRetranslateUI<QIDialog>(pParent)
    150154    , m_pMainLayout(0)
     
    154158    , m_pToolBar(0)
    155159    , m_pActionAdd(0)
     160    , m_pActionCreate(0)
    156161    , m_pActionRefresh(0)
    157162    , m_pAttachedSubTreeRoot(0)
     
    159164    , m_pParent(pParent)
    160165    , m_pSearchWidget(0)
     166    , m_strMachineSettingsFilePath(machineSettigFilePath)
     167    , m_strMachineName(machineName)
    161168{
    162169    configure();
     
    188195        m_pActionAdd->setStatusTip(QApplication::translate("UIMediumManager", "Add disk image file"));
    189196    }
     197
     198    if (m_pActionCreate)
     199    {
     200        m_pActionCreate->setText(QApplication::translate("UIMediumManager", "&Create"));
     201        m_pActionCreate->setToolTip(QApplication::translate("UIMediumManager", "Create an Empty Disk Image"));
     202        m_pActionCreate->setStatusTip(QApplication::translate("UIMediumManager", "Create an Empty Disk Image"));
     203    }
     204
    190205    if (m_pActionRefresh)
    191206    {
     
    218233void UIMediumSelector::prepareActions()
    219234{
     235    QString strPrefix("hd");
     236    switch (m_enmMediumType)
     237    {
     238        case UIMediumType_DVD:
     239            strPrefix = "cd";
     240            break;
     241        case UIMediumType_Floppy:
     242            strPrefix = "fd";
     243            break;
     244        case UIMediumType_HardDisk:
     245        case UIMediumType_All:
     246        case UIMediumType_Invalid:
     247        default:
     248            strPrefix = "hd";
     249            break;
     250    }
     251
    220252    m_pActionAdd = new QAction(this);
    221253    if (m_pActionAdd)
     
    223255        /* Configure add-action: */
    224256        m_pActionAdd->setShortcut(QKeySequence("Ctrl+A"));
    225         QString strPrefix("hd");
    226         switch (m_enmMediumType)
    227         {
    228             case UIMediumType_DVD:
    229                 strPrefix = "cd";
    230                 break;
    231             case UIMediumType_Floppy:
    232                 strPrefix = "fd";
    233                 break;
    234             case UIMediumType_HardDisk:
    235             case UIMediumType_All:
    236             case UIMediumType_Invalid:
    237             default:
    238                 strPrefix = "hd";
    239                 break;
    240         }
    241257
    242258        m_pActionAdd->setIcon(UIIconPool::iconSetFull(QString(":/%1_add_22px.png").arg(strPrefix),
     
    245261                                                      QString(":/%1_add_disabled_16px.png").arg(strPrefix)));
    246262    }
     263
     264    /* Currently create is supported only for Floppy: */
     265    if (m_enmMediumType == UIMediumType_Floppy)
     266    {
     267        m_pActionCreate = new QAction(this);
     268    }
     269    if (m_pActionCreate)
     270    {
     271
     272        m_pActionCreate->setShortcut(QKeySequence("Ctrl+C"));
     273        m_pActionCreate->setIcon(UIIconPool::iconSetFull(QString(":/%1_add_22px.png").arg(strPrefix),
     274                                                         QString(":/%1_add_16px.png").arg(strPrefix),
     275                                                         QString(":/%1_add_disabled_22px.png").arg(strPrefix),
     276                                                         QString(":/%1_add_disabled_16px.png").arg(strPrefix)));
     277    }
     278
    247279
    248280    m_pActionRefresh = new QAction(this);
     
    267299    if (m_pActionAdd)
    268300        connect(m_pActionAdd, &QAction::triggered, this, &UIMediumSelector::sltAddMedium);
     301    if (m_pActionCreate)
     302        connect(m_pActionCreate, &QAction::triggered, this, &UIMediumSelector::sltCreateMedium);
    269303    if (m_pActionRefresh)
    270304        connect(m_pActionRefresh, &QAction::triggered, this, &UIMediumSelector::sltHandleRefresh);
     
    397431        if (m_pActionAdd)
    398432            m_pToolBar->addAction(m_pActionAdd);
     433        if (m_pActionCreate)
     434            m_pToolBar->addAction(m_pActionCreate);
    399435        if (m_pActionRefresh)
    400436            m_pToolBar->addAction(m_pActionRefresh);
     
    439475    QString strDefaultMachineFolder = vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
    440476    vboxGlobal().openMediumWithFileOpenDialog(m_enmMediumType, this, strDefaultMachineFolder);
     477}
     478
     479
     480void UIMediumSelector::sltCreateMedium()
     481{
     482
     483    UIFDCreationDialog *pDialog = new UIFDCreationDialog(this, m_strMachineSettingsFilePath, m_strMachineName);
     484    pDialog->exec();
     485
     486    // QVector<CMediumFormat>  mediumFormats = vboxGlobal().getFormatsForDeviceType(UIMediumDefs::mediumTypeToGlobal(m_enmMediumType));
     487    // if (mediumFormats.isEmpty())
     488    //     return;
     489    // QString strMachineFolder = QFileInfo(m_strMachineSettingsFilePath).absolutePath();
     490    // QString strMediumPath =vboxGlobal().getNewMediumPath(m_enmMediumType, this,
     491    //                                             strMachineFolder, m_strMachineName);
     492    // if (strMediumPath.isEmpty())
     493    //     return;
     494    // //
     495    // CVirtualBox vbox = vboxGlobal().virtualBox();
     496
     497    // CMedium newMedium = vbox.CreateMedium(mediumFormats[0].GetName(), strMediumPath,
     498    //                                       KAccessMode_ReadWrite, UIMediumDefs::mediumTypeToGlobal(m_enmMediumType));
     499    // if (!vbox.isOk())
     500    // {
     501    //     msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this);
     502    //     return;
     503    // }
     504
     505
    441506}
    442507
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h

    r72444 r72815  
    4848public:
    4949
    50     UIMediumSelector(UIMediumType enmMediumType, QWidget *pParent = 0);
     50    UIMediumSelector(UIMediumType enmMediumType, const QString &machineName = QString(),
     51                     const QString &machineSettigFilePath = QString(), QWidget *pParent = 0);
    5152    QStringList selectedMediumIds() const;
    5253
     
    5859
    5960    void sltAddMedium();
     61    void sltCreateMedium();
    6062    void sltHandleItemSelectionChanged();
    6163    void sltHandleMediumEnumerationStart();
     
    98100    void          saveDefaultForeground();
    99101
     102
    100103    QVBoxLayout          *m_pMainLayout;
    101104    QITreeWidget         *m_pTreeWidget;
     
    104107    UIToolBar            *m_pToolBar;
    105108    QAction              *m_pActionAdd;
     109    QAction              *m_pActionCreate;
    106110    QAction              *m_pActionRefresh;
    107111    /** All the known media that are already attached to some vm are added under the following top level tree item */
     
    113117    QList<UIMediumItem*>  m_mediumItemList;
    114118    QBrush                m_defaultItemForeground;
    115 
     119    QString               m_strMachineSettingsFilePath;
     120    QString               m_strMachineName;
    116121};
    117122
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r72406 r72815  
    21932193    m_strMachineId = m_machine.GetId();
    21942194    m_strMachineSettingsFilePath = m_machine.GetSettingsFilePath();
     2195    m_strMachineName = m_machine.GetName();
    21952196    m_strMachineGuestOSTypeId = m_machine.GetOSTypeId();
    21962197
     
    37973798{
    37983799    QWidget *pParent = windowManager().realParentWindow(this);
    3799     QPointer<UIMediumSelector> pSelector = new UIMediumSelector(enmMediumType, pParent);
     3800    QPointer<UIMediumSelector> pSelector = new UIMediumSelector(enmMediumType, m_strMachineName,
     3801                                                                m_strMachineSettingsFilePath, pParent);
    38003802
    38013803    if (!pSelector)
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h

    r72406 r72815  
    797797    /** Holds the machine settings file-path. */
    798798    QString  m_strMachineSettingsFilePath;
     799    /** Holds the machine settings file-path. */
     800    QString  m_strMachineName;
    799801    /** Holds the machine guest OS type ID. */
    800802    QString  m_strMachineGuestOSTypeId;
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