コード例 #1
0
ファイル: oevent.cpp プロジェクト: opieproject/opie
QString OEvent::toRichText()const {
    QString text, value;

    // description
    text += "<b><h3><img src=\"datebook/DateBook\">";
    if ( !description().isEmpty() ) {
        text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"),  "" );
    }
    text += "</h3></b><br><hr><br>";

    // location
    if ( !(value = location()).isEmpty() ) {
        text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
        text += Qtopia::escapeString(value) + "<br>";
    }

    // all day event
    if ( isAllDay() ) {
        text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
    }
    // multiple day event
    else if ( isMultipleDay () ) {
        text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
    }
    // start & end times
    else {
        // start time
        if ( startDateTime().isValid() ) {
            text += "<b>" + QObject::tr( "Start:") + "</b> ";
            text += Qtopia::escapeString(startDateTime().toString() ).
                    replace(QRegExp( "[\n]"),  "<br>" ) + "<br>";
        }

        // end time
        if ( endDateTime().isValid() ) {
            text += "<b>" + QObject::tr( "End:") + "</b> ";
            text += Qtopia::escapeString(endDateTime().toString() ).
                    replace(QRegExp( "[\n]"),  "<br>" ) + "<br>";
        }
    }

    // categories
    if ( categoryNames("Calendar").count() ){
	    text += "<b>" + QObject::tr( "Category:") + "</b> ";
	    text += categoryNames("Calendar").join(", ");
	    text += "<br>";
    }

    //notes
    if ( !note().isEmpty() ) {
        text += "<b>" + QObject::tr( "Note:") + "</b><br>";
        text += note();
//         text += Qtopia::escapeString(note() ).
//                 replace(QRegExp( "[\n]"),  "<br>" ) + "<br>";
    }
    return text;
}
コード例 #2
0
ファイル: oevent.cpp プロジェクト: opieproject/opie
QString OEvent::toShortText()const {
    QString text;
    text += QString::number( startDateTime().date().day() );
    text += ".";
    text += QString::number( startDateTime().date().month() );
    text += ".";
    text += QString::number( startDateTime().date().year() );
    text += " ";
    text += QString::number( startDateTime().time().hour() );
    text += ":";
    text += QString::number( startDateTime().time().minute() );
    text += " - ";
    text += description();
    return text;
}
コード例 #3
0
ファイル: MGPWorkitem.cpp プロジェクト: nagyistge/mesa
void MGPWorkitem::import(const MDomainObject& o)
{
  SOPInstanceUID(o.value("sopinsuid")); 
  SOPClassUID(o.value("sopclassuid")); 
  status(o.value("status")); 
  inputAvailabilityFlag(o.value("inputavailflag")); 
  priority(o.value("priority")); 
  procedureStepID(o.value("procstepid")); 
  startDateTime(o.value("startdattim")); 
  endDateTime(o.value("enddattim")); 
  resultStudyInstanceUID(o.value("resultstuinsuid")); 
  inputStudyInstanceUID(o.value("inputstuinsuid")); 
  multipleCopiesFlag(o.value("multcopyflag")); 
  description(o.value("description")); 
  patientID(o.value("patientid")); 
  patientName(o.value("patientname")); 
  patientBirthDate(o.value("birthdate")); 
  patientSex(o.value("sex")); 
  workItemCodeValue(o.value("workitemcodevalue")); 
  workItemCodeScheme(o.value("workitemcodescheme")); 
  workItemCodeMeaning(o.value("workitemcodemeaning")); 
  requestedProcAccessionNum(o.value("reqprocAccessionNum"));
  requestedProcID(o.value("reqprocID"));
  requestedProcDesc(o.value("reqprocDesc"));
  requestedProcCodevalue(o.value("reqprocCodevalue"));
  requestedProcCodemeaning(o.value("reqprocCodemeaning"));
  requestedProcCodescheme(o.value("reqprocCodescheme"));
  requestingPhysician(o.value("requestingPhys"));
  transactionUID(o.value("transactionUID"));
}
コード例 #4
0
void Character::SaveCharacter()
{
    _log( ITEM__TRACE, "Saving character %u.", itemID() );

    sLog.Debug( "Character::SaveCharacter()", "Saving all character info and skill attribute info to DB for character %s...", itemName().c_str() );
    // character data
    m_factory.db().SaveCharacter(
        itemID(),
        CharacterData(
            accountID(),
            title().c_str(),
            description().c_str(),
            gender(),
            bounty(),
            balance(),
            securityRating(),
            logonMinutes(),
            corporationID(),
            allianceID(),
            warFactionID(),
            stationID(),
            solarSystemID(),
            constellationID(),
            regionID(),
            ancestryID(),
            careerID(),
            schoolID(),
            careerSpecialityID(),
            startDateTime(),
            createDateTime(),
            corporationDateTime()
        )
    );

    // corporation data
    m_factory.db().SaveCorpMemberInfo(
        itemID(),
        CorpMemberInfo(
            corporationHQ(),
            corpRole(),
            rolesAtAll(),
            rolesAtBase(),
            rolesAtHQ(),
            rolesAtOther()
        )
    );

    // Save this character's own attributes:
    SaveAttributes();

    // Loop through all skills and invoke mAttributeMap.SaveAttributes() for each
    std::vector<InventoryItemRef> skills;
    GetSkillsList( skills );
    std::vector<InventoryItemRef>::iterator cur, end;
    cur = skills.begin();
    end = skills.end();
    for(; cur != end; cur++)
        cur->get()->SaveAttributes();
        //cur->get()->mAttributeMap.Save();
}
コード例 #5
0
void CGUIDialogBoxeeLiveTvCtx::LoadTimeSlot()
{
  time_t startTime;
  time_t endTime;
  struct tm *loctime;

  m_model.GetCurrentTimeSlot(startTime, endTime);

  CStdString timeSlotStr = "[B]";
  if (startTime == 0)
  {
    timeSlotStr += "NOW";
  }
  else
  {
    loctime = localtime(&startTime);
    CDateTime startDateTime(*loctime);
    timeSlotStr += startDateTime.GetAsLocalizedTime("", false);
  }

  timeSlotStr += " - ";

  loctime = localtime(&endTime);
  CDateTime endDateTime(*loctime);
  timeSlotStr += endDateTime.GetAsLocalizedTime("", false);

  timeSlotStr += "[/B]";

  SET_CONTROL_LABEL(CONTROL_LABEL_EPG,timeSlotStr);
}
コード例 #6
0
ファイル: Event.cpp プロジェクト: MichaelRyanWebber/Charm
void Event::dump() const
{
    qDebug() << "[Event" << id() << "] - task "
             << taskId()
             << " - start: " << startDateTime()
             << " - end: " << endDateTime()
             << " - duration: " << duration()
             << "seconds - comment:" << comment();
}
コード例 #7
0
ファイル: Event.cpp プロジェクト: MichaelRyanWebber/Charm
bool Event::operator == ( const Event& other ) const
{
    return ( other.id() == id()
             && other.installationId() == installationId()
             && other.taskId() == taskId()
             && other.comment() == comment()
             && other.startDateTime() ==  startDateTime()
             && other.endDateTime() == endDateTime()
             && other.userId() == userId()
             && other.reportId() == reportId() );
}
コード例 #8
0
void RecurrenceWidget::set(bool recurring, int frequency, QString period, QDate startDate, QDate endDate, int max)
{
  if (DEBUG)
    qDebug() << objectName() << "::set(" << recurring << ", "
             << frequency    << ", "     << period    << ", "
             << startDate    << ", "     << endDate   << ", "
             << max          << ") entered";
  // run from the beginning of the start date to the end of the end date
  QDateTime startDateTime(startDate);
  QDateTime endDateTime(endDate.addDays(1));
  endDateTime = endDateTime.addMSecs(-1);

  set(recurring, frequency, period, startDateTime, endDateTime, max);
}
コード例 #9
0
ファイル: oevent.cpp プロジェクト: opieproject/opie
// Exporting Event data to map. Using the same
// encoding as ODateBookAccessBackend_xml does..
// Thus, we could remove the stuff there and use this
// for it and for all other places..
// Encoding should happen at one place, only ! (eilers)
QMap<int, QString> OEvent::toMap()const {
    QMap<int, QString> retMap;

    retMap.insert( OEvent::FUid, QString::number( uid() ) );
    retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
    retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
    retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
    retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
    OPimAlarm alarm = notifiers().alarms()[0];
    retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo(  startDateTime() ) / 60 ) );
    retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );

    OTimeZone zone(  timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
    retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime(  startDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime(  endDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
    retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
    if( parent() )
	    retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
    if( children().count() ){
            QArray<int> childr = children();
	    QString buf;
            for ( uint i = 0; i < childr.count(); i++ ) {
		    if ( i != 0 ) buf += " ";
		    buf += QString::number( childr[i] );
            }
	    retMap.insert( OEvent::FRecChildren, buf );
    }

    // Add recurrence stuff
    if( hasRecurrence() ){
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
	    retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
	    retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
	    retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
	    retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
	    retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
	    retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
	    retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
    } else {
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
    }

    return retMap;
}
コード例 #10
0
bool RecurrenceWidget::modified() const
{
  if (DEBUG)
    qDebug() << "recurring:"     << isRecurring()  << _prevRecurring     << "\n"
             << "period:"        << period()       << _prevPeriod        << "\n"
             << "frequency:"     << frequency()    << _prevFrequency     << "\n"
             << "startDateTime:" << startDateTime()<< _prevStartDateTime << "\n"
             << "endDateTime:"   << endDateTime()  << _prevEndDateTime   << "\n"
             << "max:"           << max()          << _prevMax           << "\n"
             << "_parentId:"     << _parentId      << _prevParentId      << "\n"
             << "_parentType:"   << _parentType    << _prevParentType
             ;

  bool returnVal = (isRecurring()   != _prevRecurring    ||
                    period()        != _prevPeriod       ||
                    frequency()     != _prevFrequency    ||
                    startDateTime() != _prevStartDateTime||
                    endDateTime()   != _prevEndDateTime  ||
                    max()           != _prevMax          ||
                    _parentId       != _prevParentId     ||
                    _parentType     != _prevParentType);

  return returnVal;
}
コード例 #11
0
ファイル: Character.cpp プロジェクト: AlTahir/Apocrypha_combo
void Character::SaveCharacter() const
{
    _log( ITEM__TRACE, "Saving character %u.", itemID() );

    // character data
    m_factory.db().SaveCharacter(
        itemID(),
        CharacterData(
            accountID(),
            title().c_str(),
            description().c_str(),
            gender(),
            bounty(),
            balance(),
            securityRating(),
            logonMinutes(),
            corporationID(),
            allianceID(),
			warFactionID(),
            stationID(),
            solarSystemID(),
            constellationID(),
            regionID(),
            ancestryID(),
            careerID(),
            schoolID(),
            careerSpecialityID(),
            startDateTime(),
            createDateTime(),
            corporationDateTime()
        )
    );

    // corporation data
    m_factory.db().SaveCorpMemberInfo(
        itemID(),
        CorpMemberInfo(
            corporationHQ(),
            corpRole(),
            rolesAtAll(),
            rolesAtBase(),
            rolesAtHQ(),
            rolesAtOther()
        )
    );
}
コード例 #12
0
//
// Calculate Start Time of TimeAlignment (UTC)
//
void CTzDbStdTimeAlignment::CalculateStartTime(TTime& aStartTime)
  	{
  	TInt startYear;
  	TInt startMonth;
  	TInt startDay;
  	TInt startHour;
  	TInt startMinute;
  	TInt startSecond = 0;
  	TInt startMicrosecond = 0;
  	
  	if (iPrevTimeAlignment == NULL)
  		{
  		aStartTime = 0;
  		}
  	else
  		{
  		startYear = iPrevTimeAlignment->iUntilYear;
  		startMonth = iPrevTimeAlignment->iUntilMonth; if (startMonth == (TInt)KMaxTUint8) startMonth = EJanuary;
  		startDay = iPrevTimeAlignment->iUntilDayOfMonth; if (startDay == (TInt)KMaxTUint8) startDay = 0;
  		if (iPrevTimeAlignment->iUntilTimeInMinutes == KMaxTUint16)
  			{
  			startHour = startMinute = 0;
  			}
  		else
  			{
  			startHour = iPrevTimeAlignment->iUntilTimeInMinutes / 60;
  			startMinute = iPrevTimeAlignment->iUntilTimeInMinutes % 60;
  			}
  
  		TDateTime startDateTime(startYear,(TMonth)startMonth,startDay,startHour,startMinute,startSecond,startMicrosecond);
  		aStartTime = startDateTime;
		// convert time to UTC
		TTzTimeReference taTimeReference(static_cast<TTzTimeReference>(iPersistedEntity.iUntilTimeReference) );
		if (taTimeReference == ETzStdTimeReference)
			{
			aStartTime -= static_cast<TTimeIntervalMinutes>(iPersistedEntity.iUtcOffset);
			}		
  		}		
  	}
コード例 #13
0
TInt CTzDbRuleSet::GetLocalTimeOffsetAtEndOfYearL(TInt aYear, TInt aUtcOffset) const
	{
	RArray<TTzRuleDefinition*> ruleDefs;
	CleanupClosePushL(ruleDefs);
	RArray<TTzRuleUse*> ruleUses;
	CleanupClosePushL(ruleUses);
	
	TDateTime startDateTime(aYear,EJanuary,0,0,0,0,0);
	TDateTime endDateTime(aYear,EDecember,30,23,59,59,0);
	
	FetchRuleDefinitionsL(ruleDefs,ruleUses,aYear,aYear);
	
	CVTzActualisedRules* actRules = CVTzActualisedRules::NewL(aYear,aYear);
	CleanupStack::PushL(actRules);
	TVTzActualisedRule tDefaultRule(startDateTime,aUtcOffset,ETzUtcTimeReference);
	ActualiseRuleDefinitionsL(*actRules,ruleDefs,ruleUses,aUtcOffset,startDateTime,endDateTime,tDefaultRule);

	TInt count = actRules->Count();
	TInt finalOffset = (*actRules)[count-1].iNewOffset;
		
	CleanupStack::PopAndDestroy(3,&ruleDefs);
	return finalOffset;
	}
コード例 #14
0
ファイル: oevent.cpp プロジェクト: opieproject/opie
void OEvent::fromMap( const QMap<int, QString>& map )
{

	// We just want to set the UID if it is really stored.
	if ( !map[OEvent::FUid].isEmpty() )
		setUid( map[OEvent::FUid].toInt() );

	setCategories( idsFromString( map[OEvent::FCategories] ) );
	setDescription( map[OEvent::FDescription] );
	setLocation( map[OEvent::FLocation] );

	if ( map[OEvent::FType] == "AllDay" )
		setAllDay( true );
	else
		setAllDay( false );

	int alarmTime = -1;
	if( !map[OEvent::FAlarm].isEmpty() )
		alarmTime = map[OEvent::FAlarm].toInt();

	int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
	if ( ( alarmTime != -1 )  ){
		QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 );
		OPimAlarm al( sound ,  dt  );
		notifiers().add( al );
	}
	if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){
		setTimeZone( map[OEvent::FTimeZone] );
	}

	time_t start = (time_t) map[OEvent::FStart].toLong();
	time_t end   = (time_t) map[OEvent::FEnd].toLong();

	/* AllDay is always in UTC */
	if ( isAllDay() ) {
		OTimeZone utc = OTimeZone::utc();
		setStartDateTime( utc.fromUTCDateTime( start ) );
		setEndDateTime  ( utc.fromUTCDateTime( end   ) );
		setTimeZone( "UTC"); // make sure it is really utc
	}else {
		/* to current date time */
		// qWarning(" Start is %d", start );
		OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
		QDateTime date = zone.toDateTime( start );
		qWarning(" Start is %s", date.toString().latin1() );
		setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );

		date = zone.toDateTime( end );
		setEndDateTime  ( zone.toDateTime( date, OTimeZone::current() ) );
	}

	if ( !map[OEvent::FRecParent].isEmpty() )
		setParent( map[OEvent::FRecParent].toInt() );

	if ( !map[OEvent::FRecChildren].isEmpty() ){
		QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] );
		for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
			addChild( (*it).toInt() );
		}
	}

	// Fill recurrence stuff and put it directly into the ORecur-Object using fromMap..
	if( !map[OEvent::FRType].isEmpty() ){
		QMap<int, QString> recFields;
		recFields.insert( ORecur::RType, map[OEvent::FRType] );
		recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] );
		recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] );
		recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] );
		recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] );
		recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] );
		recFields.insert( ORecur::Created, map[OEvent::FRCreated] );
		recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] );
		ORecur recur( recFields );
		setRecurrence( recur );
	}

}
コード例 #15
0
void CTzDbZone::GetRulesL(CTzRules& aRules)
	{	
	// start and end years of interest
	TInt firstYearOfInterest = aRules.StartYear();
	TInt lastYearOfInterest = aRules.EndYear();

	// record last instant of end year, in order to see if we need to get another time alignment
	TDateTime endDateTimeOfInterest(lastYearOfInterest,EDecember,30,23,59,59,0);
	TTime endTimeOfInterest(endDateTimeOfInterest);

	// initialise start time to beginning of startYear (UTC)
	TDateTime startDateTime(firstYearOfInterest,EJanuary,0,0,0,0,0);
	TTime startTime(startDateTime);
	TTime staEndTime;
	TDateTime staEndDateTime;
	TTzTimeReference staTimeReference(ETzUtcTimeReference);

	// the following variables are used to iterate through the list of standard time alignments for this location
	TInt taCount = iPersistedEntity.iNumberOfStdTimeAlignments;
	TInt tmpOffset;
	TTzStdTimeAlignment* ta(NULL);
	TTzStdTimeAlignment* prevTa(NULL);
	CTzDbStdTimeAlignment* sta = NULL;

	// the standard time offset at the beginning of the period of interest has to be set in aTzRules
	TBool initialOffsetHasBeenSet = EFalse;
	
	// Iterate through std time alignments until we find the one that contains our date of interest.
	// Get the rules for this time alignment, up to the end of the time alignment or the end of our 
	// period of interest (whichever comes first).
	// If the period of interest is covered by only one time alignment, finish and return.
	// If the period of interest is covered by more than one time alignment, repeat procedure with 
	// next time alignment(s) until we reach the end of the period of interest
	for (TInt i = 0; (i < taCount) && (startTime < endTimeOfInterest ); i++)
		{
		// get a standard time alignment

		prevTa = ta; // this will be needed to eventually wrap the time alignment in a CTzDbStdTimeAlignment object
		tmpOffset = iPersistedEntity.iOffsetsToTimeAlignments[i];
		ta = const_cast<TTzStdTimeAlignment*>(&iReadOnlyTzDb.GetTStdTimeAlignment(tmpOffset));

		// check if our time of interest is within this time alignment
		if (IsTimeInStdTimeAlignment(*ta,	startDateTime.Year(),
											startDateTime.Month(),
											startDateTime.Day(),
											startDateTime.Hour(),
											startDateTime.Minute(),
											staTimeReference) )
			{
			// wrap the time alignment in a CTzDbStdTimeAlignment object
			sta = CTzDbStdTimeAlignment::NewL(iReadOnlyTzDb,*ta,prevTa);
			if (sta)
				{
				CleanupStack::PushL(sta); // push #1 - sta
				
				if (initialOffsetHasBeenSet == EFalse)
					{
					aRules.SetInitialStdTimeOffset(ta->iUtcOffset);
					initialOffsetHasBeenSet = ETrue;
					}
					
				// staStartDateTime, staEndTime are passed by reference and their values
				// are updated in GetRulesL
				sta->GetRulesL(aRules,startDateTime,staEndDateTime);

				// The time reference to calculate the start of the next time alignment is the time reference
				// in which the end time of this time alignment is expressed 
				staTimeReference = static_cast<TTzTimeReference>(sta->UntilTimeReference());
				CleanupStack::PopAndDestroy(sta); // pop #1 - sta

				staEndTime = staEndDateTime;
				if (staEndTime == Time::MaxTTime())
					{
					startTime = staEndTime; // this will cause loop to finish
					}
				else
					{
					// move just after end of time alignment
					startTime = staEndTime + static_cast<TTimeIntervalSeconds>(1);
					startDateTime = startTime.DateTime();
					}
				}
			} // if IsTimeInStdTimeAlignment(...)
		} // for
			
	}
コード例 #16
0
 /// Return the current time as a posix time object.
 virtual boost::posix_time::ptime currentDateTime() const
 {
    return startDateTime() + boost::posix_time::seconds( (int) simulationTimeElapsed());
        //boost::posix_time::ptime(startDate()) +  boost::posix_time::seconds( (int) simulationTimeElapsed());
 }
コード例 #17
0
ファイル: oevent.cpp プロジェクト: opieproject/opie
QDateTime OEvent::startDateTimeInZone()const {
    /* if no timezone, or all day event or if the current and this timeZone match... */
    if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();

    OTimeZone zone(data->timezone  );
    return zone.toDateTime( data->start, OTimeZone::current() );
}
コード例 #18
0
 boost::posix_time::ptime SimulatorTimer::currentDateTime() const
 {
     return startDateTime() + boost::posix_time::seconds( (int) simulationTimeElapsed());
 }
コード例 #19
0
bool RecurrenceWidget::save(bool externaltxn, RecurrenceChangePolicy cp, QString *message)
{
  if (! message)
    message = new QString();

  if (DEBUG)
    qDebug("%s::save(%d, %d, %p) entered with id %d type %s",
           qPrintable(objectName()), externaltxn, cp, message, _parentId,
           qPrintable(_parentType));

  if (! modified())
    return true;

  if (_parentId < 0 || _parentType.isEmpty())
  {
    *message = tr("Could not save Recurrence information. The "
                  "parent object/event has not been set.");
    if (! externaltxn)
      QMessageBox::warning(this, tr("Missing Data"), *message);
    else
      qWarning("%s", qPrintable(*message));
    return false;
  }

  if (! externaltxn && cp == NoPolicy)
  {
    cp = getChangePolicy();
    if (cp == NoPolicy)
      return false;
  }
  else if (externaltxn && cp == NoPolicy)
  {
    *message = tr("You must choose how open events are to be handled");
    qWarning("%s", qPrintable(*message));
    return false;
  }

  XSqlQuery rollbackq;
  if (! externaltxn)
  {
    XSqlQuery beginq("BEGIN;");
    rollbackq.prepare("ROLLBACK;");
  }

  XSqlQuery recurq;
  if (isRecurring())
  {
    if (_id > 0)
    {
      if (cp == ChangeFuture)
      {
        XSqlQuery futureq;
        futureq.prepare("SELECT splitRecurrence(:parent_id, :parent_type,"
                        "                       :splitdate) AS newrecurid;");
        futureq.bindValue(":parent_id",   _parentId);
        futureq.bindValue(":parent_type", _parentType);
        futureq.bindValue(":splitdate",   startDate());
        futureq.exec();
        if (futureq.first())
        {
          int result = futureq.value("newrecurid").toInt();
          if (result > 0)
          {
            _id = result;
            futureq.prepare("SELECT recur_parent_id"
                            "  FROM recur"
                            " WHERE recur_id=:recur_id;");
            futureq.bindValue(":recur_id", _id);
            futureq.exec();
            if (futureq.first())
              _parentId = futureq.value("recur_parent_id").toInt();
          }
          else if (result < 0)
          {
            *message = storedProcErrorLookup("splitRecurrence", result);
            if (! externaltxn)
            {
              rollbackq.exec();
              QMessageBox::warning(this, tr("Processing Error"), *message);
            }
            else
              qWarning("%s", qPrintable(*message));
            return false;
          }
        }
        // one check for potentially 2 queries
        if (futureq.lastError().type() != QSqlError::NoError)
        {
          *message = futureq.lastError().text();
          if (! externaltxn)
          {
            rollbackq.exec();
            QMessageBox::warning(this, tr("Database Error"), *message);
          }
          else
            qWarning("%s", qPrintable(*message));
          return false;
        }
      }

      recurq.prepare("UPDATE recur SET"
                     "  recur_parent_id=:recur_parent_id,"
                     "  recur_parent_type=UPPER(:recur_parent_type),"
                     "  recur_period=:recur_period,"
                     "  recur_freq=:recur_freq,"
                     "  recur_start=:recur_start,"
                     "  recur_end=:recur_end,"
                     "  recur_max=:recur_max"
                     " WHERE (recur_id=:recurid)"
                     " RETURNING recur_id;");
      recurq.bindValue(":recurid", _id);
    }
    else
    {
      recurq.prepare("INSERT INTO recur ("
                     "  recur_parent_id,  recur_parent_type,"
                     "  recur_period,     recur_freq,"
                     "  recur_start,      recur_end,"
                     "  recur_max"
                     ") VALUES ("
                     "  :recur_parent_id, UPPER(:recur_parent_type),"
                     "  :recur_period,    :recur_freq,"
                     "  :recur_start,     :recur_end,"
                     "  :recur_max"
                     ") RETURNING recur_id;");
    }

    recurq.bindValue(":recur_parent_id",   _parentId);
    recurq.bindValue(":recur_parent_type", _parentType);
    recurq.bindValue(":recur_period",      periodCode());
    recurq.bindValue(":recur_freq",        frequency());
    recurq.bindValue(":recur_start",       startDateTime());
    if (endDate() < _eot.date())
      recurq.bindValue(":recur_end",       endDateTime());
    recurq.bindValue(":recur_max",         max());
    recurq.exec();
    if (recurq.first())
    {
      _id = recurq.value("recur_id").toInt();
      _prevParentId      = _parentId;
      _prevParentType    = _parentType;
      _prevEndDateTime   = endDateTime();
      _prevFrequency     = frequency();
      _prevMax           = max();
      _prevPeriod        = period();
      _prevRecurring     = isRecurring();
      _prevStartDateTime = startDateTime();
    }
  }
  else // ! isRecurring()
  {
    recurq.prepare("DELETE FROM recur"
                   " WHERE ((recur_parent_id=:recur_parent_id)"
                   "    AND (UPPER(recur_parent_type)=UPPER(:recur_parent_type)));");
    recurq.bindValue(":recur_parent_id",   _parentId);
    recurq.bindValue(":recur_parent_type", _parentType);
    recurq.exec();
  }

  if (recurq.lastError().type() != QSqlError::NoError)
  {
    *message = recurq.lastError().text();
    if (! externaltxn)
    {
      rollbackq.exec();
      QMessageBox::warning(this, tr("Database Error"), *message);
    }
    else
      qWarning("%s", qPrintable(*message));
    return false;
  }

  if (cp == ChangeFuture)
  {
    int procresult = -1;
    QString procname = "deleteOpenRecurringItems";
    XSqlQuery cfq;
    cfq.prepare("SELECT deleteOpenRecurringItems(:parentId, :parentType,"
                "                                :splitdate, false) AS result;");
    cfq.bindValue(":parentId",   _parentId);
    cfq.bindValue(":parentType", _parentType);
    cfq.bindValue(":splitdate",  startDate());
    cfq.exec();
    if (cfq.first())
    {
      procresult = cfq.value("result").toInt();
      if (procresult >= 0)
      {
        QString procname = "createOpenRecurringItems";
        cfq.prepare("SELECT createRecurringItems(:parentId, :parentType)"
                    "       AS result;");
        cfq.bindValue(":parentId",   _parentId);
        cfq.bindValue(":parentType", _parentType);
        cfq.exec();
        if (cfq.first())
          procresult = cfq.value("result").toInt();
      }
    }

    // error handling for either 1 or 2 queries so not elseif
    // check cfq.lastError() first to avoid misreporting db errs as -1
    if (cfq.lastError().type() != QSqlError::NoError)
    {
      *message = cfq.lastError().text();
      if (! externaltxn)
      {
        rollbackq.exec();
        QMessageBox::critical(this, tr("Database Error"), *message);
      }
      else
        qWarning("%s", qPrintable(*message));
      return false;
    }
    else if (procresult < 0)
    {
      *message = storedProcErrorLookup(procname, procresult);
      if (! externaltxn)
      {
        rollbackq.exec();
        QMessageBox::critical(this, tr("Processing Error"), *message);
      }
      else
        qWarning("%s", qPrintable(*message));
      return false;
    }
  }

  if (! externaltxn)
    XSqlQuery commitq("COMMIT;");
  return true;
}
コード例 #20
0
int CGUIDialogBoxeeLiveTvCtx::LoadEPG()
{
  LiveTvModelChannelsType channels = m_model.GetChannels();
  LiveTvModelProgramsType programs = m_model.GetPrograms();

  int currentChannelIndex = DVBManager::GetInstance().GetCurrentChannel()->GetIndex();

  time_t startSlotTime;
  time_t endSlotTime;
  m_model.GetCurrentTimeSlot(startSlotTime, endSlotTime);

  m_listEPG.Clear();

  int selectedItem = 0;

  for (int channelIndex = 0; channelIndex < (int) channels.size(); channelIndex++)
  {
    LiveTvModelChannel& channelInfo = channels[channelIndex];

    if (!channelInfo.enabled)
      continue;

    bool isActive = (currentChannelIndex == channelIndex);

    std::vector<LiveTvModelProgram>& programsForChannel = programs[channelIndex];

    if (programsForChannel.size() > 0)
    {
      bool firstProgram = true;
      foreach (LiveTvModelProgram program, programsForChannel)
      {
        time_t startTime = (time_t) program.info.start;
        struct tm* startLocaltime = localtime(&startTime);
        CDateTime startDateTime(*startLocaltime);

        time_t endTime = (time_t) program.info.end;
        struct tm* endLocaltime = localtime(&endTime);
        CDateTime endDateTime(*endLocaltime);

        CFileItemPtr channelItem(new CFileItem(program.info.title));
        channelItem->SetProperty("ChannelName", channelInfo.label);
        channelItem->SetProperty("ChannelNumber", channelInfo.number);
        channelItem->SetProperty("channel-id", channelInfo.id);
        channelItem->SetProperty("hasepg", true);
        channelItem->SetProperty("rating", program.info.rating);
        channelItem->SetProperty("hasrating", program.info.rating.length() > 0);
        channelItem->SetProperty("issubitem", !firstProgram);
        channelItem->SetProperty("program-id", program.info.id);

        channelItem->SetProperty("starttime", startDateTime.GetAsLocalizedTime("", false));
        channelItem->SetProperty("endtime", endDateTime.GetAsLocalizedTime("", false));
        channelItem->SetProperty("isnow", program.isNow);
        channelItem->SetProperty("isnew", program.info.isNew);
        channelItem->SetProperty("isactive", isActive);

        channelItem->SetProperty("show-synopsis", program.info.synopsis);
        channelItem->SetProperty("show-title", program.info.title);
        channelItem->SetProperty("episode-title", program.info.episodeTitle);
        channelItem->SetProperty("episode-number", program.info.episodeNumber);
        channelItem->SetProperty("season-number", program.info.seasonNumber);

        // In case there are multiple shows on the selected channels, we only want
        // the first one to be active
        if (isActive)
        {
          selectedItem = m_listEPG.Size();
          isActive = false;
        }

        if (program.isNow && program.social.watching)
        {
          int numOfFriendsWatching = program.social.friends.size();

          channelItem->SetProperty("friendswatching", true);
          channelItem->SetProperty("watching-label", program.social.label);

          if (numOfFriendsWatching == 1)
          {
            channelItem->SetProperty("userthumb-1", program.social.friends[0].thumbSmallUrl);
          }
          else if (numOfFriendsWatching == 2)
          {
            channelItem->SetProperty("userthumb-1", program.social.friends[0].thumbSmallUrl);
            channelItem->SetProperty("userthumb-2", program.social.friends[1].thumbSmallUrl);
          }
        }

        m_listEPG.Add(channelItem);

        firstProgram = false;
      }
    }