Exemplo n.º 1
0
void ResourceCached::cleanUpEventCache(const Event::List &eventList)
{
    CalendarLocal calendar(QString::fromLatin1("UTC"));

    if(KStandardDirs::exists(cacheFile()))
        calendar.load(cacheFile());
    else
        return;

    Event::List list = calendar.events();
    Event::List::ConstIterator cacheIt, it;
    for(cacheIt = list.begin(); cacheIt != list.end(); ++cacheIt)
    {
        bool found = false;
        for(it = eventList.begin(); it != eventList.end(); ++it)
        {
            if((*it)->uid() == (*cacheIt)->uid())
                found = true;
        }

        if(!found)
        {
            mIdMapper.removeRemoteId(mIdMapper.remoteId((*cacheIt)->uid()));
            Event *event = mCalendar.event((*cacheIt)->uid());
            if(event)
                mCalendar.deleteEvent(event);
        }
    }

    calendar.close();
}
Exemplo n.º 2
0
// taking a QDate, this function will look for an eventlist in the dict
// with that date attached -
Event::List ResourceExchange::rawEventsForDate(const QDate &qd,
        EventSortField sortField,
        SortDirection sortDirection)
{
    if(!mCache) return Event::List();
    // If the events for this date are not in the cache, or if they are old,
    // get them again
    QDateTime now = QDateTime::currentDateTime();
    // kdDebug() << "Now is " << now.toString() << endl;
    // kdDebug() << "mDates: " << mDates << endl;
    QDate start = QDate(qd.year(), qd.month(), 1);   // First day of month
    if(mDates && (!mDates->contains(start) ||
                  (*mCacheDates)[start].secsTo(now) > mCachedSeconds))
    {
        QDate end = start.addMonths(1).addDays(-1);     // Last day of month
        // Get events that occur in this period from the cache
        Event::List oldEvents = mCache->rawEvents(start, end, false);
        // And remove them all
        Event::List::ConstIterator it;
        for(it = oldEvents.begin(); it != oldEvents.end(); ++it)
        {
            mCache->deleteEvent(*it);
        }

        // FIXME: This is needed for the hack below:
        Event::List eventsBefore = mCache->rawEvents();

        kdDebug() << "Reading events for month of " << start.toString() << endl;
        mClient->downloadSynchronous(mCache, start, end, true);   // Show progress dialog

        // FIXME: This is a terrible hack! We need to install the observer for
        // newly downloaded events.However, downloading is done by
        // mClient->downloadSynchronous, where we don't have the pointer to this
        // available... On the other hand, here we don't really know which events
        // are really new.
        Event::List eventsAfter = mCache->rawEvents();
        for(it = eventsAfter.begin(); it != eventsAfter.end(); ++it)
        {
            if(eventsBefore.find(*it) == eventsBefore.end())
            {
                // it's a new event downloaded by downloadSynchronous -> install observer
                (*it)->registerObserver(this);
            }
        }

        mDates->add(start);
        mCacheDates->insert(start, now);
    }

    // Events are safely in the cache now, return them from cache
    Event::List events;
    if(mCache)
        events = mCache->rawEventsForDate(qd, sortField, sortDirection);
    // kdDebug() << "Found " << events.count() << " events." << endl;
    return events;
}
Exemplo n.º 3
0
/* Invoked by korgac when checking alarms. Always updates the cache. */
Alarm::List ResourceExchange::alarms(const QDateTime &from, const QDateTime &to)
{
    kdDebug(5800) << "ResourceExchange::alarms(" << from.toString() << " - " << to.toString() << ")\n";
    Alarm::List list;

    QDate start = from.date();
    QDate end = to.date();

    if(mCache)
    {

        /* Clear the cache */
        Event::List oldEvents = mCache->rawEvents(start, end, false);

        Event::List::ConstIterator it;
        for(it = oldEvents.begin(); it != oldEvents.end(); ++it)
        {
            mCache->deleteEvent(*it);
        }

        /* Fetch events */
        mClient->downloadSynchronous(mCache, start, end, false);

        list = mCache->alarms(from, to);
    }
    return list;
}
Exemplo n.º 4
0
void HtmlExport::createEventList(QTextStream *ts)
{
    int columns = 3;
    *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
    *ts << "  <tr>\n";
    *ts << "    <th class=\"sum\">" << i18n("Start Time") << "</th>\n";
    *ts << "    <th>" << i18n("End Time") << "</th>\n";
    *ts << "    <th>" << i18n("Event") << "</th>\n";
    if(mSettings->eventLocation())
    {
        *ts << "    <th>" << i18n("Location") << "</th>\n";
        ++columns;
    }
    if(mSettings->eventCategories())
    {
        *ts << "    <th>" << i18n("Categories") << "</th>\n";
        ++columns;
    }
    if(mSettings->eventAttendees())
    {
        *ts << "    <th>" << i18n("Attendees") << "</th>\n";
        ++columns;
    }

    *ts << "  </tr>\n";

    for(QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1))
    {
        kdDebug(5850) << "Getting events for " << dt.toString() << endl;
        Event::List events = mCalendar->events(dt,
                                               EventSortStartDate,
                                               SortDirectionAscending);
        if(events.count())
        {
            Event::List::ConstIterator it;
            bool first = true;
            for(it = events.begin(); it != events.end(); ++it)
            {
                if(checkSecrecy(*it))
                {
                    if(first)
                    {
                        *ts << "  <tr><td colspan=\"" << QString::number(columns)
                            << "\" class=\"datehead\"><i>"
                            << KGlobal::locale()->formatDate(dt)
                            << "</i></td></tr>\n";
                        first = false;
                    }
                    createEvent(ts, *it, dt);
                }
            }
        }
    }

    *ts << "</table>\n";
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
void KOWhatsNextView::updateView()
{
  KIconLoader kil("kdepim");
  QString *ipath = new QString();
  kil.loadIcon("kdepim",KIcon::NoGroup,32,KIcon::DefaultState,ipath);

  mText = "<table width=\"100%\">\n";
  mText += "<tr bgcolor=\"#3679AD\"><td><h1>";
  mText += "<img src=\"";
  mText += *ipath;
  mText += "\">";
  mText += "<font color=\"white\"> ";
  mText += i18n("What's Next?") + "</font></h1>";
  mText += "</td></tr>\n<tr><td>";

  mText += "<h2>";
  if ( mStartDate.daysTo( mEndDate ) < 1 ) {
    mText += KGlobal::locale()->formatDate( mStartDate );
  } else {
    mText += i18n("Date from - to", "%1 - %2")
            .arg( KGlobal::locale()->formatDate( mStartDate ) )
            .arg( KGlobal::locale()->formatDate( mEndDate ) );
  }
  mText+="</h2>\n";

  Event::List events;
  for ( QDate date = mStartDate; date <= mEndDate; date = date.addDays( 1 ) )
    events += calendar()->events(date, EventSortStartDate, SortDirectionAscending);

  if (events.count() > 0) {
    mText += "<p></p>";
    kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
    mText += "<h2><img src=\"";
    mText += *ipath;
    mText += "\">";
    mText += i18n("Events:") + "</h2>\n";
    mText += "<table>\n";
    Event::List::ConstIterator it;
    for( it = events.begin(); it != events.end(); ++it ) {
      Event *ev = *it;
      if ( !ev->doesRecur() ){
        appendEvent(ev);
      } else {
        // FIXME: This should actually be cleaned up. Libkcal should
        // provide a method to return a list of all recurrences in a
        // given time span.
        Recurrence *recur = ev->recurrence();
        int duration = ev->dtStart().secsTo( ev->dtEnd() );
        QDateTime start = recur->getPreviousDateTime(
                                QDateTime( mStartDate, QTime() ) );
        QDateTime end = start.addSecs( duration );
        if ( end.date() >= mStartDate ) {
          appendEvent( ev, start, end );
        }
        start = recur->getNextDateTime( start );
        while ( start.isValid() && start.date() <= mEndDate ) {
          appendEvent( ev, start );
          start = recur->getNextDateTime( start );
        }
      }
    }
    mText += "</table>\n";
  }

  mTodos.clear();
  Todo::List todos = calendar()->todos( TodoSortDueDate, SortDirectionAscending );
  if ( todos.count() > 0 ) {
    kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
    mText += "<h2><img src=\"";
    mText += *ipath;
    mText += "\">";
    mText += i18n("To-do:") + "</h2>\n";
    mText += "<ul>\n";
    Todo::List::ConstIterator it;
    for( it = todos.begin(); it != todos.end(); ++it ) {
      Todo *todo = *it;
      if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= mEndDate )
                  appendTodo(todo);
    }
    bool gotone = false;
    int priority = 1;
    while (!gotone && priority<=9 ) {
      for( it = todos.begin(); it != todos.end(); ++it ) {
        Todo *todo = *it;
        if (!todo->isCompleted() && (todo->priority() == priority) ) {
          appendTodo(todo);
          gotone = true;
        }
      }
      priority++;
      kdDebug(5850) << "adding the todos..." << endl;
    }
    mText += "</ul>\n";
  }

  QStringList myEmails( KOPrefs::instance()->allEmails() );
  int replies = 0;
  events = calendar()->events( QDate::currentDate(), QDate(2975,12,6) );
  Event::List::ConstIterator it2;
  for( it2 = events.begin(); it2 != events.end(); ++it2 ) {
    Event *ev = *it2;
    Attendee *me = ev->attendeeByMails( myEmails );
    if (me!=0) {
      if (me->status()==Attendee::NeedsAction && me->RSVP()) {
        if (replies == 0) {
          mText += "<p></p>";
          kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
          mText += "<h2><img src=\"";
          mText += *ipath;
          mText += "\">";
          mText += i18n("Events and to-dos that need a reply:") + "</h2>\n";
          mText += "<table>\n";
        }
        replies++;
        appendEvent( ev );
      }
    }
  }
  todos = calendar()->todos();
  Todo::List::ConstIterator it3;
  for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) {
    Todo *to = *it3;
    Attendee *me = to->attendeeByMails( myEmails );
    if (me!=0) {
      if (me->status()==Attendee::NeedsAction && me->RSVP()) {
        if (replies == 0) {
          mText += "<p></p>";
          kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
          mText += "<h2><img src=\"";
          mText += *ipath;
          mText += "\">";
          mText += i18n("Events and to-dos that need a reply:") + "</h2>\n";
          mText += "<table>\n";
        }
        replies++;
        appendEvent(to);
      }
    }
    kdDebug () << "check for todo-replies..." << endl;
  }
  if (replies > 0 ) mText += "</table>\n";


  mText += "</td></tr>\n</table>\n";

  kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl;

  delete ipath;

  mView->setText(mText);
}
Exemplo n.º 8
0
FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end )
{
  kdDebug(5800) << "FreeBusy::FreeBusy" << endl;
  mCalendar = calendar;

  setDtStart(start);
  setDtEnd(end);

  // Get all the events in the calendar
  Event::List eventList = mCalendar->rawEvents( start.date(), end.date() );

  int extraDays, i, x, duration;
  duration = start.daysTo(end);
  QDate day;
  QDateTime tmpStart;
  QDateTime tmpEnd;
  // Loops through every event in the calendar
  Event::List::ConstIterator it;
  for( it = eventList.begin(); it != eventList.end(); ++it ) {
    Event *event = *it;

    // The code below can not handle floating events. Fixing this resulted
    // in a lot of duplicated code. Instead, make a copy of the event and
    // set the period to the full day(s). This trick works for recurring,
    // multiday, and single day floating events.
    Event *floatingEvent = 0;
    if ( event->doesFloat() ) {
      // Floating event. Do the hack
      kdDebug(5800) << "Floating event\n";
      floatingEvent = new Event( *event );

      // Set the start and end times to be on midnight
      QDateTime start( floatingEvent->dtStart().date(), QTime( 0, 0 ) );
      QDateTime end( floatingEvent->dtEnd().date(), QTime( 23, 59, 59, 999 ) );
      floatingEvent->setFloats( false );
      floatingEvent->setDtStart( start );
      floatingEvent->setDtEnd( end );

      kdDebug(5800) << "Use: " << start.toString() << " to " << end.toString()
                    << endl;
      // Finally, use this event for the setting below
      event = floatingEvent;
    }

    // This whole for loop is for recurring events, it loops through
    // each of the days of the freebusy request

    // First check if this is transparent. If it is, it shouldn't be in the
    // freebusy list
    if ( event->transparency() == Event::Transparent )
      // Transparent
      continue;

    for( i = 0; i <= duration; ++i ) {
      day=(start.addDays(i).date());
      tmpStart.setDate(day);
      tmpEnd.setDate(day);

      if( event->doesRecur() ) {
        if ( event->isMultiDay() ) {
// FIXME: This doesn't work for sub-daily recurrences or recurrences with
//        a different time than the original event.
          extraDays = event->dtStart().date().daysTo(event->dtEnd().date());
          for ( x = 0; x <= extraDays; ++x ) {
            if ( event->recursOn(day.addDays(-x))) {
              tmpStart.setDate(day.addDays(-x));
              tmpStart.setTime(event->dtStart().time());
              tmpEnd=tmpStart.addSecs( (event->duration()) );

              addLocalPeriod( tmpStart, tmpEnd );
              break;
            }
          }
        } else {
          if (event->recursOn(day)) {
            tmpStart.setTime(event->dtStart().time());
            tmpEnd.setTime(event->dtEnd().time());

            addLocalPeriod (tmpStart, tmpEnd);
          }
        }
      }

    }
    // Non-recurring events
    addLocalPeriod(event->dtStart(), event->dtEnd());

    // Clean up
    delete floatingEvent;
  }

  sortList();
}
Exemplo n.º 9
0
void HtmlExport::createMonthView(QTextStream *ts)
{
    QDate start = fromDate();
    start.setYMD( start.year(), start.month(), 1 );  // go back to first day in month

    QDate end( start.year(), start.month(), start.daysInMonth() );

    int startmonth = start.month();
    int startyear = start.year();

    while ( start < toDate() ) {
        // Write header
        *ts << "<h2>" << (i18n("month_year","%1 %2").arg(KGlobal::locale()->calendar()->monthName(start))
                          .arg(start.year())) << "</h2>\n";
        if ( KGlobal::locale()->weekStartDay() == 1 ) {
            start = start.addDays(1 - start.dayOfWeek());
        } else {
            if (start.dayOfWeek() != 7) {
                start = start.addDays(-start.dayOfWeek());
            }
        }
        *ts << "<table border=\"1\">\n";

        // Write table header
        *ts << "  <tr>";
        for(int i=0; i<7; ++i) {
            *ts << "<th>" << KGlobal::locale()->calendar()->weekDayName( start.addDays(i) ) << "</th>";
        }
        *ts << "</tr>\n";

        // Write days
        while (start <= end) {
            *ts << "  <tr>\n";
            for(int i=0; i<7; ++i) {
                *ts << "    <td valign=\"top\"><table border=\"0\">";

                *ts << "<tr><td ";
                if (mHolidayMap.contains(start) || start.dayOfWeek() == 7) {
                    *ts << "class=\"dateholiday\"";
                } else {
                    *ts << "class=\"date\"";
                }
                *ts << ">" << QString::number(start.day());

                if (mHolidayMap.contains(start)) {
                    *ts << " <em>" << mHolidayMap[start] << "</em>";
                }

                *ts << "</td></tr><tr><td valign=\"top\">";

                Event::List events = mCalendar->events( start,
                                                        EventSortStartDate,
                                                        SortDirectionAscending );
                if (events.count()) {
                    *ts << "<table>";
                    Event::List::ConstIterator it;
                    for( it = events.begin(); it != events.end(); ++it ) {
                        if ( checkSecrecy( *it ) ) {
                            createEvent( ts, *it, start, false );
                        }
                    }
                    *ts << "</table>";
                } else {
                    *ts << "&nbsp;";
                }

                *ts << "</td></tr></table></td>\n";
                start = start.addDays(1);
            }
            *ts << "  </tr>\n";
        }
        *ts << "</table>\n";
        startmonth += 1;
        if ( startmonth > 12 ) {
            startyear += 1;
            startmonth = 1;
        }
        start.setYMD( startyear, startmonth, 1 );
        end.setYMD(start.year(),start.month(),start.daysInMonth());
    }
}
Exemplo n.º 10
0
/******************************************************************************
* Initialise or update the birthday selection list by fetching all birthdays
* from the address book and displaying those which do not already have alarms.
*/
void BirthdayDlg::updateSelectionList()
{
	// Compile a list of all pending alarm messages which look like birthdays
	QStringList messageList;
	KAEvent event;
	Event::List events = AlarmCalendar::activeCalendar()->events();
	for (Event::List::ConstIterator it = events.begin();  it != events.end();  ++it)
	{
		Event* kcalEvent = *it;
		event.set(*kcalEvent);
		if (event.action() == KAEvent::MESSAGE
		&&  event.recurType() == KARecurrence::ANNUAL_DATE
		&&  (mPrefixText.isEmpty()  ||  event.message().startsWith(mPrefixText)))
			messageList.append(event.message());
	}

	// Fetch all birthdays from the address book
	for (KABC::AddressBook::ConstIterator abit = mAddressBook->begin();  abit != mAddressBook->end();  ++abit)
	{
		const KABC::Addressee& addressee = *abit;
		if (addressee.birthday().isValid())
		{
			// Create a list entry for this birthday
			QDate birthday = addressee.birthday().date();
			QString name = addressee.nickName();
			if (name.isEmpty())
				name = addressee.realName();
			// Check if the birthday already has an alarm
			QString text = mPrefixText + name + mSuffixText;
			bool alarmExists = (messageList.find(text) != messageList.end());
			// Check if the birthday is already in the selection list
			bool inSelectionList = false;
			AddresseeItem* item = 0;
			for (QListViewItem* qitem = mAddresseeList->firstChild();  qitem;  qitem = qitem->nextSibling())
			{
				item = dynamic_cast<AddresseeItem*>(qitem);
				if (item  &&  item->text(AddresseeItem::NAME) == name  &&  item->birthday() == birthday)
				{
					inSelectionList = true;
					break;
				}
			}

			if (alarmExists  &&  inSelectionList)
				delete item;     // alarm exists, so remove from selection list
			else if (!alarmExists  &&  !inSelectionList)
				new AddresseeItem(mAddresseeList, name, birthday);   // add to list
		}
	}
//	mAddresseeList->setUpdatesEnabled(true);

	// Enable/disable OK button according to whether anything is currently selected
	bool selection = false;
	for (QListViewItem* item = mAddresseeList->firstChild();  item;  item = item->nextSibling())
		if (mAddresseeList->isSelected(item))
		{
			selection = true;
			break;
		}
	enableButtonOK(selection);
}
Exemplo n.º 11
0
Event::List Calendar::sortEvents(Event::List *eventList,
                                 EventSortField sortField,
                                 SortDirection sortDirection)
{
    Event::List eventListSorted;
    Event::List tempList, t;
    Event::List alphaList;
    Event::List::Iterator sortIt;
    Event::List::Iterator eit;

    // Notice we alphabetically presort Summaries first.
    // We do this so comparison "ties" stay in a nice order.

    switch(sortField)
    {
        case EventSortUnsorted:
            eventListSorted = *eventList;
            break;

        case EventSortStartDate:
            alphaList = sortEvents(eventList, EventSortSummary, sortDirection);
            for(eit = alphaList.begin(); eit != alphaList.end(); ++eit)
            {
                sortIt = eventListSorted.begin();
                if(sortDirection == SortDirectionAscending)
                {
                    while(sortIt != eventListSorted.end() &&
                            (*eit)->dtStart() >= (*sortIt)->dtStart())
                    {
                        ++sortIt;
                    }
                }
                else
                {
                    while(sortIt != eventListSorted.end() &&
                            (*eit)->dtStart() < (*sortIt)->dtStart())
                    {
                        ++sortIt;
                    }
                }
                eventListSorted.insert(sortIt, *eit);
            }
            break;

        case EventSortEndDate:
            alphaList = sortEvents(eventList, EventSortSummary, sortDirection);
            for(eit = alphaList.begin(); eit != alphaList.end(); ++eit)
            {
                if((*eit)->hasEndDate())
                {
                    sortIt = eventListSorted.begin();
                    if(sortDirection == SortDirectionAscending)
                    {
                        while(sortIt != eventListSorted.end() &&
                                (*eit)->dtEnd() >= (*sortIt)->dtEnd())
                        {
                            ++sortIt;
                        }
                    }
                    else
                    {
                        while(sortIt != eventListSorted.end() &&
                                (*eit)->dtEnd() < (*sortIt)->dtEnd())
                        {
                            ++sortIt;
                        }
                    }
                }
                else
                {
                    // Keep a list of the Events without End DateTimes
                    tempList.append(*eit);
                }
                eventListSorted.insert(sortIt, *eit);
            }
            if(sortDirection == SortDirectionAscending)
            {
                // Append the list of Events without End DateTimes
                eventListSorted += tempList;
            }
            else
            {
                // Prepend the list of Events without End DateTimes
                tempList += eventListSorted;
                eventListSorted = tempList;
            }
            break;

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

    return eventListSorted;

}