Ticket #10995: 10995-v1.patch

File 10995-v1.patch, 4.3 KB (added by danielk, 11 years ago)

fix, needs testing

  • mythtv/programs/mythshutdown/commandlineparser.cpp

    diff --git a/mythtv/programs/mythshutdown/commandlineparser.cpp b/mythtv/programs/mythshutdown/commandlineparser.cpp
    index d1cb383..17d8c1f 100644
    a b void MythShutdownCommandLineParser::LoadArguments(void) 
    2222    CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
    2323         << add(QStringList( QStringList() << "-w" << "--setwakeup" ),
    2424                "setwakeup", "",
    25                 "Set the wakeup time (yyyy-MM-ddThh:mm:ss)", "")
     25                "Set the wakeup time (yyyy-MM-ddThh:mm:ss) default is in utc", "")
    2626         << add(QStringList( QStringList() << "-t" << "--setscheduledwakeup" ),
    2727                "setschedwakeup", false,
    2828                "Set wakeup time to the next scheduled recording", "")
    void MythShutdownCommandLineParser::LoadArguments(void) 
    6666                "        64 - In daily wakeup/shutdown period\n"
    6767                "       128 - Less than 15 minutes to next wakeup period\n"
    6868                "       255 - Setup is running") );
     69
     70    // The utc command line parameter exists solely to make scripts using
     71    // this executable self documenting.
     72
     73    CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
     74         << add("--utc",
     75                "utc", false,
     76                "Specify that the wakeup time is in utc", "")
     77         << add("--localtime",
     78                "localtime", false,
     79                "Specify that the wakeup time is in local time", "") );
    6980}
    7081
  • mythtv/programs/mythshutdown/main.cpp

    diff --git a/mythtv/programs/mythshutdown/main.cpp b/mythtv/programs/mythshutdown/main.cpp
    index cf369d9..ee8b633 100644
    a b static int checkOKShutdown(bool bWantRecStatus) 
    375375    return res;
    376376}
    377377
    378 static int setWakeupTime(QString sWakeupTime)
     378static void setWakeupTime(const QDateTime &wakeupTime)
    379379{
    380380    LOG(VB_GENERAL, LOG_INFO, "Mythshutdown: --setwakeup");
    381381
    382382    LOG(VB_GENERAL, LOG_NOTICE,
    383         QString("Mythshutdown: wakeup time given is: %1").arg(sWakeupTime));
    384 
    385     // check time given is valid
    386     QDateTime dtWakeupTime;
    387     dtWakeupTime = MythDate::fromString(sWakeupTime);
    388 
    389     if (!dtWakeupTime.isValid())
    390     {
    391         LOG(VB_GENERAL, LOG_ERR,
    392             QString("Mythshutdown: --setwakeup invalid date "
    393                                       "format (%1)\n\t\t\t"
    394                                       "must be yyyy-MM-ddThh:mm:ss")
    395                                       .arg(sWakeupTime));
    396         return 1;
    397     }
     383        QString("Mythshutdown: wakeup time given is: %1 (local time)")
     384        .arg(MythDate::toString(wakeupTime)));
    398385
    399386    setGlobalSetting("MythShutdownNextScheduled",
    400                      MythDate::toString(dtWakeupTime, MythDate::kDatabase));
    401 
    402     return 0;
     387                     MythDate::toString(wakeupTime, MythDate::kDatabase));
    403388}
    404389
    405390static int setScheduledWakeupTime()
    static int setScheduledWakeupTime() 
    432417        if (add)
    433418            restarttime = restarttime.addSecs((-1) * add);
    434419
    435         setWakeupTime(restarttime.toString(Qt::ISODate));
     420        setWakeupTime(restarttime);
    436421
    437422        return 0;
    438423    }
    int main(int argc, char **argv) 
    821806    else if (cmdline.toBool("status"))
    822807        res = getStatus((bool)(cmdline.toInt("status") == 1));
    823808    else if (cmdline.toBool("setwakeup"))
    824         res = setWakeupTime(cmdline.toString("setwakeup"));
     809    {
     810        // only one of --utc or --localtime can be passed per
     811        // CommandLineArg::AllowOneOf() in commandlineparser.cpp
     812        bool localtime = cmdline.toBool("localtime");
     813        QString tmp = cmdline.toString("setwakeup");
     814
     815        QDateTime wakeuptime = (localtime) ?
     816            QDateTime::fromString(tmp, Qt::ISODate).toUTC() :
     817            MythDate::fromString(tmp);
     818
     819        if (!wakeuptime.isValid())
     820        {
     821            cerr << qPrintable(
     822                QObject::tr("mythshutdown: --setwakeup invalid date "
     823                            "format (%1)\n\t\t\t"
     824                            "must be yyyy-MM-ddThh:mm:ss")
     825                .arg(tmp)) << endl;
     826            res = 1;
     827        }
     828        else
     829        {
     830            setWakeupTime(wakeuptime);
     831        }
     832    }
    825833    else if (cmdline.toBool("safeshutdown"))
    826834    {
    827835        res = checkOKShutdown(true);