VirtualBox

Changeset 35956 in vbox


Ignore:
Timestamp:
Feb 14, 2011 11:43:07 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 3792: Using user-home-path as the default path while creating new shared folders; UIMachineSettingsSFDetails class cleanup.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSFDetails.cpp

    r33882 r35956  
    77
    88/*
    9  * Copyright (C) 2008-2010 Oracle Corporation
     9 * Copyright (C) 2008-2011 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 #include "UIMachineSettingsSFDetails.h"
    21 #include "VBoxGlobal.h"
    22 
    2320/* Qt includes */
    2421#include <QDir>
    2522#include <QPushButton>
    2623
    27 UIMachineSettingsSFDetails::UIMachineSettingsSFDetails (DialogType aType,
    28                                                   bool aEnableSelector, /* for "permanent" checkbox */
    29                                                   const SFoldersNameList &aUsedNames,
    30                                                   QWidget *aParent /* = NULL */)
    31    : QIWithRetranslateUI2<QIDialog> (aParent)
    32    , mType (aType)
    33    , mUsePermanent (aEnableSelector)
    34    , mUsedNames (aUsedNames)
     24/* Other includes */
     25#include "UIMachineSettingsSFDetails.h"
     26#include "VBoxGlobal.h"
     27
     28UIMachineSettingsSFDetails::UIMachineSettingsSFDetails(DialogType type,
     29                                                       bool fEnableSelector, /* for "permanent" checkbox */
     30                                                       const SFoldersNameList &usedNames,
     31                                                       QWidget *pParent /* = 0 */)
     32   : QIWithRetranslateUI2<QIDialog>(pParent)
     33   , m_type(type)
     34   , m_fUsePermanent(fEnableSelector)
     35   , m_usedNames(usedNames)
    3536{
    36     /* Apply UI decorations */
    37     Ui::UIMachineSettingsSFDetails::setupUi (this);
     37    /* Apply UI decorations: */
     38    Ui::UIMachineSettingsSFDetails::setupUi(this);
    3839
    39     mCbPermanent->setHidden (!aEnableSelector);
    40 
    41     /* No reset button */
    42     mPsPath->setResetEnabled (false);
     40    /* Setup widgets: */
     41    mPsPath->setResetEnabled(false);
     42    mPsPath->setHomeDir(QDir::homePath());
     43    mCbPermanent->setHidden(!fEnableSelector);
    4344
    4445    /* Setup connections: */
    45     connect (mPsPath, SIGNAL (currentIndexChanged (int)),
    46              this, SLOT (onSelectPath()));
    47     connect (mPsPath, SIGNAL (pathChanged (const QString &)),
    48              this, SLOT (onSelectPath()));
    49     connect (mLeName, SIGNAL (textChanged (const QString &)),
    50              this, SLOT (validate()));
     46    connect(mPsPath, SIGNAL(currentIndexChanged(int)), this, SLOT(sltSelectPath()));
     47    connect(mPsPath, SIGNAL(pathChanged(const QString &)), this, SLOT(sltSelectPath()));
     48    connect(mLeName, SIGNAL(textChanged(const QString &)), this, SLOT(sltValidate()));
     49    if (fEnableSelector)
     50        connect(mCbPermanent, SIGNAL(toggled(bool)), this, SLOT(sltValidate()));
    5151
    52     if (aEnableSelector)
    53     {
    54         connect (mCbPermanent, SIGNAL (toggled (bool)),
    55                  this, SLOT (validate()));
    56     }
    57 
    58      /* Applying language settings */
     52     /* Applying language settings: */
    5953    retranslateUi();
    6054
    61     /* Validate the initial fields */
    62     validate();
     55    /* Validate the initial field values: */
     56    sltValidate();
    6357
     58    /* Adjust dialog size: */
    6459    adjustSize();
    6560
    6661#ifdef Q_WS_MAC
    67     setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
    68     setFixedSize (minimumSize());
     62    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     63    setFixedSize(minimumSize());
    6964#endif /* Q_WS_MAC */
    7065}
    7166
    72 void UIMachineSettingsSFDetails::setPath (const QString &aPath)
     67void UIMachineSettingsSFDetails::setPath(const QString &strPath)
    7368{
    74     mPsPath->setPath (aPath);
     69    mPsPath->setPath(strPath);
    7570}
    7671
     
    8075}
    8176
    82 void UIMachineSettingsSFDetails::setName (const QString &aName)
     77void UIMachineSettingsSFDetails::setName(const QString &strName)
    8378{
    84     mLeName->setText (aName);
     79    mLeName->setText(strName);
    8580}
    8681
     
    9085}
    9186
    92 void UIMachineSettingsSFDetails::setWriteable (bool aWritable)
     87void UIMachineSettingsSFDetails::setWriteable(bool fWritable)
    9388{
    94     mCbReadonly->setChecked (!aWritable);
     89    mCbReadonly->setChecked(!fWritable);
    9590}
    9691
     
    10095}
    10196
    102 void UIMachineSettingsSFDetails::setAutoMount (bool aAutoMount)
     97void UIMachineSettingsSFDetails::setAutoMount(bool fAutoMount)
    10398{
    104     mCbAutoMount->setChecked (aAutoMount);
     99    mCbAutoMount->setChecked(fAutoMount);
    105100}
    106101
     
    110105}
    111106
    112 void UIMachineSettingsSFDetails::setPermanent (bool aPermanent)
     107void UIMachineSettingsSFDetails::setPermanent(bool fPermanent)
    113108{
    114     mCbPermanent->setChecked (aPermanent);
     109    mCbPermanent->setChecked(fPermanent);
    115110}
    116111
    117112bool UIMachineSettingsSFDetails::isPermanent() const
    118113{
    119     return mUsePermanent ? mCbPermanent->isChecked() : true;
     114    return m_fUsePermanent ? mCbPermanent->isChecked() : true;
    120115}
    121116
    122117void UIMachineSettingsSFDetails::retranslateUi()
    123118{
    124     /* Translate uic generated strings */
    125     Ui::UIMachineSettingsSFDetails::retranslateUi (this);
     119    /* Translate uic generated strings: */
     120    Ui::UIMachineSettingsSFDetails::retranslateUi(this);
    126121
    127     switch (mType)
     122    switch (m_type)
    128123    {
    129124        case AddType:
    130             setWindowTitle (tr ("Add Share"));
     125            setWindowTitle(tr("Add Share"));
    131126            break;
    132127        case EditType:
    133             setWindowTitle (tr ("Edit Share"));
     128            setWindowTitle(tr("Edit Share"));
    134129            break;
    135130        default:
    136             AssertMsgFailed (("Incorrect SF Dialog type\n"));
     131            AssertMsgFailed(("Incorrect shared-folders dialog type: %d\n", m_type));
    137132    }
    138133}
    139134
    140 void UIMachineSettingsSFDetails::validate()
     135void UIMachineSettingsSFDetails::sltValidate()
    141136{
    142     UISharedFolderType resultType =
    143         mUsePermanent && !mCbPermanent->isChecked() ? ConsoleType : MachineType;
    144     SFolderName pair = qMakePair (mLeName->text(), resultType);
     137    UISharedFolderType resultType = m_fUsePermanent && !mCbPermanent->isChecked() ? ConsoleType : MachineType;
     138    SFolderName pair = qMakePair(mLeName->text(), resultType);
    145139
    146     mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!mPsPath->path().isEmpty() &&
    147                                                            QDir(mPsPath->path()).exists() &&
    148                                                            !mLeName->text().trimmed().isEmpty() &&
    149                                                            !mLeName->text().contains(" ") &&
    150                                                            !mUsedNames.contains (pair));
     140    mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!mPsPath->path().isEmpty() &&
     141                                                         QDir(mPsPath->path()).exists() &&
     142                                                         !mLeName->text().trimmed().isEmpty() &&
     143                                                         !mLeName->text().contains(" ") &&
     144                                                         !m_usedNames.contains (pair));
    151145}
    152146
    153 void UIMachineSettingsSFDetails::onSelectPath()
     147void UIMachineSettingsSFDetails::sltSelectPath()
    154148{
    155149    if (!mPsPath->isPathSelected())
    156150        return;
    157151
    158     QString folderName (mPsPath->path());
    159 #if defined (Q_OS_WIN) || defined (Q_OS_OS2)
    160     if (folderName[0].isLetter() && folderName[1] == ':' && folderName[2] == 0)
     152    QString strFolderName(mPsPath->path());
     153#if defined (Q_WS_WIN) || defined (Q_OS_OS2)
     154    if (strFolderName[0].isLetter() && strFolderName[1] == ':' && strFolderName[2] == 0)
    161155    {
    162156        /* VBoxFilePathSelectorWidget returns root path as 'X:', which is invalid path.
    163          * Append the trailing backslash to get a valid root path 'X:\'.
    164          */
    165         folderName += "\\";
    166         mPsPath->setPath(folderName);
     157         * Append the trailing backslash to get a valid root path 'X:\': */
     158        strFolderName += "\\";
     159        mPsPath->setPath(strFolderName);
    167160    }
    168 #endif
    169     QDir folder (folderName);
     161#endif /* Q_WS_WIN || Q_OS_OS2 */
     162    QDir folder(strFolderName);
    170163    if (!folder.isRoot())
     164    {
    171165        /* Processing non-root folder */
    172         mLeName->setText (folder.dirName().replace(' ', '_'));
     166        mLeName->setText(folder.dirName().replace(' ', '_'));
     167    }
    173168    else
    174169    {
    175         /* Processing root folder */
    176 #if defined (Q_OS_WIN) || defined (Q_OS_OS2)
    177         mLeName->setText (folderName.toUpper()[0] + "_DRIVE");
    178 #elif defined (Q_OS_UNIX)
    179         mLeName->setText ("ROOT");
     170        /* Processing root folder: */
     171#if defined (Q_WS_WIN) || defined (Q_OS_OS2)
     172        mLeName->setText(strFolderName.toUpper()[0] + "_DRIVE");
     173#elif defined (Q_WS_X11)
     174        mLeName->setText("ROOT");
    180175#endif
    181176    }
    182     /* Validate the fields */
    183     validate();
     177    /* Validate the field values: */
     178    sltValidate();
    184179}
    185180
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSFDetails.h

    r33882 r35956  
    66
    77/*
    8  * Copyright (C) 2008 Oracle Corporation
     8 * Copyright (C) 2008-2011 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#define __UIMachineSettingsSFDetails_h__
    2121
     22/* Includes */
    2223#include "UIMachineSettingsSFDetails.gen.h"
    2324#include "QIDialog.h"
     
    2526#include "UIMachineSettingsSF.h"
    2627
     28/* Shared folders details dialog: */
    2729class UIMachineSettingsSFDetails : public QIWithRetranslateUI2<QIDialog>,
    28                                 public Ui::UIMachineSettingsSFDetails
     30                                   public Ui::UIMachineSettingsSFDetails
    2931{
    3032    Q_OBJECT;
     
    3840    };
    3941
    40     UIMachineSettingsSFDetails (DialogType aType,
    41                              bool aEnableSelector, /* for "permanent" checkbox */
    42                              const SFoldersNameList &aUsedNames,
    43                              QWidget *aParent = NULL);
     42    UIMachineSettingsSFDetails(DialogType type,
     43                               bool fEnableSelector, /* for "permanent" checkbox */
     44                               const SFoldersNameList &usedNames,
     45                               QWidget *pParent = 0);
    4446
    45     void setPath (const QString &aPath);
     47    void setPath(const QString &strPath);
    4648    QString path() const;
    4749
    48     void setName (const QString &aName);
     50    void setName(const QString &strName);
    4951    QString name() const;
    5052
    51     void setWriteable (bool aWriteable);
     53    void setWriteable(bool fWriteable);
    5254    bool isWriteable() const;
    5355
    54     void setAutoMount (bool aAutoMount);
     56    void setAutoMount(bool fAutoMount);
    5557    bool isAutoMounted() const;
    5658
    57     void setPermanent (bool aPermanent);
     59    void setPermanent(bool fPermanent);
    5860    bool isPermanent() const;
    5961
     
    6466private slots:
    6567
    66     void onSelectPath();
    67     void validate();
     68    void sltSelectPath();
     69    void sltValidate();
    6870
    6971private:
    7072
    71     /* Private member vars */
    72     DialogType       mType;
    73     bool             mUsePermanent;
    74     SFoldersNameList mUsedNames;
     73    DialogType       m_type;
     74    bool             m_fUsePermanent;
     75    SFoldersNameList m_usedNames;
    7576};
    7677
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