Permalink
Browse files

Fix #10995. Default to local time for mythshutdown --setwakeup.

  • Loading branch information...
daniel-kristjansson committed Nov 21, 2012
1 parent 35ff26d commit ef7810c473e36d1022b62b1b411abf8efd49aa68
Showing with 42 additions and 22 deletions.
  1. +13 −1 mythtv/programs/mythshutdown/commandlineparser.cpp
  2. +29 −21 mythtv/programs/mythshutdown/main.cpp
@@ -22,7 +22,8 @@ void MythShutdownCommandLineParser::LoadArguments(void)
CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
<< add(QStringList( QStringList() << "-w" << "--setwakeup" ),
"setwakeup", "",
"Set the wakeup time (yyyy-MM-ddThh:mm:ss)", "")
"Set the wakeup time (yyyy-MM-ddThh:mm:ss) "
"default is in local time", "")
<< add(QStringList( QStringList() << "-t" << "--setscheduledwakeup" ),
"setschedwakeup", false,
"Set wakeup time to the next scheduled recording", "")
@@ -66,5 +67,16 @@ void MythShutdownCommandLineParser::LoadArguments(void)
" 64 - In daily wakeup/shutdown period\n"
" 128 - Less than 15 minutes to next wakeup period\n"
" 255 - Setup is running") );
// The localtime command line parameter exists solely to make scripts
// using this executable self documenting.
CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
<< add("--utc",
"utc", false,
"Specify that the wakeup time is in utc", "")
<< add("--localtime",
"localtime", false,
"Specify that the wakeup time is in local time", "") );
}
@@ -377,31 +377,16 @@ static int checkOKShutdown(bool bWantRecStatus)
return res;
}
static int setWakeupTime(QString sWakeupTime)
static void setWakeupTime(const QDateTime &wakeupTime)
{
LOG(VB_GENERAL, LOG_INFO, "Mythshutdown: --setwakeup");
LOG(VB_GENERAL, LOG_NOTICE,
QString("Mythshutdown: wakeup time given is: %1").arg(sWakeupTime));
// check time given is valid
QDateTime dtWakeupTime;
dtWakeupTime = MythDate::fromString(sWakeupTime);
if (!dtWakeupTime.isValid())
{
LOG(VB_GENERAL, LOG_ERR,
QString("Mythshutdown: --setwakeup invalid date "
"format (%1)\n\t\t\t"
"must be yyyy-MM-ddThh:mm:ss")
.arg(sWakeupTime));
return 1;
}
QString("Mythshutdown: wakeup time given is: %1 (local time)")
.arg(MythDate::toString(wakeupTime)));
setGlobalSetting("MythShutdownNextScheduled",
MythDate::toString(dtWakeupTime, MythDate::kDatabase));
return 0;
MythDate::toString(wakeupTime, MythDate::kDatabase));
}
static int setScheduledWakeupTime()
@@ -434,7 +419,7 @@ static int setScheduledWakeupTime()
if (add)
restarttime = restarttime.addSecs((-1) * add);
setWakeupTime(restarttime.toString(Qt::ISODate));
setWakeupTime(restarttime);
return 0;
}
@@ -823,7 +808,30 @@ int main(int argc, char **argv)
else if (cmdline.toBool("status"))
res = getStatus((bool)(cmdline.toInt("status") == 1));
else if (cmdline.toBool("setwakeup"))
res = setWakeupTime(cmdline.toString("setwakeup"));
{
// only one of --utc or --localtime can be passed per
// CommandLineArg::AllowOneOf() in commandlineparser.cpp
bool utc = cmdline.toBool("utc");
QString tmp = cmdline.toString("setwakeup");
QDateTime wakeuptime = (utc) ?
MythDate::fromString(tmp) :
QDateTime::fromString(tmp, Qt::ISODate).toUTC();
if (!wakeuptime.isValid())
{
cerr << qPrintable(
QObject::tr("mythshutdown: --setwakeup invalid date "
"format (%1)\n\t\t\t"
"must be yyyy-MM-ddThh:mm:ss")
.arg(tmp)) << endl;
res = 1;
}
else
{
setWakeupTime(wakeuptime);
}
}
else if (cmdline.toBool("safeshutdown"))
{
res = checkOKShutdown(true);

0 comments on commit ef7810c

Please sign in to comment.