-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to handle timezones with timedatectl provided by systemd instead …
…of liboobs.
- Loading branch information
Showing
5 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "timedatectl.h" | ||
#include <QProcess> | ||
#include <QDebug> | ||
|
||
TimeDateCtl::TimeDateCtl() | ||
{ | ||
QProcess timedatectl; | ||
timedatectl.start(QStringLiteral("timedatectl")); | ||
timedatectl.waitForFinished(); | ||
while(!timedatectl.atEnd()) { | ||
QString line = timedatectl.readLine().trimmed(); | ||
int findTZ = line.indexOf(QLatin1String("Time zone:")); | ||
if(findTZ != -1) { | ||
findTZ += 10; | ||
while(line[findTZ] == ' ') | ||
++findTZ; | ||
int space = line.indexOf(' ', findTZ); | ||
mTimeZone = line.mid(findTZ, space - findTZ); | ||
break; | ||
} | ||
} | ||
timedatectl.close(); | ||
} | ||
|
||
bool TimeDateCtl::commit() | ||
{ | ||
QProcess timedatectl; | ||
QStringList args; | ||
if(mTimeZoneChanged) { | ||
args << "set-timezone" << mTimeZone; | ||
} | ||
timedatectl.start(QStringLiteral("timedatectl"), args); | ||
timedatectl.waitForFinished(); | ||
return timedatectl.exitCode() == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef TIMEDATECTL_H | ||
#define TIMEDATECTL_H | ||
|
||
#include <QString> | ||
#include <QDateTime> | ||
|
||
class TimeDateCtl | ||
{ | ||
public: | ||
explicit TimeDateCtl(); | ||
|
||
QString timeZone() const { | ||
return mTimeZone; | ||
} | ||
|
||
void setTimeZone(QString timeZone) { | ||
mTimeZone = timeZone; | ||
mTimeZoneChanged = true; | ||
} | ||
|
||
void setDateTime(QDateTime dateTime) { | ||
mDateTime = dateTime; | ||
mTimeChanged = true; | ||
} | ||
|
||
// really commit the changes to the system | ||
bool commit(); | ||
|
||
private: | ||
bool mTimeZoneChanged; | ||
QString mTimeZone; | ||
bool mTimeChanged; | ||
QDateTime mDateTime; | ||
}; | ||
|
||
#endif // TIMEDATECTL_H |