diff --git a/CMakeLists.txt b/CMakeLists.txt index 76ae4e84..a770a04e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,191 +1,191 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.12.40") project(kdepim-addons VERSION ${PIM_VERSION}) if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() set(KF5_MIN_VERSION "5.60.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ ${ECM_MODULE_PATH}) set(CMAKE_AUTORCC TRUE) # Do NOT add quote set(KDEPIM_DEV_VERSION alpha) # add an extra space if(DEFINED KDEPIM_DEV_VERSION) set(KDEPIM_DEV_VERSION " ${KDEPIM_DEV_VERSION}") endif() set(KDEPIMADDONS_VERSION_NUMBER ${PIM_VERSION}) set(KDEPIMADDONS_VERSION "${KDEPIMADDONS_VERSION_NUMBER}${KDEPIM_DEV_VERSION}") set(KDEPIMADDONS_LIB_VERSION "${KDEPIMADDONS_VERSION_NUMBER}") set(KDEPIMADDONS_LIB_SOVERSION "5") set(AKONADINOTES_LIB_VERSION "5.12.40") set(QT_REQUIRED_VERSION "5.11.0") include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddTests) include(GenerateExportHeader) include(ECMGenerateHeaders) include(FeatureSummary) include(CheckFunctionExists) include(ECMGeneratePriFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) option(KDEPIMADDONS_BUILD_EXAMPLES "Build the kdepim-addons example applications." TRUE) option(KDEPIM_ENTERPRISE_BUILD "Enable features specific to the enterprise branch, which are normally disabled. Also, it disables many components not needed for Kontact such as the Kolab client." FALSE) option(KMAIL_EDITORCONVERTERPLUGIN_TEMPLATE_BUILD "Build the kmail editor converter plugin." FALSE) option(KMAIL_DKIM_CONFIGURE_DIALOG_BUILD "Build dkim-verify configure dialog (experimental)." FALSE) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets Widgets Test) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Config ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiNotes ${AKONADINOTES_LIB_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Declarative ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5SyntaxHighlighting ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Parts ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Prison ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Holidays ${KF5_MIN_VERSION} CONFIG REQUIRED) set(MAILCOMMON_LIB_VERSION "5.12.40") set(GRAVATAR_LIB_VERSION "5.12.40") set(PIMCOMMON_LIB_VERSION "5.12.40") set(GRANTLEETHEME_LIB_VERSION "5.12.40") -set(CALENDARSUPPORT_LIB_VERSION "5.12.40") +set(CALENDARSUPPORT_LIB_VERSION "5.12.41") set(EVENTVIEW_LIB_VERSION "5.12.40") set(LIBKDEPIM_LIB_VERSION "5.12.40") set(KDEPIM_APPS_LIB_VERSION "5.12.40") set(LIBKLEO_LIB_VERSION "5.12.40") set(AKONADI_LIB_VERSION "5.12.40") set(INCIDENCEEDITOR_LIB_VERSION "5.12.40") set(KTNEF_LIB_VERSION "5.12.40") set(MESSAGELIB_LIB_VERSION "5.12.42") set(AKONADICALENDAR_LIB_VERSION "5.12.40") set(CALENDAR_UTILS_VERSION "5.12.40") set(KPIMTEXTEDIT_LIB_VERSION "5.12.41") set(KIMAP_LIB_VERSION "5.12.40") set(LIBKSIEVE_LIB_VERSION "5.12.40") set(KMAILTRANSPORT_LIB_VERSION "5.12.40") set(AKONADICONTACT_LIB_VERSION "5.12.40") set(KCONTACTS_LIB_VERSION "5.12.40") set(IMPORTWIZARD_LIB_VERSION "5.12.40") set(MAILIMPORTER_LIB_VERSION "5.12.40") set(KPIMPKPASS_LIB_VERSION "5.12.40") set(KPIMITINERARY_LIB_VERSION "5.12.41") set(KCALENDARCORE_LIB_VERSION "5.12.40") set(KONTACTINTERFACE_LIB_VERSION "5.12.40") set(CALENDARSUPPORT_LIB_VERSION_LIB "5.12.40") find_package(KF5CalendarCore ${KCALENDARCORE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarUtils ${CALENDAR_UTILS_VERSION} CONFIG REQUIRED) find_package(KF5WebEngineViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5TemplateParser ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailCommon ${MAILCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KaddressbookGrantlee ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KaddressbookImportExport ${KDEPIM_APPS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Libkleo ${LIBKLEO_LIB_VERSION} CONFIG REQUIRED) find_package(KF5GrantleeTheme ${GRANTLEETHEME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IncidenceEditor ${INCIDENCEEDITOR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageCore ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageComposer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageList ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5EventViews ${EVENTVIEW_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Akonadi ${AKONADI_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiCalendar ${AKONADICALENDAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Gravatar ${GRAVATAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IdentityManagement ${KIDENTITYMANAGEMENT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5IMAP ${KIMAP_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibKSieve ${LIBKSIEVE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Tnef ${KTNEF_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailTransportAkonadi ${KMAILTRANSPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Contacts ${KCONTACTS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiContact ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5ContactEditor ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KPimImportWizard ${IMPORTWIZARD_LIB_VERSION} CONFIG) find_package(KF5MailImporterAkonadi ${MAILIMPORTER_LIB_VERSION} CONFIG REQUIRED) find_package(KPimPkPass ${KPIMPKPASS_LIB_VERSION} CONFIG REQUIRED) find_package(KPimItinerary ${KPIMITINERARY_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KontactInterface ${KONTACTINTERFACE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION_LIB} CONFIG REQUIRED) set(CMAKE_CXX_STANDARD 14) if(BUILD_TESTING) add_definitions(-DBUILD_TESTING) endif(BUILD_TESTING) if(KDEPIM_ENTERPRISE_BUILD) set(KDEPIM_ENTERPRISE_BUILD true) else() set(KDEPIM_ENTERPRISE_BUILD false) endif() # Extra package find_package(Gpgmepp 1.11.1 CONFIG) set_package_properties(Gpgmepp PROPERTIES DESCRIPTION "GpgME library" URL "https://www.gnupg.org" TYPE REQUIRED) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_definitions(-DQT_NO_FOREACH) option(KDEPIM_RUN_AKONADI_TEST "Enable autotest based on Akonadi." TRUE) if(KDEPIMADDONS_BUILD_EXAMPLES) add_subdirectory(examples) endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(QTCREATOR_TEMPLATE_INSTALL_DIR ${KDE_INSTALL_DATADIR}/qtcreator/templates CACHE PATH "Define qtcreator template install path (default is /usr/share/qtcreator/templates)") find_package(Discount "2") set_package_properties("discount" PROPERTIES DESCRIPTION "A library that gives you formatting functions suitable for marking down entire documents or lines of text" URL "https://www.pell.portland.or.us/~orc/Code/discount/" TYPE RECOMMENDED PURPOSE "Generate Markdown file.") if(discount_FOUND) if (${PC_LIBMARKDOWN_VERSION_STRING}) if (${PC_LIBMARKDOWN_VERSION_STRING} VERSION_GREATER "2.2.5") set(DISCOUNT_HAS_HIGHLIGHTING_SUPPORT TRUE) MESSAGE(STATUS "Discount ${PC_LIBMARKDOWN_VERSION_STRING}: has hightlighting support") endif() endif() endif() add_subdirectory(plugins) add_subdirectory(korganizer) add_subdirectory(kmail) add_subdirectory(kaddressbook) add_subdirectory(sieveeditor) add_subdirectory(kmailtransport) if(KPimImportWizard_FOUND) add_subdirectory(akonadi-import-wizard) endif() install(FILES kdepim-addons.categories kdepim-addons.renamecategories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/plugins/messageviewerplugins/autotests/CMakeLists.txt b/plugins/messageviewerplugins/autotests/CMakeLists.txt index cca23aa1..f6066fbd 100644 --- a/plugins/messageviewerplugins/autotests/CMakeLists.txt +++ b/plugins/messageviewerplugins/autotests/CMakeLists.txt @@ -1,53 +1,53 @@ set(common_SRCS) ecm_qt_declare_logging_category(common_SRCS HEADER createeventplugin_debug.h IDENTIFIER CREATEEVENTPLUGIN_LOG CATEGORY_NAME org.kde.pim.createeventplugin) ecm_qt_declare_logging_category(common_SRCS HEADER createnoteplugin_debug.h IDENTIFIER CREATENOTEPLUGIN_LOG CATEGORY_NAME org.kde.pim.createnoteplugin) ecm_qt_declare_logging_category(common_SRCS HEADER createtodoplugin_debug.h IDENTIFIER CREATETODOPLUGIN_LOG CATEGORY_NAME org.kde.pim.createtodoplugin) macro(add_messageviewer_viewerplugin_unittest _source _additional _jsonfile) set( _test ${_source} ${_additional} ${common_SRCS}) get_filename_component(_name ${_source} NAME_WE) if (${_jsonfile}) kcoreaddons_desktop_to_json(${_name} ${_jsonfile}) endif() ecm_add_test(${_test} TEST_NAME ${_name} NAME_PREFIX "messageviewerplugins-" - LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditor KF5::AkonadiWidgets KF5::XmlGui + LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditor KF5::AkonadiWidgets KF5::XmlGui KF5::CalendarSupport ) endmacro () macro(add_messageviewer_viewerplugin_class_unittest _source ) set( _test ${_source} ${common_SRCS}) get_filename_component(_name ${_source} NAME_WE) ecm_add_test(${_test} TEST_NAME ${_name} NAME_PREFIX "messageviewerplugins-" - LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::AkonadiWidgets + LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::AkonadiWidgets KF5::CalendarSupport ) endmacro () macro(add_messageviewer_viewerplugin_widget_unittest _source _additional ) set( _test ${_source} ${_additional} ${common_SRCS}) get_filename_component(_name ${_source} NAME_WE) ecm_add_test(${_test} TEST_NAME ${_name} NAME_PREFIX "messageviewerplugins-" - LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditor KF5::AkonadiWidgets) + LINK_LIBRARIES KF5::MessageViewer KF5::Libkleo Qt5::Test KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditor KF5::AkonadiWidgets KF5::CalendarSupport) endmacro () add_messageviewer_viewerplugin_class_unittest(viewerpluginmanagertest.cpp) add_messageviewer_viewerplugin_widget_unittest(todoedittest.cpp "../createtodoplugin/todoedit.cpp") add_messageviewer_viewerplugin_widget_unittest(noteedittest.cpp "../createnoteplugin/noteedit.cpp") set_tests_properties(messageviewerplugins-todoedittest PROPERTIES ENVIRONMENT "LC_ALL=C") add_messageviewer_viewerplugin_widget_unittest(eventedittest.cpp "../createeventplugin/eventedit.cpp;../createeventplugin/eventdatetimewidget.cpp") add_messageviewer_viewerplugin_widget_unittest(eventdatetimewidgettest.cpp "../createeventplugin/eventdatetimewidget.cpp") add_messageviewer_viewerplugin_unittest(viewerplugincreateeventtest.cpp "../createeventplugin/createeventjob.cpp;../createeventplugin/eventdatetimewidget.cpp;../createeventplugin/eventedit.cpp;../createeventplugin/viewerplugincreateevent.cpp;../createeventplugin/viewerplugincreateeventinterface.cpp" "") add_messageviewer_viewerplugin_unittest(viewerplugincreatetodotest.cpp "../createtodoplugin/viewerplugincreatetodo.cpp;../createtodoplugin/viewerplugincreatetodointerface.cpp;../createtodoplugin/todoedit.cpp;../createtodoplugin/createtodojob.cpp" "") add_messageviewer_viewerplugin_unittest(viewerplugincreatenotetest.cpp "../createnoteplugin/noteedit.cpp;../createnoteplugin/viewerplugincreatenote.cpp;../createnoteplugin/viewerplugincreatenoteinterface.cpp;../createnoteplugin/createnotejob.cpp" "") add_messageviewer_viewerplugin_unittest(viewerplugintranslatortest.cpp "../common/translatorplugin/viewerplugintranslator.cpp;../common/translatorplugin/viewerplugintranslatorinterface.cpp" "") diff --git a/plugins/messageviewerplugins/createeventplugin/eventedit.cpp b/plugins/messageviewerplugins/createeventplugin/eventedit.cpp index 15021e19..4ceae71b 100644 --- a/plugins/messageviewerplugins/createeventplugin/eventedit.cpp +++ b/plugins/messageviewerplugins/createeventplugin/eventedit.cpp @@ -1,392 +1,374 @@ /* Copyright (C) 2014-2019 Montel Laurent 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")); connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &EventEdit::slotCollectionChanged); 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()) { - int duration; // in secs - switch (CalendarSupport::KCalPrefs::instance()->mReminderTimeUnits) { - default: - case 0: // mins - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60; - break; - case 1: // hours - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60 * 60; - break; - case 2: // days - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60 * 60 * 24; - break; - } KCalendarCore::Alarm::Ptr alm = event->newAlarm(); - alm->setType(KCalendarCore::Alarm::Display); - alm->setEnabled(true); - if (event->type() == KCalendarCore::Incidence::TypeEvent) { - alm->setStartOffset(KCalendarCore::Duration(-duration)); - } else { - alm->setEndOffset(KCalendarCore::Duration(-duration)); - } + 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/createtodoplugin/todoedit.cpp b/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp index d8c230e2..5f0a2c8b 100644 --- a/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp +++ b/plugins/messageviewerplugins/createtodoplugin/todoedit.cpp @@ -1,348 +1,330 @@ /* Copyright (C) 2014-2019 Montel Laurent 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")); connect(mCollectionCombobox, qOverload(&Akonadi::CollectionComboBox::currentIndexChanged), this, &TodoEdit::slotCollectionChanged); 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()) { - int duration; // in secs - switch (CalendarSupport::KCalPrefs::instance()->mReminderTimeUnits) { - default: - case 0: // mins - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60; - break; - case 1: // hours - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60 * 60; - break; - case 2: // days - duration = CalendarSupport::KCalPrefs::instance()->mReminderTime * 60 * 60 * 24; - break; - } KCalendarCore::Alarm::Ptr alm = todo->newAlarm(); - alm->setType(KCalendarCore::Alarm::Display); - alm->setEnabled(true); - if (todo->type() == KCalendarCore::Incidence::TypeEvent) { - alm->setStartOffset(KCalendarCore::Duration(-duration)); - } else { - alm->setEndOffset(KCalendarCore::Duration(-duration)); - } + 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(); } }