incidencewhatwhere.cpp 2.51 KB
Newer Older
1
/*
2
3
  SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
4

5
  SPDX-License-Identifier: LGPL-2.0-or-later
6
7
8
9
10
11
12
13
14
15
16
*/

#include "incidencewhatwhere.h"
#include "ui_dialogdesktop.h"

#include "incidenceeditor_debug.h"
#include <KLocalizedString>

using namespace IncidenceEditorNG;

IncidenceWhatWhere::IncidenceWhatWhere(Ui::EventOrTodoDesktop *ui)
Laurent Montel's avatar
Laurent Montel committed
17
18
    : IncidenceEditor(nullptr)
    , mUi(ui)
19
20
{
    setObjectName(QStringLiteral("IncidenceWhatWhere"));
Laurent Montel's avatar
Laurent Montel committed
21
22
23
24
    connect(mUi->mSummaryEdit, &QLineEdit::textChanged, this,
            &IncidenceWhatWhere::checkDirtyStatus);
    connect(mUi->mLocationEdit, &QLineEdit::textChanged, this,
            &IncidenceWhatWhere::checkDirtyStatus);
25
26
}

27
void IncidenceWhatWhere::load(const KCalendarCore::Incidence::Ptr &incidence)
28
29
30
31
32
33
34
35
36
37
38
{
    qCDebug(INCIDENCEEDITOR_LOG);
    mLoadedIncidence = incidence;
    if (mLoadedIncidence) {
        mUi->mSummaryEdit->setText(mLoadedIncidence->summary());
        mUi->mLocationEdit->setText(mLoadedIncidence->location());
    } else {
        mUi->mSummaryEdit->clear();
        mUi->mLocationEdit->clear();
    }

39
40
    mUi->mLocationEdit->setVisible(type() != KCalendarCore::Incidence::TypeJournal);
    mUi->mLocationLabel->setVisible(type() != KCalendarCore::Incidence::TypeJournal);
41
42
43
44

    mWasDirty = false;
}

45
void IncidenceWhatWhere::save(const KCalendarCore::Incidence::Ptr &incidence)
46
47
48
49
50
51
52
53
54
55
{
    Q_ASSERT(incidence);
    incidence->setSummary(mUi->mSummaryEdit->text());
    incidence->setLocation(mUi->mLocationEdit->text());
}

bool IncidenceWhatWhere::isDirty() const
{
    if (mLoadedIncidence) {
        return
Laurent Montel's avatar
Laurent Montel committed
56
57
            (mUi->mSummaryEdit->text() != mLoadedIncidence->summary())
            || (mUi->mLocationEdit->text() != mLoadedIncidence->location());
58
59
    } else {
        return
Laurent Montel's avatar
Laurent Montel committed
60
61
            mUi->mSummaryEdit->text().isEmpty()
            && mUi->mLocationEdit->text().isEmpty();
62
63
64
    }
}

Glen Ditchfield's avatar
Glen Ditchfield committed
65
66
67
68
69
70
71
void IncidenceWhatWhere::focusInvalidField()
{
    if (mUi->mSummaryEdit->text().isEmpty()) {
        mUi->mSummaryEdit->setFocus();
    }
}

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
bool IncidenceWhatWhere::isValid() const
{
    if (mUi->mSummaryEdit->text().isEmpty()) {
        qCDebug(INCIDENCEEDITOR_LOG) << "Specify a title";
        mLastErrorString = i18nc("@info", "Please specify a title.");
        return false;
    } else {
        mLastErrorString.clear();
        return true;
    }
}

void IncidenceWhatWhere::validate()
{
    if (mUi->mSummaryEdit->text().isEmpty()) {
        mUi->mSummaryEdit->setFocus();
    }
}