VirtualBox

Changeset 74928 in vbox


Ignore:
Timestamp:
Oct 18, 2018 4:46:59 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125937
Message:

FE/Qt: bugref:9230: Cloud Profile Manager: Support for profile name changes; Possiblity to add new profile directly from details widget.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/UICloudProfileDetailsWidget.cpp

    r74910 r74928  
    2121
    2222/* Qt includes: */
     23# include <QGridLayout>
    2324# include <QHeaderView>
     25# include <QLabel>
     26# include <QLineEdit>
    2427# include <QPushButton>
    2528# include <QTableWidget>
     
    5457    /* Load data: */
    5558    loadData();
     59
     60    /* Translate linked widgets: */
     61    retranslateEditor();
     62    retranslateButtons();
    5663}
    5764
     
    6067    /// @todo add description tool-tips
    6168
     69    /* Translate name-editor label: */
     70    m_pLabelName->setText(tr("Name:"));
     71    /* Translate name-editor: */
     72    retranslateEditor();
     73
     74    /* Translate table-widget label: */
     75    m_pLabelTableWidget->setText(tr("Properties:"));
    6276    /* Translate table-widget: */
    6377    m_pTableWidget->setToolTip(tr("Contains cloud profile settings"));
    6478
     79    /* Translate buttons: */
     80    retranslateButtons();
     81
     82    /* Retranslate validation: */
     83    retranslateValidation();
     84
     85    /* Update table tool-tips: */
     86    updateTableToolTips();
     87}
     88
     89void UICloudProfileDetailsWidget::retranslateEditor()
     90{
     91    /* Translate placeholders: */
     92    m_pEditorName->setPlaceholderText(  m_oldData.m_strName.isNull()
     93                                      ? tr("Enter a name for the new profile...")
     94                                      : tr("Enter a name for this profile..."));
     95}
     96
     97void UICloudProfileDetailsWidget::retranslateButtons()
     98{
    6599    /* Translate button-box: */
    66100    if (m_pButtonBox)
    67101    {
     102        /* Common: 'Reset' button: */
    68103        m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Reset"));
    69         m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Apply"));
     104        m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Reset changes in current profile details"));
    70105        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
    71         m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
    72         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Reset changes in current profile details"));
    73         m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Apply changes in current profile details"));
    74106        m_pButtonBox->button(QDialogButtonBox::Cancel)->
    75107            setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString()));
    76         m_pButtonBox->button(QDialogButtonBox::Ok)->
    77             setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
    78     }
    79 
    80     /* Retranslate validation: */
    81     retranslateValidation();
    82 
    83     /* Update table tool-tips: */
    84     updateTableToolTips();
     108
     109        if (m_oldData.m_strName.isNull())
     110        {
     111            /* Provider: 'Add' button: */
     112            m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Add"));
     113            m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Add a new profile with following name"));
     114            m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
     115            m_pButtonBox->button(QDialogButtonBox::Ok)->
     116                setToolTip(tr("Add Profile (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
     117        }
     118        else
     119        {
     120            /* Profile: 'Apply' button: */
     121            m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Apply"));
     122            m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Apply changes in current profile details"));
     123            m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
     124            m_pButtonBox->button(QDialogButtonBox::Ok)->
     125                setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
     126        }
     127    }
     128}
     129
     130void UICloudProfileDetailsWidget::sltNameChanged(const QString &strName)
     131{
     132    /* Push changes back: */
     133    m_newData.m_strName = strName;
     134
     135    /* Revalidate: */
     136    revalidate(m_pEditorName);
     137    /* Update button states: */
     138    updateButtonStates();
    85139}
    86140
     
    142196{
    143197    /* Create layout: */
    144     QVBoxLayout *pLayout = new QVBoxLayout(this);
     198    QGridLayout *pLayout = new QGridLayout(this);
    145199    if (pLayout)
    146200    {
    147         /* Configure layout: */
    148         pLayout->setContentsMargins(0, 0, 0, 0);
     201        if (m_enmEmbedding == EmbedTo_Dialog)
     202        {
     203            pLayout->setContentsMargins(0, 0, 0, 0);
     204#ifdef VBOX_WS_MAC
     205            pLayout->setSpacing(10);
     206#else
     207            pLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);
     208#endif
     209        }
     210
     211        /* Create name editor: */
     212        m_pEditorName = new QLineEdit;
     213        if (m_pEditorName)
     214        {
     215            connect(m_pEditorName, &QLineEdit::textChanged, this, &UICloudProfileDetailsWidget::sltNameChanged);
     216
     217            /* Add into layout: */
     218            pLayout->addWidget(m_pEditorName, 0, 1);
     219        }
     220        /* Create name label: */
     221        m_pLabelName = new QLabel;
     222        if (m_pLabelName)
     223        {
     224            m_pLabelName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
     225            m_pLabelName->setBuddy(m_pEditorName);
     226
     227            /* Add into layout: */
     228            pLayout->addWidget(m_pLabelName, 0, 0);
     229        }
    149230
    150231        /* Create tab-widget: */
     
    159240
    160241            /* Add into layout: */
    161             pLayout->addWidget(m_pTableWidget);
     242            pLayout->addWidget(m_pTableWidget, 1, 1);
     243        }
     244        /* Create tab-widget label: */
     245        m_pLabelTableWidget = new QLabel;
     246        if (m_pLabelTableWidget)
     247        {
     248            m_pLabelTableWidget->setAlignment(Qt::AlignRight | Qt::AlignTop);
     249            m_pLabelTableWidget->setBuddy(m_pTableWidget);
     250
     251            /* Add into layout: */
     252            pLayout->addWidget(m_pLabelTableWidget, 1, 0);
    162253        }
    163254
     
    184275
    185276                /* Add into layout: */
    186                 pLayout->addLayout(pButtonBoxLayout);
     277                pLayout->addLayout(pButtonBoxLayout, 2, 0, 1, 2);
    187278            }
    188279        }
     
    194285    /* Clear table initially: */
    195286    m_pTableWidget->clear();
     287
     288    /* Fill name editor: */
     289    m_pEditorName->setText(m_oldData.m_strName);
    196290
    197291    /* Configure table: */
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/UICloudProfileDetailsWidget.h

    r74898 r74928  
    2929/* Forward declarations: */
    3030class QAbstractButton;
     31class QLabel;
     32class QLineEdit;
    3133class QTableWidget;
    3234class QTableWidgetItem;
     
    122124    /** Handles translation event. */
    123125    virtual void retranslateUi() /* override */;
     126    /** Handles editor translation. */
     127    void retranslateEditor();
     128    /** Handles buttons translation. */
     129    void retranslateButtons();
    124130
    125131private slots:
     
    127133    /** @name Change handling stuff.
    128134      * @{ */
     135        /** Handles name change. */
     136        void sltNameChanged(const QString &strName);
    129137        /** Handles table change. */
    130138        void sltTableChanged(QTableWidgetItem *pItem);
     
    178186    /** @} */
    179187
    180     /** @name Interface variables.
    181       * @{ */
    182         /** Holds the automatic interface configuration button. */
     188    /** @name Widget variables.
     189      * @{ */
     190        /** Holds the name label instance. */
     191        QLabel    *m_pLabelName;
     192        /** Holds the name editor instance. */
     193        QLineEdit *m_pEditorName;
     194
     195        /** Holds the table-widget label instance. */
     196        QLabel       *m_pLabelTableWidget;
     197        /** Holds the table-widget instance. */
    183198        QTableWidget *m_pTableWidget;
    184199
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/UICloudProfileManager.cpp

    r74923 r74928  
    187187void UICloudProfileManagerWidget::sltApplyCloudProfileDetailsChanges()
    188188{
     189    /* Is can be that there is provider item, not profile item currently selected.
     190     * In such case we are not applying parameters, we are creating new one profile. */
     191    UIItemCloudProvider *pMaybeProviderItem = static_cast<UIItemCloudProvider*>(m_pTreeWidget->currentItem());
     192    if (pMaybeProviderItem)
     193        return sltAddCloudProfile();
     194
    189195    /* Get profile item: */
    190196    UIItemCloudProfile *pProfileItem = static_cast<UIItemCloudProfile*>(m_pTreeWidget->currentItem());
     
    224230            else
    225231            {
    226                 /* Iterate through old/new data: */
    227                 foreach (const QString &strKey, oldData.m_data.keys())
     232                /* Set profile name, if necessary: */
     233                if (newData.m_strName != oldData.m_strName)
     234                    comCloudProfile.SetName(newData.m_strName);
     235                /* Show error message if necessary: */
     236                if (!comCloudProfile.isOk())
     237                    msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
     238                else
    228239                {
    229                     /* Get values: */
    230                     const QString strOldValue = oldData.m_data.value(strKey).first;
    231                     const QString strNewValue = newData.m_data.value(strKey).first;
    232                     if (strNewValue != strOldValue)
     240                    /* Iterate through old/new data: */
     241                    foreach (const QString &strKey, oldData.m_data.keys())
    233242                    {
    234                         /* Apply property: */
    235                         comCloudProfile.SetProperty(strKey, strNewValue);
    236                         /* Show error message if necessary: */
    237                         if (!comCloudProfile.isOk())
     243                        /* Get values: */
     244                        const QString strOldValue = oldData.m_data.value(strKey).first;
     245                        const QString strNewValue = newData.m_data.value(strKey).first;
     246                        if (strNewValue != strOldValue)
    238247                        {
    239                             msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
    240                             break;
     248                            /* Apply property: */
     249                            comCloudProfile.SetProperty(strKey, strNewValue);
     250                            /* Show error message if necessary: */
     251                            if (!comCloudProfile.isOk())
     252                            {
     253                                msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
     254                                break;
     255                            }
    241256                        }
    242257                    }
     
    271286    AssertMsgReturnVoid(pProviderItem, ("Current item must not be null!\n"));
    272287
    273     /* Acquire profile name first of all: */
    274     QString strProfileName;
    275     QPointer<QInputDialog> pDialog = new QInputDialog(this);
    276     pDialog->setInputMode(QInputDialog::TextInput);
    277     pDialog->setWindowIcon(UIIconPool::iconSet(":/cloud_profile_add_16px.png"));
    278     pDialog->setWindowTitle(tr("Add Profile"));
    279     pDialog->setLabelText(tr("Name:"));
    280     bool fCancelled = false;
    281     if (pDialog->exec() == QDialog::Accepted)
    282         strProfileName = pDialog->textValue();
    283     else
    284         fCancelled = true;
    285     delete pDialog;
    286     if (fCancelled)
    287         return;
     288    /* Acquire profile name if not proposed by details widget: */
     289    QString strProfileName = m_pDetailsWidget->data().m_strName;
     290    if (strProfileName.isNull())
     291    {
     292        QPointer<QInputDialog> pDialog = new QInputDialog(this);
     293        pDialog->setInputMode(QInputDialog::TextInput);
     294        pDialog->setWindowIcon(UIIconPool::iconSet(":/cloud_profile_add_16px.png"));
     295        pDialog->setWindowTitle(tr("Add Profile"));
     296        pDialog->setLabelText(tr("Name:"));
     297        bool fCancelled = false;
     298        if (pDialog->exec() == QDialog::Accepted)
     299            strProfileName = pDialog->textValue();
     300        else
     301            fCancelled = true;
     302        delete pDialog;
     303        if (fCancelled)
     304            return;
     305    }
    288306
    289307    /* Get VirtualBox for further activities: */
     
    465483    m_pActionPool->action(UIActionIndexST_M_Cloud_S_Add)->setEnabled(!pItem || pItemProvider);
    466484    m_pActionPool->action(UIActionIndexST_M_Cloud_S_Remove)->setEnabled(pItemProfile);
    467     m_pActionPool->action(UIActionIndexST_M_Cloud_T_Details)->setEnabled(pItemProfile);
     485    m_pActionPool->action(UIActionIndexST_M_Cloud_T_Details)->setEnabled(pItemProfile || pItemProvider);
    468486    m_pActionPool->action(UIActionIndexST_M_Cloud_S_Import)->setEnabled(!pItem || pItemProvider);
    469487
     
    500518    {
    501519        menu.addAction(m_pActionPool->action(UIActionIndexST_M_Cloud_S_Add));
     520        menu.addAction(m_pActionPool->action(UIActionIndexST_M_Cloud_T_Details));
    502521        menu.addAction(m_pActionPool->action(UIActionIndexST_M_Cloud_S_Import));
    503522    }
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