Example #1
0
void PosService::on_btSetTime_clicked()
{
    int button_width  = data->getVariables()->value(_S("standart_button_width")).toInt();
    int button_height = data->getVariables()->value(_S("standart_button_height")).toInt();
    int button_margin = data->getVariables()->value(_S("standart_margins")).toInt();

    QDialog dlg;

    QVBoxLayout* mainLayout = new QVBoxLayout();
    dlg.setLayout(mainLayout);

    dlg.setWindowTitle(_T("Установка времени"));

    QDateTimeEdit* edit = new QDateTimeEdit(QDateTime::currentDateTime());
    edit->setMaximumHeight(button_height);
    edit->setMinimumHeight(button_height);
    mainLayout->addWidget(edit);

    QHBoxLayout *btLayout = new QHBoxLayout();
    mainLayout->addLayout(btLayout);

    QPushButton* bt;

    bt = new QPushButton(_T("OK"), this);
    bt->setMaximumSize(button_width * 2 + button_margin, button_height);
    bt->setMinimumSize(button_width * 2 + button_margin, button_height);
    btLayout->addWidget(bt);
    connect(bt, SIGNAL(clicked()), &dlg, SLOT(accept()));

    bt = new QPushButton(_T("Отмена"), this);
    bt->setMaximumSize(button_width * 2 + button_margin, button_height);
    bt->setMinimumSize(button_width * 2 + button_margin, button_height);
    btLayout->addWidget(bt);
    connect(bt, SIGNAL(clicked()), &dlg, SLOT(reject()));

    int result = dlg.exec();
    if(result==QDialog::Accepted)
    {
        QString dt = edit->dateTime().toString(data->getSettings()->value("posservice/command_setdatetime_format").toString());
        QString command = data->getSettings()->value("posservice/command_setdatetime").toString().arg(dt);
        if (loglevel > 0)
            qDebug() << _T("%1 Устанавливаем новое время: %2 (было: %3)")
                        .arg(posForLog)
                        .arg(edit->dateTime().toString(Qt::ISODate))
                        .arg(QDateTime::currentDateTime().toString(Qt::ISODate));

        int result = QProcess::execute(command);
        if(result<0)
        {
            qDebug() << _T("%1 Ошибка установки нового времени. Код ошибки: %2")
                        .arg(posForLog)
                        .arg(result);

            QMessageBox message;
            message.setText(_T("Ошибка установки нового времени.\nКод ошибки: %1").arg(result));
            message.exec();
        }
    }
}