diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f467a2..f733e21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,101 +1,102 @@ cmake_minimum_required(VERSION 3.0) -set(PIM_VERSION "5.8.41") +set(PIM_VERSION "5.8.42") project(eventviews VERSION ${PIM_VERSION}) # ECM setup set(KF5_VERSION "5.46.0") find_package(ECM ${KF5_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(LIBRARY_NAMELINK) if(POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(CMakePackageConfigHelpers) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) include(ECMAddTests) include(ECMCoverageOption) set(EVENTVIEW_LIB_VERSION ${PIM_VERSION}) set(CALENDARUTILS_LIB_VERSION "5.8.40") set(AKONADI_LIB_VERSION "5.8.40") set(QT_REQUIRED_VERSION "5.9.0") set(KCALENDARCORE_LIB_VERSION "5.8.40") set(AKONADICALENDAR_LIB_VERSION "5.8.40") set(KMIME_LIB_VERSION "5.8.40") set(LIBKDEPIM_LIB_VERSION "5.8.40") set(CALENDARSUPPORT_LIB_VERSION "5.8.40") find_package(KF5Akonadi ${AKONADI_LIB_VERSION} CONFIG REQUIRED) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets UiTools) find_package(KF5I18n ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5GuiAddons ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Service ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED) +find_package(KF5Holidays ${KF5_VERSION} CONFIG REQUIRED) set(KDIAGRAM_LIB_VERSION "1.4.0") find_package(KGantt ${KDIAGRAM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarUtils ${CALENDARUTILS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarCore ${KCALENDARCORE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiCalendar ${AKONADICALENDAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED) ecm_setup_version(PROJECT VARIABLE_PREFIX EVENTVIEWS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/eventviews_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfigVersion.cmake" SOVERSION 5 ) ########### Targets ########### add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII") add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) #add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5EventViews") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5EventViewsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5EventViewsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5EventViewsTargets.cmake NAMESPACE KF5::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eventviews_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) add_subdirectory(src) if(BUILD_TESTING) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test) add_subdirectory(tests) endif() install(FILES eventviews.renamecategories eventviews.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d83d76..9faaac1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,235 +1,233 @@ # The following macros can be defined to alter behavior. # (if desired, use add_definitions() to define them) # # EVENTVIEWS_NODECOS - turns-off decoration plugins in views. # No idea why you would want to define this, perhaps to save # screen real estate? But there are a config options for that. -add_definitions( -DQT_NO_CAST_FROM_ASCII ) -add_definitions( -DQT_NO_CAST_TO_ASCII ) +add_definitions(-DQT_NO_CAST_FROM_ASCII) +add_definitions(-DQT_NO_CAST_TO_ASCII) add_definitions(-DTRANSLATION_DOMAIN=\"libeventviews\") if(KDEPIM_BUILD_EXAMPLES) add_subdirectory(viewerapp) endif() option(EVENTVIEWS_NODECOS "Turn-off decoration plugins in views." FALSE) if(EVENTVIEWS_NODECOS) add_definitions(-DEVENTVIEWS_NODECOS) endif() - ########### next target ############### set(eventviews_LIB_SRCS eventview_p.cpp eventview.cpp helper.cpp prefs.cpp # Agenda view specific code. agenda/agenda.cpp agenda/agendaitem.cpp agenda/agendaview.cpp agenda/alternatelabel.cpp agenda/calendardecoration.cpp agenda/decorationlabel.cpp agenda/timelabels.cpp agenda/timelabelszone.cpp agenda/timescaleconfigdialog.cpp agenda/viewcalendar.cpp journal/journalframe.cpp journal/journalview.cpp list/listview.cpp month/monthgraphicsitems.cpp month/monthitem.cpp month/monthscene.cpp month/monthview.cpp multiagenda/multiagendaview.cpp todo/tododelegates.cpp todo/todomodel.cpp todo/incidencetreemodel.cpp todo/todoviewquickaddline.cpp todo/todoviewquicksearch.cpp todo/todoviewsortfilterproxymodel.cpp todo/todoviewview.cpp todo/todoview.cpp timeline/timelineview.cpp timeline/timelineitem.cpp timeline/timelineview_p.cpp whatsnext/whatsnextview.cpp ) kconfig_add_kcfg_files(eventviews_LIB_SRCS prefs_base.kcfgc) ecm_qt_declare_logging_category(eventviews_LIB_SRCS HEADER calendarview_debug.h IDENTIFIER CALENDARVIEW_LOG CATEGORY_NAME org.kde.pim.calendarview) ki18n_wrap_ui(eventviews_LIB_SRCS agenda/timescaleedit_base.ui ) add_library(KF5EventViews ${eventviews_LIB_SRCS}) generate_export_header(KF5EventViews BASE_NAME eventviews) add_library(KF5::EventViews ALIAS KF5EventViews) target_link_libraries(KF5EventViews PUBLIC KF5::AkonadiCore KF5::CalendarSupport KF5::CalendarCore KF5::CalendarUtils KF5::AkonadiCalendar PRIVATE + KF5::Holidays KF5::Completion KF5::Service KF5::IconThemes KF5::GuiAddons KF5::I18n KF5::LibkdepimAkonadi KF5::Codecs KGantt KF5::AkonadiWidgets ) target_include_directories(KF5EventViews INTERFACE "$") target_include_directories(KF5EventViews PUBLIC "$") set_target_properties(KF5EventViews PROPERTIES - VERSION ${EVENTVIEWS_VERSION_STRING} - SOVERSION ${EVENTVIEWS_SOVERSION} - EXPORT_NAME EventViews + VERSION ${EVENTVIEWS_VERSION_STRING} + SOVERSION ${EVENTVIEWS_SOVERSION} + EXPORT_NAME EventViews ) install(TARGETS - KF5EventViews - EXPORT KF5EventViewsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} + KF5EventViews + EXPORT KF5EventViewsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) ecm_generate_headers(eventviews_CamelCase_HEADERS HEADER_NAMES Helper Prefs EventView REQUIRED_HEADERS eventviews_CamelCase_HEADERS PREFIX EventViews ) ecm_generate_headers(eventviews_CamelCaseagenda_HEADERS HEADER_NAMES CalendarDecoration AgendaView ViewCalendar REQUIRED_HEADERS eventviews_agenda_HEADERS PREFIX EventViews RELATIVE agenda ) ecm_generate_headers(eventviews_CamelCasetodo_HEADERS HEADER_NAMES TodoView REQUIRED_HEADERS eventviews_todo_HEADERS PREFIX EventViews RELATIVE todo ) ecm_generate_headers(eventviews_CamelCasemonth_HEADERS HEADER_NAMES MonthView REQUIRED_HEADERS eventviews_month_HEADERS PREFIX EventViews RELATIVE month ) ecm_generate_headers(eventviews_CamelCaselist_HEADERS HEADER_NAMES ListView REQUIRED_HEADERS eventviews_list_HEADERS PREFIX EventViews RELATIVE list ) ecm_generate_headers(eventviews_CamelCasejournal_HEADERS HEADER_NAMES JournalView REQUIRED_HEADERS eventviews_journal_HEADERS PREFIX EventViews RELATIVE journal ) ecm_generate_headers(eventviews_CamelCasemultiagenda_HEADERS HEADER_NAMES MultiAgendaView ConfigDialogInterface REQUIRED_HEADERS eventviews_multiagenda_HEADERS PREFIX EventViews RELATIVE multiagenda ) ecm_generate_headers(eventviews_CamelCasetimeline_HEADERS HEADER_NAMES TimeLineView REQUIRED_HEADERS eventviews_timeline_HEADERS PREFIX EventViews RELATIVE timeline ) ecm_generate_headers(eventviews_CamelCasewhatsnext_HEADERS HEADER_NAMES WhatsNextView REQUIRED_HEADERS eventviews_whatsnext_HEADERS PREFIX EventViews RELATIVE whatsnext ) + ecm_generate_pri_file(BASE_NAME EventViews - LIB_NAME KF5EventViews - DEPS "Mime AkonadiCalendar" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/EventViews + LIB_NAME KF5EventViews + DEPS "Mime AkonadiCalendar" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR + ${KDE_INSTALL_INCLUDEDIR_KF5}/EventViews ) - install(FILES - ${eventviews_CamelCase_HEADERS} - ${eventviews_CamelCaseagenda_HEADERS} - ${eventviews_CamelCasetodo_HEADERS} - ${eventviews_CamelCasewhatsnext_HEADERS} - ${eventviews_CamelCasetimeline_HEADERS} - ${eventviews_CamelCasemultiagenda_HEADERS} - ${eventviews_CamelCasejournal_HEADERS} - ${eventviews_CamelCaselist_HEADERS} - ${eventviews_CamelCasemonth_HEADERS} - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/EventViews - COMPONENT Devel + ${eventviews_CamelCase_HEADERS} + ${eventviews_CamelCaseagenda_HEADERS} + ${eventviews_CamelCasetodo_HEADERS} + ${eventviews_CamelCasewhatsnext_HEADERS} + ${eventviews_CamelCasetimeline_HEADERS} + ${eventviews_CamelCasemultiagenda_HEADERS} + ${eventviews_CamelCasejournal_HEADERS} + ${eventviews_CamelCaselist_HEADERS} + ${eventviews_CamelCasemonth_HEADERS} + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/EventViews + COMPONENT Devel ) install(FILES - ${eventviews_HEADERS} - ${CMAKE_CURRENT_BINARY_DIR}/eventviews_export.h - ${eventviews_CamelCase_HEADERS} - ${eventviews_agenda_HEADERS} - ${eventviews_todo_HEADERS} - ${eventviews_whatsnext_HEADERS} - ${eventviews_timeline_HEADERS} - ${eventviews_multiagenda_HEADERS} - ${eventviews_journal_HEADERS} - ${eventviews_list_HEADERS} - ${eventviews_month_HEADERS} - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/eventviews - COMPONENT Devel -) -install(FILES - ${PRI_FILENAME} - DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) + ${eventviews_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/eventviews_export.h + ${eventviews_CamelCase_HEADERS} + ${eventviews_agenda_HEADERS} + ${eventviews_todo_HEADERS} + ${eventviews_whatsnext_HEADERS} + ${eventviews_timeline_HEADERS} + ${eventviews_multiagenda_HEADERS} + ${eventviews_journal_HEADERS} + ${eventviews_list_HEADERS} + ${eventviews_month_HEADERS} + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/eventviews + COMPONENT Devel +) + +install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) install(FILES agenda/calendardecoration.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) - - diff --git a/src/eventview.cpp b/src/eventview.cpp index ca88626..576f38d 100644 --- a/src/eventview.cpp +++ b/src/eventview.cpp @@ -1,672 +1,684 @@ /* Copyright (c) 2000,2001 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Author: Kevin Krammer, krake@kdab.com Author: Sergio Martins, sergio.martins@kdab.com 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "eventview_p.h" #include "prefs.h" #include #include #include #include #include #include #include #include #include +#include + #include #include #include #include #include #include #include "calendarview_debug.h" #include #include #include using namespace KCalCore; using namespace EventViews; using namespace Akonadi; CalendarSupport::CollectionSelection *EventViewPrivate::sGlobalCollectionSelection = nullptr; /* static */ void EventView::setGlobalCollectionSelection(CalendarSupport::CollectionSelection *s) { EventViewPrivate::sGlobalCollectionSelection = s; } EventView::EventView(QWidget *parent) : QWidget(parent) , d_ptr(new EventViewPrivate()) { QByteArray cname = metaObject()->className(); cname.replace(':', '_'); d_ptr->identifier = cname + '_' + KRandom::randomString(8).toLatin1(); //AKONADI_PORT review: the FocusLineEdit in the editor emits focusReceivedSignal(), //which triggered finishTypeAhead. But the global focus widget in QApplication is //changed later, thus subsequent keyevents still went to this view, triggering another //editor, for each keypress. //Thus, listen to the global focusChanged() signal (seen in Qt 4.6-stable-patched 20091112 -Frank) connect(qobject_cast(QApplication::instance()), &QApplication::focusChanged, this, &EventView::focusChanged); d_ptr->setUpModels(); } EventView::~EventView() { delete d_ptr; } void EventView::defaultAction(const Akonadi::Item &aitem) { qCDebug(CALENDARVIEW_LOG); const Incidence::Ptr incidence = CalendarSupport::incidence(aitem); if (!incidence) { return; } qCDebug(CALENDARVIEW_LOG) << " type:" << int(incidence->type()); if (incidence->isReadOnly()) { Q_EMIT showIncidenceSignal(aitem); } else { Q_EMIT editIncidenceSignal(aitem); } } -void EventView::setHolidayRegion(const KHolidays::HolidayRegionPtr &holidayRegion) +void EventView::setHolidayRegions(const QStringList ®ions) { Q_D(EventView); - d->mHolidayRegion = holidayRegion; + qDeleteAll(d->mHolidayRegions); + d->mHolidayRegions.clear(); + foreach (const QString ®ionStr, regions) { + KHolidays::HolidayRegion *region = new KHolidays::HolidayRegion(regionStr); + if (region->isValid()) { + d->mHolidayRegions.append(region); + } else { + delete region; + } + } } int EventView::showMoveRecurDialog(const Incidence::Ptr &inc, const QDate &date) { QDateTime dateTime(date, {}, Qt::LocalTime); int availableOccurrences = KCalUtils::RecurrenceActions::availableOccurrences(inc, dateTime); const QString caption = i18nc("@title:window", "Changing Recurring Item"); KGuiItem itemFuture(i18n("Also &Future Items")); KGuiItem itemSelected(i18n("Only &This Item")); KGuiItem itemAll(i18n("&All Occurrences")); switch (availableOccurrences) { case KCalUtils::RecurrenceActions::NoOccurrence: return KCalUtils::RecurrenceActions::NoOccurrence; case KCalUtils::RecurrenceActions::SelectedOccurrence: return KCalUtils::RecurrenceActions::SelectedOccurrence; case KCalUtils::RecurrenceActions::AllOccurrences: Q_ASSERT(availableOccurrences & KCalUtils::RecurrenceActions::SelectedOccurrence); // if there are all kinds of ooccurrences (i.e. past present and future) the user might // want the option only apply to current and future occurrences, leaving the past ones // provide a third choice for that ("Also future") if (availableOccurrences == KCalUtils::RecurrenceActions::AllOccurrences) { const QString message = i18n("The item you are trying to change is a recurring item. " "Should the changes be applied only to this single occurrence, " "also to future items, or to all items in the recurrence?"); return KCalUtils::RecurrenceActions::questionSelectedFutureAllCancel( message, caption, itemSelected, itemFuture, itemAll, this); } Q_FALLTHROUGH(); default: Q_ASSERT(availableOccurrences & KCalUtils::RecurrenceActions::SelectedOccurrence); // selected occurrence and either past or future occurrences const QString message = i18n("The item you are trying to change is a recurring item. " "Should the changes be applied only to this single occurrence " "or to all items in the recurrence?"); return KCalUtils::RecurrenceActions::questionSelectedAllCancel( message, caption, itemSelected, itemAll, this); break; } return KCalUtils::RecurrenceActions::NoOccurrence; } void EventView::setCalendar(const Akonadi::ETMCalendar::Ptr &calendar) { Q_D(EventView); if (d->calendar != calendar) { if (d->calendar) { disconnect(d->calendar.data()); } d->calendar = calendar; if (calendar) { if (d->collectionSelectionModel) { d->collectionSelectionModel->setSourceModel(calendar->model()); } connect(calendar.data(), &ETMCalendar::collectionChanged, this, &EventView::onCollectionChanged); } } } Akonadi::ETMCalendar::Ptr EventView::calendar() const { Q_D(const EventView); return d->calendar; } void EventView::setPreferences(const PrefsPtr &preferences) { Q_D(EventView); if (d->mPrefs != preferences) { if (preferences) { d->mPrefs = preferences; } else { d->mPrefs = PrefsPtr(new Prefs()); } updateConfig(); } } void EventView::setKCalPreferences(const KCalPrefsPtr &preferences) { Q_D(EventView); if (d->mKCalPrefs != preferences) { if (preferences) { d->mKCalPrefs = preferences; } else { d->mKCalPrefs = KCalPrefsPtr(new CalendarSupport::KCalPrefs()); } updateConfig(); } } PrefsPtr EventView::preferences() const { Q_D(const EventView); return d->mPrefs; } KCalPrefsPtr EventView::kcalPreferences() const { Q_D(const EventView); return d->mKCalPrefs; } void EventView::dayPassed(const QDate &) { updateView(); } void EventView::setIncidenceChanger(Akonadi::IncidenceChanger *changer) { Q_D(EventView); d->mChanger = changer; } void EventView::flushView() { } EventView *EventView::viewAt(const QPoint &) { return this; } void EventView::updateConfig() { } QDateTime EventView::selectionStart() const { return QDateTime(); } QDateTime EventView::selectionEnd() const { return QDateTime(); } bool EventView::dateRangeSelectionEnabled() const { Q_D(const EventView); return d->mDateRangeSelectionEnabled; } void EventView::setDateRangeSelectionEnabled(bool enable) { Q_D(EventView); d->mDateRangeSelectionEnabled = enable; } bool EventView::supportsZoom() const { return false; } bool EventView::hasConfigurationDialog() const { return false; } void EventView::setDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth) { Q_D(EventView); d->startDateTime = start; d->endDateTime = end; showDates(start.date(), end.date(), preferredMonth); const QPair adjusted = actualDateRange(start, end, preferredMonth); d->actualStartDateTime = adjusted.first; d->actualEndDateTime = adjusted.second; } QDateTime EventView::startDateTime() const { Q_D(const EventView); return d->startDateTime; } QDateTime EventView::endDateTime() const { Q_D(const EventView); return d->endDateTime; } QDateTime EventView::actualStartDateTime() const { Q_D(const EventView); return d->actualStartDateTime; } QDateTime EventView::actualEndDateTime() const { Q_D(const EventView); return d->actualEndDateTime; } void EventView::showConfigurationDialog(QWidget *) { } bool EventView::processKeyEvent(QKeyEvent *ke) { Q_D(EventView); // If Return is pressed bring up an editor for the current selected time span. if (ke->key() == Qt::Key_Return) { if (ke->type() == QEvent::KeyPress) { d->mReturnPressed = true; } else if (ke->type() == QEvent::KeyRelease) { if (d->mReturnPressed) { Q_EMIT newEventSignal(); d->mReturnPressed = false; return true; } else { d->mReturnPressed = false; } } } // Ignore all input that does not produce any output if (ke->text().isEmpty() || (ke->modifiers() & Qt::ControlModifier)) { return false; } if (ke->type() == QEvent::KeyPress) { switch (ke->key()) { case Qt::Key_Escape: case Qt::Key_Return: case Qt::Key_Enter: case Qt::Key_Tab: case Qt::Key_Backtab: case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: case Qt::Key_Down: case Qt::Key_Backspace: case Qt::Key_Delete: case Qt::Key_PageUp: case Qt::Key_PageDown: case Qt::Key_Home: case Qt::Key_End: case Qt::Key_Control: case Qt::Key_Meta: case Qt::Key_Alt: break; default: d->mTypeAheadEvents.append( new QKeyEvent(ke->type(), ke->key(), ke->modifiers(), ke->text(), ke->isAutoRepeat(), static_cast(ke->count()))); if (!d->mTypeAhead) { d->mTypeAhead = true; Q_EMIT newEventSignal(); } return true; } } return false; } void EventView::setTypeAheadReceiver(QObject *o) { Q_D(EventView); d->mTypeAheadReceiver = o; } void EventView::focusChanged(QWidget *, QWidget *now) { Q_D(EventView); if (d->mTypeAhead && now && now == d->mTypeAheadReceiver) { d->finishTypeAhead(); } } CalendarSupport::CollectionSelection *EventView::collectionSelection() const { Q_D(const EventView); return d->customCollectionSelection ? d->customCollectionSelection : globalCollectionSelection(); } void EventView::setCustomCollectionSelectionProxyModel(KCheckableProxyModel *model) { Q_D(EventView); if (d->collectionSelectionModel == model) { return; } delete d->collectionSelectionModel; d->collectionSelectionModel = model; d->setUpModels(); } KCheckableProxyModel *EventView::customCollectionSelectionProxyModel() const { Q_D(const EventView); return d->collectionSelectionModel; } KCheckableProxyModel *EventView::takeCustomCollectionSelectionProxyModel() { Q_D(EventView); KCheckableProxyModel *m = d->collectionSelectionModel; d->collectionSelectionModel = nullptr; d->setUpModels(); return m; } CalendarSupport::CollectionSelection *EventView::customCollectionSelection() const { Q_D(const EventView); return d->customCollectionSelection; } void EventView::clearSelection() { } bool EventView::eventDurationHint(QDateTime &startDt, QDateTime &endDt, bool &allDay) const { Q_UNUSED(startDt); Q_UNUSED(endDt); Q_UNUSED(allDay); return false; } Akonadi::IncidenceChanger *EventView::changer() const { Q_D(const EventView); return d->mChanger; } void EventView::doRestoreConfig(const KConfigGroup &) { } void EventView::doSaveConfig(KConfigGroup &) { } -QPair EventView::actualDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth) const +QPair EventView::actualDateRange(const QDateTime &start, const QDateTime &end, + const QDate &preferredMonth) const { Q_UNUSED(preferredMonth); return qMakePair(start, end); } /* void EventView::incidencesAdded( const Akonadi::Item::List & ) { } void EventView::incidencesAboutToBeRemoved( const Akonadi::Item::List & ) { } void EventView::incidencesChanged( const Akonadi::Item::List & ) { } */ void EventView::handleBackendError(const QString &errorString) { qCCritical(CALENDARVIEW_LOG) << errorString; } void EventView::calendarReset() { } CalendarSupport::CollectionSelection *EventView::globalCollectionSelection() { return EventViewPrivate::sGlobalCollectionSelection; } QByteArray EventView::identifier() const { Q_D(const EventView); return d->identifier; } void EventView::setIdentifier(const QByteArray &identifier) { Q_D(EventView); d->identifier = identifier; } void EventView::setChanges(Changes changes) { Q_D(EventView); if (d->mChanges == NothingChanged) { #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) QMetaObject::invokeMethod(this, &EventView::updateView, Qt::QueuedConnection); #else QMetaObject::invokeMethod(this, "updateView", Qt::QueuedConnection); #endif } d->mChanges = changes; } EventView::Changes EventView::changes() const { Q_D(const EventView); return d->mChanges; } void EventView::restoreConfig(const KConfigGroup &configGroup) { Q_D(EventView); const bool useCustom = configGroup.readEntry("UseCustomCollectionSelection", false); if (!d->collectionSelectionModel && !useCustom) { delete d->collectionSelectionModel; d->collectionSelectionModel = nullptr; d->setUpModels(); } else if (useCustom) { if (!d->collectionSelectionModel) { // Sort the calendar model on calendar name QSortFilterProxyModel *sortProxy = new QSortFilterProxyModel(this); sortProxy->setDynamicSortFilter(true); sortProxy->setSortCaseSensitivity(Qt::CaseInsensitive); if (d->calendar) { sortProxy->setSourceModel(d->calendar->entityTreeModel()); } // Only show the first column. KRearrangeColumnsProxyModel *columnFilterProxy = new KRearrangeColumnsProxyModel(this); columnFilterProxy->setSourceColumns( QVector() << Akonadi::ETMCalendar::CollectionTitle); columnFilterProxy->setSourceModel(sortProxy); // Make the calendar model checkable. d->collectionSelectionModel = new KCheckableProxyModel(this); d->collectionSelectionModel->setSourceModel(columnFilterProxy); d->setUpModels(); } const KConfigGroup selectionGroup = configGroup.config()->group(configGroup.name() + QLatin1String("_selectionSetup")); KViewStateMaintainer maintainer(selectionGroup); maintainer.setSelectionModel(d->collectionSelectionModel->selectionModel()); maintainer.restoreState(); } doRestoreConfig(configGroup); } void EventView::saveConfig(KConfigGroup &configGroup) { Q_D(EventView); configGroup.writeEntry("UseCustomCollectionSelection", d->collectionSelectionModel != nullptr); if (d->collectionSelectionModel) { KConfigGroup selectionGroup = configGroup.config()->group(configGroup.name() + QLatin1String("_selectionSetup")); KViewStateMaintainer maintainer(selectionGroup); maintainer.setSelectionModel(d->collectionSelectionModel->selectionModel()); maintainer.saveState(); } doSaveConfig(configGroup); } void EventView::setCollectionId(Akonadi::Collection::Id id) { Q_D(EventView); if (d->mCollectionId != id) { d->mCollectionId = id; } } Akonadi::Collection::Id EventView::collectionId() const { Q_D(const EventView); return d->mCollectionId; } bool EventView::makesWholeDayBusy(const KCalCore::Incidence::Ptr &incidence) const { // Must be event // Must be all day // Must be marked busy (TRANSP: OPAQUE) // You must be attendee or organizer if (incidence->type() != KCalCore::Incidence::TypeEvent || !incidence->allDay()) { return false; } KCalCore::Event::Ptr ev = incidence.staticCast(); if (ev->transparency() != KCalCore::Event::Opaque) { return false; } // Last check: must be organizer or attendee: if (kcalPreferences()->thatIsMe(ev->organizer()->email())) { return true; } KCalCore::Attendee::List attendees = ev->attendees(); KCalCore::Attendee::List::ConstIterator it; for (it = attendees.constBegin(); it != attendees.constEnd(); ++it) { if (kcalPreferences()->thatIsMe((*it)->email())) { return true; } } return false; } /*static*/ QColor EventView::itemFrameColor(const QColor &color, bool selected) { if (color.isValid()) { return selected ? QColor(85 + color.red() * 2.0 / 3, 85 + color.green() * 2.0 / 3, 85 + color.blue() * 2.0 / 3) : color.darker(115); } else { return Qt::black; } } QString EventView::iconForItem(const Akonadi::Item &item) { QString iconName; Akonadi::Collection collection = item.parentCollection(); while (collection.parentCollection().isValid() && collection.parentCollection() != Akonadi::Collection::root()) { collection = calendar()->collection(collection.parentCollection().id()); } if (collection.isValid() && collection.hasAttribute()) { iconName = collection.attribute()->iconName(); } return iconName; } void EventView::onCollectionChanged(const Akonadi::Collection &collection, const QSet &changedAttributes) { Q_UNUSED(collection); if (changedAttributes.contains("AccessRights")) { setChanges(changes() | EventViews::EventView::ResourcesChanged); updateView(); } } diff --git a/src/eventview.h b/src/eventview.h index 9c5b03f..7ee4ee8 100644 --- a/src/eventview.h +++ b/src/eventview.h @@ -1,525 +1,520 @@ /* Copyright (c) 1999 Preston Brown Copyright (c) 2000,2001 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Author: Kevin Krammer, krake@kdab.com 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef EVENTVIEWS_EVENTVIEW_H #define EVENTVIEWS_EVENTVIEW_H #include "eventviews_export.h" #include #include #include #include #include #include #include #include #include namespace KCalCore { template class SortableList; typedef SortableList DateList; } -namespace KHolidays { -class HolidayRegion; -typedef QSharedPointer HolidayRegionPtr; -} - namespace CalendarSupport { class CollectionSelection; class KCalPrefs; } namespace Akonadi { class IncidenceChanger; } class KCheckableProxyModel; class KConfigGroup; namespace EventViews { enum { BUSY_BACKGROUND_ALPHA = 70 }; class EventViewPrivate; class Prefs; typedef QSharedPointer PrefsPtr; typedef QSharedPointer KCalPrefsPtr; /** EventView is the abstract base class from which all other calendar views for event data are derived. It provides methods for displaying appointments and events on one or more days. The actual number of days that a view actually supports is not defined by this abstract class; that is up to the classes that inherit from it. It also provides methods for updating the display, retrieving the currently selected event (or events), and the like. @short Abstract class from which all event views are derived. @author Preston Brown @see KOListView, AgendaView, KOMonthView */ class EVENTVIEWS_EXPORT EventView : public QWidget { Q_OBJECT public: enum { // This value is passed to QColor's lighter(int factor) for selected events BRIGHTNESS_FACTOR = 125 }; enum ItemIcon { CalendarCustomIcon = 0, TaskIcon, JournalIcon, RecurringIcon, ReminderIcon, ReadOnlyIcon, ReplyIcon, AttendingIcon, TentativeIcon, OrganizerIcon, IconCount = 10 // Always keep at the end }; enum Change { NothingChanged = 0, IncidencesAdded = 1, IncidencesEdited = 2, IncidencesDeleted = 4, DatesChanged = 8, FilterChanged = 16, ResourcesChanged = 32, ZoomChanged = 64, ConfigChanged = 128 }; Q_DECLARE_FLAGS(Changes, Change) /** * Constructs a view. * @param cal is a pointer to the calendar object from which events * will be retrieved for display. * @param parent is the parent QWidget. */ explicit EventView(QWidget *parent = nullptr); /** * Destructor. Views will do view-specific cleanups here. */ ~EventView(); virtual void setCalendar(const Akonadi::ETMCalendar::Ptr &cal); /** Return calendar object of this view. TODO: replace with a version that returns a KCalCore::Calendar so it can be used in different environments. see agendaview for example calendar2(incidence) */ virtual Akonadi::ETMCalendar::Ptr calendar() const; /* update config is called after prefs are set. */ virtual void setPreferences(const PrefsPtr &preferences); PrefsPtr preferences() const; virtual void setKCalPreferences(const KCalPrefsPtr &preferences); KCalPrefsPtr kcalPreferences() const; /** @return a list of selected events. Most views can probably only select a single event at a time, but some may be able to select more than one. */ virtual Akonadi::Item::List selectedIncidences() const = 0; /** Returns a list of the dates of selected events. Most views can probably only select a single event at a time, but some may be able to select more than one. */ virtual KCalCore::DateList selectedIncidenceDates() const = 0; /** Returns the start of the selection, or an invalid QDateTime if there is no selection or the view doesn't support selecting cells. */ virtual QDateTime selectionStart() const; /** Returns the end of the selection, or an invalid QDateTime if there is no selection or the view doesn't support selecting cells. */ virtual QDateTime selectionEnd() const; /** Sets the default start/end date/time for new events. Return true if anything was changed */ virtual bool eventDurationHint(QDateTime &startDt, QDateTime &endDt, bool &allDay) const; /** Returns whether or not date range selection is enabled. This setting only applies to views that actually supports selecting cells. @see selectionStart() @see selectionEnd() */ bool dateRangeSelectionEnabled() const; /** Enable or disable date range selection. @see dateRangeSelectionEnabled() */ void setDateRangeSelectionEnabled(bool enable); /** Returns the number of currently shown dates. A return value of 0 means no idea. */ virtual int currentDateCount() const = 0; /** * returns whether this view supports zoom. * Base implementation returns false. */ virtual bool supportsZoom() const; virtual bool hasConfigurationDialog() const; virtual void showConfigurationDialog(QWidget *parent); QByteArray identifier() const; void setIdentifier(const QByteArray &identifier); /** * reads the view configuration. View-specific configuration can be * restored via doRestoreConfig() * * @param configGroup the group to read settings from * @see doRestoreConfig() */ void restoreConfig(const KConfigGroup &configGroup); /** * writes out the view configuration. View-specific configuration can be * saved via doSaveConfig() * * @param configGroup the group to store settings in * @see doSaveConfig() */ void saveConfig(KConfigGroup &configGroup); /** Makes the eventview display only items of collection @p id. Useful for example in multi-agendaview (side-by-side) where each AgendaView displays only one collection. */ void setCollectionId(Akonadi::Collection::Id id); Akonadi::Collection::Id collectionId() const; //---------------------------------------------------------------------------- KCheckableProxyModel *takeCustomCollectionSelectionProxyModel(); KCheckableProxyModel *customCollectionSelectionProxyModel() const; void setCustomCollectionSelectionProxyModel(KCheckableProxyModel *model); CalendarSupport::CollectionSelection *customCollectionSelection() const; static CalendarSupport::CollectionSelection *globalCollectionSelection(); static void setGlobalCollectionSelection(CalendarSupport::CollectionSelection *selection); //---------------------------------------------------------------------------- /** * returns the view at the given widget coordinate. This is usually the view * itself, except for composite views, where a subview will be returned. * The default implementation returns @p this . */ virtual EventView *viewAt(const QPoint &p); /** * @param preferredMonth Used by month orientated views. Contains the * month to show when the week crosses months. It's a QDate instead * of uint so it can be easily fed to KCalendarSystem's functions. */ virtual void setDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate()); QDateTime startDateTime() const; QDateTime endDateTime() const; QDateTime actualStartDateTime() const; QDateTime actualEndDateTime() const; int showMoveRecurDialog(const KCalCore::Incidence::Ptr &incidence, const QDate &date); /** Handles key events, opens the new event dialog when enter is pressed, activates type ahead. */ bool processKeyEvent(QKeyEvent *); /* * Sets the QObject that will receive key events that were made * while the new event dialog was still being created. */ void setTypeAheadReceiver(QObject *o); /** Returns the selection of collection to be used by this view (custom if set, or global otherwise). */ CalendarSupport::CollectionSelection *collectionSelection() const; /** Notifies the view that there are pending changes so a redraw is needed. @param needed if the update is needed or not. */ virtual void setChanges(Changes changes); /** Returns if there are pending changes and a redraw is needed. */ Changes changes() const; /** * Returns a variation of @p color that will be used for the border * of an agenda or month item. */ static QColor itemFrameColor(const QColor &color, bool selected); QString iconForItem(const Akonadi::Item &); public Q_SLOTS: /** Shows given incidences. Depending on the actual view it might not be possible to show all given events. @param incidenceList a list of incidences to show. @param date is the QDate on which the incidences are being shown. */ virtual void showIncidences(const Akonadi::Item::List &incidenceList, const QDate &date) = 0; /** Updates the current display to reflect changes that may have happened in the calendar since the last display refresh. */ virtual void updateView() = 0; virtual void dayPassed(const QDate &); /** Assign a new incidence change helper object. */ virtual void setIncidenceChanger(Akonadi::IncidenceChanger *changer); /** Write all unsaved data back to calendar store. */ virtual void flushView(); /** Re-reads the configuration and picks up relevant changes which are applicable to the view. */ virtual void updateConfig(); /** Clear selection. The incidenceSelected signal is not emitted. */ virtual void clearSelection(); void focusChanged(QWidget *, QWidget *); /** Perform the default action for an incidence, e.g. open the event editor, when double-clicking an event in the agenda view. */ void defaultAction(const Akonadi::Item &incidence); /** - Set which holidays the user wants to use. - @param holidayRegion a HolidayRegion object initialized with the desired locale. + Set which holiday regions the user wants to use. + @param regions a list of Holiday Regions strings. */ - void setHolidayRegion(const KHolidays::HolidayRegionPtr &holidayRegion); + void setHolidayRegions(const QStringList ®ions); Q_SIGNALS: /** * when the view changes the dates that are selected in one way or * another, this signal is emitted. It should be connected back to * the KDateNavigator object so that it changes appropriately, * and any other objects that need to be aware that the list of * selected dates has changed. * @param datelist the new list of selected dates */ void datesSelected(const KCalCore::DateList &datelist); /** * Emitted when an event is moved using the mouse in an agenda * view (week / month). */ void shiftedEvent(const QDate &olddate, const QDate &newdate); void incidenceSelected(const Akonadi::Item &, const QDate); /** * instructs the receiver to show the incidence in read-only mode. */ void showIncidenceSignal(const Akonadi::Item &); /** * instructs the receiver to begin editing the incidence specified in * some manner. Doesn't make sense to connect to more than one * receiver. */ void editIncidenceSignal(const Akonadi::Item &); /** * instructs the receiver to delete the Incidence in some manner; some * possibilities include automatically, with a confirmation dialog * box, etc. Doesn't make sense to connect to more than one receiver. */ void deleteIncidenceSignal(const Akonadi::Item &); /** * instructs the receiver to cut the Incidence */ void cutIncidenceSignal(const Akonadi::Item &); /** * instructs the receiver to copy the incidence */ void copyIncidenceSignal(const Akonadi::Item &); /** * instructs the receiver to paste the incidence */ void pasteIncidenceSignal(); /** * instructs the receiver to toggle the alarms of the Incidence. */ void toggleAlarmSignal(const Akonadi::Item &); /** * instructs the receiver to toggle the completion state of the Incidence * (which must be a Todo type). */ void toggleTodoCompletedSignal(const Akonadi::Item &); /** * Copy the incidence to the specified resource. */ void copyIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &); /** * Move the incidence to the specified resource. */ void moveIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &); /** Dissociate from a recurring incidence the occurrence on the given * date to a new incidence or dissociate all occurrences from the * given date onwards. */ void dissociateOccurrencesSignal(const Akonadi::Item &, const QDate &); /** * instructs the receiver to create a new event in given collection. Doesn't make * sense to connect to more than one receiver. */ void newEventSignal(); /** * instructs the receiver to create a new event with the specified beginning * time. Doesn't make sense to connect to more than one receiver. */ void newEventSignal(const QDate &); /** * instructs the receiver to create a new event with the specified beginning * time. Doesn't make sense to connect to more than one receiver. */ void newEventSignal(const QDateTime &); /** * instructs the receiver to create a new event, with the specified * beginning end ending times. Doesn't make sense to connect to more * than one receiver. */ void newEventSignal(const QDateTime &, const QDateTime &); void newTodoSignal(const QDate &); void newSubTodoSignal(const Akonadi::Item &); void newJournalSignal(const QDate &); protected Q_SLOTS: virtual void calendarReset(); private: void onCollectionChanged(const Akonadi::Collection &, const QSet &); protected: bool makesWholeDayBusy(const KCalCore::Incidence::Ptr &incidence) const; Akonadi::IncidenceChanger *changer() const; /** * reimplement to read view-specific settings. */ virtual void doRestoreConfig(const KConfigGroup &configGroup); /** * reimplement to write view-specific settings. */ virtual void doSaveConfig(KConfigGroup &configGroup); /** @deprecated */ virtual void showDates(const QDate &start, const QDate &end, const QDate &preferredMonth = QDate()) = 0; /** * from the requested date range (passed via setDateRange()), calculates the * adjusted date range actually displayed by the view, depending on the * view's supported range (e.g., a month view always displays one month) * The default implementation returns the range unmodified * * @param preferredMonth Used by month orientated views. Contains the * month to show when the week crosses months. It's a QDate instead of * uint so it can be easily fed to KCalendarSystem's functions. */ virtual QPair actualDateRange( const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate()) const; /* virtual void incidencesAdded( const Akonadi::Item::List &incidences ); virtual void incidencesAboutToBeRemoved( const Akonadi::Item::List &incidences ); virtual void incidencesChanged( const Akonadi::Item::List &incidences ); */ virtual void handleBackendError(const QString &error); private: EventViewPrivate *const d_ptr; Q_DECLARE_PRIVATE(EventView) }; } #endif diff --git a/src/eventview_p.h b/src/eventview_p.h index 3ff92f3..0aa4fc7 100644 --- a/src/eventview_p.h +++ b/src/eventview_p.h @@ -1,83 +1,87 @@ /* Copyright (c) 2000,2001 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Author: Kevin Krammer, krake@kdab.com Author: Sergio Martins, sergio.martins@kdab.com 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef EVENTVIEWS_EVENTVIEW_P_H #define EVENTVIEWS_EVENTVIEW_P_H #include "eventview.h" -#include +namespace KHolidays { +class HolidayRegion; +} class KCheckableProxyModel; +#include + namespace EventViews { class EventViewPrivate { public: /// Methods EventViewPrivate(); ~EventViewPrivate(); /** This is called when the new event dialog is shown. It sends all events in mTypeAheadEvents to the receiver. */ void finishTypeAhead(); public: // virtual functions void setUpModels(); public: /// Members Akonadi::ETMCalendar::Ptr calendar; CalendarSupport::CollectionSelection *customCollectionSelection; KCheckableProxyModel *collectionSelectionModel; QByteArray identifier; QDateTime startDateTime; QDateTime endDateTime; QDateTime actualStartDateTime; QDateTime actualEndDateTime; /* When we receive a QEvent with a key_Return release * we will only show a new event dialog if we previously received a * key_Return press, otherwise a new event dialog appears when * you hit return in some yes/no dialog */ bool mReturnPressed; bool mDateRangeSelectionEnabled; bool mTypeAhead; QObject *mTypeAheadReceiver = nullptr; QList mTypeAheadEvents; static CalendarSupport::CollectionSelection *sGlobalCollectionSelection; - KHolidays::HolidayRegionPtr mHolidayRegion; + QList mHolidayRegions; PrefsPtr mPrefs; KCalPrefsPtr mKCalPrefs; Akonadi::IncidenceChanger *mChanger = nullptr; EventView::Changes mChanges; Akonadi::Collection::Id mCollectionId; }; } // EventViews #endif