VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp@ 82781

Last change on this file since 82781 was 79365, checked in by vboxsync, 5 years ago

Renaming VBoxGlobal to UICommon for bugref:9049 as planned.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: UIFDCreationDialog.cpp 79365 2019-06-26 15:57:32Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFDCreationDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2008-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/* Qt includes */
19#include<QCheckBox>
20#include<QDialogButtonBox>
21#include<QDir>
22#include<QGridLayout>
23#include<QLabel>
24#include<QPushButton>
25
26/* GUI includes */
27#include "UIFDCreationDialog.h"
28#include "UIFilePathSelector.h"
29#include "UIMedium.h"
30#include "UIMessageCenter.h"
31#include "UICommon.h"
32
33/* COM includes: */
34#include "CSystemProperties.h"
35#include "CMedium.h"
36#include "CMediumFormat.h"
37
38
39UIFDCreationDialog::UIFDCreationDialog(QWidget *pParent,
40 const QString &strDefaultFolder,
41 const QString &strMachineName /* = QString() */)
42 : QIWithRetranslateUI<QDialog>(pParent)
43 , m_pFilePathselector(0)
44 , m_pPathLabel(0)
45 , m_pSizeLabel(0)
46 , m_pSizeCombo(0)
47 , m_pButtonBox(0)
48 , m_pFormatCheckBox(0)
49 , m_strDefaultFolder(strDefaultFolder)
50 , m_strMachineName(strMachineName)
51{
52
53 prepare();
54 /* Adjust dialog size: */
55 adjustSize();
56
57#ifdef VBOX_WS_MAC
58 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
59 setFixedSize(minimumSize());
60#endif /* VBOX_WS_MAC */
61}
62
63void UIFDCreationDialog::retranslateUi()
64{
65 if (m_strMachineName.isEmpty())
66 setWindowTitle(QString("%1").arg(tr("Floppy Disk Creator")));
67 else
68 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Floppy Disk Creator")));
69 if (m_pPathLabel)
70 m_pPathLabel->setText(tr("File Path:"));
71 if (m_pSizeLabel)
72 m_pSizeLabel->setText(tr("Size:"));
73 if (m_pButtonBox)
74 m_pButtonBox->button(QDialogButtonBox::Ok)->setText("Create");
75 if (m_pFormatCheckBox)
76 m_pFormatCheckBox->setText(tr("Format disk as FAT12"));
77 if (m_pSizeCombo)
78 {
79 //m_pSizeCombo->setItemText(FDSize_2_88M, tr("2.88M"));
80 m_pSizeCombo->setItemText(FDSize_1_44M, tr("1.44M"));
81 m_pSizeCombo->setItemText(FDSize_1_2M, tr("1.2M"));
82 m_pSizeCombo->setItemText(FDSize_720K, tr("720K"));
83 m_pSizeCombo->setItemText(FDSize_360K, tr("360K"));
84 }
85}
86
87void UIFDCreationDialog::prepare()
88{
89
90#ifndef VBOX_WS_MAC
91 setWindowIcon(QIcon(":/fd_add_32px.png"));
92#endif
93
94 setWindowModality(Qt::WindowModal);
95 setSizeGripEnabled(false);
96
97 QGridLayout *pMainLayout = new QGridLayout;
98 if (!pMainLayout)
99 return;
100 setLayout(pMainLayout);
101
102 m_pPathLabel = new QLabel;
103 if (m_pPathLabel)
104 {
105 pMainLayout->addWidget(m_pPathLabel, 0, 0, 1, 1);
106 m_pPathLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
107 }
108
109 m_pFilePathselector = new UIFilePathSelector;
110 if (m_pFilePathselector)
111 {
112 pMainLayout->addWidget(m_pFilePathselector, 0, 1, 1, 2);
113 m_pFilePathselector->setMode(UIFilePathSelector::Mode_File_Save);
114 QString strFolder = getDefaultFolder();
115 m_pFilePathselector->setDefaultPath(strFolder);
116 m_pFilePathselector->setPath(strFolder);
117 }
118
119 m_pSizeLabel = new QLabel;
120 if (m_pSizeLabel)
121 {
122 pMainLayout->addWidget(m_pSizeLabel, 1, 0, 1, 1);
123 m_pSizeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
124 }
125
126 m_pSizeCombo = new QComboBox;
127 if (m_pSizeCombo)
128 {
129 pMainLayout->addWidget(m_pSizeCombo, 1, 1, 1, 1);
130 //m_pSizeCombo->insertItem(FDSize_2_88M, "2.88M", 2949120);
131 m_pSizeCombo->insertItem(FDSize_1_44M, "1.44M", 1474560);
132 m_pSizeCombo->insertItem(FDSize_1_2M, "1.2M", 1228800);
133 m_pSizeCombo->insertItem(FDSize_720K, "720K", 737280);
134 m_pSizeCombo->insertItem(FDSize_360K, "360K", 368640);
135 m_pSizeCombo->setCurrentIndex(FDSize_1_44M);
136
137 }
138
139 m_pFormatCheckBox = new QCheckBox;
140 if (m_pFormatCheckBox)
141 {
142 pMainLayout->addWidget(m_pFormatCheckBox, 2, 1, 1, 1);
143 m_pFormatCheckBox->setCheckState(Qt::Checked);
144 }
145
146 m_pButtonBox =
147 new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
148 if (m_pButtonBox)
149 {
150 pMainLayout->addWidget(m_pButtonBox, 3, 0, 1, 3);
151 connect(m_pButtonBox, &QDialogButtonBox::accepted, this, &UIFDCreationDialog::accept);
152 connect(m_pButtonBox, &QDialogButtonBox::rejected, this, &UIFDCreationDialog::reject);
153 }
154 retranslateUi();
155}
156
157QString UIFDCreationDialog::getDefaultFolder() const
158{
159 QString strPreferredExtension = UIMediumDefs::getPreferredExtensionForMedium(KDeviceType_Floppy);
160
161 QString strInitialPath = m_strDefaultFolder;
162 if (strInitialPath.isEmpty())
163 strInitialPath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
164
165 if (strInitialPath.isEmpty())
166 return strInitialPath;
167
168 QString strDiskname = !(m_strMachineName.isEmpty()) ? m_strMachineName : "NewFloppyDisk";
169 strDiskname = UICommon::findUniqueFileName(m_strDefaultFolder, strDiskname);
170
171 strInitialPath = QDir(strInitialPath).absoluteFilePath(strDiskname + "." + strPreferredExtension);
172 return strInitialPath;
173}
174
175void UIFDCreationDialog::accept()
176{
177 QVector<CMediumFormat> mediumFormats = UIMediumDefs::getFormatsForDeviceType(KDeviceType_Floppy);
178
179 if (m_pFilePathselector->path().isEmpty() || mediumFormats.isEmpty())
180 return;
181
182 CVirtualBox vbox = uiCommon().virtualBox();
183 QString strMediumLocation = m_pFilePathselector->path();
184
185 CMedium newMedium = vbox.CreateMedium(mediumFormats[0].GetName(), strMediumLocation,
186 KAccessMode_ReadWrite, KDeviceType_Floppy);
187 if (!vbox.isOk())
188 {
189 msgCenter().cannotCreateMediumStorage(vbox, strMediumLocation, this);
190 return;
191 }
192
193 QVector<KMediumVariant> variants(1, KMediumVariant_Fixed);
194 /* Decide if formatting the disk is required: */
195 if (m_pFormatCheckBox && m_pFormatCheckBox->checkState() == Qt::Checked)
196 variants.push_back(KMediumVariant_Formatted);
197 CProgress progress = newMedium.CreateBaseStorage(m_pSizeCombo->currentData().toLongLong(), variants);
198
199 if (!newMedium.isOk())
200 {
201 msgCenter().cannotCreateMediumStorage(newMedium, strMediumLocation, this);
202 return;
203 }
204 /* Show creation progress: */
205 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this);
206 if (progress.GetCanceled())
207 return;
208
209 if (!progress.isOk() || progress.GetResultCode() != 0)
210 {
211 msgCenter().cannotCreateHardDiskStorage(progress, strMediumLocation, this);
212 return;
213 }
214 /* Store the id of the newly create medium: */
215 m_uMediumID = newMedium.GetId();
216
217 /* Notify UICommon about the new medium: */
218 uiCommon().createMedium(UIMedium(newMedium, UIMediumDeviceType_Floppy, KMediumState_Created));
219
220 /* After a successful creation and initilization of the floppy disk we call base class accept
221 effectively closing this dialog: */
222 QDialog::accept();
223}
224
225QUuid UIFDCreationDialog::mediumID() const
226{
227 return m_uMediumID;
228}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use