Esempio n. 1
0
Incidence *ICalFormat::fromString(const QString &text)
{
    CalendarLocal cal(mTimeZoneId);
    fromString(&cal, text);

    Incidence *ical = 0;
    Event::List elist = cal.events();
    if(elist.count() > 0)
    {
        ical = elist.first();
    }
    else
    {
        Todo::List tlist = cal.todos();
        if(tlist.count() > 0)
        {
            ical = tlist.first();
        }
        else
        {
            Journal::List jlist = cal.journals();
            if(jlist.count() > 0)
            {
                ical = jlist.first();
            }
        }
    }

    return ical ? ical->clone() : 0;
}
void CalPrintJournal::print( QPainter &p, int width, int height )
{
  int x=0, y=0;
  Journal::List journals( mCalendar->journals() );
  if ( mUseDateRange ) {
    Journal::List allJournals = journals;
    journals.clear();
    Journal::List::Iterator it = allJournals.begin();
    for ( ; it != allJournals.end(); ++it ) {
      QDate dt = (*it)->dtStart().date();
      if ( mFromDate <= dt && dt <= mToDate ) {
        journals.append( *it );
      }
    }
  }

  drawHeader( p, i18n( "Journal entries" ), QDate(), QDate(),
              QRect( 0, 0, width, headerHeight() ) );
  y = headerHeight() + 15;

  Journal::List::Iterator it = journals.begin();
  for ( ; it != journals.end(); ++it ) {
    drawJournal( *it, p, x, y, width, height );
  }
}
Esempio n. 3
0
QString ICalFormat::toString(Calendar *cal)
{
    setTimeZone(cal->timeZoneId(), !cal->isLocalTime());

    icalcomponent *calendar = mImpl->createCalendarComponent(cal);

    icalcomponent *component;

    // todos
    Todo::List todoList = cal->rawTodos();
    Todo::List::ConstIterator it;
    for(it = todoList.begin(); it != todoList.end(); ++it)
    {
        //    kdDebug(5800) << "ICalFormat::toString() write todo "
        //                  << (*it)->uid() << endl;
        component = mImpl->writeTodo(*it);
        icalcomponent_add_component(calendar, component);
    }

    // events
    Event::List events = cal->rawEvents();
    Event::List::ConstIterator it2;
    for(it2 = events.begin(); it2 != events.end(); ++it2)
    {
        //    kdDebug(5800) << "ICalFormat::toString() write event "
        //                  << (*it2)->uid() << endl;
        component = mImpl->writeEvent(*it2);
        icalcomponent_add_component(calendar, component);
    }

    // journals
    Journal::List journals = cal->journals();
    Journal::List::ConstIterator it3;
    for(it3 = journals.begin(); it3 != journals.end(); ++it3)
    {
        kdDebug(5800) << "ICalFormat::toString() write journal "
                      << (*it3)->uid() << endl;
        component = mImpl->writeJournal(*it3);
        icalcomponent_add_component(calendar, component);
    }

    QString text = QString::fromUtf8(icalcomponent_as_ical_string(calendar));

    icalcomponent_free(calendar);
    icalmemory_free_ring();

    if(!text)
    {
        setException(new ErrorFormat(ErrorFormat::SaveError,
                                     i18n("libical error")));
        return QString::null;
    }

    return text;
}
Esempio n. 4
0
Incidence::List Calendar::mergeIncidenceList(const Event::List &events,
        const Todo::List &todos,
        const Journal::List &journals)
{
    Incidence::List incidences;

    Event::List::ConstIterator it1;
    for(it1 = events.begin(); it1 != events.end(); ++it1)
        incidences.append(*it1);

    Todo::List::ConstIterator it2;
    for(it2 = todos.begin(); it2 != todos.end(); ++it2)
        incidences.append(*it2);

    Journal::List::ConstIterator it3;
    for(it3 = journals.begin(); it3 != journals.end(); ++it3)
        incidences.append(*it3);

    return incidences;
}
void KNotesPlugin::processDropEvent( QDropEvent *event )
{
  const QMimeData *md = event->mimeData();

  if ( KVCardDrag::canDecode( md ) ) {
    KABC::Addressee::List contacts;

    KVCardDrag::fromMimeData( md, contacts );

    KABC::Addressee::List::ConstIterator it;

    QStringList attendees;
    for ( it = contacts.constBegin(); it != contacts.constEnd(); ++it ) {
      QString email = (*it).fullEmail();
      if ( email.isEmpty() ) {
        attendees.append( (*it).realName() + "<>" );
      } else {
        attendees.append( email );
      }
    }
    event->accept();
    static_cast<KNotesPart *>( part() )->newNote(
      i18nc( "@item", "Meeting" ), attendees.join( ", " ) );
    return;
  }

  if ( ICalDrag::canDecode( event->mimeData() ) ) {
    CalendarLocal cal( KSystemTimeZones::local() );
    if ( ICalDrag::fromMimeData( event->mimeData(), &cal ) ) {
      Journal::List journals = cal.journals();
      if ( !journals.isEmpty() ) {
        event->accept();
        Journal *j = journals.first();
        static_cast<KNotesPart *>( part() )->
          newNote( i18nc( "@item", "Note: %1", j->summary() ), j->description() );
        return;
      }
      // else fall through to text decoding
    }
  }

  if ( md->hasText() ) {
    static_cast<KNotesPart *>( part() )->newNote(
      i18nc( "@item", "New Note" ), md->text() );
    return;
  }

  if ( MailList::canDecode( md ) ) {
    MailList mails = MailList::fromMimeData( md );
    event->accept();
    if ( mails.count() != 1 ) {
      KMessageBox::sorry(
        core(),
        i18nc( "@info", "Dropping multiple mails is not supported." ) );
    } else {
      MailSummary mail = mails.first();
      QString txt = i18nc( "@item", "From: %1\nTo: %2\nSubject: %3",
                           mail.from(), mail.to(), mail.subject() );
      static_cast<KNotesPart *>( part() )->newNote(
        i18nc( "@item", "Mail: %1", mail.subject() ), txt );
    }
    return;
  }

  kWarning() << QString( "Cannot handle drop events of type '%1'." ).arg( event->format() );
}
Esempio n. 6
0
Journal::List Calendar::sortJournals(Journal::List *journalList,
                                     JournalSortField sortField,
                                     SortDirection sortDirection)
{
    Journal::List journalListSorted;
    Journal::List::Iterator sortIt;
    Journal::List::Iterator eit;

    switch(sortField)
    {
        case JournalSortUnsorted:
            journalListSorted = *journalList;
            break;

        case JournalSortDate:
            for(eit = journalList->begin(); eit != journalList->end(); ++eit)
            {
                sortIt = journalListSorted.begin();
                if(sortDirection == SortDirectionAscending)
                {
                    while(sortIt != journalListSorted.end() &&
                            (*eit)->dtStart() >= (*sortIt)->dtStart())
                    {
                        ++sortIt;
                    }
                }
                else
                {
                    while(sortIt != journalListSorted.end() &&
                            (*eit)->dtStart() < (*sortIt)->dtStart())
                    {
                        ++sortIt;
                    }
                }
                journalListSorted.insert(sortIt, *eit);
            }
            break;

        case JournalSortSummary:
            for(eit = journalList->begin(); eit != journalList->end(); ++eit)
            {
                sortIt = journalListSorted.begin();
                if(sortDirection == SortDirectionAscending)
                {
                    while(sortIt != journalListSorted.end() &&
                            (*eit)->summary() >= (*sortIt)->summary())
                    {
                        ++sortIt;
                    }
                }
                else
                {
                    while(sortIt != journalListSorted.end() &&
                            (*eit)->summary() < (*sortIt)->summary())
                    {
                        ++sortIt;
                    }
                }
                journalListSorted.insert(sortIt, *eit);
            }
            break;
    }

    return journalListSorted;
}