ngwt__Note *IncidenceConverter::convertToNote(KCal::Journal *journal)
{
    if(!journal)
        return 0;
    ngwt__Note *note = soap_new_ngwt__Note(soap(), -1);
    note->startDate = 0;

    if(!convertToCalendarItem(journal, note))
    {
        soap_dealloc(soap(), note);
        return 0;
    }

    if(journal->doesFloat())
    {
        if(journal->dtStart().isValid())
            note->startDate = qDateToString(journal->dtStart().date());
    }
    else
    {
        if(journal->dtStart().isValid())
            note->startDate = qDateTimeToString(journal->dtStart(), mTimezone);
    }

    if(!note->subject)
        note->subject = qStringToString(QString("NO SUBJECT"));
    return note;
}
void IncidenceConverter::setItemDescription(KCal::Incidence *incidence,
        ngwt__CalendarItem *item)
{
    if(!incidence->description().isEmpty())
    {
        ngwt__MessageBody *message = soap_new_ngwt__MessageBody(soap(), -1);
        message->part =
            *soap_new_std__vectorTemplateOfPointerTongwt__MessagePart(soap(), -1);

        ngwt__MessagePart *part = soap_new_ngwt__MessagePart(soap(), -1);

        xsd__base64Binary data;
        data.__ptr =
            (unsigned char *)qStringToChar(incidence->description().utf8());
        data.__size = incidence->description().utf8().length();

        part->id = 0;
        part->__item = data;
        part->contentId = 0;
        std::string *str = soap_new_std__string(soap(), -1);
        str->append("text/plain");
        part->contentType = str;

        part->length = 0; // this is optional and sending the actual length of the source string truncates the data.
        part->offset = 0; // optional
        message->part.push_back(part);

        item->message = message;
    }
    else
        item->message = 0;
}
ngwt__Task* IncidenceConverter::convertToTask( KCal::Todo* todo )
{
  if ( !todo )
    return 0;
  ngwt__Task* task = soap_new_ngwt__Task( soap(), -1 );
  task->startDate = 0;
  task->dueDate = 0;
  task->assignedDate = 0;
  task->taskPriority = 0;
  task->completed = 0;

  if ( !convertToCalendarItem( todo, task ) ) {
    soap_dealloc( soap(), task );
    return 0;
  }

  if ( todo->dtStart().isValid() )
    task->startDate = kDateTimeToString( todo->dtStart(), mTimeSpec );

  if ( todo->hasDueDate() ) {
    task->dueDate = kDateTimeToString( todo->dtDue() );
  }

  // FIXME: Restore custom priorities
  QString priority = QString::number( todo->priority() );
  task->taskPriority = qStringToString( priority );

  task->completed = (bool*)soap_malloc( soap(), 1 );
  if ( todo->isCompleted() )
    (*task->completed) = true;
  else
    (*task->completed) = false;

  return task;
}
void IncidenceConverter::setAttendees(KCal::Incidence *incidence,
                                      ngwt__CalendarItem *item)
{
    item->distribution = soap_new_ngwt__Distribution(soap(), -1);

    item->distribution->from = soap_new_ngwt__From(soap(), -1);

    // ngwt__From
    item->distribution->from->replyTo = 0;
    // ngwt__NameAndEmail
    item->distribution->from->displayName = 0;
    item->distribution->from->email = 0;
    item->distribution->from->uuid = 0;

    item->distribution->from->displayName = qStringToString(incidence->organizer().name());
    item->distribution->from->email = qStringToString(incidence->organizer().email());

    if(!mFromName.isEmpty()) item->distribution->from->displayName = qStringToString(mFromName);
    if(!mFromEmail.isEmpty()) item->distribution->from->email = qStringToString(mFromEmail);
    if(!mFromUuid.isEmpty()) item->distribution->from->uuid = qStringToString(mFromUuid);

    QString to; // To list consists of display names of organizer and attendees separated by ";  "
    to += incidence->organizer().name();
    item->distribution->sendoptions = soap_new_ngwt__SendOptions(soap(), -1);

    item->distribution->sendoptions->requestReply = 0;
    item->distribution->sendoptions->mimeEncoding = 0;
    item->distribution->sendoptions->notification = 0;

    item->distribution->sendoptions->statusTracking = soap_new_ngwt__StatusTracking(soap(),
            -1);

    item->distribution->sendoptions->statusTracking->autoDelete = nullptr;
    item->distribution->sendoptions->statusTracking->__item = All_;

    item->distribution->recipients = soap_new_ngwt__RecipientList(soap(), -1);
    item->distribution->recipients->recipient = *(soap_new_std__vectorTemplateOfPointerTongwt__Recipient(soap(), -1));

    KCal::Attendee::List attendees = incidence->attendees();
    KCal::Attendee::List::ConstIterator it;
    for(it = attendees.begin(); it != attendees.end(); ++it)
    {
        if(!to.isEmpty())
            to += QString::fromLatin1(";  %1").arg((*it)->name());
        kdDebug() << "IncidenceConverter::setAttendees(), adding " << (*it)->fullName()
                  << endl;
        QString uuid;
        QValueList<KABC::Addressee> addList = KABC::StdAddressBook::self()->findByEmail((*it)->email());
        if(!addList.first().isEmpty())
            uuid = addList.first().custom("GWRESOURCE", "UUID");   //uuid may be mandatory for the recipients list to be stored on the server...
        item->distribution->recipients->recipient.push_back(createRecipient((*it)->name(), (*it)->email(), uuid));
    }
    item->distribution->to = qStringToString(to);
    item->distribution->cc = 0;
    item->distribution->bc = 0;
}
ngwt__Recipient *IncidenceConverter::createRecipient(const QString &name,
        const QString &email, const QString &uuid)
{
    ngwt__Recipient *recipient = soap_new_ngwt__Recipient(soap(), -1);

    recipient->recipientStatus = 0;
    if(!uuid.isEmpty()) recipient->uuid = qStringToString(uuid);
    else recipient->uuid = 0;
    if(!name.isEmpty())
    {
        kdDebug() << "- recipient name: " << name << endl;
        recipient->displayName = qStringToString(name);
    }
    else
    {
        recipient->displayName = 0;
    }
    if(!email.isEmpty())
    {
        kdDebug() << "- recipient email: " << email << endl;
        recipient->email = qStringToString(email);
    }
    else
    {
        recipient->email = 0;
    }
    recipient->distType = TO;
    recipient->recipType = User_;
    recipient->acceptLevel = 0;
    return recipient;
}
Exemple #6
0
Game::Game(QWidget *parent){

    // view
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setFixedSize(1400,800);

    // scene
    scene = new QGraphicsScene();
    scene->setSceneRect(0,0,1400,800);
    setScene(scene);

    ship1 = NULL;

    setMouseTracking(true);
    //mehrnaz chicken_level_1
     QTimer *timer=new QTimer();
     QObject::connect(timer,SIGNAL(timeout()),ship_level_1,SLOT(soap()));
     timer->start(2000);

     //mehrnaz for chicken level 2
     QTimer *timer2=new QTimer();
    QObject::connect(timer2,SIGNAL(timeout()),ship_level_2,SLOT(soap2()));
    timer->start(1000);

}
void IncidenceConverter::setRecurrence(KCal::Incidence *incidence, ngwt__CalendarItem *item)
{
    kdDebug() << k_funcinfo << endl;
    ngwt__Frequency *freq = 0;
    const KCal::Recurrence *recur = incidence->recurrence();

    if(incidence->doesRecur())
    {
        item->rrule = soap_new_ngwt__RecurrenceRule(soap(), -1);
        item->rrule->frequency = 0; //
        item->rrule->count = 0;
        item->rrule->until = 0; //
        item->rrule->interval = 0; //
        item->rrule->byDay = 0;
        item->rrule->byYearDay = 0;
        item->rrule->byMonthDay = 0;
        item->rrule->byMonth = 0;
        freq = (ngwt__Frequency *)soap_malloc(soap(), sizeof(ngwt__Frequency));
        // interval
        if(recur->frequency() > 1)
        {
            item->rrule->interval = (unsigned long *)soap_malloc(soap(), sizeof(unsigned long *));
            *item->rrule->interval = recur->frequency();
        }
        // end date
        if(recur->duration() > 0)        // number of recurrences. If end date is set we don't use this.
        {
            item->rrule->count = (long unsigned int *)soap_malloc(soap(), sizeof(long unsigned int *));
            *item->rrule->count = recur->duration();
        }
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
        else if(recur->endDateTime().isValid())
#else
        else if(recur->endDate().isValid())
#endif
            item->rrule->until = qDateToString(recur->endDate());
        else // GROUPWISE doesn't accept infinite recurrence so end after GW_MAX_RECURRENCES recurrences
        {
            item->rrule->count = (long unsigned int *)soap_malloc(soap(), sizeof(long unsigned int *));
            *item->rrule->count = GW_MAX_RECURRENCES;
        }

        // recurrence date - try setting it using the recurrence start date - didn't help
        /*    std::string startDate;
            startDate.append( recur->recurStart().date().toString( Qt::ISODate ).utf8() );
            item->rdate = soap_new_ngwt__RecurrenceDateType( soap(), -1 );
            item->rdate->date.push_back( startDate );*/
        // exceptions list - try sending empty list even if no exceptions
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
        KCal::DateList exceptions = recur->exDates();
#else
        KCal::DateList exceptions = incidence->exDates();
#endif
        if(!exceptions.isEmpty())
        {
            item->exdate = soap_new_ngwt__RecurrenceDateType(soap(), -1);
            for(KCal::DateList::ConstIterator it = exceptions.begin(); it != exceptions.end(); ++it)
            {
                std::string startDate;
                startDate.append((*it).toString(Qt::ISODate).utf8());
                item->exdate->date.push_back(startDate);
            }
        }
    }
bool IncidenceConverter::convertToCalendarItem(KCal::Incidence *incidence, ngwt__CalendarItem *item)
{
    kdDebug() << k_funcinfo << endl;
    //TODO: support the new iCal standard recurrence rule

    // ngwt__CalendarItem
    item->rdate = 0;
    item->rrule = 0;
    item->exdate = 0;
    item->recurrenceKey = 0;
    item->iCalId = 0;
    // ngwt__Mail
    item->subject = 0;
    item->originalSubject = 0;
    item->subjectPrefix = 0;
    item->distribution = 0;
    item->message = 0;
    item->attachments = 0;
    item->options = 0;
    item->link = 0;
    item->hasAttachment = false;
    item->size = 0;
    item->subType = 0;
    item->nntpOrImap = 0;
    item->smimeType = 0;
    // ngwt__BoxEntry
    item->status = 0;
    item->thread = 0;
    item->msgId = 0;
    item->messageId = 0;
    item->source = 0;
    item->returnSentItemsId = 0;
    item->delivered = 0;
    item->class_ = 0;
    item->security = 0;
    item->comment = 0;
    // ngwt__ContainerItem
    item->categories = 0;
    item->created = 0;
    item->customs = 0;
    // ngwt__Item
    item->id = 0;
    item->name = 0;
    item->version = 0;
    item->modified = 0;
    item->changes = 0;

    QString id = incidence->customProperty("GWRESOURCE", "UID");
    if(!id.isEmpty()) item->id = qStringToString(id);

    // Container
    if(!incidence->customProperty("GWRESOURCE", "CONTAINER").isEmpty())
    {
        std::vector<ngwt__ContainerRef *> *container = soap_new_std__vectorTemplateOfPointerTongwt__ContainerRef(soap(), -1);
        ngwt__ContainerRef *containerRef = soap_new_ngwt__ContainerRef(soap(), -1);
        containerRef->deleted = 0;
        containerRef->__item = incidence->customProperty("GWRESOURCE", "CONTAINER").utf8();
        container->push_back(containerRef);

        item->container = *container;
    }

    // secrecy
    item->class_ = (ngwt__ItemClass *)soap_malloc(soap(), sizeof(ngwt__ItemClass));
    switch(incidence->secrecy())
    {
        case KCal::Event::SecrecyPublic:
            *item->class_ = Public;
            break;
        case KCal::Event::SecrecyPrivate:
            *item->class_ = Private;
            break;
        case KCal::Event::SecrecyConfidential:
            *item->class_ = Private;
            break;
    }

    // options
    item->options = soap_new_ngwt__ItemOptions(soap(), -1);
    item->options->concealSubject = 0;
    item->options->delayDeliveryUntil = 0;
    item->options->expires = 0;
    item->options->hidden = 0;
    item->options->priority = Standard;

    // summary
    if(!incidence->summary().isEmpty())
        item->subject = qStringToString(incidence->summary());

    // TODO: reinstate when we know that this isn't causing problems with recurrence
    //   if ( incidence->created().isValid() ) {
    //     item->created = qDateTimeToChar( incidence->created(), mTimezone );
    //   } else
    //     item->created = 0;

    //   if ( incidence->lastModified().isValid() )
    //     item->modified = qDateTimeToChar( incidence->lastModified(), mTimezone );

    setItemDescription(incidence, item);

    item->source = (ngwt__ItemSource *)soap_malloc(soap(), sizeof(ngwt__ItemSource));
#if 1
    if(incidence->attendeeCount() > 0)
    {
        setAttendees(incidence, item);
        *item->source = sent_;
    }
    else
        *item->source = personal_;
#endif

    setRecurrence(incidence, item);
    return true;
}
ngwt__Appointment *IncidenceConverter::convertToAppointment(KCal::Event *event)
{
    kdDebug() << "IncidenceConverter::convertToAppointment()" << endl;
    if(!event)
        return 0;

    ngwt__Appointment *appointment = soap_new_ngwt__Appointment(soap(), -1);
    appointment->startDate = 0;
    appointment->endDate = 0;
    appointment->startDay = 0;
    appointment->endDay = 0;
    appointment->acceptLevel = 0;
    appointment->alarm = 0;
    appointment->allDayEvent = 0;
    appointment->place = 0;
    appointment->timezone = 0;

    if(!convertToCalendarItem(event, appointment))
    {
        soap_dealloc(soap(), appointment);
        return 0;
    }

    if(event->doesFloat())
    {
        bool *allDayEvent = (bool *)soap_malloc(soap(), 1);
        (*allDayEvent) = true;
        appointment->allDayEvent = allDayEvent;

        if(event->dtStart().isValid())
        {
            /*      kdDebug() << " convertToAppointment() raw start date: " << event->dtStart().toString() << endl;*/
            QDateTime start = event->dtStart();
            start.setTime(QTime(0, 0, 0));
            appointment->startDate = qDateTimeToChar(start, mTimezone);
            //appointment->startDay = qDateToString( event->dtStart().date()/*.addDays( -1 )*/ );
            /*      kdDebug() << "   converted start date: " << appointment->startDate << endl;*/
        }
        else
            kdDebug() << "   event start date not valid " << endl;
        if(event->hasEndDate())
        {
            //       kdDebug() << " convertToAppointment() raw end date: " << event->dtEnd().toString() << endl;
            QDateTime end = event->dtEnd();
            end = end.addDays(1);
            end.setTime(QTime(0, 0, 0));
            appointment->endDate = qDateTimeToChar(end, mTimezone);
            //appointment->endDay = qDateToString( event->dtEnd().date() );
            //       kdDebug() << "   converted end date:" << appointment->endDate << endl;
        }
        else
            kdDebug() << "   event end date not valid " << endl;
    }
    else
    {
        appointment->allDayEvent = 0;

        if(event->dtStart().isValid())
            appointment->startDate = qDateTimeToChar(event->dtStart(), mTimezone);

        if(event->hasEndDate())
            appointment->endDate = qDateTimeToChar(event->dtEnd(), mTimezone);
    }

    enum ngwt__AcceptLevel *al = (enum ngwt__AcceptLevel *)soap_malloc(soap(), sizeof(enum ngwt__AcceptLevel));
    *al = Busy;
    appointment->acceptLevel = al;

    KCal::Alarm::List alarms = event->alarms();
    if(!alarms.isEmpty())
    {
        ngwt__Alarm *alarm = soap_new_ngwt__Alarm(soap(), -1);
        alarm->__item = alarms.first()->startOffset().asSeconds() * -1;
        bool *enabled = (bool *)soap_malloc(soap(), sizeof(bool));
        *enabled = alarms.first()->enabled();
        alarm->enabled = enabled;

        appointment->alarm = alarm;
    }
    else
        appointment->alarm = 0;

    if(!event->location().isEmpty())
    {
        std::string *location = qStringToString(event->location());

        appointment->place = location;
    }
    else
        appointment->place = 0;

    appointment->timezone = 0;

    return appointment;
}
void IncidenceConverter::setRecurrence( KCal::Incidence * incidence, ngwt__CalendarItem * item )
{
  kDebug() ;
  ngwt__Frequency * freq = 0;
  const KCal::Recurrence * recur = incidence->recurrence();

  if ( incidence->recurs() )
  {
    item->rrule = soap_new_ngwt__RecurrenceRule( soap(), -1 );
    item->rrule->frequency = 0; //
    item->rrule->count = 0;
    item->rrule->until = 0; //
    item->rrule->interval = 0; //
    item->rrule->byDay = 0;
    item->rrule->byYearDay = 0;
    item->rrule->byMonthDay = 0;
    item->rrule->byMonth = 0;
    freq = (ngwt__Frequency *)soap_malloc( soap(), sizeof( ngwt__Frequency ) );
    // interval
    if ( recur->frequency() > 1 ) {
      item->rrule->interval = (unsigned long *)soap_malloc( soap(), sizeof( unsigned long * ) );
      *item->rrule->interval = recur->frequency();
    }
    // end date
    if ( recur->duration() > 0 )     // number of recurrences. If end date is set we don't use this.
    {
      item->rrule->count = (long unsigned int *)soap_malloc( soap(), sizeof( long unsigned int * ) );
      *item->rrule->count = recur->duration();
    }
    else if ( recur->endDateTime().isValid() )
      item->rrule->until = qDateToString( recur->endDate() );
    else // GROUPWISE doesn't accept infinite recurrence so end after GW_MAX_RECURRENCES recurrences
    {
      item->rrule->count = (long unsigned int *)soap_malloc( soap(), sizeof( long unsigned int * ) );
      *item->rrule->count = GW_MAX_RECURRENCES;
    }

    // recurrence date - try setting it using the recurrence start date - didn't help
/*    std::string startDate;
    startDate.append( recur->recurStart().date().toString( Qt::ISODate ).toUtf8().data() );
    item->rdate = soap_new_ngwt__RecurrenceDateType( soap(), -1 );
    item->rdate->date.push_back( startDate );*/
    // exceptions list - try sending empty list even if no exceptions
    KCal::DateList exceptions = recur->exDates();
    if ( !exceptions.isEmpty() )
    {
      item->exdate = soap_new_ngwt__RecurrenceDateType( soap(), -1 );
      for ( KCal::DateList::ConstIterator it = exceptions.constBegin(); it != exceptions.constEnd(); ++it )
      {
        std::string startDate;
        startDate.append( (*it).toString( Qt::ISODate ).toUtf8().data() );
        item->exdate->date.push_back( startDate );
      }
    }
  }

  if ( incidence->recurrenceType() == KCal::Recurrence::rDaily )
  {
    kDebug() <<"incidence recurs daily";
    *freq = Daily;
    item->rrule->frequency = freq;
  }
  else if ( incidence->recurrenceType() == KCal::Recurrence::rWeekly )
  {
    kDebug() <<"incidence recurs weekly";
#if 1 //trying out byDay recurrence
    *freq = Weekly;
    item->rrule->frequency = freq;
    // now change the bitArray of the days of the week that it recurs on to a ngwt__DayOfWeekList *
    QBitArray ba = recur->days();
    ngwt__DayOfYearWeekList * weeklyDays = soap_new_ngwt__DayOfYearWeekList( soap(), -1 );
    for ( int i = 0; i < 7; ++i )
    {
      if ( ba[i] )
      {
        ngwt__DayOfYearWeek * day = soap_new_ngwt__DayOfYearWeek( soap(), -1 );
        day->occurrence = 0;
        switch( i )
        {
          case 0:
            day->__item = Monday;
            break;
          case 1:
            day->__item = Tuesday;
            break;
          case 2:
            day->__item = Wednesday;
            break;
          case 3:
            day->__item = Thursday;
            break;
          case 4:
            day->__item = Friday;
            break;
          case 5:
            day->__item = Saturday;
            break;
          case 6:
            day->__item = Sunday;
            break;
        }
        weeklyDays->day.push_back( day );
      }
    }
    // add the list of days to the recurrence rule
    item->rrule->byDay = weeklyDays;
#endif
  }
  else if ( incidence->recurrenceType() == KCal::Recurrence::rMonthlyDay )
  {
    kDebug() <<"incidence recurs monthly";
    ;
    *freq = Monthly;
    item->rrule->frequency = freq;

    // TODO: translate '3rd wednesday of month' etc into rdates
  }
  else if ( incidence->recurrenceType() == KCal::Recurrence::rYearlyDay )
  {
    kDebug() <<"incidence recurs yearly on day #";
    *freq = Yearly;
    item->rrule->frequency = freq;
    // TODO: translate '1st sunday in may'
    ngwt__DayOfYearList * daysOfYear = soap_new_ngwt__DayOfYearList( soap(), -1 );
    QList<int> rmd;
    rmd = recur->yearMonths();
    daysOfYear->day.push_back( rmd.first() );

    item->rrule->byYearDay = daysOfYear;
    // no need to do MonthList recurrence as these will appear as separate instances when fetched from GW
  }
  else if ( incidence->recurrenceType() == KCal::Recurrence::rYearlyMonth )
  {
    kDebug() <<"incidence recurs yearly on monthday";
    *freq = Yearly;
    item->rrule->frequency = freq;
  }
}