void TimeShiftDialog::checkDateTime(SyntaxLineEdit &time_le) { int Y, M, D, h, m; long double s; const gchar *err_str; syntax_err_.clear(); if (time_le.text().isEmpty()) { time_le.setSyntaxState(SyntaxLineEdit::Empty); } else if ((err_str = time_string_parse(time_le.text().toUtf8().constData(), &Y, &M, &D, NULL, &h, &m, &s)) != NULL) { syntax_err_ = err_str; time_le.setSyntaxState(SyntaxLineEdit::Invalid); } else { time_le.setSyntaxState(SyntaxLineEdit::Valid); } }
void TimeShiftDialog::on_shiftAllTimeLineEdit_textChanged(const QString &sa_text) { int h, m; long double s; gboolean neg; const gchar *err_str; syntax_err_.clear(); if (sa_text.isEmpty()) { ts_ui_->shiftAllTimeLineEdit->setSyntaxState(SyntaxLineEdit::Empty); } else if ((err_str = time_string_parse(sa_text.toUtf8().constData(), NULL, NULL, NULL, &neg, &h, &m, &s)) != NULL) { syntax_err_ = err_str; ts_ui_->shiftAllTimeLineEdit->setSyntaxState(SyntaxLineEdit::Invalid); } else { ts_ui_->shiftAllTimeLineEdit->setSyntaxState(SyntaxLineEdit::Valid); } ts_ui_->shiftAllButton->setChecked(true); enableWidgets(); }
const gchar * time_shift_all(capture_file *cf, const gchar *offset_text) { nstime_t offset; long double offset_float = 0; guint32 i; frame_data *fd; gboolean neg; int h, m; long double f; const gchar *err_str; if (!cf || !offset_text) return "Nothing to work with."; if ((err_str = time_string_parse(offset_text, NULL, NULL, NULL, &neg, &h, &m, &f)) != NULL) return err_str; offset_float = h * 3600 + m * 60 + f; if (offset_float == 0) return "Offset is zero."; nstime_set_zero(&offset); offset.secs = (time_t)floorl(offset_float); offset_float -= offset.secs; offset.nsecs = (int)(offset_float * 1000000000); if ((fd = frame_data_sequence_find(cf->frames, 1)) == NULL) return "No frames found."; /* Shouldn't happen */ modify_time_init(fd); for (i = 1; i <= cf->count; i++) { if ((fd = frame_data_sequence_find(cf->frames, i)) == NULL) continue; /* Shouldn't happen */ modify_time_perform(fd, neg ? SHIFT_NEG : SHIFT_POS, &offset, SHIFT_KEEPOFFSET); } packet_list_queue_draw(); return NULL; }
static const gchar * time_string_to_nstime(const gchar *time_text, nstime_t *packettime, nstime_t *nstime) { int h, m, Y, M, D; long double f; struct tm tm, *tmptm; time_t tt; const gchar *err_str; if ((err_str = time_string_parse(time_text, &Y, &M, &D, NULL, &h, &m, &f)) != NULL) return err_str; /* Convert the time entered in an epoch offset */ tmptm = localtime(&(packettime->secs)); if (tmptm) { tm = *tmptm; } else { memset (&tm, 0, sizeof (tm)); } if (Y != 0) { tm.tm_year = Y - 1900; tm.tm_mon = M - 1; tm.tm_mday = D; } tm.tm_hour = h; tm.tm_min = m; tm.tm_sec = (int)floorl(f); tm.tm_isdst = -1; tt = mktime(&tm); if (tt == -1) { return "Mktime went wrong. Is the time valid?"; } nstime->secs = tt; f -= tm.tm_sec; nstime->nsecs = (int)(f * 1000000000); return NULL; }