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

« back to all changes in this revision

Viewing changes to src/jobs/job.h

  • 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
#if !defined(JOB__H)
 
21
 
 
22
#define JOB__H
 
23
 
 
24
#include "fs/filesystem.h"
 
25
 
 
26
#include <QObject>
 
27
#include <qglobal.h>
 
28
 
 
29
#include <parted/parted.h>
 
30
 
 
31
class QString;
 
32
class QIcon;
 
33
 
 
34
class CopySource;
 
35
class CopyTarget;
 
36
class Report;
 
37
 
 
38
/** @brief Base class for all Jobs.
 
39
 
 
40
        Each Operation is made up of one or more Jobs. Usually, an Operation will run each Job it is
 
41
        made up of and only complete successfully if each Job could be run without error. Jobs are
 
42
        all-or-nothing and try to be as atomic as possible: A Job is either successfully run or not, there
 
43
        is no case where a Job finishes with a warning.
 
44
 
 
45
        @author vl@fidra.de
 
46
*/
 
47
class Job : public QObject
 
48
{
 
49
        Q_OBJECT
 
50
        Q_DISABLE_COPY(Job)
 
51
 
 
52
        public:
 
53
                /** Status of this Job */
 
54
                enum JobStatus
 
55
                {
 
56
                        Pending = 0,            /**< Pending, not yet run */
 
57
                        Success,                        /**< Successfully run */
 
58
                        Error                           /**< Running generated an error */
 
59
                };
 
60
 
 
61
        protected:
 
62
                Job();
 
63
 
 
64
        public:
 
65
                virtual ~Job();
 
66
 
 
67
        signals:
 
68
                void started();
 
69
                void progress(int);
 
70
                void finished();
 
71
                
 
72
        public:
 
73
                virtual qint32 numSteps() const { return 1; } /**< @return the number of steps the job takes to complete */
 
74
                virtual QString description() const = 0; /**< @return the Job's description */
 
75
                virtual bool run(Report& parent) = 0; /**< @param parent parent Report to add new child to for this Job @return true if successfully run */
 
76
 
 
77
                virtual QIcon statusIcon() const;
 
78
                virtual QString statusText() const;
 
79
 
 
80
                JobStatus status() const { return m_Status; } /**< @return the Job's current status */
 
81
                
 
82
                static FileSystem::Type detectFileSystem(PedDevice* pedDevice, PedPartition* pedPartition);
 
83
                
 
84
        protected:
 
85
                bool openPed(const QString& path, bool diskFailOk = false);
 
86
                void closePed();
 
87
                
 
88
                bool commit(quint32 timeout = 10);
 
89
                static bool commit(PedDisk* disk, quint32 timeout = 10);
 
90
 
 
91
                bool copyBlocks(Report& report, CopyTarget& target, CopySource& source);
 
92
                bool rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource& origSource);
 
93
 
 
94
                FileSystem::Type detectFileSystemBySector(Report& report, Device& device, qint64 sector);
 
95
 
 
96
                void emitProgress(int i);
 
97
 
 
98
                Report* jobStarted(Report& parent);
 
99
                void jobFinished(Report& report, bool b);
 
100
 
 
101
                void setStatus(JobStatus s) { m_Status = s; }
 
102
 
 
103
                PedDevice* pedDevice() { return m_PedDevice; }
 
104
                PedDisk* pedDisk() { return m_PedDisk; }
 
105
 
 
106
                static PedFileSystemType* getPedFileSystemType(FileSystem::Type t);
 
107
                static void pedTimerHandler(PedTimer* pedTimer, void* ctx);
 
108
 
 
109
        private:
 
110
                PedDevice* m_PedDevice;
 
111
                PedDisk* m_PedDisk;
 
112
                JobStatus m_Status;
 
113
};
 
114
 
 
115
#endif