DTC::VideoLookupList* Video::LookupVideo( const QString &Title, const QString &Subtitle, const QString &Inetref, int Season, int Episode, const QString &GrabberType ) { DTC::VideoLookupList *pVideoLookups = new DTC::VideoLookupList(); MetadataLookupList list; MetadataFactory *factory = new MetadataFactory(NULL); if (factory) list = factory->SynchronousLookup(Title, Subtitle, Inetref, Season, Episode, GrabberType); if ( !list.size() ) return pVideoLookups; for( int n = 0; n < list.size(); n++ ) { DTC::VideoLookup *pVideoLookup = pVideoLookups->AddNewVideoLookup(); MetadataLookup *lookup = list[n]; if (lookup) { pVideoLookup->setTitle(lookup->GetTitle()); pVideoLookup->setSubTitle(lookup->GetSubtitle()); pVideoLookup->setSeason(lookup->GetSeason()); pVideoLookup->setEpisode(lookup->GetEpisode()); pVideoLookup->setYear(lookup->GetYear()); pVideoLookup->setTagline(lookup->GetTagline()); pVideoLookup->setDescription(lookup->GetDescription()); pVideoLookup->setCertification(lookup->GetCertification()); pVideoLookup->setInetref(lookup->GetInetref()); pVideoLookup->setHomePage(lookup->GetHomepage()); pVideoLookup->setReleaseDate(QDateTime(lookup->GetReleaseDate())); pVideoLookup->setUserRating(lookup->GetUserRating()); pVideoLookup->setLength(lookup->GetRuntime()); pVideoLookup->setLanguage(lookup->GetLanguage()); pVideoLookup->setCountries(lookup->GetCountries()); pVideoLookup->setPopularity(lookup->GetPopularity()); pVideoLookup->setBudget(lookup->GetBudget()); pVideoLookup->setRevenue(lookup->GetRevenue()); pVideoLookup->setIMDB(lookup->GetIMDB()); pVideoLookup->setTMSRef(lookup->GetTMSref()); ArtworkList coverartlist = lookup->GetArtwork(kArtworkCoverart); ArtworkList::iterator c; for (c = coverartlist.begin(); c != coverartlist.end(); ++c) { DTC::ArtworkItem *art = pVideoLookup->AddNewArtwork(); art->setType("coverart"); art->setUrl((*c).url); art->setThumbnail((*c).thumbnail); art->setWidth((*c).width); art->setHeight((*c).height); } ArtworkList fanartlist = lookup->GetArtwork(kArtworkFanart); ArtworkList::iterator f; for (f = fanartlist.begin(); f != fanartlist.end(); ++f) { DTC::ArtworkItem *art = pVideoLookup->AddNewArtwork(); art->setType("fanart"); art->setUrl((*f).url); art->setThumbnail((*f).thumbnail); art->setWidth((*f).width); art->setHeight((*f).height); } ArtworkList bannerlist = lookup->GetArtwork(kArtworkBanner); ArtworkList::iterator b; for (b = bannerlist.begin(); b != bannerlist.end(); ++b) { DTC::ArtworkItem *art = pVideoLookup->AddNewArtwork(); art->setType("banner"); art->setUrl((*b).url); art->setThumbnail((*b).thumbnail); art->setWidth((*b).width); art->setHeight((*b).height); } ArtworkList screenshotlist = lookup->GetArtwork(kArtworkScreenshot); ArtworkList::iterator s; for (s = screenshotlist.begin(); s != screenshotlist.end(); ++s) { DTC::ArtworkItem *art = pVideoLookup->AddNewArtwork(); art->setType("screenshot"); art->setUrl((*s).url); art->setThumbnail((*s).thumbnail); art->setWidth((*s).width); art->setHeight((*s).height); } delete lookup; } } pVideoLookups->setCount ( list.count() ); pVideoLookups->setAsOf ( QDateTime::currentDateTime() ); pVideoLookups->setVersion ( MYTH_BINARY_VERSION ); pVideoLookups->setProtoVer ( MYTH_PROTO_VERSION ); delete factory; return pVideoLookups; }
// Refresh not up to date metrics void MetricAggregator::refreshMetrics() { refreshMetrics(QDateTime()); }
QDateTime InfoTimeDestination::dateTime() const { return QDateTime( QDate( m_year, m_month, m_day ), QTime( m_hour, m_minute, 0 ) ); }
/*! Sets minimum \a minTime and maximum \a maxTime in QTime format. This will allow the user to set a time range on datetime picker. \param minTime minimum time in QTime format. \param maxTime maximum time in QTime format. \sa setMinimumTime \sa setMaximumTime */ void HbDateTimePicker::setTimeRange(const QTime &minTime, const QTime &maxTime) { Q_D(HbDateTimePicker); setDateTimeRange(QDateTime(d->mMinimumDate.date(), minTime), QDateTime(d->mMinimumDate.date(), maxTime)); }
qDebug() << "Failed to save the recurrent event; error:" << defaultManager.error(); //! [Creating a recurrent event] //! [Retrieving occurrences of a particular recurrent event within a time period] QList<QOrganizerItem> instances = defaultManager.itemOccurrences(marshmallowMeeting, startDateTime, endDateTime); //! [Retrieving occurrences of a particular recurrent event within a time period] qDebug() << "dumping retrieved instances:"; foreach(const QOrganizerItem& currInst, instances) { dumpItem(currInst); qDebug() << "...................."; } //! [Retrieving the next 5 occurrences of a particular recurrent event] instances = defaultManager.itemOccurrences(marshmallowMeeting, QDateTime::currentDateTime(), QDateTime(), 5); //! [Retrieving the next 5 occurrences of a particular recurrent event] //! [Retrieving the next 10 occurrences of any item (Agenda View)] instances = defaultManager.items(QDateTime::currentDateTime(), QDateTime()); instances = instances.mid(0, 10); //! [Retrieving the next 10 occurrences of any item (Agenda View)] //! [Creating a non-recurrent entry] // a default constructed journal will have it's date/time set to the current date/time. QOrganizerJournal journal; journal.setDescription("The conference went well. We all agree that marshmallows are awesome, "\ "but we were unable to reach any agreement as to how we could possibly "\ "increase our intake of marshmallows. Several action points were assigned "\ "to various members of the group; I have been tasked with finding a good "\ "recipe that combines both marshmallows and chocolate, by next Wednesday.");
/*! Sets maximum \a date in QDate format. \param date Maximum date to be set on datetime picker in QDate format. \sa maximumDate */ void HbDateTimePicker::setMaximumDate(const QDate& date) { Q_D(HbDateTimePicker); setMaximumDateTime(QDateTime(date, d->mMaximumDate.time())); }
/*! Sets the current \a time, to be set on datetime picker widget, in QTime format. \param time in QTime format. \sa time */ void HbDateTimePicker::setTime(const QTime &time) { Q_D(HbDateTimePicker); setDateTime(QDateTime(d->mDateTime.date(), time)); }
void PublicationType::clearDate() { m_date = QDateTime(); }
void PublicationType::clearTime() { m_time = QDateTime(); }
void EclipsesItem::initialize() { // set basic information int year, month, day, hour, min, phase; double secs, tz; phase = m_ecl->getEclYearInfo( m_index, year, month, day, hour, min, secs, tz, m_magnitude ); switch( phase ) { case -4: m_phase = EclipsesItem::TotalMoon; break; case -3: m_phase = EclipsesItem::PartialMoon; break; case -2: case -1: m_phase = EclipsesItem::PenumbralMoon; break; case 1: m_phase = EclipsesItem::PartialSun; break; case 2: m_phase = EclipsesItem::NonCentralAnnularSun; break; case 3: m_phase = EclipsesItem::NonCentralTotalSun; break; case 4: m_phase = EclipsesItem::AnnularSun; break; case 5: m_phase = EclipsesItem::TotalSun; break; case 6: m_phase = EclipsesItem::AnnularTotalSun; break; default: mDebug() << "Invalid phase for eclipse at" << year << "/" << day << "/" << month << "!"; } m_dateMaximum = QDateTime( QDate( year, month, day ), QTime( hour, min, secs ), Qt::LocalTime ); // get global start/end date of eclipse double mjd_start, mjd_end; m_ecl->putEclSelect( m_index ); if( m_ecl->getPartial( mjd_start, mjd_end ) != 0 ) { m_ecl->getDatefromMJD( mjd_start, year, month, day, hour, min, secs ); m_startDatePartial = QDateTime( QDate( year, month, day ), QTime( hour, min, secs ), Qt::LocalTime ); m_ecl->getDatefromMJD( mjd_end, year, month, day, hour, min, secs ); m_endDatePartial = QDateTime( QDate( year, month, day ), QTime( hour, min, secs ), Qt::LocalTime ); } else { // duration is shorter than 1 min m_startDatePartial = m_dateMaximum; m_endDatePartial = m_dateMaximum; } m_isTotal = ( m_ecl->getTotal( mjd_start, mjd_end ) != 0 ); if( m_isTotal ) { m_ecl->getDatefromMJD( mjd_start, year, month, day, hour, min, secs ); m_startDateTotal = QDateTime( QDate( year, month, day ), QTime( hour, min, secs ), Qt::LocalTime ); m_ecl->getDatefromMJD( mjd_end, year, month, day, hour, min, secs ); m_endDateTotal = QDateTime( QDate( year, month, day ), QTime( hour, min, secs ), Qt::LocalTime ); } // detailed calculations are done when required m_calculationsNeedUpdate = true; }
bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath ) { // use scale dependent visibility flag layerElement.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 ); layerElement.setAttribute( "minimumScale", QString::number( minimumScale() ) ); layerElement.setAttribute( "maximumScale", QString::number( maximumScale() ) ); // ID QDomElement layerId = document.createElement( "id" ); QDomText layerIdText = document.createTextNode( id() ); layerId.appendChild( layerIdText ); layerElement.appendChild( layerId ); // data source QDomElement dataSource = document.createElement( "datasource" ); QString src = source(); QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this ); // TODO: what about postgres, mysql and others, they should not go through writePath() if ( vlayer && vlayer->providerType() == "spatialite" ) { QgsDataSourceURI uri( src ); QString database = QgsProject::instance()->writePath( uri.database(), relativeBasePath ); uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() ); src = uri.uri(); } else if ( vlayer && vlayer->providerType() == "ogr" ) { QStringList theURIParts = src.split( "|" ); theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0], relativeBasePath ); src = theURIParts.join( "|" ); } else if ( vlayer && vlayer->providerType() == "gpx" ) { QStringList theURIParts = src.split( "?" ); theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0], relativeBasePath ); src = theURIParts.join( "?" ); } else if ( vlayer && vlayer->providerType() == "delimitedtext" ) { QUrl urlSource = QUrl::fromEncoded( src.toAscii() ); QUrl urlDest = QUrl::fromLocalFile( QgsProject::instance()->writePath( urlSource.toLocalFile(), relativeBasePath ) ); urlDest.setQueryItems( urlSource.queryItems() ); src = QString::fromAscii( urlDest.toEncoded() ); } else { bool handled = false; if ( !vlayer ) { QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this ); // Update path for subdataset if ( rlayer && rlayer->providerType() == "gdal" ) { if ( src.startsWith( "NETCDF:" ) ) { // NETCDF:filename:variable // filename can be quoted with " as it can contain colons QRegExp r( "NETCDF:(.+):([^:]+)" ); if ( r.exactMatch( src ) ) { QString filename = r.cap( 1 ); if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) filename = filename.mid( 1, filename.length() - 2 ); src = "NETCDF:\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 2 ); handled = true; } } else if ( src.startsWith( "HDF4_SDS:" ) ) { // HDF4_SDS:subdataset_type:file_name:subdataset_index // filename can be quoted with " as it can contain colons QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" ); if ( r.exactMatch( src ) ) { QString filename = r.cap( 2 ); if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) filename = filename.mid( 1, filename.length() - 2 ); src = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 3 ); handled = true; } } else if ( src.startsWith( "HDF5:" ) ) { // HDF5:file_name:subdataset // filename can be quoted with " as it can contain colons QRegExp r( "HDF5:(.+):([^:]+)" ); if ( r.exactMatch( src ) ) { QString filename = r.cap( 1 ); if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) filename = filename.mid( 1, filename.length() - 2 ); src = "HDF5:\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 2 ); handled = true; } } else if ( src.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) ) { // NITF_IM:0:filename // RADARSAT_2_CALIB:?:filename QRegExp r( "([^:]+):([^:]+):(.+)" ); if ( r.exactMatch( src ) ) { src = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->writePath( r.cap( 3 ), relativeBasePath ); handled = true; } } } } if ( !handled ) src = QgsProject::instance()->writePath( src, relativeBasePath ); } QDomText dataSourceText = document.createTextNode( src ); dataSource.appendChild( dataSourceText ); layerElement.appendChild( dataSource ); // layer name QDomElement layerName = document.createElement( "layername" ); QDomText layerNameText = document.createTextNode( originalName() ); layerName.appendChild( layerNameText ); // layer title QDomElement layerTitle = document.createElement( "title" ); QDomText layerTitleText = document.createTextNode( title() ); layerTitle.appendChild( layerTitleText ); // layer abstract QDomElement layerAbstract = document.createElement( "abstract" ); QDomText layerAbstractText = document.createTextNode( abstract() ); layerAbstract.appendChild( layerAbstractText ); layerElement.appendChild( layerName ); layerElement.appendChild( layerTitle ); layerElement.appendChild( layerAbstract ); // layer keyword list QStringList keywordStringList = keywordList().split( "," ); if ( keywordStringList.size() > 0 ) { QDomElement layerKeywordList = document.createElement( "keywordList" ); for ( int i = 0; i < keywordStringList.size(); ++i ) { QDomElement layerKeywordValue = document.createElement( "value" ); QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() ); layerKeywordValue.appendChild( layerKeywordText ); layerKeywordList.appendChild( layerKeywordValue ); } layerElement.appendChild( layerKeywordList ); } // layer metadataUrl QString aDataUrl = dataUrl(); if ( !aDataUrl.isEmpty() ) { QDomElement layerDataUrl = document.createElement( "dataUrl" ); QDomText layerDataUrlText = document.createTextNode( aDataUrl ); layerDataUrl.appendChild( layerDataUrlText ); layerDataUrl.setAttribute( "format", dataUrlFormat() ); layerElement.appendChild( layerDataUrl ); } // layer legendUrl QString aLegendUrl = legendUrl(); if ( !aLegendUrl.isEmpty() ) { QDomElement layerLegendUrl = document.createElement( "legendUrl" ); QDomText layerLegendUrlText = document.createTextNode( aLegendUrl ); layerLegendUrl.appendChild( layerLegendUrlText ); layerLegendUrl.setAttribute( "format", legendUrlFormat() ); layerElement.appendChild( layerLegendUrl ); } // layer attribution QString aAttribution = attribution(); if ( !aAttribution.isEmpty() ) { QDomElement layerAttribution = document.createElement( "attribution" ); QDomText layerAttributionText = document.createTextNode( aAttribution ); layerAttribution.appendChild( layerAttributionText ); layerAttribution.setAttribute( "href", attributionUrl() ); layerElement.appendChild( layerAttribution ); } // layer metadataUrl QString aMetadataUrl = metadataUrl(); if ( !aMetadataUrl.isEmpty() ) { QDomElement layerMetadataUrl = document.createElement( "metadataUrl" ); QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl ); layerMetadataUrl.appendChild( layerMetadataUrlText ); layerMetadataUrl.setAttribute( "type", metadataUrlType() ); layerMetadataUrl.setAttribute( "format", metadataUrlFormat() ); layerElement.appendChild( layerMetadataUrl ); } // timestamp if supported if ( timestamp() > QDateTime() ) { QDomElement stamp = document.createElement( "timestamp" ); QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) ); stamp.appendChild( stampText ); layerElement.appendChild( stamp ); } layerElement.appendChild( layerName ); // zorder // This is no longer stored in the project file. It is superfluous since the layers // are written and read in the proper order. // spatial reference system id QDomElement mySrsElement = document.createElement( "srs" ); mCRS->writeXML( mySrsElement, document ); layerElement.appendChild( mySrsElement ); #if 0 // <transparencyLevelInt> QDomElement transparencyLevelIntElement = document.createElement( "transparencyLevelInt" ); QDomText transparencyLevelIntText = document.createTextNode( QString::number( getTransparency() ) ); transparencyLevelIntElement.appendChild( transparencyLevelIntText ); maplayer.appendChild( transparencyLevelIntElement ); #endif // now append layer node to map layer node writeCustomProperties( layerElement, document ); return writeXml( layerElement, document ); } // bool QgsMapLayer::writeXML
void DailyRollingFileAppender::computeRollOverTime() { // Q_ASSERT_X(, "DailyRollingFileAppender::computeRollOverTime()", "Lock must be held by caller") Q_ASSERT_X(!mActiveDatePattern.isEmpty(), "DailyRollingFileAppender::computeRollOverTime()", "No active date pattern"); QDateTime now = QDateTime::currentDateTime(); QDate now_date = now.date(); QTime now_time = now.time(); QDateTime start; switch (mFrequency) { case MINUTELY_ROLLOVER: { start = QDateTime(now_date, QTime(now_time.hour(), now_time.minute(), 0, 0)); mRollOverTime = start.addSecs(60); } break; case HOURLY_ROLLOVER: { start = QDateTime(now_date, QTime(now_time.hour(), 0, 0, 0)); mRollOverTime = start.addSecs(60*60); } break; case HALFDAILY_ROLLOVER: { int hour = now_time.hour(); if (hour >= 12) hour = 12; else hour = 0; start = QDateTime(now_date, QTime(hour, 0, 0, 0)); mRollOverTime = start.addSecs(60*60*12); } break; case DAILY_ROLLOVER: { start = QDateTime(now_date, QTime(0, 0, 0, 0)); mRollOverTime = start.addDays(1); } break; case WEEKLY_ROLLOVER: { // QT numbers the week days 1..7. The week starts on Monday. // Change it to being numbered 0..6, starting with Sunday. int day = now_date.dayOfWeek(); if (day == Qt::Sunday) day = 0; start = QDateTime(now_date, QTime(0, 0, 0, 0)).addDays(-1 * day); mRollOverTime = start.addDays(7); } break; case MONTHLY_ROLLOVER: { start = QDateTime(QDate(now_date.year(), now_date.month(), 1), QTime(0, 0, 0, 0)); mRollOverTime = start.addMonths(1); } break; default: Q_ASSERT_X(false, "DailyRollingFileAppender::computeInterval()", "Invalid datePattern constant"); mRollOverTime = QDateTime::fromTime_t(0); } mRollOverSuffix = static_cast<DateTime>(start).toString(mActiveDatePattern); Q_ASSERT_X(static_cast<DateTime>(now).toString(mActiveDatePattern) == mRollOverSuffix, "DailyRollingFileAppender::computeRollOverTime()", "File name changes within interval"); Q_ASSERT_X(mRollOverSuffix != static_cast<DateTime>(mRollOverTime).toString(mActiveDatePattern), "DailyRollingFileAppender::computeRollOverTime()", "File name does not change with rollover"); logger()->trace("Computing roll over time from %1: The interval start time is %2. The roll over time is %3", now, start, mRollOverTime); }
void tst_QXmppRpcIq::testDateTime() { checkVariant(QDateTime(QDate(1998, 7, 17), QTime(14, 8, 55)), QByteArray("<value><dateTime.iso8601>1998-07-17T14:08:55</dateTime.iso8601></value>")); }
/* 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 ClearPrivateData::dialogAccepted() { QApplication::setOverrideCursor(Qt::WaitCursor); if (ui->history->isChecked()) { qint64 start = QDateTime::currentMSecsSinceEpoch(); qint64 end = 0; const QDate today = QDate::currentDate(); const QDate week = today.addDays(1 - today.dayOfWeek()); const QDate month = QDate(today.year(), today.month(), 1); switch (ui->historyLength->currentIndex()) { case 0: //Later Today end = QDateTime(today).toMSecsSinceEpoch(); break; case 1: //Week end = QDateTime(week).toMSecsSinceEpoch(); break; case 2: //Month end = QDateTime(month).toMSecsSinceEpoch(); break; case 3: //All break; } if (end == 0) { mApp->history()->clearHistory(); } else { const QList<int> &indexes = mApp->history()->indexesFromTimeRange(start, end); mApp->history()->deleteHistoryEntry(indexes); } } if (ui->cookies->isChecked()) { mApp->cookieJar()->setAllCookies(QList<QNetworkCookie>()); } if (ui->cache->isChecked()) { clearCache(); } if (ui->databases->isChecked()) { clearWebDatabases(); } if (ui->localStorage->isChecked()) { clearLocalStorage(); } if (ui->icons->isChecked()) { clearIcons(); } QApplication::restoreOverrideCursor(); ui->clear->setEnabled(false); ui->clear->setText(tr("Done")); QTimer::singleShot(1000, this, SLOT(close())); }
HUrl::HUrl() { this->_set(QString(), QDateTime()); // Null QDateTime is not valid() }
/*! If \a time is \c CreationTime, return when the file was created. If \a time is \c ModificationTime, return when the file was most recently modified. If \a time is \c AccessTime, return when the file was most recently accessed (e.g. read or written). If the time cannot be determined return QDateTime() (an invalid date time). This virtual function must be reimplemented by all subclasses. \sa setFileName(), QDateTime, QDateTime::isValid(), FileTime */ QDateTime QAbstractFileEngine::fileTime(FileTime time) const { Q_UNUSED(time); return QDateTime(); }
QDateTime EPGItem::end() const { return QDateTime( m_start ).addSecs( m_duration ); }
/*! Sets minimum \a minDate and maximum \a maxDate dates in QDate format. This will allow user to set date range on datetime picker. \param minDate Minimum date in QDate format. \param maxDate Maximum date in QDate format. \sa setMinimumDate \sa setMaximumDate */ void HbDateTimePicker::setDateRange(const QDate &minDate, const QDate &maxDate) { Q_D(HbDateTimePicker); setDateTimeRange(QDateTime(minDate, d->mMinimumDate.time()), QDateTime(maxDate, d->mMaximumDate.time())); }
soundkonverter_codec_ffmpeg::soundkonverter_codec_ffmpeg( QObject *parent, const QStringList& args ) : CodecPlugin( parent ) { Q_UNUSED(args) binaries["ffmpeg"] = ""; KSharedConfig::Ptr conf = KGlobal::config(); KConfigGroup group; group = conf->group( "Plugin-"+name() ); configVersion = group.readEntry( "configVersion", 0 ); experimentalCodecsEnabled = group.readEntry( "experimentalCodecsEnabled", false ); ffmpegVersionMajor = group.readEntry( "ffmpegVersionMajor", 0 ); ffmpegVersionMinor = group.readEntry( "ffmpegVersionMinor", 0 ); ffmpegLastModified = group.readEntry( "ffmpegLastModified", QDateTime() ); ffmpegCodecList = group.readEntry( "codecList", QStringList() ).toSet(); CodecData data; FFmpegCodecData ffmpegData; // WARNING enabled codecs need to be rescanned everytime new codecs are added here -> increase plugin version data.ffmpegCodecList.clear(); data.codecName = "wav"; ffmpegData.name = "wav"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "ogg vorbis"; ffmpegData.name = "libvorbis"; ffmpegData.external = true; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); ffmpegData.name = "vorbis"; ffmpegData.external = true; // ? ffmpegData.experimental = true; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); // data.ffmpegCodecList.clear(); // data.codecName = "opus"; // ffmpegData.name = "opus"; // ffmpegData.external = true; // ffmpegData.experimental = false; // data.ffmpegCodecList.append( ffmpegData ); // codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "mp3"; ffmpegData.name = "libmp3lame"; ffmpegData.external = true; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "flac"; ffmpegData.name = "flac"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "wma"; ffmpegData.name = "wmav2"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); ffmpegData.name = "wmav1"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "aac"; ffmpegData.name = "libfaac"; ffmpegData.external = true; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); ffmpegData.name = "aac"; ffmpegData.external = false; ffmpegData.experimental = true; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "m4a/aac"; ffmpegData.name = "libfaac"; ffmpegData.external = true; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); ffmpegData.name = "aac"; ffmpegData.external = false; ffmpegData.experimental = true; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "ac3"; ffmpegData.name = "ac3"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "m4a/alac"; ffmpegData.name = "alac"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "mp2"; ffmpegData.name = "mp2"; ffmpegData.external = false; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); data.ffmpegCodecList.clear(); data.codecName = "amr nb"; ffmpegData.name = "libopencore_amrnb"; ffmpegData.external = true; ffmpegData.experimental = false; data.ffmpegCodecList.append( ffmpegData ); codecList.append( data ); // codecMap["sonic"] = "sonic"; // codecMap["sonic lossless"] = "sonicls"; // codecMap["real audio 1"] = "real_144"; // codecMap["e-ac3"] = "eac3"; for( int i=0; i<codecList.count(); i++ ) { for( int j=0; j<codecList.at(i).ffmpegCodecList.count(); j++ ) { if( !codecList.at(i).ffmpegCodecList.at(j).external && ( !codecList.at(i).ffmpegCodecList.at(j).experimental || experimentalCodecsEnabled ) ) { codecList[i].currentFFmpegCodec = codecList.at(i).ffmpegCodecList.at(j); break; } } } }
/*! Sets maximum \a time, to be set on datetime picker, in QTime format. \param time maximum time in QTime format \sa maximumTime */ void HbDateTimePicker::setMaximumTime(const QTime& time) { Q_D(HbDateTimePicker); setMaximumDateTime(QDateTime(d->mMaximumDate.date(), time)); }
int n; if((n=RDGetSqlValue("CUTS","CUT_NAME",cut_name,"END_POINT",cut_db). toInt())!=-1) { return n; } return (int)length(); } void RDCut::logPlayout() const { QString sql= QString().sprintf("update CUTS set LAST_PLAY_DATETIME=\"%s\",\ PLAY_COUNTER=%d,LOCAL_COUNTER=%d where CUT_NAME=\"%s\"", (const char *)QDateTime(QDate::currentDate(), QTime::currentTime()).toString("yyyy-MM-dd hh:mm:ss"), playCounter()+1,localCounter()+1,(const char *)cut_name); RDSqlQuery *q=new RDSqlQuery(sql); delete q; } bool RDCut::copyTo(RDStation *station,RDUser *user, const QString &cutname,RDConfig *config) const { #ifdef WIN32 return false; #else QString sql; RDSqlQuery *q; bool ret=true;
QDateTime KGPGFile::keyExpires(const QString& name) { Q_UNUSED(name); return QDateTime(); }
bool RDCut::isValid() const { return isValid(QDateTime(QDate::currentDate(),QTime::currentTime())); }
/*! * \reimp */ void QxtHttpSessionManager::processEvents() { if (QThread::currentThreadId() != qxt_d().mainThread) { QMetaObject::invokeMethod(this, "processEvents", Qt::QueuedConnection); return; } QxtHttpSessionManagerPrivate& d = qxt_d(); QMutexLocker locker(&d.eventLock); if (!d.eventQueue.count()) return; int ct = d.eventQueue.count(), sessionID = 0, requestID = 0, pagePos = -1; QxtWebRedirectEvent* re = 0; QxtWebPageEvent* pe = 0; for (int i = 0; i < ct; i++) { if (d.eventQueue[i]->type() != QxtWebEvent::Page && d.eventQueue[i]->type() != QxtWebEvent::Redirect) continue; pagePos = i; sessionID = d.eventQueue[i]->sessionID; if (d.eventQueue[pagePos]->type() == QxtWebEvent::Redirect) { re = static_cast<QxtWebRedirectEvent*>(d.eventQueue[pagePos]); } pe = static_cast<QxtWebPageEvent*>(d.eventQueue[pagePos]); requestID = pe->requestID; break; } if (pagePos == -1) return; // no pages to send yet QHttpResponseHeader header; QList<int> removeIDs; QxtWebEvent* e = 0; for (int i = 0; i < pagePos; i++) { if (d.eventQueue[i]->sessionID != sessionID) continue; e = d.eventQueue[i]; if (e->type() == QxtWebEvent::StoreCookie) { QxtWebStoreCookieEvent* ce = static_cast<QxtWebStoreCookieEvent*>(e); QString cookie = ce->name + '=' + ce->data; if (!ce->path.isEmpty()) cookie += "; path=" + ce->path; if (ce->expiration.isValid()) { cookie += "; max-age=" + QString::number(QDateTime::currentDateTime().secsTo(ce->expiration)) + "; expires=" + ce->expiration.toUTC().toString("ddd, dd-MMM-YYYY hh:mm:ss GMT"); } header.addValue("set-cookie", cookie); removeIDs.push_front(i); } else if (e->type() == QxtWebEvent::RemoveCookie) { QxtWebRemoveCookieEvent* ce = static_cast<QxtWebRemoveCookieEvent*>(e); QString path; if(!ce->path.isEmpty()) path = "path=" + ce->path + "; "; header.addValue("set-cookie", ce->name + "=; "+path+"max-age=0; expires=" + QDateTime(QDate(1970, 1, 1)).toString("ddd, dd-MMM-YYYY hh:mm:ss GMT")); removeIDs.push_front(i); } } removeIDs.push_front(pagePos); QIODevice* device = connector()->getRequestConnection(requestID); QxtWebContent* content = qobject_cast<QxtWebContent*>(device); // TODO: This should only be invoked when pipelining occurs // In theory it shouldn't cause any problems as POST is specced to not be pipelined if (content) content->ignoreRemainingContent(); QHash<QPair<int,int>,QxtWebRequestEvent*>::iterator iPending = qxt_d().pendingRequests.find(QPair<int,int>(sessionID, requestID)); if(iPending != qxt_d().pendingRequests.end()){ delete *iPending; qxt_d().pendingRequests.erase(iPending); } QxtHttpSessionManagerPrivate::ConnectionState& state = qxt_d().connectionState[connector()->getRequestConnection(requestID)]; QIODevice* source; header.setStatusLine(pe->status, pe->statusMessage, state.httpMajorVersion, state.httpMinorVersion); if (re) { header.setValue("location", re->destination); } // Set custom header values for (QMultiHash<QString, QString>::iterator it = pe->headers.begin(); it != pe->headers.end(); ++it) { header.setValue(it.key(), it.value()); } header.setContentType(pe->contentType); if (state.httpMajorVersion == 0 || (state.httpMajorVersion == 1 && state.httpMinorVersion == 0)) pe->chunked = false; source = pe->dataSource; state.finishedTransfer = false; bool emptyContent = !source->bytesAvailable() && !pe->streaming; state.readyRead = source->bytesAvailable(); state.streaming = pe->streaming; if (emptyContent) { header.setValue("connection", "close"); connector()->writeHeaders(device, header); closeConnection(requestID); } else { pe->dataSource = 0; // so that it isn't destroyed when the event is deleted state.clearHandlers(); // disconnect old handlers if (!pe->chunked) { state.keepAlive = false; state.onBytesWritten = QxtMetaObject::bind(this, SLOT(sendNextBlock(int, QObject*)), Q_ARG(int, requestID), Q_ARG(QObject*, source)); state.onReadyRead = QxtMetaObject::bind(this, SLOT(blockReadyRead(int, QObject*)), Q_ARG(int, requestID), Q_ARG(QObject*, source)); state.onAboutToClose = QxtMetaObject::bind(this, SLOT(closeConnection(int)), Q_ARG(int, requestID)); } else {
bool RDCut::isValid(const QTime &time) const { return isValid(QDateTime(QDate::currentDate(),time)); }
QString CustomEdit::evaluate(QString clause) { int s0=0; int e0=0; while (1) { s0 = clause.indexOf (QRegExp("\\{[A-Z]+\\}"), e0); if (s0 < 0) break; e0 = clause.indexOf ("}", s0); QString mid = clause.mid(s0 + 1, e0 - s0 - 1); QString repl = ""; if (!mid.compare("TITLE")) { repl = m_pginfo->GetTitle(); repl.replace("\'","\'\'"); } else if (!mid.compare("SUBTITLE")) { repl = m_pginfo->GetSubtitle(); repl.replace("\'","\'\'"); } else if (!mid.compare("DESCR")) { repl = m_pginfo->GetDescription(); repl.replace("\'","\'\'"); } else if (!mid.compare("SERIESID")) { repl = QString("%1").arg(m_pginfo->GetSeriesID()); } else if (!mid.compare("PROGID")) { repl = m_pginfo->GetProgramID(); } else if (!mid.compare("SEASON")) { repl = QString::number(m_pginfo->GetSeason()); } else if (!mid.compare("EPISODE")) { repl = QString::number(m_pginfo->GetEpisode()); } else if (!mid.compare("CATEGORY")) { repl = m_pginfo->GetCategory(); } else if (!mid.compare("CHANID")) { repl = QString("%1").arg(m_pginfo->GetChanID()); } else if (!mid.compare("CHANNUM")) { repl = m_pginfo->GetChanNum(); } else if (!mid.compare("SCHEDID")) { repl = m_pginfo->GetChannelSchedulingID(); } else if (!mid.compare("CHANNAME")) { repl = m_pginfo->GetChannelName(); } else if (!mid.compare("DAYNAME")) { repl = m_pginfo->GetScheduledStartTime().toString("dddd"); } else if (!mid.compare("STARTDATE")) { repl = m_pginfo->GetScheduledStartTime().toString("yyyy-mm-dd hh:mm:ss"); } else if (!mid.compare("ENDDATE")) { repl = m_pginfo->GetScheduledEndTime().toString("yyyy-mm-dd hh:mm:ss"); } else if (!mid.compare("STARTTIME")) { repl = m_pginfo->GetScheduledStartTime().toString("hh:mm"); } else if (!mid.compare("ENDTIME")) { repl = m_pginfo->GetScheduledEndTime().toString("hh:mm"); } else if (!mid.compare("STARTSEC")) { QDateTime date = m_pginfo->GetScheduledStartTime(); QDateTime midnight = QDateTime(date.date()); repl = QString("%1").arg(midnight.secsTo(date)); } else if (!mid.compare("ENDSEC")) { QDateTime date = m_pginfo->GetScheduledEndTime(); QDateTime midnight = QDateTime(date.date()); repl = QString("%1").arg(midnight.secsTo(date)); } // unknown tags are simply removed clause.replace(s0, e0 - s0 + 1, repl); } return clause; }
void OSCPacketDispatcher::dispatchMessage(OSCMessage& message, QHostAddress& address) { QDateTime dtimeNull = QDateTime(); dispatchMessage(message, address, dtimeNull); }
RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QList<RideFile*>*) const { if (!file.open(QFile::ReadOnly)) { errorStrings << QString("can't open file %1").arg(file.fileName()); return NULL; } QDataStream in(&file); in.setByteOrder( QDataStream::LittleEndian ); RideFile *result = new RideFile; result->setDeviceType("SRM"); result->setTag("Sport", "Bike" ); char magic[4]; in.readRawData(magic, sizeof(magic)); if( strncmp(magic, "SRM", 3)){ errorStrings << QString("Unrecognized file type, missing magic." ); return NULL; } int version = magic[3] - '0'; switch( version ){ case 5: case 6: case 7: // ok break; default: errorStrings << QString("Unsupported SRM file format version: %1") .arg(version); return NULL; } quint16 dayssince1880 = readShort(in); quint16 wheelcirc = readShort(in); quint8 recint1 = readByte(in); quint8 recint2 = readByte(in); quint16 blockcnt = readShort(in); quint16 markercnt = readShort(in); readByte(in); // padding quint8 commentlen = readByte(in); if( commentlen > 70 ) commentlen = 70; char comment[71]; in.readRawData(comment, sizeof(comment) - 1); comment[commentlen] = '\0'; result->setTag("Notes", QString(comment) ); // assert propper markercnt to avoid segfaults if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read file header" ); return NULL; } result->setRecIntSecs(((double) recint1) / recint2); unsigned recintms = (unsigned) round(result->recIntSecs() * 1000.0); result->setTag("Wheel Circumference", QString("%1").arg(wheelcirc) ); QDate date(1880, 1, 1); date = date.addDays(dayssince1880); QVector<marker> markers(markercnt + 1); for (int i = 0; i <= markercnt; ++i) { char mcomment[256]; size_t mcommentlen = version < 6 ? 3 : 255; assert( mcommentlen < sizeof(mcomment) ); in.readRawData(mcomment, mcommentlen ); mcomment[mcommentlen] = '\0'; quint8 active = readByte(in); quint16 start = readShort(in); quint16 end = readShort(in); quint16 avgwatts = readShort(in); quint16 avghr = readShort(in); quint16 avgcad = readShort(in); quint16 avgspeed = readShort(in); quint16 pwc150 = readShort(in); // data fixup: Although the data chunk index in srm files starts // with 1, some srmwin wrote files referencing index 0. if( end < 1 ) end = 1; if( start < 1 ) start = 1; // data fixup: some srmwin versions wrote markers with start > end if( end < start ){ markers[i].start = end; markers[i].end = start; } else { markers[i].start = start; markers[i].end = end; } markers[i].note = QString( mcomment); if( i == 0 ){ result->setTag("Athlete Name", QString(mcomment) ); } (void) active; (void) avgwatts; (void) avghr; (void) avgcad; (void) avgspeed; (void) pwc150; (void) wheelcirc; } // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read marker" ); return NULL; } blockhdr *blockhdrs = new blockhdr[blockcnt+1]; for (int i = 0; i < blockcnt; ++i) { // In the .srm files generated by Rainer Clasen's srmcmd, // hsecsincemidn is a *signed* 32-bit integer. I haven't seen a // negative value in any .srm files generated by srmwin.exe, but // since the number of hundredths of a second in a day is << 2^31, // it seems safe to always treat this number as signed. qint32 hsecsincemidn = readLong(in); blockhdrs[i].chunkcnt = readShort(in); blockhdrs[i].dt = QDateTime(date); blockhdrs[i].dt = blockhdrs[i].dt.addMSecs(hsecsincemidn * 10); } // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read block headers" ); return NULL; } quint16 zero = readShort(in); quint16 slope = readShort(in); quint16 datacnt = readShort(in); readByte(in); // padding // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read calibration data" ); return NULL; } result->setTag("Slope", QString("%1") .arg( 140.0 / 42781 * slope, 0, 'f', 2) ); result->setTag("Zero Offset", QString("%1").arg(zero) ); // SRM5 files have no blocks - synthesize one if( blockcnt < 1 ){ blockcnt = 0; blockhdrs[0].chunkcnt = datacnt; blockhdrs[0].dt = QDateTime(date); } int blknum = 0, blkidx = 0, mrknum = 0, interval = 0; double km = 0.0, secs = 0.0; if (markercnt > 0) mrknum = 1; for (int i = 0; i < datacnt; ++i) { int cad, hr, watts; double kph, alt; double temp=-255; if (version < 7) { quint8 ps[3]; in.readRawData((char*) ps, sizeof(ps)); cad = readByte(in); hr = readByte(in); kph = (((((unsigned) ps[1]) & 0xf0) << 3) | (ps[0] & 0x7f)) * 3.0 / 26.0; watts = (ps[1] & 0x0f) | (ps[2] << 0x4); alt = 0.0; } else { assert(version == 7); watts = readShort(in); cad = readByte(in); hr = readByte(in); qint32 kph_tmp = readSignedLong(in); kph = kph_tmp < 0 ? 0 : kph_tmp * 3.6 / 1000.0; alt = readSignedLong(in); temp = 0.1 * readSignedShort(in); } if (i == 0) { result->setStartTime(blockhdrs[blknum].dt); } if (mrknum < markers.size() && i == markers[mrknum].end) { ++interval; ++mrknum; } // markers count from 1 if ((i > 0) && (mrknum < markers.size()) && (i == markers[mrknum].start - 1)) ++interval; km += result->recIntSecs() * kph / 3600.0; double nm = watts / 2.0 / PI / cad * 60.0; result->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, 0.0, 0.0, 0.0, 0.0, temp, 0.0, interval); ++blkidx; if ((blkidx == blockhdrs[blknum].chunkcnt) && (blknum + 1 < blockcnt)) { QDateTime end = blockhdrs[blknum].dt.addMSecs( recintms * blockhdrs[blknum].chunkcnt); ++blknum; blkidx = 0; QDateTime start = blockhdrs[blknum].dt; qint64 endms = ((qint64) end.toTime_t()) * 1000 + end.time().msec(); qint64 startms = ((qint64) start.toTime_t()) * 1000 + start.time().msec(); double diff_secs = (startms - endms) / 1000.0; if (diff_secs < result->recIntSecs()) { errorStrings << QString("ERROR: time goes backwards by %1 s" " on trans " "to block %2" ).arg(diff_secs).arg(blknum); secs += result->recIntSecs(); // for lack of a better option } else { secs += diff_secs; } } else { secs += result->recIntSecs(); } } // assert some points were found. prevents segfault when looking at // the overall markers[0].start/.end // note: we're not checking in.status() to cope with truncated files if( result->dataPoints().size() < 1 ){ errorStrings << QString("file contains no data points"); return NULL; } double last = 0.0; for (int i = 1; i < markers.size(); ++i) { const marker &marker = markers[i]; int start = marker.start - 1; double start_secs = result->dataPoints()[start]->secs; int end = qMin(marker.end - 1, result->dataPoints().size() - 1); double end_secs = result->dataPoints()[end]->secs + result->recIntSecs(); if( last < start_secs ) result->addInterval(last, start_secs, ""); QString note = QString("%1").arg(i); if( marker.note.length() ) note += QString(" ") + marker.note; result->addInterval(start_secs, end_secs, note ); last = end_secs; } if (!markers.empty() && markers.last().end < result->dataPoints().size()) { double start_secs = result->dataPoints().last()->secs + result->recIntSecs(); result->addInterval(last, start_secs, ""); } file.close(); return result; }
const QDateTime CollectionConfiguration::lastRegisterTime(const QHelpEngineCore &helpEngine) { return helpEngine.customValue(LastRegisterTime, QDateTime()).toDateTime(); }