Beispiel #1
0
void EventArchiver::deleteIncidences(Calendar *calendar, const QDate &limitDate, QWidget *widget, const Incidence::List &incidences, bool withGUI)
{
    QStringList incidenceStrs;
    Incidence::List::ConstIterator it;
    for(it = incidences.begin(); it != incidences.end(); ++it)
    {
        incidenceStrs.append((*it)->summary());
    }

    if(withGUI)
    {
        int result = KMessageBox::warningContinueCancelList(
                         widget, i18n("Delete all items before %1 without saving?\n"
                                      "The following items will be deleted:")
                         .arg(KGlobal::locale()->formatDate(limitDate)), incidenceStrs,
                         i18n("Delete Old Items"), KStdGuiItem::del());
        if(result != KMessageBox::Continue)
            return;
    }
    for(it = incidences.begin(); it != incidences.end(); ++it)
    {
        calendar->deleteIncidence(*it);
    }
    emit eventsDeleted();
}
Beispiel #2
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() );

}
Beispiel #3
0
bool DndFactory::copyIncidences( const Incidence::List &incidences )
{
  QClipboard *clipboard = QApplication::clipboard();
  Q_ASSERT( clipboard );
  MemoryCalendar::Ptr calendar( new MemoryCalendar( d->mCalendar->timeSpec() ) );

  Incidence::List::ConstIterator it;
  for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
    if ( *it ) {
      calendar->addIncidence( Incidence::Ptr( ( *it )->clone() ) );
    }
  }

  QMimeData *mimeData = new QMimeData;

  ICalDrag::populateMimeData( mimeData, calendar );
  VCalDrag::populateMimeData( mimeData, calendar );

  if ( calendar->incidences().isEmpty() ) {
    return false;
  } else {
    clipboard->setMimeData( mimeData );
    return true;
  }
}
Beispiel #4
0
void KOListView::addIncidences(const Incidence::List &incidenceList)
{
    Incidence::List::ConstIterator it;
    for(it = incidenceList.begin(); it != incidenceList.end(); ++it)
    {
        addIncidence(*it);
    }
}
Beispiel #5
0
Incidence::List KOListView::selectedIncidences()
{
    Incidence::List eventList;

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

    return eventList;
}
Beispiel #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;
}
Beispiel #7
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;
}
Beispiel #8
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;
}
bool ResourceGroupware::doSave( bool )
{
  kDebug() <<"KCal::ResourceGroupware::doSave()";

  saveToCache();

  if ( !hasChanges() ) {
    kDebug() <<"No changes";
    return true;
  }
  
  if ( !confirmSave() ) return false;

#if 0
  Incidence::List::ConstIterator it;

  Incidence::List added = addedIncidences();
  for( it = added.begin(); it != added.end(); ++it ) {
    if ( mServer->addIncidence( *it, this ) ) {
      clearChange( *it );
      saveToCache();
    }
  }
  Incidence::List changed = changedIncidences();
  for( it = changed.begin(); it != changed.end(); ++it ) {
    if ( mServer->changeIncidence( *it ) ) clearChange( *it );
  }
  Incidence::List deleted = deletedIncidences();
  for( it = deleted.begin(); it != deleted.end(); ++it ) {
    if ( mServer->deleteIncidence( *it ) ) clearChange( *it );
  }
#endif

  return true;
}
Beispiel #10
0
Incidence *Calendar::incidenceFromSchedulingID(const QString &UID)
{
    Incidence::List incidences = rawIncidences();
    Incidence::List::iterator it = incidences.begin();
    for(; it != incidences.end(); ++it)
        if((*it)->schedulingID() == UID)
            // Touchdown, and the crowd goes wild
            return *it;
    // Not found
    return 0;
}
Beispiel #11
0
void EventArchiver::run(Calendar *calendar, const QDate &limitDate, QWidget *widget, bool withGUI, bool errorIfNone)
{
    // We need to use rawEvents, otherwise events hidden by filters will not be archived.
    Incidence::List incidences;
    Event::List events;
    Todo::List todos;
    Journal::List journals;

    if(KOPrefs::instance()->mArchiveEvents)
    {
        events = calendar->rawEvents(
                     QDate(1769, 12, 1),
                     // #29555, also advertised by the "limitDate not included" in the class docu
                     limitDate.addDays(-1),
                     true);
    }
    if(KOPrefs::instance()->mArchiveTodos)
    {
        Todo::List t = calendar->rawTodos();
        Todo::List::ConstIterator it;
        for(it = t.begin(); it != t.end(); ++it)
        {
            if((*it) && ((*it)->isCompleted()) && ((*it)->completed().date() < limitDate))
            {
                todos.append(*it);
            }
        }
    }

    incidences = Calendar::mergeIncidenceList(events, todos, journals);


    kdDebug(5850) << "EventArchiver: archiving incidences before " << limitDate << " -> " << incidences.count() << " incidences found." << endl;
    if(incidences.isEmpty())
    {
        if(withGUI && errorIfNone)
            KMessageBox::information(widget, i18n("There are no items before %1")
                                     .arg(KGlobal::locale()->formatDate(limitDate)),
                                     "ArchiverNoIncidences");
        return;
    }


    switch(KOPrefs::instance()->mArchiveAction)
    {
        case KOPrefs::actionDelete:
            deleteIncidences(calendar, limitDate, widget, incidences, withGUI);
            break;
        case KOPrefs::actionArchive:
            archiveIncidences(calendar, limitDate, widget, incidences, withGUI);
            break;
    }
}
Beispiel #12
0
bool DndFactory::cutIncidences( const Incidence::List &incidences )
{
  if ( copyIncidences( incidences ) ) {
    Incidence::List::ConstIterator it;
    for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
      d->mCalendar->deleteIncidence( *it );
    }
    return true;
  } else {
    return false;
  }
}
Beispiel #13
0
void ConfirmSaveDialog::addIncidences( const Incidence::List &incidences,
                                       const QString &operation )
{
  Incidence::List::ConstIterator it;
  for( it = incidences.begin(); it != incidences.end(); ++it ) {
    Incidence *i = *it;
    KListViewItem *item = new KListViewItem( mListView );
    item->setText( 0, operation );
    item->setText( 1, i->type() );
    item->setText( 2, i->summary() );
    item->setText( 3, i->uid() );
  }
}
bool ResourceLocalDir::doFileLoad(CalendarLocal &cal, const QString &fileName)
{
    if(!cal.load(fileName))
        return false;
    Incidence::List incidences = cal.rawIncidences();
    Incidence::List::ConstIterator it;
    for(it = incidences.constBegin(); it != incidences.constEnd(); ++it)
    {
        Incidence *i = *it;
        if(i) mCalendar.addIncidence(i->clone());
    }
    return true;
}
Beispiel #15
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
}
Beispiel #16
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() );
}
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
}
bool ResourceLocalDir::doSave()
{
    Incidence::List list;
    bool success = true;

    list = addedIncidences();
    list += changedIncidences();

    for(Incidence::List::iterator it = list.begin(); it != list.end(); ++it)
        if(!doSave(*it))
            success = false;

    return success;
}
static bool compareUids(const QStringList &_uids, const Incidence::List &incidences)
{
    QStringList uids = _uids;

    foreach(const KCalCore::Incidence::Ptr &incidence, incidences) {
        if (uids.contains(incidence->uid()))
            uids.removeAll(incidence->uid());
    }

    if (uids.isEmpty() && _uids.count() == incidences.count()) {
        return true;
    } else {
        qDebug() << uids.count() << incidences.count();
        return false;
    }
}
Beispiel #20
0
Incidence::Ptr DndFactory::pasteIncidence( const KDateTime &newDateTime,
                                           const QFlags<PasteFlag> &pasteOptions )
{
  QClipboard *clipboard = QApplication::clipboard();
  MemoryCalendar::Ptr calendar( createDropCalendar( clipboard->mimeData() ) );

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

  Incidence::List incidenceList = calendar->incidences();
  Incidence::Ptr incidence = incidenceList.isEmpty() ? Incidence::Ptr() : incidenceList.first();

  return d->pasteIncidence( incidence, newDateTime, pasteOptions );
}
Beispiel #21
0
void ResourceCached::loadChangesCache(QMap<Incidence *, bool> &map, const QString &type)
{
    CalendarLocal calendar(QString::fromLatin1("UTC"));

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

    const Incidence::List list = calendar.incidences();
    Incidence::List::ConstIterator it;
    for(it = list.begin(); it != list.end(); ++it)
        map.insert((*it)->clone(), true);

    calendar.close();
}
void ResourceGroupware::slotJobResult( KJob *job )
{
  kDebug() <<"ResourceGroupware::slotJobResult():";

  if ( job->error() ) {
    mIsShowingError = true;
    loadError( job->errorString() );
    mIsShowingError = false;
  } else {
    disableChangeNotification();

    clearCache();

     // FIXME: This does not take into account the time zone!
    CalendarLocal calendar;
    ICalFormat ical;
    if ( !ical.fromString( &calendar, mJobData ) ) {
      loadError( i18n("Error parsing calendar data.") );
    } else {
      Incidence::List incidences = calendar.incidences();
      Incidence::List::ConstIterator it;
      for( it = incidences.begin(); it != incidences.end(); ++it ) {
//        kDebug() <<"INCIDENCE:" << (*it)->summary();
        Incidence *i = (*it)->clone();
        QString remote = (*it)->customProperty( "GWRESOURCE", "UID" );
        QString local = idMapper().localId( remote );
        if ( local.isEmpty() ) {
          idMapper().setRemoteId( i->uid(), remote );
        } else {
          i->setUid( local );
        }
        addIncidence( i );
      }
    }
    saveToCache();
    enableChangeNotification();

    clearChanges();

    emit resourceChanged( this );
    emit resourceLoaded( this );
  }

  mDownloadJob = 0;
  if ( mProgress ) mProgress->setComplete();
  mProgress = 0;
}
Beispiel #23
0
Incidence *DndFactory::pasteIncidence( const QDate &newDate, const QTime *newTime )
{
  QClipboard *cb = QApplication::clipboard();
  Calendar *cal = createDropCalendar( cb->mimeData() );

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

  Incidence::List incList = cal->incidences();
  Incidence *inc = incList.isEmpty() ? 0 : incList.first();

  Incidence *newInc = d->pasteIncidence( inc, newDate, newTime );
  newInc->setRelatedTo( 0 );
  return newInc;
}
Beispiel #24
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;
}
Beispiel #25
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;
}
bool ResourceGroupwareBase::doSave( bool syncCache )
{
  kDebug(5800);

  Q_UNUSED( syncCache );
  saveToCache();

  if ( !hasChanges() ) {
    kDebug(5800) << "No changes";
    return true;
  }
  // TODO: Implement confirming of single changes i.e. it should be possible
  //       to upload only certain changes and discard the rest. This is
  //       particularly important for resources like the blogging resource,
  //       where uploading would mean a republication of the blog, not only
  //       a modifications.
  if ( !confirmSave() ) return false;

  mUploadJob = createUploadJob( adaptor() );
  connect( mUploadJob, SIGNAL( result( KPIM::GroupwareJob * ) ),
    SLOT( slotUploadJobResult( KPIM::GroupwareJob * ) ) );

  Incidence::List inc;
  Incidence::List::Iterator it;
  KPIM::GroupwareUploadItem::List addedItems, changedItems, deletedItems;

  inc = addedIncidences();
  for( it = inc.begin(); it != inc.end(); ++it ) {
    addedItems.append( adaptor()->newUploadItem( *it,
                                           KPIM::GroupwareUploadItem::Added ) );
  }
  // TODO: Check if the item has changed on the server...
  // In particular, check if the version we based our change on is still current
  // on the server
  inc = changedIncidences();
  for( it = inc.begin(); it != inc.end(); ++it ) {
    changedItems.append( adaptor()->newUploadItem( *it,
                                         KPIM::GroupwareUploadItem::Changed ) );
  }
  inc = deletedIncidences();
  for( it = inc.begin(); it != inc.end(); ++it ) {
    deletedItems.append( adaptor()->newUploadItem( *it,
                                         KPIM::GroupwareUploadItem::Deleted ) );
  }

  mUploadJob->setAddedItems( addedItems );
  mUploadJob->setChangedItems( changedItems );
  mUploadJob->setDeletedItems( deletedItems );

  // FIXME: Calling clearChanges() here is not the ideal way since the
  // upload might fail, but there is no other place to call it...
  clearChanges();
  return true;
}
Beispiel #27
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() );
}
Beispiel #28
0
bool DndFactory::copyIncidences( const Incidence::List &incidences )
{
  QClipboard *cb = QApplication::clipboard();
  CalendarLocal cal( d->mCalendar->timeSpec() );

  Incidence::List::ConstIterator it;
  for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
    if ( *it ) {
      cal.addIncidence( ( *it )->clone() );
    }
  }

  QMimeData *mimeData = new QMimeData;

  ICalDrag::populateMimeData( mimeData, &cal );
  VCalDrag::populateMimeData( mimeData, &cal );

  if ( cal.incidences().isEmpty() ) {
    return false;
  } else {
    cb->setMimeData( mimeData );
    return true;
  }
}
Beispiel #29
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;
}
Beispiel #30
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;
}