13#include "agenda/agenda.h"
14#include "agenda/agendaview.h"
15#include "calendarview_debug.h"
16#include "month/monthview.h"
17#include "multiagenda/multiagendaview.h"
19#include "timeline/timelineview.h"
21#include <Akonadi/Collection>
22#include <Akonadi/CollectionFilterProxyModel>
23#include <Akonadi/ControlGui>
24#include <Akonadi/EntityTreeModel>
25#include <Akonadi/IncidenceChanger>
26#include <Akonadi/ItemFetchScope>
27#include <Akonadi/Monitor>
29#include <CalendarSupport/CollectionSelection>
31#include <KCalendarCore/Event>
33#include <KCheckableProxyModel>
36using namespace CalendarSupport;
41 , mViewNames(viewNames)
42 , mIncidenceChanger(nullptr)
44 , mViewPreferences(nullptr)
47 mUi.tabWidget->clear();
53 setGeometry(0, 0, 800, 600);
57MainWindow::~MainWindow()
59 delete mViewPreferences;
63void MainWindow::addView(
const QString &viewName)
65 EventView *eventView =
nullptr;
70 if (viewName ==
"agenda"_L1) {
71 eventView =
new AgendaView(
start.date(),
end.date(),
true,
false,
this);
72 }
else if (viewName ==
"multiagenda"_L1) {
73 eventView =
new MultiAgendaView(
this);
74 }
else if (viewName ==
"month"_L1) {
75 eventView =
new MonthView(MonthView::Visible,
this);
76 }
else if (viewName ==
"timeline"_L1) {
77 eventView =
new TimelineView(
this);
81 eventView->setPreferences(*mViewPreferences);
85 for (
const auto &calendar : mCalendars) {
86 eventView->addCalendar(calendar);
91 mUi.tabWidget->addTab(eventView, viewName);
92 mEventViews.push_back(eventView);
94 qCCritical(CALENDARVIEW_LOG) <<
"Cannot create view" << viewName;
98void MainWindow::delayedInit()
101 mSettings =
new Settings;
105 mViewPreferences =
new PrefsPtr(
new Prefs(mSettings));
107 mMonitor =
new Akonadi::Monitor(
this);
109 mMonitor->setMimeTypeMonitored(mt);
111 mMonitor->itemFetchScope().fetchFullPayload();
113 mEtm =
new Akonadi::EntityTreeModel(mMonitor,
this);
115 auto collectionProxy =
new Akonadi::CollectionFilterProxyModel(mEtm);
117 collectionProxy->setSourceModel(mEtm);
119 auto selectionModel =
new QItemSelectionModel(collectionProxy, mEtm);
121 auto checkableProxy =
new KCheckableProxyModel(mEtm);
122 checkableProxy->setSourceModel(collectionProxy);
123 checkableProxy->setSelectionModel(selectionModel);
125 mUi.calendarView->setModel(checkableProxy);
127 CalendarSupport::CollectionSelection *collectionSelection =
new CalendarSupport::CollectionSelection(selectionModel,
this);
128 EventViews::EventView::setGlobalCollectionSelection(collectionSelection);
130 connect(collectionSelection, &CalendarSupport::CollectionSelection::collectionSelected,
this, &MainWindow::collectionSelected);
131 connect(collectionSelection, &CalendarSupport::CollectionSelection::collectionDeselected,
this, &MainWindow::collectionDeselected);
133 for (
const auto &collection : collectionSelection->selectedCollections()) {
134 collectionSelected(collection);
137 mIncidenceChanger =
new IncidenceChanger(
this);
139 for (
const QString &viewName : std::as_const(mViewNames)) {
144void MainWindow::addViewTriggered(
QAction *action)
146 QString viewName = action->
text().toLower();
147 viewName.
remove(QLatin1Char(
'&'));
153 qDebug() <<
"Collection selected id=" << col.
id() <<
"name=" << col.
displayName();
155 mCalendars.push_back(calendar);
157 for (
auto view : mEventViews) {
158 view->addCalendar(calendar);
165 qDebug() <<
"Collection deselected id=" << col.
id() <<
"name=" << col.
displayName();
166 auto calendar = std::find_if(mCalendars.begin(), mCalendars.end(), [col](
const auto &cal) {
167 return cal->collection() == col;
169 if (calendar == mCalendars.cend()) {
176 for (
auto view : mEventViews) {
177 view->removeCalendar(*calendar);
181 mCalendars.erase(calendar);
183#include "moc_mainwindow.cpp"
QString displayName() const
static void widgetNeedsAkonadi(QWidget *widget)
virtual void setDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth=QDate())
virtual void updateConfig()
Re-reads the configuration and picks up relevant changes which are applicable to the view.
virtual void setIncidenceChanger(Akonadi::IncidenceChanger *changer)
Assign a new incidence change helper object.
static QStringList mimeTypes()
Q_SCRIPTABLE Q_NOREPLY void start()
Namespace EventViews provides facilities for displaying incidences, including events,...
const QList< QKeySequence > & end()
QDateTime addDays(qint64 ndays) const const
QDateTime currentDateTime()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QSharedPointer< T > create(Args &&... args)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)