Skip to content

Commit

Permalink
improve (#284)
Browse files Browse the repository at this point in the history
* Prefer prefix ++ operators

Prefix ++/-- operators should be preferred for non-primitive types.
Pre-increment/decrement can be more efficient than post-increment/decrement.
Post-increment/decrement usually involves keeping a copy of the previous
value around and adds a little extra code.

* Reformat misleading code indentation

Very misleading and error prone.
  • Loading branch information
luis-pereira authored Jun 23, 2023
1 parent a6a4548 commit 72879ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
12 changes: 6 additions & 6 deletions lxqt-admin-time/fbsdtimedatectl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ FBSDTimeDateCtl::~FBSDTimeDateCtl()
QString FBSDTimeDateCtl::timeZone() const
{
QFile tzFile(QSL("/var/db/zoneinfo"));
if (!tzFile.open(QFile::ReadOnly | QFile::Text)) return QSL("Unknown");
QTextStream in(&tzFile);
QString lastTZone = in.readLine();
return lastTZone;
if (!tzFile.open(QFile::ReadOnly | QFile::Text))
return QSL("Unknown");

QTextStream in(&tzFile);
QString lastTZone = in.readLine();
return lastTZone;
}

bool FBSDTimeDateCtl::setTimeZone(QString timeZone, QString& /*errorMessage*/)
Expand All @@ -76,8 +77,7 @@ bool FBSDTimeDateCtl::useNtp() const
process.waitForFinished(-1);
QString t = QString::fromLatin1(process.readAllStandardOutput());
QStringList o = t.split(QSL("\n"));
for (QStringList::iterator it = o.begin();
it != o.end(); ++it) {
for (QStringList::iterator it = o.begin(); it != o.end(); ++it) {
QString current = *it;
if(!current.startsWith(QSL("#")) && current.contains(QSL("ntpd_enable"),Qt::CaseInsensitive) && current.contains(QSL("yes"),Qt::CaseInsensitive)) {
return true;
Expand Down
29 changes: 16 additions & 13 deletions lxqt-admin-time/nosdtimedatectl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ NOSDTimeDateCtl::~NOSDTimeDateCtl()
QString NOSDTimeDateCtl::timeZone() const
{
QFile tzFile(QSL("/etc/timezone"));
if (!tzFile.open(QFile::ReadOnly | QFile::Text)) return QSL("Unknown");
QTextStream in(&tzFile);
QString lastTZone = in.readLine();
return lastTZone;
if (!tzFile.open(QFile::ReadOnly | QFile::Text))
return QSL("Unknown");

QTextStream in(&tzFile);
QString lastTZone = in.readLine();
return lastTZone;
}

bool NOSDTimeDateCtl::setTimeZone(QString timeZone, QString& /*errorMessage*/)
Expand Down Expand Up @@ -99,18 +101,19 @@ bool NOSDTimeDateCtl::localRtc() const
{
QFile tzFile(QSL("/etc/sysconfig/clock"));
if (!tzFile.open(QFile::ReadOnly | QFile::Text))
return false;
return false;

QTextStream in(&tzFile);
QString all = in.readAll();
QStringList sl = all.split(QSL("\n"));
for (QStringList::iterator it = sl.begin(); it != sl.end(); it++) {
QString current = *it;
if(current.startsWith(QSL("#")))
continue;
if(current.startsWith(QSL("UTC=1")) || current.startsWith(QSL("UTC=true")))
return false;
if(current.startsWith(QSL("UTC=0")) || current.startsWith(QSL("UTC=false")))
return true;
for (QStringList::iterator it = sl.begin(); it != sl.end(); ++it) {
QString current = *it;
if(current.startsWith(QSL("#")))
continue;
if(current.startsWith(QSL("UTC=1")) || current.startsWith(QSL("UTC=true")))
return false;
if(current.startsWith(QSL("UTC=0")) || current.startsWith(QSL("UTC=false")))
return true;
}
return false;
}
Expand Down

0 comments on commit 72879ae

Please sign in to comment.