1 | /* $Id: UIMediumTypeChangeDialog.cpp 41819 2012-06-18 17:59:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMediumTypeChangeDialog class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2011 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Qt includes: */
|
---|
21 | #include <QVBoxLayout>
|
---|
22 | #include <QGroupBox>
|
---|
23 | #include <QRadioButton>
|
---|
24 | #include <QPushButton>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "UIMediumTypeChangeDialog.h"
|
---|
28 | #include "VBoxGlobal.h"
|
---|
29 | #include "UIMessageCenter.h"
|
---|
30 | #include "QILabel.h"
|
---|
31 | #include "QIDialogButtonBox.h"
|
---|
32 | #include "UIConverter.h"
|
---|
33 |
|
---|
34 | /* Constructor: */
|
---|
35 | UIMediumTypeChangeDialog::UIMediumTypeChangeDialog(QWidget *pParent, const QString &strMediumId)
|
---|
36 | : QIWithRetranslateUI<QIDialog>(pParent)
|
---|
37 | {
|
---|
38 | #ifdef Q_WS_MAC
|
---|
39 | setWindowFlags(Qt::Sheet);
|
---|
40 | #else /* Q_WS_MAC */
|
---|
41 | /* Enable size-grip: */
|
---|
42 | setSizeGripEnabled(true);
|
---|
43 | #endif /* Q_WS_MAC */
|
---|
44 |
|
---|
45 | /* Search for corresponding medium: */
|
---|
46 | m_medium = vboxGlobal().findMedium(strMediumId).medium();
|
---|
47 | m_oldMediumType = m_medium.GetType();
|
---|
48 | m_newMediumType = m_oldMediumType;
|
---|
49 |
|
---|
50 | /* Create main layout: */
|
---|
51 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
52 |
|
---|
53 | /* Create description label: */
|
---|
54 | m_pLabel = new QILabel(this);
|
---|
55 | m_pLabel->setWordWrap(true);
|
---|
56 | m_pLabel->useSizeHintForWidth(450);
|
---|
57 | m_pLabel->updateGeometry();
|
---|
58 | pMainLayout->addWidget(m_pLabel);
|
---|
59 |
|
---|
60 | /* Create group-box: */
|
---|
61 | m_pGroupBox = new QGroupBox(this);
|
---|
62 | pMainLayout->addWidget(m_pGroupBox);
|
---|
63 |
|
---|
64 | /* Create button-box: */
|
---|
65 | m_pButtonBox = new QIDialogButtonBox(this);
|
---|
66 | m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
---|
67 | m_pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
---|
68 | connect(m_pButtonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(sltAccept()));
|
---|
69 | connect(m_pButtonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(sltReject()));
|
---|
70 | pMainLayout->addWidget(m_pButtonBox);
|
---|
71 |
|
---|
72 | /* Finally, add a stretch: */
|
---|
73 | pMainLayout->addStretch();
|
---|
74 |
|
---|
75 | /* Create radio-buttons: */
|
---|
76 | createMediumTypeButtons();
|
---|
77 |
|
---|
78 | /* Retranslate: */
|
---|
79 | retranslateUi();
|
---|
80 |
|
---|
81 | /* Resize: */
|
---|
82 | resize(minimumSizeHint());
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* Accept finisher: */
|
---|
86 | void UIMediumTypeChangeDialog::sltAccept()
|
---|
87 | {
|
---|
88 | /* Try to assign new medium type: */
|
---|
89 | m_medium.SetType(m_newMediumType);
|
---|
90 | /* Check for result: */
|
---|
91 | if (!m_medium.isOk())
|
---|
92 | {
|
---|
93 | /* Show error message: */
|
---|
94 | msgCenter().cannotChangeMediumType(this, m_medium, m_oldMediumType, m_newMediumType);
|
---|
95 | return;
|
---|
96 | }
|
---|
97 | /* Accept dialog with parent class method: */
|
---|
98 | QIWithRetranslateUI<QIDialog>::accept();
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* Reject finisher: */
|
---|
102 | void UIMediumTypeChangeDialog::sltReject()
|
---|
103 | {
|
---|
104 | /* Reject dialog with parent class method: */
|
---|
105 | QIWithRetranslateUI<QIDialog>::reject();
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* Translation stuff: */
|
---|
109 | void UIMediumTypeChangeDialog::retranslateUi()
|
---|
110 | {
|
---|
111 | /* Translate window title: */
|
---|
112 | setWindowTitle(tr("Modify medium attributes"));
|
---|
113 |
|
---|
114 | /* Translate description: */
|
---|
115 | m_pLabel->setText(tr("<p>You are about to change the attributes of the virtual disk located in <b>%1</b>.</p>"
|
---|
116 | "<p>Please choose one of the following medium types and press <b>%2</b> "
|
---|
117 | "to proceed or <b>%3</b> otherwise.</p>")
|
---|
118 | .arg(m_medium.GetLocation())
|
---|
119 | .arg(VBoxGlobal::removeAccelMark(m_pButtonBox->button(QDialogButtonBox::Ok)->text()))
|
---|
120 | .arg(VBoxGlobal::removeAccelMark(m_pButtonBox->button(QDialogButtonBox::Cancel)->text())));
|
---|
121 |
|
---|
122 | /* Translate group-box: */
|
---|
123 | m_pGroupBox->setTitle(tr("Choose medium type:"));
|
---|
124 |
|
---|
125 | /* Translate radio-buttons: */
|
---|
126 | QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
|
---|
127 | for (int i = 0; i < buttons.size(); ++i)
|
---|
128 | buttons[i]->setText(gpConverter->toString(buttons[i]->property("mediumType").value<KMediumType>()));
|
---|
129 | }
|
---|
130 |
|
---|
131 | void UIMediumTypeChangeDialog::sltValidate()
|
---|
132 | {
|
---|
133 | /* Search for the checked button: */
|
---|
134 | QRadioButton *pCheckedButton = 0;
|
---|
135 | QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
|
---|
136 | for (int i = 0; i < buttons.size(); ++i)
|
---|
137 | {
|
---|
138 | if (buttons[i]->isChecked())
|
---|
139 | {
|
---|
140 | pCheckedButton = buttons[i];
|
---|
141 | break;
|
---|
142 | }
|
---|
143 | }
|
---|
144 | /* Determine chosen type: */
|
---|
145 | m_newMediumType = pCheckedButton->property("mediumType").value<KMediumType>();
|
---|
146 | /* Enable/disable OK button depending on chosen type,
|
---|
147 | * for now only the previous type is restricted, others are free to choose: */
|
---|
148 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_oldMediumType != m_newMediumType);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* Create medium-type radio-buttons: */
|
---|
152 | void UIMediumTypeChangeDialog::createMediumTypeButtons()
|
---|
153 | {
|
---|
154 | /* Register required meta-type: */
|
---|
155 | qRegisterMetaType<KMediumType>();
|
---|
156 | /* Create group-box layout: */
|
---|
157 | m_pGroupBoxLayout = new QVBoxLayout(m_pGroupBox);
|
---|
158 | /* Populate radio-buttons: */
|
---|
159 | createMediumTypeButton(KMediumType_Normal);
|
---|
160 | createMediumTypeButton(KMediumType_Immutable);
|
---|
161 | createMediumTypeButton(KMediumType_Writethrough);
|
---|
162 | createMediumTypeButton(KMediumType_Shareable);
|
---|
163 | createMediumTypeButton(KMediumType_MultiAttach);
|
---|
164 | /* Make sure button reflecting previoius type is checked: */
|
---|
165 | QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
|
---|
166 | for (int i = 0; i < buttons.size(); ++i)
|
---|
167 | {
|
---|
168 | if (buttons[i]->property("mediumType").value<KMediumType>() == m_oldMediumType)
|
---|
169 | {
|
---|
170 | buttons[i]->setChecked(true);
|
---|
171 | buttons[i]->setFocus();
|
---|
172 | break;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | /* Revalidate finally: */
|
---|
176 | sltValidate();
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* Create radio-button for the passed medium-type: */
|
---|
180 | void UIMediumTypeChangeDialog::createMediumTypeButton(KMediumType mediumType)
|
---|
181 | {
|
---|
182 | /* Create corresponding radio-button: */
|
---|
183 | QRadioButton *pRadioButton = new QRadioButton(m_pGroupBox);
|
---|
184 | connect(pRadioButton, SIGNAL(clicked()), this, SLOT(sltValidate()));
|
---|
185 | pRadioButton->setProperty("mediumType", QVariant::fromValue(mediumType));
|
---|
186 | m_pGroupBoxLayout->addWidget(pRadioButton);
|
---|
187 | }
|
---|
188 |
|
---|