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 "koeventpopupmenu.h"
27 #include "actionmanager.h"
28 #include "calprinter.h"
29 #include "kocorehelper.h"
30 #include "koglobals.h"
32 #include <calendarsupport/calendar.h>
33 #include <calendarsupport/kcalprefs.h>
34 #include <calendarsupport/utils.h>
36 #include <kcalcore/incidence.h>
37 #include <kmimetypetrader.h>
38 #include <KActionCollection>
41 using namespace KCalCore
;
43 KOEventPopupMenu::KOEventPopupMenu( CalendarSupport::Calendar
*calendar
, QWidget
*parent
)
44 : QMenu( parent
), mCalendar( calendar
)
46 mHasAdditionalItems
= false;
48 addAction( KOGlobals::self()->smallIcon( "document-preview" ), i18n( "&Show" ),
49 this, SLOT( popupShow() ) );
50 mEditOnlyItems
.append(
51 addAction( KOGlobals::self()->smallIcon( "document-edit" ), i18n( "&Edit..." ),
52 this, SLOT( popupEdit() ) ) );
53 mEditOnlyItems
.append( addSeparator() );
54 addAction( KOGlobals::self()->smallIcon( "document-print" ), i18n( "&Print..." ),
55 this, SLOT( print() ) );
56 QAction
*preview
= addAction( KOGlobals::self()->smallIcon( "document-print-preview" ), i18n( "Print Previe&w..." ),
57 this, SLOT( printPreview() ) );
58 preview
->setEnabled( !KMimeTypeTrader::self()->query("application/pdf", "KParts/ReadOnlyPart").isEmpty() );
59 //------------------------------------------------------------------------
60 mEditOnlyItems
.append( addSeparator() );
61 mEditOnlyItems
.append( addAction( KOGlobals::self()->smallIcon( "edit-cut" ),
62 i18nc( "cut this event", "C&ut" ),
63 this, SLOT(popupCut()) ) );
64 mEditOnlyItems
.append( addAction( KOGlobals::self()->smallIcon( "edit-copy" ),
65 i18nc( "copy this event", "&Copy" ),
66 this, SLOT(popupCopy()) ) );
67 // paste is always possible
68 mEditOnlyItems
.append( addAction( KOGlobals::self()->smallIcon( "edit-paste" ),
70 this, SLOT(popupPaste()) ) );
71 mEditOnlyItems
.append( addAction( KOGlobals::self()->smallIcon( "edit-delete" ),
72 i18nc( "delete this incidence", "&Delete" ),
73 this, SLOT(popupDelete()) ) );
74 //------------------------------------------------------------------------
75 mEditOnlyItems
.append( addSeparator() );
76 mTodoOnlyItems
.append( addAction( KOGlobals::self()->smallIcon( "task-complete" ),
77 i18n( "Togg&le To-do Completed" ),
78 this, SLOT(toggleTodoCompleted()) ) );
79 mToggleReminder
= addAction( QIcon( KOGlobals::self()->smallIcon( "appointment-reminder" ) ),
80 i18n( "&Toggle Reminder" ), this, SLOT(toggleAlarm()));
81 mEditOnlyItems
.append( mToggleReminder
);
82 //------------------------------------------------------------------------
83 mRecurrenceItems
.append( addSeparator() );
84 mDissociateOccurrences
= addAction( i18n( "&Dissociate From Recurrence..." ),
85 this, SLOT(dissociateOccurrences()) );
86 mRecurrenceItems
.append( mDissociateOccurrences
);
89 addAction( KOGlobals::self()->smallIcon( "mail-forward" ),
90 i18n( "Send as iCalendar..." ),
91 this, SLOT(forward()) );
94 void KOEventPopupMenu::showIncidencePopup( const Akonadi::Item
&item
, const QDate
&qd
)
96 mCurrentIncidence
= item
;
99 if ( !CalendarSupport::hasIncidence( mCurrentIncidence
) /*&& qd.isValid()*/ ) {
100 kDebug() << "No event selected";
106 kDebug() << "Calendar is 0";
110 const bool hasChangeRights
= mCalendar
->hasChangeRights( mCurrentIncidence
);
112 Incidence::Ptr incidence
= CalendarSupport::incidence( mCurrentIncidence
);
113 Q_ASSERT( incidence
);
114 if ( incidence
->recurs() ) {
115 const KDateTime
thisDateTime( qd
, CalendarSupport::KCalPrefs::instance()->timeSpec() );
116 const bool isLastOccurrence
=
117 !incidence
->recurrence()->getNextDateTime( thisDateTime
).isValid();
118 const bool isFirstOccurrence
=
119 !incidence
->recurrence()->getPreviousDateTime( thisDateTime
).isValid();
120 mDissociateOccurrences
->setEnabled(
121 !( isFirstOccurrence
&& isLastOccurrence
) && hasChangeRights
);
124 // Enable/Disabled menu items only valid for editable events.
125 QList
<QAction
*>::Iterator it
;
126 for ( it
= mEditOnlyItems
.begin(); it
!= mEditOnlyItems
.end(); ++it
) {
127 (*it
)->setEnabled( hasChangeRights
);
129 mToggleReminder
->setVisible( ( incidence
->type() != Incidence::TypeJournal
) );
130 for ( it
= mRecurrenceItems
.begin(); it
!= mRecurrenceItems
.end(); ++it
) {
131 (*it
)->setVisible( incidence
->recurs() );
133 for ( it
= mTodoOnlyItems
.begin(); it
!= mTodoOnlyItems
.end(); ++it
) {
134 (*it
)->setVisible( incidence
->type() == Incidence::TypeTodo
);
135 (*it
)->setEnabled( hasChangeRights
);
137 popup( QCursor::pos() );
140 void KOEventPopupMenu::popupShow()
142 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
143 emit
showIncidenceSignal( mCurrentIncidence
);
147 void KOEventPopupMenu::popupEdit()
149 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
150 emit
editIncidenceSignal( mCurrentIncidence
);
155 void KOEventPopupMenu::print()
160 void KOEventPopupMenu::print( bool preview
)
163 CalPrinter
printer( this, mCalendar
, &helper
, true );
164 connect( this, SIGNAL(configChanged()), &printer
, SLOT(updateConfig()) );
166 //Item::List selectedIncidences;
167 Incidence::List selectedIncidences
;
168 Q_ASSERT( mCurrentIncidence
.hasPayload
<KCalCore::Incidence::Ptr
>() );
169 selectedIncidences
.append( mCurrentIncidence
.payload
<KCalCore::Incidence::Ptr
>() );
171 printer
.print( KOrg::CalPrinterBase::Incidence
,
172 mCurrentDate
, mCurrentDate
, selectedIncidences
, preview
);
175 void KOEventPopupMenu::printPreview()
180 void KOEventPopupMenu::popupDelete()
182 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
183 emit
deleteIncidenceSignal( mCurrentIncidence
);
187 void KOEventPopupMenu::popupCut()
189 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
190 emit
cutIncidenceSignal( mCurrentIncidence
);
194 void KOEventPopupMenu::popupCopy()
196 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
197 emit
copyIncidenceSignal( mCurrentIncidence
);
201 void KOEventPopupMenu::popupPaste()
203 emit
pasteIncidenceSignal();
206 void KOEventPopupMenu::toggleAlarm()
208 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
209 emit
toggleAlarmSignal( mCurrentIncidence
);
213 void KOEventPopupMenu::dissociateOccurrences()
215 if ( CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
216 emit
dissociateOccurrencesSignal( mCurrentIncidence
, mCurrentDate
);
220 void KOEventPopupMenu::forward()
222 KOrg::MainWindow
*w
= ActionManager::findInstance( KUrl() );
223 if ( !w
|| !CalendarSupport::hasIncidence( mCurrentIncidence
) ) {
227 KActionCollection
*ac
= w
->getActionCollection();
228 QAction
*action
= ac
->action( "schedule_forward" );
232 kError() << "What happened to the schedule_forward action?";
236 void KOEventPopupMenu::toggleTodoCompleted()
238 if ( CalendarSupport::hasTodo( mCurrentIncidence
) ) {
239 emit
toggleTodoCompletedSignal( mCurrentIncidence
);
243 void KOEventPopupMenu::setCalendar( CalendarSupport::Calendar
*calendar
)
245 mCalendar
= calendar
;
248 #include "koeventpopupmenu.moc"