diff --git a/src/jobs/CMakeLists.txt b/src/jobs/CMakeLists.txt index 2b77bf6..b82a801 100644 --- a/src/jobs/CMakeLists.txt +++ b/src/jobs/CMakeLists.txt @@ -1,22 +1,23 @@ set(JOBS_SRC jobs/resizefilesystemjob.cpp jobs/createfilesystemjob.cpp jobs/job.cpp jobs/checkfilesystemjob.cpp jobs/shredfilesystemjob.cpp jobs/createpartitionjob.cpp jobs/createpartitiontablejob.cpp + jobs/createvolumegroupjob.cpp jobs/setfilesystemlabeljob.cpp jobs/deletepartitionjob.cpp jobs/restorefilesystemjob.cpp jobs/setpartgeometryjob.cpp jobs/deletefilesystemjob.cpp jobs/backupfilesystemjob.cpp jobs/setpartflagsjob.cpp jobs/copyfilesystemjob.cpp jobs/movefilesystemjob.cpp ) set(JOBS_LIB_HDRS jobs/job.h ) diff --git a/src/jobs/createvolumegroupjob.cpp b/src/jobs/createvolumegroupjob.cpp new file mode 100644 index 0000000..7283d23 --- /dev/null +++ b/src/jobs/createvolumegroupjob.cpp @@ -0,0 +1,53 @@ +/************************************************************************* + * Copyright (C) 2016 by Chantara Tith * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + *************************************************************************/ + +#include "jobs/createvolumegroupjob.h" + +#include "core/lvmdevice.h" + +#include "util/report.h" + +#include + +/** Creates a new CreateVolumeGroupJob + @param vgname + @parem pvList +*/ +CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgname, const QList pvlist) : + Job(), + m_vgName(vgname), + m_pvList(pvlist) +{ +} + +bool CreateVolumeGroupJob::run(Report& parent) +{ + bool rval = false; + + Report* report = jobStarted(parent); + + rval = LvmDevice::createVG(*report, vgName(), pvList()); + + jobFinished(*report, rval); + + return rval; +} + +QString CreateVolumeGroupJob::description() const +{ + return xi18nc("@info/plain", "Create new Volume Group named %1", vgName()); +} diff --git a/src/jobs/createvolumegroupjob.h b/src/jobs/createvolumegroupjob.h new file mode 100644 index 0000000..a7a59d7 --- /dev/null +++ b/src/jobs/createvolumegroupjob.h @@ -0,0 +1,58 @@ +/************************************************************************* + * Copyright (C) 2016 by Chantara Tith * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + *************************************************************************/ + +#if !defined(CREATEVOLUMEGROUPJOB_H) + +#define CREATEVOLUMEGROUPJOB_H + +#include "jobs/job.h" + +class LvmDevice; +class Partition; +class Report; + +class QString; + +class CreateVolumeGroupJob : public Job +{ +public: + CreateVolumeGroupJob(const QString& vgname, const QList pvlist); + +public: + bool run(Report& parent) override; + QString description() const override; + +protected: + QString vgName() { + return m_vgName; + } + const QString vgName() const { + return m_vgName; + } + QList pvList() { + return m_pvList; + } + const QList pvList() const { + return m_pvList; + } + +private: + QString m_vgName; + QList m_pvList; +}; + +#endif diff --git a/src/ops/CMakeLists.txt b/src/ops/CMakeLists.txt index 5a7de51..9df401a 100644 --- a/src/ops/CMakeLists.txt +++ b/src/ops/CMakeLists.txt @@ -1,29 +1,31 @@ set(OPS_SRC ops/operation.cpp ops/deleteoperation.cpp ops/restoreoperation.cpp ops/resizeoperation.cpp ops/newoperation.cpp ops/createfilesystemoperation.cpp ops/createpartitiontableoperation.cpp + ops/createvolumegroupoperation.cpp ops/setfilesystemlabeloperation.cpp ops/setpartflagsoperation.cpp ops/checkoperation.cpp ops/backupoperation.cpp ops/copyoperation.cpp ) set(OPS_LIB_HDRS ops/backupoperation.h ops/checkoperation.h ops/copyoperation.h ops/createfilesystemoperation.h ops/createpartitiontableoperation.h + ops/createvolumegroupoperation.h ops/deleteoperation.h ops/newoperation.h ops/operation.h ops/resizeoperation.h ops/restoreoperation.h ops/setfilesystemlabeloperation.h ops/setpartflagsoperation.h ) diff --git a/src/ops/createvolumegroupoperation.cpp b/src/ops/createvolumegroupoperation.cpp new file mode 100644 index 0000000..a8d3279 --- /dev/null +++ b/src/ops/createvolumegroupoperation.cpp @@ -0,0 +1,66 @@ +/************************************************************************* + * Copyright (C) 2016 by Chantara Tith * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + *************************************************************************/ + +#include "ops/createvolumegroupoperation.h" + +#include "core/lvmdevice.h" + +#include "jobs/createvolumegroupjob.h" + +#include + +#include + +/** Creates a new CreateVolumeGroupOperation. + @param d the Device to create the new PartitionTable on + @param t the type for the new PartitionTable +*/ +CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgname, const QList pvlist) : + Operation(), + m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgname, pvlist)) +{ + addJob(createVolumeGroupJob()); +} + +bool CreateVolumeGroupOperation::canCreate() +{ + //TODO: return true if there is any free PV + return true; +} + +QString CreateVolumeGroupOperation::description() const +{ + return xi18nc("@info/plain", "Create a new LVM volume group."); +} + +bool CreateVolumeGroupOperation::targets(const Device&) const +{ + return false; +} + +bool CreateVolumeGroupOperation::targets(const Partition& part) const +{ + return true; +} + +void CreateVolumeGroupOperation::preview() +{ +} + +void CreateVolumeGroupOperation::undo() +{ +} diff --git a/src/ops/createvolumegroupoperation.h b/src/ops/createvolumegroupoperation.h new file mode 100644 index 0000000..0e08444 --- /dev/null +++ b/src/ops/createvolumegroupoperation.h @@ -0,0 +1,66 @@ +/************************************************************************* + * Copyright (C) 2016 by Chantara Tith * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + *************************************************************************/ + +#if !defined(CREATEVOLUMEGROUPOPERATION_H) + +#define CREATEVOLUMEGROUPOPERATION_H + +#include "util/libpartitionmanagerexport.h" + +#include "ops/operation.h" + +#include "core/lvmdevice.h" + +#include + +class CreateVolumeGroupJob; +class OperationStack; + +class LIBKPMCORE_EXPORT CreateVolumeGroupOperation : public Operation +{ + Q_DISABLE_COPY(CreateVolumeGroupOperation) + + friend class OperationStack; + +public: + CreateVolumeGroupOperation(const QString& vgname, const QList pvlist); + +public: + QString iconName() const override { + return QStringLiteral("document-new"); + } + + QString description() const override; + + virtual bool targets(const Device&) const override; + virtual bool targets(const Partition&) const override; + + virtual void preview() override; + virtual void undo() override; + + static bool canCreate(); + +protected: + CreateVolumeGroupJob* createVolumeGroupJob() { + return m_CreateVolumeGroupJob; + } + +private: + CreateVolumeGroupJob* m_CreateVolumeGroupJob; +}; + +#endif