File indexing completed on 2025-01-05 04:54:32

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0006 
0007   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0008 */
0009 
0010 // View of Journal entries
0011 
0012 #include "kojournalview.h"
0013 #include "prefs/koprefs.h"
0014 
0015 #include <EventViews/JournalView>
0016 
0017 #include <CalendarSupport/CalPrintDefaultPlugins>
0018 #include <CalendarSupport/CalPrinter>
0019 #include <CalendarSupport/Utils>
0020 
0021 #include <Akonadi/ETMCalendar>
0022 
0023 #include <QVBoxLayout>
0024 
0025 using namespace KOrg;
0026 
0027 KOJournalView::KOJournalView(QWidget *parent)
0028     : KOrg::BaseView(parent)
0029     , mJournalView(new EventViews::JournalView(this))
0030 {
0031     auto layout = new QVBoxLayout(this);
0032 
0033     layout->addWidget(mJournalView);
0034 
0035     connect(mJournalView, &EventViews::JournalView::printJournal, this, &KOJournalView::printJournal);
0036 
0037     connect(mJournalView, &EventViews::EventView::incidenceSelected, this, &BaseView::incidenceSelected);
0038 
0039     connect(mJournalView, &EventViews::EventView::showIncidenceSignal, this, &BaseView::showIncidenceSignal);
0040 
0041     connect(mJournalView, &EventViews::EventView::editIncidenceSignal, this, &BaseView::editIncidenceSignal);
0042 
0043     connect(mJournalView, &EventViews::EventView::deleteIncidenceSignal, this, &BaseView::deleteIncidenceSignal);
0044 
0045     connect(mJournalView, &EventViews::EventView::cutIncidenceSignal, this, &BaseView::cutIncidenceSignal);
0046 
0047     connect(mJournalView, &EventViews::EventView::copyIncidenceSignal, this, &BaseView::copyIncidenceSignal);
0048 
0049     connect(mJournalView, &EventViews::EventView::pasteIncidenceSignal, this, &BaseView::pasteIncidenceSignal);
0050 
0051     connect(mJournalView, &EventViews::EventView::toggleAlarmSignal, this, &BaseView::toggleAlarmSignal);
0052 
0053     connect(mJournalView, &EventViews::EventView::toggleTodoCompletedSignal, this, &BaseView::toggleTodoCompletedSignal);
0054 
0055     connect(mJournalView, &EventViews::EventView::copyIncidenceToResourceSignal, this, &BaseView::copyIncidenceToResourceSignal);
0056 
0057     connect(mJournalView, &EventViews::EventView::moveIncidenceToResourceSignal, this, &BaseView::moveIncidenceToResourceSignal);
0058 
0059     connect(mJournalView, &EventViews::EventView::dissociateOccurrencesSignal, this, &BaseView::dissociateOccurrencesSignal);
0060 
0061     connect(mJournalView, qOverload<>(&EventViews::JournalView::newEventSignal), this, qOverload<>(&KOJournalView::newEventSignal));
0062 
0063     connect(mJournalView, qOverload<const QDate &>(&EventViews::JournalView::newEventSignal), this, qOverload<const QDate &>(&KOJournalView::newEventSignal));
0064 
0065     connect(mJournalView,
0066             qOverload<const QDateTime &>(&EventViews::JournalView::newEventSignal),
0067             this,
0068             qOverload<const QDateTime &>(&KOJournalView::newEventSignal));
0069 
0070     connect(mJournalView,
0071             qOverload<const QDateTime &, const QDateTime &>(&EventViews::JournalView::newEventSignal),
0072             this,
0073             qOverload<const QDateTime &, const QDateTime &>(&KOJournalView::newEventSignal));
0074 
0075     connect(mJournalView, &EventViews::EventView::newTodoSignal, this, &BaseView::newTodoSignal);
0076 
0077     connect(mJournalView, &EventViews::EventView::newSubTodoSignal, this, &BaseView::newSubTodoSignal);
0078 
0079     connect(mJournalView, &EventViews::EventView::newJournalSignal, this, &BaseView::newJournalSignal);
0080 }
0081 
0082 KOJournalView::~KOJournalView() = default;
0083 
0084 int KOJournalView::currentDateCount() const
0085 {
0086     return mJournalView->currentDateCount();
0087 }
0088 
0089 Akonadi::Item::List KOJournalView::selectedIncidences()
0090 {
0091     return mJournalView->selectedIncidences();
0092 }
0093 
0094 void KOJournalView::updateView()
0095 {
0096     mJournalView->updateView();
0097 }
0098 
0099 void KOJournalView::flushView()
0100 {
0101     mJournalView->flushView();
0102 }
0103 
0104 void KOJournalView::showDates(const QDate &start, const QDate &end, const QDate &dummy)
0105 {
0106     mJournalView->showDates(start, end, dummy);
0107 }
0108 
0109 void KOJournalView::showIncidences(const Akonadi::Item::List &incidences, const QDate &date)
0110 {
0111     mJournalView->showIncidences(incidences, date);
0112 }
0113 
0114 void KOJournalView::changeIncidenceDisplay(const Akonadi::Item &incidence, Akonadi::IncidenceChanger::ChangeType changeType)
0115 {
0116     mJournalView->changeIncidenceDisplay(incidence, changeType);
0117 }
0118 
0119 void KOJournalView::setIncidenceChanger(Akonadi::IncidenceChanger *changer)
0120 {
0121     mJournalView->setIncidenceChanger(changer);
0122 }
0123 
0124 void KOJournalView::getHighlightMode(bool &highlightEvents, bool &highlightTodos, bool &highlightJournals)
0125 {
0126     highlightJournals = KOPrefs::instance()->mHighlightJournals;
0127     highlightTodos = false;
0128     highlightEvents = !highlightJournals;
0129 }
0130 
0131 CalendarSupport::CalPrinterBase::PrintType KOJournalView::printType() const
0132 {
0133     return CalendarSupport::CalPrinterBase::Journallist;
0134 }
0135 
0136 void KOJournalView::setModel(QAbstractItemModel *model)
0137 {
0138     BaseView::setModel(model);
0139     mJournalView->setModel(model);
0140 }
0141 
0142 void KOJournalView::printJournal(const KCalendarCore::Journal::Ptr &journal, bool preview)
0143 {
0144     if (journal) {
0145         const auto calendar = calendarForIncidence(journal);
0146         CalendarSupport::CalPrinter printer(this, calendar, true);
0147         KCalendarCore::Incidence::List selectedIncidences;
0148         selectedIncidences.append(journal);
0149 
0150         const QDate dtStart = journal->dtStart().date();
0151 
0152         // make sure to clear and then restore the view stylesheet, else the view
0153         // stylesheet is propagated to the child print dialog. see bug 303902
0154         const QString css = styleSheet();
0155         setStyleSheet(QString());
0156         printer.print(CalendarSupport::CalPrinterBase::Incidence, dtStart, dtStart, selectedIncidences, preview);
0157         setStyleSheet(css);
0158     }
0159 }
0160 
0161 void KOJournalView::calendarAdded(const Akonadi::CollectionCalendar::Ptr &calendar)
0162 {
0163     mJournalView->addCalendar(calendar);
0164 }
0165 
0166 void KOJournalView::calendarRemoved(const Akonadi::CollectionCalendar::Ptr &calendar)
0167 {
0168     mJournalView->removeCalendar(calendar);
0169 }
0170 
0171 #include "moc_kojournalview.cpp"