Messagelib

followupreminderselectdatedialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2023 Laurent Montel <[email protected]>
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>
22 using namespace MessageComposer;
23 class MessageComposer::FollowUpReminderSelectDateDialogPrivate
24 {
25 public:
26  KDateComboBox *mDateComboBox = nullptr;
27  Akonadi::CollectionComboBox *mCollectionCombobox = nullptr;
28  QPushButton *mOkButton = nullptr;
29 };
30 
31 FollowUpReminderSelectDateDialog::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(QStringLiteral("ok_button"));
41  d->mOkButton->setDefault(true);
42  d->mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
43  connect(buttonBox, &QDialogButtonBox::accepted, this, &FollowUpReminderSelectDateDialog::accept);
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(QStringLiteral("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(QStringLiteral("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 
78 FollowUpReminderSelectDateDialog::~FollowUpReminderSelectDateDialog() = default;
79 
80 void 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 
86 void FollowUpReminderSelectDateDialog::slotDateChanged()
87 {
88  updateOkButton();
89 }
90 
91 QDate FollowUpReminderSelectDateDialog::selectedDate() const
92 {
93  return d->mDateComboBox->date();
94 }
95 
96 Akonadi::Collection FollowUpReminderSelectDateDialog::collection() const
97 {
98  return d->mCollectionCombobox->currentCollection();
99 }
100 
101 void 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."), i18n("Invalid date"));
106  return;
107  }
108  if (!d->mCollectionCombobox->currentCollection().isValid()) {
109  KMessageBox::error(this, i18n("The selected folder is not valid."), i18n("Invalid folder"));
110  return;
111  }
112  QDialog::accept();
113 }
114 
115 #include "moc_followupreminderselectdatedialog.cpp"
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
virtual void reject()
static QLatin1String todoMimeType()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString i18n(const char *text, const TYPE &arg...)
void textChanged(const QString &text)
virtual void accept()
QDate currentDate()
QDate addDays(qint64 ndays) const const
Key_Return
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void currentIndexChanged(int index)
void setContentsMargins(int left, int top, int right, int bottom)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:02:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.