~ubuntu-branches/ubuntu/raring/kdepim/raring-proposed

« back to all changes in this revision

Viewing changes to korganizer/htmlexportjob.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-07 07:56:38 UTC
  • mfrom: (0.2.27)
  • Revision ID: package-import@ubuntu.com-20120607075638-0luhdq11z7sgvs4m
Tags: 4:4.8.80-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <calendarsupport/calendar.h>
27
27
#include <calendarsupport/utils.h>
28
28
 
29
 
#include <KCalCore/Calendar>
30
 
#include <KCalCore/Event>
31
 
#include <KCalCore/Todo>
 
29
#include <Akonadi/Contact/ContactSearchJob>
 
30
 
 
31
#include <KCalCore/Attendee>
 
32
 
32
33
#include <KCalUtils/IncidenceFormatter>
33
34
 
34
 
#include <akonadi/contact/contactsearchjob.h>
35
 
 
36
 
#include <kcalendarsystem.h>
37
 
#include <kdebug.h>
38
 
#include <kglobal.h>
39
 
#include <kio/netaccess.h>
40
 
#include <klocale.h>
41
 
#include <kmessagebox.h>
42
 
#include <ktemporaryfile.h>
43
 
 
44
 
#include <QtCore/QFile>
45
 
#include <QtCore/QTextStream>
46
 
#include <QtCore/QTextCodec>
47
 
#include <QtCore/QRegExp>
48
 
#include <QtCore/QMap>
49
 
#include <QtGui/QApplication>
50
 
 
51
 
using namespace KCalCore;
52
 
using namespace KCalUtils;
 
35
#include <KCalendarSystem>
 
36
#include <KDebug>
 
37
#include <KLocale>
 
38
#include <KMessageBox>
 
39
#include <KTemporaryFile>
 
40
#include <KIO/NetAccess>
 
41
 
 
42
#include <QApplication>
 
43
#include <QFile>
 
44
#include <QTextStream>
 
45
 
53
46
using namespace KOrg;
54
47
 
55
48
static QString cleanChars( const QString &txt );
93
86
  // first collect the email addresses of all organisators
94
87
  const Akonadi::Item::List events = d->mCalendar->events();
95
88
  foreach ( const Akonadi::Item &event, events ) {
96
 
    Q_ASSERT( event.hasPayload<Event::Ptr>() );
97
 
    const Event::Ptr eventPtr = event.payload<Event::Ptr>();
98
 
    const Attendee::List attendees = eventPtr->attendees();
 
89
    Q_ASSERT( event.hasPayload<KCalCore::Event::Ptr>() );
 
90
    const KCalCore::Event::Ptr eventPtr = event.payload<KCalCore::Event::Ptr>();
 
91
    const KCalCore::Attendee::List attendees = eventPtr->attendees();
99
92
    if ( !attendees.isEmpty() ) {
100
93
      Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob( this );
101
94
      job->setQuery( Akonadi::ContactSearchJob::Email, eventPtr->organizer()->email() );
110
103
 
111
104
  const Akonadi::Item::List todos = d->mCalendar->todos();
112
105
  foreach ( const Akonadi::Item &todo, todos ) {
113
 
    Q_ASSERT( todo.hasPayload<Todo::Ptr>() );
114
 
    const Todo::Ptr todoPtr = todo.payload<Todo::Ptr>();
115
 
    const Attendee::List attendees = todoPtr->attendees();
 
106
    Q_ASSERT( todo.hasPayload<KCalCore::Todo::Ptr>() );
 
107
    const KCalCore::Todo::Ptr todoPtr = todo.payload<KCalCore::Todo::Ptr>();
 
108
    const KCalCore::Attendee::List attendees = todoPtr->attendees();
116
109
    if ( !attendees.isEmpty() ) {
117
110
      Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob( this );
118
111
      job->setQuery( Akonadi::ContactSearchJob::Email, todoPtr->organizer()->email() );
339
332
          if ( events.count() ) {
340
333
            *ts << "<table>";
341
334
            foreach ( const Akonadi::Item &event, events ) {
342
 
              Q_ASSERT( event.hasPayload<Event::Ptr>() );
343
 
              Event::Ptr e = event.payload<Event::Ptr>();
 
335
              Q_ASSERT( event.hasPayload<KCalCore::Event::Ptr>() );
 
336
              KCalCore::Event::Ptr e = event.payload<KCalCore::Event::Ptr>();
344
337
              if ( checkSecrecy( e ) ) {
345
338
                createEvent( ts, e, start, false );
346
339
              }
408
401
          << "</i></td></tr>" << endl;
409
402
 
410
403
      foreach ( const Akonadi::Item &event, events ) {
411
 
        Q_ASSERT( event.hasPayload<Event::Ptr>() );
412
 
        Event::Ptr e = event.payload<Event::Ptr>();
 
404
        Q_ASSERT( event.hasPayload<KCalCore::Event::Ptr>() );
 
405
        KCalCore::Event::Ptr e = event.payload<KCalCore::Event::Ptr>();
413
406
        if ( checkSecrecy( e ) ) {
414
407
          createEvent( ts, e, dt );
415
408
        }
420
413
  *ts << "</table>" << endl;
421
414
}
422
415
 
423
 
void HtmlExportJob::createEvent ( QTextStream *ts, const Event::Ptr &event,
 
416
void HtmlExportJob::createEvent ( QTextStream *ts, const KCalCore::Event::Ptr &event,
424
417
                                  QDate date, bool withDescription )
425
418
{
426
419
  kDebug() << event->summary();
431
424
      *ts << "    <td>&nbsp;</td>" << endl;
432
425
    } else {
433
426
      *ts << "    <td valign=\"top\">"
434
 
          << IncidenceFormatter::timeToString( event->dtStart(), true, d->mCalendar->timeSpec() )
 
427
          << KCalUtils::IncidenceFormatter::timeToString( event->dtStart(),
 
428
                                                          true, d->mCalendar->timeSpec() )
435
429
          << "</td>" << endl;
436
430
    }
437
431
    if ( event->isMultiDay( d->mCalendar->timeSpec() ) && ( event->dtEnd().date() != date ) ) {
438
432
      *ts << "    <td>&nbsp;</td>" << endl;
439
433
    } else {
440
434
      *ts << "    <td valign=\"top\">"
441
 
          << IncidenceFormatter::timeToString( event->dtEnd(), true, d->mCalendar->timeSpec() )
 
435
          << KCalUtils::IncidenceFormatter::timeToString( event->dtEnd(),
 
436
                                                          true, d->mCalendar->timeSpec() )
442
437
          << "</td>" << endl;
443
438
    }
444
439
  } else {
480
475
  int index = 0;
481
476
  while ( index < rawTodoList.count() ) {
482
477
    const Akonadi::Item rawTodo = rawTodoList.value( index );
483
 
    Q_ASSERT( rawTodo.hasPayload<Todo::Ptr>() );
484
 
    Todo::Ptr ev = CalendarSupport::todo( rawTodo );
 
478
    Q_ASSERT( rawTodo.hasPayload<KCalCore::Todo::Ptr>() );
 
479
    KCalCore::Todo::Ptr ev = CalendarSupport::todo( rawTodo );
485
480
    const Akonadi::Item parentItem = d->mCalendar->findParent( rawTodo );
486
481
 
487
482
    ++index;
489
484
 
490
485
  // FIXME: Sort list by priorities. This is brute force and should be
491
486
  // replaced by a real sorting algorithm.
492
 
  Todo::List todoList;
493
 
  Todo::List::ConstIterator it;
 
487
  KCalCore::Todo::List todoList;
 
488
  KCalCore::Todo::List::ConstIterator it;
494
489
  for ( int i = 1; i <= 9; ++i ) {
495
490
    foreach ( const Akonadi::Item &rawTodo, rawTodoList ) {
496
 
      Todo::Ptr t = rawTodo.payload<Todo::Ptr>();
 
491
      KCalCore::Todo::Ptr t = rawTodo.payload<KCalCore::Todo::Ptr>();
497
492
      if ( t->priority() == i && checkSecrecy( t ) ) {
498
493
        todoList.append( t );
499
494
      }
500
495
    }
501
496
  }
502
497
  foreach ( const Akonadi::Item &rawTodo, rawTodoList ) {
503
 
    Todo::Ptr t = rawTodo.payload<Todo::Ptr>();
 
498
    KCalCore::Todo::Ptr t = rawTodo.payload<KCalCore::Todo::Ptr>();
504
499
    if ( t->priority() == 0 && checkSecrecy( t ) ) {
505
500
      todoList.append( t );
506
501
    }
561
556
          << "</b></a></td>" << endl;
562
557
      *ts << "  </tr>" << endl;
563
558
 
564
 
      Todo::List sortedList;
 
559
      KCalCore::Todo::List sortedList;
565
560
      // FIXME: Sort list by priorities. This is brute force and should be
566
561
      // replaced by a real sorting algorithm.
567
562
      for ( int i = 1; i <= 9; ++i ) {
568
563
        foreach ( const Akonadi::Item &item, relations ) {
569
 
          Todo::Ptr ev3 = CalendarSupport::todo( item );
 
564
          KCalCore::Todo::Ptr ev3 = CalendarSupport::todo( item );
570
565
          if ( ev3 && ev3->priority() == i ) {
571
566
            sortedList.append( ev3 );
572
567
          }
574
569
      }
575
570
 
576
571
      foreach ( const Akonadi::Item &item, relations ) {
577
 
        Todo::Ptr ev3 = CalendarSupport::todo( item );
 
572
        KCalCore::Todo::Ptr ev3 = CalendarSupport::todo( item );
578
573
        if ( ev3 && ev3->priority() == 0 ) {
579
574
          sortedList.append( ev3 );
580
575
        }
581
576
      }
582
577
 
583
 
      Todo::List::ConstIterator it3;
 
578
      KCalCore::Todo::List::ConstIterator it3;
584
579
      for ( it3 = sortedList.constBegin(); it3 != sortedList.constEnd(); ++it3 ) {
585
580
        createTodo( ts, *it3 );
586
581
      }
590
585
  *ts << "</table>" << endl;
591
586
}
592
587
 
593
 
void HtmlExportJob::createTodo( QTextStream *ts, const Todo::Ptr &todo )
 
588
void HtmlExportJob::createTodo( QTextStream *ts, const KCalCore::Todo::Ptr &todo )
594
589
{
595
590
  kDebug();
596
591
 
640
635
    }
641
636
    *ts << ">" << endl;
642
637
    if ( todo->hasDueDate() ) {
643
 
      *ts << "    " << IncidenceFormatter::dateToString( todo->dtDue( true ) ) << endl;
 
638
      *ts << "    " << KCalUtils::IncidenceFormatter::dateToString( todo->dtDue( true ) ) << endl;
644
639
    } else {
645
640
      *ts << "    &nbsp;" << endl;
646
641
    }
699
694
  // FIXME: Implement this!
700
695
}
701
696
 
702
 
bool HtmlExportJob::checkSecrecy( const Incidence::Ptr &incidence )
 
697
bool HtmlExportJob::checkSecrecy( const KCalCore::Incidence::Ptr &incidence )
703
698
{
704
699
  int secrecy = incidence->secrecy();
705
 
  if ( secrecy == Incidence::SecrecyPublic ) {
706
 
    return true;
707
 
  }
708
 
  if ( secrecy == Incidence::SecrecyPrivate && !d->mSettings->excludePrivate() ) {
709
 
    return true;
710
 
  }
711
 
  if ( secrecy == Incidence::SecrecyConfidential &&
 
700
  if ( secrecy == KCalCore::Incidence::SecrecyPublic ) {
 
701
    return true;
 
702
  }
 
703
  if ( secrecy == KCalCore::Incidence::SecrecyPrivate && !d->mSettings->excludePrivate() ) {
 
704
    return true;
 
705
  }
 
706
  if ( secrecy == KCalCore::Incidence::SecrecyConfidential &&
712
707
       !d->mSettings->excludeConfidential() ) {
713
708
    return true;
714
709
  }
715
710
  return false;
716
711
}
717
712
 
718
 
void HtmlExportJob::formatLocation( QTextStream *ts, const Incidence::Ptr &incidence )
 
713
void HtmlExportJob::formatLocation( QTextStream *ts, const KCalCore::Incidence::Ptr &incidence )
719
714
{
720
715
  if ( !incidence->location().isEmpty() ) {
721
716
    *ts << "    " << cleanChars( incidence->location() ) << endl;
724
719
  }
725
720
}
726
721
 
727
 
void HtmlExportJob::formatCategories( QTextStream *ts, const Incidence::Ptr &incidence )
 
722
void HtmlExportJob::formatCategories( QTextStream *ts, const KCalCore::Incidence::Ptr &incidence )
728
723
{
729
724
  if ( !incidence->categoriesStr().isEmpty() ) {
730
725
    *ts << "    " << cleanChars( incidence->categoriesStr() ) << endl;
733
728
  }
734
729
}
735
730
 
736
 
void HtmlExportJob::formatAttendees( QTextStream *ts, const Incidence::Ptr &incidence )
 
731
void HtmlExportJob::formatAttendees( QTextStream *ts, const KCalCore::Incidence::Ptr &incidence )
737
732
{
738
 
  Attendee::List attendees = incidence->attendees();
 
733
  KCalCore::Attendee::List attendees = incidence->attendees();
739
734
  if ( attendees.count() ) {
740
735
    *ts << "<em>";
741
736
    const KABC::Addressee organizer = d->mOrganizersMap.value( incidence->uid() );
746
741
      *ts << incidence->organizer()->fullName();
747
742
    }
748
743
    *ts << "</em><br />";
749
 
    Attendee::List::ConstIterator it;
 
744
    KCalCore::Attendee::List::ConstIterator it;
750
745
    for ( it = attendees.constBegin(); it != attendees.constEnd(); ++it ) {
751
 
      Attendee::Ptr a = *it;
 
746
      KCalCore::Attendee::Ptr a = *it;
752
747
      if ( !a->email().isEmpty() ) {
753
748
        *ts << "<a href=\"mailto:" << a->email();
754
749
        *ts << "\">" << cleanChars( a->name() ) << "</a>";