1
/***************************************************************************
2
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18
***************************************************************************/
20
#include "gui/newdialog.h"
21
#include "gui/sizedialogwidget.h"
23
#include "core/partition.h"
24
#include "core/device.h"
26
#include "fs/filesystem.h"
27
#include "fs/filesystemfactory.h"
29
#include "util/capacity.h"
33
#include <QtAlgorithms>
35
/** Creates a NewDialog
36
@param parent the parent widget
37
@param device the Device on which a new Partition is to be created
38
@param unallocatedPartition the unallocated space on the Device to create a Partition in
39
@param r the permitted Roles for the new Partition
41
NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r) :
42
SizeDialogBase(parent, Capacity::MiB, device, unallocatedPartition, 0, 0),
45
setMainWidget(&dialogWidget());
46
setCaption(i18nc("@title:window", "Create a new partition"));
52
restoreDialogSize(KConfigGroup(KGlobal::config(), "newDialog"));
55
NewDialog::~NewDialog()
57
KConfigGroup kcg(KGlobal::config(), "newDialog");
61
void NewDialog::setupDialog()
64
foreach (const FileSystem* fs, FileSystemFactory::map().values())
65
if (fs->supportCreate() != FileSystem::SupportNone && fs->type() != FileSystem::Extended)
66
fsNames.append(fs->name());
69
dialogWidget().comboFileSystem().addItems(fsNames);
71
dialogWidget().radioPrimary().setVisible(partitionRoles() & PartitionRole::Primary);
72
dialogWidget().radioExtended().setVisible(partitionRoles() & PartitionRole::Extended);
73
dialogWidget().radioLogical().setVisible(partitionRoles() & PartitionRole::Logical);
75
if (partitionRoles() & PartitionRole::Primary)
76
dialogWidget().radioPrimary().setChecked(true);
78
dialogWidget().radioLogical().setChecked(true);
80
SizeDialogBase::setupDialog();
82
// don't move these above the call to parent's setupDialog, because only after that has
83
// run there is a valid partition set in the part resizer widget and they will need that.
85
onFilesystemChanged(0);
88
void NewDialog::setupConnections()
90
connect(&dialogWidget().radioPrimary(), SIGNAL(toggled(bool)), SLOT(onRoleChanged(bool)));
91
connect(&dialogWidget().radioExtended(), SIGNAL(toggled(bool)), SLOT(onRoleChanged(bool)));
92
connect(&dialogWidget().radioLogical(), SIGNAL(toggled(bool)), SLOT(onRoleChanged(bool)));
93
connect(&dialogWidget().comboFileSystem(), SIGNAL(currentIndexChanged(int)), SLOT(onFilesystemChanged(int)));
95
SizeDialogBase::setupConnections();
98
void NewDialog::accept()
100
if (partition().roles().has(PartitionRole::Extended))
102
partition().deleteFileSystem();
103
partition().setFileSystem(FileSystemFactory::create(FileSystem::Extended, partition().firstSector(), partition().lastSector()));
109
void NewDialog::onRoleChanged(bool)
111
PartitionRole::Roles r = PartitionRole::None;
113
if (dialogWidget().radioPrimary().isChecked())
114
r = PartitionRole::Primary;
115
else if (dialogWidget().radioExtended().isChecked())
116
r = PartitionRole::Extended;
117
else if (dialogWidget().radioLogical().isChecked())
118
r = PartitionRole::Logical;
120
dialogWidget().comboFileSystem().setEnabled(r != PartitionRole::Extended);
121
partition().setRoles(PartitionRole(r));
122
dialogWidget().partResizerWidget().update();
125
void NewDialog::onFilesystemChanged(int idx)
127
const FileSystem::Type t = FileSystem::typeForName(dialogWidget().comboFileSystem().itemText(idx));
129
partition().deleteFileSystem();
130
partition().setFileSystem(FileSystemFactory::create(t, partition().firstSector(), partition().lastSector()));
134
dialogWidget().partResizerWidget().updateLength(partition().length());