mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 10:52:51 +00:00
kcontrol: return when error occurs in ClockHelper::tz()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0b66b72b98
commit
75d6a1da15
2 changed files with 50 additions and 52 deletions
|
@ -58,10 +58,8 @@ static QString findNtpUtility()
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClockHelper::ntp( const QStringList& ntpServers, bool ntpEnabled )
|
ClockHelper::CH_Error ClockHelper::ntp( const QStringList& ntpServers, bool ntpEnabled )
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
// write to the system config file
|
// write to the system config file
|
||||||
QFile config_file(KDE_CONFDIR "/kcmclockrc");
|
QFile config_file(KDE_CONFDIR "/kcmclockrc");
|
||||||
if(!config_file.exists()) {
|
if(!config_file.exists()) {
|
||||||
|
@ -86,16 +84,16 @@ int ClockHelper::ntp( const QStringList& ntpServers, bool ntpEnabled )
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !QProcess::execute(ntpUtility, QStringList() << timeServer) ) {
|
if ( !QProcess::execute(ntpUtility, QStringList() << timeServer) ) {
|
||||||
ret |= NTPError;
|
return NTPError;
|
||||||
}
|
}
|
||||||
} else if( ntpEnabled ) {
|
} else if( ntpEnabled ) {
|
||||||
ret |= NTPError;
|
return NTPError;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClockHelper::date( const QString& newdate, const QString& olddate )
|
ClockHelper::CH_Error ClockHelper::date( const QString& newdate, const QString& olddate )
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
|
@ -109,18 +107,17 @@ int ClockHelper::date( const QString& newdate, const QString& olddate )
|
||||||
if (!hwclock.isEmpty()) {
|
if (!hwclock.isEmpty()) {
|
||||||
QProcess::execute(hwclock, QStringList() << "--systohc");
|
QProcess::execute(hwclock, QStringList() << "--systohc");
|
||||||
}
|
}
|
||||||
return 0;
|
return NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClockHelper::tz( const QString& selectedzone )
|
ClockHelper::CH_Error ClockHelper::tz( const QString& selectedzone )
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
//only allow letters, numbers hyphen underscore plus and forward slash
|
//only allow letters, numbers hyphen underscore plus and forward slash
|
||||||
//allowed pattern taken from time-util.c in systemd
|
//allowed pattern taken from time-util.c in systemd
|
||||||
if (!QRegExp("[a-zA-Z0-9-_+/]*").exactMatch(selectedzone)) {
|
if (!QRegExp("[a-zA-Z0-9-_+/]*").exactMatch(selectedzone)) {
|
||||||
return ret;
|
return TimezoneError;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from ktimezoned
|
// from ktimezoned
|
||||||
QString ZONE_INFO_DIR;
|
QString ZONE_INFO_DIR;
|
||||||
|
|
||||||
|
@ -140,10 +137,11 @@ int ClockHelper::tz( const QString& selectedzone )
|
||||||
|
|
||||||
QFile f("/etc/localtime");
|
QFile f("/etc/localtime");
|
||||||
if (f.exists() && !f.remove()) {
|
if (f.exists() && !f.remove()) {
|
||||||
ret |= TimezoneError;
|
return TimezoneError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!QFile::link(tz, "/etc/localtime")) {
|
if (!QFile::link(tz, "/etc/localtime")) {
|
||||||
ret |= TimezoneError;
|
return TimezoneError;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString val = ':' + tz;
|
QString val = ':' + tz;
|
||||||
|
@ -151,16 +149,16 @@ int ClockHelper::tz( const QString& selectedzone )
|
||||||
setenv("TZ", val.toAscii(), 1);
|
setenv("TZ", val.toAscii(), 1);
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
return ret;
|
return NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClockHelper::tzreset()
|
ClockHelper::CH_Error ClockHelper::tzreset()
|
||||||
{
|
{
|
||||||
unlink( "/etc/localtime" );
|
unlink( "/etc/localtime" );
|
||||||
|
|
||||||
setenv("TZ", "", 1);
|
setenv("TZ", "", 1);
|
||||||
tzset();
|
tzset();
|
||||||
return 0;
|
return NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionReply ClockHelper::save(const QVariantMap &args)
|
ActionReply ClockHelper::save(const QVariantMap &args)
|
||||||
|
@ -172,7 +170,7 @@ ActionReply ClockHelper::save(const QVariantMap &args)
|
||||||
|
|
||||||
KComponentData data( "kcmdatetimehelper" );
|
KComponentData data( "kcmdatetimehelper" );
|
||||||
|
|
||||||
int ret = 0; // error code
|
int ret = NoError; // error code
|
||||||
// The order here is important
|
// The order here is important
|
||||||
if( _ntp )
|
if( _ntp )
|
||||||
ret |= ntp( args.value("ntpServers").toStringList(), args.value("ntpEnabled").toBool());
|
ret |= ntp( args.value("ntpServers").toStringList(), args.value("ntpEnabled").toBool());
|
||||||
|
@ -183,7 +181,7 @@ ActionReply ClockHelper::save(const QVariantMap &args)
|
||||||
if( _tzreset )
|
if( _tzreset )
|
||||||
ret |= tzreset();
|
ret |= tzreset();
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == NoError) {
|
||||||
return ActionReply::SuccessReply;
|
return ActionReply::SuccessReply;
|
||||||
} else {
|
} else {
|
||||||
ActionReply reply(ActionReply::HelperError);
|
ActionReply reply(ActionReply::HelperError);
|
||||||
|
|
|
@ -30,22 +30,22 @@ class ClockHelper : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum
|
enum CH_Error {
|
||||||
{
|
NoError = 0,
|
||||||
CallError = 1 << 0,
|
CallError = 1,
|
||||||
TimezoneError = 1 << 1,
|
TimezoneError = 2,
|
||||||
NTPError = 1 << 2,
|
NTPError = 3,
|
||||||
DateError = 1 << 3
|
DateError = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ActionReply save(const QVariantMap &map);
|
ActionReply save(const QVariantMap &map);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ntp(const QStringList& ntpServers, bool ntpEnabled);
|
CH_Error ntp(const QStringList& ntpServers, bool ntpEnabled);
|
||||||
int date(const QString& newdate, const QString& olddate);
|
CH_Error date(const QString& newdate, const QString& olddate);
|
||||||
int tz(const QString& selectedzone);
|
CH_Error tz(const QString& selectedzone);
|
||||||
int tzreset();
|
CH_Error tzreset();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLOCK_HELPER_H
|
#endif // CLOCK_HELPER_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue