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

korganizer

  • sources
  • kde-4.12
  • 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 "calprinter.h"
29 #include "kocorehelper.h"
30 #include "koglobals.h"
31 
32 #include <calendarsupport/kcalprefs.h>
33 #include <calendarsupport/utils.h>
34 
35 #include <KCalCore/Incidence>
36 
37 #include <KActionCollection>
38 #include <KMimeTypeTrader>
39 
40 KOEventPopupMenu::KOEventPopupMenu( Akonadi::ETMCalendar * calendar, QWidget *parent )
41  : QMenu( parent ), mCalendar( calendar )
42 {
43  mHasAdditionalItems = false;
44 
45  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-preview") ), i18n( "&Show" ),
46  this, SLOT(popupShow()) );
47  mEditOnlyItems.append(
48  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-edit") ), i18n( "&Edit..." ),
49  this, SLOT(popupEdit()) ) );
50  mEditOnlyItems.append( addSeparator() );
51  addAction( KOGlobals::self()->smallIcon( QLatin1String("document-print") ), i18n( "&Print..." ),
52  this, SLOT(print()) );
53  QAction *preview = addAction( KOGlobals::self()->smallIcon( QLatin1String("document-print-preview") ),
54  i18n( "Print Previe&w..." ),
55  this, SLOT(printPreview()) );
56  preview->setEnabled( !KMimeTypeTrader::self()->query(QLatin1String( "application/pdf"),
57  QLatin1String("KParts/ReadOnlyPart") ).isEmpty() );
58  //------------------------------------------------------------------------
59  mEditOnlyItems.append( addSeparator() );
60  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-cut") ),
61  i18nc( "cut this event", "C&ut" ),
62  this, SLOT(popupCut()) ) );
63  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-copy") ),
64  i18nc( "copy this event", "&Copy" ),
65  this, SLOT(popupCopy()) ) );
66  // paste is always possible
67  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-paste") ),
68  i18n( "&Paste" ),
69  this, SLOT(popupPaste()) ) );
70  mEditOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("edit-delete") ),
71  i18nc( "delete this incidence", "&Delete" ),
72  this, SLOT(popupDelete()) ) );
73  //------------------------------------------------------------------------
74  mEditOnlyItems.append( addSeparator() );
75  mTodoOnlyItems.append( addAction( KOGlobals::self()->smallIcon( QLatin1String("task-complete") ),
76  i18n( "Togg&le To-do Completed" ),
77  this, SLOT(toggleTodoCompleted()) ) );
78  mToggleReminder = addAction( QIcon( KOGlobals::self()->smallIcon( QLatin1String("appointment-reminder") ) ),
79  i18n( "&Toggle Reminder" ), this, SLOT(toggleAlarm()));
80  mEditOnlyItems.append( mToggleReminder );
81  //------------------------------------------------------------------------
82  mRecurrenceItems.append( addSeparator() );
83  mDissociateOccurrences = addAction( i18n( "&Dissociate From Recurrence..." ),
84  this, SLOT(dissociateOccurrences()) );
85  mRecurrenceItems.append( mDissociateOccurrences );
86 
87  addSeparator();
88  addAction( KOGlobals::self()->smallIcon( QLatin1String("mail-forward") ),
89  i18n( "Send as iCalendar..." ),
90  this, SLOT(forward()) );
91 }
92 
93 void KOEventPopupMenu::showIncidencePopup( const Akonadi::Item &item, const QDate &qd )
94 {
95  mCurrentIncidence = item;
96  mCurrentDate = qd;
97 
98  if ( !CalendarSupport::hasIncidence( mCurrentIncidence )/*&& qd.isValid()*/ ) {
99  kDebug() << "No event selected";
100  return;
101  }
102 
103  if ( !mCalendar ) {
104  //TODO fix it
105  kDebug() << "Calendar is 0";
106  return;
107  }
108 
109  const bool hasChangeRights = mCalendar->hasRight( mCurrentIncidence, Akonadi::Collection::CanChangeItem );
110 
111  KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence( mCurrentIncidence );
112  Q_ASSERT( incidence );
113  if ( incidence->recurs() ) {
114  const KDateTime thisDateTime( qd, CalendarSupport::KCalPrefs::instance()->timeSpec() );
115  const bool isLastOccurrence =
116  !incidence->recurrence()->getNextDateTime( thisDateTime ).isValid();
117  const bool isFirstOccurrence =
118  !incidence->recurrence()->getPreviousDateTime( thisDateTime ).isValid();
119  mDissociateOccurrences->setEnabled(
120  !( isFirstOccurrence && isLastOccurrence ) && hasChangeRights );
121  }
122 
123  // Enable/Disabled menu items only valid for editable events.
124  QList<QAction *>::Iterator it;
125  for ( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) {
126  (*it)->setEnabled( hasChangeRights );
127  }
128  mToggleReminder->setVisible( ( incidence->type() != KCalCore::Incidence::TypeJournal ) );
129  for ( it = mRecurrenceItems.begin(); it != mRecurrenceItems.end(); ++it ) {
130  (*it)->setVisible( incidence->recurs() );
131  }
132  for ( it = mTodoOnlyItems.begin(); it != mTodoOnlyItems.end(); ++it ) {
133  (*it)->setVisible( incidence->type() == KCalCore::Incidence::TypeTodo );
134  (*it)->setEnabled( hasChangeRights );
135  }
136  popup( QCursor::pos() );
137 }
138 
139 void KOEventPopupMenu::popupShow()
140 {
141  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
142  emit showIncidenceSignal( mCurrentIncidence );
143  }
144 }
145 
146 void KOEventPopupMenu::popupEdit()
147 {
148  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
149  emit editIncidenceSignal( mCurrentIncidence );
150  }
151 }
152 
153 void KOEventPopupMenu::print()
154 {
155  print( false );
156 }
157 
158 void KOEventPopupMenu::print( bool preview )
159 {
160  KOCoreHelper helper;
161  CalPrinter printer( this, mCalendar, &helper, true );
162  connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
163 
164  //Item::List selectedIncidences;
165  KCalCore::Incidence::List selectedIncidences;
166  Q_ASSERT( mCurrentIncidence.hasPayload<KCalCore::Incidence::Ptr>() );
167  selectedIncidences.append( mCurrentIncidence.payload<KCalCore::Incidence::Ptr>() );
168 
169  printer.print( KOrg::CalPrinterBase::Incidence,
170  mCurrentDate, mCurrentDate, selectedIncidences, preview );
171 }
172 
173 void KOEventPopupMenu::printPreview()
174 {
175  print( true );
176 }
177 
178 void KOEventPopupMenu::popupDelete()
179 {
180  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
181  emit deleteIncidenceSignal( mCurrentIncidence );
182  }
183 }
184 
185 void KOEventPopupMenu::popupCut()
186 {
187  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
188  emit cutIncidenceSignal( mCurrentIncidence );
189  }
190 }
191 
192 void KOEventPopupMenu::popupCopy()
193 {
194  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
195  emit copyIncidenceSignal( mCurrentIncidence );
196  }
197 }
198 
199 void KOEventPopupMenu::popupPaste()
200 {
201  emit pasteIncidenceSignal();
202 }
203 
204 void KOEventPopupMenu::toggleAlarm()
205 {
206  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
207  emit toggleAlarmSignal( mCurrentIncidence );
208  }
209 }
210 
211 void KOEventPopupMenu::dissociateOccurrences()
212 {
213  if ( CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
214  emit dissociateOccurrencesSignal( mCurrentIncidence, mCurrentDate );
215  }
216 }
217 
218 void KOEventPopupMenu::forward()
219 {
220  KOrg::MainWindow *w = ActionManager::findInstance( KUrl() );
221  if ( !w || !CalendarSupport::hasIncidence( mCurrentIncidence ) ) {
222  return;
223  }
224 
225  KActionCollection *ac = w->getActionCollection();
226  QAction *action = ac->action( QLatin1String("schedule_forward") );
227  if ( action ) {
228  action->trigger();
229  } else {
230  kError() << "What happened to the schedule_forward action?";
231  }
232 }
233 
234 void KOEventPopupMenu::toggleTodoCompleted()
235 {
236  if ( CalendarSupport::hasTodo( mCurrentIncidence ) ) {
237  emit toggleTodoCompletedSignal( mCurrentIncidence );
238  }
239 }
240 
241 void KOEventPopupMenu::setCalendar( const Akonadi::ETMCalendar::Ptr &calendar )
242 {
243  mCalendar = calendar;
244 }
245 
246 #include "koeventpopupmenu.moc"
koglobals.h
KOEventPopupMenu::editIncidenceSignal
void editIncidenceSignal(const Akonadi::Item &)
KOCoreHelper
Definition: kocorehelper.h:35
KOEventPopupMenu::popupEdit
void popupEdit()
Definition: koeventpopupmenu.cpp:146
KOEventPopupMenu::forward
void forward()
Definition: koeventpopupmenu.cpp:218
QWidget
KOEventPopupMenu::printPreview
void printPreview()
Definition: koeventpopupmenu.cpp:173
KOEventPopupMenu::pasteIncidenceSignal
void pasteIncidenceSignal()
KOEventPopupMenu::toggleAlarm
void toggleAlarm()
Definition: koeventpopupmenu.cpp:204
KOEventPopupMenu::popupCut
void popupCut()
Definition: koeventpopupmenu.cpp:185
KOEventPopupMenu::popupDelete
void popupDelete()
Definition: koeventpopupmenu.cpp:178
KOrg::CalPrinterBase::Incidence
Definition: printplugin.h:46
actionmanager.h
KOEventPopupMenu::print
void print()
Definition: koeventpopupmenu.cpp:153
KOEventPopupMenu::toggleTodoCompletedSignal
void toggleTodoCompletedSignal(const Akonadi::Item &)
KOEventPopupMenu::configChanged
void configChanged()
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:139
koeventpopupmenu.h
KOrg::MainWindow::getActionCollection
virtual KActionCollection * getActionCollection() const =0
Return actionCollection of this main window.
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:241
KOEventPopupMenu::dissociateOccurrencesSignal
void dissociateOccurrencesSignal(const Akonadi::Item &, const QDate &)
CalPrinter
CalPrinter is a class for printing Calendars.
Definition: calprinter.h:46
KOEventPopupMenu::KOEventPopupMenu
KOEventPopupMenu(Akonadi::ETMCalendar *, QWidget *parent=0)
Definition: koeventpopupmenu.cpp:40
KOEventPopupMenu::toggleTodoCompleted
void toggleTodoCompleted()
Definition: koeventpopupmenu.cpp:234
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
QMenu
KOEventPopupMenu::cutIncidenceSignal
void cutIncidenceSignal(const Akonadi::Item &)
KOEventPopupMenu::popupCopy
void popupCopy()
Definition: koeventpopupmenu.cpp:192
KOEventPopupMenu::dissociateOccurrences
void dissociateOccurrences()
Definition: koeventpopupmenu.cpp:211
KOEventPopupMenu::copyIncidenceSignal
void copyIncidenceSignal(const Akonadi::Item &)
KOEventPopupMenu::showIncidencePopup
void showIncidencePopup(const Akonadi::Item &, const QDate &)
Definition: koeventpopupmenu.cpp:93
KOEventPopupMenu::toggleAlarmSignal
void toggleAlarmSignal(const Akonadi::Item &)
KOEventPopupMenu::popupPaste
void popupPaste()
Definition: koeventpopupmenu.cpp:199
kocorehelper.h
calprinter.h
KOEventPopupMenu::deleteIncidenceSignal
void deleteIncidenceSignal(const Akonadi::Item &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 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

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