~ubuntu-branches/ubuntu/karmic/partitionmanager/karmic

« back to all changes in this revision

Viewing changes to src/gui/newdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-23 17:57:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090123175736-2ltrhgg3m55dokbm
Tags: upstream-1.0.0~beta1a
ImportĀ upstreamĀ versionĀ 1.0.0~beta1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Volker Lanz <vl@fidra.de>                       *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
#include "gui/newdialog.h"
 
21
#include "gui/sizedialogwidget.h"
 
22
 
 
23
#include "core/partition.h"
 
24
#include "core/device.h"
 
25
 
 
26
#include "fs/filesystem.h"
 
27
#include "fs/filesystemfactory.h"
 
28
 
 
29
#include "util/capacity.h"
 
30
 
 
31
#include <kdebug.h>
 
32
 
 
33
#include <QtAlgorithms>
 
34
 
 
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
 
40
*/
 
41
NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r) :
 
42
        SizeDialogBase(parent, Capacity::MiB, device, unallocatedPartition, 0, 0),
 
43
        m_PartitionRoles(r)
 
44
{
 
45
        setMainWidget(&dialogWidget());
 
46
        setCaption(i18nc("@title:window", "Create a new partition"));
 
47
 
 
48
        setupDialog();
 
49
        setupConstraints();
 
50
        setupConnections();
 
51
 
 
52
        restoreDialogSize(KConfigGroup(KGlobal::config(), "newDialog"));
 
53
}
 
54
 
 
55
NewDialog::~NewDialog()
 
56
{
 
57
        KConfigGroup kcg(KGlobal::config(), "newDialog");
 
58
        saveDialogSize(kcg);
 
59
}
 
60
 
 
61
void NewDialog::setupDialog()
 
62
{
 
63
        QStringList fsNames;
 
64
        foreach (const FileSystem* fs, FileSystemFactory::map().values())
 
65
                if (fs->supportCreate() != FileSystem::SupportNone && fs->type() != FileSystem::Extended)
 
66
                        fsNames.append(fs->name());
 
67
 
 
68
        qSort(fsNames);
 
69
        dialogWidget().comboFileSystem().addItems(fsNames);
 
70
 
 
71
        dialogWidget().radioPrimary().setVisible(partitionRoles() & PartitionRole::Primary);
 
72
        dialogWidget().radioExtended().setVisible(partitionRoles() & PartitionRole::Extended);
 
73
        dialogWidget().radioLogical().setVisible(partitionRoles() & PartitionRole::Logical);
 
74
 
 
75
        if (partitionRoles() & PartitionRole::Primary)
 
76
                dialogWidget().radioPrimary().setChecked(true);
 
77
        else
 
78
                dialogWidget().radioLogical().setChecked(true);
 
79
 
 
80
        SizeDialogBase::setupDialog();
 
81
 
 
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.
 
84
        onRoleChanged(false);
 
85
        onFilesystemChanged(0);
 
86
}
 
87
 
 
88
void NewDialog::setupConnections()
 
89
{
 
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)));
 
94
 
 
95
        SizeDialogBase::setupConnections();
 
96
}
 
97
 
 
98
void NewDialog::accept()
 
99
{
 
100
        if (partition().roles().has(PartitionRole::Extended))
 
101
        {
 
102
                partition().deleteFileSystem();
 
103
                partition().setFileSystem(FileSystemFactory::create(FileSystem::Extended, partition().firstSector(), partition().lastSector()));
 
104
        }
 
105
 
 
106
        KDialog::accept();
 
107
}
 
108
 
 
109
void NewDialog::onRoleChanged(bool)
 
110
{
 
111
        PartitionRole::Roles r = PartitionRole::None;
 
112
 
 
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;
 
119
 
 
120
        dialogWidget().comboFileSystem().setEnabled(r != PartitionRole::Extended);
 
121
        partition().setRoles(PartitionRole(r));
 
122
        dialogWidget().partResizerWidget().update();
 
123
}
 
124
 
 
125
void NewDialog::onFilesystemChanged(int idx)
 
126
{
 
127
        const FileSystem::Type t = FileSystem::typeForName(dialogWidget().comboFileSystem().itemText(idx));
 
128
 
 
129
        partition().deleteFileSystem();
 
130
        partition().setFileSystem(FileSystemFactory::create(t, partition().firstSector(), partition().lastSector()));
 
131
 
 
132
        setupConstraints();
 
133
 
 
134
        dialogWidget().partResizerWidget().updateLength(partition().length());
 
135
}