File indexing completed on 2024-11-24 04:50:39
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com> 0003 // SPDX-FileCopyrightText: 2017 Matthieu Gallien <matthieu_gallien@yahoo.fr> 0004 // SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0005 // SPDX-License-Identifier: LGPL-3.0-or-later 0006 0007 #include "calendarapplication.h" 0008 0009 #include <KAuthorized> 0010 #include <KConfigGroup> 0011 #include <KFormat> 0012 #include <KLocalizedString> 0013 #include <KSharedConfig> 0014 #include <KShortcutsDialog> 0015 #include <KWindowConfig> 0016 #include <KWindowSystem> 0017 #include <QGuiApplication> 0018 #include <QMenu> 0019 #include <QQuickWindow> 0020 #include <QSortFilterProxyModel> 0021 #include <vector> 0022 0023 #include "calendaradaptor.h" 0024 #include "merkuro_calendar_debug.h" 0025 #include "mousetracker.h" 0026 0027 CalendarApplication::CalendarApplication(QObject *parent) 0028 : AbstractApplication(parent) 0029 , mSortCollection(new KActionCollection(parent, i18n("Sort"))) 0030 , m_viewGroup(new QActionGroup(this)) 0031 , m_config(new CalendarConfig(this)) 0032 { 0033 mSortCollection->setComponentDisplayName(i18n("Sort")); 0034 setupActions(); 0035 0036 new CalendarAdaptor(this); 0037 QDBusConnection::sessionBus().registerObject(QStringLiteral("/Calendar"), this); 0038 0039 KConfig cfg(QStringLiteral("defaultcalendarrc")); 0040 KConfigGroup grp(&cfg, QStringLiteral("General")); 0041 grp.writeEntry(QStringLiteral("ApplicationId"), QStringLiteral("org.kde.merkuro")); 0042 0043 connect(MouseTracker::instance(), &MouseTracker::mouseButtonReleased, this, &CalendarApplication::handleMouseViewNavButtons); 0044 } 0045 0046 CalendarApplication::~CalendarApplication() 0047 { 0048 } 0049 0050 void CalendarApplication::setupActions() 0051 { 0052 AbstractApplication::setupActions(); 0053 0054 auto actionName = QLatin1StringView("open_todo_view"); 0055 QAction *openTodoAction = nullptr; 0056 if (KAuthorized::authorizeAction(actionName)) { 0057 openTodoAction = mCollection->addAction(actionName, this, &CalendarApplication::openTodoView); 0058 openTodoAction->setText(i18n("Tasks View")); 0059 openTodoAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-tasks"))); 0060 openTodoAction->setCheckable(true); 0061 openTodoAction->setActionGroup(m_viewGroup); 0062 connect(openTodoAction, &QAction::toggled, this, [this](bool checked) { 0063 if (checked) { 0064 m_config->setLastOpenedView(CalendarConfig::TodoView); 0065 m_config->save(); 0066 } 0067 }); 0068 mCollection->setDefaultShortcut(openTodoAction, QKeySequence(i18n("Ctrl+6"))); 0069 } 0070 0071 actionName = QLatin1StringView("open_week_view"); 0072 if (KAuthorized::authorizeAction(actionName)) { 0073 auto openWeekAction = mCollection->addAction(actionName, this, &CalendarApplication::openWeekView); 0074 openWeekAction->setText(i18n("Week View")); 0075 openWeekAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-week"))); 0076 openWeekAction->setCheckable(true); 0077 openWeekAction->setActionGroup(m_viewGroup); 0078 connect(openWeekAction, &QAction::toggled, this, [this](bool checked) { 0079 if (checked) { 0080 m_config->setLastOpenedView(CalendarConfig::WeekView); 0081 m_config->save(); 0082 } 0083 }); 0084 mCollection->setDefaultShortcut(openWeekAction, QKeySequence(i18n("Ctrl+2"))); 0085 } 0086 0087 actionName = QLatin1StringView("open_threeday_view"); 0088 if (KAuthorized::authorizeAction(actionName)) { 0089 auto openThreeDayAction = mCollection->addAction(actionName, this, &CalendarApplication::openThreeDayView); 0090 openThreeDayAction->setText(i18n("3 Day View")); 0091 openThreeDayAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-workweek"))); 0092 openThreeDayAction->setCheckable(true); 0093 openThreeDayAction->setActionGroup(m_viewGroup); 0094 connect(openThreeDayAction, &QAction::toggled, this, [this](bool checked) { 0095 if (checked) { 0096 m_config->setLastOpenedView(CalendarConfig::ThreeDayView); 0097 m_config->save(); 0098 } 0099 }); 0100 mCollection->setDefaultShortcut(openThreeDayAction, QKeySequence(i18n("Ctrl+3"))); 0101 } 0102 0103 actionName = QLatin1StringView("open_day_view"); 0104 if (KAuthorized::authorizeAction(actionName)) { 0105 auto openDayAction = mCollection->addAction(actionName, this, &CalendarApplication::openDayView); 0106 openDayAction->setText(i18n("Day View")); 0107 openDayAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-day"))); 0108 openDayAction->setCheckable(true); 0109 openDayAction->setActionGroup(m_viewGroup); 0110 connect(openDayAction, &QAction::toggled, this, [this](bool checked) { 0111 if (checked) { 0112 m_config->setLastOpenedView(CalendarConfig::DayView); 0113 m_config->save(); 0114 } 0115 }); 0116 mCollection->setDefaultShortcut(openDayAction, QKeySequence(i18n("Ctrl+4"))); 0117 } 0118 0119 actionName = QLatin1StringView("open_schedule_view"); 0120 if (KAuthorized::authorizeAction(actionName)) { 0121 auto openScheduleAction = mCollection->addAction(actionName, this, &CalendarApplication::openScheduleView); 0122 openScheduleAction->setText(i18n("Schedule View")); 0123 openScheduleAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-list"))); 0124 openScheduleAction->setCheckable(true); 0125 openScheduleAction->setActionGroup(m_viewGroup); 0126 connect(openScheduleAction, &QAction::toggled, this, [this](bool checked) { 0127 if (checked) { 0128 m_config->setLastOpenedView(CalendarConfig::ScheduleView); 0129 m_config->save(); 0130 } 0131 }); 0132 mCollection->setDefaultShortcut(openScheduleAction, QKeySequence(i18n("Ctrl+5"))); 0133 } 0134 0135 actionName = QLatin1StringView("open_month_view"); 0136 if (KAuthorized::authorizeAction(actionName)) { 0137 auto openMonthAction = mCollection->addAction(actionName, this, &CalendarApplication::openMonthView); 0138 openMonthAction->setText(i18n("Month View")); 0139 openMonthAction->setIcon(QIcon::fromTheme(QStringLiteral("view-calendar-month"))); 0140 openMonthAction->setCheckable(true); 0141 openMonthAction->setActionGroup(m_viewGroup); 0142 connect(openMonthAction, &QAction::toggled, this, [this](bool checked) { 0143 if (checked) { 0144 m_config->setLastOpenedView(CalendarConfig::MonthView); 0145 m_config->save(); 0146 } 0147 }); 0148 mCollection->setDefaultShortcut(openMonthAction, QKeySequence(i18n("Ctrl+1"))); 0149 } 0150 0151 actionName = QLatin1StringView("move_view_backwards"); 0152 if (KAuthorized::authorizeAction(actionName)) { 0153 auto moveViewBackwardsAction = mCollection->addAction(actionName, this, &CalendarApplication::moveViewBackwards); 0154 moveViewBackwardsAction->setText(i18n("Backwards")); 0155 moveViewBackwardsAction->setIcon(QIcon::fromTheme(QStringLiteral("go-previous"))); 0156 if (openTodoAction) { 0157 connect(openTodoAction, &QAction::changed, this, [moveViewBackwardsAction, openTodoAction]() { 0158 moveViewBackwardsAction->setEnabled(!openTodoAction->isChecked()); 0159 }); 0160 moveViewBackwardsAction->setEnabled(!openTodoAction->isChecked()); 0161 } 0162 } 0163 0164 actionName = QLatin1StringView("move_view_forwards"); 0165 if (KAuthorized::authorizeAction(actionName)) { 0166 auto moveViewForwardsAction = mCollection->addAction(actionName, this, &CalendarApplication::moveViewForwards); 0167 moveViewForwardsAction->setText(i18n("Forwards")); 0168 moveViewForwardsAction->setIcon(QIcon::fromTheme(QStringLiteral("go-next"))); 0169 if (openTodoAction) { 0170 connect(openTodoAction, &QAction::changed, this, [moveViewForwardsAction, openTodoAction]() { 0171 moveViewForwardsAction->setEnabled(!openTodoAction->isChecked()); 0172 }); 0173 moveViewForwardsAction->setEnabled(!openTodoAction->isChecked()); 0174 } 0175 } 0176 0177 actionName = QLatin1StringView("move_view_to_today"); 0178 if (KAuthorized::authorizeAction(actionName)) { 0179 auto moveViewToTodayAction = mCollection->addAction(actionName, this, &CalendarApplication::moveViewToToday); 0180 moveViewToTodayAction->setText(i18n("To Today")); 0181 moveViewToTodayAction->setIcon(QIcon::fromTheme(QStringLiteral("go-jump-today"))); 0182 if (openTodoAction) { 0183 connect(openTodoAction, &QAction::changed, this, [moveViewToTodayAction, openTodoAction]() { 0184 moveViewToTodayAction->setEnabled(!openTodoAction->isChecked()); 0185 }); 0186 moveViewToTodayAction->setEnabled(!openTodoAction->isChecked()); 0187 } 0188 } 0189 0190 actionName = QLatin1StringView("open_date_changer"); 0191 if (KAuthorized::authorizeAction(actionName)) { 0192 auto openDateChangerAction = mCollection->addAction(actionName, this, &CalendarApplication::openDateChanger); 0193 openDateChangerAction->setText(i18n("To Date…")); 0194 openDateChangerAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); 0195 if (openTodoAction) { 0196 connect(openTodoAction, &QAction::changed, this, [openDateChangerAction, openTodoAction]() { 0197 openDateChangerAction->setEnabled(!openTodoAction->isChecked()); 0198 }); 0199 openDateChangerAction->setEnabled(!openTodoAction->isChecked()); 0200 } 0201 } 0202 0203 actionName = QLatin1StringView("toggle_menubar"); 0204 if (KAuthorized::authorizeAction(actionName)) { 0205 auto action = mCollection->addAction(actionName, this, &CalendarApplication::toggleMenubar); 0206 action->setText(i18n("Show Menubar")); 0207 action->setIcon(QIcon::fromTheme(QStringLiteral("show-menu"))); 0208 action->setCheckable(true); 0209 action->setChecked(m_config->showMenubar()); 0210 mCollection->setDefaultShortcut(action, QKeySequence(i18n("Ctrl+M"))); 0211 } 0212 0213 actionName = QLatin1StringView("create_event"); 0214 if (KAuthorized::authorizeAction(actionName)) { 0215 auto action = mCollection->addAction(actionName, this, &CalendarApplication::createNewEvent); 0216 action->setText(i18n("New Event…")); 0217 action->setIcon(QIcon::fromTheme(QStringLiteral("resource-calendar-insert"))); 0218 } 0219 0220 actionName = QLatin1StringView("create_todo"); 0221 if (KAuthorized::authorizeAction(actionName)) { 0222 auto action = mCollection->addAction(actionName, this, &CalendarApplication::createNewTodo); 0223 action->setText(i18n("New Task…")); 0224 action->setIcon(QIcon::fromTheme(QStringLiteral("view-task-add"))); 0225 } 0226 0227 actionName = QLatin1StringView("switch_application_language"); 0228 if (KAuthorized::authorizeAction(actionName)) { 0229 auto action = KStandardAction::switchApplicationLanguage(this, &CalendarApplication::openLanguageSwitcher, this); 0230 mCollection->addAction(action->objectName(), action); 0231 } 0232 0233 actionName = QLatin1StringView("import_calendar"); 0234 if (KAuthorized::authorizeAction(actionName)) { 0235 auto importIcalAction = mCollection->addAction(actionName, this, &CalendarApplication::importCalendar); 0236 importIcalAction->setText(i18n("Import Calendar…")); 0237 importIcalAction->setIcon(QIcon::fromTheme(QStringLiteral("document-import-ocal"))); 0238 } 0239 0240 actionName = QLatin1StringView("edit_undo"); 0241 if (KAuthorized::authorizeAction(actionName)) { 0242 auto action = KStandardAction::undo(this, &CalendarApplication::undo, this); 0243 action->setEnabled(false); 0244 mCollection->addAction(action->objectName(), action); 0245 } 0246 actionName = QLatin1StringView("edit_redo"); 0247 if (KAuthorized::authorizeAction(actionName)) { 0248 auto action = KStandardAction::redo(this, &CalendarApplication::redo, this); 0249 action->setEnabled(false); 0250 mCollection->addAction(action->objectName(), action); 0251 } 0252 0253 actionName = QLatin1StringView("todoview_sort_alphabetically"); 0254 if (KAuthorized::authorizeAction(actionName)) { 0255 auto sortTodoViewAlphabeticallyAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewSortAlphabetically); 0256 sortTodoViewAlphabeticallyAction->setText(i18n("Alphabetically")); 0257 sortTodoViewAlphabeticallyAction->setIcon(QIcon::fromTheme(QStringLiteral("font"))); 0258 sortTodoViewAlphabeticallyAction->setCheckable(true); 0259 sortTodoViewAlphabeticallyAction->setActionGroup(m_todoViewSortGroup); 0260 mSortCollection->addAction(sortTodoViewAlphabeticallyAction->objectName(), sortTodoViewAlphabeticallyAction); 0261 if (openTodoAction) { 0262 connect(openTodoAction, &QAction::changed, this, [sortTodoViewAlphabeticallyAction, openTodoAction]() { 0263 sortTodoViewAlphabeticallyAction->setEnabled(openTodoAction->isChecked()); 0264 }); 0265 sortTodoViewAlphabeticallyAction->setEnabled(openTodoAction->isChecked()); 0266 } 0267 } 0268 0269 actionName = QLatin1StringView("todoview_sort_by_due_date"); 0270 if (KAuthorized::authorizeAction(actionName)) { 0271 auto sortTodoViewByDueDateAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewSortByDueDate); 0272 sortTodoViewByDueDateAction->setText(i18n("By Due Date")); 0273 sortTodoViewByDueDateAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); 0274 sortTodoViewByDueDateAction->setCheckable(true); 0275 sortTodoViewByDueDateAction->setActionGroup(m_todoViewSortGroup); 0276 mSortCollection->addAction(sortTodoViewByDueDateAction->objectName(), sortTodoViewByDueDateAction); 0277 if (openTodoAction) { 0278 connect(openTodoAction, &QAction::changed, this, [sortTodoViewByDueDateAction, openTodoAction]() { 0279 sortTodoViewByDueDateAction->setEnabled(openTodoAction->isChecked()); 0280 }); 0281 sortTodoViewByDueDateAction->setEnabled(openTodoAction->isChecked()); 0282 } 0283 } 0284 0285 actionName = QLatin1StringView("todoview_sort_by_priority"); 0286 if (KAuthorized::authorizeAction(actionName)) { 0287 auto sortTodoViewByPriorityAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewSortByPriority); 0288 sortTodoViewByPriorityAction->setText(i18n("By Priority Level")); 0289 sortTodoViewByPriorityAction->setIcon(QIcon::fromTheme(QStringLiteral("emblem-important-symbolic"))); 0290 sortTodoViewByPriorityAction->setCheckable(true); 0291 sortTodoViewByPriorityAction->setActionGroup(m_todoViewSortGroup); 0292 mSortCollection->addAction(sortTodoViewByPriorityAction->objectName(), sortTodoViewByPriorityAction); 0293 if (openTodoAction) { 0294 connect(openTodoAction, &QAction::changed, this, [sortTodoViewByPriorityAction, openTodoAction]() { 0295 sortTodoViewByPriorityAction->setEnabled(openTodoAction->isChecked()); 0296 }); 0297 sortTodoViewByPriorityAction->setEnabled(openTodoAction->isChecked()); 0298 } 0299 } 0300 0301 actionName = QLatin1StringView("todoview_order_ascending"); 0302 if (KAuthorized::authorizeAction(actionName)) { 0303 auto orderTodoViewAscendingAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewOrderAscending); 0304 orderTodoViewAscendingAction->setText(i18n("Ascending order")); 0305 orderTodoViewAscendingAction->setIcon(QIcon::fromTheme(QStringLiteral("view-sort-ascending"))); 0306 orderTodoViewAscendingAction->setCheckable(true); 0307 orderTodoViewAscendingAction->setActionGroup(m_todoViewOrderGroup); 0308 mSortCollection->addAction(orderTodoViewAscendingAction->objectName(), orderTodoViewAscendingAction); 0309 if (openTodoAction) { 0310 connect(openTodoAction, &QAction::changed, this, [orderTodoViewAscendingAction, openTodoAction]() { 0311 orderTodoViewAscendingAction->setEnabled(openTodoAction->isChecked()); 0312 }); 0313 orderTodoViewAscendingAction->setEnabled(openTodoAction->isChecked()); 0314 } 0315 } 0316 0317 actionName = QLatin1StringView("todoview_order_descending"); 0318 if (KAuthorized::authorizeAction(actionName)) { 0319 auto orderTodoViewDescendingAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewOrderDescending); 0320 orderTodoViewDescendingAction->setText(i18n("Descending Order")); 0321 orderTodoViewDescendingAction->setIcon(QIcon::fromTheme(QStringLiteral("view-sort-descending"))); 0322 orderTodoViewDescendingAction->setCheckable(true); 0323 orderTodoViewDescendingAction->setActionGroup(m_todoViewOrderGroup); 0324 mSortCollection->addAction(orderTodoViewDescendingAction->objectName(), orderTodoViewDescendingAction); 0325 if (openTodoAction) { 0326 connect(openTodoAction, &QAction::changed, this, [orderTodoViewDescendingAction, openTodoAction]() { 0327 orderTodoViewDescendingAction->setEnabled(openTodoAction->isChecked()); 0328 }); 0329 orderTodoViewDescendingAction->setEnabled(openTodoAction->isChecked()); 0330 } 0331 } 0332 0333 actionName = QLatin1StringView("todoview_show_completed"); 0334 if (KAuthorized::authorizeAction(actionName)) { 0335 auto todoViewShowCompletedAction = mSortCollection->addAction(actionName, this, &CalendarApplication::todoViewShowCompleted); 0336 todoViewShowCompletedAction->setText(i18n("Show Completed Tasks")); 0337 todoViewShowCompletedAction->setIcon(QIcon::fromTheme(QStringLiteral("task-complete"))); 0338 mSortCollection->addAction(todoViewShowCompletedAction->objectName(), todoViewShowCompletedAction); 0339 if (openTodoAction) { 0340 connect(openTodoAction, &QAction::changed, this, [todoViewShowCompletedAction, openTodoAction]() { 0341 todoViewShowCompletedAction->setEnabled(openTodoAction->isChecked()); 0342 }); 0343 todoViewShowCompletedAction->setEnabled(openTodoAction->isChecked()); 0344 } 0345 } 0346 0347 actionName = QLatin1StringView("refresh_all"); 0348 if (KAuthorized::authorizeAction(actionName)) { 0349 auto refreshAllAction = mCollection->addAction(actionName, this, &CalendarApplication::refreshAll); 0350 refreshAllAction->setText(i18n("Refresh All")); 0351 refreshAllAction->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); 0352 0353 mCollection->addAction(refreshAllAction->objectName(), refreshAllAction); 0354 mCollection->setDefaultShortcut(refreshAllAction, QKeySequence(QKeySequence::Refresh)); 0355 } 0356 0357 mSortCollection->readSettings(); 0358 mCollection->readSettings(); 0359 } 0360 0361 void CalendarApplication::setWindow(QWindow *window) 0362 { 0363 if (m_window == window) { 0364 return; 0365 } 0366 m_window = window; 0367 Q_EMIT windowChanged(); 0368 } 0369 0370 QWindow *CalendarApplication::window() const 0371 { 0372 return m_window; 0373 } 0374 0375 void CalendarApplication::saveWindowGeometry(QQuickWindow *window) 0376 { 0377 KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation); 0378 KConfigGroup windowGroup(&dataResource, QStringLiteral("Window")); 0379 KWindowConfig::saveWindowPosition(window, windowGroup); 0380 KWindowConfig::saveWindowSize(window, windowGroup); 0381 dataResource.sync(); 0382 } 0383 0384 void CalendarApplication::showIncidenceByUid(const QString &uid, const QDateTime &occurrence, const QString &xdgActivationToken) 0385 { 0386 const auto incidence = m_calendar->incidence(uid); 0387 if (!incidence) { 0388 return; 0389 } 0390 0391 const auto collection = m_calendar->item(incidence).parentCollection(); 0392 const auto incidenceEnd = incidence->endDateForStart(occurrence); 0393 KFormat format; 0394 KCalendarCore::Duration duration(occurrence, incidenceEnd); 0395 0396 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0397 KConfigGroup rColorsConfig(config, QStringLiteral("Resources Colors")); 0398 const QStringList colorKeyList = rColorsConfig.keyList(); 0399 0400 QColor incidenceColor; 0401 0402 for (const QString &key : colorKeyList) { 0403 if (key == QString::number(collection.id())) { 0404 incidenceColor = rColorsConfig.readEntry(key, QColor("blue")); 0405 } 0406 } 0407 0408 auto incidenceData = QVariantMap{ 0409 {QStringLiteral("text"), incidence->summary()}, 0410 {QStringLiteral("description"), incidence->description()}, 0411 {QStringLiteral("location"), incidence->location()}, 0412 {QStringLiteral("startTime"), occurrence}, 0413 {QStringLiteral("endTime"), incidenceEnd}, 0414 {QStringLiteral("allDay"), incidence->allDay()}, 0415 {QStringLiteral("todoCompleted"), false}, 0416 {QStringLiteral("priority"), incidence->priority()}, 0417 {QStringLiteral("durationString"), duration.asSeconds() > 0 ? format.formatSpelloutDuration(duration.asSeconds() * 1000) : QString()}, 0418 {QStringLiteral("recurs"), incidence->recurs()}, 0419 {QStringLiteral("hasReminders"), incidence->alarms().length() > 0}, 0420 {QStringLiteral("isOverdue"), false}, 0421 {QStringLiteral("isReadOnly"), collection.rights().testFlag(Akonadi::Collection::ReadOnly)}, 0422 {QStringLiteral("color"), QVariant::fromValue(incidenceColor)}, 0423 {QStringLiteral("collectionId"), collection.id()}, 0424 {QStringLiteral("incidenceId"), uid}, 0425 {QStringLiteral("incidenceType"), incidence->type()}, 0426 {QStringLiteral("incidenceTypeStr"), incidence->typeStr()}, 0427 {QStringLiteral("incidenceTypeIcon"), incidence->iconName()}, 0428 {QStringLiteral("incidencePtr"), QVariant::fromValue(incidence)}, 0429 }; 0430 0431 if (incidence->type() == KCalendarCore::Incidence::TypeTodo) { 0432 const auto todo = incidence.staticCast<KCalendarCore::Todo>(); 0433 incidenceData[QStringLiteral("todoCompleted")] = todo->isCompleted(); 0434 incidenceData[QStringLiteral("isOverdue")] = todo->isOverdue(); 0435 } 0436 0437 Q_EMIT openIncidence(incidenceData, occurrence); 0438 0439 KWindowSystem::setCurrentXdgActivationToken(xdgActivationToken); 0440 QWindow *window = QGuiApplication::topLevelWindows().isEmpty() ? nullptr : QGuiApplication::topLevelWindows().at(0); 0441 if (window) { 0442 KWindowSystem::activateWindow(window); 0443 window->raise(); 0444 } 0445 } 0446 0447 void CalendarApplication::handleMouseViewNavButtons(const Qt::MouseButton pressedButton) 0448 { 0449 switch (pressedButton) { 0450 case Qt::MouseButton::BackButton: 0451 mCollection->action(QStringLiteral("move_view_backwards"))->trigger(); 0452 break; 0453 case Qt::MouseButton::ForwardButton: 0454 mCollection->action(QStringLiteral("move_view_forwards"))->trigger(); 0455 break; 0456 default: 0457 break; 0458 } 0459 } 0460 0461 QList<KActionCollection *> CalendarApplication::actionCollections() const 0462 { 0463 return {mCollection, mSortCollection}; 0464 } 0465 0466 void CalendarApplication::toggleMenubar() 0467 { 0468 m_config->setShowMenubar(!m_config->showMenubar()); 0469 m_config->save(); 0470 } 0471 0472 bool CalendarApplication::showMenubar() const 0473 { 0474 return m_config->showMenubar(); 0475 } 0476 0477 #ifndef UNITY_CMAKE_SUPPORT 0478 Q_DECLARE_METATYPE(KCalendarCore::Incidence::Ptr) 0479 #endif 0480 0481 #include "moc_calendarapplication.cpp"