Example #1
0
void DndFactoryTest::testPasteTodo()
{
  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Todo::Ptr todo( new Todo() );
  todo->setSummary( QLatin1String( "Summary 1" ) );
  todo->setDtDue( KDateTime( QDate( 2010, 8, 9 ) ) );

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( todo );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  const KDateTime newDateTime( QDate( 2011, 1, 1 ), QTime( 10, 10 ) );

  Incidence::List pastedIncidences = factory.pasteIncidences( newDateTime );
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeTodo );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != todo->uid() );

  Todo::Ptr pastedTodo = incidence.staticCast<Todo>();

  QVERIFY( pastedTodo->dtDue() == newDateTime );
  QVERIFY( pastedTodo->summary() == todo->summary() );

}
Example #2
0
Incidence::List KOListView::selectedIncidences()
{
    Incidence::List eventList;

    QListViewItem *item = mListView->selectedItem();
    if(item) eventList.append(((KOListViewItem *)item)->data());

    return eventList;
}
Example #3
0
Incidence::List ResourceCached::allChanges() const
{
    Incidence::List changes;
    QMap<Incidence *, bool>::ConstIterator it;
    for(it = mAddedIncidences.begin(); it != mAddedIncidences.end(); ++it)
    {
        changes.append(it.key());
    }
    for(it = mChangedIncidences.begin(); it != mChangedIncidences.end(); ++it)
    {
        changes.append(it.key());
    }
    for(it = mDeletedIncidences.begin(); it != mDeletedIncidences.end(); ++it)
    {
        changes.append(it.key());
    }
    return changes;
}
Example #4
0
Incidence::List KOTodoView::selectedIncidences()
{
  Incidence::List selected;

  KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
//  if (!item) item = mActiveItem;
  if (item) selected.append(item->todo());

  return selected;
}
Example #5
0
Incidence::List Calendar::incidencesFromSchedulingID(const QString &UID)
{
    Incidence::List result;
    Incidence::List incidences = rawIncidences();
    Incidence::List::iterator it = incidences.begin();
    for(; it != incidences.end(); ++it)
        if((*it)->schedulingID() == UID)
            result.append(*it);
    return result;
}
Example #6
0
Incidence::List ResourceCached::deletedIncidences() const
{
    Incidence::List deleted;
    QMap<Incidence *, bool>::ConstIterator it;
    for(it = mDeletedIncidences.begin(); it != mDeletedIncidences.end(); ++it)
    {
        deleted.append(it.key());
    }
    return deleted;
}
Example #7
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;
}
Example #8
0
void DndFactoryTest::testPasteAllDayEvent2()
{

  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Event::Ptr allDayEvent( new Event() );
  allDayEvent->setSummary( QLatin1String( "Summary 2" ) );
  allDayEvent->setDtStart( KDateTime( QDate( 2010, 8, 8 ) ) );
  allDayEvent->setDtEnd( KDateTime( QDate( 2010, 8, 9 ) ) );
  const QString originalUid = allDayEvent->uid();

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( allDayEvent );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  const KDateTime newDateTime( QDate( 2011, 1, 1 ) );
  const uint originalLength = allDayEvent->dtStart().secsTo( allDayEvent->dtEnd() );

  // paste at the new time
  Incidence::List pastedIncidences = factory.pasteIncidences( newDateTime );

  // we only copied one incidence
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeEvent );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != originalUid );

  // the new dateTime didn't have time component
  QVERIFY( incidence->allDay() );

  Event::Ptr pastedEvent = incidence.staticCast<Event>();
  const uint newLength = pastedEvent->dtStart().secsTo( pastedEvent->dtEnd() );

  kDebug() << "originalLength was " << originalLength << "; and newLength is "
           << newLength << "; old dtStart was " << allDayEvent->dtStart()
           << " and old dtEnd was " << allDayEvent->dtEnd() << endl
           << "; new dtStart is " << pastedEvent->dtStart()
           << " and new dtEnd is " << pastedEvent->dtEnd();

  QVERIFY( originalLength == newLength );
  QVERIFY( pastedEvent->dtStart() == newDateTime );
  QVERIFY( pastedEvent->summary() == allDayEvent->summary() );
}
Example #9
0
void KOTodoView::printTodo()
{
#ifndef KORG_NOPRINTER
  KOCoreHelper helper;
  CalPrinter printer( this, BaseView::calendar(), &helper );
  connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );

  Incidence::List selectedIncidences;
  selectedIncidences.append( mActiveItem->todo() );

  printer.print( KOrg::CalPrinterBase::Incidence,
                 QDate(), QDate(), selectedIncidences );
#endif
}
void KOEventPopupMenu::print( bool preview )
{
#ifndef KORG_NOPRINTER
  KOCoreHelper helper;
  CalPrinter printer( this, mCalendar, &helper, true );
  connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );

  Incidence::List selectedIncidences;
  selectedIncidences.append( mCurrentIncidence );

  printer.print( KOrg::CalPrinterBase::Incidence,
                 mCurrentDate, mCurrentDate, selectedIncidences, preview );
#endif
}
Example #11
0
Incidence::List DndFactory::pasteIncidences( const QDate &newDate,
                                             const QTime *newTime )
{
  QClipboard *cb = QApplication::clipboard();
  Calendar *cal = createDropCalendar( cb->mimeData() );
  Incidence::List list;

  if ( !cal ) {
    kDebug() << "Can't parse clipboard";
    return list;
  }

  // All pasted incidences get new uids, must keep track of old uids,
  // so we can update child's parents
  QHash<QString,Incidence*> oldUidToNewInc;

  Incidence::List::ConstIterator it;
  const Incidence::List incs = cal->incidences();
  for ( it = incs.constBegin();
        it != incs.constEnd(); ++it ) {
    Incidence *inc = d->pasteIncidence( *it, newDate, newTime );
    if ( inc ) {
      list.append( inc );
      oldUidToNewInc[( *it )->uid()] = inc;
    }
  }

  // update relations
  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
    Incidence *inc = *it;
    if ( oldUidToNewInc.contains( inc->relatedToUid() ) ) {
      Incidence *parentInc = oldUidToNewInc[inc->relatedToUid()];
      inc->setRelatedToUid( parentInc->uid() );
      inc->setRelatedTo( parentInc );
    } else {
      // not related to anything in the clipboard
      inc->setRelatedToUid( QString() );
      inc->setRelatedTo( 0 );
    }
  }

  return list;
}
Example #12
0
Incidence::List DndFactory::pasteIncidences( const KDateTime &newDateTime,
                                             const QFlags<PasteFlag> &pasteOptions )
{
  QClipboard *clipboard = QApplication::clipboard();
  Q_ASSERT( clipboard );
  MemoryCalendar::Ptr calendar( createDropCalendar( clipboard->mimeData() ) );
  Incidence::List list;

  if ( !calendar ) {
    kDebug() << "Can't parse clipboard";
    return list;
  }

  // All pasted incidences get new uids, must keep track of old uids,
  // so we can update child's parents
  QHash<QString, Incidence::Ptr> oldUidToNewInc;

  Incidence::List::ConstIterator it;
  const Incidence::List incidences = calendar->incidences();
  for ( it = incidences.constBegin();
        it != incidences.constEnd(); ++it ) {
    Incidence::Ptr incidence = d->pasteIncidence( *it, newDateTime, pasteOptions );
    if ( incidence ) {
      list.append( incidence );
      oldUidToNewInc[(*it)->uid()] = *it;
    }
  }

  // update relations
  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
    Incidence::Ptr incidence = *it;
    if ( oldUidToNewInc.contains( incidence->relatedTo() ) ) {
      Incidence::Ptr parentInc = oldUidToNewInc[incidence->relatedTo()];
      incidence->setRelatedTo( parentInc->uid() );
    } else {
      // not related to anything in the clipboard
      incidence->setRelatedTo( QString() );
    }
  }

  return list;
}
Example #13
0
void DndFactoryTest::testPasteAllDayEvent()
{

  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Event::Ptr allDayEvent( new Event() );
  allDayEvent->setSummary( QLatin1String( "Summary 1" ) );
  allDayEvent->setDtStart( KDateTime( QDate( 2010, 8, 8 ) ) );
  allDayEvent->setDtEnd( KDateTime( QDate( 2010, 8, 9 ) ) );
  const QString originalUid = allDayEvent->uid();
  const bool originalIsAllDay = allDayEvent->allDay();

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( allDayEvent );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  Incidence::List pastedIncidences = factory.pasteIncidences();
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeEvent );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != originalUid );

  // we passed an invalid KDateTime to pasteIncidences() so dates don't change.
  QVERIFY( incidence->allDay() == originalIsAllDay );

  Event::Ptr pastedEvent = incidence.staticCast<Event>();

  QVERIFY( pastedEvent->dtStart() == allDayEvent->dtStart() );
  QVERIFY( pastedEvent->dtEnd() == allDayEvent->dtEnd() );
  QVERIFY( pastedEvent->summary() == allDayEvent->summary() );
}
Example #14
0
bool DndFactory::copyIncidence( Incidence *selectedInc )
{
  Incidence::List list;
  list.append( selectedInc );
  return copyIncidences( list );
}
Example #15
0
void DndFactory::cutIncidence( Incidence *selectedInc )
{
  Incidence::List list;
  list.append( selectedInc );
  cutIncidences( list );
}
Example #16
0
// If a task with subtasks is deleted, move it's subtasks to the orphans list
void Calendar::removeRelations(Incidence *incidence)
{
    if(!incidence)
    {
        kdDebug(5800) << "Warning: Calendar::removeRelations( 0 )!\n";
        return;
    }

    // kdDebug(5850) << "Calendar::removeRelations for incidence " << forincidence << " with UID " << forincidence->uid() << ", summary: " << forincidence->summary() << endl;
    QString uid = incidence->uid();

    Incidence::List relations = incidence->relations();
    Incidence::List::ConstIterator it;
    for(it = relations.begin(); it != relations.end(); ++it)
    {
        Incidence *i = *it;
        if(!mOrphanUids.find(i->uid()))
        {
            mOrphans.insert(uid, i);
            mOrphanUids.insert(i->uid(), i);
            i->setRelatedTo(0);
            i->setRelatedToUid(uid);
        }
    }

    // If this incidence is related to something else, tell that about it
    if(incidence->relatedTo())
        incidence->relatedTo()->removeRelation(incidence);

    // Remove this one from the orphans list
    if(mOrphanUids.remove(uid))
    {
        // This incidence is located in the orphans list - it should be removed
        // Since the mOrphans dict might contain the same key (with different
        // child incidence pointers!) multiple times, take care that we remove
        // the correct one. So we need to remove all items with the given
        // parent UID, and readd those that are not for this item. Also, there
        // might be other entries with differnet UID that point to this
        // incidence (this might happen when the relatedTo of the item is
        // changed before its parent is inserted. This might happen with
        // groupware servers....). Remove them, too
        QStringList relatedToUids;
        // First get the list of all keys in the mOrphans list that point to the removed item
        relatedToUids << incidence->relatedToUid();
        for(QDictIterator<Incidence> it(mOrphans); it.current(); ++it)
        {
            if(it.current()->uid() == uid)
            {
                relatedToUids << it.currentKey();
            }
        }

        // now go through all uids that have one entry that point to the incidence
        for(QStringList::Iterator uidit = relatedToUids.begin();
                uidit != relatedToUids.end(); ++uidit)
        {
            Incidence::List tempList;
            // Remove all to get access to the remaining entries
            while(Incidence *i = mOrphans[ *uidit ])
            {
                mOrphans.remove(*uidit);
                if(i != incidence) tempList.append(i);
            }
            // Readd those that point to a different orphan incidence
            for(Incidence::List::Iterator incit = tempList.begin();
                    incit != tempList.end(); ++incit)
            {
                mOrphans.insert(*uidit, *incit);
            }
        }
    }
}
Example #17
0
void DndFactory::cutIncidence( const Incidence::Ptr &selectedIncidence )
{
  Incidence::List list;
  list.append( selectedIncidence );
  cutIncidences( list );
}