• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.14
  • kdepim
  • korganizer
koeventpopupmenu.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
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.
11 
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.
16 
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.
20 
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.
24 */
25 
26 #include "koeventpopupmenu.h"
27 #include "actionmanager.h"
28 #include "kocorehelper.h"
29 #include "koglobals.h"
30 
31 #include <calendarsupport/kcalprefs.h>
32 #include <calendarsupport/utils.h>
33 #include <calendarsupport/printing/calprinter.h>
34 #include <calendarsupport/printing/calprintdefaultplugins.h>
35 
36 #include <KCalCore/Incidence>
37 
38 #include <KActionCollection>
39 #include <KMimeTypeTrader>
40 #include <KPrintPreview>
41 KOEventPopupMenu::KOEventPopupMenu( Akonadi::ETMCalendar * calendar, QWidget *parent )
42  : QMenu( parent ), mCalendar( calendar )
43 {
44  mHasAdditionalItems = false;
45 
46  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-preview") ), i18n( "&Show" ),
47  this, SLOT(popupShow()) );
48  mEditOnlyItems.append(
49  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-edit") ), i18n( "&Edit..." ),
50  this, SLOT(popupEdit()) ) );
51  mEditOnlyItems.append( addSeparator() );
52  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-print") ), i18n( "&Print..." ),
53  this, SLOT(print()) );
54  if (KPrintPreview::isAvailable()) {
55  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-print-preview") ),
56  i18n( "Print Previe&w..." ),
57  this, SLOT(printPreview()) );
58  }
59  //------------------------------------------------------------------------
60  mEditOnlyItems.append( addSeparator() );
61  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-cut") ),
62  i18nc( "cut this event", "C&ut" ),
63  this, SLOT(popupCut()) ) );
64  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-copy") ),
65  i18nc( "copy this event", "&Copy" ),
66  this, SLOT(popupCopy()) ) );
67  // paste is always possible
68  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-paste") ),
69  i18n( "&Paste" ),
70  this, SLOT(popupPaste()) ) );
71  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-delete") ),
72  i18nc( "delete this incidence", "&Delete" ),
73  this, SLOT(popupDelete()) ) );
74  //------------------------------------------------------------------------
75  mEditOnlyItems.append( addSeparator() );
76  mTodoOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("task-complete") ),
77  i18n( "Togg&le To-do Completed" ),
78  this, SLOT(toggleTodoCompleted()) ) );
79  mToggleReminder = addAction( QIcon( KOGlobals::self()->smallIcon( QLatin1String("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 );
87 
88  addSeparator();
89  addAction( KOGlobals::self()->smallIcon( QLatin1String("mail-forward") ),
90  i18n( "Send as iCalendar..." ),
91  this, SLOT(forward()) );
92 }
93 
94 void KOEventPopupMenu::showIncidencePopup( const Akonadi::Item &item, const QDate &qd )
95 {
96  mCurrentIncidence = item;
97  mCurrentDate = qd;
98 
99  if ( !CalendarSupport::hasIncidence( mCurrentIncidence )/*&& qd.isValid()*/ ) {
100  kDebug() << "No event selected";
101  return;
102  }
103 
104  if ( !mCalendar ) {
105  //TODO fix it
106  kDebug() << "Calendar is 0";
107  return;
108  }
109 
110  const bool hasChangeRights = mCalendar->hasRight( mCurrentIncidence, Akonadi::Collection::CanChangeItem );
111 
112  KCalCore::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 );
122  }
123 
124  // Enable/Disabled menu items only valid for editable events.
125  QList<QAction *>::Iterator it;
126  QList<QAction *>::Iterator end(mEditOnlyItems.end());
127  for ( it = mEditOnlyItems.begin(); it != end; ++it ) {
128  (*it)->setEnabled( hasChangeRights );
129  }
130  mToggleReminder->setVisible( ( incidence->type() != KCalCore::Incidence::TypeJournal ) );
131  end = mRecurrenceItems.end();
132  for ( it = mRecurrenceItems.begin(); it != end; ++it ) {
133  (*it)->setVisible( incidence->recurs() );
134  }
135  end = mTodoOnlyItems.end();
136  for ( it = mTodoOnlyItems.begin(); it != end; ++it ) {
137  (*it)->setVisible( incidence->type() == KCalCore::Incidence::TypeTodo );
138  (*it)->setEnabled( hasChangeRights );
139  }
140  popup( QCursor::pos() );
141 }
142 
143 void KOEventPopupMenu::popupShow()
144 {
145  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
146  emit showIncidenceSignal( mCurrentIncidence );
147  }
148 }
149 
150 void KOEventPopupMenu::popupEdit()
151 {
152  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
153  emit editIncidenceSignal( mCurrentIncidence );
154  }
155 }
156 
157 void KOEventPopupMenu::print()
158 {
159  print( false );
160 }
161 
162 void KOEventPopupMenu::print( bool preview )
163 {
164  KOCoreHelper helper;
165  CalendarSupport::CalPrinter printer( this, mCalendar, true );
166  connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
167 
168  //Item::List selectedIncidences;
169  KCalCore::Incidence::List selectedIncidences;
170  Q_ASSERT( mCurrentIncidence.hasPayload<KCalCore::Incidence::Ptr>() );
171  selectedIncidences.append( mCurrentIncidence.payload<KCalCore::Incidence::Ptr>() );
172 
173  printer.print( CalendarSupport::CalPrinterBase::Incidence,
174  mCurrentDate, mCurrentDate, selectedIncidences, preview );
175 }
176 
177 void KOEventPopupMenu::printPreview()
178 {
179  print( true );
180 }
181 
182 void KOEventPopupMenu::popupDelete()
183 {
184  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
185  emit deleteIncidenceSignal( mCurrentIncidence );
186  }
187 }
188 
189 void KOEventPopupMenu::popupCut()
190 {
191  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
192  emit cutIncidenceSignal( mCurrentIncidence );
193  }
194 }
195 
196 void KOEventPopupMenu::popupCopy()
197 {
198  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
199  emit copyIncidenceSignal( mCurrentIncidence );
200  }
201 }
202 
203 void KOEventPopupMenu::popupPaste()
204 {
205  emit pasteIncidenceSignal();
206 }
207 
208 void KOEventPopupMenu::toggleAlarm()
209 {
210  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
211  emit toggleAlarmSignal( mCurrentIncidence );
212  }
213 }
214 
215 void KOEventPopupMenu::dissociateOccurrences()
216 {
217  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
218  emit dissociateOccurrencesSignal( mCurrentIncidence, mCurrentDate );
219  }
220 }
221 
222 void KOEventPopupMenu::forward()
223 {
224  KOrg::MainWindow *w = ActionManager::findInstance( KUrl() );
225  if ( !w || !CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
226  return;
227  }
228 
229  KActionCollection *ac = w->getActionCollection();
230  QAction *action = ac->action( QLatin1String("schedule_forward") );
231  if ( action ) {
232  action->trigger();
233  } else {
234  kError() << "What happened to the schedule_forward action?";
235  }
236 }
237 
238 void KOEventPopupMenu::toggleTodoCompleted()
239 {
240  if ( CalendarSupport::hasTodo( mCurrentIncidence ) ) {
241  emit toggleTodoCompletedSignal( mCurrentIncidence );
242  }
243 }
244 
245 void KOEventPopupMenu::setCalendar( const Akonadi::ETMCalendar::Ptr &calendar )
246 {
247  mCalendar = calendar;
248 }
249 
QWidget
koglobals.h
KOEventPopupMenu::editIncidenceSignal
void editIncidenceSignal(const Akonadi::Item &)
KOCoreHelper
Definition: kocorehelper.h:35
KOEventPopupMenu::popupEdit
void popupEdit()
Definition: koeventpopupmenu.cpp:150
KOEventPopupMenu::forward
void forward()
Definition: koeventpopupmenu.cpp:222
QAction::setVisible
void setVisible(bool)
KOEventPopupMenu::printPreview
void printPreview()
Definition: koeventpopupmenu.cpp:177
KOEventPopupMenu::pasteIncidenceSignal
void pasteIncidenceSignal()
QMenu::addAction
void addAction(QAction *action)
KOEventPopupMenu::toggleAlarm
void toggleAlarm()
Definition: koeventpopupmenu.cpp:208
KOEventPopupMenu::popupCut
void popupCut()
Definition: koeventpopupmenu.cpp:189
KOEventPopupMenu::popupDelete
void popupDelete()
Definition: koeventpopupmenu.cpp:182
actionmanager.h
KOEventPopupMenu::print
void print()
Definition: koeventpopupmenu.cpp:157
QAction::trigger
void trigger()
KOEventPopupMenu::toggleTodoCompletedSignal
void toggleTodoCompletedSignal(const Akonadi::Item &)
KOEventPopupMenu::configChanged
void configChanged()
QList::append
void append(const T &value)
QMenu::popup
void popup(const QPoint &p, QAction *atAction)
ActionManager::findInstance
static KOrg::MainWindow * findInstance(const KUrl &url)
Is there a instance with this URL?
Definition: actionmanager.cpp:1273
KOEventPopupMenu::popupShow
void popupShow()
Definition: koeventpopupmenu.cpp:143
koeventpopupmenu.h
QDate
KOrg::MainWindow::getActionCollection
virtual KActionCollection * getActionCollection() const =0
Return actionCollection of this main window.
QMenu::addSeparator
QAction * addSeparator()
QList
KOrg::MainWindow
interface for korganizer main window
Definition: mainwindow.h:44
KOEventPopupMenu::showIncidenceSignal
void showIncidenceSignal(const Akonadi::Item &)
KOEventPopupMenu::setCalendar
void setCalendar(const Akonadi::ETMCalendar::Ptr &calendar)
Definition: koeventpopupmenu.cpp:245
KOEventPopupMenu::dissociateOccurrencesSignal
void dissociateOccurrencesSignal(const Akonadi::Item &, const QDate &)
QList::end
iterator end()
QMenu
KOEventPopupMenu::KOEventPopupMenu
KOEventPopupMenu(Akonadi::ETMCalendar *, QWidget *parent=0)
Definition: koeventpopupmenu.cpp:41
KOEventPopupMenu::toggleTodoCompleted
void toggleTodoCompleted()
Definition: koeventpopupmenu.cpp:238
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
QCursor::pos
QPoint pos()
QLatin1String
QAction
KOEventPopupMenu::cutIncidenceSignal
void cutIncidenceSignal(const Akonadi::Item &)
KOEventPopupMenu::popupCopy
void popupCopy()
Definition: koeventpopupmenu.cpp:196
KOEventPopupMenu::dissociateOccurrences
void dissociateOccurrences()
Definition: koeventpopupmenu.cpp:215
KOEventPopupMenu::copyIncidenceSignal
void copyIncidenceSignal(const Akonadi::Item &)
KOEventPopupMenu::showIncidencePopup
void showIncidencePopup(const Akonadi::Item &, const QDate &)
Definition: koeventpopupmenu.cpp:94
KOEventPopupMenu::toggleAlarmSignal
void toggleAlarmSignal(const Akonadi::Item &)
KOEventPopupMenu::popupPaste
void popupPaste()
Definition: koeventpopupmenu.cpp:203
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
kocorehelper.h
QList::begin
iterator begin()
QAction::setEnabled
void setEnabled(bool)
KOEventPopupMenu::deleteIncidenceSignal
void deleteIncidenceSignal(const Akonadi::Item &)
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal