File: gentodo.cpp

package info (click to toggle)
zanshin 25.08.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,664 kB
  • sloc: cpp: 35,502; xml: 1,393; sh: 16; makefile: 5
file content (135 lines) | stat: -rw-r--r-- 3,770 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * SPDX-FileCopyrightText: 2015 Kevin Ottens <ervin@kde.org>
 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/


#include "gentodo.h"

#include <KCalendarCore/Todo>
#include <QDateTime>
#include <akonadi/akonadiserializer.h>

using namespace Testlib;
using Akonadi::Serializer;

GenTodo::GenTodo(const Akonadi::Item &item)
    : m_item(item)
{
    m_item.setMimeType(KCalendarCore::Todo::todoMimeType());
    if (!m_item.hasPayload<KCalendarCore::Todo::Ptr>())
        m_item.setPayload(KCalendarCore::Todo::Ptr::create());
}

Testlib::GenTodo::operator Akonadi::Item()
{
    return m_item;
}

GenTodo &GenTodo::withId(Akonadi::Item::Id id)
{
    m_item.setId(id);
    return *this;
}

GenTodo &GenTodo::withParent(Akonadi::Collection::Id id)
{
    m_item.setParentCollection(Akonadi::Collection(id));
    return *this;
}

GenTodo &GenTodo::withContexts(const QStringList &contextUids)
{
    auto todo = m_item.payload<KCalendarCore::Todo::Ptr>();
    if (contextUids.isEmpty())
        todo->removeCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList());
    else
        todo->setCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList(), contextUids.join(','));
    return *this;
}

GenTodo &GenTodo::asProject(bool value)
{
    auto todo = m_item.payload<KCalendarCore::Todo::Ptr>();
    if (value)
        todo->setCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsProject(), QStringLiteral("1"));
    else
        todo->removeCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsProject());
    return *this;
}

GenTodo &GenTodo::asContext(bool value)
{
    auto todo = m_item.payload<KCalendarCore::Todo::Ptr>();
    if (value)
        todo->setCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsContext(), QStringLiteral("1"));
    else
        todo->removeCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsContext());
    return *this;
}

GenTodo &GenTodo::withUid(const QString &uid)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setUid(uid);
    return *this;
}

GenTodo &GenTodo::withParentUid(const QString &uid)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setRelatedTo(uid);
    return *this;
}

GenTodo &GenTodo::withTitle(const QString &title)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setSummary(title);
    return *this;
}

GenTodo &GenTodo::withText(const QString &text)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setDescription(text);
    return *this;
}

GenTodo &GenTodo::done(bool value)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setCompleted(value);
    return *this;
}

GenTodo &GenTodo::withDoneDate(const QString &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setCompleted(QDate::fromString(date, Qt::ISODate).startOfDay());
    return *this;
}

GenTodo &GenTodo::withDoneDate(const QDate &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setCompleted(date.startOfDay());
    return *this;
}

GenTodo &GenTodo::withStartDate(const QString &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setDtStart(QDate::fromString(date, Qt::ISODate).startOfDay());
    return *this;
}

GenTodo &GenTodo::withStartDate(const QDate &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setDtStart(date.startOfDay());
    return *this;
}

GenTodo &GenTodo::withDueDate(const QString &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setDtDue(QDate::fromString(date, Qt::ISODate).startOfDay());
    return *this;
}

GenTodo &GenTodo::withDueDate(const QDate &date)
{
    m_item.payload<KCalendarCore::Todo::Ptr>()->setDtDue(date.startOfDay());
    return *this;
}