~ubuntu-branches/ubuntu/oneiric/partitionmanager/oneiric

« back to all changes in this revision

Viewing changes to src/ops/newoperation.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 "ops/newoperation.h"
 
21
 
 
22
#include "core/partition.h"
 
23
#include "core/device.h"
 
24
#include "core/partitionnode.h"
 
25
 
 
26
#include "jobs/createpartitionjob.h"
 
27
#include "jobs/createfilesystemjob.h"
 
28
#include "jobs/setfilesystemlabeljob.h"
 
29
#include "jobs/checkfilesystemjob.h"
 
30
 
 
31
#include "fs/filesystem.h"
 
32
#include "fs/filesystemfactory.h"
 
33
 
 
34
#include "util/capacity.h"
 
35
 
 
36
#include <QString>
 
37
 
 
38
#include <kdebug.h>
 
39
#include <klocale.h>
 
40
 
 
41
/** Creates a new NewOperation.
 
42
        @param d the Device to create a new Partition on
 
43
        @param p pointer to the new Partition to create. May not be NULL.
 
44
*/
 
45
NewOperation::NewOperation(Device& d, Partition* p) :
 
46
        Operation(),
 
47
        m_TargetDevice(d),
 
48
        m_NewPartition(p),
 
49
        m_CreatePartitionJob(new CreatePartitionJob(targetDevice(), newPartition())),
 
50
        m_CreateFileSystemJob(NULL),
 
51
        m_SetFileSystemLabelJob(NULL),
 
52
        m_CheckFileSystemJob(NULL)
 
53
{
 
54
        addJob(createPartitionJob());
 
55
 
 
56
        const FileSystem& fs = newPartition().fileSystem();
 
57
 
 
58
        if (fs.type() != FileSystem::Extended)
 
59
        {
 
60
                // It would seem tempting to skip the CreateFileSystemJob or the
 
61
                // SetFileSystemLabelJob if either has nothing to do (unformatted FS or
 
62
                // empty label). However, the user might later on decide to change FS or
 
63
                // label. The operation stack will merge these operations with this one here
 
64
                // and if the jobs don't exist things will break.
 
65
                
 
66
                m_CreateFileSystemJob = new CreateFileSystemJob(newPartition());
 
67
                addJob(createFileSystemJob());
 
68
 
 
69
                m_SetFileSystemLabelJob = new SetFileSystemLabelJob(newPartition(), fs.label());
 
70
                addJob(setLabelJob());
 
71
 
 
72
                m_CheckFileSystemJob = new CheckFileSystemJob(newPartition());
 
73
                addJob(checkJob());
 
74
        }
 
75
}
 
76
 
 
77
NewOperation::~NewOperation()
 
78
{
 
79
        if (status() == StatusPending)
 
80
                delete m_NewPartition;
 
81
}
 
82
 
 
83
void NewOperation::preview()
 
84
{
 
85
        insertPreviewPartition(targetDevice(), newPartition());
 
86
}
 
87
 
 
88
void NewOperation::undo()
 
89
{
 
90
        removePreviewPartition(targetDevice(), newPartition());
 
91
}
 
92
 
 
93
QString NewOperation::description() const
 
94
{
 
95
        return QString(i18nc("@info/plain", "Create a new partition (%1, %2) on <filename>%3</filename>", Capacity(newPartition()).toString(), newPartition().fileSystem().name(), targetDevice().deviceNode()));
 
96
}
 
97
 
 
98
/** Can a Partition be created somewhere?
 
99
        @param p the Partition where a new Partition is to be created, may be NULL
 
100
        @return true if a new Partition can be created in @p p
 
101
 */
 
102
bool NewOperation::canCreateNew(const Partition* p)
 
103
{
 
104
        return p != NULL && p->roles().has(PartitionRole::Unallocated);
 
105
}
 
106
 
 
107
Partition* NewOperation::createNew(const Partition& cloneFrom)
 
108
{
 
109
        Partition* p = new Partition(cloneFrom);
 
110
 
 
111
        p->deleteFileSystem();
 
112
        p->setFileSystem(FileSystemFactory::create(FileSystem::defaultFileSystem(), p->firstSector(), p->lastSector()));
 
113
        p->setState(Partition::StateNew);
 
114
        p->setNumber(-1);
 
115
 
 
116
        return p;
 
117
}