コード例 #1
0
void CalendarResource::itemChanged(const Akonadi::Item &item,
                                   const QSet< QByteArray > &partIdentifiers)
{
    Q_UNUSED(partIdentifiers);

    if (!canPerformTask<KCalCore::Event::Ptr>(item, KCalCore::Event::eventMimeType()) &&
            !canPerformTask<KCalCore::Todo::Ptr>(item, KCalCore::Todo::todoMimeType())) {
        return;
    }

    KGAPI2::Job *job = Q_NULLPTR;
    if (item.hasPayload<KCalCore::Event::Ptr>()) {
        KCalCore::Event::Ptr event = item.payload<KCalCore::Event::Ptr>();
        EventPtr kevent(new Event(*event));
        kevent->setUid(item.remoteId());

        job = new EventModifyJob(kevent, item.parentCollection().remoteId(), account(), this);
        connect(job, &EventCreateJob::finished, this, &CalendarResource::slotGenericJobFinished);

    } else if (item.hasPayload<KCalCore::Todo::Ptr>()) {
        KCalCore::Todo::Ptr todo = item.payload<KCalCore::Todo::Ptr>();
        TaskPtr ktodo(new Task(*todo));
        QString parentUid = todo->relatedTo(KCalCore::Incidence::RelTypeParent);
        job = new TaskMoveJob(item.remoteId(), item.parentCollection().remoteId(), parentUid, account(), this);
        job->setProperty(ITEM_PROPERTY, QVariant::fromValue(item));
        connect(job, &EventCreateJob::finished, this, &CalendarResource::slotModifyTaskReparentFinished);
    } else {
        cancelTask(i18n("Invalid payload type"));
        return;
    }

    job->setProperty(ITEM_PROPERTY, QVariant::fromValue(item));
}
void IncidenceCompletionPriority::load( const KCalCore::Incidence::Ptr &incidence )
{
  mLoadedIncidence = incidence;

  // TODO priority might be valid for other incidence types as well
  // only for Todos
  KCalCore::Todo::Ptr todo = IncidenceCompletionPriority::incidence<KCalCore::Todo>();
  if ( todo == 0 ) {
    mWasDirty = false;
    return;
  }

  d->mUi->mCompletionPriorityWidget->show();
  d->mUi->mTaskLabel->show();
#ifndef KDEPIM_MOBILE_UI
  d->mUi->mTaskSeparator->show();
#endif

  d->mOrigPercentCompleted = todo->percentComplete();
  d->mUi->mCompletionSlider->blockSignals( true );
  d->mUi->mCompletionSlider->setValue( todo->percentComplete() );
  d->sliderValueChanged( d->mUi->mCompletionSlider->value() );
  d->mUi->mCompletionSlider->blockSignals( false );

  d->mUi->mPriorityCombo->blockSignals( true );
  d->mUi->mPriorityCombo->setCurrentIndex( todo->priority() );
  d->mUi->mPriorityCombo->blockSignals( false );

  mWasDirty = false;
}
コード例 #3
0
QString timetrackerstorage::addTask(const Task* task, const Task* parent)
{
    kDebug(5970) << "Entering function";
    KCalCore::Todo::Ptr todo;
    QString uid;

    if ( !d->mCalendar )
    {
        kDebug(5970) << "mCalendar is not set";
        return uid;
    }
    todo = KCalCore::Todo::Ptr( new KCalCore::Todo() );
    if ( d->mCalendar->addTodo( todo ) )
    {
        task->asTodo( todo );
        if (parent)
            todo->setRelatedTo( parent->uid() );
        uid = todo->uid();
    }
    else
    {
        // Most likely a lock could not be pulled, although there are other
        // possiblities (like a really confused resource manager).
        uid.clear();;
    }
    return uid;
}
コード例 #4
0
QString timetrackerstorage::setTaskParent(Task* task, Task* parent)
{
    kDebug(5970) << "Entering function";
    QString err;
    KCalCore::Todo::Ptr todo = d->mCalendar->todo( task->uid() );
    if ( !parent ) {
      todo->setRelatedTo( QString() );
    } else {
      todo->setRelatedTo( parent->uid() );
    }
    kDebug(5970) << "Leaving function";
    return err;
}
コード例 #5
0
void timetrackerstorage::addComment(const Task* task, const QString& comment)
{
    kDebug(5970) << "Entering function";
    KCalCore::Todo::Ptr todo = d->mCalendar->todo(task->uid());

    // Do this to avoid compiler warnings about comment not being used.  once we
    // transition to using the addComment method, we need this second param.
    QString s = comment;

    // TODO: Use libkcalcore comments
    // todo->addComment(comment);
    // temporary
    todo->setDescription(task->comment());

    saveCalendar();
}
コード例 #6
0
Akonadi::Item::List Serializer::filterDescendantItems(const Akonadi::Item::List &potentialChildren, const Akonadi::Item &ancestorItem)
{
    if (potentialChildren.isEmpty())
        return Akonadi::Item::List();

    Akonadi::Item::List itemsToProcess = potentialChildren;
    Q_ASSERT(ancestorItem.isValid() && ancestorItem.hasPayload<KCalCore::Todo::Ptr>());
    KCalCore::Todo::Ptr todo = ancestorItem.payload<KCalCore::Todo::Ptr>();

    const auto bound = std::partition(itemsToProcess.begin(), itemsToProcess.end(),
                                      [ancestorItem, todo](Akonadi::Item currentItem) {
                                          return (!currentItem.hasPayload<KCalCore::Todo::Ptr>()
                                               || currentItem == ancestorItem
                                               || currentItem.payload<KCalCore::Todo::Ptr>()->relatedTo() != todo->uid());
                                      });

    Akonadi::Item::List itemsRemoved;
    std::copy(itemsToProcess.begin(), bound, std::back_inserter(itemsRemoved));
    itemsToProcess.erase(itemsToProcess.begin(), bound);

    auto result = std::accumulate(itemsToProcess.begin(), itemsToProcess.end(), Akonadi::Item::List(),
                                 [this, itemsRemoved](Akonadi::Item::List result, Akonadi::Item currentItem) {
                                     result << currentItem;
                                     return result += filterDescendantItems(itemsRemoved, currentItem);
                                 });

    return result;
}
bool IncidenceCompletionPriority::isDirty() const
{
  KCalCore::Todo::Ptr todo = IncidenceCompletionPriority::incidence<KCalCore::Todo>();

  if ( !todo ) {
    return false;
  }

  if ( d->mUi->mCompletionSlider->value() != todo->percentComplete() ) {
    return true;
  }

  if ( d->mUi->mPriorityCombo->currentIndex() != todo->priority() ) {
    return true;
  }

  return false;
}
void IncidenceCompletionPriority::save( const KCalCore::Incidence::Ptr &incidence )
{
  // TODO priority might be valid for other incidence types as well
  // only for Todos
  KCalCore::Todo::Ptr todo = IncidenceCompletionPriority::incidence<KCalCore::Todo>( incidence );
  if ( todo == 0 ) {
    return;
  }

  // we only have multiples of ten on our combo. If the combo did not change its value,
  // see if we have an original value to restore
  if ( d->mOrigPercentCompleted != -1 ) {
    todo->setPercentComplete( d->mOrigPercentCompleted );
  } else {
    todo->setPercentComplete( d->mUi->mCompletionSlider->value() );
  }
  todo->setPriority( d->mUi->mPriorityCombo->currentIndex() );
}
コード例 #9
0
ファイル: kcalconversiontest.cpp プロジェクト: maxyz/libkolab
void KCalConversionTest::testTodoConversion()
{
    QFETCH(KCalCore::Todo, kcal);
    QFETCH(Kolab::Todo, kolab);
    
    const KCalCore::Todo::Ptr e = toKCalCore(kolab);
    
    QCOMPARE(e->uid(), kcal.uid());
    QCOMPARE(e->dtStart(), kcal.dtStart());
    QCOMPARE(e->dtDue(), kcal.dtDue());
    QCOMPARE(e->relatedTo(KCalCore::Incidence::RelTypeParent), kcal.relatedTo(KCalCore::Incidence::RelTypeParent));
   
    const Kolab::Todo &b = fromKCalCore(kcal);
    QCOMPARE(b.uid(), kolab.uid());
    QCOMPARE(b.start(), kolab.start());
    QCOMPARE(b.due(), kolab.due());
    QCOMPARE(b.relatedTo(), kolab.relatedTo());
}
コード例 #10
0
KCalCore::Event::Ptr timetrackerstorage::baseEvent(const KCalCore::Todo::Ptr &todo)
{
    kDebug(5970) << "Entering function";
    KCalCore::Event::Ptr e( new KCalCore::Event() );
    QStringList categories;
    e->setSummary(todo->summary());

    // Can't use setRelatedToUid()--no error, but no RelatedTo written to disk
    e->setRelatedTo( todo->uid() );

    // Have to turn this off to get datetimes in date fields.
    e->setAllDay(false);
    e->setDtStart(KDateTime(todo->dtStart()));

    // So someone can filter this mess out of their calendar display
    categories.append(i18n("KTimeTracker"));
    e->setCategories(categories);

    return e;
}
コード例 #11
0
QString timetrackerstorage::writeTaskAsTodo(Task* task, QStack<KCalCore::Todo::Ptr>& parents)
{
    kDebug(5970) << "Entering function";
    QString err;
    KCalCore::Todo::Ptr todo = d->mCalendar->todo(task->uid());
    task->asTodo(todo); // FIXME ?
    if ( !todo )
    {
        kDebug(5970) << "Could not get todo from calendar";
        return "Could not get todo from calendar";
    }
    task->asTodo(todo);
    if ( !parents.isEmpty() ) todo->setRelatedTo( parents.top() ? parents.top()->uid() : QString() );
    parents.push( todo );

    for ( int i = 0; i < task->childCount(); ++i )
    {
        Task *nextTask = static_cast< Task* >( task->child( i ) );
        err = writeTaskAsTodo( nextTask, parents );
    }

    parents.pop();
    return err;
}