From 34c5ac3182eefbb3c6ec1fde0494738ca393e650 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 1 Aug 2014 16:28:29 +0200 Subject: [PATCH] Add SetTimezoneJob to locale viewmodule. --- src/modules/locale/SetTimezoneJob.cpp | 68 +++++++++++++++++++++++++++ src/modules/locale/SetTimezoneJob.h | 40 ++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/modules/locale/SetTimezoneJob.cpp create mode 100644 src/modules/locale/SetTimezoneJob.h diff --git a/src/modules/locale/SetTimezoneJob.cpp b/src/modules/locale/SetTimezoneJob.cpp new file mode 100644 index 000000000..d47b32532 --- /dev/null +++ b/src/modules/locale/SetTimezoneJob.cpp @@ -0,0 +1,68 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include + +#include "JobQueue.h" +#include "GlobalStorage.h" +#include "utils/Logger.h" +#include "utils/CalamaresUtilsSystem.h" + +#include + + +SetTimezoneJob::SetTimezoneJob( const QString& region, const QString& zone ) + : Calamares::Job() + , m_region( region ) + , m_zone( zone ) +{ +} + + +QString +SetTimezoneJob::prettyName() const +{ + return tr( "Set timezone to %1/%2" ).arg( m_region ).arg( m_zone ); +} + + +Calamares::JobResult +SetTimezoneJob::exec() +{ + QString zoneinfoPath( "/usr/share/zoneinfo" ); + zoneinfoPath.append( QDir::separator() + m_region ); + zoneinfoPath.append( QDir::separator() + m_zone ); + + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + QDir zoneDir( gs->value( "rootMountPoint" ).toString() + zoneinfoPath ); + if ( !zoneDir.exists() || !zoneDir.isReadable() ) + return Calamares::JobResult::error( tr( "Cannot access timezone directory." ), + tr( "Bad path: %1" ).arg( zoneDir.absolutePath() ) ); + + int ec = CalamaresUtils::chrootCall( { "ln", + "-s", + zoneinfoPath, + "/etc/localtime" } ); + if ( ec ) + return Calamares::JobResult::error( tr( "Cannot set timezone." ), + tr( "Link creation failed, target: %1; link name: %2" ) + .arg( zoneinfoPath ) + .arg( "/etc/localtime" ) ); + + return Calamares::JobResult::ok(); +} diff --git a/src/modules/locale/SetTimezoneJob.h b/src/modules/locale/SetTimezoneJob.h new file mode 100644 index 000000000..e443c7e1b --- /dev/null +++ b/src/modules/locale/SetTimezoneJob.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef SETTIMEZONEJOB_H +#define SETTIMEZONEJOB_H + +#include + + +class SetTimezoneJob : public Calamares::Job +{ + Q_OBJECT +public: + SetTimezoneJob( const QString& region, + const QString& zone ); + + QString prettyName() const override; + Calamares::JobResult exec() override; + +private: + QString m_region; + QString m_zone; +}; + +#endif /* SETTIMEZONEJOB_H */