Messagelib

followupreminderselectdatedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "followupreminderselectdatedialog.h"
8
9#include <KDateComboBox>
10#include <KLocalizedString>
11#include <KMessageBox>
12#include <KSharedConfig>
13
14#include <Akonadi/CollectionComboBox>
15
16#include <KCalendarCore/Todo>
17
18#include <QDialogButtonBox>
19#include <QFormLayout>
20#include <QLineEdit>
21#include <QVBoxLayout>
22using namespace MessageComposer;
23class MessageComposer::FollowUpReminderSelectDateDialogPrivate
24{
25public:
26 KDateComboBox *mDateComboBox = nullptr;
27 Akonadi::CollectionComboBox *mCollectionCombobox = nullptr;
28 QPushButton *mOkButton = nullptr;
29};
30
31FollowUpReminderSelectDateDialog::FollowUpReminderSelectDateDialog(QWidget *parent, QAbstractItemModel *model)
32 : QDialog(parent)
33 , d(new MessageComposer::FollowUpReminderSelectDateDialogPrivate)
34{
35 setWindowTitle(i18nc("@title:window", "Select Date"));
36 auto topLayout = new QVBoxLayout(this);
37
39 d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
40 d->mOkButton->setObjectName(QLatin1StringView("ok_button"));
41 d->mOkButton->setDefault(true);
42 d->mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
43 connect(buttonBox, &QDialogButtonBox::accepted, this, &FollowUpReminderSelectDateDialog::accept);
44 connect(buttonBox, &QDialogButtonBox::rejected, this, &FollowUpReminderSelectDateDialog::reject);
45 setModal(true);
46
47 auto mainWidget = new QWidget(this);
48 topLayout->addWidget(mainWidget);
49 topLayout->addWidget(buttonBox);
50 auto mainLayout = new QVBoxLayout(mainWidget);
51 mainLayout->setContentsMargins({});
52 auto formLayout = new QFormLayout;
53 formLayout->setContentsMargins({});
54 mainLayout->addLayout(formLayout);
55
56 d->mDateComboBox = new KDateComboBox;
57 QDate currentDate = QDate::currentDate().addDays(1);
58 d->mDateComboBox->setMinimumDate(QDate::currentDate());
59 d->mDateComboBox->setObjectName(QLatin1StringView("datecombobox"));
60
61 d->mDateComboBox->setDate(currentDate);
62
63 formLayout->addRow(i18n("Date:"), d->mDateComboBox);
64
65 d->mCollectionCombobox = new Akonadi::CollectionComboBox(model);
66 d->mCollectionCombobox->setMinimumWidth(250);
67 d->mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
68 d->mCollectionCombobox->setMimeTypeFilter(QStringList() << KCalendarCore::Todo::todoMimeType());
69 d->mCollectionCombobox->setObjectName(QLatin1StringView("collectioncombobox"));
70
71 formLayout->addRow(i18n("Store to-do in:"), d->mCollectionCombobox);
72
73 connect(d->mDateComboBox->lineEdit(), &QLineEdit::textChanged, this, &FollowUpReminderSelectDateDialog::slotDateChanged);
74 connect(d->mCollectionCombobox, &Akonadi::CollectionComboBox::currentIndexChanged, this, &FollowUpReminderSelectDateDialog::updateOkButton);
75 updateOkButton();
76}
77
78FollowUpReminderSelectDateDialog::~FollowUpReminderSelectDateDialog() = default;
79
80void FollowUpReminderSelectDateDialog::updateOkButton()
81{
82 d->mOkButton->setEnabled(!d->mDateComboBox->lineEdit()->text().isEmpty() && d->mDateComboBox->date().isValid() && (d->mCollectionCombobox->count() > 0)
83 && d->mCollectionCombobox->currentCollection().isValid());
84}
85
86void FollowUpReminderSelectDateDialog::slotDateChanged()
87{
88 updateOkButton();
89}
90
91QDate FollowUpReminderSelectDateDialog::selectedDate() const
92{
93 return d->mDateComboBox->date();
94}
95
96Akonadi::Collection FollowUpReminderSelectDateDialog::collection() const
97{
98 return d->mCollectionCombobox->currentCollection();
99}
100
101void FollowUpReminderSelectDateDialog::accept()
102{
103 const QDate date = selectedDate();
104 if (date < QDate::currentDate()) {
105 KMessageBox::error(this, i18n("The selected date must be greater than the current date."), i18nc("@title:window", "Invalid date"));
106 return;
107 }
108 if (!d->mCollectionCombobox->currentCollection().isValid()) {
109 KMessageBox::error(this, i18n("The selected folder is not valid."), i18nc("@title:window", "Invalid folder"));
110 return;
111 }
113}
114
115#include "moc_followupreminderselectdatedialog.cpp"
static QLatin1String todoMimeType()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
void currentIndexChanged(int index)
QDate addDays(qint64 ndays) const const
QDate currentDate()
bool setDate(int year, int month, int day)
virtual void accept()
void setContentsMargins(const QMargins &margins)
void textChanged(const QString &text)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.