static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime) { switch (jobHold) { case QCUPSSupport::Indefinite: return QStringLiteral("indefinite"); case QCUPSSupport::DayTime: return QStringLiteral("day-time"); case QCUPSSupport::Night: return QStringLiteral("night"); case QCUPSSupport::SecondShift: return QStringLiteral("second-shift"); case QCUPSSupport::ThirdShift: return QStringLiteral("third-shift"); case QCUPSSupport::Weekend: return QStringLiteral("weekend"); case QCUPSSupport::SpecificTime: if (!holdUntilTime.isNull()) { // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent QDateTime localDateTime = QDateTime::currentDateTime(); // Check if time is for tomorrow in case of DST change overnight if (holdUntilTime < localDateTime.time()) localDateTime = localDateTime.addDays(1); localDateTime.setTime(holdUntilTime); return localDateTime.toUTC().time().toString(QStringLiteral("HH:mm")); } // else fall through: case QCUPSSupport::NoHold: return QString(); } Q_UNREACHABLE(); return QString(); }
static DATE QDateTimeToDATE(const QDateTime &dt) { if (!dt.isValid() || dt.isNull()) return 949998; SYSTEMTIME stime; memset(&stime, 0, sizeof(stime)); QDate date = dt.date(); QTime time = dt.time(); if (date.isValid() && !date.isNull()) { stime.wDay = date.day(); stime.wMonth = date.month(); stime.wYear = date.year(); } if (time.isValid() && !time.isNull()) { stime.wMilliseconds = time.msec(); stime.wSecond = time.second(); stime.wMinute = time.minute(); stime.wHour = time.hour(); } double vtime; SystemTimeToVariantTime(&stime, &vtime); return vtime; }
void BenchWidget::paintEvent(QPaintEvent *) { if (m_done) return; QPainter p(this); m_benchmark->begin(&p, 100); PaintingRectAdjuster adjuster; adjuster.setNewBenchmark(m_benchmark); adjuster.reset(rect()); for (int i = 0; i < 100; ++i) m_benchmark->draw(&p, adjuster.newPaintingRect(), i); m_benchmark->end(&p); ++m_iteration; uint currentElapsed = timer.isNull() ? 0 : timer.elapsed(); timer.restart(); m_total += currentElapsed; // warm up for at most 5 iterations or half a second if (m_iteration >= 5 || m_total >= 500) { iterationTimes << currentElapsed; if (iterationTimes.size() >= 5) { qreal mean = 0; qreal stddev = 0; uint min = INT_MAX; for (int i = 0; i < iterationTimes.size(); ++i) { mean += iterationTimes.at(i); min = qMin(min, iterationTimes.at(i)); } mean /= qreal(iterationTimes.size()); for (int i = 0; i < iterationTimes.size(); ++i) { qreal delta = iterationTimes.at(i) - mean; stddev += delta * delta; } stddev = qSqrt(stddev / iterationTimes.size()); stddev = 100 * stddev / mean; // do 50 iterations, break earlier if we spend more than 5 seconds or have a low std deviation after 2 seconds if (iterationTimes.size() >= 50 || m_total >= 5000 || (m_total >= 2000 && stddev < 4)) { m_result = min; m_done = true; return; } } } }
void AgendaWidgetEventItem::setEventTime(const QTime & start, const QTime & end) { QString time; if (start.isNull()) { m_hasStartTime = false; } else { m_hasStartTime = true; m_startTime = start; } if (end.isNull()) { m_hasEndTime = false; } else { m_hasEndTime = true; m_endTime = end; } if (m_hasStartTime && m_hasEndTime) { time += KGlobal::locale()->formatTime(m_startTime); time += " - "; time += KGlobal::locale()->formatTime(m_endTime); } else if (m_hasStartTime && !m_hasEndTime) { time += i18n("From"); time += " "; time += KGlobal::locale()->formatTime(m_startTime); } else if (!m_hasStartTime && m_hasEndTime) { time += i18n("Till"); time += " "; time += KGlobal::locale()->formatTime(m_endTime); } m_timeText = new Plasma::IconWidget(this); m_timeText->setOrientation(Qt::Horizontal); m_timeText->setMinimumWidth(50); m_timeText->setMaximumHeight(15); m_timeText->setText(time); m_textLayout->addItem(m_timeText); m_line->setMaximumHeight(30); connect(m_timeText, SIGNAL(clicked()), SLOT(edit())); }
void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) { QStringList cupsOptions = cupsOptionsList(printer); switch (jobHold) { case NoHold: //default break; case Indefinite: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("indefinite")); break; case DayTime: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("day-time")); break; case Night: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("night")); break; case SecondShift: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("second-shift")); break; case ThirdShift: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("third-shift")); break; case Weekend: setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), QStringLiteral("weekend")); break; case SpecificTime: if (holdUntilTime.isNull()) { setJobHold(printer, NoHold); return; } // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent QDateTime localDateTime = QDateTime::currentDateTime(); // Check if time is for tomorrow in case of DST change overnight if (holdUntilTime < localDateTime.time()) localDateTime = localDateTime.addDays(1); localDateTime.setTime(holdUntilTime); setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), localDateTime.toUTC().time().toString(QStringLiteral("HH:mm"))); break; } setCupsOptions(printer, cupsOptions); }
void MainTray::updateInterval(const QTime& val) { if (val.isNull() || val==QTime(0,0)) return; const QTime maxTime = QTime(0, 0).addMSecs(std::numeric_limits<int>::max()-1); if (val > maxTime) m_updateInterval = maxTime; else m_updateInterval = val; m_updateTimer.start(getUpdateMS()); }
static PyObject *meth_QTime_isNull(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QTime *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTime, &sipCpp)) { bool sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->isNull(); Py_END_ALLOW_THREADS return PyBool_FromLong(sipRes); } }
/*! Sets internal time to \e time. */ void TimeComboBox::setTime(const QTime &time) { if (d->time == time) return; const int index = d->combo->findData(time); if (index == -1) { // custom time, not found in combo items // QTime() is not the same as QTime(0,0)!! d->time = time.isNull()? QTime(0, 0) : time; d->combo->setEditText(time.toString(QLocale::system().timeFormat(QLocale::ShortFormat))); qDebug() << "setEditText" << time; } else { // given time is one of the combo items d->combo->setCurrentIndex(index); qDebug() << "setCurrentIndex" << index << d->combo->itemData(index); } Q_EMIT timeChanged(d->time); Q_EMIT dateTimeChanged(QDateTime(QDate(), d->time)); }
QList<int> Database::advanceSearch(const QString &keyword, const QDate &startDate, const QDate &endDate, const QTime &startTime, const QTime &endTime, int group, int domain, const QRectF & geo, const QString & weather ) { BEGIN_FNC_DEBUG QString query_str = "SELECT id,ctime,cdate FROM Papers WHERE "; QHash<QString,QVariant> boundValues; bool has_previous = false; if( !keyword.isEmpty() ) { query_str += "(title LIKE :fkwrd OR text LIKE :skwrd)"; has_previous = true; } if( !startDate.isNull() ) { if( has_previous ) query_str += " AND "; query_str += "cdate>=:csdate"; boundValues.insert(":csdate",QDate(1,1,1).daysTo(startDate)); has_previous = true; } if( !endDate.isNull() ) { if( has_previous ) query_str += " AND "; query_str += "cdate<=:cedate"; boundValues.insert(":cedate",QDate(1,1,1).daysTo(endDate)); has_previous = true; } if( !startTime.isNull() ) { if( has_previous ) query_str += " AND "; query_str += "ctime>=:cstime"; boundValues.insert(":cstime",QTime(0,0,0).secsTo(startTime)); has_previous = true; } if( !endTime.isNull() ) { if( has_previous ) query_str += " AND "; query_str += "ctime<=:cetime"; boundValues.insert(":cetime",QTime(0,0,0).secsTo(endTime)); has_previous = true; } if( group != -1 ) { if( has_previous ) query_str += " AND "; query_str += "grp=:grp"; boundValues.insert(":grp",group); has_previous = true; } if( !weather.isEmpty() ) { if( has_previous ) query_str += " AND "; query_str += "weather=:wthr"; boundValues.insert(":wthr",weather); has_previous = true; } if( geo.isValid() ) { if( has_previous ) query_str += " AND "; query_str += ":llttd<latitude AND latitude<:blttd"; boundValues.insert(":llttd",geo.y()); boundValues.insert(":blttd",geo.y()+geo.height()); query_str += " AND "; query_str += ":llntd<longitude AND longitude<:blntd"; boundValues.insert(":llntd",geo.x()); boundValues.insert(":blntd",geo.x()+geo.width()); has_previous = true; } if( domain != Enums::AllPapers ) { if( has_previous ) query_str += " AND "; query_str += "type=:type"; switch( domain ) { case Enums::NormalPapers: boundValues.insert(":type",static_cast<int>(Enums::Normal)); break; case Enums::ToDoPapers: boundValues.insert(":type",static_cast<int>(Enums::ToDo)); break; case Enums::UncompletedTasks: query_str += " AND text LIKE :kwd"; boundValues.insert(":kwd","%- %"); boundValues.insert(":type",static_cast<int>(Enums::ToDo)); break; case Enums::CompletedTasks: query_str += " AND text LIKE :kwd"; boundValues.insert(":kwd","%* %"); boundValues.insert(":type",static_cast<int>(Enums::ToDo)); break; } has_previous = true; } END_FNC_DEBUG if( !has_previous ) return QList<int>(); return searchQuery(query_str,keyword,boundValues); }
QString GameClockView::getClockText(const QTime &time) const { if(time.isNull()) return "--:--"; return time.hour()<1 ? time.toString("mm:ss") : time.toString("HH:mm:ss"); }
void BatteryWatcher::batteryChanged() { static QTime actionTime; static LxQt::Notification *notification = 0; qDebug() << "BatteryChanged" << "discharging:" << mBattery.discharging() << "chargeLevel:" << mBattery.chargeLevel() << "powerlow:" << mBattery.powerLow() << "actionTime:" << actionTime; if (mBattery.powerLow() && mSettings.getPowerLowAction() > 0) { if (actionTime.isNull()) { actionTime = QTime::currentTime().addMSecs(mSettings.getPowerLowWarningTime()*1000); } if (notification == 0) { notification = new LxQt::Notification(tr("Power low!"), this); notification->setTimeout(2000); } int milliSecondsToAction = QTime::currentTime().msecsTo(actionTime); if (milliSecondsToAction > 0) { int secondsToAction = milliSecondsToAction/1000; switch (mSettings.getPowerLowAction()) { case LxQt::Power::PowerSuspend: notification->setBody(tr("Suspending in %1 seconds").arg(secondsToAction)); break; case LxQt::Power::PowerHibernate: notification->setBody(tr("Hibernating in %1 seconds").arg(secondsToAction)); break; case LxQt::Power::PowerShutdown: notification->setBody(tr("Shutting down in %1 seconds").arg(secondsToAction)); break; } notification->update(); QTimer::singleShot(200, this, SLOT(batteryChanged())); } else { doAction(mSettings.getPowerLowAction()); } } else { if (!actionTime.isNull()) { actionTime = QTime(); } if (notification) { delete notification; notification = 0; } } mBatteryInfo.updateInfo(&mBattery); if (mSettings.isShowIcon()) mTrayIcon->update(mBattery.discharging(), mBattery.chargeLevel(), mSettings.getPowerLowLevel()); }
/* Parse all the date formats that Firefox can. The official format is: expires=ddd(d)?, dd-MMM-yyyy hh:mm:ss GMT But browsers have been supporting a very wide range of date strings. To work on many sites we need to support more then just the official date format. For reference see Firefox's PR_ParseTimeStringToExplodedTime in prtime.c. The Firefox date parser is coded in a very complex way and is slightly over ~700 lines long. While this implementation will be slightly slower for the non standard dates it is smaller, more readable, and maintainable. Or in their own words: "} // else what the hell is this." */ static QDateTime parseDateString(const QByteArray &dateString) { QTime time; // placeholders for values when we are not sure it is a year, month or day int unknown[3] = {-1, -1, -1}; int month = -1; int day = -1; int year = -1; int zoneOffset = -1; // hour:minute:second.ms pm QRegExp timeRx(QLatin1String("(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)")); int at = 0; while (at < dateString.length()) { #ifdef PARSEDATESTRINGDEBUG qDebug() << dateString.mid(at); #endif bool isNum = isNumber(dateString[at]); // Month if (!isNum && checkStaticArray(month, dateString, at, months, sizeof(months)- 1)) { ++month; #ifdef PARSEDATESTRINGDEBUG qDebug() << "Month:" << month; #endif at += 3; continue; } // Zone if (!isNum && zoneOffset == -1 && checkStaticArray(zoneOffset, dateString, at, zones, sizeof(zones)- 1)) { int sign = (at >= 0 && dateString[at - 1] == '-') ? -1 : 1; zoneOffset = sign * zoneOffsets[zoneOffset] * 60 * 60; #ifdef PARSEDATESTRINGDEBUG qDebug() << "Zone:" << month; #endif at += 3; continue; } // Zone offset if (!isNum && (zoneOffset == -1 || zoneOffset == 0) // Can only go after gmt && (dateString[at] == '+' || dateString[at] == '-') && (at == 0 || isWhitespace(dateString[at - 1]) || dateString[at - 1] == ',' || (at >= 3 && (dateString[at - 3] == 'g') && (dateString[at - 2] == 'm') && (dateString[at - 1] == 't')))) { int end = 1; while (end < 5 && dateString.length() > at+end && dateString[at + end] >= '0' && dateString[at + end] <= '9') ++end; int minutes = 0; int hours = 0; switch (end - 1) { case 4: minutes = atoi(dateString.mid(at + 3, 2).constData()); // fall through case 2: hours = atoi(dateString.mid(at + 1, 2).constData()); break; case 1: hours = atoi(dateString.mid(at + 1, 1).constData()); break; default: at += end; continue; } if (end != 1) { int sign = dateString[at] == '-' ? -1 : 1; zoneOffset = sign * ((minutes * 60) + (hours * 60 * 60)); #ifdef PARSEDATESTRINGDEBUG qDebug() << "Zone offset:" << zoneOffset << hours << minutes; #endif at += end; continue; } } // Time if (isNum && time.isNull() && dateString.length() >= at + 3 && (dateString[at + 2] == ':' || dateString[at + 1] == ':')) { // While the date can be found all over the string the format // for the time is set and a nice regexp can be used. int pos = timeRx.indexIn(QLatin1String(dateString), at); if (pos != -1) { QStringList list = timeRx.capturedTexts(); int h = atoi(list.at(1).toLatin1().constData()); int m = atoi(list.at(2).toLatin1().constData()); int s = atoi(list.at(4).toLatin1().constData()); int ms = atoi(list.at(6).toLatin1().constData()); if (h < 12 && !list.at(9).isEmpty()) if (list.at(9) == QLatin1String("pm")) h += 12; time = QTime(h, m, s, ms); #ifdef PARSEDATESTRINGDEBUG qDebug() << "Time:" << list << timeRx.matchedLength(); #endif at += timeRx.matchedLength(); continue; } } // 4 digit Year if (isNum && year == -1 && dateString.length() >= at + 3) { if (isNumber(dateString[at + 1]) && isNumber(dateString[at + 2]) && isNumber(dateString[at + 3])) { year = atoi(dateString.mid(at, 4).constData()); at += 4; #ifdef PARSEDATESTRINGDEBUG qDebug() << "Year:" << year; #endif continue; } } // a one or two digit number // Could be month, day or year if (isNum) { int length = 1; if (dateString.length() > at + 1 && isNumber(dateString[at + 1])) ++length; int x = atoi(dateString.mid(at, length).constData()); if (year == -1 && (x > 31 || x == 0)) { year = x; } else { if (unknown[0] == -1) unknown[0] = x; else if (unknown[1] == -1) unknown[1] = x; else if (unknown[2] == -1) unknown[2] = x; } at += length; #ifdef PARSEDATESTRINGDEBUG qDebug() << "Saving" << x; #endif continue; } // Unknown character, typically a weekday such as 'Mon' ++at; } // Once we are done parsing the string take the digits in unknown // and determine which is the unknown year/month/day int couldBe[3] = { 0, 0, 0 }; int unknownCount = 3; for (int i = 0; i < unknownCount; ++i) { if (unknown[i] == -1) { couldBe[i] = ADAY | AYEAR | AMONTH; unknownCount = i; continue; } if (unknown[i] >= 1) couldBe[i] = ADAY; if (month == -1 && unknown[i] >= 1 && unknown[i] <= 12) couldBe[i] |= AMONTH; if (year == -1) couldBe[i] |= AYEAR; } // For any possible day make sure one of the values that could be a month // can contain that day. // For any possible month make sure one of the values that can be a // day that month can have. // Example: 31 11 06 // 31 can't be a day because 11 and 6 don't have 31 days for (int i = 0; i < unknownCount; ++i) { int currentValue = unknown[i]; bool findMatchingMonth = couldBe[i] & ADAY && currentValue >= 29; bool findMatchingDay = couldBe[i] & AMONTH; if (!findMatchingMonth || !findMatchingDay) continue; for (int j = 0; j < 3; ++j) { if (j == i) continue; for (int k = 0; k < 2; ++k) { if (k == 0 && !(findMatchingMonth && (couldBe[j] & AMONTH))) continue; else if (k == 1 && !(findMatchingDay && (couldBe[j] & ADAY))) continue; int m = currentValue; int d = unknown[j]; if (k == 0) qSwap(m, d); if (m == -1) m = month; bool found = true; switch(m) { case 2: // When we get 29 and the year ends up having only 28 // See date.isValid below // Example: 29 23 Feb if (d <= 29) found = false; break; case 4: case 6: case 9: case 11: if (d <= 30) found = false; break; default: if (d > 0 && d <= 31) found = false; } if (k == 0) findMatchingMonth = found; else if (k == 1) findMatchingDay = found; } } if (findMatchingMonth) couldBe[i] &= ~ADAY; if (findMatchingDay) couldBe[i] &= ~AMONTH; } // First set the year/month/day that have been deduced // and reduce the set as we go along to deduce more for (int i = 0; i < unknownCount; ++i) { int unset = 0; for (int j = 0; j < 3; ++j) { if (couldBe[j] == ADAY && day == -1) { day = unknown[j]; unset |= ADAY; } else if (couldBe[j] == AMONTH && month == -1) { month = unknown[j]; unset |= AMONTH; } else if (couldBe[j] == AYEAR && year == -1) { year = unknown[j]; unset |= AYEAR; } else { // common case break; } couldBe[j] &= ~unset; } } // Now fallback to a standardized order to fill in the rest with for (int i = 0; i < unknownCount; ++i) { if (couldBe[i] & AMONTH && month == -1) month = unknown[i]; else if (couldBe[i] & ADAY && day == -1) day = unknown[i]; else if (couldBe[i] & AYEAR && year == -1) year = unknown[i]; } #ifdef PARSEDATESTRINGDEBUG qDebug() << "Final set" << year << month << day; #endif if (year == -1 || month == -1 || day == -1) { #ifdef PARSEDATESTRINGDEBUG qDebug() << "Parser failure" << year << month << day; #endif return QDateTime(); } // Y2k behavior int y2k = 0; if (year < 70) y2k = 2000; else if (year < 100) y2k = 1900; QDate date(year + y2k, month, day); // When we were given a bad cookie that when parsed // set the day to 29 and the year to one that doesn't // have the 29th of Feb rather then adding the extra // complicated checking earlier just swap here. // Example: 29 23 Feb if (!date.isValid()) date = QDate(day + y2k, month, year); QDateTime dateTime(date, time, Qt::UTC); if (zoneOffset != -1) { dateTime = dateTime.addSecs(zoneOffset); } if (!dateTime.isValid()) return QDateTime(); return dateTime; }
void Xport::EditCut() { RDCut *cut; int cart_number; int cut_number; QString str; int num; QDateTime datetime; QTime time; bool rotation_changed=false; bool length_changed=false; // // Verify Post // if(!xport_post->getValue("CART_NUMBER",&cart_number)) { XmlExit("Missing CART_NUMBER",400); } if(!xport_post->getValue("CUT_NUMBER",&cut_number)) { XmlExit("Missing CUT_NUMBER",400); } // // Verify User Perms // if(!xport_user->cartAuthorized(cart_number)) { XmlExit("No such cart",404); } if(!xport_user->editAudio()) { XmlExit("Unauthorized",401); } // // Process Request // cut=new RDCut(cart_number,cut_number); if(!cut->exists()) { delete cut; XmlExit("No such cut",404); } if(xport_post->getValue("EVERGREEN",&num)) { cut->setEvergreen(num); rotation_changed=true; } if(xport_post->getValue("DESCRIPTION",&str)) { cut->setDescription(str); } if(xport_post->getValue("OUTCUE",&str)) { cut->setOutcue(str); } if(xport_post->getValue("ISRC",&str)) { cut->setIsrc(str); } if(xport_post->getValue("ISCI",&str)) { cut->setIsci(str); } if(xport_post->getValue("START_DATETIME",&datetime)) { cut->setStartDatetime(datetime,!datetime.isNull()); length_changed=true; rotation_changed=true; } if(xport_post->getValue("END_DATETIME",&datetime)) { cut->setEndDatetime(datetime,!datetime.isNull()); length_changed=true; rotation_changed=true; } if(xport_post->getValue("MON",&num)) { cut->setWeekPart(1,num); rotation_changed=true; } if(xport_post->getValue("TUE",&num)) { cut->setWeekPart(2,num); rotation_changed=true; } if(xport_post->getValue("WED",&num)) { cut->setWeekPart(3,num); rotation_changed=true; } if(xport_post->getValue("THU",&num)) { cut->setWeekPart(4,num); rotation_changed=true; } if(xport_post->getValue("FRI",&num)) { cut->setWeekPart(5,num); rotation_changed=true; } if(xport_post->getValue("SAT",&num)) { cut->setWeekPart(6,num); rotation_changed=true; } if(xport_post->getValue("SUN",&num)) { cut->setWeekPart(7,num); rotation_changed=true; } if(xport_post->getValue("START_DAYPART",&time)) { cut->setStartDaypart(time,!time.isNull()); rotation_changed=true; } if(xport_post->getValue("END_DAYPART",&time)) { cut->setEndDaypart(time,!time.isNull()); rotation_changed=true; } if(xport_post->getValue("WEIGHT",&num)) { cut->setWeight(num); rotation_changed=true; } if(xport_post->getValue("START_POINT",&num)) { cut->setStartPoint(num); length_changed=true; } if(xport_post->getValue("END_POINT",&num)) { cut->setEndPoint(num); length_changed=true; } if(xport_post->getValue("FADEUP_POINT",&num)) { cut->setFadeupPoint(num); length_changed=true; } if(xport_post->getValue("FADEDOWN_POINT",&num)) { cut->setFadedownPoint(num); length_changed=true; } if(xport_post->getValue("SEGUE_START_POINT",&num)) { cut->setSegueStartPoint(num); length_changed=true; } if(xport_post->getValue("SEGUE_END_POINT",&num)) { cut->setSegueEndPoint(num); length_changed=true; } if(xport_post->getValue("HOOK_START_POINT",&num)) { cut->setHookStartPoint(num); length_changed=true; } if(xport_post->getValue("HOOK_END_POINT",&num)) { cut->setHookEndPoint(num); length_changed=true; } if(xport_post->getValue("TALK_START_POINT",&num)) { cut->setTalkStartPoint(num); length_changed=true; } if(xport_post->getValue("TALK_END_POINT",&num)) { cut->setTalkEndPoint(num); length_changed=true; } if(length_changed||rotation_changed) { RDCart *cart=new RDCart(cut->cartNumber()); if(length_changed) { cart->updateLength(); } if(rotation_changed) { cart->resetRotation(); } delete cart; } delete cut; XmlExit("OK",200); }
void Game::nextGameFrame() { static float chaseTimer = 0.0; static QTime lastFrameTime; if(!lastFrameTime.isNull()) { chaseTimer += lastFrameTime.msecsTo(QTime::currentTime())/1000.0; } lastFrameTime = QTime::currentTime(); Level *level = m_levels.at(m_currentLevel); // Mouvements QList<Ghost*> collision; level->movePacman(); level->moveGhosts(); collision.append(level->checkUnitsPositions()); level->updateTimer(); // if(level->eatenPellets() == level->pelletCount()) { m_timer->stop(); m_currentLevel++; if(m_currentLevel == m_levels.size()) { m_victory = true; emit gameFinished(); return; } else { m_isChangingLevel = true; m_currentLevelImageReady = false; Level *level = m_levels.at(m_currentLevel); level->startLevel(); return; } } if(collision.size() > 0) { if(!Ghost::areGhostsScared()) { m_lifes--; if(m_lifes>0) { level->resetUnitsPosition(); } else { m_defeat = true; emit gameFinished(); return; } m_timer->stop(); } else { for(int i=0; i<collision.size(); i++) { m_score += 200 * qPow(2, m_consecutivesEnergizers); m_consecutivesEnergizers ++; QTimer::singleShot(500, this, SLOT(resumeGame())); m_timer->stop(); } } } if(!Ghost::areGhostsScared()) m_consecutivesEnergizers = 0; QPixmap *image = level->render(); m_image = *image; delete image; m_currentLevelImageReady = true; }
void ServerThread::maybeSendBacktrace() { QFile coreFile("core"); if (!coreFile.exists()) { qDebug() << "No core dump found"; return; } char *receiver = getenv("CRASH_REPORT_RECEIVER"); if (!receiver) { qDebug() << "CRASH_REPORT_RECEIVER environment variable not set"; return; } QProcess gdb; gdb.start(QString("gdb %1 core -q -x print-backtrace.gdb") .arg(mExecutable)); if (!gdb.waitForStarted()) { qDebug() << "Failed to launch gdb"; coreFile.remove(); return; } if (!gdb.waitForFinished()) { qDebug() << "gdb process is not finishing, killing"; gdb.kill(); coreFile.remove(); return; } coreFile.remove(); const QByteArray gdbOutput = gdb.readAllStandardOutput(); qDebug() << "gdb output:\n" << gdbOutput.constData(); QTime current = QTime::currentTime(); if (!mLastCrash.isNull() && mLastCrash.secsTo(current) < 60 * 10) { qDebug() << "Sent a crash report less than 10 minutes ago, " "dropping this one"; return; } mLastCrash = current; QProcess mail; mail.start(QString("mail -s \"Crash report for %1\" %2") .arg(mExecutable, QString::fromLocal8Bit(receiver))); if (!mail.waitForStarted()) { qDebug() << "Failed to launch mail"; return; } mail.write(gdbOutput); mail.closeWriteChannel(); if (mail.waitForFinished()) { qDebug() << "Crash report sent to" << receiver; } else { qDebug() << "mail process is not finishing, killing"; mail.kill(); } }
bool RDRenderer::Render(const QString &outfile,RDLogEvent *log,RDSettings *s, const QTime &start_time,bool ignore_stops, QString *err_msg,int first_line,int last_line, const QTime &first_time,const QTime &last_time) { float *pcm=NULL; QTime current_time=start_time; QString temp_output_filename; render_warnings.clear(); render_abort=false; // // Open Output File // SF_INFO sf_info; SNDFILE *sf_out; memset(&sf_info,0,sizeof(sf_info)); sf_info.samplerate=rda->system()->sampleRate(); sf_info.channels=s->channels(); if(s->format()==RDSettings::Pcm16) { sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16; } else { sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_24; } sf_out=sf_open(outfile,SFM_WRITE,&sf_info); if(sf_out==NULL) { fprintf(stderr,"rdrender: unable to open output file [%s]\n", sf_strerror(sf_out)); return 1; } // // Initialize the log // std::vector<__RDRenderLogLine *> lls; for(int i=0;i<log->size();i++) { lls.push_back(new __RDRenderLogLine(log->logLine(i),s->channels())); if(ignore_stops&&(lls.back()->transType()==RDLogLine::Stop)) { lls.back()->setTransType(RDLogLine::Play); } if((!first_time.isNull())&& (lls.back()->timeType()==RDLogLine::Hard)&& (first_line==-1)&& (lls.back()->startTime(RDLogLine::Imported)==first_time)) { first_line=i; } if((!last_time.isNull())&& (lls.back()->timeType()==RDLogLine::Hard)&& (last_line==-1)&& (lls.back()->startTime(RDLogLine::Imported)==last_time)) { last_line=i; } } if((!first_time.isNull())&&(first_line==-1)) { *err_msg+=tr("first-time event not found"); } if((!last_time.isNull())&&(last_line==-1)) { if(!err_msg->isEmpty()) { *err_msg+=", "; } *err_msg+=tr("last-time event not found"); } if(!err_msg->isEmpty()) { return false; } lls.push_back(new __RDRenderLogLine(new RDLogLine(),s->channels())); lls.back()->setTransType(RDLogLine::Play); if((!first_time.isNull())&&(first_line==-1)) { first_line=log->size(); } // // Iterate through it // for(unsigned i=0;i<lls.size();i++) { if(render_abort) { emit lineStarted(log->size()+render_total_passes-1, log->size()+render_total_passes-1); *err_msg+="Render aborted.\n"; sf_close(sf_out); return false; } emit lineStarted(i,log->size()+render_total_passes-1); if(((first_line==-1)||(first_line<=(int)i))&& ((last_line==-1)||(last_line>(int)i))) { if(lls.at(i)->transType()==RDLogLine::Stop) { ProgressMessage(current_time,i,tr("STOP")+" ",lls.at(i)->summary()); render_warnings. push_back(tr("log render halted at line")+QString().sprintf(" %d ",i)+ tr("due to STOP")); break; } if(lls.at(i)->open(current_time)) { ProgressMessage(current_time,i, RDLogLine::transText(lls.at(i)->transType()), QString().sprintf(" cart %06u [",lls.at(i)->cartNumber())+ lls.at(i)->title()+"]"); sf_count_t frames=0; if((lls.at(i+1)->transType()==RDLogLine::Segue)&& (lls.at(i)->segueStartPoint()>=0)) { frames=FramesFromMsec(lls.at(i)->segueStartPoint()- lls.at(i)->startPoint()); current_time= current_time.addMSecs(lls.at(i)->segueStartPoint()- lls.at(i)->startPoint()); } else { frames=FramesFromMsec(lls.at(i)->endPoint()- lls.at(i)->startPoint()); current_time=current_time.addMSecs(lls.at(i)->endPoint()- lls.at(i)->startPoint()); } pcm=new float[frames*s->channels()]; memset(pcm,0,frames*s->channels()*sizeof(float)); for(unsigned j=0;j<i;j++) { Sum(pcm,lls.at(j),frames,s->channels()); } Sum(pcm,lls.at(i),frames,s->channels()); sf_writef_float(sf_out,pcm,frames); delete pcm; pcm=NULL; lls.at(i)->setRamp(lls.at(i+1)->transType()); } else { if(i<(lls.size()-1)) { if(lls.at(i)->type()==RDLogLine::Cart) { ProgressMessage(current_time,i,tr("FAIL"),lls.at(i)->summary()+ " ("+tr("NO AUDIO AVAILABLE")+")"); render_warnings. push_back(lls.at(i)->summary()+tr("at line")+ QString().sprintf(" %d ",i)+ tr("failed to play (NO AUDIO AVAILABLE)")); } else { ProgressMessage(current_time,i,tr("SKIP"),lls.at(i)->summary()); } } else { ProgressMessage(current_time,lls.size()-1, tr("STOP"),tr("--- end of log ---")); } } } } sf_close(sf_out); return true; }
bool PulseHandler::Suspend(enum PulseAction action) { // global lock around all access to our global singleton static QMutex global_lock; QMutexLocker locker(&global_lock); // cleanup the PulseAudio server connection if requested if (kPulseCleanup == action) { if (g_pulseHandler) { LOG(VB_GENERAL, LOG_INFO, LOC + "Cleaning up PulseHandler"); delete g_pulseHandler; g_pulseHandler = NULL; } return true; } if (getenv("DEBUG_PULSE_AUDIO_ALSA_EMULATION")) { LOG(VB_AUDIO, LOG_WARNING, "WARNING: "); LOG(VB_AUDIO, LOG_WARNING, "WARNING: ***Pulse Audio is running!!!!***"); LOG(VB_AUDIO, LOG_WARNING, "WARNING: "); LOG(VB_AUDIO, LOG_WARNING, "WARNING: You have told MythTV to ignore it."); LOG(VB_AUDIO, LOG_WARNING, "WARNING: "); return false; } static int s_iPulseRunning = -1; static QTime s_time; static enum PulseAction s_ePulseAction = PulseAction(-1); // Use the last result of IsPulseAudioRunning if within time if (!s_time.isNull() && s_time.elapsed() < 30000) { if (!s_iPulseRunning) return false; // If the last action is repeated then do nothing if (action == s_ePulseAction) return true; } // NB IsPulseAudioRunning calls myth_system and can take up to 100mS else if (IsPulseAudioRunning()) { s_iPulseRunning = 1; s_time.start(); } else { // do nothing if PulseAudio is not currently running LOG(VB_AUDIO, LOG_INFO, LOC + "PulseAudio not running"); s_iPulseRunning = 0; s_time.start(); return false; } // make sure any pre-existing handler is still valid if (g_pulseHandler && !g_pulseHandler->Valid()) { LOG(VB_AUDIO, LOG_INFO, LOC + "PulseHandler invalidated. Deleting."); delete g_pulseHandler; g_pulseHandler = NULL; } // create our handler if (!g_pulseHandler) { PulseHandler* handler = new PulseHandler(); if (handler) { LOG(VB_AUDIO, LOG_INFO, LOC + "Created PulseHandler object"); g_pulseHandler = handler; } else { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create PulseHandler object"); return false; } } bool result; // enable processing of incoming callbacks g_pulseHandlerActive = true; result = g_pulseHandler->SuspendInternal(kPulseSuspend == action); // disable processing of incoming callbacks in case we delete/recreate our // instance due to a termination or other failure g_pulseHandlerActive = false; s_ePulseAction = action; return result; }