/*! Retrieves a month name from Symbian locale. The \a month is an integer from 1 to 12. When \a short_format is true the method returns the month in short format. Otherwise it returns the month in a long format. */ static QString symbianMonthName(int month, bool short_format) { month -= 1; if (month < 0 || month > 11) return QString(); if (short_format) { return qt_TDes2QString(TMonthNameAbb(TMonth(month))); } else { return qt_TDes2QString(TMonthName(TMonth(month))); } }
/** Gets the month of the year for this repeat rule. This function will do nothing if this is not a yearly repeat rule @param aMonths On return, the months on which to repeat. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::GetByMonthL(RArray<TMonth>& aMonths) const { if (iType == EYearly) { aMonths.Reset(); if (GetNthBit(KYearlyByWeek)) { TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s TMonth theMonth = TMonth(bufferPtr[2]-1); // -1 because EJanuary stored as 1 if (theMonth >= EJanuary && theMonth <= EDecember) { aMonths.AppendL(theMonth); } } } }
QList<CContactItemField *> CntTransformBirthday::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactBirthday::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to birthday const QContactBirthday &birthday(static_cast<const QContactUrl&>(detail)); //create new field TDateTime dateTime(birthday.date().year(), TMonth(birthday.date().month() - 1), birthday.date().day() - 1, 0, 0, 0, 0); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldBirthday); newField->DateTimeStorage()->SetTime(dateTime); newField->SetMapping(KUidContactFieldVCardMapBDAY); fieldList.append(newField); CleanupStack::Pop(newField); return fieldList; }
/*! Returns localized string representation of given \a date formatted with Symbian locale date format. If \a short_format is true the format will be a short version. Otherwise it uses a longer version. */ static QString symbianDateToString(const QDate &date, bool short_format) { int month = date.month() - 1; int day = date.day() - 1; int year = date.year(); TDateTime dateTime; dateTime.Set(year, TMonth(month), day, 0, 0, 0, 0); TTime timeStr(dateTime); TBuf<KMaxLongDateFormatSpec*2> buffer; TPtrC dateFormat; if (short_format) { dateFormat.Set(ptrGetShortDateFormatSpec(_s60Locale)); } else { dateFormat.Set(ptrGetLongDateFormatSpec(_s60Locale)); } TRAPD(err, ptrTimeFormatL(timeStr, buffer, dateFormat, *_s60Locale.GetLocale());) if (err == KErrNone)
QList<CContactItemField *> CntTransformAnniversarySimple::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactAnniversary::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to anniversary const QContactAnniversary &anniversary(static_cast<const QContactAnniversary&>(detail)); //create new field TDateTime dateTime(anniversary.originalDate().year(), TMonth(anniversary.originalDate().month() - 1), anniversary.originalDate().day() - 1, 0, 0, 0, 0); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldAnniversary); newField->DateTimeStorage()->SetTime(dateTime); newField->SetMapping(KUidContactFieldVCardMapAnniversary); fieldList.append(newField); CleanupStack::Pop(newField); return fieldList; }
void CTestAgendaAddAppt::AddEntriesL( void ) { TInt count=1; if ( !GetIntFromConfig(ConfigSection(), KCount, count) ) count=1; TBuf<KMaxTestExecuteCommandLength> tempStore; TInt year; TInt month; TInt day; TInt hour; TInt minute; TInt duration; TInt alarm; TPtrC ptrAlarmSound; TPtrC ptrMessage; TBuf<KMaxDateStringLength> dateString; _LIT(KDateString,"%*E%*D%X%*N%*Y %1 %2 '%3"); RPointerArray<CCalEntry> array; CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array)); for (TInt entry=0; entry<count && TestStepResult() == EPass; ) { TTime today; today.HomeTime(); tempStore.Format(KYear(), ++entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, year) ) year=today.DateTime().Year(); tempStore.Format(KMonth(), entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, month) ) month=today.DateTime().Month(); tempStore.Format(KDay(), entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, day) ) day=today.DateTime().Day(); else --day; tempStore.Format(KHour(), entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, hour) ) hour=today.DateTime().Hour(); tempStore.Format(KMinute(), entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, minute) ) minute=0; tempStore.Format(KDuration(), entry); if ( !GetIntFromConfig(ConfigSection(), tempStore, duration) ) duration=30; tempStore.Format(KMessage(), entry); GetStringFromConfig(ConfigSection(), tempStore, ptrMessage); TTime startTime(TDateTime(year, TMonth(month-1+EJanuary), day, hour, minute,0,0)); startTime.FormatL(dateString,KDateString); INFO_PRINTF2(_L("Start date is %S"), &dateString); TTime endTime = startTime + TTimeIntervalMinutes(duration); endTime.FormatL(dateString,KDateString); INFO_PRINTF2(_L("End date is %S"), &dateString); HBufC8* uid = HBufC8::NewLC(255); TPtr8 uidP = uid->Des(); uidP.Append(count); CCalEntry* calEntry = CCalEntry::NewL(CCalEntry::EAppt, uid, CCalEntry::EMethodNone, 0); CleanupStack::Pop(); //uid CleanupStack::PushL(calEntry); TCalTime calStartTime, calEndTime; calStartTime.SetTimeLocalL(startTime); calEndTime.SetTimeLocalL(endTime); calEntry->SetStartAndEndTimeL(calStartTime, calEndTime); tempStore.Format(KAlarm(), entry); if ( GetIntFromConfig(ConfigSection(), tempStore, alarm) ) { TTimeIntervalMinutes currentTime((hour*60) + minute); TTimeIntervalMinutes alarmTime(currentTime.Int()); CCalAlarm* calAlarm = CCalAlarm::NewL(); CleanupStack::PushL(calAlarm); calAlarm->SetTimeOffset(alarmTime); tempStore.Format(KAlarmSound(), entry); if ( GetStringFromConfig(ConfigSection(), tempStore, ptrAlarmSound) ) calAlarm->SetAlarmSoundNameL(ptrAlarmSound); else calAlarm->SetAlarmSoundNameL(_L("Bells")); calEntry->SetAlarmL(calAlarm); CleanupStack::PopAndDestroy(); //calAlarm } //Store in the array array.AppendL(calEntry); CleanupStack::Pop(); //calEntry } INFO_PRINTF1(_L("About to store appointments now")); TInt success(0); TRAPD(storeError, iCalEntryViewBase->StoreL(array, success)); INFO_PRINTF2(_L("Store result is %d"), storeError); if (success != count && storeError == KErrNone) { SetTestStepResult(EFail); } CleanupStack::PopAndDestroy(&array); }
void CAzqBtGPSReader::RunL() { iCallbackTimer->Cancel(); switch(iState) { case ENoState: break; case EInquiringDevices: { if( iStatus !=KErrNone) { iHostResolver.Close(); if(iStatus == KErrHostResNoMoreResults) { { iGPSData.Reset(); _LIT(KGPSStateUpdate,"BT GPS Search finished..."); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } //choose and connect to BT GPS modules if(iBtGPSArray.Count()>0) { User::LeaveIfError(iSendingSocket.Open(iSocketServer,RFCOMM)); TBTSockAddr address; address.SetBTAddr(iBtGPSArray[0]); // GPS devices usually use port 1 as data channel // so we don't have to query it address.SetPort(1); { iGPSData.Reset(); iState = EConnecting; _LIT(KGPSStateUpdate,"Trying to connect to first device"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } iSendingSocket.Connect(address, iStatus); SetActive(); ResetBtTimer(); } else { { iGPSData.Reset(); iState = ENoState; _LIT(KGPSStateUpdate,"No BT GPS. Retry press 9"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } } } else { { iGPSData.Reset(); iState = ENoState; _LIT(KGPSStateUpdate,"Search failed. Retry press 9"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } } } else { TInquirySockAddr &addr = TInquirySockAddr::Cast(iNameEntry().iAddr); if(addr.MajorClassOfDevice() == KBtGPSMajorClass) { //add to array... iBtGPSArray.AppendL(addr.BTAddr()); { iGPSData.Reset(); _LIT(KGPSStateUpdate,"Found %d BT GPS, Searching..."); TBuf<128> buf; buf.Format(KGPSStateUpdate, iBtGPSArray.Count()); iObserver.OnGPSStateUpdate(buf,iGPSData ); } } ///////////get next device iState = EInquiringDevices; iHostResolver.Next(iNameEntry, iStatus); SetActive(); ResetBtTimer(); /////////////////////////////////// } } break; case EConnecting: { if( iStatus !=KErrNone) { //remove previous device from array if(iBtGPSArray.Count()>0) { iBtGPSArray.Remove(0); } //if more gps devices remaining to try if(iBtGPSArray.Count()>0) { //socket alraedy opened... TBTSockAddr address; address.SetBTAddr(iBtGPSArray[0]); // GPS devices usually use port 1 as data channel // so we don't have to query it address.SetPort(1); iState = EConnecting; { iGPSData.Reset(); _LIT(KGPSStateUpdate,"Connecting next device"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } iSendingSocket.Connect(address, iStatus); SetActive(); ResetBtTimer(); } else//finished list { { iGPSData.Reset(); iState = ENoState; _LIT(KGPSStateUpdate,"Connect GPS failed. Retry press 9"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } iSendingSocket.Close(); } } else { iState = EReading; { _LIT(KGPSStateUpdate,"Reading GPS data..."); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } iWaitGPSReadyRetry = 0; //only related if iSyncTimeWhenValid is ETrue line.Zero(); iLineHeadReceivedTime = 0;//just to make sure it's fresh iSendingSocket.RecvOneOrMore(data, 0, iStatus, iReadDataLength); SetActive(); ResetBtTimer(); } } break; case EReading: { if( iStatus !=KErrNone) { { iGPSData.Reset(); iState = ENoState; _LIT(KGPSStateUpdate,"Read GPS failed. Retry press 9"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } iSendingSocket.Close(); return; } iState = EReadComplete; iGPSData.Reset();//prepare for new data int rpos = 0; while ((rpos = data.Locate('\r')) != KErrNotFound) { TPtrC8 leftr(0,0); leftr.Set(data.Left(rpos)); TInt leftrlen = leftr.Length(); if(leftrlen + line.Length() < line.MaxLength()) { if(line.Length()==0) iLineHeadReceivedTime.HomeTime(); line.Append(leftr); } else { line.Zero(); if(leftrlen + line.Length() < line.MaxLength()) { //if(line.Length()==0) sure it is, see above lines iLineHeadReceivedTime.HomeTime(); line.Append(leftr); } } if(rpos+1<data.Length()) { data.Copy(data.Mid(rpos+1)); if(data[0] == '\n') data.Delete(0,1); } else { data.Zero(); } TGPSData gpsdata; TTimeIntervalMicroSeconds proctime; if(iLineHeadReceivedTime == TTime(0))//just in case... { iLineHeadReceivedTime.HomeTime(); CAknWarningNote* informationNote = new (ELeave) CAknWarningNote(ETrue); //informationNote->SetTimeout(CAknNoteDialog::EShortTimeout); _LIT(KConfirmText,"Warning: No read-offset time correction"); informationNote->ExecuteLD(KConfirmText); } if(gpsdata.ParseGPSInput(line,iLineHeadReceivedTime,proctime)) { if((gpsdata.POS_STAT.Length() == 0) || (gpsdata.POS_STAT.Length()>0 && gpsdata.POS_STAT[0]!='A'))//if data NOT valid { ///////////////BEGIN parsed but NOT valid data if(iSyncTimeWhenValid)//if the NetMonview is in the "Awaiting Fresh GPS Params State for the first time of session - needs time sync" { if(iWaitGPSReadyRetry>=KMaxWaitGPSReadyRetries) { //max retries finished, notify as in EReadcomplete state as set by above _LIT(KGPSStateUpdate,"GPS Connected but Not Ready"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); iSyncTimeWhenValid = EFalse; } else { //don't notify as in EReadcomplete state yet... iState = EReading; iWaitGPSReadyRetry++; TBuf<64> buf; _LIT(KGPSStateUpdateFormat,"GPS NotReady: TimeSync retry %d/%d"); buf.Format(KGPSStateUpdateFormat,iWaitGPSReadyRetry,KMaxWaitGPSReadyRetries); iObserver.OnGPSStateUpdate(buf,iGPSData ); } } else { _LIT(KGPSStateUpdate,"GPS Connected but Not Ready"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); } //latdeg = londeg = latmin = lonmin = latsec = lonsec = 0; line.Zero(); if(data.Length()>0) { if(line.Length() + data.Length() < line.MaxLength()) { iLineHeadReceivedTime.HomeTime(); line.Append(data); } else { line.Zero(); if(line.Length() + data.Length() < line.MaxLength()) { //line is zero len from line.Zero() above iLineHeadReceivedTime.HomeTime(); line.Append(data); } } } data.Zero(); iState = EReading; iSendingSocket.RecvOneOrMore(data, 0, iStatus, iReadDataLength); SetActive(); ResetBtTimer(); return; ///////////////END not valid } ////////// boyond here is the VALID case ////////////set device's UTC time if(iSyncTimeWhenValid) { TTime devTime; devTime.HomeTime(); TDateTime dt = devTime.DateTime(); if(gpsdata.POS_UTC.Length() < 6 || gpsdata.DATE.Length() < 6) { //line not ready/full... do nothing } else { //All NMEA chars are ASCII dt.SetHour((gpsdata.POS_UTC[0]-48)*10+(gpsdata.POS_UTC[1]-48)); dt.SetMinute((gpsdata.POS_UTC[2]-48)*10+(gpsdata.POS_UTC[3]-48)); dt.SetSecond((gpsdata.POS_UTC[4]-48)*10+(gpsdata.POS_UTC[5]-48)); dt.SetDay((gpsdata.DATE[0]-48)*10+(gpsdata.DATE[1]-48) -1); dt.SetMonth(TMonth((gpsdata.DATE[2]-48)*10+(gpsdata.DATE[3]-48) -1)); dt.SetYear((gpsdata.DATE[4]-48)*10+(gpsdata.DATE[5]-48)+KY2K); if(gpsdata.POS_UTC.Length()>9 && gpsdata.POS_UTC.Find(_L8("."))>0) { dt.SetMicroSecond((gpsdata.POS_UTC[7]-48)*KONEHUNDREDTHOUSAND+(gpsdata.POS_UTC[8]-48)*KTENTHOUSAND+(gpsdata.POS_UTC[9]-48)*1000); } devTime = dt; devTime += proctime; #ifdef EKA2 User::SetUTCTime(devTime); #else //TODO: detect timezone and add accordingly TTime hometime(devTime); hometime += TTimeIntervalHours(7); User::SetHomeTime(hometime); #endif iSyncTimeWhenValid = EFalse; CAknConfirmationNote* informationNote = new (ELeave) CAknConfirmationNote(EFalse); //informationNote->SetTimeout(CAknNoteDialog::EShortTimeout); _LIT(KConfirmText,"GPS TimeSync Successful"); informationNote->ExecuteLD(KConfirmText); //TODO: report to scheduler that device time has changed? OR let scheduler detect device time change? } } ///////////////////////// //SET LAT LON values... TBuf<1> ref; if(gpsdata.LAT.Length() < iGPSData.iLat.MaxLength() && gpsdata.LAT_REF.Length()==1) { iGPSData.iLat.Copy(gpsdata.LAT); ref.Zero(); ref.Copy(gpsdata.LAT_REF); iGPSData.iLat+=ref; } if(gpsdata.LON.Length() < iGPSData.iLon.MaxLength() && gpsdata.LON_REF.Length()==1) { iGPSData.iLon.Copy(gpsdata.LON); ref.Zero(); ref.Copy(gpsdata.LON_REF); iGPSData.iLon+=ref; } _LIT(KGPSStateUpdate,"Connected to GPS"); iObserver.OnGPSStateUpdate(KGPSStateUpdate,iGPSData ); }//END if gps parsed line.Zero(); } if(data.Length()>0) { if(line.Length() + data.Length() < line.MaxLength()) { if(line.Length()==0) //if not appending data to previous line iLineHeadReceivedTime.HomeTime(); line.Append(data); } else { line.Zero(); if(line.Length() + data.Length() < line.MaxLength()) { //if(line.Length()==0) sure it is, see above lines iLineHeadReceivedTime.HomeTime(); line.Append(data); } } } data.Zero(); iState = EReading; iSendingSocket.RecvOneOrMore(data, 0, iStatus, iReadDataLength); SetActive(); ResetBtTimer(); } break; } }