2 This file is part of KOrganizer.
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
26 #include "koeventview.h"
28 #include "koeventpopupmenu.h"
30 #include <Akonadi/Calendar/ETMCalendar>
31 #include <CalendarSupport/KCalPrefs>
32 #include <CalendarSupport/Utils>
34 #include <Libkdepim/PIMMessageBox>
36 #include <KXMLGUIFactory>
37 #include "korganizer_debug.h"
39 #include <QApplication>
42 //---------------------------------------------------------------------------
44 KOEventView::KOEventView(QWidget
*parent
)
45 : KOrg::BaseView(parent
)
47 mReturnPressed
= false;
49 mTypeAheadReceiver
= Q_NULLPTR
;
51 //AKONADI_PORT review: the FocusLineEdit in the editor emits focusReceivedSignal(),
52 //which triggered finishTypeAhead. But the global focus widget in QApplication is
53 //changed later, thus subsequent keyevents still went to this view, triggering
54 //another editor, for each keypress
55 //Thus listen to the global focusChanged() signal (seen with Qt 4.6-stable-patched 20091112)
57 connect(qobject_cast
<QApplication
*>(QApplication::instance()), &QApplication::focusChanged
,
58 this, &KOEventView::focusChanged
);
61 //---------------------------------------------------------------------------
63 KOEventView::~KOEventView()
67 //---------------------------------------------------------------------------
69 KOEventPopupMenu
*KOEventView::eventPopup()
71 KOEventPopupMenu
*eventPopup
= new KOEventPopupMenu(calendar().data(), this);
73 connect(eventPopup
, &KOEventPopupMenu::editIncidenceSignal
, this, &KOEventView::editIncidenceSignal
);
74 connect(eventPopup
, &KOEventPopupMenu::showIncidenceSignal
, this, &KOEventView::showIncidenceSignal
);
75 connect(eventPopup
, &KOEventPopupMenu::deleteIncidenceSignal
, this, &KOEventView::deleteIncidenceSignal
);
76 connect(eventPopup
, &KOEventPopupMenu::cutIncidenceSignal
, this, &KOEventView::cutIncidenceSignal
);
77 connect(eventPopup
, &KOEventPopupMenu::copyIncidenceSignal
, this, &KOEventView::copyIncidenceSignal
);
78 connect(eventPopup
, &KOEventPopupMenu::pasteIncidenceSignal
, this, &KOEventView::pasteIncidenceSignal
);
79 connect(eventPopup
, &KOEventPopupMenu::toggleAlarmSignal
, this, &KOEventView::toggleAlarmSignal
);
80 connect(eventPopup
, &KOEventPopupMenu::toggleTodoCompletedSignal
, this, &KOEventView::toggleTodoCompletedSignal
);
81 connect(eventPopup
, &KOEventPopupMenu::copyIncidenceToResourceSignal
, this, &KOEventView::copyIncidenceToResourceSignal
);
82 connect(eventPopup
, &KOEventPopupMenu::moveIncidenceToResourceSignal
, this, &KOEventView::moveIncidenceToResourceSignal
);
83 connect(eventPopup
, &KOEventPopupMenu::dissociateOccurrencesSignal
, this, &KOEventView::dissociateOccurrencesSignal
);
88 QMenu
*KOEventView::newEventPopup()
90 KXMLGUIClient
*client
= KOCore::self()->xmlguiClient(this);
92 qCCritical(KORGANIZER_LOG
) << "no xmlGuiClient.";
95 if (!client
->factory()) {
96 qCCritical(KORGANIZER_LOG
) << "no factory";
97 return Q_NULLPTR
; // can happen if called too early
100 return static_cast<QMenu
*>
101 (client
->factory()->container(QStringLiteral("rmb_selection_popup"), client
));
103 //---------------------------------------------------------------------------
105 void KOEventView::popupShow()
107 Q_EMIT
showIncidenceSignal(mCurrentIncidence
);
110 //---------------------------------------------------------------------------
112 void KOEventView::popupEdit()
114 Q_EMIT
editIncidenceSignal(mCurrentIncidence
);
117 //---------------------------------------------------------------------------
119 void KOEventView::popupDelete()
121 Q_EMIT
deleteIncidenceSignal(mCurrentIncidence
);
124 //---------------------------------------------------------------------------
126 void KOEventView::popupCut()
128 Q_EMIT
cutIncidenceSignal(mCurrentIncidence
);
131 //---------------------------------------------------------------------------
133 void KOEventView::popupCopy()
135 Q_EMIT
copyIncidenceSignal(mCurrentIncidence
);
138 //---------------------------------------------------------------------------
140 void KOEventView::showNewEventPopup()
142 QMenu
*popup
= newEventPopup();
144 qCCritical(KORGANIZER_LOG
) << "popup creation failed";
148 popup
->popup(QCursor::pos());
151 //---------------------------------------------------------------------------
153 void KOEventView::defaultAction(const Akonadi::Item
&aitem
)
156 const KCalCore::Incidence::Ptr incidence
= CalendarSupport::incidence(aitem
);
158 qCDebug(KORGANIZER_LOG
) << "Ouch, null incidence";
162 if (!calendar()->hasRight(aitem
, Akonadi::Collection::CanChangeItem
)) {
163 Q_EMIT
showIncidenceSignal(aitem
);
165 Q_EMIT
editIncidenceSignal(aitem
);
169 void KOEventView::setTypeAheadReceiver(QObject
*o
)
171 mTypeAheadReceiver
= o
;
174 void KOEventView::focusChanged(QWidget
*, QWidget
*now
)
176 if (mTypeAhead
&& now
&& now
== mTypeAheadReceiver
) {
181 void KOEventView::finishTypeAhead()
183 if (mTypeAheadReceiver
) {
184 foreach (QEvent
*e
, mTypeAheadEvents
) {
185 QApplication::sendEvent(mTypeAheadReceiver
, e
);
188 qDeleteAll(mTypeAheadEvents
);
189 mTypeAheadEvents
.clear();
193 bool KOEventView::usesCompletedTodoPixmap(const Akonadi::Item
&aitem
, const QDate
&date
)
195 const KCalCore::Todo::Ptr todo
= CalendarSupport::todo(aitem
);
200 if (todo
->isCompleted()) {
202 } else if (todo
->recurs()) {
204 if (todo
->allDay()) {
207 time
= todo
->dtDue().toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).time();
210 KDateTime
itemDateTime(date
, time
, CalendarSupport::KCalPrefs::instance()->timeSpec());
212 return itemDateTime
< todo
->dtDue(false);