diff --git a/kaddressbook/plugins/mergelib/manualmerge/mergecontactwidget.cpp b/kaddressbook/plugins/mergelib/manualmerge/mergecontactwidget.cpp index 8d53b36b..89883c80 100644 --- a/kaddressbook/plugins/mergelib/manualmerge/mergecontactwidget.cpp +++ b/kaddressbook/plugins/mergelib/manualmerge/mergecontactwidget.cpp @@ -1,166 +1,162 @@ /* Copyright (c) 2013-2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mergecontactwidget.h" #include "mergecontactwidgetlist.h" #include #include #include #include #include #include #include #include #include #include namespace KABMergeContacts { KADDRESSBOOKMERGELIB_EXPORT QAbstractItemModel *_k_mergeStubModel = nullptr; } using namespace KABMergeContacts; MergeContactWidget::MergeContactWidget(QWidget *parent) : QWidget(parent) , mConflictTypes(MergeContacts::None) { QVBoxLayout *lay = new QVBoxLayout(this); lay->setContentsMargins(0, 0, 0, 0); QSplitter *splitter = new QSplitter; splitter->setObjectName(QStringLiteral("splitter")); splitter->setChildrenCollapsible(false); lay->addWidget(splitter); QWidget *selectContactWidget = new QWidget(this); selectContactWidget->setObjectName(QStringLiteral("selectcontactwidget")); QVBoxLayout *vbox = new QVBoxLayout; selectContactWidget->setLayout(vbox); QLabel *lab = new QLabel(i18n("Select contacts that you really want to merge:")); vbox->addWidget(lab); mListWidget = new MergeContactWidgetList; mListWidget->setObjectName(QStringLiteral("listcontact")); mListWidget->setSelectionMode(QAbstractItemView::SingleSelection); vbox->addWidget(mListWidget); connect(mListWidget, &MergeContactWidgetList::itemSelectionChanged, this, &MergeContactWidget::slotUpdateMergeButton); connect(mListWidget, &MergeContactWidgetList::itemChanged, this, &MergeContactWidget::slotUpdateMergeButton); splitter->addWidget(selectContactWidget); mMergeContactInfoWidget = new MergeContactInfoWidget; mMergeContactInfoWidget->setObjectName(QStringLiteral("mergecontactinfowidget")); splitter->addWidget(mMergeContactInfoWidget); mMergeContactWarning = new MergeContactLoseInformationWarning; mMergeContactWarning->setObjectName(QStringLiteral("mergecontactwarning")); connect(mMergeContactWarning, &MergeContactLoseInformationWarning::continueMerging, this, &MergeContactWidget::slotAutomaticMerging); connect(mMergeContactWarning, &MergeContactLoseInformationWarning::customizeMergingContacts, this, &MergeContactWidget::slotCustomizeMergingContacts); lay->addWidget(mMergeContactWarning); QHBoxLayout *hbox = new QHBoxLayout; hbox->addStretch(); lab = new QLabel(i18n("Select the addressbook in which to store merged contacts:")); hbox->addWidget(lab); mCollectionCombobox = new Akonadi::CollectionComboBox(_k_mergeStubModel); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << KContacts::Addressee::mimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &MergeContactWidget::slotUpdateMergeButton); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &MergeContactWidget::slotUpdateMergeButton); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &MergeContactWidget::slotUpdateMergeButton); hbox->addWidget(mCollectionCombobox); lay->addLayout(hbox); mMergeButton = new QPushButton(i18n("merge")); mMergeButton->setObjectName(QStringLiteral("mergebutton")); hbox->addWidget(mMergeButton); mMergeButton->setEnabled(false); connect(mMergeButton, &QPushButton::clicked, this, &MergeContactWidget::slotMergeContacts); } MergeContactWidget::~MergeContactWidget() { } void MergeContactWidget::setContacts(const Akonadi::Item::List &items) { mItems = items; mListWidget->fillListContact(mItems); } Akonadi::Item::List MergeContactWidget::listSelectedContacts() const { return mListWidget->listSelectedContacts(); } Akonadi::Item MergeContactWidget::currentItem() const { return mListWidget->currentAkonadiItem(); } void MergeContactWidget::slotUpdateMergeButton() { const Akonadi::Item::List listCheckedItems = listSelectedContacts(); Akonadi::Item item = currentItem(); mMergeContactInfoWidget->setContact(item); mMergeButton->setEnabled((listCheckedItems.count() >= 2) && mCollectionCombobox->currentCollection().isValid()); } void MergeContactWidget::slotMergeContacts() { mSelectedItems = listSelectedContacts(); const Akonadi::Collection col = mCollectionCombobox->currentCollection(); KABMergeContacts::MergeContacts mergeContacts; mergeContacts.setItems(mSelectedItems); mConflictTypes = mergeContacts.requiresManualSelectionOfInformation(); if (mConflictTypes != MergeContacts::None) { mMergeContactWarning->animatedShow(); } else { slotAutomaticMerging(); } } void MergeContactWidget::slotAutomaticMerging() { KABMergeContacts::MergeContactsJob *job = new KABMergeContacts::MergeContactsJob(this); job->setListItem(mSelectedItems); job->setDestination(mCollectionCombobox->currentCollection()); connect(job, &MergeContactsJob::finished, this, &MergeContactWidget::slotMergeDone); job->start(); } void MergeContactWidget::slotCustomizeMergingContacts() { Q_EMIT customizeMergeContact(mSelectedItems, mConflictTypes, mCollectionCombobox->currentCollection()); } void MergeContactWidget::slotMergeDone(const Akonadi::Item &item) { Q_EMIT contactMerged(item); } diff --git a/kaddressbook/plugins/mergelib/searchduplicate/searchduplicateresultwidget.cpp b/kaddressbook/plugins/mergelib/searchduplicate/searchduplicateresultwidget.cpp index 289f8c59..3f716433 100644 --- a/kaddressbook/plugins/mergelib/searchduplicate/searchduplicateresultwidget.cpp +++ b/kaddressbook/plugins/mergelib/searchduplicate/searchduplicateresultwidget.cpp @@ -1,164 +1,160 @@ /* Copyright (c) 2015-2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "searchduplicateresultwidget.h" #include "widgets/mergecontactloseinformationwarning.h" #include "job/mergecontactsjob.h" #include "job/mergecontacts.h" #include "resultduplicatetreewidget.h" #include #include #include #include #include #include #include namespace KABMergeContacts { KADDRESSBOOKMERGELIB_EXPORT QAbstractItemModel *_k_searchDuplicateResultStubModel = nullptr; } using namespace KABMergeContacts; SearchDuplicateResultWidget::SearchDuplicateResultWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); QSplitter *splitter = new QSplitter; splitter->setObjectName(QStringLiteral("splitter")); splitter->setChildrenCollapsible(false); mainLayout->addWidget(splitter); mResult = new ResultDuplicateTreeWidget; mResult->setObjectName(QStringLiteral("result_treewidget")); mContactViewer = new KAddressBookGrantlee::GrantleeContactViewer; mContactViewer->setObjectName(QStringLiteral("contact_viewer")); splitter->addWidget(mResult); splitter->addWidget(mContactViewer); connect(mResult, &ResultDuplicateTreeWidget::showContactPreview, mContactViewer, &KAddressBookGrantlee::GrantleeContactViewer::setContact); mMergeContactWarning = new MergeContactLoseInformationWarning; mMergeContactWarning->setObjectName(QStringLiteral("mergecontactwarning")); connect(mMergeContactWarning, &MergeContactLoseInformationWarning::continueMerging, this, &SearchDuplicateResultWidget::slotAutomaticMerging); connect(mMergeContactWarning, &MergeContactLoseInformationWarning::customizeMergingContacts, this, &SearchDuplicateResultWidget::slotCustomizeMergingContacts); mainLayout->addWidget(mMergeContactWarning); QHBoxLayout *mergeLayout = new QHBoxLayout; mainLayout->addLayout(mergeLayout); mergeLayout->addStretch(); QLabel *lab = new QLabel(i18n("Select AddressBook:")); lab->setObjectName(QStringLiteral("select_addressbook_label")); mergeLayout->addWidget(lab); mCollectionCombobox = new Akonadi::CollectionComboBox(_k_searchDuplicateResultStubModel); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << KContacts::Addressee::mimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &SearchDuplicateResultWidget::slotUpdateMergeButton); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &SearchDuplicateResultWidget::slotUpdateMergeButton); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &SearchDuplicateResultWidget::slotUpdateMergeButton); mergeLayout->addWidget(mCollectionCombobox); mMergeContact = new QPushButton(i18n("Merge")); mMergeContact->setObjectName(QStringLiteral("merge_contact_button")); connect(mMergeContact, &QPushButton::clicked, this, &SearchDuplicateResultWidget::slotMergeContact); mergeLayout->addWidget(mMergeContact); mMergeContact->setEnabled(false); //TODO make mMergeContact enable when selected item and collection valid } SearchDuplicateResultWidget::~SearchDuplicateResultWidget() { } void SearchDuplicateResultWidget::setContacts(const QVector &lstItem) { mResult->setContacts(lstItem); } void SearchDuplicateResultWidget::slotMergeContact() { mIndexListContact = 0; mListContactToMerge = mResult->selectedContactsToMerge(); if (!mListContactToMerge.isEmpty()) { KABMergeContacts::MergeContacts mergeContacts; bool conflictFound = false; mResultConflictList.clear(); for (const Akonadi::Item::List &lst : qAsConst(mListContactToMerge)) { mergeContacts.setItems(lst); const MergeContacts::ConflictInformations conflicts = mergeContacts.requiresManualSelectionOfInformation(); if (conflicts != MergeContacts::None) { conflictFound = true; } MergeConflictResult result; result.list = lst; result.conflictInformation = conflicts; mResultConflictList.append(result); } mMergeContact->setEnabled(false); if (conflictFound) { mMergeContactWarning->animatedShow(); } else { //Detect if conflict. mergeContact(); } } } void SearchDuplicateResultWidget::mergeContact() { if (mIndexListContact < mListContactToMerge.count()) { KABMergeContacts::MergeContactsJob *job = new KABMergeContacts::MergeContactsJob(this); job->setListItem(mListContactToMerge.at(mIndexListContact)); job->setDestination(mCollectionCombobox->currentCollection()); connect(job, &KABMergeContacts::MergeContactsJob::finished, this, &SearchDuplicateResultWidget::slotMergeDone); job->start(); } else { Q_EMIT mergeDone(); } } void SearchDuplicateResultWidget::slotMergeDone(const Akonadi::Item &item) { ++mIndexListContact; Q_EMIT contactMerged(item); mergeContact(); } void SearchDuplicateResultWidget::slotUpdateMergeButton() { mMergeContact->setEnabled(mCollectionCombobox->currentCollection().isValid()); } void SearchDuplicateResultWidget::slotAutomaticMerging() { mergeContact(); } void SearchDuplicateResultWidget::slotCustomizeMergingContacts() { Q_EMIT customizeMergeContact(mResultConflictList, mCollectionCombobox->currentCollection()); } diff --git a/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp b/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp index 6cc00f8c..160213fd 100644 --- a/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp +++ b/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp @@ -1,101 +1,97 @@ /* Copyright (C) 2016-2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "automaticaddcontactstabwidget.h" #include #include #include #include #include #include #include #include #include namespace { QString configGroupName() { return QStringLiteral("Automatic Add Contacts %1"); } } AutomaticAddContactsTabWidget::AutomaticAddContactsTabWidget(QWidget *parent, QAbstractItemModel *model) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainlayout")); mEnabled = new QCheckBox(i18n("Automatic Add Contacts"), this); mEnabled->setObjectName(QStringLiteral("enabled")); connect(mEnabled, &QCheckBox::clicked, this, &AutomaticAddContactsTabWidget::configureChanged); mainLayout->addWidget(mEnabled); QHBoxLayout *hlay = new QHBoxLayout; hlay->setContentsMargins(0, 0, 0, 0); hlay->setObjectName(QStringLiteral("folderlayout")); mainLayout->addLayout(hlay); QLabel *lab = new QLabel(i18n("Select the addressbook in which to store contacts:"), this); lab->setObjectName(QStringLiteral("labelfolder")); hlay->addWidget(lab); mCollectionCombobox = new Akonadi::CollectionComboBox(model, this); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << KContacts::Addressee::mimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); hlay->addWidget(mCollectionCombobox); hlay->addStretch(1); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &AutomaticAddContactsTabWidget::configureChanged); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &AutomaticAddContactsTabWidget::configureChanged); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &AutomaticAddContactsTabWidget::configureChanged); mainLayout->addStretch(1); } AutomaticAddContactsTabWidget::~AutomaticAddContactsTabWidget() { } void AutomaticAddContactsTabWidget::resetSettings() { mEnabled->setChecked(false); } void AutomaticAddContactsTabWidget::loadSettings() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup grp = config->group(configGroupName().arg(mIdentity)); mEnabled->setChecked(grp.readEntry("Enabled", false)); mCollectionCombobox->setDefaultCollection(Akonadi::Collection(grp.readEntry("Collection", -1))); } void AutomaticAddContactsTabWidget::setIdentity(uint identity) { mIdentity = identity; } void AutomaticAddContactsTabWidget::saveSettings() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup grp = config->group(configGroupName().arg(mIdentity)); grp.writeEntry("Enabled", mEnabled->isChecked()); grp.writeEntry("Collection", mCollectionCombobox->currentCollection().id()); } diff --git a/plugins/messageviewerplugins/createeventplugin/eventedit.cpp b/plugins/messageviewerplugins/createeventplugin/eventedit.cpp index eb1f39d3..3ecbed73 100644 --- a/plugins/messageviewerplugins/createeventplugin/eventedit.cpp +++ b/plugins/messageviewerplugins/createeventplugin/eventedit.cpp @@ -1,379 +1,375 @@ /* Copyright (C) 2014-2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "eventedit.h" #include "createeventplugin_debug.h" #include "globalsettings_messageviewer.h" #include "eventdatetimewidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { QAbstractItemModel *_k_eventEditStubModel = nullptr; } using namespace MessageViewer; EventEdit::EventEdit(QWidget *parent) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(5, 5, 5, 5); vbox->setSpacing(2); QHBoxLayout *hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); QLabel *lab = new QLabel(i18n("Event:"), this); hbox->addWidget(lab); mEventEdit = new QLineEdit(this); mEventEdit->setClearButtonEnabled(true); mEventEdit->setObjectName(QStringLiteral("eventedit")); mEventEdit->setFocus(); connect(mEventEdit, &QLineEdit::returnPressed, this, &EventEdit::slotReturnPressed); connect(mEventEdit, &QLineEdit::textChanged, this, &EventEdit::slotUpdateButtons); hbox->addWidget(mEventEdit); hbox->addSpacing(5); mCollectionCombobox = new Akonadi::CollectionComboBox(_k_eventEditStubModel, this); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << KCalendarCore::Event::eventMimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); #ifndef QT_NO_ACCESSIBILITY mCollectionCombobox->setAccessibleDescription(i18n("Calendar where the new event will be stored.")); #endif mCollectionCombobox->setToolTip(i18n("Calendar where the new event will be stored")); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &EventEdit::slotCollectionChanged); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &EventEdit::slotCollectionChanged); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &EventEdit::slotCollectionChanged); connect(mCollectionCombobox->model(), &QAbstractItemModel::rowsInserted, this, &EventEdit::comboboxRowInserted); hbox->addWidget(mCollectionCombobox); hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); lab = new QLabel(i18n("Start:"), this); hbox->addWidget(lab); QDateTime currentDateTime = QDateTime::currentDateTime(); mStartDateTimeEdit = new EventDateTimeWidget(this); mStartDateTimeEdit->setObjectName(QStringLiteral("startdatetimeedit")); mStartDateTimeEdit->setDateTime(currentDateTime); #ifndef QT_NO_ACCESSIBILITY mStartDateTimeEdit->setAccessibleDescription(i18n("Select start time for event.")); #endif connect(mStartDateTimeEdit, &EventDateTimeWidget::dateTimeChanged, this, &EventEdit::slotStartDateTimeChanged); hbox->addWidget(mStartDateTimeEdit); hbox->addSpacing(5); lab = new QLabel(i18n("End:"), this); hbox->addWidget(lab); mEndDateTimeEdit = new EventDateTimeWidget(this); mEndDateTimeEdit->setObjectName(QStringLiteral("enddatetimeedit")); mEndDateTimeEdit->setDateTime(currentDateTime.addSecs(3600)); #ifndef QT_NO_ACCESSIBILITY mEndDateTimeEdit->setAccessibleDescription(i18n("Select end time for event.")); #endif connect(mEndDateTimeEdit, &EventDateTimeWidget::dateTimeChanged, this, &EventEdit::slotEndDateTimeChanged); hbox->addWidget(mEndDateTimeEdit); hbox->addStretch(1); hbox = new QHBoxLayout; hbox->setSpacing(2); hbox->setContentsMargins(0, 0, 0, 0); vbox->addLayout(hbox); hbox->addStretch(1); mSaveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("appointment-new")), i18n("&Save"), this); mSaveButton->setObjectName(QStringLiteral("save-button")); mSaveButton->setEnabled(false); #ifndef QT_NO_ACCESSIBILITY mSaveButton->setAccessibleDescription(i18n("Create new event and close this widget.")); #endif connect(mSaveButton, &QPushButton::clicked, this, &EventEdit::slotReturnPressed); hbox->addWidget(mSaveButton); mOpenEditorButton = new QPushButton(i18n("Open &editor..."), this); #ifndef QT_NO_ACCESSIBILITY mOpenEditorButton->setAccessibleDescription(i18n("Open event editor, where more details can be changed.")); #endif mOpenEditorButton->setObjectName(QStringLiteral("open-editor-button")); mOpenEditorButton->setEnabled(false); connect(mOpenEditorButton, &QPushButton::clicked, this, &EventEdit::slotOpenEditor); hbox->addWidget(mOpenEditorButton); QPushButton *btn = new QPushButton(this); KGuiItem::assign(btn, KStandardGuiItem::cancel()); btn->setObjectName(QStringLiteral("close-button")); #ifndef QT_NO_ACCESSIBILITY btn->setAccessibleDescription(i18n("Close the widget for creating new events.")); #endif connect(btn, &QPushButton::clicked, this, &EventEdit::slotCloseWidget); hbox->addWidget(btn); readConfig(); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); installEventFilter(this); mCollectionCombobox->installEventFilter(this); } EventEdit::~EventEdit() { writeConfig(); } void EventEdit::comboboxRowInserted() { slotUpdateButtons(mEventEdit->text()); } void EventEdit::writeConfig() { const Akonadi::Collection col = mCollectionCombobox->currentCollection(); // col might not be valid if the collection wasn't found yet (the combo is async), skip saving in that case. if (col.isValid() && col.id() != MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder()) { MessageViewer::MessageViewerSettingsBase::self()->setLastEventSelectedFolder(col.id()); MessageViewer::MessageViewerSettingsBase::self()->save(); } } void EventEdit::slotUpdateButtons(const QString &subject) { const bool subjectIsNotEmpty = !subject.trimmed().isEmpty(); const bool collectionComboboxEmpty = (mCollectionCombobox->count() < 1); mSaveButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty); mOpenEditorButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty); } void EventEdit::showEventEdit() { mEventEdit->setFocus(); QDateTime currentDateTime = QDateTime::currentDateTime(); mStartDateTimeEdit->setDateTime(currentDateTime); mEndDateTimeEdit->setDateTime(currentDateTime.addSecs(3600)); show(); } void EventEdit::readConfig() { const qint64 id = MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder(); if (id >= 0) { mCollectionCombobox->setDefaultCollection(Akonadi::Collection(id)); } } Akonadi::Collection EventEdit::collection() const { return mCollection; } void EventEdit::slotCollectionChanged(int /*index*/) { setCollection(mCollectionCombobox->currentCollection()); } void EventEdit::setCollection(const Akonadi::Collection &value) { if (mCollection != value) { mCollection = value; Q_EMIT collectionChanged(mCollection); } } KMime::Message::Ptr EventEdit::message() const { return mMessage; } void EventEdit::setMessage(const KMime::Message::Ptr &value) { if (mMessage != value) { mMessage = value; const KMime::Headers::Subject *const subject = mMessage ? mMessage->subject(false) : nullptr; if (subject) { mEventEdit->setText(subject->asUnicodeString()); mEventEdit->selectAll(); mEventEdit->setFocus(); } else { mEventEdit->clear(); } Q_EMIT messageChanged(mMessage); } } void EventEdit::slotCloseWidget() { if (isVisible()) { writeConfig(); mEventEdit->clear(); mMessage = KMime::Message::Ptr(); hide(); } } void EventEdit::slotReturnPressed() { if (!mMessage) { qCDebug(CREATEEVENTPLUGIN_LOG) << " Message is null"; return; } const Akonadi::Collection collection = mCollectionCombobox->currentCollection(); if (!collection.isValid()) { qCDebug(CREATEEVENTPLUGIN_LOG) << " Collection is not valid"; return; } const QDateTime dtstart = mStartDateTimeEdit->dateTime(); const QDateTime dtend = mEndDateTimeEdit->dateTime(); if (!dtstart.isValid() || !dtend.isValid()) { qCDebug(CREATEEVENTPLUGIN_LOG) << " date is not valid !"; return; } if (!mEventEdit->text().trimmed().isEmpty()) { KCalendarCore::Event::Ptr event = createEventItem(); Q_EMIT createEvent(event, collection); mEventEdit->clear(); hide(); } } bool EventEdit::eventFilter(QObject *object, QEvent *e) { // Close the bar when pressing Escape. // Not using a QShortcut for this because it could conflict with // window-global actions (e.g. Emil Sedgh binds Esc to "close tab"). // With a shortcut override we can catch this before it gets to kactions. const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride); if (shortCutOverride) { QKeyEvent *kev = static_cast(e); if (kev->key() == Qt::Key_Escape) { e->accept(); slotCloseWidget(); return true; } else if (kev->key() == Qt::Key_Enter || kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Space) { e->accept(); if (object == mCollectionCombobox) { mCollectionCombobox->showPopup(); } return true; } } return QWidget::eventFilter(object, e); } void EventEdit::slotEndDateTimeChanged(const QDateTime &newDateTime) { if (!newDateTime.isValid()) { return; } QDateTime currentDateTime = QDateTime::currentDateTime(); if (newDateTime.date() > currentDateTime.date()) { QDateTime newDateDate = newDateTime; newDateDate.setTime(QTime(0, 0, 0)); mEndDateTimeEdit->setMinimumDateTime(newDateDate); } } void EventEdit::slotStartDateTimeChanged(const QDateTime &newDateTime) { if (!newDateTime.isValid()) { return; } if (mEndDateTimeEdit->date() == newDateTime.date() && mEndDateTimeEdit->time() < newDateTime.time()) { mEndDateTimeEdit->setTime(newDateTime.time()); } if (mEndDateTimeEdit->date() < newDateTime.date()) { mEndDateTimeEdit->setDate(newDateTime.date()); } mEndDateTimeEdit->setMinimumDateTime(newDateTime); } KCalendarCore::Event::Ptr EventEdit::createEventItem() { KCalendarCore::Attachment attachment(mMessage->encodedContent().toBase64(), KMime::Message::mimeType()); const KMime::Headers::Subject *const subject = mMessage->subject(false); if (subject) { attachment.setLabel(subject->asUnicodeString()); } KCalendarCore::Event::Ptr event(new KCalendarCore::Event); event->setSummary(mEventEdit->text()); event->setDtStart(mStartDateTimeEdit->dateTime()); event->setDtEnd(mEndDateTimeEdit->dateTime()); event->addAttachment(attachment); if (CalendarSupport::KCalPrefs::instance()->defaultEventReminders()) { KCalendarCore::Alarm::Ptr alm = event->newAlarm(); CalendarSupport::createAlarmReminder(alm, event->type()); } return event; } void EventEdit::slotOpenEditor() { KCalendarCore::Event::Ptr event = createEventItem(); Akonadi::Item item; item.setPayload(event); item.setMimeType(KCalendarCore::Event::eventMimeType()); IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::create(true, KCalendarCore::IncidenceBase::TypeEvent, nullptr, this); connect(dlg, &IncidenceEditorNG::IncidenceDialog::finished, this, &EventEdit::slotCloseWidget); dlg->load(item); dlg->open(); } diff --git a/plugins/messageviewerplugins/createnoteplugin/noteedit.cpp b/plugins/messageviewerplugins/createnoteplugin/noteedit.cpp index 464aa712..ed214c67 100644 --- a/plugins/messageviewerplugins/createnoteplugin/noteedit.cpp +++ b/plugins/messageviewerplugins/createnoteplugin/noteedit.cpp @@ -1,249 +1,245 @@ /* Copyright (c) 2014 Sandro Knauß * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "noteedit.h" #include "globalsettings_messageviewer.h" #include "createnoteplugin_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { QAbstractItemModel *_k_noteEditStubModel = nullptr; } using namespace MessageViewer; NoteEdit::NoteEdit(QWidget *parent) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(5, 5, 5, 5); vbox->setSpacing(2); QHBoxLayout *hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); QLabel *lab = new QLabel(i18n("Note:"), this); hbox->addWidget(lab); mNoteEdit = new QLineEdit(this); mNoteEdit->setClearButtonEnabled(true); mNoteEdit->setObjectName(QStringLiteral("noteedit")); mNoteEdit->setFocus(); connect(mNoteEdit, &QLineEdit::returnPressed, this, &NoteEdit::slotReturnPressed); connect(mNoteEdit, &QLineEdit::textChanged, this, &NoteEdit::slotUpdateButtons); hbox->addWidget(mNoteEdit); hbox->addSpacing(5); mCollectionCombobox = new Akonadi::CollectionComboBox(_k_noteEditStubModel, this); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << Akonadi::NoteUtils::noteMimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); #ifndef QT_NO_ACCESSIBILITY mCollectionCombobox->setAccessibleDescription(i18n("Calendar where the new event will be stored.")); #endif mCollectionCombobox->setToolTip(i18n("Calendar where the new event will be stored")); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &NoteEdit::slotCollectionChanged); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &NoteEdit::slotCollectionChanged); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &NoteEdit::slotCollectionChanged); hbox->addWidget(mCollectionCombobox); hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); hbox->addStretch(1); hbox = new QHBoxLayout; hbox->setSpacing(2); hbox->setContentsMargins(0, 0, 0, 0); vbox->addLayout(hbox); hbox->addStretch(1); mSaveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("view-pim-notes")), i18n("&Save"), this); mSaveButton->setObjectName(QStringLiteral("save-button")); mSaveButton->setEnabled(false); #ifndef QT_NO_ACCESSIBILITY mSaveButton->setAccessibleDescription(i18n("Create new note and close this widget.")); #endif connect(mSaveButton, &QPushButton::clicked, this, &NoteEdit::slotReturnPressed); hbox->addWidget(mSaveButton); QPushButton *btn = new QPushButton(this); KGuiItem::assign(btn, KStandardGuiItem::cancel()); btn->setObjectName(QStringLiteral("close-button")); #ifndef QT_NO_ACCESSIBILITY btn->setAccessibleDescription(i18n("Close the widget for creating new notes.")); #endif connect(btn, &QPushButton::clicked, this, &NoteEdit::slotCloseWidget); hbox->addWidget(btn); readConfig(); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); installEventFilter(this); mCollectionCombobox->installEventFilter(this); } NoteEdit::~NoteEdit() { writeConfig(); } void NoteEdit::writeConfig() { if (mCollectionCombobox->currentCollection().id() != MessageViewer::MessageViewerSettingsBase::self()->lastNoteSelectedFolder()) { MessageViewer::MessageViewerSettingsBase::self()->setLastNoteSelectedFolder(mCollectionCombobox->currentCollection().id()); MessageViewer::MessageViewerSettingsBase::self()->save(); } } void NoteEdit::slotUpdateButtons(const QString &subject) { const bool subjectIsNotEmpty = !subject.trimmed().isEmpty(); mSaveButton->setEnabled(subjectIsNotEmpty); } void NoteEdit::showNoteEdit() { mNoteEdit->setFocus(); show(); } void NoteEdit::readConfig() { const qint64 id = MessageViewer::MessageViewerSettingsBase::self()->lastNoteSelectedFolder(); if (id != -1) { mCollectionCombobox->setDefaultCollection(Akonadi::Collection(id)); } } Akonadi::Collection NoteEdit::collection() const { return mCollection; } void NoteEdit::slotCollectionChanged(int /*index*/) { setCollection(mCollectionCombobox->currentCollection()); } void NoteEdit::setCollection(const Akonadi::Collection &value) { if (mCollection != value) { mCollection = value; Q_EMIT collectionChanged(mCollection); } } KMime::Message::Ptr NoteEdit::message() const { return mMessage; } void NoteEdit::setMessage(const KMime::Message::Ptr &value) { if (mMessage != value) { mMessage = value; const KMime::Headers::Subject *const subject = mMessage ? mMessage->subject(false) : nullptr; if (subject) { mNoteEdit->setText(subject->asUnicodeString()); mNoteEdit->selectAll(); mNoteEdit->setFocus(); } else { mNoteEdit->clear(); } Q_EMIT messageChanged(mMessage); } } void NoteEdit::slotCloseWidget() { writeConfig(); mNoteEdit->clear(); mMessage = KMime::Message::Ptr(); hide(); } void NoteEdit::slotReturnPressed() { if (!mMessage) { qCDebug(CREATENOTEPLUGIN_LOG) << " Message is null"; return; } const Akonadi::Collection collection = mCollectionCombobox->currentCollection(); if (!collection.isValid()) { qCDebug(CREATENOTEPLUGIN_LOG) << " Collection is not valid"; return; } if (!mNoteEdit->text().trimmed().isEmpty()) { Akonadi::NoteUtils::NoteMessageWrapper note; note.setTitle(mNoteEdit->text()); Q_EMIT createNote(note.message(), collection); mNoteEdit->clear(); hide(); } } bool NoteEdit::eventFilter(QObject *object, QEvent *e) { // Close the bar when pressing Escape. // Not using a QShortcut for this because it could conflict with // window-global actions (e.g. Emil Sedgh binds Esc to "close tab"). // With a shortcut override we can catch this before it gets to kactions. const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride); if (shortCutOverride) { QKeyEvent *kev = static_cast(e); if (kev->key() == Qt::Key_Escape) { e->accept(); slotCloseWidget(); return true; } else if (kev->key() == Qt::Key_Enter || kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Space) { e->accept(); if (object == mCollectionCombobox) { mCollectionCombobox->showPopup(); } return true; } } return QWidget::eventFilter(object, e); } diff --git a/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp b/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp index cc05d9b9..06558f93 100644 --- a/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp +++ b/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp @@ -1,334 +1,330 @@ /* Copyright (C) 2014-2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "todoedit.h" #include "globalsettings_messageviewer.h" #include "createtodoplugin_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { QAbstractItemModel *_k_todoEditStubModel = nullptr; } using namespace MessageViewer; TodoEdit::TodoEdit(QWidget *parent) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(5, 5, 5, 5); vbox->setSpacing(2); mMsgWidget = new KMessageWidget(this); mMsgWidget->setCloseButtonVisible(true); mMsgWidget->setMessageType(KMessageWidget::Positive); mMsgWidget->setObjectName(QStringLiteral("msgwidget")); mMsgWidget->setWordWrap(true); mMsgWidget->setVisible(false); vbox->addWidget(mMsgWidget); QHBoxLayout *hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); QLabel *lab = new QLabel(i18n("Todo:"), this); hbox->addWidget(lab); mNoteEdit = new QLineEdit(this); mNoteEdit->setClearButtonEnabled(true); mNoteEdit->setObjectName(QStringLiteral("noteedit")); mNoteEdit->setFocus(); connect(mNoteEdit, &QLineEdit::textChanged, this, &TodoEdit::slotTextEdited); connect(mNoteEdit, &QLineEdit::returnPressed, this, &TodoEdit::slotReturnPressed); hbox->addWidget(mNoteEdit, 1); hbox->addSpacing(5); mCollectionCombobox = new Akonadi::CollectionComboBox(_k_todoEditStubModel, this); mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); mCollectionCombobox->setMinimumWidth(250); mCollectionCombobox->setMimeTypeFilter(QStringList() << KCalendarCore::Todo::todoMimeType()); mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox")); connect(mCollectionCombobox->model(), &QAbstractItemModel::rowsInserted, this, &TodoEdit::comboboxRowInserted); #ifndef QT_NO_ACCESSIBILITY mCollectionCombobox->setAccessibleDescription(i18n("Todo list where the new task will be stored.")); #endif mCollectionCombobox->setToolTip(i18n("Todo list where the new task will be stored")); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &TodoEdit::slotCollectionChanged); -#else - connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &TodoEdit::slotCollectionChanged); -#endif connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::activated), this, &TodoEdit::slotCollectionChanged); hbox->addWidget(mCollectionCombobox); hbox = new QHBoxLayout; hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(2); vbox->addLayout(hbox); hbox->addStretch(1); mSaveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("task-new")), i18n("&Save"), this); mSaveButton->setObjectName(QStringLiteral("save-button")); mSaveButton->setEnabled(false); #ifndef QT_NO_ACCESSIBILITY mSaveButton->setAccessibleDescription(i18n("Create new todo and close this widget.")); #endif connect(mSaveButton, &QPushButton::clicked, this, &TodoEdit::slotReturnPressed); hbox->addWidget(mSaveButton); mOpenEditorButton = new QPushButton(i18n("Open &Editor..."), this); mOpenEditorButton->setObjectName(QStringLiteral("open-editor-button")); #ifndef QT_NO_ACCESSIBILITY mOpenEditorButton->setAccessibleDescription(i18n("Open todo editor, where more details can be changed.")); #endif mOpenEditorButton->setEnabled(false); connect(mOpenEditorButton, &QPushButton::clicked, this, &TodoEdit::slotOpenEditor); hbox->addWidget(mOpenEditorButton); QPushButton *btn = new QPushButton(this); KGuiItem::assign(btn, KStandardGuiItem::cancel()); btn->setObjectName(QStringLiteral("close-button")); #ifndef QT_NO_ACCESSIBILITY btn->setAccessibleDescription(i18n("Close the widget for creating new todos.")); #endif connect(btn, &QPushButton::clicked, this, &TodoEdit::slotCloseWidget); hbox->addWidget(btn); readConfig(); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); mCollectionCombobox->installEventFilter(this); installEventFilter(this); } TodoEdit::~TodoEdit() { writeConfig(); } void TodoEdit::comboboxRowInserted() { updateButtons(mNoteEdit->text()); } void TodoEdit::updateButtons(const QString &subject) { const bool subjectIsNotEmpty = !subject.trimmed().isEmpty(); const bool collectionComboboxEmpty = (mCollectionCombobox->count() < 1); mSaveButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty); mOpenEditorButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty); } void TodoEdit::showToDoWidget() { const KMime::Headers::Subject *const subject = mMessage ? mMessage->subject(false) : nullptr; if (subject) { bool isSentFolder = false; if (mCurrentCollection.isValid()) { isSentFolder = (Akonadi::SpecialMailCollections::self()->defaultCollection(Akonadi::SpecialMailCollections::SentMail) == mCurrentCollection); } mNoteEdit->setText(isSentFolder ? i18n("Check I received a reply about \"%1\"", subject->asUnicodeString()) : i18n("Reply to \"%1\"", subject->asUnicodeString())); mNoteEdit->selectAll(); mNoteEdit->setFocus(); } else { mNoteEdit->clear(); } mNoteEdit->setFocus(); show(); } void TodoEdit::setCurrentCollection(const Akonadi::Collection &col) { mCurrentCollection = col; } void TodoEdit::writeConfig() { const Akonadi::Collection col = mCollectionCombobox->currentCollection(); // col might not be valid if the collection wasn't found yet (the combo is async), skip saving in that case if (col.isValid() && col.id() != MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder()) { MessageViewer::MessageViewerSettingsBase::self()->setLastSelectedFolder(col.id()); MessageViewer::MessageViewerSettingsBase::self()->save(); } } void TodoEdit::readConfig() { const qint64 id = MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(); if (id != -1) { mCollectionCombobox->setDefaultCollection(Akonadi::Collection(id)); } } Akonadi::Collection TodoEdit::collection() const { return mCollection; } void TodoEdit::slotCollectionChanged(int /*index*/) { setCollection(mCollectionCombobox->currentCollection()); } void TodoEdit::setCollection(const Akonadi::Collection &value) { if (mCollection != value) { mCollection = value; Q_EMIT collectionChanged(mCollection); } } KMime::Message::Ptr TodoEdit::message() const { return mMessage; } void TodoEdit::setMessage(const KMime::Message::Ptr &value) { if (mMessage != value) { mMessage = value; Q_EMIT messageChanged(mMessage); } } void TodoEdit::slotCloseWidget() { if (isVisible()) { writeConfig(); mNoteEdit->clear(); mMessage = KMime::Message::Ptr(); mMsgWidget->hide(); hide(); } } void TodoEdit::slotReturnPressed() { if (!mMessage) { qCDebug(CREATETODOPLUGIN_LOG) << " Message is null"; return; } const Akonadi::Collection collection = mCollectionCombobox->currentCollection(); if (!collection.isValid()) { qCDebug(CREATETODOPLUGIN_LOG) << " Collection is not valid"; return; } if (!mNoteEdit->text().trimmed().isEmpty()) { mMsgWidget->setText(i18nc("%1 is summary of the todo, %2 is name of the folder in which it is stored", "New todo '%1' was added to task list '%2'", mNoteEdit->text(), collection.displayName())); KCalendarCore::Todo::Ptr todo = createTodoItem(); mNoteEdit->clear(); // We don't hide the widget here, so that multiple todo's can be added Q_EMIT createTodo(todo, collection); mMsgWidget->animatedShow(); } } KCalendarCore::Todo::Ptr TodoEdit::createTodoItem() { KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo); todo->setSummary(mNoteEdit->text()); KCalendarCore::Attachment attachment(mMessage->encodedContent().toBase64(), KMime::Message::mimeType()); const KMime::Headers::Subject *const subject = mMessage->subject(false); if (subject) { attachment.setLabel(subject->asUnicodeString()); } if (CalendarSupport::KCalPrefs::instance()->defaultTodoReminders()) { KCalendarCore::Alarm::Ptr alm = todo->newAlarm(); CalendarSupport::createAlarmReminder(alm, todo->type()); } todo->addAttachment(attachment); return todo; } bool TodoEdit::eventFilter(QObject *object, QEvent *e) { // Close the bar when pressing Escape. // Not using a QShortcut for this because it could conflict with // window-global actions (e.g. Emil Sedgh binds Esc to "close tab"). // With a shortcut override we can catch this before it gets to kactions. const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride); if (shortCutOverride || e->type() == QEvent::KeyPress) { QKeyEvent *kev = static_cast(e); if (kev->key() == Qt::Key_Escape) { e->accept(); slotCloseWidget(); return true; } else if (kev->key() == Qt::Key_Enter || kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Space) { e->accept(); if (shortCutOverride) { return true; } if (object == mCollectionCombobox) { mCollectionCombobox->showPopup(); return true; } } } return QWidget::eventFilter(object, e); } void TodoEdit::slotOpenEditor() { KCalendarCore::Todo::Ptr event = createTodoItem(); Akonadi::Item item; item.setPayload(event); item.setMimeType(KCalendarCore::Todo::todoMimeType()); IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::create(true, KCalendarCore::IncidenceBase::TypeTodo, nullptr, this); connect(dlg, &IncidenceEditorNG::IncidenceDialog::finished, this, &TodoEdit::slotCloseWidget); dlg->load(item); dlg->open(); } void TodoEdit::slotTextEdited(const QString &subject) { updateButtons(subject); if (mMsgWidget->isVisible()) { mMsgWidget->hide(); } }