korganizer

koeventpopupmenu.cpp
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqcursor.h>
26
27#include <tdeactioncollection.h>
28#include <tdelocale.h>
29#include <kdebug.h>
30#include <kiconloader.h>
31#include <kurl.h>
32
33#include <libkcal/event.h>
34
35#include "koglobals.h"
36
37#include <korganizer/baseview.h>
38#include "koeventpopupmenu.h"
39#include "koeventpopupmenu.moc"
40#include "kocorehelper.h"
41#include "actionmanager.h"
42#ifndef KORG_NOPRINTER
43#include "calprinter.h"
44#endif
45
46KOEventPopupMenu::KOEventPopupMenu()
47{
48 mCalendar = 0;
49 mCurrentIncidence = 0;
50 mCurrentDate = TQDate();
51 mHasAdditionalItems = false;
52
53 insertItem( i18n("&Show"), this, TQ_SLOT( popupShow() ) );
54 mEditOnlyItems.append(
55 insertItem(i18n("&Edit..."), this, TQ_SLOT( popupEdit() ) ) );
56#ifndef KORG_NOPRINTER
57 insertItem( KOGlobals::self()->smallIcon("printer"), i18n("&Print..."),
58 this, TQ_SLOT( print() ) );
59#endif
60 //------------------------------------------------------------------------
61 mEditOnlyItems.append( insertSeparator() );
62 mEditOnlyItems.append(
63 insertItem( KOGlobals::self()->smallIcon("edit-cut"), i18n("&Cut"),
64 this, TQ_SLOT( popupCut() ) ) );
65 mEditOnlyItems.append(
66 insertItem( KOGlobals::self()->smallIcon("edit-copy"), i18n("&Copy"),
67 this, TQ_SLOT( popupCopy() ) ) );
68 // paste is always possible
69 insertItem( KOGlobals::self()->smallIcon("edit-paste"), i18n("&Paste"),
70 this, TQ_SLOT( popupPaste() ) );
71 mEditOnlyItems.append(
72 insertItem( KOGlobals::self()->smallIcon("edit-delete"), i18n("&Delete"),
73 this, TQ_SLOT( popupDelete() ) ) );
74 //------------------------------------------------------------------------
75 mEditOnlyItems.append( insertSeparator() );
76 mEditOnlyItems.append(
77 insertItem( KOGlobals::self()->smallIcon("bell"), i18n("&Toggle Reminder"),
78 this, TQ_SLOT( popupAlarm() ) ) );
79 //------------------------------------------------------------------------
80 mRecurrenceItems.append( insertSeparator() );
81 mRecurrenceItems.append(
82 insertItem( i18n("&Dissociate This Occurrence"),
83 this, TQ_SLOT( dissociateOccurrence() ) ) );
84 mRecurrenceItems.append(
85 insertItem( i18n("&Dissociate Future Occurrences"),
86 this, TQ_SLOT( dissociateFutureOccurrence() ) ) );
87
88 insertSeparator();
89 insertItem( KOGlobals::self()->smallIcon("mail-forward"), i18n( "Send as iCalendar..."),
90 this, TQ_SLOT(forward()) );
91}
92
93void KOEventPopupMenu::showIncidencePopup( Calendar *cal, Incidence *incidence, const TQDate &qd )
94{
95 mCalendar = cal;
96 mCurrentIncidence = incidence;
97 mCurrentDate = qd;
98
99 if (mCurrentIncidence) {
100 // Enable/Disabled menu items only valid for editable events.
101 TQValueList<int>::Iterator it;
102 for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) {
103 setItemEnabled(*it,!mCurrentIncidence->isReadOnly());
104 }
105 for ( it = mRecurrenceItems.begin(); it != mRecurrenceItems.end(); ++it ) {
106 setItemVisible( *it, mCurrentIncidence->doesRecur() );
107 }
108 popup(TQCursor::pos());
109 } else {
110 kdDebug(5850) << "KOEventPopupMenu::showEventPopup(): No event selected" << endl;
111 }
112}
113
114void KOEventPopupMenu::addAdditionalItem(const TQIconSet &icon,const TQString &text,
115 const TQObject *receiver, const char *member,
116 bool editOnly)
117{
118 if (!mHasAdditionalItems) {
119 mHasAdditionalItems = true;
120 insertSeparator();
121 }
122 int id = insertItem(icon,text,receiver,member);
123 if (editOnly) mEditOnlyItems.append(id);
124}
125
126void KOEventPopupMenu::popupShow()
127{
128 if ( mCurrentIncidence ) {
129 emit showIncidenceSignal( mCurrentIncidence, mCurrentDate );
130 }
131}
132
133void KOEventPopupMenu::popupEdit()
134{
135 if ( mCurrentIncidence ) {
136 emit editIncidenceSignal( mCurrentIncidence, mCurrentDate );
137 }
138}
139
140void KOEventPopupMenu::print()
141{
142#ifndef KORG_NOPRINTER
143 KOCoreHelper helper;
144 CalPrinter printer( this, mCalendar, &helper );
145 connect( this, TQ_SIGNAL(configChanged()), &printer, TQ_SLOT(updateConfig()) );
146
147 Incidence::List selectedIncidences;
148 selectedIncidences.append( mCurrentIncidence );
149
150 printer.print( KOrg::CalPrinterBase::Incidence,
151 mCurrentDate, mCurrentDate, selectedIncidences );
152#endif
153}
154
155void KOEventPopupMenu::popupDelete()
156{
157 if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence);
158}
159
160void KOEventPopupMenu::popupCut()
161{
162 if (mCurrentIncidence) emit cutIncidenceSignal(mCurrentIncidence);
163}
164
165void KOEventPopupMenu::popupCopy()
166{
167 if (mCurrentIncidence) emit copyIncidenceSignal(mCurrentIncidence);
168}
169
170void KOEventPopupMenu::popupPaste()
171{
172 emit pasteIncidenceSignal();
173}
174
175
176void KOEventPopupMenu::popupAlarm()
177{
178 if (mCurrentIncidence) emit toggleAlarmSignal( mCurrentIncidence );
179}
180
181void KOEventPopupMenu::dissociateOccurrence()
182{
183 if ( mCurrentIncidence )
184 emit dissociateOccurrenceSignal( mCurrentIncidence, mCurrentDate );
185}
186
187void KOEventPopupMenu::dissociateFutureOccurrence()
188{
189 if ( mCurrentIncidence )
190 emit dissociateFutureOccurrenceSignal( mCurrentIncidence, mCurrentDate );
191}
192
193void KOEventPopupMenu::forward()
194{
196 if ( !w || !mCurrentIncidence )
197 return;
198 TDEActionCollection *ac = w->getActionCollection();
199 TDEAction *action = ac->action( "schedule_forward" );
200 action->activate();
201}
static KOrg::MainWindow * findInstance(const KURL &url)
Is there a instance with this URL?
CalPrinter is a class for printing Calendars.
Definition: calprinter.h:54
interface for korganizer main window
Definition: mainwindow.h:41
virtual TDEActionCollection * getActionCollection() const =0
Return actionCollection of this main window.